- adding data member for associated cluster to digits
[u/mrichter/AliRoot.git] / HLT / CALO / AliHLTCaloClusterizerComponent.cxx
CommitLineData
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
c556a27e 41ClassImp(AliHLTCaloClusterizerComponent);
42
ad44d760 43AliHLTCaloClusterizerComponent::AliHLTCaloClusterizerComponent(TString det):
ad44d760 44 AliHLTCaloProcessor(),
f92dcf21 45 AliHLTCaloConstantsHandler(det),
98baf84d 46 fDataOrigin('\0'),
47 fAnalyserPtr(0),
c1e4a18c 48 fRecoParamsPtr(0),
f92dcf21 49 fDigitsPointerArray(0),
98baf84d 50 fOutputDigitsArray(0),
4d42193f 51 fClusterizerPtr(0),
427c373f 52 fDigitCount(0)
4d42193f 53{
54 //See headerfile for documentation
a6db7bcd 55
427c373f 56
a6db7bcd 57
4d42193f 58}
59
60AliHLTCaloClusterizerComponent::~AliHLTCaloClusterizerComponent()
61{
62 //See headerfile for documentation
73d6f579 63delete fAnalyserPtr;
4d42193f 64 if(fClusterizerPtr)
65 {
66 delete fClusterizerPtr;
67 fClusterizerPtr = 0;
68 }
4d42193f 69}
70
4d42193f 71int
72AliHLTCaloClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
73 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
74 std::vector<AliHLTComponentBlockData>& outputBlocks)
75{
76 //See headerfile for documentation
77
78 if(blocks == 0) return 0;
79
80 UInt_t offset = 0;
81 UInt_t mysize = 0;
82 Int_t nRecPoints = 0;
83 Int_t nDigits = 0;
ad44d760 84 Int_t digCount = 0;
4d42193f 85
7c80a370 86 UInt_t availableSize = size;
4d42193f 87 AliHLTUInt8_t* outBPtr;
88 outBPtr = outputPtr;
89 const AliHLTComponentBlockData* iter = 0;
90 unsigned long ndx;
91
92 UInt_t specification = 0;
93
94 AliHLTCaloDigitDataStruct *digitDataPtr = 0;
427c373f 95
4d42193f 96 // Adding together all the digits, should be put in standalone method
97 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
98 {
99 iter = blocks+ndx;
ad44d760 100 // HLTError("Got block");
7c80a370 101 if (iter->fDataType == (AliHLTCaloDefinitions::fgkDigitDataType|fDataOrigin))
4d42193f 102 {
70c86cde 103
104 // Update the number of digits
105 nDigits = iter->fSize/sizeof(AliHLTCaloDigitDataStruct);
7c80a370 106 availableSize -= iter->fSize;
107
4d42193f 108 specification = specification|iter->fSpecification;
109
7c80a370 110 digitDataPtr = reinterpret_cast<AliHLTCaloDigitDataStruct*>(iter->fPtr);
c556a27e 111
112 // We copy the digits to the digit buffer used by the clusterizer
113 // This is convinient since we want the digits from all DDLs before starting
114 // Could be changed if this is a bottle neck.
7c80a370 115 for (Int_t i = 0; i < nDigits; i++)
116 {
117 fDigitsPointerArray[digCount] = digitDataPtr;
118 digCount++;
119 digitDataPtr++;
120 }
4d42193f 121 }
122 }
4d42193f 123
ad44d760 124 if(digCount > 0)
4d42193f 125 {
7c80a370 126
127 AliHLTCaloClusterHeaderStruct* caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(outBPtr);
128 caloClusterHeaderPtr->fNDigits = digCount;
129
b4479a87 130 outBPtr += sizeof(AliHLTCaloClusterHeaderStruct);
131 mysize += sizeof(AliHLTCaloClusterHeaderStruct);
132
ad44d760 133 // Sort the digit pointers
31b89da4 134// qsort(fDigitsPointerArray, digCount, sizeof(AliHLTCaloDigitDataStruct*), CompareDigits);
4d42193f 135
ad44d760 136 // Copy the digits to the output
c556a27e 137 // If we don't want the digits in the output we currently need to copy them to another buffer
138 // The reason is that the clusterizer sets the energy of the digits in the input buffer to 0,
139 // but we want to use the digits in the cluster analyser.
7c80a370 140 fOutputDigitsArray = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
ad44d760 141 for(Int_t n = 0; n < digCount; n++)
142 {
143 memcpy(outBPtr, fDigitsPointerArray[n], sizeof(AliHLTCaloDigitDataStruct));
7c80a370 144 //fOutputDigitsArray[n] = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
ad44d760 145 outBPtr = outBPtr + sizeof(AliHLTCaloDigitDataStruct);
146 }
4f8d3cfb 147
c556a27e 148 // Update the size of the output we have used, needs to be removed if we don't push the digits
149 mysize += digCount*sizeof(AliHLTCaloDigitDataStruct);
ad44d760 150
c556a27e 151 // Do the clusterisation
7c80a370 152 nRecPoints = fClusterizerPtr->ClusterizeEvent(digCount);
98baf84d 153
c556a27e 154 // Give the cluster output to the analyser
b4479a87 155 fAnalyserPtr->SetCaloClusterData(reinterpret_cast<AliHLTCaloClusterDataStruct*>(outBPtr));
7c80a370 156
c556a27e 157 // Give the rec points to the analyser (input)
7c80a370 158 fAnalyserPtr->SetRecPointArray(fClusterizerPtr->GetRecPoints(), nRecPoints);
ad44d760 159
c556a27e 160 // Give the digits to the analyser
7c80a370 161 fAnalyserPtr->SetDigitDataArray(fOutputDigitsArray);
a6db7bcd 162
c556a27e 163 // Then we create the clusters
b4479a87 164 Int_t nClusters = fAnalyserPtr->CreateClusters(nRecPoints, size, mysize);
70c86cde 165
713ace13 166 if (nClusters < 0)
167 {
c556a27e 168 HLTError("Error in clusterisation");
713ace13 169 caloClusterHeaderPtr->fNClusters = 0;
170 }
171 else
172 {
173 caloClusterHeaderPtr->fNClusters = nClusters;
174 }
175
c556a27e 176 HLTDebug("Number of clusters: %d", nRecPoints);
73d6f579 177
ad44d760 178 AliHLTComponentBlockData bd;
179 FillBlockData( bd );
180 bd.fOffset = offset;
70c86cde 181 bd.fSize = mysize;
a6db7bcd 182 bd.fDataType = kAliHLTDataTypeCaloCluster | fDataOrigin;
ad44d760 183 bd.fSpecification = specification;
184 outputBlocks.push_back( bd );
185 }
186
4d42193f 187 size = mysize;
188
189 return 0;
190}
191
192int
193AliHLTCaloClusterizerComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
194{
195 // see header file for class documentation
196
197 const char* path="HLT/ConfigPHOS/ClusterizerComponent";
198
199 if (cdbEntry) path = cdbEntry;
200
201 return ConfigureFromCDBTObjString(cdbEntry);
202}
203
204int
205AliHLTCaloClusterizerComponent::ScanConfigurationArgument(int argc, const char **argv)
206{
207 //See header file for documentation
208
209 if(argc <= 0) return 0;
210
211 int i=0;
212
213 TString argument=argv[i];
214
215 if (argument.CompareTo("-digitthreshold") == 0)
216 {
217 if (++i >= argc) return -EPROTO;
218 argument = argv[i];
219 fClusterizerPtr->SetEmcMinEnergyThreshold(argument.Atof());
220 return 1;
221 }
222
223 if (argument.CompareTo("-recpointthreshold") == 0)
224 {
225 if (++i >= argc) return -EPROTO;
226 argument = argv[i];
227 fClusterizerPtr->SetEmcClusteringThreshold(argument.Atof());
228 return 1;
229 }
38a3b2ad 230
231 if (argument.CompareTo("-cutonsinglecell") == 0)
232 {
233 if (++i >= argc) return -EPROTO;
234 argument = argv[i];
235 fAnalyserPtr->SetCutOnSingleCellClusters(true, argument.Atof());
236 return 1;
237 }
31b89da4 238 if (argument.CompareTo("-sortbyposition") == 0)
239 {
240 fClusterizerPtr->SetSortDigitsByPosition();
241 return 1;
242 }
38a3b2ad 243
4d42193f 244 return 0;
245}
246
247int
248AliHLTCaloClusterizerComponent::DoInit(int argc, const char** argv )
249{
250 //See headerfile for documentation
251
427c373f 252 fDigitsPointerArray = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNXCOLUMNSMOD()*fCaloConstants->GetNZROWSMOD()];
253
254 fClusterizerPtr = new AliHLTCaloClusterizer(fCaloConstants->GetDETNAME());
255
256 fClusterizerPtr->SetDigitArray(fDigitsPointerArray);
31b89da4 257
258 fClusterizerPtr->SetSortDigitsByEnergy();
427c373f 259
260 fAnalyserPtr = new AliHLTCaloClusterAnalyser();
261
262 if(fCaloConstants->GetDETNAME() == "PHOS")
263 {
264 fAnalyserPtr->SetClusterType(kPHOSCluster);
265 }
266 else if(fCaloConstants->GetDETNAME() == "EMCAL")
267 {
268 fAnalyserPtr->SetClusterType(kEMCALClusterv1);
269 }
270 else
271 {
272 fAnalyserPtr->SetClusterType(kUndef);
273 }
274 InitialiseGeometry();
c1e4a18c 275 if(fRecoParamsPtr)
276 {
277 if(!fRecoParamsPtr->GetParametersFromCDB())
278 {
279 fAnalyserPtr->SetRecoParamHandler(fRecoParamsPtr);
3a624ba3 280 fClusterizerPtr->SetEmcClusteringThreshold(fRecoParamsPtr->GetRecPointThreshold());
281 fClusterizerPtr->SetEmcMinEnergyThreshold(fRecoParamsPtr->GetRecPointMemberThreshold());
c1e4a18c 282 }
283 }
4d42193f 284 //
285
286 // const char *path = "HLT/ConfigPHOS/ClusterizerComponent";
287
288 // ConfigureFromCDBTObjString(path);
289
290 for (int i = 0; i < argc; i++)
291 {
292 ScanConfigurationArgument(i, argv);
293 }
294
295 return 0;
296}
427c373f 297int AliHLTCaloClusterizerComponent::DoDeinit()
298{
299 // See header file for documentation
300 if(fDigitsPointerArray)
301 {
302 delete [] fDigitsPointerArray;
303 fDigitsPointerArray = 0;
304 }
305 if(fClusterizerPtr)
306 {
307 delete fClusterizerPtr;
308 fClusterizerPtr = 0;
309 }
310 if(fAnalyserPtr)
311 {
312 delete fAnalyserPtr;
313 fAnalyserPtr = 0;
314 }
315 return 0;
316}
4d42193f 317
ad44d760 318Int_t
319AliHLTCaloClusterizerComponent::CompareDigits(const void *dig0, const void *dig1)
4d42193f 320{
ad44d760 321 // See header file for documentation
322 return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
7c80a370 323
324 //return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
4d42193f 325}