Fast online clusterizer now working (Oystein)
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSClusterizerComponent.cxx
CommitLineData
91b95d47 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
442af5b7 4 * Authors: Ã\98ystein Djuvsland <oysteind@ift.uib.no> *
91b95d47 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 **************************************************************************/
aac22523 14
aac22523 15
d2b84453 16
17
91b95d47 18#include "AliHLTPHOSClusterizerComponent.h"
aac22523 19#include "AliHLTPHOSClusterizer.h"
d2b84453 20//#include "AliHLTPHOSPhysicsDefinitions.h"
21//#include "AliHLTPHOSDefinitions.h"
91b95d47 22#include "AliHLTPHOSRecPointDataStruct.h"
23#include "AliHLTPHOSClusterDataStruct.h"
24#include "AliHLTPHOSRecPointListDataStruct.h"
9cc0deb1 25#include "AliHLTPHOSDigitContainerDataStruct.h"
91b95d47 26
27using namespace std;
aac22523 28
29
9cc0deb1 30const AliHLTComponentDataType AliHLTPHOSClusterizerComponent::fgkInputDataTypes[]=
31 {
32 kAliHLTVoidDataType,{0,"",""}
33 };
aac22523 34
35AliHLTPHOSClusterizerComponent gAliHLTPHOSClusterizerComponent;
36
9cc0deb1 37//AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSBase(), AliHLTProcessor(), fClusterizerPtr(0), fOutPtr(0),
9c9d15d6 38// fRecPointStructArrayPtr(0), fRecPointListPtr(0)
9cc0deb1 39AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSProcessor(), fClusterizerPtr(0), fOutPtr(0),
40 fRecPointStructArrayPtr(0), fRecPointListPtr(0)
aac22523 41{
91b95d47 42 //Constructor
aac22523 43}
44
45AliHLTPHOSClusterizerComponent::~AliHLTPHOSClusterizerComponent()
46{
91b95d47 47 //Destructor
48
9cc0deb1 49 if (fClusterizerPtr)
91b95d47 50 {
51 delete fClusterizerPtr;
52 fClusterizerPtr = 0;
53 }
9cc0deb1 54
55 if (fRecPointListPtr)
91b95d47 56 {
57 delete fRecPointListPtr;
58 fRecPointListPtr = 0;
59 }
60
9cc0deb1 61 if (fRecPointStructArrayPtr)
91b95d47 62 {
9cc0deb1 63 for (int i = 0; i < 1000; i++)
64 {
65 // fRecPointStructArrayPtr[i].Del();
66 }
91b95d47 67 delete fRecPointStructArrayPtr;
68 fRecPointStructArrayPtr = 0;
69 }
9cc0deb1 70
aac22523 71}
72
9c9d15d6 73/*
9cc0deb1 74int
9c9d15d6 75AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent::Deinit()
76{
77 ////////// PTH WARNING you should Define a class AliHLTPHOSModuleProcessor
78}
79*/
80
9cc0deb1 81// PTH AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(const AliHLTPHOSClusterizerComponent &):AliHLTProcessor(),
82// fClusterizerPtr(0),
d2b84453 83// fOutPtr(0),
84// fRecPointStructArrayPtr(0),
85// fRecPointListPtr(0)
86//{
9cc0deb1 87//Copy constructor, not implemented
d2b84453 88//}
aac22523 89
6e709a0d 90int
aac22523 91AliHLTPHOSClusterizerComponent::Deinit()
92{
91b95d47 93 //Deinitialization
94
9cc0deb1 95 if (fClusterizerPtr)
91b95d47 96 {
97 delete fClusterizerPtr;
98 fClusterizerPtr = 0;
99 }
9cc0deb1 100
101 if (fRecPointListPtr)
91b95d47 102 {
103 delete fRecPointListPtr;
104 fRecPointListPtr = 0;
105 }
9cc0deb1 106
107 for (int i = 0; i < 1000; i++)
6e709a0d 108 {
9cc0deb1 109 // fRecPointStructArrayPtr[i].Del();
6e709a0d 110 }
9cc0deb1 111
112 if (fRecPointStructArrayPtr)
91b95d47 113 {
9cc0deb1 114 for (int i = 0; i < 1000; i++)
115 {
116 // fRecPointStructArrayPtr[i].Del();
117 }
91b95d47 118 delete fRecPointStructArrayPtr;
119 fRecPointStructArrayPtr = 0;
120 }
121
aac22523 122 return 0;
123}
124
6e709a0d 125int
aac22523 126AliHLTPHOSClusterizerComponent::DoDeinit()
127{
91b95d47 128 //Do deinitialization
aac22523 129 Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSClusterizerComponent DoDeinit");
130
131 return 0;
132}
133
134
9cc0deb1 135const Char_t*
aac22523 136AliHLTPHOSClusterizerComponent::GetComponentID()
137{
138 return "AliHltPhosClusterizer";
139}
140
141void
142AliHLTPHOSClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
143{
91b95d47 144 //Get datatypes for input
145 const AliHLTComponentDataType* pType=fgkInputDataTypes;
9cc0deb1 146 while (pType->fID!=0)
147 {
148 list.push_back(*pType);
149 pType++;
150 }
aac22523 151}
152
9cc0deb1 153AliHLTComponentDataType
aac22523 154AliHLTPHOSClusterizerComponent::GetOutputDataType()
155{
d2b84453 156 // return AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType;
157 return AliHLTPHOSDefinitions::fgkAliHLTClusterDataType;
aac22523 158}
159
160void
161AliHLTPHOSClusterizerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
162
163{
164 constBase = 30;
6e709a0d 165 inputMultiplier = 0.2;
aac22523 166}
167
9cc0deb1 168int
aac22523 169AliHLTPHOSClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
9cc0deb1 170 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
171 std::vector<AliHLTComponentBlockData>& outputBlocks)
aac22523 172{
91b95d47 173 //Do event
9cc0deb1 174
aac22523 175 UInt_t tSize = 0;
9cc0deb1 176 UInt_t offset = 0;
aac22523 177 UInt_t mysize = 0;
178 Int_t nRecPoints = 0;
9cc0deb1 179 Int_t nDigits = 0;
aac22523 180 Int_t index = 0;
9cc0deb1 181 Int_t j =0;
aac22523 182
183 AliHLTUInt8_t* outBPtr;
184 outBPtr = outputPtr;
9cc0deb1 185 const AliHLTComponentBlockData* iter = 0;
186 unsigned long ndx;
aac22523 187
9cc0deb1 188 AliHLTPHOSDigitContainerDataStruct *digitContainerPtr = 0;
189
190 //AliHLTPHOSRecPointContainerStruct *recPointContainerPtr = (AliHLTPHOSRecPointContainerStruct*)outBPtr;
191 fClusterizerPtr->SetRecPointContainer((AliHLTPHOSRecPointContainerStruct*)outBPtr);
192 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
aac22523 193 {
194 iter = blocks+ndx;
9cc0deb1 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++;
aac22523 214 }
9cc0deb1 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 )
aac22523 244 {
9cc0deb1 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;
aac22523 249 }
250
9cc0deb1 251
aac22523 252 size = tSize;
9cc0deb1 253// fClusterizerPtr->ResetCellEnergyArray();
aac22523 254
255 return 0;
256
257}
258
6e709a0d 259int
9be2600f 260AliHLTPHOSClusterizerComponent::DoInit(int argc, const char** argv )
aac22523 261{
91b95d47 262 //Do initialization
9cc0deb1 263 fAllDigitsPtr = new AliHLTPHOSDigitContainerDataStruct();
aac22523 264 fClusterizerPtr = new AliHLTPHOSClusterizer();
9cc0deb1 265 //fClusterizerPtr->SetNoCrazyness(true);
266 //
267 for (int i = 0; i < argc; i++)
6e709a0d 268 {
9cc0deb1 269 /*
6e709a0d 270 if(!strcmp("-threshold", argv[i]))
9cc0deb1 271 fClusterizerPtr->SetThreshold(atof(argv[i+1]));
6e709a0d 272 if(!strcmp("-clusterthreshold", argv[i]))
9cc0deb1 273 fClusterizerPtr->SetClusterThreshold(atof(argv[i+1]));
6e709a0d 274 if(!strcmp("-highgain", argv[i]))
9cc0deb1 275 fClusterizerPtr->SetHighGainFactor(atof(argv[i+1]));
6e709a0d 276 if(!strcmp("-lowgain", argv[i]))
9cc0deb1 277 fClusterizerPtr->SetLowGainFactor(atof(argv[i+1]));
6e709a0d 278 if(!strcmp("-arraysize", argv[i]))
9cc0deb1 279 fClusterizerPtr->SetArraySize(atoi(argv[i+1]));*/
6e709a0d 280 }
9cc0deb1 281 // fClusterizerPtr->ResetCellEnergyArray();
442af5b7 282 fRecPointListPtr = new AliHLTPHOSRecPointListDataStruct[N_ZROWS_MOD*N_XCOLUMNS_MOD];
aac22523 283 fRecPointStructArrayPtr = new AliHLTPHOSRecPointDataStruct[1000];
9cc0deb1 284 for (int i = 0; i < 1000; i++)
6e709a0d 285 {
286 fRecPointStructArrayPtr[i].fMultiplicity = atoi(argv[4])* atoi(argv[4]);
9cc0deb1 287 // fRecPointStructArrayPtr[i].New();
6e709a0d 288 }
9cc0deb1 289 /*
6e709a0d 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());
9cc0deb1 296 */
aac22523 297 return 0;
298}
299
300AliHLTComponent*
301AliHLTPHOSClusterizerComponent::Spawn()
302{
91b95d47 303 //Spawn a new AliHLTPHOSClusterizerComponent, for HLT framework
aac22523 304 return new AliHLTPHOSClusterizerComponent();
305}