1 //====================================================================
2 #include "AliMCTruthdNdetaTask.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"
16 //____________________________________________________________________
17 AliMCTruthdNdetaTask::AliMCTruthdNdetaTask()
25 //____________________________________________________________________
26 AliMCTruthdNdetaTask::AliMCTruthdNdetaTask(const char* /* name */)
27 : AliBasedNdetaTask("MCTruth")
36 //____________________________________________________________________
37 AliMCTruthdNdetaTask::AliMCTruthdNdetaTask(const AliMCTruthdNdetaTask& o)
38 : AliBasedNdetaTask(o)
45 //____________________________________________________________________
46 AliBasedNdetaTask::CentralityBin*
47 AliMCTruthdNdetaTask::MakeCentralityBin(const char* name, Short_t l, Short_t h)
51 // Make a new centrality bin
54 // name Histogram names
59 // Newly allocated object (of our type)
61 return new AliMCTruthdNdetaTask::CentralityBin(name, l, h);
64 //____________________________________________________________________
66 AliMCTruthdNdetaTask::GetHistogram(const AliAODEvent* aod, Bool_t mc)
69 // Retrieve the histogram
73 // mc Whether to get the MC histogram or not
76 // Retrieved histogram or null
79 TObject* obj = aod->FindListObject("primary");
80 // We should have a forward object at least
82 TH2D* ret = static_cast<TH2D*>(obj);
83 // Need to fill underflow bin with 1's
84 for (Int_t i = 1; i <= ret->GetNbinsX(); i++)
85 ret->SetBinContent(i, 0, 1);
89 //________________________________________________________________________
91 AliMCTruthdNdetaTask::Terminate(Option_t *option)
94 // Called at end of event processing..
96 // This is called once in the master
100 AliBasedNdetaTask::Terminate(option);
102 THStack* truth = new THStack("dndetaTruth", "dN/d#eta MC Truth");
103 THStack* truthRebin = new THStack(Form("dndetaTruth_rebin%02d", fRebin),
104 "dN/d#eta MC Truth");
106 TIter next(fListOfCentralities);
107 CentralityBin* bin = 0;
108 while ((bin = static_cast<CentralityBin*>(next()))) {
109 if (fCentAxis && bin->IsAllBin()) continue;
111 TList* results = bin->GetResults();
112 if (!results) continue;
114 TH1* dndeta = static_cast<TH1*>(results->FindObject("dndetaTruth"));
116 static_cast<TH1*>(results->FindObject(Form("dndetaTruth_rebin%02d",
118 if (dndeta) truth->Add(dndeta);
119 if (dndetaRebin) truthRebin->Add(dndetaRebin);
121 // If available output rebinned stack
122 if (!truth->GetHists() ||
123 truth->GetHists()->GetEntries() <= 0) {
124 AliWarning("No MC truth histograms found");
128 if (truth) fOutput->Add(truth);
130 // If available output rebinned stack
131 if (!truthRebin->GetHists() ||
132 truthRebin->GetHists()->GetEntries() <= 0) {
133 AliWarning("No rebinned MC truth histograms found");
137 if (truthRebin) fOutput->Add(truthRebin);
140 //========================================================================
142 AliMCTruthdNdetaTask::CentralityBin::ProcessEvent(const AliAODForwardMult*
151 // Check the centrality class unless this is the 'all' bin
152 if (!primary) return;
155 Double_t centrality = forward->GetCentrality();
156 if (centrality < fLow || centrality >= fHigh) return;
159 if (!fSum) CreateSums(primary, 0);
161 fSumTruth = static_cast<TH2D*>(primary->Clone("truth"));
162 fSumTruth->SetDirectory(0);
164 fSums->Add(fSumTruth);
167 // translate real trigger mask to MC trigger mask
168 Int_t mask = AliAODForwardMult::kB;
169 if (triggerMask == AliAODForwardMult::kNSD) {
170 mask ^= AliAODForwardMult::kNSD;
171 mask = AliAODForwardMult::kMCNSD;
174 // Now use our normal check, but with the new mask, except ignore vertex
175 if (forward->CheckEvent(mask, -10000, -10000, 0, 0, 0)) {
176 fSumTruth->Add(primary);
178 // Store event count in left-most under- underflow bin
179 Int_t cnt = Int_t(fSumTruth->GetBinContent(0,0));
180 fSumTruth->SetBinContent(0,0, ++cnt);
183 // Now use our normal check with the full trigger mask and vertex
184 if (CheckEvent(forward, triggerMask, vzMin, vzMax))
185 fSum->Add(primary, isZero);
188 //________________________________________________________________________
190 AliMCTruthdNdetaTask::CentralityBin::End(TList* sums,
193 const TH1* shapeCorr,
207 AliInfo(Form("At end with sums=%p, results=%p, scheme=%d, "
208 "shapeCorr=%p, trigEff=%f, symmetrice=%d, rebin=%d, "
209 "rootProj=%d, corrEmpty=%d, cutEdges=%d, triggerMask=0x%08x, "
211 sums, results, scheme, shapeCorr, trigEff, symmetrice,
212 rebin, rootProj, corrEmpty, cutEdges, triggerMask, marker,
213 GetMarkerStyle(kStar)));
216 AliBasedNdetaTask::CentralityBin::End(sums, results, scheme,
219 rootProj, corrEmpty, cutEdges,
220 triggerMask, marker, color, mclist,
223 fSumTruth = static_cast<TH2D*>(fSums->FindObject("truth"));
227 Int_t n0 = Int_t(fSumTruth->GetBinContent(0,0));
228 Int_t n = (triggerMask == AliAODForwardMult::kNSD ?
229 Int_t(fTriggers->GetBinContent(AliAODForwardMult::kBinMCNSD)) :
230 Int_t(fTriggers->GetBinContent(AliAODForwardMult::kBinAll)));
231 AliInfo(Form("Normalising MC truth to %d (%d additions)", n, n0));
233 TH1D* dndetaTruth = fSumTruth->ProjectionX("dndetaTruth",1,
234 fSumTruth->GetNbinsY(),"e");
235 dndetaTruth->SetDirectory(0);
236 dndetaTruth->Scale(1./n, "width");
238 SetHistogramAttributes(dndetaTruth, GetColor(color)+1,
239 GetMarkerStyle(kCross),
240 "Monte-Carlo truth");
242 fOutput->Add(dndetaTruth);
243 fOutput->Add(Rebin(dndetaTruth, rebin, cutEdges));
245 TH1* dndeta = GetResult(0, false, "");
246 TH1* dndetaSym = GetResult(0, true, "");
247 TH1* dndeta_rebin = GetResult(rebin, false, "");
248 TH1* dndetaSym_rebin = GetResult(rebin, true, "");
250 dndeta->SetTitle("Monte-Carlo truth (selected)");
252 dndetaSym->SetTitle("Monte-Carlo truth (selected,mirrored)");
254 dndeta_rebin->SetTitle("Monte-Carlo truth (selected)");
256 dndetaSym_rebin->SetTitle("Monte-Carlo truth (selected,mirrored)");
260 //________________________________________________________________________