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 "AliHLTCaloClusterDataStruct.h"
35 #include "AliHLTPHOSPhysicsAnalyzer.h"
36 #include "AliHLTPHOSDigitReader.h"
37 #include "AliPHOSGeoUtils.h"
38 #include "AliESDCaloCluster.h"
42 ClassImp(AliHLTPHOSClusterAnalyser);
44 AliHLTPHOSClusterAnalyser::AliHLTPHOSClusterAnalyser() :
49 fCaloClusterDataPtr(0),
50 fCaloClusterHeaderPtr(0),
55 fHaveDistanceToBadChannel(false),
58 //See header file for documentation
61 AliHLTPHOSClusterAnalyser::~AliHLTPHOSClusterAnalyser()
66 AliHLTPHOSClusterAnalyser::SetCaloClusterDataPtr(AliHLTCaloClusterDataStruct *caloClusterDataPtr)
68 //see header file for documentation
69 fCaloClusterDataPtr = caloClusterDataPtr;
72 AliHLTPHOSClusterAnalyser::SetRecPointDataPtr(AliHLTPHOSRecPointHeaderStruct *recPointDataPtr, AliHLTPHOSDigitHeaderStruct *digitHeaderPtr)
74 fNRecPoints = recPointDataPtr->fNRecPoints;
75 fRecPointDataPtr = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(reinterpret_cast<Char_t*>(recPointDataPtr)+sizeof(AliHLTPHOSRecPointHeaderStruct));
76 fDigitHeaderPtr = digitHeaderPtr;
80 AliHLTPHOSClusterAnalyser::CalculateCenterOfGravity()
82 //see header file for documentation
89 AliHLTPHOSDigitDataStruct *digit = 0;
90 //AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance() ;
92 AliHLTPHOSRecPointDataStruct *recPoint = fRecPointDataPtr;
96 for(Int_t iRecPoint=0; iRecPoint < fNRecPoints; iRecPoint++)
98 digit = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(reinterpret_cast<Long_t>(fDigitHeaderPtr) + recPoint->fStartDigitOffset);
99 AliHLTPHOSDigitReader reader;
100 reader.SetCurrentDigit(digit);
105 // cout << "COG digits (x:z:E:time): " << xi << " : " << zi << " : " << digit->fEnergy << " : " << digit->fTime << endl;
106 if (recPoint->fAmp > 0 && digit->fEnergy > 0)
108 Float_t w = TMath::Max( 0., fLogWeight + TMath::Log( digit->fEnergy / recPoint->fAmp ) ) ;
113 digit = reader.NextDigit();
117 recPoint->fX = x/wtot ;
118 recPoint->fZ = z/wtot ;
124 recPoint = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(digit);
131 AliHLTPHOSClusterAnalyser::CalculateRecPointMoments()
133 //See header file for documentation
138 AliHLTPHOSClusterAnalyser::CalculateClusterMoments(AliHLTPHOSRecPointDataStruct */*recPointPtr*/, AliHLTCaloClusterDataStruct* /*clusterPtr*/)
140 //See header file for documentation
146 AliHLTPHOSClusterAnalyser::DeconvoluteClusters()
148 //See header file for documentation
153 AliHLTPHOSClusterAnalyser::CreateClusters(UInt_t availableSize, UInt_t& totSize)
155 //See header file for documentation
157 UInt_t maxClusterSize = sizeof(AliHLTCaloClusterDataStruct) + (6 << 7); //Reasonable estimate... (6 = sizeof(Short_t) + sizeof(Float_t)
159 AliHLTPHOSRecPointDataStruct* recPointPtr = fRecPointDataPtr;
160 AliHLTPHOSDigitDataStruct* digitPtr = 0;
162 AliHLTPHOSDigitReader reader;
164 AliHLTCaloClusterDataStruct* caloClusterPtr = fCaloClusterDataPtr;
165 UShort_t* cellIDPtr = &(caloClusterPtr->fCellsAbsId);
166 Float_t* cellAmpFracPtr = &(caloClusterPtr->fCellsAmpFraction);
171 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
173 digitPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(reinterpret_cast<Long_t>(fDigitHeaderPtr) + recPointPtr->fStartDigitOffset);
174 reader.SetCurrentDigit(digitPtr);
176 if(availableSize < (totSize + maxClusterSize))
178 return -1; //Might get out of buffer, exiting
180 fPHOSGeometry->Local2Global(recPointPtr->fModule, recPointPtr->fX, recPointPtr->fZ, globalPos);
182 caloClusterPtr->fGlobalPos[0] = globalPos[0];
183 caloClusterPtr->fGlobalPos[1] = globalPos[1];
184 caloClusterPtr->fGlobalPos[2] = globalPos[2];
186 caloClusterPtr->fNCells = recPointPtr->fMultiplicity;
188 cellIDPtr = &(caloClusterPtr->fCellsAbsId);
189 cellAmpFracPtr = &(caloClusterPtr->fCellsAmpFraction);
193 fPHOSGeometry->RelPosToAbsId((Int_t)(recPointPtr->fModule), (double)(digitPtr->fX), (double)(digitPtr->fZ), id);
195 *cellAmpFracPtr = digitPtr->fEnergy/recPointPtr->fAmp;
196 cellIDPtr = reinterpret_cast<UShort_t*>(reinterpret_cast<char*>(cellAmpFracPtr) + sizeof(Float_t));
197 cellAmpFracPtr = reinterpret_cast<Float_t*>(reinterpret_cast<char*>(cellIDPtr) + sizeof(Short_t));
198 digitPtr = reader.NextDigit();
201 caloClusterPtr->fEnergy = recPointPtr->fAmp;
205 FitCluster(recPointPtr);
209 caloClusterPtr->fDispersion = 0;
210 caloClusterPtr->fFitQuality = 0;
211 caloClusterPtr->fM20 = 0;
212 caloClusterPtr->fM02 = 0;
217 caloClusterPtr->fEmcCpvDistance = GetCPVDistance(recPointPtr);
221 caloClusterPtr->fEmcCpvDistance = -1;
225 DoParticleIdentification(caloClusterPtr);
229 for(Int_t k = 0; k < AliPID::kSPECIESN; k++)
231 caloClusterPtr->fPID[k] = 0;
234 if(fHaveDistanceToBadChannel)
236 caloClusterPtr->fDistanceToBadChannel = GetDistanceToBadChannel(caloClusterPtr);
240 caloClusterPtr->fDistanceToBadChannel = -1;
243 caloClusterPtr->fClusterType = (AliESDCaloCluster::kPHOSCluster);
245 totSize += sizeof(AliHLTCaloClusterDataStruct) + (caloClusterPtr->fNCells-1)*(sizeof(Short_t) + sizeof(Float_t));
247 caloClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(cellIDPtr);
248 recPointPtr = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(digitPtr);