]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/CALO/AliHLTCaloClusterAnalyser.cxx
coverity fix, plus adding some debug info to the analysis macro
[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"
c1e4a18c 42#include "AliHLTCaloRecoParamHandler.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),
4b759e43 60#ifndef HAVE_NOT_ALIVCLUSTER // backward compatibility for r42844
c8fe2783 61 fClusterType(AliVCluster::kPHOSNeutral),
4b759e43 62#else
63 fClusterType(AliESDCaloCluster::kPHOSCluster),
64#endif
38a3b2ad 65 fRecoParamsPtr(0),
66 fCutOnSingleCellClusters(false),
67 fSingleCellEnergyCut(0.5)
ea367f6a 68{
69 //See header file for documentation
ea367f6a 70}
71
72AliHLTCaloClusterAnalyser::~AliHLTCaloClusterAnalyser()
73{
98baf84d 74 // See header file for class documentation
ea367f6a 75}
76
77void
7c80a370 78AliHLTCaloClusterAnalyser::SetCaloClusterData(AliHLTCaloClusterDataStruct *caloClusterDataPtr)
ea367f6a 79{
80 //see header file for documentation
81 fCaloClusterDataPtr = caloClusterDataPtr;
82}
7c80a370 83
ea367f6a 84void
7c80a370 85AliHLTCaloClusterAnalyser::SetRecPointArray(AliHLTCaloRecPointDataStruct **recPointDataPtr, Int_t nRecPoints)
ea367f6a 86{
7c80a370 87 fRecPointArray = recPointDataPtr;
88 fNRecPoints = nRecPoints;
89}
90
91void
f92543f5 92AliHLTCaloClusterAnalyser::SetDigitDataArray(AliHLTCaloDigitDataStruct **digits)
7c80a370 93{
94// AliHLTCaloClusterizer cl("PHOS");
95 // cl.CheckDigits(fRecPointArray, digits, fNRecPoints);
96 fDigitDataArray = digits;
97 //cl.CheckDigits(fRecPointArray, fDigitDataArray, fNRecPoints);
ea367f6a 98}
99
100Int_t
101AliHLTCaloClusterAnalyser::CalculateCenterOfGravity()
102{
103 //see header file for documentation
104 Float_t wtot = 0.;
105 Float_t x = 0.;
106 Float_t z = 0.;
107 Float_t xi = 0.;
108 Float_t zi = 0.;
109
110 AliHLTCaloDigitDataStruct *digit = 0;
ea367f6a 111
112 UInt_t iDigit = 0;
113
114 for(Int_t iRecPoint=0; iRecPoint < fNRecPoints; iRecPoint++)
115 {
7c80a370 116 AliHLTCaloRecPointDataStruct *recPoint = fRecPointArray[iRecPoint];
ad44d760 117 // digit = &(recPoint->fDigits);
98baf84d 118
7c80a370 119 Int_t *digitIndexPtr = &(recPoint->fDigits);
256f1bf0 120 wtot = 0;
121 x = 0;
122 z = 0;
123
c1e4a18c 124/* Float_t maxAmp = 0;
256f1bf0 125 Int_t maxX = 0;
c1e4a18c 126 Int_t maxZ = 0;*/
7a12c14d 127 if (fDigitDataArray[*digitIndexPtr])
128
129 for(iDigit = 0; iDigit < recPoint->fMultiplicity; iDigit++)
130 {
131
132 digit = fDigitDataArray[*digitIndexPtr];
133
134 xi = digit->fX;
135 zi = digit->fZ;
136
137 //xi = digit->fX+0.5;
138 //zi = digit->fZ+0.5;
139
140 if (recPoint->fAmp > 0 && digit->fEnergy > 0)
141 {
142 Float_t w = TMath::Max( 0., fLogWeight + TMath::Log( digit->fEnergy / recPoint->fAmp ) ) ;
143 x += xi * w ;
144 z += zi * w ;
145 wtot += w ;
146 /* if(digit->fEnergy > maxAmp)
147 {
148 maxAmp = digit->fEnergy;
149 maxX = digit->fX;// + 0.5;
150 maxZ = digit->fZ;// + 0.5;
151 }*/
152 }
153 digitIndexPtr++;
154 }
155
156 if (wtot>0)
157 {
158 recPoint->fX = x/wtot ;
159 recPoint->fZ = z/wtot ;
160 }
161 else
162 {
163 recPoint->fX = -9999;
164 recPoint->fZ =-9999;
165 // no good crashes depth with FP exception
166 //recPoint->fAmp = 0;
167 }
256f1bf0 168// 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 169 }
170 return 0;
171}
172
173
174Int_t
175AliHLTCaloClusterAnalyser::CalculateRecPointMoments()
cd9e2797 176{
ea367f6a 177 //See header file for documentation
178 return 0;
179}
180
181Int_t
182AliHLTCaloClusterAnalyser::CalculateClusterMoments(AliHLTCaloRecPointDataStruct */*recPointPtr*/, AliHLTCaloClusterDataStruct* /*clusterPtr*/)
183{
184 //See header file for documentation
185 return 0;
186}
187
188
189Int_t
190AliHLTCaloClusterAnalyser::DeconvoluteClusters()
191{
192 //See header file for documentation
193 return 0;
194}
195
196Int_t
7c80a370 197AliHLTCaloClusterAnalyser::CreateClusters(Int_t nRecPoints, UInt_t availableSize, UInt_t& totSize)
ea367f6a 198{
199 //See header file for documentation
200
c1e4a18c 201 if(fRecoParamsPtr)
202 {
203 fLogWeight = fRecoParamsPtr->GetLogWeight();
204 }
73d6f579 205
7c80a370 206 fNRecPoints = nRecPoints;
207
208 if(fGeometry == 0)
209 {
210 HLTError("No geometry object is initialised, creation of clusters stopped");
73cdb797 211 return -1;
7c80a370 212 }
213
214 CalculateCenterOfGravity();
215
ad44d760 216 // AliHLTCaloDigitDataStruct* digitPtr = &(recPointPtr->fDigits);
217 AliHLTCaloDigitDataStruct* digitPtr = 0;
218
73d6f579 219 AliHLTCaloClusterDataStruct* caloClusterPtr = 0;
7fdb2519 220
221 // Int_t id = -1;
ea367f6a 222 TVector3 globalPos;
223
224 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
225 {
73d6f579 226 if((availableSize - totSize) < sizeof(AliHLTCaloClusterDataStruct))
227 {
9a0cbaba 228 HLTError("Out of buffer: available size is: %d, total size used: %d", availableSize, totSize);
73d6f579 229 return -ENOBUFS;
230 }
38a3b2ad 231
232 AliHLTCaloRecPointDataStruct *recPointPtr = fRecPointArray[i];
233
234 if(fCutOnSingleCellClusters && recPointPtr->fAmp > fSingleCellEnergyCut && recPointPtr->fMultiplicity == 1) continue;
235
7fdb2519 236 totSize += sizeof(AliHLTCaloClusterDataStruct);
73d6f579 237
238 caloClusterPtr = fCaloClusterDataPtr;
34eb3256 239 caloClusterPtr->fChi2 = 0;
240 caloClusterPtr->fClusterType = kUndef;
241 caloClusterPtr->fDispersion = 0;
242 caloClusterPtr->fDistanceToBadChannel = 0;
243 caloClusterPtr->fDistToBadChannel = 0;
244 caloClusterPtr->fEmcCpvDistance = 0;
245 caloClusterPtr->fEnergy = 0;
246 caloClusterPtr->fFitQuality = 0;
247 caloClusterPtr->fID = 0;
248 caloClusterPtr->fM02 = 0;
249 caloClusterPtr->fM20 = 0;
250 caloClusterPtr->fNCells = 0;
251 caloClusterPtr->fNExMax = 0;
252 caloClusterPtr->fTOF = 0;
fe1a0255 253 caloClusterPtr->fTrackDx = -999;
254 caloClusterPtr->fTrackDz = -999;
7c80a370 255
256 AliHLTCaloGlobalCoordinate globalCoord;
03a0ff8a 257
258 // 0 = assume photon
259 fGeometry->GetGlobalCoordinates(*recPointPtr, globalCoord, 0);
ea367f6a 260
353c33d3 261 caloClusterPtr->fModule = recPointPtr->fModule;
a6db7bcd 262 caloClusterPtr->fGlobalPos[0] = globalCoord.fX;
cd9e2797 263 caloClusterPtr->fGlobalPos[1] = globalCoord.fY;
a6db7bcd 264 caloClusterPtr->fGlobalPos[2] = globalCoord.fZ;
ea367f6a 265
5259027d 266 HLTDebug("Cluster local position: x = %f, z = %f, module = %d", recPointPtr->fX, recPointPtr->fZ, recPointPtr->fModule);
267 HLTDebug("Cluster global position: x = %f, y = %f, z = %f", globalCoord.fX, globalCoord.fY, globalCoord.fZ);
ee72b4e5 268
7fdb2519 269 //caloClusterPtr->fNCells = 0;//recPointPtr->fMultiplicity;
270 caloClusterPtr->fNCells = recPointPtr->fMultiplicity;
cd9e2797 271
a6db7bcd 272 caloClusterPtr->fClusterType = fClusterType;
7fdb2519 273// Int_t tmpSize = 0;//totSize + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
a6db7bcd 274
2a24cbbe 275 //TODO remove hardcoded 10;
276 memset(caloClusterPtr->fTracksMatched, 0xff, sizeof(Int_t)*10);
277
9a0cbaba 278 //Int_t tmpSize = totSize + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
cefad3b2 279 UInt_t tmpSize = (caloClusterPtr->fNCells-1)*sizeof(AliHLTCaloCellDataStruct);
cd9e2797 280
73d6f579 281 if((availableSize - totSize) < tmpSize)
282 {
9a0cbaba 283 HLTError("Out of buffer, available size is: %d, total size used: %d, extra size needed: %d", availableSize, totSize, tmpSize);
73d6f579 284 return -ENOBUFS;
285 }
c1e4a18c 286
cd9e2797 287 Int_t *digitIndexPtr = &(recPointPtr->fDigits);
288 Int_t id = 0;
289
7fdb2519 290 AliHLTCaloCellDataStruct *cellPtr = &(caloClusterPtr->fCaloCells);
0a899b5c 291 Float_t maxTime = 0; //time of maximum amplitude cell is assigned to cluster
ea367f6a 292 for(UInt_t j = 0; j < caloClusterPtr->fNCells; j++)
293 {
f92543f5 294 digitPtr = fDigitDataArray[*digitIndexPtr];
936dbe15 295 fGeometry->GetCellAbsId(recPointPtr->fModule, digitPtr->fX, digitPtr->fZ, id);
7fdb2519 296
297 cellPtr->fCellsAbsId= id;
298 cellPtr->fCellsAmpFraction = digitPtr->fEnergy/recPointPtr->fAmp;
0a899b5c 299 if(digitPtr->fTime > maxTime) maxTime = digitPtr->fTime;
cd9e2797 300 //printf("Cell ID pointer: %x\n", cellIDPtr);
301 //printf("Cell Amp Pointer: %x\n", cellAmpFracPtr);
9a0cbaba 302 //printf("Cell pos: x = %d, z = %d\n", digitPtr->fX, digitPtr->fZ);
34eb3256 303// printf("Cell ID: %d\n", cellPtr->fCellsAbsId);
9a0cbaba 304 //printf("Cell Amp: %f, pointer: %x\n", *cellAmpFracPtr, cellAmpFracPtr);
7fdb2519 305 cellPtr++;
cd9e2797 306 digitIndexPtr++;
307
ea367f6a 308 }
309
73d6f579 310 totSize += tmpSize;
311
c1e4a18c 312 if(fRecoParamsPtr)
313 {
314 caloClusterPtr->fEnergy = fRecoParamsPtr->GetCorrectedEnergy(recPointPtr->fAmp);
315 }
316 else
317 {
318 caloClusterPtr->fEnergy = recPointPtr->fAmp;
319 }
34eb3256 320
afcce849 321 // Set the time of the maximum digit as cluster time
0a899b5c 322 //caloClusterPtr->fTOF = recPointPtr->fTime;
323 caloClusterPtr->fTOF = maxTime;
afcce849 324
325 HLTDebug("Cluster global position: x = %f, y = %f, z = %f, energy: %f, time: %f, number of cells: %d, cluster pointer: %x", globalCoord.fX, globalCoord.fY, globalCoord.fZ, caloClusterPtr->fEnergy, caloClusterPtr->fTOF, caloClusterPtr->fNCells, caloClusterPtr);
7fdb2519 326
ea367f6a 327 if(fDoClusterFit)
328 {
329 FitCluster(recPointPtr);
330 }
331 else
332 {
333 caloClusterPtr->fDispersion = 0;
334 caloClusterPtr->fFitQuality = 0;
335 caloClusterPtr->fM20 = 0;
336 caloClusterPtr->fM02 = 0;
337
338 }
339 if(fHaveCPVInfo)
340 {
341 caloClusterPtr->fEmcCpvDistance = GetCPVDistance(recPointPtr);
342 }
343 else
344 {
345 caloClusterPtr->fEmcCpvDistance = -1;
346 }
347 if(fDoPID)
348 {
349 DoParticleIdentification(caloClusterPtr);
350 }
351 else
352 {
00a38d07 353 for(Int_t k = 0; k < AliPID::kSPECIESCN; k++)
ea367f6a 354 {
355 caloClusterPtr->fPID[k] = 0;
356 }
357 }
358 if(fHaveDistanceToBadChannel)
359 {
360 caloClusterPtr->fDistanceToBadChannel = GetDistanceToBadChannel(caloClusterPtr);
361 }
362 else
363 {
364 caloClusterPtr->fDistanceToBadChannel = -1;
365 }
366
73d6f579 367 caloClusterPtr->fClusterType = fClusterType;
cd9e2797 368 //totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells)*(sizeof(Short_t) +sizeof(Float_t)-1);
73d6f579 369 //totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
cd9e2797 370 //printf("CaloClusterPtr: %x, energy: %f\n", caloClusterPtr, caloClusterPtr->fEnergy);
371
ea367f6a 372 // caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellAmpFracPtr);
cd9e2797 373 //caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellIDPtr);
7fdb2519 374 fCaloClusterDataPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellPtr);
ea367f6a 375 recPointPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(digitPtr);
73d6f579 376 //digitPtr = &(recPointPtr->fDigits);
ea367f6a 377 }
98baf84d 378
379return fNRecPoints;
ea367f6a 380
381}
382