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
35 #include "TLorentzVector.h"
36 #include "TParticle.h"
37 #include "TParticlePDG.h"
38 #include "TDatabasePDG.h"
40 #include "AliHLTJETReader.h"
42 #include "AliHLTJETConeJetCandidate.h"
44 /** ROOT macro for the implementation of ROOT specific class methods */
45 ClassImp(AliHLTJETReader)
48 * ---------------------------------------------------------------------------------
49 * Constructor / Destructor
50 * ---------------------------------------------------------------------------------
53 // #################################################################################
54 AliHLTJETReader::AliHLTJETReader()
62 fMomentumVector(NULL),
69 // see header file for class documentation
71 // refer to README to build package
73 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
77 // #################################################################################
78 AliHLTJETReader::~AliHLTJETReader() {
79 // see header file for class documentation
82 if ( fMomentumVector )
83 delete fMomentumVector;
84 fMomentumVector = NULL;
91 if ( fJetCandidates ) {
92 fJetCandidates->Clear();
93 delete fJetCandidates;
95 fJetCandidates = NULL;
99 // #################################################################################
100 Int_t AliHLTJETReader::Initialize() {
101 // see header file for class documentation
104 AliHLTJETReaderHeader* readerHeader = NULL;
106 HLTInfo(" -= AliHLTJETReader =- " );
108 // -- Initialize reader header
109 // -----------------------------
110 if ( fReaderHeader ) {
111 readerHeader = GetReaderHeader();
113 iResult = readerHeader->Initialize();
115 HLTError("Error initializing HLT jet reader header");
118 HLTError("Reader Header not present");
119 iResult = -EINPROGRESS;
122 // -- Initialize Algorithms
123 // --------------------------
124 if ( readerHeader->GetJetAlgorithm() >= AliHLTJETBase::kFFSCSquareCell )
125 iResult = InitializeFFSC();
128 iResult = InitializeFastjet();
130 HLTError("Error FastJet not present.");
131 iResult = -EINPROGRESS;
135 // -- Get ptr to cuts from reader
136 // --------------------------------
140 fSeedCuts = readerHeader->GetSeedCuts();
142 HLTError("Error getting ptr to seed cuts.");
143 iResult = -EINPROGRESS;
149 fTrackCuts = readerHeader->GetTrackCuts();
150 if ( ! fTrackCuts ) {
151 HLTError("Error getting ptr to track cuts.");
152 iResult = -EINPROGRESS;
159 HLTError("Error initializing HLT jet reader");
164 //#################################################################################
165 void AliHLTJETReader::ResetEvent() {
166 // see header file for class documentation
168 // -- Reset FFSC algorithms
169 // --------------------------
170 if ( GetReaderHeader()->GetJetAlgorithm() >= AliHLTJETBase::kFFSCSquareCell ) {
174 // -- clear jet candidates
175 fJetCandidates->Clear();
180 // -- Reset for FastJet algorithms
181 // ---------------------------------
184 // -- Clear input vector
185 if ( fMomentumVector )
186 fMomentumVector->clear();
194 * ---------------------------------------------------------------------------------
196 * ---------------------------------------------------------------------------------
199 // #################################################################################
200 void AliHLTJETReader::SetInputEvent(const TObject* esd, const TObject* aod, const TObject* mc) {
201 // see header file for class documentation
203 // Needs "useMC" flag for running in analysis task only
205 AliHLTJETReaderHeader* readerHeader = GetReaderHeader();
208 if ( esd && !readerHeader->GetUseMC() )
209 fESD = dynamic_cast<AliESDEvent*> (const_cast<TObject*>(esd));
212 else if ( aod && !readerHeader->GetUseMC() )
213 fAOD = dynamic_cast<AliAODEvent*> (const_cast<TObject*>(aod));
216 else if ( mc && readerHeader->GetUseMC() ) {
218 // -- if off-line MC event,
219 if ( !strcmp (mc->ClassName(),"AliMCEvent") )
220 fMC = dynamic_cast<AliMCEvent*> (const_cast<TObject*>(mc));
221 // -- if on-line MC event
223 fHLTMC = dynamic_cast<AliHLTMCEvent*> (const_cast<TObject*>(mc));
230 * ---------------------------------------------------------------------------------
231 * Fastjet Reader functionality
232 * ---------------------------------------------------------------------------------
235 // #################################################################################
236 Bool_t AliHLTJETReader::FillVector() {
237 // see header file for class documentation
239 Bool_t bResult = kFALSE;
242 bResult = FillVectorESD();
244 bResult = FillVectorMC();
246 bResult = FillVectorHLTMC();
248 bResult = FillVectorAOD();
253 // #################################################################################
254 Bool_t AliHLTJETReader::FillVectorMC() {
255 // see header file for class documentation
257 Bool_t bResult = kTRUE;
260 HLTError( "No MC Event present!" );
269 AliStack* stack = fMC->Stack();
271 for (Int_t iterStack = 0; iterStack < stack->GetNtrack() && bResult; iterStack++) {
273 TParticle *particle = stack->Particle(iterStack);
275 HLTError( "Error reading particle %i out of %i", iterStack, stack->GetNtrack() );
280 // ------------------------------
281 // -- Basic cuts on MC particle --> To be done better XXX
282 // ------------------------------
285 if ( !(stack->IsPhysicalPrimary(iterStack)) )
289 if ( particle->GetNDaughters() != 0 )
293 TParticlePDG * particlePDG = particle->GetPDG();
294 if ( ! particlePDG ) {
295 particlePDG = TDatabasePDG::Instance()->GetParticle( particle->GetPdgCode() );
297 if ( ! particlePDG ) {
298 HLTError("Particle %i not in PDG database", particle->GetPdgCode() );
304 // ------------------------
305 // -- Standard track cuts
306 // ------------------------
308 // -- Apply track cuts
309 if ( ! fTrackCuts->IsSelected(particle) )
312 // -- Create PseudoJet object
313 fastjet::PseudoJet part( particle->Px(), particle->Py(),
314 particle->Pz(), particle->Energy() );
316 // -- label the particle into Fastjet algortihm
317 part.set_user_index( iterStack );
320 // -- Add to input_particles vector
321 fMomentumVector->push_back(part);
325 } // for (Int_t iterStack = 0; iterStack < stack->GetNtrack() && !bResult; iterStack++) {
327 HLTDebug(" Number of selected tracks %d", nTracks);
332 // #################################################################################
333 Bool_t AliHLTJETReader::FillVectorHLTMC() {
334 // see header file for class documentation
337 HLTError( "No HLT MC Event present!" );
346 TParticle* particle = NULL;
348 // -- Loop over particles
349 // ------------------------
350 while ( (particle = fHLTMC->NextParticle() ) ) {
352 // -- Apply track cuts
353 if ( ! fTrackCuts->IsSelected(particle) )
356 // -- Create PseudoJet object
357 fastjet::PseudoJet part( particle->Px(), particle->Py(),
358 particle->Pz(), particle->Energy() );
360 // -- label the particle into Fastjet algortihm
361 part.set_user_index( fHLTMC->GetIndex() );
364 // -- Add to input_particles vector
365 fMomentumVector->push_back(part);
370 } // while ( (particle = fHLTMC->NextParticle() ) ) {
372 HLTInfo(" Number of selected tracks %d", nTracks);
377 // #################################################################################
378 Bool_t AliHLTJETReader::FillVectorESD() {
379 // see header file for class documentation
381 Bool_t bResult = kTRUE;
384 HLTError( "No ESD Event present!" );
393 // -- Loop over particles
394 // ------------------------
395 for ( Int_t iter = 0; iter < fESD->GetNumberOfTracks() && bResult; iter++ ) {
397 AliESDtrack* esdTrack = fESD->GetTrack(iter);
399 HLTError("Could not read ESD track %d from %d", iter, fESD->GetNumberOfTracks() );
404 // -- Apply track cuts
405 if ( ! fTrackCuts->IsSelected(esdTrack) )
408 // -- Create PseudoJet object
409 fastjet::PseudoJet part( esdTrack->Px(), esdTrack->Py(),
410 esdTrack->Pz(), esdTrack->E() );
412 // -- label the particle into Fastjet algortihm
413 part.set_user_index( iter );
416 // -- Add to input_particles vector
417 fMomentumVector->push_back(part);
422 } // for ( Int_t iter = 0; iter < fESD->GetNumberOfTracks() && !iResult; iter++ ) {
424 HLTInfo(" Number of selected tracks %d", nTracks);
430 // #################################################################################
431 Bool_t AliHLTJETReader::FillVectorAOD() {
432 // see header file for class documentation
439 * ---------------------------------------------------------------------------------
441 * ---------------------------------------------------------------------------------
444 // #################################################################################
445 Bool_t AliHLTJETReader::FillGrid() {
446 // see header file for class documentation
448 Bool_t bResult = kFALSE;
451 bResult = FillGridESD();
453 bResult = FillGridMC();
455 bResult = FillGridHLTMC();
457 bResult = FillGridAOD();
462 // #################################################################################
463 Bool_t AliHLTJETReader::FillGridMC() {
464 // see header file for class documentation
466 Bool_t bResult = kTRUE;
469 HLTError( "No MC Event present!" );
476 AliHLTJETReaderHeader* readerHeader = GetReaderHeader();
480 AliStack* stack = fMC->Stack();
482 for (Int_t iterStack = 0; iterStack < stack->GetNtrack() && bResult; iterStack++) {
484 TParticle *particle = stack->Particle(iterStack);
486 HLTError( "Error reading particle %i out of %i", iterStack, stack->GetNtrack() );
491 // ------------------------------
492 // -- Basic cuts on MC particle --> To be done better XXX
493 // ------------------------------
496 if ( !(stack->IsPhysicalPrimary(iterStack)) )
500 if ( particle->GetNDaughters() != 0 )
504 TParticlePDG * particlePDG = particle->GetPDG();
505 if ( ! particlePDG ) {
506 particlePDG = TDatabasePDG::Instance()->GetParticle( particle->GetPdgCode() );
508 if ( ! particlePDG ) {
509 HLTError("Particle %i not in PDG database", particle->GetPdgCode() );
515 // ------------------------
516 // -- Standard track cuts
517 // ------------------------
519 // -- Apply track cuts
520 if ( ! fTrackCuts->IsSelected(particle) )
523 const Float_t aEtaPhi[] = { particle->Eta(), particle->Phi(), particle->Pt() };
524 Int_t aGridIdx[] = { -1, -1, -1, -1, -1 };
526 fGrid->FillTrack(particle, aEtaPhi, aGridIdx);
530 // -- Apply seed cuts
531 if ( ! fSeedCuts->IsSelected(particle) )
535 AddSeed(aEtaPhi, const_cast<const Int_t*> (aGridIdx), readerHeader->GetConeRadius());
537 } // for (Int_t iterStack = 0; iterStack < stack->GetNtrack() && !bResult; iterStack++) {
539 HLTInfo(" Number of selected tracks %d", nTracks);
540 HLTInfo(" Number of seeds %d", fNJetCandidates);
545 // #################################################################################
546 Bool_t AliHLTJETReader::FillGridHLTMC() {
547 // see header file for class documentation
550 HLTError( "No HLT MC Event present!" );
557 AliHLTJETReaderHeader* readerHeader = GetReaderHeader();
560 TParticle* particle = NULL;
562 // -- Loop over particles
563 // ------------------------
564 while ( ( particle = fHLTMC->NextParticle() ) ) {
566 // HLTError("=== nTracks %d ===",nTracks);
568 // -- Apply track cuts
569 if ( ! fTrackCuts->IsSelected(particle) )
572 const Float_t aEtaPhi[] = { particle->Eta(), particle->Phi(), particle->Pt() };
573 Int_t aGridIdx[] = { -1, -1, -1, -1, -1 };
576 fGrid->FillTrack(particle, aEtaPhi, aGridIdx);
580 // -- Apply seed cuts
581 if ( ! fSeedCuts->IsSelected(particle) )
585 AddSeed(aEtaPhi, const_cast<const Int_t*> (aGridIdx),
586 readerHeader->GetConeRadius());
588 } // while ( (particle = fHLTMC->NextParticle() ) ) {
590 HLTInfo(" Number of selected tracks %d", nTracks);
591 HLTInfo(" Number of seeds %d", fNJetCandidates);
596 // #################################################################################
597 Bool_t AliHLTJETReader::FillGridESD() {
598 // see header file for class documentation
600 Bool_t bResult = kTRUE;
603 HLTError( "No ESD Event present!" );
610 AliHLTJETReaderHeader* readerHeader = GetReaderHeader();
614 // -- Loop over particles
615 // ------------------------
616 for ( Int_t iter = 0; iter < fESD->GetNumberOfTracks() && !bResult; iter++ ) {
618 AliESDtrack* esdTrack = fESD->GetTrack(iter);
620 HLTError("Could not read ESD track %d from %d", iter, fESD->GetNumberOfTracks() );
625 // -- Apply track cuts
626 if ( ! fTrackCuts->IsSelected(esdTrack) )
629 const Float_t aEtaPhi[] = { esdTrack->Eta(), esdTrack->Phi(), esdTrack->Pt() };
630 Int_t aGridIdx[] = { -1, -1, -1, -1, -1 };
633 fGrid->FillTrack(esdTrack, aEtaPhi, aGridIdx);
637 // -- Apply seed cuts
638 if ( ! fSeedCuts->IsSelected(esdTrack) )
642 AddSeed(aEtaPhi, const_cast<const Int_t*> (aGridIdx),
643 readerHeader->GetConeRadius());
645 } // for ( Int_t iter = 0; iter < fESD->GetNumberOfTracks() && !iResult; iter++ ) {
647 HLTInfo(" Number of selected tracks %d", nTracks);
648 HLTInfo(" Number of seeds %d", fNJetCandidates);
653 // #################################################################################
654 Bool_t AliHLTJETReader::FillGridAOD() {
655 // see header file for class documentation
661 * ---------------------------------------------------------------------------------
663 * ---------------------------------------------------------------------------------
666 //#################################################################################
667 void AliHLTJETReader::AddSeed( const Float_t* aEtaPhi, const Int_t* aGridIdx,
668 const Float_t coneRadius ) {
669 // see header file for class documentation
671 Bool_t useWholeCell = kTRUE;
673 if ( GetReaderHeader()->GetJetAlgorithm() == AliHLTJETBase::kFFSCRadiusCell )
674 useWholeCell = kFALSE ;
676 // -- Add track / particle
677 new( (*fJetCandidates) [fNJetCandidates] ) AliHLTJETConeJetCandidate( aEtaPhi,
683 HLTDebug("Added Seed Pt=%f, Eta=%f, Phi=%f", aEtaPhi[kIdxPt],
684 aEtaPhi[kIdxEta], aEtaPhi[kIdxPhi] );
690 * ---------------------------------------------------------------------------------
691 * Initialize - private
692 * ---------------------------------------------------------------------------------
695 // #################################################################################
696 Int_t AliHLTJETReader::InitializeFFSC() {
697 // see header file for class documentation
700 AliHLTJETReaderHeader* readerHeader = GetReaderHeader();
702 // -- Initialize grid
703 // --------------------
707 if ( ! (fGrid = new AliHLTJETConeGrid()) ) {
708 HLTError("Error instanciating grid.");
709 iResult = -EINPROGRESS;
713 fGrid->SetEtaRange( readerHeader->GetFiducialEtaMin(),
714 readerHeader->GetFiducialEtaMax(),
715 readerHeader->GetGridEtaRange() );
717 fGrid->SetPhiRange( readerHeader->GetFiducialPhiMin(),
718 readerHeader->GetFiducialPhiMax(),
719 readerHeader->GetGridPhiRange() );
721 fGrid->SetBinning( readerHeader->GetGridEtaBinning(),
722 readerHeader->GetGridEtaBinning() );
724 fGrid->SetConeRadius( readerHeader->GetConeRadius() );
726 iResult = fGrid->Initialize();
729 // -- Initialize jet candidates
730 // ------------------------------
732 fJetCandidates = new TClonesArray("AliHLTJETConeJetCandidate", 30);
733 if ( ! fJetCandidates) {
734 HLTError("Error instanciating jet candidates.");
735 iResult = -EINPROGRESS;
743 // #################################################################################
744 Int_t AliHLTJETReader::InitializeFastjet() {
745 // see header file for class documentation
749 // -- Initialize Vector
750 // ----------------------
751 if ( fMomentumVector )
752 delete fMomentumVector;
754 if ( ! (fMomentumVector = new vector<fastjet::PseudoJet>) ) {
755 HLTError("Error instanciating momentum vector.");
756 iResult = -EINPROGRESS;