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