Logo ROOT  
Reference Guide
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, // all histogram don't have limits (the buffer is used)
28 kAllLabel = 3, // histogram have labels all axis
29 kAutoP2HaveLimits = 4, // P2 (power-of-2) algorithm: all histogram have limits
30 kAutoP2NeedLimits = 5 // P2 algorithm: some histogram still need projections
31 };
32
33 static Bool_t AxesHaveLimits(const TH1 * h);
34
35 static Int_t FindFixBinNumber(Int_t ibin, const TAxis & inAxis, const TAxis & outAxis) {
36 // should I ceck in case of underflow/overflow if underflow/overflow values of input axis
37 // outside output axis ?
38 if (ibin == 0 ) return 0; // return underflow
39 if (ibin == inAxis.GetNbins()+1 ) return outAxis.GetNbins()+1; // return overflow
40 return outAxis.FindFixBin(inAxis.GetBinCenter(ibin));
41 }
42
43 // find bin number estending the axis
44 static Int_t FindBinNumber(Int_t ibin, const TAxis & inAxis, TAxis & outAxis) {
45 // should I ceck in case of underflow/overflow if underflow/overflow values of input axis
46 // outside output axis ?
47 if (ibin == 0 ) return 0; // return underflow
48 if (ibin == inAxis.GetNbins()+1 ) return outAxis.GetNbins()+1; // return overflow
49 return outAxis.FindBin(inAxis.GetBinCenter(ibin));
50 }
51
52 // Function to find if axis label list has duplicates
53 static Bool_t HasDuplicateLabels(const THashList * labels);
54
55 // check if histogram has duplicate labels
56 static Int_t CheckForDuplicateLabels(const TH1 * hist);
57
58 // function to check if histogram bin is empty
59 static Bool_t IsBinEmpty(const TH1 *hist, Int_t bin);
60
61
62
63 TH1Merger(TH1 & h, TCollection & l, Option_t * opt = "") :
64 fH0(&h),
65 fHClone(nullptr),
67 {
69 TString option(opt);
70 if (!option.IsNull() ) {
71 option.ToUpper();
72 if (option.Contains("NOL") )
73 fNoLabelMerge = true;
74 if (option.Contains("NOCHECK") )
75 fNoCheck = true;
76 }
77 TClass *classType = h.IsA();
78 if (classType == TProfile::Class()) {
81 } else if (classType == TProfile2D::Class()) {
84 } else if (classType == TProfile3D::Class()) {
87 }
88 }
89
91 // The list contains fHClone, so let's clear it first to avoid
92 // accessing deleted memory later [we 'could' have just removed
93 // fHClone from the list]
95 if (fHClone) delete fHClone;
96 }
97
98 // function doing the actual merge
100
101private:
103
105
106 void DefineNewAxes();
107
108 void CopyBuffer(TH1 *hsrc, TH1 *hdes);
109
111
113
115
117
119
121
122 template <class TProfileType>
123 void MergeProfileBin(const TProfileType *p, Int_t ibin, Int_t outbin);
124
125 // function doing the bin merge for histograms and profiles
126 void MergeBin(const TH1 *hist, Int_t inbin, Int_t outbin);
127
128 void MergeBin(const TProfile *hist, Int_t inbin, Int_t outbin) { MergeProfileBin<TProfile>(hist, inbin, outbin); }
129 void MergeBin(const TProfile2D *hist, Int_t inbin, Int_t outbin) { MergeProfileBin<TProfile2D>(hist, inbin, outbin); }
130 void MergeBin(const TProfile3D *hist, Int_t inbin, Int_t outbin) { MergeProfileBin<TProfile3D>(hist, inbin, outbin); }
131
132 Bool_t fNoLabelMerge = kFALSE; // force merger to not use labels and do bin center by bin center
133 Bool_t fNoCheck = kFALSE; // skip check on duplicate labels
134 Bool_t fIsProfileMerge = kFALSE; // flag to indicate if is a merge of TProfiles
138 TH1 *fH0; //! histogram on which the list is merged
139 TH1 *fHClone; //! copy of fH0 - managed by this class
140 TList fInputList; // input histogram List
145};
void Class()
Definition: Class.C:29
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:45
unsigned int UInt_t
Definition: RtypesCore.h:46
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
Class to manage histogram axis.
Definition: TAxis.h:30
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:121
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
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()
Definition: TH1Merger.cxx:620
static Bool_t AxesHaveLimits(const TH1 *h)
Definition: TH1Merger.cxx:19
Bool_t AutoP2Merge()
Definition: TH1Merger.cxx:663
static Int_t CheckForDuplicateLabels(const TH1 *hist)
Check if histogram has duplicate labels Return an integer with bit set correponding on the axis that ...
Definition: TH1Merger.cxx:946
Bool_t AutoP2BuildAxes(TH1 *)
Determine final boundaries and number of bins for histograms created in power-of-2 autobin mode.
Definition: TH1Merger.cxx:77
TH1Merger(TH1 &h, TCollection &l, Option_t *opt="")
Definition: TH1Merger.h:63
static Int_t FindBinNumber(Int_t ibin, const TAxis &inAxis, TAxis &outAxis)
Definition: TH1Merger.h:44
Bool_t fIsProfileMerge
Definition: TH1Merger.h:134
Bool_t DifferentAxesMerge()
Merged histogram when axis can be different.
Definition: TH1Merger.cxx:833
Bool_t SameAxesMerge()
Definition: TH1Merger.cxx:787
TList fInputList
copy of fH0 - managed by this class
Definition: TH1Merger.h:140
Bool_t fNoLabelMerge
Definition: TH1Merger.h:132
void MergeBin(const TProfile *hist, Int_t inbin, Int_t outbin)
Definition: TH1Merger.h:128
static Int_t FindFixBinNumber(Int_t ibin, const TAxis &inAxis, const TAxis &outAxis)
Definition: TH1Merger.h:35
TH1 * fH0
Definition: TH1Merger.h:138
Bool_t fIsProfile3D
Definition: TH1Merger.h:137
TAxis fNewZAxis
Definition: TH1Merger.h:143
Bool_t fIsProfile1D
Definition: TH1Merger.h:135
void CopyBuffer(TH1 *hsrc, TH1 *hdes)
Definition: TH1Merger.cxx:586
void MergeBin(const TProfile3D *hist, Int_t inbin, Int_t outbin)
Definition: TH1Merger.h:130
Bool_t BufferMerge()
Definition: TH1Merger.cxx:761
static Bool_t IsBinEmpty(const TH1 *hist, Int_t bin)
helper function for merging
Definition: TH1Merger.cxx:1129
void MergeBin(const TProfile2D *hist, Int_t inbin, Int_t outbin)
Definition: TH1Merger.h:129
EMergerType ExamineHistograms()
Examine the list of histograms to find out which type of Merge we need to do Pass the input list cont...
Definition: TH1Merger.cxx:216
static Bool_t HasDuplicateLabels(const THashList *labels)
Find a duplicate labels in an axis label list.
Definition: TH1Merger.cxx:919
void MergeBin(const TH1 *hist, Int_t inbin, Int_t outbin)
Definition: TH1Merger.cxx:1136
Bool_t operator()()
Function performing the actual merge.
Definition: TH1Merger.cxx:27
Bool_t fIsProfile2D
Definition: TH1Merger.h:136
~TH1Merger()
Definition: TH1Merger.h:90
@ kAllNoLimits
Definition: TH1Merger.h:26
@ kNotCompatible
Definition: TH1Merger.h:24
@ kAutoP2NeedLimits
Definition: TH1Merger.h:30
@ kAllLabel
Definition: TH1Merger.h:28
@ kHasNewLimits
Definition: TH1Merger.h:27
@ kAutoP2HaveLimits
Definition: TH1Merger.h:29
@ 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 ...
Definition: TH1Merger.cxx:520
Bool_t fNoCheck
Definition: TH1Merger.h:133
TH1 * fHClone
histogram on which the list is merged
Definition: TH1Merger.h:139
UInt_t fNewAxisFlag
Definition: TH1Merger.h:144
Bool_t LabelMerge()
Merge histograms with labels.
Definition: TH1Merger.cxx:976
TAxis fNewXAxis
Definition: TH1Merger.h:141
void MergeProfileBin(const TProfileType *p, Int_t ibin, Int_t outbin)
Definition: TH1Merger.cxx:1158
TAxis fNewYAxis
Definition: TH1Merger.h:142
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
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:44
virtual void Clear(Option_t *option="")
Remove all objects from the list.
Definition: TList.cxx:402
Profile2D histograms are used to display the mean value of Z and its error for each cell in X,...
Definition: TProfile2D.h:27
Profile3D histograms are used to display the mean value of T and its RMS for each cell in X,...
Definition: TProfile3D.h:27
Profile Histogram.
Definition: TProfile.h:32
Basic string class.
Definition: TString.h:136
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1163
Bool_t IsNull() const
Definition: TString.h:407
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
auto * l
Definition: textangle.C:4