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();
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();
122 for (
Int_t bin = 0; bin <
p->fN; bin++) {
138 p->fBinEntries.Set(
p->fNcells);
139 p->fSumw2.Set(
p->fNcells);
155 if (
p->fBuffer)
p->BufferEmpty();
159 if (
p->fBinSumw2.fN == 0 ||
p->fBinSumw2.fN !=
p->fNcells) {
184 if (
li->IsEmpty())
return (
Int_t)
p->GetEntries();
193 return (
ret) ?
p->GetEntries() : -1;
195#ifdef OLD_PROFILE_MERGE
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());
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",
290 (*next)->ClassName(),
p->ClassName());
327 while ( (
h =
dynamic_cast<T*
> (next()) ) ) {
328 if (
h->GetXaxis()->GetXmin() >=
h->GetXaxis()->GetXmax() &&
h->fBuffer) {
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];
362 return (
Int_t)
p->GetEntries();
375 while ( (
h=
static_cast<T*
>(next())) ) {
378 if (
h->GetXaxis()->GetXmin() <
h->GetXaxis()->GetXmax()) {
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!");
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) ) );
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];
446 if (axis->
GetNbins() <= 0)
return 0;
452 if (!
p->FindNewAxisLimits(axis,
x,
xmin,
xmax))
456 T*
hold = (T*)
p->IsA()->New();
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;
483 iz =
p->fZaxis.FindFixBin(
zc);
486 iy =
p->fYaxis.FindFixBin(
yc);
489 ix =
p->fXaxis.FindFixBin(
xc);
496 "Histogram %s has underflow or overflow in the %s that is extendable"
497 " their content will be lost",
p->GetName(),axis->
GetName());
523 for (bin=0;bin<
p->fN;bin++) {
524 p->fArray[bin] =
c1*
cu1[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())) {
589 if (nbins < 1) nbins = 1;
592 if (nbins==axis->
GetNbins())
return;
594 T *
hold = (T*)
p->IsA()->New();
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);
614 for (bin =0; bin <
hold->fN; ++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());
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();
646 T *
hold = (T*)
p->IsA()->New();
647 hold->SetDirectory(0);
662 p->SetBinsLength(-1);
666 if (
p->fBinSumw2.fN)
p->fBinSumw2.Set(
ncells);
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);
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();
717 if (
sum == 0)
return 0;
739 if (
p->fgApproximate && (
test < 1.e-4 ||
eprim2 <= 0)) {
745 if (
p->GetDimension() == 2)
index = 7;
746 if (
p->GetDimension() == 3)
index = 11;
776 p->fBinEntries.fArray[bin] =
w;
777 if (
p->fBinSumw2.fN)
p->fBinSumw2.fArray[bin] =
w;
int Int_t
Signed integer 4 bytes (int)
const char Option_t
Option string (const char)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#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
Collection abstract base class.
TH1 is the base class of all histogram classes in ROOT.
@ kNoAxis
NOTE: Must always be 0 !!!
static Bool_t GetDefaultSumw2()
Return kTRUE if TH1::Sumw2 must be called when creating new histograms.
@ kNstat
Size of statistics data (up to TProfile3D)
const char * GetName() const override
Returns name of object.
Mother of all ROOT objects.
virtual UInt_t GetUniqueID() const
Return the unique object id.
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
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)