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",
290 (*next)->ClassName(),p->ClassName());
301 if (!allSameLimits) {
306 hclone = (T*)p->IsA()->New();
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))
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;
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"
497 " their content will be lost",p->GetName(),axis->
GetName());
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];
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;
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);
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();
646 T *hold = (T*)p->IsA()->New();
647 hold->SetDirectory(0);
662 p->SetBinsLength(-1);
663 Int_t ncells = p->fN;
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] );