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 
20 class TH1Merger {
21 
22 public:
23  enum EMergerType {
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),
66  fNewAxisFlag(0)
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]
94  fInputList.Clear();
95  if (fHClone) delete fHClone;
96  }
97 
98  // function doing the actual merge
100 
101 private:
103 
105 
106  void DefineNewAxes();
107 
108  void CopyBuffer(TH1 *hsrc, TH1 *hdes);
109 
111 
113 
115 
117 
119 
120  Bool_t LabelMerge();
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 };
l
auto * l
Definition: textangle.C:4
TH1Merger::kAutoP2HaveLimits
@ kAutoP2HaveLimits
Definition: TH1Merger.h:29
TAxis
Class to manage histogram axis.
Definition: TAxis.h:30
TH1Merger::IsBinEmpty
static Bool_t IsBinEmpty(const TH1 *hist, Int_t bin)
helper function for merging
Definition: TH1Merger.cxx:1128
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TH1Merger::AutoP2Merge
Bool_t AutoP2Merge()
Definition: TH1Merger.cxx:662
TH1Merger::MergeProfileBin
void MergeProfileBin(const TProfileType *p, Int_t ibin, Int_t outbin)
Definition: TH1Merger.cxx:1157
TH1Merger::AutoP2BuildAxes
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::FindFixBinNumber
static Int_t FindFixBinNumber(Int_t ibin, const TAxis &inAxis, const TAxis &outAxis)
Definition: TH1Merger.h:35
Option_t
const char Option_t
Definition: RtypesCore.h:66
TH1Merger::fNoCheck
Bool_t fNoCheck
Definition: TH1Merger.h:133
TH1Merger::kAutoP2NeedLimits
@ kAutoP2NeedLimits
Definition: TH1Merger.h:30
TH1Merger::HasDuplicateLabels
static Bool_t HasDuplicateLabels(const THashList *labels)
Find a duplicate labels in an axis label list.
Definition: TH1Merger.cxx:918
TH1Merger::MergeBin
void MergeBin(const TH1 *hist, Int_t inbin, Int_t outbin)
Definition: TH1Merger.cxx:1135
TH1Merger::BufferMerge
Bool_t BufferMerge()
Definition: TH1Merger.cxx:760
TProfile2D
Profile2D histograms are used to display the mean value of Z and its error for each cell in X,...
Definition: TProfile2D.h:27
TH1Merger::kHasNewLimits
@ kHasNewLimits
Definition: TH1Merger.h:27
TH1Merger::kAllLabel
@ kAllLabel
Definition: TH1Merger.h:28
Int_t
int Int_t
Definition: RtypesCore.h:45
TAxis::GetBinCenter
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:478
TString::Contains
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
TList.h
TH1Merger::LabelMerge
Bool_t LabelMerge()
Merge histograms with labels.
Definition: TH1Merger.cxx:975
TH1Merger::fInputList
TList fInputList
copy of fH0 - managed by this class
Definition: TH1Merger.h:140
TProfile.h
TString
Basic string class.
Definition: TString.h:136
TH1Merger::FindBinNumber
static Int_t FindBinNumber(Int_t ibin, const TAxis &inAxis, TAxis &outAxis)
Definition: TH1Merger.h:44
TCollection::AddAll
virtual void AddAll(const TCollection *col)
Add all objects from collection col to this collection.
Definition: TCollection.cxx:195
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TH1Merger::MergeBin
void MergeBin(const TProfile *hist, Int_t inbin, Int_t outbin)
Definition: TH1Merger.h:128
bool
TH1Merger
Definition: TH1Merger.h:20
TProfile2D.h
TH1Merger::CopyBuffer
void CopyBuffer(TH1 *hsrc, TH1 *hdes)
Definition: TH1Merger.cxx:586
TH1Merger::DefineNewAxes
void DefineNewAxes()
Function to define new histogram axis when merging It is call only in case of merging with different ...
Definition: TH1Merger.cxx:520
TString::ToUpper
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1138
TH1Merger::fH0
TH1 * fH0
Definition: TH1Merger.h:138
TH1Merger::fNewXAxis
TAxis fNewXAxis
Definition: TH1Merger.h:141
TH1Merger::fNewYAxis
TAxis fNewYAxis
Definition: TH1Merger.h:142
TH1Merger::kAllNoLimits
@ kAllNoLimits
Definition: TH1Merger.h:26
THashList
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:34
h
#define h(i)
Definition: RSha256.hxx:106
TH1Merger::CheckForDuplicateLabels
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:945
TH1Merger::DifferentAxesMerge
Bool_t DifferentAxesMerge()
Merged histogram when axis can be different.
Definition: TH1Merger.cxx:832
TH1Merger::fIsProfile3D
Bool_t fIsProfile3D
Definition: TH1Merger.h:137
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TH1Merger::~TH1Merger
~TH1Merger()
Definition: TH1Merger.h:90
TH1Merger::fNewAxisFlag
UInt_t fNewAxisFlag
Definition: TH1Merger.h:144
TH1Merger::fNewZAxis
TAxis fNewZAxis
Definition: TH1Merger.h:143
TH1Merger::MergeBin
void MergeBin(const TProfile2D *hist, Int_t inbin, Int_t outbin)
Definition: TH1Merger.h:129
TH1Merger::ExamineHistograms
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
TProfile3D
Profile3D histograms are used to display the mean value of T and its RMS for each cell in X,...
Definition: TProfile3D.h:27
TH1Merger::kNotCompatible
@ kNotCompatible
Definition: TH1Merger.h:24
TH1Merger::fIsProfileMerge
Bool_t fIsProfileMerge
Definition: TH1Merger.h:134
unsigned int
TH1Merger::SameAxesMerge
Bool_t SameAxesMerge()
Definition: TH1Merger.cxx:786
TProfile
Profile Histogram.
Definition: TProfile.h:32
TH1Merger::fIsProfile1D
Bool_t fIsProfile1D
Definition: TH1Merger.h:135
TString::IsNull
Bool_t IsNull() const
Definition: TString.h:407
TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
TH1Merger::AutoP2BufferMerge
Bool_t AutoP2BufferMerge()
Definition: TH1Merger.cxx:619
TH1
TH1 is the base class of all histogramm classes in ROOT.
Definition: TH1.h:58
TProfile3D.h
TList::Clear
virtual void Clear(Option_t *option="")
Remove all objects from the list.
Definition: TList.cxx:402
TH1Merger::EMergerType
EMergerType
Definition: TH1Merger.h:23
TAxis::FindBin
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:293
TAxis::FindFixBin
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:419
TH1Merger::operator()
Bool_t operator()()
Function performing the actual merge.
Definition: TH1Merger.cxx:27
TCollection
Collection abstract base class.
Definition: TCollection.h:63
Class
void Class()
Definition: Class.C:29
TH1Merger::fHClone
TH1 * fHClone
histogram on which the list is merged
Definition: TH1Merger.h:139
TH1Merger::fIsProfile2D
Bool_t fIsProfile2D
Definition: TH1Merger.h:136
TH1.h
TH1Merger::kAllSameAxes
@ kAllSameAxes
Definition: TH1Merger.h:25
TH1Merger::TH1Merger
TH1Merger(TH1 &h, TCollection &l, Option_t *opt="")
Definition: TH1Merger.h:63
TAxis::GetNbins
Int_t GetNbins() const
Definition: TAxis.h:121
TH1Merger::MergeBin
void MergeBin(const TProfile3D *hist, Int_t inbin, Int_t outbin)
Definition: TH1Merger.h:130
TH1Merger::AxesHaveLimits
static Bool_t AxesHaveLimits(const TH1 *h)
Definition: TH1Merger.cxx:19
TList
A doubly linked list.
Definition: TList.h:44
int
TH1Merger::fNoLabelMerge
Bool_t fNoLabelMerge
Definition: TH1Merger.h:132