1 #include "SummaryDrawer.C"
3 #include <TMultiGraph.h>
5 class SummarydNdetaDrawer : public SummaryDrawer
20 const char* ColName(const char* prefix, bool results=false)
22 return Form("%sdNdeta%s", prefix, results ? "Results" : "Sums");
24 //____________________________________________________________________
25 void Run(const char* fname="forward_dndeta.root", UShort_t flags=kNormal)
27 // --- Open the file -----------------------------------------------
28 TString filename(fname);
29 TFile* file = TFile::Open(filename.Data(), "READ");
31 Error("Run", "Failed to open \"%s\"", filename.Data());
35 Bool_t forward = flags & kForward;
36 Bool_t central = flags & kCentral;
37 Bool_t sums = flags & kSums;
38 Bool_t results = flags & kResults;
39 Bool_t onlyMB = flags & kMinBias;
40 Bool_t mc = flags & kMC;
41 fPause = flags & kPause;
43 // --- Force MB for pp ---------------------------------------------
45 TCollection* c = GetCollection(file, ColName("Forward", false));
46 GetParameter(c, "sys", sys);
49 Info("Run", "Found sys==1 -> Forcing MB");
52 // --- Test of MC --------------------------------------------------
53 TCollection* mcC = GetCollection(file, ColName("MCTruth"), false);
55 TCollection* mcAll = GetCollection(mcC, "all");
56 if (mcAll && GetObject(mcAll, "sum")) {
57 Info("Run", "Found MC truth output");
61 // --- Make our canvas ---------------------------------------------
62 TString pdfName(filename);
63 pdfName.ReplaceAll(".root", ".pdf");
64 CreateCanvas(pdfName, flags & kLandscape);
66 // --- Make a Title page -------------------------------------------
67 DrawTitlePage(file, mc, onlyMB);
69 // --- Do each sub-algorithm ---------------------------------------
71 if (forward && sums) DrawSums(file, "Forward", onlyMB);
72 if (forward && results) rF = DrawRes(file, "Forward", onlyMB);
75 if (central && sums) DrawSums(file, "Central", onlyMB);
76 if (central && results) rC = DrawRes(file, "Central", onlyMB);
79 if (mc && sums) DrawSums(file, "MCTruth", onlyMB);
80 if (mc && results) rM = DrawRes(file, "MCTruth", onlyMB);
82 if (rC && rF && results) DrawBoth(rC, rF, rM, file, onlyMB);
88 //____________________________________________________________________
89 TCollection* GetCentCollection(const TCollection* sums,
96 title = TString::Format("%s %s: ", base.Data(), title.Data());
97 if (cLow < 0 || cHigh < 0 || cLow >= cHigh) {
99 title.Append("All selected events");
103 folder.Form("cent%03d_%03d", cLow, cHigh);
104 title.Append(Form("%3d%% - %3d%%", cLow, cHigh));
107 return GetCollection(sums, folder);
110 //____________________________________________________________________
111 void DrawTitlePage(TFile* file, Bool_t mc, Bool_t onlyMB)
113 TCollection* c = GetCollection(file, ColName("Forward", true));
118 TLatex* ltx = new TLatex(.5, y,
119 "#frac{1}{#it{N}}#kern[.1]"
120 "{#frac{d#it{N_{ch}}}{d#it{#eta}}}");
121 ltx->SetTextSize(0.07);
122 ltx->SetTextFont(42);
123 ltx->SetTextAlign(22);
129 ltx = new TLatex(.5, y, "Simulation input");
131 ltx->SetTextAlign(23);
132 ltx->SetTextFont(42);
133 ltx->SetTextSize(.03);
138 ltx = new TLatex(.5, y, "No centrality");
140 ltx->SetTextAlign(23);
141 ltx->SetTextFont(42);
142 ltx->SetTextSize(.03);
147 DrawResTitle(c, y, onlyMB);
149 PrintCanvas("1/N dN/d#eta");
151 //____________________________________________________________________
152 void DrawBoth(THStack* rC, THStack* rF, THStack* rM,
153 TFile* file, Bool_t onlyMB)
156 Double_t y1 = fLandscape ? 0 : .3;
157 Double_t x2 = fLandscape ? .7 : 1;
158 Double_t x1 = fLandscape ? x2 : 0;
159 Double_t y2 = fLandscape ? 1 : y1;
160 TPad* p1 = new TPad("p1", "p1", 0, y1, x2, 1, 0, 0);
161 TPad* p2 = new TPad("p2", "p2", x1, 0, 1, y2, 0, 0);
169 TIter nextM(rM->GetHists());
170 while ((h = static_cast<TH1*>(nextM()))) rC->Add(h);
173 TIter next(rF->GetHists());
174 while ((h = static_cast<TH1*>(next()))) rC->Add(h);
179 TCollection* fS = GetCollection(file, ColName("Forward", false));
182 GetParameter(fS, "sNN", sNN);
183 GetParameter(fS, "sys", sys);
184 GetParameter(fS, "trigger", trigger);
186 static_cast<TAxis*>(GetObject(fS, "centAxis", false));
187 UShort_t cLow = centAxis && !onlyMB ? centAxis->GetXmin() : 0;
188 UShort_t cHigh = centAxis && !onlyMB ? centAxis->GetXmax() : 100;
190 CompileScript("OtherData.C", "", "RefData", false);
192 // If we have V0AND trigger, get NSD other data
193 TMultiGraph* other = 0;
195 Int_t oT = (trigger == 0x2000) ? 0x4 : trigger;
196 TString oC = Form("RefData::GetData(%hu,%hu,%hu,%hu,%hu,0xF)",
197 sys, sNN, oT, cLow, cHigh);
198 other = reinterpret_cast<TMultiGraph*>(gROOT->ProcessLine(oC));
201 other = new TMultiGraph("other", "");
202 Int_t nCent = centAxis->GetNbins();
203 for (Int_t i = 1; i <= nCent; i++) {
204 TString oC = Form("RefData::GetData(%hu,%hu,%hu,%hu,%hu,0xF)",
205 sys, sNN, 0, UShort_t(centAxis->GetBinLowEdge(i)),
206 UShort_t(centAxis->GetBinUpEdge(i)));
208 reinterpret_cast<TMultiGraph*>(gROOT->ProcessLine(oC));
209 if (oM) other->Add(oM);
214 // other->Draw("ap");
215 // Double_t oMax = other->GetHistogram()->GetMaximum();
216 // Double_t rMax = rC->GetMaximum("nostack");
217 // other->SetMaximum(1.2*TMath::Max(oMax, rMax));
218 // rC->Draw("same nostack");
220 TIter nextG(other->GetListOfGraphs());
221 while ((g = nextG())) {
222 // Printf("Drawing %s/%s", g->GetName(), g->GetTitle());
223 g->DrawClone("same p");
233 TLegend* l = new TLegend(0.01, 0.1, 0.99, 0.99,
234 onlyMB || !centAxis ? "" : "Centralities");
235 l->SetNColumns(fLandscape ? 1 : 2);
238 CleanStack(rC, l, onlyMB ? 0 : centAxis);
241 TIter nextG(other->GetListOfGraphs());
243 while ((g = nextG())) {
244 if (seen.Index(g->GetTitle()) != kNPOS) continue;
245 seen.Append(Form("|%s", g->GetTitle()));
246 TLegendEntry* e = l->AddEntry("dummy", g->GetTitle(), "p");
247 TGraph* gg = static_cast<TGraph*>(g);
248 e->SetMarkerStyle(gg->GetMarkerStyle());
249 e->SetMarkerSize(gg->GetMarkerSize());
250 e->SetMarkerColor(kBlack);
257 //____________________________________________________________________
258 void DrawSums(TDirectory* top, const TString& base, bool onlyMB)
260 TCollection* c = GetCollection(top, ColName(base));
263 TAxis* centAxis = static_cast<TAxis*>(GetObject(c, "centAxis", false));
264 if (centAxis->GetNbins() < 1) centAxis = 0;
267 Double_t save = fParName->GetTextSize();
268 Double_t xSave = fParVal->GetX();
269 fParName->SetTextSize(0.03);
270 fParVal->SetTextSize(0.03);
274 if (!onlyMB && centAxis) {
279 for (Int_t i = 1; i <= centAxis->GetNbins(); i++) {
280 DrawParameter(y, (i == 1 ? "Centrality classes" : ""),
281 Form("%3d%% - %3d%%",
282 Int_t(centAxis->GetBinLowEdge(i)),
283 Int_t(centAxis->GetBinUpEdge(i))));
286 TH1* cent = GetH1(c, "cent");
287 cent->SetFillColor(kRed+1);
288 cent->SetFillStyle(3001);
289 cent->SetXTitle("Centrality [%]");
290 cent->SetYTitle("Events");
292 DrawInPad(fBody, 2, cent);
296 UShort_t sys, sNN, scheme;
298 GetParameter(c, "sNN", sNN);
299 GetParameter(c, "sys", sys);
300 GetParameter(c, "scheme", scheme);
301 GetParameter(c, "trigger", trigger);
303 TString schemeString;
304 if (scheme == 0) schemeString = "1/N_{accepted}";
305 if (scheme & 0x1) schemeString.Append("1/#epsilon_{V}1/#epsilon_{T}");
306 if (scheme & 0x2) schemeString.Append("Shape ");
307 if (scheme & 0x4) schemeString.Append("A+C-E ");
308 if (scheme & 0x8) schemeString.Append("#epsilon_{T,MC} ");
309 if (scheme & 0x10) schemeString.Append("0-bin");
311 TString trigString; TriggerString(trigger, trigString);
312 TString sysString; SysString(sys, sysString);
313 TString sNNString; SNNString(sNN, sNNString);
315 DrawParameter(y, "Collision system", sysString);
316 DrawParameter(y, "#sqrt{s_{NN}}", sNNString);
317 DrawParameter(y, "Normalization scheme", schemeString);
318 DrawParameter(y, "Triggers", trigString);
320 fParName->SetTextSize(save);
321 fParVal->SetTextSize(save);
322 fParVal->SetX(xSave);
324 PrintCanvas(Form("%s sums", base.Data()));
326 Int_t cLow = centAxis ? centAxis->GetXmin() : 0;
327 Int_t cHigh = centAxis ? -centAxis->GetXmax() : -100;
328 DrawCentSum(c, base, cLow, cHigh);
329 if (onlyMB || !centAxis) return;
331 for (Int_t i = 1; i <= centAxis->GetNbins(); i++)
332 DrawCentSum(c, base, centAxis->GetBinLowEdge(i),
333 centAxis->GetBinUpEdge(i));
335 //____________________________________________________________________
336 void DrawCentSum(const TCollection* sums, const TString& base,
337 Int_t cLow, Int_t cHigh)
339 TString title("sums");
340 TCollection* c = GetCentCollection(sums, base, cLow, cHigh, title);
343 TH2* bin = GetH2(c, "sum");
344 TH2* bin0 = GetH2(c, "sum0");
345 TH1* type = GetH1(c, "events");
346 TH1* trig = GetH1(c, "triggers");
347 if (!bin0 || !bin || !trig || !type) return;
349 type->SetFillStyle(3001);
350 type->SetFillColor(kGreen+1);
354 DrawInPad(fBody, 1, trig, "HIST TEXT");
355 DrawInPad(fBody, 2, type, "HIST TEXT");
356 DrawInPad(fBody, 3, bin, "colz");
357 DrawInPad(fBody, 4, bin0, "colz");
359 if (bin0->GetEntries() <= 0) {
361 TLatex* l = new TLatex(0.5, 0.5, "No 0-bin events");
368 //____________________________________________________________________
369 void DrawResTitle(TCollection* c, Double_t& y, Bool_t onlyMB)
371 Double_t save = fParName->GetTextSize();
372 Double_t xSave = fParVal->GetX();
373 fParName->SetTextSize(0.03);
374 fParVal->SetTextSize(0.03);
377 TAxis* centAxis = static_cast<TAxis*>(GetObject(c, "centAxis", false));
378 if (!onlyMB && centAxis) {
379 for (Int_t i = 1; i <= centAxis->GetNbins(); i++) {
380 DrawParameter(y, (i == 1 ? "Centrality classes" : ""),
381 Form("%3d%% - %3d%%",
382 Int_t(centAxis->GetBinLowEdge(i)),
383 Int_t(centAxis->GetBinUpEdge(i))));
386 TObject* oSNN = GetObject(c, "sNN");
387 TString tSNN; SNNString(oSNN->GetUniqueID(), tSNN);
389 DrawParameter(y, "Collision system", GetObject(c, "sys")->GetTitle());
390 DrawParameter(y, "#sqrt{s_{NN}}",tSNN);
391 DrawParameter(y, "Trigger",GetObject(c,"trigger")->GetTitle());
392 TObject* oscheme = GetObject(c,"scheme");
393 TString scheme = oscheme ? oscheme->GetTitle() : "";
394 if (scheme.IsNull()) scheme = "1/N_{accepted}";
395 DrawParameter(y, "Normalization scheme", scheme);
397 Double_t epsT, epsT0;
398 GetParameter(c, "triggerEff", epsT);
399 GetParameter(c, "triggerEff0", epsT0);
400 DrawParameter(y, "#epsilon_{T}", Form("%5.3f", epsT));
401 DrawParameter(y, "#epsilon_{T,zero bin}", Form("%5.3f", epsT0));
403 TObject* options = GetObject(c, "options");
404 TString opts(options->GetTitle());
405 TObjArray* tokens = opts.Tokenize(",");
406 TObjString* opt = 0;;
409 while ((opt = static_cast<TObjString*>(oNext()))) {
410 DrawParameter(y, (first ? "options" : ""),
411 opt->String().Strip(TString::kBoth));
414 fParName->SetTextSize(save);
415 fParVal->SetTextSize(save);
416 fParVal->SetX(xSave);
419 //____________________________________________________________________
420 THStack* DrawRes(TDirectory* top, const TString& base, Bool_t onlyMB)
422 TCollection* c = GetCollection(top, ColName(base, true));
427 DrawResTitle(c, y, onlyMB);
428 PrintCanvas(Form("%s results", base.Data()));
430 TAxis* centAxis = static_cast<TAxis*>(GetObject(c, "centAxis", false));
431 if (centAxis->GetNbins() < 1) centAxis = 0;
433 TLegend* l = new TLegend(0.1, 0.1, 0.9, 0.9,
434 onlyMB || !centAxis? "" : "Centralities");
435 l->SetNColumns(fLandscape ? 1 : 2);
439 THStack* dndeta_ = GetStack(c, "dndeta");
440 THStack* dndeta5_ = GetStack(c, "dndeta_rebin05");
441 THStack* dndeta = CleanStack(dndeta_, l, centAxis);
442 THStack* dndeta5 = CleanStack(dndeta5_, 0, 0);
445 Double_t y1 = fLandscape ? 0 : .3;
446 Double_t x2 = fLandscape ? .7 : 1;
447 Double_t x1 = fLandscape ? x2 : 0;
448 Double_t y2 = fLandscape ? 1 : y1;
449 TPad* p1 = new TPad("p1", "p1", 0, y1, x2, 1, 0, 0);
450 TPad* p2 = new TPad("p2", "p2", x1, 0, 1, y2, 0, 0);
459 // fBody->Divide(1, 3, 0, 0);
461 DrawInPad(p2, 0, l, "");
462 DrawInPad(p1, 1, dndeta, "nostack");
463 DrawInPad(p1, 2, dndeta5, "nostack");
464 p1->GetPad(1)->SetGridx();
465 p1->GetPad(2)->SetGridx();
467 PrintCanvas(Form("%s results - stacks", base.Data()));
470 Int_t cLow = centAxis ? centAxis->GetXmin() : 0;
471 Int_t cHigh = centAxis ? -centAxis->GetXmax() : -100;
472 DrawCentRes(c, base, cLow, cHigh);
473 if (onlyMB || !centAxis) {
474 Info("", "Returning dndeta for MB");
475 dndeta = MakeMBStack(c, base);
479 for (Int_t i = 1; i <= centAxis->GetNbins(); i++)
480 DrawCentRes(c, base, centAxis->GetBinLowEdge(i),
481 centAxis->GetBinUpEdge(i));
485 //____________________________________________________________________
486 THStack* MakeMBStack(const TCollection* sums, const TString& base)
488 TString title("results");
489 TCollection* c = GetCentCollection(sums, base, 0, -1, title);
492 TH1* dndeta = GetH1(c, Form("dndeta%s",base.Data()));
493 if (!dndeta) return 0;
495 THStack* ret = new THStack("dndetaMB", title);
498 if (base.EqualTo("MCTruth")) {
499 dndeta = GetH1(c, "dndetaTruth");
500 if (dndeta) ret->Add(dndeta);
505 //____________________________________________________________________
506 void DrawCentRes(const TCollection* sums, const TString& base,
507 Int_t cLow, Int_t cHigh)
509 TString title("results");
510 TCollection* c = GetCentCollection(sums, base, cLow, cHigh, title);
514 TH1* trig = GetH1(c, "triggers");
515 TH1* norm = GetH1(c, Form("norm%s",base.Data()));
516 TH1* dndeta = GetH1(c, Form("dndeta%s",base.Data()));
517 TH2* d2ndetadphi = GetH2(c, Form("d2Ndetadphi%s", base.Data()));
518 if (!trig || !norm || !dndeta || !d2ndetadphi) return;
520 norm->SetFillColor(kGreen+1);
521 norm->SetFillStyle(3001);
524 fBody->Divide(2, 3, 0.05, 0);
527 TVirtualPad* p = fBody->GetPad(trP);
528 p->SetBottomMargin(0.15);
529 p->SetLeftMargin(0.15);
530 if (trP > 2) p->SetTopMargin(0.05);
532 DrawInPad(fBody, trP, trig, "HIST TEXT");
533 DrawInPad(fBody, 2, norm, "", 0, "Normalization");
534 DrawInPad(fBody, 4, dndeta, "", 0, "d#it{N}_{ch}/d#it{#eta}");
535 DrawInPad(fBody, 6, GetH1(c, Form("dndeta%s_rebin05",base.Data())),
536 "", 0, "d#it{N}_{ch}/d#it{#eta} (rebinned by 5)");
537 DrawInPad(fBody, 5, d2ndetadphi, "colz");
539 fBody->GetPad(2)->SetGridx(); fBody->GetPad(2)->SetLeftMargin(0.15);
540 fBody->GetPad(4)->SetGridx(); fBody->GetPad(4)->SetLeftMargin(0.15);
541 fBody->GetPad(6)->SetGridx(); fBody->GetPad(6)->SetLeftMargin(0.15);
543 TObject* normCalc = GetObject(c, "normCalc");
544 TString calc = normCalc ? normCalc->GetTitle() : "?";
547 calc.ReplaceAll("beta", "#beta");
548 calc.ReplaceAll("eps", "#epsilon");
549 const char* sufs[] = { "all", "acc", "trg", "vtx", "B", "A", "C", "E",
551 const char** suf = sufs;
553 calc.ReplaceAll(Form("_%s", *suf), Form("_{%s}", *suf));
558 TObjArray* lines = calc.Tokenize("\n");
559 // TPaveText* disp = new TPaveText(.1,.1,.9,.9, "NDC");
561 TObjString* sline = 0;
563 Double_t xSave = fParName->GetX();
564 Int_t aSave = fParName->GetTextAlign();
565 fParName->SetTextAlign(33);
566 fParName->SetX(fParVal->GetX()-.05);
567 while ((sline = static_cast<TObjString*>(next()))) {
568 // disp->AddText(line->GetName());
569 TString& line = sline->String();
570 Ssiz_t eq = line.Last('=');
572 DrawParameter(y, line, "");
575 TString name = line(0, eq);
576 TString val = line(eq+1,line.Length()-eq-1);
577 DrawParameter(y, name.Strip(TString::kBoth),
578 val.Strip(TString::kBoth));
581 fParName->SetTextAlign(aSave);
582 fParName->SetX(xSave);
583 // disp->SetBorderSize(0);
584 // disp->SetBorderSize(0);
585 // disp->SetFillStyle(0);
586 // DrawInPad(fBody, 3, disp);
591 DrawCentResDetails(c, title);
593 //____________________________________________________________________
594 void DrawCentResDetails(const TCollection* sums, const TString& base)
596 TString title = TString::Format("%s - details: ", base.Data());
598 TCollection* c = GetCollection(sums, "partial");
600 Warning("", "Collection partical not found in %s", sums->GetName());
605 fBody->Divide(3, 1, 0.05, 0);
607 const char* typs[] = { "", "0", "All" };
608 const char* tits[] = { "Non-zero events", "Zero events", "Weighted sum" };
609 for (Int_t i = 1; i <= 3; i++) {
610 const char* suf = typs[i-1];
611 TVirtualPad* p = fBody->cd(i);
612 p->SetTopMargin(0.10);
614 TLatex* ltx = new TLatex(0.5, .99, tits[i-1]);
616 ltx->SetTextAlign(23);
617 ltx->SetTextSize(0.05);
620 TH1* sum = GetH2(c, Form("sum%s", suf));
621 TH1* norm = GetH1(c, Form("norm%s", suf));
622 TH1* phi = GetH1(c, Form("phi%s", suf));
624 norm->SetFillColor(kGreen+1);
625 norm->SetFillStyle(3002);
626 phi->SetFillColor(kBlue+1);
627 phi->SetFillStyle(3001);
629 p->Divide(1, 3, 0, 0);
630 DrawInPad(p, 1, sum, sum->Integral()>0 ? "col" : "", 0,
631 "d^{2}#it{N}_{ch}/d#it{#varphi}d#it{#eta}");
632 DrawInPad(p, 2, GetH1(c, Form("average%s", suf)), "", 0,
633 "d#it{N}_{ch}/d#it{#eta}");
634 DrawInPad(p, 3, norm, "", 0, "#eta-coverage/#varphi-acceptance");
635 DrawInPad(p, 3, phi, "same", kLegend);
640 //____________________________________________________________________
641 THStack* CleanStack(const THStack* stack, TLegend* l, const TAxis* axis)
643 THStack* ret = new THStack(stack->GetName(), stack->GetTitle());
644 TList* hists = stack->GetHists();
649 while ((h = static_cast<TH1*>(next()))) {
650 TString name(h->GetTitle());
651 TString nme(h->GetName());
652 if (nme.Contains("_mirror", TString::kIgnoreCase)) {
653 // Printf("Ignore %s/%s in stack", nme.Data(), name.Data());
659 name.Form("%3d%% - %3d%%",
660 Int_t(axis->GetBinLowEdge(j)),
661 Int_t(axis->GetBinUpEdge(j)));
663 name.ReplaceAll("ALICE", "");
664 name.ReplaceAll("dNdeta", " - work in progress");
666 ok = axis && axis->GetBinUpEdge(j) > 100;
667 // Printf("Adding entry %d: %s/%s", j, nme.Data(), name.Data());
668 TLegendEntry* e = l->AddEntry("dummy", name, "f");
669 e->SetFillStyle(1001);
670 e->SetFillColor(h->GetMarkerColor());