1 #ifndef ALITRACKLETDNDETAUTILS_H 2 #define ALITRACKLETDNDETAUTILS_H 7 # include <TParameter.h> 10 # include <TDirectory.h> 11 # include <THashList.h> 129 static TObject*
GetO(Container* parent,
const char* name,TClass* cls);
139 static TObject*
GetO(TDirectory* parent,
const char* name,TClass* cls);
148 static TH1*
GetH1(Container* parent,
const char* name);
157 static TH2*
GetH2(Container* parent,
const char* name);
166 static Container*
GetC(Container* parent,
const char* name);
175 static Container*
GetC(TDirectory* parent,
const char* name);
195 static Int_t GetI(Container* parent,
const char* name,
Int_t def=-1);
205 static Int_t GetB(Container* parent,
const char* name,
Bool_t def=
false);
215 static TH1*
CopyH1(Container* parent,
const char* name,
const char* newName=0);
225 static TH2*
CopyH2(Container* parent,
const char* name,
const char* newName=0);
450 if (a1->GetNbins() != a2->GetNbins()) {
451 ::Warning(
"CheckAxisNBins",
"Incompatible number %s bins: %d vs %d",
452 which, a1->GetNbins(), a2->GetNbins());
462 if (!TMath::AreEqualRel(a1->GetXmin(), a2->GetXmin(),1.E-12) ||
463 !TMath::AreEqualRel(a1->GetXmax(), a2->GetXmax(),1.E-12)) {
464 Warning(
"CheckAxisLimits",
465 "Limits of %s axis incompatible [%f,%f] vs [%f,%f]", which,
466 a1->GetXmin(), a1->GetXmax(), a2->GetXmin(), a2->GetXmax());
476 const TArrayD * h1Array = a1->GetXbins();
477 const TArrayD * h2Array = a2->GetXbins();
478 Int_t fN = h1Array->fN;
479 if ( fN == 0 )
return true;
480 if (h2Array->fN != fN) {
482 Warning(
"CheckAxisBins",
"Not equal number of %s bin limits: %d vs %d",
483 which, fN, h2Array->fN);
487 for (
int i = 0; i < fN; ++i) {
488 if (!TMath::AreEqualRel(h1Array->GetAt(i),h2Array->GetAt(i),1E-10)) {
489 Warning(
"CheckAxisBins",
490 "%s limit # %3d incompatible: %f vs %f",
491 which, i, h1Array->GetAt(i),h2Array->GetAt(i));
504 THashList *l1 = (
const_cast<TAxis*
>(a1))->GetLabels();
505 THashList *l2 = (
const_cast<TAxis*
>(a2))->GetLabels();
507 if (!l1 && !l2)
return true;
509 Warning(
"CheckAxisLabels",
"Difference in %s labels: %p vs %p",
514 if (l1->GetSize() != l2->GetSize()) {
515 Warning(
"CheckAxisLabels",
"Different number of %s labels: %d vs %d",
516 which, l1->GetSize(), l2->GetSize());
519 for (
int i = 1; i <= a1->GetNbins(); ++i) {
520 TString label1 = a1->GetBinLabel(i);
521 TString label2 = a2->GetBinLabel(i);
522 if (label1 != label2) {
523 Warning(
"CheckAxisLabels",
"%s label # %d not the same: '%s' vs '%s'",
524 which, i, label1.Data(), label2.Data());
547 if (h1 == h2)
return true;
549 if (h1->GetDimension() != h2->GetDimension() ) {
550 Warning(
"CheckConsistency",
551 "%s and %s have different dimensions %d vs %d",
552 h1->GetName(), h2->GetName(),
553 h1->GetDimension(), h2->GetDimension());
556 Int_t dim = h1->GetDimension();
558 Bool_t alsoLbls = (h1->GetEntries() != 0 && h2->GetEntries() != 0);
559 if (!
CheckAxis(
"X", h1->GetXaxis(), h2->GetXaxis(), alsoLbls))
return false;
561 !
CheckAxis(
"Y", h1->GetYaxis(), h2->GetYaxis(), alsoLbls))
return false;
563 !
CheckAxis(
"Z", h1->GetZaxis(), h2->GetZaxis(), alsoLbls))
return false;
571 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
574 Double_t dr = (dc > 1e-6 ? 1/dc : 0);
576 for (
Int_t j = 1; j <= h->GetNbinsY(); j++) {
577 Double_t nc = h->GetBinContent(i,j);
581 Double_t se = sc*TMath::Sqrt(ns*ns+dq*dq);
583 h->SetBinContent(i,j,sc);
584 h->SetBinError (i,j,se);
594 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
595 for (
Int_t j = 1; j <= h->GetNbinsY(); j++) {
600 Double_t se = sc*TMath::Sqrt(s*s+rr*rr);
602 h->SetBinContent(i,j,sc);
603 h->SetBinError (i,j,se);
613 for (
Int_t i = 1; i <= h->GetNbinsX(); i++) {
618 Double_t se = sc*TMath::Sqrt(s*s+rr*rr);
620 h->SetBinContent(i,sc);
621 h->SetBinError (i,se);
632 ::Warning(
"GetO",
"No parent container passed");
635 TObject* o = parent->FindObject(name);
637 ::Warning(
"GetO",
"Object \"%s\" not found in \"%s\"",
638 name, parent->GetName());
643 if (!o->IsA()->InheritsFrom(cls)) {
644 ::Warning(
"GetO",
"\"%s\" is an object of class %s, not %s",
645 name, o->ClassName(), cls->GetName());
656 ::Warning(
"GetO",
"No parent directory passed");
659 TObject* o = parent->Get(name);
661 ::Warning(
"GetO",
"Object \"%s\" not found in \"%s\"",
662 name, parent->GetName());
667 if (!o->IsA()->InheritsFrom(cls)) {
668 ::Warning(
"GetO",
"\"%s\" is an object of class %s, not %s",
669 name, o->ClassName(), cls->GetName());
677 return static_cast<TH1*
>(
GetO(parent, name, TH1::Class()));
682 return static_cast<TH2*
>(
GetO(parent, name, TH2::Class()));
688 return static_cast<Container*
>(
GetO(parent, name, Container::Class()));
694 return static_cast<Container*
>(
GetO(parent, name, Container::Class()));
735 TH1* ret =
static_cast<TH1*
>(orig->Clone(newName ? newName : name));
736 ret->SetDirectory(0);
746 TH2* ret =
static_cast<TH2*
>(orig->Clone(newName ? newName : name));
747 ret->SetDirectory(0);
761 Int_t nx = xAxis.GetNbins();
762 if (t.IsNull()) t = xAxis.GetTitle();
763 if (xAxis.GetXbins() && xAxis.GetXbins()->GetArray())
764 ret =
new TH1D(n,t,nx,xAxis.GetXbins()->GetArray());
766 ret =
new TH1D(n,t,nx,xAxis.GetXmin(),xAxis.GetXmax());
768 ret->SetXTitle(xAxis.GetTitle());
769 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
770 ret->SetDirectory(0);
771 ret->SetLineColor(color);
772 ret->SetMarkerColor(color);
773 ret->SetFillColor(kWhite);
774 ret->SetFillStyle(0);
775 ret->SetMarkerStyle(style);
776 if (const_cast<TAxis&>(xAxis).GetLabels()) {
777 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
778 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
783 ret->SetMarkerSize(1.4);
787 ret->SetMarkerSize(1.2);
805 Int_t nx = xAxis.GetNbins();
806 Int_t ny = yAxis.GetNbins();
807 const Double_t* xb = (xAxis.GetXbins() && xAxis.GetXbins()->GetArray() ?
808 xAxis.GetXbins()->GetArray() : 0);
809 const Double_t* yb = (yAxis.GetXbins() && yAxis.GetXbins()->GetArray() ?
810 yAxis.GetXbins()->GetArray() : 0);
812 t.Form(
"%s vs %s", yAxis.GetTitle(), xAxis.GetTitle());
814 if (yb) ret =
new TH2D(n,t,nx,xb,ny,yb);
815 else ret =
new TH2D(n,t,
817 ny,yAxis.GetXmin(),yAxis.GetXmax());
820 if (yb) ret =
new TH2D(n,t,
821 nx,xAxis.GetXmin(),xAxis.GetXmax(),
823 else ret =
new TH2D(n,t,
824 nx,xAxis.GetXmin(),xAxis.GetXmax(),
825 ny,yAxis.GetXmin(),yAxis.GetXmax());
828 ret->SetXTitle(xAxis.GetTitle());
829 ret->SetYTitle(yAxis.GetTitle());
830 ret->SetLineColor(color);
831 ret->SetMarkerColor(color);
832 ret->SetFillColor(color);
833 ret->SetMarkerStyle(style);
834 static_cast<const TAttAxis&
>(xAxis).Copy(*(ret->GetXaxis()));
835 static_cast<const TAttAxis&
>(yAxis).Copy(*(ret->GetYaxis()));
836 ret->SetDirectory(0);
837 if (const_cast<TAxis&>(xAxis).GetLabels()) {
838 for (
Int_t i = 1; i <= xAxis.GetNbins(); i++)
839 ret->GetXaxis()->SetBinLabel(i, xAxis.GetBinLabel(i));
841 if (const_cast<TAxis&>(yAxis).GetLabels()) {
842 for (
Int_t i = 1; i <= yAxis.GetNbins(); i++)
843 ret->GetYaxis()->SetBinLabel(i, yAxis.GetBinLabel(i));
851 if (title && title[0] !=
'\0') axis.SetTitle(title);
852 axis. SetNdivisions(210);
853 axis. SetLabelFont(42);
854 axis. SetLabelSize(0.03);
855 axis. SetLabelOffset(0.005);
856 axis. SetLabelColor(kBlack);
857 axis. SetTitleOffset(1);
858 axis. SetTitleFont(42);
859 axis. SetTitleSize(0.04);
860 axis. SetTitleColor(kBlack);
861 axis. SetTickLength(0.03);
862 axis. SetAxisColor(kBlack);
868 if (ret.GetXbins()->GetArray()) {
870 for (
Int_t i = 0; i < bins.GetSize(); i++) bins[i] *= fact;
871 ret.Set(ret.GetNbins(), bins.GetArray());
874 ret.Set(ret.GetNbins(), fact*ret.GetXmin(), fact*ret.GetXmax());
881 axis.Set(n, borders);
890 Bool_t isRange =
false, isUnit =
false;
891 if (s[0] ==
'r' || s[0] ==
'R') {
895 if (s[0] ==
'u' || s[0] ==
'U') {
900 TArrayD bins(tokens->GetEntries());
901 TObjString* token = 0;
904 while ((token = static_cast<TObjString*>(next()))) {
905 Double_t v = token->String().Atof();
911 if (bins.GetSize() > 1)
912 SetAxis(axis,
Int_t(bins[1]-bins[0]), bins[0], bins[1]);
918 if (bins.GetSize() > 2)
919 SetAxis(axis, nBins, bins[1], bins[2]);
924 SetAxis(axis, bins.GetSize()-1,bins.GetArray());
938 SetAxis(axis, n, -TMath::Abs(m), +TMath::Abs(m));
945 printf(
" %17s axis: ", alt ? alt : axis.GetTitle());
946 if (axis.GetXbins() && axis.GetXbins()->GetArray()) {
947 printf(
"%.*f", nSig, axis.GetBinLowEdge(1));
948 for (
Int_t i = 1; i <= axis.GetNbins(); i++)
949 printf(
":%.*f", nSig, axis.GetBinUpEdge(i));
952 printf(
"%d bins between %.*f and %.*f",
953 axis.GetNbins(), nSig, axis.GetXmin(),nSig,axis.GetXmax());
960 ::Warning(
"ScaleToIPz",
"Nothing to scale");
964 ::Warning(
"ScaleToIPz",
"Nothing to scale by");
967 TH2* ret =
static_cast<TH2*
>(h->Clone());
968 ret->SetDirectory(0);
969 if (!ipZ)
return ret;
970 for (
Int_t iy = 1; iy <= ret->GetNbinsY(); iy++) {
971 Double_t z = ret->GetYaxis()->GetBinCenter(iy);
972 Int_t bin = ipZ->GetXaxis()->FindBin(z);
973 Double_t nEv = ipZ->GetBinContent(bin);
974 Double_t eEv = ipZ->GetBinError (bin);
975 Double_t esc = (nEv > 0 ? 1./nEv : 0);
977 for (
Int_t ix = 1; ix <= ret->GetNbinsX(); ix++) {
979 Double_t e = ret->GetBinError (ix,iy);
984 if (full) se = sc * TMath::Sqrt(r*r+rE2);
986 Double_t scl = 1 / ret->GetXaxis()->GetBinWidth(ix);
987 ret->SetBinContent(ix, iy, scl*sc);
988 ret->SetBinError (ix, iy, scl*se);
1002 Int_t nIPz = h->GetNbinsY();
1003 Int_t nEta = h->GetNbinsX();
1004 TH1* p = h->ProjectionX(name,1,nIPz,
"e");
1005 TH2* mask = (other ? other : h);
1009 p->SetYTitle(Form(
"#LT%s#GT", h->GetYaxis()->GetTitle()));
1011 for (
Int_t etaBin = 1; etaBin <= nEta; etaBin++) {
1017 for (
Int_t ipzBin = 1; ipzBin <= nIPz; ipzBin++) {
1018 Double_t bc = mask->GetBinContent(etaBin, ipzBin);
1019 if (bc < 1e-9)
continue;
1020 Double_t be = mask->GetBinError (etaBin, ipzBin);
1021 if (TMath::IsNaN(be))
continue;
1032 TMath::Sort(j, hr.fArray, idx.fArray,
false);
1041 for (k = 0; k < j; k++) {
1043 Int_t ipzBin = hb[l];
1046 Double_t x = TMath::Sqrt(nsume+hee*hee)/(nsum+hvv);
1051 Double_t by = mask->GetYaxis()->GetBinCenter(ipzBin);
1052 Int_t ib = ipz ? ipz->FindBin(by) : 0;
1054 nsum += h->GetBinContent(etaBin, ipzBin);
1055 nsume += TMath::Power(h->GetBinError(etaBin, ipzBin), 2);
1058 dsum += !ipz ? 1 : ipz->GetBinContent(ib);
1059 dsume += !ipz ? 0 : TMath::Power(ipz->GetBinError(ib),2);
1062 if (k == 0 || n == 0) {
1063 ::Warning(
"Average",
"Eta bin # %3d has no data",etaBin);
1066 Double_t norm = (mode > 0 ? n : dsum);
1071 if (mode==2) ave = TMath::Sqrt(nsume)/n;
1072 else ave = av*TMath::Sqrt(rne+rde);
1073 p->SetBinContent(etaBin, av);
1074 p->SetBinError (etaBin, ave);
1076 if (mode == 0) p->Scale(1,
"width");
1084 ::Warning(
"CloneAndAdd",
"Nothing to clone");
1088 if (copy->IsA()->InheritsFrom(TH1::Class()))
1090 static_cast<TH1*>(copy)->SetDirectory(0);
1103 Int_t bMin = h->FindBin(min+epsilon);
1104 Int_t bMax = h->FindBin(max-epsilon);
1105 if (bMin < 1) bMin = 0;
1106 Double_t val = h->IntegralAndError(bMin, bMax, err);
1108 if (TMath::Abs(h->GetXaxis()->GetXmin()+h->GetXaxis()->GetXmax())>=epsilon)
1113 bMin = h->FindBin(-min+epsilon);
1114 bMax = h->FindBin(-max-epsilon);
1115 val += h->IntegralAndError(bMin, bMax, err2);
1116 err = TMath::Sqrt(err*err+err2*err2);
1126 if (TMath::Abs(n) < 1e-16 || TMath::Abs(d) < 1e-16)
return 0;
1128 er = TMath::Sqrt(en*en/n/n + ed*ed/d/d);
1138 if (TMath::Abs(n) < 1e-16 || TMath::Abs(d) < 1e-16)
return 0;
1140 e2r = (e2n/n/n + e2d/d/d);
Int_t color[]
print message on plot with ok/not ok
static TH2 * CopyH2(Container *parent, const char *name, const char *newName=0)
virtual ~AliTrackletdNdetaUtils()
static Bool_t CheckAxisNBins(const char *which, const TAxis *a1, const TAxis *a2)
static Bool_t CheckAxis(const char *which, const TAxis *a1, const TAxis *a2, Bool_t alsoLbls)
static TH1 * AverageOverIPz(TH2 *h, const char *name, UShort_t mode, TH1 *ipz, TH2 *mask=0)
static TH1 * Make1D(Container &c, const TString &name, const TString &title, Color_t color, Style_t style, const TAxis &xAxis)
static void SetAxis(TAxis &axis, Int_t n, Double_t *borders)
static Int_t GetI(Container *parent, const char *name, Int_t def=-1)
static Double_t RatioE(Double_t n, Double_t en, Double_t d, Double_t ed, Double_t &er)
static Double_t RatioE2(Double_t n, Double_t e2n, Double_t d, Double_t e2d, Double_t &e2r)
static Bool_t CheckAxisLabels(const char *which, const TAxis *a1, const TAxis *a2)
static Double_t Integrate(TH1 *h, Double_t min, Double_t max, Double_t &err)
static TH2 * ScaleToIPz(TH2 *h, TH1 *ipZ, Bool_t full=false)
static void PrintAxis(const TAxis &axis, Int_t nSig=2, const char *alt=0)
static Container * GetC(Container *parent, const char *name)
static TH1 * CopyH1(Container *parent, const char *name, const char *newName=0)
static Int_t GetB(Container *parent, const char *name, Bool_t def=false)
static Bool_t CheckAxisLimits(const char *which, const TAxis *a1, const TAxis *a2)
static void FixAxis(TAxis &axis, const char *title=0)
static void ScaleAxis(TAxis &axis, Double_t fact=1)
static TH1 * Scale(TH1 *h, Double_t x, Double_t xe)
static Double_t GetD(Container *parent, const char *name, Double_t def=-1)
static TH1 * GetH1(Container *parent, const char *name)
static Bool_t CheckConsistency(const TH1 *h1, const TH1 *h2)
static TH2 * Make2D(Container &c, const TString &name, const TString &title, Color_t color, Style_t style, const TAxis &xAxis, const TAxis &yAxis)
static TObject * CloneAndAdd(Container *c, TObject *o)
static TObject * GetO(Container *parent, const char *name, TClass *cls)
static Bool_t CheckAxisBins(const char *which, const TAxis *a1, const TAxis *a2)
static TH2 * GetH2(Container *parent, const char *name)