AliPhysics  b81c3d2 (b81c3d2)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DeltaShapes.C
Go to the documentation of this file.
1 #ifndef __CINT__
2 #include "AliTrackletAODUtils.C"
3 #include <TCanvas.h>
4 #include <TLegend.h>
5 #include <TLegendEntry.h>
6 #else
7 class TCanvas;
8 class THStack;
9 class TVirtualPad;
10 class TH1;
11 #endif
12 
13 struct Computer
14 {
15 #ifndef __CINT__
17 #endif
18 
19  Computer() {}
20 
21  void Run(const char* filename, Double_t c1, Double_t c2, Bool_t mid=true)
22  {
23  Printf("Opening file %s", filename);
24  TString cntN = U::CentName(c1,c2);
25  TFile* file = U::OpenFile(filename);
26  U::Container* top = U::GetC(file, "MidRapidityMCResults");
27  U::Container* cent = U::GetC(top, cntN);
28 
29  THStack* prim = DoOne(cent, mid, "primaries");
30  THStack* seco = DoOne(cent, mid, "secondaries");
31  THStack* fake = DoOne(cent, mid, "combinatorics");
32  THStack* meas = MakeMeas(prim, seco, fake);
33  THStack* norm = Normalize(meas);
34  THStack* rati = ToOther(meas);
35 
36  prim->SetTitle("P: Primaries");
37  seco->SetTitle("S: Secondaries");
38  fake->SetTitle("C: Combinatorics");
39  meas->SetTitle("M=P+S+C: Measured");
40  norm->SetTitle("Normalized M");
41  rati->SetTitle("Ratio to total");
42  file->Close();
43 
44  Double_t yr = .93;
45  TCanvas* canvas = new TCanvas(filename,filename, 1200, 1200);
46 
47  TLegend* l = new TLegend(0.01,yr+.01,.99,.99);
48  l->SetBorderSize(0);
49  l->SetFillStyle(0);
50  l->SetNColumns(7);
51  TIter next(norm->GetHists());
52  TH1* hist = 0;
53  while ((hist = static_cast<TH1*>(next()))) {
54  TLegendEntry* e = l->AddEntry("dummy",hist->GetTitle(), "p");
55  e->SetMarkerStyle(hist->GetMarkerStyle());
56  e->SetMarkerColor(hist->GetMarkerColor());
57  e->SetMarkerSize (2*hist->GetMarkerSize());
58  }
59  canvas->cd();
60  l->Draw();
61 
62 
63  TPad* body = new TPad("body","body",0,0,1,yr);
64  canvas->cd();
65  body->Draw();
66  body->SetTopMargin(0.01);
67  body->SetRightMargin(0.01);
68  body->Divide(2,1);
69 
70  TVirtualPad* q = body->cd(1);
71  q->SetTopMargin(0.01);
72  q->SetRightMargin(0.01);
73  q->Divide(1,3,0,0);
74 
75  TVirtualPad* p = 0;
76  DrawStack(q->cd(1),prim);
77  DrawStack(q->cd(2),seco);
78  DrawStack(q->cd(3),fake);
79 
80  q = body->cd(2);
81  q->SetTopMargin(0.01);
82  q->SetRightMargin(0.01);
83  q->Divide(1,3,0,0);
84 
85  DrawStack(q->cd(1), meas);
86  DrawStack(q->cd(2), norm);
87  DrawStack(q->cd(3), rati, false, "Ratio");
88 
89  canvas->Modified();
90  canvas->Update();
91  canvas->cd();
92  TString outName(filename); outName.ReplaceAll(".root","");
93  outName.Prepend("deltaContrib");
94  // outName.Append(".png");
95  TFile* outRoot = TFile::Open(Form("%s.root", outName.Data()),"RECREATE");
96  prim->Write();
97  seco->Write();
98  fake->Write();
99  meas->Write();
100  norm->Write();
101  rati->Write();
102  outRoot->Write();
103  canvas->SaveAs(Form("%s.png",outName.Data()));
104  }
105  void DrawStack(TVirtualPad* p, THStack* hs, Bool_t logy=true,
106  const char* title="d#it{N}_{X}/d#it{#Delta}")
107  {
108  p->cd();
109  p->SetLogy(logy);
110  p->SetRightMargin(0.01);
111  p->SetTicks();
112  p->SetGridx();
113  p->SetGridy();
114  hs->Draw("nostack");
115  hs->GetHistogram()->SetXTitle("#it{#Delta}");
116  hs->GetHistogram()->SetYTitle(title);
117  hs->GetHistogram()->GetYaxis()->SetTitleSize(0.025/p->GetHNDC());
118  hs->GetHistogram()->GetXaxis()->SetTitleSize(0.025/p->GetHNDC());
119  hs->GetHistogram()->GetYaxis()->SetTitleOffset(0.6);
120  hs->GetHistogram()->GetXaxis()->SetTitleOffset(0.6);
121  hs->GetHistogram()->GetYaxis()->SetLabelSize(0.02/p->GetHNDC());
122  hs->GetHistogram()->GetXaxis()->SetLabelSize(0.02/p->GetHNDC());
123  hs->GetHistogram()->GetXaxis()->SetNdivisions(210);
124  hs->GetHistogram()->GetXaxis()->SetLimits(-1,26);
125  p->Modified();
126  }
127  THStack* DoOne(TList* c, Bool_t mid, const char* subName)
128  {
129  U::Container* sub = U::GetC(c, subName);
130  U::Container* spec = U::GetC(sub, "specie");
131  U::Container* regi = U::GetC(spec, mid ? "mid" : "fwd");
132  THStack* all = U::GetHS(regi, "all");
133  if (!all) return 0;
134 
135  TIter next(all->GetHists());
136  TH1* hist = 0;
137  TH1* k0s = 0;
138  TH1* kpm = 0;
139  TH1* lam = 0;
140  TH1* xi = 0;
141  TH1* sim = 0;
142  TH1* sip = 0;
143  TH1* tot = 0;
144  TH1* oth = 0;
145  while ((hist = static_cast<TH1*>(next()))) {
146  TString name(hist->GetName());
147  if (name.EqualTo("total")) tot = static_cast<TH1*>(hist->Clone());
148  else if (name.EqualTo("321")) kpm = static_cast<TH1*>(hist->Clone());
149  else if (name.EqualTo("310")) k0s = static_cast<TH1*>(hist->Clone());
150  else if (name.EqualTo("3122")) lam = static_cast<TH1*>(hist->Clone());
151  else if (name.EqualTo("3112")) sim = static_cast<TH1*>(hist->Clone());
152  else if (name.EqualTo("3222")) sip = static_cast<TH1*>(hist->Clone());
153  else if (name.EqualTo("3312")) xi = static_cast<TH1*>(hist->Clone());
154  else {
155  if (!oth) oth = static_cast<TH1*>(hist->Clone("0"));
156  else oth->Add(hist);
157  }
158  }
159  sim->Add(sip);
160  tot->SetMarkerStyle(25);
161  tot->SetMarkerSize(1.5);
162  oth->SetMarkerColor(kRed+1);
163  oth->SetLineColor(kRed+1);
164  oth->SetFillColor(kRed+1);
165  oth->SetMarkerStyle(20);
166  oth->SetTitle("Other");
167  oth->SetName("0");
168 #if 0
169  TString nam;
170  Color_t col;
171  Style_t sty;
172  U::PdgAttr(321, nam, col, sty); kpm->SetTitle(nam);
173  U::PdgAttr(310, nam, col, sty); k0s->SetTitle(nam);
174  U::PdgAttr(3122, nam, col, sty); lam->SetTitle(nam);
175  U::PdgAttr(3112, nam, col, sty); sim->SetTitle(nam);
176  U::PdgAttr(3312, nam, col, sty); xi ->SetTitle(nam);
177 #endif
178  THStack* ret = new THStack(subName,subName);
179  TH1* a[] = { k0s, kpm, lam, sim, xi, oth, tot };
180  for (int i = 0; i < 7; i++) {
181  if (!a[i]) continue;
182  a[i]->SetDirectory(0);
183  ret->Add(a[i]);
184  }
185  return ret;
186  }
187  TH1* FindHist(THStack* s, const char* name)
188  {
189  return U::GetH1(s->GetHists(), name, false);
190  }
191  TH1* MakeMeas(const char* name, THStack* prim, THStack* seco, THStack* fake)
192  {
193  TH1* r = 0;
194  TH1* a[] = { FindHist(prim, name),
195  FindHist(seco, name),
196  FindHist(fake, name) };
197  for (int i = 0; i < 3; i++) {
198  if (!a[i]) continue;
199  if (!r) {
200  r = static_cast<TH1*>(a[i]->Clone());
201  r->SetDirectory(0);
202  // r->Sumw2();
203  r->Reset();
204  }
205  r->Add(a[i]);
206  }
207  return r;
208  }
209  THStack* MakeMeas(THStack* prim, THStack* seco, THStack* fake)
210  {
211  THStack* ret = new THStack("measured", "measured");
212  ret->Add(MakeMeas("310", prim, seco, fake));
213  ret->Add(MakeMeas("321", prim, seco, fake));
214  ret->Add(MakeMeas("3122", prim, seco, fake));
215  ret->Add(MakeMeas("3112", prim, seco, fake));
216  ret->Add(MakeMeas("3312", prim, seco, fake));
217  ret->Add(MakeMeas("0", prim, seco, fake));
218  ret->Add(MakeMeas("total", prim, seco, fake));
219  return ret;
220  }
221  THStack* Normalize(THStack* inp)
222  {
223  THStack* ret = new THStack(Form("norm%s",inp->GetName()),
224  Form("%s normalised", inp->GetTitle()));
225  TIter next(inp->GetHists());
226  TH1* hist = 0;
227  while ((hist = static_cast<TH1*>(next()))) {
228  Double_t err = 0;
229  Double_t ing = hist->IntegralAndError(1,hist->GetNbinsX(), err);
230  TH1* hir = static_cast<TH1*>(hist->Clone());
231  hir->SetDirectory(0);
232  // hir->Sumw2();
233  Printf("%10s integral %f +/- %f", hist->GetTitle(), ing, err);
234  // U::Scale(hir, 1/ing, err);
235  hir->Scale(1/ing);
236  ret->Add(hir);
237  }
238  return ret;
239  }
240  THStack* ToOther(THStack* inp)
241  {
242  TH1* o = FindHist(inp, "0");
243  TH1* t = FindHist(inp, "total");
244  THStack* ret = new THStack(Form("rat%s",inp->GetName()),
245  Form("%s ratios", inp->GetTitle()));
246  TIter next(inp->GetHists());
247  TH1* hist = 0;
248  while ((hist = static_cast<TH1*>(next()))) {
249  // if (hist == o) continue;
250  if (hist == t) {
251 #if 0
252  Printf("%10s: integral %f \t-> %f",
253  hist->GetTitle(),
254  hist->Integral(1,hist->GetNbinsX()),
255  t->Integral(1,t->GetNbinsX()));
256 #endif
257  continue;
258  }
259  TH1* hir = static_cast<TH1*>(hist->Clone());
260  hir->Reset();
261  hir->Divide(hist,t);
262  hir->SetDirectory(0);
263  hir->Scale(25./hir->Integral(1,hir->GetNbinsX()), "width");
264  ret->Add(hir);
265 #if 0
266  Printf("%10s: integral %f \t-> %f",
267  hist->GetTitle(),
268  hist->Integral(1,hist->GetNbinsX()),
269  hir->Integral(1,hir->GetNbinsX(),"width"));
270 #endif
271  }
272  return ret;
273 
274  }
275 
276 };
277 
278 
279 void DeltaShapes(const char* what="hijing.root", Double_t c1=48, Double_t c2=52)
280 {
281  if (!gROOT->GetClass("AliTrackletAODUtils")) {
282  Printf("Loading utilities");
283  gROOT->LoadMacro("$ANA_SRC/dndeta/tracklets3/AliTrackletAODUtils.C+g");
284  }
285 
286  Computer c;
287  c.Run(what, c1, c2);
288 }
const char * filename
Definition: TestFCM.C:1
static void PdgAttr(Int_t pdg, TString &nme, Color_t &c, Style_t &s)
double Double_t
Definition: External.C:58
THStack * MakeMeas(THStack *prim, THStack *seco, THStack *fake)
Definition: DeltaShapes.C:209
const char * title
Definition: MakeQAPdf.C:26
TCanvas * canvas
Definition: DrawAnaELoss.C:28
static TFile * OpenFile(const char *filename)
TH1 * MakeMeas(const char *name, THStack *prim, THStack *seco, THStack *fake)
Definition: DeltaShapes.C:191
static TH1 * GetH1(Container *parent, const char *name, Bool_t verb=true)
static const char * CentName(Double_t c1, Double_t c2)
TH1 * FindHist(THStack *s, const char *name)
Definition: DeltaShapes.C:187
void DeltaShapes(const char *what="hijing.root", Double_t c1=48, Double_t c2=52)
Definition: DeltaShapes.C:279
TCanvas * c
Definition: TestFitELoss.C:172
Utilities for midrapidity analysis.
void DrawStack(TVirtualPad *p, THStack *hs, Bool_t logy=true, const char *title="d#it{N}_{X}/d#it{#Delta}")
Definition: DeltaShapes.C:105
THStack * ToOther(THStack *inp)
Definition: DeltaShapes.C:240
THStack * DoOne(TList *c, Bool_t mid, const char *subName)
Definition: DeltaShapes.C:127
static THStack * GetHS(Container *parent, const char *name, Bool_t verb=true)
TFile * file
static Container * GetC(Container *parent, const char *name, Bool_t verb=true)
bool Bool_t
Definition: External.C:53
THStack * Normalize(THStack *inp)
Definition: DeltaShapes.C:221
void Run(const char *filename, Double_t c1, Double_t c2, Bool_t mid=true)
Definition: DeltaShapes.C:21
Definition: External.C:196
AliTrackletAODUtils U
Definition: DeltaShapes.C:16