8 # include <TLegendEntry.h>
21 * A simple script to draw results from MakedNdeta.C (or similar)
25 * Get a stack from the passed list
27 * @param list List to get the stack from
28 * @param name Name of stack
29 * @param rebin Optional rebinning - must exists in list
31 * @return Stack or null
34 GetStack(const TList* list, const char* name, Int_t rebin)
37 Warning("GetStack", "List is null");
42 if (rebin > 1) n.Append(Form("_rebin%02d", rebin));
43 TObject* o = list->FindObject(n);
45 Warning("GetStack", "No %s object found in %s", n.Data(), list->GetName());
48 return static_cast<THStack*>(o);
52 GetHist(const TList* list, const char* name, Int_t rebin)
55 Warning("GetStack", "List is null");
58 TList* all = static_cast<TList*>(list->FindObject("all"));
60 Warning("GetHist", "List all not found in %s", list->GetName());
65 if (rebin > 1) n.Append(Form("_rebin%02d", rebin));
66 TObject* o = all->FindObject(n);
68 Warning("GetStack", "No %s object found in %s", n.Data(), all->GetName());
71 return static_cast<TH1*>(o);
75 * Add histograms from one stack to another
77 * @param p Parent stack to add to
78 * @param list List to look for the stack in
79 * @param name Name of stack to add
80 * @param rebin Optional rebinning - must exists in list
82 * @return Added stack or null
85 AddStack(THStack* p, const TList* list, const char* name, Int_t rebin)
87 THStack* s = GetStack(list, name, rebin);
90 TIter next(s->GetHists());
92 while ((hist = static_cast<TH1*>(next())))
98 * Build up a centrality legend
100 * @param c Centrality axis
103 BuildCentLegend(const TAxis* c)
106 TLegend* l = new TLegend(1.2*gPad->GetLeftMargin(),
107 .55, .35, 1-gPad->GetTopMargin());
112 l->SetHeader("Centralities");
115 Int_t nCol = gStyle->GetNumberOfColors();
116 for (Int_t i = 0; i < c->GetNbins(); i++) {
117 UShort_t low = c->GetBinLowEdge(i+1);
118 UShort_t high = c->GetBinUpEdge(i+1);
119 Float_t fc = (low+double(high-low)/2) / 100;
120 Int_t icol = TMath::Min(nCol-1,int(fc * nCol + .5));
121 Int_t col = gStyle->GetColorPalette(icol);
122 TLegendEntry* e = l->AddEntry(Form("dummy%02d", i),
123 Form("%3d%% - %3d%%", low, high), "p");
124 e->SetMarkerColor(col);
131 * Build a legend. Histograms a filtered for the same title
133 * @param stack Stack of histograms
134 * @param c Centrality axis. If present, markers are black
137 BuildLegend(const THStack* stack, const TAxis* c)
139 Double_t x1 = .75, x2 = 1-gPad->GetRightMargin();
140 Double_t y1 = .8, y2 = 1-gPad->GetTopMargin();
148 TLegend* l = new TLegend(x1, y1, x2, y2, "");
156 TIter next(stack->GetHists());
158 while ((hist = static_cast<TH1*>(next()))) {
159 TString n(hist->GetTitle());
160 if (n.Contains("mirrored")) continue;
161 if (seen.FindObject(n.Data())) continue;
162 TObjString* ns = new TObjString(n);
163 ns->SetUniqueID(((hist->GetMarkerStyle() & 0xFFFF) << 16) |
164 ((hist->GetMarkerColor() & 0xFFFF) << 0));
171 while ((s = nextu())) {
172 TLegendEntry* dd = l->AddEntry(Form("data%2d", i++),
174 Int_t style = (s->GetUniqueID() >> 16) & 0xFFFF;
175 Int_t color = (s->GetUniqueID() >> 0) & 0xFFFF;
176 dd->SetLineColor(kBlack);
177 if (c) dd->SetMarkerColor(kBlack);
178 else dd->SetMarkerColor(color);
179 dd->SetMarkerStyle(style);
180 Int_t st = dd->GetMarkerStyle();
181 if (st == 27 || st == 28 || st == 29 || st == 30 || st == 33 || st == 34)
182 dd->SetMarkerSize(1.4*dd->GetMarkerSize());
184 // TLegendEntry* sep = l->AddEntry("s", "_", "h");
185 // sep->SetTextSize(0.01);
186 TLine* sep = new TLine(0,0,1,1);
187 sep->SetLineWidth(1);
188 sep->DrawLineNDC(x1+.02, y1-.005, x2-.03, y1-.005);
191 TLegend* l2 = new TLegend(x1, y1-.005, x2, y1-.15, "");
194 l2->SetBorderSize(0);
195 l2->SetTextFont(132);
197 TLegendEntry* d1 = l2->AddEntry("d1", "Data", "p");
198 d1->SetLineColor(kBlack);
199 d1->SetMarkerColor(kBlack);
200 d1->SetMarkerStyle(20);
201 TLegendEntry* d2 = l2->AddEntry("d2", "Mirrored data", "p");
202 d2->SetLineColor(kBlack);
203 d2->SetMarkerColor(kBlack);
204 d2->SetMarkerStyle(24);
211 AddInformation(TList* forward, bool prelim=true)
217 TLatex* wip = new TLatex(x, y, "Work in progress");
219 wip->SetTextColor(TColor::GetColor(234,26,46));
220 wip->SetTextAlign(13);
221 wip->SetTextFont(132);
222 wip->SetTextSize(ts);
227 TObject* sNN = forward->FindObject("sNN");
228 TObject* sys = forward->FindObject("sys");
229 TObject* trg = forward->FindObject("trigger");
230 TObject* vtx = forward->FindObject("vtxAxis");
231 TObject* sch = forward->FindObject("scheme");
233 TString t(sys->GetTitle());
234 Bool_t isPP = t == "pp";
237 TString s = Form("%s @ #sqrt{s%s}=",
239 (isPP ? "" : "_{NN}"));
240 Int_t cms = sNN->GetUniqueID();
241 if (cms > 1000) s.Append(Form("%5.2fTeV", float(cms)/1000));
242 else s.Append(Form("%3dGeV", cms));
243 s.Append(Form(", %s", trg->GetTitle()));
245 // if (isPP) { x = .3; y = .3; }
247 x = 1-gPad->GetRightMargin()-.01;
248 y = 1-gPad->GetTopMargin()-.01;
251 TLatex* ltx = new TLatex(x, y, s.Data());
253 ltx->SetTextColor(TColor::GetColor(41,73,156));
254 ltx->SetTextAlign((isPP ? 33 : 13));
255 ltx->SetTextFont(132);
256 ltx->SetTextSize(ts);
259 ltx->DrawLatex(x, y, vtx->GetTitle());
261 ltx->DrawLatex(x, y, sch->GetTitle());
264 Double_t myFunc(Double_t* xp, Double_t* pp)
271 return a1*(TMath::Gaus(x, 0, s1) - a2 * TMath::Gaus(x, 0, s2));
275 MakeSysError(const TH1* cen, const TH1* fwd, Double_t sysErr=0.7)
277 TH1* tmp = static_cast<TH1*>(fwd->Clone("dndetaFitted"));
278 tmp->SetMarkerStyle(0);
279 tmp->SetFillColor(kGray);
280 tmp->SetFillStyle(3001);
281 tmp->SetDirectory(0);
284 for (Int_t i = 1; i <= tmp->GetNbinsX(); i++) {
285 Double_t cc = cen->GetBinContent(i);
286 Double_t cf = fwd->GetBinContent(i);
287 Double_t ec = fwd->GetBinError(i);
288 Double_t ef = fwd->GetBinError(i);
291 if (cc < 0.001 && cf < 0.01) continue;
292 xlow = TMath::Min(tmp->GetXaxis()->GetBinLowEdge(i),xlow);
293 xhigh = TMath::Max(tmp->GetXaxis()->GetBinUpEdge(i),xhigh);
299 ne = TMath::Sqrt(ec*ec + ef*ef);
302 tmp->SetBinContent(i, nc);
303 tmp->SetBinError(i, ne);
305 TF1* tmpf = new TF1("tmpf", "gaus", xlow, xhigh);
306 tmp->Fit(tmpf, "NQ", "");
308 TF1* fit = new TF1("f", myFunc, xlow, xhigh, 4);
309 fit->SetParNames("a_{1}", "a_{2}", "#sigma_{1}", "#sigma_{2}");
310 fit->SetParameters(tmpf->GetParameter(0),
312 tmpf->GetParameter(2),
313 tmpf->GetParameter(2)/4);
314 tmp->Fit(fit,"0WQ","");
315 for (Int_t i = 1; i <= tmp->GetNbinsX(); i++) {
316 Double_t tc = tmp->GetBinContent(i);
317 if (tc < 0.01) continue;
318 Double_t x = tmp->GetXaxis()->GetBinCenter(i);
319 Double_t y = fit->Eval(x);
320 tmp->SetBinContent(i, y);
321 tmp->SetBinError(i,sysErr*y);
327 * Function to draw the results from forward_dndeta.root file
329 * @param rebin Rebinnig. Note, the data must be present in the file
330 * @param filename File to open and draw stuff from >
333 SimpledNdeta(Int_t what=0x5,
334 Int_t rebin=5, const char* filename="forward_dndeta.root")
336 TFile* file = TFile::Open(filename, "READ");
338 Error("SimpledNdeta", "File %s not found", filename);
342 TList* forward = static_cast<TList*>(file->Get("ForwardResults"));
343 TList* central = static_cast<TList*>(file->Get("CentralResults"));
344 TList* mctruth = static_cast<TList*>(file->Get("MCTruthResults"));
346 THStack* all = new THStack("all", "All");
347 if (what & 0x1) AddStack(all, forward, "dndeta", rebin);
348 if (what & 0x2) AddStack(all, forward, "dndetaMC", rebin);
349 if (what & 0x1) AddStack(all, central, "dndeta", rebin);
350 if (what & 0x2) AddStack(all, central, "dndetaMC", rebin);
351 if (what & 0x4) AddStack(all, mctruth, "dndeta", rebin);
355 Double_t sysErr = 0.07;
356 TH1* fwd = GetHist(forward, "dndetaForward", rebin);
357 TH1* cen = GetHist(central, "dndetaCentral", rebin);
358 tmp = MakeSysError(cen, fwd, sysErr);
362 TAxis* centAxis = static_cast<TAxis*>(forward->FindObject("centAxis"));
363 Bool_t isPP = centAxis == 0;
365 gStyle->SetPalette(1);
366 gStyle->SetOptTitle(0);
367 TCanvas* c = new TCanvas("dndeta", "dN/deta results", 900, 600);
372 c->SetTopMargin(0.03);
373 c->SetRightMargin(0.03);
375 all->Draw("nostack");
376 TAxis* xa = all->GetHistogram()->GetXaxis();
377 xa->SetTitleFont(132);
378 xa->SetLabelFont(132);
379 xa->SetTitle("#eta");
380 TAxis* ya = all->GetHistogram()->GetYaxis();
381 ya->SetTitleFont(132);
382 ya->SetLabelFont(132);
383 ya->SetTitle("dN_{ch}/d#eta");
386 tmp->Draw("e5 same");
387 all->Draw("same nostack");
391 // if (fit) fit->Draw("same");
392 // if (tmp) tmp->Draw("same");
394 BuildCentLegend(centAxis);
395 BuildLegend(all, centAxis);
397 AddInformation(forward);
399 c->SaveAs("dndeta_simple.C");
400 c->SaveAs("dndeta_simple.png");
401 c->SaveAs("dndeta_simple.root");