]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/CALO/AliHLTCaloClusterizerComponent.cxx
- added different sorting algorithms for the 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 AliHLTCaloClusterizerComponent::AliHLTCaloClusterizerComponent(TString det): 
42   AliHLTCaloProcessor(),
43   AliHLTCaloConstantsHandler(det),
44   fDataOrigin('\0'),
45   fAnalyserPtr(0),
46   fRecoParamsPtr(0),
47   fDigitsPointerArray(0), 
48   fOutputDigitsArray(0),
49   fClusterizerPtr(0),
50   fDigitCount(0)
51 {
52   //See headerfile for documentation
53   
54  
55   
56 }
57
58 AliHLTCaloClusterizerComponent::~AliHLTCaloClusterizerComponent()
59 {
60   //See headerfile for documentation
61 delete fAnalyserPtr;
62   if(fClusterizerPtr)
63     {
64       delete fClusterizerPtr;
65       fClusterizerPtr = 0;
66     }
67 }
68
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;
82   Int_t digCount          = 0;
83
84   UInt_t availableSize = size;
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;
93
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;
98       //            HLTError("Got block");
99       if (iter->fDataType == (AliHLTCaloDefinitions::fgkDigitDataType|fDataOrigin))
100         {
101
102            // Update the number of digits
103           nDigits = iter->fSize/sizeof(AliHLTCaloDigitDataStruct);
104           availableSize -= iter->fSize;
105           
106           specification = specification|iter->fSpecification;
107
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             }
115         }
116     }
117
118   if(digCount > 0)
119     {
120        
121       AliHLTCaloClusterHeaderStruct* caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(outBPtr);
122       caloClusterHeaderPtr->fNDigits = digCount;
123       
124       outBPtr += sizeof(AliHLTCaloClusterHeaderStruct);
125       mysize += sizeof(AliHLTCaloClusterHeaderStruct);
126       
127       // Sort the digit pointers
128 //      qsort(fDigitsPointerArray, digCount, sizeof(AliHLTCaloDigitDataStruct*), CompareDigits);
129
130       // Copy the digits to the output
131       fOutputDigitsArray = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
132       for(Int_t n = 0; n < digCount; n++)
133         {
134           memcpy(outBPtr, fDigitsPointerArray[n], sizeof(AliHLTCaloDigitDataStruct));
135           //fOutputDigitsArray[n] = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
136           outBPtr = outBPtr + sizeof(AliHLTCaloDigitDataStruct);
137         }
138   
139       mysize += digCount*sizeof(AliHLTCaloDigitDataStruct);
140       
141       //HLTDebug("Total number of digits: %d", digCount );
142
143       nRecPoints = fClusterizerPtr->ClusterizeEvent(digCount);
144
145       //HLTDebug("Number of rec points found: %d", nRecPoints);
146       fAnalyserPtr->SetCaloClusterData(reinterpret_cast<AliHLTCaloClusterDataStruct*>(outBPtr));
147       
148       fAnalyserPtr->SetRecPointArray(fClusterizerPtr->GetRecPoints(), nRecPoints);
149
150       fAnalyserPtr->SetDigitDataArray(fOutputDigitsArray);
151       
152       Int_t nClusters = fAnalyserPtr->CreateClusters(nRecPoints, size, mysize);
153       
154       if (nClusters < 0) 
155         {
156           caloClusterHeaderPtr->fNClusters = 0;
157         } 
158       else 
159         {
160           caloClusterHeaderPtr->fNClusters = nClusters;
161         }
162      
163       //HLTDebug("Number of clusters: %d", nRecPoints);
164       
165       AliHLTComponentBlockData bd;
166       FillBlockData( bd );
167       bd.fOffset = offset;
168       bd.fSize = mysize;
169       bd.fDataType = kAliHLTDataTypeCaloCluster | fDataOrigin;
170       bd.fSpecification = specification;
171       outputBlocks.push_back( bd );
172     }
173
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     }
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     }
225   if (argument.CompareTo("-sortbyposition") == 0)
226     {
227       fClusterizerPtr->SetSortDigitsByPosition();
228        return 1;
229     }
230     
231   return 0;
232 }
233
234 int
235 AliHLTCaloClusterizerComponent::DoInit(int argc, const char** argv )
236 {
237   //See headerfile for documentation
238
239   fDigitsPointerArray = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNXCOLUMNSMOD()*fCaloConstants->GetNZROWSMOD()];
240
241   fClusterizerPtr = new AliHLTCaloClusterizer(fCaloConstants->GetDETNAME());
242
243   fClusterizerPtr->SetDigitArray(fDigitsPointerArray);
244   
245   fClusterizerPtr->SetSortDigitsByEnergy();
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();
262   if(fRecoParamsPtr)
263   {
264      if(!fRecoParamsPtr->GetParametersFromCDB())
265      {
266          fAnalyserPtr->SetRecoParamHandler(fRecoParamsPtr);
267          fClusterizerPtr->SetEmcClusteringThreshold(fRecoParamsPtr->GetRecPointThreshold());
268          fClusterizerPtr->SetEmcMinEnergyThreshold(fRecoParamsPtr->GetRecPointMemberThreshold());
269      }
270   }
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 }
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 }
304
305 Int_t 
306 AliHLTCaloClusterizerComponent::CompareDigits(const void *dig0, const void *dig1)
307 {
308   // See header file for documentation
309   return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
310
311   //return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
312 }