]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/FORWARD/analysis2/AliMCTruthdNdetaTask.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / AliMCTruthdNdetaTask.cxx
CommitLineData
9ecab72f 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//____________________________________________________________________
17AliMCTruthdNdetaTask::AliMCTruthdNdetaTask()
786db950 18 : AliBasedNdetaTask(),
19 fHasData(true)
9ecab72f 20{
21 //
22 // Constructor
23 //
24}
25
26//____________________________________________________________________
27AliMCTruthdNdetaTask::AliMCTruthdNdetaTask(const char* /* name */)
786db950 28 : AliBasedNdetaTask("MCTruth"),
29 fHasData(true)
9ecab72f 30{
31 //
32 // Constructor
33 //
34 // Paramters
35 // name Name of task
36}
37
9ecab72f 38
39//____________________________________________________________________
40AliBasedNdetaTask::CentralityBin*
41AliMCTruthdNdetaTask::MakeCentralityBin(const char* name, Short_t l, Short_t h)
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//____________________________________________________________________
59TH2D*
c8b1a7db 60AliMCTruthdNdetaTask::GetHistogram(const AliAODEvent& aod, Bool_t mc)
9ecab72f 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 //
786db950 72 if (!fHasData) return 0;
9ecab72f 73 if (mc) return 0;
c8b1a7db 74
75 TH2D* ret = GetPrimary(aod);
76 if (!ret) {
786db950 77 fHasData = false;
78 return 0;
79 }
808d97d9 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 }
9ecab72f 86 return ret;
87}
88
89//________________________________________________________________________
c8b1a7db 90Bool_t
91AliMCTruthdNdetaTask::Finalize()
9ecab72f 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
786db950 100 if (!fHasData) {
101 AliInfo("The MC truth dN/deta task didn't get any data");
c8b1a7db 102 return false;
786db950 103 }
c8b1a7db 104 AliBasedNdetaTask::Finalize();
9ecab72f 105
5f2f85f0 106 THStack* truth = new THStack("dndetaTruth", "dN/d#eta MC Truth");
107 CentralityBin* bin = 0;
108 TIter next(fListOfCentralities);
9ecab72f 109 while ((bin = static_cast<CentralityBin*>(next()))) {
c8b1a7db 110 if (HasCentrality() && bin->IsAllBin()) continue;
9ecab72f 111
112 TList* results = bin->GetResults();
113 if (!results) continue;
114
115 TH1* dndeta = static_cast<TH1*>(results->FindObject("dndetaTruth"));
9ecab72f 116 if (dndeta) truth->Add(dndeta);
9ecab72f 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 }
c8b1a7db 125 if (truth) fResults->Add(truth);
9ecab72f 126
c8b1a7db 127 return true;
9ecab72f 128}
129
130//========================================================================
bfab35d9 131Bool_t
9ecab72f 132AliMCTruthdNdetaTask::CentralityBin::ProcessEvent(const AliAODForwardMult*
133 forward,
134 Int_t triggerMask,
135 Bool_t isZero,
136 Double_t vzMin,
137 Double_t vzMax,
138 const TH2D* primary,
5f2f85f0 139 const TH2D*,
140 Bool_t checkPileup)
9ecab72f 141{
142 // Check the centrality class unless this is the 'all' bin
bfab35d9 143 if (!primary) return false;
9ecab72f 144
145 if (!IsAllBin()) {
146 Double_t centrality = forward->GetCentrality();
bfab35d9 147 if (centrality < fLow || centrality >= fHigh) return false;
9ecab72f 148 }
149
150 if (!fSum) CreateSums(primary, 0);
151 if (!fSumTruth) {
152 fSumTruth = static_cast<TH2D*>(primary->Clone("truth"));
153 fSumTruth->SetDirectory(0);
154 fSumTruth->Reset();
155 fSums->Add(fSumTruth);
156 }
157
158 // translate real trigger mask to MC trigger mask
159 Int_t mask = AliAODForwardMult::kB;
160 if (triggerMask == AliAODForwardMult::kNSD) {
161 mask ^= AliAODForwardMult::kNSD;
162 mask = AliAODForwardMult::kMCNSD;
163 }
164
165 // Now use our normal check, but with the new mask, except ignore vertex
5f2f85f0 166 if (forward->CheckEvent(mask, -10000, -10000, 0, 0, 0, 0, checkPileup)) {
9ecab72f 167 fSumTruth->Add(primary);
168
169 // Store event count in left-most under- underflow bin
170 Int_t cnt = Int_t(fSumTruth->GetBinContent(0,0));
171 fSumTruth->SetBinContent(0,0, ++cnt);
172 }
173
174 // Now use our normal check with the full trigger mask and vertex
5f2f85f0 175 if (CheckEvent(forward, triggerMask, vzMin, vzMax, checkPileup))
9ecab72f 176 fSum->Add(primary, isZero);
bfab35d9 177 return true;
9ecab72f 178}
179
180//________________________________________________________________________
181void
182AliMCTruthdNdetaTask::CentralityBin::End(TList* sums,
183 TList* results,
184 UShort_t scheme,
9ecab72f 185 Double_t trigEff,
66cf95f2 186 Double_t trigEff0,
9ecab72f 187 Bool_t rootProj,
188 Bool_t corrEmpty,
9ecab72f 189 Int_t triggerMask,
190 Int_t marker,
c89b9ac1 191 Int_t color,
192 TList* mclist,
193 TList* truthlist)
9ecab72f 194{
195#if 0
196 AliInfo(Form("At end with sums=%p, results=%p, scheme=%d, "
197 "shapeCorr=%p, trigEff=%f, symmetrice=%d, rebin=%d, "
198 "rootProj=%d, corrEmpty=%d, cutEdges=%d, triggerMask=0x%08x, "
199 "marker=%d (%d)",
66cf95f2 200 sums, results, scheme, shapeCorr, trigEff, trigEff0, symmetrice,
9ecab72f 201 rebin, rootProj, corrEmpty, cutEdges, triggerMask, marker,
202 GetMarkerStyle(kStar)));
203#endif
204
5f2f85f0 205 AliBasedNdetaTask::CentralityBin::End(sums, results, scheme, trigEff,
206 trigEff0, rootProj, corrEmpty,
f7cfc454 207 triggerMask, marker, color, mclist,
208 truthlist);
9ecab72f 209
210 fSumTruth = static_cast<TH2D*>(fSums->FindObject("truth"));
211
212
213 if (fSumTruth) {
f7cfc454 214 Int_t n0 = Int_t(fSumTruth->GetBinContent(0,0));
9ecab72f 215 Int_t n = (triggerMask == AliAODForwardMult::kNSD ?
216 Int_t(fTriggers->GetBinContent(AliAODForwardMult::kBinMCNSD)) :
217 Int_t(fTriggers->GetBinContent(AliAODForwardMult::kBinAll)));
c8b1a7db 218 DMSG(fDebug,0,"Normalising MC truth to %d (%d additions)", n, n0);
9ecab72f 219
220 TH1D* dndetaTruth = fSumTruth->ProjectionX("dndetaTruth",1,
221 fSumTruth->GetNbinsY(),"e");
222 dndetaTruth->SetDirectory(0);
223 dndetaTruth->Scale(1./n, "width");
224
225 SetHistogramAttributes(dndetaTruth, GetColor(color)+1,
226 GetMarkerStyle(kCross),
227 "Monte-Carlo truth");
228
229 fOutput->Add(dndetaTruth);
9ecab72f 230 }
5f2f85f0 231 TH1* dndeta = GetResult("");
9ecab72f 232 if (dndeta)
233 dndeta->SetTitle("Monte-Carlo truth (selected)");
9ecab72f 234}
235
236//________________________________________________________________________
237//
238// EOF
239//