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 "AliHLTCaloClusterizer.h"
44 ClassImp(AliHLTCaloClusterAnalyser);
46 AliHLTCaloClusterAnalyser::AliHLTCaloClusterAnalyser() :
52 fCaloClusterDataPtr(0),
53 fCaloClusterHeaderPtr(0),
58 fHaveDistanceToBadChannel(false),
60 fClusterType(AliESDCaloCluster::kPHOSCluster)
62 //See header file for documentation
65 AliHLTCaloClusterAnalyser::~AliHLTCaloClusterAnalyser()
67 // See header file for class documentation
71 AliHLTCaloClusterAnalyser::SetCaloClusterData(AliHLTCaloClusterDataStruct *caloClusterDataPtr)
73 //see header file for documentation
74 fCaloClusterDataPtr = caloClusterDataPtr;
78 AliHLTCaloClusterAnalyser::SetRecPointArray(AliHLTCaloRecPointDataStruct **recPointDataPtr, Int_t nRecPoints)
80 fRecPointArray = recPointDataPtr;
81 fNRecPoints = nRecPoints;
85 AliHLTCaloClusterAnalyser::SetDigitDataArray(AliHLTCaloDigitDataStruct *digits)
87 // AliHLTCaloClusterizer cl("PHOS");
88 // cl.CheckDigits(fRecPointArray, digits, fNRecPoints);
89 fDigitDataArray = digits;
90 //cl.CheckDigits(fRecPointArray, fDigitDataArray, fNRecPoints);
94 AliHLTCaloClusterAnalyser::CalculateCenterOfGravity()
96 //see header file for documentation
103 AliHLTCaloDigitDataStruct *digit = 0;
107 for(Int_t iRecPoint=0; iRecPoint < fNRecPoints; iRecPoint++)
109 AliHLTCaloRecPointDataStruct *recPoint = fRecPointArray[iRecPoint];
110 // digit = &(recPoint->fDigits);
112 Int_t *digitIndexPtr = &(recPoint->fDigits);
117 /*Float_t maxAmp = 0;
120 */for(iDigit = 0; iDigit < recPoint->fMultiplicity; iDigit++)
123 digit = &(fDigitDataArray[*digitIndexPtr]);
128 if (recPoint->fAmp > 0 && digit->fEnergy > 0)
130 Float_t w = TMath::Max( 0., fLogWeight + TMath::Log( digit->fEnergy / recPoint->fAmp ) ) ;
134 /* if(digit->fEnergy > maxAmp)
136 maxAmp = digit->fEnergy;
137 maxX = digit->fX + 0.5;
138 maxZ = digit->fZ + 0.5;
146 recPoint->fX = x/wtot ;
147 recPoint->fZ = z/wtot ;
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);
160 AliHLTCaloClusterAnalyser::CalculateRecPointMoments()
162 //See header file for documentation
167 AliHLTCaloClusterAnalyser::CalculateClusterMoments(AliHLTCaloRecPointDataStruct */*recPointPtr*/, AliHLTCaloClusterDataStruct* /*clusterPtr*/)
169 //See header file for documentation
175 AliHLTCaloClusterAnalyser::DeconvoluteClusters()
177 //See header file for documentation
182 AliHLTCaloClusterAnalyser::CreateClusters(Int_t nRecPoints, UInt_t availableSize, UInt_t& totSize)
184 //See header file for documentation
187 fNRecPoints = nRecPoints;
191 HLTError("No geometry object is initialised, creation of clusters stopped");
194 CalculateCenterOfGravity();
196 // AliHLTCaloDigitDataStruct* digitPtr = &(recPointPtr->fDigits);
197 AliHLTCaloDigitDataStruct* digitPtr = 0;
199 AliHLTCaloClusterDataStruct* caloClusterPtr = 0;
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
206 if((availableSize - totSize) < sizeof(AliHLTCaloClusterDataStruct))
208 HLTError("Out of buffer: available size is: %d, total size used: %d", availableSize, totSize);
211 totSize += sizeof(AliHLTCaloClusterDataStruct);
213 caloClusterPtr = fCaloClusterDataPtr;
215 AliHLTCaloRecPointDataStruct *recPointPtr = fRecPointArray[i];
217 AliHLTCaloGlobalCoordinate globalCoord;
218 fGeometry->GetGlobalCoordinates(*recPointPtr, globalCoord);
220 caloClusterPtr->fGlobalPos[0] = globalCoord.fX;
221 caloClusterPtr->fGlobalPos[1] = globalCoord.fY;
222 caloClusterPtr->fGlobalPos[2] = globalCoord.fZ;
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);
227 //caloClusterPtr->fNCells = 0;//recPointPtr->fMultiplicity;
228 caloClusterPtr->fNCells = recPointPtr->fMultiplicity;
230 caloClusterPtr->fClusterType = fClusterType;
231 // Int_t tmpSize = 0;//totSize + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
233 //TODO remove hardcoded 10;
234 memset(caloClusterPtr->fTracksMatched, 0xff, sizeof(Int_t)*10);
236 //Int_t tmpSize = totSize + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
237 UInt_t tmpSize = (caloClusterPtr->fNCells-1)*sizeof(AliHLTCaloCellDataStruct);
239 if((availableSize - totSize) < tmpSize)
241 HLTError("Out of buffer, available size is: %d, total size used: %d, extra size needed: %d", availableSize, totSize, tmpSize);
244 Int_t *digitIndexPtr = &(recPointPtr->fDigits);
247 AliHLTCaloCellDataStruct *cellPtr = &(caloClusterPtr->fCaloCells);
249 for(UInt_t j = 0; j < caloClusterPtr->fNCells; j++)
251 digitPtr = &(fDigitDataArray[*digitIndexPtr]);
253 fGeometry->GetCellAbsId(recPointPtr->fModule, digitPtr->fX, digitPtr->fZ, id);
255 cellPtr->fCellsAbsId= id;
256 cellPtr->fCellsAmpFraction = digitPtr->fEnergy/recPointPtr->fAmp;
257 //printf("Cell ID pointer: %x\n", cellIDPtr);
258 //printf("Cell Amp Pointer: %x\n", cellAmpFracPtr);
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);
269 caloClusterPtr->fEnergy = recPointPtr->fAmp;
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);
275 FitCluster(recPointPtr);
279 caloClusterPtr->fDispersion = 0;
280 caloClusterPtr->fFitQuality = 0;
281 caloClusterPtr->fM20 = 0;
282 caloClusterPtr->fM02 = 0;
287 caloClusterPtr->fEmcCpvDistance = GetCPVDistance(recPointPtr);
291 caloClusterPtr->fEmcCpvDistance = -1;
295 DoParticleIdentification(caloClusterPtr);
299 for(Int_t k = 0; k < AliPID::kSPECIESN; k++)
301 caloClusterPtr->fPID[k] = 0;
304 if(fHaveDistanceToBadChannel)
306 caloClusterPtr->fDistanceToBadChannel = GetDistanceToBadChannel(caloClusterPtr);
310 caloClusterPtr->fDistanceToBadChannel = -1;
313 caloClusterPtr->fClusterType = fClusterType;
314 //totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells)*(sizeof(Short_t) +sizeof(Float_t)-1);
315 //totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
316 //printf("CaloClusterPtr: %x, energy: %f\n", caloClusterPtr, caloClusterPtr->fEnergy);
318 // caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellAmpFracPtr);
319 //caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellIDPtr);
320 fCaloClusterDataPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellPtr);
321 recPointPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(digitPtr);
322 //digitPtr = &(recPointPtr->fDigits);