AliPhysics  67e0feb (67e0feb)
YieldExpectations.C
Go to the documentation of this file.
1 
11 #ifndef __CINT__
12 # include "AliTrackletAODUtils.C"
13 # include <vector>
14 # include <TFile.h>
15 # include <TError.h>
16 # include <TCollection.h>
17 # include <TString.h>
18 # include <TH1.h>
19 # include <TH2.h>
20 # include <THStack.h>
21 # include <TClass.h>
22 # include <TBrowser.h>
23 # include <TCanvas.h>
24 # include <TLegend.h>
25 # include <TLegendEntry.h>
26 # include <TStyle.h>
27 #else
28 class TFile;
29 class TClass;
30 class TH1;
31 class TH2;
32 class TDirectory;
33 class THStack;
34 class TCollection;
35 class TBrowser;
36 class TCanvas;
37 class TVirtualPad;
38 class TLegend;
39 #endif
40 
46 {
47 #ifndef __CINT__
49 #endif
50 
51  struct One
52  {
53  THStack* fStack;
57  TH1* fXi;
61 
62  One(const char* filename,
63  const char* title,
64  Color_t color,
65  Double_t offset,
66  Double_t width=.15,
67  Double_t c1=0,
68  Double_t c2=0)
69  : fStack(0),
70  fK0S(0),
71  fKpm(0),
72  fLambda(0),
73  fXi(0),
74  fSigma(0),
75  fOther(0),
76  fYields(0)
77  {
78  TString cntN = U::CentName(c1,c2);
79  TFile* file = U::OpenFile(filename);
80  U::Container* top = U::GetC(file, "MidRapidityMCResults");
81  U::Container* cent = U::GetC(top, cntN);
82  U::Container* gen = U::GetC(cent, "generated");
83  U::Container* mix = U::GetC(gen, "mix");
84 
85  fStack = new THStack("dists", title);
86  fYields = new TH1D("yields", title, 6, 0, 6);
87  fYields->SetMarkerSize(1.5);
88  ModHist(fYields, 0, color, offset, width);
89 
90  TIter next(mix);
91  TObject* o = 0;
92  while ((o = next())) {
93  if (!o->IsA()->InheritsFrom(TH1::Class())) continue;
94  TH1* t = static_cast<TH1*>(o);
95 
96  TString nme(t->GetName());
97  if (!nme.BeginsWith("eta_")) continue;
98 
99  nme.ReplaceAll("eta_","");
100  Int_t pdg = nme.Atoi();
101 
102  TH1** h = 0;
103  switch (pdg) {
104  case 310: h = &fK0S; break;
105  case 321: h = &fKpm; break;
106  case 3122: h = &fLambda; break;
107  // case 3322: h = &fXi; break; // Old, wrong code
108  case 3312: h = &fXi; break; // New, right code
109  case 3112: h = &fSigma; break;
110  // case 3212: h = &fSigma; break; // Old, wrong code
111  case 3222: h = &fSigma; break; // New, right code
112  default: h = &fOther; break;
113  }
114  if (!h) {
115  Printf("Unknown PDG=%d", pdg);
116  continue;
117  }
118  if (!*h) {
119  *h = static_cast<TH1*>(t->Clone());
120  (*h)->Reset();
121  }
122  (*h)->Add(t);
123  }
124  if (!fOther || !fK0S || !fKpm || !fLambda || !fXi || !fSigma)
125  return;
126  fOther ->SetTitle("Other");
127  fOther ->SetMarkerStyle(20); fOther ->SetMarkerSize(1.2);
128  fK0S ->SetMarkerStyle(21); fK0S ->SetMarkerSize(1);
129  fKpm ->SetMarkerStyle(25); fKpm ->SetMarkerSize(1);
130  fLambda->SetMarkerStyle(23); fLambda->SetMarkerSize(1.2);
131  fXi ->SetMarkerStyle(22); fXi ->SetMarkerSize(1.2);
132  fSigma ->SetMarkerStyle(26); fSigma ->SetMarkerSize(1.2);
133  fStack->Add(fK0S );
134  fStack->Add(fKpm );
135  fStack->Add(fLambda);
136  fStack->Add(fXi );
137  fStack->Add(fSigma );
138  fStack->Add(fOther );
139 
140  if (color == kMagenta+1) {
141  fK0S ->Scale(1.52233);
142  fKpm ->Scale(1.41178);
143  fLambda->Scale(2.75002);
144  fXi ->Scale(3.24110);
145  fSigma ->Scale(2.75002);
146  } fOther ->Scale(1);
147 
148  TIter nextH(fStack->GetHists());
149  TH1* hist = 0;
150  Int_t bin = 1;
151  while ((hist = static_cast<TH1*>(nextH()))) {
152  CalcYield(hist, bin++);
153  ModHist(hist, 0, color, offset, width);
154  }
155  }
156  void ModHist(TH1* h,
157  const char* title,
158  Color_t color,
159  Double_t offset,
160  Double_t width)
161  {
162  // Printf("%10s offset=%f width=%f", h->GetTitle(), offset, width);
163  h->SetDirectory(0);
164  h->SetMarkerColor(color);
165  h->SetLineColor(color);
166  h->SetFillColor(color);
167  h->SetBarOffset(offset);
168  h->SetBarWidth(width);
169 
170  TString nme(Form("%s%s",h->GetName(),title)); nme.ReplaceAll("-","");
171  h->SetName(nme);
172 
173  if (h == fYields) return;
174  TAxis* axis = h->GetXaxis();
175  Double_t shift = axis->GetBinWidth(1)*(offset-0.5);
176  axis->SetLimits(axis->GetXmin()+shift, axis->GetXmax()+shift);
177  if (title) h->SetTitle(Form("%s #minus %s", h->GetTitle(), title));
178  }
179  void CalcYield(TH1* h, Int_t bin)
180  {
181  Double_t err;
182  Double_t yie = h->IntegralAndError(1,h->GetNbinsX(),err);
183  fYields->SetBinContent(bin, yie);
184  fYields->SetBinError (bin, err);
185  fYields->GetXaxis()->SetBinLabel(bin, h->GetTitle());
186  }
187  void AddToStacks(THStack* dists, THStack* yields,
188  TLegend* ld, TLegend* ly)
189  {
190  TIter next(fStack->GetHists());
191  TH1* hist = 0;
192  while ((hist = static_cast<TH1*>(next()))) {
193  dists->Add(hist);
194  if (!ld) continue;
195  TLegendEntry* e = ld->AddEntry("dummy", hist->GetTitle(), "p");
196  e->SetMarkerStyle(hist->GetMarkerStyle());
197  e->SetMarkerSize(1.5*hist->GetMarkerSize());
198  }
199 
200  yields->Add(fYields, "hist bar text90");
201  TLegendEntry* e = ly->AddEntry("dummy", fYields->GetTitle(), "f");
202  e->SetFillColor(fYields->GetFillColor());
203  e->SetFillStyle(1001);
204  }
205  };
206  void Run(Double_t c1, Double_t c2)
207  {
208  One* stk = new One("stk.root", "Reduced", kRed+1, .15,.15,c1,c2);
209  One* expe = new One("stk.root", "Expected", kMagenta+1,.35,.15,c1,c2);
210  One* wstk = new One("wstk.root", "Reweighed",kBlue+1, .55,.15,c1,c2);
211  One* hijing = new One("hijing.root","As-is", kGreen+1, .75,.15,c1,c2);
212  One* ones[] = { stk, expe, wstk, hijing, 0 };
213  One** ptr = ones;
214 
215  gStyle->SetPaintTextFormat("5.0f");
216  gStyle->SetErrorX(0.2);
217  Int_t mode = 1; // 0: square, 1: landscape, 2: portrait
218  Int_t cw = (mode == 1 ? 1600 : mode == 2 ? 800 : 1000);
219  Int_t ch = (mode == 1 ? cw/2 : mode == 2 ? 1.5*cw : cw);
220  TCanvas* c = new TCanvas(Form("yieldExpectation_%s",U::CentName(c1,c2)),
221  "YieldCanvas",cw,ch);
222  c->Divide(2,1);
223  TVirtualPad* p = c->GetPad(1);
224  TVirtualPad* q = c->GetPad(2);
225  p->SetTopMargin(0.01);
226  p->SetRightMargin(0.01);
227  p->SetLogy();
228  p->SetTicks();
229  q->SetTopMargin(0.01);
230  q->SetRightMargin(0.01);
231  q->SetLeftMargin(0.13);
232  q->SetLogy();
233  q->SetTicks();
234 
235  TLegend* le = new TLegend(p->GetLeftMargin()+.01, .75,
236  1-p->GetRightMargin(), .85);
237  TLegend* ly = new TLegend(q->GetLeftMargin()+.01, .75,
238  1-q->GetRightMargin(),
239  1-q->GetTopMargin());
240  le->SetBorderSize(0);
241  le->SetFillStyle(0);
242  le->SetNColumns(6);
243  ly->SetBorderSize(0);
244  ly->SetFillStyle(0);
245 
246  THStack* dists = new THStack("dists", "");
247  THStack* yields = new THStack("yields", "");
248 
249  while (*ptr) {
250  (*ptr)->AddToStacks(dists, yields, (*ptr == stk ? le : 0), ly);
251  ptr++;
252  }
253  p->cd();
254  dists->Draw("nostack");
255  dists->GetHistogram()->SetXTitle("#it{#eta}");
256  dists->GetHistogram()->SetYTitle("d#it{N}_{X}/d#it{#eta}");
257  le->Draw();
258 
259  q->cd();
260  yields->SetMaximum(2*yields->GetMaximum("nostack"));
261  yields->Draw("nostack");
262  yields->GetHistogram()->GetXaxis()->SetLabelSize(0.07);
263  yields->GetHistogram()->GetYaxis()->SetLabelSize(0);
264  yields->GetHistogram()->GetYaxis()->SetTitleOffset(1.2);
265  yields->GetHistogram()->SetYTitle(Form("#int_{-2}^{+2}d#it{#eta} %s",
266  dists->GetHistogram()->GetYaxis()
267  ->GetTitle()));
268  ly->Draw();
269 
270  c->Modified();
271  c->Update();
272  c->cd();
273  c->SaveAs(Form("%s.png", c->GetName()));
274  }
275 };
276 
283 {
284  if (!gROOT->GetClass("AliTrackletAODUtils")) {
285  Printf("Loading utilities");
286  gROOT->LoadMacro("$ANA_SRC/dndeta/tracklets3/AliTrackletAODUtils.C+g");
287  }
288 #if 0
289  gSystem->AddIncludePath("-DSELF_COMPILE__");
290  if (!gROOT->GetClass("YieldCalculations")) {
291  gInterpreter->ClearFileBusy();
292  // gInterpreter->UnloadFile("YieldExpectations.C");
293  Printf("Reload self compiled");
294  gROOT->LoadMacro("$ANA_SRC/dndeta/tracklets3/YieldExpectations.C+g");
295  }
296 #endif
298  c.Run(c1,c2);
299 }
300 
301 
Int_t color[]
print message on plot with ok/not ok
Int_t pdg
const char * filename
Definition: TestFCM.C:1
double Double_t
Definition: External.C:58
const char * title
Definition: MakeQAPdf.C:27
void CalcYield(TH1 *h, Int_t bin)
static TFile * OpenFile(const char *filename)
TSystem * gSystem
static const char * CentName(Double_t c1, Double_t c2)
TCanvas * c
Definition: TestFitELoss.C:172
One(const char *filename, const char *title, Color_t color, Double_t offset, Double_t width=.15, Double_t c1=0, Double_t c2=0)
void YieldExpectations(Double_t c1=0, Double_t c2=0)
void ModHist(TH1 *h, const char *title, Color_t color, Double_t offset, Double_t width)
Utilities for midrapidity analysis.
int Int_t
Definition: External.C:63
Definition: External.C:212
void AddToStacks(THStack *dists, THStack *yields, TLegend *ld, TLegend *ly)
Int_t mode
Definition: anaM.C:41
void Run(Double_t c1, Double_t c2)
Definition: External.C:220
AliTrackletAODUtils U
TFile * file
TList with histograms for a given trigger.
static Container * GetC(Container *parent, const char *name, Bool_t verb=true)
Definition: External.C:196