13 # include <TLegendEntry.h>
19 # include <TApplication.h>
50 Warning(
"GetO",
"No directory passed");
56 Warning(
"GetO",
"object %s not found in %s",
57 name, dir->GetPath());
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());
69 static TDirectory*
GetD(TDirectory*
dir,
const char* name)
71 return static_cast<TDirectory*
>(
GetO(dir,name,TDirectory::Class()));
77 return static_cast<TH1*
>(
GetO(dir,name,TH1::Class()));
83 name.Form(
"cent%03dd%02d_%03dd%02d",
86 TDirectory* newSubDir =
GetD(newDir, name);
87 TDirectory* oldSubDir =
GetD(oldDir, name);
88 if (!newSubDir || !oldSubDir)
return 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;
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;
98 TDirectory* newSubSubDir =
GetD(newSubDir, Form(
"results%dd",newDim));
99 TDirectory* oldSubSubDir =
GetD(oldSubDir, Form(
"results%dd",oldDim));
100 if (!newSubSubDir || !oldSubSubDir)
return 0;
102 TH1* newRes =
GetH1(newSubSubDir,
"result");
103 TH1* oldRes =
GetH1(oldSubSubDir,
"result");
104 if (!newRes || !oldRes)
return 0;
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());
114 Printf(
"Calculated %s/%s", newDir->GetName(), oldDir->GetName());
119 fLegend->AddEntry(
"", Form(
"%3.0f - %3.0f%%", c1, c2),
"f");
120 e->SetFillStyle(1001);
121 e->SetFillColor(ratio->GetMarkerColor());
126 void Run(
const char* newName,
const char* oldName,
127 const char* newTitle=
"New",
const char* oldTitle=
"Old")
129 TFile* newFile = TFile::Open(newName,
"READ");
130 TFile* oldFile = TFile::Open(oldName,
"READ");
131 if (!newFile || !oldFile)
return;
133 TH1* newCent =
GetH1(newFile,
"realCent");
134 TH1* oldCent =
GetH1(oldFile,
"realCent");
135 if (!newCent || !oldCent)
return;
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(),
147 THStack*
stack =
new THStack(
"ratios",
"");
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);
159 one =
static_cast<TH1*
>(r->Clone(
"one"));
160 one->SetDirectory(0);
162 for (
Int_t j = 1; j <= one->GetNbinsX(); j++) {
163 one->SetBinContent(j,1);
164 one->SetBinError (j,0);
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}");
180 c->SaveAs(Form(
"%sover%s.png", newTitle, oldTitle));
195 const char* newTit,
const char* oldTit)
198 c->
Run(newFile,oldFile,newTit,oldTit);
215 const char** ptr = argv;
219 if (argi.Contains(
"help")) {
220 Printf(
"Usage: CompareResults AFILE BFILE [ATITLTE [BTITLE]]");
223 if (argi.Contains(
"CompareResults.C"))
continue;
224 if (argi.BeginsWith(
"-"))
continue;
225 if (argi.EndsWith(
".root")) {
226 if (newFile.IsNull()) newFile = argi;
230 if (newTit.IsNull()) newTit = argi;
234 if (newTit.IsNull()) newTit =
"New";
235 if (oldTit.IsNull()) oldTit =
"Old";
249 CompareResults(const_cast<const char**>(&(gApplication->Argv()[1])));
250 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)
static TDirectory * GetD(TDirectory *dir, const char *name)
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)