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