AliPhysics  6bc8652 (6bc8652)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimpledNdeta.C
Go to the documentation of this file.
1 #ifndef __CINT__
2 # include <TStyle.h>
3 # include <TFile.h>
4 # include <TList.h>
5 # include <TH1.h>
6 # include <THStack.h>
7 # include <TLegend.h>
8 # include <TLegendEntry.h>
9 # include <TLatex.h>
10 # include <TLine.h>
11 # include <TString.h>
12 # include <TCanvas.h>
13 # include <TError.h>
14 # include <TColor.h>
15 #else
16 class THStack;
17 class TAxis;
18 #endif
19 
36 THStack*
37 GetStack(const TList* list, const char* name, Int_t rebin)
38 {
39  if (!list) {
40  Warning("GetStack", "List is null");
41  return 0;
42  }
43 
44  TString n(name);
45  if (rebin > 1) n.Append(Form("_rebin%02d", rebin));
46  TObject* o = list->FindObject(n);
47  if (!o) {
48  Warning("GetStack", "No %s object found in %s", n.Data(), list->GetName());
49  return 0;
50  }
51  return static_cast<THStack*>(o);
52 }
53 
65 TH1*
66 GetHist(const TList* list, const char* name, Int_t rebin)
67 {
68  if (!list) {
69  Warning("GetStack", "List is null");
70  return 0;
71  }
72  TList* all = static_cast<TList*>(list->FindObject("all"));
73  if (!all) {
74  Warning("GetHist", "List all not found in %s", list->GetName());
75  return 0;
76  }
77 
78  TString n(name);
79  if (rebin > 1) n.Append(Form("_rebin%02d", rebin));
80  TObject* o = all->FindObject(n);
81  if (!o) {
82  Warning("GetStack", "No %s object found in %s", n.Data(), all->GetName());
83  return 0;
84  }
85  return static_cast<TH1*>(o);
86 }
87 
100 THStack*
101 AddStack(THStack* p, const TList* list, const char* name, Int_t rebin)
102 {
103  THStack* s = GetStack(list, name, rebin);
104  if (!s) return 0;
105 
106  TIter next(s->GetHists());
107  TH1* hist = 0;
108  while ((hist = static_cast<TH1*>(next())))
109  p->Add(hist);
110  return s;
111 }
112 
120 void
122 {
123  if (!c) return;
124  TLegend* l = new TLegend(1.2*gPad->GetLeftMargin(),
125  .55, .35, 1-gPad->GetTopMargin());
126  l->SetFillColor(0);
127  l->SetFillStyle(0);
128  l->SetBorderSize(0);
129  l->SetTextFont(22);
130  l->SetHeader("Centralities");
131  l->SetTextFont(132);
132 
133  Int_t nCol = gStyle->GetNumberOfColors();
134  for (Int_t i = 0; i < c->GetNbins(); i++) {
135  UShort_t low = c->GetBinLowEdge(i+1);
136  UShort_t high = c->GetBinUpEdge(i+1);
137  Float_t fc = (low+double(high-low)/2) / 100;
138  Int_t icol = TMath::Min(nCol-1,int(fc * nCol + .5));
139  Int_t col = gStyle->GetColorPalette(icol);
140  TLegendEntry* e = l->AddEntry(Form("dummy%02d", i),
141  Form("%3d%% - %3d%%", low, high), "p");
142  e->SetMarkerColor(col);
143 
144  }
145  l->Draw();
146 }
147 
156 void
157 BuildLegend(const THStack* stack, const TAxis* c)
158 {
159  Double_t x1 = .75, x2 = 1-gPad->GetRightMargin();
160  Double_t y1 = .8, y2 = 1-gPad->GetTopMargin();
161  if (!c) {
162  // PP
163  x1 = .4;
164  y1 = .4;
165  x2 = .8;
166  y2 = .6;
167  }
168  TLegend* l = new TLegend(x1, y1, x2, y2, "");
169  l->SetFillColor(0);
170  l->SetFillStyle(0);
171  l->SetBorderSize(0);
172  l->SetTextFont(132);
173 
174  TObjArray seen;
175  seen.SetOwner();
176  TIter next(stack->GetHists());
177  TH1* hist = 0;
178  while ((hist = static_cast<TH1*>(next()))) {
179  TString n(hist->GetTitle());
180  if (n.Contains("mirrored")) continue;
181  if (seen.FindObject(n.Data())) continue;
182  TObjString* ns = new TObjString(n);
183  ns->SetUniqueID(((hist->GetMarkerStyle() & 0xFFFF) << 16) |
184  ((hist->GetMarkerColor() & 0xFFFF) << 0));
185  seen.Add(ns);
186  }
187  seen.Sort();
188  TIter nextu(&seen);
189  TObject* s = 0;
190  Int_t i = 0;
191  while ((s = nextu())) {
192  TLegendEntry* dd = l->AddEntry(Form("data%2d", i++),
193  s->GetName(), "p");
194  Int_t style = (s->GetUniqueID() >> 16) & 0xFFFF;
195  Int_t color = (s->GetUniqueID() >> 0) & 0xFFFF;
196  dd->SetLineColor(kBlack);
197  if (c) dd->SetMarkerColor(kBlack);
198  else dd->SetMarkerColor(color);
199  dd->SetMarkerStyle(style);
200  Int_t st = dd->GetMarkerStyle();
201  if (st == 27 || st == 28 || st == 29 || st == 30 || st == 33 || st == 34)
202  dd->SetMarkerSize(1.4*dd->GetMarkerSize());
203  }
204  // TLegendEntry* sep = l->AddEntry("s", "_", "h");
205  // sep->SetTextSize(0.01);
206  TLine* sep = new TLine(0,0,1,1);
207  sep->SetLineWidth(1);
208  sep->DrawLineNDC(x1+.02, y1-.005, x2-.03, y1-.005);
209  // sep->Draw();
210 
211  TLegend* l2 = new TLegend(x1, y1-.005, x2, y1-.15, "");
212  l2->SetFillColor(0);
213  l2->SetFillStyle(0);
214  l2->SetBorderSize(0);
215  l2->SetTextFont(132);
216 
217  TLegendEntry* d1 = l2->AddEntry("d1", "Data", "p");
218  d1->SetLineColor(kBlack);
219  d1->SetMarkerColor(kBlack);
220  d1->SetMarkerStyle(20);
221  TLegendEntry* d2 = l2->AddEntry("d2", "Mirrored data", "p");
222  d2->SetLineColor(kBlack);
223  d2->SetMarkerColor(kBlack);
224  d2->SetMarkerStyle(24);
225 
226  l->Draw();
227  l2->Draw();
228 }
229 
236 void
237 AddInformation(TList* forward, bool prelim=true)
238 {
239  Double_t x = .12;
240  Double_t y = .95;
241  Double_t ts = 0.05;
242  if (prelim) {
243  TLatex* wip = new TLatex(x, y, "Work in progress");
244  wip->SetNDC();
245  wip->SetTextColor(TColor::GetColor(234,26,46));
246  wip->SetTextAlign(13);
247  wip->SetTextFont(132);
248  wip->SetTextSize(ts);
249  wip->Draw();
250  y -= ts;
251  }
252 
253  TObject* sNN = forward->FindObject("sNN");
254  TObject* sys = forward->FindObject("sys");
255  TObject* trg = forward->FindObject("trigger");
256  TObject* vtx = forward->FindObject("vtxAxis");
257  TObject* sch = forward->FindObject("scheme");
258 
259  TString t(sys->GetTitle());
260  Bool_t isPP = t == "pp";
261 
262 
263  TString s = Form("%s @ #sqrt{s%s}=",
264  sys->GetTitle(),
265  (isPP ? "" : "_{NN}"));
266  Int_t cms = sNN->GetUniqueID();
267  if (cms > 1000) s.Append(Form("%5.2fTeV", float(cms)/1000));
268  else s.Append(Form("%3dGeV", cms));
269  s.Append(Form(", %s", trg->GetTitle()));
270 
271  // if (isPP) { x = .3; y = .3; }
272  if (isPP) {
273  x = 1-gPad->GetRightMargin()-.01;
274  y = 1-gPad->GetTopMargin()-.01;
275  ts = .04;
276  }
277  TLatex* ltx = new TLatex(x, y, s.Data());
278  ltx->SetNDC();
279  ltx->SetTextColor(TColor::GetColor(41,73,156));
280  ltx->SetTextAlign((isPP ? 33 : 13));
281  ltx->SetTextFont(132);
282  ltx->SetTextSize(ts);
283  ltx->Draw();
284  y -= ts;
285  ltx->DrawLatex(x, y, vtx->GetTitle());
286  y -= ts;
287  ltx->DrawLatex(x, y, sch->GetTitle());
288 }
289 
301 {
302  Double_t x = xp[0];
303  Double_t a1 = pp[0];
304  Double_t a2 = pp[1];
305  Double_t s1 = pp[2];
306  Double_t s2 = pp[3];
307  return a1*(TMath::Gaus(x, 0, s1) - a2 * TMath::Gaus(x, 0, s2));
308 }
309 
321 TH1*
322 MakeSysError(const TH1* cen, const TH1* fwd, Double_t sysErr=0.7)
323 {
324  TH1* tmp = static_cast<TH1*>(fwd->Clone("dndetaFitted"));
325  tmp->SetMarkerStyle(0);
326  tmp->SetFillColor(kGray);
327  tmp->SetFillStyle(3001);
328  tmp->SetDirectory(0);
329  Double_t xlow = 100;
330  Double_t xhigh = 0;
331  for (Int_t i = 1; i <= tmp->GetNbinsX(); i++) {
332  Double_t cc = cen->GetBinContent(i);
333  Double_t cf = fwd->GetBinContent(i);
334  Double_t ec = fwd->GetBinError(i);
335  Double_t ef = fwd->GetBinError(i);
336  Double_t nc = cf;
337  Double_t ne = ef;
338  if (cc < 0.001 && cf < 0.01) continue;
339  xlow = TMath::Min(tmp->GetXaxis()->GetBinLowEdge(i),xlow);
340  xhigh = TMath::Max(tmp->GetXaxis()->GetBinUpEdge(i),xhigh);
341  if (cc > 0.001) {
342  nc = cc;
343  ne = ec;
344  if (cf > 0.001) {
345  nc = (cf + cc) / 2;
346  ne = TMath::Sqrt(ec*ec + ef*ef);
347  }
348  }
349  tmp->SetBinContent(i, nc);
350  tmp->SetBinError(i, ne);
351  }
352  TF1* tmpf = new TF1("tmpf", "gaus", xlow, xhigh);
353  tmp->Fit(tmpf, "NQ", "");
354 
355  TF1* fit = new TF1("f", myFunc, xlow, xhigh, 4);
356  fit->SetParNames("a_{1}", "a_{2}", "#sigma_{1}", "#sigma_{2}");
357  fit->SetParameters(tmpf->GetParameter(0),
358  .2,
359  tmpf->GetParameter(2),
360  tmpf->GetParameter(2)/4);
361  tmp->Fit(fit,"0WQ","");
362  for (Int_t i = 1; i <= tmp->GetNbinsX(); i++) {
363  Double_t tc = tmp->GetBinContent(i);
364  if (tc < 0.01) continue;
365  Double_t x = tmp->GetXaxis()->GetBinCenter(i);
366  Double_t y = fit->Eval(x);
367  tmp->SetBinContent(i, y);
368  tmp->SetBinError(i,sysErr*y);
369  }
370  return tmp;
371 }
372 
382 void
383 SimpledNdeta(Int_t what=0x5,
384  Int_t rebin=5, const char* filename="forward_dndeta.root")
385 {
386  TFile* file = TFile::Open(filename, "READ");
387  if (!file) {
388  Error("SimpledNdeta", "File %s not found", filename);
389  return;
390  }
391 
392  TList* forward = static_cast<TList*>(file->Get("ForwardResults"));
393  TList* central = static_cast<TList*>(file->Get("CentralResults"));
394  TList* mctruth = static_cast<TList*>(file->Get("MCTruthResults"));
395 
396  THStack* all = new THStack("all", "All");
397  if (what & 0x1) AddStack(all, forward, "dndeta", rebin);
398  if (what & 0x2) AddStack(all, forward, "dndetaMC", rebin);
399  if (what & 0x1) AddStack(all, central, "dndeta", rebin);
400  if (what & 0x2) AddStack(all, central, "dndetaMC", rebin);
401  if (what & 0x4) AddStack(all, mctruth, "dndeta", rebin);
402 
403  TH1* tmp = 0;
404  if (what & 0x1) {
405  Double_t sysErr = 0.07;
406  TH1* fwd = GetHist(forward, "dndetaForward", rebin);
407  TH1* cen = GetHist(central, "dndetaCentral", rebin);
408  tmp = MakeSysError(cen, fwd, sysErr);
409  // fit = tmpf;
410  }
411 
412  TAxis* centAxis = static_cast<TAxis*>(forward->FindObject("centAxis"));
413  Bool_t isPP = centAxis == 0;
414 
415  gStyle->SetPalette(1);
416  gStyle->SetOptTitle(0);
417  TCanvas* c = new TCanvas("dndeta", "dN/deta results", 900, 600);
418  c->SetFillColor(0);
419  c->SetFillStyle(0);
420  c->SetBorderSize(0);
421  c->SetBorderMode(0);
422  c->SetTopMargin(0.03);
423  c->SetRightMargin(0.03);
424 
425  all->Draw("nostack");
426  TAxis* xa = all->GetHistogram()->GetXaxis();
427  xa->SetTitleFont(132);
428  xa->SetLabelFont(132);
429  xa->SetTitle("#eta");
430  TAxis* ya = all->GetHistogram()->GetYaxis();
431  ya->SetTitleFont(132);
432  ya->SetLabelFont(132);
433  ya->SetTitle("dN_{ch}/d#eta");
434 
435  if (tmp) {
436  tmp->Draw("e5 same");
437  all->Draw("same nostack");
438  }
439 
440 
441  // if (fit) fit->Draw("same");
442  // if (tmp) tmp->Draw("same");
443 
444  BuildCentLegend(centAxis);
445  BuildLegend(all, centAxis);
446 
447  AddInformation(forward);
448 
449  c->SaveAs("dndeta_simple.C");
450  c->SaveAs("dndeta_simple.png");
451  c->SaveAs("dndeta_simple.root");
452 }
453 //
454 // EOF
455 //
Int_t color[]
const char * filename
Definition: TestFCM.C:1
THStack * GetStack(const TList *list, const char *name, Int_t rebin)
Definition: SimpledNdeta.C:37
const Color_t cc[]
Definition: DrawKs.C:1
double Double_t
Definition: External.C:58
TList * list
TCanvas * c
Definition: TestFitELoss.C:172
TH1 * GetHist(const TList *list, const char *name, Int_t rebin)
Definition: SimpledNdeta.C:66
Double_t myFunc(Double_t *xp, Double_t *pp)
Definition: DrawdNdeta.C:3354
void BuildLegend(const THStack *stack, const TAxis *c)
Definition: SimpledNdeta.C:157
int Int_t
Definition: External.C:63
float Float_t
Definition: External.C:68
TH1 * MakeSysError(const TH1 *cen, const TH1 *fwd, Double_t sysErr=0.7)
Definition: SimpledNdeta.C:322
const char * fwd
void BuildCentLegend(const TAxis *c)
Definition: SimpledNdeta.C:121
TFile * file
Int_t rebin
unsigned short UShort_t
Definition: External.C:28
TList * ef
Definition: TestFitELoss.C:145
void SimpledNdeta(Int_t what=0x5, Int_t rebin=5, const char *filename="forward_dndeta.root")
Definition: SimpledNdeta.C:383
bool Bool_t
Definition: External.C:53
THStack * AddStack(THStack *p, const TList *list, const char *name, Int_t rebin)
Definition: SimpledNdeta.C:101
void AddInformation(TList *forward, bool prelim=true)
Definition: SimpledNdeta.C:237
Definition: External.C:196