AliPhysics  f05a842 (f05a842)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SummaryUnfoldedDrawer.C
Go to the documentation of this file.
1 #include "SummaryDrawer.C"
2 #include <TMultiGraph.h>
3 #include <TKey.h>
4 #include <TList.h>
5 
12 {
13 
15  //____________________________________________________________________
16  void Run(const char* fname)
17  {
18  TString filename(fname);
19  TFile* file = TFile::Open(filename,"READ");
20  if (!file) {
21  Error("Run", "Failed to open \"%s\"", filename.Data());
22  return;
23  }
24 
25  TString pdfName(filename);
26  pdfName.ReplaceAll(".root", ".pdf");
27  CreateCanvas(pdfName, 0); // what & kLandscape);
28 
29  // --- Title page ------------------------------------------------
30  DrawTitlePage(file);
31 
32  // --- Loop over all keys in the file ----------------------------
33  TIter next(file->GetListOfKeys());
34  TKey* k = 0;
35  while ((k = static_cast<TKey*>(next()))) {
36  file->cd();
37 
38  TString clName = k->GetClassName();
39  TClass* cl = gROOT->GetClass(clName);
40  if (!cl) {
41  // Warning("Run", "Ignoring object %s of unknown type %s",
42  // k->GetName(), clName.Data());
43  continue;
44  }
45  if (!cl->InheritsFrom(TDirectory::Class())) {
46  // Warning("Run", "Ignoring object %s of type %s",
47  // k->GetName(), clName.Data());
48  continue;
49  }
50  file->cd(k->GetName());
51  ProcessType(gDirectory);
52  }
53  file->cd();
54  CloseCanvas();
55  }
56  //____________________________________________________________________
57  void DrawTitlePage(const TDirectory* file)
58  {
59  fBody->cd();
60 
61  TLatex* ltx = new TLatex(.5, .7, "Raw P(#it{N}_{ch}) #rightarrow "
62  "corrected P(#it{N}_{ch})");
63  ltx->SetNDC();
64  ltx->SetTextSize(0.07);
65  ltx->SetTextAlign(22);
66  ltx->Draw();
67 
68  Double_t y = .6;
69 
70  Double_t save = fParName->GetTextSize();
71  fParName->SetTextSize(0.03);
72  fParVal->SetTextSize(0.03);
73 
74  TObject* method = GetObject(file, "method");
75  TObject* sys = GetObject(file, "sys");
76  TObject* sNN = GetObject(file, "sNN");
77  TObject* trig = GetObject(file, "trigger");
78  Double_t regP;
79  Double_t minIpZ;
80  Double_t maxIpZ;
81  Bool_t self;
82  GetParameter(file, "regParam", regP);
83  GetParameter(file, "minIpZ", minIpZ);
84  GetParameter(file, "maxIpZ", maxIpZ);
85  GetParameter(file, "self", self);
86 
87  DrawParameter(y, "Consistency check", self ? "yes" : "no");
88  DrawParameter(y, "System", sys->GetTitle());
89  DrawParameter(y, "#sqrt{s_{NN}}", sNN->GetTitle());
90  DrawParameter(y, "Trigger", trig->GetTitle());
91  DrawParameter(y, "Method", method->GetTitle());
92  DrawParameter(y, "Reg. param.", Form("%g", regP));
93  DrawParameter(y, "IP_{z} range", Form("%+5.2fcm - %+5.2fcm",
94  minIpZ, maxIpZ));
95 
96 
97  PrintCanvas("Title page");
98  fParName->SetTextSize(save);
99  fParVal->SetTextSize(save);
100  }
101  //____________________________________________________________________
102  void ProcessType(TDirectory* d)
103  {
104  Printf(" ProcessType: %s", d->GetPath());
105  // d->ls();
106  MakeChapter(d->GetName());
107  static TRegexp regex("[pm][0-9]d[0-9]*_[pm][0-9]d[0-9]*");
108 
109  // --- Loop over bins in this directory --------------------------
110  TIter next(d->GetListOfKeys());
111  TKey* k = 0;
112  while ((k = static_cast<TKey*>(next()))) {
113  d->cd();
114  TString clName = k->GetClassName();
115  TClass* cl = gROOT->GetClass(clName);
116  if (!cl) {
117  // Warning("ProcessType", "Ignoring object %s of unknown type %s",
118  // k->GetName(), clName.Data());
119  continue;
120  }
121  if (!cl->InheritsFrom(TDirectory::Class())) {
122  // Warning("ProcessType", "Ignoring object %s of type %s",
123  // k->GetName(), clName.Data());
124  continue;
125  }
126  TString n(k->GetName());
127  if (n.Index(regex) == kNPOS) {
128  Warning("ProcessType", "Ignoring non-bin directory %s", n.Data());
129  continue;
130  }
131  d->cd(n);
132  ProcessBin(gDirectory);
133  }
134  d->cd();
135  DrawResults(d);
136  }
137  //____________________________________________________________________
138  void DrawResults(TDirectory* d)
139  {
140  THStack* c = GetStack(d, "corrected");
141  if (!c) {
142  Warning("DrawResults", "Stack of corrected results not found!");
143  return;
144  }
145  DrawInPad(fBody, 0, c, "nostack", kLogy);
146  c->GetXaxis()->SetTitle("#it{N}_{ch}");
147  c->GetYaxis()->SetTitle("P(#it{N}_{ch})");
148 
149  TObject* alice = d->Get("alice");
150  TObject* cms = d->Get("cms");
151  if (cms) cms->Draw();
152  if (alice) alice->Draw();
153 
154  if (alice || cms) {
155  TObject* dummy = 0;
156  TLegend* l = new TLegend(0.15, 0.12, .4, .3, "", "NDC");
157  l->SetFillColor(0);
158  l->SetFillStyle(0);
159  l->SetBorderSize(0);
160  TLegendEntry* e = l->AddEntry(dummy, "This work", "F");
161  e->SetFillColor(kRed+2);
162  e->SetFillStyle(1001);
163  if (alice) {
164  e = l->AddEntry(dummy, "ALICE", "F");
165  e->SetFillColor(kPink+1);
166  e->SetFillStyle(1001);
167  }
168  if (cms) {
169  e = l->AddEntry(dummy, "CMS", "F");
170  e->SetFillColor(kGreen+2);
171  e->SetFillStyle(1001);
172  }
173  l->Draw();
174  }
175  PrintCanvas(" Results");
176 
177  THStack* s = GetStack(d, "ratios");
178  if (s) {
179  fBody->SetLogy(false);
180  DrawInPad(fBody, 0, s, "nostack", kGridy);
181  s->GetYaxis()->SetTitle("(this - other)/other");
182  s->GetXaxis()->SetTitle("#it{N}_{ch}");
183 
184  TObject* dummy = 0;
185  TLegend* l = new TLegend(0.65, 0.12, .95, .3, "", "NDC");
186  TLegendEntry* e = 0;
187  l->SetFillColor(0);
188  l->SetFillStyle(0);
189  l->SetBorderSize(0);
190  if (alice) {
191  e = l->AddEntry(dummy, "to ALICE", "F");
192  e->SetFillColor(kPink+1);
193  e->SetFillStyle(1001);
194  }
195  if (cms) {
196  e = l->AddEntry(dummy, "to CMS", "F");
197  e->SetFillColor(kGreen+2);
198  e->SetFillStyle(1001);
199  }
200  l->Draw();
201  if (s->GetMinimum() > -1) s->SetMinimum(-1);
202 
203  PrintCanvas(" Ratios");
204  }
205  }
206  //____________________________________________________________________
207  void ProcessBin(TDirectory* d)
208  {
209  Printf(" ProcessBin: %s", d->GetPath());
210 
211  TString tmp(d->GetName());
212  tmp.ReplaceAll("p", "+");
213  tmp.ReplaceAll("m", "-");
214  tmp.ReplaceAll("d", ".");
215  tmp.ReplaceAll("_", " ");
216  TObjArray* tokens = tmp.Tokenize(" ");
217  if (!tokens || tokens->GetEntriesFast() < 2) {
218  Error("Other2Stack", "Failed to decode eta range from %s",
219  d->GetName());
220  if (tokens) tokens->Delete();
221  return;
222  }
223  Double_t eta1 = static_cast<TObjString*>(tokens->At(0))->String().Atof();
224  Double_t eta2 = static_cast<TObjString*>(tokens->At(1))->String().Atof();
225  tokens->Delete();
226 
227  fBody->Divide(1,5,0,0);
228  TVirtualPad* p = fBody->cd(5);
229  p->SetRightMargin(0.15);
230  p->SetTopMargin(0.05);
231  p = fBody->cd(4);
232  p->SetBottomMargin(0.15);
233  THStack* all = GetStack(d,"all");
234  if (!all) {
235  Warning("ProcessBin", "Argh! All stack not found!");
236  return;
237  }
238  DrawInPad(fBody,1,all, "nostack", kLogy);
239  DrawInPad(fBody,2,GetH1(d,"ratioCorrTruth"), "", 0);
240  DrawInPad(fBody,3,GetH1(d,"ratioUnfAcc"), "", 0);
241  DrawInPad(fBody,4,GetH1(d,"triggerVertex"), "", 0);
242  DrawInPad(fBody,5,GetH2(d,"response"), "colz", kLogz);
243  all->GetXaxis()->SetTitle("#it{N}_{ch}");
244  all->GetYaxis()->SetTitle("P(#it{N}_{ch})");
245 
246  PrintCanvas(Form(" %+5.2f<eta<%+5.2f", eta1, eta2));
247 
248  DrawSteps(all, eta1, eta2);
249  }
250  //____________________________________________________________________
251  void DrawSteps(THStack* stack, Double_t e1, Double_t e2)
252  {
253  fBody->Divide(2, 3, 0, 0);
254  TList* hists = stack->GetHists();
255  Int_t nHist = hists->GetEntries();
256 
257  // Make a background stack
258  THStack* bg = static_cast<THStack*>(stack->Clone("bg"));
259  bg->SetTitle();
260 
261  for (Int_t i = 0; i < nHist; i++) {
262  // Loop over histograms and set the saved color
263  TH1* h = static_cast<TH1*>(bg->GetHists()->At(i));
264  h->SetMarkerColor(kGray+1);
265  h->SetFillColor(kGray);
266  h->SetLineColor(kGray);
267 
268  TList* lf = h->GetListOfFunctions();
269  if (lf) {
270  TObject* ll = lf->FindObject("legend");
271  if (ll) lf->Remove(ll);
272  }
273  }
274  const char* txt[] = { "MC 'truth'",
275  "Selected MC 'truth'",
276  "Measured",
277  "Unfolded",
278  "Corrected" };
279  // Now loop again, this time drawing the stack
280  for (Int_t i = 0; i < nHist; i++) {
281 
282  DrawInPad(fBody, i+1, bg, "nostack", kLogy);
283  DrawInPad(fBody, i+1, hists->At(i), "same hist p e", kLogy);
284  gPad->SetGridx();
285  gPad->SetGridy();
286  bg->GetXaxis()->SetTitle("#it{N}_{ch}");
287  bg->GetYaxis()->SetTitle("P(#it{N}_{ch})");
288 
289  TLatex* l = new TLatex(.95, .95, Form("Step %d", i));
290  l->SetNDC();
291  l->SetTextAlign(33);
292  l->SetTextSize(0.06);
293  l->Draw();
294  l->DrawLatex(.95, .88, txt[i]);
295 
296  }
297  PrintCanvas(Form(" %+5.2f<eta<%+5.2f - Steps", e1, e2));
298  }
299 };
300 //
301 // EOF
302 //
303 
const char * filename
Definition: TestFCM.C:1
TLatex * fParName
double Double_t
Definition: External.C:58
Base class for classes to draw summaries.
static TH1 * GetH1(const TObject *parent, const TString &name, Bool_t verb=true)
static TH2 * GetH2(const TObject *parent, const TString &name, Bool_t verb=true)
TCanvas * c
Definition: TestFitELoss.C:172
void ProcessBin(TDirectory *d)
void MakeChapter(const TString &title)
void DrawTitlePage(const TDirectory *file)
int Int_t
Definition: External.C:63
void DrawSteps(THStack *stack, Double_t e1, Double_t e2)
void Run(const char *fname)
static Bool_t GetParameter(const TObject *c, const TString &name, Short_t &value, Bool_t verb=true)
static TObject * GetObject(const TObject *parent, const TString &name, Bool_t verb=true)
const char * pdfName
Definition: DrawAnaELoss.C:30
void CreateCanvas(const TString &pname, Bool_t landscape=false, Bool_t pdf=true, Bool_t useTop=true)
void DrawParameter(Double_t &y, const TString &name, const TString &value, Double_t size=0)
void PrintCanvas(const TString &title, Float_t size=.7)
void DrawResults(TDirectory *d)
void CloseCanvas()
TLatex * fParVal
void ProcessType(TDirectory *d)
TFile * file
TObject * DrawInPad(TVirtualPad *c, Int_t padNo, TObject *h, Option_t *opts="", UInt_t flags=0x0, const char *title="")
bool Bool_t
Definition: External.C:53
Definition: External.C:196
static THStack * GetStack(const TObject *parent, const TString &name, const char *sub=0, Bool_t verb=true)