]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/JET/cone/AliHLTJETConeGrid.cxx
Add new classes for the jet cone finder
[u/mrichter/AliRoot.git] / HLT / JET / cone / AliHLTJETConeGrid.cxx
CommitLineData
7c3c85cd 1//-*- Mode: C++ -*-
2// $Id: AliHLTJETConeGrid.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 AliHLTJETConeGrid.cxx
20 @author Jochen Thaeder
21 @date
22 @brief Eta-Phi grid of the 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 "AliHLTJETConeGrid.h"
36#include "AliHLTJETConeEtaPhiCell.h"
37
38/** ROOT macro for the implementation of ROOT specific class methods */
39ClassImp(AliHLTJETConeGrid)
40
41/*
42 * ---------------------------------------------------------------------------------
43 * Constructor / Destructor
44 * ---------------------------------------------------------------------------------
45 */
46
47// #################################################################################
48AliHLTJETConeGrid::AliHLTJETConeGrid()
49 :
50 fGrid(NULL),
51 fEtaMin(-0.9),
52 fEtaMax(0.9),
53 fPhiMin(0.0),
54 fPhiMax(6.3),
55 fEtaRange(1.8),
56 fPhiRange(6.3),
57 fEtaBinning(0.05),
58 fPhiBinning(0.05),
59 fEtaNGridBins(-1),
60 fPhiNGridBins(-1),
61 fNBins(-1),
62 fEtaNRBins(-1),
63 fPhiNRBins(-1),
64 fEtaIdxCurrent(0),
65 fEtaIdxMin(0),
66 fEtaIdxMax(0),
67 fPhiIdxCurrent(0),
68 fPhiIdxMin(0),
69 fPhiIdxMax(0),
70 fConeRadius(0.0) {
71 // see header file for class documentation
72 // or
73 // refer to README to build package
74 // or
75 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
76
77}
78
79// #################################################################################
80AliHLTJETConeGrid::~AliHLTJETConeGrid() {
81 // see header file for class documentation
82
83 if ( fGrid ) {
84 fGrid->Clear("C");
85 delete fGrid;
86 }
87 fGrid = NULL;
88
89}
90
91/*
92 * ---------------------------------------------------------------------------------
93 * Setup / Reset
94 * ---------------------------------------------------------------------------------
95 */
96
97// #################################################################################
98Int_t AliHLTJETConeGrid::Initialize() {
99 // see header file for class documentation
100
101 Int_t iResult = 0;
102
103 // -- Set total N bins in eta and phi
104 fEtaNGridBins = TMath::CeilNint( fEtaRange / fEtaBinning );
105 fPhiNGridBins = TMath::CeilNint( fPhiRange / fPhiBinning );
106
107 // -- Set total number of bins
108 fNBins = fEtaNGridBins * fPhiNGridBins;
109
110 // -- Set cells around R in eta and phi
111 fEtaNRBins = TMath::CeilNint( fConeRadius / fEtaBinning );
112 fPhiNRBins = TMath::CeilNint( fConeRadius / fPhiBinning );
113
114 HLTInfo(" -= Grid =- ");
115 HLTInfo(" NGridBins (%d,%d)", fEtaNGridBins, fPhiNGridBins);
116 HLTInfo(" NRBins (%d,%d)", fEtaNRBins , fPhiNRBins);
117 HLTInfo(" NBins %d", fNBins );
118
119 fGrid = new TClonesArray("AliHLTJETConeEtaPhiCell", fNBins );
120
121 if ( ! fGrid ) {
122 HLTError( "Error: Setup search grid with size %d .", fNBins );
123 iResult = 1;
124 }
125
126 return iResult;
127}
128
129// #################################################################################
130void AliHLTJETConeGrid::Reset() {
131 // see header file for class documentation
132
133 if ( fGrid )
134 fGrid->Clear("C");
135
136 return;
137}
138
139/*
140 * ---------------------------------------------------------------------------------
141 * Process
142 * ---------------------------------------------------------------------------------
143 */
144
145//##################################################################################
146Int_t AliHLTJETConeGrid::FillTrack( TParticle* particle, const Float_t* aEtaPhi, Int_t* aGridIdx ) {
147 // see header file for class documentation
148
149 Int_t iResult = 0;
150
151 // ---------------------------
152 // -- Get Cell Indices
153 // ---------------------------
154 iResult = GetCellIndex( aEtaPhi, aGridIdx );
155 if ( iResult < 0 ) {
156 HLTError("Error getting cell index");
157 return iResult;
158 }
159
160 // ---------------------------
161 // -- Fill track in primary region
162 // ---------------------------
163
164 // -- Create new cell and add track to cell
165 if (! fGrid->UncheckedAt( aGridIdx[kIdxPrimary] ) ) {
166 new( (*fGrid ) [aGridIdx[kIdxPrimary]] ) AliHLTJETConeEtaPhiCell( aGridIdx[kIdxEtaPrimary],
167 aGridIdx[kIdxPhiPrimary],
168 particle );
169 }
170 // -- Add track to existing cell
171 else {
172 (reinterpret_cast<AliHLTJETConeEtaPhiCell*> ((*fGrid)[aGridIdx[kIdxPrimary]]))->AddTrack(particle);
173 }
174
175 // ---------------------------
176 // -- Fill track in outter region
177 // ---------------------------
178
179 // -- if it has to be filled
180 if ( iResult == 1 ) {
181
182 // -- Create new cell and add track to cell
183 if (! fGrid->UncheckedAt( aGridIdx[kIdxOutter] ) ) {
184 new( (*fGrid) [aGridIdx[kIdxOutter]] ) AliHLTJETConeEtaPhiCell( aGridIdx[kIdxEtaPrimary],
185 aGridIdx[kIdxPhiOutter],
186 particle );
187 }
188 // -- Add track to existing cell
189 else {
190 (reinterpret_cast<AliHLTJETConeEtaPhiCell*> ((*fGrid)[aGridIdx[kIdxOutter]]))->AddTrack(particle);
191 }
192 }
193
194 return 0;
195}
196
197//##################################################################################
198Int_t AliHLTJETConeGrid::FillTrack( AliESDtrack *esdTrack, const Float_t* aEtaPhi, Int_t* aGridIdx ) {
199 // see header file for class documentation
200
201 Int_t iResult = 0;
202
203 // ---------------------------
204 // -- Get Cell Indices
205 // ---------------------------
206
207 iResult = GetCellIndex( aEtaPhi, aGridIdx );
208 if ( iResult < 0 ) {
209 return iResult;
210 }
211
212 // ---------------------------
213 // -- Fill track in primary region
214 // ---------------------------
215
216 // -- Create new cell and add track to cell
217 if (! fGrid->UncheckedAt( aGridIdx[kIdxPrimary] ) ) {
218 new( (*fGrid ) [aGridIdx[kIdxPrimary]] ) AliHLTJETConeEtaPhiCell( aGridIdx[kIdxEtaPrimary],
219 aGridIdx[kIdxPhiPrimary],
220 esdTrack );
221 }
222 // -- Add track to existing cell
223 else {
224 (reinterpret_cast<AliHLTJETConeEtaPhiCell*> ((*fGrid)[aGridIdx[kIdxPrimary]]))->AddTrack(esdTrack);
225 }
226
227 // ---------------------------
228 // -- Fill track in outter region
229 // ---------------------------
230
231 // -- if it has to be filled
232 if ( iResult == 1 ) {
233
234 // -- Create new cell and add track to cell
235 if (! fGrid->UncheckedAt( aGridIdx[kIdxOutter] ) ) {
236 new( (*fGrid) [aGridIdx[kIdxOutter]] ) AliHLTJETConeEtaPhiCell( aGridIdx[kIdxEtaPrimary],
237 aGridIdx[kIdxPhiOutter],
238 esdTrack );
239 }
240 // -- Add track to existing cell
241 else {
242 (reinterpret_cast<AliHLTJETConeEtaPhiCell*> ((*fGrid)[aGridIdx[kIdxOutter]]))->AddTrack(esdTrack);
243 }
244 }
245
246 return 0;
247}
248
249/*
250 * ---------------------------------------------------------------------------------
251 * Helper - public
252 * ---------------------------------------------------------------------------------
253 */
254
255// #################################################################################
256Int_t AliHLTJETConeGrid::NextCell() {
257 // see header file for class documentation
258
259 Int_t cellIdx = 0;
260
261 ++fPhiIdxCurrent;
262
263 if ( fPhiIdxCurrent > fPhiIdxMax ) {
264 fPhiIdxCurrent = fPhiIdxMin;
265
266 ++fEtaIdxCurrent;
267
268 if ( fEtaIdxCurrent > fEtaIdxMax )
269 cellIdx = -1;
270 }
271
272 if ( cellIdx != -1 )
273 cellIdx = fEtaIdxCurrent + ( fPhiIdxCurrent * fEtaNGridBins );
274
275 if ( cellIdx > fNBins ) {
276 HLTError("Idx out of bound (%d,%d) -> %d", fEtaIdxCurrent, fPhiIdxCurrent, cellIdx );
277 HLTError("MAX %d,%d - %d", fEtaNGridBins, fPhiNGridBins, fNBins );
278
279 cellIdx = -1;
280 }
281
282 return cellIdx;
283}
284
285// #################################################################################
286void AliHLTJETConeGrid::SetCellIter( const Int_t etaIdx, const Int_t phiIdx ) {
287 // see header file for class documentation
288
289 fEtaIdxMax = etaIdx + fEtaNRBins;
290 fEtaIdxMin = etaIdx - fEtaNRBins;
291 fEtaIdxCurrent = fEtaIdxMin;
292
293 fPhiIdxMax = phiIdx + fPhiNRBins;
294 fPhiIdxMin = phiIdx - fPhiNRBins;
295 fPhiIdxCurrent = fPhiIdxMin - 1;
296
297 return;
298}
299
300/*
301 * ---------------------------------------------------------------------------------
302 * Helper - private
303 * ---------------------------------------------------------------------------------
304 */
305
306//##################################################################################
307Int_t AliHLTJETConeGrid::GetCellIndex( const Float_t* aEtaPhi, Int_t* aGridIdx ) {
308 // see header file for class documentation
309
310 Int_t iResult = 0;
311
312 // -- Prime is relative to (0,0) in grid which is (-fEtaMax,-fConeRadius)
313 Float_t etaPrime = fEtaMax + aEtaPhi[kIdxEta];
314 Float_t phiPrime = aEtaPhi[kIdxPhi] + fConeRadius;
315
316 HLTDebug("eta : %f - phi :%f", aEtaPhi[kIdxEta], aEtaPhi[kIdxPhi] );
317 HLTDebug("eta\' : %f - phi\':%f", etaPrime, phiPrime );
318
319 // -- Index in 2D (idxEta,idxPhi)
320 aGridIdx[kIdxEtaPrimary] = TMath::FloorNint( etaPrime / fEtaBinning );
321 aGridIdx[kIdxPhiPrimary] = TMath::FloorNint( phiPrime / fPhiBinning );
322
323 // -- Index in 1D
324 aGridIdx[kIdxPrimary] = aGridIdx[kIdxEtaPrimary] + ( aGridIdx[kIdxPhiPrimary] * fEtaNGridBins );
325
326 // -- Boundery Check 2D
327 if ( (aGridIdx[kIdxEtaPrimary] < 0) ||
328 (aGridIdx[kIdxPhiPrimary] < 0) ||
329 (aGridIdx[kIdxEtaPrimary] >= fEtaNGridBins) ||
330 (aGridIdx[kIdxPhiPrimary] >= fPhiNGridBins) ) {
331 HLTError ( "Index out of range: idxEta %d - max %d, idxPhi %d - max %d",
332 aGridIdx[kIdxEtaPrimary], fEtaNGridBins,
333 aGridIdx[kIdxPhiPrimary], fPhiNGridBins);
334 iResult = -1;
335 }
336
337 // -- Boundery Check 1D
338 if ( (aGridIdx[kIdxPrimary] < 0) ||
339 (aGridIdx[kIdxPrimary] >= fNBins) ) {
340 HLTError( "Index out of range: 1D idx %d - max %d",
341 aGridIdx[kIdxPrimary], fNBins );
342 iResult = -2;
343 }
344
345 HLTDebug( "idxEta %d - max %d, idxPhi %d - max %d",
346 aGridIdx[kIdxEtaPrimary], fEtaNGridBins,
347 aGridIdx[kIdxPhiPrimary], fPhiNGridBins);
348 HLTDebug( "1D idx %d - max %d", aGridIdx[kIdxPrimary], fNBins );
349
350 if ( iResult )
351 return iResult;
352
353 // -- check if to map from border region to outter region
354 Float_t phiOutterPrime = 0.0;
355
356 // -- upper border
357 if ( aEtaPhi[kIdxPhi] > ( fPhiMax - fConeRadius ) ) {
358 phiOutterPrime = phiPrime - fPhiMax;
359 iResult = 1;
360
361 HLTDebug("eta : %f - phiOutter :%f .", aEtaPhi[kIdxEta], aEtaPhi[kIdxPhi] - fPhiMax );
362 HLTDebug("eta\' : %f - phiOutter\':%f .", etaPrime, phiOutterPrime );
363 }
364 // -- lower border
365 else if ( aEtaPhi[kIdxPhi] < fConeRadius ) {
366 phiOutterPrime = phiPrime + fPhiMax;
367 iResult = 1;
368
369 HLTDebug("eta : %f - phiOutter :%f .", aEtaPhi[kIdxEta], aEtaPhi[kIdxPhi] + fPhiMax );
370 HLTDebug("eta\' : %f - phiOutter\':%f .", etaPrime, phiOutterPrime );
371 }
372
373 // -- if outter phi present
374 if ( iResult == 1 ) {
375
376 // -- Index in 2D (idxEta,idxPhiOutter)
377 aGridIdx[kIdxPhiOutter] = TMath::FloorNint( phiOutterPrime / fPhiBinning );
378
379 // -- Index in 1D
380 aGridIdx[kIdxOutter] = aGridIdx[kIdxEtaPrimary] + ( aGridIdx[kIdxPhiOutter] * fEtaNGridBins );
381
382 // -- Boundery Check 2D
383 if ( aGridIdx[kIdxPhiOutter] < 0 || aGridIdx[kIdxPhiOutter] >= fPhiNGridBins ) {
384 HLTError( "Index out of range ( Outter Phi ): idxPhiOutter %d - max %d",
385 aGridIdx[kIdxPhiOutter], fPhiNGridBins);
386 iResult = -3;
387 }
388
389 // -- Boundery Check 1D
390 if ( aGridIdx[kIdxOutter] >= fNBins ) {
391 HLTError( "Index out of range ( Outter Phi ): 1D idx %d - max %d",
392 aGridIdx[kIdxOutter], fNBins );
393 iResult = -4;
394 }
395
396 HLTDebug( "idxEta %d - max %d, idxPhiOutter %d - max %d",
397 aGridIdx[kIdxEtaPrimary], fEtaNGridBins, aGridIdx[kIdxPhiOutter], fPhiNGridBins);
398 HLTDebug( "1D idx %d - max %d", aGridIdx[kIdxOutter], fNBins );
399 }
400
401 return iResult;
402}