1 // $Id: AliHLTCaloClusterAnalyser.cxx 35107 2009-09-30 01:45:06Z phille $
3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * All rights reserved. *
7 * Primary Authors: Oystein Djuvsland *
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 **************************************************************************/
19 * @file AliHLTCaloClusterAnalyser.cxx
20 * @author Oystein Djuvsland
22 * @brief Cluster analyser for Calo HLT
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
31 #include "AliHLTCaloClusterAnalyser.h"
32 #include "AliHLTCaloRecPointHeaderStruct.h"
33 #include "AliHLTCaloRecPointDataStruct.h"
34 #include "AliHLTCaloClusterDataStruct.h"
35 //#include "AliHLTCaloPhysicsAnalyzer.h"
36 #include "AliHLTCaloGeometry.h"
37 #include "AliESDCaloCluster.h"
42 #include "AliHLTCaloRecoParamHandler.h"
44 ClassImp(AliHLTCaloClusterAnalyser);
46 AliHLTCaloClusterAnalyser::AliHLTCaloClusterAnalyser() :
52 fCaloClusterDataPtr(0),
53 fCaloClusterHeaderPtr(0),
58 fHaveDistanceToBadChannel(false),
60 fClusterType(AliESDCaloCluster::kPHOSCluster),
63 //See header file for documentation
66 AliHLTCaloClusterAnalyser::~AliHLTCaloClusterAnalyser()
68 // See header file for class documentation
72 AliHLTCaloClusterAnalyser::SetCaloClusterData(AliHLTCaloClusterDataStruct *caloClusterDataPtr)
74 //see header file for documentation
75 fCaloClusterDataPtr = caloClusterDataPtr;
79 AliHLTCaloClusterAnalyser::SetRecPointArray(AliHLTCaloRecPointDataStruct **recPointDataPtr, Int_t nRecPoints)
81 fRecPointArray = recPointDataPtr;
82 fNRecPoints = nRecPoints;
86 AliHLTCaloClusterAnalyser::SetDigitDataArray(AliHLTCaloDigitDataStruct *digits)
88 // AliHLTCaloClusterizer cl("PHOS");
89 // cl.CheckDigits(fRecPointArray, digits, fNRecPoints);
90 fDigitDataArray = digits;
91 //cl.CheckDigits(fRecPointArray, fDigitDataArray, fNRecPoints);
95 AliHLTCaloClusterAnalyser::CalculateCenterOfGravity()
97 //see header file for documentation
104 AliHLTCaloDigitDataStruct *digit = 0;
108 for(Int_t iRecPoint=0; iRecPoint < fNRecPoints; iRecPoint++)
110 AliHLTCaloRecPointDataStruct *recPoint = fRecPointArray[iRecPoint];
111 // digit = &(recPoint->fDigits);
113 Int_t *digitIndexPtr = &(recPoint->fDigits);
118 /* Float_t maxAmp = 0;
121 for(iDigit = 0; iDigit < recPoint->fMultiplicity; iDigit++)
124 digit = &(fDigitDataArray[*digitIndexPtr]);
129 if (recPoint->fAmp > 0 && digit->fEnergy > 0)
131 Float_t w = TMath::Max( 0., fLogWeight + TMath::Log( digit->fEnergy / recPoint->fAmp ) ) ;
135 /* if(digit->fEnergy > maxAmp)
137 maxAmp = digit->fEnergy;
138 maxX = digit->fX;// + 0.5;
139 maxZ = digit->fZ;// + 0.5;
147 recPoint->fX = x/wtot ;
148 recPoint->fZ = z/wtot ;
154 // 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);
161 AliHLTCaloClusterAnalyser::CalculateRecPointMoments()
163 //See header file for documentation
168 AliHLTCaloClusterAnalyser::CalculateClusterMoments(AliHLTCaloRecPointDataStruct */*recPointPtr*/, AliHLTCaloClusterDataStruct* /*clusterPtr*/)
170 //See header file for documentation
176 AliHLTCaloClusterAnalyser::DeconvoluteClusters()
178 //See header file for documentation
183 AliHLTCaloClusterAnalyser::CreateClusters(Int_t nRecPoints, UInt_t availableSize, UInt_t& totSize)
185 //See header file for documentation
189 fLogWeight = fRecoParamsPtr->GetLogWeight();
192 fNRecPoints = nRecPoints;
196 HLTError("No geometry object is initialised, creation of clusters stopped");
200 CalculateCenterOfGravity();
202 // AliHLTCaloDigitDataStruct* digitPtr = &(recPointPtr->fDigits);
203 AliHLTCaloDigitDataStruct* digitPtr = 0;
205 AliHLTCaloClusterDataStruct* caloClusterPtr = 0;
210 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
212 if((availableSize - totSize) < sizeof(AliHLTCaloClusterDataStruct))
214 HLTError("Out of buffer: available size is: %d, total size used: %d", availableSize, totSize);
217 totSize += sizeof(AliHLTCaloClusterDataStruct);
219 caloClusterPtr = fCaloClusterDataPtr;
220 caloClusterPtr->fChi2 = 0;
221 caloClusterPtr->fClusterType = kUndef;
222 caloClusterPtr->fDispersion = 0;
223 caloClusterPtr->fDistanceToBadChannel = 0;
224 caloClusterPtr->fDistToBadChannel = 0;
225 caloClusterPtr->fEmcCpvDistance = 0;
226 caloClusterPtr->fEnergy = 0;
227 caloClusterPtr->fFitQuality = 0;
228 caloClusterPtr->fID = 0;
229 caloClusterPtr->fM02 = 0;
230 caloClusterPtr->fM20 = 0;
231 caloClusterPtr->fNCells = 0;
232 caloClusterPtr->fNExMax = 0;
233 caloClusterPtr->fTOF = 0;
234 caloClusterPtr->fTrackDx = 0;
235 caloClusterPtr->fTrackDz = 0;
237 AliHLTCaloRecPointDataStruct *recPointPtr = fRecPointArray[i];
239 AliHLTCaloGlobalCoordinate globalCoord;
240 fGeometry->GetGlobalCoordinates(*recPointPtr, globalCoord);
242 caloClusterPtr->fModule = recPointPtr->fModule;
243 caloClusterPtr->fGlobalPos[0] = globalCoord.fX;
244 caloClusterPtr->fGlobalPos[1] = globalCoord.fY;
245 caloClusterPtr->fGlobalPos[2] = globalCoord.fZ;
247 HLTDebug("Cluster local position: x = %f, z = %f, module = %d", recPointPtr->fX, recPointPtr->fZ, recPointPtr->fModule);
248 HLTDebug("Cluster global position: x = %f, y = %f, z = %f", globalCoord.fX, globalCoord.fY, globalCoord.fZ);
250 //caloClusterPtr->fNCells = 0;//recPointPtr->fMultiplicity;
251 caloClusterPtr->fNCells = recPointPtr->fMultiplicity;
253 caloClusterPtr->fClusterType = fClusterType;
254 // Int_t tmpSize = 0;//totSize + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
256 //TODO remove hardcoded 10;
257 memset(caloClusterPtr->fTracksMatched, 0xff, sizeof(Int_t)*10);
259 //Int_t tmpSize = totSize + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
260 UInt_t tmpSize = (caloClusterPtr->fNCells-1)*sizeof(AliHLTCaloCellDataStruct);
262 if((availableSize - totSize) < tmpSize)
264 HLTError("Out of buffer, available size is: %d, total size used: %d, extra size needed: %d", availableSize, totSize, tmpSize);
268 Int_t *digitIndexPtr = &(recPointPtr->fDigits);
271 AliHLTCaloCellDataStruct *cellPtr = &(caloClusterPtr->fCaloCells);
273 for(UInt_t j = 0; j < caloClusterPtr->fNCells; j++)
275 digitPtr = &(fDigitDataArray[*digitIndexPtr]);
276 fGeometry->GetCellAbsId(recPointPtr->fModule, digitPtr->fX, digitPtr->fZ, id);
278 cellPtr->fCellsAbsId= id;
279 cellPtr->fCellsAmpFraction = digitPtr->fEnergy/recPointPtr->fAmp;
280 //printf("Cell ID pointer: %x\n", cellIDPtr);
281 //printf("Cell Amp Pointer: %x\n", cellAmpFracPtr);
282 //printf("Cell pos: x = %d, z = %d\n", digitPtr->fX, digitPtr->fZ);
283 // printf("Cell ID: %d\n", cellPtr->fCellsAbsId);
284 //printf("Cell Amp: %f, pointer: %x\n", *cellAmpFracPtr, cellAmpFracPtr);
294 caloClusterPtr->fEnergy = fRecoParamsPtr->GetCorrectedEnergy(recPointPtr->fAmp);
298 caloClusterPtr->fEnergy = recPointPtr->fAmp;
301 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);
305 FitCluster(recPointPtr);
309 caloClusterPtr->fDispersion = 0;
310 caloClusterPtr->fFitQuality = 0;
311 caloClusterPtr->fM20 = 0;
312 caloClusterPtr->fM02 = 0;
317 caloClusterPtr->fEmcCpvDistance = GetCPVDistance(recPointPtr);
321 caloClusterPtr->fEmcCpvDistance = -1;
325 DoParticleIdentification(caloClusterPtr);
329 for(Int_t k = 0; k < AliPID::kSPECIESN; k++)
331 caloClusterPtr->fPID[k] = 0;
334 if(fHaveDistanceToBadChannel)
336 caloClusterPtr->fDistanceToBadChannel = GetDistanceToBadChannel(caloClusterPtr);
340 caloClusterPtr->fDistanceToBadChannel = -1;
343 caloClusterPtr->fClusterType = fClusterType;
344 //totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells)*(sizeof(Short_t) +sizeof(Float_t)-1);
345 //totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
346 //printf("CaloClusterPtr: %x, energy: %f\n", caloClusterPtr, caloClusterPtr->fEnergy);
348 // caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellAmpFracPtr);
349 //caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellIDPtr);
350 fCaloClusterDataPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellPtr);
351 recPointPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(digitPtr);
352 //digitPtr = &(recPointPtr->fDigits);