- bug fixes in the CALO clusterizer - digits pushed from the clusterizer
[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
ef44ec64 43 fRecPointDataPtr(0),\r
ad44d760 44 fDigitIndexPtr(0),\r
ef44ec64 45 fEmcClusteringThreshold(0),\r
46 fEmcMinEnergyThreshold(0),\r
47 fEmcTimeGate(0),\r
48 fDigitsInCluster(0),\r
49 fDigitContainerPtr(0),\r
ad44d760 50 fMaxDigitIndexDiff(0),\r
51 fNDigits(0)\r
ef44ec64 52{\r
53 //See header file for documentation\r
54 fEmcClusteringThreshold = 0.2;\r
55 fEmcMinEnergyThreshold = 0.03;\r
56 fEmcTimeGate = 1.e-6 ;\r
57 \r
58 fMaxDigitIndexDiff = 2*fCaloConstants->GetNZROWSMOD();\r
c375e15d 59\r
c375e15d 60}//end\r
61\r
4f4b7ba4 62\r
63//BALLE how do you set the right detector?\r
ad44d760 64// AliHLTCaloClusterizer::AliHLTCaloClusterizer(const AliHLTCaloClusterizer &) :\r
65// AliHLTCaloConstantsHandler("BALLE"),\r
66// fRecPointDataPtr(0),\r
67// fDigitDataPtr(0),\r
68// fEmcClusteringThreshold(0),\r
69// fEmcMinEnergyThreshold(0),\r
70// fEmcTimeGate(0),\r
71// fDigitsInCluster(0),\r
72// fDigitContainerPtr(0),\r
73// fMaxDigitIndexDiff(0)\r
74// {\r
75// // dummy copy constructor\r
76// }//end\r
ef44ec64 77\r
78\r
79AliHLTCaloClusterizer::~AliHLTCaloClusterizer() \r
80{\r
81 //See header file for documentation\r
82}\r
83\r
84void \r
85AliHLTCaloClusterizer::SetRecPointDataPtr(AliHLTCaloRecPointDataStruct* recPointDataPtr)\r
86{\r
87 // See header file for documentation\r
88 fRecPointDataPtr = recPointDataPtr;\r
89}\r
90\r
ef44ec64 91Int_t \r
ad44d760 92AliHLTCaloClusterizer::ClusterizeEvent(Int_t nDigits, UInt_t availableSize, UInt_t& totSize)\r
ef44ec64 93{\r
94 //see header file for documentation\r
95 Int_t nRecPoints = 0;\r
96\r
ad44d760 97 fNDigits = nDigits;\r
98\r
ef44ec64 99 UInt_t maxRecPointSize = sizeof(AliHLTCaloRecPointDataStruct) + (sizeof(AliHLTCaloDigitDataStruct) << 7); //Reasonable estimate... \r
100\r
101 //Clusterization starts\r
ad44d760 102 for(UInt_t i = 0; i < nDigits; i++)\r
ef44ec64 103 { \r
104 fDigitsInCluster = 0;\r
ad44d760 105 // printf("ENERGY: %f\n", fDigitsPointerArray[i]->fEnergy);\r
106 if(fDigitsPointerArray[i]->fEnergy < fEmcClusteringThreshold)\r
ef44ec64 107 {\r
108 continue;\r
109 }\r
110 if(availableSize < (totSize + maxRecPointSize)) \r
111 {\r
112 return -1; //Might get out of buffer, exiting\r
113 }\r
ad44d760 114 // printf("cluster candidate!\n");\r
ef44ec64 115 // First digit is placed at the fDigits member variable in the recpoint\r
ad44d760 116 fDigitIndexPtr = &(fRecPointDataPtr->fDigits);\r
ef44ec64 117\r
118 fRecPointDataPtr->fAmp = 0;\r
ad44d760 119 fRecPointDataPtr->fModule = fDigitsPointerArray[i]->fModule;\r
ef44ec64 120\r
ad44d760 121 // Assigning the digit to this rec point\r
122 fRecPointDataPtr->fDigits = i;\r
ef44ec64 123\r
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
133 ScanForNeighbourDigits(i, fRecPointDataPtr);\r
134\r
135 totSize += sizeof(AliHLTCaloRecPointDataStruct) + (fDigitsInCluster-1)*sizeof(AliHLTCaloDigitDataStruct); \r
136 fRecPointDataPtr->fMultiplicity = fDigitsInCluster; \r
ad44d760 137 // printf("Rec point energy: %f\n", fRecPointDataPtr->fAmp);\r
138 fRecPointDataPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(fDigitIndexPtr);\r
ef44ec64 139\r
ef44ec64 140 }//end of clusterization\r
141\r
142 return nRecPoints;\r
143}\r
144\r
145void\r
146AliHLTCaloClusterizer::ScanForNeighbourDigits(Int_t index, AliHLTCaloRecPointDataStruct* recPoint)\r
147{\r
148 //see header file for documentation\r
ad44d760 149 Int_t max = TMath::Min(fNDigits, (Int_t)fMaxDigitIndexDiff+index);\r
ef44ec64 150 Int_t min = TMath::Max(0, (Int_t)(index - (Int_t)fMaxDigitIndexDiff));\r
151\r
ad44d760 152 max = fNDigits;\r
ef44ec64 153 min = 0;\r
154 for(Int_t j = min; j < max; j++)\r
155 {\r
ad44d760 156 if(fDigitsPointerArray[j]->fEnergy > fEmcMinEnergyThreshold)\r
ef44ec64 157 {\r
158 if(j != index)\r
159 {\r
ad44d760 160 if(AreNeighbours(fDigitsPointerArray[index],\r
161 fDigitsPointerArray[j]))\r
ef44ec64 162 {\r
163 // Assigning value to digit ptr\r
ad44d760 164 *fDigitIndexPtr = j;\r
ef44ec64 165 // Incrementing digit pointer to be ready for new entry\r
ad44d760 166 fDigitIndexPtr++;\r
ef44ec64 167\r
ad44d760 168 recPoint->fAmp += fDigitsPointerArray[j]->fEnergy;\r
169 fDigitsPointerArray[j]->fEnergy = 0; \r
ef44ec64 170 fDigitsInCluster++;\r
171 ScanForNeighbourDigits(j, recPoint);\r
172 }\r
173 }\r
174 }\r
175 }\r
176 return;\r
177}\r
178\r
179Int_t \r
180AliHLTCaloClusterizer::AreNeighbours(AliHLTCaloDigitDataStruct* digit1, \r
181 AliHLTCaloDigitDataStruct* digit2)\r
182{\r
183 //see header file for documentation\r
184 if ( (digit1->fModule == digit2->fModule) /*&& (coord1[1]==coord2[1])*/ ) // inside the same PHOS module\r
185 { \r
186// Int_t rowdiff = TMath::Abs( digit1->fZ - digit2->fZ ); \r
187// Int_t coldiff = TMath::Abs( digit1->fX - digit2->fX ); \r
188// if (( coldiff <= 1 && rowdiff == 0 ) || ( coldiff == 0 && rowdiff <= 1 ))\r
189// {\r
190// cout << "Are neighbours: digit (E = " << digit1->fEnergy << ") with x = " << digit1->fX << " and z = " << digit1->fZ << \r
191// " is neighbour with digit (E = " << digit2->fEnergy << ") with x = " << digit2->fX << " and z = " << digit2->fZ << endl;\r
192\r
193// if(TMath::Abs(digit1->fTime - digit2->fTime ) < fEmcTimeGate)\r
194// {\r
195// return 1; \r
196// }\r
197// }\r
198\r
199 Float_t rowdiff = TMath::Abs( digit1->fZ - digit2->fZ ); \r
200 Float_t coldiff = TMath::Abs( digit1->fX - digit2->fX ); \r
201 if (( coldiff <= 2.4 && rowdiff < 0.4 ) || ( coldiff < 0.4 && rowdiff <= 2.4 ))\r
202 {\r
203 // cout << "Are neighbours: digit (E = " << digit1->fEnergy << ") with x = " << digit1->fX << " and z = " << digit1->fZ << \r
204 // " is neighbour with digit (E = " << digit2->fEnergy << ") with x = " << digit2->fX << " and z = " << digit2->fZ << endl;\r
205\r
206 if(TMath::Abs(digit1->fTime - digit2->fTime ) < fEmcTimeGate)\r
207 {\r
208 return 1; \r
209 }\r
210 }\r
211 else\r
212 {\r
213 // cout << "Not neighbours: digit (E = " << digit1->fEnergy << ") with x = " << digit1->fX << " and z = " << digit1->fZ << \r
214 // " is not neighbour with digit (E = " << digit2->fEnergy << ") with x = " << digit2->fX << " and z = " << digit2->fZ << endl;\r
215 }\r
216 }\r
217 return 0;\r
218}\r