Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TH1Merger.h
Go to the documentation of this file.
1// @(#)root/cont:$Id$
2// Author: Lorenzo Moneta 08/2016
3
4/*************************************************************************
5 * Copyright (C) 1995-2003, Rene Brun, Fons Rademakers and al. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12// Helper clas implementing some of the TH1 functionality
13
14#include "TH1.h"
15#include "TProfile.h"
16#include "TProfile2D.h"
17#include "TProfile3D.h"
18#include "TList.h"
19
20class TH1Merger {
21
22public:
24 kNotCompatible = -1, // histogram arenot compatible and cannot be merged
25 kAllSameAxes = 0, // histogram have all some axes
26 kAllNoLimits = 1, // all histogram don't have limits (the buffer is used)
27 kHasNewLimits = 2, // some histogram have different limits but are compatibles
28 kAllLabel = 3, // histogram have labels all axis and same limits
29 kLabelAndNewLimits = 4, // histogram have label but also some axes with different limits
30 kAutoP2HaveLimits = 5, // P2 (power-of-2) algorithm: all histogram have limits
31 kAutoP2NeedLimits = 6 // P2 algorithm: some histogram still need projections
32 };
33
34 static Bool_t AxesHaveLimits(const TH1 * h);
35
36 static Int_t FindFixBinNumber(Int_t ibin, const TAxis & inAxis, const TAxis & outAxis) {
37 // should I ceck in case of underflow/overflow if underflow/overflow values of input axis
38 // outside output axis ?
39 if (ibin == 0 ) return 0; // return underflow
40 if (ibin == inAxis.GetNbins()+1 ) return outAxis.GetNbins()+1; // return overflow
41 return outAxis.FindFixBin(inAxis.GetBinCenter(ibin));
42 }
43
44 // find bin number estending the axis
45 static Int_t FindBinNumber(Int_t ibin, const TAxis & inAxis, TAxis & outAxis) {
46 // should I ceck in case of underflow/overflow if underflow/overflow values of input axis
47 // outside output axis ?
48 if (ibin == 0 ) return 0; // return underflow
49 if (ibin == inAxis.GetNbins()+1 ) return outAxis.GetNbins()+1; // return overflow
50 return outAxis.FindBin(inAxis.GetBinCenter(ibin));
51 }
52
53 // Function to find if axis label list has duplicates
54 static Bool_t HasDuplicateLabels(const THashList * labels);
55
56 // check if histogram has duplicate labels
57 static Int_t CheckForDuplicateLabels(const TH1 * hist);
58
59 // function to check if histogram bin is empty
60 static Bool_t IsBinEmpty(const TH1 *hist, Int_t bin);
61
62
63
64 TH1Merger(TH1 & h, TCollection & l, Option_t * opt = "") :
65 fH0(&h),
66 fHClone(nullptr),
68 {
70 TString option(opt);
71 if (!option.IsNull() ) {
72 option.ToUpper();
73 if (option.Contains("NOL") )
74 fNoLabelMerge = true;
75 if (option.Contains("NOCHECK") )
76 fNoCheck = true;
77 }
78 TClass *classType = h.IsA();
79 if (classType == TProfile::Class()) {
82 } else if (classType == TProfile2D::Class()) {
85 } else if (classType == TProfile3D::Class()) {
88 }
89 }
90
92 // The list contains fHClone, so let's clear it first to avoid
93 // accessing deleted memory later [we 'could' have just removed
94 // fHClone from the list]
96 if (fHClone) delete fHClone;
97 }
98
99 // function doing the actual merge
101
102private:
104
106
107 void DefineNewAxes();
108
109 void CopyBuffer(TH1 *hsrc, TH1 *hdes);
110
112
114
116
118
120
121 Bool_t LabelMerge(bool newLimits = false);
122
123 template <class TProfileType>
124 void MergeProfileBin(const TProfileType *p, Int_t ibin, Int_t outbin);
125
126 // function doing the bin merge for histograms and profiles
127 void MergeBin(const TH1 *hist, Int_t inbin, Int_t outbin);
128
129 void MergeBin(const TProfile *hist, Int_t inbin, Int_t outbin) { MergeProfileBin<TProfile>(hist, inbin, outbin); }
130 void MergeBin(const TProfile2D *hist, Int_t inbin, Int_t outbin) { MergeProfileBin<TProfile2D>(hist, inbin, outbin); }
131 void MergeBin(const TProfile3D *hist, Int_t inbin, Int_t outbin) { MergeProfileBin<TProfile3D>(hist, inbin, outbin); }
132
133 Bool_t fNoLabelMerge = kFALSE; // force merger to not use labels and do bin center by bin center
134 Bool_t fNoCheck = kFALSE; // skip check on duplicate labels
135 Bool_t fIsProfileMerge = kFALSE; // flag to indicate if is a merge of TProfiles
139 TH1 *fH0; //! histogram on which the list is merged
140 TH1 *fHClone; //! copy of fH0 - managed by this class
141 TList fInputList; // input histogram List
146};
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Class to manage histogram axis.
Definition TAxis.h:31
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition TAxis.cxx:478
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition TAxis.cxx:293
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x.
Definition TAxis.cxx:419
Int_t GetNbins() const
Definition TAxis.h:125
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
TClass * IsA() const override
Definition TClass.h:618
Collection abstract base class.
Definition TCollection.h:65
virtual void AddAll(const TCollection *col)
Add all objects from collection col to this collection.
Bool_t AutoP2BufferMerge()
static Bool_t AxesHaveLimits(const TH1 *h)
Definition TH1Merger.cxx:19
Bool_t AutoP2Merge()
static Int_t CheckForDuplicateLabels(const TH1 *hist)
Check if histogram has duplicate labels Return an integer with bit set correponding on the axis that ...
Bool_t AutoP2BuildAxes(TH1 *)
Determine final boundaries and number of bins for histograms created in power-of-2 autobin mode.
Definition TH1Merger.cxx:80
TH1Merger(TH1 &h, TCollection &l, Option_t *opt="")
Definition TH1Merger.h:64
static Int_t FindBinNumber(Int_t ibin, const TAxis &inAxis, TAxis &outAxis)
Definition TH1Merger.h:45
Bool_t fIsProfileMerge
Definition TH1Merger.h:135
Bool_t DifferentAxesMerge()
Merged histogram when axis can be different.
Bool_t SameAxesMerge()
TList fInputList
copy of fH0 - managed by this class
Definition TH1Merger.h:141
Bool_t fNoLabelMerge
Definition TH1Merger.h:133
void MergeBin(const TProfile *hist, Int_t inbin, Int_t outbin)
Definition TH1Merger.h:129
static Int_t FindFixBinNumber(Int_t ibin, const TAxis &inAxis, const TAxis &outAxis)
Definition TH1Merger.h:36
TH1 * fH0
Definition TH1Merger.h:139
Bool_t fIsProfile3D
Definition TH1Merger.h:138
TAxis fNewZAxis
Definition TH1Merger.h:144
Bool_t fIsProfile1D
Definition TH1Merger.h:136
void CopyBuffer(TH1 *hsrc, TH1 *hdes)
Bool_t LabelMerge(bool newLimits=false)
Merge histograms with labels and if newLimits is set support the case that one of the axis can set ne...
void MergeBin(const TProfile3D *hist, Int_t inbin, Int_t outbin)
Definition TH1Merger.h:131
Bool_t BufferMerge()
static Bool_t IsBinEmpty(const TH1 *hist, Int_t bin)
helper function for merging
void MergeBin(const TProfile2D *hist, Int_t inbin, Int_t outbin)
Definition TH1Merger.h:130
EMergerType ExamineHistograms()
Examine the list of histograms to find out which type of Merge we need to do Pass the input list cont...
static Bool_t HasDuplicateLabels(const THashList *labels)
Find a duplicate labels in an axis label list.
void MergeBin(const TH1 *hist, Int_t inbin, Int_t outbin)
Bool_t operator()()
Function performing the actual merge.
Definition TH1Merger.cxx:27
Bool_t fIsProfile2D
Definition TH1Merger.h:137
@ kAllNoLimits
Definition TH1Merger.h:26
@ kLabelAndNewLimits
Definition TH1Merger.h:29
@ kNotCompatible
Definition TH1Merger.h:24
@ kAutoP2NeedLimits
Definition TH1Merger.h:31
@ kHasNewLimits
Definition TH1Merger.h:27
@ kAutoP2HaveLimits
Definition TH1Merger.h:30
@ kAllSameAxes
Definition TH1Merger.h:25
void DefineNewAxes()
Function to define new histogram axis when merging It is call only in case of merging with different ...
Bool_t fNoCheck
Definition TH1Merger.h:134
TH1 * fHClone
histogram on which the list is merged
Definition TH1Merger.h:140
UInt_t fNewAxisFlag
Definition TH1Merger.h:145
TAxis fNewXAxis
Definition TH1Merger.h:142
void MergeProfileBin(const TProfileType *p, Int_t ibin, Int_t outbin)
TAxis fNewYAxis
Definition TH1Merger.h:143
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
A doubly linked list.
Definition TList.h:38
void Clear(Option_t *option="") override
Remove all objects from the list.
Definition TList.cxx:400
Profile2D histograms are used to display the mean value of Z and its error for each cell in X,...
Definition TProfile2D.h:27
static TClass * Class()
Profile3D histograms are used to display the mean value of T and its RMS for each cell in X,...
Definition TProfile3D.h:27
static TClass * Class()
Profile Histogram.
Definition TProfile.h:32
static TClass * Class()
Basic string class.
Definition TString.h:139
TLine l
Definition textangle.C:4