Fix some documentation issues
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / scripts / SummaryUnfoldedDrawer.C
CommitLineData
281a2bf8 1#include "SummaryDrawer.C"
2#include <TMultiGraph.h>
3#include <TKey.h>
4#include <TList.h>
5
671df6c9 6/**
7 * Class to draw summary of unfolding
8 *
9 * @ingroup pwglf_forward_multdist
10 */
281a2bf8 11struct SummaryUnfoldedDrawer : public SummaryDrawer
12{
13
14 SummaryUnfoldedDrawer() : SummaryDrawer() {}
fba5d22d 15 //____________________________________________________________________
281a2bf8 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
fba5d22d 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 {
281a2bf8 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
fba5d22d 74 TObject* method = GetObject(file, "method");
75 TObject* sys = GetObject(file, "sys");
76 TObject* sNN = GetObject(file, "sNN");
77 TObject* trig = GetObject(file, "trigger");
281a2bf8 78 Double_t regP;
79 Double_t minIpZ;
80 Double_t maxIpZ;
fba5d22d 81 Bool_t self;
281a2bf8 82 GetParameter(file, "regParam", regP);
83 GetParameter(file, "minIpZ", minIpZ);
84 GetParameter(file, "maxIpZ", maxIpZ);
fba5d22d 85 GetParameter(file, "self", self);
281a2bf8 86
fba5d22d 87 DrawParameter(y, "Consistency check", self ? "yes" : "no");
281a2bf8 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));
281a2bf8 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);
281a2bf8 100 }
fba5d22d 101 //____________________________________________________________________
281a2bf8 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]*");
fba5d22d 108
109 // --- Loop over bins in this directory --------------------------
281a2bf8 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 }
fba5d22d 137 //____________________________________________________________________
281a2bf8 138 void DrawResults(TDirectory* d)
139 {
fba5d22d 140 THStack* c = GetStack(d, "corrected");
141 DrawInPad(fBody, 0, c, "nostack", kLogy);
142 c->GetXaxis()->SetTitle("#it{N}_{ch}");
143 c->GetYaxis()->SetTitle("P(#it{N}_{ch})");
144
281a2bf8 145 TObject* alice = d->Get("alice");
146 TObject* cms = d->Get("cms");
147 if (cms) cms->Draw();
148 if (alice) alice->Draw();
149
150 if (alice || cms) {
151 TObject* dummy = 0;
152 TLegend* l = new TLegend(0.15, 0.12, .4, .3, "", "NDC");
153 l->SetFillColor(0);
154 l->SetFillStyle(0);
155 l->SetBorderSize(0);
156 TLegendEntry* e = l->AddEntry(dummy, "This work", "F");
157 e->SetFillColor(kRed+2);
158 e->SetFillStyle(1001);
159 if (alice) {
160 e = l->AddEntry(dummy, "ALICE", "F");
161 e->SetFillColor(kPink+1);
162 e->SetFillStyle(1001);
163 }
164 if (cms) {
165 e = l->AddEntry(dummy, "CMS", "F");
166 e->SetFillColor(kGreen+2);
167 e->SetFillStyle(1001);
168 }
169 l->Draw();
170 }
171 PrintCanvas(" Results");
fba5d22d 172
173 THStack* s = GetStack(d, "ratios");
174 if (s) {
175 fBody->SetLogy(false);
176 DrawInPad(fBody, 0, s, "nostack", kGridy);
177 s->GetYaxis()->SetTitle("(this - other)/other");
178 s->GetXaxis()->SetTitle("#it{N}_{ch}");
179
180 TObject* dummy = 0;
181 TLegend* l = new TLegend(0.65, 0.12, .95, .3, "", "NDC");
182 TLegendEntry* e = 0;
183 l->SetFillColor(0);
184 l->SetFillStyle(0);
185 l->SetBorderSize(0);
186 if (alice) {
187 e = l->AddEntry(dummy, "to ALICE", "F");
188 e->SetFillColor(kPink+1);
189 e->SetFillStyle(1001);
190 }
191 if (cms) {
192 e = l->AddEntry(dummy, "to CMS", "F");
193 e->SetFillColor(kGreen+2);
194 e->SetFillStyle(1001);
195 }
196 l->Draw();
197
198 PrintCanvas(" Ratios");
199 }
281a2bf8 200 }
fba5d22d 201 //____________________________________________________________________
281a2bf8 202 void ProcessBin(TDirectory* d)
203 {
204 Printf(" ProcessBin: %s", d->GetPath());
205
206 TString tmp(d->GetName());
207 tmp.ReplaceAll("p", "+");
208 tmp.ReplaceAll("m", "-");
209 tmp.ReplaceAll("d", ".");
210 tmp.ReplaceAll("_", " ");
211 TObjArray* tokens = tmp.Tokenize(" ");
212 if (!tokens || tokens->GetEntriesFast() < 2) {
213 Error("Other2Stack", "Failed to decode eta range from %s",
214 d->GetName());
215 if (tokens) tokens->Delete();
216 return;
217 }
218 Double_t eta1 = static_cast<TObjString*>(tokens->At(0))->String().Atof();
219 Double_t eta2 = static_cast<TObjString*>(tokens->At(1))->String().Atof();
220 tokens->Delete();
221
222 fBody->Divide(1,5,0,0);
223 TVirtualPad* p = fBody->cd(5);
224 p->SetRightMargin(0.15);
225 p->SetTopMargin(0.05);
226 p = fBody->cd(4);
227 p->SetBottomMargin(0.15);
228 THStack* all = GetStack(d,"all");
fba5d22d 229 if (!all) {
230 Warning("ProcessBin", "Argh! All stack not found!");
231 return;
232 }
281a2bf8 233 DrawInPad(fBody,1,all, "nostack", kLogy);
234 DrawInPad(fBody,2,GetH1(d,"ratioCorrTruth"), "", 0);
235 DrawInPad(fBody,3,GetH1(d,"ratioUnfAcc"), "", 0);
236 DrawInPad(fBody,4,GetH1(d,"triggerVertex"), "", 0);
237 DrawInPad(fBody,5,GetH2(d,"response"), "colz", kLogz);
fba5d22d 238 all->GetXaxis()->SetTitle("#it{N}_{ch}");
239 all->GetYaxis()->SetTitle("P(#it{N}_{ch})");
281a2bf8 240
241 PrintCanvas(Form(" %+5.2f<eta<%+5.2f", eta1, eta2));
242
243 DrawSteps(all, eta1, eta2);
244 }
fba5d22d 245 //____________________________________________________________________
281a2bf8 246 void DrawSteps(THStack* stack, Double_t e1, Double_t e2)
247 {
248 fBody->Divide(2, 3, 0, 0);
249 TList* hists = stack->GetHists();
250 Int_t nHist = hists->GetEntries();
251
252 // Make a background stack
253 THStack* bg = static_cast<THStack*>(stack->Clone("bg"));
254 bg->SetTitle();
fba5d22d 255
281a2bf8 256 for (Int_t i = 0; i < nHist; i++) {
257 // Loop over histograms and set the saved color
258 TH1* h = static_cast<TH1*>(bg->GetHists()->At(i));
259 h->SetMarkerColor(kGray+1);
260 h->SetFillColor(kGray);
261 h->SetLineColor(kGray);
262
263 TList* lf = h->GetListOfFunctions();
264 if (lf) {
265 TObject* ll = lf->FindObject("legend");
266 if (ll) lf->Remove(ll);
267 }
268 }
269 const char* txt[] = { "MC 'truth'",
270 "Selected MC 'truth'",
271 "Measured",
272 "Unfolded",
273 "Corrected" };
274 // Now loop again, this time drawing the stack
275 for (Int_t i = 0; i < nHist; i++) {
276
277 DrawInPad(fBody, i+1, bg, "nostack", kLogy);
278 DrawInPad(fBody, i+1, hists->At(i), "same hist p e", kLogy);
279 gPad->SetGridx();
280 gPad->SetGridy();
fba5d22d 281 bg->GetXaxis()->SetTitle("#it{N}_{ch}");
282 bg->GetYaxis()->SetTitle("P(#it{N}_{ch})");
281a2bf8 283
284 TLatex* l = new TLatex(.95, .95, Form("Step %d", i));
285 l->SetNDC();
286 l->SetTextAlign(33);
287 l->SetTextSize(0.06);
288 l->Draw();
289 l->DrawLatex(.95, .88, txt[i]);
290
291 }
292 PrintCanvas(Form(" %+5.2f<eta<%+5.2f - Steps", e1, e2));
293 }
294};
295//
296// EOF
297//
298