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