]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGJE/EMCALJetTasks/AliEmcalJetTask.cxx
Merge branch 'master' into flatdev
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / AliEmcalJetTask.cxx
CommitLineData
542ac102 1//
2// Emcal jet finder task.
3//
b65fac7a 4// Authors: C.Loizides, S.Aiola
48d874ff 5
c64cb1f6 6#include <vector>
04905231 7#include "AliEmcalJetTask.h"
8
6ea168d0 9#include <TChain.h>
48d874ff 10#include <TClonesArray.h>
6ea168d0 11#include <TList.h>
12#include <TLorentzVector.h>
ca5c29fa 13#include <TMath.h>
6421eeb0 14#include <TRandom3.h>
b65fac7a 15
48d874ff 16#include "AliAnalysisManager.h"
6ea168d0 17#include "AliCentrality.h"
f5f3c8e9 18#include "AliEMCALGeometry.h"
04905231 19#include "AliESDEvent.h"
f5f3c8e9 20#include "AliEmcalJet.h"
04905231 21#include "AliEmcalParticle.h"
63206072 22#include "AliFJWrapper.h"
04905231 23#include "AliMCEvent.h"
35789a2d 24#include "AliVCluster.h"
b65fac7a 25#include "AliVEvent.h"
04905231 26#include "AliVParticle.h"
c2aad3ae 27using std::cout;
28using std::endl;
29using std::cerr;
48d874ff 30
914d486c 31ClassImp(AliEmcalJetTask)
48d874ff 32
6ea168d0 33//________________________________________________________________________
914d486c 34AliEmcalJetTask::AliEmcalJetTask() :
35 AliAnalysisTaskSE("AliEmcalJetTask"),
6ea168d0 36 fTracksName("Tracks"),
37 fCaloName("CaloClusters"),
38 fJetsName("Jets"),
6a20534a 39 fJetType(kNone),
d1f2e0d9 40 fConstSel(0),
41 fMCConstSel(0),
6a20534a 42 fMarkConst(kFALSE),
6ea168d0 43 fRadius(0.4),
914d486c 44 fMinJetTrackPt(0.15),
45 fMinJetClusPt(0.15),
04905231 46 fPhiMin(0),
47 fPhiMax(TMath::TwoPi()),
83086e6c 48 fEtaMin(-0.9),
49 fEtaMax(+0.9),
cba7b46e 50 fMinJetArea(0.005),
f5f3c8e9 51 fMinJetPt(1.0),
c9ad772c 52 fJetPhiMin(-10),
83086e6c 53 fJetPhiMax(+10),
c9ad772c 54 fJetEtaMin(-1),
83086e6c 55 fJetEtaMax(+1),
cba7b46e 56 fGhostArea(0.005),
a7477843 57 fMinMCLabel(0),
751cb2dc 58 fRecombScheme(fastjet::pt_scheme),
6421eeb0 59 fTrackEfficiency(1.),
04905231 60 fIsInit(0),
d14d6e2c 61 fIsPSelSet(0),
04905231 62 fIsMcPart(0),
63 fIsEmcPart(0),
5d0a5007 64 fLegacyMode(kFALSE),
ffdca6aa 65 fCodeDebug(kFALSE),
b65fac7a 66 fJets(0),
04905231 67 fEvent(0),
68 fTracks(0),
69 fClus(0)
6ea168d0 70{
71 // Default constructor.
6ea168d0 72}
73
48d874ff 74//________________________________________________________________________
914d486c 75AliEmcalJetTask::AliEmcalJetTask(const char *name) :
63206072 76 AliAnalysisTaskSE(name),
7efbea04 77 fTracksName("Tracks"),
48d874ff 78 fCaloName("CaloClusters"),
7efbea04 79 fJetsName("Jets"),
6a20534a 80 fJetType(kAKT|kFullJet|kRX1Jet),
d1f2e0d9 81 fConstSel(0),
82 fMCConstSel(0),
6a20534a 83 fMarkConst(kFALSE),
48d874ff 84 fRadius(0.4),
6ea168d0 85 fMinJetTrackPt(0.15),
914d486c 86 fMinJetClusPt(0.15),
04905231 87 fPhiMin(0),
88 fPhiMax(TMath::TwoPi()),
83086e6c 89 fEtaMin(-0.9),
90 fEtaMax(+0.9),
cba7b46e 91 fMinJetArea(0.001),
f5f3c8e9 92 fMinJetPt(1.0),
c9ad772c 93 fJetPhiMin(-10),
83086e6c 94 fJetPhiMax(+10),
c9ad772c 95 fJetEtaMin(-1),
83086e6c 96 fJetEtaMax(+1),
cba7b46e 97 fGhostArea(0.005),
a7477843 98 fMinMCLabel(0),
751cb2dc 99 fRecombScheme(fastjet::pt_scheme),
6421eeb0 100 fTrackEfficiency(1.),
04905231 101 fIsInit(0),
d14d6e2c 102 fIsPSelSet(0),
04905231 103 fIsMcPart(0),
104 fIsEmcPart(0),
31bab07e 105 fLegacyMode(kFALSE),
ffdca6aa 106 fCodeDebug(kFALSE),
b65fac7a 107 fJets(0),
04905231 108 fEvent(0),
109 fTracks(0),
110 fClus(0)
48d874ff 111{
112 // Standard constructor.
7efbea04 113
7efbea04 114 fBranchNames="ESD:AliESDRun.,AliESDHeader.,PrimaryVertex.";
48d874ff 115}
116
117//________________________________________________________________________
914d486c 118AliEmcalJetTask::~AliEmcalJetTask()
48d874ff 119{
120 // Destructor
121}
122
123//________________________________________________________________________
914d486c 124void AliEmcalJetTask::UserCreateOutputObjects()
48d874ff 125{
126 // Create user objects.
127
914d486c 128 fJets = new TClonesArray("AliEmcalJet");
48d874ff 129 fJets->SetName(fJetsName);
48d874ff 130}
131
132//________________________________________________________________________
914d486c 133void AliEmcalJetTask::UserExec(Option_t *)
48d874ff 134{
135 // Main loop, called for each event.
04905231 136 if (!fIsInit) {
137 if (!DoInit())
138 return;
139 fIsInit = kTRUE;
1772fe65 140 }
b65fac7a 141
918dd8c8 142 // clear the jet array (normally a null operation)
143 fJets->Delete();
144
04905231 145 FindJets();
48d874ff 146}
147
148//________________________________________________________________________
914d486c 149void AliEmcalJetTask::Terminate(Option_t *)
48d874ff 150{
151 // Called once at the end of the analysis.
48d874ff 152}
153
154//________________________________________________________________________
04905231 155void AliEmcalJetTask::FindJets()
48d874ff 156{
157 // Find jets.
3c5aff5d 158 if (!fTracks && !fClus){
159 cout << "WARNING NO TRACKS OR CLUSTERS:" <<endl;
d03084cd 160 return;
3c5aff5d 161 }
162
48d874ff 163 TString name("kt");
164 fastjet::JetAlgorithm jalgo(fastjet::kt_algorithm);
6a20534a 165 if ((fJetType & kAKT) != 0) {
48d874ff 166 name = "antikt";
167 jalgo = fastjet::antikt_algorithm;
ca5c29fa 168 AliDebug(1,"Using AKT algorithm");
169 }
170 else {
171 AliDebug(1,"Using KT algorithm");
48d874ff 172 }
173
6a20534a 174 if ((fJetType & kR020Jet) != 0)
175 fRadius = 0.2;
176 else if ((fJetType & kR030Jet) != 0)
177 fRadius = 0.3;
178 else if ((fJetType & kR040Jet) != 0)
179 fRadius = 0.4;
180
04905231 181 // setup fj wrapper
48d874ff 182 AliFJWrapper fjw(name, name);
f5f3c8e9 183 fjw.SetAreaType(fastjet::active_area_explicit_ghosts);
1f9c287f 184 fjw.SetGhostArea(fGhostArea);
04905231 185 fjw.SetR(fRadius);
7071e730 186 fjw.SetAlgorithm(jalgo);
31bab07e 187 fjw.SetRecombScheme(static_cast<fastjet::RecombinationScheme>(fRecombScheme));
83086e6c 188 fjw.SetMaxRap(fEtaMax);
48d874ff 189 fjw.Clear();
190
04905231 191 // get primary vertex
192 Double_t vertex[3] = {0, 0, 0};
816bb2c8 193 if(fEvent->GetPrimaryVertex()) fEvent->GetPrimaryVertex()->GetXYZ(vertex);
04905231 194
ca5c29fa 195 AliDebug(2,Form("Jet type = %d", fJetType));
6a20534a 196
197 if ((fIsMcPart || ((fJetType & kFullJet) != 0) || ((fJetType & kChargedJet) != 0)) && fTracks) {
04905231 198 const Int_t Ntracks = fTracks->GetEntries();
48d874ff 199 for (Int_t iTracks = 0; iTracks < Ntracks; ++iTracks) {
04905231 200 AliVParticle *t = static_cast<AliVParticle*>(fTracks->At(iTracks));
48d874ff 201 if (!t)
202 continue;
6a20534a 203 if (fIsMcPart) {
5be3857d 204 if (((fJetType & kChargedJet) != 0) && (t->Charge() == 0)) {
205 AliDebug(2,Form("Skipping track %d because it is neutral.", iTracks));
6a20534a 206 continue;
5be3857d 207 }
208 if (((fJetType & kNeutralJet) != 0) && (t->Charge() != 0)) {
209 AliDebug(2,Form("Skipping track %d because it is charged.", iTracks));
6a20534a 210 continue;
5be3857d 211 }
6a20534a 212 }
a7477843 213 if (fIsMcPart || TMath::Abs(t->GetLabel()) > fMinMCLabel) {
d1f2e0d9 214 if (t->TestBits(fMCConstSel) != (Int_t)fMCConstSel) {
215 AliDebug(2,Form("Skipping track %d because it does not match the bit mask (%d, %d)", iTracks, fMCConstSel, t->TestBits(TObject::kBitMask)));
6a20534a 216 continue;
217 }
d1f2e0d9 218 else {
219 AliDebug(2,Form("Track %d matches the bit mask (%d, %d)", iTracks, fMCConstSel, t->TestBits(TObject::kBitMask)));
ca5c29fa 220 }
6a20534a 221 }
222 else {
d1f2e0d9 223 if (t->TestBits(fConstSel) != (Int_t)fConstSel) {
224 AliDebug(2,Form("Skipping track %d because it does not match the bit mask (%d, %d)", iTracks, fConstSel, t->TestBits(TObject::kBitMask)));
6a20534a 225 continue;
226 }
d1f2e0d9 227 else {
228 AliDebug(2,Form("Track %d matches the bit mask (%d, %d)", iTracks, fConstSel, t->TestBits(TObject::kBitMask)));
ca5c29fa 229 }
230 }
1772fe65 231 if (t->Pt() < fMinJetTrackPt)
914d486c 232 continue;
04905231 233 Double_t eta = t->Eta();
234 Double_t phi = t->Phi();
ddf74a88 235 if ((eta<fEtaMin) || (eta>fEtaMax) ||
236 (phi<fPhiMin) || (phi>fPhiMax))
04905231 237 continue;
da67b88a 238
6421eeb0 239 // artificial inefficiency
240 if (fTrackEfficiency < 1.) {
241 Double_t rnd = gRandom->Rndm();
242 if (fTrackEfficiency < rnd) {
243 AliDebug(2,Form("Track %d rejected due to artificial tracking inefficiency", iTracks));
244 continue;
245 }
246 }
247
a3c8c8c8 248 // offset of 100 for consistency with cluster ids
ca5c29fa 249 AliDebug(2,Form("Track %d accepted (label = %d, pt = %f)", iTracks, t->GetLabel(), t->Pt()));
751cb2dc 250 fjw.AddInputVector(t->Px(), t->Py(), t->Pz(), t->E(), iTracks + 100);
48d874ff 251 }
252 }
6ea168d0 253
6a20534a 254 if ((((fJetType & kFullJet) != 0) || ((fJetType & kNeutralJet) != 0)) && fClus) {
da67b88a 255 const Int_t Nclus = fClus->GetEntries();
256 for (Int_t iClus = 0; iClus < Nclus; ++iClus) {
257 AliVCluster *c = 0;
258 Double_t cEta=0,cPhi=0,cPt=0;
259 Double_t cPx=0,cPy=0,cPz=0;
260 if (fIsEmcPart) {
261 AliEmcalParticle *ep = static_cast<AliEmcalParticle*>(fClus->At(iClus));
262 if (!ep)
263 continue;
6a20534a 264
da67b88a 265 c = ep->GetCluster();
266 if (!c)
6a20534a 267 continue;
268
a7477843 269 if (c->GetLabel() > fMinMCLabel) {
d1f2e0d9 270 if (ep->TestBits(fMCConstSel) != (Int_t)fMCConstSel) {
271 AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fMCConstSel, ep->TestBits(TObject::kBitMask)));
6a20534a 272 continue;
ca5c29fa 273 }
d1f2e0d9 274 else {
275 AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fMCConstSel, ep->TestBits(TObject::kBitMask)));
ca5c29fa 276 }
6a20534a 277 }
278 else {
d1f2e0d9 279 if (ep->TestBits(fConstSel) != (Int_t)fConstSel) {
280 AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fConstSel, ep->TestBits(TObject::kBitMask)));
6a20534a 281 continue;
ca5c29fa 282 }
d1f2e0d9 283 else {
284 AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fConstSel, ep->TestBits(TObject::kBitMask)));
ca5c29fa 285 }
6a20534a 286 }
287
da67b88a 288 cEta = ep->Eta();
289 cPhi = ep->Phi();
290 cPt = ep->Pt();
291 cPx = ep->Px();
292 cPy = ep->Py();
293 cPz = ep->Pz();
294 } else {
295 c = static_cast<AliVCluster*>(fClus->At(iClus));
296 if (!c)
297 continue;
6a20534a 298
a7477843 299 if (c->GetLabel() > fMinMCLabel) {
d1f2e0d9 300 if (c->TestBits(fMCConstSel) != (Int_t)fMCConstSel) {
301 AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fMCConstSel, c->TestBits(TObject::kBitMask)));
6a20534a 302 continue;
ca5c29fa 303 }
d1f2e0d9 304 else {
305 AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fMCConstSel, c->TestBits(TObject::kBitMask)));
ca5c29fa 306 }
6a20534a 307 }
308 else {
d1f2e0d9 309 if (c->TestBits(fConstSel) != (Int_t)fConstSel) {
310 AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fConstSel, c->TestBits(TObject::kBitMask)));
6a20534a 311 continue;
ca5c29fa 312 }
d1f2e0d9 313 else {
314 AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fConstSel, c->TestBits(TObject::kBitMask)));
ca5c29fa 315 }
6a20534a 316 }
317
da67b88a 318 TLorentzVector nP;
319 c->GetMomentum(nP, vertex);
320 cEta = nP.Eta();
321 cPhi = nP.Phi();
322 cPt = nP.Pt();
323 cPx = nP.Px();
324 cPy = nP.Py();
325 cPz = nP.Pz();
04905231 326 }
da67b88a 327 if (!c->IsEMCAL())
328 continue;
329 if (cPt < fMinJetClusPt)
330 continue;
ddf74a88 331 if ((cEta<fEtaMin) || (cEta>fEtaMax) ||
332 (cPhi<fPhiMin) || (cPhi>fPhiMax))
da67b88a 333 continue;
334 // offset of 100 to skip ghost particles uid = -1
ca5c29fa 335 AliDebug(2,Form("Cluster %d accepted (label = %d)", iClus, c->GetLabel()));
f660c2d6 336 fjw.AddInputVector(cPx, cPy, cPz, TMath::Sqrt(cPx*cPx+cPy*cPy+cPz*cPz), -iClus - 100);
48d874ff 337 }
338 }
5d0a5007 339
340 // setting legacy mode
341 if (fLegacyMode) {
342 fjw.SetLegacyMode(kTRUE);
343 }
344
7efbea04 345 // run jet finder
48d874ff 346 fjw.Run();
f5f3c8e9 347
348 // get geometry
349 AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
350 if (!geom) {
02c7e943 351 AliFatal(Form("%s: Can not create geometry", GetName()));
f5f3c8e9 352 return;
353 }
04905231 354
355 // loop over fastjet jets
48d874ff 356 std::vector<fastjet::PseudoJet> jets_incl = fjw.GetInclusiveJets();
ca5c29fa 357 // sort jets according to jet pt
358 static Int_t indexes[9999] = {-1};
359 GetSortedArray(indexes, jets_incl);
360
361 AliDebug(1,Form("%d jets found", (Int_t)jets_incl.size()));
362 for (UInt_t ijet=0, jetCount=0; ijet<jets_incl.size(); ++ijet) {
363 Int_t ij = indexes[ijet];
364 AliDebug(3,Form("Jet pt = %f, area = %f", jets_incl[ij].perp(), fjw.GetJetArea(ij)));
365
f5f3c8e9 366 if (jets_incl[ij].perp()<fMinJetPt)
367 continue;
368 if (fjw.GetJetArea(ij)<fMinJetArea)
48d874ff 369 continue;
c9ad772c 370 if ((jets_incl[ij].eta()<fJetEtaMin) || (jets_incl[ij].eta()>fJetEtaMax) ||
371 (jets_incl[ij].phi()<fJetPhiMin) || (jets_incl[ij].phi()>fJetPhiMax))
372 continue;
04905231 373
914d486c 374 AliEmcalJet *jet = new ((*fJets)[jetCount])
375 AliEmcalJet(jets_incl[ij].perp(), jets_incl[ij].eta(), jets_incl[ij].phi(), jets_incl[ij].m());
04905231 376
377 // loop over constituents
c64cb1f6 378 std::vector<fastjet::PseudoJet> constituents(fjw.GetJetConstituents(ij));
04905231 379 jet->SetNumberOfTracks(constituents.size());
380 jet->SetNumberOfClusters(constituents.size());
381
b65fac7a 382 Int_t nt = 0;
383 Int_t nc = 0;
f5f3c8e9 384 Double_t neutralE = 0;
111318e8 385 Double_t maxCh = 0;
386 Double_t maxNe = 0;
f5f3c8e9 387 Int_t gall = 0;
388 Int_t gemc = 0;
04905231 389 Int_t cemc = 0;
111318e8 390 Int_t ncharged = 0;
391 Int_t nneutral = 0;
02c7e943 392 Double_t mcpt = 0;
04905231 393 Double_t emcpt = 0;
b65fac7a 394
b65fac7a 395 for(UInt_t ic = 0; ic < constituents.size(); ++ic) {
48d874ff 396 Int_t uid = constituents[ic].user_index();
5be3857d 397 AliDebug(3,Form("Processing constituent %d", uid));
04905231 398 if ((uid == -1) /*&& (constituents[ic].kt2() < 1e-25)*/) { //ghost particle
f5f3c8e9 399 ++gall;
04905231 400 Double_t gphi = constituents[ic].phi();
401 if (gphi<0)
402 gphi += TMath::TwoPi();
403 gphi *= TMath::RadToDeg();
f5f3c8e9 404 Double_t geta = constituents[ic].eta();
b65fac7a 405 if ((gphi > geom->GetArm1PhiMin()) && (gphi < geom->GetArm1PhiMax()) &&
406 (geta > geom->GetArm1EtaMin()) && (geta < geom->GetArm1EtaMax()))
04905231 407 ++gemc;
408 } else if ((uid > 0) && fTracks) { // track constituent
111318e8 409 Int_t tid = uid - 100;
04905231 410 AliVParticle *t = static_cast<AliVParticle*>(fTracks->At(tid));
ca5c29fa 411 if (!t) {
412 AliError(Form("Could not find track %d",tid));
04905231 413 continue;
ca5c29fa 414 }
415 if (jetCount < fMarkConst) {
416 AliDebug(2,Form("Marking track %d with bit map %d", tid, fJetType));
6a20534a 417 t->SetBit(fJetType);
ca5c29fa 418 }
04905231 419 Double_t cEta = t->Eta();
420 Double_t cPhi = t->Phi();
421 Double_t cPt = t->Pt();
422 Double_t cP = t->P();
423 if (t->Charge() == 0) {
424 neutralE += cP;
425 ++nneutral;
426 if (cPt > maxNe)
427 maxNe = cPt;
428 } else {
429 ++ncharged;
430 if (cPt > maxCh)
431 maxCh = cPt;
432 }
a7477843 433 if (fIsMcPart || TMath::Abs(t->GetLabel()) > fMinMCLabel) // check if MC particle
04905231 434 mcpt += cPt;
435
436 if (cPhi<0)
437 cPhi += TMath::TwoPi();
438 cPhi *= TMath::RadToDeg();
439 if ((cPhi > geom->GetArm1PhiMin()) && (cPhi < geom->GetArm1PhiMax()) &&
440 (cEta > geom->GetArm1EtaMin()) && (cEta < geom->GetArm1EtaMax())) {
441 emcpt += cPt;
442 ++cemc;
d03084cd 443 }
04905231 444
445 jet->AddTrackAt(tid, nt);
446 ++nt;
447 } else if (fClus) { // cluster constituent
111318e8 448 Int_t cid = -uid - 100;
04905231 449 AliVCluster *c = 0;
450 Double_t cEta=0,cPhi=0,cPt=0,cP=0;
451 if (fIsEmcPart) {
452 AliEmcalParticle *ep = static_cast<AliEmcalParticle*>(fClus->At(cid));
453 if (!ep)
454 continue;
455 c = ep->GetCluster();
456 if (!c)
457 continue;
7030f36f 458 if (jetCount < fMarkConst)
6a20534a 459 ep->SetBit(fJetType);
04905231 460 cEta = ep->Eta();
461 cPhi = ep->Phi();
462 cPt = ep->Pt();
463 cP = ep->P();
464 } else {
465 c = static_cast<AliVCluster*>(fClus->At(cid));
466 if (!c)
467 continue;
7030f36f 468 if (jetCount < fMarkConst)
6a20534a 469 c->SetBit(fJetType);
04905231 470 TLorentzVector nP;
471 c->GetMomentum(nP, vertex);
472 cEta = nP.Eta();
473 cPhi = nP.Phi();
474 cPt = nP.Pt();
475 cP = nP.P();
476 }
477
478 neutralE += cP;
479 if (cPt > maxNe)
480 maxNe = cPt;
481
a7477843 482 if (c->GetLabel() > fMinMCLabel) // MC particle
43032ce2 483 mcpt += c->GetMCEnergyFraction() > 1e-6 ? cPt * c->GetMCEnergyFraction() : cPt;
04905231 484
485 if (cPhi<0)
486 cPhi += TMath::TwoPi();
487 cPhi *= TMath::RadToDeg();
488 if ((cPhi > geom->GetArm1PhiMin()) && (cPhi < geom->GetArm1PhiMax()) &&
489 (cEta > geom->GetArm1EtaMin()) && (cEta < geom->GetArm1EtaMax())) {
490 emcpt += cPt;
491 ++cemc;
492 }
493
494 jet->AddClusterAt(cid, nc);
495 ++nc;
496 ++nneutral;
02c7e943 497 } else {
498 AliError(Form("%s: No logical way to end up here.", GetName()));
499 continue;
48d874ff 500 }
04905231 501 } /* end of constituent loop */
502
35789a2d 503 jet->SetNumberOfTracks(nt);
504 jet->SetNumberOfClusters(nc);
f5f3c8e9 505 jet->SortConstituents();
111318e8 506 jet->SetMaxNeutralPt(maxNe);
507 jet->SetMaxChargedPt(maxCh);
b65fac7a 508 jet->SetNEF(neutralE / jet->E());
a88b5c99 509 fastjet::PseudoJet area(fjw.GetJetAreaVector(ij));
510 jet->SetArea(area.perp());
511 jet->SetAreaEta(area.eta());
512 jet->SetAreaPhi(area.phi());
111318e8 513 jet->SetNumberOfCharged(ncharged);
514 jet->SetNumberOfNeutrals(nneutral);
02c7e943 515 jet->SetMCPt(mcpt);
04905231 516 jet->SetNEmc(cemc);
517 jet->SetPtEmc(emcpt);
518
b65fac7a 519 if (gall > 0)
520 jet->SetAreaEmc(fjw.GetJetArea(ij) * gemc / gall);
f5f3c8e9 521 else
522 jet->SetAreaEmc(-1);
b65fac7a 523 if ((jet->Phi() > geom->GetArm1PhiMin() * TMath::DegToRad()) &&
1772fe65 524 (jet->Phi() < geom->GetArm1PhiMax() * TMath::DegToRad()) &&
525 (jet->Eta() > geom->GetArm1EtaMin()) &&
526 (jet->Eta() < geom->GetArm1EtaMax()))
f5f3c8e9 527 jet->SetAxisInEmcal(kTRUE);
ca5c29fa 528
529 AliDebug(2,Form("Added jet n. %d, pt = %f, area = %f, constituents = %d", jetCount, jet->Pt(), jet->Area(), (Int_t)constituents.size()));
48d874ff 530 jetCount++;
531 }
7030f36f 532 //fJets->Sort();
48d874ff 533}
04905231 534
ca5c29fa 535//________________________________________________________________________
536Bool_t AliEmcalJetTask::GetSortedArray(Int_t indexes[], std::vector<fastjet::PseudoJet> array) const
537{
538 // Get the leading jets.
539
540 static Float_t pt[9999] = {0};
541
542 const Int_t n = (Int_t)array.size();
543
544 if (n < 1)
545 return kFALSE;
546
547 for (Int_t i = 0; i < n; i++)
548 pt[i] = array[i].perp();
549
550 TMath::Sort(n, pt, indexes);
551
552 return kTRUE;
553}
554
04905231 555//________________________________________________________________________
556Bool_t AliEmcalJetTask::DoInit()
557{
558 // Init. Return true if successful.
559
6421eeb0 560 if (fTrackEfficiency < 1.) {
561 if (gRandom) delete gRandom;
562 gRandom = new TRandom3(0);
563 }
564
04905231 565 // get input collections
566 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
567
568 // get the event
569 fEvent = InputEvent();
570 if (!fEvent) {
571 AliError(Form("%s: Could not retrieve event! Returning", GetName()));
572 return 0;
573 }
574
575 // add jets to event if not yet there
576 if (!(fEvent->FindListObject(fJetsName)))
577 fEvent->AddObject(fJets);
578 else {
f4b49fa6 579 AliError(Form("%s: Object with name %s already in event! Returning", GetName(), fJetsName.Data()));
04905231 580 return 0;
581 }
582
da67b88a 583 if (fTracksName == "Tracks")
584 am->LoadBranch("Tracks");
585 if (!fTracks && !fTracksName.IsNull()) {
586 fTracks = dynamic_cast<TClonesArray*>(fEvent->FindListObject(fTracksName));
587 if (!fTracks) {
588 AliError(Form("%s: Pointer to tracks %s == 0", GetName(), fTracksName.Data()));
589 return 0;
04905231 590 }
da67b88a 591 }
592 if (fTracks) {
593 TClass cls(fTracks->GetClass()->GetName());
5be3857d 594 if (cls.InheritsFrom("AliMCParticle") || cls.InheritsFrom("AliAODMCParticle"))
04905231 595 fIsMcPart = 1;
596 }
da67b88a 597
598 if (fCaloName == "CaloClusters")
599 am->LoadBranch("CaloClusters");
600 if (!fClus && !fCaloName.IsNull()) {
601 fClus = dynamic_cast<TClonesArray*>(fEvent->FindListObject(fCaloName));
602 if (!fClus) {
603 AliError(Form("%s: Pointer to clus %s == 0", GetName(), fCaloName.Data()));
604 return 0;
04905231 605 }
da67b88a 606 }
607 if (fClus) {
608 TClass cls(fClus->GetClass()->GetName());
04905231 609 if (cls.InheritsFrom("AliEmcalParticle"))
610 fIsEmcPart = 1;
611 }
612
613 return 1;
614}