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.
134 //________________________________________________________________________
135 void AliEmcalJetTask::Terminate(Option_t *)
137 // Called once at the end of the analysis.
140 //________________________________________________________________________
141 void AliEmcalJetTask::FindJets()
144 if (!fTracks && !fClus){
145 cout << "WARNING NO TRACKS OR CLUSTERS:" <<endl;
151 fastjet::JetAlgorithm jalgo(fastjet::kt_algorithm);
152 if ((fJetType & kAKT) != 0) {
154 jalgo = fastjet::antikt_algorithm;
155 AliDebug(1,"Using AKT algorithm");
158 AliDebug(1,"Using KT algorithm");
161 if ((fJetType & kR020Jet) != 0)
163 else if ((fJetType & kR030Jet) != 0)
165 else if ((fJetType & kR040Jet) != 0)
169 AliFJWrapper fjw(name, name);
170 fjw.SetAreaType(fastjet::active_area_explicit_ghosts);
171 fjw.SetGhostArea(fGhostArea);
173 fjw.SetAlgorithm(jalgo);
174 fjw.SetMaxRap(fEtaMax);
177 // get primary vertex
178 Double_t vertex[3] = {0, 0, 0};
179 fEvent->GetPrimaryVertex()->GetXYZ(vertex);
181 AliDebug(2,Form("Jet type = %d", fJetType));
183 if ((fIsMcPart || ((fJetType & kFullJet) != 0) || ((fJetType & kChargedJet) != 0)) && fTracks) {
184 const Int_t Ntracks = fTracks->GetEntries();
185 for (Int_t iTracks = 0; iTracks < Ntracks; ++iTracks) {
186 AliVParticle *t = static_cast<AliVParticle*>(fTracks->At(iTracks));
190 if (((fJetType & kChargedJet) != 0) && (t->Charge() == 0)) {
191 AliDebug(2,Form("Skipping track %d because it is neutral.", iTracks));
194 if (((fJetType & kNeutralJet) != 0) && (t->Charge() != 0)) {
195 AliDebug(2,Form("Skipping track %d because it is charged.", iTracks));
199 if (fIsMcPart || TMath::Abs(t->GetLabel()) > fMinMCLabel) {
200 if (t->TestBits(fMCConstSel) != (Int_t)fMCConstSel) {
201 AliDebug(2,Form("Skipping track %d because it does not match the bit mask (%d, %d)", iTracks, fMCConstSel, t->TestBits(TObject::kBitMask)));
205 AliDebug(2,Form("Track %d matches the bit mask (%d, %d)", iTracks, fMCConstSel, t->TestBits(TObject::kBitMask)));
209 if (t->TestBits(fConstSel) != (Int_t)fConstSel) {
210 AliDebug(2,Form("Skipping track %d because it does not match the bit mask (%d, %d)", iTracks, fConstSel, t->TestBits(TObject::kBitMask)));
214 AliDebug(2,Form("Track %d matches the bit mask (%d, %d)", iTracks, fConstSel, t->TestBits(TObject::kBitMask)));
217 if (t->Pt() < fMinJetTrackPt)
219 Double_t eta = t->Eta();
220 Double_t phi = t->Phi();
221 if ((eta<fEtaMin) || (eta>fEtaMax) ||
222 (phi<fPhiMin) || (phi>fPhiMax))
225 // offset of 100 for consistency with cluster ids
226 AliDebug(2,Form("Track %d accepted (label = %d, pt = %f)", iTracks, t->GetLabel(), t->Pt()));
227 fjw.AddInputVector(t->Px(), t->Py(), t->Pz(), t->P(), iTracks + 100);
231 if ((((fJetType & kFullJet) != 0) || ((fJetType & kNeutralJet) != 0)) && fClus) {
232 const Int_t Nclus = fClus->GetEntries();
233 for (Int_t iClus = 0; iClus < Nclus; ++iClus) {
235 Double_t cEta=0,cPhi=0,cPt=0;
236 Double_t cPx=0,cPy=0,cPz=0;
238 AliEmcalParticle *ep = static_cast<AliEmcalParticle*>(fClus->At(iClus));
242 c = ep->GetCluster();
246 if (c->GetLabel() > fMinMCLabel) {
247 if (ep->TestBits(fMCConstSel) != (Int_t)fMCConstSel) {
248 AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fMCConstSel, ep->TestBits(TObject::kBitMask)));
252 AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fMCConstSel, ep->TestBits(TObject::kBitMask)));
256 if (ep->TestBits(fConstSel) != (Int_t)fConstSel) {
257 AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fConstSel, ep->TestBits(TObject::kBitMask)));
261 AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fConstSel, ep->TestBits(TObject::kBitMask)));
272 c = static_cast<AliVCluster*>(fClus->At(iClus));
276 if (c->GetLabel() > fMinMCLabel) {
277 if (c->TestBits(fMCConstSel) != (Int_t)fMCConstSel) {
278 AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fMCConstSel, c->TestBits(TObject::kBitMask)));
282 AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fMCConstSel, c->TestBits(TObject::kBitMask)));
286 if (c->TestBits(fConstSel) != (Int_t)fConstSel) {
287 AliDebug(2,Form("Skipping cluster %d because it does not match the bit mask (%d, %d)", iClus, fConstSel, c->TestBits(TObject::kBitMask)));
291 AliDebug(2,Form("Cluster %d matches the bit mask (%d, %d)", iClus, fConstSel, c->TestBits(TObject::kBitMask)));
296 c->GetMomentum(nP, vertex);
306 if (cPt < fMinJetClusPt)
308 if ((cEta<fEtaMin) || (cEta>fEtaMax) ||
309 (cPhi<fPhiMin) || (cPhi>fPhiMax))
311 // offset of 100 to skip ghost particles uid = -1
312 AliDebug(2,Form("Cluster %d accepted (label = %d)", iClus, c->GetLabel()));
313 fjw.AddInputVector(cPx, cPy, cPz, TMath::Sqrt(cPx*cPx+cPy*cPy+cPz*cPz), -iClus - 100);
321 AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
323 AliFatal(Form("%s: Can not create geometry", GetName()));
327 // loop over fastjet jets
328 std::vector<fastjet::PseudoJet> jets_incl = fjw.GetInclusiveJets();
329 // sort jets according to jet pt
330 static Int_t indexes[9999] = {-1};
331 GetSortedArray(indexes, jets_incl);
333 AliDebug(1,Form("%d jets found", (Int_t)jets_incl.size()));
334 for (UInt_t ijet=0, jetCount=0; ijet<jets_incl.size(); ++ijet) {
335 Int_t ij = indexes[ijet];
336 AliDebug(3,Form("Jet pt = %f, area = %f", jets_incl[ij].perp(), fjw.GetJetArea(ij)));
338 if (jets_incl[ij].perp()<fMinJetPt)
340 if (fjw.GetJetArea(ij)<fMinJetArea)
342 if ((jets_incl[ij].eta()<fJetEtaMin) || (jets_incl[ij].eta()>fJetEtaMax) ||
343 (jets_incl[ij].phi()<fJetPhiMin) || (jets_incl[ij].phi()>fJetPhiMax))
346 AliEmcalJet *jet = new ((*fJets)[jetCount])
347 AliEmcalJet(jets_incl[ij].perp(), jets_incl[ij].eta(), jets_incl[ij].phi(), jets_incl[ij].m());
349 // loop over constituents
350 std::vector<fastjet::PseudoJet> constituents(fjw.GetJetConstituents(ij));
351 jet->SetNumberOfTracks(constituents.size());
352 jet->SetNumberOfClusters(constituents.size());
356 Double_t neutralE = 0;
367 for(UInt_t ic = 0; ic < constituents.size(); ++ic) {
368 Int_t uid = constituents[ic].user_index();
369 AliDebug(3,Form("Processing constituent %d", uid));
370 if ((uid == -1) /*&& (constituents[ic].kt2() < 1e-25)*/) { //ghost particle
372 Double_t gphi = constituents[ic].phi();
374 gphi += TMath::TwoPi();
375 gphi *= TMath::RadToDeg();
376 Double_t geta = constituents[ic].eta();
377 if ((gphi > geom->GetArm1PhiMin()) && (gphi < geom->GetArm1PhiMax()) &&
378 (geta > geom->GetArm1EtaMin()) && (geta < geom->GetArm1EtaMax()))
380 } else if ((uid > 0) && fTracks) { // track constituent
381 Int_t tid = uid - 100;
382 AliVParticle *t = static_cast<AliVParticle*>(fTracks->At(tid));
384 AliError(Form("Could not find track %d",tid));
387 if (jetCount < fMarkConst) {
388 AliDebug(2,Form("Marking track %d with bit map %d", tid, fJetType));
391 Double_t cEta = t->Eta();
392 Double_t cPhi = t->Phi();
393 Double_t cPt = t->Pt();
394 Double_t cP = t->P();
395 if (t->Charge() == 0) {
405 if (fIsMcPart || TMath::Abs(t->GetLabel()) > fMinMCLabel) // check if MC particle
409 cPhi += TMath::TwoPi();
410 cPhi *= TMath::RadToDeg();
411 if ((cPhi > geom->GetArm1PhiMin()) && (cPhi < geom->GetArm1PhiMax()) &&
412 (cEta > geom->GetArm1EtaMin()) && (cEta < geom->GetArm1EtaMax())) {
417 jet->AddTrackAt(tid, nt);
419 } else if (fClus) { // cluster constituent
420 Int_t cid = -uid - 100;
422 Double_t cEta=0,cPhi=0,cPt=0,cP=0;
424 AliEmcalParticle *ep = static_cast<AliEmcalParticle*>(fClus->At(cid));
427 c = ep->GetCluster();
430 if (jetCount < fMarkConst)
431 ep->SetBit(fJetType);
437 c = static_cast<AliVCluster*>(fClus->At(cid));
440 if (jetCount < fMarkConst)
443 c->GetMomentum(nP, vertex);
454 if (c->GetLabel() > fMinMCLabel) // MC particle
458 cPhi += TMath::TwoPi();
459 cPhi *= TMath::RadToDeg();
460 if ((cPhi > geom->GetArm1PhiMin()) && (cPhi < geom->GetArm1PhiMax()) &&
461 (cEta > geom->GetArm1EtaMin()) && (cEta < geom->GetArm1EtaMax())) {
466 jet->AddClusterAt(cid, nc);
470 AliError(Form("%s: No logical way to end up here.", GetName()));
473 } /* end of constituent loop */
475 jet->SetNumberOfTracks(nt);
476 jet->SetNumberOfClusters(nc);
477 jet->SortConstituents();
478 jet->SetMaxNeutralPt(maxNe);
479 jet->SetMaxChargedPt(maxCh);
480 jet->SetNEF(neutralE / jet->E());
481 fastjet::PseudoJet area(fjw.GetJetAreaVector(ij));
482 jet->SetArea(area.perp());
483 jet->SetAreaEta(area.eta());
484 jet->SetAreaPhi(area.phi());
485 jet->SetNumberOfCharged(ncharged);
486 jet->SetNumberOfNeutrals(nneutral);
489 jet->SetPtEmc(emcpt);
492 jet->SetAreaEmc(fjw.GetJetArea(ij) * gemc / gall);
495 if ((jet->Phi() > geom->GetArm1PhiMin() * TMath::DegToRad()) &&
496 (jet->Phi() < geom->GetArm1PhiMax() * TMath::DegToRad()) &&
497 (jet->Eta() > geom->GetArm1EtaMin()) &&
498 (jet->Eta() < geom->GetArm1EtaMax()))
499 jet->SetAxisInEmcal(kTRUE);
501 AliDebug(2,Form("Added jet n. %d, pt = %f, area = %f, constituents = %d", jetCount, jet->Pt(), jet->Area(), (Int_t)constituents.size()));
507 //________________________________________________________________________
508 Bool_t AliEmcalJetTask::GetSortedArray(Int_t indexes[], std::vector<fastjet::PseudoJet> array) const
510 // Get the leading jets.
512 static Float_t pt[9999] = {0};
514 const Int_t n = (Int_t)array.size();
519 for (Int_t i = 0; i < n; i++)
520 pt[i] = array[i].perp();
522 TMath::Sort(n, pt, indexes);
527 //________________________________________________________________________
528 Bool_t AliEmcalJetTask::DoInit()
530 // Init. Return true if successful.
532 // get input collections
533 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
536 fEvent = InputEvent();
538 AliError(Form("%s: Could not retrieve event! Returning", GetName()));
542 // add jets to event if not yet there
544 if (!(fEvent->FindListObject(fJetsName)))
545 fEvent->AddObject(fJets);
547 AliError(Form("%s: Object with name %s already in event! Returning", GetName(), fJetsName.Data()));
551 if (fTracksName == "Tracks")
552 am->LoadBranch("Tracks");
553 if (!fTracks && !fTracksName.IsNull()) {
554 fTracks = dynamic_cast<TClonesArray*>(fEvent->FindListObject(fTracksName));
556 AliError(Form("%s: Pointer to tracks %s == 0", GetName(), fTracksName.Data()));
561 TClass cls(fTracks->GetClass()->GetName());
562 if (cls.InheritsFrom("AliMCParticle") || cls.InheritsFrom("AliAODMCParticle"))
566 if (fCaloName == "CaloClusters")
567 am->LoadBranch("CaloClusters");
568 if (!fClus && !fCaloName.IsNull()) {
569 fClus = dynamic_cast<TClonesArray*>(fEvent->FindListObject(fCaloName));
571 AliError(Form("%s: Pointer to clus %s == 0", GetName(), fCaloName.Data()));
576 TClass cls(fClus->GetClass()->GetName());
577 if (cls.InheritsFrom("AliEmcalParticle"))