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