]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/FORWARD/analysis2/AliMCTruthdNdetaTask.cxx
Better trigger histogram
[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()
18 : AliBasedNdetaTask()
19{
20 //
21 // Constructor
22 //
23}
24
25//____________________________________________________________________
26AliMCTruthdNdetaTask::AliMCTruthdNdetaTask(const char* /* name */)
27 : AliBasedNdetaTask("MCTruth")
28{
29 //
30 // Constructor
31 //
32 // Paramters
33 // name Name of task
34}
35
36//____________________________________________________________________
37AliMCTruthdNdetaTask::AliMCTruthdNdetaTask(const AliMCTruthdNdetaTask& o)
38 : AliBasedNdetaTask(o)
39{
40 //
41 // Copy constructor
42 //
43}
44
45//____________________________________________________________________
46AliBasedNdetaTask::CentralityBin*
47AliMCTruthdNdetaTask::MakeCentralityBin(const char* name, Short_t l, Short_t h)
48 const
49{
50 //
51 // Make a new centrality bin
52 //
53 // Parameters:
54 // name Histogram names
55 // l Lower cut
56 // h Upper cut
57 //
58 // Return:
59 // Newly allocated object (of our type)
60 //
61 return new AliMCTruthdNdetaTask::CentralityBin(name, l, h);
62}
63
64//____________________________________________________________________
65TH2D*
66AliMCTruthdNdetaTask::GetHistogram(const AliAODEvent* aod, Bool_t mc)
67{
68 //
69 // Retrieve the histogram
70 //
71 // Parameters:
72 // aod AOD event
73 // mc Whether to get the MC histogram or not
74 //
75 // Return:
76 // Retrieved histogram or null
77 //
78 if (mc) return 0;
79 TObject* obj = aod->FindListObject("primary");
80 // We should have a forward object at least
81 if (!obj) return 0;
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);
86 return ret;
87}
88
89//________________________________________________________________________
90void
91AliMCTruthdNdetaTask::Terminate(Option_t *option)
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 AliBasedNdetaTask::Terminate(option);
101
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");
105
106 TIter next(fListOfCentralities);
107 CentralityBin* bin = 0;
108 while ((bin = static_cast<CentralityBin*>(next()))) {
109 if (fCentAxis && bin->IsAllBin()) continue;
110
111 TList* results = bin->GetResults();
112 if (!results) continue;
113
114 TH1* dndeta = static_cast<TH1*>(results->FindObject("dndetaTruth"));
115 TH1* dndetaRebin =
116 static_cast<TH1*>(results->FindObject(Form("dndetaTruth_rebin%02d",
117 fRebin)));
118 if (dndeta) truth->Add(dndeta);
119 if (dndetaRebin) truthRebin->Add(dndetaRebin);
120 }
121 // If available output rebinned stack
122 if (!truth->GetHists() ||
123 truth->GetHists()->GetEntries() <= 0) {
124 AliWarning("No MC truth histograms found");
125 delete truth;
126 truth = 0;
127 }
128 if (truth) fOutput->Add(truth);
129
130 // If available output rebinned stack
131 if (!truthRebin->GetHists() ||
132 truthRebin->GetHists()->GetEntries() <= 0) {
133 AliWarning("No rebinned MC truth histograms found");
134 delete truthRebin;
135 truthRebin = 0;
136 }
137 if (truthRebin) fOutput->Add(truthRebin);
138}
139
140//========================================================================
141void
142AliMCTruthdNdetaTask::CentralityBin::ProcessEvent(const AliAODForwardMult*
143 forward,
144 Int_t triggerMask,
145 Bool_t isZero,
146 Double_t vzMin,
147 Double_t vzMax,
148 const TH2D* primary,
149 const TH2D*)
150{
151 // Check the centrality class unless this is the 'all' bin
152 if (!primary) return;
153
154 if (!IsAllBin()) {
155 Double_t centrality = forward->GetCentrality();
156 if (centrality < fLow || centrality >= fHigh) return;
157 }
158
159 if (!fSum) CreateSums(primary, 0);
160 if (!fSumTruth) {
161 fSumTruth = static_cast<TH2D*>(primary->Clone("truth"));
162 fSumTruth->SetDirectory(0);
163 fSumTruth->Reset();
164 fSums->Add(fSumTruth);
165 }
166
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;
172 }
173
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);
177
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);
181 }
182
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);
186}
187
188//________________________________________________________________________
189void
190AliMCTruthdNdetaTask::CentralityBin::End(TList* sums,
191 TList* results,
192 UShort_t scheme,
f67d699c 193 const TH2F* shapeCorr,
9ecab72f 194 Double_t trigEff,
66cf95f2 195 Double_t trigEff0,
9ecab72f 196 Bool_t symmetrice,
197 Int_t rebin,
198 Bool_t rootProj,
199 Bool_t corrEmpty,
200 Bool_t cutEdges,
201 Int_t triggerMask,
202 Int_t marker,
c89b9ac1 203 Int_t color,
204 TList* mclist,
205 TList* truthlist)
9ecab72f 206{
207#if 0
208 AliInfo(Form("At end with sums=%p, results=%p, scheme=%d, "
209 "shapeCorr=%p, trigEff=%f, symmetrice=%d, rebin=%d, "
210 "rootProj=%d, corrEmpty=%d, cutEdges=%d, triggerMask=0x%08x, "
211 "marker=%d (%d)",
66cf95f2 212 sums, results, scheme, shapeCorr, trigEff, trigEff0, symmetrice,
9ecab72f 213 rebin, rootProj, corrEmpty, cutEdges, triggerMask, marker,
214 GetMarkerStyle(kStar)));
215#endif
216
217 AliBasedNdetaTask::CentralityBin::End(sums, results, scheme,
66cf95f2 218 shapeCorr, trigEff, trigEff0,
9ecab72f 219 symmetrice, rebin,
220 rootProj, corrEmpty, cutEdges,
f7cfc454 221 triggerMask, marker, color, mclist,
222 truthlist);
9ecab72f 223
224 fSumTruth = static_cast<TH2D*>(fSums->FindObject("truth"));
225
226
227 if (fSumTruth) {
f7cfc454 228 Int_t n0 = Int_t(fSumTruth->GetBinContent(0,0));
9ecab72f 229 Int_t n = (triggerMask == AliAODForwardMult::kNSD ?
230 Int_t(fTriggers->GetBinContent(AliAODForwardMult::kBinMCNSD)) :
231 Int_t(fTriggers->GetBinContent(AliAODForwardMult::kBinAll)));
232 AliInfo(Form("Normalising MC truth to %d (%d additions)", n, n0));
233
234 TH1D* dndetaTruth = fSumTruth->ProjectionX("dndetaTruth",1,
235 fSumTruth->GetNbinsY(),"e");
236 dndetaTruth->SetDirectory(0);
237 dndetaTruth->Scale(1./n, "width");
238
239 SetHistogramAttributes(dndetaTruth, GetColor(color)+1,
240 GetMarkerStyle(kCross),
241 "Monte-Carlo truth");
242
243 fOutput->Add(dndetaTruth);
244 fOutput->Add(Rebin(dndetaTruth, rebin, cutEdges));
245 }
246 TH1* dndeta = GetResult(0, false, "");
247 TH1* dndetaSym = GetResult(0, true, "");
248 TH1* dndeta_rebin = GetResult(rebin, false, "");
249 TH1* dndetaSym_rebin = GetResult(rebin, true, "");
250 if (dndeta)
251 dndeta->SetTitle("Monte-Carlo truth (selected)");
252 if (dndetaSym)
253 dndetaSym->SetTitle("Monte-Carlo truth (selected,mirrored)");
254 if (dndeta_rebin)
255 dndeta_rebin->SetTitle("Monte-Carlo truth (selected)");
256 if (dndetaSym_rebin)
257 dndetaSym_rebin->SetTitle("Monte-Carlo truth (selected,mirrored)");
258
259}
260
261//________________________________________________________________________
262//
263// EOF
264//