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
63 fHist = new TH1F("cluster_energies", "cluster_energies", 200, 0, 20);
67 AliHLTCaloClusterAnalyser::~AliHLTCaloClusterAnalyser()
69 TFile *file = TFile::Open("debug.root", "RECREATE");
75 AliHLTCaloClusterAnalyser::SetCaloClusterData(AliHLTCaloClusterDataStruct *caloClusterDataPtr)
77 //see header file for documentation
78 fCaloClusterDataPtr = caloClusterDataPtr;
82 AliHLTCaloClusterAnalyser::SetRecPointArray(AliHLTCaloRecPointDataStruct **recPointDataPtr, Int_t nRecPoints)
84 fRecPointArray = recPointDataPtr;
85 fNRecPoints = nRecPoints;
89 AliHLTCaloClusterAnalyser::SetDigitDataArray(AliHLTCaloDigitDataStruct *digits)
91 // AliHLTCaloClusterizer cl("PHOS");
92 // cl.CheckDigits(fRecPointArray, digits, fNRecPoints);
93 fDigitDataArray = digits;
94 //cl.CheckDigits(fRecPointArray, fDigitDataArray, fNRecPoints);
98 AliHLTCaloClusterAnalyser::CalculateCenterOfGravity()
100 //see header file for documentation
107 AliHLTCaloDigitDataStruct *digit = 0;
108 //AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance() ;
111 //AliHLTCaloClusterizer cl("PHOS");
112 //cl.CheckDigits(fRecPointArray, fDigitDataArray, fNRecPoints);
116 for(Int_t iRecPoint=0; iRecPoint < fNRecPoints; iRecPoint++)
118 AliHLTCaloRecPointDataStruct *recPoint = fRecPointArray[iRecPoint];
119 // digit = &(recPoint->fDigits);
120 cout << "COG: Rec point multiplicity: " << recPoint->fMultiplicity << ", rec point energy: " << recPoint->fAmp << endl;
121 Int_t *digitIndexPtr = &(recPoint->fDigits);
123 for(iDigit = 0; iDigit < recPoint->fMultiplicity; iDigit++)
125 //cout << "1. Digit array: " << fDigitDataArray << ", Digit: " << digit << ", Index: " << *digitIndexPtr << ", ID: " << digit->fID << endl;
127 digit = &(fDigitDataArray[*digitIndexPtr]);
128 cout << "COG: 2. Digit array: " << fDigitDataArray << ", Digit: " << digit << ", Index: " << *digitIndexPtr << ", index pointer: " << digitIndexPtr<< endl;
129 cout << ", dig Energy: " << digit->fEnergy << ", Index: " << *digitIndexPtr << ", ID: " << digit->fID << endl;
132 // cout << "COG digits (x:z:E:time): " << xi << " : " << zi << " : " << digit->fEnergy << " : " << digit->fTime << endl;
133 if (recPoint->fAmp > 0 && digit->fEnergy > 0)
135 Float_t w = TMath::Max( 0., fLogWeight + TMath::Log( digit->fEnergy / recPoint->fAmp ) ) ;
145 recPoint->fX = x/wtot ;
146 recPoint->fZ = z/wtot ;
158 AliHLTCaloClusterAnalyser::CalculateRecPointMoments()
160 //See header file for documentation
165 AliHLTCaloClusterAnalyser::CalculateClusterMoments(AliHLTCaloRecPointDataStruct */*recPointPtr*/, AliHLTCaloClusterDataStruct* /*clusterPtr*/)
167 //See header file for documentation
173 AliHLTCaloClusterAnalyser::DeconvoluteClusters()
175 //See header file for documentation
180 AliHLTCaloClusterAnalyser::CreateClusters(Int_t nRecPoints, UInt_t availableSize, UInt_t& totSize)
182 //See header file for documentation
185 totSize += sizeof(AliHLTCaloClusterDataStruct);
186 fNRecPoints = nRecPoints;
190 HLTError("No geometry object is initialised, creation of clusters stopped");
193 CalculateCenterOfGravity();
195 // AliHLTCaloDigitDataStruct* digitPtr = &(recPointPtr->fDigits);
196 AliHLTCaloDigitDataStruct* digitPtr = 0;
198 AliHLTCaloClusterDataStruct* caloClusterPtr = 0;
199 UShort_t* cellIDPtr = 0;
200 Float_t* cellAmpFracPtr = 0;;
205 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
207 if((availableSize - totSize) < sizeof(AliHLTCaloClusterDataStruct))
209 HLTError("Out of buffer");
213 caloClusterPtr = fCaloClusterDataPtr;
215 cellIDPtr = &(caloClusterPtr->fCellsAbsId);
216 cellAmpFracPtr = &(caloClusterPtr->fCellsAmpFraction);
218 AliHLTCaloRecPointDataStruct *recPointPtr = fRecPointArray[i];
219 cout << "CA: rec point energy: " << recPointPtr->fAmp << ", rec point multiplicity: " << recPointPtr->fMultiplicity << endl;
220 // cout << "Local Position (x:z:module): " << recPointPtr->fX << " : "<< recPointPtr->fZ << " : " << recPointPtr->fModule << endl;
222 AliHLTCaloGlobalCoordinate globalCoord;
223 fGeometry->GetGlobalCoordinates(*recPointPtr, globalCoord);
224 // cout << "Global Position (x:y:z): " << globalPos[0] << " : "<< globalPos[1] << " : " << globalPos[2] << endl << endl;
226 caloClusterPtr->fGlobalPos[0] = globalCoord.fX;
227 caloClusterPtr->fGlobalPos[1] = globalCoord.fY;
228 caloClusterPtr->fGlobalPos[2] = globalCoord.fZ;
230 caloClusterPtr->fNCells = 0;//recPointPtr->fMultiplicity;
232 Int_t tmpSize = totSize + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
234 if((availableSize - totSize) < tmpSize)
236 HLTError("Out of buffer");
240 for(UInt_t j = 0; j < caloClusterPtr->fNCells; j++)
242 /* fGeometry->GetCellAbsId(recPointPtr->fModule, digitPtr->fX, digitPtr->fZ, id);
244 *cellAmpFracPtr = digitPtr->fEnergy/recPointPtr->fAmp;
246 cellIDPtr = reinterpret_cast<UShort_t*>(reinterpret_cast<char*>(cellAmpFracPtr) + sizeof(Float_t));
247 cellAmpFracPtr = reinterpret_cast<Float_t*>(reinterpret_cast<char*>(cellIDPtr) + sizeof(Short_t)); */
252 caloClusterPtr->fEnergy = recPointPtr->fAmp;
254 fHist->Fill(caloClusterPtr->fEnergy);
256 cout << "CA: cluster energy: " << caloClusterPtr->fEnergy << endl;
257 cout << "CA: recpoint energy: " << recPointPtr->fAmp << endl;
262 FitCluster(recPointPtr);
266 caloClusterPtr->fDispersion = 0;
267 caloClusterPtr->fFitQuality = 0;
268 caloClusterPtr->fM20 = 0;
269 caloClusterPtr->fM02 = 0;
274 caloClusterPtr->fEmcCpvDistance = GetCPVDistance(recPointPtr);
278 caloClusterPtr->fEmcCpvDistance = -1;
282 DoParticleIdentification(caloClusterPtr);
286 for(Int_t k = 0; k < AliPID::kSPECIESN; k++)
288 caloClusterPtr->fPID[k] = 0;
291 if(fHaveDistanceToBadChannel)
293 caloClusterPtr->fDistanceToBadChannel = GetDistanceToBadChannel(caloClusterPtr);
297 caloClusterPtr->fDistanceToBadChannel = -1;
300 caloClusterPtr->fClusterType = fClusterType;
301 // totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells)*(sizeof(Short_t) +sizeof(Float_t)-1);
302 //totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
304 // caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellAmpFracPtr);
305 caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellIDPtr);
307 recPointPtr = reinterpret_cast<AliHLTCaloRecPointDataStruct*>(digitPtr);
308 //digitPtr = &(recPointPtr->fDigits);
310 // cout << "CA: Energy End: " << fCaloClusterDataPtr->fEnergy << endl;
311 //cout << "CA totSize: " << totSize << endl;