AliPhysics  bba8f44 (bba8f44)
AliMCTruthdNdetaTask.cxx
Go to the documentation of this file.
1 //====================================================================
2 #include "AliMCTruthdNdetaTask.h"
3 #include <TMath.h>
4 #include <TH2D.h>
5 #include <TH1D.h>
6 #include <THStack.h>
7 #include <TList.h>
8 #include <TFile.h>
9 #include <AliAnalysisManager.h>
10 #include <AliAODEvent.h>
11 #include <AliAODHandler.h>
12 #include <AliAODInputHandler.h>
13 #include "AliForwardUtil.h"
14 #include "AliAODForwardMult.h"
15 
16 //____________________________________________________________________
19  fHasData(true)
20 {
21  //
22  // Constructor
23  //
24 }
25 
26 //____________________________________________________________________
28  : AliBasedNdetaTask("MCTruth"),
29  fHasData(true)
30 {
31  //
32  // Constructor
33  //
34  // Paramters
35  // name Name of task
36 }
37 
38 
39 //____________________________________________________________________
42  const
43 {
44  //
45  // Make a new centrality bin
46  //
47  // Parameters:
48  // name Histogram names
49  // l Lower cut
50  // h Upper cut
51  //
52  // Return:
53  // Newly allocated object (of our type)
54  //
55  return new AliMCTruthdNdetaTask::CentralityBin(name, l, h);
56 }
57 
58 //____________________________________________________________________
59 TH2D*
61 {
62  //
63  // Retrieve the histogram
64  //
65  // Parameters:
66  // aod AOD event
67  // mc Whether to get the MC histogram or not
68  //
69  // Return:
70  // Retrieved histogram or null
71  //
72  if (!fHasData) return 0;
73  if (mc) return 0;
74 
75  TH2D* ret = GetPrimary(aod);
76  if (!ret) {
77  fHasData = false;
78  return 0;
79  }
80  Int_t nY = ret->GetNbinsY();
81  // Need to fill under-/overflow bin with 1's
82  for (Int_t i = 1; i <= ret->GetNbinsX(); i++) {
83  ret->SetBinContent(i, 0, 1);
84  ret->SetBinContent(i, nY+1, 1);
85  }
86  return ret;
87 }
88 
89 //________________________________________________________________________
90 Bool_t
92 {
93  //
94  // Called at end of event processing..
95  //
96  // This is called once in the master
97  //
98  // Parameters:
99  // option Not used
100  if (!fHasData) {
101  AliInfo("The MC truth dN/deta task didn't get any data");
102  return false;
103  }
105 
106  THStack* truth = new THStack("dndetaTruth", "dN/d#eta MC Truth");
107  CentralityBin* bin = 0;
108  TIter next(fListOfCentralities);
109  while ((bin = static_cast<CentralityBin*>(next()))) {
110  if (HasCentrality() && bin->IsAllBin()) continue;
111 
112  TList* results = bin->GetResults();
113  if (!results) continue;
114 
115  TH1* dndeta = static_cast<TH1*>(results->FindObject("dndetaTruth"));
116  if (dndeta) truth->Add(dndeta);
117  }
118  // If available output rebinned stack
119  if (!truth->GetHists() ||
120  truth->GetHists()->GetEntries() <= 0) {
121  AliWarning("No MC truth histograms found");
122  delete truth;
123  truth = 0;
124  }
125  if (truth) fResults->Add(truth);
126 
127  return true;
128 }
129 
130 //========================================================================
131 Bool_t
133  forward,
134  UInt_t triggerMask,
135  Bool_t isZero,
136  Double_t vzMin,
137  Double_t vzMax,
138  const TH2D* primary,
139  const TH2D*,
140  UInt_t filter,
141  Double_t weight)
142 {
143  // Check the centrality class unless this is the 'all' bin
144  if (!primary) return false;
145 
146  if (!IsAllBin()) {
147  Double_t centrality = forward->GetCentrality();
148  if (centrality < fLow || centrality >= fHigh) return false;
149  }
150 
151  if (!fSum) CreateSums(primary, 0);
152  if (!fSumTruth) {
153  fSumTruth = static_cast<TH2D*>(primary->Clone("truth"));
154  fSumTruth->SetDirectory(0);
155  fSumTruth->Reset();
156  fSums->Add(fSumTruth);
157  }
158 
159  // translate real trigger mask to MC trigger mask
161  if (triggerMask == AliAODForwardMult::kNSD) {
162  mask ^= AliAODForwardMult::kNSD;
164  }
165 
166  // Now use our normal check, but with the new mask, except ignore vertex
167  if (forward->CheckEvent(mask, -10000, -10000, 0, 0, 0, 0, filter)) {
168  fSumTruth->Add(primary, weight);
169 
170  // Store event count in left-most under- underflow bin
171  Int_t cnt = Int_t(fSumTruth->GetBinContent(0,0));
172  fSumTruth->SetBinContent(0,0, ++cnt);
173  }
174 
175  // Now use our normal check with the full trigger mask and vertex
176  if (CheckEvent(forward, triggerMask, vzMin, vzMax, filter))
177  fSum->Add(primary, isZero, weight);
178  return true;
179 }
180 
181 //________________________________________________________________________
182 bool
184  TList* results,
185  UShort_t scheme,
186  Double_t trigEff,
187  Double_t trigEff0,
188  Bool_t rootProj,
189  Bool_t corrEmpty,
190  Int_t triggerMask,
191  Int_t marker,
192  Int_t color,
193  TList* mclist,
194  TList* truthlist)
195 {
196 #if 0
197  AliInfo(Form("At end with sums=%p, results=%p, scheme=%d, "
198  "shapeCorr=%p, trigEff=%f, symmetrice=%d, rebin=%d, "
199  "rootProj=%d, corrEmpty=%d, cutEdges=%d, triggerMask=0x%08x, "
200  "marker=%d (%d)",
201  sums, results, scheme, shapeCorr, trigEff, trigEff0, symmetrice,
202  rebin, rootProj, corrEmpty, cutEdges, triggerMask, marker,
204 #endif
205 
206  if (!AliBasedNdetaTask::CentralityBin::End(sums, results, scheme, trigEff,
207  trigEff0, rootProj, corrEmpty,
208  triggerMask,
209  marker, color, mclist,
210  truthlist))
211  return false;
212 
213  fSumTruth = static_cast<TH2D*>(fSums->FindObject("truth"));
214 
215 
216  if (fSumTruth) {
217  Int_t n0 = Int_t(fSumTruth->GetBinContent(0,0));
218  Int_t n = (triggerMask == AliAODForwardMult::kNSD ?
219  Int_t(fTriggers->GetBinContent(AliAODForwardMult::kBinMCNSD)) :
220  Int_t(fTriggers->GetBinContent(AliAODForwardMult::kBinAll)));
221  DMSG(fDebug,0,"Normalising MC truth to %d (%d additions)", n, n0);
222 
223  TH1D* dndetaTruth = fSumTruth->ProjectionX("dndetaTruth",1,
224  fSumTruth->GetNbinsY(),"e");
225  dndetaTruth->SetDirectory(0);
226  dndetaTruth->Scale(1./n, "width");
227 
228  SetHistogramAttributes(dndetaTruth, GetColor(color)+1,
230  "Monte-Carlo truth");
231 
232  fOutput->Add(dndetaTruth);
233  }
234  TH1* dndeta = GetResult("");
235  if (dndeta)
236  dndeta->SetTitle("Monte-Carlo truth (selected)");
237  return true;
238 }
239 
240 //________________________________________________________________________
241 //
242 // EOF
243 //
Int_t color[]
print message on plot with ok/not ok
virtual Bool_t ProcessEvent(const AliAODForwardMult *forward, UInt_t triggerMask, Bool_t isZero, Double_t vzMin, Double_t vzMax, const TH2D *data, const TH2D *mc, UInt_t filter, Double_t weight)
double Double_t
Definition: External.C:58
centrality
#define DMSG(L, N, F,...)
virtual bool End(TList *sums, TList *results, UShort_t scheme, Double_t trigEff, Double_t trigEff0, Bool_t rootProj, Bool_t corrEmpty, Int_t triggerMask, Int_t marker, Int_t color, TList *mclist, TList *truthlist)
TH2D * GetHistogram(const AliAODEvent &aod, Bool_t mc)
AliBasedNdetaTask::CentralityBin * MakeCentralityBin(const char *name, Float_t l, Float_t h) const
static Int_t GetMarkerStyle(UShort_t bits)
virtual Bool_t Finalize()
Per-event per bin.
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
float Float_t
Definition: External.C:68
Various utilities used in PWGLF/FORWARD.
Definition: External.C:228
Definition: External.C:212
TObjArray * fListOfCentralities
virtual Int_t GetColor() const
virtual bool End(TList *sums, TList *results, UShort_t scheme, Double_t trigEff, Double_t trigEff0, Bool_t rootProj, Bool_t corrEmpty, Int_t triggerMask, Int_t marker, Int_t color, TList *mclist, TList *truthlist)
Int_t rebin
unsigned short UShort_t
Definition: External.C:28
virtual Bool_t CheckEvent(const AliAODForwardMult &forward)
Float_t GetCentrality() const
TH2D * GetPrimary(const AliAODEvent &aod)
bool Bool_t
Definition: External.C:53
Bool_t CheckEvent(UInt_t triggerMask=kInel, Double_t vzMin=-10, Double_t vzMax=10, Double_t cMin=0, Double_t cMax=100, TH1 *hist=0, TH1 *status=0, UInt_t filterMask=kDefaultFilter) const
Definition: External.C:196
Bool_t HasCentrality() const
static void SetHistogramAttributes(TH1D *h, Int_t colour, Int_t marker, const char *title, const char *ytitle=0)