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 // ---------------------------------
183 // -- Clear input vector
184 if ( fMomentumVector )
185 fMomentumVector->clear();
192 * ---------------------------------------------------------------------------------
194 * ---------------------------------------------------------------------------------
197 // #################################################################################
198 void AliHLTJETReader::SetInputEvent(const TObject* esd, const TObject* aod, const TObject* mc) {
199 // see header file for class documentation
201 // Needs "useMC" flag for running in analysis task only
203 AliHLTJETReaderHeader* readerHeader = GetReaderHeader();
206 if ( esd && !readerHeader->GetUseMC() )
207 fESD = dynamic_cast<AliESDEvent*> (const_cast<TObject*>(esd));
210 else if ( aod && !readerHeader->GetUseMC() )
211 fAOD = dynamic_cast<AliAODEvent*> (const_cast<TObject*>(aod));
214 else if ( mc && readerHeader->GetUseMC() ) {
216 // -- if off-line MC event,
217 if ( !strcmp (mc->ClassName(),"AliMCEvent") )
218 fMC = dynamic_cast<AliMCEvent*> (const_cast<TObject*>(mc));
219 // -- if on-line MC event
221 fHLTMC = dynamic_cast<AliHLTMCEvent*> (const_cast<TObject*>(mc));
228 * ---------------------------------------------------------------------------------
229 * Fastjet Reader functionality
230 * ---------------------------------------------------------------------------------
233 // #################################################################################
234 Bool_t AliHLTJETReader::FillVector() {
235 // see header file for class documentation
237 Bool_t bResult = kFALSE;
240 bResult = FillVectorESD();
242 bResult = FillVectorMC();
244 bResult = FillVectorHLTMC();
246 bResult = FillVectorAOD();
251 // #################################################################################
252 Bool_t AliHLTJETReader::FillVectorMC() {
253 // see header file for class documentation
255 Bool_t bResult = kTRUE;
258 HLTError( "No MC Event present!" );
267 AliStack* stack = fMC->Stack();
269 for (Int_t iterStack = 0; iterStack < stack->GetNtrack() && bResult; iterStack++) {
271 TParticle *particle = stack->Particle(iterStack);
273 HLTError( "Error reading particle %i out of %i", iterStack, stack->GetNtrack() );
278 // ------------------------------
279 // -- Basic cuts on MC particle --> To be done better XXX
280 // ------------------------------
283 if ( !(stack->IsPhysicalPrimary(iterStack)) )
287 if ( particle->GetNDaughters() != 0 )
291 TParticlePDG * particlePDG = particle->GetPDG();
292 if ( ! particlePDG ) {
293 particlePDG = TDatabasePDG::Instance()->GetParticle( particle->GetPdgCode() );
295 if ( ! particlePDG ) {
296 HLTError("Particle %i not in PDG database", particle->GetPdgCode() );
302 // ------------------------
303 // -- Standard track cuts
304 // ------------------------
306 // -- Apply track cuts
307 if ( ! fTrackCuts->IsSelected(particle) )
310 // -- Create PseudoJet object
311 fastjet::PseudoJet part( particle->Px(), particle->Py(),
312 particle->Pz(), particle->Energy() );
314 // -- label the particle into Fastjet algortihm
315 part.set_user_index( iterStack );
317 // -- Add to input_particles vector
318 fMomentumVector->push_back(part);
321 } // for (Int_t iterStack = 0; iterStack < stack->GetNtrack() && !bResult; iterStack++) {
323 HLTDebug(" Number of selected tracks %d", nTracks);
328 // #################################################################################
329 Bool_t AliHLTJETReader::FillVectorHLTMC() {
330 // see header file for class documentation
333 HLTError( "No HLT MC Event present!" );
342 TParticle* particle = NULL;
344 // -- Loop over particles
345 // ------------------------
346 while ( (particle = fHLTMC->NextParticle() ) ) {
348 // -- Apply track cuts
349 if ( ! fTrackCuts->IsSelected(particle) )
352 // -- Create PseudoJet object
353 fastjet::PseudoJet part( particle->Px(), particle->Py(),
354 particle->Pz(), particle->Energy() );
356 // -- label the particle into Fastjet algortihm
357 part.set_user_index( fHLTMC->GetIndex() );
359 // -- Add to input_particles vector
360 fMomentumVector->push_back(part);
364 } // while ( (particle = fHLTMC->NextParticle() ) ) {
366 HLTInfo(" Number of selected tracks %d", nTracks);
371 // #################################################################################
372 Bool_t AliHLTJETReader::FillVectorESD() {
373 // see header file for class documentation
375 Bool_t bResult = kTRUE;
378 HLTError( "No ESD Event present!" );
387 // -- Loop over particles
388 // ------------------------
389 for ( Int_t iter = 0; iter < fESD->GetNumberOfTracks() && bResult; iter++ ) {
391 AliESDtrack* esdTrack = fESD->GetTrack(iter);
393 HLTError("Could not read ESD track %d from %d", iter, fESD->GetNumberOfTracks() );
398 // -- Apply track cuts
399 if ( ! fTrackCuts->IsSelected(esdTrack) )
402 // -- Create PseudoJet object
403 fastjet::PseudoJet part( esdTrack->Px(), esdTrack->Py(),
404 esdTrack->Pz(), esdTrack->E() );
406 // -- label the particle into Fastjet algortihm
407 part.set_user_index( iter );
409 // -- Add to input_particles vector
410 fMomentumVector->push_back(part);
414 } // for ( Int_t iter = 0; iter < fESD->GetNumberOfTracks() && !iResult; iter++ ) {
416 HLTInfo(" Number of selected tracks %d", nTracks);
422 // #################################################################################
423 Bool_t AliHLTJETReader::FillVectorAOD() {
424 // see header file for class documentation
431 * ---------------------------------------------------------------------------------
433 * ---------------------------------------------------------------------------------
436 // #################################################################################
437 Bool_t AliHLTJETReader::FillGrid() {
438 // see header file for class documentation
440 Bool_t bResult = kFALSE;
443 bResult = FillGridESD();
445 bResult = FillGridMC();
447 bResult = FillGridHLTMC();
449 bResult = FillGridAOD();
454 // #################################################################################
455 Bool_t AliHLTJETReader::FillGridMC() {
456 // see header file for class documentation
458 Bool_t bResult = kTRUE;
461 HLTError( "No MC Event present!" );
468 AliHLTJETReaderHeader* readerHeader = GetReaderHeader();
472 AliStack* stack = fMC->Stack();
474 for (Int_t iterStack = 0; iterStack < stack->GetNtrack() && bResult; iterStack++) {
476 TParticle *particle = stack->Particle(iterStack);
478 HLTError( "Error reading particle %i out of %i", iterStack, stack->GetNtrack() );
483 // ------------------------------
484 // -- Basic cuts on MC particle --> To be done better XXX
485 // ------------------------------
488 if ( !(stack->IsPhysicalPrimary(iterStack)) )
492 if ( particle->GetNDaughters() != 0 )
496 TParticlePDG * particlePDG = particle->GetPDG();
497 if ( ! particlePDG ) {
498 particlePDG = TDatabasePDG::Instance()->GetParticle( particle->GetPdgCode() );
500 if ( ! particlePDG ) {
501 HLTError("Particle %i not in PDG database", particle->GetPdgCode() );
507 // ------------------------
508 // -- Standard track cuts
509 // ------------------------
511 // -- Apply track cuts
512 if ( ! fTrackCuts->IsSelected(particle) )
515 const Float_t aEtaPhi[] = { particle->Eta(), particle->Phi(), particle->Pt() };
516 Int_t aGridIdx[] = { -1, -1, -1, -1, -1 };
518 fGrid->FillTrack(particle, aEtaPhi, aGridIdx);
522 // -- Apply seed cuts
523 if ( ! fSeedCuts->IsSelected(particle) )
527 AddSeed(aEtaPhi, const_cast<const Int_t*> (aGridIdx), readerHeader->GetConeRadius());
529 } // for (Int_t iterStack = 0; iterStack < stack->GetNtrack() && !bResult; iterStack++) {
531 HLTInfo(" Number of selected tracks %d", nTracks);
532 HLTInfo(" Number of seeds %d", fNJetCandidates);
537 // #################################################################################
538 Bool_t AliHLTJETReader::FillGridHLTMC() {
539 // see header file for class documentation
542 HLTError( "No HLT MC Event present!" );
549 AliHLTJETReaderHeader* readerHeader = GetReaderHeader();
552 TParticle* particle = NULL;
554 // -- Loop over particles
555 // ------------------------
556 while ( ( particle = fHLTMC->NextParticle() ) ) {
558 // HLTError("=== nTracks %d ===",nTracks);
560 // -- Apply track cuts
561 if ( ! fTrackCuts->IsSelected(particle) )
564 const Float_t aEtaPhi[] = { particle->Eta(), particle->Phi(), particle->Pt() };
565 Int_t aGridIdx[] = { -1, -1, -1, -1, -1 };
568 fGrid->FillTrack(particle, aEtaPhi, aGridIdx);
572 // -- Apply seed cuts
573 if ( ! fSeedCuts->IsSelected(particle) )
577 AddSeed(aEtaPhi, const_cast<const Int_t*> (aGridIdx),
578 readerHeader->GetConeRadius());
580 } // while ( (particle = fHLTMC->NextParticle() ) ) {
582 HLTInfo(" Number of selected tracks %d", nTracks);
583 HLTInfo(" Number of seeds %d", fNJetCandidates);
588 // #################################################################################
589 Bool_t AliHLTJETReader::FillGridESD() {
590 // see header file for class documentation
592 Bool_t bResult = kTRUE;
595 HLTError( "No ESD Event present!" );
602 AliHLTJETReaderHeader* readerHeader = GetReaderHeader();
606 // -- Loop over particles
607 // ------------------------
608 for ( Int_t iter = 0; iter < fESD->GetNumberOfTracks() && !bResult; iter++ ) {
610 AliESDtrack* esdTrack = fESD->GetTrack(iter);
612 HLTError("Could not read ESD track %d from %d", iter, fESD->GetNumberOfTracks() );
617 // -- Apply track cuts
618 if ( ! fTrackCuts->IsSelected(esdTrack) )
621 const Float_t aEtaPhi[] = { esdTrack->Eta(), esdTrack->Phi(), esdTrack->Pt() };
622 Int_t aGridIdx[] = { -1, -1, -1, -1, -1 };
625 fGrid->FillTrack(esdTrack, aEtaPhi, aGridIdx);
629 // -- Apply seed cuts
630 if ( ! fSeedCuts->IsSelected(esdTrack) )
634 AddSeed(aEtaPhi, const_cast<const Int_t*> (aGridIdx),
635 readerHeader->GetConeRadius());
637 } // for ( Int_t iter = 0; iter < fESD->GetNumberOfTracks() && !iResult; iter++ ) {
639 HLTInfo(" Number of selected tracks %d", nTracks);
640 HLTInfo(" Number of seeds %d", fNJetCandidates);
645 // #################################################################################
646 Bool_t AliHLTJETReader::FillGridAOD() {
647 // see header file for class documentation
653 * ---------------------------------------------------------------------------------
655 * ---------------------------------------------------------------------------------
658 //#################################################################################
659 void AliHLTJETReader::AddSeed( const Float_t* aEtaPhi, const Int_t* aGridIdx,
660 const Float_t coneRadius ) {
661 // see header file for class documentation
663 Bool_t useWholeCell = kTRUE;
665 if ( GetReaderHeader()->GetJetAlgorithm() == AliHLTJETBase::kFFSCRadiusCell )
666 useWholeCell = kFALSE ;
668 // -- Add track / particle
669 new( (*fJetCandidates) [fNJetCandidates] ) AliHLTJETConeJetCandidate( aEtaPhi,
675 HLTDebug("Added Seed Pt=%f, Eta=%f, Phi=%f", aEtaPhi[kIdxPt],
676 aEtaPhi[kIdxEta], aEtaPhi[kIdxPhi] );
682 * ---------------------------------------------------------------------------------
683 * Initialize - private
684 * ---------------------------------------------------------------------------------
687 // #################################################################################
688 Int_t AliHLTJETReader::InitializeFFSC() {
689 // see header file for class documentation
692 AliHLTJETReaderHeader* readerHeader = GetReaderHeader();
694 // -- Initialize grid
695 // --------------------
699 if ( ! (fGrid = new AliHLTJETConeGrid()) ) {
700 HLTError("Error instanciating grid.");
701 iResult = -EINPROGRESS;
705 fGrid->SetEtaRange( readerHeader->GetFiducialEtaMin(),
706 readerHeader->GetFiducialEtaMax(),
707 readerHeader->GetGridEtaRange() );
709 fGrid->SetPhiRange( readerHeader->GetFiducialPhiMin(),
710 readerHeader->GetFiducialPhiMax(),
711 readerHeader->GetGridPhiRange() );
713 fGrid->SetBinning( readerHeader->GetGridEtaBinning(),
714 readerHeader->GetGridEtaBinning() );
716 fGrid->SetConeRadius( readerHeader->GetConeRadius() );
718 iResult = fGrid->Initialize();
721 // -- Initialize jet candidates
722 // ------------------------------
724 fJetCandidates = new TClonesArray("AliHLTJETConeJetCandidate", 30);
725 if ( ! fJetCandidates) {
726 HLTError("Error instanciating jet candidates.");
727 iResult = -EINPROGRESS;
735 // #################################################################################
736 Int_t AliHLTJETReader::InitializeFastjet() {
737 // see header file for class documentation
741 // -- Initialize Vector
742 // ----------------------
743 if ( fMomentumVector )
744 delete fMomentumVector;
746 if ( ! (fMomentumVector = new vector<fastjet::PseudoJet>) ) {
747 HLTError("Error instanciating momentum vector.");
748 iResult = -EINPROGRESS;