Logo ROOT   6.16/01
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
17class TH1Merger {
18
19public:
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 // Function to find if axis label list has duplicates
50 static Bool_t HasDuplicateLabels(const THashList * labels);
51
52 // check if histogram has duplicate labels
53 static Int_t CheckForDuplicateLabels(const TH1 * hist);
54
55
56 TH1Merger(TH1 & h, TCollection & l, Option_t * opt = "") :
57 fH0(&h),
58 fHClone(nullptr),
60 {
62 TString option(opt);
63 if (!option.IsNull() ) {
64 option.ToUpper();
65 if (option.Contains("NOL") )
66 fNoLabelMerge = true;
67 if (option.Contains("NOCHECK") )
68 fNoCheck = true;
69 }
70 }
71
73 // The list contains fHClone, so let's clear it first to avoid
74 // accessing deleted memory later [we 'could' have just removed
75 // fHClone from the list]
77 if (fHClone) delete fHClone;
78 }
79
80 // function douing the actual merge
82
83private:
85
87
88 void DefineNewAxes();
89
90 void CopyBuffer(TH1 *hsrc, TH1 *hdes);
91
93
95
97
99
101
103
104
105 Bool_t fNoLabelMerge = kFALSE; // force merger to not use labels and do bin center by bin center
106 Bool_t fNoCheck = kFALSE; // skip check on duplicate labels
107 TH1 * fH0; //! histogram on which the list is merged
108 TH1 * fHClone; //! copy of fH0 - managed by this class
109 TList fInputList; // input histogram List
114};
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const char Option_t
Definition: RtypesCore.h:62
Class to manage histogram axis.
Definition: TAxis.h:30
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:464
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:279
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:405
Int_t GetNbins() const
Definition: TAxis.h:121
Collection abstract base class.
Definition: TCollection.h:63
virtual void AddAll(const TCollection *col)
Add all objects from collection col to this collection.
Bool_t AutoP2BufferMerge()
Definition: TH1Merger.cxx:577
static Bool_t AxesHaveLimits(const TH1 *h)
Definition: TH1Merger.cxx:19
Bool_t AutoP2Merge()
Definition: TH1Merger.cxx:620
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:914
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:56
static Int_t FindBinNumber(Int_t ibin, const TAxis &inAxis, TAxis &outAxis)
Definition: TH1Merger.h:41
Bool_t DifferentAxesMerge()
Merged histogram when axis can be different.
Definition: TH1Merger.cxx:797
Bool_t SameAxesMerge()
Definition: TH1Merger.cxx:744
TList fInputList
copy of fH0 - managed by this class
Definition: TH1Merger.h:109
Bool_t fNoLabelMerge
Definition: TH1Merger.h:105
static Int_t FindFixBinNumber(Int_t ibin, const TAxis &inAxis, const TAxis &outAxis)
Definition: TH1Merger.h:32
TH1 * fH0
Definition: TH1Merger.h:107
TAxis fNewZAxis
Definition: TH1Merger.h:112
void CopyBuffer(TH1 *hsrc, TH1 *hdes)
Definition: TH1Merger.cxx:544
Bool_t BufferMerge()
Definition: TH1Merger.cxx:718
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:887
Bool_t operator()()
Function performing the actual merge.
Definition: TH1Merger.cxx:27
~TH1Merger()
Definition: TH1Merger.h:72
@ kAllNoLimits
Definition: TH1Merger.h:23
@ kNotCompatible
Definition: TH1Merger.h:21
@ kAutoP2NeedLimits
Definition: TH1Merger.h:27
@ kAllLabel
Definition: TH1Merger.h:25
@ kHasNewLimits
Definition: TH1Merger.h:24
@ kAutoP2HaveLimits
Definition: TH1Merger.h:26
@ kAllSameAxes
Definition: TH1Merger.h:22
void DefineNewAxes()
Function to define new histogram axis when merging It is call only in case of merging with different ...
Definition: TH1Merger.cxx:478
Bool_t fNoCheck
Definition: TH1Merger.h:106
TH1 * fHClone
histogram on which the list is merged
Definition: TH1Merger.h:108
UInt_t fNewAxisFlag
Definition: TH1Merger.h:113
Bool_t LabelMerge()
Merge histograms with labels.
Definition: TH1Merger.cxx:944
TAxis fNewXAxis
Definition: TH1Merger.h:110
TAxis fNewYAxis
Definition: TH1Merger.h:111
The TH1 histogram class.
Definition: TH1.h:56
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:399
Basic string class.
Definition: TString.h:131
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1113
Bool_t IsNull() const
Definition: TString.h:402
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
auto * l
Definition: textangle.C:4