AliPhysics  6bc8652 (6bc8652)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BackOfTheEnvelope.C
Go to the documentation of this file.
1 
12 #ifndef __CINT__
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 #else
25 class TFile;
26 class TClass;
27 class TH1;
28 class TH2;
29 class TDirectory;
30 class THStack;
31 class TCollection;
32 class TBrowser;
33 class TCanvas;
34 #endif
35 
41 const char* fmt = "%-10s | %5.3f | %5.2f | %5.2f | %5.2f %5.2f |";
48 {
54  struct Particle
55  {
69  Double_t Get(Int_t i) const
70  {
71  return (i == 0 ? Ps :
72  i == 1 ? Ss :
73  i == 2 ? Cs :
74  i == 3 ? Cb : 0);
75  }
76  void Print() const
77  {
78  Printf(fmt, n.Data(), w, Ps, Ss, Cs, Cb);
79  }
80  };
81 #ifndef __CINT__
82  typedef std::vector<Particle*> ParticleList;
83 #else
84  typedef std::vector<void*> ParticleList;
85 #endif
87  Double_t fP; // Ratio of primaries to all tracklets
88  Double_t fS; // Ratio of secondaries to all tracklets
89  Double_t fC; // Ratio of combinatorics to all tracklets
90  Double_t fPs; // Ratio of signal primaries to all tracklets
91  Double_t fSs; // Ratio of signal secondaries to all tracklets
92  Double_t fCs; // Ratio of signal combinatorics to all tracklets
97  void Print()
98  {
99  TString head(fmt);
100  head.ReplaceAll("%5.3f", "%5s");
101  head.ReplaceAll("%5.2f", "%5s");
102  TString lne(head);
103  lne.ReplaceAll("|", "+");
104  lne.ReplaceAll("%5s", "-----");
105  lne.ReplaceAll("%10s", "----------");
106  lne.ReplaceAll(" ", "-");
107  Printf(head.Data(), "Type", "W", "Ps", "Ss", "Cs", "Cb");
108  Printf(lne);
109  Printf(fmt, "Full", 0., fP, fS, fC, 0.);
110  Printf(fmt, "Signal", 0., fPs, fSs, fCs, 0.);
111  Printf(lne);
112  for (ParticleList::const_iterator i = particles.begin();
113  i != particles.end(); ++i)
114  (*i)->Print();
115  Printf(lne);
116  }
123  {
124  particles.push_back(p);
125  }
135  Double_t R(Int_t i, const char* w="", Bool_t verb=true) const
136  {
137  Double_t ret = 1;
138  if (verb) printf("%-10s: %6.4f", w, ret);
139  for (ParticleList::const_iterator j = particles.begin();
140  j != particles.end(); ++j) {
141  Particle* p = *j;
142  ret += (p->w-1)*(p->Get(i)/100);
143  if (verb) printf("+(%4.2f-1)*%6.4f", (p->w), (p->Get(i)/100));
144  }
145  if (verb) printf("=%6.4f\n", ret);
146  return ret;
147  }
155  Double_t Calc(Bool_t verb=true)
156  {
157  Double_t rPs = R(0, "rPs", verb);
158  Double_t rSs = R(1, "rSs", verb);
159  Double_t rCs = R(2, "rCs", verb);
160  Double_t rCb = R(3, "rCb", verb);
161  Double_t rMsim = (fP*rPs+fS*rSs+fC*rCs)/(fP+fS+fC);
162  Printf("%-10s: (%5.3f*%6.4f+%5.3f*%6.4f+%5.3f*%6.4f)/"
163  "(%5.3f+%5.3f+%5.3f)=%6.4f",
164  "rM'", fP, rPs, fS, rSs, fC, rCs, fP, fS, fC, rMsim);
165  Double_t beta = (fCs)/(fPs+fSs+fCs);
166  Printf("%-10s: %5.3f/(%5.3f+%5.3f+%5.3f)=%6.4f", "beta",fCs,fPs,fSs,fCs);
167  Double_t rBetasim = (1-rCs/rMsim*beta)/(1-beta);
168  Printf("%-10s: (1-%6.4f/%6.4f*%6.4f)/(1-%6.4f)=%6.4f",
169  "rbeta'", rCs, rMsim, beta, beta);
170  Double_t rScale = rCs/rCb;
171  Printf("%-10s: %6.4f/%6.4f=%6.4f", "rk", rCs, rCb, rScale);
172  Double_t rBetarea = (1-rScale*beta)/(1-beta);
173  Printf("%-10s: (1-%6.4f*%6.4f)/(1-%6.4f)=%6.4f",
174  "rbeta", rScale, beta, beta);
175  Double_t rR = rPs * rBetarea / rBetasim / rMsim;
176  Printf("%-10s: %6.4f*%6.4f/%6.4f/%6.4f=%6.4f",
177  "rR", rPs, rBetarea, rBetasim, rMsim);
178  return rR;
179  }
180  TObject* ChkC(TObject* o, TClass* c) const
181  {
182  if (!o) return 0;
183  if (!c) return o;
184  if (!o->IsA()->InheritsFrom(c)) {
185  ::Warning("ChkC", "Object %s is not a %s but a %s",
186  o->GetName(), c->GetName(), o->ClassName());
187  return 0;
188  }
189  return o;
190  }
191  TObject* ChkO(TObject* src, TObject* o, const char* name) const
192  {
193  if (!o) {
194  ::Warning("ChkO", "Object %s not found in %s", name, src->GetName());
195  src->ls();
196  return 0;
197  }
198  return o;
199  }
200  TObject* GetO(TDirectory* d, const char* name, TClass* cls) const
201  {
202  if (!d) {
203  ::Warning("GetO", "No directory passed for %s", name);
204  return 0;
205  }
206  TObject* o = d->Get(name);
207  return ChkC(ChkO(d, o, name), cls);
208  }
209  TObject* GetO(TCollection* d, const char* name, TClass* cls) const
210  {
211  if (!d) {
212  ::Warning("GetO", "No collection passed for %s", name);
213  return 0;
214  }
215  TObject* o = d->FindObject(name);
216  return ChkC(ChkO(d, o, name), cls);
217  }
218  TCollection* GetC(TDirectory* d, const char* name)
219  {
220  return static_cast<TCollection*>(GetO(d, name, TCollection::Class()));
221  }
222  TCollection* GetC(TCollection* d, const char* name)
223  {
224  return static_cast<TCollection*>(GetO(d, name, TCollection::Class()));
225  }
226  TH1* GetH1(TCollection* d, const char* name)
227  {
228  return static_cast<TH1*>(GetO(d, name, TH1::Class()));
229  }
230  TH2* GetH2(TCollection* d, const char* name)
231  {
232  return static_cast<TH2*>(GetO(d, name, TH2::Class()));
233  }
234  THStack* GetHS(TCollection* d, const char* name)
235  {
236  return static_cast<THStack*>(GetO(d, name, THStack::Class()));
237  }
250  THStack* hp, THStack* hs, THStack* hc)
251  {
252  TH1* rps = GetH1(hp->GetHists(), "rowSig");
253  TH1* rss = GetH1(hs->GetHists(), "rowSig");
254  TH1* rcs = GetH1(hc->GetHists(), "rowSig");
255  TH1* rcb = GetH1(hc->GetHists(), "rowBg");
256  Particle* ret = new Particle;
257  ret->n = rps->GetXaxis()->GetBinLabel(bin);
258  ret->w = w;
259  ret->Ps = rps->GetBinContent(bin);
260  ret->Ss = rss->GetBinContent(bin);
261  ret->Cs = rcs->GetBinContent(bin);
262  ret->Cb = rcb->GetBinContent(bin);
263  AddParticle(ret);
264  return ret;
265  }
273  void Run(const char* fileName, const char* binName, Bool_t mid=true)
274  {
275  TFile* file = TFile::Open(fileName, "READ");
276  if (!file) return;
277  TString sub = (mid ? "mid" : "fwd");
278  TString oth = (mid ? "fwd" : "mid");
279  TCollection* top = GetC(file, "MidRapidityMCResults");
280  TCollection* bin = GetC(top, binName);
281  TCollection* prim = GetC(GetC(GetC(bin,"primaries"), "specie"),sub);
282  TCollection* seco = GetC(GetC(GetC(bin,"secondaries"), "specie"),sub);
283  TCollection* comb = GetC(GetC(GetC(bin,"combinatorics"),"specie"),sub);
284  TCollection* opri = GetC(GetC(GetC(bin,"primaries"), "specie"),oth);
285  TCollection* osec = GetC(GetC(GetC(bin,"secondaries"), "specie"),oth);
286  TCollection* ocom = GetC(GetC(GetC(bin,"combinatorics"),"specie"),oth);
287  TH1* ip = GetH1(prim, "totalIntegrals");
288  TH1* is = GetH1(seco, "totalIntegrals");
289  TH1* ic = GetH1(comb, "totalIntegrals");
290  TH1* op = GetH1(opri, "totalIntegrals");
291  TH1* os = GetH1(osec, "totalIntegrals");
292  TH1* oc = GetH1(ocom, "totalIntegrals");
293  THStack* hp = GetHS(prim, "rows");
294  THStack* hs = GetHS(seco, "rows");
295  THStack* hc = GetHS(comb, "rows");
296  Double_t tot = (ip->GetBinContent(1)+
297  is->GetBinContent(1)+
298  ic->GetBinContent(1)+
299  op->GetBinContent(1)+
300  os->GetBinContent(1)+
301  oc->GetBinContent(1));
302  ip->Scale(1./tot);
303  is->Scale(1./tot);
304  ic->Scale(1./tot);
305  fP = ip->GetBinContent(1)*100;
306  fS = is->GetBinContent(1)*100;
307  fC = ic->GetBinContent(1)*100;
308  fPs = ip->GetBinContent(2)*100;
309  fSs = is->GetBinContent(2)*100;
310  fCs = ic->GetBinContent(2)*100;
311 
312  Create(1.52233, 1, hp, hs, hc);
313  Create(1.41178, 2, hp, hs, hc);
314  Create(2.75002, 3, hp, hs, hc);
315  Create(3.24110, 4, hp, hs, hc);
316  Create(2.75002, 5, hp, hs, hc);
317  Create(1, 6, hp, hs, hc);
318 
319  TCanvas* c = new TCanvas("c","c");
320  c->Divide(2,3);
321  c->cd(1); ip->Draw("hist text30");
322  c->cd(3); is->Draw("hist text30");
323  c->cd(5); ic->Draw("hist text30");
324  c->cd(2); hp->Draw("nostack");
325  c->cd(4); hs->Draw("nostack");
326  c->cd(6); hc->Draw("nostack");
327 
328  Print();
329 
330  Double_t r = Calc();
331  Printf("R = %5.3f", r);
332 
333  // file->Close();
334  }
335  void Run(const char* fileName, Double_t c1=0, Double_t c2=0, Bool_t mid=true)
336  {
337  TString bin("all");
338  if (c2 > c1)
339  bin.Format("cent%03dd%02d_%03dd%02d",
340  Int_t(c1), Int_t(100*c1) % 100,
341  Int_t(c2), Int_t(100*c2) % 100);
342  Run(fileName, bin, mid);
343  }
344 };
345 
356 void BackOfTheEnvelope(const char* file, Double_t c1=0, Double_t c2=0,
357  Bool_t mid=true)
358 {
359  Calculation c;
360  c.Run(file, c1, c2, mid);
361 }
362 //
363 // EOF
364 //
THStack * GetHS(TCollection *d, const char *name)
TCollection * GetC(TDirectory *d, const char *name)
void Run(const char *fileName, Double_t c1=0, Double_t c2=0, Bool_t mid=true)
double Double_t
Definition: External.C:58
void BackOfTheEnvelope(const char *file, Double_t c1=0, Double_t c2=0, Bool_t mid=true)
ParticleList particles
TObject * GetO(TCollection *d, const char *name, TClass *cls) const
const char * fmt
TString fileName
Double_t Get(Int_t i) const
Particle * Create(Double_t w, Int_t bin, THStack *hp, THStack *hs, THStack *hc)
Double_t Calc(Bool_t verb=true)
TCanvas * c
Definition: TestFitELoss.C:172
int Int_t
Definition: External.C:63
Double_t R(Int_t i, const char *w="", Bool_t verb=true) const
TObject * GetO(TDirectory *d, const char *name, TClass *cls) const
void AddParticle(Particle *p)
TCollection * GetC(TCollection *d, const char *name)
TObject * ChkO(TObject *src, TObject *o, const char *name) const
Definition: External.C:220
TFile * file
TH1 * GetH1(TCollection *d, const char *name)
TObject * ChkC(TObject *o, TClass *c) const
void Run(const char *fileName, const char *binName, Bool_t mid=true)
bool Bool_t
Definition: External.C:53
Definition: External.C:196
TH2 * GetH2(TCollection *d, const char *name)
std::vector< Particle * > ParticleList