Exec() removed.
[u/mrichter/AliRoot.git] / HLT / CALO / AliHLTCaloClusterizer.cxx
CommitLineData
ef44ec64 1// $Id$\r
2\r
3/**************************************************************************\r
4 * This file is property of and copyright by the ALICE HLT Project * \r
5 * All rights reserved. *\r
6 * *\r
7 * Primary Authors: Oystein Djuvsland *\r
8 * *\r
9 * Permission to use, copy, modify and distribute this software and its *\r
10 * documentation strictly for non-commercial purposes is hereby granted *\r
11 * without fee, provided that the above copyright notice appears in all *\r
12 * copies and that both the copyright notice and this permission notice *\r
13 * appear in the supporting documentation. The authors make no claims *\r
14 * about the suitability of this software for any purpose. It is * \r
15 * provided "as is" without express or implied warranty. *\r
16 **************************************************************************/\r
17\r
18/** \r
19 * @file AliHLTCaloClusterizer.cxx\r
20 * @author Oystein Djuvsland\r
21 * @date \r
22 * @brief Clusterizer for PHOS HLT \r
23 */\r
24\r
25// see header file for class documentation\r
26// or\r
27// refer to README to build package\r
28// or\r
29// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt\r
30\r
31#include "AliHLTCaloClusterizer.h"\r
ef44ec64 32#include "AliHLTLogging.h"\r
33#include "TMath.h"\r
ef44ec64 34#include "AliHLTCaloRecPointDataStruct.h"\r
35#include "AliHLTCaloDigitDataStruct.h"\r
36#include "AliHLTCaloDigitContainerDataStruct.h"\r
4f4b7ba4 37#include "AliHLTCaloConstantsHandler.h"\r
ef44ec64 38\r
39ClassImp(AliHLTCaloClusterizer);\r
40\r
41AliHLTCaloClusterizer::AliHLTCaloClusterizer(TString det):\r
4f4b7ba4 42 AliHLTCaloConstantsHandler(det),\r
7c80a370 43 fRecPointArray(0),\r
ef44ec64 44 fRecPointDataPtr(0),\r
7c80a370 45 fFirstRecPointPtr(0),\r
46 fArraySize(0),\r
47 fAvailableSize(0),\r
48 fUsedSize(0),\r
49 fNRecPoints(0),\r
ad44d760 50 fDigitIndexPtr(0),\r
ef44ec64 51 fEmcClusteringThreshold(0),\r
52 fEmcMinEnergyThreshold(0),\r
53 fEmcTimeGate(0),\r
54 fDigitsInCluster(0),\r
f92dcf21 55 fDigitsPointerArray(0),\r
ef44ec64 56 fDigitContainerPtr(0),\r
ad44d760 57 fMaxDigitIndexDiff(0),\r
58 fNDigits(0)\r
ef44ec64 59{\r
60 //See header file for documentation\r
2a24cbbe 61 //fEmcClusteringThreshold = 0.2;\r
62 //fEmcMinEnergyThreshold = 0.03;\r
63\r
64 fEmcClusteringThreshold = 0.1;\r
65 fEmcMinEnergyThreshold = 0.01;\r
ef44ec64 66 fEmcTimeGate = 1.e-6 ;\r
67 \r
68 fMaxDigitIndexDiff = 2*fCaloConstants->GetNZROWSMOD();\r
7c80a370 69 \r
70 \r
71 fArraySize = 10;\r
72 fRecPointArray = new AliHLTCaloRecPointDataStruct*[fArraySize];\r
73 \r
74 fAvailableSize = sizeof(AliHLTCaloRecPointDataStruct) * 20;\r
75 fRecPointDataPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(new UChar_t[fAvailableSize]);\r
76 fFirstRecPointPtr = fRecPointDataPtr; \r
c375e15d 77\r
c375e15d 78}//end\r
79\r
ef44ec64 80AliHLTCaloClusterizer::~AliHLTCaloClusterizer() \r
81{\r
82 //See header file for documentation\r
83}\r
84\r
85void \r
86AliHLTCaloClusterizer::SetRecPointDataPtr(AliHLTCaloRecPointDataStruct* recPointDataPtr)\r
87{\r
88 // See header file for documentation\r
89 fRecPointDataPtr = recPointDataPtr;\r
90}\r
91\r
ef44ec64 92Int_t \r
7c80a370 93AliHLTCaloClusterizer::ClusterizeEvent(Int_t nDigits)\r
ef44ec64 94{\r
95 //see header file for documentation\r
96 Int_t nRecPoints = 0;\r
7c80a370 97 fNRecPoints = 0;\r
98 fUsedSize = 0;\r
ad44d760 99 fNDigits = nDigits;\r
7c80a370 100 fRecPointDataPtr = fFirstRecPointPtr;\r
ef44ec64 101 //Clusterization starts\r
f92dcf21 102 for(Int_t i = 0; i < nDigits; i++)\r
ef44ec64 103 { \r
104 fDigitsInCluster = 0;\r
98baf84d 105\r
ad44d760 106 if(fDigitsPointerArray[i]->fEnergy < fEmcClusteringThreshold)\r
ef44ec64 107 {\r
108 continue;\r
109 }\r
7c80a370 110 CheckArray();\r
111 CheckBuffer();\r
98baf84d 112\r
ef44ec64 113 // First digit is placed at the fDigits member variable in the recpoint\r
ad44d760 114 fDigitIndexPtr = &(fRecPointDataPtr->fDigits);\r
b4479a87 115 fUsedSize += sizeof(AliHLTCaloRecPointDataStruct);\r
116 \r
ef44ec64 117 fRecPointDataPtr->fAmp = 0;\r
ad44d760 118 fRecPointDataPtr->fModule = fDigitsPointerArray[i]->fModule;\r
ef44ec64 119\r
ad44d760 120 // Assigning the digit to this rec point\r
121 fRecPointDataPtr->fDigits = i;\r
7c80a370 122 fUsedSize += sizeof(AliHLTCaloRecPointDataStruct);\r
123 \r
ef44ec64 124 // Incrementing the pointer to be ready for new entry\r
ad44d760 125 fDigitIndexPtr++;\r
ef44ec64 126\r
ad44d760 127 fRecPointDataPtr->fAmp += fDigitsPointerArray[i]->fEnergy;\r
128 fDigitsPointerArray[i]->fEnergy = 0;\r
ef44ec64 129 fDigitsInCluster++;\r
130 nRecPoints++;\r
131\r
132 // Scanning for the neighbours\r
9bd6f29b 133 if(ScanForNeighbourDigits(i, fRecPointDataPtr) != 0)\r
134 {\r
135 return -1;\r
136 }\r
ef44ec64 137\r
7c80a370 138 //fUsedSize += sizeof(AliHLTCaloRecPointDataStruct) + (fDigitsInCluster-1)*sizeof(AliHLTCaloDigitDataStruct); \r
139 \r
ef44ec64 140 fRecPointDataPtr->fMultiplicity = fDigitsInCluster; \r
7c80a370 141 fRecPointArray[fNRecPoints] = fRecPointDataPtr; \r
142 \r
ad44d760 143 fRecPointDataPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(fDigitIndexPtr);\r
b4479a87 144\r
145 fNRecPoints++;\r
7c80a370 146 \r
ef44ec64 147 }//end of clusterization\r
b4479a87 148\r
ef44ec64 149 return nRecPoints;\r
150}\r
151\r
9bd6f29b 152Int_t\r
ef44ec64 153AliHLTCaloClusterizer::ScanForNeighbourDigits(Int_t index, AliHLTCaloRecPointDataStruct* recPoint)\r
154{\r
155 //see header file for documentation\r
ad44d760 156 Int_t max = TMath::Min(fNDigits, (Int_t)fMaxDigitIndexDiff+index);\r
ef44ec64 157 Int_t min = TMath::Max(0, (Int_t)(index - (Int_t)fMaxDigitIndexDiff));\r
158\r
ad44d760 159 max = fNDigits;\r
ef44ec64 160 min = 0;\r
161 for(Int_t j = min; j < max; j++)\r
162 {\r
ad44d760 163 if(fDigitsPointerArray[j]->fEnergy > fEmcMinEnergyThreshold)\r
ef44ec64 164 {\r
165 if(j != index)\r
166 {\r
ad44d760 167 if(AreNeighbours(fDigitsPointerArray[index],\r
168 fDigitsPointerArray[j]))\r
ef44ec64 169 {\r
7c80a370 170// if((fAvailableSize - fUsedSize) < sizeof(Int_t))\r
171// {\r
172// UChar_t *tmp = new UChar_t[fAvailableSize*2];\r
173// memcpy(tmp, fRecPointDataPtr, fAvailableSize);\r
174// for(Int_t n = 0; n < fNRecPoints; n++)\r
175// {\r
176// fRecPointArray[n] = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(reinterpret_cast<UChar_t*>(fRecPointArray[n]) - reinterpret_cast<UChar_t*>(fFirstRecPointPtr) + reinterpret_cast<UChar_t*>(tmp));\r
177// }\r
178// fRecPointDataPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(tmp);\r
179// fFirstRecPointPtr = fRecPointDataPtr;\r
180// fUsedSize = 0;\r
181// } \r
182 CheckBuffer();\r
9bd6f29b 183 // Assigning index to digit\r
ad44d760 184 *fDigitIndexPtr = j;\r
7c80a370 185 fUsedSize += sizeof(Int_t);\r
186 \r
ef44ec64 187 // Incrementing digit pointer to be ready for new entry\r
ad44d760 188 fDigitIndexPtr++;\r
ef44ec64 189\r
ad44d760 190 recPoint->fAmp += fDigitsPointerArray[j]->fEnergy;\r
191 fDigitsPointerArray[j]->fEnergy = 0; \r
ef44ec64 192 fDigitsInCluster++;\r
193 ScanForNeighbourDigits(j, recPoint);\r
194 }\r
195 }\r
196 }\r
197 }\r
9bd6f29b 198 return 0;\r
ef44ec64 199}\r
200\r
201Int_t \r
202AliHLTCaloClusterizer::AreNeighbours(AliHLTCaloDigitDataStruct* digit1, \r
203 AliHLTCaloDigitDataStruct* digit2)\r
204{\r
205 //see header file for documentation\r
206 if ( (digit1->fModule == digit2->fModule) /*&& (coord1[1]==coord2[1])*/ ) // inside the same PHOS module\r
207 { \r
7c80a370 208 Int_t rowdiff = TMath::Abs( digit1->fZ - digit2->fZ ); \r
209 Int_t coldiff = TMath::Abs( digit1->fX - digit2->fX ); \r
210 if (( coldiff <= 1 && rowdiff == 0 ) || ( coldiff == 0 && rowdiff <= 1 ))\r
211 {\r
212// cout << "Are neighbours: digit (E = " << digit1->fEnergy << ") with x = " << digit1->fX << " and z = " << digit1->fZ << \r
213// " is neighbour with digit (E = " << digit2->fEnergy << ") with x = " << digit2->fX << " and z = " << digit2->fZ << endl;\r
214\r
215 if(TMath::Abs(digit1->fTime - digit2->fTime ) < fEmcTimeGate)\r
216 {\r
217 return 1; \r
218 }\r
219 }\r
220\r
221 /* Float_t rowdiff = TMath::Abs( digit1->fZ - digit2->fZ ); \r
ef44ec64 222 Float_t coldiff = TMath::Abs( digit1->fX - digit2->fX ); \r
223 if (( coldiff <= 2.4 && rowdiff < 0.4 ) || ( coldiff < 0.4 && rowdiff <= 2.4 ))\r
224 {\r
225 // cout << "Are neighbours: digit (E = " << digit1->fEnergy << ") with x = " << digit1->fX << " and z = " << digit1->fZ << \r
226 // " is neighbour with digit (E = " << digit2->fEnergy << ") with x = " << digit2->fX << " and z = " << digit2->fZ << endl;\r
227\r
228 if(TMath::Abs(digit1->fTime - digit2->fTime ) < fEmcTimeGate)\r
229 {\r
230 return 1; \r
231 }\r
232 }\r
7c80a370 233 */\r
ef44ec64 234 else\r
235 {\r
7c80a370 236// cout << "Not neighbours: digit (E = " << digit1->fEnergy << ") with x = " << digit1->fX << " and z = " << digit1->fZ << \r
237// " is not neighbour with digit (E = " << digit2->fEnergy << ") with x = " << digit2->fX << " and z = " << digit2->fZ << endl;\r
ef44ec64 238 }\r
239 }\r
240 return 0;\r
241}\r
7c80a370 242\r
243\r
244\r
245Int_t AliHLTCaloClusterizer::CheckArray()\r
246{\r
7c80a370 247 if(fArraySize == fNRecPoints)\r
248 {\r
7c80a370 249 fArraySize *= 2;\r
250 AliHLTCaloRecPointDataStruct **tmp = new AliHLTCaloRecPointDataStruct*[fArraySize];\r
251 memcpy(tmp, fRecPointArray, fArraySize/2 * sizeof(AliHLTCaloRecPointDataStruct*));\r
252 delete fRecPointArray;\r
253 fRecPointArray = tmp;\r
254 }\r
255 return 0;\r
256}\r
257\r
258Int_t AliHLTCaloClusterizer::CheckBuffer()\r
259{\r
260 // See header file for class documentation \r
98baf84d 261 if((fAvailableSize - fUsedSize) < sizeof(AliHLTCaloRecPointDataStruct))\r
7c80a370 262 {\r
7c80a370 263 Int_t recPointOffset = reinterpret_cast<UChar_t*>(fRecPointDataPtr) - reinterpret_cast<UChar_t*>(fFirstRecPointPtr);\r
e22c4ac9 264 UChar_t *tmp = new UChar_t[fAvailableSize*2];\r
265 memcpy(tmp, fFirstRecPointPtr, fAvailableSize);\r
7c80a370 266 fAvailableSize *= 2;\r
7c80a370 267 for(Int_t n = 0; n < fNRecPoints; n++)\r
268 {\r
269 fRecPointArray[n] = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(reinterpret_cast<UChar_t*>(fRecPointArray[n]) - reinterpret_cast<UChar_t*>(fFirstRecPointPtr) + reinterpret_cast<UChar_t*>(tmp));\r
270 }\r
e22c4ac9 271 delete fFirstRecPointPtr;\r
7c80a370 272 fFirstRecPointPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(tmp);\r
273 fRecPointDataPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(tmp + recPointOffset);\r
274 fUsedSize = 0;\r
275 }\r
276 return 0;\r
277}\r
278\r
279Int_t AliHLTCaloClusterizer::CheckDigits(AliHLTCaloRecPointDataStruct** recArray, AliHLTCaloDigitDataStruct** digitArray, Int_t nRP)\r
280{\r
281 AliHLTCaloRecPointDataStruct **recpoints = recArray;\r
282 AliHLTCaloDigitDataStruct **digits = digitArray;\r
283 Int_t nRecPoints = nRP;\r
284 \r
285 if(recArray == 0)\r
286 {\r
287 recpoints = fRecPointArray;\r
288 }\r
289 if(digitArray == 0)\r
290 {\r
291 digits = fDigitsPointerArray;\r
292 }\r
293 if(nRP == 0)\r
294 {\r
295 nRecPoints = fNRecPoints;\r
296 }\r
7c80a370 297 for(Int_t i = 0; i < nRecPoints; i++)\r
298 {\r
299 \r
300 AliHLTCaloRecPointDataStruct *recPoint = recpoints[i];\r
301\r
302 //AliHLTCaloRecPointDataStruct *recPoint = fRecPointArray[0];\r
303 Int_t multiplicity = recPoint->fMultiplicity;\r
304 Int_t *digitIndexPtr = &(recPoint->fDigits);\r
7c80a370 305 for(Int_t j = 0; j < multiplicity; j++)\r
306 {\r
307 //AliHLTCaloRecPointDataStruct *recPoint = fRecPointArray[j];\r
98baf84d 308// AliHLTCaloDigitDataStruct *digit = digits[*digitIndexPtr];\r
7c80a370 309 digitIndexPtr++;\r
310 //recPoint = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(digitIndexPtr);\r
311 }\r
312 }\r
313 \r
98baf84d 314 return 0;\r
7c80a370 315}\r
316\r
317Int_t AliHLTCaloClusterizer::CheckDigits(AliHLTCaloRecPointDataStruct** recArray, AliHLTCaloDigitDataStruct* digitArray, Int_t nRP)\r
318{\r
319 AliHLTCaloRecPointDataStruct **recpoints = recArray;\r
320 AliHLTCaloDigitDataStruct *digits = digitArray;\r
321 Int_t nRecPoints = nRP;\r
322 \r
323 if(recArray == 0)\r
324 {\r
325 recpoints = fRecPointArray;\r
326 }\r
327 if(nRP == 0)\r
328 {\r
329 nRecPoints = fNRecPoints;\r
330 }\r
7c80a370 331 for(Int_t i = 0; i < nRecPoints; i++)\r
332 {\r
333 \r
334 AliHLTCaloRecPointDataStruct *recPoint = recpoints[i];\r
335\r
336 //AliHLTCaloRecPointDataStruct *recPoint = fRecPointArray[0];\r
337 Int_t multiplicity = recPoint->fMultiplicity;\r
338 Int_t *digitIndexPtr = &(recPoint->fDigits);\r
7c80a370 339 for(Int_t j = 0; j < multiplicity; j++)\r
340 {\r
341 //AliHLTCaloRecPointDataStruct *recPoint = fRecPointArray[j];\r
342 AliHLTCaloDigitDataStruct digit = digits[*digitIndexPtr];\r
7c80a370 343 digitIndexPtr++;\r
344 //recPoint = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(digitIndexPtr);\r
345 }\r
346 }\r
98baf84d 347 return 0;\r
7c80a370 348 \r
2a24cbbe 349}\r