2 // $Id: AliHLTJETReaderHeader.cxx $
3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
8 * for The ALICE HLT Project. *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 /** @file AliHLTJETReader.cxx
20 @author Jochen Thaeder
22 @brief Reader for jet finder
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
31 #include "TLorentzVector.h"
32 #include "TParticle.h"
33 #include "TParticlePDG.h"
34 #include "TDatabasePDG.h"
36 #include "AliHLTJETReader.h"
38 #include "AliHLTJETConeJetCandidate.h"
42 /** ROOT macro for the implementation of ROOT specific class methods */
43 ClassImp(AliHLTJETReader)
46 * ---------------------------------------------------------------------------------
47 * Constructor / Destructor
48 * ---------------------------------------------------------------------------------
51 // #################################################################################
52 AliHLTJETReader::AliHLTJETReader()
60 fMomentumVector(NULL),
67 // see header file for class documentation
69 // refer to README to build package
71 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
75 // #################################################################################
76 AliHLTJETReader::~AliHLTJETReader() {
77 // see header file for class documentation
80 if ( fMomentumVector )
81 delete fMomentumVector;
82 fMomentumVector = NULL;
89 if ( fJetCandidates ) {
90 fJetCandidates->Clear();
91 delete fJetCandidates;
93 fJetCandidates = NULL;
97 // #################################################################################
98 Int_t AliHLTJETReader::Initialize() {
99 // see header file for class documentation
102 AliHLTJETReaderHeader* readerHeader = NULL;
104 HLTInfo(" -= AliHLTJETReader =- ");
106 // -- Initialize reader header
107 // -----------------------------
108 if ( fReaderHeader ) {
109 readerHeader = GetReaderHeader();
111 iResult = readerHeader->Initialize();
113 HLTError("Error initializing HLT jet reader header");
116 HLTError("Reader Header not present");
117 iResult = -EINPROGRESS;
120 // -- Initialize Algorithms
121 // --------------------------
123 if ( readerHeader->GetJetAlgorithm() >= AliHLTJETBase::kFFSCSquareCell )
124 iResult = InitializeFFSC();
127 iResult = InitializeFastjet();
129 HLTError("Error FastJet not present.");
130 iResult = -EINPROGRESS;
135 // -- Get ptr to cuts from reader
136 // --------------------------------
138 fTrackCuts = readerHeader->GetTrackCuts();
139 if ( ! fTrackCuts ) {
140 HLTError("Error getting ptr to track cuts.");
141 iResult = -EINPROGRESS;
148 HLTError("Error initializing HLT jet reader");
153 //#################################################################################
154 void AliHLTJETReader::ResetEvent() {
155 // see header file for class documentation
157 // -- Reset FFSC algorithms
158 // --------------------------
159 if ( GetReaderHeader()->GetJetAlgorithm() >= AliHLTJETBase::kFFSCSquareCell ) {
163 // -- clear jet candidates
164 fJetCandidates->Clear();
169 // -- Reset for FastJet algorithms
170 // ---------------------------------
173 // -- Clear input vector
174 if ( fMomentumVector )
175 fMomentumVector->clear();
183 * ---------------------------------------------------------------------------------
185 * ---------------------------------------------------------------------------------
188 // #################################################################################
189 void AliHLTJETReader::SetInputEvent(const TObject* esd, const TObject* aod, const TObject* mc) {
190 // see header file for class documentation
192 // Needs "useMC" flag for running in analysis task only
194 AliHLTJETReaderHeader* readerHeader = GetReaderHeader();
197 if ( esd && !readerHeader->GetUseMC() )
198 fESD = dynamic_cast<AliESDEvent*> (const_cast<TObject*>(esd));
201 else if ( aod && !readerHeader->GetUseMC() )
202 fAOD = dynamic_cast<AliAODEvent*> (const_cast<TObject*>(aod));
205 else if ( mc && readerHeader->GetUseMC() ) {
207 // -- if off-line MC event,
208 if ( !strcmp (mc->ClassName(),"AliMCEvent") )
209 fMC = dynamic_cast<AliMCEvent*> (const_cast<TObject*>(mc));
210 // -- if on-line MC event
212 fHLTMC = dynamic_cast<AliHLTMCEvent*> (const_cast<TObject*>(mc));
219 * ---------------------------------------------------------------------------------
220 * Fastjet Reader functionality
221 * ---------------------------------------------------------------------------------
224 // #################################################################################
225 Bool_t AliHLTJETReader::FillVector() {
226 // see header file for class documentation
228 Bool_t bResult = kFALSE;
231 bResult = FillVectorESD();
233 bResult = FillVectorMC();
235 bResult = FillVectorHLTMC();
237 bResult = FillVectorAOD();
242 // #################################################################################
243 Bool_t AliHLTJETReader::FillVectorMC() {
244 // see header file for class documentation
246 Bool_t bResult = kTRUE;
249 HLTError( "No MC Event present!" );
258 AliStack* stack = fMC->Stack();
260 for (Int_t iterStack = 0; iterStack < stack->GetNtrack() && bResult; iterStack++) {
262 TParticle *particle = stack->Particle(iterStack);
264 HLTError( "Error reading particle %i out of %i", iterStack, stack->GetNtrack() );
269 // ------------------------------
270 // -- Basic cuts on MC particle --> To be done better XXX
271 // ------------------------------
274 if ( !(stack->IsPhysicalPrimary(iterStack)) )
278 if ( particle->GetNDaughters() != 0 )
282 TParticlePDG * particlePDG = particle->GetPDG();
283 if ( ! particlePDG ) {
284 particlePDG = TDatabasePDG::Instance()->GetParticle( particle->GetPdgCode() );
286 if ( ! particlePDG ) {
287 HLTError("Particle %i not in PDG database", particle->GetPdgCode() );
293 // ------------------------
294 // -- Standard track cuts
295 // ------------------------
297 // -- Apply track cuts
298 if ( ! fTrackCuts->IsSelected(particle) )
301 // -- Create PseudoJet object
302 fastjet::PseudoJet part( particle->Px(), particle->Py(),
303 particle->Pz(), particle->Energy() );
305 // -- label the particle into Fastjet algortihm
306 part.set_user_index( iterStack );
309 // -- Add to input_particles vector
310 fMomentumVector->push_back(part);
314 } // for (Int_t iterStack = 0; iterStack < stack->GetNtrack() && !bResult; iterStack++) {
316 HLTDebug(" Number of selected tracks %d", nTracks);
321 // #################################################################################
322 Bool_t AliHLTJETReader::FillVectorHLTMC() {
323 // see header file for class documentation
326 HLTError( "No HLT MC Event present!" );
335 TParticle* particle = NULL;
337 // -- Loop over particles
338 // ------------------------
339 while ( (particle = fHLTMC->NextParticle() ) ) {
341 // -- Apply track cuts
342 if ( ! fTrackCuts->IsSelected(particle) )
345 // -- Create PseudoJet object
346 fastjet::PseudoJet part( particle->Px(), particle->Py(),
347 particle->Pz(), particle->Energy() );
349 // -- label the particle into Fastjet algortihm
350 part.set_user_index( fHLTMC->GetIndex() );
353 // -- Add to input_particles vector
354 fMomentumVector->push_back(part);
359 } // while ( (particle = fHLTMC->NextParticle() ) ) {
361 HLTInfo(" Number of selected tracks %d", nTracks);
366 // #################################################################################
367 Bool_t AliHLTJETReader::FillVectorESD() {
368 // see header file for class documentation
370 Bool_t bResult = kTRUE;
373 HLTError( "No ESD Event present!" );
382 // -- Loop over particles
383 // ------------------------
384 for ( Int_t iter = 0; iter < fESD->GetNumberOfTracks() && bResult; iter++ ) {
386 AliESDtrack* esdTrack = fESD->GetTrack(iter);
388 HLTError("Could not read ESD track %d from %d", iter, fESD->GetNumberOfTracks() );
393 // -- Apply track cuts
394 if ( ! fTrackCuts->IsSelected(esdTrack) )
397 // -- Create PseudoJet object
398 fastjet::PseudoJet part( esdTrack->Px(), esdTrack->Py(),
399 esdTrack->Pz(), esdTrack->E() );
401 // -- label the particle into Fastjet algortihm
402 part.set_user_index( iter );
405 // -- Add to input_particles vector
406 fMomentumVector->push_back(part);
411 } // for ( Int_t iter = 0; iter < fESD->GetNumberOfTracks() && !iResult; iter++ ) {
413 HLTInfo(" Number of selected tracks %d", nTracks);
418 // #################################################################################
419 Bool_t AliHLTJETReader::FillVectorAOD() {
420 // see header file for class documentation
427 * ---------------------------------------------------------------------------------
429 * ---------------------------------------------------------------------------------
432 // #################################################################################
433 Bool_t AliHLTJETReader::FillGrid() {
434 // see header file for class documentation
436 Bool_t bResult = kFALSE;
439 bResult = FillGridESD();
441 bResult = FillGridMC();
443 bResult = FillGridHLTMC();
445 bResult = FillGridAOD();
450 // #################################################################################
451 Bool_t AliHLTJETReader::FillGridMC() {
452 // see header file for class documentation
454 Bool_t bResult = kTRUE;
457 HLTError( "No MC Event present!" );
464 AliHLTJETReaderHeader* readerHeader = GetReaderHeader();
468 AliStack* stack = fMC->Stack();
470 for (Int_t iterStack = 0; iterStack < stack->GetNtrack() && bResult; iterStack++) {
472 TParticle *particle = stack->Particle(iterStack);
474 HLTError( "Error reading particle %i out of %i", iterStack, stack->GetNtrack() );
479 // ------------------------------
480 // -- Basic cuts on MC particle --> To be done better XXX
481 // ------------------------------
484 if ( !(stack->IsPhysicalPrimary(iterStack)) )
488 if ( particle->GetNDaughters() != 0 )
492 TParticlePDG * particlePDG = particle->GetPDG();
493 if ( ! particlePDG ) {
494 particlePDG = TDatabasePDG::Instance()->GetParticle( particle->GetPdgCode() );
496 if ( ! particlePDG ) {
497 HLTError("Particle %i not in PDG database", particle->GetPdgCode() );
503 // ------------------------
504 // -- Standard track cuts
505 // ------------------------
507 // -- Apply track cuts
508 if ( ! fTrackCuts->IsSelected(particle) )
511 const Float_t aEtaPhi[] = { static_cast<Float_t>(particle->Eta()), static_cast<Float_t>(particle->Phi()), static_cast<Float_t>(particle->Pt()) };
512 Int_t aGridIdx[] = { -1, -1, -1, -1, -1 };
514 fGrid->FillTrack(particle, aEtaPhi, aGridIdx);
518 // -- Apply seed cuts
519 if ( ! fSeedCuts->IsSelected(particle) )
523 AddSeed(aEtaPhi, const_cast<const Int_t*> (aGridIdx), readerHeader->GetConeRadius());
525 } // for (Int_t iterStack = 0; iterStack < stack->GetNtrack() && !bResult; iterStack++) {
527 HLTInfo(" Number of selected tracks %d", nTracks);
528 HLTInfo(" Number of seeds %d", fNJetCandidates);
533 // #################################################################################
534 Bool_t AliHLTJETReader::FillGridHLTMC() {
535 // see header file for class documentation
538 HLTError( "No HLT MC Event present!" );
545 AliHLTJETReaderHeader* readerHeader = GetReaderHeader();
548 TParticle* particle = NULL;
550 // -- Loop over particles
551 // ------------------------
552 while ( ( particle = fHLTMC->NextParticle() ) ) {
554 // HLTError("=== nTracks %d ===",nTracks);
556 // -- Apply track cuts
557 if ( ! fTrackCuts->IsSelected(particle) )
560 const Float_t aEtaPhi[] = { static_cast<Float_t>(particle->Eta()), static_cast<Float_t>(particle->Phi()), static_cast<Float_t>(particle->Pt()) };
561 Int_t aGridIdx[] = { -1, -1, -1, -1, -1 };
564 fGrid->FillTrack(particle, aEtaPhi, aGridIdx);
568 // -- Apply seed cuts
569 if ( ! fSeedCuts->IsSelected(particle) )
573 AddSeed(aEtaPhi, const_cast<const Int_t*> (aGridIdx),
574 readerHeader->GetConeRadius());
576 } // while ( (particle = fHLTMC->NextParticle() ) ) {
578 HLTInfo(" Number of selected tracks %d", nTracks);
579 HLTInfo(" Number of seeds %d", fNJetCandidates);
584 // #################################################################################
585 Bool_t AliHLTJETReader::FillGridESD() {
586 // see header file for class documentation
588 Bool_t bResult = kTRUE;
591 HLTError( "No ESD Event present!" );
598 AliHLTJETReaderHeader* readerHeader = GetReaderHeader();
602 // -- Loop over particles
603 // ------------------------
604 // for ( Int_t iter = 0; iter < fESD->GetNumberOfTracks() && !bResult; iter++ ) { JMT Coverity
605 for ( Int_t iter = 0; iter < fESD->GetNumberOfTracks() && bResult; iter++ ) {
607 AliESDtrack* esdTrack = fESD->GetTrack(iter);
609 HLTError("Could not read ESD track %d from %d", iter, fESD->GetNumberOfTracks() );
614 // -- Apply track cuts
615 if ( ! fTrackCuts->IsSelected(esdTrack) )
618 const Float_t aEtaPhi[] = { static_cast<Float_t>(esdTrack->Eta()), static_cast<Float_t>(esdTrack->Phi()), static_cast<Float_t>(esdTrack->Pt()) };
619 Int_t aGridIdx[] = { -1, -1, -1, -1, -1 };
622 fGrid->FillTrack(esdTrack, aEtaPhi, aGridIdx);
626 // -- Apply seed cuts
627 if ( ! fSeedCuts->IsSelected(esdTrack) )
631 AddSeed(aEtaPhi, const_cast<const Int_t*> (aGridIdx),
632 readerHeader->GetConeRadius());
634 } // for ( Int_t iter = 0; iter < fESD->GetNumberOfTracks() && !iResult; iter++ ) {
636 HLTInfo(" Number of selected tracks %d", nTracks);
637 HLTInfo(" Number of seeds %d", fNJetCandidates);
642 // #################################################################################
643 Bool_t AliHLTJETReader::FillGridAOD() {
644 // see header file for class documentation
650 * ---------------------------------------------------------------------------------
652 * ---------------------------------------------------------------------------------
655 //#################################################################################
656 void AliHLTJETReader::AddSeed( const Float_t* aEtaPhi, const Int_t* aGridIdx,
657 const Float_t coneRadius ) {
658 // see header file for class documentation
660 Bool_t useWholeCell = kTRUE;
662 if ( GetReaderHeader()->GetJetAlgorithm() == AliHLTJETBase::kFFSCRadiusCell )
663 useWholeCell = kFALSE ;
665 // -- Add track / particle
666 new( (*fJetCandidates) [fNJetCandidates] ) AliHLTJETConeJetCandidate( aEtaPhi,
672 HLTDebug("Added Seed Pt=%f, Eta=%f, Phi=%f", aEtaPhi[kIdxPt],
673 aEtaPhi[kIdxEta], aEtaPhi[kIdxPhi] );
679 * ---------------------------------------------------------------------------------
680 * Initialize - private
681 * ---------------------------------------------------------------------------------
684 // #################################################################################
685 Int_t AliHLTJETReader::InitializeFFSC() {
686 // see header file for class documentation
689 AliHLTJETReaderHeader* readerHeader = GetReaderHeader();
691 // -- Initialize grid
692 // --------------------
696 if ( ! (fGrid = new AliHLTJETConeGrid()) ) {
697 HLTError("Error instanciating grid.");
698 iResult = -EINPROGRESS;
702 fGrid->SetEtaRange( readerHeader->GetFiducialEtaMin(),
703 readerHeader->GetFiducialEtaMax(),
704 readerHeader->GetGridEtaRange() );
706 fGrid->SetPhiRange( readerHeader->GetFiducialPhiMin(),
707 readerHeader->GetFiducialPhiMax(),
708 readerHeader->GetGridPhiRange() );
710 fGrid->SetBinning( readerHeader->GetGridEtaBinning(),
711 readerHeader->GetGridEtaBinning() );
713 fGrid->SetConeRadius( readerHeader->GetConeRadius() );
715 iResult = fGrid->Initialize();
718 // -- Initialize jet candidates
719 // ------------------------------
721 fJetCandidates = new TClonesArray("AliHLTJETConeJetCandidate", 30);
722 if ( ! fJetCandidates) {
723 HLTError("Error instanciating jet candidates.");
724 iResult = -EINPROGRESS;
728 // -- Get ptr to cuts from reader
729 // --------------------------------
733 fSeedCuts = readerHeader->GetSeedCuts();
735 HLTError("Error getting ptr to seed cuts.");
736 iResult = -EINPROGRESS;
744 // #################################################################################
745 Int_t AliHLTJETReader::InitializeFastjet() {
746 // see header file for class documentation
750 // -- Initialize Vector
751 // ----------------------
752 if ( fMomentumVector )
753 delete fMomentumVector;
755 if ( ! (fMomentumVector = new vector<fastjet::PseudoJet>) ) {
756 HLTError("Error instanciating momentum vector.");
757 iResult = -EINPROGRESS;