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), |
7b3a0a0e |
50 | fDigitCount(0), |
51 | fGeometryInitialised(true) |
4d42193f |
52 | { |
53 | //See headerfile for documentation |
ad44d760 |
54 | |
70c86cde |
55 | fDigitsPointerArray = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNXCOLUMNSMOD()*fCaloConstants->GetNZROWSMOD()]; |
ad44d760 |
56 | |
57 | fClusterizerPtr = new AliHLTCaloClusterizer(det); |
58 | |
59 | fClusterizerPtr->SetDigitArray(fDigitsPointerArray); |
7c80a370 |
60 | |
61 | fAnalyserPtr = new AliHLTCaloClusterAnalyser(); |
62 | |
a6db7bcd |
63 | if(det == "PHOS") |
64 | { |
65 | fAnalyserPtr->SetClusterType(kPHOSCluster); |
66 | } |
67 | else if(det == "EMCAL") |
68 | { |
69 | fAnalyserPtr->SetClusterType(kEMCALClusterv1); |
70 | } |
71 | else |
72 | { |
73 | fAnalyserPtr->SetClusterType(kUndef); |
74 | } |
75 | |
76 | |
4d42193f |
77 | } |
78 | |
79 | AliHLTCaloClusterizerComponent::~AliHLTCaloClusterizerComponent() |
80 | { |
81 | //See headerfile for documentation |
73d6f579 |
82 | delete fAnalyserPtr; |
4d42193f |
83 | if(fClusterizerPtr) |
84 | { |
85 | delete fClusterizerPtr; |
86 | fClusterizerPtr = 0; |
87 | } |
4d42193f |
88 | } |
89 | |
90 | |
91 | int |
92 | AliHLTCaloClusterizerComponent::Deinit() |
93 | { |
94 | //See headerfile for documentation |
95 | |
73d6f579 |
96 | if (fClusterizerPtr) |
4d42193f |
97 | { |
98 | delete fClusterizerPtr; |
99 | fClusterizerPtr = 0; |
100 | } |
101 | |
102 | return 0; |
103 | } |
104 | |
4d42193f |
105 | int |
106 | AliHLTCaloClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, |
107 | AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, |
108 | std::vector<AliHLTComponentBlockData>& outputBlocks) |
109 | { |
110 | //See headerfile for documentation |
111 | |
112 | if(blocks == 0) return 0; |
113 | |
114 | UInt_t offset = 0; |
115 | UInt_t mysize = 0; |
116 | Int_t nRecPoints = 0; |
117 | Int_t nDigits = 0; |
ad44d760 |
118 | Int_t digCount = 0; |
4d42193f |
119 | |
7c80a370 |
120 | UInt_t availableSize = size; |
4d42193f |
121 | AliHLTUInt8_t* outBPtr; |
122 | outBPtr = outputPtr; |
123 | const AliHLTComponentBlockData* iter = 0; |
124 | unsigned long ndx; |
125 | |
126 | UInt_t specification = 0; |
127 | |
128 | AliHLTCaloDigitDataStruct *digitDataPtr = 0; |
7b3a0a0e |
129 | if(fGeometryInitialised == false) InitialiseGeometry(); |
4d42193f |
130 | // Adding together all the digits, should be put in standalone method |
131 | for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) |
132 | { |
133 | iter = blocks+ndx; |
ad44d760 |
134 | // HLTError("Got block"); |
7c80a370 |
135 | if (iter->fDataType == (AliHLTCaloDefinitions::fgkDigitDataType|fDataOrigin)) |
4d42193f |
136 | { |
70c86cde |
137 | |
138 | // Update the number of digits |
139 | nDigits = iter->fSize/sizeof(AliHLTCaloDigitDataStruct); |
7c80a370 |
140 | availableSize -= iter->fSize; |
141 | |
4d42193f |
142 | specification = specification|iter->fSpecification; |
143 | |
7c80a370 |
144 | digitDataPtr = reinterpret_cast<AliHLTCaloDigitDataStruct*>(iter->fPtr); |
145 | for (Int_t i = 0; i < nDigits; i++) |
146 | { |
147 | fDigitsPointerArray[digCount] = digitDataPtr; |
148 | digCount++; |
149 | digitDataPtr++; |
150 | } |
4d42193f |
151 | } |
152 | } |
4d42193f |
153 | |
ad44d760 |
154 | if(digCount > 0) |
4d42193f |
155 | { |
7c80a370 |
156 | |
157 | AliHLTCaloClusterHeaderStruct* caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(outBPtr); |
158 | caloClusterHeaderPtr->fNDigits = digCount; |
159 | |
b4479a87 |
160 | outBPtr += sizeof(AliHLTCaloClusterHeaderStruct); |
161 | mysize += sizeof(AliHLTCaloClusterHeaderStruct); |
162 | |
ad44d760 |
163 | // Sort the digit pointers |
164 | qsort(fDigitsPointerArray, digCount, sizeof(AliHLTCaloDigitDataStruct*), CompareDigits); |
4d42193f |
165 | |
ad44d760 |
166 | // Copy the digits to the output |
7c80a370 |
167 | fOutputDigitsArray = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr); |
ad44d760 |
168 | for(Int_t n = 0; n < digCount; n++) |
169 | { |
170 | memcpy(outBPtr, fDigitsPointerArray[n], sizeof(AliHLTCaloDigitDataStruct)); |
7c80a370 |
171 | //fOutputDigitsArray[n] = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr); |
ad44d760 |
172 | outBPtr = outBPtr + sizeof(AliHLTCaloDigitDataStruct); |
173 | } |
174 | |
70c86cde |
175 | mysize += digCount*sizeof(AliHLTCaloDigitDataStruct); |
4f8d3cfb |
176 | |
7c80a370 |
177 | //HLTDebug("Total number of digits: %d", digCount ); |
ad44d760 |
178 | |
7c80a370 |
179 | nRecPoints = fClusterizerPtr->ClusterizeEvent(digCount); |
98baf84d |
180 | |
7c80a370 |
181 | //HLTDebug("Number of rec points found: %d", nRecPoints); |
b4479a87 |
182 | fAnalyserPtr->SetCaloClusterData(reinterpret_cast<AliHLTCaloClusterDataStruct*>(outBPtr)); |
7c80a370 |
183 | |
7c80a370 |
184 | fAnalyserPtr->SetRecPointArray(fClusterizerPtr->GetRecPoints(), nRecPoints); |
ad44d760 |
185 | |
7c80a370 |
186 | fAnalyserPtr->SetDigitDataArray(fOutputDigitsArray); |
a6db7bcd |
187 | |
b4479a87 |
188 | Int_t nClusters = fAnalyserPtr->CreateClusters(nRecPoints, size, mysize); |
70c86cde |
189 | |
713ace13 |
190 | if (nClusters < 0) |
191 | { |
192 | caloClusterHeaderPtr->fNClusters = 0; |
193 | } |
194 | else |
195 | { |
196 | caloClusterHeaderPtr->fNClusters = nClusters; |
197 | } |
198 | |
98baf84d |
199 | //HLTDebug("Number of clusters: %d", nRecPoints); |
73d6f579 |
200 | |
ad44d760 |
201 | AliHLTComponentBlockData bd; |
202 | FillBlockData( bd ); |
203 | bd.fOffset = offset; |
70c86cde |
204 | bd.fSize = mysize; |
a6db7bcd |
205 | bd.fDataType = kAliHLTDataTypeCaloCluster | fDataOrigin; |
ad44d760 |
206 | bd.fSpecification = specification; |
207 | outputBlocks.push_back( bd ); |
208 | } |
209 | |
4d42193f |
210 | size = mysize; |
211 | |
212 | return 0; |
213 | } |
214 | |
215 | int |
216 | AliHLTCaloClusterizerComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/) |
217 | { |
218 | // see header file for class documentation |
219 | |
220 | const char* path="HLT/ConfigPHOS/ClusterizerComponent"; |
221 | |
222 | if (cdbEntry) path = cdbEntry; |
223 | |
224 | return ConfigureFromCDBTObjString(cdbEntry); |
225 | } |
226 | |
227 | int |
228 | AliHLTCaloClusterizerComponent::ScanConfigurationArgument(int argc, const char **argv) |
229 | { |
230 | //See header file for documentation |
231 | |
232 | if(argc <= 0) return 0; |
233 | |
234 | int i=0; |
235 | |
236 | TString argument=argv[i]; |
237 | |
238 | if (argument.CompareTo("-digitthreshold") == 0) |
239 | { |
240 | if (++i >= argc) return -EPROTO; |
241 | argument = argv[i]; |
242 | fClusterizerPtr->SetEmcMinEnergyThreshold(argument.Atof()); |
243 | return 1; |
244 | } |
245 | |
246 | if (argument.CompareTo("-recpointthreshold") == 0) |
247 | { |
248 | if (++i >= argc) return -EPROTO; |
249 | argument = argv[i]; |
250 | fClusterizerPtr->SetEmcClusteringThreshold(argument.Atof()); |
251 | return 1; |
252 | } |
253 | return 0; |
254 | } |
255 | |
256 | int |
257 | AliHLTCaloClusterizerComponent::DoInit(int argc, const char** argv ) |
258 | { |
259 | //See headerfile for documentation |
260 | |
c1e4a18c |
261 | if(fRecoParamsPtr) |
262 | { |
263 | if(!fRecoParamsPtr->GetParametersFromCDB()) |
264 | { |
265 | fAnalyserPtr->SetRecoParamHandler(fRecoParamsPtr); |
3a624ba3 |
266 | fClusterizerPtr->SetEmcClusteringThreshold(fRecoParamsPtr->GetRecPointThreshold()); |
267 | fClusterizerPtr->SetEmcMinEnergyThreshold(fRecoParamsPtr->GetRecPointMemberThreshold()); |
c1e4a18c |
268 | } |
269 | } |
4d42193f |
270 | // |
271 | |
272 | // const char *path = "HLT/ConfigPHOS/ClusterizerComponent"; |
273 | |
274 | // ConfigureFromCDBTObjString(path); |
275 | |
276 | for (int i = 0; i < argc; i++) |
277 | { |
278 | ScanConfigurationArgument(i, argv); |
279 | } |
280 | |
281 | return 0; |
282 | } |
283 | |
ad44d760 |
284 | Int_t |
285 | AliHLTCaloClusterizerComponent::CompareDigits(const void *dig0, const void *dig1) |
4d42193f |
286 | { |
ad44d760 |
287 | // See header file for documentation |
288 | return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID; |
7c80a370 |
289 | |
290 | //return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID; |
4d42193f |
291 | } |