18#include <TDatabasePDG.h>
26#include <TMCProcess.h>
29#include <TObjString.h>
31#include <TParticlePDG.h>
48 if (xmin < 1e-20 || xmax < 1e-20) {
49 Error(
"PairAnalysisHelper::MakeLogBinning",
"For Log binning xmin and xmax must be > 1e-20. Using linear binning "
58 TVectorD* binLim =
new TVectorD(nbinsX + 1);
59 Double_t
first = xmin;
61 Double_t expMax = TMath::Log(last /
first);
62 for (Int_t i = 0; i < nbinsX + 1; ++i) {
63 (*binLim)[i] =
first * TMath::Exp(expMax / nbinsX * (Double_t) i);
80 TVectorD* binLim =
new TVectorD(nbinsX + 1);
81 Double_t
first = xmin;
83 Double_t binWidth = (last -
first) / nbinsX;
84 for (Int_t i = 0; i < nbinsX + 1; ++i) {
85 (*binLim)[i] =
first + binWidth * (Double_t) i;
97 if (limits.IsNull()) {
98 Error(
"PairAnalysisHelper::MakeArbitraryBinning",
"Bin Limit string is empty, cannot add the variable");
102 TObjArray* arr = limits.Tokenize(
",");
103 Int_t nLimits = arr->GetEntries();
105 Error(
"PairAnalysisHelper::MakeArbitraryBinning",
"Need at leas 2 bin limits, cannot add the variable");
110 TVectorD* binLimits =
new TVectorD(nLimits);
111 for (Int_t iLim = 0; iLim < nLimits; ++iLim) {
112 (*binLimits)[iLim] = (
static_cast<TObjString*
>(arr->At(iLim)))->GetString().Atof();
127 TVectorD* binLim =
new TVectorD(nbinsX + 1);
129 TF1 g(
"g",
"gaus", mean - 5 * sigma, mean + 5 * sigma);
130 g.SetParameters(1, mean, sigma);
131 Double_t sum = g.Integral(mean - 5 * sigma, mean + 5 * sigma);
134 TF1 g2(
"g2",
"gaus(0)/[3]", mean - 5 * sigma, mean + 5 * sigma);
135 g2.SetParameters(1, mean, sigma, sum);
139 Double_t epsilon = sigma / 10000;
140 Double_t xt = mean - 5 * sigma;
144 Double_t lim = epsilon;
147 while ((xt += epsilon) <= mean + 5 * sigma) {
151 Double_t cint = g2.Integral(mean - 5 * sigma, xt);
155 if (cint >= lim && pint < lim) {
162 lim = bin * (1. / nbinsX);
164 if (bin == nbinsX) lim = 1. - epsilon;
184 Int_t lastEqualsFirst = (Int_t)(TMath::Abs((*low)[low->GetNrows() - 1] - (*high)[0]) < 1.e-15);
185 TVectorD* binLim =
new TVectorD(low->GetNrows() + high->GetNrows() - lastEqualsFirst);
186 for (Int_t i = 0; i < low->GetNrows(); i++)
187 (*binLim)[i] = (*low)[i];
188 for (Int_t i = 0; i < high->GetNrows() - lastEqualsFirst; i++)
189 (*binLim)[low->GetNrows() + i] = (*high)[i + lastEqualsFirst];
203 if (!
h || stat > 1.)
return 0x0;
207 Double_t from =
h->GetBinLowEdge(1);
210 TArrayD* vBins =
new TArrayD(1 + 1);
211 vBins->AddAt(from, 0);
214 for (Int_t i = 1; i <=
h->GetNbinsX(); i++) {
216 if (
h->GetBinContent(i) == 0.0 &&
h->GetBinError(i) == 0.)
continue;
218 to =
h->GetBinLowEdge(i + 1);
219 cont +=
h->GetBinContent(i);
220 err += (
h->GetBinError(i) *
h->GetBinError(i));
221 vBins->AddAt(to, vEle);
227 if (TMath::Sqrt(err) / cont <= stat
236 vBins->Set(vEle + 1);
240 vBins->AddAt(
h->GetXaxis()->GetXmax(), vBins->GetSize() - 1);
254 TDatabasePDG* pdg =
new TDatabasePDG();
256 TIter next(pdg->ParticleList());
260 while ((p = (TParticlePDG*) next())) {
261 if (TMath::Abs(p->PdgCode()) < 1e+6) {
263 gr.SetPoint(i++, p->PdgCode(), 1.);
267 TVectorD* vec =
new TVectorD(
gr.GetN(),
gr.GetX());
279 Double_t params[10] = {0.};
281 for (Int_t ip = 0; ip < form->GetNpar(); ip++)
282 params[ip] = values[(UInt_t) form->GetParameter(ip)];
283 return (form->EvalPar(0x0, params));
293 TString tform(form->GetExpFormula());
298 tform.ReplaceAll(
"*",
"#upoint");
300 tform.ReplaceAll(
"TMath::",
"");
301 tform.ReplaceAll(
"()",
"");
304 for (Int_t j = 0; j < form->GetNpar(); j++)
316 for (Int_t j = 0; j < form->GetNpar(); j++) {
318 if (j != form->GetNpar() - 1) tform +=
",";
330 TString check(formula);
331 if (check.IsNull())
return 0x0;
332 TFormula* form =
new TFormula(name, formula);
334 if (form->Compile())
return 0x0;
336 for (Int_t i = 0; i < form->GetNpar(); i++) {
351 if (!hLbl) hLbl = hist;
353 TDatabasePDG* pdg = TDatabasePDG::Instance();
354 TAxis* xaxis = hLbl->GetXaxis();
355 for (Int_t i = 1; i < hist->GetNbinsX() + 1; i++) {
357 if (clean && !hist->GetBinContent(i))
continue;
358 Int_t pdgCode = (Int_t) xaxis->GetBinLowEdge(i);
359 TParticlePDG* p = pdg->GetParticle(pdgCode);
361 xaxis->SetBinLabel(i, (p ?
GetPDGlabel(pdgCode) :
""));
364 if (hLbl->GetDimension() == 1)
return;
366 TAxis* yaxis = hLbl->GetYaxis();
367 TString keyY = yaxis->GetName();
368 if (keyY.Contains(
"pdg", TString::kIgnoreCase)) {
369 for (Int_t i = 1; i < hist->GetNbinsY() + 1; i++) {
371 if (clean && !hist->GetBinContent(i))
continue;
372 Int_t pdgCode = (Int_t) yaxis->GetBinLowEdge(i);
373 TParticlePDG* p = pdg->GetParticle(pdgCode);
375 yaxis->SetBinLabel(i, (p ?
GetPDGlabel(pdgCode) :
""));
387 TString name = TDatabasePDG::Instance()->GetParticle(pdg)->GetName();
388 name.ReplaceAll(
"dd_1_bar",
"primary");
389 name.ReplaceAll(
"proton",
"p");
407 name.ReplaceAll(
"delta",
"#delta");
408 name.ReplaceAll(
"gamma",
"#gamma");
409 name.ReplaceAll(
"psi",
"#psi");
410 name.ReplaceAll(
"sigma",
"#sigma");
411 name.ReplaceAll(
"xi",
"#xi");
412 name.ReplaceAll(
"lambda",
"#lambda");
413 name.ReplaceAll(
"omega",
"#omega");
414 name.ReplaceAll(
"eta",
"#eta");
415 name.ReplaceAll(
"tau",
"#tau");
416 name.ReplaceAll(
"phi",
"#phi");
417 name.ReplaceAll(
"upsilon",
"#upsilon");
418 name.ReplaceAll(
"nu",
"#nu");
419 name.ReplaceAll(
"mu",
"#mu");
420 name.ReplaceAll(
"pi",
"#pi");
421 name.ReplaceAll(
"rho",
"#rho");
424 if (name.Contains(
"anti")) {
425 name.ReplaceAll(
"anti",
"#bar{");
428 else if (name.Contains(
"_bar")) {
429 name.ReplaceAll(
"_bar",
"}");
430 name.Prepend(
"#bar{");
433 name.ReplaceAll(
"+",
"^{+}");
434 name.ReplaceAll(
"-",
"^{-}");
435 name.ReplaceAll(
"0",
"^{0}");
436 name.ReplaceAll(
"_s",
"_{s}");
437 name.ReplaceAll(
"_c",
"_{c}");
438 name.ReplaceAll(
"_b",
"_{b}");
439 name.ReplaceAll(
"_1",
"_{1}");
441 name.ReplaceAll(
"/psi",
"/#psi");
452 TAxis* xaxis = hist->GetXaxis();
453 for (Int_t i = 1; i < hist->GetNbinsX() + 1; i++) {
454 xaxis->SetBinLabel(i, TMCProcessName[i - 1]);
456 xaxis->LabelsOption(
"v");
458 xaxis->SetTitleOffset(3.6);
459 gPad->SetTopMargin(0.01);
460 gPad->SetBottomMargin(0.4);
484 Int_t bin, binx, biny, binz;
485 Int_t xfirst =
h->GetXaxis()->GetFirst();
486 Int_t xlast =
h->GetXaxis()->GetLast();
487 Int_t yfirst =
h->GetYaxis()->GetFirst();
488 Int_t ylast =
h->GetYaxis()->GetLast();
489 Int_t zfirst =
h->GetZaxis()->GetFirst();
490 Int_t zlast =
h->GetZaxis()->GetLast();
491 Double_t minimum = FLT_MAX, value = 0., error = 0.;
492 for (binz = zfirst; binz <= zlast; binz++) {
493 for (biny = yfirst; biny <= ylast; biny++) {
494 for (binx = xfirst; binx <= xlast; binx++) {
495 bin =
h->GetBin(binx, biny, binz);
496 value =
h->GetBinContent(bin);
497 error =
h->GetBinError(bin);
499 if (gPad->GetLogy() && (value - error) <= 0.)
continue;
500 if (error > value * 0.9)
continue;
501 if (inclErr) value -=
h->GetBinError(bin);
502 if (value < minimum && TMath::Abs(
h->GetBinError(bin) - 1.e-15) > 1.e-15) { minimum = value; }
515 Int_t bin, binx, biny, binz;
516 Int_t xfirst =
h->GetXaxis()->GetFirst();
517 Int_t xlast =
h->GetXaxis()->GetLast();
518 Int_t yfirst =
h->GetYaxis()->GetFirst();
519 Int_t ylast =
h->GetYaxis()->GetLast();
520 Int_t zfirst =
h->GetZaxis()->GetFirst();
521 Int_t zlast =
h->GetZaxis()->GetLast();
522 Double_t maximum = -1. * FLT_MAX, value = 0., error = 0.;
523 for (binz = zfirst; binz <= zlast; binz++) {
524 for (biny = yfirst; biny <= ylast; biny++) {
525 for (binx = xfirst; binx <= xlast; binx++) {
526 bin =
h->GetBin(binx, biny, binz);
527 value =
h->GetBinContent(bin);
528 error =
h->GetBinError(bin);
529 if (inclErr) value +=
h->GetBinError(bin);
530 if (value > maximum && TMath::Abs(error - 1.e-15) > 1.e-15) { maximum = value; }
543 if (p < 0.0 || p > 1.)
return -1.;
544 Int_t nbinsX = h1->GetNbinsX();
545 Int_t nbinsY = h1->GetNbinsY();
546 Int_t nbinsZ = h1->GetNbinsZ();
547 Int_t nbins = (nbinsX * (nbinsY ? nbinsY : 1) * (nbinsZ ? nbinsZ : 1));
554 for (Int_t i = 1; i <= nbins; i++) {
555 h1->GetBinXYZ(i, xbin, ybin, zbin);
556 if (xbin < h1->GetXaxis()->GetFirst() || xbin > h1->GetXaxis()->GetLast())
continue;
557 if (ybin < h1->GetYaxis()->GetFirst() || ybin > h1->GetYaxis()->GetLast())
continue;
558 Double_t con = h1->GetBinContent(i);
559 Double_t err = h1->GetBinError(i);
562 val[nfilled] = con + (h1->GetDimension() < 2 ? err : 0.0);
566 if (nfilled == 0)
return -1.;
567 TMath::Sort(nfilled, val, idx, kFALSE);
568 Int_t
pos = (Int_t)((Double_t) nfilled * p);
571 return val[idx[
pos]];
579 TH2* hsum = (TH2*)
h->Clone(
"SliceInts");
581 for (Int_t ix = 0; ix <= hsum->GetNbinsX() + 1; ix++) {
582 Double_t ysum =
h->Integral(ix, ix, 0, hsum->GetNbinsY() + 1);
583 for (Int_t iy = 0; iy <= hsum->GetNbinsY() + 1; iy++) {
584 hsum->SetBinContent(ix, iy, ysum);
599 Int_t xstart = (reverse ?
h->GetNbinsX() + 1 : 0 - 1);
600 Int_t xend = (reverse ? 0 :
h->GetNbinsX() + 1 + 1);
601 Int_t xincr = (reverse ? -1 : +1);
603 Double_t integral = 1.;
604 for (Int_t iy = 0; iy <=
h->GetNbinsY() + 1; iy++) {
605 if (norm) integral =
h->Integral(0,
h->GetNbinsX() + 1, iy, iy);
608 for (Int_t ix = xstart; ix != xend; ix += xincr) {
609 cumInt +=
h->GetBinContent(ix, iy);
610 h->SetBinContent(ix, iy, cumInt / integral);
621 Int_t xstart = (reverse ?
h->GetNbinsX() + 1 : 0 - 1);
622 Int_t xend = (reverse ? 0 :
h->GetNbinsX() + 1 + 1);
623 Int_t xincr = (reverse ? -1 : +1);
625 Double_t integral = 1.;
626 if (norm) integral =
h->Integral(0,
h->GetNbinsX() + 1);
629 for (Int_t ix = xstart; ix != xend; ix += xincr) {
630 cumInt +=
h->GetBinContent(ix);
631 h->SetBinContent(ix, cumInt / integral);
641 for (Int_t i = 0; i < arrhist->GetEntriesFast(); i++) {
642 if (!ref.CompareTo(arrhist->UncheckedAt(i)->GetTitle())) {
return arrhist->UncheckedAt(i); }
658 Bool_t bfnd = kFALSE;
663 bfnd = ((TMath::Abs(value * TMath::Power(10, precision)) / 1e6
664 - TMath::Floor(TMath::Abs(value * TMath::Power(10, precision)) / 1e6))
668 if (!bfnd) precision++;
static TString GetModuleNameCaps(ECbmModuleId moduleId)
Data class with information on a STS local track.
static const char * GetValueName(Int_t i)
static const char * GetValueLabel(Int_t i)
Int_t GetPrecision(Double_t value)
void NormalizeSlicesY(TH2 *h)
TString GetFormulaName(TFormula *form)
TObject * FindObjectByTitle(TObjArray *arrhist, TString ref)
TVectorD * MakePdgBinning()
void SetGEANTBinLabels(TH1 *hist)
TArrayD * MakeStatBinLimits(TH1 *h, Double_t stat)
TString GetFormulaTitle(TFormula *form)
Double_t GetQuantile(TH1 *h1, Double_t p=0.5)
void CumulateSlicesX(TH2 *h, Bool_t reverse=kFALSE, Bool_t norm=kFALSE)
Double_t GetContentMinimum(TH1 *h, Bool_t inclErr=kTRUE)
Double_t GetContentMaximum(TH1 *h, Bool_t inclErr=kTRUE)
TFormula * GetFormula(const char *name, const char *formula)
TVectorD * CombineBinning(TVectorD *low, TVectorD *high)
Double_t EvalFormula(TFormula *form, const Double_t *values)
TVectorD * MakeLinBinning(Int_t nbinsX, Double_t xmin, Double_t xmax)
TVectorD * MakeGausBinning(Int_t nbinsX, Double_t mean, Double_t sigma)
void SetPDGBinLabels(TH1 *hist, Bool_t clean)
TString GetDetName(ECbmModuleId det)
void Cumulate(TH1 *h, Bool_t reverse=kFALSE, Bool_t norm=kFALSE)
TString GetPDGlabel(Int_t pdg)
TVectorD * MakeArbitraryBinning(const char *bins)
TVectorD * MakeLogBinning(Int_t nbinsX, Double_t xmin, Double_t xmax)
TH1 * GetFirstHistogram()