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