]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FORWARD/analysis2/qa/DrawMCResult.C
Documentation fixes
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / qa / DrawMCResult.C
1 /**
2  * @file   DrawMCResult.C
3  * @author Christian Holm Christensen <cholm@dalsgaard.hehi.nbi.dk>
4  * @date   Thu Jul  7 10:57:01 2011
5  * 
6  * @brief  Script to draw steps (deprecated version - use DrawSteps.C)
7  * 
8  * 
9  * @ingroup pwg2_forward_scripts_qa
10  */
11 /** 
12  * 
13  * 
14  * @param forward 
15  * @param sub 
16  * @param name 
17  * 
18  * @return 
19  *
20  * @ingroup pwg2_forward_scripts_qa
21  */
22 THStack*
23 GetStack(const TList& forward,  const char* sub, const char* name)
24 {
25   TList* lsub = static_cast<TList*>(forward.FindObject(sub));
26   if (!lsub) { 
27     Warning("GetStack", "Sub list %s not found in %s", sub, forward.GetName());
28     return 0;
29   }
30   THStack* ret = static_cast<THStack*>(lsub->FindObject(name));
31   if (!ret) 
32     Warning("GetStack" "Stack %s not found in %s", name, sub);
33   return ret;
34 }
35
36 /** 
37  * 
38  * 
39  * @param h 
40  * @param rebin 
41  * 
42  * @return 
43  *
44  * @ingroup pwg2_forward_scripts_qa
45  */
46 TH1* 
47 Rebin(TH1* h, Int_t rebin)
48 {
49   if (rebin <= 1) return h;
50   h->Rebin(rebin);
51   h->Scale(1. / rebin);
52   return h;
53 }
54
55 /** 
56  * 
57  * 
58  * @param h1 
59  * @param h2 
60  * 
61  * @return 
62  *
63  * @ingroup pwg2_forward_scripts_qa
64  */
65 TH1*
66 Ratio(const TH1* h1, const TH1* h2)
67 {
68   if (!h1) return;
69   if (!h2) return;
70   
71   TH1* copy = static_cast<TH1*>(h2->Clone("tmp"));
72   copy->SetName(Form("%s_%s", h2->GetName(), h1->GetName()));
73   copy->SetTitle(Form("%s/%s", h2->GetTitle(), h1->GetTitle()));
74   copy->SetDirectory(0);
75   copy->Divide(h1);
76
77   return copy;
78 }
79 /** 
80  * 
81  * 
82  * @param r 
83  * @param h1 
84  * @param h2 
85  * 
86  * @return 
87  *
88  * @ingroup pwg2_forward_scripts_qa
89  */
90 Int_t 
91 Ratio(THStack* r, const THStack* h1, const THStack* h2)
92 {
93   if (!h1) return 0;
94   if (!h2) return 0;
95
96   int n1 = h1->GetHists()->GetEntries();
97   int n2 = h2->GetHists()->GetEntries();
98   int nH = 0;
99   for (int i = 0; i < n1 && i < n2; i++) { 
100     TH1* hh1 = static_cast<TH1*>(h1->GetHists()->At(i));
101     TH1* hh2 = static_cast<TH1*>(h2->GetHists()->At(i));
102     TH1* h   = Ratio(hh1, hh2);
103     if (!h) continue;
104     nH++;
105     r->Add(h);
106   }
107   return nH;
108 }
109 /** 
110  * 
111  * 
112  * @param filename 
113  * @param rebin 
114  * @param ratios 
115  *
116  * @ingroup pwg2_forward_scripts_qa
117  */
118 void
119 DrawMCResult(const char* filename="forward.root", Int_t rebin=1,
120              Bool_t ratios=true)
121 {
122   gStyle->SetPalette(1);
123   gStyle->SetOptFit(0);
124   gStyle->SetOptStat(0);
125
126   TFile* file = TFile::Open(filename, "READ");
127   if (!file) { 
128     Error("DrawMCResult", "failed to open %s", filename);
129     return;
130   }
131
132   TList* forward = static_cast<TList*>(file->Get("Forward"));
133   if (!forward) { 
134     Error("DrawMCResult", "List Forward not found in %s", filename);
135     return;
136   }
137   THStack* res    = GetStack(*forward, "ringResults", "all");
138   THStack* mcRes  = GetStack(*forward, "mcRingResults", "all");
139   THStack* deltas = GetStack(*forward, "fmdSharingFilter", "sums");
140   THStack* nchs   = GetStack(*forward, "fmdDensityCalculator", "sums");
141   THStack* prims  = GetStack(*forward, "fmdCorrector", "sums");
142   
143   TH1* sumEta = static_cast<TH1*>(forward->FindObject("mcSumEta"));
144   if (!sumEta) { 
145     Warning("DrawMCResults", "mcSumEta not found in Forward");
146   }
147
148
149   gStyle->SetTitleBorderSize(0);
150   gStyle->SetTitleFillColor(0);
151   gStyle->SetTitleStyle(0);
152   // gStyle->SetTitleColor(kBlack);
153
154
155   TCanvas* c = new TCanvas("c", "C", 900, 700);
156   c->SetFillColor(0);
157   c->SetBorderSize(0);
158   c->SetTopMargin(0.05);
159   c->SetRightMargin(0.05);
160
161   Double_t y1 = (ratios ? .3 : 0);
162   TPad* p1 = new TPad("p1", "p1", 0, y1, 1, 1, 0, 0, 0); 
163   p1->SetBottomMargin(ratios ? 0.01 : .10);
164   p1->SetFillColor(0);
165   p1->SetBorderSize(0);
166   p1->SetTopMargin(0.05);
167   p1->SetRightMargin(0.05);
168   p1->Draw();
169   p1->cd();
170
171   THStack* all = new THStack("all", "Analysis steps");
172   if (res) {
173     res->SetTitle("dN_{ch}/d#eta");
174     TIter next(res->GetHists());
175     TH1* h = 0;
176     while ((h = static_cast<TH1*>(next()))) all->Add(Rebin(h,rebin));
177   }
178   if (mcRes) {
179     mcRes->SetTitle("Track-Refs");
180     TIter next(mcRes->GetHists());
181     TH1* h = 0;
182     while ((h = static_cast<TH1*>(next()))) all->Add(Rebin(h,rebin));
183   }
184   if (deltas) {
185     deltas->SetTitle("#sum_{} #Delta/#Delta_{mip}");
186     TIter next(deltas->GetHists());
187     TH1* h = 0;
188     while ((h = static_cast<TH1*>(next()))) { 
189       h->SetMarkerStyle(25);
190       all->Add(Rebin(h,rebin));
191     }
192   }
193   if (nchs) {
194     nchs->SetTitle("#sum_{} N_{ch,incl}");
195     TIter next(nchs->GetHists());
196     TH1* h = 0;
197     while ((h = static_cast<TH1*>(next()))) { 
198       h->SetMarkerStyle(21);
199       all->Add(Rebin(h,rebin));
200     }
201   }
202   if (prims) {
203     prims->SetTitle("#sum_{} N_{ch,primary}");
204     TIter next(prims->GetHists());
205     TH1* h = 0;
206     while ((h = static_cast<TH1*>(next()))) { 
207       h->SetMarkerStyle(22);
208       all->Add(Rebin(h,rebin));
209     }
210   }
211   if (sumEta) all->Add(sumEta);
212   all->Draw("nostack");
213   all->GetHistogram()->SetXTitle("#eta");
214   all->GetHistogram()->SetYTitle("signal");
215   all->GetHistogram()->GetXaxis()->SetLabelFont(132);
216   all->GetHistogram()->GetXaxis()->SetTitleFont(132);
217   all->GetHistogram()->GetYaxis()->SetLabelFont(132);
218   all->GetHistogram()->GetYaxis()->SetTitleFont(132);
219   c->SetGridx();
220
221   TLegend* l = new TLegend(.33, .2, .53, .9);
222   TLegendEntry* e = 0;
223   l->SetFillColor(0);
224   l->SetFillStyle(0);
225   l->SetBorderSize(0);
226   l->SetNColumns(1);
227   l->SetTextFont(132);
228   Int_t i = 0;
229   if (res) { 
230     TIter next(res->GetHists());
231     TH1* h = 0;
232     while ((h = static_cast<TH1*>(next()))) {
233       e = l->AddEntry(Form("dummy%02d", i++),h->GetTitle(),"pl");
234       e->SetMarkerStyle(20);
235       e->SetMarkerColor(h->GetMarkerColor());
236     }
237     e = l->AddEntry(Form("dummy%02d", i++),res->GetTitle(),"pl");
238     e->SetMarkerStyle(20);
239     e->SetMarkerColor(kBlack);
240   }
241   if (deltas) { 
242     e = l->AddEntry(Form("dummy%02d", i++), deltas->GetTitle(),"pl");
243     TH1* h = static_cast<TH1*>(deltas->GetHists()->At(0));
244     e->SetMarkerStyle(h->GetMarkerStyle());
245     e->SetMarkerColor(kBlack);
246   }
247   if (nchs) { 
248     e = l->AddEntry(Form("dummy%02d",i++),nchs->GetTitle(),"pl");
249     TH1* h = static_cast<TH1*>(nchs->GetHists()->At(0));
250     e->SetMarkerStyle(h->GetMarkerStyle());
251     e->SetMarkerColor(kBlack);
252   }
253   if (prims) { 
254     e = l->AddEntry(Form("dummy%02d", i++), prims->GetTitle(),"pl");
255     TH1* h = static_cast<TH1*>(prims->GetHists()->At(0));
256     e->SetMarkerStyle(h->GetMarkerStyle());
257     e->SetMarkerColor(kBlack);
258   }
259
260   if (mcRes) { 
261     e = l->AddEntry(Form("dummy%02d", i++), mcRes->GetTitle(), "pl");
262     TH1* h = static_cast<TH1*>(mcRes->GetHists()->At(0));
263     e->SetMarkerStyle(h->GetMarkerStyle());
264     e->SetMarkerColor(kBlack);
265   }
266
267   if (sumEta) l->AddEntry(sumEta);
268   l->Draw();
269
270
271   if (!ratios) return;
272
273   c->cd();
274   TPad* p2 = new TPad("p2", "p2", 0, 0, 1, y1, 0, 0, 0); 
275   p2->SetTopMargin(0);
276   p2->SetFillColor(0);
277   p2->SetBorderSize(0);
278   p2->SetRightMargin(0.05);
279   p2->Draw();
280   p2->cd();
281
282   THStack* rs = new THStack("ratios", "Ratios");
283   Int_t nDN = Ratio(rs, deltas, nchs);
284   Int_t nNR = Ratio(rs, nchs, res);
285   Int_t nRP = Ratio(rs, res, prims);
286   rs->Draw("nostack");
287
288   TLegend* ll = new TLegend(.38, .2, .48, .9);
289   ll->SetFillColor(0);
290   ll->SetFillStyle(0);
291   ll->SetBorderSize(0);
292   ll->SetNColumns(1);
293   ll->SetTextFont(132);
294   if (nDN) {
295     e = ll->AddEntry("d1", Form("#frac{%s}{%s}", 
296                                               nchs->GetTitle(), 
297                                               deltas->GetTitle()), "lp");
298     e->SetMarkerStyle(21);
299   }
300   if (nNR) {
301     e = ll->AddEntry("d2", Form("#frac{%s}{%s}", res->GetTitle(), 
302                                 nchs->GetTitle()), "lp");
303     e->SetMarkerStyle(20);
304   }
305   if (nRP) {
306     e = ll->AddEntry("d3", Form("#frac{%s}{%s}", prims->GetTitle(), 
307                             res->GetTitle()), "lp");
308     e->SetMarkerStyle(22);
309   }
310   ll->Draw();
311   
312
313 }
314
315   
316   
317  
318 //
319 // EOF
320 //