3 * @defgroup pwg2_forward_scripts_qa Quality Assurance scripts
6 * @ingroup pwg2_forward_scripts
13 * @param forward Input list
15 * @param name Name of stack
17 * @return A stack or null
19 * @ingroup pwg2_forward_scripts_qa
22 GetStack(const TList& forward, const char* sub, const char* name)
24 TList* lsub = &forward;
26 if (sub && sub[0] != '\0')
27 lsub = static_cast<TList*>(forward.FindObject(sub));
30 Warning("GetStack", "Sub list %s not found in %s", sub, forward.GetName());
33 THStack* ret = static_cast<THStack*>(lsub->FindObject(name));
35 Warning("GetStack" "Stack %s not found in %s", name, sub);
43 * @param rebin Rebinning factor
47 * @ingroup pwg2_forward_scripts_qa
50 Rebin(TH1* h, Int_t rebin)
52 if (rebin <= 1) return h;
59 * Ratio of two histograms
62 * @param h2 denominator
66 * @ingroup pwg2_forward_scripts_qa
69 Ratio(const TH1* h1, const TH1* h2)
74 TH1* copy = static_cast<TH1*>(h2->Clone("tmp"));
75 copy->SetName(Form("%s_%s", h2->GetName(), h1->GetName()));
76 copy->SetTitle(Form("%s/%s", h2->GetTitle(), h1->GetTitle()));
77 copy->SetDirectory(0);
84 * Ratio all histograms in stacks
87 * @param h1 Numerators
88 * @param h2 Denominators
90 * @return Number of histograms
92 * @ingroup pwg2_forward_scripts_qa
95 Ratio(THStack* r, const THStack* h1, const THStack* h2)
100 int n1 = h1->GetHists()->GetEntries();
101 int n2 = h2->GetHists()->GetEntries();
103 for (int i = 0; i < n1 && i < n2; i++) {
104 TH1* hh1 = static_cast<TH1*>(h1->GetHists()->At(i));
105 TH1* hh2 = static_cast<TH1*>(h2->GetHists()->At(i));
106 TH1* h = Ratio(hh1, hh2);
115 * Add a histogram to the all stack
119 * @param singleStep Showing individual steps?
121 * @ingroup pwg2_forward_scripts_qa
124 AddToAll(THStack* all, const TH1* h, Bool_t singleStep)
126 TH1* copy = static_cast<TH1*>(h->Clone(Form("%s_copy", h->GetName())));
127 copy->SetDirectory(0);
129 copy->SetMarkerColor(kGray);
130 copy->SetLineColor(kGray);
138 * @param thisId This step
139 * @param step Current step
140 * @param e Entry in legend
142 * @ingroup pwg2_forward_scripts_qa
145 DimEntry(Int_t thisId, Int_t step, TLegendEntry* e)
148 Int_t col = (thisId == step || step <= 0) ? kBlack : kGray;
149 e->SetMarkerColor(col);
150 e->SetLineColor(col);
151 e->SetTextColor(col);
157 * @param deltas From energy loss
158 * @param nchs After 2nd correction
159 * @param prims Primaries
160 * @param dndeta Result
161 * @param step Step number
163 * @ingroup pwg2_forward_scripts_qa
166 DrawStep(THStack* deltas, THStack* nchs, THStack* prims,
167 TH1* dndeta, Int_t step)
169 THStack* all = new THStack("all", "Analysis steps");
170 if (step > 0) all->SetTitle(Form("Step %d", step));
173 deltas->SetTitle("#sum_{} #Delta/#Delta_{mip}");
174 TIter next(deltas->GetHists());
176 while ((h = static_cast<TH1*>(next()))) {
177 h->SetMarkerStyle(25);
178 // Info("DrawStep", "Adding %s", h->GetName());
179 AddToAll(all, h, step>0);
183 nchs->SetTitle("#sum_{} N_{ch,incl}");
184 TIter next(nchs->GetHists());
186 while ((h = static_cast<TH1*>(next()))) {
187 h->SetMarkerStyle(21);
188 // Info("DrawStep", "Adding %s", h->GetName());
189 AddToAll(all, h, step>0);
193 prims->SetTitle("#sum_{} N_{ch,primary}");
194 TIter next(prims->GetHists());
196 while ((h = static_cast<TH1*>(next()))) {
197 h->SetMarkerStyle(22);
198 // Info("DrawStep", "Adding %s", h->GetName());
199 AddToAll(all, h, step>0);
203 dndeta->SetTitle("1/N dN_{ch}/d#eta");
204 dndeta->SetMarkerStyle(20);
205 dndeta->SetMarkerColor(kBlack);
206 // Info("DrawStep", "Adding %s", dndeta->GetName());
207 AddToAll(all, dndeta, step>0);
210 all->Draw("nostack");
211 all->GetHistogram()->SetXTitle("#eta");
212 all->GetHistogram()->SetYTitle("signal");
213 all->GetHistogram()->GetXaxis()->SetLabelFont(132);
214 all->GetHistogram()->GetXaxis()->SetTitleFont(132);
215 all->GetHistogram()->GetYaxis()->SetLabelFont(132);
216 all->GetHistogram()->GetYaxis()->SetTitleFont(132);
219 TLegend* l = new TLegend(.33, .2, .53, .9);
228 TIter next(deltas->GetHists());
230 while ((h = static_cast<TH1*>(next()))) {
231 e = l->AddEntry(Form("dummy%02d", i++),h->GetTitle(),"pl");
232 e->SetMarkerStyle(20);
233 e->SetMarkerColor(h->GetMarkerColor());
235 e = l->AddEntry(Form("dummy%02d", i++), deltas->GetTitle(),"pl");
236 TH1* h = static_cast<TH1*>(deltas->GetHists()->At(0));
237 e->SetMarkerStyle(h->GetMarkerStyle());
238 DimEntry(1, step, e);
241 e = l->AddEntry(Form("dummy%02d",i++),nchs->GetTitle(),"pl");
242 TH1* h = static_cast<TH1*>(nchs->GetHists()->At(0));
243 e->SetMarkerStyle(h->GetMarkerStyle());
244 DimEntry(2, step, e);
247 e = l->AddEntry(Form("dummy%02d", i++), prims->GetTitle(),"pl");
248 TH1* h = static_cast<TH1*>(prims->GetHists()->At(0));
249 e->SetMarkerStyle(h->GetMarkerStyle());
250 DimEntry(3, step, e);
253 e = l->AddEntry(Form("dummy%02d", i++), dndeta->GetTitle(),"pl");
254 e->SetMarkerStyle(dndeta->GetMarkerStyle());
255 DimEntry(4, step, e);
263 deltas->Draw("same nostack");
264 what = "After merging";
267 nchs->Draw("same nostack");
268 what = "After particle counting";
271 prims->Draw("same nostack");
272 what = "After corrections";
275 dndeta->Draw("same");
276 what = "After normalisation";
279 Error("DrawSteps", "Unknown step: %d (must be in 1-4)");
283 TLatex* ltx = new TLatex(.95, .85, what);
285 ltx->SetTextSize(.07);
286 ltx->SetTextAlign(33);
287 ltx->SetTextFont(132);
294 * @param filename Input file
295 * @param single Whether to show individial steps
297 * @ingroup pwg2_forward_scripts_qa
299 void DrawSteps(const char* filename="forward.root", Bool_t single=true)
301 gStyle->SetPalette(1);
302 gStyle->SetOptFit(0);
303 gStyle->SetOptStat(0);
305 TFile* file = TFile::Open(filename, "READ");
307 Error("DrawMCResult", "failed to open %s", filename);
310 const char* fname2 = "forward_dndeta.root";
311 TFile* file2 = TFile::Open(fname2, "READ");
313 Error("DrawSteps", "File %s not found", fname2);
316 TList* forward = static_cast<TList*>(file->Get("Forward"));
318 Error("DrawMCResult", "List Forward not found in %s", filename);
321 TList* forwardRes = (file2 ?
322 static_cast<TList*>(file2->Get("ForwardResults")) :
324 TList* forwardAll = (forwardRes ?
325 static_cast<TList*>(forwardRes->FindObject("all")) :
329 // THStack* res = GetStack(*forward, "ringResults", "all");
330 // THStack* mcRes = GetStack(*forward, "mcRingResults", "all");
331 THStack* deltas = GetStack(*forward, "fmdSharingFilter", "sums");
332 THStack* nchs = GetStack(*forward, "fmdDensityCalculator", "sums");
333 THStack* prims = GetStack(*forward, "fmdCorrector", "sums");
334 TH1* dndeta = (forwardAll ?
335 static_cast<TH1*>(forwardAll->FindObject("dndetaForward")):
338 Info("DrawSteps", "Got steps deltas=%p, nchs=%p, prims=%p, dndeta=%p",
339 deltas, nchs, prims, dndeta);
342 gStyle->SetTitleBorderSize(0);
343 gStyle->SetTitleFillColor(0);
344 gStyle->SetTitleStyle(0);
345 gStyle->SetTitleX(.7);
346 gStyle->SetTitleY(.95);
347 gStyle->SetTitleH(.1);
348 gStyle->SetTitleW(.25);
349 gStyle->SetOptTitle(1);
350 // gStyle->SetTitleColor(kBlack);
355 TCanvas* c = new TCanvas("c", "C", 900, 700);
358 c->SetTopMargin(0.05);
359 c->SetRightMargin(0.05);
361 DrawStep(deltas, nchs, prims, dndeta, 0);
362 c->SaveAs("steps_all.png");
366 if (deltas) nSteps++;
369 if (dndeta) nSteps++;
371 Int_t w = (nSteps >= 4 ? 1100 : 700);
372 Int_t h = (nSteps >= 4 ? 800 : 1100);
374 TCanvas* c = new TCanvas("c", "C", w, h);
377 c->SetTopMargin(0.05);
378 c->SetRightMargin(0.05);
381 c->Divide(2,(nSteps+1)/2,0,0);
383 c->Divide(1,nSteps,0,0);
385 for (Int_t i=1; i<=nSteps; i++) {
386 TVirtualPad* p = c->cd(i);
393 DrawStep(deltas, nchs, prims, dndeta, i);
395 c->SaveAs("steps_comic.png");