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>
198 static TH1*
GetH1(TDirectory* parent,
const char* name,
Bool_t verb=
true);
228 static TH2*
GetH2(TDirectory* parent,
const char* name,
Bool_t verb=
true);
248 static TH3*
GetH3(TDirectory* parent,
const char* name,
Bool_t verb=
true);
271 return GetP1(parent, name, verb);
292 static THStack*
GetHS(TDirectory* parent,
const char* name,
Bool_t verb=
true);
322 static TDirectory*
GetT(TDirectory* parent,
const char* name,
Bool_t verb=
true);
371 const char* newName=0,
385 const char* newName=0,
399 const char* newName=0,
750 static TH1*
RatioH(
const TH1* num,
const TH1* denom,
const char* name=0);
844 if (a1->GetNbins() != a2->GetNbins()) {
845 ::Warning(
"CheckAxisNBins",
"Incompatible number %s bins: %d vs %d",
846 which, a1->GetNbins(), a2->GetNbins());
856 if (TMath::AreEqualAbs(a1->GetXmin(), a2->GetXmin(), 1.e-3) &&
857 TMath::AreEqualAbs(a1->GetXmax(), a2->GetXmax(), 1.e-3))
return true;
858 if (!TMath::AreEqualRel(a1->GetXmin(), a2->GetXmin(),1.E-12) ||
859 !TMath::AreEqualRel(a1->GetXmax(), a2->GetXmax(),1.E-12)) {
860 Warning(
"CheckAxisLimits",
861 "Limits of %s axis incompatible [%f,%f] vs [%f,%f]", which,
862 a1->GetXmin(), a1->GetXmax(), a2->GetXmin(), a2->GetXmax());
872 const TArrayD * h1Array = a1->GetXbins();
873 const TArrayD * h2Array = a2->GetXbins();
874 Int_t fN = h1Array->fN;
875 if ( fN == 0 )
return true;
876 if (h2Array->fN != fN) {
878 Warning(
"CheckAxisBins",
"Not equal number of %s bin limits: %d vs %d",
879 which, fN, h2Array->fN);
883 for (
int i = 0; i < fN; ++i) {
884 if (TMath::AreEqualAbs(h1Array->GetAt(i),
885 h2Array->GetAt(i), 1.e-3))
continue;
886 if (!TMath::AreEqualRel(h1Array->GetAt(i),h2Array->GetAt(i),1E-10)) {
887 Warning(
"CheckAxisBins",
888 "%s limit # %3d incompatible: %f vs %f",
889 which, i, h1Array->GetAt(i),h2Array->GetAt(i));
902 THashList *l1 = (
const_cast<TAxis*
>(a1))->GetLabels();
903 THashList *l2 = (
const_cast<TAxis*
>(a2))->GetLabels();
905 if (!l1 && !l2)
return true;
907 Warning(
"CheckAxisLabels",
"Difference in %s labels: %p vs %p",
912 if (l1->GetSize() != l2->GetSize()) {
913 Warning(
"CheckAxisLabels",
"Different number of %s labels: %d vs %d",
914 which, l1->GetSize(), l2->GetSize());
917 for (
int i = 1; i <= a1->GetNbins(); ++i) {
918 TString label1 = a1->GetBinLabel(i);
919 TString label2 = a2->GetBinLabel(i);
920 if (label1 != label2) {
921 Warning(
"CheckAxisLabels",
"%s label # %d not the same: '%s' vs '%s'",
922 which, i, label1.Data(), label2.Data());
935 if (a1->GetNbins() == 0 && a2->GetNbins() == 0)
return true;
946 if (h1 == h2)
return true;
948 if (h1->GetDimension() != h2->GetDimension() ) {
949 Warning(
"CheckConsistency",
950 "%s and %s have different dimensions %d vs %d",
951 h1->GetName(), h2->GetName(),
952 h1->GetDimension(), h2->GetDimension());
955 Int_t dim = h1->GetDimension();
957 Bool_t alsoLbls = (h1->GetEntries() != 0 && h2->GetEntries() != 0);
958 if (!
CheckAxis(
"X", h1->GetXaxis(), h2->GetXaxis(), alsoLbls))
return false;
960 !
CheckAxis(
"Y", h1->GetYaxis(), h2->GetYaxis(), alsoLbls))
return false;
962 !
CheckAxis(
"Z", h1->GetZaxis(), h2->GetZaxis(), alsoLbls))
return false;
970 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
973 Double_t dr = (dc > 1e-6 ? de/dc : 0);
974 for (
Int_t j = 1; j <= h->GetNbinsY(); j++) {
975 Double_t nc = h->GetBinContent(i,j);
979 Double_t se = sc*TMath::Sqrt(ns*ns+dr*dr);
981 h->SetBinContent(i,j,sc);
982 h->SetBinError (i,j,se);
992 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
993 for (
Int_t j = 1; j <= h->GetNbinsY(); j++) {
998 Double_t se = sc*TMath::Sqrt(s*s+rr*rr);
1000 h->SetBinContent(i,j,sc);
1001 h->SetBinError (i,j,se);
1011 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
1016 Double_t se = sc*TMath::Sqrt(s*s+rr*rr);
1018 h->SetBinContent(i,sc);
1019 h->SetBinError (i,se);
1031 if (verb) ::Warning(
"GetO",
"No parent container passed");
1034 TObject* o = parent->FindObject(name);
1036 if (verb) ::Warning(
"GetO",
"Object \"%s\" not found in \"%s\"",
1037 name, parent->GetName());
1042 if (!o->IsA()->InheritsFrom(cls)) {
1043 if (verb) ::Warning(
"GetO",
"\"%s\" is an object of class %s, not %s",
1044 name, o->ClassName(), cls->GetName());
1056 if (!verb) ::Warning(
"GetO",
"No parent directory passed");
1059 TObject* o = parent->Get(name);
1061 if (verb) ::Warning(
"GetO",
"Object \"%s\" not found in \"%s\"",
1062 name, parent->GetName());
1067 if (!o->IsA()->InheritsFrom(cls)) {
1068 if (verb) ::Warning(
"GetO",
"\"%s\" is an object of class %s, not %s",
1069 name, o->ClassName(), cls->GetName());
1077 return static_cast<TH1*
>(
GetO(parent, name, TH1::Class(), v));
1082 return static_cast<TH1*
>(
GetO(parent, name, TH1::Class(), v));
1087 return static_cast<TH2*
>(
GetO(parent, name, TH2::Class(), v));
1092 return static_cast<TH2*
>(
GetO(parent, name, TH2::Class(), v));
1097 return static_cast<TH3*
>(
GetO(parent, name, TH3::Class(), v));
1102 return static_cast<TH3*
>(
GetO(parent, name, TH3::Class(), v));
1108 return static_cast<TProfile*
>(
GetO(parent, name, TProfile::Class(), v));
1114 return static_cast<TProfile2D*
>(
GetO(parent, name, TProfile2D::Class(), v));
1120 return static_cast<THStack*
>(
GetO(parent, name, THStack::Class(), v));
1126 return static_cast<THStack*
>(
GetO(parent, name, THStack::Class(), v));
1132 return static_cast<Container*
>(
GetO(parent, name, Container::Class(), v));
1138 return static_cast<Container*
>(
GetO(parent, name, Container::Class(), v));
1144 TDirectory* d = parent->GetDirectory(name);
1146 if (v) ::Warning(
"GetO",
"Directory \"%s\" not found in \"%s\"",
1147 name, parent->GetName());
1191 const char* newName,
1194 TH1* orig =
GetH1(parent, name, v);
1195 if (!orig)
return 0;
1196 TH1* ret =
static_cast<TH1*
>(orig->Clone(newName ? newName : name));
1197 ret->SetDirectory(0);
1203 const char* newName,
1206 TH2* orig =
GetH2(parent, name, v);
1207 if (!orig)
return 0;
1208 TH2* ret =
static_cast<TH2*
>(orig->Clone(newName ? newName : name));
1209 ret->SetDirectory(0);
1215 const char* newName,
1218 TH3* orig =
GetH3(parent, name, v);
1219 if (!orig)
return 0;
1220 TH3* ret =
static_cast<TH3*
>(orig->Clone(newName ? newName : name));
1221 ret->SetDirectory(0);
1228 if (!src || !dest)
return;
1229 dest->SetMarkerStyle(src->GetMarkerStyle());
1230 dest->SetMarkerColor(src->GetMarkerColor());
1231 dest->SetMarkerSize (src->GetMarkerSize());
1232 dest->SetLineStyle (src->GetLineStyle());
1233 dest->SetLineColor (src->GetLineColor());
1234 dest->SetLineWidth (src->GetLineWidth());
1235 dest->SetFillStyle (src->GetFillStyle());
1236 dest->SetFillColor (src->GetFillColor());
1251 Int_t nx = xAxis.GetNbins();
1252 if (t.IsNull()) t = xAxis.GetTitle();
1253 if (xAxis.GetXbins() && xAxis.GetXbins()->GetArray())
1254 ret =
new TH1D(n,t,nx,xAxis.GetXbins()->GetArray());
1256 ret =
new TH1D(n,t,nx,xAxis.GetXmin(),xAxis.GetXmax());
1258 ret->SetXTitle(xAxis.GetTitle());
1259 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
1260 ret->SetDirectory(0);
1261 ret->SetLineColor(color);
1262 ret->SetMarkerColor(color);
1263 ret->SetFillColor(kWhite);
1264 ret->SetFillStyle(0);
1265 ret->SetMarkerStyle(style);
1266 if (const_cast<TAxis&>(xAxis).GetLabels()) {
1267 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
1268 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
1273 ret->SetMarkerSize(1.4);
1277 ret->SetMarkerSize(1.2);
1294 Int_t nx = xAxis.GetNbins();
1295 if (t.IsNull()) t = xAxis.GetTitle();
1296 if (xAxis.GetXbins() && xAxis.GetXbins()->GetArray())
1297 ret =
new TProfile(n,t,nx,xAxis.GetXbins()->GetArray());
1299 ret =
new TProfile(n,t,nx,xAxis.GetXmin(),xAxis.GetXmax());
1301 ret->SetXTitle(xAxis.GetTitle());
1302 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
1303 ret->SetDirectory(0);
1304 ret->SetLineColor(color);
1305 ret->SetMarkerColor(color);
1306 ret->SetFillColor(kWhite);
1307 ret->SetFillStyle(0);
1308 ret->SetMarkerStyle(style);
1309 if (const_cast<TAxis&>(xAxis).GetLabels()) {
1310 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
1311 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
1316 ret->SetMarkerSize(1.4);
1320 ret->SetMarkerSize(1.2);
1338 Int_t nx = xAxis.GetNbins();
1339 Int_t ny = yAxis.GetNbins();
1340 const Double_t* xb = (xAxis.GetXbins() && xAxis.GetXbins()->GetArray() ?
1341 xAxis.GetXbins()->GetArray() : 0);
1342 const Double_t* yb = (yAxis.GetXbins() && yAxis.GetXbins()->GetArray() ?
1343 yAxis.GetXbins()->GetArray() : 0);
1345 t.Form(
"%s vs %s", yAxis.GetTitle(), xAxis.GetTitle());
1347 if (yb) ret =
new TH2D(n,t,nx,xb,ny,yb);
1348 else ret =
new TH2D(n,t,
1350 ny,yAxis.GetXmin(),yAxis.GetXmax());
1353 if (yb) ret =
new TH2D(n,t,
1354 nx,xAxis.GetXmin(),xAxis.GetXmax(),
1356 else ret =
new TH2D(n,t,
1357 nx,xAxis.GetXmin(),xAxis.GetXmax(),
1358 ny,yAxis.GetXmin(),yAxis.GetXmax());
1361 ret->SetXTitle(xAxis.GetTitle());
1362 ret->SetYTitle(yAxis.GetTitle());
1363 ret->SetLineColor(color);
1364 ret->SetMarkerColor(color);
1365 ret->SetFillColor(color);
1366 ret->SetMarkerStyle(style);
1367 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
1368 static_cast<const TAttAxis&
>(yAxis).Copy(*(ret->GetYaxis()));
1369 ret->SetDirectory(0);
1370 if (const_cast<TAxis&>(xAxis).GetLabels()) {
1371 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
1372 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
1374 if (const_cast<TAxis&>(yAxis).GetLabels()) {
1375 for (
Int_t i = 1; i <= yAxis.GetNbins(); i++)
1376 ret->GetYaxis()->SetBinLabel(i, yAxis.GetBinLabel(i));
1394 Int_t nx = xAxis.GetNbins();
1395 Int_t ny = yAxis.GetNbins();
1396 Int_t nz = zAxis.GetNbins();
1397 Double_t* xb = (xAxis.GetXbins() && xAxis.GetXbins()->GetArray() ?
1398 const_cast<Double_t*
>(xAxis.GetXbins()->GetArray()) : 0);
1399 Double_t* yb = (yAxis.GetXbins() && yAxis.GetXbins()->GetArray() ?
1400 const_cast<Double_t*
>(yAxis.GetXbins()->GetArray()) : 0);
1401 Double_t* zb = (zAxis.GetXbins() && zAxis.GetXbins()->GetArray() ?
1402 const_cast<Double_t*
>(zAxis.GetXbins()->GetArray()) : 0);
1404 t.Form(
"%s vs %s vs %s",
1405 zAxis.GetTitle(), yAxis.GetTitle(), xAxis.GetTitle());
1406 if (xb || yb || zb) {
1411 Double_t dx = (xAxis.GetXmax()-xAxis.GetXmin())/nx;
1412 xb[0] = xAxis.GetXmin();
1413 for (
Int_t i = 1; i <= nx; i++) xb[i] = xb[i-1]+dx;
1417 Double_t dy = (yAxis.GetXmax()-yAxis.GetXmin())/ny;
1418 yb[0] = yAxis.GetXmin();
1419 for (
Int_t i = 1; i <= ny; i++) yb[i] = yb[i-1]+dy;
1423 Double_t dz = (zAxis.GetXmax()-zAxis.GetXmin())/nz;
1424 zb[0] = zAxis.GetXmin();
1425 for (
Int_t i = 1; i <= nz; i++) zb[i] = zb[i-1]+dz;
1427 ret =
new TH3D(n,t,nx,xb,ny,yb,nz,zb);
1431 nx, xAxis.GetXmin(), xAxis.GetXmax(),
1432 ny, yAxis.GetXmin(), yAxis.GetXmax(),
1433 nz, zAxis.GetXmin(), zAxis.GetXmax());
1436 ret->SetXTitle(xAxis.GetTitle());
1437 ret->SetYTitle(yAxis.GetTitle());
1438 ret->SetZTitle(zAxis.GetTitle());
1439 ret->SetLineColor(color);
1440 ret->SetMarkerColor(color);
1441 ret->SetFillColor(color);
1442 ret->SetMarkerStyle(style);
1443 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
1444 static_cast<const TAttAxis&
>(yAxis).Copy(*(ret->GetYaxis()));
1445 static_cast<const TAttAxis&
>(zAxis).Copy(*(ret->GetZaxis()));
1446 ret->SetDirectory(0);
1447 if (const_cast<TAxis&>(xAxis).GetLabels()) {
1448 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
1449 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
1451 if (const_cast<TAxis&>(yAxis).GetLabels()) {
1452 for (
Int_t i = 1; i <= yAxis.GetNbins(); i++)
1453 ret->GetYaxis()->SetBinLabel(i, yAxis.GetBinLabel(i));
1455 if (const_cast<TAxis&>(zAxis).GetLabels()) {
1456 for (
Int_t i = 1; i <= zAxis.GetNbins(); i++)
1457 ret->GetZaxis()->SetBinLabel(i, zAxis.GetBinLabel(i));
1473 TProfile2D* ret = 0;
1474 Int_t nx = xAxis.GetNbins();
1475 Int_t ny = yAxis.GetNbins();
1476 const Double_t* xb = (xAxis.GetXbins() && xAxis.GetXbins()->GetArray() ?
1477 xAxis.GetXbins()->GetArray() : 0);
1478 const Double_t* yb = (yAxis.GetXbins() && yAxis.GetXbins()->GetArray() ?
1479 yAxis.GetXbins()->GetArray() : 0);
1481 t.Form(
"%s vs %s", yAxis.GetTitle(), xAxis.GetTitle());
1483 if (yb) ret =
new TProfile2D(n,t,nx,xb,ny,yb);
1484 else ret =
new TProfile2D(n,t,
1486 ny,yAxis.GetXmin(),yAxis.GetXmax());
1489 if (yb) ret =
new TProfile2D(n,t,
1490 nx,xAxis.GetXmin(),xAxis.GetXmax(),
1492 else ret =
new TProfile2D(n,t,
1493 nx,xAxis.GetXmin(),xAxis.GetXmax(),
1494 ny,yAxis.GetXmin(),yAxis.GetXmax());
1497 ret->SetXTitle(xAxis.GetTitle());
1498 ret->SetYTitle(yAxis.GetTitle());
1499 ret->SetLineColor(color);
1500 ret->SetMarkerColor(color);
1501 ret->SetFillColor(color);
1502 ret->SetMarkerStyle(style);
1503 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
1504 static_cast<const TAttAxis&
>(yAxis).Copy(*(ret->GetYaxis()));
1505 ret->SetDirectory(0);
1506 if (const_cast<TAxis&>(xAxis).GetLabels()) {
1507 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
1508 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
1510 if (const_cast<TAxis&>(yAxis).GetLabels()) {
1511 for (
Int_t i = 1; i <= yAxis.GetNbins(); i++)
1512 ret->GetYaxis()->SetBinLabel(i, yAxis.GetBinLabel(i));
1520 if (title && title[0] !=
'\0') axis.SetTitle(title);
1521 axis. SetNdivisions(210);
1522 axis. SetLabelFont(42);
1523 axis. SetLabelSize(0.03);
1524 axis. SetLabelOffset(0.005);
1525 axis. SetLabelColor(kBlack);
1526 axis. SetTitleOffset(1);
1527 axis. SetTitleFont(42);
1528 axis. SetTitleSize(0.04);
1529 axis. SetTitleColor(kBlack);
1530 axis. SetTickLength(0.03);
1531 axis. SetAxisColor(kBlack);
1537 if (ret.GetXbins()->GetArray()) {
1538 TArrayD bins(*ret.GetXbins());
1539 for (
Int_t i = 0; i < bins.GetSize(); i++) bins[i] *= fact;
1540 ret.Set(ret.GetNbins(), bins.GetArray());
1543 ret.Set(ret.GetNbins(), fact*ret.GetXmin(), fact*ret.GetXmax());
1550 axis.Set(n, borders);
1559 Bool_t isRange =
false, isUnit =
false;
1560 if (s[0] ==
'r' || s[0] ==
'R') {
1564 if (s[0] ==
'u' || s[0] ==
'U') {
1569 TArrayD bins(tokens->GetEntries());
1570 TObjString* token = 0;
1573 while ((token = static_cast<TObjString*>(next()))) {
1574 Double_t v = token->String().Atof();
1580 if (bins.GetSize() > 1)
1581 SetAxis(axis,
Int_t(bins[1]-bins[0]), bins[0], bins[1]);
1587 if (bins.GetSize() > 2)
1588 SetAxis(axis, nBins, bins[1], bins[2]);
1590 SetAxis(axis, nBins, bins[1]);
1593 SetAxis(axis, bins.GetSize()-1,bins.GetArray());
1607 SetAxis(axis, n, -TMath::Abs(m), +TMath::Abs(m));
1614 printf(
" %17s axis: ", alt ? alt : axis.GetTitle());
1615 if (axis.GetXbins() && axis.GetXbins()->GetArray()) {
1616 printf(
"%.*f", nSig, axis.GetBinLowEdge(1));
1617 for (
Int_t i = 1; i <= axis.GetNbins(); i++)
1618 printf(
":%.*f", nSig, axis.GetBinUpEdge(i));
1621 printf(
"%d bins between %.*f and %.*f",
1622 axis.GetNbins(), nSig, axis.GetXmin(),nSig,axis.GetXmax());
1629 ::Warning(
"ScaleToIPz",
"Nothing to scale");
1633 ::Warning(
"ScaleToIPz",
"Nothing to scale by");
1636 TH2* ret =
static_cast<TH2*
>(h->Clone());
1637 ret->SetDirectory(0);
1638 if (!ipZ)
return ret;
1639 for (
Int_t iy = 1; iy <= ret->GetNbinsY(); iy++) {
1640 Double_t z = ret->GetYaxis()->GetBinCenter(iy);
1641 Int_t bin = ipZ->GetXaxis()->FindBin(z);
1642 Double_t nEv = ipZ->GetBinContent(bin);
1643 Double_t eEv = ipZ->GetBinError (bin);
1644 Double_t esc = (nEv > 0 ? 1./nEv : 0);
1646 for (
Int_t ix = 1; ix <= ret->GetNbinsX(); ix++) {
1648 Double_t e = ret->GetBinError (ix,iy);
1653 if (full) se = sc * TMath::Sqrt(r*r+rE2);
1655 Double_t scl = 1 / ret->GetXaxis()->GetBinWidth(ix);
1656 ret->SetBinContent(ix, iy, scl*sc);
1657 ret->SetBinError (ix, iy, scl*se);
1666 ::Warning(
"ScaleToIPz",
"Nothing to scale");
1670 ::Warning(
"ScaleToIPz",
"Nothing to scale by");
1673 TH3* ret =
static_cast<TH3*
>(h->Clone());
1674 ret->SetDirectory(0);
1675 if (!ipZ)
return ret;
1676 for (
Int_t iz = 1; iz <= ret->GetNbinsZ(); iz++) {
1677 Double_t z = ret->GetZaxis()->GetBinCenter(iz);
1678 Int_t bin = ipZ->GetXaxis()->FindBin(z);
1679 Double_t nEv = ipZ->GetBinContent(bin);
1680 Double_t eEv = ipZ->GetBinError (bin);
1681 Double_t esc = (nEv > 0 ? 1./nEv : 0);
1683 for (
Int_t iy = 1; iy <= ret->GetNbinsY(); iy++) {
1684 for (
Int_t ix = 1; ix <= ret->GetNbinsX(); ix++) {
1685 Double_t c = ret->GetBinContent(ix,iy,iz);
1686 Double_t e = ret->GetBinError (ix,iy,iz);
1691 if (full) se = sc * TMath::Sqrt(r*r+rE2);
1693 Double_t scl = 1 / ret->GetXaxis()->GetBinWidth(ix);
1694 ret->SetBinContent(ix, iy, iz, scl*sc);
1695 ret->SetBinError (ix, iy, iz, scl*se);
1704 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
1705 for (
Int_t j = 1; j <= h->GetNbinsZ(); j++) {
1706 Double_t scale = etaIPzScale->GetBinContent(i,j);
1707 Double_t scaleE = etaIPzScale->GetBinError (i,j);
1708 Double_t q = (scale > 0 ? scaleE / scale : 0);
1709 for (
Int_t k = 1; k <= h->GetNbinsY(); k++) {
1711 Double_t e = h->GetBinError (i,k,j);
1714 Double_t v = w * TMath::Sqrt(r*r + q*q);
1715 h->SetBinContent(i,k,j,w);
1716 h->SetBinError (i,k,j,v);
1718 Printf(
"%2d,%3d,%2d=(%9g+/-%9g)*(%9g+/-%9g)=(%9g+/-%9g)",
1719 i,k,j,c,e,scale,scaleE,w,v);
1730 TH2* etaDelta =
static_cast<TH2*
>(h->Project3D(
"yx e"));
1731 etaDelta->SetName(
"etaDelta");
1732 etaDelta->SetTitle(h->GetTitle());
1733 etaDelta->SetDirectory(0);
1734 etaDelta->SetZTitle(
"d^{2}#it{N}/(d#etad#Delta)");
1738 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
1739 for (
Int_t j = 1; j <= h->GetNbinsY(); j++) {
1743 for (
Int_t k = 1; k <= h->GetNbinsZ(); k++) {
1745 Double_t e = h->GetBinError (i,j,k);
1746 if (c < 1e-6 || e/c > 1)
continue;
1757 if (sumw < 1e-6)
continue;
1759 etaDelta->SetBinContent(i,j,sum/sumw);
1760 etaDelta->SetBinError (i,j,TMath::Sqrt(1/sumw));
1762 etaDelta->SetBinContent(i,j,sum/cnt);
1763 etaDelta->SetBinError (i,j,TMath::Sqrt(sumw)/cnt);
1775 Warning(
"ProjectDelta",
"No histogram passed");
1778 TH1* delta = h->ProjectionY(
"delta");
1779 delta->SetDirectory(0);
1780 delta->SetTitle(h->GetTitle());
1781 delta->SetYTitle(
"d#it{N}/d#Delta");
1782 delta->Scale(1./h->GetNbinsX());
1789 Warning(
"ProjectDelta",
"No histogram passed");
1794 delta->SetDirectory(0);
1795 tmp->SetDirectory(0);
1810 Int_t nIPz = h->GetNbinsY();
1811 Int_t nEta = h->GetNbinsX();
1812 TH1* p = h->ProjectionX(name,1,nIPz,
"e");
1813 TH2* mask = (other ? other : h);
1817 p->SetYTitle(Form(
"#LT%s#GT", h->GetYaxis()->GetTitle()));
1819 for (
Int_t etaBin = 1; etaBin <= nEta; etaBin++) {
1825 for (
Int_t ipzBin = 1; ipzBin <= nIPz; ipzBin++) {
1826 Double_t bc = mask->GetBinContent(etaBin, ipzBin);
1827 if (bc < 1e-9)
continue;
1828 Double_t be = mask->GetBinError (etaBin, ipzBin);
1829 if (TMath::IsNaN(be))
continue;
1840 TMath::Sort(j, hr.fArray, idx.fArray,
false);
1849 for (k = 0; k < j; k++) {
1851 Int_t ipzBin = hb[l];
1854 Double_t x = TMath::Sqrt(nsume+hee*hee)/(nsum+hvv);
1859 Double_t by = mask->GetYaxis()->GetBinCenter(ipzBin);
1860 Int_t ib = ipz ? ipz->FindBin(by) : 0;
1862 nsum += h->GetBinContent(etaBin, ipzBin);
1863 nsume += TMath::Power(h->GetBinError(etaBin, ipzBin), 2);
1866 dsum += !ipz ? 1 : ipz->GetBinContent(ib);
1867 dsume += !ipz ? 0 : TMath::Power(ipz->GetBinError(ib),2);
1870 if (k == 0 || n == 0) {
1872 ::Warning(
"Average",
"Eta bin # %3d of %10s has no data",
1873 etaBin, h->GetName());
1876 Double_t norm = (mode > 0 ? n : dsum);
1881 if (mode==2) ave = TMath::Sqrt(nsume)/n;
1882 else ave = av*TMath::Sqrt(rne+rde);
1883 p->SetBinContent(etaBin, av);
1884 p->SetBinError (etaBin, ave);
1886 if (mode == 0) p->Scale(1,
"width");
1894 ::Warning(
"CloneAndAdd",
"Nothing to clone");
1898 if (copy->IsA()->InheritsFrom(TH1::Class()))
1900 static_cast<TH1*>(copy)->SetDirectory(0);
1913 Int_t bMin = h->FindBin(min+epsilon);
1914 Int_t bMax = h->FindBin(max-epsilon);
1915 if (bMin < 1) bMin = 0;
1916 Double_t val = h->IntegralAndError(bMin, bMax, err);
1918 if (TMath::Abs(h->GetXaxis()->GetXmin()+h->GetXaxis()->GetXmax())>=epsilon)
1923 bMin = h->FindBin(-min+epsilon);
1924 bMax = h->FindBin(-max-epsilon);
1925 val += h->IntegralAndError(bMin, bMax, err2);
1926 err = TMath::Sqrt(err*err+err2*err2);
1936 if (TMath::Abs(n) < 1e-16 || TMath::Abs(d) < 1e-16)
return 0;
1938 er = TMath::Sqrt(en*en/n/n + ed*ed/d/d);
1948 if (TMath::Abs(n) < 1e-16 || TMath::Abs(d) < 1e-16)
return 0;
1950 e2r = (e2n/n/n + e2d/d/d);
1958 if (!num || !denom) {
1959 ::Warning(
"RatioH",
"Numerator (%p) or denominator (%p) missing",
1965 TH1* ratio =
static_cast<TH1*
>(num->Clone(name ? name : num->GetName()));
1966 ratio->SetDirectory(0);
1967 ratio->SetMinimum(-1111);
1968 ratio->SetMaximum(-1111);
1969 ratio->GetListOfFunctions()->Clear();
1970 ratio->Divide(denom);
1971 ratio->SetYTitle(Form(
"%s / %s",
1972 num ->GetYaxis()->GetTitle(),
1973 denom->GetYaxis()->GetTitle()));
1974 ratio->SetTitle(Form(
"%s / %s", num ->GetTitle(), denom->GetTitle()));
1984 for (
Int_t ix = 1; ix <= h->GetNbinsX(); ix++) {
1985 for (
Int_t iy = 1; iy <= h->GetNbinsY(); iy++) {
1986 for (
Int_t iz = 1; iz <= h->GetNbinsZ(); iz++) {
1987 Int_t bin = h->GetBin(ix,iy,iz);
1988 Double_t c = h->GetBinContent(bin);
1990 if (c == 0 && ignoreZero)
continue;
1991 min = TMath::Min(min, c-e);
1992 max = TMath::Max(max, c+e);
2004 TIter next(stack->GetHists());
2006 while ((h = static_cast<TH1*>(next()))) {
2008 min = TMath::Min(min, h->GetMinimum());
2009 max = TMath::Max(max, h->GetMaximum());
2011 stack->SetMinimum(min);
2012 stack->SetMaximum(max);
2018 static Int_t codes[] = {
2067 static Int_t nCodes =
sizeof(codes) /
sizeof(
Int_t);
2068 static Int_t* sorted = 0;
2070 if (sorted)
return sorted;
2072 sorted =
new Int_t[nCodes];
2074 TMath::Sort(nCodes, codes, idx,
false);
2075 for (
Int_t i = 0; i < nCodes; i++) sorted[i] = codes[idx[i]];
2082 Color_t& c, Style_t& s)
2092 case -1: c=kPink +7; s=20; nme=
"?";
break;
2093 case 11: c=kBlack +0; s=20; nme=
"e^{-}";
break;
2094 case 13: c=kBlack +0; s=21; nme=
"#mu^{-}";
break;
2095 case 22: c=kBlack +0; s=22; nme=
"#gamma";
break;
2096 case 111: c=kRed +2; s=20; nme=
"#pi^{0}";
break;
2097 case 211: c=kRed +2; s=21; nme=
"#pi^{+}";
break;
2098 case 213: c=kRed +2; s=22; nme=
"#rho^{+}";
break;
2099 case 113: c=kRed +2; s=23; nme=
"#rho^{0}";
break;
2100 case 223: c=kRed +2; s=24; nme=
"#omega";
break;
2101 case 321: c=kBlue +2; s=20; nme=
"K^{+}";
break;
2102 case 323: c=kBlue +2; s=21; nme=
"K^{*+}";
break;
2103 case 310: c=kBlue +2; s=22; nme=
"K^{0}_{S}";
break;
2104 case 130: c=kBlue +2; s=23; nme=
"K^{0}_{L}";
break;
2105 case 311: c=kBlue +2; s=24; nme=
"K^{0}";
break;
2106 case 313: c=kBlue +2; s=25; nme=
"K^{*}";
break;
2107 case 221: c=kBlue +2; s=26; nme=
"#eta";
break;
2108 case 333: c=kBlue +2; s=27; nme=
"#varphi";
break;
2109 case 331: c=kBlue +2; s=28; nme=
"#eta'";
break;
2110 case 411: c=kGreen +2; s=20; nme=
"D^{+}";
break;
2111 case 413: c=kGreen +2; s=21; nme=
"D^{*+}";
break;
2112 case 421: c=kGreen +2; s=22; nme=
"D^{0}";
break;
2113 case 423: c=kGreen +2; s=23; nme=
"D^{*0}";
break;
2114 case 431: c=kGreen +2; s=24; nme=
"D_{s}^{+}";
break;
2115 case 433: c=kGreen +2; s=25; nme=
"D_{s}^{*+}";
break;
2116 case 2212: c=kMagenta+2; s=20; nme=
"p";
break;
2117 case 2112: c=kMagenta+2; s=21; nme=
"n";
break;
2118 case 2114: c=kMagenta+2; s=22; nme=
"#Delta^{0}";
break;
2119 case 1114: c=kMagenta+2; s=23; nme=
"#Delta^{-}";
break;
2120 case 2214: c=kMagenta+2; s=24; nme=
"#Delta^{+}";
break;
2121 case 2224: c=kMagenta+2; s=25; nme=
"#Delta^{++}";
break;
2122 case 3112: c=kCyan +2; s=20; nme=
"#Sigma^{-}";
break;
2123 case 3222: c=kCyan +2; s=21; nme=
"#Sigma^{+}";
break;
2124 case 3114: c=kCyan +2; s=22; nme=
"#Sigma^{*-}";
break;
2125 case 3224: c=kCyan +2; s=23; nme=
"#Sigma^{*+}";
break;
2126 case 3312: c=kCyan +2; s=24; nme=
"#Xi^{-}";
break;
2127 case 3314: c=kCyan +2; s=25; nme=
"#Xi^{*-}";
break;
2128 case 3122: c=kCyan +2; s=26; nme=
"#Lambda";
break;
2129 case 3212: c=kCyan +2; s=27; nme=
"#Sigma^{0}";
break;
2130 case 3214: c=kCyan +2; s=28; nme=
"#Sigma^{*0}";
break;
2131 case 3322: c=kCyan +2; s=29; nme=
"#Xi^{0}";
break;
2132 case 3324: c=kCyan +2; s=30; nme=
"#Xi^{*0}";
break;
2133 case 4214: c=kYellow +2; s=20; nme=
"#Sigma^{*+}_{c}";
break;
2134 case 4224: c=kYellow +2; s=21; nme=
"#Sigma^{*++}_{c}";
break;
2135 case 4122: c=kYellow +2; s=22; nme=
"#Lambda^{+}_{c}";
break;
2136 case 4114: c=kYellow +2; s=23; nme=
"#Sigma^{*0}_{c}";
break;
2137 case 4132: c=kYellow +2; s=24; nme=
"#Xi^{0}_{c}";
break;
2138 case 4314: c=kYellow +2; s=25; nme=
"#Xi^{*0}_{c}";
break;
2139 case 1000000000:c=kPink +2; s=20; nme=
"Nuclei";
break;
2140 default: c=kGray; s=1; nme.Form(
"%d",pdg);
break;
2149 Int_t apdg = TMath::Abs(pdg);
2150 Int_t idx = TMath::BinarySearch(size, array, apdg);
2151 if (idx == size - 1)
return idx+1;
2152 if (array[idx] != apdg)
return size+1;
2159 static TAxis* axis = 0;
2160 if (axis)
return *axis;
2164 axis =
new TAxis(size+1, +.5, size+1.5);
2166 for (
Int_t i = 1; i <= size; i++) {
2168 axis->SetBinLabel(i, Form(
"%d", pdg));
2174 axis->SetBinLabel(size+1,
"-1");
2181 TFile*
file = TFile::Open(filename,
"READ");
2183 ::Warning(
"OpenFile",
"Failed to open \"%s\"", filename);
2192 tmp.Form(
"cent%03dd%02d_%03dd%02d",
2200 const Color_t
cc[] = { kMagenta+2,
2211 Color_t tc = cc[bin % 10];
2220 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)