3 * @author Christian Holm Christensen <cholm@dalsgaard.hehi.nbi.dk>
4 * @date Wed Mar 23 14:07:10 2011
6 * @brief Script to visualise the dN/deta for pp and PbPb
8 * This script is independent of any AliROOT code - and should stay
11 * The script is <emph>very</emph> long - sigh - the joy of drawing
12 * things nicely in ROOT
14 * @ingroup pwg2_forward_dndeta
19 #include <TGraphErrors.h>
20 #include <TGraphAsymmErrors.h>
21 #include <TMultiGraph.h>
33 #include <TLegendEntry.h>
41 Double_t myFunc(Double_t* xp, Double_t* pp);
44 * Class to draw dN/deta results
46 * @ingroup pwg2_forward_tasks_dndeta
47 * @ingroup pwg2_forward_dndeta
52 * POD of data for range zooming
56 TAxis* fMasterAxis; // Master axis
57 TAxis* fSlave1Axis; // First slave axis
58 TVirtualPad* fSlave1Pad; // First slave pad
59 TAxis* fSlave2Axis; // Second slave axis
60 TVirtualPad* fSlave2Pad; // Second slave pad
62 //__________________________________________________________________
69 fShowRatios(false), // Show ratios
70 fShowLeftRight(false), // Show asymmetry
71 fShowRings(false), // Show rings too
72 fExport(false), // Export data to script
73 fCutEdges(false), // Whether to cut edges
74 fRemoveOuters(false), // Whether to remove outers
75 fShowOthers(0), // Show other data
77 fRebin(0), // Rebinning factor
78 fFwdSysErr(0.076), // Systematic error in forward range
79 fCenSysErr(0), // Systematic error in central range
80 fTitle(""), // Title on plot
81 fClusterScale(""), // Scaling of clusters to tracklets
82 // Read (or set) information
83 fTrigString(0), // Trigger string (read, or set)
84 fNormString(0), // Normalisation string (read, or set)
85 fSNNString(0), // Energy string (read, or set)
86 fSysString(0), // Collision system string (read or set)
87 fVtxAxis(0), // Vertex cuts (read or set)
88 fCentAxis(0), // Centrality axis
90 fResults(0), // Stack of results
91 fRatios(0), // Stack of ratios
92 fLeftRight(0), // Left-right asymmetry
93 fOthers(0), // Older data
94 fTriggers(0), // Number of triggers
95 fTruth(0), // Pointer to truth
96 fRangeParam(0) // Parameter object for range zoom
98 fRangeParam = new RangeParam;
99 fRangeParam->fMasterAxis = 0;
100 fRangeParam->fSlave1Axis = 0;
101 fRangeParam->fSlave1Pad = 0;
102 fRangeParam->fSlave2Axis = 0;
103 fRangeParam->fSlave2Pad = 0;
105 dNdetaDrawer(const dNdetaDrawer&) {}
106 dNdetaDrawer& operator=(const dNdetaDrawer&) { return *this; }
108 //__________________________________________________________________
109 virtual ~dNdetaDrawer()
111 if (fRatios && fRatios->GetHists()) fRatios->GetHists()->Delete();
112 if (fResults && fResults->GetHists()) fResults->GetHists()->Delete();
114 if (fTrigString) { delete fTrigString; fTrigString = 0; }
115 if (fSNNString) { delete fSNNString; fSNNString = 0; }
116 if (fSysString) { delete fSysString; fSysString = 0; }
117 if (fVtxAxis) { delete fVtxAxis; fVtxAxis = 0; }
118 if (fCentAxis) { delete fCentAxis; fCentAxis = 0; }
119 if (fResults) { delete fResults; fResults = 0; }
120 if (fRatios) { delete fRatios; fRatios = 0; }
121 if (fOthers) { delete fOthers; fOthers = 0; }
122 if (fTriggers) { delete fTriggers; fTriggers = 0; }
126 //==================================================================
129 * @name Set parameters
132 * Show other (UA5, CMS, ...) data
134 * @param x Whether to show or not
136 void SetShowOthers(UShort_t x) { fShowOthers = x; }
137 //__________________________________________________________________
139 * Whether to show ratios or not. If there's nothing to compare to,
140 * the ratio panel will be implicitly disabled
142 * @param x Whether to show or not
144 void SetShowRatios(Bool_t x) { fShowRatios = x; }
145 //__________________________________________________________________
148 * Whether to show the left/right asymmetry
150 * @param x To show or not
152 void SetShowLeftRight(Bool_t x) { fShowLeftRight = x; }
153 //__________________________________________________________________
155 * Whether to show rings
157 * @param x To show or not
159 void SetShowRings(Bool_t x) { fShowRings = x; }
160 //__________________________________________________________________
162 * Whether to export results to a script
164 * @param x Wheter to export results to a script
166 void SetExport(Bool_t x) { fExport = x; }
167 //__________________________________________________________________
169 * Set the rebinning factor
171 * @param x Rebinning factor (must be a divisor in the number of bins)
173 void SetRebin(UShort_t x) { fRebin = x; }
174 //__________________________________________________________________
176 * Wheter to cut away the edges
178 * @param x Whether or not to cut away edges
180 void SetCutEdges(Bool_t x) { fCutEdges = x; }
181 //__________________________________________________________________
183 * Set the title of the plot
187 void SetTitle(TString x) { fTitle = x; }
188 //__________________________________________________________________
190 * Set the systematic error in the forward region
192 * @param e Systematic error in the forward region
194 void SetForwardSysError(Double_t e=0) { fFwdSysErr = e; }
195 //__________________________________________________________________
197 * Set the systematic error in the forward region
199 * @param e Systematic error in the forward region
201 void SetCentralSysError(Double_t e=0) { fCenSysErr = e; }
203 //==================================================================
206 * @name Override settings from input
209 * Override setting from file
211 * @param sNN Center of mass energy per nucleon pair (GeV)
213 void SetSNN(UShort_t sNN)
215 fSNNString = new TNamed("sNN", Form("%04dGeV", sNN));
216 fSNNString->SetUniqueID(sNN);
218 //__________________________________________________________________
220 * Set the collision system
224 * @param sys collision system
226 void SetSys(UShort_t sys)
228 fSysString = new TNamed("sys", (sys == 1 ? "pp" :
229 sys == 2 ? "PbPb" : "unknown"));
230 fSysString->SetUniqueID(sys);
232 //__________________________________________________________________
234 * Set the vertex range in centimeters
236 * @param vzMin Min @f$ v_z@f$
237 * @param vzMax Max @f$ v_z@f$
239 void SetVertexRange(Double_t vzMin, Double_t vzMax)
241 fVtxAxis = new TAxis(10, vzMin, vzMax);
242 fVtxAxis->SetName("vtxAxis");
243 fVtxAxis->SetTitle(Form("v_{z}#in[%+5.1f,%+5.1f]cm", vzMin, vzMax));
245 //__________________________________________________________________
246 void SetTrigger(UShort_t trig)
248 fTrigString = new TNamed("trigString", (trig & 0x1 ? "INEL" :
249 trig & 0x2 ? "INEL>0" :
252 fTrigString->SetUniqueID(trig);
256 //==================================================================
259 * @name Main steering functions
262 * Run the code to produce the final result.
264 * @param filename File containing the data
266 void Run(const char* filename="forward_dndeta.root")
268 Double_t max = 0, rmax=0, amax=0;
270 gStyle->SetPalette(1);
272 // --- Open input file -------------------------------------------
273 TFile* file = TFile::Open(filename, "READ");
275 Error("Open", "Cannot open %s", filename);
278 // --- Get forward list ------------------------------------------
279 TList* forward = static_cast<TList*>(file->Get("ForwardResults"));
281 Error("Open", "Couldn't find list ForwardResults");
284 // --- Get information on the run --------------------------------
285 FetchInformation(forward);
286 // --- Set the macro pathand load other data script --------------
287 gROOT->SetMacroPath(Form("%s:$(ALICE_ROOT)/PWG2/FORWARD/analysis2",
288 gROOT->GetMacroPath()));
289 gROOT->LoadMacro("OtherData.C");
291 // --- Get the central results -----------------------------------
292 TList* clusters = static_cast<TList*>(file->Get("CentralResults"));
293 if (!clusters) Warning("Open", "Couldn't find list CentralResults");
295 // --- Get the central results -----------------------------------
296 TList* mcTruth = static_cast<TList*>(file->Get("MCTruthResults"));
297 if (!mcTruth) Warning("Open", "Couldn't find list MCTruthResults");
299 // --- Make our containtes ---------------------------------------
300 fResults = new THStack("results", "Results");
301 fRatios = new THStack("ratios", "Ratios");
302 fLeftRight = new THStack("asymmetry", "Left-right asymmetry");
303 fOthers = new TMultiGraph();
305 // --- Loop over input data --------------------------------------
306 /*TObjArray* mcA =*/ FetchResults(mcTruth, "MCTruth", max, rmax, amax);
307 TObjArray* fwdA = FetchResults(forward, "Forward", max, rmax, amax);
308 TObjArray* cenA = FetchResults(clusters, "Central", max, rmax, amax);
310 // --- Get trigger information -----------------------------------
311 TList* sums = static_cast<TList*>(file->Get("ForwardSums"));
313 TList* all = static_cast<TList*>(sums->FindObject("all"));
315 fTriggers = FetchResult(all, "triggers");
316 if (!fTriggers) all->ls();
319 Warning("Run", "List all not found in ForwardSums");
324 Warning("Run", "No ForwardSums directory found in %s", file->GetName());
328 // --- Check our stacks ------------------------------------------
329 if (!fResults->GetHists() ||
330 fResults->GetHists()->GetEntries() <= 0) {
331 Error("Run", "No histograms in result stack!");
334 if (!fOthers->GetListOfGraphs() ||
335 fOthers->GetListOfGraphs()->GetEntries() <= 0) {
336 Warning("Run", "No other data found - disabling that");
339 if (!fRatios->GetHists() ||
340 fRatios->GetHists()->GetEntries() <= 0) {
341 Warning("Run", "No ratio data found - disabling that");
345 if (!fLeftRight->GetHists() ||
346 fLeftRight->GetHists()->GetEntries() <= 0) {
347 Warning("Run", "No left/right data found - disabling that");
349 fShowLeftRight = false;
351 if (fFwdSysErr > 0) {
352 if (fCenSysErr <= 0) fCenSysErr = fFwdSysErr;
353 for (Int_t i = 0; i < fwdA->GetEntriesFast(); i++) {
354 TH1* fwd = static_cast<TH1*>(fwdA->At(i));
355 TH1* cen = static_cast<TH1*>(cenA->At(i));
359 TH1* tmp = Merge(cen, fwd, low, high);
360 TF1* f = FitMerged(tmp, low, high);
361 MakeSysError(tmp, cen, fwd, f);
363 Info("", "Adding systematic error histogram %s",
365 fResults->GetHists()->AddFirst(tmp, "e5");
366 TH1* tmp2 = Symmetrice(tmp);
367 tmp2->SetFillColor(tmp->GetFillColor());
368 tmp2->SetFillStyle(tmp->GetFillStyle());
369 tmp2->SetMarkerStyle(tmp->GetMarkerStyle());
370 tmp2->SetLineWidth(tmp->GetLineWidth());
371 fResults->GetHists()->AddFirst(tmp2, "e5");
372 fResults->Modified();
378 // --- Close the input file --------------------------------------
383 // --- Plot results ----------------------------------------------
384 Plot(max, rmax, amax);
387 //__________________________________________________________________
389 * Fetch the information on the run from the results list
391 * @param results Results list
393 void FetchInformation(const TList* results)
396 fTrigString = static_cast<TNamed*>(results->FindObject("trigger"));
398 fNormString = static_cast<TNamed*>(results->FindObject("scheme"));
400 fSNNString = static_cast<TNamed*>(results->FindObject("sNN"));
402 fSysString = static_cast<TNamed*>(results->FindObject("sys"));
404 fVtxAxis = static_cast<TAxis*>(results->FindObject("vtxAxis"));
406 fCentAxis = static_cast<TAxis*>(results->FindObject("centAxis"));
408 TNamed* options = static_cast<TAxis*>(results->FindObject("options"));
409 if (!fTrigString) fTrigString = new TNamed("trigger", "unknown");
410 if (!fNormString) fNormString = new TNamed("scheme", "unknown");
411 if (!fSNNString) fSNNString = new TNamed("sNN", "unknown");
412 if (!fSysString) fSysString = new TNamed("sys", "unknown");
414 fVtxAxis = new TAxis(1,0,0);
415 fVtxAxis->SetName("vtxAxis");
416 fVtxAxis->SetTitle("v_{z} range unspecified");
419 TString centTxt("none");
421 Int_t nCent = fCentAxis->GetNbins();
422 centTxt = Form("%d bins", nCent);
423 for (Int_t i = 0; i <= nCent; i++)
424 centTxt.Append(Form("%c%d", i == 0 ? ' ' : '-',
425 int(fCentAxis->GetXbins()->At(i))));
427 Info("FetchInformation",
429 " Trigger: %-30s (%d)\n"
430 " sqrt(sNN): %-30s (%dGeV)\n"
431 " System: %-30s (%d)\n"
432 " Vz range: %-30s (%f,%f)\n"
433 " Normalization: %-30s (%d)\n"
436 fTrigString->GetTitle(), fTrigString->GetUniqueID(),
437 fSNNString->GetTitle(), fSNNString->GetUniqueID(),
438 fSysString->GetTitle(), fSysString->GetUniqueID(),
439 fVtxAxis->GetTitle(), fVtxAxis->GetXmin(), fVtxAxis->GetXmax(),
440 fNormString->GetTitle(), fNormString->GetUniqueID(),
441 centTxt.Data(), (options ? options->GetTitle() : "none"));
443 //__________________________________________________________________
444 TMultiGraph* FetchOthers(UShort_t centLow, UShort_t centHigh)
446 TMultiGraph* thisOther = 0;
447 if (fShowOthers == 0) return 0;
449 UShort_t sys = (fSysString ? fSysString->GetUniqueID() : 0);
450 UShort_t trg = (fTrigString ? fTrigString->GetUniqueID() : 0);
451 UShort_t snn = (fSNNString ? fSNNString->GetUniqueID() : 0);
452 Long_t ret = gROOT->ProcessLine(Form("GetData(%d,%d,%d,%d,%d,%d);",
458 thisOther = reinterpret_cast<TMultiGraph*>(ret);
461 //__________________________________________________________________
463 * Get the results from the top-level list
467 * @param max On return, maximum of data
468 * @param rmax On return, maximum of ratios
469 * @param amax On return, maximum of left-right comparisons
472 FetchResults(const TList* list,
478 UShort_t n = fCentAxis ? fCentAxis->GetNbins() : 0;
480 TList* all = static_cast<TList*>(list->FindObject("all"));
482 Error("FetchResults", "Couldn't find list 'all' in %s",
486 TObjArray* a = new TObjArray;
487 TH1* h = FetchResults(all, name, FetchOthers(0,0),
488 -1000, 0, max, rmax, amax);
493 TObjArray* a = new TObjArray;
494 for (UShort_t i = 0; i < n; i++) {
495 UShort_t centLow = fCentAxis->GetBinLowEdge(i+1);
496 UShort_t centHigh = fCentAxis->GetBinUpEdge(i+1);
497 TString lname = Form("cent%03d_%03d", centLow, centHigh);
498 TList* thisCent = static_cast<TList*>(list->FindObject(lname));
499 Int_t col = GetCentralityColor(i+1);
501 TString centTxt = Form("%3d%%-%3d%% central", centLow, centHigh);
503 Error("FetchResults", "Couldn't find list '%s' in %s",
504 lname.Data(), list->GetName());
507 TH1* h = FetchResults(thisCent, name, FetchOthers(centLow, centHigh),
508 col, centTxt.Data(), max, rmax, amax);
513 //__________________________________________________________________
514 Int_t GetCentralityColor(Int_t bin) const
516 UShort_t centLow = fCentAxis->GetBinLowEdge(bin);
517 UShort_t centHigh = fCentAxis->GetBinUpEdge(bin);
518 Float_t fc = (centLow+double(centHigh-centLow)/2) / 100;
519 Int_t nCol = gStyle->GetNumberOfColors();
520 Int_t icol = TMath::Min(nCol-1,int(fc * nCol + .5));
521 Int_t col = gStyle->GetColorPalette(icol);
522 //Info("GetCentralityColor","%3d: %3d-%3d -> %3d",bin,centLow,centHigh,col);
525 //__________________________________________________________________
526 void SetAttributes(TH1* h, Int_t color)
529 if (color < 0) return;
530 // h->SetLineColor(color);
531 h->SetMarkerColor(color);
532 // h->SetFillColor(color);
534 //__________________________________________________________________
535 void SetAttributes(TGraph* g, Int_t color)
538 if (color < 0) return;
539 // g->SetLineColor(color);
540 g->SetMarkerColor(color);
541 // g->SetFillColor(color);
543 //__________________________________________________________________
544 void ModifyTitle(TNamed* /*h*/, const char* /*centTxt*/)
547 // if (!centTxt || !h) return;
548 // h->SetTitle(Form("%s, %s", h->GetTitle(), centTxt));
551 //__________________________________________________________________
553 * Fetch results for a particular centrality bin
557 * @param thisOther Other graphs
559 * @param centTxt Centrality text
560 * @param max On return, data maximum
561 * @param rmax On return, ratio maximum
562 * @param amax On return, left-right maximum
564 TH1* FetchResults(const TList* list,
566 TMultiGraph* thisOther,
573 TH1* dndeta = FetchResult(list, Form("dndeta%s", name));
574 TH1* dndetaMC = FetchResult(list, Form("dndeta%sMC", name));
575 TH1* dndetaTruth = FetchResult(list, "dndetaTruth");
577 TH1* dndetaMCSym = 0;
578 SetAttributes(dndeta, color);
579 SetAttributes(dndetaMC, fCentAxis ? color : color+2);
580 SetAttributes(dndetaTruth,color);
581 SetAttributes(dndetaSym, color);
582 SetAttributes(dndetaMCSym,fCentAxis ? color : color+2);
583 if (dndetaMC && fCentAxis)
584 dndetaMC->SetMarkerStyle(dndetaMC->GetMarkerStyle()+2);
585 if (dndetaMCSym && fCentAxis)
586 dndetaMCSym->SetMarkerStyle(dndetaMCSym->GetMarkerStyle()+2);
587 if (dndetaTruth && fCentAxis) {
588 dndetaTruth->SetMarkerStyle(34);
589 dndetaTruth->SetMarkerColor(kYellow-1);
591 ModifyTitle(dndeta, centTxt);
592 ModifyTitle(dndetaMC, centTxt);
593 ModifyTitle(dndetaTruth,centTxt);
594 ModifyTitle(dndetaSym, centTxt);
595 ModifyTitle(dndetaMCSym,centTxt);
598 max = TMath::Max(max, AddHistogram(fResults, dndetaTruth, "e5 p"));
599 max = TMath::Max(max, AddHistogram(fResults, dndetaMC, dndetaMCSym));
600 max = TMath::Max(max, AddHistogram(fResults, dndeta, dndetaSym));
603 fTruth = dndetaTruth;
607 THStack* rings = static_cast<THStack*>(list->FindObject("dndetaRings"));
609 TIter next(rings->GetHists());
611 while ((hist = static_cast<TH1*>(next())))
612 max = TMath::Max(max, AddHistogram(fResults, hist));
615 // Info("FetchResults", "Got %p, %p, %p from %s with name %s, max=%f",
616 // dndeta, dndetaMC, dndetaTruth, list->GetName(), name, max);
618 if (fShowLeftRight) {
619 fLeftRight->Add(Asymmetry(dndeta, amax));
620 fLeftRight->Add(Asymmetry(dndetaMC, amax));
624 TIter next(thisOther->GetListOfGraphs());
626 while ((g = static_cast<TGraph*>(next()))) {
627 fRatios->Add(Ratio(dndeta, g, rmax));
628 fRatios->Add(Ratio(dndetaSym, g, rmax));
629 SetAttributes(g, color);
630 ModifyTitle(g, centTxt);
631 if (!fOthers->GetListOfGraphs() ||
632 !fOthers->GetListOfGraphs()->FindObject(g->GetName())) {
633 max = TMath::Max(max,TMath::MaxElement(g->GetN(), g->GetY()));
637 // fOthers->Add(thisOther);
641 fRatios->Add(Ratio(dndeta, dndetaMC, rmax));
642 fRatios->Add(Ratio(dndetaSym, dndetaMCSym, rmax));
645 fRatios->Add(Ratio(dndeta, fTruth, rmax));
646 fRatios->Add(Ratio(dndetaSym, fTruth, rmax));
650 //__________________________________________________________________
653 * @param max Max value
654 * @param rmax Maximum diviation from 1 of ratios
655 * @param amax Maximum diviation from 1 of asymmetries
657 void Plot(Double_t max,
661 gStyle->SetOptTitle(0);
662 gStyle->SetTitleFont(132, "xyz");
663 gStyle->SetLabelFont(132, "xyz");
666 Int_t w = 800; // h / TMath::Sqrt(2);
670 if (!fShowRatios) w *= 1.3;
672 if (!fShowLeftRight) w *= 1.3;
675 y1 = (y11 > 0.0001 ? 0.4 : 0.2);
676 y2 = (y11 > 0.0001 ? 0.2 : 0.3);
678 TCanvas* c = new TCanvas("Results", "Results", w, h);
683 PlotResults(max, y1);
686 PlotRatios(rmax, y2, y1);
689 PlotLeftRight(amax, y3, y2);
693 Int_t vMin = fVtxAxis->GetXmin();
694 Int_t vMax = fVtxAxis->GetXmax();
695 TString trg(fTrigString->GetTitle());
697 if (fTriggers) nev = fTriggers->GetBinContent(1);
698 trg = trg.Strip(TString::kBoth);
699 trg.ReplaceAll(" ", "_");
700 trg.ReplaceAll(">", "Gt");
701 TString base(Form("dndeta_%s_%s_%s_%c%02d%c%02dcm_%09dev",
702 fSysString->GetTitle(),
703 fSNNString->GetTitle(),
705 vMin < 0 ? 'm' : 'p', TMath::Abs(vMin),
706 vMax < 0 ? 'm' : 'p', TMath::Abs(vMax),
708 c->SaveAs(Form("%s.png", base.Data()));
709 c->SaveAs(Form("%s.root", base.Data()));
710 c->SaveAs(Form("%s.C", base.Data()));
711 base.ReplaceAll("dndeta", "export");
714 //__________________________________________________________________
718 * @param stack Stack to include
719 * @param mg (optional) Multi graph to include
720 * @param x1 Lower X coordinate in the range [0,1]
721 * @param y1 Lower Y coordinate in the range [0,1]
722 * @param x2 Upper X coordinate in the range [0,1]
723 * @param y2 Upper Y coordinate in the range [0,1]
725 void BuildLegend(THStack* stack, TMultiGraph* mg,
726 Double_t x1, Double_t y1, Double_t x2, Double_t y2)
728 TLegend* l = new TLegend(x1,y1,x2,y2);
729 l->SetNColumns(fCentAxis ? 1 : 2);
735 // Loop over items in stack and get unique items, while ignoring
736 // mirrored data and systematic error bands
737 TIter next(stack->GetHists());
741 Bool_t sysErrSeen = false;
742 while ((hist = static_cast<TH1*>(next()))) {
743 TString t(hist->GetTitle());
744 TString n(hist->GetName());
746 if (t.Contains("mirrored")) continue;
747 if (n.Contains("syserror")) { sysErrSeen = true; continue; }
748 if (unique.FindObject(t.Data())) continue;
749 TObjString* s = new TObjString(hist->GetTitle());
750 s->SetUniqueID(((hist->GetMarkerStyle() & 0xFFFF) << 16) |
751 ((hist->GetMarkerColor() & 0xFFFF) << 0));
753 // l->AddEntry(hist, hist->GetTitle(), "pl");
756 // If we have other stuff, scan for unique names
757 TIter nexto(mg->GetListOfGraphs());
759 while ((g = static_cast<TGraph*>(nexto()))) {
760 TString n(g->GetTitle());
761 if (n.Contains("mirrored")) continue;
762 if (unique.FindObject(n.Data())) continue;
763 TObjString* s = new TObjString(n);
764 s->SetUniqueID(((g->GetMarkerStyle() & 0xFFFF) << 16) |
765 ((g->GetMarkerColor() & 0xFFFF) << 0));
767 // l->AddEntry(hist, hist->GetTitle(), "pl");
771 // Add legend entries for unique items only
772 TIter nextu(&unique);
775 while ((s = nextu())) {
776 TLegendEntry* dd = l->AddEntry(Form("data%2d", i++),
778 Int_t style = (s->GetUniqueID() >> 16) & 0xFFFF;
779 Int_t color = (s->GetUniqueID() >> 0) & 0xFFFF;
780 dd->SetLineColor(kBlack);
781 if (fCentAxis) dd->SetMarkerColor(kBlack);
782 else dd->SetMarkerColor(color);
783 dd->SetMarkerStyle(style);
786 // Add entry for systematic errors
787 TLegendEntry* d0 = l->AddEntry("d0", Form("%4.1f%% Systematic error",
788 100*fFwdSysErr), "f");
789 d0->SetLineColor(SYSERR_COLOR);
790 d0->SetMarkerColor(SYSERR_COLOR);
791 d0->SetFillColor(SYSERR_COLOR);
792 d0->SetFillStyle(SYSERR_STYLE);
793 d0->SetMarkerStyle(0);
797 if (!fCentAxis && i % 2 == 1) {
798 // To make sure the 'data' and 'mirrored' entries are on a line
800 TLegendEntry* dd = l->AddEntry("dd", " ", "");
806 dd->SetMarkerSize(0);
808 // Add entry for 'data'
809 TLegendEntry* d1 = l->AddEntry("d1", "Data", "lp");
810 d1->SetLineColor(kBlack);
811 d1->SetMarkerColor(kBlack);
812 d1->SetMarkerStyle(20);
813 // Add entry for 'mirrored data'
814 TLegendEntry* d2 = l->AddEntry("d2", "Mirrored data", "lp");
815 d2->SetLineColor(kBlack);
816 d2->SetMarkerColor(kBlack);
817 d2->SetMarkerStyle(24);
821 //__________________________________________________________________
823 * Build centrality legend
825 * @param axis Stack to include
826 * @param x1 Lower X coordinate in the range [0,1]
827 * @param y1 Lower Y coordinate in the range [0,1]
828 * @param x2 Upper X coordinate in the range [0,1]
829 * @param y2 Upper Y coordinate in the range [0,1]
831 void BuildCentLegend(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
833 if (!fCentAxis) return;
835 TLegend* l = new TLegend(x1,y1,x2,y2);
842 Int_t n = fCentAxis->GetNbins();
843 for (Int_t i = 1; i <= n; i++) {
844 Double_t low = fCentAxis->GetBinLowEdge(i);
845 Double_t upp = fCentAxis->GetBinUpEdge(i);
846 TLegendEntry* e = l->AddEntry(Form("dummy%02d", i),
847 Form("%3d%% - %3d%%",
848 int(low), int(upp)), "pl");
849 e->SetMarkerColor(GetCentralityColor(i));
853 //__________________________________________________________________
858 * @param yd Bottom position of pad
860 void PlotResults(Double_t max, Double_t yd)
862 // Make a sub-pad for the result itself
863 TPad* p1 = new TPad("p1", "p1", 0, yd, 1.0, 1.0, 0, 0, 0);
864 p1->SetTopMargin(0.05);
865 p1->SetBorderSize(0);
866 p1->SetBorderMode(0);
867 p1->SetBottomMargin(yd > 0.001 ? 0.001 : 0.1);
868 p1->SetRightMargin(0.03);
869 if (fShowLeftRight || fShowRatios) p1->SetGridx();
875 // Info("PlotResults", "Plotting results with max=%f", max);
876 fResults->SetMaximum(1.15*max);
877 fResults->SetMinimum(yd > 0.00001 ? -0.1 : 0);
879 FixAxis(fResults, (1-yd)*(yd > .001 ? 1 : .9 / 1.2),
880 "#font[12]{#frac{1}{N} "
881 "#frac{dN_{#font[132]{ch}}}{d#font[152]{#eta}}}");
884 fResults->DrawClone("nostack e1");
886 fRangeParam->fSlave1Axis = fResults->GetXaxis();
887 fRangeParam->fSlave1Pad = p1;
890 if (fShowOthers != 0) {
891 TGraphAsymmErrors* o = 0;
892 TIter nextG(fOthers->GetListOfGraphs());
893 while ((o = static_cast<TGraphAsymmErrors*>(nextG())))
894 o->DrawClone("same p");
897 // Make a legend in the main result pad
898 BuildCentLegend(.12, 1-p1->GetTopMargin()-.01-.5,
899 .35, 1-p1->GetTopMargin()-.01-.1);
900 Double_t x1 = (fCentAxis ? .7 : .15);
901 Double_t x2 = (fCentAxis ? 1-p1->GetRightMargin()-.01: .90);
902 Double_t y1 = (fCentAxis ? .5: p1->GetBottomMargin()+.01);
903 Double_t y2 = (fCentAxis ? 1-p1->GetTopMargin()-.01-.15 : .35);
905 BuildLegend(fResults, fOthers, x1, y1, x2, y2);
907 // Put a title on top
908 fTitle.ReplaceAll("@", " ");
909 TLatex* tit = new TLatex(0.10, 0.95, fTitle.Data());
911 tit->SetTextFont(132);
912 tit->SetTextSize(0.05);
915 Int_t aliceBlue = TColor::GetColor(41,73,156);
916 // Put a nice label in the plot
918 UShort_t snn = fSNNString->GetUniqueID();
919 const char* sys = fSysString->GetTitle();
920 if (snn == 2750) snn = 2760;
921 if (snn > 1000) eS = Form("%4.2fTeV", float(snn)/1000);
922 else eS = Form("%3dGeV", snn);
923 TLatex* tt = new TLatex(.93, .93, Form("%s #sqrt{s%s}=%s, %s",
925 (fCentAxis ? "_{NN}" : ""),
927 fCentAxis ? "by centrality" :
928 fTrigString->GetTitle()));
929 tt->SetTextColor(aliceBlue);
931 tt->SetTextFont(132);
932 tt->SetTextAlign(33);
935 // Put number of accepted events on the plot
937 if (fTriggers) nev = fTriggers->GetBinContent(1);
938 TLatex* et = new TLatex(.93, .83, Form("%d events", nev));
939 et->SetTextColor(aliceBlue);
941 et->SetTextFont(132);
942 et->SetTextAlign(33);
945 // Put number of accepted events on the plot
947 TLatex* vt = new TLatex(.93, .88, fVtxAxis->GetTitle());
949 vt->SetTextFont(132);
950 vt->SetTextAlign(33);
951 vt->SetTextColor(aliceBlue);
954 // results->Draw("nostack e1 same");
956 fRangeParam->fSlave1Axis = FindXAxis(p1, fResults->GetName());
957 fRangeParam->fSlave1Pad = p1;
960 // Mark the plot as preliminary
961 TLatex* pt = new TLatex(.12, .93, "Work in progress");
964 // pt->SetTextSize();
965 pt->SetTextColor(TColor::GetColor(234,26,46));
966 pt->SetTextAlign(13);
969 const char* logos[] = { "ALICE.png", "FMD.png", 0 };
970 const char** logo = logos;
972 if (gSystem->AccessPathName(*logo)) {
976 TPad* pad = new TPad("logo", "logo", .12, .7, .25, .9, 0, 0, 0);
977 pad->SetFillStyle(0);
980 TImage* i = TImage::Create();
987 //__________________________________________________________________
991 * @param max Maximum diviation from 1
992 * @param y1 Lower y coordinate of pad
993 * @param y2 Upper y coordinate of pad
995 void PlotRatios(Double_t max, Double_t y1, Double_t y2)
997 if (fShowRatios == 0) return;
999 bool isBottom = (y1 < 0.0001);
1000 Double_t yd = y2 - y1;
1001 // Make a sub-pad for the result itself
1002 TPad* p2 = new TPad("p2", "p2", 0, y1, 1.0, y2, 0, 0, 0);
1003 p2->SetTopMargin(0.001);
1004 p2->SetRightMargin(0.03);
1005 p2->SetBottomMargin(isBottom ? 1/yd * 0.07 : 0.0001);
1013 FixAxis(fRatios, yd, "Ratios", 7);
1015 fRatios->SetMaximum(1+TMath::Max(.22,1.05*max));
1016 fRatios->SetMinimum(1-TMath::Max(.32,1.05*max));
1018 fRatios->DrawClone("nostack e1");
1022 BuildLegend(fRatios, 0, .15,p2->GetBottomMargin()+.01,.9,
1023 isBottom ? .6 : .4);
1025 TLegend* l2 = p2->BuildLegend(.15,p2->GetBottomMargin()+.01,.9,
1026 isBottom ? .6 : .4);
1028 l2->SetFillColor(0);
1029 l2->SetFillStyle(0);
1030 l2->SetBorderSize(0);
1031 l2->SetTextFont(132);
1033 // Make a nice band from 0.9 to 1.1
1034 TGraphErrors* band = new TGraphErrors(2);
1035 band->SetPoint(0, fResults->GetXaxis()->GetXmin(), 1);
1036 band->SetPoint(1, fResults->GetXaxis()->GetXmax(), 1);
1037 band->SetPointError(0, 0, .1);
1038 band->SetPointError(1, 0, .1);
1039 band->SetFillColor(kYellow+2);
1040 band->SetFillStyle(3002);
1041 band->SetLineStyle(2);
1042 band->SetLineWidth(1);
1043 band->Draw("3 same");
1044 band->DrawClone("X L same");
1046 // Replot the ratios on top
1047 fRatios->DrawClone("nostack e1 same");
1050 fRangeParam->fMasterAxis = FindXAxis(p2, fRatios->GetName());
1051 p2->AddExec("range", Form("RangeExec((dNdetaDrawer::RangeParam*)%p)",
1055 fRangeParam->fSlave2Axis = FindXAxis(p2, fRatios->GetName());
1056 fRangeParam->fSlave2Pad = p2;
1059 //__________________________________________________________________
1061 * Plot the asymmetries
1063 * @param max Maximum diviation from 1
1064 * @param y1 Lower y coordinate of pad
1065 * @param y2 Upper y coordinate of pad
1067 void PlotLeftRight(Double_t max, Double_t y1, Double_t y2)
1069 if (!fShowLeftRight) return;
1071 bool isBottom = (y1 < 0.0001);
1072 Double_t yd = y2 - y1;
1073 // Make a sub-pad for the result itself
1074 TPad* p3 = new TPad("p3", "p3", 0, y1, 1.0, y2, 0, 0, 0);
1075 p3->SetTopMargin(0.001);
1076 p3->SetRightMargin(0.03);
1077 p3->SetBottomMargin(isBottom ? 1/yd * 0.07 : 0.0001);
1085 FixAxis(fLeftRight, yd, "Right/Left", 4);
1087 fLeftRight->SetMaximum(1+TMath::Max(.12,1.05*max));
1088 fLeftRight->SetMinimum(1-TMath::Max(.15,1.05*max));
1090 fLeftRight->DrawClone("nostack e1");
1094 Double_t xx1 = (fCentAxis ? .7 : .15);
1095 Double_t xx2 = (fCentAxis ? 1-p3->GetRightMargin()-.01 : .90);
1096 Double_t yy1 = p3->GetBottomMargin()+.01;
1097 Double_t yy2 = (fCentAxis ? 1-p3->GetTopMargin()-.01-.15 : .5);
1098 BuildLegend(fLeftRight, 0, xx1, yy1, xx2, yy2);
1099 // TLegend* l2 = p3->BuildLegend(.15,p3->GetBottomMargin()+.01,.9,.5);
1100 // l2->SetNColumns(2);
1101 // l2->SetFillColor(0);
1102 // l2->SetFillStyle(0);
1103 // l2->SetBorderSize(0);
1104 // l2->SetTextFont(132);
1106 // Make a nice band from 0.9 to 1.1
1107 TGraphErrors* band = new TGraphErrors(2);
1108 band->SetPoint(0, fResults->GetXaxis()->GetXmin(), 1);
1109 band->SetPoint(1, fResults->GetXaxis()->GetXmax(), 1);
1110 band->SetPointError(0, 0, .05);
1111 band->SetPointError(1, 0, .05);
1112 band->SetFillColor(kYellow+2);
1113 band->SetFillStyle(3002);
1114 band->SetLineStyle(2);
1115 band->SetLineWidth(1);
1116 band->Draw("3 same");
1117 band->DrawClone("X L same");
1119 fLeftRight->DrawClone("nostack e1 same");
1121 fRangeParam->fMasterAxis = FindXAxis(p3, fLeftRight->GetName());
1122 p3->AddExec("range", Form("RangeExec((dNdetaDrawer::RangeParam*)%p)",
1126 fRangeParam->fSlave2Axis = FindXAxis(p3, fLeftRight->GetName());
1127 fRangeParam->fSlave2Pad = p3;
1131 //==================================================================
1134 * @name Data utility functions
1137 * Get a result from the passed list
1139 * @param list List to search
1140 * @param name Object name to search for
1144 TH1* FetchResult(const TList* list, const char* name) const
1146 if (!list) return 0;
1148 TH1* ret = static_cast<TH1*>(list->FindObject(name));
1152 Warning("GetResult", "Histogram %s not found", name);
1158 //__________________________________________________________________
1160 * Add a histogram to the stack after possibly rebinning it
1162 * @param stack Stack to add to
1163 * @param hist histogram
1164 * @param option Draw options
1166 * @return Maximum of histogram
1168 Double_t AddHistogram(THStack* stack, TH1* hist, Option_t* option="") const
1170 // Check if we have input
1171 if (!hist) return 0;
1176 stack->Add(hist, option);
1177 return hist->GetMaximum();
1179 //__________________________________________________________________
1181 * Add a histogram to the stack after possibly rebinning it
1183 * @param stack Stack to add to
1184 * @param hist histogram
1185 * @param option Draw options
1186 * @param sym On return, the data symmetriced (added to stack)
1188 * @return Maximum of histogram
1190 Double_t AddHistogram(THStack* stack, TH1* hist, TH1*& sym,
1191 Option_t* option="") const
1193 // Check if we have input
1194 if (!hist) return 0;
1198 stack->Add(hist, option);
1200 // Now symmetrice the histogram
1201 sym = Symmetrice(hist);
1202 stack->Add(sym, option);
1204 return hist->GetMaximum();
1207 //__________________________________________________________________
1211 * @param h Histogram to rebin
1215 virtual void Rebin(TH1* h) const
1217 if (fRebin <= 1) return;
1219 Int_t nBins = h->GetNbinsX();
1220 if(nBins % fRebin != 0) {
1221 Warning("Rebin", "Rebin factor %d is not a devisor of current number "
1222 "of bins %d in the histogram %s", fRebin, nBins, h->GetName());
1227 TH1* tmp = static_cast<TH1*>(h->Clone("tmp"));
1229 tmp->SetDirectory(0);
1231 // The new number of bins
1232 Int_t nBinsNew = nBins / fRebin;
1233 for(Int_t i = 1;i<= nBinsNew; i++) {
1234 Double_t content = 0;
1238 for(Int_t j = 1; j<=fRebin;j++) {
1239 Int_t bin = (i-1)*fRebin + j;
1240 Double_t c = h->GetBinContent(bin);
1242 if (c <= 0) continue;
1245 if (h->GetBinContent(bin+1)<=0 ||
1246 h->GetBinContent(bin-1)) {
1247 Warning("Rebin", "removing bin %d=%f of %s (%d=%f,%d=%f)",
1248 bin, c, h->GetName(),
1249 bin+1, h->GetBinContent(bin+1),
1250 bin-1, h->GetBinContent(bin-1));
1254 Double_t e = h->GetBinError(bin);
1255 Double_t w = 1 / (e*e); // 1/c/c
1262 if(content > 0 && nbins > 1 ) {
1263 tmp->SetBinContent(i, wsum / sumw);
1264 tmp->SetBinError(i,1./TMath::Sqrt(sumw));
1268 // Finally, rebin the histogram, and set new content
1271 for(Int_t i = 1; i<= nBinsNew; i++) {
1272 h->SetBinContent(i,tmp->GetBinContent(i));
1273 h->SetBinError(i, tmp->GetBinError(i));
1278 //__________________________________________________________________
1280 * Make an extension of @a h to make it symmetric about 0
1282 * @param h Histogram to symmertrice
1284 * @return Symmetric extension of @a h
1286 TH1* Symmetrice(const TH1* h) const
1288 Int_t nBins = h->GetNbinsX();
1289 TH1* s = static_cast<TH1*>(h->Clone(Form("%s_mirror", h->GetName())));
1290 s->SetTitle(Form("%s (mirrored)", h->GetTitle()));
1292 s->SetBins(nBins, -h->GetXaxis()->GetXmax(), -h->GetXaxis()->GetXmin());
1293 s->SetMarkerColor(h->GetMarkerColor());
1294 s->SetMarkerSize(h->GetMarkerSize());
1295 s->SetMarkerStyle(h->GetMarkerStyle()+4);
1296 s->SetFillColor(h->GetFillColor());
1297 s->SetFillStyle(h->GetFillStyle());
1300 // Find the first and last bin with data
1301 Int_t first = nBins+1;
1303 for (Int_t i = 1; i <= nBins; i++) {
1304 if (h->GetBinContent(i) <= 0) continue;
1305 first = TMath::Min(first, i);
1306 last = TMath::Max(last, i);
1309 Double_t xfirst = h->GetBinCenter(first-1);
1310 Int_t f1 = h->GetXaxis()->FindBin(-xfirst);
1311 Int_t l2 = s->GetXaxis()->FindBin(xfirst);
1312 for (Int_t i = f1, j=l2; i <= last; i++,j--) {
1313 s->SetBinContent(j, h->GetBinContent(i));
1314 s->SetBinError(j, h->GetBinError(i));
1316 // Fill in overlap bin
1317 s->SetBinContent(l2+1, h->GetBinContent(first));
1318 s->SetBinError(l2+1, h->GetBinError(first));
1321 //__________________________________________________________________
1323 * Calculate the left-right asymmetry of input histogram
1325 * @param h Input histogram
1326 * @param max On return, the maximum distance from 1 of the histogram
1330 TH1* Asymmetry(TH1* h, Double_t& max)
1334 TH1* ret = static_cast<TH1*>(h->Clone(Form("%s_leftright", h->GetName())));
1335 // Int_t oBins = h->GetNbinsX();
1336 // Double_t high = h->GetXaxis()->GetXmax();
1337 // Double_t low = h->GetXaxis()->GetXmin();
1338 // Double_t dBin = (high - low) / oBins;
1339 // Int_t tBins = Int_t(2*high/dBin+.5);
1340 // ret->SetBins(tBins, -high, high);
1341 ret->SetDirectory(0);
1343 ret->SetTitle(Form("%s (+/-)", h->GetTitle()));
1344 ret->SetYTitle("Right/Left");
1345 Int_t nBins = h->GetNbinsX();
1346 for (Int_t i = 1; i <= nBins; i++) {
1347 Double_t x = h->GetBinCenter(i);
1350 Double_t c1 = h->GetBinContent(i);
1351 Double_t e1 = h->GetBinError(i);
1352 if (c1 <= 0) continue;
1354 Int_t j = h->FindBin(-x);
1355 if (j <= 0 || j > nBins) continue;
1357 Double_t c2 = h->GetBinContent(j);
1358 Double_t e2 = h->GetBinError(j);
1360 Double_t c12 = c1*c1;
1361 Double_t e = TMath::Sqrt((e2*e2*c1*c1+e1*e1*c2*c2)/(c12*c12));
1363 Int_t k = ret->FindBin(x);
1364 ret->SetBinContent(k, c2/c1);
1365 ret->SetBinError(k, e);
1367 max = TMath::Max(max, RatioMax(ret));
1371 //__________________________________________________________________
1373 * Transform a graph into a histogram
1379 TH1* Graph2Hist(const TGraphAsymmErrors* g) const
1381 Int_t nBins = g->GetN();
1382 TArrayF bins(nBins+1);
1384 for (Int_t i = 0; i < nBins; i++) {
1385 Double_t x = g->GetX()[i];
1386 Double_t exl = g->GetEXlow()[i];
1387 Double_t exh = g->GetEXhigh()[i];
1388 bins.fArray[i] = x-exl;
1389 bins.fArray[i+1] = x+exh;
1390 Double_t dxi = exh+exl;
1391 if (i == 0) dx = dxi;
1392 else if (dxi != dx) dx = 0;
1394 TString name(g->GetName());
1395 TString title(g->GetTitle());
1398 h = new TH1D(name.Data(), title.Data(), nBins, bins[0], bins[nBins]);
1401 h = new TH1D(name.Data(), title.Data(), nBins, bins.fArray);
1403 h->SetMarkerStyle(g->GetMarkerStyle());
1404 h->SetMarkerColor(g->GetMarkerColor());
1405 h->SetMarkerSize(g->GetMarkerSize());
1410 //==================================================================
1413 * @name Ratio utility functions
1416 * Get the maximum diviation from 1 in the passed ratio
1418 * @param h Ratio histogram
1420 * @return Max diviation from 1
1422 Double_t RatioMax(TH1* h) const
1424 Int_t nBins = h->GetNbinsX();
1426 for (Int_t i = 1; i <= nBins; i++) {
1427 Double_t c = h->GetBinContent(i);
1428 if (c == 0) continue;
1429 Double_t e = h->GetBinError(i);
1430 Double_t d = TMath::Abs(1-c-e);
1431 ret = TMath::Max(d, ret);
1435 //__________________________________________________________________
1437 * Make the ratio of h1 to h2
1439 * @param o1 First object (numerator)
1440 * @param o2 Second object (denominator)
1441 * @param max Maximum diviation from 1
1445 TH1* Ratio(const TObject* o1, const TObject* o2, Double_t& max) const
1447 if (!o1 || !o2) return 0;
1450 const TAttMarker* m1 = 0;
1451 const TAttMarker* m2 = 0;
1452 const TH1* h1 = dynamic_cast<const TH1*>(o1);
1455 const TH1* h2 = dynamic_cast<const TH1*>(o2);
1461 const TGraph* g2 = dynamic_cast<const TGraph*>(o2);
1469 const TGraphAsymmErrors* g1 = dynamic_cast<const TGraphAsymmErrors*>(o1);
1472 const TGraphAsymmErrors* g2 =
1473 dynamic_cast<const TGraphAsymmErrors*>(o2);
1476 r = RatioGG(g1, g2);
1481 Warning("Ratio", "Don't know how to divide a %s (%s) with a %s (%s)",
1482 o1->ClassName(), o1->GetName(), o2->ClassName(), o2->GetName());
1485 // Check that the histogram isn't empty
1486 if (r->GetEntries() <= 0) {
1491 r->SetMarkerStyle(m2->GetMarkerStyle());
1492 r->SetMarkerColor(m1->GetMarkerColor());
1493 r->SetMarkerSize(0.9*m1->GetMarkerSize());
1494 r->SetName(Form("%s_over_%s", o1->GetName(), o2->GetName()));
1495 r->SetTitle(Form("%s / %s", o1->GetTitle(), o2->GetTitle()));
1497 max = TMath::Max(RatioMax(r), max);
1502 //__________________________________________________________________
1504 * Compute the ratio of @a h to @a g. @a g is evaluated at the bin
1507 * @param h Numerator
1512 TH1* RatioHG(const TH1* h, const TGraph* g) const
1514 if (!h || !g) return 0;
1516 TH1* ret = static_cast<TH1*>(h->Clone("tmp"));
1518 Double_t xlow = g->GetX()[0];
1519 Double_t xhigh = g->GetX()[g->GetN()-1];
1520 if (xlow > xhigh) { Double_t t = xhigh; xhigh = xlow; xlow = t; }
1522 for (Int_t i = 1; i <= h->GetNbinsX(); i++) {
1523 Double_t c = h->GetBinContent(i);
1524 if (c <= 0) continue;
1526 Double_t x = h->GetBinCenter(i);
1527 if (x < xlow || x > xhigh) continue;
1529 Double_t f = g->Eval(x);
1530 if (f <= 0) continue;
1532 ret->SetBinContent(i, c / f);
1533 ret->SetBinError(i, h->GetBinError(i) / f);
1537 //__________________________________________________________________
1539 * Make the ratio of h1 to h2
1541 * @param h1 First histogram (numerator)
1542 * @param h2 Second histogram (denominator)
1546 TH1* RatioHH(const TH1* h1, const TH1* h2) const
1548 if (!h1 || !h2) return 0;
1549 TH1* t1 = static_cast<TH1*>(h1->Clone("tmp"));
1553 //__________________________________________________________________
1555 * Calculate the ratio of two graphs - g1 / g2
1557 * @param g1 Numerator
1558 * @param g2 Denominator
1560 * @return g1 / g2 in a histogram
1562 TH1* RatioGG(const TGraphAsymmErrors* g1,
1563 const TGraphAsymmErrors* g2) const
1565 Int_t nBins = g1->GetN();
1566 TArrayF bins(nBins+1);
1568 for (Int_t i = 0; i < nBins; i++) {
1569 Double_t x = g1->GetX()[i];
1570 Double_t exl = g1->GetEXlow()[i];
1571 Double_t exh = g1->GetEXhigh()[i];
1572 bins.fArray[i] = x-exl;
1573 bins.fArray[i+1] = x+exh;
1574 Double_t dxi = exh+exl;
1575 if (i == 0) dx = dxi;
1576 else if (dxi != dx) dx = 0;
1580 h = new TH1F("tmp", "tmp", nBins, bins[0], bins[nBins]);
1583 h = new TH1F("tmp", "tmp", nBins, bins.fArray);
1586 Double_t low = g2->GetX()[0];
1587 Double_t high = g2->GetX()[g2->GetN()-1];
1588 if (low > high) { Double_t t = low; low = high; high = t; }
1589 for (Int_t i = 0; i < nBins; i++) {
1590 Double_t x = g1->GetX()[i];
1591 if (x < low-dx || x > high+dx) continue;
1592 Double_t c1 = g1->GetY()[i];
1593 Double_t e1 = g1->GetErrorY(i);
1594 Double_t c2 = g2->Eval(x);
1596 h->SetBinContent(i+1, c1 / c2);
1597 h->SetBinError(i+1, e1 / c2);
1602 //==================================================================
1605 * @name Graphics utility functions
1608 * Find an X axis in a pad
1611 * @param name Histogram to find axis for
1613 * @return Found axis or null
1615 TAxis* FindXAxis(TVirtualPad* p, const char* name)
1617 TObject* o = p->GetListOfPrimitives()->FindObject(name);
1619 Warning("FindXAxis", "%s not found in pad", name);
1622 THStack* stack = dynamic_cast<THStack*>(o);
1624 Warning("FindXAxis", "%s is not a THStack", name);
1627 if (!stack->GetHistogram()) {
1628 Warning("FindXAxis", "%s has no histogram", name);
1631 TAxis* ret = stack->GetHistogram()->GetXaxis();
1635 //__________________________________________________________________
1637 * Fix the apperance of the axis in a stack
1639 * @param stack stack of histogram
1640 * @param s Scaling factor
1641 * @param ytitle Y axis title
1642 * @param force Whether to draw the stack first or not
1643 * @param ynDiv Divisions on Y axis
1645 void FixAxis(THStack* stack, Double_t yd, const char* ytitle,
1646 Int_t ynDiv=210, Bool_t force=true)
1649 Warning("FixAxis", "No stack passed for %s!", ytitle);
1652 if (force) stack->Draw("nostack e1");
1654 TH1* h = stack->GetHistogram();
1656 Warning("FixAxis", "Stack %s has no histogram", stack->GetName());
1659 Double_t s = 1/yd/1.2;
1660 // Info("FixAxis", "for %s, s=1/%f=%f", stack->GetName(), yd, s);
1662 h->SetXTitle("#font[152]{#eta}");
1663 h->SetYTitle(ytitle);
1664 TAxis* xa = h->GetXaxis();
1665 TAxis* ya = h->GetYaxis();
1667 // Int_t npixels = 20
1668 // Float_t dy = gPad->AbsPixeltoY(0) - gPad->AbsPixeltoY(npixels);
1669 // Float_t ts = dy/(gPad->GetY2() - gPad->GetY1());
1672 // xa->SetTitle(h->GetXTitle());
1673 // xa->SetTicks("+-");
1674 xa->SetTitleSize(s*xa->GetTitleSize());
1675 xa->SetLabelSize(s*xa->GetLabelSize());
1676 xa->SetTickLength(s*xa->GetTickLength());
1677 // xa->SetTitleOffset(xa->GetTitleOffset()/s);
1679 if (stack != fResults) {
1680 TAxis* rxa = fResults->GetXaxis();
1681 xa->Set(rxa->GetNbins(), rxa->GetXmin(), rxa->GetXmax());
1685 // ya->SetTitle(h->GetYTitle());
1687 // ya->SetTicks("+-");
1688 ya->SetNdivisions(ynDiv);
1689 ya->SetTitleSize(s*ya->GetTitleSize());
1690 ya->SetTitleOffset(ya->GetTitleOffset()/s);
1691 ya->SetLabelSize(s*ya->GetLabelSize());
1694 //__________________________________________________________________
1696 * Merge two histograms into one
1698 * @param cen Central part
1699 * @param fwd Forward part
1700 * @param xlow On return, lower eta bound
1701 * @param xhigh On return, upper eta bound
1703 * @return Newly allocated histogram or null
1706 Merge(const TH1* cen, const TH1* fwd, Double_t& xlow, Double_t& xhigh)
1708 TH1* tmp = static_cast<TH1*>(fwd->Clone("tmp"));
1709 TString name(fwd->GetName());
1710 name.ReplaceAll("Forward", "Merged");
1713 // tmp->SetMarkerStyle(28);
1714 // tmp->SetMarkerColor(kBlack);
1715 tmp->SetDirectory(0);
1718 for (Int_t i = 1; i <= tmp->GetNbinsX(); i++) {
1719 Double_t cc = cen->GetBinContent(i);
1720 Double_t cf = fwd->GetBinContent(i);
1721 Double_t ec = cen->GetBinError(i);
1722 Double_t ef = fwd->GetBinError(i);
1725 if (cc < 0.001 && cf < 0.01) continue;
1726 xlow = TMath::Min(tmp->GetXaxis()->GetBinLowEdge(i),xlow);
1727 xhigh = TMath::Max(tmp->GetXaxis()->GetBinUpEdge(i),xhigh);
1733 ne = TMath::Sqrt(ec*ec + ef*ef);
1736 tmp->SetBinContent(i, nc);
1737 tmp->SetBinError(i, ne);
1741 //____________________________________________________________________
1743 * Fit @f$g(x;A_1,A_2,\sigma_1,\sigma_2)@f$ to histogram data
1745 * @param tmp Histogram
1746 * @param xlow Lower x bound
1747 * @param xhigh Upper x bound
1749 * @return Fitted function
1752 FitMerged(TH1* tmp, Double_t xlow, Double_t xhigh)
1754 TF1* tmpf = new TF1("tmpf", "gaus", xlow, xhigh);
1755 tmp->Fit(tmpf, "NQ", "");
1756 tmp->SetDirectory(0);
1758 TF1* fit = new TF1("f", myFunc, xlow, xhigh, 4);
1759 fit->SetParNames("a_{1}", "a_{2}", "#sigma_{1}", "#sigma_{2}");
1760 fit->SetParameters(tmpf->GetParameter(0),
1762 tmpf->GetParameter(2),
1763 tmpf->GetParameter(2)/4);
1764 fit->SetParLimits(3, 0, 100);
1765 fit->SetParLimits(4, 0, 100);
1766 tmp->Fit(fit,"0W","");
1771 //____________________________________________________________________
1773 * Make band of systematic errors
1775 * @param tmp Histogram
1779 MakeSysError(TH1* tmp, TH1* cen, TH1* fwd, TF1* fit)
1781 for (Int_t i = 1; i <= tmp->GetNbinsX(); i++) {
1782 Double_t tc = tmp->GetBinContent(i);
1783 if (tc < 0.01) continue;
1784 Double_t fc = fwd->GetBinContent(i);
1785 Double_t cc = cen->GetBinContent(i);
1786 Double_t sysErr = fFwdSysErr;
1787 if (cc > .01 && fc > 0.01)
1788 sysErr = (fFwdSysErr+fCenSysErr) / 2;
1790 sysErr = fCenSysErr;
1791 Double_t x = tmp->GetXaxis()->GetBinCenter(i);
1792 Double_t y = fit->Eval(x);
1793 tmp->SetBinContent(i, y);
1794 tmp->SetBinError(i,sysErr*y);
1796 TString name(tmp->GetName());
1797 name.ReplaceAll("Merged", "SysError");
1799 tmp->SetMarkerColor(SYSERR_COLOR);
1800 tmp->SetLineColor(SYSERR_COLOR);
1801 tmp->SetFillColor(SYSERR_COLOR);
1802 tmp->SetFillStyle(SYSERR_STYLE);
1803 tmp->SetMarkerStyle(0);
1804 tmp->SetLineWidth(0);
1806 void CorrectForward(TH1* h) const
1808 if (!fRemoveOuters) return;
1810 for (Int_t i = 1; i <= h->GetNbinsX(); i++) {
1811 Double_t eta = h->GetBinCenter(i);
1812 if (TMath::Abs(eta) < 2.3) {
1813 h->SetBinContent(i, 0);
1814 h->SetBinError(i, 0);
1818 void CorrectCentral(TH1* h) const
1820 if (fClusterScale.IsNull()) return;
1821 TString t(h->GetTitle());
1822 Info("CorrectCentral", "Replacing Central with Tracklets in %s", t.Data());
1823 t.ReplaceAll("Central", "Tracklets");
1826 TF1* cf = new TF1("clusterScale", fClusterScale);
1827 for (Int_t i = 1; i <= h->GetNbinsX(); i++) {
1828 Double_t eta = h->GetBinCenter(i);
1829 Double_t f = cf->Eval(eta);
1830 Double_t c = h->GetBinContent(i);
1832 h->SetBinContent(i, c / f);
1836 //____________________________________________________________________
1837 void Export(const char* basename)
1839 TString bname(basename);
1840 bname.ReplaceAll(" ", "_");
1841 bname.ReplaceAll("-", "_");
1842 TString fname(Form("%s.C", bname.Data()));
1844 std::ofstream out(fname.Data());
1846 Error("Export", "Failed to open output file %s", fname.Data());
1849 out << "// Create by dNdetaDrawer\n"
1850 << "void " << bname << "(THStack* stack, TLegend* l, Int_t m)\n"
1852 << " Int_t ma[] = { 24, 25, 26, 32,\n"
1853 << " 20, 21, 22, 33,\n"
1854 << " 34, 30, 29, 0, \n"
1856 << " Int_t mm = ((m < 20 || m > 34) ? 0 : ma[m-20]);\n\n";
1857 TList* hists = fResults->GetHists();
1860 while ((hist = static_cast<TH1*>(next()))) {
1861 TString hname = hist->GetName();
1862 hname.Append(Form("_%04x", (gRandom->Integer(0xffff) & 0xffff)));
1863 hist->SetName(hname);
1864 hist->GetListOfFunctions()->Clear();
1865 hist->SavePrimitive(out, "nodraw");
1866 bool mirror = hname.Contains("mirror");
1867 bool syserr = hname.Contains("SysError");
1869 out << " " << hname << "->SetMarkerStyle("
1870 << (mirror ? "mm" : "m") << ");\n";
1872 out << " " << hname << "->SetMarkerStyle(1);\n";
1873 out << " stack->Add(" << hname
1874 << (syserr ? ",\"e5\"" : "") << ");\n\n";
1876 UShort_t snn = fSNNString->GetUniqueID();
1877 // const char* sys = fSysString->GetTitle();
1879 if (snn == 2750) snn = 2760;
1880 if (snn < 1000) eS = Form("%3dGeV", snn);
1881 else if (snn % 1000 == 0) eS = Form("%dTeV", snn/1000);
1882 else eS = Form("%4.2fTeV", float(snn)/1000);
1883 out << " if (l) {\n"
1884 << " TLegendEntry* e = l->AddEntry(\"\",\"" << eS << "\",\"pl\");\n"
1885 << " e->SetMarkerStyle(m);\n"
1886 << " e->SetMarkerColor(kBlack);\n"
1888 << "}\n" << std::endl;
1895 //__________________________________________________________________
1900 Bool_t fShowRatios; // Show ratios
1901 Bool_t fShowLeftRight;// Show asymmetry
1902 Bool_t fShowRings; // Show rings too
1903 Bool_t fExport; // Export results to file
1904 Bool_t fCutEdges; // Whether to cut edges
1905 Bool_t fRemoveOuters; // Whether to remove outers
1906 UShort_t fShowOthers; // Show other data
1912 UShort_t fRebin; // Rebinning factor
1913 Double_t fFwdSysErr; // Systematic error in forward range
1914 Double_t fCenSysErr; // Systematic error in central range
1915 TString fTitle; // Title on plot
1916 TString fClusterScale; // Scaling of clusters to tracklets
1920 * @name Read (or set) information
1922 TNamed* fTrigString; // Trigger string (read, or set)
1923 TNamed* fNormString; // Normalisation string (read, or set)
1924 TNamed* fSNNString; // Energy string (read, or set)
1925 TNamed* fSysString; // Collision system string (read or set)
1926 TAxis* fVtxAxis; // Vertex cuts (read or set)
1927 TAxis* fCentAxis; // Centrality axis
1931 * @name Resulting plots
1933 THStack* fResults; // Stack of results
1934 THStack* fRatios; // Stack of ratios
1935 THStack* fLeftRight; // Left-right asymmetry
1936 TMultiGraph* fOthers; // Older data
1937 TH1* fTriggers; // Number of triggers
1938 TH1* fTruth; // Pointer to truth
1940 RangeParam* fRangeParam; // Parameter object for range zoom
1943 //____________________________________________________________________
1945 * Function to calculate
1947 * g(x;A_1,A_2,\sigma_1,\sigma_2) =
1948 * A_1\left(\frac{1}{2\pi\sigma_1}e^{(x/\sigma_1)^2} -
1949 * A_2\frac{1}{2\pi\sigma_2}e^{(x/\sigma_2)^2}\right)
1952 * @param xp Pointer to x array
1953 * @param pp Pointer to parameter array
1955 * @return @f$g(x;A_1,A_2,\sigma_1,\sigma_2)@f$
1957 Double_t myFunc(Double_t* xp, Double_t* pp)
1960 Double_t a1 = pp[0];
1961 Double_t a2 = pp[1];
1962 Double_t s1 = pp[2];
1963 Double_t s2 = pp[3];
1964 return a1*(TMath::Gaus(x, 0, s1) - a2 * TMath::Gaus(x, 0, s2));
1967 //=== Stuff for auto zooming =========================================
1968 void UpdateRange(dNdetaDrawer::RangeParam* p)
1971 Warning("UpdateRange", "No parameters %p", p);
1974 if (!p->fMasterAxis) {
1975 Warning("UpdateRange", "No master axis %p", p->fMasterAxis);
1978 Int_t first = p->fMasterAxis->GetFirst();
1979 Int_t last = p->fMasterAxis->GetLast();
1980 Double_t x1 = p->fMasterAxis->GetBinCenter(first);
1981 Double_t x2 = p->fMasterAxis->GetBinCenter(last);
1983 if (p->fSlave1Axis) {
1984 Int_t i1 = p->fSlave1Axis->FindBin(x1);
1985 Int_t i2 = p->fSlave1Axis->FindBin(x2);
1986 p->fSlave1Axis->SetRange(i1, i2);
1987 p->fSlave1Pad->Modified();
1988 p->fSlave1Pad->Update();
1990 if (p->fSlave2Axis) {
1991 Int_t i1 = p->fSlave2Axis->FindBin(x1);
1992 Int_t i2 = p->fSlave2Axis->FindBin(x2);
1993 p->fSlave2Axis->SetRange(i1, i2);
1994 p->fSlave2Pad->Modified();
1995 p->fSlave2Pad->Update();
1997 TCanvas* c = gPad->GetCanvas();
2001 //____________________________________________________________________
2002 void RangeExec(dNdetaDrawer::RangeParam* p)
2009 // 11: Mouse release
2010 // dNdetaDrawer::RangeParam* p =
2011 // reinterpret_cast<dNdetaDrawer::RangeParam*>(addr);
2012 Int_t event = gPad->GetEvent();
2013 TObject *select = gPad->GetSelected();
2018 if (event != 11 || !select || select != p->fMasterAxis) return;
2022 //=== Steering functions
2023 //==============================================
2027 Info("DrawdNdeta", "Usage: DrawdNdeta(FILE,TITLE,REBIN,OTHERS,FLAGS)\n\n"
2028 " const char* FILE File name to open (\"forward_root\")\n"
2029 " const char* TITLE Title to put on plot (\"\")\n"
2030 " UShort_t REBIN Rebinning factor (1)\n"
2031 " UShort_t OTHERS Other data to draw - more below (0x7)\n"
2032 " UShort_t FLAGS Visualisation flags - more below (0x7)\n\n"
2033 " OTHERS is a bit mask of\n\n"
2034 " 0x1 Show UA5 data (INEL,NSD, ppbar, 900GeV)\n"
2035 " 0x2 Show CMS data (NSD, pp)\n"
2036 " 0x4 Show published ALICE data (INEL,INEL>0,NSD, pp)\n"
2037 " 0x8 Show event genertor data\n\n"
2038 " FLAGS is a bit mask of\n\n"
2039 " 0x1 Show ratios of data to other data and possibly MC\n"
2040 " 0x2 Show left-right asymmetry\n"
2041 " 0x4 Show systematic error band\n"
2042 " 0x8 Show individual ring results (INEL only)\n"
2043 " 0x10 Cut edges when rebinning\n"
2044 " 0x20 Remove FMDxO points\n"
2045 " 0x40 Do not make our own canvas\n"
2049 //____________________________________________________________________
2051 * Draw @f$ dN/d\eta@f$
2053 * @param filename File name
2054 * @param flags Flags
2055 * @param title Title
2056 * @param rebin Rebinning factor
2057 * @param cutEdges Whether to cut edges when rebinning
2058 * @param sNN (optional) Collision energy [GeV]
2059 * @param sys (optional) Collision system (1: pp, 2: PbPb)
2060 * @param trg (optional) Trigger (1: INEL, 2: INEL>0, 4: NSD)
2061 * @param vzMin Least @f$ v_z@f$
2062 * @param vzMax Largest @f$ v_z@f$
2064 * @ingroup pwg2_forward_dndeta
2067 DrawdNdeta(const char* filename="forward_dndeta.root",
2068 const char* title="",
2070 UShort_t others=0x7,
2078 TString fname(filename);
2080 if (fname.CompareTo("help") == 0 ||
2081 fname.CompareTo("--help") == 0) {
2085 dNdetaDrawer* pd = new dNdetaDrawer;
2086 dNdetaDrawer& d = *pd;
2089 d.SetShowOthers(others);
2090 d.SetShowRatios(flags & 0x1);
2091 d.SetShowLeftRight(flags & 0x2);
2092 d.SetForwardSysError(flags & 0x4 ? 0.076 : 0);
2093 d.SetShowRings(flags & 0x8);
2094 d.SetCutEdges(flags & 0x10);
2095 d.fRemoveOuters = (flags & 0x20);
2096 d.SetExport(flags & 0x40);
2097 // d.fClusterScale = "1.06 -0.003*x +0.0119*x*x";
2098 // Do the below if your input data does not contain these settings
2099 if (sNN > 0) d.SetSNN(sNN); // Collision energy per nucleon pair (GeV)
2100 if (sys > 0) d.SetSys(sys); // Collision system (1:pp, 2:PbPB)
2101 if (trg > 0) d.SetTrigger(trg); // Collision trigger (1:INEL, 2:INEL>0, 4:NSD)
2102 if (vzMin < 999 && vzMax > -999)
2103 d.SetVertexRange(vzMin,vzMax); // Collision vertex range (cm)
2106 //____________________________________________________________________