AliPhysics  ec7afe5 (ec7afe5)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Summarize.C
Go to the documentation of this file.
1 
2 struct Summarizer
3 {
4  TFile* fFile;
5  TCanvas* fCanvas;
6  TVirtualPad* fTop;
7  TVirtualPad* fBody;
8  TLatex* fTitle;
10  : fFile(0),
11  fCanvas(0),
12  fTop(0),
13  fBody(0),
14  fTitle(0)
15  {}
16  TObject* GetO(TDirectory* d, const char* name, TClass* cls=0)
17  {
18  if (!d) return 0;
19  TObject* o = d->Get(name);
20  if (!o) {
21  ::Warning("GetO", "No object %s in %s", name, d->GetName());
22  return 0;
23  }
24  if (!cls) return o;
25 
26  if (!o->IsA()->InheritsFrom(cls)) {
27  Warning("GetO", "Object %s read from %s, is not a %s but a %s",
28  name, d->GetName(), cls->GetName(), o->ClassName());
29  return 0;
30  }
31  return o;
32  }
33  THStack* GetHS(TDirectory* d, const char* name)
34  {
35  return static_cast<THStack*>(GetO(d, name, THStack::Class()));
36  }
37  TH1* GetH1(TDirectory* d, const char* name)
38  {
39  return static_cast<TH1*>(GetO(d, name, TH1::Class()));
40  }
41  TH2* GetH2(TDirectory* d, const char* name)
42  {
43  return static_cast<TH2*>(GetO(d, name, TH2::Class()));
44  }
45  TDirectory* GetD(TDirectory* d, const char* name)
46  {
47  if (!d) return;
48  TDirectory* sub = d->GetDirectory(name);
49  if (!sub) {
50  ::Warning("GetO", "No directory %s in %s", name, d->GetName());
51  return 0;
52  }
53  return sub;
54  }
55 
56  void Run(const char* filename)
57  {
58  fFile = TFile::Open(filename, "READ");
59  if (!fFile) return;
60 
61  TString outName(filename); outName.ReplaceAll(".root", ".pdf");
62  Int_t h = 1000;
63  Int_t w = h/TMath::Sqrt(2);
64 
65  fCanvas = new TCanvas(outName, outName, w, h);
66  fTop = new TPad("top","top",0,.9,1,1);
67  fTop->SetFillColor(kYellow-10);
68  fTop->SetFillStyle(1001);
69  fCanvas->cd();
70  fTop->Draw();
71  fBody = new TPad("body","body",0,0,1,.9);
72  fBody->SetFillColor(kWhite);
73  fBody->SetFillStyle(1001);
74  fBody->SetTopMargin(0.01);
75  fBody->SetRightMargin(0.03);
76  fCanvas->cd();
77  fBody->Draw();
78 
79  fTitle = new TLatex(0.5, 0.5, "");
80  fTitle->SetTextAlign(22);
81  fTitle->SetTextSize(0.3);
82  fTop->cd();
83  fTitle->Draw();
84 
85  fCanvas->Print(Form("%s[", fCanvas->GetName()), "PDF");
86 
87  TAxis* centAxis = VisualizeResults();
88  for (Int_t i = 1; i <= centAxis->GetNbins(); i++) {
89  Double_t c1 = centAxis->GetBinLowEdge(i);
90  Double_t c2 = centAxis->GetBinUpEdge(i);
91 
92  VisualizeBin(c1, c2);
93  }
94 
95  fCanvas->Print(Form("%s]", fCanvas->GetName()), "PDF");
96  }
98  {
99  THStack* result = GetHS(fFile, "result");
100  fBody->SetLogy();
101  fBody->SetTicks();
102  fBody->cd();
103  result->Draw("nostack");
104  Print("Results");
105 
106  TH1* cent = GetH1(fFile, "cent");
107  TH1* mid = GetH1(fFile, "mid");
108  fBody->cd();
109  fBody->Divide(1,2,0,0);
110  TVirtualPad* p = fBody->cd(1);
111  p->SetRightMargin(0.01);
112  p->SetTicks();
113  cent->Draw("hist");
114  p = fBody->cd(2);
115  p->SetRightMargin(0.01);
116  p->SetTicks();
117  mid ->Draw();
118  Print("Centralities");
119 
120  return cent->GetXaxis();
121  }
123  {
124  TString binName;
125  binName.Form("cent%03dd%02d_%03dd%02d",
126  Int_t(c1), (100*Int_t(c1)) % 100,
127  Int_t(c2), (100*Int_t(c2)) % 100);
128 
129  TDirectory* binDir = GetD(fFile, binName);
130  if (!binDir) return;
131 
132  THStack* summary = GetHS(binDir, "summary");
133  fBody->cd();
134  fBody->SetRightMargin(0.2);
135  summary->Draw("nostack");
136  fBody->BuildLegend(1-fBody->GetRightMargin(),
137  fBody->GetBottomMargin(),
138  .99,
139  1-fBody->GetTopMargin());
140  Print(Form("%5.2f-%5.2f%% - Calculations", c1, c2));
141 
142  TDirectory* detDir = GetD(binDir, "details");
143  THStack* deltas = GetHS(detDir, "deltas");
144  fBody->cd();
145  fBody->SetLogx();
146  fBody->SetLogy();
147  fBody->SetRightMargin(0.2);
148  deltas->Draw("nostack");
149  fBody->BuildLegend(1-fBody->GetRightMargin(),
150  fBody->GetBottomMargin(),
151  .99,
152  1-fBody->GetTopMargin());
153  Print(Form("%5.2f-%5.2f%% - #Delta", c1, c2));
154 
155 
156  }
157  void Print(const char* title="")
158  {
159  fTitle->SetTitle(title);
160  fTop->cd();
161  fTitle->Draw();
162  fCanvas->Modified();
163  fCanvas->Update();
164  fCanvas->cd();
165 
166  fCanvas->Print(Form("%s", fCanvas->GetName()), Form("PDF Title=%s", title));
167 
168  fCanvas->WaitPrimitive();
169 
170  fBody->Clear();
171  fTop->Clear();
172  fBody->SetLogy(false);
173  fBody->SetLogx(false);
174  fBody->SetTicks();
175  }
176 };
177 
178 void Summarize(const char* name)
179 {
180  Summarizer* s = new Summarizer;
181  s->Run(name);
182 }
183 
184 //
185 // EOF
186 //
const char * filename
Definition: TestFCM.C:1
double Double_t
Definition: External.C:58
const char * title
Definition: MakeQAPdf.C:26
TDirectory * GetD(TDirectory *d, const char *name)
Definition: Summarize.C:45
void VisualizeBin(Double_t c1, Double_t c2)
Definition: Summarize.C:122
void Summarize(const char *name)
Definition: Summarize.C:178
TCanvas * fCanvas
Definition: Summarize.C:5
TH1 * GetH1(TDirectory *d, const char *name)
Definition: Summarize.C:37
void Print(const char *title="")
Definition: Summarize.C:157
TVirtualPad * fBody
Definition: Summarize.C:7
TLatex * fTitle
Definition: Summarize.C:8
int Int_t
Definition: External.C:63
TAxis * VisualizeResults()
Definition: Summarize.C:97
Summarizer()
Definition: Summarize.C:9
TFile * fFile
Definition: Summarize.C:4
void Run(const char *filename)
Definition: Summarize.C:56
THStack * GetHS(TDirectory *d, const char *name)
Definition: Summarize.C:33
Definition: External.C:220
TVirtualPad * fTop
Definition: Summarize.C:6
TH2 * GetH2(TDirectory *d, const char *name)
Definition: Summarize.C:41
TObject * GetO(TDirectory *d, const char *name, TClass *cls=0)
Definition: Summarize.C:16
Definition: External.C:196