]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGGA/EMCALTasks/AliAnalysisTaskEmcal.cxx
changes from saiola
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / AliAnalysisTaskEmcal.cxx
CommitLineData
2da09763 1// $Id: AliAnalysisTaskEmcal.cxx 56756 2012-05-30 05:03:02Z loizides $
2//
3// Emcal base analysis task.
4//
5// Author: S.Aiola
6
7#include "AliAnalysisTaskEmcal.h"
8
2da09763 9#include <TChain.h>
10#include <TClonesArray.h>
11#include <TList.h>
09ca054b 12#include <TObject.h>
2da09763 13
2da09763 14#include "AliAnalysisManager.h"
15#include "AliCentrality.h"
3c124212 16#include "AliEventplane.h"
09ca054b 17#include "AliEMCALGeometry.h"
18#include "AliESDEvent.h"
2da09763 19#include "AliEmcalJet.h"
09ca054b 20#include "AliEmcalParticle.h"
2da09763 21#include "AliLog.h"
09ca054b 22#include "AliMCParticle.h"
23#include "AliVCluster.h"
24#include "AliVEventHandler.h"
25#include "AliVParticle.h"
2da09763 26
27ClassImp(AliAnalysisTaskEmcal)
28
29//________________________________________________________________________
30AliAnalysisTaskEmcal::AliAnalysisTaskEmcal() :
31 AliAnalysisTaskSE("AliAnalysisTaskEmcal"),
32 fAnaType(kTPC),
33 fInitialized(kFALSE),
34 fCreateHisto(kTRUE),
20f79d37 35 fTracksName(),
36 fCaloName(),
2da09763 37 fNbins(500),
38 fMinBinPt(0),
39 fMaxBinPt(250),
e44e8726 40 fClusPtCut(0.15),
41 fTrackPtCut(0.15),
8210e4cb 42 fClusTimeCutLow(-10),
43 fClusTimeCutUp(10),
2da09763 44 fTracks(0),
45 fCaloClusters(0),
46 fCent(0),
47 fCentBin(-1),
3c124212 48 fEPV0(-1.0),
49 fEPV0A(-1.0),
50 fEPV0C(-1.0),
1f6fff78 51 fBeamType(kNA),
2da09763 52 fOutput(0)
53{
54 // Default constructor.
55
56 fVertex[0] = 0;
57 fVertex[1] = 0;
58 fVertex[2] = 0;
2da09763 59}
60
61//________________________________________________________________________
62AliAnalysisTaskEmcal::AliAnalysisTaskEmcal(const char *name, Bool_t histo) :
63 AliAnalysisTaskSE(name),
64 fAnaType(kTPC),
65 fInitialized(kFALSE),
66 fCreateHisto(histo),
20f79d37 67 fTracksName(),
68 fCaloName(),
2da09763 69 fNbins(500),
70 fMinBinPt(0),
71 fMaxBinPt(250),
e44e8726 72 fClusPtCut(0.15),
73 fTrackPtCut(0.15),
8210e4cb 74 fClusTimeCutLow(-10),
75 fClusTimeCutUp(10),
2da09763 76 fTracks(0),
77 fCaloClusters(0),
78 fCent(0),
79 fCentBin(-1),
3c124212 80 fEPV0(-1.0),
81 fEPV0A(-1.0),
82 fEPV0C(-1.0),
1f6fff78 83 fBeamType(kNA),
2da09763 84 fOutput(0)
85{
86 // Standard constructor.
87
88 fVertex[0] = 0;
89 fVertex[1] = 0;
90 fVertex[2] = 0;
91
92 if (fCreateHisto) {
2da09763 93 DefineOutput(1, TList::Class());
94 }
95}
96
97//________________________________________________________________________
98AliAnalysisTaskEmcal::~AliAnalysisTaskEmcal()
99{
100 // Destructor
101}
102
103//________________________________________________________________________
629c7ac0 104void AliAnalysisTaskEmcal::UserExec(Option_t *)
105{
106 // Main loop, called for each event.
107
e44e8726 108 if (!fInitialized)
b3376347 109 ExecOnce();
629c7ac0 110
e44e8726 111 if (!fInitialized)
112 return;
113
629c7ac0 114 if (!RetrieveEventObjects())
115 return;
116
117 if (!Run())
118 return;
119
120 if (!FillHistograms())
121 return;
122
123 if (fCreateHisto) {
124 // information for this iteration of the UserExec in the container
125 PostData(1, fOutput);
126 }
127}
128
129//________________________________________________________________________
130Bool_t AliAnalysisTaskEmcal::AcceptCluster(AliVCluster *clus, Bool_t acceptMC) const
2da09763 131{
629c7ac0 132 // Return true if cluster is accepted.
133
134 if (!clus)
135 return kFALSE;
136
137 if (!clus->IsEMCAL())
138 return kFALSE;
139
140 if (!acceptMC && clus->Chi2() == 100)
141 return kFALSE;
142
090a0c3e 143 if (clus->GetTOF() > fClusTimeCutUp || clus->GetTOF() < fClusTimeCutLow)
144 return kFALSE;
145
629c7ac0 146 TLorentzVector nPart;
147 clus->GetMomentum(nPart, const_cast<Double_t*>(fVertex));
148
e44e8726 149 if (nPart.Et() < fClusPtCut)
629c7ac0 150 return kFALSE;
151
152 return kTRUE;
153}
154
155//________________________________________________________________________
156Bool_t AliAnalysisTaskEmcal::AcceptEmcalPart(AliEmcalParticle *part, Bool_t acceptMC) const
157{
158 // Return true if EMCal particle is accepted.
159
160 if (!part)
161 return kFALSE;
162
163 if (fAnaType == kEMCAL && !part->IsEMCAL())
164 return kFALSE;
165
e44e8726 166 if ((part->IsTrack() && part->Pt() < fTrackPtCut) || (part->IsCluster() && part->Pt() < fClusPtCut))
629c7ac0 167 return kFALSE;
168
169 if (!acceptMC && part->IsMC())
170 return kFALSE;
171
172 return kTRUE;
173}
174
175//________________________________________________________________________
176Bool_t AliAnalysisTaskEmcal::AcceptTrack(AliVTrack *track, Bool_t acceptMC) const
177{
178 // Return true if track is accepted.
179
180 if (!track)
181 return kFALSE;
182
183 if (!acceptMC && track->GetLabel() == 100)
184 return kFALSE;
185
e44e8726 186 if (track->Pt() < fTrackPtCut)
629c7ac0 187 return kFALSE;
188
189 return kTRUE;
2da09763 190}
191
192//_____________________________________________________
1f6fff78 193AliAnalysisTaskEmcal::BeamType AliAnalysisTaskEmcal::GetBeamType()
2da09763 194{
195 // Get beam type : pp-AA-pA
196 // ESDs have it directly, AODs get it from hardcoded run number ranges
197
198 AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
199 if (esd) {
200 const AliESDRun *run = esd->GetESDRun();
201 TString beamType = run->GetBeamType();
202 if (beamType == "p-p")
203 return kpp;
204 else if (beamType == "A-A")
205 return kAA;
206 else if (beamType == "p-A")
207 return kpA;
208 else
209 return kNA;
901cc837 210 } else {
2da09763 211 Int_t runNumber = InputEvent()->GetRunNumber();
212 if ((runNumber >= 136851 && runNumber <= 139517) || // LHC10h
213 (runNumber >= 166529 && runNumber <= 170593)) // LHC11h
214 {
215 return kAA;
901cc837 216 } else {
2da09763 217 return kpp;
218 }
219 }
220}
221
629c7ac0 222//________________________________________________________________________
b3376347 223void AliAnalysisTaskEmcal::ExecOnce()
8a28ded1 224{
225 // Init the analysis.
b3376347 226 if (!InputEvent()) {
227 AliError(Form("%s: Could not retrieve event! Returning!", GetName()));
228 return;
229 }
230
a5621834 231 if (!fCaloName.IsNull() && (fAnaType == kEMCAL || fAnaType == kEMCALOnly) && !fCaloClusters) {
b3376347 232 fCaloClusters = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fCaloName));
233 if (!fCaloClusters) {
234 AliError(Form("%s: Could not retrieve clusters %s!", GetName(), fCaloName.Data()));
235 return;
236 } else {
237 TClass *cl = fCaloClusters->GetClass();
238 if (!cl->GetBaseClass("AliVCluster") && !cl->GetBaseClass("AliEmcalParticle")) {
239 AliError(Form("%s: Collection %s does not contain AliVCluster nor AliEmcalParticle objects!", GetName(), fCaloName.Data()));
240 fCaloClusters = 0;
241 return;
242 }
243 }
244 }
245
a5621834 246 if (!fTracksName.IsNull() && fAnaType != kEMCALOnly && !fTracks) {
b3376347 247 fTracks = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksName));
248 if (!fTracks) {
249 AliError(Form("%s: Could not retrieve tracks %s!", GetName(), fTracksName.Data()));
250 return;
251 } else {
252 TClass *cl = fTracks->GetClass();
253 if (!cl->GetBaseClass("AliVParticle") && !cl->GetBaseClass("AliEmcalParticle")) {
254 AliError(Form("%s: Collection %s does not contain AliVParticle nor AliEmcalParticle objects!", GetName(), fTracksName.Data()));
255 fTracks = 0;
256 return;
257 }
258 }
259 }
8a28ded1 260
8a28ded1 261 SetInitialized();
262}
263
c596bd28 264//________________________________________________________________________
265TClonesArray *AliAnalysisTaskEmcal::GetArrayFromEvent(const char *name, const char *clname)
266{
267 // Get array from event.
268
269 TClonesArray *arr = 0;
270 TString sname(name);
271 if (!sname.IsNull()) {
272 arr = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(sname));
273 if (!arr) {
274 AliWarning(Form("%s: Could not retrieve array with name %s!", GetName(), name));
275 return 0;
276 }
af0280a9 277 } else {
278 return 0;
c596bd28 279 }
af0280a9 280
c596bd28 281 if (!clname)
282 return arr;
283
284 TString objname(arr->GetClass()->GetName());
285 TClass cls(objname);
286 if (!cls.InheritsFrom(clname)) {
287 AliWarning(Form("%s: Objects of type %s in %s are not inherited from %s!",
288 GetName(), cls.GetName(), name, clname));
289 return 0;
290 }
291 return arr;
292}
293
2da09763 294//________________________________________________________________________
295Bool_t AliAnalysisTaskEmcal::RetrieveEventObjects()
296{
297 // Retrieve objects from event.
298
2da09763 299 fVertex[0] = 0;
300 fVertex[1] = 0;
301 fVertex[2] = 0;
302 InputEvent()->GetPrimaryVertex()->GetXYZ(fVertex);
303
1f6fff78 304 fBeamType = GetBeamType();
305
306 if (fBeamType == kAA) {
2da09763 307 AliCentrality *aliCent = InputEvent()->GetCentrality();
308 if (aliCent) {
309 fCent = aliCent->GetCentralityPercentile("V0M");
310 if (fCent >= 0 && fCent < 10) fCentBin = 0;
311 else if (fCent >= 10 && fCent < 30) fCentBin = 1;
312 else if (fCent >= 30 && fCent < 50) fCentBin = 2;
313 else if (fCent >= 50 && fCent <= 100) fCentBin = 3;
314 else {
901cc837 315 AliWarning(Form("%s: Negative centrality: %f. Assuming 99", GetName(), fCent));
2da09763 316 fCentBin = 3;
317 }
901cc837 318 } else {
319 AliWarning(Form("%s: Could not retrieve centrality information! Assuming 99", GetName()));
2da09763 320 fCentBin = 3;
321 }
3c124212 322 AliEventplane *aliEP = InputEvent()->GetEventplane();
323 if (aliEP) {
324 fEPV0 = aliEP->GetEventplane("V0" ,InputEvent());
325 fEPV0A = aliEP->GetEventplane("V0A",InputEvent());
326 fEPV0C = aliEP->GetEventplane("V0C",InputEvent());
327 } else {
328 AliWarning(Form("%s: Could not retrieve event plane information!", GetName()));
329 }
901cc837 330 } else {
2da09763 331 fCent = 99;
332 fCentBin = 0;
333 }
334
2da09763 335 return kTRUE;
336}