AliPhysics  fb6b143 (fb6b143)
Expectations.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 # 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 #endif
39 
45 const char* parFmt = "%-10s | %5.3f |";
46 const char* rowFmt = " %5.2f | %5.2f | %5.2f | %5.2f |";
47 struct Utilities
48 {
57  static TObject* ChkC(TObject* o, TClass* c)
58  {
59  if (!o) return 0;
60  if (!c) return o;
61  if (!o->IsA()->InheritsFrom(c)) {
62  ::Warning("ChkC", "Object %s is not a %s but a %s",
63  o->GetName(), c->GetName(), o->ClassName());
64  return 0;
65  }
66  return o;
67  }
77  static TObject* ChkO(TObject* src, TObject* o, const char* name)
78  {
79  if (!o) {
80  ::Warning("ChkO", "Object %s not found in %s", name, src->GetName());
81  src->ls();
82  return 0;
83  }
84  return o;
85  }
95  static TObject* GetO(TDirectory* d, const char* name, TClass* cls)
96  {
97  if (!d) {
98  ::Warning("GetO", "No directory passed for %s", name);
99  return 0;
100  }
101  TObject* o = d->Get(name);
102  return ChkC(ChkO(d, o, name), cls);
103  }
113  static TObject* GetO(TCollection* d, const char* name, TClass* cls)
114  {
115  if (!d) {
116  ::Warning("GetO", "No collection passed for %s", name);
117  return 0;
118  }
119  TObject* o = d->FindObject(name);
120  return ChkC(ChkO(d, o, name), cls);
121  }
130  static TCollection* GetC(TDirectory* d, const char* name)
131  {
132  return static_cast<TCollection*>(GetO(d, name, TCollection::Class()));
133  }
142  static TCollection* GetC(TCollection* d, const char* name)
143  {
144  return static_cast<TCollection*>(GetO(d, name, TCollection::Class()));
145  }
154  static TH1* GetH1(TCollection* d, const char* name)
155  {
156  return static_cast<TH1*>(GetO(d, name, TH1::Class()));
157  }
166  static TH2* GetH2(TCollection* d, const char* name)
167  {
168  return static_cast<TH2*>(GetO(d, name, TH2::Class()));
169  }
178  static THStack* GetHS(TCollection* d, const char* name)
179  {
180  return static_cast<THStack*>(GetO(d, name, THStack::Class()));
181  }
182 };
183 
189 struct Calculation : public Utilities
190 {
191  enum EColumn {
195  kCb
196  };
197  enum ERow {
201  kAsIs
202  };
203  enum EKind {
204  kK0S = 1,
209  kOther
210  };
211  struct Row
212  {
229  {
230  return (i == kPs ? Ps :
231  i == kSs ? Ss :
232  i == kCs ? Cs :
233  i == kCb ? Cb : 0);
234  }
243  {
244  return (i == kPs ? ePs :
245  i == kSs ? eSs :
246  i == kCs ? eCs :
247  i == kCb ? eCb : 0);
248  }
255  void Scale(EColumn i, Double_t s)
256  {
257  switch (i) {
258  case kPs: Ps *= s; ePs *= s; break;
259  case kSs: Ss *= s; eSs *= s; break;
260  case kCs: Cs *= s; eCs *= s; break;
261  case kCb: Cb *= s; eCb *= s; break;
262  }
263  }
268  void Print() const
269  {
270  printf(rowFmt, Ps, Ss, Cs, Cb);
271  }
272  };
278  struct Particle
279  {
280  TString n;
281  Double_t w;
294  {
295  return (i == kReduced ? reduced :
296  i == kExpectation ? expected :
297  i == kReweighed ? reweighed :
298  asis);
299  }
304  void Print()
305  {
306  printf(parFmt, n.Data(), w);
307  reduced. Print();
308  expected. Print();
309  reweighed.Print();
310  asis. Print();
311  printf("\n");
312  }
326  EKind kind,
327  TCollection* bin,
328  const TString& sub,
329  const TString& oth,
330  Bool_t abso=true)
331  {
332  TString pn = "primaries";
333  TString sn = "secondaries";
334  TString cn = "combinatorics";
335  TCollection* pc = GetC(GetC(GetC(bin,pn),"specie"),sub);
336  TCollection* sc = GetC(GetC(GetC(bin,sn),"specie"),sub);
337  TCollection* cc = GetC(GetC(GetC(bin,cn),"specie"),sub);
338  TCollection* po = GetC(GetC(GetC(bin,pn),"specie"),oth);
339  TCollection* so = GetC(GetC(GetC(bin,sn),"specie"),oth);
340  TCollection* co = GetC(GetC(GetC(bin,cn),"specie"),oth);
341  THStack* hp = GetHS(pc,"rows");
342  THStack* hs = GetHS(sc,"rows");
343  THStack* hc = GetHS(cc,"rows");
344  TH1* rps = GetH1(hp->GetHists(), "rowSig");
345  TH1* rss = GetH1(hs->GetHists(), "rowSig");
346  TH1* rcs = GetH1(hc->GetHists(), "rowSig");
347  TH1* rcb = GetH1(hc->GetHists(), "rowBg");
348  TH1* pi = GetH1(pc, "totalIntegrals");
349  TH1* si = GetH1(sc, "totalIntegrals");
350  TH1* ci = GetH1(cc, "totalIntegrals");
351  TH1* pj = GetH1(po, "totalIntegrals");
352  TH1* sj = GetH1(so, "totalIntegrals");
353  TH1* cj = GetH1(co, "totalIntegrals");
354  Double_t ww = (row == kExpectation ? w : 1);
355  Int_t bn = kind;
356  Row& ret = Get(row);
357  if (n.IsNull()) n = rps->GetXaxis()->GetBinLabel(bn);
358  if (abso) {
359  ret.Ps = ww*pi->GetBinContent(2)*rps->GetBinContent(bn);
360  ret.Ss = ww*si->GetBinContent(2)*rss->GetBinContent(bn);
361  ret.Cs = ww*ci->GetBinContent(2)*rcs->GetBinContent(bn);
362  ret.Cb = ww*ci->GetBinContent(3)*rcb->GetBinContent(bn);
363  ret.ePs = ww*pi->GetBinContent(2)*rps->GetBinError (bn);
364  ret.eSs = ww*si->GetBinContent(2)*rss->GetBinError (bn);
365  ret.eCs = ww*ci->GetBinContent(2)*rcs->GetBinError (bn);
366  ret.eCb = ww*ci->GetBinContent(3)*rcb->GetBinError (bn);
367  }
368  else {
369  ret.Ps = ww*rps->GetBinContent(bn);
370  ret.Ss = ww*rss->GetBinContent(bn);
371  ret.Cs = ww*rcs->GetBinContent(bn);
372  ret.Cb = ww*rcb->GetBinContent(bn);
373  ret.ePs = ww*rps->GetBinError (bn);
374  ret.eSs = ww*rss->GetBinError (bn);
375  ret.eCs = ww*rcs->GetBinError (bn);
376  ret.eCb = ww*rcb->GetBinError (bn);
377  }
378  return this;
379  }
380  };
381 #ifndef __CINT__
382  typedef std::vector<Particle*> ParticleList;
383 #else
384  typedef std::vector<void*> ParticleList;
385 #endif
386  ParticleList particles;
387  Double_t fP; // Ratio of primaries to all tracklets
388  Double_t fS; // Ratio of secondaries to all tracklets
389  Double_t fC; // Ratio of combinatorics to all tracklets
390  Double_t fPs; // Ratio of signal primaries to all tracklets
391  Double_t fSs; // Ratio of signal secondaries to all tracklets
392  Double_t fCs; // Ratio of signal combinatorics to all tracklets
397  void Print()
398  {
399  printf("%-18s |", "Sample");
400  printf(" %-29s |", "Reduced");
401  printf(" %-29s |", "Expected");
402  printf(" %-29s |", "Reweighed");
403  printf(" %-29s |", "As-is");
404  printf("\n");
405  TString head(parFmt);
406  for (Int_t i = 0; i < 4; i++) head.Append(rowFmt);
407  head.ReplaceAll("%5.3f", "%5s");
408  head.ReplaceAll("%5.2f", "%5s");
409  TString lne(head);
410  lne.ReplaceAll("|", "+");
411  lne.ReplaceAll("%5s", "-----");
412  lne.ReplaceAll("%10s", "----------");
413  lne.ReplaceAll(" ", "-");
414  Printf(head.Data(), "Type", "W",
415  "Ps", "Ss", "Cs", "Cb",
416  "Ps", "Ss", "Cs", "Cb",
417  "Ps", "Ss", "Cs", "Cb",
418  "Ps", "Ss", "Cs", "Cb");
419  Printf(lne);
420  for (ParticleList::const_iterator i = particles.begin();
421  i != particles.end(); ++i)
422  (*i)->Print();
423  Printf(lne);
424  }
430  {
431  for (Int_t i = 0; i < 4; i++) {
432  EColumn c = (i == 0 ? kPs :
433  i == 1 ? kSs :
434  i == 2 ? kCs : kCb);
435  Double_t sum = 0;
436  for (ParticleList::const_iterator j = particles.begin();
437  j != particles.end(); ++j)
438  sum += (*j)->expected.Get(c);
439  for (ParticleList::const_iterator j = particles.begin();
440  j != particles.end(); ++j)
441  (*j)->expected.Scale(c,100/sum);
442  }
443  }
444 
445 
462  EKind kind,
463  TCollection* reduced,
464  TCollection* reweighed,
465  TCollection* asis,
466  const TString& sub,
467  const TString& oth,
468  Bool_t abso)
469  {
470  Particle* ret = new Particle;
471  ret->w = w;
472  ret->Read(kReduced, kind, reduced, sub, oth, abso);
473  ret->Read(kExpectation, kind, reduced, sub, oth, abso);
474  ret->Read(kReweighed, kind, reweighed, sub, oth, abso);
475  ret->Read(kAsIs, kind, asis, sub, oth, abso);
476  particles.push_back(ret);
477  return ret;
478  }
488  THStack* MakeStack(EColumn column,
489  const char* name,
490  const char* title,
491  Int_t mode)
492  {
493  const char* names[] = { "red", "exp", "rew", "asi" };
494  const char* titles[] = { "Reduced", "Expected", "Reweighed", "As-is" };
495  const Color_t colors[] = { kRed+1, kMagenta+1, kBlue+1, kGreen+1 };
496  Int_t nPart = particles.size();
497  Double_t bW = 0.15;
498  Double_t bS = 0.05;
499  Double_t bT = 4*bW+3*bS;
500  Double_t bO = (1-bT)/2;
501  THStack* stack = new THStack(name, title);
502  for (Int_t i = 0; i < 4; i++) {
503  ERow q = (i == 0 ? kReduced :
504  i == 1 ? kExpectation :
505  i == 2 ? kReweighed : kAsIs);
506  TH1* h = new TH1D(names[i],titles[i],nPart,0,nPart);
507  h->SetFillColor(colors[i]);
508  h->SetLineColor(colors[i]);
509  h->SetMarkerColor(colors[i]);
510  h->SetBarOffset(bO+i*(bW+bS));
511  h->SetMarkerSize(mode == 2 ? 3.5 : 2);
512  h->SetBarWidth (bW);
513  h->SetDirectory(0);
514  stack->Add(h, "bar0 text90");
515 
516  for (Int_t j = 0; j < nPart; j++) {
517  Particle* p = particles[j];
518  Row& r = p->Get(q);
519  h->GetXaxis()->SetBinLabel(j+1,p->n);
520  h->SetBinContent (j+1,r.Get (column));
521  h->SetBinError (j+1,r.GetE(column));
522  }
523  }
524  return stack;
525  }
535  void DrawStack(TVirtualPad* mother,
536  EColumn column,
537  THStack* stack,
538  Bool_t logy,
539  Bool_t abso,
540  Int_t mode)
541  {
542  TVirtualPad* p = mother->cd(column+1);
543  p->SetGridx();
544  p->SetGridy();
545  p->SetTicks();
546  if (logy) p->SetLogy();
547  if (mode==2 || (p->GetNumber() % (mode==1 ? 4 : 2)) == 0)
548  p->SetRightMargin(0.01);
549  if (!abso) {
550  stack->SetMinimum(0.019);
551  stack->SetMaximum(logy ? (mode == 2 ? 900 : 400) : 110);
552  }
553  gStyle->SetTitleFontSize(0.02/p->GetHNDC());
554  stack->Draw("nostack hist");
555  stack->GetHistogram()->GetYaxis()->SetNdivisions(210);
556  stack->GetHistogram()->GetYaxis()->SetLabelSize(0.03/p->GetHNDC());
557  stack->GetHistogram()->GetYaxis()->SetTitleSize(0.03/p->GetHNDC());
558  stack->GetHistogram()->GetXaxis()->SetLabelSize(0.03/p->GetHNDC());
559  TString tit = abso ? "#it{N}_{tracklet}" : "Fraction [%]";
560  if ((mode == 2 || mode == 0) && p->GetNumber() != 1) tit="";
561  stack->GetHistogram()->GetYaxis()->SetTitle(tit);
562  stack->GetHistogram()->GetYaxis()->SetTitleOffset(mode == 2 ? 0.5 : 1);
563  }
564 
572  void Run(Double_t c1=0, Double_t c2=0, Bool_t mid=true)
573  {
574  Bool_t abso = false;
575  Bool_t logy = true;
576  Int_t mode = 2; // 0: square, 1: landscape, 2: portrait
577 
578  TString bin("all");
579  if (c2 > c1)
580  bin.Form("cent%03dd%02d_%03dd%02d",
581  Int_t(c1), Int_t(100*c1) % 100,
582  Int_t(c2), Int_t(100*c2) % 100);
583 
584  TFile* redFile = TFile::Open("stk.root", "READ");
585  TFile* rweFile = TFile::Open("wstk.root", "READ");
586  TFile* trhFile = TFile::Open("hijing.root", "READ");
587  if (!redFile || !rweFile || !trhFile) return;
588  TString sub = (mid ? "mid" : "fwd");
589  TString oth = (mid ? "fwd" : "mid");
590  TCollection* redTop = GetC(GetC(redFile,"MidRapidityMCResults"),bin.Data());
591  TCollection* rweTop = GetC(GetC(rweFile,"MidRapidityMCResults"),bin.Data());
592  TCollection* trhTop = GetC(GetC(trhFile,"MidRapidityMCResults"),bin.Data());
593 
594  Create(1.52233, kK0S, redTop, rweTop, trhTop, sub, oth, abso);
595  Create(1.41178, kKpm, redTop, rweTop, trhTop, sub, oth, abso);
596  Create(2.75002, kLambda, redTop, rweTop, trhTop, sub, oth, abso);
597  Create(3.24110, kXi, redTop, rweTop, trhTop, sub, oth, abso);
598  Create(2.75002, kSigma, redTop, rweTop, trhTop, sub, oth, abso);
599  Create(1, kOther, redTop, rweTop, trhTop, sub, oth, abso);
600 
601  if (!abso) ScaleExpected();
602  Print();
603 
604  THStack* Ps = MakeStack(kPs, "Ps", "Signal primaries", mode);
605  THStack* Ss = MakeStack(kSs, "Ss", "Signal secondaries", mode);
606  THStack* Cs = MakeStack(kCs, "Cs", "Signal fake", mode);
607  THStack* Cb = MakeStack(kCb, "Cb", "Background fake", mode);
608 
609  gStyle->SetPaintTextFormat("5.2f%%");
610 
611  Int_t cw = (mode == 1 ? 1600 : mode == 2 ? 800 : 1000);
612  Int_t ch = (mode == 1 ? cw/2 : mode == 2 ? 1.5*cw : cw);
613  TCanvas* c = new TCanvas("c","c",cw,ch);
614  c->SetTopMargin(0.01);
615  c->SetRightMargin(0.01);
616  c->SetLeftMargin(mode == 1 ? 0.09 : 0.13);
617  switch (mode) {
618  case 1: c->Divide(4,1,0,0); break;
619  case 2: c->Divide(1,4,0,0); break;
620  default: c->Divide(2,2,0,0); break;
621  }
622 
623  DrawStack(c, kPs, Ps, logy, abso, mode);
624  DrawStack(c, kSs, Ss, logy, abso, mode);
625  DrawStack(c, kCs, Cs, logy, abso, mode);
626  DrawStack(c, kCb, Cb, logy, abso, mode);
627 
628  TVirtualPad* p = c->cd(1);
629  TString t = mid ? "|#eta|<1" : "|#eta|>1";
630  if (c1 >= c2) t.Append(" MB");
631  else t.Append(Form(" %4.1f#minus%4.1f%%", c1, c2));
632  TLegend* l = (logy
633  ? p->BuildLegend(0.45,(mode==2?0.3:0.5),0.95,0.9, t)
634  : p->BuildLegend(0.16,0.4,0.6,0.8, t));
635  l->SetFillStyle(0);
636  l->SetBorderSize(0);
637 
638  c->SaveAs(Form("expected_%s_%s.png", bin.Data(), mid ? "mid" : "fwd"));
639  }
640 };
641 
652 void Expectations(Bool_t mid=true, Double_t c1=0, Double_t c2=5)
653 {
654  Calculation c;
655  c.Run(c1, c2, mid);
656 }
657 //
658 // EOF
659 //
static TObject * ChkO(TObject *src, TObject *o, const char *name)
Definition: Expectations.C:77
void Run(Double_t c1=0, Double_t c2=0, Bool_t mid=true)
Definition: Expectations.C:572
static TObject * GetO(TDirectory *d, const char *name, TClass *cls)
Definition: Expectations.C:95
void Print(std::ostream &o, const char *name, Double_t dT, Double_t dVM, Double_t alldT, Double_t alldVM)
Definition: PlotSysInfo.C:121
const Color_t cc[]
Definition: DrawKs.C:1
double Double_t
Definition: External.C:58
const char * title
Definition: MakeQAPdf.C:27
static TH1 * GetH1(TCollection *d, const char *name)
Definition: Expectations.C:154
const char * rowFmt
Definition: Expectations.C:46
static TCollection * GetC(TCollection *d, const char *name)
Definition: Expectations.C:142
Double_t Get(Int_t i) const
const char * parFmt
Definition: Expectations.C:45
static TCollection * GetC(TDirectory *d, const char *name)
Definition: Expectations.C:130
TCanvas * c
Definition: TestFitELoss.C:172
Particle * Read(ERow row, EKind kind, TCollection *bin, const TString &sub, const TString &oth, Bool_t abso=true)
Definition: Expectations.C:325
static TObject * GetO(TCollection *d, const char *name, TClass *cls)
Definition: Expectations.C:113
AliStack * stack
void DrawStack(TVirtualPad *p, THStack *s, Double_t min, Double_t max)
Definition: DrawDeltas3.C:48
static TH2 * GetH2(TCollection *d, const char *name)
Definition: Expectations.C:166
Particle * Create(Double_t w, EKind kind, TCollection *reduced, TCollection *reweighed, TCollection *asis, const TString &sub, const TString &oth, Bool_t abso)
Definition: Expectations.C:461
void ScaleExpected()
Definition: Expectations.C:429
int Int_t
Definition: External.C:63
static TObject * ChkC(TObject *o, TClass *c)
Definition: Expectations.C:57
Definition: External.C:212
static THStack * GetHS(TCollection *d, const char *name)
Definition: Expectations.C:178
Int_t mode
Definition: anaM.C:41
Int_t colors[nPtBins]
void Print() const
Definition: Expectations.C:268
Definition: External.C:220
Double_t Get(EColumn i) const
Definition: Expectations.C:228
Double_t GetE(EColumn i) const
Definition: Expectations.C:242
void DrawStack(TVirtualPad *mother, EColumn column, THStack *stack, Bool_t logy, Bool_t abso, Int_t mode)
Definition: Expectations.C:535
void Run(const char *fileName, const char *binName, Bool_t mid=true)
const Double_t pi
void Expectations(Bool_t mid=true, Double_t c1=0, Double_t c2=5)
Definition: Expectations.C:652
bool Bool_t
Definition: External.C:53
THStack * MakeStack(Bool_t isNSD, Bool_t showClusters, Double_t strangeCorr, Double_t maxFactor=1.1)
Definition: ExtractData.C:204
void Scale(EColumn i, Double_t s)
Definition: Expectations.C:255
Definition: External.C:196
void Print()
Definition: Expectations.C:397
std::vector< Particle * > ParticleList
Definition: Expectations.C:382
THStack * MakeStack(EColumn column, const char *name, const char *title, Int_t mode)
Definition: Expectations.C:488