]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/CALO/AliHLTCaloClusterAnalyser.cxx
- fixing bug in cluster analyser
[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);
113
ea367f6a 114 for(iDigit = 0; iDigit < recPoint->fMultiplicity; iDigit++)
115 {
7c80a370 116
117 digit = &(fDigitDataArray[*digitIndexPtr]);
98baf84d 118
a6db7bcd 119 xi = digit->fX+0.5;
120 zi = digit->fZ+0.5;
98baf84d 121
ea367f6a 122 if (recPoint->fAmp > 0 && digit->fEnergy > 0)
123 {
124 Float_t w = TMath::Max( 0., fLogWeight + TMath::Log( digit->fEnergy / recPoint->fAmp ) ) ;
125 x += xi * w ;
126 z += zi * w ;
127 wtot += w ;
128 }
7c80a370 129 digitIndexPtr++;
ea367f6a 130 }
98baf84d 131
ea367f6a 132 if (wtot>0)
133 {
134 recPoint->fX = x/wtot ;
135 recPoint->fZ = z/wtot ;
136 }
137 else
138 {
139 recPoint->fAmp = 0;
140 }
ea367f6a 141 }
142 return 0;
143}
144
145
146Int_t
147AliHLTCaloClusterAnalyser::CalculateRecPointMoments()
cd9e2797 148{
ea367f6a 149 //See header file for documentation
150 return 0;
151}
152
153Int_t
154AliHLTCaloClusterAnalyser::CalculateClusterMoments(AliHLTCaloRecPointDataStruct */*recPointPtr*/, AliHLTCaloClusterDataStruct* /*clusterPtr*/)
155{
156 //See header file for documentation
157 return 0;
158}
159
160
161Int_t
162AliHLTCaloClusterAnalyser::DeconvoluteClusters()
163{
164 //See header file for documentation
165 return 0;
166}
167
168Int_t
7c80a370 169AliHLTCaloClusterAnalyser::CreateClusters(Int_t nRecPoints, UInt_t availableSize, UInt_t& totSize)
ea367f6a 170{
171 //See header file for documentation
172
73d6f579 173
7c80a370 174 fNRecPoints = nRecPoints;
175
176 if(fGeometry == 0)
177 {
178 HLTError("No geometry object is initialised, creation of clusters stopped");
179 }
180
181 CalculateCenterOfGravity();
182
ad44d760 183 // AliHLTCaloDigitDataStruct* digitPtr = &(recPointPtr->fDigits);
184 AliHLTCaloDigitDataStruct* digitPtr = 0;
185
73d6f579 186 AliHLTCaloClusterDataStruct* caloClusterPtr = 0;
7fdb2519 187
188 // Int_t id = -1;
ea367f6a 189 TVector3 globalPos;
190
191 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
192 {
73d6f579 193 if((availableSize - totSize) < sizeof(AliHLTCaloClusterDataStruct))
194 {
9a0cbaba 195 HLTError("Out of buffer: available size is: %d, total size used: %d", availableSize, totSize);
73d6f579 196 return -ENOBUFS;
197 }
7fdb2519 198 totSize += sizeof(AliHLTCaloClusterDataStruct);
73d6f579 199
200 caloClusterPtr = fCaloClusterDataPtr;
201
7c80a370 202 AliHLTCaloRecPointDataStruct *recPointPtr = fRecPointArray[i];
7c80a370 203
204 AliHLTCaloGlobalCoordinate globalCoord;
205 fGeometry->GetGlobalCoordinates(*recPointPtr, globalCoord);
ea367f6a 206
a6db7bcd 207 caloClusterPtr->fGlobalPos[0] = globalCoord.fX;
cd9e2797 208 caloClusterPtr->fGlobalPos[1] = globalCoord.fY;
a6db7bcd 209 caloClusterPtr->fGlobalPos[2] = globalCoord.fZ;
ea367f6a 210
ee72b4e5 211 HLTDebug("Cluster local position: x = %f, z = %f, module = %d", recPointPtr->fX, recPointPtr->fZ, recPointPtr->fModule);
212 HLTDebug("Cluster global position: x = %f, y = %f, z = %f", globalCoord.fX, globalCoord.fY, globalCoord.fZ);
213
7fdb2519 214 //caloClusterPtr->fNCells = 0;//recPointPtr->fMultiplicity;
215 caloClusterPtr->fNCells = recPointPtr->fMultiplicity;
cd9e2797 216
a6db7bcd 217 caloClusterPtr->fClusterType = fClusterType;
7fdb2519 218// Int_t tmpSize = 0;//totSize + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
a6db7bcd 219
2a24cbbe 220 //TODO remove hardcoded 10;
221 memset(caloClusterPtr->fTracksMatched, 0xff, sizeof(Int_t)*10);
222
9a0cbaba 223 //Int_t tmpSize = totSize + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
7fdb2519 224 Int_t tmpSize = (caloClusterPtr->fNCells-1)*sizeof(AliHLTCaloCellDataStruct);
cd9e2797 225
73d6f579 226 if((availableSize - totSize) < tmpSize)
227 {
9a0cbaba 228 HLTError("Out of buffer, available size is: %d, total size used: %d, extra size needed: %d", availableSize, totSize, tmpSize);
73d6f579 229 return -ENOBUFS;
230 }
cd9e2797 231 Int_t *digitIndexPtr = &(recPointPtr->fDigits);
232 Int_t id = 0;
233
7fdb2519 234 AliHLTCaloCellDataStruct *cellPtr = &(caloClusterPtr->fCaloCells);
235
ea367f6a 236 for(UInt_t j = 0; j < caloClusterPtr->fNCells; j++)
237 {
cd9e2797 238 digitPtr = &(fDigitDataArray[*digitIndexPtr]);
239 id++;
936dbe15 240 fGeometry->GetCellAbsId(recPointPtr->fModule, digitPtr->fX, digitPtr->fZ, id);
7fdb2519 241
242 cellPtr->fCellsAbsId= id;
243 cellPtr->fCellsAmpFraction = digitPtr->fEnergy/recPointPtr->fAmp;
cd9e2797 244 //printf("Cell ID pointer: %x\n", cellIDPtr);
245 //printf("Cell Amp Pointer: %x\n", cellAmpFracPtr);
9a0cbaba 246 //printf("Cell pos: x = %d, z = %d\n", digitPtr->fX, digitPtr->fZ);
247 //printf("Cell ID: %d, pointer: %x\n", *cellIDPtr, cellIDPtr);
248 //printf("Cell Amp: %f, pointer: %x\n", *cellAmpFracPtr, cellAmpFracPtr);
7fdb2519 249 cellPtr++;
cd9e2797 250 digitIndexPtr++;
251
ea367f6a 252 }
253
73d6f579 254 totSize += tmpSize;
255
ea367f6a 256 caloClusterPtr->fEnergy = recPointPtr->fAmp;
73d6f579 257
7fdb2519 258 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);
259
ea367f6a 260 if(fDoClusterFit)
261 {
262 FitCluster(recPointPtr);
263 }
264 else
265 {
266 caloClusterPtr->fDispersion = 0;
267 caloClusterPtr->fFitQuality = 0;
268 caloClusterPtr->fM20 = 0;
269 caloClusterPtr->fM02 = 0;
270
271 }
272 if(fHaveCPVInfo)
273 {
274 caloClusterPtr->fEmcCpvDistance = GetCPVDistance(recPointPtr);
275 }
276 else
277 {
278 caloClusterPtr->fEmcCpvDistance = -1;
279 }
280 if(fDoPID)
281 {
282 DoParticleIdentification(caloClusterPtr);
283 }
284 else
285 {
286 for(Int_t k = 0; k < AliPID::kSPECIESN; k++)
287 {
288 caloClusterPtr->fPID[k] = 0;
289 }
290 }
291 if(fHaveDistanceToBadChannel)
292 {
293 caloClusterPtr->fDistanceToBadChannel = GetDistanceToBadChannel(caloClusterPtr);
294 }
295 else
296 {
297 caloClusterPtr->fDistanceToBadChannel = -1;
298 }
299
73d6f579 300 caloClusterPtr->fClusterType = fClusterType;
cd9e2797 301 //totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells)*(sizeof(Short_t) +sizeof(Float_t)-1);
73d6f579 302 //totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
cd9e2797 303 //printf("CaloClusterPtr: %x, energy: %f\n", caloClusterPtr, caloClusterPtr->fEnergy);
304
ea367f6a 305 // caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellAmpFracPtr);
cd9e2797 306 //caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellIDPtr);
7fdb2519 307 fCaloClusterDataPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellPtr);
ea367f6a 308 recPointPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(digitPtr);
73d6f579 309 //digitPtr = &(recPointPtr->fDigits);
ea367f6a 310 }
98baf84d 311
312return fNRecPoints;
ea367f6a 313
314}
315