]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FORWARD/analysis2/qa/DrawSteps.C
Re-organised scripts
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / qa / DrawSteps.C
1 THStack*
2 GetStack(const TList& forward,  const char* sub, const char* name)
3 {
4   TList* lsub = &forward;
5
6   if (sub && sub[0] != '\0') 
7     lsub = static_cast<TList*>(forward.FindObject(sub));
8
9   if (!lsub) { 
10     Warning("GetStack", "Sub list %s not found in %s", sub, forward.GetName());
11     return 0;
12   }
13   THStack* ret = static_cast<THStack*>(lsub->FindObject(name));
14   if (!ret) 
15     Warning("GetStack" "Stack %s not found in %s", name, sub);
16   return ret;
17 }
18
19 TH1* 
20 Rebin(TH1* h, Int_t rebin)
21 {
22   if (rebin <= 1) return h;
23   h->Rebin(rebin);
24   h->Scale(1. / rebin);
25   return h;
26 }
27
28 TH1*
29 Ratio(const TH1* h1, const TH1* h2)
30 {
31   if (!h1) return;
32   if (!h2) return;
33   
34   TH1* copy = static_cast<TH1*>(h2->Clone("tmp"));
35   copy->SetName(Form("%s_%s", h2->GetName(), h1->GetName()));
36   copy->SetTitle(Form("%s/%s", h2->GetTitle(), h1->GetTitle()));
37   copy->SetDirectory(0);
38   copy->Divide(h1);
39
40   return copy;
41 }
42
43 Int_t 
44 Ratio(THStack* r, const THStack* h1, const THStack* h2)
45 {
46   if (!h1) return 0;
47   if (!h2) return 0;
48
49   int n1 = h1->GetHists()->GetEntries();
50   int n2 = h2->GetHists()->GetEntries();
51   int nH = 0;
52   for (int i = 0; i < n1 && i < n2; i++) { 
53     TH1* hh1 = static_cast<TH1*>(h1->GetHists()->At(i));
54     TH1* hh2 = static_cast<TH1*>(h2->GetHists()->At(i));
55     TH1* h   = Ratio(hh1, hh2);
56     if (!h) continue;
57     nH++;
58     r->Add(h);
59   }
60   return nH;
61 }
62
63 void
64 AddToAll(THStack* all, const TH1* h, Bool_t singleStep)
65 {
66   TH1* copy = static_cast<TH1*>(h->Clone(Form("%s_copy", h->GetName())));
67   copy->SetDirectory(0);
68   if (singleStep) { 
69     copy->SetMarkerColor(kGray);
70     copy->SetLineColor(kGray);
71   }
72   all->Add(copy);
73 }
74
75 void
76 DimEntry(Int_t thisId, Int_t step, TLegendEntry* e)
77 {
78   
79   Int_t col = (thisId == step || step <= 0) ? kBlack : kGray;
80   e->SetMarkerColor(col);
81   e->SetLineColor(col);
82   e->SetTextColor(col);
83 }
84
85 void
86 DrawStep(THStack* deltas, THStack* nchs, THStack* prims, 
87          TH1*     dndeta, Int_t step)
88 {
89   THStack* all = new THStack("all", "Analysis steps");
90   if (step > 0) all->SetTitle(Form("Step %d", step));
91
92   if (deltas) {
93     deltas->SetTitle("#sum_{} #Delta/#Delta_{mip}");
94     TIter next(deltas->GetHists());
95     TH1* h = 0;
96     while ((h = static_cast<TH1*>(next()))) { 
97       h->SetMarkerStyle(25);
98       // Info("DrawStep", "Adding %s", h->GetName());
99       AddToAll(all, h, step>0);
100     }
101   }
102   if (nchs) {
103     nchs->SetTitle("#sum_{} N_{ch,incl}");
104     TIter next(nchs->GetHists());
105     TH1* h = 0;
106     while ((h = static_cast<TH1*>(next()))) { 
107       h->SetMarkerStyle(21);
108       // Info("DrawStep", "Adding %s", h->GetName());
109       AddToAll(all, h, step>0);
110     }
111   }
112   if (prims) {
113     prims->SetTitle("#sum_{} N_{ch,primary}");
114     TIter next(prims->GetHists());
115     TH1* h = 0;
116     while ((h = static_cast<TH1*>(next()))) { 
117       h->SetMarkerStyle(22);
118       // Info("DrawStep", "Adding %s", h->GetName());
119       AddToAll(all, h, step>0);
120     }
121   }
122   if (dndeta) {
123     dndeta->SetTitle("1/N dN_{ch}/d#eta");
124     dndeta->SetMarkerStyle(20);
125     dndeta->SetMarkerColor(kBlack);
126     // Info("DrawStep", "Adding %s", dndeta->GetName());
127     AddToAll(all, dndeta, step>0);
128   }
129
130   all->Draw("nostack");
131   all->GetHistogram()->SetXTitle("#eta");
132   all->GetHistogram()->SetYTitle("signal");
133   all->GetHistogram()->GetXaxis()->SetLabelFont(132);
134   all->GetHistogram()->GetXaxis()->SetTitleFont(132);
135   all->GetHistogram()->GetYaxis()->SetLabelFont(132);
136   all->GetHistogram()->GetYaxis()->SetTitleFont(132);
137   c->SetGridx();
138
139   TLegend* l = new TLegend(.33, .2, .53, .9);
140   TLegendEntry* e = 0;
141   l->SetFillColor(0);
142   l->SetFillStyle(0);
143   l->SetBorderSize(0);
144   l->SetNColumns(1);
145   l->SetTextFont(132);
146   Int_t i = 0;
147   if (deltas) { 
148     TIter next(deltas->GetHists());             
149     TH1*  h = 0;
150     while ((h = static_cast<TH1*>(next()))) {
151       e = l->AddEntry(Form("dummy%02d", i++),h->GetTitle(),"pl");
152       e->SetMarkerStyle(20);
153       e->SetMarkerColor(h->GetMarkerColor());
154     }
155     e = l->AddEntry(Form("dummy%02d", i++), deltas->GetTitle(),"pl");
156     TH1* h = static_cast<TH1*>(deltas->GetHists()->At(0));
157     e->SetMarkerStyle(h->GetMarkerStyle());
158     DimEntry(1, step, e);
159   }
160   if (nchs) { 
161     e = l->AddEntry(Form("dummy%02d",i++),nchs->GetTitle(),"pl");
162     TH1* h = static_cast<TH1*>(nchs->GetHists()->At(0));
163     e->SetMarkerStyle(h->GetMarkerStyle());
164     DimEntry(2, step, e);
165   }
166   if (prims) { 
167     e = l->AddEntry(Form("dummy%02d", i++), prims->GetTitle(),"pl");
168     TH1* h = static_cast<TH1*>(prims->GetHists()->At(0));
169     e->SetMarkerStyle(h->GetMarkerStyle());
170     DimEntry(3, step, e);
171   }
172   if (dndeta) { 
173     e = l->AddEntry(Form("dummy%02d", i++), dndeta->GetTitle(),"pl");
174     e->SetMarkerStyle(dndeta->GetMarkerStyle());
175     DimEntry(4, step, e);
176   }
177   l->Draw();
178
179   TString what;
180   if (step > 0) {
181     switch (step) { 
182     case 1: 
183       deltas->Draw("same nostack"); 
184       what = "After merging";
185       break;
186     case 2: 
187       nchs->Draw("same nostack"); 
188       what = "After particle counting";
189       break;
190     case 3: 
191       prims->Draw("same nostack"); 
192       what = "After corrections";
193       break;
194     case 4: 
195       dndeta->Draw("same"); 
196       what = "After normalisation";
197       break;
198     default: 
199       Error("DrawSteps", "Unknown step: %d (must be in 1-4)");
200       break;
201     }
202   }
203   TLatex* ltx = new TLatex(.95, .85, what);
204   ltx->SetNDC();
205   ltx->SetTextSize(.07);
206   ltx->SetTextAlign(33);
207   ltx->SetTextFont(132);
208   ltx->Draw();
209 }
210
211
212 void DrawSteps(const char* filename="forward.root", Bool_t single=true)
213 {
214   gStyle->SetPalette(1);
215   gStyle->SetOptFit(0);
216   gStyle->SetOptStat(0);
217
218   TFile* file = TFile::Open(filename, "READ");
219   if (!file) { 
220     Error("DrawMCResult", "failed to open %s", filename);
221     return;
222   }
223   const char* fname2 = "forward_dndeta.root";
224   TFile* file2 = TFile::Open(fname2, "READ");
225   if (!file2) { 
226     Error("DrawSteps", "File %s not found", fname2);
227   }
228
229   TList* forward = static_cast<TList*>(file->Get("Forward"));
230   if (!forward) { 
231     Error("DrawMCResult", "List Forward not found in %s", filename);
232     return;
233   }
234   TList* forwardRes = (file2 ? 
235                        static_cast<TList*>(file2->Get("ForwardResults")) :
236                        0);
237   TList* forwardAll = (forwardRes ? 
238                        static_cast<TList*>(forwardRes->FindObject("all")) :
239                        0);
240                        
241   
242   // THStack* res    = GetStack(*forward, "ringResults", "all");
243   // THStack* mcRes  = GetStack(*forward, "mcRingResults", "all");
244   THStack* deltas = GetStack(*forward, "fmdSharingFilter", "sums");
245   THStack* nchs   = GetStack(*forward, "fmdDensityCalculator", "sums");
246   THStack* prims  = GetStack(*forward, "fmdCorrector", "sums");
247   TH1*     dndeta = (forwardAll ? 
248                      static_cast<TH1*>(forwardAll->FindObject("dndetaForward")):
249                      0);
250
251   Info("DrawSteps", "Got steps deltas=%p, nchs=%p, prims=%p, dndeta=%p",
252        deltas, nchs, prims, dndeta);
253
254
255   gStyle->SetTitleBorderSize(0);
256   gStyle->SetTitleFillColor(0);
257   gStyle->SetTitleStyle(0);
258   gStyle->SetTitleX(.7);
259   gStyle->SetTitleY(.95);
260   gStyle->SetTitleH(.1);
261   gStyle->SetTitleW(.25);
262   gStyle->SetOptTitle(1);
263   // gStyle->SetTitleColor(kBlack);
264
265
266   
267   if (!single) { 
268     TCanvas* c = new TCanvas("c", "C", 900, 700);
269     c->SetFillColor(0);
270     c->SetBorderSize(0);
271     c->SetTopMargin(0.05);
272     c->SetRightMargin(0.05);
273
274     DrawStep(deltas, nchs, prims, dndeta, 0);
275     c->SaveAs("steps_all.png");
276     return;
277   }
278   Int_t nSteps = 0;
279   if (deltas) nSteps++;
280   if (nchs)   nSteps++;
281   if (prims)  nSteps++;
282   if (dndeta) nSteps++;
283
284   Int_t w = (nSteps >= 4 ? 1100 :  700);
285   Int_t h = (nSteps >= 4 ? 800  : 1100);
286
287   TCanvas* c = new TCanvas("c", "C", w, h);
288   c->SetFillColor(0);
289   c->SetBorderSize(0);
290   c->SetTopMargin(0.05);
291   c->SetRightMargin(0.05);
292
293   if (nSteps >= 4) 
294     c->Divide(2,(nSteps+1)/2,0,0);
295   else 
296     c->Divide(1,nSteps,0,0);
297   
298   for (Int_t i=1; i<=nSteps; i++) { 
299     TVirtualPad* p = c->cd(i);
300     p->SetFillColor(0);
301     p->SetFillStyle(0);
302     p->SetBorderSize(0);
303     p->SetGridx();
304     p->SetGridy();
305
306     DrawStep(deltas, nchs, prims, dndeta, i);
307   }
308   c->SaveAs("steps_comic.png");
309 }
310 //
311 // EOF
312 //
313
314