Logo ROOT   6.14/05
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 "TList.h"
16 
17 class TH1Merger {
18 
19 public:
20  enum EMergerType {
21  kNotCompatible = -1, // histogram arenot compatible and cannot be merged
22  kAllSameAxes = 0, // histogram have all some axes
23  kAllNoLimits = 1, // all histogram don't have limits (the buffer is used)
24  kHasNewLimits = 2, // all histogram don't have limits (the buffer is used)
25  kAllLabel = 3, // histogram have labels all axis
26  kAutoP2HaveLimits = 4, // P2 (power-of-2) algorithm: all histogram have limits
27  kAutoP2NeedLimits = 5 // P2 algorithm: some histogram still need projections
28  };
29 
30  static Bool_t AxesHaveLimits(const TH1 * h);
31 
32  static Int_t FindFixBinNumber(Int_t ibin, const TAxis & inAxis, const TAxis & outAxis) {
33  // should I ceck in case of underflow/overflow if underflow/overflow values of input axis
34  // outside output axis ?
35  if (ibin == 0 ) return 0; // return underflow
36  if (ibin == inAxis.GetNbins()+1 ) return outAxis.GetNbins()+1; // return overflow
37  return outAxis.FindFixBin(inAxis.GetBinCenter(ibin));
38  }
39 
40  // find bin number estending the axis
41  static Int_t FindBinNumber(Int_t ibin, const TAxis & inAxis, TAxis & outAxis) {
42  // should I ceck in case of underflow/overflow if underflow/overflow values of input axis
43  // outside output axis ?
44  if (ibin == 0 ) return 0; // return underflow
45  if (ibin == inAxis.GetNbins()+1 ) return outAxis.GetNbins()+1; // return overflow
46  return outAxis.FindBin(inAxis.GetBinCenter(ibin));
47  }
48 
49 
51  fH0(&h),
52  fHClone(nullptr),
53  fNewAxisFlag(0)
54  {
55  fInputList.AddAll(&l);
56  }
57 
59  // The list contains fHClone, so let's clear it first to avoid
60  // accessing deleted memory later [we 'could' have just removed
61  // fHClone from the list]
62  fInputList.Clear();
63  if (fHClone) delete fHClone;
64  }
65 
66  // function douing the actual merge
68 
69 private:
71 
73 
74  void DefineNewAxes();
75 
76  void CopyBuffer(TH1 *hsrc, TH1 *hdes);
77 
79 
81 
83 
85 
87 
89 
90 
91  TH1 * fH0; //! histogram on which the list is merged
92  TH1 * fHClone; //! copy of fH0 - managed by this class
93  TList fInputList; // input histogram List
98 };
TH1 * fHClone
histogram on which the list is merged
Definition: TH1Merger.h:92
static Bool_t AxesHaveLimits(const TH1 *h)
Definition: TH1Merger.cxx:19
void DefineNewAxes()
Function to define new histogram axis when merging It is call only in case of merging with different ...
Definition: TH1Merger.cxx:474
TAxis fNewYAxis
Definition: TH1Merger.h:95
Bool_t LabelMerge()
Merge histograms with labels.
Definition: TH1Merger.cxx:884
virtual void AddAll(const TCollection *col)
Add all objects from collection col to this collection.
static Int_t FindFixBinNumber(Int_t ibin, const TAxis &inAxis, const TAxis &outAxis)
Definition: TH1Merger.h:32
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TList fInputList
copy of fH0 - managed by this class
Definition: TH1Merger.h:93
~TH1Merger()
Definition: TH1Merger.h:58
Bool_t AutoP2BufferMerge()
Definition: TH1Merger.cxx:573
void CopyBuffer(TH1 *hsrc, TH1 *hdes)
Definition: TH1Merger.cxx:540
TH1Merger(TH1 &h, TCollection &l)
Definition: TH1Merger.h:50
TAxis fNewZAxis
Definition: TH1Merger.h:96
Bool_t operator()()
Function performing the actual merge.
Definition: TH1Merger.cxx:27
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:464
Bool_t DifferentAxesMerge()
Merged histogram when axis can be different.
Definition: TH1Merger.cxx:793
A doubly linked list.
Definition: TList.h:44
UInt_t fNewAxisFlag
Definition: TH1Merger.h:97
TAxis fNewXAxis
Definition: TH1Merger.h:94
Class to manage histogram axis.
Definition: TAxis.h:30
Bool_t AutoP2BuildAxes(TH1 *)
Determine final boundaries and number of bins for histograms created in power-of-2 autobin mode...
Definition: TH1Merger.cxx:77
Collection abstract base class.
Definition: TCollection.h:63
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t SameAxesMerge()
Definition: TH1Merger.cxx:740
#define h(i)
Definition: RSha256.hxx:106
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:279
Bool_t BufferMerge()
Definition: TH1Merger.cxx:714
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
The TH1 histogram class.
Definition: TH1.h:56
virtual void Clear(Option_t *option="")
Remove all objects from the list.
Definition: TList.cxx:399
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:405
static Int_t FindBinNumber(Int_t ibin, const TAxis &inAxis, TAxis &outAxis)
Definition: TH1Merger.h:41
auto * l
Definition: textangle.C:4
TH1 * fH0
Definition: TH1Merger.h:91
Int_t GetNbins() const
Definition: TAxis.h:121
Bool_t AutoP2Merge()
Definition: TH1Merger.cxx:616