27 if (
gDebug)
Info(
"Merge",
"Histogram Merge type is %d and new axis flag is %d",(
int) type,(
int)
fNewAxisFlag);
47 if (ret)
return kTRUE;
51 Error(
"TH1Merger",
"Unknown type of Merge for histogram %s",
fH0->
GetName());
98 Error(
"Merge",
"Cannot merge histogram - dimensions are different\n " 108 allHaveLimits = allHaveLimits && hasLimits;
109 allSameLimits &= allHaveLimits;
130 if (!initialLimitsFound) {
131 initialLimitsFound =
kTRUE;
158 Error(
"Merge",
"Cannot merge histograms - limits are inconsistent:\n " 159 "first: %s (%d, %f, %f), second: %s (%d, %f, %f)",
fH0->
GetName(),
173 Error(
"Merge",
"Cannot merge histograms - limits are inconsistent:\n " 174 "first: %s (%d, %f, %f), second: %s (%d, %f, %f)",
fH0->
GetName(),
184 Error(
"Merge",
"Cannot merge histograms - limits are inconsistent:\n " 185 "first: %s (%d, %f, %f), second: %s (%d, %f, %f)",
fH0->
GetName(),
192 allSameLimits = sameLimitsX && sameLimitsY && sameLimitsZ;
202 if (allHaveLabels && !histoIsEmpty) {
204 Bool_t haveOneLabel = (hlabels !=
nullptr);
206 if (foundLabelHist && allHaveLabels && !haveOneLabel) {
207 Warning(
"Merge",
"Not all histograms have labels. I will ignore labels," 208 " falling back to bin numbering mode.");
211 allHaveLabels &= (haveOneLabel);
213 if (haveOneLabel) foundLabelHist =
kTRUE;
215 if (foundLabelHist &&
gDebug)
216 Info(
"TH1Merger::ExamineHistogram",
"Histogram %s has labels",h->
GetName() );
225 Info(
"TH1Merger::ExamineHistogram",
"Histogram %s to be merged is empty and we are merging with %s that has labels. Force the axis to be extended",
fH0->
GetName(),h->
GetName());
233 Info(
"TH1Merger::ExamineHistogram",
"Histogram %s to be merged has label but axis cannot be extended - using bin numeric mode to merge. Call TH1::SetExtendAllAxes() if want to merge using label mode",
fH0->
GetName());
243 Int_t non_zero_bins = 0;
252 Warning(
"TH1Merger::ExamineHistograms",
"Histogram %s contains non-empty bins without labels - falling back to bin numbering mode",h->
GetName() );
259 Info(
"TH1Merger::ExamineHistogram",
"Examine histogram %s - labels %d - same limits %d - axis found %d",h->
GetName(),allHaveLabels,allSameLimits,initialLimitsFound );
261 }
while ( ( h = dynamic_cast<TH1*> ( next() ) ) !=
NULL );
263 if (!h && (*next) ) {
264 Error(
"Merge",
"Attempt to merge object of class: %s to a %s",
272 if (!initialLimitsFound) {
354 if (newLimitsX)
Info(
"DefineNewAxis",
"A new X axis has been defined Nbins=%d , [%f,%f]",
fH0->
fXaxis.
GetNbins(),
356 if (newLimitsY)
Info(
"DefineNewAxis",
"A new Y axis has been defined Nbins=%d , [%f,%f]",
fH0->
fYaxis.
GetNbins(),
358 if (newLimitsZ)
Info(
"DefineNewAxis",
"A new Z axis has been defined Nbins=%d , [%f,%f]",
fH0->
fZaxis.
GetNbins(),
369 while (
TH1* hist = (
TH1*)next()) {
374 Info(
"TH1Merger::BufferMerge",
"Merging histogram %s into %s",hist->GetName(),
fH0->
GetName() );
382 for (
Int_t i = 0; i < nbentries; i++)
383 fH0->
Fill(hist->fBuffer[2*i + 2], hist->fBuffer[2*i + 1]);
386 auto h2 =
dynamic_cast<TH2*
>(
fH0);
388 for (
Int_t i = 0; i < nbentries; i++)
389 h2->Fill(hist->fBuffer[3*i + 2], hist->fBuffer[3*i + 3],hist->fBuffer[3*i + 1] );
392 auto h3 =
dynamic_cast<TH3*
>(
fH0);
394 for (
Int_t i = 0; i < nbentries; i++)
395 h3->Fill(hist->fBuffer[4*i + 2], hist->fBuffer[4*i + 3],hist->fBuffer[4*i + 4], hist->fBuffer[4*i + 1] );
417 totstats[i] = stats[i] = 0;
423 while (
TH1* hist=(
TH1*)next()) {
428 Info(
"TH1Merger::SameAxesMerge",
"Merging histogram %s into %s",hist->GetName(),
fH0->
GetName() );
431 if (hist->IsEmpty())
continue;
434 hist->GetStats(stats);
436 totstats[i] += stats[i];
437 nentries += hist->GetEntries();
441 for (
Int_t ibin = 0; ibin < hist->fNcells; ibin++) {
443 Double_t cu = hist->RetrieveBinContent(ibin);
445 if (
fH0->
fSumw2.
fN) e1sq= hist->GetBinErrorSqUnchecked(ibin);
473 while (
TH1* hist=(
TH1*)next()) {
476 Info(
"TH1Merger::DifferentAxesMerge",
"Merging histogram %s into %s",hist->GetName(),
fH0->
GetName() );
479 if (hist->IsEmpty())
continue;
482 hist->GetStats(stats);
484 totstats[i] += stats[i];
485 nentries += hist->GetEntries();
488 for (
Int_t ibin = 0; ibin < hist->fNcells; ibin++) {
490 Double_t cu = hist->RetrieveBinContent(ibin);
492 if (
fH0->
fSumw2.
fN) e1sq= hist->GetBinErrorSqUnchecked(ibin);
495 if (cu == 0 && e1sq == 0)
continue;
497 Int_t binx,biny,binz;
498 hist->GetBinXYZ(ibin, binx, biny, binz);
501 if (binx <= 0 || binx >= hist->GetNbinsX() + 1) {
503 Error(
"TH1Merger::DifferentAxesMerge",
"Cannot merge histograms - the histograms %s can extend the X axis or have" 504 " different limits and underflows/overflows are present in the histogram %s.",
fH0->
GetName(),hist->GetName());
508 if (biny <= 0 || biny >= hist->GetNbinsY() + 1) {
510 Error(
"TH1Merger::DifferentAxesMerge",
"Cannot merge histograms - the histograms %s can extend the Y axis or have" 511 " different limits and underflows/overflows are present in the histogram %s.",
fH0->
GetName(),hist->GetName());
515 if (binz <= 0 || binz >= hist->GetNbinsZ() + 1) {
517 Error(
"TH1Merger::DifferentAxesMerge",
"Cannot merge histograms - the histograms %s can extend the Z axis or have" 518 " different limits and underflows/overflows are present in the histogram %s.",
fH0->
GetName(),hist->GetName());
537 Fatal(
"TH1Merger::LabelMerge",
"Fatal error merging histogram %s - bin number is %d and array size is %d",
565 while (
TH1* hist=(
TH1*)next()) {
568 Info(
"TH1Merger::LabelMerge",
"Merging histogram %s into %s",hist->GetName(),
fH0->
GetName() );
571 if (hist->IsEmpty())
continue;
574 hist->GetStats(stats);
576 totstats[i] += stats[i];
577 nentries += hist->GetEntries();
579 auto labelsX = hist->GetXaxis()->GetLabels();
580 auto labelsY = hist->GetYaxis()->GetLabels();
581 auto labelsZ = hist->GetZaxis()->GetLabels();
582 R__ASSERT(!( labelsX ==
nullptr && labelsY ==
nullptr && labelsZ ==
nullptr));
585 for (
Int_t ibin = 0; ibin < hist->fNcells; ibin++) {
587 Double_t cu = hist->RetrieveBinContent(ibin);
589 if (
fH0->
fSumw2.
fN) e1sq= hist->GetBinErrorSqUnchecked(ibin);
592 if (cu == 0 && e1sq == 0)
continue;
594 Int_t binx,biny,binz;
595 hist->GetBinXYZ(ibin, binx, biny, binz);
598 const char * labelX = 0;
599 const char * labelY = 0;
600 const char * labelZ = 0;
601 labelX=hist->GetXaxis()->GetBinLabel(binx);
602 if (
fH0->
fDimension > 1) labelY = hist->GetYaxis()->GetBinLabel(biny);
603 if (
fH0->
fDimension > 2) labelZ = hist->GetYaxis()->GetBinLabel(binz);
613 if (binx == 0 &&
TString(labelX) ==
"" ) ix = 0;
616 if (biny == 0 &&
TString(labelY) ==
"" ) iy = 0;
620 if (binz == 0 &&
TString(labelZ) ==
"" ) iz = 0;
648 Info(
"TH1Merge::LabelMerge",
"Merge bin [%d,%d,%d] with label [%s,%s,%s] into bin [%d,%d,%d]",
649 binx,biny,binz,labelX,labelY,labelZ,ix,iy,iz);
653 Fatal(
"TH1Merger::LabelMerge",
"Fatal error merging histogram %s - bin number is %d and array size is %d",
virtual const char * GetName() const
Returns name of object.
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
TH1 * fHClone
histogram on which the list is merged
static Bool_t AxesHaveLimits(const TH1 *h)
void DefineNewAxes()
Function to define new histogram axis when merging It is call only in case of merging with different ...
void Fatal(const char *location, const char *msgfmt,...)
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
TAxis fYaxis
Y axis descriptor.
virtual void PutStats(Double_t *stats)
Replace current statistics with the values in array stats.
const Double_t * GetArray() const
Bool_t TestBit(UInt_t f) const
static Bool_t SameLimitsAndNBins(const TAxis &axis1, const TAxis &axis2)
Same limits and bins.
virtual Int_t GetEntries() const
Bool_t LabelMerge()
Merge histograms with labels.
virtual void AddFirst(TObject *obj)
Add object at the beginning of the list.
static Int_t FindFixBinNumber(Int_t ibin, const TAxis &inAxis, const TAxis &outAxis)
TList fInputList
copy of fH0 - managed by this class
TArrayD fSumw2
Array of sum of squares of weights.
static Bool_t RecomputeAxisLimits(TAxis &destAxis, const TAxis &anAxis)
Finds new limits for the axis for the Merge function.
TAxis fZaxis
Z axis descriptor.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual void GetStats(Double_t *stats) const
fill the array stats from the contents of this histogram The array stats must be correctly dimensione...
virtual Bool_t CanExtendAllAxes() const
Returns true if all axes are extendable.
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
virtual Int_t GetDimension() const
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Bool_t operator()()
Function performing the actual merge.
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
THashList * GetLabels() const
void Info(const char *location, const char *msgfmt,...)
virtual void AddBinContent(Int_t bin)
Increment bin content by 1.
void Error(const char *location, const char *msgfmt,...)
The 3-D histogram classes derived from the 1-D histogram classes.
Bool_t DifferentAxesMerge()
Merged histogram when axis can be different.
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis from bin first to last.
Service class for 2-Dim histogram classes.
virtual TObject * Remove(TObject *obj)
Remove object from the list.
virtual void Copy(TObject &hnew) const
Copy this histogram structure to newth1.
void Warning(const char *location, const char *msgfmt,...)
virtual Int_t GetBin(Int_t binx, Int_t biny=0, Int_t binz=0) const
Return Global bin number corresponding to binx,y,z.
virtual Double_t RetrieveBinContent(Int_t bin) const
Raw retrieval of bin content on internal data structure see convention for numbering bins in TH1::Get...
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Bool_t CanBeAlphanumeric()
EMergerType ExamineHistograms()
Examine the list of histograms to find out which type of Merge we need to do Pass the input list cont...
virtual Double_t GetEntries() const
Return the current number of entries.
virtual UInt_t SetCanExtend(UInt_t extendBitMask)
Make the histogram axes extendable / not extendable according to the bit mask returns the previous bi...
virtual void SetBinsLength(Int_t=-1)
Int_t fDimension
!Histogram dimension (1, 2 or 3 dim)
virtual Int_t BufferEmpty(Int_t action=0)
Fill histogram with all entries in the buffer.
virtual void SetEntries(Double_t n)
TAxis fXaxis
X axis descriptor.
virtual Int_t GetSize() const
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Double_t * fBuffer
[fBufferSize] entry buffer
void Set(Int_t n)
Set size of this array to n doubles.
const TArrayD * GetXbins() const
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Int_t fNcells
number of bins(1D), cells (2D) +U/Overflows