AliPhysics  58f3d52 (58f3d52)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CompareResults.C
Go to the documentation of this file.
1 
11 #ifndef __CINT__
12 # include <TLegend.h>
13 # include <TLegendEntry.h>
14 # include <TCanvas.h>
15 # include <TH1.h>
16 # include <TFile.h>
17 # include <THStack.h>
18 # include <TError.h>
19 # include <TApplication.h>
20 #else
21 class TH1;
22 class TDirectory;
23 class TLegend;
24 #endif
25 
26 //____________________________________________________________________
36 struct Compare
37 {
40  TLegend* fLegend;
42  : fMin(+1e9),
43  fMax(-1e9)
44  {}
45 
46  //____________________________________________________________________
47  static TObject* GetO(TDirectory* dir, const char* name, TClass* cls=0)
48  {
49  if (!dir) {
50  Warning("GetO", "No directory passed");
51  return 0;
52  }
53 
54  TObject* o = dir->Get(name);
55  if (!o) {
56  Warning("GetO", "object %s not found in %s",
57  name, dir->GetPath());
58  return 0;
59  }
60  if (!cls) return o;
61  if (!o->IsA()->InheritsFrom(cls)) {
62  Warning("GetO", "Object %s in %s is not a %s, but a %s",
63  name, dir->GetPath(), cls->GetName(), o->ClassName());
64  return 0;
65  }
66  return o;
67  }
68  //____________________________________________________________________
69  static TDirectory* GetD(TDirectory* dir, const char* name)
70  {
71  return static_cast<TDirectory*>(GetO(dir,name,TDirectory::Class()));
72  }
73 
74  //____________________________________________________________________
75  static TH1* GetH1(TDirectory* dir, const char* name)
76  {
77  return static_cast<TH1*>(GetO(dir,name,TH1::Class()));
78  }
79  //____________________________________________________________________
80  TH1* One(TDirectory* newDir, TDirectory* oldDir, Double_t c1, Double_t c2)
81  {
82  TString name;
83  name.Form("cent%03dd%02d_%03dd%02d",
84  Int_t(c1), Int_t(c1*100)%100,
85  Int_t(c2), Int_t(c2*100)%100);
86  TDirectory* newSubDir = GetD(newDir, name);
87  TDirectory* oldSubDir = GetD(oldDir, name);
88  if (!newSubDir || !oldSubDir) return 0;
89  Int_t newDim = 0;
90  if (TString(newDir->GetName()).Contains("etaipz")) newDim = 3;
91  else if (TString(newDir->GetName()).Contains("eta")) newDim = 2;
92  else if (TString(newDir->GetName()).Contains("const")) newDim = 1;
93  Int_t oldDim = 0;
94  if (TString(oldDir->GetName()).Contains("etaipz")) oldDim = 3;
95  else if (TString(oldDir->GetName()).Contains("eta")) oldDim = 2;
96  else if (TString(oldDir->GetName()).Contains("const")) oldDim = 1;
97 
98  TDirectory* newSubSubDir = GetD(newSubDir, Form("results%dd",newDim));
99  TDirectory* oldSubSubDir = GetD(oldSubDir, Form("results%dd",oldDim));
100  if (!newSubSubDir || !oldSubSubDir) return 0;
101 
102  TH1* newRes = GetH1(newSubSubDir, "result");
103  TH1* oldRes = GetH1(oldSubSubDir, "result");
104  if (!newRes || !oldRes) return 0;
105 
106  TH1* ratio = static_cast<TH1*>(newRes->Clone(name));
107  ratio->SetDirectory(0);
108  ratio->SetTitle(Form("%5.1f - %5.1f%%", c1, c2));
109  ratio->SetYTitle("New / Old");
110  ratio->Divide(oldRes);
111  fMin = TMath::Min(fMin, ratio->GetMinimum());
112  fMax = TMath::Max(fMax, ratio->GetMaximum());
113 
114  Printf("Calculated %s/%s", newDir->GetName(), oldDir->GetName());
115  if (!fLegend) return ratio;
116 
117 
118  TLegendEntry* e =
119  fLegend->AddEntry("", Form("%3.0f - %3.0f%%", c1, c2), "f");
120  e->SetFillStyle(1001);
121  e->SetFillColor(ratio->GetMarkerColor());
122 
123  return ratio;
124  }
125  //____________________________________________________________________
126  void Run(const char* newName, const char* oldName,
127  const char* newTitle="New", const char* oldTitle="Old")
128  {
129  TFile* newFile = TFile::Open(newName,"READ");
130  TFile* oldFile = TFile::Open(oldName,"READ");
131  if (!newFile || !oldFile) return;
132 
133  TH1* newCent = GetH1(newFile, "realCent");
134  TH1* oldCent = GetH1(oldFile, "realCent");
135  if (!newCent || !oldCent) return;
136 
137  TString t; t.Form("#it{R}=#frac{%s}{%s}", newTitle, oldTitle);
138  TCanvas* c = new TCanvas("c", t, 1200, 800);
139  c->SetTopMargin(0.01);
140  c->SetRightMargin(0.20);
141  fLegend = new TLegend(1-c->GetRightMargin(),
142  c->GetBottomMargin(),
143  1, 1-c->GetTopMargin(),
144  t);
145  fLegend->SetFillStyle(0);
146  fLegend->SetBorderSize(0);
147  THStack* stack = new THStack("ratios","");
148 
149  fMin = +1e6;
150  fMax = -1e6;
151  TH1* one = 0;
152  for (Int_t i = newCent->GetNbinsX(); i--;) {
153  Double_t c1 = newCent->GetXaxis()->GetBinLowEdge(i+1);
154  Double_t c2 = newCent->GetXaxis()->GetBinUpEdge(i+1);
155  Info("", "c1=%f c2=%f", c1, c2);
156  TH1* r = One(newFile, oldFile, c1, c2);
157  if (!r) continue;
158  if (!one) {
159  one = static_cast<TH1*>(r->Clone("one"));
160  one->SetDirectory(0);
161  one->Reset();
162  for (Int_t j = 1; j <= one->GetNbinsX(); j++) {
163  one->SetBinContent(j,1);
164  one->SetBinError (j,0);
165  }
166  }
167  // r->Add(one, i-1);
168  // r->Scale(TMath::Power(10,i));
169  stack->Add(r);
170  }
171  stack->Draw("nostack");
172  stack->SetMinimum(0.95*fMin);
173  stack->SetMaximum(1.05*fMax);
174  stack->GetHistogram()->SetXTitle("#eta");
175  stack->GetHistogram()->SetYTitle("#it{R}");
176  fLegend->Draw();
177  c->Modified();
178  c->Update();
179  c->cd();
180  c->SaveAs(Form("%sover%s.png", newTitle, oldTitle));
181  }
182 };
194 void CompareResults(const char* newFile, const char* oldFile,
195  const char* newTit, const char* oldTit)
196 {
197  Compare* c = new Compare;
198  c->Run(newFile,oldFile,newTit,oldTit);
199 }
200 
209 void CompareResults(const char** argv)
210 {
211  TString newFile;
212  TString oldFile;
213  TString newTit("");
214  TString oldTit("");
215  const char** ptr = argv;
216  while ((*ptr)) {
217  TString argi = *ptr;
218  ptr++;
219  if (argi.Contains("help")) {
220  Printf("Usage: CompareResults AFILE BFILE [ATITLTE [BTITLE]]");
221  return;
222  }
223  if (argi.Contains("CompareResults.C")) continue;
224  if (argi.BeginsWith("-")) continue;
225  if (argi.EndsWith(".root")) {
226  if (newFile.IsNull()) newFile = argi;
227  else oldFile = argi;
228  }
229  else {
230  if (newTit.IsNull()) newTit = argi;
231  else oldTit = argi;
232  }
233  }
234  if (newTit.IsNull()) newTit = "New";
235  if (oldTit.IsNull()) oldTit = "Old";
236 
237 
238  CompareResults(newFile, oldFile, newTit, oldTit);
239 }
240 
248 {
249  CompareResults(const_cast<const char**>(&(gApplication->Argv()[1])));
250  gApplication->ClearInputFiles();
251 }
252 
253 
254 
255 //
256 // EOF
257 //
258 
double Double_t
Definition: External.C:58
Double_t fMax
void Run(const char *newName, const char *oldName, const char *newTitle="New", const char *oldTitle="Old")
TCanvas * c
Definition: TestFitELoss.C:172
AliStack * stack
static TObject * GetO(TDirectory *dir, const char *name, TClass *cls=0)
int Int_t
Definition: External.C:63
TH1 * Compare(TH1 *def, TH1 *oth)
Definition: Compare.C:124
TLegend * fLegend
void CompareResults()
static TDirectory * GetD(TDirectory *dir, const char *name)
Double_t fMin
void CompareResults(const char **argv)
static TH1 * GetH1(TDirectory *dir, const char *name)
void CompareResults(const char *newFile, const char *oldFile, const char *newTit, const char *oldTit)
TH1 * One(TDirectory *newDir, TDirectory *oldDir, Double_t c1, Double_t c2)
Definition: External.C:196
TDirectoryFile * dir