2 // $Id: AliHLTJETConeFinder.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 AliHLTJETConeFinder.cxx
20 @author Jochen Thaeder
22 @brief Jet cone 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 "AliHLTJETReader.h"
37 #include "AliHLTJETConeGrid.h"
38 #include "AliHLTJETConeFinder.h"
39 #include "AliHLTJETConeHeader.h"
40 #include "AliHLTJETConeJetCandidate.h"
41 #include "AliHLTJETConeEtaPhiCell.h"
43 /** ROOT macro for the implementation of ROOT specific class methods */
44 ClassImp(AliHLTJETConeFinder)
47 * ---------------------------------------------------------------------------------
48 * Constructor / Destructor
49 * ---------------------------------------------------------------------------------
52 // #################################################################################
53 AliHLTJETConeFinder::AliHLTJETConeFinder()
58 // see header file for class documentation
60 // refer to README to build package
62 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
66 // #################################################################################
67 AliHLTJETConeFinder::~AliHLTJETConeFinder() {
68 // see header file for class documentation
73 * ---------------------------------------------------------------------------------
75 * ---------------------------------------------------------------------------------
78 // #################################################################################
79 Int_t AliHLTJETConeFinder::Initialize() {
80 // see header file for class documentation
84 if ( !fHeader || !fReader ) {
85 HLTError("No header or reader set!");
89 // -- Initialize Reader
90 AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
92 iResult = reader->Initialize();
94 HLTError( "Initializing Reader failed!");
98 // -- Initialize Header
99 AliHLTJETConeHeader *header = dynamic_cast<AliHLTJETConeHeader*> (fHeader);
101 iResult = header->Initialize();
103 HLTError( "Initializing Header failed!");
107 // -- Set ptr to grid
108 fGrid = reader->GetGrid();
110 HLTError( "Getting ptr to grid failed!");
114 // -- Check ptr to output container
116 HLTError( "Ptr to output container not set!");
123 // #################################################################################
124 void AliHLTJETConeFinder::Reset() {
125 // see header file for class documentation
127 // -- Reset output container
135 * ---------------------------------------------------------------------------------
137 * ---------------------------------------------------------------------------------
140 // #################################################################################
141 Bool_t AliHLTJETConeFinder::ProcessEvent() {
142 // see header file for class documentation
144 // -- Pick up jet reader
145 AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
151 if ( !reader->FillGrid() ){
152 HLTError("Error filling grid.");
157 if ( FindConeLeading() ) {
158 HLTError("Error finding leading.");
163 if ( FindConeJets() ) {
164 HLTError("Error finding jets.");
168 // -- Fill Jets and apply jet cuts
169 if ( FillConeJets() ) {
170 HLTError("Error filling jets.");
177 // #################################################################################
178 Bool_t AliHLTJETConeFinder::ProcessHLTEvent() {
179 // see header file for class documentation
185 if ( FindConeLeading() ) {
186 HLTError("Error finding leading.");
191 if ( FindConeJets() ) {
192 HLTError("Error finding jets.");
196 // -- Fill Jets and apply jet cuts
197 if ( FillConeJets() ) {
198 HLTError("Error filling jets.");
206 * ---------------------------------------------------------------------------------
208 * ---------------------------------------------------------------------------------
211 // #################################################################################
212 Int_t AliHLTJETConeFinder::FindConeLeading() {
213 // see header file for class documentation
215 // -- Pick up jet reader
216 AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
218 // -- Pick up jet canidates
219 TClonesArray* jetCandidates = reader->GetJetCandidates();
221 // -- Check for more than 1 jet candidate
222 if ( reader->GetNJetCandidates() > 1 ) {
224 // -- Sort jet candidates with seed pt
225 jetCandidates->Sort();
227 // -- Use leading seed only
228 // Keep index 0, remove the others
229 if ( (dynamic_cast<AliHLTJETConeHeader*> (fHeader))->GetUseLeading() ) {
231 for ( Int_t iter = 1; iter < reader->GetNJetCandidates(); iter++ )
232 jetCandidates->RemoveAt(iter);
234 reader->SetNJetCandidates(1);
237 } // if ( reader->GetNJetCandidates() > 1 ) {
239 // -- Resize the seed TClonesArray
240 jetCandidates->Compress();
245 // #################################################################################
246 Int_t AliHLTJETConeFinder::FindConeJets() {
247 // see header file for class documentation
251 // -- Pick up jet reader
252 AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
254 // -- Pick up jet canidates
255 TClonesArray* jetCandidates = reader->GetJetCandidates();
257 // -- Loop over jet candidates
258 for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
260 AliHLTJETConeJetCandidate* jet = reinterpret_cast<AliHLTJETConeJetCandidate*> ((*jetCandidates)[iter]);
262 // -- Set iterator for cells around seed
263 fGrid->SetCellIter( jet->GetSeedEtaIdx(), jet->GetSeedPhiIdx() );
267 // -- Loop over cells around ssed
268 while ( (cellIdx = fGrid->NextCell() ) >= 0 && !iResult) {
270 AliHLTJETConeEtaPhiCell* cell = NULL;
271 if ( ! (cell = reinterpret_cast<AliHLTJETConeEtaPhiCell*>(fGrid->UncheckedAt(cellIdx))) )
274 if ( ( iResult = jet->AddCell(cell) ) ) {
275 HLTError( "Error adding cell %d to jet candiate %d", cellIdx, iter);
278 } // while ( (cellIdx = fGrid->NextCell() ) >= 0 && !iResult) {
280 } // for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
285 // #################################################################################
286 Int_t AliHLTJETConeFinder::FillConeJets() {
287 // see header file for class documentation
291 // -- Pick up jet reader
292 AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
294 // -- Pick up jet header
295 AliHLTJETConeHeader *header = dynamic_cast<AliHLTJETConeHeader*> (fHeader);
297 // -- Get jet canidates
298 TClonesArray* jetCandidates = reader->GetJetCandidates();
301 AliHLTJETJetCuts* jetCuts = header->GetJetCuts();
303 // -- Loop over jet candidates
304 for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
306 AliHLTJETConeJetCandidate* jet = reinterpret_cast<AliHLTJETConeJetCandidate*> ((*jetCandidates)[iter]);
309 if ( ! jetCuts->IsSelected(jet) )
312 // -- Add jet as AliAODJet
313 fJets->AddJet(jet->GetEta(), jet->GetPhi(), jet->GetPt(), jet->GetEt());
315 } // for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
317 // xxx HLTDebug( "Added %d jets", fJets->GetNAODJets());
318 HLTInfo( "Added %d jets", fJets->GetNAODJets());