AliPhysics  97344c9 (97344c9)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PureMCWeights.C
Go to the documentation of this file.
1 
11 #include "AliTrackletAODUtils.C"
12 #ifndef __CINT__
13 #include "AliTrackletWeights.C"
14 #include <THStack.h>
15 #include <TFile.h>
16 #include <TH1.h>
17 #include <TH2.h>
18 #include <TF1.h>
19 #else
20 class THStack;
21 class TFile;
22 class TCanvas;
23 #endif
24 
31 {
40  const char* CentName(Double_t c1, Double_t c2)
41  {
42  static TString tmp;
43  tmp.Form("cent%06.2f_%06.2f", c1, c2);
44  tmp.ReplaceAll(".", "d");
45  return tmp.Data();
46  }
54  void Run(const char* nFile, const char* dFile, const char* oFile=0) {
55 
56  const Color_t cc[] = { kMagenta+2, // 0
57  kBlue+2, // 1
58  kAzure-1, // 2 // 10,
59  kCyan+2, // 3
60  kGreen+1, // 4
61  kSpring+5, // 5 //+10,
62  kYellow+1, // 6
63  kOrange+5, // 7 //+10,
64  kRed+1, // 8
65  kPink+5, // 9 //+10,
66  kBlack }; // 10
67  TString oN(oFile);
68  if (oN.IsNull()) oN.Form("%c2%c.root", dFile[0], nFile[0]);
69  Printf("********************************************************\n"
70  " Generating pure MC weights\n"
71  "\n"
72  " Numerator (truth) file: %s\n"
73  " Denominator (correction) file: %s\n"
74  " Output (weight) file: %s\n",
75  nFile, dFile, oN.Data());
76 
77 
78  TFile* nF = TFile::Open(nFile, "READ");
79  TFile* dF = TFile::Open(dFile, "READ");
80  if (!nF || !dF) return;
81 
82  Container* nT = GetC(nF, "MidRapidityMCResults");
83  Container* dT = GetC(dF, "MidRapidityMCResults");
84  if (!nT || !dT) return;
85 
86  TH1* nC = GetH1(nT, "cent");
87  TH1* dC = GetH1(dT, "cent");
88  if (!nC || !dC || !CheckConsistency(nC,dC)) return;
89 
90  TList* pdg = new TList;
91  TH2D* pt = 0;
92  pdg->SetOwner();
93 
94  for (Int_t b = 1; b <= nC->GetNbinsX(); b++) {
95  Double_t c1 = nC->GetXaxis()->GetBinLowEdge(b);
96  Double_t c2 = nC->GetXaxis()->GetBinUpEdge (b);
97  const char* cN = CentName(c1, c2);
98  Color_t cC = cc[b%10];
99  Container* nB = GetC(nT, cN);
100  Container* dB = GetC(dT, cN);
101  if (!nB || !dB) continue;
102 
103  Container* nG = GetC(nB, "generated");
104  Container* dG = GetC(dB, "generated");
105  if (!nG || !dG) continue;
106 
107  TH2* nPt2 = GetH2(nG, "etaPt");
108  TH2* dPt2 = GetH2(dG, "etaPt");
109  if (!nPt2 || !dPt2) continue;
110 
111  TH1* nPt = nPt2->ProjectionY(Form("n%s",cN)); nPt->SetDirectory(0);
112  TH1* dPt = dPt2->ProjectionY(Form("d%s",cN)); dPt->SetDirectory(0);
113  TH1* rPt = static_cast<TH1*>(nPt->Clone(Form("r%s", cN)));
114  rPt->Divide(dPt);
115  rPt->SetMarkerColor(cC);
116  rPt->SetDirectory(0);
117 
118  if (!pt) {
119  pt = static_cast<TH2D*>(Make2D(0, "pt", "pt weights",
120  kBlack, 20, *(nC->GetXaxis()),
121  *(nPt->GetXaxis())));
122  pt->SetDirectory(0);
123  }
124  for (Int_t p = 1; p <= rPt->GetNbinsX(); p++) {
125  pt->SetBinContent(b, p, rPt->GetBinContent(p));
126  pt->SetBinError (b, p, rPt->GetBinError (p));
127  }
128  // nPt->SetMarkerColor(kRed); pt->Add(nPt);
129  // dPt->SetMarkerColor(kBlue); pt->Add(dPt);
130  // pt->Add(nPt2->ProjectionY());
131  // pt->Add(dPt2->ProjectionY());
132  delete nPt;
133  delete dPt;
134 
135  TH2* nPdg2 = GetH2(nG, "etaPdg");
136  TH2* dPdg2 = GetH2(dG, "etaPdg");
137  if (!nPdg2 || !dPdg2) continue;
138  if (!CheckConsistency(nPdg2,dPdg2)) continue;
139 
140  for (Int_t p = 1; p <= nPdg2->GetNbinsY(); p++) {
141  TString sPdg = nPdg2->GetYaxis()->GetBinLabel(p);
142  Int_t iPdg = sPdg.Atoi();
143  if (iPdg < 0) continue;
144 
145  TH1* nPdg = nPdg2->ProjectionX("ntmp", p, p);
146  TH1* dPdg = dPdg2->ProjectionX("dtmp", p, p);
147  if (!nPdg || !dPdg) continue;
148 
149  TH1* rPdg =
150  static_cast<TH1*>(nPdg->Clone(Form("r%s_%s",cN,sPdg.Data())));
151  rPdg->Divide(dPdg);
152  rPdg->SetDirectory(0);
153  if (rPdg->GetEntries() < 1) {
154  delete nPdg;
155  delete dPdg;
156  delete rPdg;
157  continue;
158  }
159 
160  TF1* fPdg = new TF1("fPdg", "pol0", -5, .5);
161  rPdg->Fit(fPdg, "NQR", "", -.5, +.5);
162 
163  TH1* hPdg = static_cast<TH1*>(pdg->FindObject(sPdg));
164  if (!hPdg) {
165  TString tmp;
166  Color_t c;
167  Style_t s;
168  PdgAttr(iPdg, tmp, c, s);
169  hPdg = Make1D(pdg,sPdg, tmp, c, s, *(nC->GetXaxis()));
170  hPdg->SetBinContent(0, iPdg);
171  }
172  hPdg->SetBinContent(b, fPdg->GetParameter(0));
173  hPdg->SetBinError (b, fPdg->GetParError (0));
174 
175  delete nPdg;
176  delete dPdg;
177  delete rPdg;
178  delete fPdg;
179  }
180 
181  }
182  pt->Draw("colz");
183  // pdg->Draw("nostack");
184 
186  w->SetPtWeight(pt);
187  TIter next(pdg);
188  TH1D* hPdg = 0;
189  while ((hPdg = static_cast<TH1D*>(next()))) {
190  Int_t iPdg = hPdg->GetBinContent(0);
191  hPdg->SetBinContent(0, 0);
192  w->AddAbundanceWeight(iPdg, hPdg);
193  }
194  TCanvas* c = new TCanvas("c","c");
195  w->Draw();
196 
197  TFile* out = TFile::Open(oN, "RECREATE");
198  w->Write();
199  out->Write();
200 
201  }
202 };
Int_t pdg
static void PdgAttr(Int_t pdg, TString &nme, Color_t &c, Style_t &s)
static TH2 * Make2D(Container *c, const TString &name, const TString &title, Color_t color, Style_t style, const TAxis &xAxis, const TAxis &yAxis)
const Color_t cc[]
Definition: DrawKs.C:1
double Double_t
Definition: External.C:58
Bool_t AddAbundanceWeight(Short_t pdg, const TH1D *h, UShort_t mode=0)
static TH1 * GetH1(Container *parent, const char *name, Bool_t verb=true)
const char * CentName(Double_t c1, Double_t c2)
Definition: PureMCWeights.C:40
TCanvas * c
Definition: TestFitELoss.C:172
void Draw(Option_t *option="")
static Bool_t CheckConsistency(const TH1 *h1, const TH1 *h2)
Utilities for midrapidity analysis.
int Int_t
Definition: External.C:63
Encode simulation weights for 2nd pass.
Definition: External.C:228
Definition: External.C:212
Bool_t SetPtWeight(const TH2D *h, UShort_t mode=0)
static TH2 * GetH2(Container *parent, const char *name, Bool_t verb=true)
Definition: External.C:220
static Container * GetC(Container *parent, const char *name, Bool_t verb=true)
static TH1 * Make1D(Container *c, const TString &name, const TString &title, Color_t color, Style_t style, const TAxis &xAxis)
void Run(const char *nFile, const char *dFile, const char *oFile=0)
Definition: PureMCWeights.C:54
Definition: External.C:196