]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGGA/EMCALTasks/AliAnalysisTaskEmcal.cxx
bugfix
[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"
09ca054b 16#include "AliEMCALGeometry.h"
17#include "AliESDEvent.h"
2da09763 18#include "AliEmcalJet.h"
09ca054b 19#include "AliEmcalParticle.h"
2da09763 20#include "AliLog.h"
09ca054b 21#include "AliMCParticle.h"
22#include "AliVCluster.h"
23#include "AliVEventHandler.h"
24#include "AliVParticle.h"
2da09763 25
26ClassImp(AliAnalysisTaskEmcal)
27
28//________________________________________________________________________
29AliAnalysisTaskEmcal::AliAnalysisTaskEmcal() :
30 AliAnalysisTaskSE("AliAnalysisTaskEmcal"),
31 fAnaType(kTPC),
32 fInitialized(kFALSE),
33 fCreateHisto(kTRUE),
2da09763 34 fTracksName("Tracks"),
35 fCaloName("CaloClusters"),
36 fNbins(500),
37 fMinBinPt(0),
38 fMaxBinPt(250),
39 fPtCut(0.15),
40 fTracks(0),
41 fCaloClusters(0),
42 fCent(0),
43 fCentBin(-1),
1f6fff78 44 fBeamType(kNA),
2da09763 45 fOutput(0)
46{
47 // Default constructor.
48
49 fVertex[0] = 0;
50 fVertex[1] = 0;
51 fVertex[2] = 0;
2da09763 52}
53
54//________________________________________________________________________
55AliAnalysisTaskEmcal::AliAnalysisTaskEmcal(const char *name, Bool_t histo) :
56 AliAnalysisTaskSE(name),
57 fAnaType(kTPC),
58 fInitialized(kFALSE),
59 fCreateHisto(histo),
2da09763 60 fTracksName("Tracks"),
61 fCaloName("CaloClusters"),
62 fNbins(500),
63 fMinBinPt(0),
64 fMaxBinPt(250),
65 fPtCut(0.15),
66 fTracks(0),
67 fCaloClusters(0),
68 fCent(0),
69 fCentBin(-1),
1f6fff78 70 fBeamType(kNA),
2da09763 71 fOutput(0)
72{
73 // Standard constructor.
74
75 fVertex[0] = 0;
76 fVertex[1] = 0;
77 fVertex[2] = 0;
78
79 if (fCreateHisto) {
2da09763 80 DefineOutput(1, TList::Class());
81 }
82}
83
84//________________________________________________________________________
85AliAnalysisTaskEmcal::~AliAnalysisTaskEmcal()
86{
87 // Destructor
88}
89
90//________________________________________________________________________
91void AliAnalysisTaskEmcal::UserCreateOutputObjects()
92{
93 // User create outputs.
94}
95
96//_____________________________________________________
1f6fff78 97AliAnalysisTaskEmcal::BeamType AliAnalysisTaskEmcal::GetBeamType()
2da09763 98{
99 // Get beam type : pp-AA-pA
100 // ESDs have it directly, AODs get it from hardcoded run number ranges
101
102 AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
103 if (esd) {
104 const AliESDRun *run = esd->GetESDRun();
105 TString beamType = run->GetBeamType();
106 if (beamType == "p-p")
107 return kpp;
108 else if (beamType == "A-A")
109 return kAA;
110 else if (beamType == "p-A")
111 return kpA;
112 else
113 return kNA;
114 }
115 else
116 {
117 Int_t runNumber = InputEvent()->GetRunNumber();
118 if ((runNumber >= 136851 && runNumber <= 139517) || // LHC10h
119 (runNumber >= 166529 && runNumber <= 170593)) // LHC11h
120 {
121 return kAA;
122 }
123 else
124 {
125 return kpp;
126 }
127 }
128}
129
130//________________________________________________________________________
131Bool_t AliAnalysisTaskEmcal::RetrieveEventObjects()
132{
133 // Retrieve objects from event.
134
135 if (!InputEvent()) {
136 AliError("Could not retrieve event! Returning...");
137 return kFALSE;
138 }
139
140 fVertex[0] = 0;
141 fVertex[1] = 0;
142 fVertex[2] = 0;
143 InputEvent()->GetPrimaryVertex()->GetXYZ(fVertex);
144
1f6fff78 145 fBeamType = GetBeamType();
146
147 if (fBeamType == kAA) {
2da09763 148 AliCentrality *aliCent = InputEvent()->GetCentrality();
149 if (aliCent) {
150 fCent = aliCent->GetCentralityPercentile("V0M");
151 if (fCent >= 0 && fCent < 10) fCentBin = 0;
152 else if (fCent >= 10 && fCent < 30) fCentBin = 1;
153 else if (fCent >= 30 && fCent < 50) fCentBin = 2;
154 else if (fCent >= 50 && fCent <= 100) fCentBin = 3;
155 else {
156 AliWarning(Form("Negative centrality: %f. Assuming 99", fCent));
157 fCentBin = 3;
158 }
159 }
160 else {
161 AliWarning(Form("Could not retrieve centrality information! Assuming 99"));
162 fCentBin = 3;
163 }
164 }
165 else {
166 fCent = 99;
167 fCentBin = 0;
168 }
169
170 if ((!fCaloName.IsNull()) && (fAnaType == kEMCAL)) {
171 fCaloClusters = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fCaloName));
172 if (!fCaloClusters) {
173 AliWarning(Form("Could not retrieve clusters %s!", fCaloName.Data()));
174 }
175 }
176
177 if (!fTracksName.IsNull()) {
178 fTracks = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksName));
179 if (!fTracks) {
180 AliWarning(Form("Could not retrieve tracks %s!", fTracksName.Data()));
181 }
182 }
183
184 return kTRUE;
185}
186
2da09763 187
188//________________________________________________________________________
09ca054b 189Bool_t AliAnalysisTaskEmcal::AcceptCluster(AliVCluster *clus, Bool_t acceptMC) const
2da09763 190{
191 // Return true if cluster is accepted.
09ca054b 192
193 if (!clus)
194 return kFALSE;
195
2da09763 196 if (!clus->IsEMCAL())
197 return kFALSE;
198
199 if (!acceptMC && clus->Chi2() == 100)
200 return kFALSE;
201
202 TLorentzVector nPart;
203 clus->GetMomentum(nPart, const_cast<Double_t*>(fVertex));
204
205 if (nPart.Et() < fPtCut)
206 return kFALSE;
207
208 return kTRUE;
209}
210
211//________________________________________________________________________
09ca054b 212Bool_t AliAnalysisTaskEmcal::AcceptEmcalPart(AliEmcalParticle *part, Bool_t acceptMC) const
213{
dfa0c20c 214 // Return true if EMCal particle is accepted.
09ca054b 215
216 if (!part)
217 return kFALSE;
218
dfa0c20c 219 if (fAnaType == kEMCAL && !part->IsEMCAL())
09ca054b 220 return kFALSE;
221
222 if (part->Pt() < fPtCut)
223 return kFALSE;
224
225 if (!acceptMC && part->IsMC())
226 return kFALSE;
227
228 return kTRUE;
229}
230
231//________________________________________________________________________
232Bool_t AliAnalysisTaskEmcal::AcceptTrack(AliVTrack *track, Bool_t acceptMC) const
2da09763 233{
234 // Return true if track is accepted.
09ca054b 235
236 if (!track)
237 return kFALSE;
238
2da09763 239 if (!acceptMC && track->GetLabel() == 100)
240 return kFALSE;
241
242 if (track->Pt() < fPtCut)
243 return kFALSE;
244
1f6fff78 245 return kTRUE;
2da09763 246}
247
248//________________________________________________________________________
249void AliAnalysisTaskEmcal::UserExec(Option_t *)
250{
251 // Main loop, called for each event.
252
2da09763 253 if (!RetrieveEventObjects())
254 return;
255
256 if (!Run())
257 return;
258
259 if (!FillHistograms())
260 return;
261
262 if (fCreateHisto) {
263 // information for this iteration of the UserExec in the container
264 PostData(1, fOutput);
265 }
266}
267
268//________________________________________________________________________
269void AliAnalysisTaskEmcal::Terminate(Option_t *)
270{
271 // Called once at the end of the analysis.
272}