]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/JET/cone/AliHLTJETConeFinder.cxx
Add new classes for the jet cone finder
[u/mrichter/AliRoot.git] / HLT / JET / cone / AliHLTJETConeFinder.cxx
CommitLineData
7c3c85cd 1//-*- Mode: C++ -*-
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. *
6 * *
7 * Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
8 * for The ALICE HLT Project. *
9 * *
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 **************************************************************************/
18
19/** @file AliHLTJETConeFinder.cxx
20 @author Jochen Thaeder
21 @date
22 @brief Jet cone finder
23*/
24
25// see header file for class documentation
26// or
27// refer to README to build package
28// or
29// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31#if __GNUC__ >= 3
32using namespace std;
33#endif
34
35#include "AliHLTJETReader.h"
36
37#include "AliHLTJETConeGrid.h"
38#include "AliHLTJETConeFinder.h"
39#include "AliHLTJETConeHeader.h"
40#include "AliHLTJETConeJetCandidate.h"
41#include "AliHLTJETConeEtaPhiCell.h"
42
43/** ROOT macro for the implementation of ROOT specific class methods */
44ClassImp(AliHLTJETConeFinder)
45
46/*
47 * ---------------------------------------------------------------------------------
48 * Constructor / Destructor
49 * ---------------------------------------------------------------------------------
50 */
51
52// #################################################################################
53AliHLTJETConeFinder::AliHLTJETConeFinder()
54 :
55 AliJetFinder(),
56 fGrid(NULL),
57 fJets(NULL) {
58 // see header file for class documentation
59 // or
60 // refer to README to build package
61 // or
62 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
63
64}
65
66// #################################################################################
67AliHLTJETConeFinder::~AliHLTJETConeFinder() {
68 // see header file for class documentation
69
70}
71
72/*
73 * ---------------------------------------------------------------------------------
74 * Initialize
75 * ---------------------------------------------------------------------------------
76 */
77
78// #################################################################################
79Int_t AliHLTJETConeFinder::Initialize() {
80 // see header file for class documentation
81
82 Int_t iResult = 0;
83
84 if ( !fHeader || !fReader ) {
85 HLTError("No header or reader set!");
86 return -EINPROGRESS;
87 }
88
89 // -- Initialize Reader
90 AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
91
92 iResult = reader->Initialize();
93 if ( iResult ) {
94 HLTError( "Initializing Reader failed!");
95 return iResult;
96 }
97
98 // -- Initialize Header
99 AliHLTJETConeHeader *header = dynamic_cast<AliHLTJETConeHeader*> (fHeader);
100
101 iResult = header->Initialize();
102 if ( iResult ) {
103 HLTError( "Initializing Header failed!");
104 return iResult;
105 }
106
107 // -- Set ptr to grid
108 fGrid = reader->GetGrid();
109 if ( ! fGrid ) {
110 HLTError( "Getting ptr to grid failed!");
111 return -EINPROGRESS;
112 }
113
114 // -- Check ptr to output container
115 if ( !fJets ) {
116 HLTError( "Ptr to output container not set!");
117 return -EINPROGRESS;
118 }
119
120 return iResult;
121}
122
123// #################################################################################
124void AliHLTJETConeFinder::Reset() {
125 // see header file for class documentation
126
127 // -- Reset reader
128 (dynamic_cast<AliHLTJETReader*> (fReader))->ResetEvent();
129
130 // -- Reset output container
131 if (fJets)
132 fJets->Reset();
133
134 return;
135}
136
137
138/*
139 * ---------------------------------------------------------------------------------
140 * Process
141 * ---------------------------------------------------------------------------------
142 */
143
144// #################################################################################
145Bool_t AliHLTJETConeFinder::ProcessEvent() {
146 // see header file for class documentation
147
148 // -- Pick up jet reader
149 AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
150
151 // -- Reset
152 Reset();
153
154 // -- Fill Grid
155 if ( !reader->FillGrid() ){
156 HLTError("Error filling grid.");
157 return kFALSE;
158 }
159
160 // -- Find Leading
161 if ( FindConeLeading() ) {
162 HLTError("Error finding leading.");
163 return kFALSE;
164 }
165
166 // -- Find Jets
167 if ( FindConeJets() ) {
168 HLTError("Error finding jets.");
169 return kFALSE;
170 }
171
172 // -- Fill Jets and apply jet cuts
173 if ( FillConeJets() ) {
174 HLTError("Error filling jets.");
175 return kFALSE;
176 }
177
178 return kTRUE;
179}
180
181// #################################################################################
182Bool_t AliHLTJETConeFinder::ProcessConeEvent() {
183 // see header file for class documentation
184
185 // -- Find Leading
186 if ( FindConeLeading() ) {
187 HLTError("Error finding leading.");
188 return kFALSE;
189 }
190
191 // -- Find Jets
192 if ( FindConeJets() ) {
193 HLTError("Error finding jets.");
194 return kFALSE;
195 }
196
197 // -- Fill Jets and apply jet cuts
198 if ( FillConeJets() ) {
199 HLTError("Error filling jets.");
200 return kFALSE;
201 }
202
203 return kTRUE;
204}
205
206/*
207 * ---------------------------------------------------------------------------------
208 * Process - private
209 * ---------------------------------------------------------------------------------
210 */
211
212// #################################################################################
213Int_t AliHLTJETConeFinder::FindConeLeading() {
214 // see header file for class documentation
215
216 // -- Pick up jet reader
217 AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
218
219 // -- Pick up jet canidates
220 TClonesArray* jetCandidates = reader->GetJetCandidates();
221
222 // -- Sort jet candidates with seed pt
223 jetCandidates->Sort();
224
225 // -- Use leading seed only
226 // Keep index 0, remove the others
227 if ( (dynamic_cast<AliHLTJETConeHeader*> (fHeader))->GetUseLeading() ) {
228
229 for ( Int_t iter = 1; iter < reader->GetNJetCandidates(); iter++ )
230 jetCandidates->RemoveAt(iter);
231
232 reader->SetNJetCandidates(1);
233 }
234
235 // -- Resize the seed TClonesArray
236 jetCandidates->Compress();
237
238 return 0;
239}
240
241// #################################################################################
242Int_t AliHLTJETConeFinder::FindConeJets() {
243 // see header file for class documentation
244
245 Int_t iResult = 0;
246
247 // -- Pick up jet reader
248 AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
249
250 // -- Pick up jet canidates
251 TClonesArray* jetCandidates = reader->GetJetCandidates();
252
253 // -- Loop over jet candidates
254 for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
255
256 AliHLTJETConeJetCandidate* jet = reinterpret_cast<AliHLTJETConeJetCandidate*> ((*jetCandidates)[iter]);
257
258 // -- Set iterator for cells around seed
259 fGrid->SetCellIter( jet->GetSeedEtaIdx(), jet->GetSeedPhiIdx() );
260
261 Int_t cellIdx = 0;
262
263 // -- Loop over cells around ssed
264 while ( (cellIdx = fGrid->NextCell() ) != -1 && !iResult) {
265
266 AliHLTJETConeEtaPhiCell* cell = NULL;
267 if ( ! (cell = reinterpret_cast<AliHLTJETConeEtaPhiCell*>(fGrid->UncheckedAt(cellIdx))) )
268 continue;
269
270 if ( ( iResult = jet->AddCell(cell) ) ) {
271 HLTError( "Error adding cell %d to jet candiate %d", cellIdx, iter);
272 continue;
273 }
274 } // while ( (cellIdx = fGrid->NextCell() ) != -1 && !iResult) {
275
276 } // for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
277
278 return iResult;
279}
280
281// #################################################################################
282Int_t AliHLTJETConeFinder::FillConeJets() {
283 // see header file for class documentation
284
285 Int_t iResult = 0;
286
287 // -- Pick up jet reader
288 AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
289
290 // -- Pick up jet header
291 AliHLTJETConeHeader *header = dynamic_cast<AliHLTJETConeHeader*> (fHeader);
292
293 // -- Get jet canidates
294 TClonesArray* jetCandidates = reader->GetJetCandidates();
295
296 // -- Get jet cuts
297 AliHLTJETJetCuts* jetCuts = header->GetJetCuts();
298
299 // -- Loop over jet candidates
300 for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
301
302 AliHLTJETConeJetCandidate* jet = reinterpret_cast<AliHLTJETConeJetCandidate*> ((*jetCandidates)[iter]);
303
304 // -- Apply jet cuts
305 if ( ! jetCuts->IsSelected(jet) )
306 continue;
307
308 // -- Add jet as AliAODJet
309 fJets->AddJet(jet);
310
311 } // for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
312
313 HLTDebug( "Added %d jets", fJets->GetNAODJets());
314
315 return iResult;
316}