AliPhysics  f05a842 (f05a842)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MakeDeltaWeights.C
Go to the documentation of this file.
1 
11 #include <TSystem.h>
12 #include "AliTrackletAODUtils.C"
13 #include "AliTrackletWeights.C"
14 
21 {
23 
24  AliTrackletDeltaWeights*Run(const char* realFileName,
25  const char* simFileName)
26  {
27  TFile* realFile = 0;
28  TFile* simFile = 0;
29  if (!(realFile = OpenFile(realFileName))) return 0;
30  if (!(simFile = OpenFile(simFileName))) return 0;
31 
32  TString outName(gSystem->BaseName(simFileName));
33  const char* base = "MidRapidity";
34  Container* realTop = GetC(realFile, Form("%sResults", base));
35  Container* simTop = GetC(simFile, Form("%sMCResults", base));
36  if (!realTop) {
37  realTop = GetC(realFile, Form("%sMCResults", base));
38  if (realTop)
39  Warning("Run","\n"
40  "*********************************************\n"
41  "* Testing MC vs. MC: *\n"
42  "* 'Data' file: %23s *\n"
43  "* Simulation file: %23s *\n"
44  "*********************************************\n",
45  realFileName, simFileName);
46  // fRealIsSim = true;
47  outName.Append("_");
48  outName.Append(gSystem->BaseName(realFileName));
49  outName.ReplaceAll(".root","");
50  }
51  outName.ReplaceAll(".root","");
52  outName.Prepend("delta_");
53  outName.Append(".root");
54 
55  TH1* realCent = GetH1(realTop, "cent");
56  TH1* simCent = GetH1(simTop, "cent");
57  TH1* realIPz = GetH1(realTop, "ipz");
58  TH1* simIPz = GetH1(simTop, "ipz");
59 
60  // Check consistency of found histograms
61  if (!CheckConsistency(realCent, simCent)) {
62  Warning("Post", "Centrality bins are incompatible, giving up");
63  return 0;
64  }
65  if (!CheckConsistency(realIPz, simIPz)) {
66  Warning("Post", "IPz bins are incompatible, giving up");
67  return 0;
68  }
69 
70  TFile* out = TFile::Open(outName, "RECREATE");
71  out->cd();
72 
73  AliTrackletDeltaWeights* weights =
74  new AliTrackletDeltaWeights("weights", "w_{#Delta}");
75  weights->SetCentAxis(*(realCent->GetXaxis()));
76  // Loop over defined centrality bins
77  for (Int_t i = 1; i <= realCent->GetNbinsX(); i++) {
78  Double_t c1 = realCent->GetXaxis()->GetBinLowEdge(i);
79  Double_t c2 = realCent->GetXaxis()->GetBinUpEdge (i);
80 
81  ProcessBin(i, c1, c2, realTop, simTop, weights);
82  }
83 
84  weights->Write();
85  out->Write();
86  Printf("Output writtten to %s", outName.Data());
87 
88  return weights;
89  }
90  void Normalize(TH3* h)
91  {
92  for (Int_t i = 1; i <= h->GetNbinsX(); i++) {
93  for (Int_t j = 1; j <= h->GetNbinsZ(); j++) {
94  // Project out delta distribution for this bin
95  TH1* tmp = h->ProjectionY(Form("%s_%02d_%02d",
96  h->GetName(), i, j),
97  i, i, j, j);
98  Double_t intg = tmp->Integral();
99  tmp->SetDirectory(0);
100  // Scale to average
101  if (intg > 1e-3) tmp->Scale(tmp->GetNbinsX()*1./intg);
102  else tmp->Reset();
103  for (Int_t k = 1; k <= h->GetNbinsY(); k++) {
104  h->SetBinContent(i, k, j, tmp->GetBinContent(k));
105  h->SetBinError (i, k, j, tmp->GetBinError (k));
106  }
107  delete tmp;
108  }
109  }
110  }
124  Double_t c1,
125  Double_t c2,
126  Container* realTop,
127  Container* simTop,
128  AliTrackletDeltaWeights* weights)
129  {
130  TString name = CentName(c1, c2);
131  Color_t color = CentColor(bin);
132  Container* realBin = GetC(realTop, name);
133  Container* simBin = GetC(simTop, name);
134  if (!realBin || !simBin) return false;
135  Container* realMeas = GetC(realBin, "measured");
136  Container* simMeas = GetC(simBin, "measured");
137  if (!realMeas || !simMeas) return false;
138  TH3* realDelta = GetH3(realMeas, "etaDeltaIPz");
139  TH3* simDelta = GetH3(simMeas, "etaDeltaIPz");
140  if (!realDelta || !simDelta) return false;
141  // Normalize(realDelta);
142  // Normalize(simDelta);
143 
144  TH3* ratio = static_cast<TH3*>(realDelta->Clone(name));
145  ratio->Divide(simDelta);
146  ratio->SetDirectory(0);
147  ratio->SetMarkerColor(color);
148  ratio->SetLineColor(color);
149  ratio->SetFillColor(color);
150  // Normalize(ratio);
151 
152  weights->SetHisto(bin, ratio);
153  return true;
154  }
155 };
156 
157 //
158 // EOF
159 //
160 
Int_t color[]
Bool_t ProcessBin(Int_t bin, Double_t c1, Double_t c2, Container *realTop, Container *simTop, AliTrackletDeltaWeights *weights)
double Double_t
Definition: External.C:58
Definition: External.C:244
static TFile * OpenFile(const char *filename)
TSystem * gSystem
static TH1 * GetH1(Container *parent, const char *name, Bool_t verb=true)
static const char * CentName(Double_t c1, Double_t c2)
static Bool_t CheckConsistency(const TH1 *h1, const TH1 *h2)
Utilities for midrapidity analysis.
void SetCentAxis(const TAxis &axis)
int Int_t
Definition: External.C:63
Encode simulation weights for 2nd pass.
static Color_t CentColor(const TAxis &axis, Double_t c1, Double_t c2)
static TH3 * GetH3(Container *parent, const char *name, Bool_t verb=true)
static Container * GetC(Container *parent, const char *name, Bool_t verb=true)
bool Bool_t
Definition: External.C:53
AliTrackletDeltaWeights * Run(const char *realFileName, const char *simFileName)
void Normalize(TH3 *h)
Definition: External.C:196
Bool_t SetHisto(Int_t bin, TH3 *h)