3 * @author Christian Holm Christensen <cholm@nbi.dk>
4 * @date Thu Nov 17 11:34:01 2011
9 * @defgroup pwglf_forward_scripts_qa Quality Assurance scripts
11 * Quality assurance scripts and functions
13 * @ingroup pwglf_forward_scripts
18 * @param forward Input list
20 * @param name Name of stack
22 * @return A stack or null
24 * @ingroup pwglf_forward_scripts_qa
27 GetStack(const TList& forward, const char* sub, const char* name)
29 TList* lsub = &forward;
31 if (sub && sub[0] != '\0')
32 lsub = static_cast<TList*>(forward.FindObject(sub));
35 Warning("GetStack", "Sub list %s not found in %s", sub, forward.GetName());
38 THStack* ret = static_cast<THStack*>(lsub->FindObject(name));
40 Warning("GetStack" "Stack %s not found in %s", name, sub);
48 * @param rebin Rebinning factor
52 * @ingroup pwglf_forward_scripts_qa
55 Rebin(TH1* h, Int_t rebin)
57 if (rebin <= 1) return h;
64 * Ratio of two histograms
67 * @param h2 denominator
71 * @ingroup pwglf_forward_scripts_qa
74 Ratio(const TH1* h1, const TH1* h2)
79 TH1* copy = static_cast<TH1*>(h2->Clone("tmp"));
80 copy->SetName(Form("%s_%s", h2->GetName(), h1->GetName()));
81 copy->SetTitle(Form("%s/%s", h2->GetTitle(), h1->GetTitle()));
82 copy->SetDirectory(0);
89 * Ratio all histograms in stacks
92 * @param h1 Numerators
93 * @param h2 Denominators
95 * @return Number of histograms
97 * @ingroup pwglf_forward_scripts_qa
100 Ratio(THStack* r, const THStack* h1, const THStack* h2)
105 int n1 = h1->GetHists()->GetEntries();
106 int n2 = h2->GetHists()->GetEntries();
108 for (int i = 0; i < n1 && i < n2; i++) {
109 TH1* hh1 = static_cast<TH1*>(h1->GetHists()->At(i));
110 TH1* hh2 = static_cast<TH1*>(h2->GetHists()->At(i));
111 TH1* h = Ratio(hh1, hh2);
120 * Add a histogram to the all stack
124 * @param singleStep Showing individual steps?
126 * @ingroup pwglf_forward_scripts_qa
129 AddToAll(THStack* all, const TH1* h, Bool_t singleStep)
131 TH1* copy = static_cast<TH1*>(h->Clone(Form("%s_copy", h->GetName())));
132 copy->SetDirectory(0);
134 copy->SetMarkerColor(kGray);
135 copy->SetLineColor(kGray);
143 * @param thisId This step
144 * @param step Current step
145 * @param e Entry in legend
147 * @ingroup pwglf_forward_scripts_qa
150 DimEntry(Int_t thisId, Int_t step, TLegendEntry* e)
153 Int_t col = (thisId == step || step <= 0) ? kBlack : kGray;
154 e->SetMarkerColor(col);
155 e->SetLineColor(col);
156 e->SetTextColor(col);
162 * @param deltas From energy loss
163 * @param nchs After 2nd correction
164 * @param prims Primaries
165 * @param dndeta Result
166 * @param step Step number
168 * @ingroup pwglf_forward_scripts_qa
171 DrawStep(THStack* deltas, THStack* nchs, THStack* prims,
172 TH1* dndeta, Int_t step)
174 THStack* all = new THStack("all", "Analysis steps");
175 if (step > 0) all->SetTitle(Form("Step %d", step));
178 deltas->SetTitle("#sum_{} #Delta/#Delta_{mip}");
179 TIter next(deltas->GetHists());
181 while ((h = static_cast<TH1*>(next()))) {
182 h->SetMarkerStyle(25);
183 // Info("DrawStep", "Adding %s", h->GetName());
184 AddToAll(all, h, step>0);
188 nchs->SetTitle("#sum_{} N_{ch,incl}");
189 TIter next(nchs->GetHists());
191 while ((h = static_cast<TH1*>(next()))) {
192 h->SetMarkerStyle(21);
193 // Info("DrawStep", "Adding %s", h->GetName());
194 AddToAll(all, h, step>0);
198 prims->SetTitle("#sum_{} N_{ch,primary}");
199 TIter next(prims->GetHists());
201 while ((h = static_cast<TH1*>(next()))) {
202 h->SetMarkerStyle(22);
203 // Info("DrawStep", "Adding %s", h->GetName());
204 AddToAll(all, h, step>0);
208 dndeta->SetTitle("1/N dN_{ch}/d#eta");
209 dndeta->SetMarkerStyle(20);
210 dndeta->SetMarkerColor(kBlack);
211 // Info("DrawStep", "Adding %s", dndeta->GetName());
212 AddToAll(all, dndeta, step>0);
215 all->Draw("nostack");
216 all->GetHistogram()->SetXTitle("#eta");
217 all->GetHistogram()->SetYTitle("signal");
218 all->GetHistogram()->GetXaxis()->SetLabelFont(132);
219 all->GetHistogram()->GetXaxis()->SetTitleFont(132);
220 all->GetHistogram()->GetYaxis()->SetLabelFont(132);
221 all->GetHistogram()->GetYaxis()->SetTitleFont(132);
224 TLegend* l = new TLegend(.33, .2, .53, .9);
233 TIter next(deltas->GetHists());
235 while ((h = static_cast<TH1*>(next()))) {
236 e = l->AddEntry(Form("dummy%02d", i++),h->GetTitle(),"pl");
237 e->SetMarkerStyle(20);
238 e->SetMarkerColor(h->GetMarkerColor());
240 e = l->AddEntry(Form("dummy%02d", i++), deltas->GetTitle(),"pl");
241 TH1* h = static_cast<TH1*>(deltas->GetHists()->At(0));
242 e->SetMarkerStyle(h->GetMarkerStyle());
243 DimEntry(1, step, e);
246 e = l->AddEntry(Form("dummy%02d",i++),nchs->GetTitle(),"pl");
247 TH1* h = static_cast<TH1*>(nchs->GetHists()->At(0));
248 e->SetMarkerStyle(h->GetMarkerStyle());
249 DimEntry(2, step, e);
252 e = l->AddEntry(Form("dummy%02d", i++), prims->GetTitle(),"pl");
253 TH1* h = static_cast<TH1*>(prims->GetHists()->At(0));
254 e->SetMarkerStyle(h->GetMarkerStyle());
255 DimEntry(3, step, e);
258 e = l->AddEntry(Form("dummy%02d", i++), dndeta->GetTitle(),"pl");
259 e->SetMarkerStyle(dndeta->GetMarkerStyle());
260 DimEntry(4, step, e);
268 deltas->Draw("same nostack");
269 what = "After merging";
272 nchs->Draw("same nostack");
273 what = "After particle counting";
276 prims->Draw("same nostack");
277 what = "After corrections";
280 dndeta->Draw("same");
281 what = "After normalisation";
284 Error("DrawSteps", "Unknown step: %d (must be in 1-4)");
288 TLatex* ltx = new TLatex(.95, .85, what);
290 ltx->SetTextSize(.07);
291 ltx->SetTextAlign(33);
292 ltx->SetTextFont(132);
299 * @param filename Input file
300 * @param single Whether to show individial steps
302 * @ingroup pwglf_forward_scripts_qa
304 void DrawSteps(const char* filename="forward.root", Bool_t single=true)
306 gStyle->SetPalette(1);
307 gStyle->SetOptFit(0);
308 gStyle->SetOptStat(0);
310 TFile* file = TFile::Open(filename, "READ");
312 Error("DrawMCResult", "failed to open %s", filename);
315 const char* fname2 = "forward_dndeta.root";
316 TFile* file2 = TFile::Open(fname2, "READ");
318 Error("DrawSteps", "File %s not found", fname2);
321 TList* forward = static_cast<TList*>(file->Get("Forward"));
323 Error("DrawMCResult", "List Forward not found in %s", filename);
326 TList* forwardRes = (file2 ?
327 static_cast<TList*>(file2->Get("ForwardResults")) :
329 TList* forwardAll = (forwardRes ?
330 static_cast<TList*>(forwardRes->FindObject("all")) :
334 // THStack* res = GetStack(*forward, "ringResults", "all");
335 // THStack* mcRes = GetStack(*forward, "mcRingResults", "all");
336 THStack* deltas = GetStack(*forward, "fmdSharingFilter", "sums");
337 THStack* nchs = GetStack(*forward, "fmdDensityCalculator", "sums");
338 THStack* prims = GetStack(*forward, "fmdCorrector", "sums");
339 TH1* dndeta = (forwardAll ?
340 static_cast<TH1*>(forwardAll->FindObject("dndetaForward")):
343 Info("DrawSteps", "Got steps deltas=%p, nchs=%p, prims=%p, dndeta=%p",
344 deltas, nchs, prims, dndeta);
347 gStyle->SetTitleBorderSize(0);
348 gStyle->SetTitleFillColor(0);
349 gStyle->SetTitleStyle(0);
350 gStyle->SetTitleX(.7);
351 gStyle->SetTitleY(.95);
352 gStyle->SetTitleH(.1);
353 gStyle->SetTitleW(.25);
354 gStyle->SetOptTitle(1);
355 // gStyle->SetTitleColor(kBlack);
360 TCanvas* c = new TCanvas("c", "C", 900, 700);
363 c->SetTopMargin(0.05);
364 c->SetRightMargin(0.05);
366 DrawStep(deltas, nchs, prims, dndeta, 0);
367 c->SaveAs("steps_all.png");
371 if (deltas) nSteps++;
374 if (dndeta) nSteps++;
376 Int_t w = (nSteps >= 4 ? 1100 : 700);
377 Int_t h = (nSteps >= 4 ? 800 : 1100);
379 TCanvas* c = new TCanvas("c", "C", w, h);
382 c->SetTopMargin(0.05);
383 c->SetRightMargin(0.05);
386 c->Divide(2,(nSteps+1)/2,0,0);
388 c->Divide(1,nSteps,0,0);
390 for (Int_t i=1; i<=nSteps; i++) {
391 TVirtualPad* p = c->cd(i);
398 DrawStep(deltas, nchs, prims, dndeta, i);
400 c->SaveAs("steps_comic.png");