AliPhysics  fde8a9f (fde8a9f)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CompareResults.C
Go to the documentation of this file.
1 //____________________________________________________________________
2 TObject*
3 GetO(TDirectory* dir, const char* name, TClass* cls=0)
4 {
5  if (!dir) {
6  Warning("GetO", "No directory passed");
7  return 0;
8  }
9 
10  TObject* o = dir->Get(name);
11  if (!o) {
12  Warning("GetO", "object %s not found in %s",
13  name, dir->GetPath());
14  return 0;
15  }
16  if (!cls) return o;
17  if (!o->IsA()->InheritsFrom(cls)) {
18  Warning("GetO", "Object %s in %s is not a %s, but a %s",
19  name, dir->GetPath(), cls->GetName(), o->ClassName());
20  return 0;
21  }
22  return o;
23 }
24 //____________________________________________________________________
25 TDirectory* GetD(TDirectory* dir, const char* name)
26 {
27  return static_cast<TDirectory*>(GetO(dir,name,TDirectory::Class()));
28 }
29 
30 //____________________________________________________________________
31 TH1* GetH1(TDirectory* dir, const char* name)
32 {
33  return static_cast<TH1*>(GetO(dir,name,TH1::Class()));
34 }
35 
36 //____________________________________________________________________
37 TH1* CompareOne(TDirectory* newDir,
38  TDirectory* oldDir,
39  Double_t c1,
40  Double_t c2,
41  Double_t& min,
42  Double_t& max,
43  TLegend* l)
44 {
45  TString name;
46  name.Form("cent%03dd%02d_%03dd%02d",
47  Int_t(c1), Int_t(c1*100)%100,
48  Int_t(c2), Int_t(c2*100)%100);
49  TDirectory* newSubDir = GetD(newDir, name);
50  TDirectory* oldSubDir = GetD(oldDir, name);
51  if (!newSubDir || !oldSubDir) return 0;
52 
53  TH1* newRes = GetH1(newSubDir, "dndeta");
54  TH1* oldRes = GetH1(oldSubDir, "dndeta");
55  if (!newRes || !oldRes) return 0;
56 
57  TH1* ratio = static_cast<TH1*>(newRes->Clone(name));
58  ratio->SetDirectory(0);
59  ratio->SetTitle(Form("%5.1f - %5.1f%%", c1, c2));
60  ratio->SetYTitle("New / Old");
61  ratio->Divide(oldRes);
62 
63  if (l) {
64  TLegendEntry* e = l->AddEntry("", Form("%3.0f - %3.0f%%", c1, c2), "f");
65  e->SetFillStyle(1001);
66  e->SetFillColor(ratio->GetMarkerColor());
67  }
68  min = TMath::Min(min, ratio->GetMinimum());
69  max = TMath::Max(max, ratio->GetMaximum());
70  return ratio;
71 }
72 
73 //____________________________________________________________________
74 void
75 CompareResults(const char* newName="NewTaskNewPost.root",
76  const char* oldName="OldTaskNewCorrect.root",
77  const char* newTitle="New",
78  const char* oldTitle="Old")
79 {
80  TFile* newFile = TFile::Open(newName,"READ");
81  TFile* oldFile = TFile::Open(oldName,"READ");
82  if (!newFile || !oldFile) return;
83 
84  TH1* newCent = GetH1(newFile, "realCent");
85  TH1* oldCent = GetH1(oldFile, "realCent");
86  if (!newCent || !oldCent) return;
87 
88  TString t; t.Form("#it{R}=#frac{%s}{%s}", oldTitle, newTitle);
89  TCanvas* c = new TCanvas("c", t, 1200, 800);
90  c->SetTopMargin(0.01);
91  c->SetRightMargin(0.20);
92  TLegend* l = new TLegend(1-c->GetRightMargin(),
93  c->GetBottomMargin(),
94  1, 1-c->GetTopMargin(),
95  t);
96  l->SetFillStyle(0);
97  l->SetBorderSize(0);
98  THStack* stack = new THStack("ratios","");
99 
100  Double_t min = +1e6;
101  Double_t max = -1e6;
102  TH1* one = 0;
103  for (Int_t i = newCent->GetNbinsX(); i--;) {
104  Double_t c1 = newCent->GetXaxis()->GetBinLowEdge(i+1);
105  Double_t c2 = newCent->GetXaxis()->GetBinUpEdge(i+1);
106  Info("", "c1=%f c2=%f", c1, c2);
107  TH1* r = CompareOne(newFile, oldFile, c1, c2, min, max, l);
108  if (!r) continue;
109  if (!one) {
110  one = static_cast<TH1*>(r->Clone("one"));
111  one->SetDirectory(0);
112  one->Reset();
113  for (Int_t j = 1; j <= one->GetNbinsX(); j++) {
114  one->SetBinContent(j,1);
115  one->SetBinError (j,0);
116  }
117  }
118  // r->Add(one, i-1);
119  // r->Scale(TMath::Power(10,i));
120  stack->Add(r);
121  }
122  stack->Draw("nostack");
123  stack->SetMinimum(0.95*min);
124  stack->SetMaximum(1.05*max);
125  stack->GetHistogram()->SetXTitle("#eta");
126  stack->GetHistogram()->SetYTitle("#it{R}");
127  l->Draw();
128  c->Modified();
129  c->Update();
130  c->cd();
131  c->SaveAs(Form("%sover%s.png", oldTitle, newTitle));
132 }
133 
134 
135 
double Double_t
Definition: External.C:58
TCanvas * c
Definition: TestFitELoss.C:172
TObject * GetO(TDirectory *dir, const char *name, TClass *cls=0)
Definition: CompareResults.C:3
TH1 * CompareOne(TDirectory *newDir, TDirectory *oldDir, Double_t c1, Double_t c2, Double_t &min, Double_t &max, TLegend *l)
int Int_t
Definition: External.C:63
void CompareResults(const char *newName="NewTaskNewPost.root", const char *oldName="OldTaskNewCorrect.root", const char *newTitle="New", const char *oldTitle="Old")
TH1 * GetH1(TDirectory *dir, const char *name)
TDirectory * GetD(TDirectory *dir, const char *name)
Definition: External.C:196