]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/scripts/SummaryAODDrawer.C
fcb662fc787e605e5576ce2f3b959ce6f5dc9d74
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / scripts / SummaryAODDrawer.C
1 #include "SummaryDrawer.C"
2
3 /**
4  * Class to draw a summary of the AOD production
5  *
6  * @par Input: 
7  * - The merged <tt>forward.root</tt> file.
8  *   If the file isn't merged, it should still work. 
9  *
10  * @par Output:
11  * - A PDF file named after the input, but with <tt>.root</tt>
12  *   replaced with <tt>pdf</tt>
13  * 
14  */
15 class SummaryAODDrawer : public SummaryDrawer
16 {
17 public:
18   enum EFlags { 
19     kEventInspector    = 0x001, 
20     kSharingFilter     = 0x002, 
21     kDensityCalculator = 0x004,
22     kCorrector         = 0x008,
23     kHistCollector     = 0x010,
24     kSteps             = 0x020, 
25     kResults           = 0x040, 
26     kPause             = 0x080,
27     kLandscape         = 0x100, 
28     kCentral           = 0x200,
29     kNormal            = 0x27F
30   };
31   SummaryAODDrawer() 
32     : SummaryDrawer(),
33       fSums(0),
34       fResults(0)
35   {}
36   
37   //__________________________________________________________________
38   /** 
39    * 
40    * 
41    * @param fname 
42    * @param what 
43    */
44   void Run(const char* fname, UShort_t what=kNormal)
45   {
46     // --- Open the file ---------------------------------------------
47     TString filename(fname);
48     TFile*  file = TFile::Open(filename, "READ");
49     if (!file) { 
50       Error("Run", "Failed to open \"%s\"", filename.Data());
51       return;
52     }
53    
54
55     // --- Get top-level collection ----------------------------------
56     fSums = GetCollection(file, "Forward");
57     if (!fSums) return;
58
59     // --- Do the results ----------------------------------------------
60     fResults = GetCollection(file, "ForwardResults");
61     if (!fResults) fResults = fSums; // Old-style
62
63     // --- Make our canvas -------------------------------------------
64     TString pdfName(filename);
65     pdfName.ReplaceAll(".root", ".pdf");
66     CreateCanvas(pdfName, what & kLandscape);
67     DrawTitlePage(file);
68
69     // --- Possibly make a chapter here ------------------------------
70     if (what & kCentral && GetCollection(file, "Central")) 
71       MakeChapter("Forward");
72     
73     // --- Set pause flag --------------------------------------------
74     fPause = what & kPause;
75
76     // --- Do each sub-algorithm -------------------------------------
77     if (what & kEventInspector)    DrawEventInspector(fSums);
78     if (what & kSharingFilter)     DrawSharingFilter();
79     if (what & kDensityCalculator) DrawDensityCalculator();
80     if (what & kCorrector)         DrawCorrector();
81     if (what & kHistCollector)     DrawHistCollector();
82   
83     
84     if (what & kSteps) DrawSteps();
85     if (what & kResults) DrawResults();
86
87     // --- SPD clusters ----------------------------------------------
88     if (what & kCentral) { 
89       // --- Get top-level collection --------------------------------
90       fSums = GetCollection(file, "Central");
91       if (fSums) {
92         MakeChapter("Central");
93         DrawCentral();
94         if (what & kEventInspector) DrawEventInspector(fSums);
95       }
96       fResults = GetCollection(file, "CentralResults");
97       if (fResults && (what & kResults)) {
98         DrawCentralResults();
99       }
100
101       if (what & kResults) DrawBoth(file);
102     }
103
104     
105     CloseCanvas();
106   }
107 protected:
108   //____________________________________________________________________
109   void DrawTitlePage(TFile* f)
110   {
111     fBody->cd();
112
113     TLatex* ltx = new TLatex(.5, .7, "ESD #rightarrow AOD filtering");
114     ltx->SetNDC();
115     ltx->SetTextSize(0.07);
116     ltx->SetTextAlign(22);
117     ltx->Draw();
118
119     TCollection* fwd = GetCollection(f, "Forward");
120     TCollection* cen = GetCollection(f, "Central");
121     Double_t y = .6;
122     
123     Double_t save = fParName->GetTextSize();
124     fParName->SetTextSize(0.03);
125     fParVal->SetTextSize(0.03);
126
127     DrawParameter(y, "Tasks", (fwd ? "Forward" : ""));
128     DrawParameter(y, "",      (cen ? "Central" : ""));
129
130     if (fwd) { 
131       TCollection* ei = GetCollection(fwd, "fmdEventInspector");
132       if (ei) { 
133
134         Int_t sys=0, sNN=0, field=0, runNo=0;
135         Bool_t mc=false;
136
137         if (GetParameter(ei, "sys", sys))
138           DrawParameter(y, "System", (sys == 1 ? "pp" : sys == 2 ? "PbPb" : 
139                                       sys == 3 ? "pPb" : "unknown"));
140         if (GetParameter(ei, "sNN", sNN)) {
141           TString tsNN = TString::Format("%dGeV", sNN);
142           if (sNN >= 10000) 
143             tsNN = TString::Format("%5.2f", float(sNN)/1000);
144           else if (sNN >= 1000) 
145             tsNN = TString::Format("%4.2f", float(sNN)/1000);
146           DrawParameter(y, "#sqrt{s_{NN}}", tsNN);
147         }
148
149         if (GetParameter(ei, "field", field))
150           DrawParameter(y, "L3 B field", Form("%+2dkG", field));
151
152         if (GetParameter(ei, "runNo", runNo))
153           DrawParameter(y, "Run #", Form("%6d", runNo));
154         
155         if (!GetParameter(ei, "mc", mc)) mc = false;
156         DrawParameter(y, "Simulation", (mc ? "yes" : "no"));    
157       }
158     }
159     PrintCanvas("Title page");
160     fParName->SetTextSize(save);
161     fParVal->SetTextSize(save);
162   }
163   //____________________________________________________________________
164   void DrawSharingFilter()
165   {
166     Info("DrawSharingFilter", "Drawing sharing filter");
167     TCollection* c = GetCollection(fSums, "fmdSharingFilter");
168     if (!c) return;
169     TCollection* rc = GetCollection(fResults, "fmdSharingFilter");
170     if (!rc) rc = c;
171
172     fBody->Divide(1, 3);
173     fBody->cd(1);
174   
175     Double_t y = .8;
176     Bool_t   angle=false, lowSignal=false, simple=false;
177
178     if (GetParameter(c, "angle", angle))
179       DrawParameter(y, "Angle correct", (angle ? "yes" : "no")); 
180     if (GetParameter(c, "lowSignal", lowSignal))
181       DrawParameter(y, "Lower signal",  (lowSignal ? "yes" : "no"));
182     
183     if (GetParameter(c, "simple", simple))
184       DrawParameter(y, "Simple method", (simple ? "yes" : "no"));
185     TParameter<int>* nFiles = 
186       static_cast<TParameter<int>*>(GetObject(c, "nFiles"));
187     if (nFiles)
188       DrawParameter(y, "# files merged", Form("%d", nFiles->GetVal()));
189
190     
191     TCollection* lc = GetCollection(c, "lCuts");
192     TCollection* hc = GetCollection(c, "hCuts");
193     Int_t lm, hm;
194     if (GetParameter(lc, "method", lm)) 
195       DrawParameter(y, "Low cut method", (lm == 0 ? "fixed" : 
196                                           lm == 1 ? "fraction of MPV" : 
197                                           lm == 2 ? "fit range" : 
198                                           lm == 3 ? "Landau width" : 
199                                           "unknown"));
200     if (GetParameter(hc, "method", hm)) 
201       DrawParameter(y, "High cut method", (hm == 0 ? "fixed" : 
202                                           hm == 1 ? "fraction of MPV" : 
203                                           hm == 2 ? "fit range" : 
204                                           hm == 3 ? "Landau width" : 
205                                           "unknown"));
206
207                                           
208     TH2* hLow  = GetH2(c, "lowCuts");
209     TH2* hHigh = GetH2(c, "highCuts");
210     if (hLow  && nFiles) hLow->Scale(1. / nFiles->GetVal());
211     if (hHigh && nFiles) hHigh->Scale(1. / nFiles->GetVal());
212     DrawInPad(fBody, 2, hLow,  "colz");
213     DrawInPad(fBody, 3, hHigh, "colz");
214   
215     PrintCanvas("Sharing filter");
216
217     const char* subs[] = { "FMD1I", "FMD2I", "FMD2O", "FMD3O", "FMD3I", 0 };
218     const char** ptr   = subs;
219     while (*ptr) { 
220       TCollection* sc = GetCollection(c, *ptr);
221       if (!sc) { ptr++; continue; }
222     
223       fBody->Divide(2,3);
224       DrawInPad(fBody, 1, GetH1(sc, "esdEloss"),       "",     0x2);
225       DrawInPad(fBody, 1, GetH1(sc, "anaEloss"),       "same", 0x12);
226       DrawInPad(fBody, 2, GetH1(sc, "singleEloss"),    "",     0x2);
227       DrawInPad(fBody, 2, GetH1(sc, "doubleEloss"),    "same", 0x2);
228       DrawInPad(fBody, 2, GetH1(sc, "tripleEloss"),    "same", 0x12);  
229       DrawInPad(fBody, 3, GetH2(sc, "singlePerStrip"), "colz", 0x4);
230       // DrawInPad(fBody, 4, GetH1(sc, "distanceBefore"), "",     0x2);
231       // DrawInPad(fBody, 4, GetH1(sc, "distanceAfter"),  "same", 0x12);
232       DrawInPad(fBody, 4, GetH2(sc, "summed"),         "colz", 0x0);
233
234       TH2* nB = GetH2(sc, "neighborsBefore");
235       if (nB) { 
236         nB->GetXaxis()->SetRangeUser(0,8); 
237         nB->GetYaxis()->SetRangeUser(0,8); 
238       }
239       DrawInPad(fBody, 5, nB, "colz", 0x4);
240       DrawInPad(fBody, 5, GetH2(sc, "neighborsAfter"), "p same", 0x4);
241       DrawInPad(fBody, 6, GetH2(sc, "beforeAfter"),    "colz",   0x4);
242
243       PrintCanvas(Form("Sharing filter - %s", *ptr));
244       ptr++;
245     }
246
247     // --- MC --------------------------------------------------------
248     TCollection* cc = GetCollection(c, "esd_mc_comparion", false); // Spelling!
249     if (!cc) return; // Not MC 
250
251     DivideForRings(false, false);
252     DrawInRingPad(1, 'I', GetH2(cc, "FMD1i_corr"), "colz", 0x4);
253     DrawInRingPad(2, 'I', GetH2(cc, "FMD2i_corr"), "colz", 0x4);
254     DrawInRingPad(2, 'O', GetH2(cc, "FMD2o_corr"), "colz", 0x4);
255     DrawInRingPad(3, 'I', GetH2(cc, "FMD3i_corr"), "colz", 0x4);
256     DrawInRingPad(3, 'O', GetH2(cc, "FMD3o_corr"), "colz", 0x4);
257
258     PrintCanvas("Sharing filter - MC vs Reco");
259
260     // --- MC --------------------------------------------------------
261     DrawTrackDensity(c);
262   }
263
264   //____________________________________________________________________
265   void DrawDensityCalculator()
266   {
267     Info("DrawDensityCalculator", "Drawing density calculator");
268     TCollection* c = GetCollection(fSums, "fmdDensityCalculator");
269     if (!c) return;
270
271     fBody->Divide(2, 2);
272     fBody->cd(1);
273   
274     Double_t y = .8;
275     Int_t maxParticles=0, phiAcceptance=0, etaLumping=0, phiLumping=0;
276     Bool_t method=false, recalcEta=false, recalcPhi=false;
277     Double_t size = fLandscape ? 0.06 : 0.04;
278   
279     GetParameter(c, "maxParticle", maxParticles);
280
281     if (GetParameter(c, "phiAcceptance", phiAcceptance))
282       DrawParameter(y, "#phi acceptance method", 
283                     (phiAcceptance == 1 ? "N_{ch}" : 
284                      phiAcceptance == 2 ? "#DeltaE" : "none"),       size);
285     
286     if (GetParameter(c, "etaLumping", etaLumping) &&
287         GetParameter(c, "phiLumping", phiLumping))
288       DrawParameter(y, "Region size (sector#timesstrip)", 
289                     Form("%2d #times %2d", phiLumping, etaLumping),  size);
290     
291     if (GetParameter(c, "method", method))
292       DrawParameter(y, "Method", (method ? "Poisson" : "#DeltaE"),   size); 
293
294     if (GetParameter(c, "recalcEta", recalcEta))
295       DrawParameter(y, "Recalculate #eta",(recalcEta ? "yes" : "no"),size); 
296
297     if (GetParameter(c, "recalcPhi", recalcPhi))
298       DrawParameter(y, "Recalculate #phi",(recalcPhi ? "yes" : "no"),size); 
299     TParameter<int>* nFiles = 
300       static_cast<TParameter<int>*>(GetObject(c, "nFiles"));
301     if (nFiles)
302       DrawParameter(y, "# files merged", Form("%d", nFiles->GetVal()));
303
304     TCollection* lc = GetCollection(c, "lCuts");
305     Int_t lm;
306     if (GetParameter(lc, "method", lm)) 
307       DrawParameter(y, "Low cut method", (lm == 0 ? "fixed" : 
308                                           lm == 1 ? "fraction of MPV" : 
309                                           lm == 2 ? "fit range" : 
310                                           lm == 3 ? "Landau width" : 
311                                           "unknown"));
312
313
314     TVirtualPad* p = fBody; // fBody->cd(2);
315     // p->Divide(3,1);
316
317     TH1* accI = GetH1(c, "accI");
318     TH1* accO = GetH1(c, "accO");
319     if (accI) { 
320       Double_t scale = 1./accI->GetMaximum();
321       accI->Scale(scale); 
322       accO->Scale(scale);
323       accI->SetMinimum(0); 
324     }
325     TH2* lCuts = GetH2(c, "lowCuts");
326     TH2* maxW  = GetH2(c, "maxWeights");
327     if (nFiles && lCuts) lCuts->Scale(1. / nFiles->GetVal());
328     if (nFiles && maxW)  maxW->Scale(1. / nFiles->GetVal());
329     DrawInPad(p, 2, accI); 
330     DrawInPad(p, 2, accO,  "same", 0x10); 
331     DrawInPad(p, 3, lCuts, "colz");
332     DrawInPad(p, 4, maxW,  "colz");
333   
334     PrintCanvas("Density calculator");
335
336     const char* subs[] = { "FMD1I", "FMD2I", "FMD2O", "FMD3O", "FMD3I", 0 };
337     const char** ptr   = subs;
338     while (*ptr) { 
339       TCollection* sc = GetCollection(c, *ptr);
340       if (!sc) { ptr++; continue; }
341     
342       fBody->Divide(2,3);
343     
344       DrawInPad(fBody, 1, GetH2(sc, "elossVsPoisson"),   "colz",   0x4);
345       DrawInPad(fBody, 2, GetH1(sc, "diffElossPoisson"), "HIST E", 0x2);
346       DrawInPad(fBody, 3, GetH1(sc, "occupancy"),        "",       0x2);
347       DrawInPad(fBody, 4, GetH1(sc, "eloss"),            "",       0x2);
348       DrawInPad(fBody, 4, GetH1(sc, "elossUsed"),        "same",   0x12);
349       TH1* phiB = GetH1(sc, "phiBefore");
350       TH1* phiA = GetH1(sc, "phiAfter");
351       if (phiB && phiA) { 
352         phiA->Add(phiB, -1);
353         phiA->Divide(phiB);
354         phiA->SetTitle("#Delta#phi from Ip (x,y) correction");
355         phiA->SetYTitle("(#phi_{after}-#phi_{before})/#phi_{before}");
356       }
357       DrawInPad(fBody, 5, phiA);
358       DrawInPad(fBody, 6, GetH2(sc, "phiAcc"), "colz",   0x4);
359     
360       PrintCanvas(Form("Density calculator - %s", *ptr));
361       ptr++;    
362     }
363
364     TCollection* cc = GetCollection(c, "esd_mc_comparison", false); 
365     if (!cc) return; // Not MC 
366
367     fBody->Divide(2,5);
368     DrawInPad(fBody, 1, GetH2(cc, "FMD1I_corr_mc_esd"), "colz", 0x4);
369     DrawInPad(fBody, 3, GetH2(cc, "FMD2I_corr_mc_esd"), "colz", 0x4);
370     DrawInPad(fBody, 5, GetH2(cc, "FMD2O_corr_mc_esd"), "colz", 0x4);
371     DrawInPad(fBody, 7, GetH2(cc, "FMD3O_corr_mc_esd"), "colz", 0x4);
372     DrawInPad(fBody, 9, GetH2(cc, "FMD3I_corr_mc_esd"), "colz", 0x4);
373     DrawInPad(fBody, 2,  GetH1(cc, "FMD1I_diff_mc_esd"), "", 0x2);
374     DrawInPad(fBody, 4,  GetH1(cc, "FMD2I_diff_mc_esd"), "", 0x2);
375     DrawInPad(fBody, 6,  GetH1(cc, "FMD2O_diff_mc_esd"), "", 0x2);
376     DrawInPad(fBody, 8,  GetH1(cc, "FMD3O_diff_mc_esd"), "", 0x2);
377     DrawInPad(fBody, 10, GetH1(cc, "FMD3I_diff_mc_esd"), "", 0x2);
378
379     PrintCanvas("Density calculator - MC vs Reco");
380   }
381
382   //____________________________________________________________________
383   void DrawCorrector()
384   {
385     Info("DrawCorrector", "Drawing corrector"); 
386     TCollection* c = GetCollection(fSums, "fmdCorrector"); 
387     if (!c) return;
388   
389     fBody->cd();
390   
391     Double_t y = .8;  
392     Bool_t secondary=false, vertexBias=false, acceptance=false, merging=false;  
393     if (GetParameter(c, "secondary", secondary))
394       DrawParameter(y, "Secondary corr.", secondary ? "yes" : "no");
395     if (GetParameter(c, "acceptance", acceptance))
396       DrawParameter(y, "Acceptance corr.", acceptance ? "yes" : "no");
397     if (GetParameter(c, "vertexBias", vertexBias))
398       DrawParameter(y, "Vertex bias corr.", vertexBias ? "yes" : "no");
399     if (GetParameter(c, "merging", merging))  
400       DrawParameter(y, "Merging eff.", merging ? "yes" : "no");
401     
402     PrintCanvas("Corrector");
403
404     TCollection* cc = GetCollection(c, "esd_mc_comparison", false); 
405     if (!cc) return; // Not MC 
406     
407     DivideForRings(false, false);
408
409     DrawInRingPad(1, 'I', GetH2(cc, "FMD1I_esd_vs_mc"), "colz", 0x0);
410     DrawInRingPad(2, 'I', GetH2(cc, "FMD2I_esd_vs_mc"), "colz", 0x0);
411     DrawInRingPad(2, 'O', GetH2(cc, "FMD2O_esd_vs_mc"), "colz", 0x0);
412     DrawInRingPad(3, 'O', GetH2(cc, "FMD3O_esd_vs_mc"), "colz", 0x0);
413     DrawInRingPad(3, 'I', GetH2(cc, "FMD3I_esd_vs_mc"), "colz", 0x0);
414
415     PrintCanvas("Corrector - MC vs Reco");
416   }
417
418   //____________________________________________________________________
419   void DrawHistCollector()
420   {
421     Info("DrawHistCollector", "Drawing histogram collector");  
422     TCollection* c = GetCollection(fSums, "fmdHistCollector");
423     if (!c) return;
424
425     fBody->Divide(1, 3);
426     fBody->cd(1);
427
428     Double_t y = .8;
429     Int_t nCutBins=0, fiducial=0, merge=0, skipRings=0;
430     Double_t fiducialCut=0.;
431     Bool_t  bgAndHits=false;
432
433     if (GetParameter(c, "nCutBins", nCutBins))
434       DrawParameter(y, "# of bins to cut",      Form("%d", nCutBins));
435
436     if (GetParameter(c, "skipRings", skipRings)) {
437       TString skipped;
438       if (skipRings & 0x05) skipped.Append("FMD1i ");
439       if (skipRings & 0x09) skipped.Append("FMD2i ");
440       if (skipRings & 0x0a) skipped.Append("FMD2o ");
441       if (skipRings & 0x11) skipped.Append("FMD3i ");
442       if (skipRings & 0x12) skipped.Append("FMD3o ");
443       DrawParameter(y, "Skipped rings", skipped);
444     }
445
446     if (GetParameter(c, "bgAndHits", bgAndHits))
447       DrawParameter(y, "Bg & hit maps stored.", bgAndHits?"yes":"no");
448
449     if (GetParameter(c, "merge", merge))
450       DrawParameter(y, "Merge method", 
451                     (merge == 0 ? "straight mean" :
452                      merge == 1 ? "straight mean, no zeroes" : 
453                      merge == 2 ? "weighted mean" : 
454                      merge == 3 ? "least error" : 
455                      merge == 4 ? "sum" : "unknown"));
456
457     if (GetParameter(c, "fiducial", fiducial))
458       DrawParameter(y, "Fiducial method.", 
459                     fiducial == 0 ? "cut" : "distance");
460
461     if (GetParameter(c, "fiducialCut", fiducialCut))
462       DrawParameter(y, "Fiducial cut.", Form("%f", fiducialCut));
463
464                  
465     DrawInPad(fBody, 2, GetH2(c, "sumRings"), "colz"); 
466     DrawInPad(fBody, 3, GetH2(c, "coverage"), "colz");
467
468     fBody->cd(1)->Modified();
469     fBody->cd(2)->Modified();
470     fBody->cd(3)->Modified();
471     fBody->cd(1)->Update();
472     fBody->cd(2)->Update();
473     fBody->cd(3)->Update();
474     PrintCanvas("Histogram collector");
475                 
476     
477     TIter next(c);
478     TObject* o = 0;
479     TRegexp regexp("[pm][0-9]+_[pm][0-9]+");
480     while ((o = next())) { 
481       TString name(o->GetName());
482       if (name.Index(regexp) == kNPOS) continue;
483       
484       TList* vl = static_cast<TList*>(o);
485
486       DivideForRings(false, false);
487       
488       DrawInRingPad(1, 'I', GetH2(vl, "secMapFMD1I"), "colz", 0x0);
489       DrawInRingPad(2, 'I', GetH2(vl, "secMapFMD2I"), "colz", 0x0);
490       DrawInRingPad(2, 'O', GetH2(vl, "secMapFMD2O"), "colz", 0x0);
491       DrawInRingPad(3, 'O', GetH2(vl, "secMapFMD3O"), "colz", 0x0);
492       DrawInRingPad(3, 'I', GetH2(vl, "secMapFMD3I"), "colz", 0x0);
493       DrawInRingPad(1, 'I', GetH2(vl, "hitMapFMD1I"), "box same", 0x0);
494       DrawInRingPad(2, 'I', GetH2(vl, "hitMapFMD2I"), "box same", 0x0);
495       DrawInRingPad(2, 'O', GetH2(vl, "hitMapFMD2O"), "box same", 0x0);
496       DrawInRingPad(3, 'O', GetH2(vl, "hitMapFMD3O"), "box same", 0x0);
497       DrawInRingPad(3, 'I', GetH2(vl, "hitMapFMD3I"), "box same", 0x0);
498
499       PrintCanvas(Form("Histogram Collector - Vertex bin %s", vl->GetName()));
500     }
501
502     o = c->FindObject("byCentrality");
503     if (!o) return;
504     TList* bc = static_cast<TList*>(o);
505
506     DrawInPad(fBody, GetH3(bc, "FMD1I"), "box", 0);
507     DrawInPad(fBody, GetH3(bc, "FMD2I"), "box same", 0);
508     DrawInPad(fBody, GetH3(bc, "FMD2O"), "box same", 0);
509     DrawInPad(fBody, GetH3(bc, "FMD3O"), "box same", 0);
510     DrawInPad(fBody, GetH3(bc, "FMD3I"), "box same", 0x10);
511   }
512
513   //____________________________________________________________________
514   void DrawCentral()
515   {
516     Info("DrawCentral", "Drawing central (SPD)");  
517     TCollection* c = fSums; 
518     if (!c) return;
519
520     fBody->Divide(1, 3);
521     fBody->cd(1);
522
523                  
524     DrawInPad(fBody, 1, GetH2(c, "coverage"), "col", 0);
525     DrawInPad(fBody, 2, GetH2(c, "nClusterVsnTracklet"), "colz", 0x03); 
526     DrawInPad(fBody, 3, GetH2(c, "clusterPerTracklet"), "colz", 0x0); 
527
528     fBody->cd(1)->Modified();
529     fBody->cd(2)->Modified();
530     fBody->cd(3)->Modified();
531     fBody->cd(1)->Update();
532     fBody->cd(2)->Update();
533     fBody->cd(3)->Update();
534     PrintCanvas("Central - overview");
535                 
536     
537     TIter next(c);
538     TObject* o = 0;
539     TRegexp regexp("[pm][0-9]+_[pm][0-9]+");
540     while ((o = next())) { 
541       TString name(o->GetName());
542       if (name.Index(regexp) == kNPOS) continue;
543       
544       TList* vl = static_cast<TList*>(o);
545
546       fBody->Divide(1, 3);
547     
548       DrawInPad(fBody, 1, GetH1(vl, "acceptance"), "", 0);
549
550       TH1* sec = GetH1(vl, "secondary");
551       sec->SetMarkerStyle(21);
552       sec->SetMarkerSize(1.2);
553       DrawInPad(fBody, 2, sec, "", 0);
554       DrawInPad(fBody, 2, GetH1(vl, "secondaryFiducial"),    "same", 0x0);
555       DrawInPad(fBody, 3, GetH2(vl, "secondaryMapFiducial"), "colz", 0);
556       DrawInPad(fBody, 3, GetH2(vl, "hitMap"),               "box same", 0x0);
557
558       fBody->cd(1)->Modified();
559       fBody->cd(2)->Modified();
560       fBody->cd(3)->Modified();
561       fBody->cd(1)->Update();
562       fBody->cd(2)->Update();
563       fBody->cd(3)->Update();
564       PrintCanvas(Form("Central - Vertex bin %s", vl->GetName()));
565     }
566   }
567
568   
569   //____________________________________________________________________
570   void AddToAll(THStack* all, const THStack* stack, Int_t curr, Int_t step)
571   {
572     if (!stack) return;
573
574     TIter   next(stack->GetHists());
575     TH1*    h = 0;
576     while ((h = static_cast<TH1*>(next()))) {
577       TH1* copy = static_cast<TH1*>(h->Clone(Form("%s_copy", h->GetName())));
578       copy->SetDirectory(0);
579       if (curr != step) {
580         copy->SetMarkerColor(kGray);
581         copy->SetLineColor(kGray);
582       }
583       all->Add(copy);
584     }
585   }
586   //____________________________________________________________________
587   void AddToAll(THStack* all, const THStack* stack)
588   {
589     if (!stack) return;
590
591     TIter   next(stack->GetHists());
592     TH1*    h = 0;
593     while ((h = static_cast<TH1*>(next()))) {
594       TH1* copy = static_cast<TH1*>(h->Clone(Form("%s_copy", h->GetName())));
595       copy->SetDirectory(0);
596       copy->SetMarkerColor(kGray);
597       copy->SetLineColor(kGray);
598       all->Add(copy);
599     }
600   }
601
602   //____________________________________________________________________
603   void DrawStep(Int_t        step,
604                 THStack*     all,
605                 TObject*     cur,
606                 TLegend*     leg,
607                 const char*  title,
608                 TVirtualPad* can)
609   {
610     if (all->GetHists()->GetEntries() <= 0 || !cur) return;
611
612     // Info("", "Drawing step # %d", step);
613     Bool_t left = (step % 2) == 1; 
614     TVirtualPad* p = can->cd(step);
615     gStyle->SetOptTitle(0);
616     p->SetTitle(Form("Step # %d", step));
617     p->SetFillColor(kWhite);
618     p->SetRightMargin(left ? 0 : 0.02);
619     p->SetTopMargin(0); // 0.02);
620
621     p->cd();
622     all->Draw("nostack");
623     all->GetHistogram()->SetXTitle("#eta");
624     all->GetHistogram()->SetYTitle("signal");
625
626     // p->cd();
627     gROOT->SetSelectedPad(p);
628     cur->DrawClone("same nostack");
629     leg->DrawClone("");
630
631     TLatex* ltx = new TLatex(.97, .97, title);
632     ltx->SetNDC();
633     ltx->SetTextSize(.06);
634     ltx->SetTextAlign(33);
635     ltx->Draw();
636
637     ltx = new TLatex((left ? .12 : .02), .97, p->GetTitle());
638     ltx->SetNDC();
639     ltx->SetTextSize(.06);
640     ltx->SetTextAlign(13);
641     ltx->Draw();
642
643     p->Modified();
644     p->Update();
645     p->cd();
646   }
647
648   //____________________________________________________________________
649   void FixStack(THStack* stack, const TString& title, 
650                 const TString& extra, Int_t marker)
651   {
652     if (!stack) return;
653     stack->SetTitle(title);
654     TIter next(stack->GetHists());
655     TH1*  h = 0;
656     while ((h = static_cast<TH1*>(next())))  {
657       h->SetMarkerStyle(marker);
658       TString tit(h->GetTitle());
659       tit.ReplaceAll("cache", "");
660       tit.Append(extra);
661       h->SetTitle(tit);
662     }
663   }
664   void AddLegendEntry(TLegend* l, 
665                       const TH1* h, 
666                       const TString& title)
667   {
668     if (!h) return;
669
670     TLegendEntry* e = l->AddEntry("dummy", title.Data(), "pl");
671     e->SetMarkerStyle(h->GetMarkerStyle());
672     e->SetMarkerColor(kGray);
673     e->SetLineColor(kGray);
674     e->SetTextColor(kGray);
675   }
676                       
677
678   //____________________________________________________________________
679   void DrawSteps()
680   {
681     // MakeChapter(can, "Steps");
682
683     THStack* deltas  = GetStack(GetCollection(fResults, "fmdSharingFilter"), 
684                                 "sums", "summed");
685     THStack* nchs    = GetStack(GetCollection(fResults, 
686                                               "fmdDensityCalculator"), 
687                                 "sums", "inclDensity");
688     THStack* prims   = GetStack(GetCollection(fResults, "fmdCorrector"), 
689                                 "sums", "primaryDensity");
690     THStack* rings   = GetStack(GetCollection(fResults, "ringResults"), "all");
691     THStack* mcRings = GetStack(GetCollection(fResults, "mcRingResults", false),
692                                 "all","dndeta_eta", false);
693     TH1*     dndeta  = GetH1(fResults, "dNdeta");
694     if (dndeta) dndeta->SetMarkerColor(kBlack);
695
696     FixStack(deltas, "#sum_{} #Delta/#Delta_{mip}",  "",     20);
697     FixStack(nchs,   "#sum_{} N_{ch,incl}",          "",     21);
698     FixStack(prims,  "#sum_{} N_{ch,primary}",       "",     22);
699     FixStack(rings,  "dN/d#eta per ring",            "",     23);
700     FixStack(mcRings,"dN/d#eta per ring (MC)",       "(MC)", 34);
701
702     THStack* all = new THStack;
703     AddToAll(all, mcRings);
704     AddToAll(all, deltas);
705     AddToAll(all, nchs);
706     AddToAll(all, prims);
707     AddToAll(all, rings);
708
709     TH1* res = 0;
710     if (dndeta) {
711       res = static_cast<TH1*>(dndeta->Clone("dNdeta"));
712       res->SetTitle("dN/d#eta");
713       res->SetMarkerColor(kGray);
714       res->SetLineColor(kGray);
715       res->SetDirectory(0);
716       all->Add(res);
717     }
718
719     TLegend* l = new TLegend(.35, .2, .55, .9);
720     l->SetFillColor(kWhite);
721     l->SetFillStyle(0);
722     l->SetBorderSize(0);
723     TLegendEntry* e = 0;
724
725     TH1* h = 0;
726     if (mcRings) {
727       h = static_cast<TH1*>(mcRings->GetHists()->At(0));
728       AddLegendEntry(l, h, mcRings->GetTitle());
729     }
730
731     if (deltas) {
732       h = static_cast<TH1*>(deltas->GetHists()->At(0));
733       AddLegendEntry(l, h, deltas->GetTitle());    
734     }
735
736     if (nchs) {
737       h = static_cast<TH1*>(nchs->GetHists()->At(0));
738       AddLegendEntry(l, h, nchs->GetTitle());    
739     }
740
741     if (prims) {
742       h = static_cast<TH1*>(prims->GetHists()->At(0));
743       AddLegendEntry(l, h, prims->GetTitle());    
744     }
745
746     if (rings) {
747       h = static_cast<TH1*>(rings->GetHists()->At(0));
748       AddLegendEntry(l, h, rings->GetTitle());    
749     }
750
751     if (res) {
752       h = res;
753       AddLegendEntry(l, h, h->GetTitle());
754     }
755     
756     TObject* objs[] = { mcRings, 
757                         deltas, 
758                         nchs, 
759                         prims, 
760                         rings, 
761                         dndeta };
762     const char* titles[] = { "MC", 
763                              "After merging", 
764                              "After particle counting", 
765                              "After corrections", 
766                              "After normalization", 
767                              "After combining" };
768     
769     fBody->Divide(2, 3, 0, 0); // mcRings ? 4 : 3, 0, 0);
770     Int_t step = 0;
771     for (Int_t i = 0; i < 6; i++) { 
772       TObject* obj = objs[i];
773       if (!obj) continue;
774       e = static_cast<TLegendEntry*>(l->GetListOfPrimitives()->At(step));
775       e->SetMarkerColor(kBlack);
776       e->SetLineColor(kBlack);
777       e->SetTextColor(kBlack);
778       step++;
779       
780       DrawStep(step, all, obj, l, titles[i], fBody);
781       e->SetMarkerColor(kGray);
782       e->SetLineColor(kGray);
783       e->SetTextColor(kGray);
784     }
785
786     if (!mcRings && deltas) { 
787       fBody->cd(6);
788       TLegend* ll = new TLegend(0.01, 0.11, 0.99, 0.99);
789       // ll->SetNDC();
790       ll->SetFillColor(kWhite);
791       ll->SetFillStyle(0);
792       ll->SetBorderSize(0);
793
794       TIter next(deltas->GetHists());
795       TH1*  hh = 0;
796       while ((hh = static_cast<TH1*>(next()))) {
797         e = ll->AddEntry("dummy", hh->GetTitle(), "pl");
798         e->SetMarkerColor(hh->GetMarkerColor());
799         e->SetMarkerStyle(hh->GetMarkerStyle());
800         e->SetLineColor(kBlack);
801       }
802       ll->Draw();
803     }
804     PrintCanvas("Steps");
805   }
806
807
808   //____________________________________________________________________
809   void DrawResults()
810   {
811     // MakeChapter(can, "Results");
812
813     fBody->Divide(2,2);
814
815     TCollection* c = GetCollection(fResults, "ringResults");
816     if (!c) return;
817   
818     THStack* mcRings = GetStack(GetCollection(fResults, "mcRingResults", false),
819                                 "all", "dndeta_eta", false);
820
821     TH1* dndeta_phi = GetH1(fResults, "dNdeta");
822     TH1* dndeta_eta = GetH1(fResults, "dNdeta_");
823     dndeta_phi->SetTitle("1/N_{ev}dN_{ch}/d#eta (#varphi norm)");
824     dndeta_eta->SetTitle("1/N_{ev}dN_{ch}/d#eta (#eta norm)");
825     dndeta_eta->SetMarkerSize(0.7);
826
827     THStack* allPhi = new THStack("phiAcc", "#varphi Acceptance");
828     THStack* allEta = new THStack("etaCov", "#eta Coverage");
829     const char*  rings[] = { "FMD1I", "FMD2I", "FMD2O", "FMD3I", "FMD3O", 0 };
830     const char** pring   = rings;
831     
832     while ((*pring)) { 
833       TCollection* cc     = GetCollection(c, *pring);
834       TH1*         etaCov = GetH1(cc, "etaCov");
835       TH1*         phiAcc = GetH1(cc, "phiAcc");
836       TH1*         dndeta = GetH1(cc, "dndeta_phi");
837       Int_t        color  = kBlack;
838       if (dndeta)  color  = dndeta->GetMarkerColor();
839       if (etaCov) { 
840         etaCov->SetTitle(*pring);
841         etaCov->SetFillColor(color);
842         etaCov->SetLineColor(color);
843         allEta->Add(etaCov);
844       }
845       if (phiAcc) { 
846         phiAcc->SetFillColor(color);
847         phiAcc->SetLineColor(color);
848         allPhi->Add(phiAcc);
849       }
850       pring++;
851     }
852     DrawInPad(fBody, 1, GetStack(c, "all"), "nostack", mcRings ? 0 : 0x10);
853     DrawInPad(fBody, 2, dndeta_phi);
854     DrawInPad(fBody, 2, dndeta_eta, "Same", 0x10);
855     DrawInPad(fBody, 3, allEta, "nostack hist", 0x10);
856     DrawInPad(fBody, 3, allPhi, "nostack hist same", 0x0);
857     DrawInPad(fBody, 4, GetH1(fResults, "norm"));
858     DrawInPad(fBody, 4, GetH1(fResults, "phi"), "same", 0x10);
859     // DrawInPad(fBody, 4, GetH1(fSums,    "d2Ndetadphi"), "colz");
860     DrawInPad(fBody, 1, mcRings, "nostack same", 0x10);
861
862     fBody->cd(1);
863     TLatex* l = new TLatex(.5, .2, "Ring results");
864     l->SetNDC();
865     l->SetTextAlign(21);
866     l->Draw();
867
868     fBody->cd(2);
869     l->DrawLatex(.5, .2, "1/N_{ev}dN_{ch}/d#eta");
870
871     // fBody->cd(3);
872     // l->DrawLatex(.5, .2, "1/N_{ev}dN_{ch}/d#eta (#vta norm.)");
873     
874     PrintCanvas("Results");
875   }
876
877   //____________________________________________________________________
878   void DrawCentralResults()
879   {
880     // MakeChapter(can, "Results");
881     Info("DrawCentralResults", "Drawing central results");
882
883     fBody->Divide(1,2,0,0);
884
885     TH1* dndeta_ = GetH1(fResults, "dNdeta_");
886     TH1* dndeta  = GetH1(fResults, "dNdeta");
887     THStack* stack = new THStack("dndetas", 
888                                  "d#it{N}_{ch}/d#it{#eta} - central");
889     stack->Add(dndeta_);
890     stack->Add(dndeta);
891     
892     DrawInPad(fBody, 1, stack, "nostack");
893     stack->GetHistogram()->SetXTitle("#it{#eta}");
894     stack->GetHistogram()->SetYTitle("#frac{d#it{N}_{ch}}{d#it{#eta}}");
895     fBody->cd(1);
896     TLegend* l = new TLegend(.3, .05, .7, .4);
897     l->SetFillColor(0);
898     l->SetFillStyle(0);
899     l->SetBorderSize(0);
900     l->AddEntry(dndeta_, "Normalized to coverage",        "lp");
901     l->AddEntry(dndeta,  "Normalized to #phi acceptance", "lp");
902     l->Draw();
903
904     DrawInPad(fBody, 2, GetH1(fResults, "norm"));
905     DrawInPad(fBody, 2, GetH1(fResults, "phi"), "same", kLegend);
906
907     PrintCanvas("Central Results");
908
909   }
910   void DrawBoth(TFile* file)
911   {
912     Info("DrawBoth", "Drawing central & forward results");
913     TCollection* central = GetCollection(file, "CentralResults");
914     TCollection* forward = GetCollection(file, "ForwardResults");
915     
916     if (!central || !forward) {
917       Warning("DrawBoth", "central %p or forward %p results not found", 
918               central, forward);
919       return;
920     }
921
922     TH1* f1 = GetH1(forward, "dNdeta_");
923     TH1* c1 = GetH1(central, "dNdeta_");
924     TH1* f2 = GetH1(forward, "dNdeta");
925     TH1* c2 = GetH1(central, "dNdeta");
926     f1->SetLineColor(kBlack);
927     f2->SetLineColor(kBlack);
928     c1->SetLineColor(kBlack);
929     c2->SetLineColor(kBlack);
930     f1->SetMarkerColor(f2->GetMarkerColor());
931     f1->SetMarkerStyle(24);
932     c1->SetMarkerStyle(24);
933     c2->SetMarkerStyle(20);
934     c2->SetMarkerColor(c1->GetMarkerColor());
935     THStack* s = new THStack("dndetas", "d#it{N}_{ch}/d#it{#eta}");
936     s->Add(f1);
937     s->Add(c1);
938     s->Add(f2);
939     s->Add(c2);
940
941     fBody->Divide(1, 2, 0, 0);
942     DrawInPad(fBody, 1, s, "nostack");
943     s->GetHistogram()->SetXTitle("#it{#eta}");
944     s->GetHistogram()->SetYTitle("#frac{d#it{N}_{ch}}{d#it{#eta}}");
945     
946     fBody->cd(1);
947     TLegend* l = new TLegend(.4, .05, .8, .4);
948     l->SetFillColor(0);
949     l->SetFillStyle(0);
950     l->SetBorderSize(0);
951     TLegendEntry* entry = l->AddEntry("dummy", "Forward", "f");
952     entry->SetFillColor(f1->GetMarkerColor());
953     entry->SetLineColor(f1->GetMarkerColor());
954     entry->SetFillStyle(1001);
955     entry->SetLineWidth(0);
956     entry = l->AddEntry("dummy", "Central", "f");
957     entry->SetFillColor(c1->GetMarkerColor());
958     entry->SetLineColor(c1->GetMarkerColor());
959     entry->SetLineWidth(0);
960     entry->SetFillStyle(1001);
961     entry = l->AddEntry("dummy", "Normalized to coverage", "lp");
962     entry->SetMarkerStyle(f1->GetMarkerStyle());
963     entry = l->AddEntry("dummy", "Normalized to #phi acceptance", "lp");
964     entry->SetMarkerStyle(f2->GetMarkerStyle());
965     l->Draw();
966
967     TH1* f3 = GetH1(forward, "norm");
968     TH1* c3 = GetH1(central, "norm");
969     TH1* f4 = GetH1(forward, "phi");
970     TH1* c4 = GetH1(central, "phi");
971     f3->SetFillColor(f1->GetMarkerColor());
972     f4->SetFillColor(f1->GetMarkerColor());
973     c3->SetFillColor(c1->GetMarkerColor());
974     c4->SetFillColor(c1->GetMarkerColor());
975     f3->SetLineColor(f1->GetMarkerColor());
976     f4->SetLineColor(f1->GetMarkerColor());
977     c3->SetLineColor(c1->GetMarkerColor());
978     c4->SetLineColor(c1->GetMarkerColor());
979     
980     THStack* a = new THStack("norms", "Normalizations");
981     a->Add(f3);
982     a->Add(c3);
983     a->Add(f4);
984     a->Add(c4);
985     
986     a->SetMaximum(a->GetMaximum("nostack")*1.2);
987     DrawInPad(fBody, 2, a, "nostack");
988     a->GetHistogram()->SetXTitle("#it{#eta}");
989     a->GetHistogram()->SetYTitle("Normalization (coverage or acceptance)");
990     
991     fBody->cd(2);
992     l = new TLegend(.2, .94, .9, .99);
993     l->SetFillColor(0);
994     l->SetFillStyle(0);
995     l->SetBorderSize(0);
996     l->SetNColumns(2);
997     // entry = l->AddEntry("dummy", "Forward", "f");
998     // entry->SetFillColor(f1->GetMarkerColor());
999     // entry->SetLineColor(f1->GetMarkerColor());
1000     // entry->SetFillStyle(1001);
1001     // entry->SetLineWidth(0);
1002     // entry = l->AddEntry("dummy", "Central", "f");
1003     // entry->SetFillColor(c1->GetMarkerColor());
1004     // entry->SetLineColor(c1->GetMarkerColor());
1005     // entry->SetLineWidth(0);
1006     // entry->SetFillStyle(1001);
1007     entry = l->AddEntry("dummy", "#eta Coverage", "f");
1008     entry->SetFillStyle(f3->GetFillStyle());
1009     entry->SetFillColor(kBlack);
1010     entry = l->AddEntry("dummy", "#phi Acceptance", "f");
1011     entry->SetFillStyle(f4->GetFillStyle());
1012     entry->SetFillColor(kBlack);
1013     l->Draw();
1014
1015     PrintCanvas("Both results");
1016   }
1017   TCollection* fSums;
1018   TCollection* fResults;
1019 };
1020
1021 // #endif