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