12#ifndef ROOT_TProfileHelper
13#define ROOT_TProfileHelper
79 if (
p->fBuffer)
p->BufferEmpty(1);
86 if ( nx != p1->GetNbinsX() || nx != p2->GetNbinsX() ||
87 ny != p1->GetNbinsY() || ny != p2->GetNbinsY() ||
88 nz != p1->GetNbinsZ() || nz != p2->GetNbinsZ() ) {
89 Error(
"TProfileHelper::Add",
"Attempt to add profiles with different number of bins");
96 p->fEntries = ac1*p1->GetEntries() + ac2*p2->GetEntries();
105 else s0[i] = ac1*
s1[i] + ac2*s2[i];
110 if (
p->fBinSumw2.fN == 0 && (p1->fBinSumw2.fN != 0 || p2->fBinSumw2.fN != 0))
p->Sumw2();
112 if (
p->fSumw2.fN == 0 && (
c1 != 1.0 ||
c2 != 1.0))
p->Sumw2();
120 if (ew1 ==
nullptr) ew1 = en1;
121 if (ew2 ==
nullptr) ew2 = en2;
122 for (
Int_t bin = 0; bin <
p->fN; bin++) {
123 p->fArray[bin] =
c1*cu1[bin] +
c2*cu2[bin];
124 p->fSumw2.fArray[bin] = ac1*er1[bin] + ac2*er2[bin];
125 p->fBinEntries.fArray[bin] = ac1*en1[bin] + ac2*en2[bin];
126 if (
p->fBinSumw2.fN )
p->fBinSumw2.fArray[bin] = ac1*ac1*ew1[bin] + ac2*ac2*ew2[bin];
138 p->fBinEntries.Set(
p->fNcells);
139 p->fSumw2.Set(
p->fNcells);
155 if (
p->fBuffer)
p->BufferEmpty();
157 if (bin < 0 || bin >=
p->fNcells)
return 0;
158 double sumOfWeights =
p->fBinEntries.fArray[bin];
159 if (
p->fBinSumw2.fN == 0 ||
p->fBinSumw2.fN !=
p->fNcells) {
164 double sumOfWeightsSquare =
p->fBinSumw2.fArray[bin];
165 return ( sumOfWeightsSquare > 0 ? sumOfWeights * sumOfWeights / sumOfWeightsSquare : 0 );
193 return (ret) ?
p->GetEntries() : -1;
195#ifdef OLD_PROFILE_MERGE
213 Bool_t hasLimits =
h->GetXaxis()->GetXmin() <
h->GetXaxis()->GetXmax();
214 allHaveLimits = allHaveLimits && hasLimits;
222 if (firstNonEmptyHist ) {
225 if (!
p->SameLimitsAndNBins(
p->fXaxis, *(
h->GetXaxis())) )
226 p->fXaxis.Set(
h->GetXaxis()->GetNbins(),
h->GetXaxis()->GetXmin(),
h->GetXaxis()->GetXmax());
227 if (!
p->SameLimitsAndNBins(
p->fYaxis, *(
h->GetYaxis())) )
228 p->fYaxis.Set(
h->GetYaxis()->GetNbins(),
h->GetYaxis()->GetXmin(),
h->GetYaxis()->GetXmax());
229 if (!
p->SameLimitsAndNBins(
p->fZaxis, *(
h->GetZaxis())) )
230 p->fZaxis.Set(
h->GetZaxis()->GetNbins(),
h->GetZaxis()->GetXmin(),
h->GetZaxis()->GetXmax());
232 firstNonEmptyHist =
kFALSE;
238 if (!initialLimitsFound) {
239 initialLimitsFound =
kTRUE;
240 newXAxis.
Set(
h->GetXaxis()->GetNbins(),
h->GetXaxis()->GetXmin(),
241 h->GetXaxis()->GetXmax());
242 if (
p->GetDimension() >= 2 )
243 newYAxis.
Set(
h->GetYaxis()->GetNbins(),
h->GetYaxis()->GetXmin(),
244 h->GetYaxis()->GetXmax());
245 if (
p->GetDimension() >= 3 )
246 newZAxis.
Set(
h->GetZaxis()->GetNbins(),
h->GetZaxis()->GetXmin(),
247 h->GetZaxis()->GetXmax());
251 if (!
p->SameLimitsAndNBins(newXAxis, *(
h->GetXaxis())) ||
252 !
p->SameLimitsAndNBins(newYAxis, *(
h->GetYaxis())) ||
253 !
p->SameLimitsAndNBins(newZAxis, *(
h->GetZaxis())) ) {
260 if (!
p->RecomputeAxisLimits(newXAxis, *(
h->GetXaxis()))) {
261 Error(
"TProfileHelper::Merge",
"Cannot merge profiles %d dim - limits are inconsistent:\n "
262 "first: (%d, %f, %f), second: (%d, %f, %f)",
p->GetDimension(),
264 h->GetXaxis()->GetNbins(),
h->GetXaxis()->GetXmin(),
265 h->GetXaxis()->GetXmax());
268 if (
p->GetDimension() >= 2 && !
p->RecomputeAxisLimits(newYAxis, *(
h->GetYaxis()))) {
269 Error(
"TProfileHelper::Merge",
"Cannot merge profiles %d dim - limits are inconsistent:\n "
270 "first: (%d, %f, %f), second: (%d, %f, %f)",
p->GetDimension(),
272 h->GetYaxis()->GetNbins(),
h->GetYaxis()->GetXmin(),
273 h->GetYaxis()->GetXmax());
276 if (
p->GetDimension() >= 3 && !
p->RecomputeAxisLimits(newZAxis, *(
h->GetZaxis()))) {
277 Error(
"TProfileHelper::Merge",
"Cannot merge profiles %d dim - limits are inconsistent:\n "
278 "first: (%d, %f, %f), second: (%d, %f, %f)",
p->GetDimension(),
280 h->GetZaxis()->GetNbins(),
h->GetZaxis()->GetXmin(),
281 h->GetZaxis()->GetXmax());
287 }
while ( (
h =
dynamic_cast<T*
> ( next() ) ) !=
nullptr );
288 if (!
h && (*next) ) {
289 Error(
"TProfileHelper::Merge",
"Attempt to merge object of class: %s to a %s",
301 if (!allSameLimits) {
308 hclone->SetDirectory(0);
317 if (!allSameLimits && initialLimitsFound) {
325 if (!allHaveLimits) {
327 while ( (
h =
dynamic_cast<T*
> (next()) ) ) {
328 if (
h->GetXaxis()->GetXmin() >=
h->GetXaxis()->GetXmax() &&
h->fBuffer) {
332 for (
Int_t i = 0; i < nbentries; i++)
333 if (
p->GetDimension() == 3 ) {
334 v[0] =
h->fBuffer[5*i + 2];
335 v[1] =
h->fBuffer[5*i + 3];
336 v[2] =
h->fBuffer[5*i + 4];
337 v[3] =
h->fBuffer[5*i + 5];
338 v[4] =
h->fBuffer[5*i + 1];
340 }
else if (
p->GetDimension() == 2 ) {
341 v[0] =
h->fBuffer[4*i + 2];
342 v[1] =
h->fBuffer[4*i + 3];
343 v[2] =
h->fBuffer[4*i + 4];
344 v[3] =
h->fBuffer[4*i + 1];
348 else if (
p->GetDimension() == 1 ) {
349 v[0] =
h->fBuffer[3*i + 2];
350 v[1] =
h->fBuffer[3*i + 3];
351 v[2] =
h->fBuffer[3*i + 1];
357 if (!initialLimitsFound) {
362 return (
Int_t)
p->GetEntries();
370 p->GetStats(totstats);
372 Bool_t canExtend =
p->CanExtendAllAxes();
375 while ( (
h=
static_cast<T*
>(next())) ) {
378 if (
h->GetXaxis()->GetXmin() <
h->GetXaxis()->GetXmax()) {
382 totstats[i] += stats[i];
385 for (
Int_t hbin = 0; hbin <
h->fN; ++hbin ) {
387 if (!allSameLimits) {
392 if (
h->GetW()[hbin] != 0 && (
h->IsBinUnderflow(hbin) ||
h->IsBinOverflow(hbin)) ) {
394 Error(
"TProfileHelper::Merge",
"Cannot merge profiles - they have"
395 " different limits and underflows/overflows are present."
396 " The initial profile is now broken!");
399 Int_t hbinx, hbiny, hbinz;
400 h->GetBinXYZ(hbin, hbinx, hbiny, hbinz);
402 pbin =
p->GetBin(
p->fXaxis.FindBin(
h->GetXaxis()->GetBinCenter(hbinx) ),
403 p->fYaxis.FindBin(
h->GetYaxis()->GetBinCenter(hbiny) ),
404 p->fZaxis.FindBin(
h->GetZaxis()->GetBinCenter(hbinz) ) );
408 p->fArray[pbin] +=
h->GetW()[hbin];
409 p->fSumw2.fArray[pbin] +=
h->GetW2()[hbin];
410 p->fBinEntries.fArray[pbin] +=
h->GetB()[hbin];
411 if (
p->fBinSumw2.fN) {
412 if (
h->GetB2() )
p->fBinSumw2.fArray[pbin] +=
h->GetB2()[hbin];
413 else p->fBinSumw2.fArray[pbin] +=
h->GetB()[hbin];
421 p->PutStats(totstats);
446 if (axis->
GetNbins() <= 0)
return 0;
452 if (!
p->FindNewAxisLimits(axis,
x,
xmin,
xmax))
458 hold->SetDirectory(0);
462 if (
p->fBinSumw2.fN) hold->Sumw2();
465 Int_t nx =
p->fXaxis.GetNbins() + 2;
466 Int_t ny = (
p->GetDimension() > 1) ?
p->fYaxis.GetNbins() + 2 : 1;
467 Int_t nz = (
p->GetDimension() > 2) ?
p->fZaxis.GetNbins() + 2 : 1;
470 if (axis ==
p->GetXaxis()) iaxis = 1;
471 if (axis ==
p->GetYaxis()) iaxis = 2;
472 if (axis ==
p->GetZaxis()) iaxis = 3;
480 Int_t ix, iy, iz, binx, biny, binz;
481 for (binz=0;binz< nz;binz++) {
482 zc = hold->GetZaxis()->GetBinCenter(binz);
483 iz =
p->fZaxis.FindFixBin(zc);
484 for (biny=0;biny<ny;biny++) {
485 yc = hold->GetYaxis()->GetBinCenter(biny);
486 iy =
p->fYaxis.FindFixBin(yc);
487 for (binx=0;binx<nx;binx++) {
488 xc = hold->GetXaxis()->GetBinCenter(binx);
489 ix =
p->fXaxis.FindFixBin(xc);
490 Int_t sourceBin = hold->GetBin(binx,biny,binz);
492 if (hold->fBinEntries.fArray[sourceBin] == 0)
continue;
493 if (hold->IsBinUnderflow(sourceBin, iaxis) || hold->IsBinOverflow(sourceBin, iaxis)) {
496 "Histogram %s has underflow or overflow in the %s that is extendable"
502 Int_t destinationBin =
p->GetBin(ix,iy,iz);
503 p->AddBinContent(destinationBin, hold->fArray[sourceBin]);
504 p->fBinEntries.fArray[destinationBin] += hold->fBinEntries.fArray[sourceBin];
505 p->fSumw2.fArray[destinationBin] += hold->fSumw2.fArray[sourceBin];
506 if (
p->fBinSumw2.fN)
p->fBinSumw2.fArray[destinationBin] += hold->fBinSumw2.fArray[sourceBin];
523 for (bin=0;bin<
p->fN;bin++) {
524 p->fArray[bin] =
c1*cu1[bin];
525 p->fSumw2.fArray[bin] = ac1*ac1*er1[bin];
526 p->fBinEntries.fArray[bin] = en1[bin];
543 if (
p->fBinSumw2.fN > 0 )
p->fBinSumw2.Set(0);
547 if (
p->fBinSumw2.fN ==
p->fNcells) {
548 if (!
p->fgDefaultSumw2)
549 Warning(
"Sumw2",
"Sum of squares of profile bin weights structure already created");
553 p->fBinSumw2.Set(
p->fNcells);
556 for (
Int_t bin=0; bin<
p->fNcells; bin++) {
557 p->fBinSumw2.fArray[bin] =
p->fBinEntries.fArray[bin];
570 TAxis *axis =
p->GetXaxis();
571 if (ax[0] ==
'y' || ax[0] ==
'Y') axis =
p->GetYaxis();
572 if (ax[0] ==
'z' || ax[0] ==
'Z') axis =
p->GetZaxis();
574 Error(
"TProfileHelper::LabelsDeflate",
"Invalid axis option %s",ax);
585 while ((obj = next())) {
587 if (ibin > nbins) nbins = ibin;
589 if (nbins < 1) nbins = 1;
592 if (nbins==axis->
GetNbins())
return;
595 hold->SetDirectory(0);
604 p->SetBinsLength(-1);
605 p->fBinEntries.Set(
p->fN);
606 p->fSumw2.Set(
p->fN);
607 if (
p->fBinSumw2.fN)
p->fBinSumw2.Set(
p->fN);
613 Int_t bin,binx,biny,binz;
614 for (bin =0; bin < hold->fN; ++bin)
616 hold->GetBinXYZ(bin, binx, biny, binz);
617 Int_t ibin =
p->GetBin(binx, biny, binz);
618 p->fArray[ibin] += hold->fArray[bin];
619 p->fBinEntries.fArray[ibin] += hold->fBinEntries.fArray[bin];
620 p->fSumw2.fArray[ibin] += hold->fSumw2.fArray[bin];
621 if (
p->fBinSumw2.fN)
p->fBinSumw2.fArray[ibin] += hold->fBinSumw2.fArray[bin];
635 if (
gDebug)
Info(
"LabelsInflate",
"Inflate label for axis %s of profile %s",ax,
p->
GetName());
637 Int_t iaxis =
p->AxisChoice(ax);
638 TAxis *axis =
nullptr;
639 if (iaxis == 1) axis =
p->GetXaxis();
640 if (iaxis == 2) axis =
p->GetYaxis();
641 if (iaxis == 3) axis =
p->GetZaxis();
647 hold->SetDirectory(0);
662 p->SetBinsLength(-1);
664 p->fBinEntries.Set(ncells);
665 p->fSumw2.Set(ncells);
666 if (
p->fBinSumw2.fN)
p->fBinSumw2.Set(ncells);
672 Int_t binx, biny, binz = 0;
673 for (
Int_t ibin =0; ibin < hold->fNcells; ibin++) {
675 hold->GetBinXYZ(ibin,binx,biny,binz);
676 Int_t bin =
p->GetBin(binx,biny,binz);
679 if (hold->IsBinUnderflow(ibin,iaxis) || hold->IsBinOverflow(ibin,iaxis)) {
680 if (
gDebug && hold->fBinEntries.fArray[ibin] > 0)
Info(
"LabelsInflate",
"Content for underflow/overflow of bin (%d,%d,%d) will be lost",binx,biny,binz);
684 p->fArray[bin] = hold->fArray[ibin];
685 p->fBinEntries.fArray[bin] = hold->fBinEntries.fArray[ibin];
686 p->fSumw2.fArray[bin] = hold->fSumw2.fArray[ibin];
687 if (
p->fBinSumw2.fN)
p->fBinSumw2.fArray[bin] = hold->fBinSumw2.fArray[ibin];
688 if (
gDebug)
Info(
"LabelsInflate",
"Copy Content from bin (%d,%d,%d) from %d in %d (%f,%f)",binx,biny,binz, ibin, bin, hold->fArray[ibin],hold->fBinEntries.fArray[ibin] );
710 if (
p->fBuffer)
p->BufferEmpty();
712 if (bin < 0 || bin >=
p->fNcells)
return 0;
716 Double_t neff =
p->GetBinEffectiveEntries(bin);
717 if (
sum == 0)
return 0;
737 if (err2 != 0 && neff < 5) test = eprim2*
sum/err2;
739 if (
p->fgApproximate && (test < 1.e-4 || eprim2 <= 0)) {
745 if (
p->GetDimension() == 2)
index = 7;
746 if (
p->GetDimension() == 3)
index = 11;
775 if (bin < 0 || bin >=
p->fNcells)
return;
776 p->fBinEntries.fArray[bin] =
w;
777 if (
p->fBinSumw2.fN)
p->fBinSumw2.fArray[bin] =
w;
int Int_t
Signed integer 4 bytes (int)
long long Long64_t
Portable signed long integer 8 bytes.
const char Option_t
Option string (const char)
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Class to manage histogram axis.
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
virtual void SetLimits(Double_t xmin, Double_t xmax)
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
THashList * GetLabels() const
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Collection abstract base class.
virtual void AddAll(const TCollection *col)
Add all objects from collection col to this collection.
virtual Bool_t IsEmpty() const
TH1 is the base class of all histogram classes in ROOT.
static Bool_t GetDefaultSumw2()
Return kTRUE if TH1::Sumw2 must be called when creating new histograms.
@ kNoAxis
NOTE: Must always be 0 !!!
@ kNstat
Size of statistics data (up to TProfile3D)
TObject * Remove(TObject *obj) override
Remove object from the list.
void AddFirst(TObject *obj) override
Add object at the beginning of the list.
const char * GetName() const override
Returns name of object.
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual UInt_t GetUniqueID() const
Return the unique object id.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual void Copy(TObject &object) const
Copy this to obj.
static void LabelsInflate(T *p, Option_t *)
static Double_t GetBinError(T *p, Int_t bin)
static T * ExtendAxis(T *p, Double_t x, TAxis *axis)
static void Sumw2(T *p, Bool_t flag)
static void SetBinEntries(T *p, Int_t bin, Double_t w)
static void Scale(T *p, Double_t c1, Option_t *option)
static void SetErrorOption(T *p, Option_t *opt)
static Long64_t Merge(T *p, TCollection *list)
static void BuildArray(T *p)
static Bool_t Add(T *p, const TH1 *h1, const TH1 *h2, Double_t c1, Double_t c2=1)
static Double_t GetBinEffectiveEntries(T *p, Int_t bin)
static void LabelsDeflate(T *p, Option_t *)
void ToLower()
Change string to lower-case.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TClass * IsA() const override
Double_t Sqrt(Double_t x)
Returns the square root of x.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
static uint64_t sum(uint64_t i)