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) {
203 if (histoIsEmpty)
continue;
205 Bool_t haveOneLabel = (hlabels !=
nullptr);
207 if (foundLabelHist && allHaveLabels && !haveOneLabel) {
208 Warning(
"Merge",
"Not all histograms have labels. I will ignore labels," 209 " falling back to bin numbering mode.");
212 allHaveLabels &= (haveOneLabel);
214 if (haveOneLabel) foundLabelHist =
kTRUE;
216 if (foundLabelHist &&
gDebug)
217 Info(
"TH1Merger::ExamineHistogram",
"Histogram %s has labels",h->
GetName() );
226 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());
234 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());
244 Int_t non_zero_bins = 0;
253 Warning(
"TH1Merger::ExamineHistograms",
"Histogram %s contains non-empty bins without labels - falling back to bin numbering mode",h->
GetName() );
260 Info(
"TH1Merger::ExamineHistogram",
"Examine histogram %s - labels %d - same limits %d - axis found %d",h->
GetName(),allHaveLabels,allSameLimits,initialLimitsFound );
262 }
while ( ( h = dynamic_cast<TH1*> ( next() ) ) !=
NULL );
264 if (!h && (*next) ) {
265 Error(
"Merge",
"Attempt to merge object of class: %s to a %s",
273 if (!initialLimitsFound) {
355 if (newLimitsX)
Info(
"DefineNewAxis",
"A new X axis has been defined Nbins=%d , [%f,%f]",
fH0->
fXaxis.
GetNbins(),
357 if (newLimitsY)
Info(
"DefineNewAxis",
"A new Y axis has been defined Nbins=%d , [%f,%f]",
fH0->
fYaxis.
GetNbins(),
359 if (newLimitsZ)
Info(
"DefineNewAxis",
"A new Z axis has been defined Nbins=%d , [%f,%f]",
fH0->
fZaxis.
GetNbins(),
370 while (
TH1* hist = (
TH1*)next()) {
375 Info(
"TH1Merger::BufferMerge",
"Merging histogram %s into %s",hist->GetName(),
fH0->
GetName() );
383 for (
Int_t i = 0; i < nbentries; i++)
384 fH0->
Fill(hist->fBuffer[2*i + 2], hist->fBuffer[2*i + 1]);
387 auto h2 =
dynamic_cast<TH2*
>(
fH0);
389 for (
Int_t i = 0; i < nbentries; i++)
390 h2->Fill(hist->fBuffer[3*i + 2], hist->fBuffer[3*i + 3],hist->fBuffer[3*i + 1] );
393 auto h3 =
dynamic_cast<TH3*
>(
fH0);
395 for (
Int_t i = 0; i < nbentries; i++)
396 h3->Fill(hist->fBuffer[4*i + 2], hist->fBuffer[4*i + 3],hist->fBuffer[4*i + 4], hist->fBuffer[4*i + 1] );
418 totstats[i] = stats[i] = 0;
424 while (
TH1* hist=(
TH1*)next()) {
429 Info(
"TH1Merger::SameAxesMerge",
"Merging histogram %s into %s",hist->GetName(),
fH0->
GetName() );
432 if (hist->IsEmpty())
continue;
435 hist->GetStats(stats);
437 totstats[i] += stats[i];
438 nentries += hist->GetEntries();
442 for (
Int_t ibin = 0; ibin < hist->fNcells; ibin++) {
444 Double_t cu = hist->RetrieveBinContent(ibin);
446 if (
fH0->
fSumw2.
fN) e1sq= hist->GetBinErrorSqUnchecked(ibin);
474 while (
TH1* hist=(
TH1*)next()) {
477 Info(
"TH1Merger::DifferentAxesMerge",
"Merging histogram %s into %s",hist->GetName(),
fH0->
GetName() );
480 if (hist->IsEmpty())
continue;
483 hist->GetStats(stats);
485 totstats[i] += stats[i];
486 nentries += hist->GetEntries();
489 for (
Int_t ibin = 0; ibin < hist->fNcells; ibin++) {
491 Double_t cu = hist->RetrieveBinContent(ibin);
493 if (
fH0->
fSumw2.
fN) e1sq= hist->GetBinErrorSqUnchecked(ibin);
496 if (cu == 0 && e1sq == 0)
continue;
498 Int_t binx,biny,binz;
499 hist->GetBinXYZ(ibin, binx, biny, binz);
502 if (binx <= 0 || binx >= hist->GetNbinsX() + 1) {
504 Error(
"TH1Merger::DifferentAxesMerge",
"Cannot merge histograms - the histograms %s can extend the X axis or have" 505 " different limits and underflows/overflows are present in the histogram %s.",
fH0->
GetName(),hist->GetName());
509 if (biny <= 0 || biny >= hist->GetNbinsY() + 1) {
511 Error(
"TH1Merger::DifferentAxesMerge",
"Cannot merge histograms - the histograms %s can extend the Y axis or have" 512 " different limits and underflows/overflows are present in the histogram %s.",
fH0->
GetName(),hist->GetName());
516 if (binz <= 0 || binz >= hist->GetNbinsZ() + 1) {
518 Error(
"TH1Merger::DifferentAxesMerge",
"Cannot merge histograms - the histograms %s can extend the Z axis or have" 519 " different limits and underflows/overflows are present in the histogram %s.",
fH0->
GetName(),hist->GetName());
538 Fatal(
"TH1Merger::LabelMerge",
"Fatal error merging histogram %s - bin number is %d and array size is %d",
566 while (
TH1* hist=(
TH1*)next()) {
569 Info(
"TH1Merger::LabelMerge",
"Merging histogram %s into %s",hist->GetName(),
fH0->
GetName() );
572 if (hist->IsEmpty())
continue;
575 hist->GetStats(stats);
577 totstats[i] += stats[i];
578 nentries += hist->GetEntries();
580 auto labelsX = hist->GetXaxis()->GetLabels();
581 auto labelsY = hist->GetYaxis()->GetLabels();
582 auto labelsZ = hist->GetZaxis()->GetLabels();
583 R__ASSERT(!( labelsX ==
nullptr && labelsY ==
nullptr && labelsZ ==
nullptr));
586 for (
Int_t ibin = 0; ibin < hist->fNcells; ibin++) {
588 Double_t cu = hist->RetrieveBinContent(ibin);
590 if (
fH0->
fSumw2.
fN) e1sq= hist->GetBinErrorSqUnchecked(ibin);
593 if (cu == 0 && e1sq == 0)
continue;
595 Int_t binx,biny,binz;
596 hist->GetBinXYZ(ibin, binx, biny, binz);
599 const char * labelX = 0;
600 const char * labelY = 0;
601 const char * labelZ = 0;
602 labelX=hist->GetXaxis()->GetBinLabel(binx);
603 if (
fH0->
fDimension > 1) labelY = hist->GetYaxis()->GetBinLabel(biny);
604 if (
fH0->
fDimension > 2) labelZ = hist->GetYaxis()->GetBinLabel(binz);
614 if (binx == 0 &&
TString(labelX) ==
"" ) ix = 0;
617 if (biny == 0 &&
TString(labelY) ==
"" ) iy = 0;
621 if (binz == 0 &&
TString(labelZ) ==
"" ) iz = 0;
649 Info(
"TH1Merge::LabelMerge",
"Merge bin [%d,%d,%d] with label [%s,%s,%s] into bin [%d,%d,%d]",
650 binx,biny,binz,labelX,labelY,labelZ,ix,iy,iz);
654 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
if(line.BeginsWith("/*"))
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