]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/EMCALTasks/AliAnalysisTaskEmcal.cxx
71049aaa6b44e5e7aaa8ac069bc79c79d2aad1b9
[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("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),
44   fBeamType(kNA),
45   fOutput(0)
46 {
47   // Default constructor.
48
49   fVertex[0] = 0;
50   fVertex[1] = 0;
51   fVertex[2] = 0;
52 }
53
54 //________________________________________________________________________
55 AliAnalysisTaskEmcal::AliAnalysisTaskEmcal(const char *name, Bool_t histo) : 
56   AliAnalysisTaskSE(name),
57   fAnaType(kTPC),
58   fInitialized(kFALSE),
59   fCreateHisto(histo),
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),
70   fBeamType(kNA),
71   fOutput(0)
72 {
73   // Standard constructor.
74
75   fVertex[0] = 0;
76   fVertex[1] = 0;
77   fVertex[2] = 0;
78
79   if (fCreateHisto) {
80     DefineOutput(1, TList::Class()); 
81   }
82 }
83
84 //________________________________________________________________________
85 AliAnalysisTaskEmcal::~AliAnalysisTaskEmcal()
86 {
87   // Destructor
88 }
89
90 //________________________________________________________________________
91 void AliAnalysisTaskEmcal::UserCreateOutputObjects()
92 {
93   // User create outputs.
94 }
95
96 //_____________________________________________________
97 AliAnalysisTaskEmcal::BeamType AliAnalysisTaskEmcal::GetBeamType()
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   } else {
115     Int_t runNumber = InputEvent()->GetRunNumber();
116     if ((runNumber >= 136851 && runNumber <= 139517) ||  // LHC10h
117         (runNumber >= 166529 && runNumber <= 170593))    // LHC11h
118     {
119       return kAA;
120     } else {
121       return kpp;
122     }
123   }  
124 }
125
126 void AliAnalysisTaskEmcal::Init()
127 {
128   // Init the analysis.
129
130   if (!fCaloName.IsNull() && (fAnaType == kEMCAL) && !fCaloClusters) {
131     fCaloClusters =  dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fCaloName));
132     if (!fCaloClusters) {
133       AliWarning(Form("%s: Could not retrieve clusters %s!", GetName(), fCaloName.Data())); 
134     }
135   }
136
137   if (!fTracksName.IsNull() && !fTracks) {
138     fTracks = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksName));
139     if (!fTracks) {
140       AliWarning(Form("%s: Could not retrieve tracks %s!", GetName(), fTracksName.Data())); 
141     }
142   }
143
144   SetInitialized();
145 }
146
147 //________________________________________________________________________
148 Bool_t AliAnalysisTaskEmcal::RetrieveEventObjects()
149 {
150   // Retrieve objects from event.
151
152   if (!InputEvent()) {
153     AliError(Form("%s: Could not retrieve event! Returning!", GetName()));
154     return kFALSE;
155   }
156
157   fVertex[0] = 0;
158   fVertex[1] = 0;
159   fVertex[2] = 0;
160   InputEvent()->GetPrimaryVertex()->GetXYZ(fVertex);
161
162   fBeamType = GetBeamType();
163
164   if (fBeamType == kAA) {
165     AliCentrality *aliCent = InputEvent()->GetCentrality();
166     if (aliCent) {
167       fCent = aliCent->GetCentralityPercentile("V0M");
168       if      (fCent >=  0 && fCent <   10) fCentBin = 0;
169       else if (fCent >= 10 && fCent <   30) fCentBin = 1;
170       else if (fCent >= 30 && fCent <   50) fCentBin = 2;
171       else if (fCent >= 50 && fCent <= 100) fCentBin = 3; 
172       else {
173         AliWarning(Form("%s: Negative centrality: %f. Assuming 99", GetName(), fCent));
174         fCentBin = 3;
175       }
176     } else {
177       AliWarning(Form("%s: Could not retrieve centrality information! Assuming 99", GetName()));
178       fCentBin = 3;
179     }
180   } else {
181     fCent = 99;
182     fCentBin = 0;
183   }
184
185   return kTRUE;
186 }
187
188 //________________________________________________________________________
189 Bool_t AliAnalysisTaskEmcal::AcceptCluster(AliVCluster *clus, Bool_t acceptMC) const
190 {
191   // Return true if cluster is accepted.
192
193   if (!clus)
194     return kFALSE;
195
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 //________________________________________________________________________
212 Bool_t AliAnalysisTaskEmcal::AcceptEmcalPart(AliEmcalParticle *part, Bool_t acceptMC) const
213 {
214   // Return true if EMCal particle is accepted.
215
216   if (!part)
217     return kFALSE;
218
219   if (fAnaType == kEMCAL && !part->IsEMCAL())
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 //________________________________________________________________________
232 Bool_t AliAnalysisTaskEmcal::AcceptTrack(AliVTrack *track, Bool_t acceptMC) const
233 {
234   // Return true if track is accepted.
235
236   if (!track)
237     return kFALSE;
238
239   if (!acceptMC && track->GetLabel() == 100)
240     return kFALSE;
241
242   if (track->Pt() < fPtCut)
243     return kFALSE;
244   
245   return kTRUE;
246 }
247
248 //________________________________________________________________________
249 void AliAnalysisTaskEmcal::UserExec(Option_t *) 
250 {
251   // Main loop, called for each event.
252
253   if (!fInitialized) 
254     Init();
255
256   if (!RetrieveEventObjects())
257     return;
258
259   if (!Run())
260     return;
261
262   if (!FillHistograms())
263     return;
264     
265   if (fCreateHisto) {
266     // information for this iteration of the UserExec in the container
267     PostData(1, fOutput);
268   }
269 }
270
271 //________________________________________________________________________
272 void AliAnalysisTaskEmcal::Terminate(Option_t *) 
273 {
274   // Called once at the end of the analysis.
275 }