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 AliHLTPHOSClusterAnalyser.cxx
20 * @author Oystein Djuvsland
22 * @brief Cluster analyser for PHOS 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 "AliHLTPHOSClusterAnalyser.h"
32 #include "AliHLTPHOSRecPointHeaderStruct.h"
33 #include "AliHLTPHOSRecPointDataStruct.h"
34 #include "AliHLTPHOSCaloClusterHeaderStruct.h"
35 #include "AliHLTPHOSCaloClusterDataStruct.h"
36 #include "AliHLTPHOSPhysicsAnalyzer.h"
37 #include "AliPHOSGeoUtils.h"
41 ClassImp(AliHLTPHOSClusterAnalyser);
43 AliHLTPHOSClusterAnalyser::AliHLTPHOSClusterAnalyser() :
48 fCaloClusterDataPtr(0),
49 fCaloClusterHeaderPtr(0),
55 fHaveDistanceToBadChannel(false)
57 //See header file for documentation
60 fAnalyzerPtr = new AliHLTPHOSPhysicsAnalyzer();
61 // fPHOSGeometry = AliPHOSGeometry::GetInstance("noCPV");
62 fPHOSGeometry = new AliPHOSGeoUtils("PHOS", "noCPV");
65 AliHLTPHOSClusterAnalyser::~AliHLTPHOSClusterAnalyser()
70 AliHLTPHOSClusterAnalyser::SetCaloClusterDataPtr(AliHLTPHOSCaloClusterDataStruct *caloClusterDataPtr)
72 //see header file for documentation
73 fCaloClusterDataPtr = caloClusterDataPtr;
76 AliHLTPHOSClusterAnalyser::SetRecPointDataPtr(AliHLTPHOSRecPointHeaderStruct *recPointDataPtr)
78 fNRecPoints = recPointDataPtr->fNRecPoints;
79 fRecPointDataPtr = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(reinterpret_cast<Char_t*>(recPointDataPtr)+sizeof(AliHLTPHOSRecPointHeaderStruct));
83 AliHLTPHOSClusterAnalyser::CalculateCenterOfGravity()
85 //see header file for documentation
92 AliHLTPHOSDigitDataStruct *digit = 0;
93 //AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance() ;
95 AliHLTPHOSRecPointDataStruct *recPoint = fRecPointDataPtr;
99 for(Int_t iRecPoint=0; iRecPoint < fNRecPoints; iRecPoint++)
101 digit = &(recPoint->fDigits);
102 for(iDigit = 0; iDigit < recPoint->fMultiplicity; iDigit++)
107 // cout << "COG digits (x:z:E:time): " << xi << " : " << zi << " : " << digit->fEnergy << " : " << digit->fTime << endl;
108 if (recPoint->fAmp > 0 && digit->fEnergy > 0)
110 Float_t w = TMath::Max( 0., fLogWeight + TMath::Log( digit->fEnergy / recPoint->fAmp ) ) ;
120 recPoint->fX = x/wtot ;
121 recPoint->fZ = z/wtot ;
127 recPoint = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(digit);
134 AliHLTPHOSClusterAnalyser::CalculateRecPointMoments()
136 //See header file for documentation
141 AliHLTPHOSClusterAnalyser::CalculateClusterMoments(AliHLTPHOSRecPointDataStruct */*recPointPtr*/, AliHLTPHOSCaloClusterDataStruct* /*clusterPtr*/)
143 //See header file for documentation
149 AliHLTPHOSClusterAnalyser::DeconvoluteClusters()
151 //See header file for documentation
156 AliHLTPHOSClusterAnalyser::CreateClusters(UInt_t availableSize, UInt_t& totSize)
158 //See header file for documentation
160 UInt_t maxClusterSize = sizeof(AliHLTPHOSCaloClusterDataStruct) + (6 << 7); //Reasonable estimate... (6 = sizeof(Short_t) + sizeof(Float_t)
162 AliHLTPHOSRecPointDataStruct* recPointPtr = fRecPointDataPtr;
163 AliHLTPHOSDigitDataStruct* digitPtr = &(recPointPtr->fDigits);
165 AliHLTPHOSCaloClusterDataStruct* caloClusterPtr = fCaloClusterDataPtr;
166 UShort_t* cellIDPtr = &(caloClusterPtr->fCellsAbsId);
167 Float_t* cellAmpFracPtr = &(caloClusterPtr->fCellsAmpFraction);
172 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
175 if(availableSize < (totSize + maxClusterSize))
177 return -1; //Might get out of buffer, exiting
179 // localPos[0] = recPointPtr->fX;
180 // localPos[1] = recPointPtr->fZ;
181 // fAnalyzerPtr->GlobalPosition( localPos, globalPos, recPointPtr->fModule);
184 // cout << "Local Position (x:z:module): " << recPointPtr->fX << " : "<< recPointPtr->fZ << " : " << recPointPtr->fModule << endl;
185 fPHOSGeometry->Local2Global(recPointPtr->fModule + 1, recPointPtr->fX, recPointPtr->fZ, globalPos);
186 // cout << "Global Position (x:y:z): " << globalPos[0] << " : "<< globalPos[1] << " : " << globalPos[2] << endl << endl;
188 caloClusterPtr->fGlobalPos[0] = globalPos[0];
189 caloClusterPtr->fGlobalPos[1] = globalPos[1];
190 caloClusterPtr->fGlobalPos[2] = globalPos[2];
192 caloClusterPtr->fNCells = recPointPtr->fMultiplicity;
194 cellIDPtr = &(caloClusterPtr->fCellsAbsId);
195 cellAmpFracPtr = &(caloClusterPtr->fCellsAmpFraction);
197 for(UInt_t j = 0; j < caloClusterPtr->fNCells; j++)
199 fPHOSGeometry->RelPosToAbsId((Int_t)(recPointPtr->fModule + 1), (double)(digitPtr->fX), (double)(digitPtr->fZ), id);
201 *cellAmpFracPtr = digitPtr->fEnergy/recPointPtr->fAmp;
203 cellIDPtr = reinterpret_cast<UShort_t*>(reinterpret_cast<char*>(cellAmpFracPtr) + sizeof(Float_t));
204 cellAmpFracPtr = reinterpret_cast<Float_t*>(reinterpret_cast<char*>(cellIDPtr) + sizeof(Short_t));
207 caloClusterPtr->fEnergy = recPointPtr->fAmp;
208 // cout << "CA: Energy End: " << caloClusterPtr->fEnergy << endl;
211 FitCluster(recPointPtr);
215 caloClusterPtr->fDispersion = 0;
216 caloClusterPtr->fFitQuality = 0;
217 caloClusterPtr->fM20 = 0;
218 caloClusterPtr->fM02 = 0;
219 // caloClusterPtr->fM11 = 0;
223 caloClusterPtr->fEmcCpvDistance = GetCPVDistance(recPointPtr);
227 caloClusterPtr->fEmcCpvDistance = -1;
231 DoParticleIdentification(caloClusterPtr);
235 for(Int_t k = 0; k < AliPID::kSPECIESN; k++)
237 caloClusterPtr->fPID[k] = 0;
240 if(fHaveDistanceToBadChannel)
242 caloClusterPtr->fDistanceToBadChannel = GetDistanceToBadChannel(caloClusterPtr);
246 caloClusterPtr->fDistanceToBadChannel = -1;
249 caloClusterPtr->fClusterType = '\0';
250 // totSize += sizeof(AliHLTPHOSCaloClusterDataStruct) + (caloClusterPtr->fNCells)*(sizeof(Short_t) +sizeof(Float_t)-1);
251 totSize += sizeof(AliHLTPHOSCaloClusterDataStruct) + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
253 // caloClusterPtr = reinterpret_cast<AliHLTPHOSCaloClusterDataStruct*>(cellAmpFracPtr);
254 caloClusterPtr = reinterpret_cast<AliHLTPHOSCaloClusterDataStruct*>(cellIDPtr);
255 recPointPtr = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(digitPtr);
256 digitPtr = &(recPointPtr->fDigits);
258 // cout << "CA: Energy End: " << fCaloClusterDataPtr->fEnergy << endl;
259 //cout << "CA totSize: " << totSize << endl;