1 #if !defined(__CINT__) || defined(__MAKECINT__)
18 #include "TGraphErrors.h"
106 enum {
kSigCorr,
kMCPrim,
kRawDtCut,
kSignalEst,
kSignalEstMC,
kBgEst,
k1MBeta,
k1MBetaMC,
k1MBetaMCscl,
kAlpha,
kAlphaMC,
kBgMC,
kBgRescFc,
118 vsnprintf(buf, 511, fmt, ap);
121 gROOT->IndentLevel();
124 void Incr() { gROOT->IncreaseDirLevel(); }
125 void Decr() { gROOT->DecreaseDirLevel(); }
135 vsnprintf(buf, 511, fmt, ap);
138 gROOT->IndentLevel();
145 #define MyPrint(L,F,...) _MyPrint(L,F, ## __VA_ARGS__)
146 #define MyGuard(L,F,...) _MyGuard _guard(L,F, ## __VA_ARGS__)
151 Printf(
"Wat is %d", wait);
156 if (wait) c->WaitPrimitive();
159 void CorrectSpectraMultiMCBG(
const char* flNameData,
const char* flNameMC,
const char* unique=
"",
int maxBins=10,
Bool_t waitForUser=
false,
const char* bgType=
"Comb");
164 TList*
LoadList(
const char* flName,
const char* addPref,
const char* nameL=
"clist");
165 void GetRatE(
double x,
double xe,
double y,
double ye,
double &rat,
double &rate);
167 void Integrate(
TH1* hist,
double xmn,
double xmx,
double &val,
double& err);
168 void CropHisto(
TH1* histo,
int b00,
int b01,
int b10=-1,
int b11=-1);
169 void CropHisto(
TH1* histo,
double b00,
double b01,
double b10=-1,
double b11=-1);
171 const char*
HName(
const char* prefix,
const char* htype);
202 uniqueName = uniqueNm;
203 Printf(
"WaitForUser is %d", waitForUser);
204 MyPrint(1,
"Loading lists from %s and %s", flNameData, flNameMC);
206 MyGuard(1,
"Loading data lists");
207 listDt =
LoadList(flNameData,
"dt_");
217 MyPrint(2,
"Got statistics histogram %p", hstat);
221 int nbstat = hstat->GetNbinsX();
227 double myMergeFactor = hstat->GetBinContent(
kOneUnit);
228 if (myMergeFactor<1) myMergeFactor = 1.;
229 MyPrint(2,
"Output was merged from %5.1f jobs", myMergeFactor);
237 MyPrint(2,
"Signal cuts used: dPhiS: %f WDist:%f",
241 MyGuard(1,
"Now looping over bins");
244 MyGuard(1,
"Extracting from MC");
248 MyGuard(1,
"Extracting from Data");
252 MyGuard(1,
"Processing information");
259 sprintf(
outStr,
"CutEta%.1f_%.1f_Zv%.1f_%.1f_bg%s_Shape_%s_%s_cutSig%.1f_cutBg%.1f",
260 hstat->GetBinContent(
kEtaMin)/myMergeFactor,
261 hstat->GetBinContent(
kEtaMax)/myMergeFactor,
262 hstat->GetBinContent(
kZVMin)/myMergeFactor,
263 hstat->GetBinContent(
kZVMax)/myMergeFactor,
272 printf(
"Final Results:\n");
274 for (
int i=
nCentBins;i--;) printf(
"%.2f,",dNdEta[i]); printf(
"\n");
275 printf(
"dNdEtaErr: ");
276 for (
int i=
nCentBins;i--;) printf(
"%.2f,",dNdEtaErr[i]); printf(
"\n");
279 rtnm1 +=
"_"; rtnm1 +=
nCentBins; rtnm1+=
"bins_";
280 rtnm1 +=
outStr; rtnm1 +=
".root";
281 TFile* flRes = TFile::Open(rtnm1.Data(),
"recreate");
282 flRes->WriteObject(&resDnDeta,
"TObjArray",
"kSingleKey");
283 flRes->WriteObject(&resArr,
"TObjArrayAux",
"kSingleKey");
286 printf(
"Stored result in %s\n",rtnm1.Data());
298 TH1* ret =
static_cast<TH1*
>(h->Clone(name));
299 ret->SetTitle(title);
300 if (col) col->AddAtAndExpand(ret, location+shift);
308 Warning(
"PrepareHistos",
"No list for %s", isMC ?
"simulation" :
"data");
316 double cutBgMin,cutBgMax;
317 double cutSgMin,cutSgMax;
335 MyPrint(2,
"Got statistics histogram %p", hstat);
339 Warning(
"PrepareHistos",
"Norm is 0 for bin %d",bin);
342 MyPrint(0,
"Normalization for bin %d: %f", bin, nrmBin);
344 const char* zeCut =
"ZvEtaCutT";
351 Warning(
"PrepareHistos",
"Didn't find %s",
HName(
"Data",zeCut));
355 Form(
"bin%d_%s_RawWithCut",bin,isMC?
"mc":
"dt"),
356 Form(
"bin%d %s Raw Data with cut on tracklets",
357 bin,isMC ?
"mc":
"dt"),
359 MyPrint(1,
"Measurements %s (clone of %s)", hRawDtCut->GetName(),
363 int nbEta = hRawDtCut->GetXaxis()->GetNbins();
364 int nbZV = hRawDtCut->GetYaxis()->GetNbins();
368 TH1* hz = hzv2->ProjectionX(Form(
"zv%d_%s",bin,isMC ?
"mc":
"dt"),
370 MyPrint(1,
"Get histogram of vertex disp for bin %d and scale by %f",
372 hz->Scale(1./nrmBin);
373 res->AddAtAndExpand(hz,
kZvDist+shift);
379 Form(
"bin%d_%s_SignalWithCut",bin,isMC ?
"mc":
"dt"),
380 Form(
"bin%d %s Signal (raw-bg) with cut on tracklets",
381 bin,isMC ?
"mc":
"dt"),
383 MyPrint(1,
"Signal estimate: %s (clone of %s)", hSignalEst->GetName(),
384 hRawDtCut->GetName());
388 TH2* hSignalEstMC = 0;
390 MyGuard(1,
"MC specific code - MC signal estimate");
393 Form(
"bin%d_%s_SignalWithCut_bgMCLabels",
394 bin,isMC ?
"mc":
"dt"),
395 Form(
"bin%d %s Signal (raw-bg_MCLabels) w/cut on tracklets",
396 bin,isMC ?
"mc":
"dt"),
398 MyPrint(1,
"MC signal estimate %s (copy of %s)",hSignalEstMC->GetName(),
399 hRawDtCut->GetName());
405 TList* localLst = (useBgType.EqualTo(
"Comb") ? lstMC : lst);
408 Form(
"bin%d_%s_BgEst",bin,isMC ?
"mc":
"dt"),
409 Form(
"bin%d %s Estimated Bg",bin,isMC?
"mc":
"dt"),
411 MyPrint(1,
"Bg estimate %s (clone of %s)",hBgEst->GetName(),tmp2->GetName());
414 Form(
"bin%d_%s_1mBeta",bin,isMC ?
"mc":
"dt"),
415 Form(
"bin%d %s 1-#beta with estimated bg",
416 bin,isMC ?
"mc":
"dt"),
419 MyPrint(1,
"1-beta %s (clone of %s)", h1mBeta->GetName(), hBgEst->GetName());
424 TH2* h1mBetaMCscl = 0;
427 MyGuard(1,
"MC specific code - prepare 1-beta");
429 MyPrint(1,
"Get MC background from %s",
HName(
"Comb",zeCut));
430 if (!tmp2)
return kFALSE;
432 Form(
"bin%d_%s_BgMC",bin,isMC ?
"mc":
"dt"),
433 Form(
"bin%d %s Bg from MC labels",
434 bin,isMC ?
"mc":
"dt"),
436 MyPrint(1,
"Set MC background %s (clone of %s)",hBgMC->GetName(),
442 Form(
"bin%d_%s_h1mBetaMC",bin,isMC ?
"mc":
"dt"),
443 Form(
"bin%d %s 1-#beta with bg. from MC labels",
444 bin,isMC ?
"mc":
"dt"),
446 h1mBetaMC->Divide(hRawDtCut);
447 MyPrint(1,
"1-beta (MC) %s (ratio of %s to %s)",
448 h1mBetaMC->GetName(),
449 hBgMC->GetName(), hRawDtCut->GetName());
452 Form(
"%s_scl",h1mBetaMC->GetName()),
453 h1mBetaMC->GetTitle(),
456 MyPrint(1,
"1-beta (MC) %s (clone of %s)", h1mBetaMCscl->GetName(),
457 h1mBetaMC->GetName());
459 for (
int ib0=1;ib0<=nbEta;ib0++)
460 for (
int ib1=1;ib1<=nbZV;ib1++) {
462 Double_t oneMBeta = h1mBetaMC->GetBinContent(ib0,ib1);
463 Double_t oneMBetaScl = h1mBetaMCscl->GetBinContent(ib0,ib1);
464 h1mBetaMCscl->SetBinContent(ib0,ib1, 1.- oneMBetaScl);
465 h1mBetaMC->SetBinContent(ib0,ib1, 1.- oneMBeta);
467 MyPrint(1,
"Did 1-X on %s and %s (%f)", h1mBetaMC->GetName(),
468 h1mBetaMCscl->GetName(),
scaleBG);
471 hSignalEstMC->Multiply(h1mBetaMC);
472 MyPrint(1,
"Multiply %s onto %s", h1mBetaMC->GetName(),
473 hSignalEstMC->GetName());
478 "WDist":
"DPhiS"),lst);
479 if (!tmp1)
return kFALSE;
481 Form(
"bin%d_%s_DistRawData",bin,isMC ?
"mc":
"dt"),
482 Form(
"bin%d %s Raw Distance for Data",
485 MyPrint(1,
"Delta dist %s (clone of %s)", hDstDt->GetName(), tmp1->GetName());
488 double nrmDst,dumErr = 0;
489 Integrate(hDstDt, cutBgMin,cutBgMax, nrmDst, dumErr);
490 MyPrint(1,
"Integral of %s is %f +/- %f", hDstDt->GetName(), nrmDst, dumErr);
492 if (nrmDst<1e-10) nrmDst = 1.;
494 hDstDt->Scale(1./nrmDst);
495 MyPrint(1,
"Scaled %s and by integral %f", hDstDt->GetName(),nrmDst);
500 if (!useBgType.IsNull()) {
503 "WDist":
"DPhiS"),localLst);
504 if (!tmp1)
return false;
506 Form(
"bin%d_%s_DistRawGenBgNorm",bin,isMC ?
"mc":
"dt"),
507 Form(
"bin%d %s Raw Dist. for Gen.Bg. Normalized to data",
508 bin,isMC ?
"mc":
"dt"),
511 hDstBg->Scale(1./nrmDst);
512 MyPrint(1,
"%s (copy of %s) scaled by %f", hDstBg->GetName(),
513 tmp1->GetName(), nrmDst);
520 MyPrint(1,
"Scaling between %s and %s: %f +/- %f",
521 hDstDt->GetName(), hDstBg->GetName(), scl, sclE);
522 res->AddAtAndExpand(hDstBg,
kBgDist+shift);
526 Integrate(hDstBg, cutSgMin, cutSgMax, bgVal, bgErr);
527 Integrate(hDstDt, cutSgMin, cutSgMax, dtVal, dtErr);
530 GetRatE(bgVal,bgErr, dtVal, dtErr,sclb,sclbErr);
531 MyPrint(1,
"Ratio of (%s) %f +/- %f over (%s) %f +/- %f -> %f +/- %f",
532 hDstBg->GetName(), bgVal, bgErr,
533 hDstDt->GetName(), dtVal, dtErr,
540 MyPrint(1,
"Scaling %s by %f", hBgEst->GetName(), scl);
543 MyGuard(1,
"Using MC Combinatorials fraction for real data bg.estimate");
546 MyPrint(1,
"Multiply %s with %s", hSignalEst->GetName(), bet1m->GetName());
547 hSignalEst->Multiply(bet1m);
551 MyPrint(1,
"Subtracting %s from %s",hBgEst->GetName(),hSignalEst->GetName());
552 hSignalEst->Add(hBgEst,-1);
558 for (
int ib0=1;ib0<=nbEta;ib0++) {
559 for (
int ib1=1;ib1<=nbZV;ib1++) {
561 double bg = hBgEst->GetBinContent(ib0,ib1);
562 double bgE = hBgEst->GetBinError(ib0,ib1);
563 double dt = hRawDtCut->GetBinContent(ib0,ib1);
564 double dtE = hRawDtCut->GetBinError(ib0,ib1);
566 GetRatE(bg,bgE,dt,dtE, beta,betaE );
567 h1mBeta->SetBinContent(ib0,ib1,1.-beta);
568 h1mBeta->SetBinError(ib0,ib1,betaE);
572 MyPrint(1,
"%s calculated as 1 minus ratio of %s to %s",
573 h1mBeta->GetName(), hBgEst->GetName(), hRawDtCut->GetName());
577 MyGuard(1,
"MC specific stuff");
580 MyPrint(1,
"MC truth vertex distribution %s", hzv2ns->GetName());
581 TH1* hzns = hzv2ns->ProjectionX(Form(
"zvMCNS%d",bin),bin+1,bin+1,
"e");
582 MyPrint(1,
"Projection %s", hzns->GetName());
584 double myMergeFactor = hstat->GetBinContent(
kOneUnit);
585 double zmn = hstat->GetBinContent(
kZVMin)/myMergeFactor;
586 double zmx = hstat->GetBinContent(
kZVMax)/myMergeFactor;
587 int zbmn = hzns->FindBin(zmn+1e-3);
588 int zbmx = hzns->FindBin(zmx-1e-3);
589 double nEvTot = hzns->Integral(zbmn,zbmx);
590 MyPrint(1,
"Scale MC Truth By %9.1f",nEvTot);
591 if (nEvTot<1) exit(1);
592 hzns->Scale(1./nEvTot);
611 Form(
"bin%d_zvEtaPrimMC",bin),
612 Form(
"bin%d MC True signal Zv vs Eta",bin),
614 mcPrim->Scale(1./nEvTot);
615 MyPrint(1,
"%s (copy of %s) scaled by %f", mcPrim->GetName(),
616 tmp2->GetName(), nEvTot);
620 tmp2 = (
TH2*)
FindObject(bin,
"zvrecEtaPrimMCSel", lst, kTRUE );
622 Form(
"bin%d_zvEtaPrimMCSel", bin),
623 Form(
"bin%d MC True signal Zv vs Eta (sel)",bin),
625 MyPrint(1,
"%s (copy of %s)", mcPrim->GetName(), tmp2->GetName());
637 MyPrint(2,
"Shift for bin %d is %d", bin, shift);
639 TString prefN =
"bin"; prefN += bin; prefN+=
"_";
640 TString prefT =
"bin"; prefT += bin; prefT+=
" ";
657 TH1* mcVtxEff = (
TH1*)hZVmcRec->Clone(Form(
"Eff_%s",hZVmcRec->GetName()));
658 MyPrint(1,
"Got vertex distributions %s (data) %s %s (MC)",
659 hZV->GetName(), hZVmcRec->GetName(), hZVmcGen->GetName());
661 mcVtxEff->Divide(hZVmcRec,hZVmcGen,1,1,
"B");
662 MyPrint(1,
"Calculate vertex efficiency as %s over %s -> %s",
663 hZVmcRec->GetName(), hZVmcGen->GetName(), mcVtxEff->GetName());
665 TH1* hZVcorr = (
TH1*)hZV->Clone(Form(
"corr_%s",hZV->GetName()));
666 hZVcorr->Divide(mcVtxEff);
667 MyPrint(1,
"Calculate corrected vertex distribution %s", hZVcorr->GetName());
671 MyPrint(2,
"Adding vtx corr (%s) and eff (%s) at %d and %d",
672 hZVcorr->GetName(), mcVtxEff->GetName(), shift+
kZvDistCorr,
677 MyPrint(1,
"Start of alpha: %s", halp->GetName());
678 halp = (
TH2*) halp->Clone(prefN+
"Alpha");
679 MyPrint(1,
"Cloned as %s", halp->GetName());
680 halp->SetTitle(prefN+
"#alpha");
684 halp->Divide( omBeta );
685 halp->Divide( mcRaw );
686 MyPrint(1,
"%s scaled by %s and %s", halp->GetName(), omBeta->GetName(),
688 res->AddAtAndExpand(halp, shift +
kAlpha);
689 MyPrint(2,
"Adding alpha %s at %d", halp->GetName(), shift+
kAlpha);
697 MyPrint(1,
"Start of alpha MC: %s", halpMC->GetName());
698 halpMC = (
TH2*) halpMC->Clone(prefN +
"AlphaMC");
699 MyPrint(1,
"Cloned as %s", halpMC->GetName());
700 halpMC->SetTitle(prefT +
"#alpha MC labels");
703 halpMC->Divide( omBetaMC );
704 halpMC->Divide( mcRaw );
705 MyPrint(1,
"%s scaled by %s and %s", halpMC->GetName(), omBetaMC->GetName(),
707 res->AddAtAndExpand(halpMC, shift +
kAlphaMC);
714 MyPrint(1,
"Start of corrected signal: %s", hsigCorr->GetName());
715 hsigCorr = (
TH2*) hsigCorr->Clone(prefN +
"SignalEstCorr");
716 MyPrint(1,
"Cloned as %s", hsigCorr->GetName());
717 hsigCorr->SetTitle(prefT +
"Corrected Signal");
719 hsigCorr->Multiply(
use1mBeta ? halpMC : halp );
721 MyPrint(1,
"Multiply by %s",
use1mBeta ? halpMC->GetName() : halp->GetName());
722 res->AddAtAndExpand(hsigCorr, shift +
kSigCorr);
723 MyPrint(2,
"Add corrected signal %s at %d", hsigCorr->GetName(), shift+
kSigCorr);
726 TH2* tmpSC = (
TH2*)hsigCorr->Clone(
"tmpSC");
733 MyPrint(1,
"Corrected X signal from weighted mean: %s",
734 hsigCorrX->GetName());
738 hsigCorrX =
ProjNorm(tmpSC,useZV,
"DataCorrSignalX");
739 MyPrint(1,
"Corrected X signal from normal mean %s", hsigCorrX->GetName());
743 hsigCorrX->Scale(1./hsigCorrX->GetBinWidth(1));
744 MyPrint(1,
"Scaling corrected X signal %s with bin width",
745 hsigCorrX->GetName());
747 TF1* pl0 =
new TF1(
"pl0",
"pol0");
748 pl0->SetParameter(0,hsigCorr->GetMinimum());
750 MyPrint(1,
"Fit straight line to X signal %s", hsigCorrX->GetName());
751 double fval = pl0->GetParameter(0);
752 double ferr = pl0->GetParError(0);
755 dNdEtaErr[bin] = ferr;
756 printf(
"Bin %d: dN/d#eta_{|#eta|<0.5} = %.2f %.2f\n",bin, fval,ferr);
762 MyGuard(1,
"Plottinmg results");
764 psnm1 +=
"_"; psnm1 +=
nCentBins; psnm1+=
"bins_";
765 psnm1 +=
outStr; psnm1 +=
".pdf";
772 double myMergeFactor = hstat->GetBinContent(
kOneUnit);
773 if (myMergeFactor<1) myMergeFactor = 1.;
777 if (!
canvFin)
canvFin =
new TCanvas(
"canvFin",
"canvFin",0,50,700,1000);
784 gPad->SetLeftMargin(0.15);
787 grp->SetPoint(i,hbins->GetBinCenter(i+1),dNdEta[i]);
788 grp->SetPointError(i,hbins->GetBinWidth(i+1)/2,dNdEtaErr[i]);
790 grp->SetMarkerStyle(20);
791 grp->SetMarkerColor(kRed);
792 grp->SetLineColor(kRed);
793 grp->SetMinimum(1e-6);
795 grp->GetXaxis()->SetTitle(
"Centrality Variable");
796 grp->GetYaxis()->SetTitle(
"dN/d#eta_{|#eta|<0.5}");
797 grp->GetYaxis()->SetTitleOffset(1.8);
798 MyPrint(2,
"Created graph of central dNch/deta %s", grp->GetName());
802 gPad->SetLeftMargin(0.15);
804 hbins->SetMinimum(1e-6);
805 hbins->SetMarkerStyle(20);
806 hbins->SetMarkerColor(kRed);
807 hbins->SetLineColor(kRed);
808 hbins->GetYaxis()->SetTitle(
"accepted events");
809 hbins->GetYaxis()->SetTitleOffset(1.8);
811 MyPrint(2,
"Drew %s", hbins->GetName());
816 const TArrayD &binArr = *hbins->GetXaxis()->GetXbins();
819 MyGuard(1,
"Looping over centrality bins");
822 sprintf(
outTitle,
"%s, %d<C_%s<%d, %.1f<#eta<%.1f, %.1f<Z_{V}<%.1f, Bg.:%s, %s, CutVar:%s, |sig|<%.2f, %.2f<|bg.nrm|<%.2f",
825 hstat->GetXaxis()->GetBinLabel(
kCentVar),
827 hstat->GetBinContent(
kEtaMin)/myMergeFactor,
828 hstat->GetBinContent(
kEtaMax)/myMergeFactor,
829 hstat->GetBinContent(
kZVMin)/myMergeFactor,
830 hstat->GetBinContent(
kZVMax)/myMergeFactor,
846 MyPrint(2,
"Now plotting species");
855 MyGuard(1,
"Plotting dN/deta in bin %d", bin);
858 TString prefN =
"bin"; prefN += bin; prefN+=
"_";
863 gStyle->SetOptFit(0);
864 gStyle->SetOptStat(0);
865 gStyle->SetOptTitle(0);
866 double mn = 1e6,mx = -1e6;
867 if (!
canvFin)
canvFin =
new TCanvas(
"canvFin",
"canvFin",0,50,700,1000);
871 gPad->SetLeftMargin(0.15);
879 MyPrint(2,
"Got Z vertex and correction histograms: %s %s", hZV->GetName(), hZVcorr->GetName());
883 nms +=
"DataCorrSignal";
886 TH2* tmpSCorr = (
TH2F*)res->At(shift +
kSigCorr)->Clone(Form(
"%stmpSCorrBin%d",prefN.Data(),bin));
890 res->At(shift +
kSigCorr)->GetName(), tmpSCorr->GetName());
898 hsigCorr =
ProjNorm(tmpSCorr,useZV,nms.Data());
899 MyPrint(2,
"Corrected X signal from normal mean %s", hsigCorr->GetName());
903 hsigCorr->Scale(1./hsigCorr->GetBinWidth(1));
905 MyPrint(2,
"Scaled %s by bin width, and drew", hsigCorr->GetName());
906 mx = TMath::Max(mx, hsigCorr->GetMaximum());
907 mn = TMath::Min(mn, hsigCorr->GetMinimum());
908 resDnDeta.AddAtAndExpand( hsigCorr, bin );
909 MyPrint(2,
"Added %s at %d", hsigCorr->GetName(), bin);
910 hsigCorr->SetDirectory(0);
911 resDnDeta.AddAtAndExpand( res->At(shift +
kSigCorr), 100+bin );
912 MyPrint(2,
"Added unnormalized %s at %d", hsigCorr->GetName(), bin);
913 resDnDeta.AddAtAndExpand( tmpSCorr, 200+bin );
914 tmpSCorr->SetDirectory(0);
915 resDnDeta.AddAtAndExpand(hZV , 250+bin );
916 MyPrint(2,
"Added vertex %s at %d", hZV->GetName(), 250+bin);
917 hZV->SetDirectory(0);
922 TH1* hraw = tmpRaw->ProjectionX(prefN+
"DataRaw");
924 MyPrint(2,
"Got the raw data %s and made projection %s",
925 res->At(shift+
kRawDtCut)->GetName(), hraw->GetName());
927 hraw->Scale(1./hraw->GetBinWidth(1));
929 mn = TMath::Min(mn, hraw->GetMinimum());
930 mx = TMath::Max(mx, hraw->GetMaximum());
934 TH1* hraws = tmpRawB->ProjectionX(prefN+
"DataRawSub");
937 MyPrint(2,
"Got the raw data %s and made projection %s",
938 res->At(shift+
kSignalEst)->GetName(), hraws->GetName());
939 hraws->Scale(1./hraw->GetBinWidth(1));
941 mn = TMath::Min(mn, hraw->GetMinimum());
942 mx = TMath::Max(mx, hraw->GetMaximum());
946 TH1* hbg = tmpBg->ProjectionX(prefN+
"BgEst");
948 MyPrint(2,
"Got the bg estimate %s and made projection %s",
949 res->At(shift+
kBgEst)->GetName(), hbg->GetName());
951 hbg->Scale(1./hbg->GetBinWidth(1));
953 mn = TMath::Min(mn, hbg->GetMinimum());
954 mx = TMath::Max(mx, hbg->GetMaximum());
962 TH1* hrawMC = tmpRawMC->ProjectionX(prefN+
"DataRawMC");
964 MyPrint(2,
"Got the MC raw %s and made projection %s",
967 hrawMC->Scale(1./hrawMC->GetBinWidth(1));
968 hrawMC->Draw(
"same");
969 mn = TMath::Min(mn, hrawMC->GetMinimum());
970 mx = TMath::Max(mx, hrawMC->GetMaximum());
974 TH1* hrawsMC = tmpRawBMC->ProjectionX(prefN+
"DataRawSubMC");
976 MyPrint(2,
"Got the MC signal estimate %s and made projection %s",
979 hrawsMC->Scale(1./hrawMC->GetBinWidth(1));
980 hrawsMC->Draw(
"same");
981 mn = TMath::Min(mn, hrawMC->GetMinimum());
982 mx = TMath::Max(mx, hrawMC->GetMaximum());
986 TH1* hrawsMCLB = tmpRawLBMC->ProjectionX(prefN+
"DataRawSubMCLB");
988 MyPrint(2,
"Got the MC signal estimate %s from labels and made projection %s",
991 hrawsMCLB->Scale(1./hrawsMCLB->GetBinWidth(1));
992 hrawsMCLB->Draw(
"same");
993 mn = TMath::Min(mn, hrawsMCLB->GetMinimum());
994 mx = TMath::Max(mx, hrawsMCLB->GetMaximum());
998 TH1* hbgMCEst = tmpBgMCEst->ProjectionX(prefN+
"BgEstMC");
999 MyPrint(2,
"Got the MC bg estimate %s and made projection %s",
1003 hbgMCEst->Scale(1./hbgMCEst->GetBinWidth(1));
1004 hbgMCEst->Draw(
"same");
1005 mn = TMath::Min(mn, hbgMCEst->GetMinimum());
1006 mx = TMath::Max(mx, hbgMCEst->GetMaximum());
1010 TH1* hbgMC = tmpBgMC->ProjectionX(prefN+
"BgMC");
1012 MyPrint(2,
"Got the MC bg %s and made projection %s",
1013 res->At(shift+
kBgMC+
kMCShift)->GetName(), hbgMC->GetName());
1015 hbgMC->Scale(1./hbgMC->GetBinWidth(1));
1016 hbgMC->Draw(
"same");
1017 mn = TMath::Min(mn, hbgMC->GetMinimum());
1018 mx = TMath::Max(mx, hbgMC->GetMaximum());
1021 TH2* tmpMCTrue = (
TH2F*)res->At(shift+
kMCPrim+
kMCShift)->Clone(Form(
"%stmpMCTrueBin%d",prefN.Data(),bin));
1029 hMCtrue =
ProjNorm(tmpMCTrue,hzMC,prefN+
"MCTruth");
1033 MyPrint(2,
"Got the MC truth %s and made projection %s",
1036 hMCtrue->Scale(1./hMCtrue->GetBinWidth(1));
1037 hMCtrue->SetLineStyle(1);
1038 hMCtrue->Draw(
"same");
1039 mn = TMath::Min(mn, hMCtrue->GetMinimum());
1040 mx = TMath::Max(mx, hMCtrue->GetMaximum());
1042 hMCtrue->SetDirectory(0);
1043 tmpMCTrue->SetDirectory(0);
1044 resDnDeta.AddAtAndExpand( hMCtrue, 300+bin);
1046 resDnDeta.AddAtAndExpand( tmpMCTrue, 500+bin );
1047 resDnDeta.AddAtAndExpand( hZVMCNS, 550+bin );
1051 hsigCorr->SetMinimum(mn);
1052 hsigCorr->SetMaximum(mx + 0.4*(mx-mn));
1055 sprintf(ftres,
"dN/d#eta_{|#eta|<%.2f} = %.2f #pm %.2f",
kEtaFitRange,dNdEta[bin],dNdEtaErr[bin]);
1056 double xtxt = (hsigCorr->GetXaxis()->GetXmin()+hsigCorr->GetXaxis()->GetXmax())/2;
1057 TLatex *txfit =
new TLatex(xtxt,mn+0.25*(mx-mn), ftres);
1058 txfit->SetTextSize(0.04);
1064 MyPrint(2,
"Making the legend");
1065 TLegend *legDnDeta =
new TLegend(0.15,0.75, 0.45,0.95);
1066 legDnDeta->SetFillColor(kWhite);
1067 legDnDeta->SetHeader(
"Data");
1068 legDnDeta->AddEntry(hsigCorr,
"Corrected",
"pl");
1069 legDnDeta->AddEntry(hraw,
"Reconstructed",
"pl");
1070 sprintf(buff,
"Reconstructed - Bckg.%s.",useBgType.Data());
1071 legDnDeta->AddEntry(hraws, buff,
"pl");
1072 sprintf(buff,
"Background %s.",useBgType.Data());
1073 legDnDeta->AddEntry(hbg, buff,
"pl");
1076 TLegend *legDnDetaMC =
new TLegend(0.60,0.72, 0.95,0.95);
1077 legDnDetaMC->SetFillColor(kWhite);
1078 legDnDetaMC->SetHeader(
"MC");
1079 legDnDetaMC->AddEntry(hrawMC,
"Reconstructed",
"pl");
1080 sprintf(buff,
"Reconstructed - Bckg.%s.",useBgType.Data());
1081 legDnDetaMC->AddEntry(hrawsMC, buff,
"pl");
1082 sprintf(buff,
"Reconstructed - Bckg.%s.",
"MC.Labels");
1083 legDnDetaMC->AddEntry(hrawsMCLB, buff,
"pl");
1084 sprintf(buff,
"Background %s.",useBgType.Data());
1085 legDnDetaMC->AddEntry(hbgMCEst, buff,
"pl");
1086 sprintf(buff,
"Background %s.",
"MC Labels");
1087 legDnDetaMC->AddEntry(hbgMC, buff,
"pl");
1089 legDnDetaMC->Draw();
1100 MyPrint(2,
"Drawing AUX distributions");
1114 mcDstSec->Scale(scl);
1115 mcDstCombU->Scale(scl);
1116 mcDstCombC->Scale(scl);
1117 mcDstCombC->Add(mcDstCombU,-1);
1121 dtdst->GetXaxis()->SetLabelSize(0.03);
1122 dtdst->GetXaxis()->SetTitleSize(0.03);
1123 dtdst->GetXaxis()->SetTitleOffset(2);
1124 dtdstbg->Draw(
"same");
1126 mcdst->Draw(
"same");
1127 mcDstSec->Draw(
"same");
1128 if (mcdstbgLB) mcdstbgLB->Draw(
"same");
1129 mcdstbg->Draw(
"same");
1130 mcDstCombC->Draw(
"same");
1134 if (mcdstbgLB)
SetHStyle(mcdstbgLB,kGreen, 7,0.5);
1142 double vmcTot,vmcTotE;
1143 double vmcSec,vmcSecE, ratSec,ratSecE;
1144 double vmcCmbEst,vmcCmbEstE, ratCmbEst,ratCmbEstE;
1145 double vmcCmb,vmcCmbE, ratCmb,ratCmbE;
1146 double vmcCmbC,vmcCmbCE, ratCmbC,ratCmbCE;
1147 double cutSgMin,cutSgMax;
1148 double cutBgMin,cutBgMax;
1161 Integrate(mcdst, cutSgMin,cutSgMax, vmcTot,vmcTotE);
1162 Integrate(mcDstSec, cutSgMin,cutSgMax, vmcSec,vmcSecE);
1163 GetRatE(vmcSec,vmcSecE, vmcTot,vmcTotE, ratSec,ratSecE);
1166 Integrate(mcdstbgLB, cutSgMin,cutSgMax, vmcCmb,vmcCmbE);
1167 GetRatE(vmcCmb,vmcCmbE, vmcTot,vmcTotE, ratCmb,ratCmbE);
1170 Integrate(mcdstbg, cutSgMin,cutSgMax, vmcCmbEst,vmcCmbEstE);
1171 GetRatE(vmcCmbEst,vmcCmbEstE, vmcTot,vmcTotE, ratCmbEst,ratCmbEstE);
1173 Integrate(mcDstCombC, cutSgMin,cutSgMax, vmcCmbC,vmcCmbCE);
1174 GetRatE(vmcCmbC,vmcCmbCE, vmcTot,vmcTotE, ratCmbC,ratCmbCE);
1176 double vdtTot,vdtTotE;
1177 double vdtBg,vdtBgE, ratdtBg,ratdtBgE;
1179 Integrate(dtdst, cutSgMin,cutSgMax, vdtTot,vdtTotE);
1180 Integrate(dtdstbg, cutSgMin,cutSgMax, vdtBg,vdtBgE);
1181 GetRatE( vdtBg,vdtBgE, vdtTot,vdtTotE, ratdtBg,ratdtBgE);
1184 double dmn = mcdst->GetMinimum();
1185 double dmx = mcdst->GetMaximum();
1186 TLine *ln =
new TLine(cutSgMax, dmn, cutSgMax, dmx);
1187 ln->SetLineColor(kBlack);
1189 TLine *lnc =
new TLine(cutBgMin, dmn, cutBgMin, dmx);
1190 lnc->SetLineColor(kRed);
1193 ln =
new TLine(-cutSgMax, dmn, -cutSgMax, dmx);
1194 ln->SetLineColor(kBlack);
1197 lnc =
new TLine(-cutBgMin, dmn, -cutBgMin, dmx);
1198 lnc->SetLineColor(kRed);
1202 TLegend *legDstMC1 =
new TLegend(0.60,0.72, 0.95,0.95);
1203 legDstMC1->SetFillColor(kWhite);
1206 legDstMC1->AddEntry(dtdst,
"Data raw",
"pl");
1207 sprintf(buff,
"Data Comb. %s. : %.1f%%",useBgType.Data(),ratdtBg*100);
1208 legDstMC1->AddEntry(dtdstbg, buff,
"pl");
1212 legDstMC1->AddEntry(mcdst,
"MC raw",
"pl");
1213 sprintf(buff,
"MC Comb. %s. : %.1f%%",useBgType.Data(),ratCmbEst*100);
1214 legDstMC1->AddEntry(mcdstbg, buff,
"pl");
1216 sprintf(buff,
"MC Comb. %s. : %.1f%%",
"MC Lbl.",ratCmb*100);
1217 legDstMC1->AddEntry(mcdstbgLB, buff,
"pl");
1219 sprintf(buff,
"MC Comb.Uncorr %s. : %.1f%%",
"MC Lbl.",ratCmbC*100);
1220 legDstMC1->AddEntry(mcDstCombC, buff,
"pl");
1222 sprintf(buff,
"MC Sec. : %.1f%%",ratSec*100);
1223 legDstMC1->AddEntry(mcDstSec, buff,
"pl");
1235 sprintf(buff,
"%s/%s_b%d_dNdEta_%s",
figDir,uniqueName.Data(),bin,
outStr);
1243 MyGuard(2,
"Draw alpha and beta");
1246 gStyle->SetOptFit(0);
1247 gStyle->SetOptStat(0);
1248 gStyle->SetOptTitle(0);
1251 if (!
canvFin)
canvFin =
new TCanvas(
"canvFin",
"canvFin",10,10,700,1000);
1253 canvFin->Divide(2,3,0.01,0.01);
1259 double mn,mx,mnt,mxt;
1262 if (mnt<mn) mn = mnt;
1263 if (mxt>mx) mx = mxt;
1265 if (mnt<mn) mn = mnt;
1266 if (mxt>mx) mx = mxt;
1268 dtBet->SetMinimum(mn - 0.05*(mx-mn));
1269 dtBet->SetMaximum(mx + 0.05*(mx-mn));
1270 mcBet->SetMinimum(mn - 0.05*(mx-mn));
1271 mcBet->SetMaximum(mx + 0.05*(mx-mn));
1272 mcBetLB->SetMinimum(mn - 0.05*(mx-mn));
1273 mcBetLB->SetMaximum(mx + 0.05*(mx-mn));
1276 gPad->SetRightMargin(0.15);
1277 dtBet->Draw(
"colz");
1278 AddLabel(
"#beta Data",0.2,0.95,kBlack,0.04);
1280 dtBet->GetYaxis()->SetTitleOffset(1.4);
1285 gPad->SetRightMargin(0.15);
1286 mcBet->Draw(
"colz");
1287 AddLabel(
"#beta MC (bckg.estimated)",0.2,0.95,kBlack,0.04);
1289 mcBet->GetYaxis()->SetTitleOffset(1.4);
1293 gPad->SetRightMargin(0.15);
1294 mcBetLB->Draw(
"colz");
1295 AddLabel(
"#beta MC (bckg.from MC labels)",0.2,0.95,kBlack,0.04);
1297 mcBetLB->GetYaxis()->SetTitleOffset(1.4);
1306 if (mnt<mn) mn = mnt;
1307 if (mxt>mx) mx = mxt;
1308 dtAlp->SetMinimum(mn - 0.05*(mx-mn));
1309 dtAlp->SetMaximum(mx + 0.05*(mx-mn));
1310 mcAlp->SetMinimum(mn - 0.05*(mx-mn));
1311 mcAlp->SetMaximum(mx + 0.05*(mx-mn));
1314 gPad->SetRightMargin(0.15);
1315 dtAlp->Draw(
"colz");
1316 AddLabel(
"#alpha (bckg.estimated)",0.2,0.95,kBlack,0.04);
1318 dtAlp->GetYaxis()->SetTitleOffset(1.4);
1322 gPad->SetRightMargin(0.15);
1323 mcAlp->Draw(
"colz");
1324 AddLabel(
"#alpha (bckg.from MC labels)",0.2,0.95,kBlack,0.04);
1326 mcAlp->GetYaxis()->SetTitleOffset(1.4);
1334 sprintf(buff,
"%s/%sAlphaBeta_%s",
figDir,uniqueName.Data(),
outStr);
1342 MyGuard(2,
"Plotting species");
1344 gStyle->SetOptFit(0);
1345 gStyle->SetOptStat(0);
1346 gStyle->SetOptTitle(0);
1352 int nbd = hSpecPrim->GetXaxis()->GetNbins();
1354 TH1* hSpecPrimAll = hSpecPrim->ProjectionX(
"specPrimAll",1,nbd+1,
"e");
1355 hSpecPrimAll->Scale(100./hSpecPrimAll->Integral());
1356 hSpecPrimAll->GetYaxis()->SetTitle(
"Fraction,%");
1357 hSpecPrimAll->GetXaxis()->SetLabelSize(0.06);
1358 hSpecPrimAll->GetXaxis()->LabelsOption(
"v");
1360 TH1* hSpecSecAll = hSpecSec->ProjectionX(
"specSecAll",1,nbd+1,
"e");
1361 hSpecSecAll->Scale(100./hSpecSecAll->Integral());
1362 hSpecSecAll->GetYaxis()->SetTitle(
"Fraction,%");
1363 hSpecSecAll->GetXaxis()->SetLabelSize(0.05);
1365 TH1* hSpecPrimPAll = hSpecPrimP->ProjectionX(
"specPrimPAll",1,nbd+1,
"e");
1366 hSpecPrimPAll->Scale(100./hSpecPrimPAll->Integral());
1367 hSpecPrimPAll->GetYaxis()->SetTitle(
"Fraction,%");
1368 hSpecPrimPAll->GetXaxis()->SetLabelSize(0.06);
1369 hSpecPrimPAll->GetXaxis()->LabelsOption(
"v");
1372 TH1* hSpecSecPAll = hSpecSecP->ProjectionX(
"specSecPAll",1,nbd+1,
"e");
1373 hSpecSecPAll->Scale(100./hSpecSecPAll->Integral());
1374 hSpecSecPAll->GetYaxis()->SetTitle(
"Fraction,%");
1375 hSpecSecPAll->GetXaxis()->SetLabelSize(0.05);
1378 TH1* hSpecPrimSel = hSpecPrim->ProjectionX(
"specPrimSel",1,binCut,
"e");
1379 if (hSpecPrimSel->Integral()<1)
return;
1380 hSpecPrimSel->Scale(100./hSpecPrimSel->Integral());
1381 hSpecPrimSel->GetYaxis()->SetTitle(
"Fraction,%");
1382 hSpecPrimSel->GetXaxis()->SetLabelSize(0.05);
1384 TH1* hSpecSecSel = hSpecSec->ProjectionX(
"specSecSel",1,binCut,
"e");
1385 hSpecSecSel->Scale(100./hSpecSecSel->Integral());
1386 hSpecSecSel->GetYaxis()->SetTitle(
"Fraction,%");
1387 hSpecSecSel->GetXaxis()->SetLabelSize(0.05);
1389 TH1* hSpecPrimPSel = hSpecPrimP->ProjectionX(
"specPrimPSel",1,binCut,
"e");
1390 hSpecPrimPSel->Scale(100./hSpecPrimPSel->Integral());
1391 hSpecPrimPSel->GetYaxis()->SetTitle(
"Fraction,%");
1392 hSpecPrimPSel->GetXaxis()->SetLabelSize(0.05);
1394 TH1* hSpecSecPSel = hSpecSecP->ProjectionX(
"specSecPSel",1,binCut,
"e");
1395 hSpecSecPSel->Scale(100./hSpecSecPSel->Integral());
1396 hSpecSecPSel->GetYaxis()->SetTitle(
"Fraction,%");
1397 hSpecSecPSel->GetXaxis()->SetLabelSize(0.05);
1399 if (!
canvFin)
canvFin =
new TCanvas(
"canvFin",
"canvFin",10,10,1100,800);
1401 canvFin->Divide(1,2,0.01,0.01);
1403 hSpecPrimAll->Draw();
1405 hSpecPrimSel->Draw(
"same");
1408 hSpecSecAll->Draw(
"same");
1410 hSpecSecSel->Draw(
"same");
1413 TLegend *legPart =
new TLegend(0.8,0.72, 0.999,0.999);
1414 legPart->SetFillColor(kWhite);
1415 legPart->SetHeader(
"Tracklet PDG");
1417 legPart->AddEntry(hSpecPrimAll,
"Prim., before #Delta cut",
"pl");
1418 legPart->AddEntry(hSpecPrimSel,
"Prim., after #Delta cut",
"pl");
1419 legPart->AddEntry(hSpecSecAll,
"Sec., before #Delta cut",
"pl");
1420 legPart->AddEntry(hSpecSecSel,
"Sec., after #Delta cut",
"pl");
1428 hSpecPrimPAll->Draw();
1430 hSpecPrimPSel->Draw(
"same");
1433 hSpecSecPAll->Draw(
"same");
1435 hSpecSecPSel->Draw(
"same");
1438 TLegend *legPartP =
new TLegend(0.8,0.72, 0.999,0.999);
1439 legPartP->SetFillColor(kWhite);
1440 legPartP->SetHeader(
"Tracklet Parents PDG");
1442 legPartP->AddEntry(hSpecPrimPAll,
"Prim., before #Delta cut",
"pl");
1443 legPartP->AddEntry(hSpecPrimPSel,
"Prim., after #Delta cut",
"pl");
1444 legPartP->AddEntry(hSpecSecPAll,
"Sec., before #Delta cut",
"pl");
1445 legPartP->AddEntry(hSpecSecPSel,
"Sec., after #Delta cut",
"pl");
1457 sprintf(buff,
"%s/%sSpecies_%s",
figDir,uniqueName.Data(),
outStr);
1465 MyGuard(3,
"Cropping histogram %s between bins %d,%d x %d,%d", bx0, bx1, by0, by1);
1467 TAxis *xax = histo->GetXaxis();
1468 int nbx = xax->GetNbins();
1469 double vmn=1e16,vmx=-1e16;
1470 if (histo->InheritsFrom(TH2::Class())) {
1471 TAxis *yax = histo->GetYaxis();
1472 int nby = yax->GetNbins();
1473 for (
int ix=nbx+2;ix--;) {
1474 for (
int iy=nby+2;iy--;) {
1475 if ((ix<bx0||ix>bx1)||(iy<by0||iy>by1)) {
1476 histo->SetBinContent(ix,iy,0);
1477 histo->SetBinError(ix,iy,0);
1480 double vl = histo->GetBinContent(ix,iy);
1481 if (vl<vmn) vmn = vl;
1482 if (vl>vmx) vmx = vl;
1488 for (
int ix=nbx+2;ix--;) {
1489 if ((ix<bx0||ix>bx1)) {
1490 histo->SetBinContent(ix,0);
1491 histo->SetBinError(ix,0);
1494 double vl = histo->GetBinContent(ix);
1495 if (vl<vmn) vmn = vl;
1496 if (vl>vmx) vmx = vl;
1505 histo->SetMaximum(vmx);
1506 histo->SetMinimum(vmn);
1512 MyGuard(3,
"Cropping histogram %s between values %f,%f x %f,%f", vx0, vx1, vy0, vy1);
1514 TAxis *xax = histo->GetXaxis();
1515 int bx0,bx1,by0=-1,by1=-1;
1516 bx0 = xax->FindBin(vx0+
kEps);
1517 bx1 = xax->FindBin(vx1-
kEps);
1518 if (histo->InheritsFrom(TH2::Class())) {
1519 TAxis *yax = histo->GetYaxis();
1520 by0 = yax->FindBin(vy0+
kEps);
1521 by1 = yax->FindBin(vy1-
kEps);
1532 MyGuard(1,
"Normalize background from %s and %s",
1533 dataH->GetName(), bgH->GetName());
1535 TAxis* xax = dataH->GetXaxis();
1536 int nbtot = xax->GetNbins();
1537 int bgBins[2][2] = {{0}};
1555 MyPrint(2,
"NormalizeBg: bins for tails: right: %d:%d / left: %d:%d",
1556 bgBins[0][0],bgBins[0][1],bgBins[1][0],bgBins[1][1]);
1558 double meanR=0,meanRE=0,meanRE2=0;
1559 double meanD=0,meanDE2=0;
1560 double meanB=0,meanBE2=0;
1561 double meanRI=0,meanRIE=0;
1562 for (
int itp=0;itp<=ntails;itp++) {
1563 for (
int ib=bgBins[itp][0];ib<=bgBins[itp][1];ib++) {
1564 if (ib<1||ib>nbtot)
continue;
1565 double vD = dataH->GetBinContent(ib);
1566 double vB = bgH->GetBinContent(ib);
1567 double eD = dataH->GetBinError(ib);
1568 double eB = bgH->GetBinError(ib);
1569 meanD += vD; meanDE2 += eD*eD;
1570 meanB += vB; meanBE2 += eB*eB;
1571 if (vD<=0 || vB<=0 || eD<=0 || eB<=0)
continue;
1573 double ratE2 = rat*rat*(eD*eD/vD/vD + eB*eB/vB/vB);
1574 meanR += rat/ratE2; meanRE2 += 1.0/ratE2;
1580 meanRE2 = 1./meanRE2;
1581 meanRE = TMath::Sqrt(meanRE2);
1583 if (meanDE2>0 && meanBE2>0) {
1584 meanRI = meanD/meanB;
1585 meanRIE = meanRI*TMath::Sqrt(meanDE2/meanD/meanD + meanBE2/meanB/meanB);
1587 MyPrint(1,
"NormalizeBg: Tails scaling %s wrt %s: "
1588 "Wgh.Mean:%.4f(%.4f) / Integral:%.4f(%.4f)",
1589 bgH->GetName(),dataH->GetName(), meanR,meanRE, meanRI,meanRIE);
1590 MyPrint(2,
"NormalizeBg: Select scaling type %s",
1598 sprintf(buff,
"%s_bgNorm",bgH->GetName());
1600 bgH = (
TH1*)tmp->Clone(buff);
1601 sprintf(buff,
"%s bgNorm%d %.4f+-%.4f",bgH->GetName(),
useScaleType,scl,sclE);
1602 TH1* dumH = (
TH1*)bgH->Clone(
"dummySCL$"); dumH->Reset();
1603 for (
int i=1;i<=nbtot;i++) {
1604 dumH->SetBinContent(i,scl);
1605 dumH->SetBinError(i,sclE);
1607 bgH->Multiply(dumH);
1608 MyPrint(1,
"Returning normal backg delta distribution %s (copy of %s)",
1609 bgH->GetName(), tmp->GetName());
1619 Warning(
"FindObject",
"%s: No list provided",nameH);
1623 int nent = lst->GetEntries();
1625 if (bin>=0) sprintf(buff,
"b%d_%s",bin,nameH);
1626 else sprintf(buff,
"%s",nameH);
1628 MyGuard(1,
"Looking for bin %d of %s: %s", bin, nameH, buff);
1632 for (
int i=nent;i--;) {
1633 nm = lst->At(i)->GetName();
1634 if (nm.EndsWith(buff)) {hst = lst->At(i);
break;}
1637 Warning(
"FindObject",
1638 "No bin %d %s histo in list %s\n",bin,nameH,lst->GetName());
1658 Warning(
"FindObject",
1659 "%s: Anomaluous %d number of events processed in bin %d of list %p",
1660 buff,
int(nrm),bin,lst);
1663 MyPrint(2,
"Normalization: %f", nrm);
1666 if (hst->InheritsFrom(TH1::Class())) {
1667 MyPrint(0,
"Scaling histogram %s by %f", hst->GetName(), nrm);
1668 ((
TH1*)hst)->Scale(1./nrm);
1670 else if (hst->InheritsFrom(THnSparse::Class())) {
1671 THnSparse* spr = (THnSparse*) hst;
1673 int coord[3] = {0,0,0};
1674 for (
Long64_t i = 0; i < spr->GetNbins(); ++i) {
1676 Double_t v = spr->GetBinContent(i, coord);
1677 spr->SetBinContent(coord, v/nrm);
1678 spr->SetBinError(coord,TMath::Sqrt(v)/nrm);
1682 MyPrint(2,
"Flagging %s a scaled", hst->GetName());
1690 MyPrint(2,
"Loading lists from %s (prefix=%s, name=%s)", flName, addPref, nameL);
1696 TFile* fl = TFile::Open(nms.Data());
1698 Error(
"LoadList",
"No file %s\n",nms.Data());
1704 Error(
"LoadList",
"No list %s in file %s\n",nameL,nms.Data());
1708 MyPrint(2,
"Setting name to %s", flName);
1709 lst->SetName(flName);
1710 int nEnt = lst->GetSize();
1712 for (
int i=0;i<nEnt;i++) {
1715 nm += ob->GetName();
1716 MyPrint(2,
" Renaming %40s to %s", ob->GetName(), nm.Data());
1717 ob->SetName(nm.Data());
1724 void GetRatE(
double x,
double xe,
double y,
double ye,
double &rat,
double &rate)
1726 MyGuard(10,
"Calculating ratio of %f +/- %f over %f +/- %f", x, xe, y, ye);
1728 if (TMath::Abs(y)<1e-16 || TMath::Abs(x)<1e-16)
return;
1730 rate = rat*TMath::Sqrt( xe*xe/(x*x) + ye*ye/(y*y));
1731 MyPrint(10,
"Result: %f +/- %f", rat, rate);
1737 MyGuard(1,
"Integrate %s over [%f,%f]", hist->GetName(), xmn, xmx);
1739 TAxis* xax = hist->GetXaxis();
1740 int bmn = xax->FindBin(xmn+
kEps);
if (bmn<1) bmn = 0;
1741 int bmx = xax->FindBin(xmx-
kEps);
1742 val = hist->IntegralAndError(bmn,bmx,err);
1744 if (TMath::Abs( xax->GetXmin() + xax->GetXmax() )<1e-6) {
1745 bmn = xax->FindBin(-xmx+
kEps);
1746 bmx = xax->FindBin(-xmn-
kEps);
1748 val += hist->IntegralAndError(bmn,bmx,errn);
1749 err = TMath::Sqrt(err*err + errn*errn);
1751 MyPrint(1,
"Integral: %f +/- %f", val, err);
1756 const char*
HName(
const char* prefix,
const char* htype)
1760 strh =
"Tr"; strh += prefix; strh +=
"_"; strh += htype;
1767 MyGuard(3,
"Check input list %s for %s", lst->GetName(), dtType);
1771 if (dts==
"Data")
return int( hstat->GetBinContent(
kEvProcData) );
1772 if (dts==
"Mix")
return int( hstat->GetBinContent(
kEvProcMix) );
1773 if (dts==
"Inj")
return int( hstat->GetBinContent(
kEvProcInj) );
1774 if (dts==
"Rot")
return int( hstat->GetBinContent(
kEvProcRot) );
1775 MyPrint(3,
"Unknown process %s statistics is checked. Alowed: Data,Mix,Inj,Rot",dtType);
1782 MyGuard(3,
"Get real min and max of %s", histo->GetName());
1783 TAxis *xax = histo->GetXaxis();
1784 int nbx = xax->GetNbins();
1786 if (histo->InheritsFrom(TH2::Class())) {
1787 TAxis *yax = histo->GetYaxis();
1788 int nby = yax->GetNbins();
1789 for (
int ix=nbx+2;ix--;) {
1790 for (
int iy=nby+2;iy--;) {
1791 double vl = histo->GetBinContent(ix,iy);
1792 if (vl<
kEps)
continue;
1793 if (vl<vmn) vmn = vl;
1794 if (vl>vmx) vmx = vl;
1800 for (
int ix=nbx+2;ix--;) {
1801 double vl = histo->GetBinContent(ix);
1802 if (vl<vmn) vmn = vl;
1803 if (vl>vmx) vmx = vl;
1812 MyGuard(2,
"Correcting %s for vertex efficiency using %s",
1813 hEtaZ->GetName(), hZv->GetName());
1815 int nbEta = hEtaZ->GetNbinsX();
1816 int nbZv = hEtaZ->GetNbinsY();
1819 TAxis* zax = hEtaZ->GetYaxis();
1820 for (
int ibz=1;ibz<=nbZv;ibz++) {
1821 double z = zax->GetBinCenter(ibz);
1822 int izbh = hZv->FindBin(z);
1823 double scl = hZv->GetBinContent(izbh);
1824 double scle = hZv->GetBinError(izbh);
1825 MyPrint(2,
"Vertex correction for z=%f: %f +/- %f", z, scl, scle);
1828 MyPrint(2,
"Did not find ZV weight for Z=%f, stop",z);
1831 for (
int ibe=1;ibe<=nbEta;ibe++) {
1832 double val = hEtaZ->GetBinContent(ibe,ibz);
1833 double err = hEtaZ->GetBinError(ibe,ibz);
1835 double rat = val/scl;
1836 double ratE = (val>0 && scl>0) ? rat*TMath::Sqrt((err*err)/(val*val) + (scle*scle)/(scl*scl) ) : 0.0;
1839 hEtaZ->SetBinContent(ibe,ibz, rat);
1840 hEtaZ->SetBinError(ibe,ibz, ratE);
1848 MyGuard(1,
"Projection of %s - %s", hEtaZ->GetName(), hEtaZ->GetTitle());
1850 int nbEta = hEtaZ->GetNbinsX();
1851 int nbZv = hEtaZ->GetNbinsY();
1852 if (firstbin<1) firstbin = 1;
1853 if (lastbin<firstbin) lastbin = nbZv;
1855 TH1* prj = hEtaZ->ProjectionX(name,firstbin,lastbin,
"e");
1857 MyPrint(2,
"Made projection and reset it");
1858 double *arrV =
new double[nbZv];
1859 double *arrE =
new double[nbZv];
1860 double *arZV =
new double[nbZv];
1861 double *arZE =
new double[nbZv];
1862 double *relE =
new double[nbZv];
1863 int *ind =
new int[nbZv];
1865 TAxis* zax = hEtaZ->GetYaxis();
1866 for (
int ibe=1;ibe<=nbEta;ibe++) {
1869 for (
int ibz=firstbin;ibz<=lastbin;ibz++) {
1870 double val = hEtaZ->GetBinContent(ibe,ibz);
1871 double err = hEtaZ->GetBinError(ibe,ibz);
1872 if (val<1e-9)
continue;
1874 double z = zax->GetBinCenter(ibz);
1875 int izbh = hZv->FindBin(z);
1879 relE[cnt] = err/val;
1880 arZV[cnt] = hZv->GetBinContent(izbh);
1881 arZE[cnt] = hZv->GetBinError(izbh);
1885 TMath::Sort(cnt,relE,ind,kFALSE);
1886 double av=0,ave=0,vsm=0,vsme=0,zsm=0,zsme=0;
1889 for (iu=0;iu<cnt;iu++) {
1891 double rt = TMath::Sqrt(vsme+arrE[j]*arrE[j])/(vsm+ arrV[j]);
1893 MyPrint(10,
" %10s - bin %3d,%3d %9.3f+/-%9.3f (%5.2f%%) [%9.3f+/-%9.3f] "
1895 hEtaZ->GetName(), ibe, j, arrV[j], arrE[j],
1896 100*relE[j], arZV[j], arZE[j], rt, rat);
1897 if (rt>rat)
continue;
1900 vsme+= arrE[j]*arrE[j];
1902 zsme+= arZE[j]*arZE[j];
1907 if (iu==0)
continue;
1911 ave = av*TMath::Sqrt( vsme + zsme );
1913 "%10s - bin %3d (%+6.3f) count=%2d n=%9.3f+/-%9.3f d=%9.3f+/-%9.3f"
1914 " -> %9.3f +/- %9.3f", hEtaZ->GetName(), ibe,
1915 hEtaZ->GetXaxis()->GetBinCenter(ibe), iu, vsm, TMath::Sqrt(vsme),
1916 zsm, TMath::Sqrt(zsme), av, ave);
1918 prj->SetBinContent(ibe, av);
1919 prj->SetBinError(ibe, ave);
1935 MyGuard(2,
"Calculating weighted mean projection of %s from %d to %d",
1936 hEtaZ, firstbin, lastbin);
1938 int nbEta = hEtaZ->GetNbinsX();
1939 int nbZv = hEtaZ->GetNbinsY();
1940 if (firstbin<1) firstbin = 1;
1941 if (lastbin<firstbin) lastbin = nbZv;
1943 MyPrint(2,
"HISTO: %s %s %p | bins: %d %d",hEtaZ->GetName(),hEtaZ->GetTitle(), hEtaZ, firstbin, lastbin);
1944 TArrayD val(nbZv),err(nbZv),prc(nbZv);
1947 TH1* prj = hEtaZ->ProjectionX(name,firstbin,lastbin,
"e");
1949 MyPrint(2,
"Made projection, and reset it");
1950 for (
int ibe=1;ibe<=nbEta;ibe++) {
1955 for (
int ibz=firstbin;ibz<=lastbin;ibz++) {
1956 val[cnt] = hEtaZ->GetBinContent(ibe,ibz);
1957 err[cnt] = hEtaZ->GetBinError(ibe,ibz);
1958 if (!err[cnt]>0)
continue;
1959 valAv += val[cnt]/(err[cnt]*err[cnt]);
1960 errAv += 1./(err[cnt]*err[cnt]);
1964 if (cnt<1)
continue;
1966 errAv = 1./TMath::Sqrt(errAv);
1971 double valFin=0,errFin=0;
1972 while(cntSkip<cnt-1) {
1974 TMath::Sort(cnt,val.GetArray(),ind.GetArray(), kFALSE);
1975 if (cntSkip>-1) err[ind[cntSkip]] = -1;
1978 for (
int ic=0;ic<cnt;ic++) {
1979 double erb = err[ind[ic]];
1980 double vlb = val[ind[ic]];
1981 if (!(erb>0))
continue;
1982 valAv += vlb/(erb*erb);
1983 errAv += 1./(erb*erb);
1986 if (useCnt<1 || !(errAv>0))
break;
1988 errAv = 1./TMath::Sqrt(errAv);
1991 for (
int ic=0;ic<cnt;ic++) prc[ic] = err[ic]>0 ? TMath::Abs(valAv-val[ic])/err[ic] : 1e9;
1993 TMath::Sort(cnt,prc.GetArray(),ind.GetArray(), kFALSE);
1994 useCnt = cnt>10 ? cnt/2 : cnt*0.7;
1995 if (useCnt<1) useCnt = 1;
1998 for (
int ic=0;ic<useCnt;ic++) {
1999 double erb = err[ind[ic]];
2000 double vlb = val[ind[ic]];
2001 if (!(erb>0))
continue;
2002 valAv += vlb/(erb*erb);
2003 errAv += 1./(erb*erb);
2005 if (!(errAv>0))
break;
2007 errAv = 1./TMath::Sqrt(errAv);
2012 for (
int ic=0;ic<cnt;ic++) {
2013 double erb = err[ic];
2014 double vlb = val[ic];
2015 if (!(erb>0))
continue;
2016 double dev = TMath::Abs(valAv-vlb)/erb;
2017 if (rejOutliers>0 && dev>rejOutliers)
continue;
2019 valFin += vlb/(erb*erb);
2020 errFin += 1./(erb*erb);
2023 if (useCnt<1 || !(errFin)>0) {
2028 errFin = 1./TMath::Sqrt(errFin);
2033 printf(
"failed to evaluate eta bin %d\n",ibe);
2039 prj->SetBinContent(ibe,valFin);
2040 prj->SetBinError(ibe,errFin);
2048 MyGuard(2,
"Killing bad (<%f or >%f) bins of %s",
2049 mn, mx, histo->GetName());
2050 int nbx = histo->GetNbinsX();
2051 int nby = histo->GetNbinsY();
2052 for (
int ix=1;ix<=nbx;ix++) {
2053 for (
int iy=1;iy<=nby;iy++) {
2054 double vl = histo->GetBinContent(ix,iy);
2055 if (vl>mx || vl<mn) {
2056 histo->SetBinContent(ix,iy,0);
2057 histo->SetBinError(ix,iy,0);
2061 histo->SetMinimum(mn);
2062 histo->SetMaximum(mx);
2067 Printf(
"Content of %s - %s", h->GetName(), h->GetTitle());
2068 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
2070 for (
Int_t j = 1; j <= h->GetNbinsY(); j++) {
2071 printf(
"%.*f+/-%.*f ",
2072 prec, h->GetBinContent(i,j),
2073 prec, h->GetBinError(i,j));
2081 Printf(
"Content of %s - %s", h->GetName(), h->GetTitle());
2082 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
2083 if (h->GetBinContent(i) <= 1e-6)
continue;
2084 printf(
"%3d (%+6.3f): %.*f+/-%.*f\n", i,
2085 h->GetXaxis()->GetBinCenter(i),
2086 prec, h->GetBinContent(i),
2087 prec, h->GetBinError(i));
const char * HName(const char *prefix, const char *htype)
#define MyGuard(L, F,...)
TLatex * AddLabel(const char *txt, float x=0.1, float y=0.9, int color=kBlack, float size=0.04)
Bool_t creatSpeciesCMacro
void SaveCanvas(TCanvas *canv, const char *path="canv", const Option_t *option="ecn")
void CropHisto(TH1 *histo, int b00, int b01, int b10=-1, int b11=-1)
Bool_t PrepareHistos(int bin, TList *lst, TList *lisMC, Bool_t isMC)
void GetRealMinMax(TH1 *h, double &vmn, double &vmx)
void KillBadBins(TH2 *histo, double mn=-1e50, double mx=1e50)
void PrintH(TH2 *h, Int_t prec=2)
TH1 * ProjectWghMean(TH2 *hEtaZ, const char *name="_px", Int_t firstbin=0, Int_t lastbin=-1, double rejOutliers=6.)
void PrintAndPause(TCanvas *c, const TString &what, Bool_t wait)
_MyGuard(UShort_t lvl, const char *fmt,...)
TH1 * CopyAdd(TH1 *h, const char *name, const char *title, TObjArray *col, Int_t location, Int_t shift)
void _MyPrint(UShort_t lvl, const char *fmt,...)
TH1 * NormalizeBg(TH1 *dataH, TH1 *bgH, double &scl, double &scle)
void CorrectSpectraMultiMCBG(const char *flNameData, const char *flNameMC, const char *unique="", int maxBins=10, Bool_t waitForUser=false, const char *bgType="Comb")
void PlotResults(Bool_t waitForUser)
void Integrate(TH1 *hist, double xmn, double xmx, double &val, double &err)
TH1 * ProjNorm(TH2 *hEtaZ, TH1 *hZv, const char *name="_px", Int_t firstbin=0, Int_t lastbin=-1)
void PlotAlphaBeta(int bin)
Bool_t creatAlphaBetaCMacro
TObject * FindObject(int bin, const char *nameH, const TList *lst, Bool_t normPerEvent=kTRUE)
TList * LoadList(const char *flName, const char *addPref, const char *nameL="clist")
void CorrectForZV(TH2 *hEtaZ, TH1 *hZv)
#define MyPrint(L, F,...)
const double kEtaFitRange
void GetRatE(double x, double xe, double y, double ye, double &rat, double &rate)
Int_t CheckStat(const TList *lst, const char *dtType)
void SetHStyle(TH1 *hst, int col=kRed, int mark=20, float mrsize=0.7)
void ProcessHistos(int bin)