13 # include <TLegendEntry.h>
19 # include <TApplication.h>
38 static TObject*
GetO(TDirectory* dir,
const char* name, TClass* cls=0)
41 Warning(
"GetO",
"No directory passed");
47 Warning(
"GetO",
"object %s not found in %s",
48 name, dir->GetPath());
52 if (!o->IsA()->InheritsFrom(cls)) {
53 Warning(
"GetO",
"Object %s in %s is not a %s, but a %s",
54 name, dir->GetPath(), cls->GetName(), o->ClassName());
60 static TDirectory*
GetD(TDirectory* dir,
const char* name)
62 return static_cast<TDirectory*
>(
GetO(dir,name,TDirectory::Class()));
66 static TH1*
GetH1(TDirectory* dir,
const char* name)
68 return static_cast<TH1*
>(
GetO(dir,name,TH1::Class()));
74 name.Form(
"cent%03dd%02d_%03dd%02d",
77 TDirectory* newSubDir =
GetD(newDir, name);
78 TDirectory* oldSubDir =
GetD(oldDir, name);
79 if (!newSubDir || !oldSubDir)
return 0;
81 if (
TString(newDir->GetName()).Contains(
"etaipz")) newDim = 3;
82 else if (
TString(newDir->GetName()).Contains(
"eta")) newDim = 2;
83 else if (
TString(newDir->GetName()).Contains(
"const")) newDim = 1;
85 if (
TString(oldDir->GetName()).Contains(
"etaipz")) oldDim = 3;
86 else if (
TString(oldDir->GetName()).Contains(
"eta")) oldDim = 2;
87 else if (
TString(oldDir->GetName()).Contains(
"const")) oldDim = 1;
89 TDirectory* newSubSubDir =
GetD(newSubDir, Form(
"results%dd",newDim));
90 TDirectory* oldSubSubDir =
GetD(oldSubDir, Form(
"results%dd",oldDim));
91 if (!newSubSubDir || !oldSubSubDir)
return 0;
93 TH1* newRes =
GetH1(newSubSubDir,
"result");
94 TH1* oldRes =
GetH1(oldSubSubDir,
"result");
95 if (!newRes || !oldRes)
return 0;
97 TH1* ratio =
static_cast<TH1*
>(newRes->Clone(name));
98 ratio->SetDirectory(0);
99 ratio->SetTitle(Form(
"%5.1f - %5.1f%%", c1, c2));
100 ratio->SetYTitle(
"New / Old");
101 ratio->Divide(oldRes);
102 fMin = TMath::Min(
fMin, ratio->GetMinimum());
103 fMax = TMath::Max(fMax, ratio->GetMaximum());
105 Printf(
"Calculated %s/%s", newDir->GetName(), oldDir->GetName());
110 fLegend->AddEntry(
"", Form(
"%3.0f - %3.0f%%", c1, c2),
"f");
111 e->SetFillStyle(1001);
112 e->SetFillColor(ratio->GetMarkerColor());
117 void Run(
const char* newName,
const char* oldName,
118 const char* newTitle=
"New",
const char* oldTitle=
"Old")
120 TFile* newFile = TFile::Open(newName,
"READ");
121 TFile* oldFile = TFile::Open(oldName,
"READ");
122 if (!newFile || !oldFile)
return;
124 TH1* newCent =
GetH1(newFile,
"realCent");
125 TH1* oldCent =
GetH1(oldFile,
"realCent");
126 if (!newCent || !oldCent)
return;
128 TString t; t.Form(
"#it{R}=#frac{%s}{%s}", newTitle, oldTitle);
129 TCanvas*
c =
new TCanvas(
"c", t, 1200, 800);
130 c->SetTopMargin(0.01);
131 c->SetRightMargin(0.20);
132 fLegend =
new TLegend(1-c->GetRightMargin(),
133 c->GetBottomMargin(),
134 1, 1-c->GetTopMargin(),
138 THStack* stack =
new THStack(
"ratios",
"");
143 for (
Int_t i = newCent->GetNbinsX(); i--;) {
144 Double_t c1 = newCent->GetXaxis()->GetBinLowEdge(i+1);
145 Double_t c2 = newCent->GetXaxis()->GetBinUpEdge(i+1);
146 Info(
"",
"c1=%f c2=%f", c1, c2);
147 TH1* r =
One(newFile, oldFile, c1, c2);
150 one =
static_cast<TH1*
>(r->Clone(
"one"));
151 one->SetDirectory(0);
153 for (
Int_t j = 1; j <= one->GetNbinsX(); j++) {
154 one->SetBinContent(j,1);
155 one->SetBinError (j,0);
162 stack->Draw(
"nostack");
163 stack->SetMinimum(0.95*
fMin);
164 stack->SetMaximum(1.05*
fMax);
165 stack->GetHistogram()->SetXTitle(
"#eta");
166 stack->GetHistogram()->SetYTitle(
"#it{R}");
171 c->SaveAs(Form(
"%sover%s.png", newTitle, oldTitle));
176 const char* newTit,
const char* oldTit)
179 c->
Run(newFile,oldFile,newTit,oldTit);
188 const char** ptr = argv;
192 if (argi.Contains(
"help")) {
193 Printf(
"Usage: CompareResults AFILE BFILE [ATITLTE [BTITLE]]");
196 if (argi.Contains(
"CompareResults.C"))
continue;
197 if (argi.BeginsWith(
"-"))
continue;
198 if (argi.EndsWith(
".root")) {
199 if (newFile.IsNull()) newFile = argi;
203 if (newTit.IsNull()) newTit = argi;
207 if (newTit.IsNull()) newTit =
"New";
208 if (oldTit.IsNull()) oldTit =
"Old";
216 CompareResults(const_cast<const char**>(&(gApplication->Argv()[1])));
217 gApplication->ClearInputFiles();
void Run(const char *newName, const char *oldName, const char *newTitle="New", const char *oldTitle="Old")
static TObject * GetO(TDirectory *dir, const char *name, TClass *cls=0)
TH1 * Compare(TH1 *def, TH1 *oth)
void CompareResults(const char *newName="NewTaskNewPost.root", const char *oldName="OldTaskNewCorrect.root", const char *newTitle="New", const char *oldTitle="Old")
static TDirectory * GetD(TDirectory *dir, const char *name)
static TH1 * GetH1(TDirectory *dir, const char *name)
TH1 * One(TDirectory *newDir, TDirectory *oldDir, Double_t c1, Double_t c2)