]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/JET/cone/AliHLTJETConeFinder.cxx
Proper treatment of runs in which only a subset of the QA tasks are available
[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);
f5561f3a 91 if (!reader) {
92 HLTError( "Casting Reader failed!");
93 return -EINPROGRESS;
94 }
95
7c3c85cd 96 iResult = reader->Initialize();
97 if ( iResult ) {
98 HLTError( "Initializing Reader failed!");
f5561f3a 99 return -EINPROGRESS;
7c3c85cd 100 }
101
102 // -- Initialize Header
103 AliHLTJETConeHeader *header = dynamic_cast<AliHLTJETConeHeader*> (fHeader);
f5561f3a 104 if (!header) {
105 HLTError( "Casting Header failed!");
106 return -EINPROGRESS;
107 }
7c3c85cd 108
109 iResult = header->Initialize();
110 if ( iResult ) {
111 HLTError( "Initializing Header failed!");
f5561f3a 112 return -EINPROGRESS;
7c3c85cd 113 }
114
115 // -- Set ptr to grid
116 fGrid = reader->GetGrid();
117 if ( ! fGrid ) {
118 HLTError( "Getting ptr to grid failed!");
119 return -EINPROGRESS;
120 }
121
122 // -- Check ptr to output container
123 if ( !fJets ) {
124 HLTError( "Ptr to output container not set!");
125 return -EINPROGRESS;
126 }
127
128 return iResult;
129}
130
131// #################################################################################
132void AliHLTJETConeFinder::Reset() {
133 // see header file for class documentation
134
7c3c85cd 135 // -- Reset output container
136 if (fJets)
137 fJets->Reset();
138
139 return;
140}
141
7c3c85cd 142/*
143 * ---------------------------------------------------------------------------------
144 * Process
145 * ---------------------------------------------------------------------------------
146 */
147
148// #################################################################################
149Bool_t AliHLTJETConeFinder::ProcessEvent() {
150 // see header file for class documentation
151
7c3c85cd 152 // -- Reset
153 Reset();
154
ba05d245 155 // -- Pick up jet reader
156 AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
157 if ( !reader ) {
158 HLTError("Error getting reader.");
159 return kFALSE;
160 }
161
7c3c85cd 162 // -- Fill Grid
163 if ( !reader->FillGrid() ){
164 HLTError("Error filling grid.");
165 return kFALSE;
166 }
167
168 // -- Find Leading
169 if ( FindConeLeading() ) {
170 HLTError("Error finding leading.");
171 return kFALSE;
172 }
173
174 // -- Find Jets
175 if ( FindConeJets() ) {
176 HLTError("Error finding jets.");
177 return kFALSE;
178 }
179
180 // -- Fill Jets and apply jet cuts
181 if ( FillConeJets() ) {
182 HLTError("Error filling jets.");
183 return kFALSE;
184 }
185
186 return kTRUE;
187}
188
189// #################################################################################
1f9fec4a 190Bool_t AliHLTJETConeFinder::ProcessHLTEvent() {
7c3c85cd 191 // see header file for class documentation
192
1f9fec4a 193 // -- Reset
194 Reset();
195
7c3c85cd 196 // -- Find Leading
197 if ( FindConeLeading() ) {
198 HLTError("Error finding leading.");
199 return kFALSE;
200 }
201
202 // -- Find Jets
203 if ( FindConeJets() ) {
204 HLTError("Error finding jets.");
205 return kFALSE;
206 }
207
208 // -- Fill Jets and apply jet cuts
209 if ( FillConeJets() ) {
210 HLTError("Error filling jets.");
211 return kFALSE;
212 }
213
214 return kTRUE;
215}
216
217/*
218 * ---------------------------------------------------------------------------------
219 * Process - private
220 * ---------------------------------------------------------------------------------
221 */
222
223// #################################################################################
224Int_t AliHLTJETConeFinder::FindConeLeading() {
225 // see header file for class documentation
226
227 // -- Pick up jet reader
228 AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
ba05d245 229 if ( !reader ) {
230 HLTError("Error getting reader.");
231 return -EINPROGRESS;
232 }
233
234 // -- Pick up jet header
235 AliHLTJETConeHeader* header = dynamic_cast<AliHLTJETConeHeader*> (fHeader);
236 if ( !header ) {
237 HLTError("Error getting header.");
238 return -EINPROGRESS;
239 }
5e2e85e8 240
7c3c85cd 241 // -- Pick up jet canidates
242 TClonesArray* jetCandidates = reader->GetJetCandidates();
1f9fec4a 243
5e2e85e8 244 // -- Check for more than 1 jet candidate
245 if ( reader->GetNJetCandidates() > 1 ) {
7c3c85cd 246
5e2e85e8 247 // -- Sort jet candidates with seed pt
248 jetCandidates->Sort();
7c3c85cd 249
5e2e85e8 250 // -- Use leading seed only
251 // Keep index 0, remove the others
ba05d245 252 if ( header->GetUseLeading() ) {
5e2e85e8 253
254 for ( Int_t iter = 1; iter < reader->GetNJetCandidates(); iter++ )
255 jetCandidates->RemoveAt(iter);
256
257 reader->SetNJetCandidates(1);
258 }
259
260 } // if ( reader->GetNJetCandidates() > 1 ) {
261
7c3c85cd 262 // -- Resize the seed TClonesArray
263 jetCandidates->Compress();
1f9fec4a 264
7c3c85cd 265 return 0;
266}
267
268// #################################################################################
269Int_t AliHLTJETConeFinder::FindConeJets() {
270 // see header file for class documentation
271
272 Int_t iResult = 0;
273
274 // -- Pick up jet reader
275 AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
ba05d245 276 if ( !reader ) {
277 HLTError("Error getting reader.");
278 return -EINPROGRESS;
279 }
280
7c3c85cd 281 // -- Pick up jet canidates
282 TClonesArray* jetCandidates = reader->GetJetCandidates();
283
284 // -- Loop over jet candidates
285 for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
286
287 AliHLTJETConeJetCandidate* jet = reinterpret_cast<AliHLTJETConeJetCandidate*> ((*jetCandidates)[iter]);
288
289 // -- Set iterator for cells around seed
290 fGrid->SetCellIter( jet->GetSeedEtaIdx(), jet->GetSeedPhiIdx() );
291
292 Int_t cellIdx = 0;
293
294 // -- Loop over cells around ssed
5e2e85e8 295 while ( (cellIdx = fGrid->NextCell() ) >= 0 && !iResult) {
7c3c85cd 296
297 AliHLTJETConeEtaPhiCell* cell = NULL;
298 if ( ! (cell = reinterpret_cast<AliHLTJETConeEtaPhiCell*>(fGrid->UncheckedAt(cellIdx))) )
299 continue;
300
301 if ( ( iResult = jet->AddCell(cell) ) ) {
302 HLTError( "Error adding cell %d to jet candiate %d", cellIdx, iter);
303 continue;
304 }
5e2e85e8 305 } // while ( (cellIdx = fGrid->NextCell() ) >= 0 && !iResult) {
7c3c85cd 306
307 } // for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
308
309 return iResult;
310}
311
312// #################################################################################
313Int_t AliHLTJETConeFinder::FillConeJets() {
314 // see header file for class documentation
315
316 Int_t iResult = 0;
317
318 // -- Pick up jet reader
319 AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
ba05d245 320 if ( !reader ) {
321 HLTError("Error getting reader.");
322 return -EINPROGRESS;
323 }
7c3c85cd 324
325 // -- Pick up jet header
326 AliHLTJETConeHeader *header = dynamic_cast<AliHLTJETConeHeader*> (fHeader);
ba05d245 327 if ( !header ) {
328 HLTError("Error getting header.");
329 return -EINPROGRESS;
330 }
331
7c3c85cd 332 // -- Get jet canidates
333 TClonesArray* jetCandidates = reader->GetJetCandidates();
334
335 // -- Get jet cuts
336 AliHLTJETJetCuts* jetCuts = header->GetJetCuts();
337
338 // -- Loop over jet candidates
339 for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
340
341 AliHLTJETConeJetCandidate* jet = reinterpret_cast<AliHLTJETConeJetCandidate*> ((*jetCandidates)[iter]);
342
343 // -- Apply jet cuts
344 if ( ! jetCuts->IsSelected(jet) )
345 continue;
346
347 // -- Add jet as AliAODJet
6ce099ba 348 fJets->AddJet(jet->GetEta(), jet->GetPhi(), jet->GetPt(), jet->GetEt());
349
7c3c85cd 350 } // for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
351
1f9fec4a 352 // xxx HLTDebug( "Added %d jets", fJets->GetNAODJets());
353 HLTInfo( "Added %d jets", fJets->GetNAODJets());
7c3c85cd 354
355 return iResult;
356}