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>
199 static TH1*
GetH1(TDirectory* parent,
const char* name,
Bool_t verb=
true);
229 static TH2*
GetH2(TDirectory* parent,
const char* name,
Bool_t verb=
true);
249 static TH3*
GetH3(TDirectory* parent,
const char* name,
Bool_t verb=
true);
272 return GetP1(parent, name, verb);
293 static THStack*
GetHS(TDirectory* parent,
const char* name,
Bool_t verb=
true);
323 static TDirectory*
GetT(TDirectory* parent,
const char* name,
Bool_t verb=
true);
372 const char* newName=0,
386 const char* newName=0,
400 const char* newName=0,
756 static TH1*
RatioH(
const TH1* num,
const TH1* denom,
const char* name=0);
884 static void Format(
TString& out,
const char* format, va_list ap);
898 if (a1->GetNbins() != a2->GetNbins()) {
899 ::Warning(
"CheckAxisNBins",
"Incompatible number %s bins: %d vs %d",
900 which, a1->GetNbins(), a2->GetNbins());
910 if (TMath::AreEqualAbs(a1->GetXmin(), a2->GetXmin(), 1.e-3) &&
911 TMath::AreEqualAbs(a1->GetXmax(), a2->GetXmax(), 1.e-3))
return true;
912 if (!TMath::AreEqualRel(a1->GetXmin(), a2->GetXmin(),1.E-12) ||
913 !TMath::AreEqualRel(a1->GetXmax(), a2->GetXmax(),1.E-12)) {
914 Warning(
"CheckAxisLimits",
915 "Limits of %s axis incompatible [%f,%f] vs [%f,%f]", which,
916 a1->GetXmin(), a1->GetXmax(), a2->GetXmin(), a2->GetXmax());
926 const TArrayD * h1Array = a1->GetXbins();
927 const TArrayD * h2Array = a2->GetXbins();
928 Int_t fN = h1Array->fN;
929 if ( fN == 0 )
return true;
930 if (h2Array->fN != fN) {
932 Warning(
"CheckAxisBins",
"Not equal number of %s bin limits: %d vs %d",
933 which, fN, h2Array->fN);
937 for (
int i = 0; i < fN; ++i) {
938 if (TMath::AreEqualAbs(h1Array->GetAt(i),
939 h2Array->GetAt(i), 1.e-3))
continue;
940 if (!TMath::AreEqualRel(h1Array->GetAt(i),h2Array->GetAt(i),1E-10)) {
941 Warning(
"CheckAxisBins",
942 "%s limit # %3d incompatible: %f vs %f",
943 which, i, h1Array->GetAt(i),h2Array->GetAt(i));
956 THashList *l1 = (
const_cast<TAxis*
>(a1))->GetLabels();
957 THashList *l2 = (
const_cast<TAxis*
>(a2))->GetLabels();
959 if (!l1 && !l2)
return true;
961 Warning(
"CheckAxisLabels",
"Difference in %s labels: %p vs %p",
966 if (l1->GetSize() != l2->GetSize()) {
967 Warning(
"CheckAxisLabels",
"Different number of %s labels: %d vs %d",
968 which, l1->GetSize(), l2->GetSize());
971 for (
int i = 1; i <= a1->GetNbins(); ++i) {
972 TString label1 = a1->GetBinLabel(i);
973 TString label2 = a2->GetBinLabel(i);
974 if (label1 != label2) {
975 Warning(
"CheckAxisLabels",
"%s label # %d not the same: '%s' vs '%s'",
976 which, i, label1.Data(), label2.Data());
989 if (a1->GetNbins() == 0 && a2->GetNbins() == 0)
return true;
1000 if (h1 == h2)
return true;
1002 if (h1->GetDimension() != h2->GetDimension() ) {
1003 Warning(
"CheckConsistency",
1004 "%s and %s have different dimensions %d vs %d",
1005 h1->GetName(), h2->GetName(),
1006 h1->GetDimension(), h2->GetDimension());
1009 Int_t dim = h1->GetDimension();
1011 Bool_t alsoLbls = (h1->GetEntries() != 0 && h2->GetEntries() != 0);
1012 if (!
CheckAxis(
"X", h1->GetXaxis(), h2->GetXaxis(), alsoLbls))
return false;
1014 !
CheckAxis(
"Y", h1->GetYaxis(), h2->GetYaxis(), alsoLbls))
return false;
1016 !
CheckAxis(
"Z", h1->GetZaxis(), h2->GetZaxis(), alsoLbls))
return false;
1024 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
1027 Double_t dr = (dc > 1e-6 ? de/dc : 0);
1028 for (
Int_t j = 1; j <= h->GetNbinsY(); j++) {
1029 Double_t nc = h->GetBinContent(i,j);
1030 Double_t ne = h->GetBinError (i,j);
1031 Double_t ns = (nc > 0 ? ne/nc : 0);
1033 Double_t se = sc*TMath::Sqrt(ns*ns+dr*dr);
1035 h->SetBinContent(i,j,sc);
1036 h->SetBinError (i,j,se);
1046 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
1047 for (
Int_t j = 1; j <= h->GetNbinsY(); j++) {
1052 Double_t se = sc*TMath::Sqrt(s*s+rr*rr);
1054 h->SetBinContent(i,j,sc);
1055 h->SetBinError (i,j,se);
1065 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
1070 Double_t se = sc*TMath::Sqrt(s*s+rr*rr);
1072 h->SetBinContent(i,sc);
1073 h->SetBinError (i,se);
1085 if (verb) ::Warning(
"GetO",
"No parent container passed");
1088 TObject* o = parent->FindObject(name);
1090 if (verb) ::Warning(
"GetO",
"Object \"%s\" not found in \"%s\"",
1091 name, parent->GetName());
1096 if (!o->IsA()->InheritsFrom(cls)) {
1097 if (verb) ::Warning(
"GetO",
"\"%s\" is an object of class %s, not %s",
1098 name, o->ClassName(), cls->GetName());
1110 if (!verb) ::Warning(
"GetO",
"No parent directory passed");
1113 TObject* o = parent->Get(name);
1115 if (verb) ::Warning(
"GetO",
"Object \"%s\" not found in \"%s\"",
1116 name, parent->GetName());
1121 if (!o->IsA()->InheritsFrom(cls)) {
1122 if (verb) ::Warning(
"GetO",
"\"%s\" is an object of class %s, not %s",
1123 name, o->ClassName(), cls->GetName());
1131 return static_cast<TH1*
>(
GetO(parent, name, TH1::Class(), v));
1136 return static_cast<TH1*
>(
GetO(parent, name, TH1::Class(), v));
1141 return static_cast<TH2*
>(
GetO(parent, name, TH2::Class(), v));
1146 return static_cast<TH2*
>(
GetO(parent, name, TH2::Class(), v));
1151 return static_cast<TH3*
>(
GetO(parent, name, TH3::Class(), v));
1156 return static_cast<TH3*
>(
GetO(parent, name, TH3::Class(), v));
1162 return static_cast<TProfile*
>(
GetO(parent, name, TProfile::Class(), v));
1168 return static_cast<TProfile2D*
>(
GetO(parent, name, TProfile2D::Class(), v));
1174 return static_cast<THStack*
>(
GetO(parent, name, THStack::Class(), v));
1180 return static_cast<THStack*
>(
GetO(parent, name, THStack::Class(), v));
1186 return static_cast<Container*
>(
GetO(parent, name, Container::Class(), v));
1192 return static_cast<Container*
>(
GetO(parent, name, Container::Class(), v));
1199 if (v) ::Warning(
"GetT",
"No parent directory passed");
1202 TDirectory* d = parent->GetDirectory(name);
1204 if (v) ::Warning(
"GetT",
"Directory \"%s\" not found in \"%s\"",
1205 name, parent->GetName());
1249 const char* newName,
1252 TH1* orig =
GetH1(parent, name, v);
1253 if (!orig)
return 0;
1254 TH1* ret =
static_cast<TH1*
>(orig->Clone(newName ? newName : name));
1255 ret->SetDirectory(0);
1261 const char* newName,
1264 TH2* orig =
GetH2(parent, name, v);
1265 if (!orig)
return 0;
1266 TH2* ret =
static_cast<TH2*
>(orig->Clone(newName ? newName : name));
1267 ret->SetDirectory(0);
1273 const char* newName,
1276 TH3* orig =
GetH3(parent, name, v);
1277 if (!orig)
return 0;
1278 TH3* ret =
static_cast<TH3*
>(orig->Clone(newName ? newName : name));
1279 ret->SetDirectory(0);
1286 if (!src || !dest)
return;
1287 dest->SetMarkerStyle(src->GetMarkerStyle());
1288 dest->SetMarkerColor(src->GetMarkerColor());
1289 dest->SetMarkerSize (src->GetMarkerSize());
1290 dest->SetLineStyle (src->GetLineStyle());
1291 dest->SetLineColor (src->GetLineColor());
1292 dest->SetLineWidth (src->GetLineWidth());
1293 dest->SetFillStyle (src->GetFillStyle());
1294 dest->SetFillColor (src->GetFillColor());
1309 Int_t nx = xAxis.GetNbins();
1310 if (t.IsNull()) t = xAxis.GetTitle();
1311 if (xAxis.GetXbins() && xAxis.GetXbins()->GetArray())
1312 ret =
new TH1D(n,t,nx,xAxis.GetXbins()->GetArray());
1314 ret =
new TH1D(n,t,nx,xAxis.GetXmin(),xAxis.GetXmax());
1316 ret->SetXTitle(xAxis.GetTitle());
1317 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
1318 ret->SetDirectory(0);
1319 ret->SetLineColor(color);
1320 ret->SetMarkerColor(color);
1321 ret->SetFillColor(kWhite);
1322 ret->SetFillStyle(0);
1323 ret->SetMarkerStyle(style);
1324 if (const_cast<TAxis&>(xAxis).GetLabels()) {
1325 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
1326 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
1331 ret->SetMarkerSize(1.4);
1335 ret->SetMarkerSize(1.2);
1352 Int_t nx = xAxis.GetNbins();
1353 if (t.IsNull()) t = xAxis.GetTitle();
1354 if (xAxis.GetXbins() && xAxis.GetXbins()->GetArray())
1355 ret =
new TProfile(n,t,nx,xAxis.GetXbins()->GetArray());
1357 ret =
new TProfile(n,t,nx,xAxis.GetXmin(),xAxis.GetXmax());
1359 ret->SetXTitle(xAxis.GetTitle());
1360 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
1361 ret->SetDirectory(0);
1362 ret->SetLineColor(color);
1363 ret->SetMarkerColor(color);
1364 ret->SetFillColor(kWhite);
1365 ret->SetFillStyle(0);
1366 ret->SetMarkerStyle(style);
1367 if (const_cast<TAxis&>(xAxis).GetLabels()) {
1368 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
1369 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
1374 ret->SetMarkerSize(1.4);
1378 ret->SetMarkerSize(1.2);
1396 Int_t nx = xAxis.GetNbins();
1397 Int_t ny = yAxis.GetNbins();
1398 const Double_t* xb = (xAxis.GetXbins() && xAxis.GetXbins()->GetArray() ?
1399 xAxis.GetXbins()->GetArray() : 0);
1400 const Double_t* yb = (yAxis.GetXbins() && yAxis.GetXbins()->GetArray() ?
1401 yAxis.GetXbins()->GetArray() : 0);
1403 t.Form(
"%s vs %s", yAxis.GetTitle(), xAxis.GetTitle());
1405 if (yb) ret =
new TH2D(n,t,nx,xb,ny,yb);
1406 else ret =
new TH2D(n,t,
1408 ny,yAxis.GetXmin(),yAxis.GetXmax());
1411 if (yb) ret =
new TH2D(n,t,
1412 nx,xAxis.GetXmin(),xAxis.GetXmax(),
1414 else ret =
new TH2D(n,t,
1415 nx,xAxis.GetXmin(),xAxis.GetXmax(),
1416 ny,yAxis.GetXmin(),yAxis.GetXmax());
1419 ret->SetXTitle(xAxis.GetTitle());
1420 ret->SetYTitle(yAxis.GetTitle());
1421 ret->SetLineColor(color);
1422 ret->SetMarkerColor(color);
1423 ret->SetFillColor(color);
1424 ret->SetMarkerStyle(style);
1425 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
1426 static_cast<const TAttAxis&
>(yAxis).Copy(*(ret->GetYaxis()));
1427 ret->SetDirectory(0);
1428 if (const_cast<TAxis&>(xAxis).GetLabels()) {
1429 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
1430 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
1432 if (const_cast<TAxis&>(yAxis).GetLabels()) {
1433 for (
Int_t i = 1; i <= yAxis.GetNbins(); i++)
1434 ret->GetYaxis()->SetBinLabel(i, yAxis.GetBinLabel(i));
1452 Int_t nx = xAxis.GetNbins();
1453 Int_t ny = yAxis.GetNbins();
1454 Int_t nz = zAxis.GetNbins();
1455 Double_t* xb = (xAxis.GetXbins() && xAxis.GetXbins()->GetArray() ?
1456 const_cast<Double_t*
>(xAxis.GetXbins()->GetArray()) : 0);
1457 Double_t* yb = (yAxis.GetXbins() && yAxis.GetXbins()->GetArray() ?
1458 const_cast<Double_t*
>(yAxis.GetXbins()->GetArray()) : 0);
1459 Double_t* zb = (zAxis.GetXbins() && zAxis.GetXbins()->GetArray() ?
1460 const_cast<Double_t*
>(zAxis.GetXbins()->GetArray()) : 0);
1462 t.Form(
"%s vs %s vs %s",
1463 zAxis.GetTitle(), yAxis.GetTitle(), xAxis.GetTitle());
1464 if (xb || yb || zb) {
1469 Double_t dx = (xAxis.GetXmax()-xAxis.GetXmin())/nx;
1470 xb[0] = xAxis.GetXmin();
1471 for (
Int_t i = 1; i <= nx; i++) xb[i] = xb[i-1]+dx;
1475 Double_t dy = (yAxis.GetXmax()-yAxis.GetXmin())/ny;
1476 yb[0] = yAxis.GetXmin();
1477 for (
Int_t i = 1; i <= ny; i++) yb[i] = yb[i-1]+dy;
1481 Double_t dz = (zAxis.GetXmax()-zAxis.GetXmin())/nz;
1482 zb[0] = zAxis.GetXmin();
1483 for (
Int_t i = 1; i <= nz; i++) zb[i] = zb[i-1]+dz;
1485 ret =
new TH3D(n,t,nx,xb,ny,yb,nz,zb);
1489 nx, xAxis.GetXmin(), xAxis.GetXmax(),
1490 ny, yAxis.GetXmin(), yAxis.GetXmax(),
1491 nz, zAxis.GetXmin(), zAxis.GetXmax());
1494 ret->SetXTitle(xAxis.GetTitle());
1495 ret->SetYTitle(yAxis.GetTitle());
1496 ret->SetZTitle(zAxis.GetTitle());
1497 ret->SetLineColor(color);
1498 ret->SetMarkerColor(color);
1499 ret->SetFillColor(color);
1500 ret->SetMarkerStyle(style);
1501 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
1502 static_cast<const TAttAxis&
>(yAxis).Copy(*(ret->GetYaxis()));
1503 static_cast<const TAttAxis&
>(zAxis).Copy(*(ret->GetZaxis()));
1504 ret->SetDirectory(0);
1505 if (const_cast<TAxis&>(xAxis).GetLabels()) {
1506 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
1507 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
1509 if (const_cast<TAxis&>(yAxis).GetLabels()) {
1510 for (
Int_t i = 1; i <= yAxis.GetNbins(); i++)
1511 ret->GetYaxis()->SetBinLabel(i, yAxis.GetBinLabel(i));
1513 if (const_cast<TAxis&>(zAxis).GetLabels()) {
1514 for (
Int_t i = 1; i <= zAxis.GetNbins(); i++)
1515 ret->GetZaxis()->SetBinLabel(i, zAxis.GetBinLabel(i));
1531 TProfile2D* ret = 0;
1532 Int_t nx = xAxis.GetNbins();
1533 Int_t ny = yAxis.GetNbins();
1534 const Double_t* xb = (xAxis.GetXbins() && xAxis.GetXbins()->GetArray() ?
1535 xAxis.GetXbins()->GetArray() : 0);
1536 const Double_t* yb = (yAxis.GetXbins() && yAxis.GetXbins()->GetArray() ?
1537 yAxis.GetXbins()->GetArray() : 0);
1539 t.Form(
"%s vs %s", yAxis.GetTitle(), xAxis.GetTitle());
1541 if (yb) ret =
new TProfile2D(n,t,nx,xb,ny,yb);
1542 else ret =
new TProfile2D(n,t,
1544 ny,yAxis.GetXmin(),yAxis.GetXmax());
1547 if (yb) ret =
new TProfile2D(n,t,
1548 nx,xAxis.GetXmin(),xAxis.GetXmax(),
1550 else ret =
new TProfile2D(n,t,
1551 nx,xAxis.GetXmin(),xAxis.GetXmax(),
1552 ny,yAxis.GetXmin(),yAxis.GetXmax());
1555 ret->SetXTitle(xAxis.GetTitle());
1556 ret->SetYTitle(yAxis.GetTitle());
1557 ret->SetLineColor(color);
1558 ret->SetMarkerColor(color);
1559 ret->SetFillColor(color);
1560 ret->SetMarkerStyle(style);
1561 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
1562 static_cast<const TAttAxis&
>(yAxis).Copy(*(ret->GetYaxis()));
1563 ret->SetDirectory(0);
1564 if (const_cast<TAxis&>(xAxis).GetLabels()) {
1565 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
1566 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
1568 if (const_cast<TAxis&>(yAxis).GetLabels()) {
1569 for (
Int_t i = 1; i <= yAxis.GetNbins(); i++)
1570 ret->GetYaxis()->SetBinLabel(i, yAxis.GetBinLabel(i));
1578 if (title && title[0] !=
'\0') axis.SetTitle(title);
1579 axis. SetNdivisions(210);
1580 axis. SetLabelFont(42);
1581 axis. SetLabelSize(0.03);
1582 axis. SetLabelOffset(0.005);
1583 axis. SetLabelColor(kBlack);
1584 axis. SetTitleOffset(1);
1585 axis. SetTitleFont(42);
1586 axis. SetTitleSize(0.04);
1587 axis. SetTitleColor(kBlack);
1588 axis. SetTickLength(0.03);
1589 axis. SetAxisColor(kBlack);
1595 if (ret.GetXbins()->GetArray()) {
1596 TArrayD bins(*ret.GetXbins());
1597 for (
Int_t i = 0; i < bins.GetSize(); i++) bins[i] *= fact;
1598 ret.Set(ret.GetNbins(), bins.GetArray());
1601 ret.Set(ret.GetNbins(), fact*ret.GetXmin(), fact*ret.GetXmax());
1608 axis.Set(n, borders);
1617 Bool_t isRange =
false, isUnit =
false;
1618 if (s[0] ==
'r' || s[0] ==
'R') {
1622 if (s[0] ==
'u' || s[0] ==
'U') {
1627 TArrayD bins(tokens->GetEntries());
1628 TObjString* token = 0;
1631 while ((token = static_cast<TObjString*>(next()))) {
1632 Double_t v = token->String().Atof();
1638 if (bins.GetSize() > 1)
1639 SetAxis(axis,
Int_t(bins[1]-bins[0]), bins[0], bins[1]);
1645 if (bins.GetSize() > 2)
1646 SetAxis(axis, nBins, bins[1], bins[2]);
1648 SetAxis(axis, nBins, bins[1]);
1651 SetAxis(axis, bins.GetSize()-1,bins.GetArray());
1665 SetAxis(axis, n, -TMath::Abs(m), +TMath::Abs(m));
1672 printf(
" %17s axis: ", alt ? alt : axis.GetTitle());
1673 if (axis.GetXbins() && axis.GetXbins()->GetArray()) {
1674 printf(
"%.*f", nSig, axis.GetBinLowEdge(1));
1675 for (
Int_t i = 1; i <= axis.GetNbins(); i++)
1676 printf(
":%.*f", nSig, axis.GetBinUpEdge(i));
1679 printf(
"%d bins between %.*f and %.*f",
1680 axis.GetNbins(), nSig, axis.GetXmin(),nSig,axis.GetXmax());
1687 ::Warning(
"ScaleToIPz",
"Nothing to scale");
1691 ::Warning(
"ScaleToIPz",
"Nothing to scale by");
1694 TH2* ret =
static_cast<TH2*
>(h->Clone());
1695 ret->SetDirectory(0);
1696 if (!ipZ)
return ret;
1697 for (
Int_t iy = 1; iy <= ret->GetNbinsY(); iy++) {
1698 Double_t z = ret->GetYaxis()->GetBinCenter(iy);
1699 Int_t bin = ipZ->GetXaxis()->FindBin(z);
1700 Double_t nEv = ipZ->GetBinContent(bin);
1701 Double_t eEv = ipZ->GetBinError (bin);
1702 Double_t esc = (nEv > 0 ? 1./nEv : 0);
1704 for (
Int_t ix = 1; ix <= ret->GetNbinsX(); ix++) {
1706 Double_t e = ret->GetBinError (ix,iy);
1711 if (full) se = sc * TMath::Sqrt(r*r+rE2);
1713 Double_t scl = 1 / ret->GetXaxis()->GetBinWidth(ix);
1714 ret->SetBinContent(ix, iy, scl*sc);
1715 ret->SetBinError (ix, iy, scl*se);
1724 ::Warning(
"ScaleToIPz",
"Nothing to scale");
1728 ::Warning(
"ScaleToIPz",
"Nothing to scale by");
1731 TH3* ret =
static_cast<TH3*
>(h->Clone());
1732 ret->SetDirectory(0);
1733 if (!ipZ)
return ret;
1734 for (
Int_t iz = 1; iz <= ret->GetNbinsZ(); iz++) {
1735 Double_t z = ret->GetZaxis()->GetBinCenter(iz);
1736 Int_t bin = ipZ->GetXaxis()->FindBin(z);
1737 Double_t nEv = ipZ->GetBinContent(bin);
1738 Double_t eEv = ipZ->GetBinError (bin);
1739 Double_t esc = (nEv > 0 ? 1./nEv : 0);
1741 for (
Int_t iy = 1; iy <= ret->GetNbinsY(); iy++) {
1742 for (
Int_t ix = 1; ix <= ret->GetNbinsX(); ix++) {
1743 Double_t c = ret->GetBinContent(ix,iy,iz);
1744 Double_t e = ret->GetBinError (ix,iy,iz);
1749 if (full) se = sc * TMath::Sqrt(r*r+rE2);
1751 Double_t scl = 1 / ret->GetXaxis()->GetBinWidth(ix);
1752 ret->SetBinContent(ix, iy, iz, scl*sc);
1753 ret->SetBinError (ix, iy, iz, scl*se);
1762 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
1763 for (
Int_t j = 1; j <= h->GetNbinsZ(); j++) {
1764 Double_t scale = etaIPzScale->GetBinContent(i,j);
1765 Double_t scaleE = etaIPzScale->GetBinError (i,j);
1766 Double_t q = (scale > 0 ? scaleE / scale : 0);
1767 for (
Int_t k = 1; k <= h->GetNbinsY(); k++) {
1769 Double_t e = h->GetBinError (i,k,j);
1772 Double_t v = w * TMath::Sqrt(r*r + q*q);
1773 h->SetBinContent(i,k,j,w);
1774 h->SetBinError (i,k,j,v);
1776 Printf(
"%2d,%3d,%2d=(%9g+/-%9g)*(%9g+/-%9g)=(%9g+/-%9g)",
1777 i,k,j,c,e,scale,scaleE,w,v);
1788 TH2* etaDelta =
static_cast<TH2*
>(h->Project3D(
"yx e"));
1789 etaDelta->SetName(
"etaDelta");
1790 etaDelta->SetTitle(h->GetTitle());
1791 etaDelta->SetDirectory(0);
1792 etaDelta->SetZTitle(
"d^{2}#it{N}/(d#etad#Delta)");
1796 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
1797 for (
Int_t j = 1; j <= h->GetNbinsY(); j++) {
1801 for (
Int_t k = 1; k <= h->GetNbinsZ(); k++) {
1803 Double_t e = h->GetBinError (i,j,k);
1804 if (c < 1e-6 || e/c > 1)
continue;
1815 if (sumw < 1e-6)
continue;
1817 etaDelta->SetBinContent(i,j,sum/sumw);
1818 etaDelta->SetBinError (i,j,TMath::Sqrt(1/sumw));
1820 etaDelta->SetBinContent(i,j,sum/cnt);
1821 etaDelta->SetBinError (i,j,TMath::Sqrt(sumw)/cnt);
1833 Warning(
"ProjectDelta",
"No histogram passed");
1836 TH1* delta = h->ProjectionY(
"delta");
1837 delta->SetDirectory(0);
1838 delta->SetTitle(h->GetTitle());
1839 delta->SetYTitle(
"d#it{N}/d#Delta");
1840 delta->Scale(1./h->GetNbinsX());
1847 Warning(
"ProjectDelta",
"No histogram passed");
1852 delta->SetDirectory(0);
1853 tmp->SetDirectory(0);
1869 Int_t nIPz = h->GetNbinsY();
1870 Int_t nEta = h->GetNbinsX();
1871 TH1* p = h->ProjectionX(name,1,nIPz,
"e");
1872 TH2* mask = (other ? other : h);
1876 p->SetYTitle(Form(
"#LT%s#GT", h->GetYaxis()->GetTitle()));
1878 if (ipz && mode < 2 && ipEff > 1e-6) ipz->Scale(1./ipEff);
1880 for (
Int_t etaBin = 1; etaBin <= nEta; etaBin++) {
1886 for (
Int_t ipzBin = 1; ipzBin <= nIPz; ipzBin++) {
1887 Double_t bc = mask->GetBinContent(etaBin, ipzBin);
1888 if (bc < 1e-9)
continue;
1889 Double_t be = mask->GetBinError (etaBin, ipzBin);
1890 if (TMath::IsNaN(be))
continue;
1901 TMath::Sort(j, hr.fArray, idx.fArray,
false);
1910 for (k = 0; k < j; k++) {
1912 Int_t ipzBin = hb[l];
1915 Double_t x = TMath::Sqrt(nsume+hee*hee)/(nsum+hvv);
1920 Double_t by = mask->GetYaxis()->GetBinCenter(ipzBin);
1921 Int_t ib = ipz ? ipz->FindBin(by) : 0;
1923 nsum += h->GetBinContent(etaBin, ipzBin);
1924 nsume += TMath::Power(h->GetBinError(etaBin, ipzBin), 2);
1927 dsum += !ipz ? 1 : ipz->GetBinContent(ib);
1928 dsume += !ipz ? 0 : TMath::Power(ipz->GetBinError(ib),2);
1931 if (k == 0 || n == 0) {
1933 ::Warning(
"Average",
"Eta bin # %3d of %10s has no data",
1934 etaBin, h->GetName());
1937 Double_t norm = (mode > 0 ? n : dsum);
1942 if (mode==2) ave = TMath::Sqrt(nsume)/n;
1943 else ave = av*TMath::Sqrt(rne+rde);
1944 p->SetBinContent(etaBin, av);
1945 p->SetBinError (etaBin, ave);
1947 if (mode == 0) p->Scale(1,
"width");
1955 ::Warning(
"CloneAndAdd",
"Nothing to clone");
1959 if (copy->IsA()->InheritsFrom(TH1::Class()))
1961 static_cast<TH1*>(copy)->SetDirectory(0);
1974 Int_t bMin = h->FindBin(min+epsilon);
1975 Int_t bMax = h->FindBin(max-epsilon);
1976 if (bMin < 1) bMin = 0;
1977 Double_t val = h->IntegralAndError(bMin, bMax, err);
1979 if (TMath::Abs(h->GetXaxis()->GetXmin()+h->GetXaxis()->GetXmax())>=epsilon)
1984 bMin = h->FindBin(-min+epsilon);
1985 bMax = h->FindBin(-max-epsilon);
1986 val += h->IntegralAndError(bMin, bMax, err2);
1987 err = TMath::Sqrt(err*err+err2*err2);
1997 if (TMath::Abs(n) < 1e-16 || TMath::Abs(d) < 1e-16)
return 0;
1999 er = TMath::Sqrt(en*en/n/n + ed*ed/d/d);
2009 if (TMath::Abs(n) < 1e-16 || TMath::Abs(d) < 1e-16)
return 0;
2011 e2r = (e2n/n/n + e2d/d/d);
2019 if (!num || !denom) {
2020 ::Warning(
"RatioH",
"Numerator (%p) or denominator (%p) missing",
2026 TH1* ratio =
static_cast<TH1*
>(num->Clone(name ? name : num->GetName()));
2027 ratio->SetDirectory(0);
2028 ratio->SetMinimum(-1111);
2029 ratio->SetMaximum(-1111);
2030 ratio->GetListOfFunctions()->Clear();
2031 ratio->Divide(denom);
2032 ratio->SetYTitle(Form(
"%s / %s",
2033 num ->GetYaxis()->GetTitle(),
2034 denom->GetYaxis()->GetTitle()));
2035 ratio->SetTitle(Form(
"%s / %s", num ->GetTitle(), denom->GetTitle()));
2045 for (
Int_t ix = 1; ix <= h->GetNbinsX(); ix++) {
2046 for (
Int_t iy = 1; iy <= h->GetNbinsY(); iy++) {
2047 for (
Int_t iz = 1; iz <= h->GetNbinsZ(); iz++) {
2048 Int_t bin = h->GetBin(ix,iy,iz);
2049 Double_t c = h->GetBinContent(bin);
2051 if (c == 0 && ignoreZero)
continue;
2052 min = TMath::Min(min, c-e);
2053 max = TMath::Max(max, c+e);
2065 TIter next(stack->GetHists());
2067 while ((h = static_cast<TH1*>(next()))) {
2069 min = TMath::Min(min, h->GetMinimum());
2070 max = TMath::Max(max, h->GetMaximum());
2072 stack->SetMinimum(min);
2073 stack->SetMaximum(max);
2079 static Int_t codes[] = {
2128 static Int_t nCodes =
sizeof(codes) /
sizeof(
Int_t);
2129 static Int_t* sorted = 0;
2131 if (sorted)
return sorted;
2133 sorted =
new Int_t[nCodes];
2135 TMath::Sort(nCodes, codes, idx,
false);
2136 for (
Int_t i = 0; i < nCodes; i++) sorted[i] = codes[idx[i]];
2143 Color_t& c, Style_t& s)
2153 case -1: c=kPink +7; s=20; nme=
"?";
break;
2154 case 11: c=kBlack +0; s=20; nme=
"e^{-}";
break;
2155 case 13: c=kBlack +0; s=21; nme=
"#mu^{-}";
break;
2156 case 22: c=kBlack +0; s=22; nme=
"#gamma";
break;
2157 case 111: c=kRed +2; s=20; nme=
"#pi^{0}";
break;
2158 case 211: c=kRed +2; s=21; nme=
"#pi^{+}";
break;
2159 case 213: c=kRed +2; s=22; nme=
"#rho^{+}";
break;
2160 case 113: c=kRed +2; s=23; nme=
"#rho^{0}";
break;
2161 case 223: c=kRed +2; s=24; nme=
"#omega";
break;
2162 case 321: c=kBlue +2; s=20; nme=
"K^{+}";
break;
2163 case 323: c=kBlue +2; s=21; nme=
"K^{*+}";
break;
2164 case 310: c=kBlue +2; s=22; nme=
"K^{0}_{S}";
break;
2165 case 130: c=kBlue +2; s=23; nme=
"K^{0}_{L}";
break;
2166 case 311: c=kBlue +2; s=24; nme=
"K^{0}";
break;
2167 case 313: c=kBlue +2; s=25; nme=
"K^{*}";
break;
2168 case 221: c=kBlue +2; s=26; nme=
"#eta";
break;
2169 case 333: c=kBlue +2; s=27; nme=
"#varphi";
break;
2170 case 331: c=kBlue +2; s=28; nme=
"#eta'";
break;
2171 case 411: c=kGreen +2; s=20; nme=
"D^{+}";
break;
2172 case 413: c=kGreen +2; s=21; nme=
"D^{*+}";
break;
2173 case 421: c=kGreen +2; s=22; nme=
"D^{0}";
break;
2174 case 423: c=kGreen +2; s=23; nme=
"D^{*0}";
break;
2175 case 431: c=kGreen +2; s=24; nme=
"D_{s}^{+}";
break;
2176 case 433: c=kGreen +2; s=25; nme=
"D_{s}^{*+}";
break;
2177 case 2212: c=kMagenta+2; s=20; nme=
"p";
break;
2178 case 2112: c=kMagenta+2; s=21; nme=
"n";
break;
2179 case 2114: c=kMagenta+2; s=22; nme=
"#Delta^{0}";
break;
2180 case 1114: c=kMagenta+2; s=23; nme=
"#Delta^{-}";
break;
2181 case 2214: c=kMagenta+2; s=24; nme=
"#Delta^{+}";
break;
2182 case 2224: c=kMagenta+2; s=25; nme=
"#Delta^{++}";
break;
2183 case 3112: c=kCyan +2; s=20; nme=
"#Sigma^{-}";
break;
2184 case 3222: c=kCyan +2; s=21; nme=
"#Sigma^{+}";
break;
2185 case 3114: c=kCyan +2; s=22; nme=
"#Sigma^{*-}";
break;
2186 case 3224: c=kCyan +2; s=23; nme=
"#Sigma^{*+}";
break;
2187 case 3312: c=kCyan +2; s=24; nme=
"#Xi^{-}";
break;
2188 case 3314: c=kCyan +2; s=25; nme=
"#Xi^{*-}";
break;
2189 case 3122: c=kCyan +2; s=26; nme=
"#Lambda";
break;
2190 case 3212: c=kCyan +2; s=27; nme=
"#Sigma^{0}";
break;
2191 case 3214: c=kCyan +2; s=28; nme=
"#Sigma^{*0}";
break;
2192 case 3322: c=kCyan +2; s=29; nme=
"#Xi^{0}";
break;
2193 case 3324: c=kCyan +2; s=30; nme=
"#Xi^{*0}";
break;
2194 case 4214: c=kYellow +2; s=20; nme=
"#Sigma^{*+}_{c}";
break;
2195 case 4224: c=kYellow +2; s=21; nme=
"#Sigma^{*++}_{c}";
break;
2196 case 4122: c=kYellow +2; s=22; nme=
"#Lambda^{+}_{c}";
break;
2197 case 4114: c=kYellow +2; s=23; nme=
"#Sigma^{*0}_{c}";
break;
2198 case 4132: c=kYellow +2; s=24; nme=
"#Xi^{0}_{c}";
break;
2199 case 4314: c=kYellow +2; s=25; nme=
"#Xi^{*0}_{c}";
break;
2200 case 1000000000:c=kPink +2; s=20; nme=
"Nuclei";
break;
2201 default: c=kGray; s=1; nme.Form(
"%d",pdg);
break;
2210 Int_t apdg = TMath::Abs(pdg);
2211 Int_t idx = TMath::BinarySearch(size, array, apdg);
2212 if (idx == size - 1)
return idx+1;
2213 if (array[idx] != apdg)
return size+1;
2220 static TAxis* axis = 0;
2221 if (axis)
return *axis;
2225 axis =
new TAxis(size+1, +.5, size+1.5);
2227 for (
Int_t i = 1; i <= size; i++) {
2229 axis->SetBinLabel(i, Form(
"%d", pdg));
2235 axis->SetBinLabel(size+1,
"-1");
2242 TFile*
file = TFile::Open(filename,
"READ");
2244 ::Warning(
"OpenFile",
"Failed to open \"%s\"", filename);
2255 tmp.Form(
"cent%03dd%02d_%03dd%02d",
2263 const Color_t
cc[] = { kMagenta+2,
2274 Color_t tc = cc[bin % 10];
2283 Int_t binC =
const_cast<TAxis&
>(axis).FindBin(avgC);
2292 if (lvl < msgLvl)
return;
2294 va_start(ap, format);
2302 if (fMsg.IsNull())
return;
2310 if (lvl < msgLvl)
return;
2313 va_start(ap, format);
2314 Format(msg, format, ap);
2324 static char buf[512];
2325 Int_t n = gROOT->GetDirLevel() + 2;
2326 for (
Int_t i = 0; i < n; i++) buf[i] =
' ';
2327 vsnprintf(&(buf[n]), 511-n, format, ap);
2335 msg[0] = (in > 0 ?
'>' : in < 0 ?
'<' :
'=');
2336 if (in < 0) gROOT->DecreaseDirLevel();
2339 if (in > 0) gROOT->IncreaseDirLevel();
virtual ~AliTrackletAODUtils()
Int_t color[]
print message on plot with ok/not ok
static void Message(Int_t lvl, Int_t msgLvl, const char *format,...)
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)
TString format
file names tag, basically the trigger and calorimeter combination
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 void Format(TString &out, const char *format, va_list ap)
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 * 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)
DebugGuard(Int_t lvl, Int_t msgLvl, const char *format,...)
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 TH1 * AverageOverIPz(TH2 *h, const char *name, UShort_t mode, TH1 *ipz, Double_t ipEff=0, TH2 *mask=0, Bool_t verb=false)
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)
TFile * file
TList with histograms for a given trigger.
static Container * GetC(Container *parent, const char *name, Bool_t verb=true)
static void Output(int in, TString &msg)
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)