3 // Emcal jet finder task.
5 // Authors: C.Loizides, S.Aiola
8 #include "AliEmcalJetTask.h"
11 #include <TClonesArray.h>
13 #include <TLorentzVector.h>
16 #include "AliAnalysisManager.h"
17 #include "AliCentrality.h"
18 #include "AliEMCALGeometry.h"
19 #include "AliESDEvent.h"
20 #include "AliEmcalJet.h"
21 #include "AliEmcalParticle.h"
22 #include "AliFJWrapper.h"
23 #include "AliMCEvent.h"
24 #include "AliVCluster.h"
25 #include "AliVEvent.h"
26 #include "AliVParticle.h"
28 ClassImp(AliEmcalJetTask)
30 //________________________________________________________________________
31 AliEmcalJetTask::AliEmcalJetTask() :
32 AliAnalysisTaskSE("AliEmcalJetTask"),
33 fTracksName("Tracks"),
34 fCaloName("CaloClusters"),
44 fPhiMax(TMath::TwoPi()),
64 // Default constructor.
67 //________________________________________________________________________
68 AliEmcalJetTask::AliEmcalJetTask(const char *name) :
69 AliAnalysisTaskSE(name),
70 fTracksName("Tracks"),
71 fCaloName("CaloClusters"),
73 fJetType(kAKT|kFullJet|kRX1Jet),
81 fPhiMax(TMath::TwoPi()),
101 // Standard constructor.
103 fBranchNames="ESD:AliESDRun.,AliESDHeader.,PrimaryVertex.";
106 //________________________________________________________________________
107 AliEmcalJetTask::~AliEmcalJetTask()
112 //________________________________________________________________________
113 void AliEmcalJetTask::UserCreateOutputObjects()
115 // Create user objects.
117 fJets = new TClonesArray("AliEmcalJet");
118 fJets->SetName(fJetsName);
121 //________________________________________________________________________
122 void AliEmcalJetTask::UserExec(Option_t *)
124 // Main loop, called for each event.
135 //________________________________________________________________________
136 void AliEmcalJetTask::Terminate(Option_t *)
138 // Called once at the end of the analysis.
141 //________________________________________________________________________
142 void AliEmcalJetTask::FindJets()
146 if (!fTracks && !fClus)
150 fastjet::JetAlgorithm jalgo(fastjet::kt_algorithm);
151 if ((fJetType & kAKT) != 0) {
153 jalgo = fastjet::antikt_algorithm;
154 AliDebug(1,"Using AKT algorithm");
157 AliDebug(1,"Using KT algorithm");
160 if ((fJetType & kR020Jet) != 0)
162 else if ((fJetType & kR030Jet) != 0)
164 else if ((fJetType & kR040Jet) != 0)
168 AliFJWrapper fjw(name, name);
169 fjw.SetAreaType(fastjet::active_area_explicit_ghosts);
170 fjw.SetGhostArea(fGhostArea);
172 fjw.SetAlgorithm(jalgo);
173 fjw.SetMaxRap(fEtaMax);
176 // get primary vertex
177 Double_t vertex[3] = {0, 0, 0};
178 fEvent->GetPrimaryVertex()->GetXYZ(vertex);
180 AliDebug(2,Form("Jet type = %d", fJetType));
182 if ((fIsMcPart || ((fJetType & kFullJet) != 0) || ((fJetType & kChargedJet) != 0)) && fTracks) {
183 const Int_t Ntracks = fTracks->GetEntries();
184 for (Int_t iTracks = 0; iTracks < Ntracks; ++iTracks) {
185 AliVParticle *t = static_cast<AliVParticle*>(fTracks->At(iTracks));
189 if (((fJetType & kChargedJet) != 0) && (t->Charge() == 0)) {
190 AliDebug(2,Form("Skipping track %d because it is neutral.", iTracks));
193 if (((fJetType & kNeutralJet) != 0) && (t->Charge() != 0)) {
194 AliDebug(2,Form("Skipping track %d because it is charged.", iTracks));
198 if (fIsMcPart || TMath::Abs(t->GetLabel()) > fMinMCLabel) {
199 if (t->TestBits(fMCConstSel) != (Int_t)fMCConstSel) {
200 AliDebug(2,Form("Skipping track %d because it does not match the bit mask (%d, %d)", iTracks, fMCConstSel, t->TestBits(TObject::kBitMask)));
204 AliDebug(2,Form("Track %d matches the bit mask (%d, %d)", iTracks, fMCConstSel, t->TestBits(TObject::kBitMask)));
208 if (t->TestBits(fConstSel) != (Int_t)fConstSel) {
209 AliDebug(2,Form("Skipping track %d because it does not match the bit mask (%d, %d)", iTracks, fConstSel, t->TestBits(TObject::kBitMask)));
213 AliDebug(2,Form("Track %d matches the bit mask (%d, %d)", iTracks, fConstSel, t->TestBits(TObject::kBitMask)));
216 if (t->Pt() < fMinJetTrackPt)
218 Double_t eta = t->Eta();
219 Double_t phi = t->Phi();
220 if ((eta<fEtaMin) || (eta>fEtaMax) ||
221 (phi<fPhiMin) || (phi>fPhiMax))
224 // offset of 100 for consistency with cluster ids
225 AliDebug(2,Form("Track %d accepted (label = %d, pt = %f)", iTracks, t->GetLabel(), t->Pt()));
226 fjw.AddInputVector(t->Px(), t->Py(), t->Pz(), t->P(), iTracks + 100);
230 if ((((fJetType & kFullJet) != 0) || ((fJetType & kNeutralJet) != 0)) && fClus) {
231 const Int_t Nclus = fClus->GetEntries();
232 for (Int_t iClus = 0; iClus < Nclus; ++iClus) {
234 Double_t cEta=0,cPhi=0,cPt=0;
235 Double_t cPx=0,cPy=0,cPz=0;
237 AliEmcalParticle *ep = static_cast<AliEmcalParticle*>(fClus->At(iClus));
241 c = ep->GetCluster();
245 if (c->GetLabel() > fMinMCLabel) {
246 if (ep->TestBits(fMCConstSel) != (Int_t)fMCConstSel) {
247 AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fMCConstSel, ep->TestBits(TObject::kBitMask)));
251 AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fMCConstSel, ep->TestBits(TObject::kBitMask)));
255 if (ep->TestBits(fConstSel) != (Int_t)fConstSel) {
256 AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fConstSel, ep->TestBits(TObject::kBitMask)));
260 AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fConstSel, ep->TestBits(TObject::kBitMask)));
271 c = static_cast<AliVCluster*>(fClus->At(iClus));
275 if (c->GetLabel() > fMinMCLabel) {
276 if (c->TestBits(fMCConstSel) != (Int_t)fMCConstSel) {
277 AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fMCConstSel, c->TestBits(TObject::kBitMask)));
281 AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fMCConstSel, c->TestBits(TObject::kBitMask)));
285 if (c->TestBits(fConstSel) != (Int_t)fConstSel) {
286 AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fConstSel, c->TestBits(TObject::kBitMask)));
290 AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fConstSel, c->TestBits(TObject::kBitMask)));
295 c->GetMomentum(nP, vertex);
305 if (cPt < fMinJetClusPt)
307 if ((cEta<fEtaMin) || (cEta>fEtaMax) ||
308 (cPhi<fPhiMin) || (cPhi>fPhiMax))
310 // offset of 100 to skip ghost particles uid = -1
311 AliDebug(2,Form("Cluster %d accepted (label = %d)", iClus, c->GetLabel()));
312 fjw.AddInputVector(cPx, cPy, cPz, TMath::Sqrt(cPx*cPx+cPy*cPy+cPz*cPz), -iClus - 100);
320 AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
322 AliFatal(Form("%s: Can not create geometry", GetName()));
326 // loop over fastjet jets
327 std::vector<fastjet::PseudoJet> jets_incl = fjw.GetInclusiveJets();
328 // sort jets according to jet pt
329 static Int_t indexes[9999] = {-1};
330 GetSortedArray(indexes, jets_incl);
332 AliDebug(1,Form("%d jets found", (Int_t)jets_incl.size()));
333 for (UInt_t ijet=0, jetCount=0; ijet<jets_incl.size(); ++ijet) {
334 Int_t ij = indexes[ijet];
335 AliDebug(3,Form("Jet pt = %f, area = %f", jets_incl[ij].perp(), fjw.GetJetArea(ij)));
337 if (jets_incl[ij].perp()<fMinJetPt)
339 if (fjw.GetJetArea(ij)<fMinJetArea)
341 if ((jets_incl[ij].eta()<fJetEtaMin) || (jets_incl[ij].eta()>fJetEtaMax) ||
342 (jets_incl[ij].phi()<fJetPhiMin) || (jets_incl[ij].phi()>fJetPhiMax))
345 AliEmcalJet *jet = new ((*fJets)[jetCount])
346 AliEmcalJet(jets_incl[ij].perp(), jets_incl[ij].eta(), jets_incl[ij].phi(), jets_incl[ij].m());
348 // loop over constituents
349 std::vector<fastjet::PseudoJet> constituents(fjw.GetJetConstituents(ij));
350 jet->SetNumberOfTracks(constituents.size());
351 jet->SetNumberOfClusters(constituents.size());
355 Double_t neutralE = 0;
366 for(UInt_t ic = 0; ic < constituents.size(); ++ic) {
367 Int_t uid = constituents[ic].user_index();
368 AliDebug(3,Form("Processing constituent %d", uid));
369 if ((uid == -1) /*&& (constituents[ic].kt2() < 1e-25)*/) { //ghost particle
371 Double_t gphi = constituents[ic].phi();
373 gphi += TMath::TwoPi();
374 gphi *= TMath::RadToDeg();
375 Double_t geta = constituents[ic].eta();
376 if ((gphi > geom->GetArm1PhiMin()) && (gphi < geom->GetArm1PhiMax()) &&
377 (geta > geom->GetArm1EtaMin()) && (geta < geom->GetArm1EtaMax()))
379 } else if ((uid > 0) && fTracks) { // track constituent
380 Int_t tid = uid - 100;
381 AliVParticle *t = static_cast<AliVParticle*>(fTracks->At(tid));
383 AliError(Form("Could not find track %d",tid));
386 if (jetCount < fMarkConst) {
387 AliDebug(2,Form("Marking track %d with bit map %d", tid, fJetType));
390 Double_t cEta = t->Eta();
391 Double_t cPhi = t->Phi();
392 Double_t cPt = t->Pt();
393 Double_t cP = t->P();
394 if (t->Charge() == 0) {
404 if (fIsMcPart || TMath::Abs(t->GetLabel()) > fMinMCLabel) // check if MC particle
408 cPhi += TMath::TwoPi();
409 cPhi *= TMath::RadToDeg();
410 if ((cPhi > geom->GetArm1PhiMin()) && (cPhi < geom->GetArm1PhiMax()) &&
411 (cEta > geom->GetArm1EtaMin()) && (cEta < geom->GetArm1EtaMax())) {
416 jet->AddTrackAt(tid, nt);
418 } else if (fClus) { // cluster constituent
419 Int_t cid = -uid - 100;
421 Double_t cEta=0,cPhi=0,cPt=0,cP=0;
423 AliEmcalParticle *ep = static_cast<AliEmcalParticle*>(fClus->At(cid));
426 c = ep->GetCluster();
429 if (jetCount < fMarkConst)
430 ep->SetBit(fJetType);
436 c = static_cast<AliVCluster*>(fClus->At(cid));
439 if (jetCount < fMarkConst)
442 c->GetMomentum(nP, vertex);
453 if (c->GetLabel() > fMinMCLabel) // MC particle
457 cPhi += TMath::TwoPi();
458 cPhi *= TMath::RadToDeg();
459 if ((cPhi > geom->GetArm1PhiMin()) && (cPhi < geom->GetArm1PhiMax()) &&
460 (cEta > geom->GetArm1EtaMin()) && (cEta < geom->GetArm1EtaMax())) {
465 jet->AddClusterAt(cid, nc);
469 AliError(Form("%s: No logical way to end up here.", GetName()));
472 } /* end of constituent loop */
474 jet->SetNumberOfTracks(nt);
475 jet->SetNumberOfClusters(nc);
476 jet->SortConstituents();
477 jet->SetMaxNeutralPt(maxNe);
478 jet->SetMaxChargedPt(maxCh);
479 jet->SetNEF(neutralE / jet->E());
480 fastjet::PseudoJet area(fjw.GetJetAreaVector(ij));
481 jet->SetArea(area.perp());
482 jet->SetAreaEta(area.eta());
483 jet->SetAreaPhi(area.phi());
484 jet->SetNumberOfCharged(ncharged);
485 jet->SetNumberOfNeutrals(nneutral);
488 jet->SetPtEmc(emcpt);
491 jet->SetAreaEmc(fjw.GetJetArea(ij) * gemc / gall);
494 if ((jet->Phi() > geom->GetArm1PhiMin() * TMath::DegToRad()) &&
495 (jet->Phi() < geom->GetArm1PhiMax() * TMath::DegToRad()) &&
496 (jet->Eta() > geom->GetArm1EtaMin()) &&
497 (jet->Eta() < geom->GetArm1EtaMax()))
498 jet->SetAxisInEmcal(kTRUE);
500 AliDebug(2,Form("Added jet n. %d, pt = %f, area = %f, constituents = %d", jetCount, jet->Pt(), jet->Area(), (Int_t)constituents.size()));
506 //________________________________________________________________________
507 Bool_t AliEmcalJetTask::GetSortedArray(Int_t indexes[], std::vector<fastjet::PseudoJet> array) const
509 // Get the leading jets.
511 static Float_t pt[9999] = {0};
513 const Int_t n = (Int_t)array.size();
518 for (Int_t i = 0; i < n; i++)
519 pt[i] = array[i].perp();
521 TMath::Sort(n, pt, indexes);
526 //________________________________________________________________________
527 Bool_t AliEmcalJetTask::DoInit()
529 // Init. Return true if successful.
531 // get input collections
532 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
535 fEvent = InputEvent();
537 AliError(Form("%s: Could not retrieve event! Returning", GetName()));
541 // add jets to event if not yet there
543 if (!(fEvent->FindListObject(fJetsName)))
544 fEvent->AddObject(fJets);
546 AliError(Form("%s: Object with name %s already in event! Returning", GetName(), fJetsName.Data()));
550 if (fTracksName == "Tracks")
551 am->LoadBranch("Tracks");
552 if (!fTracks && !fTracksName.IsNull()) {
553 fTracks = dynamic_cast<TClonesArray*>(fEvent->FindListObject(fTracksName));
555 AliError(Form("%s: Pointer to tracks %s == 0", GetName(), fTracksName.Data()));
560 TClass cls(fTracks->GetClass()->GetName());
561 if (cls.InheritsFrom("AliMCParticle") || cls.InheritsFrom("AliAODMCParticle"))
565 if (fCaloName == "CaloClusters")
566 am->LoadBranch("CaloClusters");
567 if (!fClus && !fCaloName.IsNull()) {
568 fClus = dynamic_cast<TClonesArray*>(fEvent->FindListObject(fCaloName));
570 AliError(Form("%s: Pointer to clus %s == 0", GetName(), fCaloName.Data()));
575 TClass cls(fClus->GetClass()->GetName());
576 if (cls.InheritsFrom("AliEmcalParticle"))