]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSClusterizer.cxx
Selectiv readout and writing to FXS (oystein)
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSClusterizer.cxx
CommitLineData
ab38011b 1/**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
4 * *
1804b020 5 * Primary Authors: Oystein Djuvsland *
ab38011b 6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
aac22523 15
2374af72 16/**
17 * @file AliHLTPHOSClusterizer.cxx
18 * @author Oystein Djuvsland
19 * @date
20 * @brief Clusterizer for PHOS HLT
21 */
22
23// see header file for class documentation
24// or
25// refer to README to build package
26// or
27// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
aac22523 28
aac22523 29#include "AliHLTPHOSClusterizer.h"
9cc0deb1 30#include "AliHLTPHOSBase.h"
aac22523 31#include "TMath.h"
9cc0deb1 32#include "AliHLTPHOSRecPointContainerStruct.h"
91b95d47 33#include "AliHLTPHOSRecPointDataStruct.h"
9cc0deb1 34#include "AliHLTPHOSDigitDataStruct.h"
35#include "AliHLTPHOSDigitContainerDataStruct.h"
36#include "TClonesArray.h"
37#include "AliPHOSGeometry.h"
38#include "AliPHOSDigit.h"
39#include "AliPHOSRecoParamEmc.h"
40
41ClassImp(AliHLTPHOSClusterizer);
42
43AliHLTPHOSClusterizer::AliHLTPHOSClusterizer():
44 AliHLTPHOSBase(),
45 fEmcClusteringThreshold(0),
46 fEmcMinEnergyThreshold(0),
47 fEmcTimeGate(0),
48 fLogWeight(0),
49 fDigitsInCluster(0),
50 fOnlineMode(true),
51 fDigitArrayPtr(0),
52 fEmcRecPointsPtr(0),
53 fDigitPtr(0),
54 fDigitContainerPtr(0),
55 fRecPointContainerPtr(0),
56 fPHOSGeometry(0),
57 fGetterPtr(0)
aac22523 58{
6e709a0d 59 //See header file for documentation
9cc0deb1 60 fPHOSGeometry = AliPHOSGeometry::GetInstance("noCPV");
61 fEmcClusteringThreshold = 0.2;
62 fEmcMinEnergyThreshold = 0.03;
d949e02e 63 fEmcTimeGate = 1.e-6 ;
9cc0deb1 64 fLogWeight = 4.5;
aac22523 65
9cc0deb1 66
aac22523 67}//end
68
9c9d15d6 69
9cc0deb1 70AliHLTPHOSClusterizer::~AliHLTPHOSClusterizer()
aac22523 71{
2374af72 72 //See header file for documentation
aac22523 73}
74
25b7f84c 75void
76AliHLTPHOSClusterizer::SetRecPointContainer(AliHLTPHOSRecPointContainerStruct* recPointContainerPtr)
77 {
78 fRecPointContainerPtr = recPointContainerPtr;
79 fRecPointContainerPtr->fNRecPoints = 0;
80 }
2374af72 81
9cc0deb1 82void
83AliHLTPHOSClusterizer::SetRecoParameters(AliPHOSRecoParamEmc* params)
84{
2374af72 85 //see header file for documentation
9cc0deb1 86 fEmcClusteringThreshold = params->GetClusteringThreshold();
87 fEmcMinEnergyThreshold = params->GetMinE();
88 fLogWeight = params->GetLogWeight();
89}
aac22523 90
9cc0deb1 91void
92AliHLTPHOSClusterizer::SetOfflineMode(AliPHOSGetter* getter)
aac22523 93{
2374af72 94 //see header file for documentation
9cc0deb1 95 fRecPointContainerPtr = new AliHLTPHOSRecPointContainerStruct();
96 fDigitContainerPtr = new AliHLTPHOSDigitContainerDataStruct();
97 fGetterPtr = getter;
98 fDigitArrayPtr = fGetterPtr->Digits();
99 fEmcRecPointsPtr = fGetterPtr->EmcRecPoints();
100 fOnlineMode = false;
101}
aac22523 102
9cc0deb1 103Int_t
104AliHLTPHOSClusterizer::GetEvent(Int_t i)
105{
2374af72 106 //see header file for documentation
9cc0deb1 107 Int_t coord[4];
aac22523 108
9cc0deb1 109 fGetterPtr->Event(i, "D");
110 for(Int_t j = 0; j < fDigitArrayPtr->GetEntries(); j++)
aac22523 111 {
9cc0deb1 112 fDigitPtr = (AliPHOSDigit*)fDigitArrayPtr->At(j);
113 fPHOSGeometry->AbsToRelNumbering(fDigitPtr->GetId(), coord);
114 fDigitContainerPtr->fDigitDataStruct[j].fX = coord[3];
115 fDigitContainerPtr->fDigitDataStruct[j].fZ = coord[2];
116 fDigitContainerPtr->fDigitDataStruct[j].fModule = coord[0];
117 fDigitContainerPtr->fDigitDataStruct[j].fEnergy = fDigitPtr->GetEnergy();
118 fDigitContainerPtr->fDigitDataStruct[j].fTime = fDigitPtr->GetTime();
119 }
120 fDigitContainerPtr->fNDigits = fDigitArrayPtr->GetEntriesFast();
121 return 0;
122}
aac22523 123
9cc0deb1 124Int_t
125AliHLTPHOSClusterizer::GetNEvents()
126{
2374af72 127 //see header file for documentation
9cc0deb1 128 if(fOnlineMode)
129 {
130 printf("Number of events not available in online mode!\n");
131 return -1;
132 }
133 return fGetterPtr->MaxEvent();
134}
aac22523 135
aac22523 136
9cc0deb1 137Int_t
138AliHLTPHOSClusterizer::ClusterizeEvent()
aac22523 139{
2374af72 140 //see header file for documentation
aac22523 141 Int_t nRecPoints = 0;
9cc0deb1 142 UInt_t i = 0;
aac22523 143
d949e02e 144 //printf("Starting clusterisation of event.\n");
6e709a0d 145
9cc0deb1 146 AliHLTPHOSRecPointDataStruct *recPoint = 0;
d949e02e 147
9cc0deb1 148 //Clusterization starts
149 for(i = 0; i < fDigitContainerPtr->fNDigits; i++)
150 {
aac22523 151
d949e02e 152 fDigitsInCluster = 0;
153 //printf("Digit energy: %f\n", fDigitContainerPtr->fDigitDataStruct[i].fEnergy);
9cc0deb1 154 if(fDigitContainerPtr->fDigitDataStruct[i].fEnergy < fEmcClusteringThreshold)
aac22523 155 {
9cc0deb1 156 continue;
aac22523 157 }
d949e02e 158 //printf("Got rec point above clustering threshold!\n");
9cc0deb1 159 recPoint = &(fRecPointContainerPtr->fRecPointArray[nRecPoints]);
160 recPoint->fAmp = 0;
25b7f84c 161 //TODO!!!!!!!
162 recPoint->fModule = fDigitContainerPtr->fDigitDataStruct[i].fModule;
163 //TODO!!!!!!!
9cc0deb1 164 //recPoint->
165 recPoint->fDigitsList[fDigitsInCluster] = fDigitContainerPtr->fDigitDataStruct[i];
166 recPoint->fAmp += fDigitContainerPtr->fDigitDataStruct[i].fEnergy;
167 fDigitContainerPtr->fDigitDataStruct[i].fEnergy = 0;
168 fDigitsInCluster++;
169 nRecPoints++;
170 ScanForNeighbourDigits(i, recPoint);
171
172 recPoint->fMultiplicity = fDigitsInCluster;
d949e02e 173
9cc0deb1 174 }//end of clusterization
175 fRecPointContainerPtr->fNRecPoints = nRecPoints;
aac22523 176
9cc0deb1 177 return nRecPoints;
178}
aac22523 179
9cc0deb1 180void
181AliHLTPHOSClusterizer::ScanForNeighbourDigits(Int_t index, AliHLTPHOSRecPointDataStruct* recPoint)
aac22523 182
aac22523 183{
2374af72 184 //see header file for documentation
9cc0deb1 185
186 for(UInt_t j = 0; j < fDigitContainerPtr->fNDigits; j++)
aac22523 187 {
9cc0deb1 188 if(fDigitContainerPtr->fDigitDataStruct[j].fEnergy > fEmcMinEnergyThreshold)
189 {
190 switch(AreNeighbours(&(fDigitContainerPtr->fDigitDataStruct[index]),
191 &(fDigitContainerPtr->fDigitDataStruct[j])))
192 {
193 case 0:
194 break;
195 case 1:
196 recPoint->fDigitsList[fDigitsInCluster] = fDigitContainerPtr->fDigitDataStruct[j];
197 recPoint->fAmp += fDigitContainerPtr->fDigitDataStruct[j].fEnergy;
198 fDigitContainerPtr->fDigitDataStruct[j].fEnergy = 0;
199 fDigitsInCluster++;
200 ScanForNeighbourDigits(j, recPoint);
201 break;
202 case 2:
203 break;
204 }
aac22523 205 }
9cc0deb1 206 }
207 return;
208}
6e709a0d 209
aac22523 210
9cc0deb1 211Int_t
212AliHLTPHOSClusterizer::AreNeighbours(AliHLTPHOSDigitDataStruct* digit1,
213 AliHLTPHOSDigitDataStruct* digit2)
6e709a0d 214{
2374af72 215 //see header file for documentation
d2b84453 216
9cc0deb1 217 if ( (digit1->fModule == digit2->fModule) /*&& (coord1[1]==coord2[1])*/ ) // inside the same PHOS module
218 {
d2b84453 219
9cc0deb1 220 Int_t rowdiff = TMath::Abs( digit1->fZ - digit2->fZ );
221 Int_t coldiff = TMath::Abs( digit1->fX - digit2->fX );
d949e02e 222
223 //cout << "x1: " << digit1->fX << " x2: " << digit2->fX << " z1: " << digit1->fZ << " z2: " << digit2->fZ <<
224 //" t1: " << digit1->fTime << " t2: " << digit1->fTime << " --> ";
9cc0deb1 225
226 if (( coldiff <= 1 ) && ( rowdiff <= 1 ))
6e709a0d 227 {
9cc0deb1 228 if(TMath::Abs(digit1->fTime - digit2->fTime ) < fEmcTimeGate)
d949e02e 229 {
230 //cout << "OK\n";
231 return 1;
232 }
233 // cout << "Time difference\n";
6e709a0d 234 }
d949e02e 235 //else
236 //{
237 // cout << "Space difference\n";
238 //}
6e709a0d 239 }
240 return 0;
241}
aac22523 242
9cc0deb1 243void
244AliHLTPHOSClusterizer::CalculateCenterOfGravity()
aac22523 245{
2374af72 246 //see header file for documentation
247
9cc0deb1 248 Float_t wtot = 0.;
249
1804b020 250 //Int_t relid[4];
aac22523 251
9cc0deb1 252 Float_t x = 0.;
253 Float_t z = 0.;
254 Float_t xi = 0.;
255 Float_t zi = 0.;
aac22523 256
9cc0deb1 257 AliHLTPHOSRecPointDataStruct *recPoint = 0;
258 AliHLTPHOSDigitDataStruct *digit = 0;
aac22523 259
1804b020 260 //AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance() ;
aac22523 261
1804b020 262 UInt_t iDigit = 0;
263 UInt_t iRecPoint = 0;
91b95d47 264
9cc0deb1 265 for(iRecPoint=0; iRecPoint<fRecPointContainerPtr->fNRecPoints; iRecPoint++)
aac22523 266 {
9cc0deb1 267 recPoint = &(fRecPointContainerPtr->fRecPointArray[iRecPoint]);
268 for(iDigit = 0; iDigit < recPoint->fMultiplicity; iDigit++)
aac22523 269 {
9cc0deb1 270 digit = &(recPoint->fDigitsList[iDigit]);
271
272 //fPHOSGeometry->AbsToRelNumbering(digit->fID, relid) ;
273 // fPHOSGeometry->RelPosInModule(relid, xi, zi);
274 xi = digit->fX;
275 zi = digit->fZ;
276
277 if (recPoint->fAmp > 0 && digit->fEnergy > 0)
278 {
279 Float_t w = TMath::Max( 0., fLogWeight + TMath::Log( digit->fEnergy / recPoint->fAmp ) ) ;
280 x += xi * w ;
281 z += zi * w ;
282 wtot += w ;
283 }
284 }
285
286 if (wtot>0)
287 {
288 recPoint->fX = x/wtot ;
289 recPoint->fZ = z/wtot ;
290 }
291 else
292 {
293 recPoint->fAmp = 0;
aac22523 294 }
295 }
9cc0deb1 296
297}
aac22523 298
aac22523 299