1 //====================================================================
2 #include "AliForwarddNdetaTask.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 AliForwarddNdetaTask::AliForwarddNdetaTask()
25 //____________________________________________________________________
26 AliForwarddNdetaTask::AliForwarddNdetaTask(const char* /* name */)
27 : AliBasedNdetaTask("Forward")
36 //____________________________________________________________________
37 AliForwarddNdetaTask::AliForwarddNdetaTask(const AliForwarddNdetaTask& o)
38 : AliBasedNdetaTask(o)
45 //____________________________________________________________________
46 AliBasedNdetaTask::CentralityBin*
47 AliForwarddNdetaTask::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 AliForwarddNdetaTask::CentralityBin(name, l, h);
64 //____________________________________________________________________
66 AliForwarddNdetaTask::UserExec(Option_t* option)
69 // Called at each event
71 // This is called once in the master
76 AliBasedNdetaTask::UserExec(option);
78 AliAODEvent* aod = dynamic_cast<AliAODEvent*>(InputEvent());
80 AliError("Cannot get the AOD event");
84 TObject* obj = aod->FindListObject("Forward");
86 AliWarning("No forward object found");
89 AliAODForwardMult* forward = static_cast<AliAODForwardMult*>(obj);
91 TObject* oPrimary = aod->FindListObject("primary");
92 if (!oPrimary) return;
94 TH2D* primary = static_cast<TH2D*>(oPrimary);
96 // Loop over centrality bins
97 TIter next(fListOfCentralities);
98 CentralityBin* bin = 0;
99 while ((bin = static_cast<CentralityBin*>(next())))
100 bin->ProcessPrimary(forward, fTriggerMask, fVtxMin, fVtxMax, primary);
103 //________________________________________________________________________
105 AliForwarddNdetaTask::Terminate(Option_t *option)
108 // Called at end of event processing..
110 // This is called once in the master
114 AliBasedNdetaTask::Terminate(option);
116 THStack* truth = new THStack("dndetaTruth", "dN/d#eta MC Truth");
117 THStack* truthRebin = new THStack(Form("dndetaTruth_rebin%02d", fRebin),
118 "dN/d#eta MC Truth");
120 TIter next(fListOfCentralities);
121 CentralityBin* bin = 0;
122 while ((bin = static_cast<CentralityBin*>(next()))) {
123 if (fCentAxis && bin->IsAllBin()) continue;
125 TList* results = bin->GetResults();
126 if (!results) continue;
128 TH1* dndeta = static_cast<TH1*>(results->FindObject("dndetaTruth"));
130 static_cast<TH1*>(results->FindObject(Form("dndetaTruth_rebin%02d",
132 if (dndeta) truth->Add(dndeta);
133 if (dndetaRebin) truthRebin->Add(dndetaRebin);
135 // If available output rebinned stack
136 if (!truth->GetHists() ||
137 truth->GetHists()->GetEntries() <= 0) {
138 AliWarning("No MC truth histograms found");
142 if (truth) fOutput->Add(truth);
144 // If available output rebinned stack
145 if (!truthRebin->GetHists() ||
146 truthRebin->GetHists()->GetEntries() <= 0) {
147 AliWarning("No rebinned MC truth histograms found");
151 if (truthRebin) fOutput->Add(truthRebin);
155 //____________________________________________________________________
157 AliForwarddNdetaTask::GetHistogram(const AliAODEvent* aod, Bool_t mc)
160 // Retrieve the histogram
164 // mc Whether to get the MC histogram or not
167 // Retrieved histogram or null
170 if (mc) obj = aod->FindListObject("ForwardMC");
171 else obj = aod->FindListObject("Forward");
173 // We should have a forward object at least
175 if (!mc) AliWarning("No Forward object found AOD");
178 AliAODForwardMult* forward = static_cast<AliAODForwardMult*>(obj);
179 return &(forward->GetHistogram());
182 //========================================================================
184 AliForwarddNdetaTask::CentralityBin::ProcessPrimary(const AliAODForwardMult*
191 // Check the centrality class unless this is the 'all' bin
193 Double_t centrality = forward->GetCentrality();
194 if (centrality < fLow || centrality >= fHigh) return;
197 // Create sum histogram
199 fSumPrimary = static_cast<TH2D*>(primary->Clone("truth"));
200 fSumPrimary->SetDirectory(0);
201 fSumPrimary->Reset();
202 fSums->Add(fSumPrimary);
205 // translate real trigger mask to MC trigger mask
206 Int_t mask = AliAODForwardMult::kB;
207 if (triggerMask == AliAODForwardMult::kNSD) {
208 mask ^= AliAODForwardMult::kNSD;
209 mask = AliAODForwardMult::kMCNSD;
212 // Now use our normal check, but with the new mask, except
213 vzMin = vzMax = -10000; // ignore vertex
214 if (!forward->CheckEvent(mask, vzMin, vzMax, 0, 0, 0)) return;
216 fSumPrimary->Add(primary);
217 Int_t n = Int_t(fSumPrimary->GetBinContent(0,0));
218 fSumPrimary->SetBinContent(0,0, ++n);
221 //________________________________________________________________________
223 AliForwarddNdetaTask::CentralityBin::End(TList* sums,
226 const TH1* shapeCorr,
236 AliInfo(Form("In End of %s with corrEmpty=%d, cutEdges=%d, rootProj=%d",
237 GetName(), corrEmpty, cutEdges, rootProj));
238 AliBasedNdetaTask::CentralityBin::End(sums, results, scheme,
241 rootProj, corrEmpty, cutEdges,
242 triggerMask, marker);
244 fSumPrimary = static_cast<TH2D*>(fSums->FindObject("truth"));
248 Int_t n = fSumPrimary->GetBinContent(0,0);
250 Int_t n = (triggerMask == AliAODForwardMult::kNSD ?
251 Int_t(fTriggers->GetBinContent(AliAODForwardMult::kBinMCNSD)) :
252 Int_t(fTriggers->GetBinContent(AliAODForwardMult::kBinAll)));
254 AliInfo(Form("Normalising MC truth to %d", n));
256 TH1D* dndetaTruth = fSumPrimary->ProjectionX("dndetaTruth",1,
257 fSumPrimary->GetNbinsY(),"e");
258 dndetaTruth->SetDirectory(0);
259 dndetaTruth->Scale(1./n, "width");
262 SetHistogramAttributes(dndetaTruth, GetColor(), 30, "Monte-Carlo truth");
264 fOutput->Add(dndetaTruth);
265 fOutput->Add(Rebin(dndetaTruth, rebin, cutEdges));
267 // Get analysis result, and form ratio
268 TH1D* dndeta = static_cast<TH1D*>(fOutput->FindObject(Form("dndeta%s",
271 AliWarning(Form("No dndeta%s in the list %s",
272 GetName(), fOutput->GetName()));
275 TH1D* ratio = static_cast<TH1D*>(dndeta->Clone("ratio"));
276 ratio->SetDirectory(0);
277 ratio->Divide(dndetaTruth);
280 fOutput->Add(Rebin(ratio, rebin, cutEdges));
284 if (!IsAllBin()) return;
285 TFile* file = TFile::Open("forward.root", "READ");
288 TList* forward = static_cast<TList*>(file->Get("Forward"));
290 AliError("List Forward not found in forward.root");
293 TList* rings = static_cast<TList*>(forward->FindObject("ringResults"));
295 AliError("List ringResults not found in forward.root");
298 THStack* res = static_cast<THStack*>(rings->FindObject("all"));
300 AliError(Form("Stack all not found in %s", rings->GetName()));
304 AliError("Triggers histogram not set");
308 Double_t epsilonT = trigEff;
310 if (triggerMask == AliAODForwardMult::kNSD) {
311 // This is a local change
313 AliWarning(Form("Using hard-coded NSD trigger efficiency of %f",epsilonT));
315 AliInfo("Adding per-ring histograms to output");
316 Double_t scaler = Normalization(*fTriggers, scheme, epsilonT, ntotal);
317 TIter next(res->GetHists());
319 while ((hist = static_cast<TH1*>(next()))) hist->Scale(scaler);
320 res->SetName("dndetaRings");
324 //________________________________________________________________________