]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx
new classes for cosmic calibration
[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
26 using namespace std;
27
28
29 const AliHLTComponentDataType AliHLTPHOSClusterizerComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
30
31 AliHLTPHOSClusterizerComponent gAliHLTPHOSClusterizerComponent;
32
33 //AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSBase(), AliHLTProcessor(), fClusterizerPtr(0), fOutPtr(0), 
34 //                                                               fRecPointStructArrayPtr(0), fRecPointListPtr(0)
35 AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSProcessor(), fClusterizerPtr(0), fOutPtr(0), 
36                                                                   fRecPointStructArrayPtr(0), fRecPointListPtr(0)
37 {
38   //Constructor
39 }
40
41 AliHLTPHOSClusterizerComponent::~AliHLTPHOSClusterizerComponent()
42 {
43   //Destructor
44
45   if(fClusterizerPtr)
46     {
47       delete fClusterizerPtr;
48       fClusterizerPtr = 0;
49     }
50   
51   if(fRecPointListPtr)
52     {
53       delete fRecPointListPtr;
54       fRecPointListPtr = 0;
55     }
56
57   if(fRecPointStructArrayPtr)
58     {
59       for(int i = 0; i < 1000; i++) 
60         {
61           fRecPointStructArrayPtr[i].Del();
62         }
63       delete fRecPointStructArrayPtr;
64       fRecPointStructArrayPtr = 0;
65     }
66   
67 }
68
69 /*
70 int 
71 AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent::Deinit()
72 {
73   ////////// PTH WARNING you should Define a class AliHLTPHOSModuleProcessor
74 }
75 */
76
77 // PTH AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(const AliHLTPHOSClusterizerComponent &):AliHLTProcessor(), 
78 //                                                                                                     fClusterizerPtr(0), 
79 //                                                                                                     fOutPtr(0),
80 //                                                                                                     fRecPointStructArrayPtr(0),
81 //                                                                                                     fRecPointListPtr(0)
82 //{
83   //Copy constructor, not implemented
84 //}
85
86 int
87 AliHLTPHOSClusterizerComponent::Deinit()
88 {
89   //Deinitialization
90
91   if(fClusterizerPtr)
92     {
93       delete fClusterizerPtr;
94       fClusterizerPtr = 0;
95     }
96   
97   if(fRecPointListPtr)
98     {
99       delete fRecPointListPtr;
100       fRecPointListPtr = 0;
101     }
102   
103   for(int i = 0; i < 1000; i++) 
104     {
105       fRecPointStructArrayPtr[i].Del();
106     }
107   
108   if(fRecPointStructArrayPtr)
109     {
110       for(int i = 0; i < 1000; i++) 
111         {
112           fRecPointStructArrayPtr[i].Del();
113         }
114       delete fRecPointStructArrayPtr;
115       fRecPointStructArrayPtr = 0;
116     }
117
118
119
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     list.push_back(*pType);
148     pType++;
149   }
150 }
151
152 AliHLTComponentDataType 
153 AliHLTPHOSClusterizerComponent::GetOutputDataType()
154 {
155   //  return AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType;
156   return AliHLTPHOSDefinitions::fgkAliHLTClusterDataType;
157 }
158
159 void
160 AliHLTPHOSClusterizerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
161
162 {
163   constBase = 30;
164   inputMultiplier = 0.2;
165 }
166
167 int 
168 AliHLTPHOSClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
169                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
170                                         std::vector<AliHLTComponentBlockData>& outputBlocks)
171 {
172   //Do event
173    
174   UInt_t tSize            = 0;
175   UInt_t offset           = 0; 
176   UInt_t mysize           = 0;
177   Int_t nRecPoints        = 0;
178   Int_t index             = 0;
179
180   AliHLTUInt8_t* outBPtr;
181   outBPtr = outputPtr;
182   const AliHLTComponentBlockData* iter = 0; 
183   unsigned long ndx; 
184
185   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
186     {
187       iter = blocks+ndx;
188       
189       if(iter->fDataType != AliHLTPHOSDefinitions::fgkCellEnergyDataType)
190         {
191           cout << "Warning: data type is not fgkCellEnergyDataType " << endl;
192           continue;
193         }
194       index = fClusterizerPtr->BuildCellEnergyArray( reinterpret_cast<AliHLTPHOSRcuCellEnergyDataStruct*>(iter->fPtr),
195                                                      fRecPointListPtr);
196       
197     }
198  
199   nRecPoints = fClusterizerPtr->CreateRecPointStructArray(fRecPointStructArrayPtr, fRecPointListPtr, index);
200   
201   cout << "Number of clusters found: " << nRecPoints << endl;
202   
203   for(Int_t i = 0; i < nRecPoints; i++)
204     {
205       mysize = 0;
206       offset = tSize;
207       
208       fOutPtr =  (AliHLTPHOSClusterDataStruct*)outBPtr;
209       fClusterizerPtr->CalculateCenterOfGravity(&fRecPointStructArrayPtr[i]);
210       //      fClusterizerPtr->CalculateMoments(&fRecPointStructArrayPtr[i], 0);
211       //     fClusterizerPtr->ClusterizeStruct(&fRecPointStructArrayPtr[i], fOutPtr);
212
213       mysize += sizeof(AliHLTPHOSClusterDataStruct);
214       
215       AliHLTComponentBlockData bd;
216       FillBlockData( bd );
217       bd.fOffset = offset;
218       bd.fSize = mysize;
219       // PTH      bd.fDataType = AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType;
220       bd.fDataType = AliHLTPHOSDefinitions::fgkAliHLTClusterDataType;
221       bd.fSpecification = 0xFFFFFFFF;
222       outputBlocks.push_back( bd );
223        
224       tSize += mysize;
225       outBPtr += mysize;
226       
227       if( tSize > size )
228         {
229           Logging( kHLTLogFatal, "HLT::AliHLTPHOSClusterizerComponent::DoEvent", "Too much data",
230                    "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
231                    , tSize, size );
232           return EMSGSIZE;
233         }
234     }
235
236   size = tSize;
237   fClusterizerPtr->ResetCellEnergyArray();
238
239   return 0;
240
241 }
242
243 int
244 AliHLTPHOSClusterizerComponent::DoInit(int argc, const char** argv )
245 {
246   //Do initialization
247   fClusterizerPtr = new AliHLTPHOSClusterizer();
248   for(int i = 0; i < argc; i++)
249     {
250       if(!strcmp("-threshold", argv[i]))
251         fClusterizerPtr->SetThreshold(atof(argv[i+1]));
252       if(!strcmp("-clusterthreshold", argv[i]))
253         fClusterizerPtr->SetClusterThreshold(atof(argv[i+1]));
254       if(!strcmp("-highgain", argv[i]))
255         fClusterizerPtr->SetHighGainFactor(atof(argv[i+1]));
256       if(!strcmp("-lowgain", argv[i]))
257         fClusterizerPtr->SetLowGainFactor(atof(argv[i+1]));
258       if(!strcmp("-arraysize", argv[i]))
259         fClusterizerPtr->SetArraySize(atoi(argv[i+1]));
260     }
261   fClusterizerPtr->ResetCellEnergyArray();
262   fRecPointListPtr = new AliHLTPHOSRecPointListDataStruct[N_ZROWS_MOD*N_XCOLUMNS_MOD];
263   fRecPointStructArrayPtr = new AliHLTPHOSRecPointDataStruct[1000];
264   for(int i = 0; i < 1000; i++) 
265     {
266       fRecPointStructArrayPtr[i].fMultiplicity = atoi(argv[4])* atoi(argv[4]);
267       fRecPointStructArrayPtr[i].New();
268     }
269   printf("Clusterizer component started with:\n");
270   printf(" Cell threshold:     %f\n", fClusterizerPtr->GetThreshold());
271   printf(" Cluster threshold:  %f\n", fClusterizerPtr->GetClusterThreshold());
272   printf(" High gain factor:   %f\n", fClusterizerPtr->GetHighGainFactor());
273   printf(" Low gain factor:    %f\n", fClusterizerPtr->GetLowGainFactor());
274   printf(" Cluster array size: %d\n\n", fClusterizerPtr->GetArraySize());
275
276   return 0;
277 }
278
279 AliHLTComponent*
280 AliHLTPHOSClusterizerComponent::Spawn()
281 {
282   //Spawn a new AliHLTPHOSClusterizerComponent, for HLT framework
283   return new AliHLTPHOSClusterizerComponent();
284 }