12 #ifndef ALITRACKLETAODUTILS_H
13 #define ALITRACKLETAODUTILS_H
19 # include <TParameter.h>
23 # include <TDirectory.h>
24 # include <THashList.h>
25 # include <TProfile.h>
26 # include <TProfile2D.h>
27 # include <TDatabasePDG.h>
398 static TH1*
GetH1(TDirectory* parent,
const char* name,
Bool_t verb=
true);
428 static TH2*
GetH2(TDirectory* parent,
const char* name,
Bool_t verb=
true);
448 static TH3*
GetH3(TDirectory* parent,
const char* name,
Bool_t verb=
true);
471 return GetP1(parent, name, verb);
492 static THStack*
GetHS(TDirectory* parent,
const char* name,
Bool_t verb=
true);
522 static TDirectory*
GetT(TDirectory* parent,
const char* name,
Bool_t verb=
true);
571 const char* newName=0,
585 const char* newName=0,
599 const char* newName=0,
950 static TH1*
RatioH(
const TH1* num,
const TH1* denom,
const char* name=0);
1044 if (a1->GetNbins() != a2->GetNbins()) {
1045 ::Warning(
"CheckAxisNBins",
"Incompatible number %s bins: %d vs %d",
1046 which, a1->GetNbins(), a2->GetNbins());
1056 if (!TMath::AreEqualRel(a1->GetXmin(), a2->GetXmin(),1.E-12) ||
1057 !TMath::AreEqualRel(a1->GetXmax(), a2->GetXmax(),1.E-12)) {
1058 Warning(
"CheckAxisLimits",
1059 "Limits of %s axis incompatible [%f,%f] vs [%f,%f]", which,
1060 a1->GetXmin(), a1->GetXmax(), a2->GetXmin(), a2->GetXmax());
1070 const TArrayD * h1Array = a1->GetXbins();
1071 const TArrayD * h2Array = a2->GetXbins();
1072 Int_t fN = h1Array->fN;
1073 if ( fN == 0 )
return true;
1074 if (h2Array->fN != fN) {
1076 Warning(
"CheckAxisBins",
"Not equal number of %s bin limits: %d vs %d",
1077 which, fN, h2Array->fN);
1081 for (
int i = 0; i < fN; ++i) {
1082 if (!TMath::AreEqualRel(h1Array->GetAt(i),h2Array->GetAt(i),1E-10)) {
1083 Warning(
"CheckAxisBins",
1084 "%s limit # %3d incompatible: %f vs %f",
1085 which, i, h1Array->GetAt(i),h2Array->GetAt(i));
1098 THashList *l1 = (
const_cast<TAxis*
>(a1))->GetLabels();
1099 THashList *l2 = (
const_cast<TAxis*
>(a2))->GetLabels();
1101 if (!l1 && !l2)
return true;
1103 Warning(
"CheckAxisLabels",
"Difference in %s labels: %p vs %p",
1108 if (l1->GetSize() != l2->GetSize()) {
1109 Warning(
"CheckAxisLabels",
"Different number of %s labels: %d vs %d",
1110 which, l1->GetSize(), l2->GetSize());
1113 for (
int i = 1; i <= a1->GetNbins(); ++i) {
1114 TString label1 = a1->GetBinLabel(i);
1115 TString label2 = a2->GetBinLabel(i);
1116 if (label1 != label2) {
1117 Warning(
"CheckAxisLabels",
"%s label # %d not the same: '%s' vs '%s'",
1118 which, i, label1.Data(), label2.Data());
1141 if (h1 == h2)
return true;
1143 if (h1->GetDimension() != h2->GetDimension() ) {
1144 Warning(
"CheckConsistency",
1145 "%s and %s have different dimensions %d vs %d",
1146 h1->GetName(), h2->GetName(),
1147 h1->GetDimension(), h2->GetDimension());
1150 Int_t dim = h1->GetDimension();
1152 Bool_t alsoLbls = (h1->GetEntries() != 0 && h2->GetEntries() != 0);
1153 if (!
CheckAxis(
"X", h1->GetXaxis(), h2->GetXaxis(), alsoLbls))
return false;
1155 !
CheckAxis(
"Y", h1->GetYaxis(), h2->GetYaxis(), alsoLbls))
return false;
1157 !
CheckAxis(
"Z", h1->GetZaxis(), h2->GetZaxis(), alsoLbls))
return false;
1165 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
1168 Double_t dr = (dc > 1e-6 ? de/dc : 0);
1169 for (
Int_t j = 1; j <= h->GetNbinsY(); j++) {
1170 Double_t nc = h->GetBinContent(i,j);
1171 Double_t ne = h->GetBinError (i,j);
1172 Double_t ns = (nc > 0 ? ne/nc : 0);
1174 Double_t se = sc*TMath::Sqrt(ns*ns+dr*dr);
1176 h->SetBinContent(i,j,sc);
1177 h->SetBinError (i,j,se);
1187 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
1188 for (
Int_t j = 1; j <= h->GetNbinsY(); j++) {
1193 Double_t se = sc*TMath::Sqrt(s*s+rr*rr);
1195 h->SetBinContent(i,j,sc);
1196 h->SetBinError (i,j,se);
1206 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
1211 Double_t se = sc*TMath::Sqrt(s*s+rr*rr);
1213 h->SetBinContent(i,sc);
1214 h->SetBinError (i,se);
1226 if (verb) ::Warning(
"GetO",
"No parent container passed");
1229 TObject* o = parent->FindObject(name);
1231 if (verb) ::Warning(
"GetO",
"Object \"%s\" not found in \"%s\"",
1232 name, parent->GetName());
1237 if (!o->IsA()->InheritsFrom(cls)) {
1238 if (verb) ::Warning(
"GetO",
"\"%s\" is an object of class %s, not %s",
1239 name, o->ClassName(), cls->GetName());
1251 if (!verb) ::Warning(
"GetO",
"No parent directory passed");
1254 TObject* o = parent->Get(name);
1256 if (verb) ::Warning(
"GetO",
"Object \"%s\" not found in \"%s\"",
1257 name, parent->GetName());
1262 if (!o->IsA()->InheritsFrom(cls)) {
1263 if (verb) ::Warning(
"GetO",
"\"%s\" is an object of class %s, not %s",
1264 name, o->ClassName(), cls->GetName());
1272 return static_cast<TH1*
>(
GetO(parent, name, TH1::Class(), v));
1277 return static_cast<TH1*
>(
GetO(parent, name, TH1::Class(), v));
1282 return static_cast<TH2*
>(
GetO(parent, name, TH2::Class(), v));
1287 return static_cast<TH2*
>(
GetO(parent, name, TH2::Class(), v));
1292 return static_cast<TH3*
>(
GetO(parent, name, TH3::Class(), v));
1297 return static_cast<TH3*
>(
GetO(parent, name, TH3::Class(), v));
1303 return static_cast<TProfile*
>(
GetO(parent, name, TProfile::Class(), v));
1309 return static_cast<TProfile2D*
>(
GetO(parent, name, TProfile2D::Class(), v));
1315 return static_cast<THStack*
>(
GetO(parent, name, THStack::Class(), v));
1321 return static_cast<THStack*
>(
GetO(parent, name, THStack::Class(), v));
1327 return static_cast<Container*
>(
GetO(parent, name, Container::Class(), v));
1333 return static_cast<Container*
>(
GetO(parent, name, Container::Class(), v));
1339 TDirectory* d = parent->GetDirectory(name);
1341 if (v) ::Warning(
"GetO",
"Directory \"%s\" not found in \"%s\"",
1342 name, parent->GetName());
1386 const char* newName,
1389 TH1* orig =
GetH1(parent, name, v);
1390 if (!orig)
return 0;
1391 TH1* ret =
static_cast<TH1*
>(orig->Clone(newName ? newName : name));
1392 ret->SetDirectory(0);
1398 const char* newName,
1401 TH2* orig =
GetH2(parent, name, v);
1402 if (!orig)
return 0;
1403 TH2* ret =
static_cast<TH2*
>(orig->Clone(newName ? newName : name));
1404 ret->SetDirectory(0);
1410 const char* newName,
1413 TH3* orig =
GetH3(parent, name, v);
1414 if (!orig)
return 0;
1415 TH3* ret =
static_cast<TH3*
>(orig->Clone(newName ? newName : name));
1416 ret->SetDirectory(0);
1423 if (!src || !dest)
return;
1424 dest->SetMarkerStyle(src->GetMarkerStyle());
1425 dest->SetMarkerColor(src->GetMarkerColor());
1426 dest->SetMarkerSize (src->GetMarkerSize());
1427 dest->SetLineStyle (src->GetLineStyle());
1428 dest->SetLineColor (src->GetLineColor());
1429 dest->SetLineWidth (src->GetLineWidth());
1430 dest->SetFillStyle (src->GetFillStyle());
1431 dest->SetFillColor (src->GetFillColor());
1446 Int_t nx = xAxis.GetNbins();
1447 if (t.IsNull()) t = xAxis.GetTitle();
1448 if (xAxis.GetXbins() && xAxis.GetXbins()->GetArray())
1449 ret =
new TH1D(n,t,nx,xAxis.GetXbins()->GetArray());
1451 ret =
new TH1D(n,t,nx,xAxis.GetXmin(),xAxis.GetXmax());
1453 ret->SetXTitle(xAxis.GetTitle());
1454 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
1455 ret->SetDirectory(0);
1456 ret->SetLineColor(color);
1457 ret->SetMarkerColor(color);
1458 ret->SetFillColor(kWhite);
1459 ret->SetFillStyle(0);
1460 ret->SetMarkerStyle(style);
1461 if (const_cast<TAxis&>(xAxis).GetLabels()) {
1462 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
1463 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
1468 ret->SetMarkerSize(1.4);
1472 ret->SetMarkerSize(1.2);
1489 Int_t nx = xAxis.GetNbins();
1490 if (t.IsNull()) t = xAxis.GetTitle();
1491 if (xAxis.GetXbins() && xAxis.GetXbins()->GetArray())
1492 ret =
new TProfile(n,t,nx,xAxis.GetXbins()->GetArray());
1494 ret =
new TProfile(n,t,nx,xAxis.GetXmin(),xAxis.GetXmax());
1496 ret->SetXTitle(xAxis.GetTitle());
1497 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
1498 ret->SetDirectory(0);
1499 ret->SetLineColor(color);
1500 ret->SetMarkerColor(color);
1501 ret->SetFillColor(kWhite);
1502 ret->SetFillStyle(0);
1503 ret->SetMarkerStyle(style);
1504 if (const_cast<TAxis&>(xAxis).GetLabels()) {
1505 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
1506 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
1511 ret->SetMarkerSize(1.4);
1515 ret->SetMarkerSize(1.2);
1533 Int_t nx = xAxis.GetNbins();
1534 Int_t ny = yAxis.GetNbins();
1535 const Double_t* xb = (xAxis.GetXbins() && xAxis.GetXbins()->GetArray() ?
1536 xAxis.GetXbins()->GetArray() : 0);
1537 const Double_t* yb = (yAxis.GetXbins() && yAxis.GetXbins()->GetArray() ?
1538 yAxis.GetXbins()->GetArray() : 0);
1540 t.Form(
"%s vs %s", yAxis.GetTitle(), xAxis.GetTitle());
1542 if (yb) ret =
new TH2D(n,t,nx,xb,ny,yb);
1543 else ret =
new TH2D(n,t,
1545 ny,yAxis.GetXmin(),yAxis.GetXmax());
1548 if (yb) ret =
new TH2D(n,t,
1549 nx,xAxis.GetXmin(),xAxis.GetXmax(),
1551 else ret =
new TH2D(n,t,
1552 nx,xAxis.GetXmin(),xAxis.GetXmax(),
1553 ny,yAxis.GetXmin(),yAxis.GetXmax());
1556 ret->SetXTitle(xAxis.GetTitle());
1557 ret->SetYTitle(yAxis.GetTitle());
1558 ret->SetLineColor(color);
1559 ret->SetMarkerColor(color);
1560 ret->SetFillColor(color);
1561 ret->SetMarkerStyle(style);
1562 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
1563 static_cast<const TAttAxis&
>(yAxis).Copy(*(ret->GetYaxis()));
1564 ret->SetDirectory(0);
1565 if (const_cast<TAxis&>(xAxis).GetLabels()) {
1566 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
1567 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
1569 if (const_cast<TAxis&>(yAxis).GetLabels()) {
1570 for (
Int_t i = 1; i <= yAxis.GetNbins(); i++)
1571 ret->GetYaxis()->SetBinLabel(i, yAxis.GetBinLabel(i));
1589 Int_t nx = xAxis.GetNbins();
1590 Int_t ny = yAxis.GetNbins();
1591 Int_t nz = zAxis.GetNbins();
1592 Double_t* xb = (xAxis.GetXbins() && xAxis.GetXbins()->GetArray() ?
1593 const_cast<Double_t*
>(xAxis.GetXbins()->GetArray()) : 0);
1594 Double_t* yb = (yAxis.GetXbins() && yAxis.GetXbins()->GetArray() ?
1595 const_cast<Double_t*
>(yAxis.GetXbins()->GetArray()) : 0);
1596 Double_t* zb = (zAxis.GetXbins() && zAxis.GetXbins()->GetArray() ?
1597 const_cast<Double_t*
>(zAxis.GetXbins()->GetArray()) : 0);
1599 t.Form(
"%s vs %s vs %s",
1600 zAxis.GetTitle(), yAxis.GetTitle(), xAxis.GetTitle());
1601 if (xb || yb || zb) {
1606 Double_t dx = (xAxis.GetXmax()-xAxis.GetXmin())/nx;
1607 xb[0] = xAxis.GetXmin();
1608 for (
Int_t i = 1; i <= nx; i++) xb[i] = xb[i-1]+dx;
1612 Double_t dy = (yAxis.GetXmax()-yAxis.GetXmin())/ny;
1613 yb[0] = yAxis.GetXmin();
1614 for (
Int_t i = 1; i <= ny; i++) yb[i] = yb[i-1]+dy;
1618 Double_t dz = (zAxis.GetXmax()-zAxis.GetXmin())/nz;
1619 zb[0] = zAxis.GetXmin();
1620 for (
Int_t i = 1; i <= nz; i++) zb[i] = zb[i-1]+dz;
1622 ret =
new TH3D(n,t,nx,xb,ny,yb,nz,zb);
1626 nx, xAxis.GetXmin(), xAxis.GetXmax(),
1627 ny, yAxis.GetXmin(), yAxis.GetXmax(),
1628 nz, zAxis.GetXmin(), zAxis.GetXmax());
1631 ret->SetXTitle(xAxis.GetTitle());
1632 ret->SetYTitle(yAxis.GetTitle());
1633 ret->SetZTitle(zAxis.GetTitle());
1634 ret->SetLineColor(color);
1635 ret->SetMarkerColor(color);
1636 ret->SetFillColor(color);
1637 ret->SetMarkerStyle(style);
1638 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
1639 static_cast<const TAttAxis&
>(yAxis).Copy(*(ret->GetYaxis()));
1640 static_cast<const TAttAxis&
>(zAxis).Copy(*(ret->GetZaxis()));
1641 ret->SetDirectory(0);
1642 if (const_cast<TAxis&>(xAxis).GetLabels()) {
1643 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
1644 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
1646 if (const_cast<TAxis&>(yAxis).GetLabels()) {
1647 for (
Int_t i = 1; i <= yAxis.GetNbins(); i++)
1648 ret->GetYaxis()->SetBinLabel(i, yAxis.GetBinLabel(i));
1650 if (const_cast<TAxis&>(zAxis).GetLabels()) {
1651 for (
Int_t i = 1; i <= zAxis.GetNbins(); i++)
1652 ret->GetZaxis()->SetBinLabel(i, zAxis.GetBinLabel(i));
1668 TProfile2D* ret = 0;
1669 Int_t nx = xAxis.GetNbins();
1670 Int_t ny = yAxis.GetNbins();
1671 const Double_t* xb = (xAxis.GetXbins() && xAxis.GetXbins()->GetArray() ?
1672 xAxis.GetXbins()->GetArray() : 0);
1673 const Double_t* yb = (yAxis.GetXbins() && yAxis.GetXbins()->GetArray() ?
1674 yAxis.GetXbins()->GetArray() : 0);
1676 t.Form(
"%s vs %s", yAxis.GetTitle(), xAxis.GetTitle());
1678 if (yb) ret =
new TProfile2D(n,t,nx,xb,ny,yb);
1679 else ret =
new TProfile2D(n,t,
1681 ny,yAxis.GetXmin(),yAxis.GetXmax());
1684 if (yb) ret =
new TProfile2D(n,t,
1685 nx,xAxis.GetXmin(),xAxis.GetXmax(),
1687 else ret =
new TProfile2D(n,t,
1688 nx,xAxis.GetXmin(),xAxis.GetXmax(),
1689 ny,yAxis.GetXmin(),yAxis.GetXmax());
1692 ret->SetXTitle(xAxis.GetTitle());
1693 ret->SetYTitle(yAxis.GetTitle());
1694 ret->SetLineColor(color);
1695 ret->SetMarkerColor(color);
1696 ret->SetFillColor(color);
1697 ret->SetMarkerStyle(style);
1698 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
1699 static_cast<const TAttAxis&
>(yAxis).Copy(*(ret->GetYaxis()));
1700 ret->SetDirectory(0);
1701 if (const_cast<TAxis&>(xAxis).GetLabels()) {
1702 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
1703 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
1705 if (const_cast<TAxis&>(yAxis).GetLabels()) {
1706 for (
Int_t i = 1; i <= yAxis.GetNbins(); i++)
1707 ret->GetYaxis()->SetBinLabel(i, yAxis.GetBinLabel(i));
1715 if (title && title[0] !=
'\0') axis.SetTitle(title);
1716 axis. SetNdivisions(210);
1717 axis. SetLabelFont(42);
1718 axis. SetLabelSize(0.03);
1719 axis. SetLabelOffset(0.005);
1720 axis. SetLabelColor(kBlack);
1721 axis. SetTitleOffset(1);
1722 axis. SetTitleFont(42);
1723 axis. SetTitleSize(0.04);
1724 axis. SetTitleColor(kBlack);
1725 axis. SetTickLength(0.03);
1726 axis. SetAxisColor(kBlack);
1732 if (ret.GetXbins()->GetArray()) {
1733 TArrayD bins(*ret.GetXbins());
1734 for (
Int_t i = 0; i < bins.GetSize(); i++) bins[i] *= fact;
1735 ret.Set(ret.GetNbins(), bins.GetArray());
1738 ret.Set(ret.GetNbins(), fact*ret.GetXmin(), fact*ret.GetXmax());
1745 axis.Set(n, borders);
1754 Bool_t isRange =
false, isUnit =
false;
1755 if (s[0] ==
'r' || s[0] ==
'R') {
1759 if (s[0] ==
'u' || s[0] ==
'U') {
1764 TArrayD bins(tokens->GetEntries());
1765 TObjString* token = 0;
1768 while ((token = static_cast<TObjString*>(next()))) {
1769 Double_t v = token->String().Atof();
1775 if (bins.GetSize() > 1)
1776 SetAxis(axis,
Int_t(bins[1]-bins[0]), bins[0], bins[1]);
1782 if (bins.GetSize() > 2)
1783 SetAxis(axis, nBins, bins[1], bins[2]);
1785 SetAxis(axis, nBins, bins[1]);
1788 SetAxis(axis, bins.GetSize()-1,bins.GetArray());
1802 SetAxis(axis, n, -TMath::Abs(m), +TMath::Abs(m));
1809 printf(
" %17s axis: ", alt ? alt : axis.GetTitle());
1810 if (axis.GetXbins() && axis.GetXbins()->GetArray()) {
1811 printf(
"%.*f", nSig, axis.GetBinLowEdge(1));
1812 for (
Int_t i = 1; i <= axis.GetNbins(); i++)
1813 printf(
":%.*f", nSig, axis.GetBinUpEdge(i));
1816 printf(
"%d bins between %.*f and %.*f",
1817 axis.GetNbins(), nSig, axis.GetXmin(),nSig,axis.GetXmax());
1824 ::Warning(
"ScaleToIPz",
"Nothing to scale");
1828 ::Warning(
"ScaleToIPz",
"Nothing to scale by");
1831 TH2* ret =
static_cast<TH2*
>(h->Clone());
1832 ret->SetDirectory(0);
1833 if (!ipZ)
return ret;
1834 for (
Int_t iy = 1; iy <= ret->GetNbinsY(); iy++) {
1835 Double_t z = ret->GetYaxis()->GetBinCenter(iy);
1836 Int_t bin = ipZ->GetXaxis()->FindBin(z);
1837 Double_t nEv = ipZ->GetBinContent(bin);
1838 Double_t eEv = ipZ->GetBinError (bin);
1839 Double_t esc = (nEv > 0 ? 1./nEv : 0);
1841 for (
Int_t ix = 1; ix <= ret->GetNbinsX(); ix++) {
1843 Double_t e = ret->GetBinError (ix,iy);
1848 if (full) se = sc * TMath::Sqrt(r*r+rE2);
1850 Double_t scl = 1 / ret->GetXaxis()->GetBinWidth(ix);
1851 ret->SetBinContent(ix, iy, scl*sc);
1852 ret->SetBinError (ix, iy, scl*se);
1861 ::Warning(
"ScaleToIPz",
"Nothing to scale");
1865 ::Warning(
"ScaleToIPz",
"Nothing to scale by");
1868 TH3* ret =
static_cast<TH3*
>(h->Clone());
1869 ret->SetDirectory(0);
1870 if (!ipZ)
return ret;
1871 for (
Int_t iz = 1; iz <= ret->GetNbinsZ(); iz++) {
1872 Double_t z = ret->GetZaxis()->GetBinCenter(iz);
1873 Int_t bin = ipZ->GetXaxis()->FindBin(z);
1874 Double_t nEv = ipZ->GetBinContent(bin);
1875 Double_t eEv = ipZ->GetBinError (bin);
1876 Double_t esc = (nEv > 0 ? 1./nEv : 0);
1878 for (
Int_t iy = 1; iy <= ret->GetNbinsY(); iy++) {
1879 for (
Int_t ix = 1; ix <= ret->GetNbinsX(); ix++) {
1880 Double_t c = ret->GetBinContent(ix,iy,iz);
1881 Double_t e = ret->GetBinError (ix,iy,iz);
1886 if (full) se = sc * TMath::Sqrt(r*r+rE2);
1888 Double_t scl = 1 / ret->GetXaxis()->GetBinWidth(ix);
1889 ret->SetBinContent(ix, iy, iz, scl*sc);
1890 ret->SetBinError (ix, iy, iz, scl*se);
1899 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
1900 for (
Int_t j = 1; j <= h->GetNbinsZ(); j++) {
1901 Double_t scale = etaIPzScale->GetBinContent(i,j);
1902 Double_t scaleE = etaIPzScale->GetBinError (i,j);
1903 Double_t q = (scale > 0 ? scaleE / scale : 0);
1904 for (
Int_t k = 1; k <= h->GetNbinsY(); k++) {
1906 Double_t e = h->GetBinError (i,k,j);
1909 Double_t v = w * TMath::Sqrt(r*r + q*q);
1910 h->SetBinContent(i,k,j,w);
1911 h->SetBinError (i,k,j,v);
1913 Printf(
"%2d,%3d,%2d=(%9g+/-%9g)*(%9g+/-%9g)=(%9g+/-%9g)",
1914 i,k,j,c,e,scale,scaleE,w,v);
1925 TH2* etaDelta =
static_cast<TH2*
>(h->Project3D(
"yx e"));
1926 etaDelta->SetName(
"etaDelta");
1927 etaDelta->SetTitle(h->GetTitle());
1928 etaDelta->SetDirectory(0);
1929 etaDelta->SetZTitle(
"d^{2}#it{N}/(d#etad#Delta)");
1933 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
1934 for (
Int_t j = 1; j <= h->GetNbinsY(); j++) {
1938 for (
Int_t k = 1; k <= h->GetNbinsZ(); k++) {
1940 Double_t e = h->GetBinError (i,j,k);
1941 if (c < 1e-6 || e/c > 1)
continue;
1952 if (sumw < 1e-6)
continue;
1954 etaDelta->SetBinContent(i,j,sum/sumw);
1955 etaDelta->SetBinError (i,j,TMath::Sqrt(1/sumw));
1957 etaDelta->SetBinContent(i,j,sum/cnt);
1958 etaDelta->SetBinError (i,j,TMath::Sqrt(sumw)/cnt);
1970 Warning(
"ProjectDelta",
"No histogram passed");
1973 TH1* delta = h->ProjectionY(
"delta");
1974 delta->SetDirectory(0);
1975 delta->SetTitle(h->GetTitle());
1976 delta->SetYTitle(
"d#it{N}/d#Delta");
1977 delta->Scale(1./h->GetNbinsX());
1984 Warning(
"ProjectDelta",
"No histogram passed");
1989 delta->SetDirectory(0);
1990 tmp->SetDirectory(0);
2005 Int_t nIPz = h->GetNbinsY();
2006 Int_t nEta = h->GetNbinsX();
2007 TH1* p = h->ProjectionX(name,1,nIPz,
"e");
2008 TH2* mask = (other ? other : h);
2012 p->SetYTitle(Form(
"#LT%s#GT", h->GetYaxis()->GetTitle()));
2014 for (
Int_t etaBin = 1; etaBin <= nEta; etaBin++) {
2020 for (
Int_t ipzBin = 1; ipzBin <= nIPz; ipzBin++) {
2021 Double_t bc = mask->GetBinContent(etaBin, ipzBin);
2022 if (bc < 1e-9)
continue;
2023 Double_t be = mask->GetBinError (etaBin, ipzBin);
2024 if (TMath::IsNaN(be))
continue;
2035 TMath::Sort(j, hr.fArray, idx.fArray,
false);
2044 for (k = 0; k < j; k++) {
2046 Int_t ipzBin = hb[l];
2049 Double_t x = TMath::Sqrt(nsume+hee*hee)/(nsum+hvv);
2054 Double_t by = mask->GetYaxis()->GetBinCenter(ipzBin);
2055 Int_t ib = ipz ? ipz->FindBin(by) : 0;
2057 nsum += h->GetBinContent(etaBin, ipzBin);
2058 nsume += TMath::Power(h->GetBinError(etaBin, ipzBin), 2);
2061 dsum += !ipz ? 1 : ipz->GetBinContent(ib);
2062 dsume += !ipz ? 0 : TMath::Power(ipz->GetBinError(ib),2);
2065 if (k == 0 || n == 0) {
2067 ::Warning(
"Average",
"Eta bin # %3d has no data",etaBin);
2070 Double_t norm = (mode > 0 ? n : dsum);
2075 if (mode==2) ave = TMath::Sqrt(nsume)/n;
2076 else ave = av*TMath::Sqrt(rne+rde);
2077 p->SetBinContent(etaBin, av);
2078 p->SetBinError (etaBin, ave);
2080 if (mode == 0) p->Scale(1,
"width");
2088 ::Warning(
"CloneAndAdd",
"Nothing to clone");
2092 if (copy->IsA()->InheritsFrom(TH1::Class()))
2094 static_cast<TH1*>(copy)->SetDirectory(0);
2107 Int_t bMin = h->FindBin(min+epsilon);
2108 Int_t bMax = h->FindBin(max-epsilon);
2109 if (bMin < 1) bMin = 0;
2110 Double_t val = h->IntegralAndError(bMin, bMax, err);
2112 if (TMath::Abs(h->GetXaxis()->GetXmin()+h->GetXaxis()->GetXmax())>=epsilon)
2117 bMin = h->FindBin(-min+epsilon);
2118 bMax = h->FindBin(-max-epsilon);
2119 val += h->IntegralAndError(bMin, bMax, err2);
2120 err = TMath::Sqrt(err*err+err2*err2);
2130 if (TMath::Abs(n) < 1e-16 || TMath::Abs(d) < 1e-16)
return 0;
2132 er = TMath::Sqrt(en*en/n/n + ed*ed/d/d);
2142 if (TMath::Abs(n) < 1e-16 || TMath::Abs(d) < 1e-16)
return 0;
2144 e2r = (e2n/n/n + e2d/d/d);
2152 if (!num || !denom) {
2153 ::Warning(
"RatioH",
"Numerator (%p) or denominator (%p) missing",
2159 TH1* ratio =
static_cast<TH1*
>(num->Clone(name ? name : num->GetName()));
2160 ratio->SetDirectory(0);
2161 ratio->SetMinimum(-1111);
2162 ratio->SetMaximum(-1111);
2163 ratio->GetListOfFunctions()->Clear();
2164 ratio->Divide(denom);
2165 ratio->SetYTitle(Form(
"%s / %s",
2166 num ->GetYaxis()->GetTitle(),
2167 denom->GetYaxis()->GetTitle()));
2168 ratio->SetTitle(Form(
"%s / %s", num ->GetTitle(), denom->GetTitle()));
2178 for (
Int_t ix = 1; ix <= h->GetNbinsX(); ix++) {
2179 for (
Int_t iy = 1; iy <= h->GetNbinsY(); iy++) {
2180 for (
Int_t iz = 1; iz <= h->GetNbinsZ(); iz++) {
2181 Int_t bin = h->GetBin(ix,iy,iz);
2182 Double_t c = h->GetBinContent(bin);
2184 if (c == 0 && ignoreZero)
continue;
2185 min = TMath::Min(min, c-e);
2186 max = TMath::Max(max, c+e);
2198 TIter next(stack->GetHists());
2200 while ((h = static_cast<TH1*>(next()))) {
2202 min = TMath::Min(min, h->GetMinimum());
2203 max = TMath::Max(max, h->GetMaximum());
2205 stack->SetMinimum(min);
2206 stack->SetMaximum(max);
2212 static Int_t codes[] = {
2261 static Int_t nCodes =
sizeof(codes) /
sizeof(
Int_t);
2262 static Int_t* sorted = 0;
2264 if (sorted)
return sorted;
2266 sorted =
new Int_t[nCodes];
2268 TMath::Sort(nCodes, codes, idx,
false);
2269 for (
Int_t i = 0; i < nCodes; i++) sorted[i] = codes[idx[i]];
2276 Color_t& c, Style_t& s)
2286 case -1: c=kPink +7; s=20; nme=
"?";
break;
2287 case 11: c=kBlack +0; s=20; nme=
"e^{-}";
break;
2288 case 13: c=kBlack +0; s=21; nme=
"#mu^{-}";
break;
2289 case 22: c=kBlack +0; s=22; nme=
"#gamma";
break;
2290 case 111: c=kRed +2; s=20; nme=
"#pi^{0}";
break;
2291 case 211: c=kRed +2; s=21; nme=
"#pi^{+}";
break;
2292 case 213: c=kRed +2; s=22; nme=
"#rho^{+}";
break;
2293 case 113: c=kRed +2; s=23; nme=
"#rho^{0}";
break;
2294 case 223: c=kRed +2; s=24; nme=
"#omega";
break;
2295 case 321: c=kBlue +2; s=20; nme=
"K^{+}";
break;
2296 case 323: c=kBlue +2; s=21; nme=
"K^{*+}";
break;
2297 case 310: c=kBlue +2; s=22; nme=
"K^{0}_{S}";
break;
2298 case 130: c=kBlue +2; s=23; nme=
"K^{0}_{L}";
break;
2299 case 311: c=kBlue +2; s=24; nme=
"K^{0}";
break;
2300 case 313: c=kBlue +2; s=25; nme=
"K^{*}";
break;
2301 case 221: c=kBlue +2; s=26; nme=
"#eta";
break;
2302 case 333: c=kBlue +2; s=27; nme=
"#varphi";
break;
2303 case 331: c=kBlue +2; s=28; nme=
"#eta'";
break;
2304 case 411: c=kGreen +2; s=20; nme=
"D^{+}";
break;
2305 case 413: c=kGreen +2; s=21; nme=
"D^{*+}";
break;
2306 case 421: c=kGreen +2; s=22; nme=
"D^{0}";
break;
2307 case 423: c=kGreen +2; s=23; nme=
"D^{*0}";
break;
2308 case 431: c=kGreen +2; s=24; nme=
"D_{s}^{+}";
break;
2309 case 433: c=kGreen +2; s=25; nme=
"D_{s}^{*+}";
break;
2310 case 2212: c=kMagenta+2; s=20; nme=
"p";
break;
2311 case 2112: c=kMagenta+2; s=21; nme=
"n";
break;
2312 case 2114: c=kMagenta+2; s=22; nme=
"#Delta^{0}";
break;
2313 case 1114: c=kMagenta+2; s=23; nme=
"#Delta^{-}";
break;
2314 case 2214: c=kMagenta+2; s=24; nme=
"#Delta^{+}";
break;
2315 case 2224: c=kMagenta+2; s=25; nme=
"#Delta^{++}";
break;
2316 case 3112: c=kCyan +2; s=20; nme=
"#Sigma^{-}";
break;
2317 case 3222: c=kCyan +2; s=21; nme=
"#Sigma^{+}";
break;
2318 case 3114: c=kCyan +2; s=22; nme=
"#Sigma^{*-}";
break;
2319 case 3224: c=kCyan +2; s=23; nme=
"#Sigma^{*+}";
break;
2320 case 3312: c=kCyan +2; s=24; nme=
"#Xi^{-}";
break;
2321 case 3314: c=kCyan +2; s=25; nme=
"#Xi^{*-}";
break;
2322 case 3122: c=kCyan +2; s=26; nme=
"#Lambda";
break;
2323 case 3212: c=kCyan +2; s=27; nme=
"#Sigma^{0}";
break;
2324 case 3214: c=kCyan +2; s=28; nme=
"#Sigma^{*0}";
break;
2325 case 3322: c=kCyan +2; s=29; nme=
"#Xi^{0}";
break;
2326 case 3324: c=kCyan +2; s=30; nme=
"#Xi^{*0}";
break;
2327 case 4214: c=kYellow +2; s=20; nme=
"#Sigma^{*+}_{c}";
break;
2328 case 4224: c=kYellow +2; s=21; nme=
"#Sigma^{*++}_{c}";
break;
2329 case 4122: c=kYellow +2; s=22; nme=
"#Lambda^{+}_{c}";
break;
2330 case 4114: c=kYellow +2; s=23; nme=
"#Sigma^{*0}_{c}";
break;
2331 case 4132: c=kYellow +2; s=24; nme=
"#Xi^{0}_{c}";
break;
2332 case 4314: c=kYellow +2; s=25; nme=
"#Xi^{*0}_{c}";
break;
2333 case 1000000000:c=kPink +2; s=20; nme=
"Nuclei";
break;
2334 default: c=kGray; s=1; nme.Form(
"%d",pdg);
break;
2343 Int_t apdg = TMath::Abs(pdg);
2344 Int_t idx = TMath::BinarySearch(size, array, apdg);
2345 if (idx == size - 1)
return idx+1;
2346 if (array[idx] != apdg)
return size+1;
2353 static TAxis* axis = 0;
2354 if (axis)
return *axis;
2358 axis =
new TAxis(size+1, +.5, size+1.5);
2360 for (
Int_t i = 1; i <= size; i++) {
2362 axis->SetBinLabel(i, Form(
"%d", pdg));
2368 axis->SetBinLabel(size+1,
"-1");
2375 TFile*
file = TFile::Open(filename,
"READ");
2377 ::Warning(
"OpenFile",
"Failed to open \"%s\"", filename);
2386 tmp.Form(
"cent%03dd%02d_%03dd%02d",
2394 const Color_t
cc[] = { kMagenta+2,
2405 Color_t tc = cc[bin % 10];
2414 Int_t binC =
const_cast<TAxis&
>(axis).FindBin(avgC);
virtual ~AliTrackletAODUtils()
static TProfile * GetP1(Container *parent, const char *name, Bool_t verb=true)
static Double_t RatioE2(Double_t n, Double_t e2n, Double_t d, Double_t e2d, Double_t &e2r)
static const TAxis & PdgAxis()
static void PdgAttr(Int_t pdg, TString &nme, Color_t &c, Style_t &s)
static TH2 * Make2D(Container *c, const TString &name, const TString &title, Color_t color, Style_t style, const TAxis &xAxis, const TAxis &yAxis)
static TDirectory * GetT(TDirectory *parent, const char *name, Bool_t verb=true)
static void ScaleAxis(TAxis &ret, Double_t fact=1)
static void PrintAxis(const TAxis &axis, Int_t nSig=2, const char *alt=0)
static void SetAxis(TAxis &axis, Int_t n, Double_t *borders)
static TFile * OpenFile(const char *filename)
static TProfile2D * Make2P(Container *c, const TString &name, const TString &title, Color_t color, Style_t style, const TAxis &xAxis, const TAxis &yAxis)
static Bool_t CheckAxisBins(const char *which, const TAxis *a1, const TAxis *a2)
static TH1 * GetH1(Container *parent, const char *name, Bool_t verb=true)
static const char * CentName(Double_t c1, Double_t c2)
static Bool_t CheckAxisLabels(const char *which, const TAxis *a1, const TAxis *a2)
static TH3 * ScaleDelta(TH3 *h, TH2 *scale)
static Bool_t CheckAxis(const char *which, const TAxis *a1, const TAxis *a2, Bool_t alsoLbls)
static Int_t GetI(Container *parent, const char *name, Int_t def=-1, Bool_t verb=true)
static TH2 * ScaleToIPz(TH2 *h, TH1 *ipZ, Bool_t full=false)
static TH2 * ProjectEtaDelta(TH3 *h)
static TH1 * AverageOverIPz(TH2 *h, const char *name, UShort_t mode, TH1 *ipz, TH2 *mask=0, Bool_t verb=true)
static TH1 * ProjectDelta(TH2 *h)
static Double_t GetD(Container *parent, const char *name, Double_t def=-1, Bool_t verb=true)
static TH3 * Make3D(Container *c, const TString &name, const TString &title, Color_t color, Style_t style, const TAxis &xAxis, const TAxis &yAxis, const TAxis &zAxis)
static Bool_t CheckConsistency(const TH1 *h1, const TH1 *h2)
static TH1 * Scale(TH1 *h, Double_t x, Double_t xe)
static Int_t GetB(Container *parent, const char *name, Bool_t def=false, Bool_t verb=true)
static void FixMinMax(TH1 *h, Bool_t ignoreZero=true)
static TProfile2D * GetP2(Container *parent, const char *name, Bool_t verb=true)
static TH1 * ProjectDeltaFull(TH3 *h)
static Int_t * PdgArray(Int_t &size)
static Double_t Integrate(TH1 *h, Double_t min, Double_t max, Double_t &err)
static Bool_t CheckAxisNBins(const char *which, const TAxis *a1, const TAxis *a2)
ClassDef(AliTrackletAODUtils, 1)
static Bool_t CheckAxisLimits(const char *which, const TAxis *a1, const TAxis *a2)
static Color_t CentColor(const TAxis &axis, Double_t c1, Double_t c2)
static TH2 * CopyH2(Container *parent, const char *name, const char *newName=0, Bool_t verb=true)
static TH1 * CopyH1(Container *parent, const char *name, const char *newName=0, Bool_t verb=true)
static TH3 * GetH3(Container *parent, const char *name, Bool_t verb=true)
static Double_t RatioE(Double_t n, Double_t en, Double_t d, Double_t ed, Double_t &er)
static TH2 * GetH2(Container *parent, const char *name, Bool_t verb=true)
static TObject * GetO(Container *parent, const char *name, TClass *cls=0, Bool_t verb=true)
static THStack * GetHS(Container *parent, const char *name, Bool_t verb=true)
static Container * GetC(Container *parent, const char *name, Bool_t verb=true)
static Int_t PdgBin(Int_t pdg)
static TH3 * CopyH3(Container *parent, const char *name, const char *newName=0, Bool_t verb=true)
static TObject * CloneAndAdd(Container *c, TObject *o)
static TH1 * RatioH(const TH1 *num, const TH1 *denom, const char *name=0)
static TH1 * Make1D(Container *c, const TString &name, const TString &title, Color_t color, Style_t style, const TAxis &xAxis)
static TProfile * Make1P(Container *c, const TString &name, const TString &title, Color_t color, Style_t style, const TAxis &xAxis)
static void FixAxis(TAxis &axis, const char *title=0)
static TProfile * GetP(Container *parent, const char *name, Bool_t verb=true)
static void CopyAttr(const TH1 *src, TH1 *dest)