]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGJE/EMCALJetTasks/AliAnalysisTaskEmcalJet.cxx
timing calibration for 2013 period added
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / AliAnalysisTaskEmcalJet.cxx
CommitLineData
8628b70c 1// $Id$
a546db49 2//
3// Emcal jet analysis base task.
4//
5// Author: S.Aiola
6
7#include "AliAnalysisTaskEmcalJet.h"
8
a546db49 9#include <TChain.h>
10#include <TClonesArray.h>
11#include <TList.h>
8f3e275e 12#include <TObject.h>
a546db49 13
a546db49 14#include "AliAnalysisManager.h"
15#include "AliCentrality.h"
8f3e275e 16#include "AliEMCALGeometry.h"
17#include "AliESDEvent.h"
a546db49 18#include "AliEmcalJet.h"
a546db49 19#include "AliLog.h"
e2c9f708 20#include "AliRhoParameter.h"
7dd1eeea 21#include "AliLocalRhoParameter.h"
8f3e275e 22#include "AliVCluster.h"
23#include "AliVEventHandler.h"
24#include "AliVParticle.h"
a546db49 25
26ClassImp(AliAnalysisTaskEmcalJet)
27
28//________________________________________________________________________
29AliAnalysisTaskEmcalJet::AliAnalysisTaskEmcalJet() :
30 AliAnalysisTaskEmcal("AliAnalysisTaskEmcalJet"),
31 fJetRadius(0.4),
e2c9f708 32 fJetsName(),
a487deae 33 fRhoName(),
7dd1eeea 34 fLocalRhoName(),
a487deae 35 fPtBiasJetTrack(0),
36 fPtBiasJetClus(0),
a546db49 37 fJetPtCut(1),
1b4db73a 38 fJetAreaCut(-1),
a487deae 39 fPercAreaCut(-1),
40 fAreaEmcCut(0),
41 fJetMinEta(-0.9),
42 fJetMaxEta(0.9),
43 fJetMinPhi(-10),
44 fJetMaxPhi(10),
b9a9ae7e 45 fMaxClusterPt(1000),
411b11e0 46 fMaxTrackPt(100),
83888eef 47 fLeadingHadronType(0),
63fac07f 48 fNLeadingJets(1),
2103dc6a 49 fJetBitMap(0),
85d48773 50 fJetTrigger(0),
a487deae 51 fJets(0),
52 fRho(0),
7dd1eeea 53 fLocalRho(0),
a487deae 54 fRhoVal(0)
a546db49 55{
56 // Default constructor.
57}
58
a546db49 59//________________________________________________________________________
60AliAnalysisTaskEmcalJet::AliAnalysisTaskEmcalJet(const char *name, Bool_t histo) :
61 AliAnalysisTaskEmcal(name, histo),
62 fJetRadius(0.4),
e2c9f708 63 fJetsName(),
a487deae 64 fRhoName(),
7dd1eeea 65 fLocalRhoName(),
a487deae 66 fPtBiasJetTrack(0),
67 fPtBiasJetClus(0),
a546db49 68 fJetPtCut(1),
1b4db73a 69 fJetAreaCut(-1),
a487deae 70 fPercAreaCut(-1),
71 fAreaEmcCut(0),
72 fJetMinEta(-0.9),
73 fJetMaxEta(0.9),
74 fJetMinPhi(-10),
75 fJetMaxPhi(10),
b9a9ae7e 76 fMaxClusterPt(1000),
411b11e0 77 fMaxTrackPt(100),
83888eef 78 fLeadingHadronType(0),
63fac07f 79 fNLeadingJets(1),
2103dc6a 80 fJetBitMap(0),
85d48773 81 fJetTrigger(0),
a487deae 82 fJets(0),
83 fRho(0),
7dd1eeea 84 fLocalRho(0),
a487deae 85 fRhoVal(0)
a546db49 86{
87 // Standard constructor.
88}
89
90//________________________________________________________________________
91AliAnalysisTaskEmcalJet::~AliAnalysisTaskEmcalJet()
92{
93 // Destructor
94}
95
2bddb6ae 96//________________________________________________________________________
97Bool_t AliAnalysisTaskEmcalJet::AcceptBiasJet(AliEmcalJet *jet) const
98{
76bc10fe 99 // Accept jet with a bias.
100
83888eef 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//________________________________________________________________________
115Float_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//________________________________________________________________________
129Double_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();
2bddb6ae 137}
138
a546db49 139//________________________________________________________________________
a487deae 140Bool_t AliAnalysisTaskEmcalJet::AcceptJet(AliEmcalJet *jet) const
a546db49 141{
142 // Return true if jet is accepted.
2103dc6a 143 if (!jet)
144 return kFALSE;
145
146 if (jet->TestBits(fJetBitMap) != (Int_t)fJetBitMap)
147 return kFALSE;
a546db49 148
07bdd4b0 149 if (jet->Pt() < fJetPtCut)
a546db49 150 return kFALSE;
ca5c29fa 151
07bdd4b0 152 if (jet->Area() < fJetAreaCut)
a546db49 153 return kFALSE;
ca5c29fa 154
a487deae 155 if (jet->AreaEmc()<fAreaEmcCut)
a546db49 156 return kFALSE;
ca5c29fa 157
a487deae 158 if (!AcceptBiasJet(jet))
159 return kFALSE;
ca5c29fa 160
a487deae 161 if (jet->MaxTrackPt() > fMaxTrackPt || jet->MaxClusterPt() > fMaxClusterPt)
411b11e0 162 return kFALSE;
a546db49 163
6f18d73a 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
85d48773 170 if (fJetTrigger != 0 && !jet->IsTriggerJet(fJetTrigger))
171 return kFALSE;
172
6f18d73a 173 return (Bool_t)(jetEta > fJetMinEta && jetEta < fJetMaxEta && jetPhi > fJetMinPhi && jetPhi < fJetMaxPhi);
1f6fff78 174}
175
e2c9f708 176//________________________________________________________________________
177AliRhoParameter *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}
7dd1eeea 192//________________________________________________________________________
193AliLocalRhoParameter *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}
1f6fff78 207//________________________________________________________________________
abc24170 208void AliAnalysisTaskEmcalJet::ExecOnce()
1f6fff78 209{
210 // Init the analysis.
211
a487deae 212 AliAnalysisTaskEmcal::ExecOnce();
213
a5621834 214 if (fPercAreaCut >= 0) {
60b1665c 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()));
a5621834 217 fJetAreaCut = fPercAreaCut * fJetRadius * fJetRadius * TMath::Pi();
218 }
1b4db73a 219 if (fJetAreaCut < 0)
220 fJetAreaCut = 0;
a5621834 221
1f6fff78 222 if (fAnaType == kTPC) {
a487deae 223 SetJetEtaLimits(-0.5, 0.5);
224 SetJetPhiLimits(-10, 10);
a487deae 225 }
226 else if (fAnaType == kEMCAL && fGeom) {
56f370b0 227
a487deae 228 SetJetEtaLimits(fGeom->GetArm1EtaMin() + fJetRadius, fGeom->GetArm1EtaMax() - fJetRadius);
56f370b0 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
a487deae 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
7dd1eeea 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
a487deae 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;
e44e8726 262 }
a487deae 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;
1f6fff78 268 }
1f6fff78 269 }
a487deae 270}
1f6fff78 271
a487deae 272//________________________________________________________________________
43032ce2 273Int_t AliAnalysisTaskEmcalJet::GetSortedArray(Int_t indexes[], TClonesArray *array, Double_t rho) const
a487deae 274{
275 // Get the leading jets.
abc24170 276
ca5c29fa 277 static Float_t pt[9999] = {0};
a487deae 278
279 if (!array)
280 return 0;
281
282 const Int_t n = array->GetEntriesFast();
283
43032ce2 284 Int_t nacc = 0;
285
9f52c61f 286 if (n < 1)
ca5c29fa 287 return kFALSE;
9f52c61f 288
289 if (array->GetClass()->GetBaseClass("AliEmcalJet")) {
a487deae 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
43032ce2 305 pt[nacc] = jet->Pt() - rho * jet->Area();
306 nacc++;
a487deae 307 }
308 }
309
9f52c61f 310 else if (array->GetClass()->GetBaseClass("AliVTrack")) {
a487deae 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
43032ce2 326 pt[nacc] = track->Pt();
327 nacc++;
a487deae 328 }
329 }
330
9f52c61f 331 else if (array->GetClass()->GetBaseClass("AliVCluster")) {
a487deae 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
43032ce2 350 pt[nacc] = nPart.Pt();
351 nacc++;
a487deae 352 }
353 }
354
43032ce2 355 if (nacc > 0)
356 TMath::Sort(nacc, pt, indexes);
a487deae 357
43032ce2 358 return nacc;
1f6fff78 359}
360
361//________________________________________________________________________
76bc10fe 362Bool_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//________________________________________________________________________
377Bool_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//________________________________________________________________________
392Bool_t AliAnalysisTaskEmcalJet::RetrieveEventObjects()
1f6fff78 393{
76bc10fe 394 // Retrieve objects from event.
1f6fff78 395
76bc10fe 396 if (!AliAnalysisTaskEmcal::RetrieveEventObjects())
397 return kFALSE;
398
a487deae 399 if (fRho)
400 fRhoVal = fRho->GetVal();
76bc10fe 401
402 return kTRUE;
a546db49 403}