Logo ROOT   6.10/09
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 
21  enum EMergerType {
22  kNotCompatible = -1, // histogram arenot compatible and cannot be merged
23  kAllSameAxes = 0, // histogram have all some axes
24  kAllNoLimits = 1, // all histogram don't have limits (the buffer is used)
25  kHasNewLimits = 2, // all histogram don't have limits (the buffer is used)
26  kAllLabel = 3 // histogram have labels all axis
27  };
28 
29  static Bool_t AxesHaveLimits(const TH1 * h);
30 
31  static Int_t FindFixBinNumber(Int_t ibin, const TAxis & inAxis, const TAxis & outAxis) {
32  // should I ceck in case of underflow/overflow if underflow/overflow values of input axis
33  // outside output axis ?
34  if (ibin == 0 ) return 0; // return underflow
35  if (ibin == inAxis.GetNbins()+1 ) return outAxis.GetNbins()+1; // return overflow
36  return outAxis.FindFixBin(inAxis.GetBinCenter(ibin));
37  }
38 
39  // find bin number estending the axis
40  static Int_t FindBinNumber(Int_t ibin, const TAxis & inAxis, TAxis & outAxis) {
41  // should I ceck in case of underflow/overflow if underflow/overflow values of input axis
42  // outside output axis ?
43  if (ibin == 0 ) return 0; // return underflow
44  if (ibin == inAxis.GetNbins()+1 ) return outAxis.GetNbins()+1; // return overflow
45  return outAxis.FindBin(inAxis.GetBinCenter(ibin));
46  }
47 
48 
50  fH0(&h),
51  fHClone(nullptr),
52  fNewAxisFlag(0)
53  {
54  fInputList.AddAll(&l);
55  }
56 
58  // The list contains fHClone, so let's clear it first to avoid
59  // accessing deleted memory later [we 'could' have just removed
60  // fHClone from the list]
61  fInputList.Clear();
62  if (fHClone) delete fHClone;
63  }
64 
65  // function douing the actual merge
67 
68 private:
69 
71 
72  void DefineNewAxes();
73 
75 
77 
79 
81 
82 
83  TH1 * fH0; //! histogram on which the list is merged
84  TH1 * fHClone; //! copy of fH0 - managed by this class
85  TList fInputList; // input histogram List
90 };
TH1 * fHClone
histogram on which the list is merged
Definition: TH1Merger.h:84
static Bool_t AxesHaveLimits(const TH1 *h)
Definition: TH1Merger.cxx:14
void DefineNewAxes()
Function to define new histogram axis when merging It is call only in case of merging with different ...
Definition: TH1Merger.cxx:300
TAxis fNewYAxis
Definition: TH1Merger.h:87
TH1 * h
Definition: legend2.C:5
Bool_t LabelMerge()
Merge histograms with labels.
Definition: TH1Merger.cxx:556
virtual void AddAll(const TCollection *col)
Add all objects from collection col to this collection.
Definition: TCollection.cxx:58
static Int_t FindFixBinNumber(Int_t ibin, const TAxis &inAxis, const TAxis &outAxis)
Definition: TH1Merger.h:31
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:85
~TH1Merger()
Definition: TH1Merger.h:57
TH1Merger(TH1 &h, TCollection &l)
Definition: TH1Merger.h:49
TAxis fNewZAxis
Definition: TH1Merger.h:88
Bool_t operator()()
Function performing the actual merge.
Definition: TH1Merger.cxx:22
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:465
A doubly linked list.
Definition: TList.h:43
UInt_t fNewAxisFlag
Definition: TH1Merger.h:89
TAxis fNewXAxis
Definition: TH1Merger.h:86
Class to manage histogram axis.
Definition: TAxis.h:30
Collection abstract base class.
Definition: TCollection.h:42
unsigned int UInt_t
Definition: RtypesCore.h:42
TLine * l
Definition: textangle.C:4
Bool_t SameAxesMerge()
Definition: TH1Merger.cxx:412
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:279
Bool_t BufferMerge()
Definition: TH1Merger.cxx:366
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:69
The TH1 histogram class.
Definition: TH1.h:56
virtual void Clear(Option_t *option="")
Remove all objects from the list.
Definition: TList.cxx:353
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:40
TH1 * fH0
Definition: TH1Merger.h:83
Int_t GetNbins() const
Definition: TAxis.h:121