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 |
32 | //#include "AliHLTCaloBase.h"\r |
33 | #include "AliHLTLogging.h"\r |
34 | #include "TMath.h"\r |
35 | #include "AliHLTCaloRecPointContainerStruct.h"\r |
36 | #include "AliHLTCaloRecPointDataStruct.h"\r |
37 | #include "AliHLTCaloDigitDataStruct.h"\r |
38 | #include "AliHLTCaloDigitContainerDataStruct.h"\r |
39 | #include "TClonesArray.h"\r |
40 | \r |
41 | //#include "AliHLTCaloConstants.h"\r |
42 | \r |
43 | #include "AliHLTCaloConstantsHandler.h";\r |
44 | #include "AliHLTCaloConstants.h";\r |
45 | \r |
46 | //#include "AliHLTCaloClusterHandler.h"\r |
47 | //#include "AliPHOSDigit.h"\r |
48 | \r |
49 | //#ifndef HAVENOT__PHOSRECOPARAMEMC // set from configure if EMC functionality not available in AliPHOSRecoParam\r |
50 | //#include "AliPHOSRecoParam.h"\r |
51 | //#else\r |
52 | //#include "AliPHOSRecoParamEmc.h"\r |
53 | //ff#endif\r |
54 | #include <iostream>\r |
55 | \r |
56 | \r |
57 | using namespace std;\r |
58 | \r |
59 | ClassImp(AliHLTCaloClusterizer);\r |
60 | \r |
61 | AliHLTCaloClusterizer::AliHLTCaloClusterizer(TString det):\r |
62 | AliHLTCaloConstantsHandler(det),\r |
63 | fRecPointDataPtr(0),\r |
64 | fDigitDataPtr(0),\r |
65 | fEmcClusteringThreshold(0),\r |
66 | fEmcMinEnergyThreshold(0),\r |
67 | fEmcTimeGate(0),\r |
68 | fDigitsInCluster(0),\r |
69 | fDigitContainerPtr(0),\r |
70 | fMaxDigitIndexDiff(0)\r |
71 | {\r |
72 | //See header file for documentation\r |
73 | fEmcClusteringThreshold = 0.2;\r |
74 | fEmcMinEnergyThreshold = 0.03;\r |
75 | fEmcTimeGate = 1.e-6 ;\r |
76 | \r |
77 | fMaxDigitIndexDiff = 2*fCaloConstants->GetNZROWSMOD();\r |
78 | }//end\r |
79 | \r |
80 | \r |
81 | AliHLTCaloClusterizer::~AliHLTCaloClusterizer() \r |
82 | {\r |
83 | //See header file for documentation\r |
84 | }\r |
85 | \r |
86 | void \r |
87 | AliHLTCaloClusterizer::SetRecPointDataPtr(AliHLTCaloRecPointDataStruct* recPointDataPtr)\r |
88 | {\r |
89 | // See header file for documentation\r |
90 | fRecPointDataPtr = recPointDataPtr;\r |
91 | }\r |
92 | \r |
93 | // void\r |
94 | // AliHLTCaloClusterizer::SetRecoParameters(AliPHOSRecoParam* params)\r |
95 | // {\r |
96 | // //see header file for documentation\r |
97 | // #ifndef HAVE_NOT_PHOSRECOPARAMEMC // set from configure if EMC functionality not available in AliPHOSRecoParam\r |
98 | // // the new AliPHOSRecoParam functions, available from revision\r |
99 | // // fEmcClusteringThreshold = params->GetEMCClusteringThreshold();\r |
100 | // // fEmcMinEnergyThreshold = params->GetEMCMinE();\r |
101 | // // fLogWeight = params->GetEMCLogWeight();\r |
102 | // params++;\r |
103 | // params--;\r |
104 | // #else\r |
105 | // fEmcClusteringThreshold = params->GetClusteringThreshold();\r |
106 | // fEmcMinEnergyThreshold = params->GetMinE();\r |
107 | // fLogWeight = params->GetLogWeight();\r |
108 | // #endif\r |
109 | // } \r |
110 | \r |
111 | Int_t \r |
112 | AliHLTCaloClusterizer::ClusterizeEvent(UInt_t availableSize, UInt_t& totSize)\r |
113 | {\r |
114 | //see header file for documentation\r |
115 | Int_t nRecPoints = 0;\r |
116 | \r |
117 | UInt_t maxRecPointSize = sizeof(AliHLTCaloRecPointDataStruct) + (sizeof(AliHLTCaloDigitDataStruct) << 7); //Reasonable estimate... \r |
118 | \r |
119 | //Clusterization starts\r |
120 | for(UInt_t i = 0; i < fDigitContainerPtr->fNDigits; i++)\r |
121 | { \r |
122 | fDigitsInCluster = 0;\r |
123 | \r |
124 | if(fDigitContainerPtr->fDigitDataStruct[i].fEnergy < fEmcClusteringThreshold)\r |
125 | {\r |
126 | continue;\r |
127 | }\r |
128 | if(availableSize < (totSize + maxRecPointSize)) \r |
129 | {\r |
130 | return -1; //Might get out of buffer, exiting\r |
131 | }\r |
132 | \r |
133 | // First digit is placed at the fDigits member variable in the recpoint\r |
134 | fDigitDataPtr = &(fRecPointDataPtr->fDigits);\r |
135 | \r |
136 | fRecPointDataPtr->fAmp = 0;\r |
137 | fRecPointDataPtr->fModule = fDigitContainerPtr->fDigitDataStruct[i].fModule;\r |
138 | \r |
139 | // Assigning digit data to the digit pointer\r |
140 | fRecPointDataPtr->fDigits = fDigitContainerPtr->fDigitDataStruct[i];\r |
141 | \r |
142 | // Incrementing the pointer to be ready for new entry\r |
143 | fDigitDataPtr++;\r |
144 | \r |
145 | fRecPointDataPtr->fAmp += fDigitContainerPtr->fDigitDataStruct[i].fEnergy;\r |
146 | fDigitContainerPtr->fDigitDataStruct[i].fEnergy = 0;\r |
147 | fDigitsInCluster++;\r |
148 | nRecPoints++;\r |
149 | \r |
150 | // Scanning for the neighbours\r |
151 | ScanForNeighbourDigits(i, fRecPointDataPtr);\r |
152 | \r |
153 | totSize += sizeof(AliHLTCaloRecPointDataStruct) + (fDigitsInCluster-1)*sizeof(AliHLTCaloDigitDataStruct); \r |
154 | fRecPointDataPtr->fMultiplicity = fDigitsInCluster; \r |
155 | \r |
156 | fRecPointDataPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(fDigitDataPtr);\r |
157 | }//end of clusterization\r |
158 | \r |
159 | return nRecPoints;\r |
160 | }\r |
161 | \r |
162 | void\r |
163 | AliHLTCaloClusterizer::ScanForNeighbourDigits(Int_t index, AliHLTCaloRecPointDataStruct* recPoint)\r |
164 | {\r |
165 | //see header file for documentation\r |
166 | Int_t max = TMath::Min((Int_t)fDigitContainerPtr->fNDigits, (Int_t)fMaxDigitIndexDiff+index);\r |
167 | Int_t min = TMath::Max(0, (Int_t)(index - (Int_t)fMaxDigitIndexDiff));\r |
168 | \r |
169 | max = fDigitContainerPtr->fNDigits;\r |
170 | min = 0;\r |
171 | for(Int_t j = min; j < max; j++)\r |
172 | {\r |
173 | if(fDigitContainerPtr->fDigitDataStruct[j].fEnergy > fEmcMinEnergyThreshold)\r |
174 | {\r |
175 | if(j != index)\r |
176 | {\r |
177 | if(AreNeighbours(&(fDigitContainerPtr->fDigitDataStruct[index]),\r |
178 | &(fDigitContainerPtr->fDigitDataStruct[j])))\r |
179 | {\r |
180 | // Assigning value to digit ptr\r |
181 | *fDigitDataPtr = fDigitContainerPtr->fDigitDataStruct[j];\r |
182 | // Incrementing digit pointer to be ready for new entry\r |
183 | fDigitDataPtr++;\r |
184 | \r |
185 | recPoint->fAmp += fDigitContainerPtr->fDigitDataStruct[j].fEnergy;\r |
186 | fDigitContainerPtr->fDigitDataStruct[j].fEnergy = 0; \r |
187 | fDigitsInCluster++;\r |
188 | ScanForNeighbourDigits(j, recPoint);\r |
189 | }\r |
190 | }\r |
191 | }\r |
192 | }\r |
193 | return;\r |
194 | }\r |
195 | \r |
196 | Int_t \r |
197 | AliHLTCaloClusterizer::AreNeighbours(AliHLTCaloDigitDataStruct* digit1, \r |
198 | AliHLTCaloDigitDataStruct* digit2)\r |
199 | {\r |
200 | //see header file for documentation\r |
201 | if ( (digit1->fModule == digit2->fModule) /*&& (coord1[1]==coord2[1])*/ ) // inside the same PHOS module\r |
202 | { \r |
203 | // Int_t rowdiff = TMath::Abs( digit1->fZ - digit2->fZ ); \r |
204 | // Int_t coldiff = TMath::Abs( digit1->fX - digit2->fX ); \r |
205 | // if (( coldiff <= 1 && rowdiff == 0 ) || ( coldiff == 0 && rowdiff <= 1 ))\r |
206 | // {\r |
207 | // cout << "Are neighbours: digit (E = " << digit1->fEnergy << ") with x = " << digit1->fX << " and z = " << digit1->fZ << \r |
208 | // " is neighbour with digit (E = " << digit2->fEnergy << ") with x = " << digit2->fX << " and z = " << digit2->fZ << endl;\r |
209 | \r |
210 | // if(TMath::Abs(digit1->fTime - digit2->fTime ) < fEmcTimeGate)\r |
211 | // {\r |
212 | // return 1; \r |
213 | // }\r |
214 | // }\r |
215 | \r |
216 | Float_t rowdiff = TMath::Abs( digit1->fZ - digit2->fZ ); \r |
217 | Float_t coldiff = TMath::Abs( digit1->fX - digit2->fX ); \r |
218 | if (( coldiff <= 2.4 && rowdiff < 0.4 ) || ( coldiff < 0.4 && rowdiff <= 2.4 ))\r |
219 | {\r |
220 | // cout << "Are neighbours: digit (E = " << digit1->fEnergy << ") with x = " << digit1->fX << " and z = " << digit1->fZ << \r |
221 | // " is neighbour with digit (E = " << digit2->fEnergy << ") with x = " << digit2->fX << " and z = " << digit2->fZ << endl;\r |
222 | \r |
223 | if(TMath::Abs(digit1->fTime - digit2->fTime ) < fEmcTimeGate)\r |
224 | {\r |
225 | return 1; \r |
226 | }\r |
227 | }\r |
228 | else\r |
229 | {\r |
230 | // cout << "Not neighbours: digit (E = " << digit1->fEnergy << ") with x = " << digit1->fX << " and z = " << digit1->fZ << \r |
231 | // " is not neighbour with digit (E = " << digit2->fEnergy << ") with x = " << digit2->fX << " and z = " << digit2->fZ << endl;\r |
232 | }\r |
233 | }\r |
234 | return 0;\r |
235 | }\r |