4d42193f |
1 | // $Id: AliHLTCaloClusterizerComponent.cxx 36709 2009-11-12 16:57:55Z odjuvsla $ |
2 | |
3 | /************************************************************************** |
4 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * |
5 | * * |
6 | * Authors: Oystein Djuvsland <oysteind@ift.uib.no> * |
7 | * * |
8 | * Permission to use, copy, modify and distribute this software and its * |
9 | * documentation strictly for non-commercial purposes is hereby granted * |
10 | * without fee, provided that the above copyright notice appears in all * |
11 | * copies and that both the copyright notice and this permission notice * |
12 | * appear in the supporting documentation. The authors make no claims * |
13 | * about the suitability of this software for any purpose. It is * |
14 | * provided "as is" without express or implied warranty. * |
15 | **************************************************************************/ |
16 | |
4d42193f |
17 | #include "AliHLTCaloClusterizerComponent.h" |
18 | #include "AliHLTCaloClusterizer.h" |
7c80a370 |
19 | #include "AliHLTCaloClusterAnalyser.h" |
4d42193f |
20 | #include "AliHLTCaloRecPointDataStruct.h" |
21 | #include "AliHLTCaloRecPointHeaderStruct.h" |
22 | #include "AliHLTCaloDigitDataStruct.h" |
23 | #include "AliHLTCaloDigitContainerDataStruct.h" |
24 | #include "AliHLTCaloDefinitions.h" |
7c80a370 |
25 | #include "AliHLTCaloClusterDataStruct.h" |
c1e4a18c |
26 | #include "AliHLTCaloRecoParamHandler.h" |
ad44d760 |
27 | #include "TString.h" |
4d42193f |
28 | |
29 | /** @file AliHLTCaloClusterizerComponent.cxx |
30 | @author Oystein Djuvsland |
31 | @date |
32 | @brief A clusterizer component for PHOS HLT |
33 | */ |
34 | |
35 | // see header file for class documentation |
36 | // or |
37 | // refer to README to build package |
38 | // or |
39 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt |
40 | |
ad44d760 |
41 | AliHLTCaloClusterizerComponent::AliHLTCaloClusterizerComponent(TString det): |
ad44d760 |
42 | AliHLTCaloProcessor(), |
f92dcf21 |
43 | AliHLTCaloConstantsHandler(det), |
98baf84d |
44 | fDataOrigin('\0'), |
45 | fAnalyserPtr(0), |
c1e4a18c |
46 | fRecoParamsPtr(0), |
f92dcf21 |
47 | fDigitsPointerArray(0), |
98baf84d |
48 | fOutputDigitsArray(0), |
4d42193f |
49 | fClusterizerPtr(0), |
427c373f |
50 | fDigitCount(0) |
4d42193f |
51 | { |
52 | //See headerfile for documentation |
a6db7bcd |
53 | |
427c373f |
54 | |
a6db7bcd |
55 | |
4d42193f |
56 | } |
57 | |
58 | AliHLTCaloClusterizerComponent::~AliHLTCaloClusterizerComponent() |
59 | { |
60 | //See headerfile for documentation |
73d6f579 |
61 | delete fAnalyserPtr; |
4d42193f |
62 | if(fClusterizerPtr) |
63 | { |
64 | delete fClusterizerPtr; |
65 | fClusterizerPtr = 0; |
66 | } |
4d42193f |
67 | } |
68 | |
4d42193f |
69 | int |
70 | AliHLTCaloClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, |
71 | AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, |
72 | std::vector<AliHLTComponentBlockData>& outputBlocks) |
73 | { |
74 | //See headerfile for documentation |
75 | |
76 | if(blocks == 0) return 0; |
77 | |
78 | UInt_t offset = 0; |
79 | UInt_t mysize = 0; |
80 | Int_t nRecPoints = 0; |
81 | Int_t nDigits = 0; |
ad44d760 |
82 | Int_t digCount = 0; |
4d42193f |
83 | |
7c80a370 |
84 | UInt_t availableSize = size; |
4d42193f |
85 | AliHLTUInt8_t* outBPtr; |
86 | outBPtr = outputPtr; |
87 | const AliHLTComponentBlockData* iter = 0; |
88 | unsigned long ndx; |
89 | |
90 | UInt_t specification = 0; |
91 | |
92 | AliHLTCaloDigitDataStruct *digitDataPtr = 0; |
427c373f |
93 | |
4d42193f |
94 | // Adding together all the digits, should be put in standalone method |
95 | for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) |
96 | { |
97 | iter = blocks+ndx; |
ad44d760 |
98 | // HLTError("Got block"); |
7c80a370 |
99 | if (iter->fDataType == (AliHLTCaloDefinitions::fgkDigitDataType|fDataOrigin)) |
4d42193f |
100 | { |
70c86cde |
101 | |
102 | // Update the number of digits |
103 | nDigits = iter->fSize/sizeof(AliHLTCaloDigitDataStruct); |
7c80a370 |
104 | availableSize -= iter->fSize; |
105 | |
4d42193f |
106 | specification = specification|iter->fSpecification; |
107 | |
7c80a370 |
108 | digitDataPtr = reinterpret_cast<AliHLTCaloDigitDataStruct*>(iter->fPtr); |
109 | for (Int_t i = 0; i < nDigits; i++) |
110 | { |
111 | fDigitsPointerArray[digCount] = digitDataPtr; |
112 | digCount++; |
113 | digitDataPtr++; |
114 | } |
4d42193f |
115 | } |
116 | } |
4d42193f |
117 | |
ad44d760 |
118 | if(digCount > 0) |
4d42193f |
119 | { |
7c80a370 |
120 | |
121 | AliHLTCaloClusterHeaderStruct* caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(outBPtr); |
122 | caloClusterHeaderPtr->fNDigits = digCount; |
123 | |
b4479a87 |
124 | outBPtr += sizeof(AliHLTCaloClusterHeaderStruct); |
125 | mysize += sizeof(AliHLTCaloClusterHeaderStruct); |
126 | |
ad44d760 |
127 | // Sort the digit pointers |
31b89da4 |
128 | // qsort(fDigitsPointerArray, digCount, sizeof(AliHLTCaloDigitDataStruct*), CompareDigits); |
4d42193f |
129 | |
ad44d760 |
130 | // Copy the digits to the output |
7c80a370 |
131 | fOutputDigitsArray = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr); |
ad44d760 |
132 | for(Int_t n = 0; n < digCount; n++) |
133 | { |
134 | memcpy(outBPtr, fDigitsPointerArray[n], sizeof(AliHLTCaloDigitDataStruct)); |
7c80a370 |
135 | //fOutputDigitsArray[n] = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr); |
ad44d760 |
136 | outBPtr = outBPtr + sizeof(AliHLTCaloDigitDataStruct); |
137 | } |
138 | |
70c86cde |
139 | mysize += digCount*sizeof(AliHLTCaloDigitDataStruct); |
4f8d3cfb |
140 | |
7c80a370 |
141 | //HLTDebug("Total number of digits: %d", digCount ); |
ad44d760 |
142 | |
7c80a370 |
143 | nRecPoints = fClusterizerPtr->ClusterizeEvent(digCount); |
98baf84d |
144 | |
7c80a370 |
145 | //HLTDebug("Number of rec points found: %d", nRecPoints); |
b4479a87 |
146 | fAnalyserPtr->SetCaloClusterData(reinterpret_cast<AliHLTCaloClusterDataStruct*>(outBPtr)); |
7c80a370 |
147 | |
7c80a370 |
148 | fAnalyserPtr->SetRecPointArray(fClusterizerPtr->GetRecPoints(), nRecPoints); |
ad44d760 |
149 | |
7c80a370 |
150 | fAnalyserPtr->SetDigitDataArray(fOutputDigitsArray); |
a6db7bcd |
151 | |
b4479a87 |
152 | Int_t nClusters = fAnalyserPtr->CreateClusters(nRecPoints, size, mysize); |
70c86cde |
153 | |
713ace13 |
154 | if (nClusters < 0) |
155 | { |
156 | caloClusterHeaderPtr->fNClusters = 0; |
157 | } |
158 | else |
159 | { |
160 | caloClusterHeaderPtr->fNClusters = nClusters; |
161 | } |
162 | |
98baf84d |
163 | //HLTDebug("Number of clusters: %d", nRecPoints); |
73d6f579 |
164 | |
ad44d760 |
165 | AliHLTComponentBlockData bd; |
166 | FillBlockData( bd ); |
167 | bd.fOffset = offset; |
70c86cde |
168 | bd.fSize = mysize; |
a6db7bcd |
169 | bd.fDataType = kAliHLTDataTypeCaloCluster | fDataOrigin; |
ad44d760 |
170 | bd.fSpecification = specification; |
171 | outputBlocks.push_back( bd ); |
172 | } |
173 | |
4d42193f |
174 | size = mysize; |
175 | |
176 | return 0; |
177 | } |
178 | |
179 | int |
180 | AliHLTCaloClusterizerComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/) |
181 | { |
182 | // see header file for class documentation |
183 | |
184 | const char* path="HLT/ConfigPHOS/ClusterizerComponent"; |
185 | |
186 | if (cdbEntry) path = cdbEntry; |
187 | |
188 | return ConfigureFromCDBTObjString(cdbEntry); |
189 | } |
190 | |
191 | int |
192 | AliHLTCaloClusterizerComponent::ScanConfigurationArgument(int argc, const char **argv) |
193 | { |
194 | //See header file for documentation |
195 | |
196 | if(argc <= 0) return 0; |
197 | |
198 | int i=0; |
199 | |
200 | TString argument=argv[i]; |
201 | |
202 | if (argument.CompareTo("-digitthreshold") == 0) |
203 | { |
204 | if (++i >= argc) return -EPROTO; |
205 | argument = argv[i]; |
206 | fClusterizerPtr->SetEmcMinEnergyThreshold(argument.Atof()); |
207 | return 1; |
208 | } |
209 | |
210 | if (argument.CompareTo("-recpointthreshold") == 0) |
211 | { |
212 | if (++i >= argc) return -EPROTO; |
213 | argument = argv[i]; |
214 | fClusterizerPtr->SetEmcClusteringThreshold(argument.Atof()); |
215 | return 1; |
216 | } |
38a3b2ad |
217 | |
218 | if (argument.CompareTo("-cutonsinglecell") == 0) |
219 | { |
220 | if (++i >= argc) return -EPROTO; |
221 | argument = argv[i]; |
222 | fAnalyserPtr->SetCutOnSingleCellClusters(true, argument.Atof()); |
223 | return 1; |
224 | } |
31b89da4 |
225 | if (argument.CompareTo("-sortbyposition") == 0) |
226 | { |
227 | fClusterizerPtr->SetSortDigitsByPosition(); |
228 | return 1; |
229 | } |
38a3b2ad |
230 | |
4d42193f |
231 | return 0; |
232 | } |
233 | |
234 | int |
235 | AliHLTCaloClusterizerComponent::DoInit(int argc, const char** argv ) |
236 | { |
237 | //See headerfile for documentation |
238 | |
427c373f |
239 | fDigitsPointerArray = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNXCOLUMNSMOD()*fCaloConstants->GetNZROWSMOD()]; |
240 | |
241 | fClusterizerPtr = new AliHLTCaloClusterizer(fCaloConstants->GetDETNAME()); |
242 | |
243 | fClusterizerPtr->SetDigitArray(fDigitsPointerArray); |
31b89da4 |
244 | |
245 | fClusterizerPtr->SetSortDigitsByEnergy(); |
427c373f |
246 | |
247 | fAnalyserPtr = new AliHLTCaloClusterAnalyser(); |
248 | |
249 | if(fCaloConstants->GetDETNAME() == "PHOS") |
250 | { |
251 | fAnalyserPtr->SetClusterType(kPHOSCluster); |
252 | } |
253 | else if(fCaloConstants->GetDETNAME() == "EMCAL") |
254 | { |
255 | fAnalyserPtr->SetClusterType(kEMCALClusterv1); |
256 | } |
257 | else |
258 | { |
259 | fAnalyserPtr->SetClusterType(kUndef); |
260 | } |
261 | InitialiseGeometry(); |
c1e4a18c |
262 | if(fRecoParamsPtr) |
263 | { |
264 | if(!fRecoParamsPtr->GetParametersFromCDB()) |
265 | { |
266 | fAnalyserPtr->SetRecoParamHandler(fRecoParamsPtr); |
3a624ba3 |
267 | fClusterizerPtr->SetEmcClusteringThreshold(fRecoParamsPtr->GetRecPointThreshold()); |
268 | fClusterizerPtr->SetEmcMinEnergyThreshold(fRecoParamsPtr->GetRecPointMemberThreshold()); |
c1e4a18c |
269 | } |
270 | } |
4d42193f |
271 | // |
272 | |
273 | // const char *path = "HLT/ConfigPHOS/ClusterizerComponent"; |
274 | |
275 | // ConfigureFromCDBTObjString(path); |
276 | |
277 | for (int i = 0; i < argc; i++) |
278 | { |
279 | ScanConfigurationArgument(i, argv); |
280 | } |
281 | |
282 | return 0; |
283 | } |
427c373f |
284 | int AliHLTCaloClusterizerComponent::DoDeinit() |
285 | { |
286 | // See header file for documentation |
287 | if(fDigitsPointerArray) |
288 | { |
289 | delete [] fDigitsPointerArray; |
290 | fDigitsPointerArray = 0; |
291 | } |
292 | if(fClusterizerPtr) |
293 | { |
294 | delete fClusterizerPtr; |
295 | fClusterizerPtr = 0; |
296 | } |
297 | if(fAnalyserPtr) |
298 | { |
299 | delete fAnalyserPtr; |
300 | fAnalyserPtr = 0; |
301 | } |
302 | return 0; |
303 | } |
4d42193f |
304 | |
ad44d760 |
305 | Int_t |
306 | AliHLTCaloClusterizerComponent::CompareDigits(const void *dig0, const void *dig1) |
4d42193f |
307 | { |
ad44d760 |
308 | // See header file for documentation |
309 | return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID; |
7c80a370 |
310 | |
311 | //return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID; |
4d42193f |
312 | } |