]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/CALO/AliHLTCaloClusterAnalyser.cxx
Unload the VZERO digits per event
[u/mrichter/AliRoot.git] / HLT / CALO / AliHLTCaloClusterAnalyser.cxx
CommitLineData
ea367f6a 1// $Id: AliHLTCaloClusterAnalyser.cxx 35107 2009-09-30 01:45:06Z phille $
2
3/**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * All rights reserved. *
6 * *
7 * Primary Authors: Oystein Djuvsland *
8 * *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
17
18/**
19 * @file AliHLTCaloClusterAnalyser.cxx
20 * @author Oystein Djuvsland
21 * @date
22 * @brief Cluster analyser for Calo HLT
23 */
24
25// see header file for class documentation
26// or
27// refer to README to build package
28// or
29// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31#include "AliHLTCaloClusterAnalyser.h"
32#include "AliHLTCaloRecPointHeaderStruct.h"
33#include "AliHLTCaloRecPointDataStruct.h"
34#include "AliHLTCaloClusterDataStruct.h"
35//#include "AliHLTCaloPhysicsAnalyzer.h"
7c80a370 36#include "AliHLTCaloGeometry.h"
ea367f6a 37#include "AliESDCaloCluster.h"
38#include "TMath.h"
39#include "TVector3.h"
73d6f579 40#include "TH1F.h"
41#include "TFile.h"
7c80a370 42#include "AliHLTCaloClusterizer.h"
ea367f6a 43
44ClassImp(AliHLTCaloClusterAnalyser);
45
7c80a370 46AliHLTCaloClusterAnalyser::AliHLTCaloClusterAnalyser() :
ea367f6a 47 // AliHLTCaloBase(),
7c80a370 48 fLogWeight(4.5),
49 fRecPointArray(0),
50 fDigitDataArray(0),
ea367f6a 51 fNRecPoints(0),
52 fCaloClusterDataPtr(0),
53 fCaloClusterHeaderPtr(0),
ea367f6a 54 //fAnalyzerPtr(0),
55 fDoClusterFit(false),
56 fHaveCPVInfo(false),
57 fDoPID(false),
7c80a370 58 fHaveDistanceToBadChannel(false),
73d6f579 59 fGeometry(0),
60 fClusterType(AliESDCaloCluster::kPHOSCluster)
ea367f6a 61{
62 //See header file for documentation
ea367f6a 63}
64
65AliHLTCaloClusterAnalyser::~AliHLTCaloClusterAnalyser()
66{
98baf84d 67 // See header file for class documentation
ea367f6a 68}
69
70void
7c80a370 71AliHLTCaloClusterAnalyser::SetCaloClusterData(AliHLTCaloClusterDataStruct *caloClusterDataPtr)
ea367f6a 72{
73 //see header file for documentation
74 fCaloClusterDataPtr = caloClusterDataPtr;
75}
7c80a370 76
ea367f6a 77void
7c80a370 78AliHLTCaloClusterAnalyser::SetRecPointArray(AliHLTCaloRecPointDataStruct **recPointDataPtr, Int_t nRecPoints)
ea367f6a 79{
7c80a370 80 fRecPointArray = recPointDataPtr;
81 fNRecPoints = nRecPoints;
82}
83
84void
85AliHLTCaloClusterAnalyser::SetDigitDataArray(AliHLTCaloDigitDataStruct *digits)
86{
87// AliHLTCaloClusterizer cl("PHOS");
88 // cl.CheckDigits(fRecPointArray, digits, fNRecPoints);
89 fDigitDataArray = digits;
90 //cl.CheckDigits(fRecPointArray, fDigitDataArray, fNRecPoints);
ea367f6a 91}
92
93Int_t
94AliHLTCaloClusterAnalyser::CalculateCenterOfGravity()
95{
96 //see header file for documentation
97 Float_t wtot = 0.;
98 Float_t x = 0.;
99 Float_t z = 0.;
100 Float_t xi = 0.;
101 Float_t zi = 0.;
102
103 AliHLTCaloDigitDataStruct *digit = 0;
ea367f6a 104
105 UInt_t iDigit = 0;
106
107 for(Int_t iRecPoint=0; iRecPoint < fNRecPoints; iRecPoint++)
108 {
7c80a370 109 AliHLTCaloRecPointDataStruct *recPoint = fRecPointArray[iRecPoint];
ad44d760 110 // digit = &(recPoint->fDigits);
98baf84d 111
7c80a370 112 Int_t *digitIndexPtr = &(recPoint->fDigits);
256f1bf0 113 wtot = 0;
114 x = 0;
115 z = 0;
116
117 /*Float_t maxAmp = 0;
118 Int_t maxX = 0;
119 Int_t maxZ = 0;
120 */for(iDigit = 0; iDigit < recPoint->fMultiplicity; iDigit++)
ea367f6a 121 {
7c80a370 122
123 digit = &(fDigitDataArray[*digitIndexPtr]);
98baf84d 124
a6db7bcd 125 xi = digit->fX+0.5;
126 zi = digit->fZ+0.5;
98baf84d 127
ea367f6a 128 if (recPoint->fAmp > 0 && digit->fEnergy > 0)
129 {
130 Float_t w = TMath::Max( 0., fLogWeight + TMath::Log( digit->fEnergy / recPoint->fAmp ) ) ;
131 x += xi * w ;
132 z += zi * w ;
133 wtot += w ;
256f1bf0 134/* if(digit->fEnergy > maxAmp)
135 {
136 maxAmp = digit->fEnergy;
137 maxX = digit->fX + 0.5;
138 maxZ = digit->fZ + 0.5;
139 }*/
ea367f6a 140 }
7c80a370 141 digitIndexPtr++;
ea367f6a 142 }
98baf84d 143
ea367f6a 144 if (wtot>0)
145 {
146 recPoint->fX = x/wtot ;
147 recPoint->fZ = z/wtot ;
148 }
149 else
150 {
151 recPoint->fAmp = 0;
152 }
256f1bf0 153// printf("Max digit: E = %f, x = %d, z= %d, cluster: E = %f, x = %f, z = %f\n" , maxAmp, maxX, maxZ, recPoint->fAmp, recPoint->fX, recPoint->fZ);
ea367f6a 154 }
155 return 0;
156}
157
158
159Int_t
160AliHLTCaloClusterAnalyser::CalculateRecPointMoments()
cd9e2797 161{
ea367f6a 162 //See header file for documentation
163 return 0;
164}
165
166Int_t
167AliHLTCaloClusterAnalyser::CalculateClusterMoments(AliHLTCaloRecPointDataStruct */*recPointPtr*/, AliHLTCaloClusterDataStruct* /*clusterPtr*/)
168{
169 //See header file for documentation
170 return 0;
171}
172
173
174Int_t
175AliHLTCaloClusterAnalyser::DeconvoluteClusters()
176{
177 //See header file for documentation
178 return 0;
179}
180
181Int_t
7c80a370 182AliHLTCaloClusterAnalyser::CreateClusters(Int_t nRecPoints, UInt_t availableSize, UInt_t& totSize)
ea367f6a 183{
184 //See header file for documentation
185
73d6f579 186
7c80a370 187 fNRecPoints = nRecPoints;
188
189 if(fGeometry == 0)
190 {
191 HLTError("No geometry object is initialised, creation of clusters stopped");
192 }
193
194 CalculateCenterOfGravity();
195
ad44d760 196 // AliHLTCaloDigitDataStruct* digitPtr = &(recPointPtr->fDigits);
197 AliHLTCaloDigitDataStruct* digitPtr = 0;
198
73d6f579 199 AliHLTCaloClusterDataStruct* caloClusterPtr = 0;
7fdb2519 200
201 // Int_t id = -1;
ea367f6a 202 TVector3 globalPos;
203
204 for(Int_t i = 0; i < fNRecPoints; i++) //TODO needs fix when we start unfolding (number of clusters not necessarily same as number of recpoints gotten from the clusterizer
205 {
73d6f579 206 if((availableSize - totSize) < sizeof(AliHLTCaloClusterDataStruct))
207 {
9a0cbaba 208 HLTError("Out of buffer: available size is: %d, total size used: %d", availableSize, totSize);
73d6f579 209 return -ENOBUFS;
210 }
7fdb2519 211 totSize += sizeof(AliHLTCaloClusterDataStruct);
73d6f579 212
213 caloClusterPtr = fCaloClusterDataPtr;
214
7c80a370 215 AliHLTCaloRecPointDataStruct *recPointPtr = fRecPointArray[i];
7c80a370 216
217 AliHLTCaloGlobalCoordinate globalCoord;
218 fGeometry->GetGlobalCoordinates(*recPointPtr, globalCoord);
ea367f6a 219
a6db7bcd 220 caloClusterPtr->fGlobalPos[0] = globalCoord.fX;
cd9e2797 221 caloClusterPtr->fGlobalPos[1] = globalCoord.fY;
a6db7bcd 222 caloClusterPtr->fGlobalPos[2] = globalCoord.fZ;
ea367f6a 223
ee72b4e5 224 HLTDebug("Cluster local position: x = %f, z = %f, module = %d", recPointPtr->fX, recPointPtr->fZ, recPointPtr->fModule);
225 HLTDebug("Cluster global position: x = %f, y = %f, z = %f", globalCoord.fX, globalCoord.fY, globalCoord.fZ);
226
7fdb2519 227 //caloClusterPtr->fNCells = 0;//recPointPtr->fMultiplicity;
228 caloClusterPtr->fNCells = recPointPtr->fMultiplicity;
cd9e2797 229
a6db7bcd 230 caloClusterPtr->fClusterType = fClusterType;
7fdb2519 231// Int_t tmpSize = 0;//totSize + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
a6db7bcd 232
2a24cbbe 233 //TODO remove hardcoded 10;
234 memset(caloClusterPtr->fTracksMatched, 0xff, sizeof(Int_t)*10);
235
9a0cbaba 236 //Int_t tmpSize = totSize + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
cefad3b2 237 UInt_t tmpSize = (caloClusterPtr->fNCells-1)*sizeof(AliHLTCaloCellDataStruct);
cd9e2797 238
73d6f579 239 if((availableSize - totSize) < tmpSize)
240 {
9a0cbaba 241 HLTError("Out of buffer, available size is: %d, total size used: %d, extra size needed: %d", availableSize, totSize, tmpSize);
73d6f579 242 return -ENOBUFS;
243 }
cd9e2797 244 Int_t *digitIndexPtr = &(recPointPtr->fDigits);
245 Int_t id = 0;
246
7fdb2519 247 AliHLTCaloCellDataStruct *cellPtr = &(caloClusterPtr->fCaloCells);
248
ea367f6a 249 for(UInt_t j = 0; j < caloClusterPtr->fNCells; j++)
250 {
cd9e2797 251 digitPtr = &(fDigitDataArray[*digitIndexPtr]);
252 id++;
936dbe15 253 fGeometry->GetCellAbsId(recPointPtr->fModule, digitPtr->fX, digitPtr->fZ, id);
7fdb2519 254
255 cellPtr->fCellsAbsId= id;
256 cellPtr->fCellsAmpFraction = digitPtr->fEnergy/recPointPtr->fAmp;
cd9e2797 257 //printf("Cell ID pointer: %x\n", cellIDPtr);
258 //printf("Cell Amp Pointer: %x\n", cellAmpFracPtr);
9a0cbaba 259 //printf("Cell pos: x = %d, z = %d\n", digitPtr->fX, digitPtr->fZ);
260 //printf("Cell ID: %d, pointer: %x\n", *cellIDPtr, cellIDPtr);
261 //printf("Cell Amp: %f, pointer: %x\n", *cellAmpFracPtr, cellAmpFracPtr);
7fdb2519 262 cellPtr++;
cd9e2797 263 digitIndexPtr++;
264
ea367f6a 265 }
266
73d6f579 267 totSize += tmpSize;
268
ea367f6a 269 caloClusterPtr->fEnergy = recPointPtr->fAmp;
73d6f579 270
7fdb2519 271 HLTDebug("Cluster global position: x = %f, y = %f, z = %f, energy: %f, number of cells: %d, cluster pointer: %x", globalCoord.fX, globalCoord.fY, globalCoord.fZ, caloClusterPtr->fEnergy, caloClusterPtr->fNCells, caloClusterPtr);
272
ea367f6a 273 if(fDoClusterFit)
274 {
275 FitCluster(recPointPtr);
276 }
277 else
278 {
279 caloClusterPtr->fDispersion = 0;
280 caloClusterPtr->fFitQuality = 0;
281 caloClusterPtr->fM20 = 0;
282 caloClusterPtr->fM02 = 0;
283
284 }
285 if(fHaveCPVInfo)
286 {
287 caloClusterPtr->fEmcCpvDistance = GetCPVDistance(recPointPtr);
288 }
289 else
290 {
291 caloClusterPtr->fEmcCpvDistance = -1;
292 }
293 if(fDoPID)
294 {
295 DoParticleIdentification(caloClusterPtr);
296 }
297 else
298 {
299 for(Int_t k = 0; k < AliPID::kSPECIESN; k++)
300 {
301 caloClusterPtr->fPID[k] = 0;
302 }
303 }
304 if(fHaveDistanceToBadChannel)
305 {
306 caloClusterPtr->fDistanceToBadChannel = GetDistanceToBadChannel(caloClusterPtr);
307 }
308 else
309 {
310 caloClusterPtr->fDistanceToBadChannel = -1;
311 }
312
73d6f579 313 caloClusterPtr->fClusterType = fClusterType;
cd9e2797 314 //totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells)*(sizeof(Short_t) +sizeof(Float_t)-1);
73d6f579 315 //totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
cd9e2797 316 //printf("CaloClusterPtr: %x, energy: %f\n", caloClusterPtr, caloClusterPtr->fEnergy);
317
ea367f6a 318 // caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellAmpFracPtr);
cd9e2797 319 //caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellIDPtr);
7fdb2519 320 fCaloClusterDataPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellPtr);
ea367f6a 321 recPointPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(digitPtr);
73d6f579 322 //digitPtr = &(recPointPtr->fDigits);
ea367f6a 323 }
98baf84d 324
325return fNRecPoints;
ea367f6a 326
327}
328