]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/EMCALJetTasks/AliAnalysisTaskEmcalJet.cxx
From Salvatore
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / AliAnalysisTaskEmcalJet.cxx
1 // $Id$
2 //
3 // Emcal jet analysis base task.
4 //
5 // Author: S.Aiola
6
7 #include "AliAnalysisTaskEmcalJet.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 "AliLog.h"
20 #include "AliRhoParameter.h"
21 #include "AliVCluster.h"
22 #include "AliVEventHandler.h"
23 #include "AliVParticle.h"
24
25 ClassImp(AliAnalysisTaskEmcalJet)
26
27 //________________________________________________________________________
28 AliAnalysisTaskEmcalJet::AliAnalysisTaskEmcalJet() : 
29   AliAnalysisTaskEmcal("AliAnalysisTaskEmcalJet"),
30   fJetRadius(0.4),
31   fJetsName(),
32   fRhoName(),
33   fPtBiasJetTrack(0),
34   fPtBiasJetClus(0),
35   fJetPtCut(1),
36   fJetAreaCut(-1),
37   fPercAreaCut(-1),
38   fAreaEmcCut(0),
39   fJetMinEta(-0.9),
40   fJetMaxEta(0.9),
41   fJetMinPhi(-10),
42   fJetMaxPhi(10),
43   fMaxClusterPt(1000),
44   fMaxTrackPt(100),
45   fLeadingHadronType(0),
46   fNLeadingJets(1),
47   fJetBitMap(0),
48   fJetTrigger(0),
49   fJets(0),
50   fRho(0),
51   fRhoVal(0)
52 {
53   // Default constructor.
54 }
55
56 //________________________________________________________________________
57 AliAnalysisTaskEmcalJet::AliAnalysisTaskEmcalJet(const char *name, Bool_t histo) : 
58   AliAnalysisTaskEmcal(name, histo),
59   fJetRadius(0.4),
60   fJetsName(),
61   fRhoName(),
62   fPtBiasJetTrack(0),
63   fPtBiasJetClus(0),
64   fJetPtCut(1),
65   fJetAreaCut(-1),
66   fPercAreaCut(-1),
67   fAreaEmcCut(0),
68   fJetMinEta(-0.9),
69   fJetMaxEta(0.9),
70   fJetMinPhi(-10),
71   fJetMaxPhi(10),
72   fMaxClusterPt(1000),
73   fMaxTrackPt(100),
74   fLeadingHadronType(0),
75   fNLeadingJets(1),
76   fJetBitMap(0),
77   fJetTrigger(0),
78   fJets(0),
79   fRho(0),
80   fRhoVal(0)
81 {
82   // Standard constructor.
83 }
84
85 //________________________________________________________________________
86 AliAnalysisTaskEmcalJet::~AliAnalysisTaskEmcalJet()
87 {
88   // Destructor
89 }
90
91 //________________________________________________________________________
92 Bool_t AliAnalysisTaskEmcalJet::AcceptBiasJet(AliEmcalJet *jet) const
93
94   // Accept jet with a bias.
95
96   if (fLeadingHadronType == 0) {
97     if (jet->MaxTrackPt() < fPtBiasJetTrack) return kFALSE;
98   }
99   else if (fLeadingHadronType == 1) {
100     if (jet->MaxClusterPt() < fPtBiasJetClus) return kFALSE;
101   }
102   else {
103     if (jet->MaxTrackPt() < fPtBiasJetTrack && jet->MaxClusterPt() < fPtBiasJetClus) return kFALSE;
104   }
105
106   return kTRUE;
107 }
108
109 //________________________________________________________________________
110 Float_t* AliAnalysisTaskEmcalJet::GenerateFixedBinArray(Int_t n, Float_t min, Float_t max) const
111 {
112   Float_t *bins = new Float_t[n+1];
113
114   Float_t binWidth = (max-min)/n;
115   bins[0] = min;
116   for (Int_t i = 1; i <= n; i++) {
117     bins[i] = bins[i-1]+binWidth;
118   }
119
120   return bins;
121 }
122
123 //________________________________________________________________________
124 Double_t AliAnalysisTaskEmcalJet::GetLeadingHadronPt(AliEmcalJet *jet) const
125 {
126   if (fLeadingHadronType == 0)       // charged leading hadron
127     return jet->MaxTrackPt();
128   else if (fLeadingHadronType == 1)  // neutral leading hadron
129     return jet->MaxClusterPt();
130   else                               // charged or neutral
131     return jet->MaxPartPt();
132 }
133
134 //________________________________________________________________________
135 Bool_t AliAnalysisTaskEmcalJet::AcceptJet(AliEmcalJet *jet) const
136 {   
137   // Return true if jet is accepted.
138   if (!jet)
139     return kFALSE;
140
141   if (jet->TestBits(fJetBitMap) != (Int_t)fJetBitMap)
142     return kFALSE;
143
144   if (jet->Pt() < fJetPtCut) 
145     return kFALSE;
146  
147   if (jet->Area() < fJetAreaCut) 
148     return kFALSE;
149
150   if (jet->AreaEmc()<fAreaEmcCut)
151     return kFALSE;
152
153   if (!AcceptBiasJet(jet))
154     return kFALSE;
155   
156   if (jet->MaxTrackPt() > fMaxTrackPt || jet->MaxClusterPt() > fMaxClusterPt)
157     return kFALSE;
158
159   Double_t jetPhi = jet->Phi();
160   Double_t jetEta = jet->Eta();
161   
162   if (fJetMinPhi < 0) // if limits are given in (-pi, pi) range
163     jetPhi -= TMath::Pi() * 2;
164
165   if (fJetTrigger != 0 && !jet->IsTriggerJet(fJetTrigger))
166     return kFALSE;
167
168   return (Bool_t)(jetEta > fJetMinEta && jetEta < fJetMaxEta && jetPhi > fJetMinPhi && jetPhi < fJetMaxPhi);
169 }
170
171 //________________________________________________________________________
172 AliRhoParameter *AliAnalysisTaskEmcalJet::GetRhoFromEvent(const char *name)
173 {
174   // Get rho from event.
175
176   AliRhoParameter *rho = 0;
177   TString sname(name);
178   if (!sname.IsNull()) {
179     rho = dynamic_cast<AliRhoParameter*>(InputEvent()->FindListObject(sname));
180     if (!rho) {
181       AliWarning(Form("%s: Could not retrieve rho with name %s!", GetName(), name)); 
182       return 0;
183     }
184   }
185   return rho;
186 }
187
188 //________________________________________________________________________
189 void AliAnalysisTaskEmcalJet::ExecOnce()
190 {
191   // Init the analysis.
192
193   AliAnalysisTaskEmcal::ExecOnce();
194
195   if (fPercAreaCut >= 0) {
196     if (fJetAreaCut >= 0)
197       AliInfo(Form("%s: jet area cut will be calculated as a percentage of the average area, given value will be overwritten", GetName()));
198     fJetAreaCut = fPercAreaCut * fJetRadius * fJetRadius * TMath::Pi();
199   }
200   if (fJetAreaCut < 0)
201     fJetAreaCut = 0;
202
203   if (fAnaType == kTPC) {
204     SetJetEtaLimits(-0.5, 0.5);
205     SetJetPhiLimits(-10, 10);
206   } 
207   else if (fAnaType == kEMCAL && fGeom) {
208
209     SetJetEtaLimits(fGeom->GetArm1EtaMin() + fJetRadius, fGeom->GetArm1EtaMax() - fJetRadius);
210
211     Int_t runno = InputEvent()->GetRunNumber();
212     if(runno>=177295 && runno<=197470) //small SM masked in 2012 and 2013
213       SetJetPhiLimits(1.4 + fJetRadius, TMath::Pi() - fJetRadius);
214     else 
215       SetJetPhiLimits(fGeom->GetArm1PhiMin() * TMath::DegToRad() + fJetRadius, fGeom->GetArm1PhiMax() * TMath::DegToRad() - fJetRadius);
216     
217   }
218
219   if (!fRhoName.IsNull() && !fRho) {
220     fRho = dynamic_cast<AliRhoParameter*>(InputEvent()->FindListObject(fRhoName));
221     if (!fRho) {
222       AliError(Form("%s: Could not retrieve rho %s!", GetName(), fRhoName.Data()));
223       fInitialized = kFALSE;
224       return;
225     }
226   }
227
228   if (!fJetsName.IsNull() && !fJets) {
229     fJets = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fJetsName));
230     if (!fJets) {
231       AliError(Form("%s: Could not retrieve jets %s!", GetName(), fJetsName.Data()));
232       fInitialized = kFALSE;
233       return;
234     }
235     else if (!fJets->GetClass()->GetBaseClass("AliEmcalJet")) {
236       AliError(Form("%s: Collection %s does not contain AliEmcalJet objects!", GetName(), fJetsName.Data())); 
237       fJets = 0;
238       fInitialized = kFALSE;
239       return;
240     }
241   }
242 }
243
244 //________________________________________________________________________
245 Int_t AliAnalysisTaskEmcalJet::GetSortedArray(Int_t indexes[], TClonesArray *array, Double_t rho) const
246 {
247   // Get the leading jets.
248
249   static Float_t pt[9999] = {0};
250
251   if (!array)
252     return 0;
253
254   const Int_t n = array->GetEntriesFast();
255
256   Int_t nacc = 0;
257
258   if (n < 1)
259     return kFALSE;
260
261   if (array->GetClass()->GetBaseClass("AliEmcalJet")) {
262
263     for (Int_t i = 0; i < n; i++) {
264
265       pt[i] = -FLT_MAX;
266
267       AliEmcalJet* jet = static_cast<AliEmcalJet*>(array->At(i));
268       
269       if (!jet) {
270         AliError(Form("Could not receive jet %d", i));
271         continue;
272       }
273       
274       if (!AcceptJet(jet))
275         continue;
276       
277       pt[nacc] = jet->Pt() - rho * jet->Area();
278       nacc++;
279     }
280   }
281
282   else if (array->GetClass()->GetBaseClass("AliVTrack")) {
283
284     for (Int_t i = 0; i < n; i++) {
285
286       pt[i] = -FLT_MAX;
287
288       AliVTrack* track = static_cast<AliVTrack*>(array->At(i));
289       
290       if (!track) {
291         AliError(Form("Could not receive track %d", i));
292         continue;
293       }  
294       
295       if (!AcceptTrack(track))
296         continue;
297       
298       pt[nacc] = track->Pt();
299       nacc++;
300     }
301   }
302
303   else if (array->GetClass()->GetBaseClass("AliVCluster")) {
304
305     for (Int_t i = 0; i < n; i++) {
306
307       pt[i] = -FLT_MAX;
308
309       AliVCluster* cluster = static_cast<AliVCluster*>(array->At(i));
310       
311       if (!cluster) {
312         AliError(Form("Could not receive cluster %d", i));
313         continue;
314       }  
315       
316       if (!AcceptCluster(cluster))
317         continue;
318
319       TLorentzVector nPart;
320       cluster->GetMomentum(nPart, const_cast<Double_t*>(fVertex));
321       
322       pt[nacc] = nPart.Pt();
323       nacc++;
324     }
325   }
326
327   if (nacc > 0)
328     TMath::Sort(nacc, pt, indexes);
329
330   return nacc;
331 }
332
333 //________________________________________________________________________
334 Bool_t AliAnalysisTaskEmcalJet::IsJetCluster(AliEmcalJet* jet, Int_t iclus, Bool_t sorted) const
335 {
336   // Return true if cluster is in jet.
337
338   for (Int_t i = 0; i < jet->GetNumberOfClusters(); ++i) {
339     Int_t ijetclus = jet->ClusterAt(i);
340     if (sorted && ijetclus > iclus)
341       return kFALSE;
342     if (ijetclus == iclus)
343       return kTRUE;
344   }
345   return kFALSE;
346 }
347
348 //________________________________________________________________________
349 Bool_t AliAnalysisTaskEmcalJet::IsJetTrack(AliEmcalJet* jet, Int_t itrack, Bool_t sorted) const
350 {
351   // Return true if track is in jet.
352
353   for (Int_t i = 0; i < jet->GetNumberOfTracks(); ++i) {
354     Int_t ijettrack = jet->TrackAt(i);
355     if (sorted && ijettrack > itrack)
356       return kFALSE;
357     if (ijettrack == itrack)
358       return kTRUE;
359   }
360   return kFALSE;
361 }
362
363 //________________________________________________________________________
364 Bool_t AliAnalysisTaskEmcalJet::RetrieveEventObjects()
365 {
366   // Retrieve objects from event.
367
368   if (!AliAnalysisTaskEmcal::RetrieveEventObjects())
369     return kFALSE;
370
371   if (fRho)
372     fRhoVal = fRho->GetVal();
373
374   return kTRUE;
375 }