]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FORWARD/analysis2/AliForwarddNdetaTask.cxx
Simplify
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliForwarddNdetaTask.cxx
CommitLineData
b2e7f2d6 1//====================================================================
2#include "AliForwarddNdetaTask.h"
3#include <TMath.h>
4#include <TH2D.h>
5#include <TH1D.h>
6#include <THStack.h>
7#include <TList.h>
8#include <AliAnalysisManager.h>
9#include <AliAODEvent.h>
10#include <AliAODHandler.h>
11#include <AliAODInputHandler.h>
12#include "AliForwardUtil.h"
01caf91f 13#include "AliAODForwardMult.h"
b2e7f2d6 14
15//____________________________________________________________________
16AliForwarddNdetaTask::AliForwarddNdetaTask()
e1f47419 17 : AliBasedNdetaTask()
fb3430ac 18{
19 //
20 // Constructor
21 //
22}
b2e7f2d6 23
24//____________________________________________________________________
25AliForwarddNdetaTask::AliForwarddNdetaTask(const char* /* name */)
e1f47419 26 : AliBasedNdetaTask("Forward")
b2e7f2d6 27{
fb3430ac 28 //
29 // Constructor
30 //
31 // Paramters
32 // name Name of task
b2e7f2d6 33}
34
35//____________________________________________________________________
36AliForwarddNdetaTask::AliForwarddNdetaTask(const AliForwarddNdetaTask& o)
e1f47419 37 : AliBasedNdetaTask(o)
fb3430ac 38{
39 //
40 // Copy constructor
41 //
42}
b2e7f2d6 43
e1f47419 44//____________________________________________________________________
45AliBasedNdetaTask::CentralityBin*
46AliForwarddNdetaTask::MakeCentralityBin(const char* name, Short_t l, Short_t h)
47 const
48{
49 //
50 // Make a new centrality bin
51 //
52 // Parameters:
53 // name Histogram names
54 // l Lower cut
55 // h Upper cut
56 //
57 // Return:
58 // Newly allocated object (of our type)
59 //
60 return new AliForwarddNdetaTask::CentralityBin(name, l, h);
61}
62
63//____________________________________________________________________
64void
65AliForwarddNdetaTask::UserExec(Option_t* option)
66{
67 //
68 // Called at each event
69 //
70 // This is called once in the master
71 //
72 // Parameters:
73 // option Not used
74 //
75 AliBasedNdetaTask::UserExec(option);
76
77 AliAODEvent* aod = dynamic_cast<AliAODEvent*>(InputEvent());
78 if (!aod) {
79 AliError("Cannot get the AOD event");
80 return;
81 }
82
83 TObject* obj = aod->FindListObject("Forward");
84 if (!obj) {
85 AliWarning("No forward object found");
86 return;
87 }
88 AliAODForwardMult* forward = static_cast<AliAODForwardMult*>(obj);
89
90 TObject* oPrimary = aod->FindListObject("primary");
91 if (!oPrimary) return;
92
93 TH2D* primary = static_cast<TH2D*>(oPrimary);
94
95 // Loop over centrality bins
96 TIter next(fListOfCentralities);
97 CentralityBin* bin = 0;
98 while ((bin = static_cast<CentralityBin*>(next())))
99 bin->ProcessPrimary(forward, fTriggerMask, fVtxMin, fVtxMax, primary);
100}
101
102
b2e7f2d6 103//____________________________________________________________________
104TH2D*
fb3430ac 105AliForwarddNdetaTask::GetHistogram(const AliAODEvent* aod, Bool_t mc)
b2e7f2d6 106{
fb3430ac 107 //
108 // Retrieve the histogram
109 //
110 // Parameters:
111 // aod AOD event
112 // mc Whether to get the MC histogram or not
113 //
114 // Return:
115 // Retrieved histogram or null
116 //
fe52e455 117 TObject* obj = 0;
118 if (mc) obj = aod->FindListObject("ForwardMC");
119 else obj = aod->FindListObject("Forward");
b2e7f2d6 120
121 // We should have a forward object at least
fe52e455 122 if (!obj) {
123 if (!mc) AliWarning("No Forward object found AOD");
124 return 0;
125 }
126 AliAODForwardMult* forward = static_cast<AliAODForwardMult*>(obj);
e1f47419 127 return &(forward->GetHistogram());
128}
fe52e455 129
e1f47419 130//========================================================================
131void
132AliForwarddNdetaTask::CentralityBin::ProcessPrimary(const AliAODForwardMult*
133 forward,
134 Int_t triggerMask,
b6b35c77 135 Double_t /*vzMin*/,
136 Double_t /*vzMax*/,
e1f47419 137 const TH2D* primary)
138{
139 // Check the centrality class unless this is the 'all' bin
140 if (!IsAllBin()) {
141 Double_t centrality = forward->GetCentrality();
142 if (centrality < fLow || centrality >= fHigh) return;
b2e7f2d6 143 }
b30dee70 144
b30dee70 145 // Create sum histogram
5fc13b13 146 if (!fSumPrimary) {
147 fSumPrimary = static_cast<TH2D*>(primary->Clone("truth"));
148 fSumPrimary->SetDirectory(0);
149 fSumPrimary->Reset();
150 fSums->Add(fSumPrimary);
151 }
c2918675 152
b6b35c77 153 // translate real trigger mask to MC trigger mask
c2918675 154 Int_t mask = AliAODForwardMult::kB;
155 if (triggerMask == AliAODForwardMult::kNSD)
156 mask = AliAODForwardMult::kMCNSD;
e1f47419 157
b6b35c77 158 // Now use our normal check, but with the new mask, except
159 if (!forward->CheckEvent(mask, -1000, -1000, 0, 0, 0)) return;
c2918675 160
b6b35c77 161 fSumPrimary->Add(primary);
b2e7f2d6 162}
163
b2e7f2d6 164//________________________________________________________________________
e1f47419 165void
166AliForwarddNdetaTask::CentralityBin::End(TList* sums,
167 TList* results,
ffca499d 168 UShort_t scheme,
e1f47419 169 const TH1* shapeCorr,
170 Double_t trigEff,
171 Bool_t symmetrice,
172 Int_t rebin,
c25b5e1b 173 Bool_t rootProj,
e1f47419 174 Bool_t corrEmpty,
c25b5e1b 175 Bool_t cutEdges,
ffca499d 176 Int_t triggerMask,
177 Int_t color,
178 Int_t marker)
b2e7f2d6 179{
c25b5e1b 180 AliInfo(Form("In End of %s with corrEmpty=%d, cutEdges=%d, rootProj=%d",
181 GetName(), corrEmpty, cutEdges, rootProj));
ffca499d 182 AliBasedNdetaTask::CentralityBin::End(sums, results, scheme,
183 shapeCorr, trigEff,
c25b5e1b 184 symmetrice, rebin,
185 rootProj, corrEmpty, cutEdges,
186 triggerMask, color, marker);
b2e7f2d6 187
fe52e455 188 fSumPrimary = static_cast<TH2D*>(fSums->FindObject("truth"));
b2e7f2d6 189
b6b35c77 190 if (!fSumPrimary) {
191 AliWarning("No MC truth histogram found");
192 fSums->ls();
193 return;
194 }
ffca499d 195 Int_t n = (triggerMask == AliAODForwardMult::kNSD ?
196 Int_t(fTriggers->GetBinContent(AliAODForwardMult::kBinMCNSD)) :
197 Int_t(fTriggers->GetBinContent(AliAODForwardMult::kBinAll)));
b30dee70 198 AliInfo(Form("Normalising MC truth to %d", n));
7646e35f 199
e1f47419 200 TH1D* dndetaTruth = fSumPrimary->ProjectionX("dndetaTruth",1,
201 fSumPrimary->GetNbinsY(),"e");
202 dndetaTruth->Scale(1./n, "width");
e58000b7 203
ffca499d 204 SetHistogramAttributes(dndetaTruth, color-2, marker+4, "Monte-Carlo truth");
e58000b7 205
e1f47419 206 fOutput->Add(dndetaTruth);
207 fOutput->Add(Rebin(dndetaTruth, rebin, cutEdges));
b2e7f2d6 208}
209
210//________________________________________________________________________
fe52e455 211//
212// EOF
213//