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 #ifndef HAVE_NOT_ALIVCLUSTER // backward compatibility for r42844
61 fClusterType(AliVCluster::kPHOSNeutral),
63 fClusterType(AliESDCaloCluster::kPHOSCluster),
66 fCutOnSingleCellClusters(false),
67 fSingleCellEnergyCut(0.5)
69 //See header file for documentation
72 AliHLTCaloClusterAnalyser::~AliHLTCaloClusterAnalyser()
74 // See header file for class documentation
78 AliHLTCaloClusterAnalyser::SetCaloClusterData(AliHLTCaloClusterDataStruct *caloClusterDataPtr)
80 //see header file for documentation
81 fCaloClusterDataPtr = caloClusterDataPtr;
85 AliHLTCaloClusterAnalyser::SetRecPointArray(AliHLTCaloRecPointDataStruct **recPointDataPtr, Int_t nRecPoints)
87 fRecPointArray = recPointDataPtr;
88 fNRecPoints = nRecPoints;
92 AliHLTCaloClusterAnalyser::SetDigitDataArray(AliHLTCaloDigitDataStruct **digits)
94 // AliHLTCaloClusterizer cl("PHOS");
95 // cl.CheckDigits(fRecPointArray, digits, fNRecPoints);
96 fDigitDataArray = digits;
97 //cl.CheckDigits(fRecPointArray, fDigitDataArray, fNRecPoints);
101 AliHLTCaloClusterAnalyser::CalculateCenterOfGravity()
103 //see header file for documentation
110 AliHLTCaloDigitDataStruct *digit = 0;
114 for(Int_t iRecPoint=0; iRecPoint < fNRecPoints; iRecPoint++)
116 AliHLTCaloRecPointDataStruct *recPoint = fRecPointArray[iRecPoint];
117 // digit = &(recPoint->fDigits);
119 Int_t *digitIndexPtr = &(recPoint->fDigits);
124 /* Float_t maxAmp = 0;
127 for(iDigit = 0; iDigit < recPoint->fMultiplicity; iDigit++)
130 digit = fDigitDataArray[*digitIndexPtr];
135 if (recPoint->fAmp > 0 && digit->fEnergy > 0)
137 Float_t w = TMath::Max( 0., fLogWeight + TMath::Log( digit->fEnergy / recPoint->fAmp ) ) ;
141 /* if(digit->fEnergy > maxAmp)
143 maxAmp = digit->fEnergy;
144 maxX = digit->fX;// + 0.5;
145 maxZ = digit->fZ;// + 0.5;
153 recPoint->fX = x/wtot ;
154 recPoint->fZ = z/wtot ;
160 // 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);
167 AliHLTCaloClusterAnalyser::CalculateRecPointMoments()
169 //See header file for documentation
174 AliHLTCaloClusterAnalyser::CalculateClusterMoments(AliHLTCaloRecPointDataStruct */*recPointPtr*/, AliHLTCaloClusterDataStruct* /*clusterPtr*/)
176 //See header file for documentation
182 AliHLTCaloClusterAnalyser::DeconvoluteClusters()
184 //See header file for documentation
189 AliHLTCaloClusterAnalyser::CreateClusters(Int_t nRecPoints, UInt_t availableSize, UInt_t& totSize)
191 //See header file for documentation
195 fLogWeight = fRecoParamsPtr->GetLogWeight();
198 fNRecPoints = nRecPoints;
202 HLTError("No geometry object is initialised, creation of clusters stopped");
206 CalculateCenterOfGravity();
208 // AliHLTCaloDigitDataStruct* digitPtr = &(recPointPtr->fDigits);
209 AliHLTCaloDigitDataStruct* digitPtr = 0;
211 AliHLTCaloClusterDataStruct* caloClusterPtr = 0;
216 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
218 if((availableSize - totSize) < sizeof(AliHLTCaloClusterDataStruct))
220 HLTError("Out of buffer: available size is: %d, total size used: %d", availableSize, totSize);
224 AliHLTCaloRecPointDataStruct *recPointPtr = fRecPointArray[i];
226 if(fCutOnSingleCellClusters && recPointPtr->fAmp > fSingleCellEnergyCut && recPointPtr->fMultiplicity == 1) continue;
228 totSize += sizeof(AliHLTCaloClusterDataStruct);
230 caloClusterPtr = fCaloClusterDataPtr;
231 caloClusterPtr->fChi2 = 0;
232 caloClusterPtr->fClusterType = kUndef;
233 caloClusterPtr->fDispersion = 0;
234 caloClusterPtr->fDistanceToBadChannel = 0;
235 caloClusterPtr->fDistToBadChannel = 0;
236 caloClusterPtr->fEmcCpvDistance = 0;
237 caloClusterPtr->fEnergy = 0;
238 caloClusterPtr->fFitQuality = 0;
239 caloClusterPtr->fID = 0;
240 caloClusterPtr->fM02 = 0;
241 caloClusterPtr->fM20 = 0;
242 caloClusterPtr->fNCells = 0;
243 caloClusterPtr->fNExMax = 0;
244 caloClusterPtr->fTOF = 0;
245 caloClusterPtr->fTrackDx = -999;
246 caloClusterPtr->fTrackDz = -999;
248 AliHLTCaloGlobalCoordinate globalCoord;
249 fGeometry->GetGlobalCoordinates(*recPointPtr, globalCoord);
251 caloClusterPtr->fModule = recPointPtr->fModule;
252 caloClusterPtr->fGlobalPos[0] = globalCoord.fX;
253 caloClusterPtr->fGlobalPos[1] = globalCoord.fY;
254 caloClusterPtr->fGlobalPos[2] = globalCoord.fZ;
256 HLTDebug("Cluster local position: x = %f, z = %f, module = %d", recPointPtr->fX, recPointPtr->fZ, recPointPtr->fModule);
257 HLTDebug("Cluster global position: x = %f, y = %f, z = %f", globalCoord.fX, globalCoord.fY, globalCoord.fZ);
259 //caloClusterPtr->fNCells = 0;//recPointPtr->fMultiplicity;
260 caloClusterPtr->fNCells = recPointPtr->fMultiplicity;
262 caloClusterPtr->fClusterType = fClusterType;
263 // Int_t tmpSize = 0;//totSize + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
265 //TODO remove hardcoded 10;
266 memset(caloClusterPtr->fTracksMatched, 0xff, sizeof(Int_t)*10);
268 //Int_t tmpSize = totSize + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
269 UInt_t tmpSize = (caloClusterPtr->fNCells-1)*sizeof(AliHLTCaloCellDataStruct);
271 if((availableSize - totSize) < tmpSize)
273 HLTError("Out of buffer, available size is: %d, total size used: %d, extra size needed: %d", availableSize, totSize, tmpSize);
277 Int_t *digitIndexPtr = &(recPointPtr->fDigits);
280 AliHLTCaloCellDataStruct *cellPtr = &(caloClusterPtr->fCaloCells);
282 for(UInt_t j = 0; j < caloClusterPtr->fNCells; j++)
284 digitPtr = fDigitDataArray[*digitIndexPtr];
285 fGeometry->GetCellAbsId(recPointPtr->fModule, digitPtr->fX, digitPtr->fZ, id);
287 cellPtr->fCellsAbsId= id;
288 cellPtr->fCellsAmpFraction = digitPtr->fEnergy/recPointPtr->fAmp;
289 //printf("Cell ID pointer: %x\n", cellIDPtr);
290 //printf("Cell Amp Pointer: %x\n", cellAmpFracPtr);
291 //printf("Cell pos: x = %d, z = %d\n", digitPtr->fX, digitPtr->fZ);
292 // printf("Cell ID: %d\n", cellPtr->fCellsAbsId);
293 //printf("Cell Amp: %f, pointer: %x\n", *cellAmpFracPtr, cellAmpFracPtr);
303 caloClusterPtr->fEnergy = fRecoParamsPtr->GetCorrectedEnergy(recPointPtr->fAmp);
307 caloClusterPtr->fEnergy = recPointPtr->fAmp;
310 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);
314 FitCluster(recPointPtr);
318 caloClusterPtr->fDispersion = 0;
319 caloClusterPtr->fFitQuality = 0;
320 caloClusterPtr->fM20 = 0;
321 caloClusterPtr->fM02 = 0;
326 caloClusterPtr->fEmcCpvDistance = GetCPVDistance(recPointPtr);
330 caloClusterPtr->fEmcCpvDistance = -1;
334 DoParticleIdentification(caloClusterPtr);
338 for(Int_t k = 0; k < AliPID::kSPECIESN; k++)
340 caloClusterPtr->fPID[k] = 0;
343 if(fHaveDistanceToBadChannel)
345 caloClusterPtr->fDistanceToBadChannel = GetDistanceToBadChannel(caloClusterPtr);
349 caloClusterPtr->fDistanceToBadChannel = -1;
352 caloClusterPtr->fClusterType = fClusterType;
353 //totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells)*(sizeof(Short_t) +sizeof(Float_t)-1);
354 //totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
355 //printf("CaloClusterPtr: %x, energy: %f\n", caloClusterPtr, caloClusterPtr->fEnergy);
357 // caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellAmpFracPtr);
358 //caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellIDPtr);
359 fCaloClusterDataPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellPtr);
360 recPointPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(digitPtr);
361 //digitPtr = &(recPointPtr->fDigits);