]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx
Fast online clusterizer now working (Oystein)
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSClusterizerComponent.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Authors: Ã\98ystein Djuvsland <oysteind@ift.uib.no>                       *
5  *                                                                        *
6  * Permission to use, copy, modify and distribute this software and its   *
7  * documentation strictly for non-commercial purposes is hereby granted   *
8  * without fee, provided that the above copyright notice appears in all   *
9  * copies and that both the copyright notice and this permission notice   *
10  * appear in the supporting documentation. The authors make no claims     *
11  * about the suitability of this software for any purpose. It is          *
12  * provided "as is" without express or implied warranty.                  *
13  **************************************************************************/
14
15
16
17
18 #include "AliHLTPHOSClusterizerComponent.h"
19 #include "AliHLTPHOSClusterizer.h"
20 //#include "AliHLTPHOSPhysicsDefinitions.h"
21 //#include "AliHLTPHOSDefinitions.h"
22 #include "AliHLTPHOSRecPointDataStruct.h"
23 #include "AliHLTPHOSClusterDataStruct.h"
24 #include "AliHLTPHOSRecPointListDataStruct.h"
25 #include "AliHLTPHOSDigitContainerDataStruct.h"
26
27 using namespace std;
28
29
30 const AliHLTComponentDataType AliHLTPHOSClusterizerComponent::fgkInputDataTypes[]=
31   {
32     kAliHLTVoidDataType,{0,"",""}
33   };
34
35 AliHLTPHOSClusterizerComponent gAliHLTPHOSClusterizerComponent;
36
37 //AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSBase(), AliHLTProcessor(), fClusterizerPtr(0), fOutPtr(0),
38 //                                                               fRecPointStructArrayPtr(0), fRecPointListPtr(0)
39 AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSProcessor(), fClusterizerPtr(0), fOutPtr(0),
40     fRecPointStructArrayPtr(0), fRecPointListPtr(0)
41 {
42   //Constructor
43 }
44
45 AliHLTPHOSClusterizerComponent::~AliHLTPHOSClusterizerComponent()
46 {
47   //Destructor
48
49   if (fClusterizerPtr)
50     {
51       delete fClusterizerPtr;
52       fClusterizerPtr = 0;
53     }
54
55   if (fRecPointListPtr)
56     {
57       delete fRecPointListPtr;
58       fRecPointListPtr = 0;
59     }
60
61   if (fRecPointStructArrayPtr)
62     {
63       for (int i = 0; i < 1000; i++)
64         {
65           //      fRecPointStructArrayPtr[i].Del();
66         }
67       delete fRecPointStructArrayPtr;
68       fRecPointStructArrayPtr = 0;
69     }
70
71 }
72
73 /*
74 int
75 AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent::Deinit()
76 {
77   ////////// PTH WARNING you should Define a class AliHLTPHOSModuleProcessor
78 }
79 */
80
81 // PTH AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(const AliHLTPHOSClusterizerComponent &):AliHLTProcessor(),
82 //                                                                                                     fClusterizerPtr(0),
83 //                                                                                                     fOutPtr(0),
84 //                                                                                                     fRecPointStructArrayPtr(0),
85 //                                                                                                     fRecPointListPtr(0)
86 //{
87 //Copy constructor, not implemented
88 //}
89
90 int
91 AliHLTPHOSClusterizerComponent::Deinit()
92 {
93   //Deinitialization
94
95   if (fClusterizerPtr)
96     {
97       delete fClusterizerPtr;
98       fClusterizerPtr = 0;
99     }
100
101   if (fRecPointListPtr)
102     {
103       delete fRecPointListPtr;
104       fRecPointListPtr = 0;
105     }
106
107   for (int i = 0; i < 1000; i++)
108     {
109       //    fRecPointStructArrayPtr[i].Del();
110     }
111
112   if (fRecPointStructArrayPtr)
113     {
114       for (int i = 0; i < 1000; i++)
115         {
116           //      fRecPointStructArrayPtr[i].Del();
117         }
118       delete fRecPointStructArrayPtr;
119       fRecPointStructArrayPtr = 0;
120     }
121
122   return 0;
123 }
124
125 int
126 AliHLTPHOSClusterizerComponent::DoDeinit()
127 {
128   //Do deinitialization
129   Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSClusterizerComponent DoDeinit");
130
131   return 0;
132 }
133
134
135 const Char_t*
136 AliHLTPHOSClusterizerComponent::GetComponentID()
137 {
138   return "AliHltPhosClusterizer";
139 }
140
141 void
142 AliHLTPHOSClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
143 {
144   //Get datatypes for input
145   const AliHLTComponentDataType* pType=fgkInputDataTypes;
146   while (pType->fID!=0)
147     {
148       list.push_back(*pType);
149       pType++;
150     }
151 }
152
153 AliHLTComponentDataType
154 AliHLTPHOSClusterizerComponent::GetOutputDataType()
155 {
156   //  return AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType;
157   return AliHLTPHOSDefinitions::fgkAliHLTClusterDataType;
158 }
159
160 void
161 AliHLTPHOSClusterizerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
162
163 {
164   constBase = 30;
165   inputMultiplier = 0.2;
166 }
167
168 int
169 AliHLTPHOSClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
170                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
171                                         std::vector<AliHLTComponentBlockData>& outputBlocks)
172 {
173   //Do event
174
175   UInt_t tSize            = 0;
176   UInt_t offset           = 0;
177   UInt_t mysize           = 0;
178   Int_t nRecPoints        = 0;
179   Int_t nDigits           = 0;
180   Int_t index             = 0;
181   Int_t j =0;
182
183   AliHLTUInt8_t* outBPtr;
184   outBPtr = outputPtr;
185   const AliHLTComponentBlockData* iter = 0;
186   unsigned long ndx;
187
188   AliHLTPHOSDigitContainerDataStruct *digitContainerPtr = 0;
189   
190   //AliHLTPHOSRecPointContainerStruct *recPointContainerPtr = (AliHLTPHOSRecPointContainerStruct*)outBPtr;
191   fClusterizerPtr->SetRecPointContainer((AliHLTPHOSRecPointContainerStruct*)outBPtr);
192   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
193     {
194       iter = blocks+ndx;
195       digitContainerPtr = reinterpret_cast<AliHLTPHOSDigitContainerDataStruct*>(iter->fPtr);
196       if (iter->fDataType != AliHLTPHOSDefinitions::fgkAliHLTDigitDataType)
197         {
198           //      cout << "Warning: data type is not fgkAliHLTDigitDataType " << endl;
199           continue;
200         }
201       for (Int_t i = 0; i < digitContainerPtr->fNDigits; i++)
202         {
203           if(fNoCrazyness && digitContainerPtr->fDigitDataStruct[i].fCrazyness)
204             continue;
205             
206           fAllDigitsPtr->fDigitDataStruct[j+nDigits].fX = digitContainerPtr->fDigitDataStruct[i].fX;
207           fAllDigitsPtr->fDigitDataStruct[j+nDigits].fZ = digitContainerPtr->fDigitDataStruct[i].fZ;
208           fAllDigitsPtr->fDigitDataStruct[j+nDigits].fAmplitude = digitContainerPtr->fDigitDataStruct[i].fAmplitude;
209           fAllDigitsPtr->fDigitDataStruct[j+nDigits].fTime = digitContainerPtr->fDigitDataStruct[i].fTime;
210          // fAllDigitsPtr->fDigitDataStruct[i+nDigits].fCrazyness = digitContainerPtr->fDigitDataStruct[i].fCrazyness;
211           j++;
212         }
213       nDigits++;
214     }
215
216 // nRecPoints = fClusterizerPtr->CreateRecPointStructArray(fRecPointStructArrayPtr, fRecPointListPtr, index);
217
218   fOutPtr =  (AliHLTPHOSRecPointContainerStruct*)outBPtr;
219   nRecPoints = fClusterizerPtr->ClusterizeEvent();
220   //nRecPoints = fClusterizerPtr->CalculateCenterOfGravity(&fRecPointStructArrayPtr[i]);
221   cout << "Number of clusters found: " << nRecPoints << " extracted from " << nDigits << " digits" << endl;
222
223   mysize = 0;
224   offset = tSize;
225
226   //      fClusterizerPtr->CalculateMoments(&fRecPointStructArrayPtr[i], 0);
227   //     fClusterizerPtr->ClusterizeStruct(&fRecPointStructArrayPtr[i], fOutPtr);
228
229   mysize += sizeof(AliHLTPHOSClusterDataStruct);
230
231   AliHLTComponentBlockData bd;
232   FillBlockData( bd );
233   bd.fOffset = offset;
234   bd.fSize = mysize;
235   // PTH      bd.fDataType = AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType;
236   bd.fDataType = AliHLTPHOSDefinitions::fgkAliHLTClusterDataType;
237   bd.fSpecification = 0xFFFFFFFF;
238   outputBlocks.push_back( bd );
239
240   tSize += mysize;
241   outBPtr += mysize;
242
243   if ( tSize > size )
244     {
245       Logging( kHLTLogFatal, "HLT::AliHLTPHOSClusterizerComponent::DoEvent", "Too much data",
246                "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
247                , tSize, size );
248       return EMSGSIZE;
249     }
250
251
252   size = tSize;
253 // fClusterizerPtr->ResetCellEnergyArray();
254
255   return 0;
256
257 }
258
259 int
260 AliHLTPHOSClusterizerComponent::DoInit(int argc, const char** argv )
261 {
262   //Do initialization
263   fAllDigitsPtr = new AliHLTPHOSDigitContainerDataStruct();
264   fClusterizerPtr = new AliHLTPHOSClusterizer();
265   //fClusterizerPtr->SetNoCrazyness(true);
266   //
267   for (int i = 0; i < argc; i++)
268     {
269       /*
270       if(!strcmp("-threshold", argv[i]))
271       fClusterizerPtr->SetThreshold(atof(argv[i+1]));
272       if(!strcmp("-clusterthreshold", argv[i]))
273       fClusterizerPtr->SetClusterThreshold(atof(argv[i+1]));
274       if(!strcmp("-highgain", argv[i]))
275       fClusterizerPtr->SetHighGainFactor(atof(argv[i+1]));
276       if(!strcmp("-lowgain", argv[i]))
277       fClusterizerPtr->SetLowGainFactor(atof(argv[i+1]));
278       if(!strcmp("-arraysize", argv[i]))
279       fClusterizerPtr->SetArraySize(atoi(argv[i+1]));*/
280     }
281   //  fClusterizerPtr->ResetCellEnergyArray();
282   fRecPointListPtr = new AliHLTPHOSRecPointListDataStruct[N_ZROWS_MOD*N_XCOLUMNS_MOD];
283   fRecPointStructArrayPtr = new AliHLTPHOSRecPointDataStruct[1000];
284   for (int i = 0; i < 1000; i++)
285     {
286       fRecPointStructArrayPtr[i].fMultiplicity = atoi(argv[4])* atoi(argv[4]);
287       // fRecPointStructArrayPtr[i].New();
288     }
289   /*
290   printf("Clusterizer component started with:\n");
291   printf(" Cell threshold:     %f\n", fClusterizerPtr->GetThreshold());
292   printf(" Cluster threshold:  %f\n", fClusterizerPtr->GetClusterThreshold());
293   printf(" High gain factor:   %f\n", fClusterizerPtr->GetHighGainFactor());
294   printf(" Low gain factor:    %f\n", fClusterizerPtr->GetLowGainFactor());
295   printf(" Cluster array size: %d\n\n", fClusterizerPtr->GetArraySize());
296   */
297   return 0;
298 }
299
300 AliHLTComponent*
301 AliHLTPHOSClusterizerComponent::Spawn()
302 {
303   //Spawn a new AliHLTPHOSClusterizerComponent, for HLT framework
304   return new AliHLTPHOSClusterizerComponent();
305 }