]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/scripts/SummaryMCCorrDrawer.C
This commit has two major parts:
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / scripts / SummaryMCCorrDrawer.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 SummaryMCCorrDrawer : public SummaryDrawer
16 {
17 public:
18   enum EFlags { 
19     kEventInspector    = 0x001, 
20     kTrackDensity      = 0x002,
21     kVertexBins        = 0x004,
22     kResults           = 0x008, 
23     kPause             = 0x080,
24     kLandscape         = 0x100, 
25     kCentral           = 0x200,
26     kNormal            = 0x20F
27   };
28   SummaryMCCorrDrawer() 
29     : SummaryDrawer(),
30       fSums(0),
31       fResults(0)
32   {}
33   virtual ~SummaryMCCorrDrawer() {}
34   
35   //__________________________________________________________________
36   /** 
37    * 
38    * 
39    * @param fname 
40    * @param what 
41    */
42   void Run(const char* fname, UShort_t what=kNormal)
43   {
44     // --- Open the file ---------------------------------------------
45     TString filename(fname);
46     TFile*  file = TFile::Open(filename, "READ");
47     if (!file) { 
48       Error("Run", "Failed to open \"%s\"", filename.Data());
49       return;
50     }
51
52
53     // --- Get top-level collection ----------------------------------
54     fSums = GetCollection(file, "ForwardCorrSums");
55     if (!fSums) return;
56
57     // --- Make our canvas -------------------------------------------
58     TString pdfName(filename);
59     pdfName.ReplaceAll(".root", ".pdf");
60     CreateCanvas(pdfName, what & 0x100);
61
62     // --- Possibly make a chapter here ------------------------------
63     if (what & kCentral && GetCollection(file, "CentralCorrSums")) 
64       MakeChapter("Forward");
65     
66     // --- Set pause flag --------------------------------------------
67     fPause = what & 0x80;
68
69     // --- Do each sub-algorithm -------------------------------------
70     if (what & kEventInspector) DrawEventInspector(fSums);
71     if (what & kTrackDensity)   DrawTrackDensity(fSums);
72     if (what & kVertexBins)     DrawVertexBins(true);
73   
74     // --- Do the results ----------------------------------------------
75     fResults = GetCollection(file, "ForwardCorrResults");
76     if (!fResults) fResults = fSums; // Old-style
77     
78     if (what & kResults) DrawResults(true);
79
80     // --- SPD clusters ----------------------------------------------
81     if (what & kCentral) { 
82       // --- Get top-level collection --------------------------------
83       fSums = GetCollection(file, "CentralCorrSums");
84       if (fSums) {
85         MakeChapter("Central");
86         if (what & kEventInspector) DrawEventInspector(fSums);
87         if (what & kTrackDensity)   DrawTrackDensity(fSums);
88         if (what & kVertexBins)     DrawVertexBins(false);
89       }
90       else 
91         Warning("", "No CentralCorrSums found");
92
93       fResults = GetCollection(file, "CentralCorrResults");
94       if (!fResults) fResults = fSums; // Old-style
95       if (!fResults) 
96         Warning("", "No CentralCorrResults found");
97
98       if (what & kResults) DrawResults(false);
99     }
100
101     CloseCanvas();
102   }
103 protected:
104   //____________________________________________________________________
105   TCollection* GetVertexList(TCollection* parent, const TAxis& axis, Int_t bin)
106   {
107     TString folder = TString::Format("vtx%+05.1f_%+05.1f", 
108                                      axis.GetBinLowEdge(bin), 
109                                      axis.GetBinUpEdge(bin));
110     folder.ReplaceAll(".", "d");
111     folder.ReplaceAll("+", "p");
112     folder.ReplaceAll("-", "m");
113     
114     TCollection* c = GetCollection(parent, folder);
115     if (!c) 
116       Warning("DrawVertexBins", "List %s not found", folder.Data());
117         
118     return c;
119   }
120   //____________________________________________________________________
121   void DrawVertexBins(Bool_t forward)
122   {
123     Info("DrawVertexBins", "Drawing %s vertex bins",
124          forward ? "Forward" : "Central");
125     TH1* vtxHist = GetH1(fSums, "vtxAxis");
126     if (!vtxHist) return;
127     
128     TAxis* vtxAxis = vtxHist->GetXaxis();
129     for (Int_t i = 1; i <= vtxAxis->GetNbins(); i++) {
130       Info("", "Bin %d", i);
131       TCollection* c = GetVertexList(fSums, *vtxAxis, i);
132       if (!c) continue;
133       
134       if (forward) {
135         DivideForRings(true, true);
136         for (UShort_t d = 1; d <= 3; d++) { 
137           for (UShort_t q = 0; q < (d == 1 ? 1 : 2); q++) { 
138             Char_t r = q == 0 ? 'I' : 'O';
139             DrawInRingPad(d,r, GetH2(c, Form("FMD%d%c_cache",d,r)), "colz");
140           }
141         }
142         DrawInPad(fBody, 2, GetH2(c, "primary"), "colz");
143       }
144       else {
145         fBody->Divide(1,3, 0, 0);
146         
147         DrawInPad(fBody, 1, GetH2(c, "hits"),     "colz");
148         DrawInPad(fBody, 2, GetH2(c, "clusters"), "colz");
149         DrawInPad(fBody, 3, GetH2(c, "primary"), "colz");
150       }
151       PrintCanvas(Form("%s sums - Vertex bin %+5.1f - %+5.1f",
152                        (forward ? "Forward" : "Central"),
153                        vtxAxis->GetBinLowEdge(i), 
154                        vtxAxis->GetBinUpEdge(i)));
155     }
156   }
157   //____________________________________________________________________
158   void DrawResults(Bool_t forward)
159   {
160     Info("DrawVertexBins", "Drawing resulting %s vertex bins",
161          forward ? "Forward" : "Central");
162     TH1* vtxHist = GetH1(fSums, "vtxAxis");
163     if (!vtxHist) return;
164     
165     TAxis* vtxAxis = vtxHist->GetXaxis();
166     for (Int_t i = 1; i <= vtxAxis->GetNbins(); i++) {
167       TCollection* c = GetVertexList(fResults, *vtxAxis, i);
168       if (!c) continue;
169
170       if (forward) {
171         DivideForRings(true, true);
172         for (UShort_t d = 1; d <= 3; d++) { 
173           for (UShort_t q = 0; q < (d == 1 ? 1 : 2); q++) { 
174             Char_t r = q == 0 ? 'I' : 'O';
175             TVirtualPad* p = RingPad(d, r);
176             p->cd();
177             p->Divide(1,2,0,0);
178             TH2* h = GetH2(c, Form("FMD%d%c_vtxbin%03d",d,r,i));
179             DrawInPad(p,1, h,"colz");
180             TVirtualPad* pp = p->cd(1);
181             TVirtualPad* ppp = p->cd(2);
182             ppp->SetRightMargin(pp->GetRightMargin());
183             TH1* hh = h->ProjectionX();
184             hh->Scale(1./ h->GetNbinsY());
185             hh->SetFillColor(RingColor(d,r));
186             hh->SetFillStyle(3001);
187             hh->SetTitle(Form("#LT%s#GT", hh->GetTitle()));
188             DrawInPad(p,2, hh, "hist e");
189           }
190         }
191       }
192       else {
193         fBody->Divide(2,4,0,0);
194         TH2* secMap               = GetH2(c, "secMap");
195         TH2* secMapAlt            = GetH2(c, "secMapEff");
196         if (!secMapAlt) secMapAlt = GetH2(c, "secMapHit");
197         TH1* acc                  = GetH1(c, "acc");
198         TH1* accAlt               = GetH1(c, "accEff");
199         if (!accAlt) accAlt       = GetH1(c, "accHit");
200
201         TH1* secMapProj = secMap->ProjectionX();
202         secMapProj->Scale(1./ secMap->GetNbinsY());
203         secMapProj->Divide(acc);
204         secMapProj->SetFillColor(kRed+1);
205         secMapProj->SetFillStyle(3001);
206         secMapProj->SetTitle(Form("#LT%s#GT/Acceptance", secMap->GetTitle()));
207
208         TH1* secMapAltProj = secMapAlt->ProjectionX();
209         secMapAltProj->Scale(1./ secMapAlt->GetNbinsY());
210         secMapAltProj->Divide(accAlt);
211         secMapAltProj->SetFillColor(kBlue+1);
212         secMapAltProj->SetFillStyle(3001);
213         secMapAltProj->SetTitle(Form("#LT%s#GT/Acceptance", 
214                                      secMapAlt->GetTitle()));
215
216         Double_t secMapMax = TMath::Max(secMap->GetMaximum(),
217                                         secMapAlt->GetMaximum());
218         secMap->SetMaximum(secMapMax);
219         secMapAlt->SetMaximum(secMapMax);
220
221         Double_t secMapProjMax = TMath::Max(secMapProj->GetMaximum(),
222                                             secMapAltProj->GetMaximum());
223         secMapProj->SetMaximum(secMapProjMax);
224         secMapAltProj->SetMaximum(secMapProjMax);
225
226         acc->SetFillColor(kRed+1);
227         acc->SetFillStyle(3001);
228         accAlt->SetFillColor(kBlue+1);
229         accAlt->SetFillStyle(3001);
230
231         Double_t accMax = TMath::Max(acc->GetMaximum(),accAlt->GetMaximum());
232         acc->SetMaximum(accMax);
233         accAlt->SetMaximum(accMax);
234
235         DrawInPad(fBody, 1, secMap,    "colz", kGridx);
236         DrawInPad(fBody, 2, secMapAlt, "colz", kGridx);
237
238         TVirtualPad* p = fBody;
239         TVirtualPad* pp = p->cd(1);
240         TVirtualPad* ppp = p->cd(3);
241         ppp->SetRightMargin(pp->GetRightMargin());
242         DrawInPad(p,3, secMapProj, "hist", kGridx|kGridy);
243
244         ppp = p->cd(5);
245         ppp->SetRightMargin(pp->GetRightMargin());
246         DrawInPad(fBody, 5, acc, "", kGridx|kGridy);
247
248         pp = p->cd(2);
249         pp->SetLeftMargin(0.10);
250         ppp = p->cd(4);
251         ppp->SetRightMargin(pp->GetRightMargin());
252         ppp->SetLeftMargin(0.10);
253         DrawInPad(p,4, secMapAltProj, "hist", kGridx|kGridy);
254
255         pp = p->cd(4);
256         pp->SetLeftMargin(0.10);
257         ppp = p->cd(6);
258         ppp->SetRightMargin(pp->GetRightMargin());
259         ppp->SetLeftMargin(0.10);
260         DrawInPad(fBody, 6, accAlt, "", kGridx|kGridy);
261
262         DrawInPad(fBody, 7, GetH2(c, "diagnostics"), "colz");
263
264         TH2* ratio = static_cast<TH2*>(secMap->Clone("ratio"));
265         ratio->Add(secMapAlt, -1);
266         ratio->Divide(secMapAlt);
267         ratio->SetTitle("Relative difference between maps");
268         ratio->SetZTitle("#frac{S - S_{alt}}{S_{alt}}");
269         
270         pp = p->cd(8);
271         pp->SetLeftMargin(0.10);
272         DrawInPad(fBody, 8, ratio, "colz");
273       }
274       PrintCanvas(Form("%s results - Vertex bin %+5.1f - %+5.1f",
275                        (forward ? "Forward" : "Central"),
276                        vtxAxis->GetBinLowEdge(i), 
277                        vtxAxis->GetBinUpEdge(i)));
278     }
279   }
280   TCollection* fSums;
281   TCollection* fResults;
282 };
283
284 // #endif