]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/JET/cone/AliHLTJETConeFinder.cxx
* Added fast interface to fastjet
[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 #if __GNUC__ >= 3
32 using 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 */
44 ClassImp(AliHLTJETConeFinder)
45
46 /*
47  * ---------------------------------------------------------------------------------
48  *                            Constructor / Destructor
49  * ---------------------------------------------------------------------------------
50  */
51   
52 // #################################################################################
53 AliHLTJETConeFinder::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 // #################################################################################
67 AliHLTJETConeFinder::~AliHLTJETConeFinder() {
68   // see header file for class documentation
69
70 }
71
72 /*
73  * ---------------------------------------------------------------------------------
74  *                                    Initialize
75  * ---------------------------------------------------------------------------------
76  */
77
78 // #################################################################################
79 Int_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 // #################################################################################
124 void AliHLTJETConeFinder::Reset() {
125   // see header file for class documentation
126
127   // -- Reset output container
128   if (fJets)
129     fJets->Reset();
130   
131   return;
132 }
133
134 /*
135  * ---------------------------------------------------------------------------------
136  *                                      Process
137  * ---------------------------------------------------------------------------------
138  */
139
140 // #################################################################################
141 Bool_t AliHLTJETConeFinder::ProcessEvent() {
142   // see header file for class documentation
143
144   // -- Pick up jet reader
145   AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
146
147   // -- Reset
148   Reset();
149
150   // -- Fill Grid
151   if ( !reader->FillGrid() ){
152     HLTError("Error filling grid.");
153     return kFALSE;  
154   }
155
156   // -- Find Leading
157   if ( FindConeLeading()  ) {
158     HLTError("Error finding leading.");
159     return kFALSE;
160   }
161
162   // -- Find Jets 
163   if ( FindConeJets()  ) {
164     HLTError("Error finding jets.");
165     return kFALSE;
166   }
167
168   // -- Fill Jets and apply jet cuts
169   if ( FillConeJets()  ) {
170     HLTError("Error filling jets.");
171     return kFALSE;
172   }
173
174   return kTRUE;
175 }
176
177 // #################################################################################
178 Bool_t AliHLTJETConeFinder::ProcessHLTEvent() {
179   // see header file for class documentation
180
181   // -- Reset
182   Reset();
183
184   // -- Find Leading
185   if ( FindConeLeading()  ) {
186     HLTError("Error finding leading.");
187     return kFALSE;
188   }
189
190   // -- Find Jets 
191   if ( FindConeJets()  ) {
192     HLTError("Error finding jets.");
193     return kFALSE;
194   }
195
196   // -- Fill Jets and apply jet cuts
197   if ( FillConeJets()  ) {
198     HLTError("Error filling jets.");
199     return kFALSE;
200   }
201
202   return kTRUE;
203 }
204
205 /*
206  * ---------------------------------------------------------------------------------
207  *                             Process - private
208  * ---------------------------------------------------------------------------------
209  */
210
211 // #################################################################################
212 Int_t AliHLTJETConeFinder::FindConeLeading() {
213   // see header file for class documentation
214
215   // -- Pick up jet reader
216   AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
217
218   // -- Pick up jet canidates
219   TClonesArray* jetCandidates = reader->GetJetCandidates();
220
221   // -- Check for more than 1 jet candidate
222   if ( reader->GetNJetCandidates() > 1 ) {
223     
224     // -- Sort jet candidates with seed pt 
225     jetCandidates->Sort();
226     
227     // -- Use leading seed only
228     //    Keep index 0, remove the others
229     if ( (dynamic_cast<AliHLTJETConeHeader*> (fHeader))->GetUseLeading() ) {
230       
231       for ( Int_t iter = 1; iter < reader->GetNJetCandidates(); iter++ )
232         jetCandidates->RemoveAt(iter);
233       
234       reader->SetNJetCandidates(1);
235     }
236
237   } // if ( reader->GetNJetCandidates() > 1 ) {
238
239   // -- Resize the seed TClonesArray
240   jetCandidates->Compress();
241
242   return 0;
243 }
244
245 // #################################################################################
246 Int_t AliHLTJETConeFinder::FindConeJets() {
247   // see header file for class documentation
248
249   Int_t iResult = 0;
250
251   // -- Pick up jet reader
252   AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
253    
254   // -- Pick up jet canidates
255   TClonesArray* jetCandidates = reader->GetJetCandidates();
256
257   // -- Loop over jet candidates
258   for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
259     
260     AliHLTJETConeJetCandidate* jet = reinterpret_cast<AliHLTJETConeJetCandidate*> ((*jetCandidates)[iter]);
261     
262     // -- Set iterator for cells around seed
263     fGrid->SetCellIter( jet->GetSeedEtaIdx(), jet->GetSeedPhiIdx() ); 
264
265     Int_t cellIdx = 0;
266     
267     // -- Loop over cells around ssed
268     while ( (cellIdx = fGrid->NextCell() ) >= 0 && !iResult) {
269
270       AliHLTJETConeEtaPhiCell* cell = NULL;
271       if ( ! (cell = reinterpret_cast<AliHLTJETConeEtaPhiCell*>(fGrid->UncheckedAt(cellIdx))) )
272         continue;
273       
274       if ( ( iResult = jet->AddCell(cell) ) ) {
275         HLTError( "Error adding cell %d to jet candiate %d", cellIdx, iter);
276         continue;
277       }
278     } // while ( (cellIdx = fGrid->NextCell() ) >= 0 && !iResult) {
279     
280   } // for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
281   
282   return iResult;
283 }
284
285 // #################################################################################
286 Int_t AliHLTJETConeFinder::FillConeJets() {
287   // see header file for class documentation
288
289   Int_t iResult = 0;
290
291   // -- Pick up jet reader
292   AliHLTJETReader *reader = dynamic_cast<AliHLTJETReader*> (fReader);
293
294   // -- Pick up jet header
295   AliHLTJETConeHeader *header = dynamic_cast<AliHLTJETConeHeader*> (fHeader);
296   
297   // -- Get jet canidates
298   TClonesArray* jetCandidates = reader->GetJetCandidates();
299   
300   // -- Get jet cuts
301   AliHLTJETJetCuts* jetCuts = header->GetJetCuts();
302
303   // -- Loop over jet candidates
304   for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
305     
306     AliHLTJETConeJetCandidate* jet = reinterpret_cast<AliHLTJETConeJetCandidate*> ((*jetCandidates)[iter]);
307   
308     // -- Apply jet cuts 
309     if ( ! jetCuts->IsSelected(jet) )
310       continue;
311
312     // -- Add jet as AliAODJet
313     fJets->AddJet(jet->GetEta(), jet->GetPhi(), jet->GetPt(), jet->GetEt());
314     
315   } // for ( Int_t iter = 0; iter < reader->GetNJetCandidates(); iter++ ) {
316   
317   // xxx  HLTDebug( "Added %d jets", fJets->GetNAODJets());
318   HLTInfo( "Added %d jets", fJets->GetNAODJets());
319
320   return iResult;
321 }