added switch for doc to configure.ac; added monilithic doc build; configure.ac and...
[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"
ae1c1854 39#ifndef HAVE_NOT_PHOSRECOPARAMEMC // set from configure if EMC functionality not available in AliPHOSRecoParam
7e88424f 40#include "AliPHOSRecoParam.h"
ae1c1854 41#else
42#include "AliPHOSRecoParamEmc.h"
43#endif
9cc0deb1 44
45ClassImp(AliHLTPHOSClusterizer);
46
47AliHLTPHOSClusterizer::AliHLTPHOSClusterizer():
48 AliHLTPHOSBase(),
49 fEmcClusteringThreshold(0),
50 fEmcMinEnergyThreshold(0),
51 fEmcTimeGate(0),
52 fLogWeight(0),
53 fDigitsInCluster(0),
54 fOnlineMode(true),
55 fDigitArrayPtr(0),
56 fEmcRecPointsPtr(0),
57 fDigitPtr(0),
58 fDigitContainerPtr(0),
59 fRecPointContainerPtr(0),
60 fPHOSGeometry(0),
61 fGetterPtr(0)
aac22523 62{
6e709a0d 63 //See header file for documentation
9cc0deb1 64 fPHOSGeometry = AliPHOSGeometry::GetInstance("noCPV");
65 fEmcClusteringThreshold = 0.2;
66 fEmcMinEnergyThreshold = 0.03;
d949e02e 67 fEmcTimeGate = 1.e-6 ;
9cc0deb1 68 fLogWeight = 4.5;
aac22523 69
9cc0deb1 70
aac22523 71}//end
72
9c9d15d6 73
9cc0deb1 74AliHLTPHOSClusterizer::~AliHLTPHOSClusterizer()
aac22523 75{
2374af72 76 //See header file for documentation
aac22523 77}
78
25b7f84c 79void
80AliHLTPHOSClusterizer::SetRecPointContainer(AliHLTPHOSRecPointContainerStruct* recPointContainerPtr)
81 {
82 fRecPointContainerPtr = recPointContainerPtr;
83 fRecPointContainerPtr->fNRecPoints = 0;
84 }
2374af72 85
9cc0deb1 86void
7e88424f 87AliHLTPHOSClusterizer::SetRecoParameters(AliPHOSRecoParam* params)
9cc0deb1 88{
2374af72 89 //see header file for documentation
ae1c1854 90#ifndef HAVE_NOT_PHOSRECOPARAMEMC // set from configure if EMC functionality not available in AliPHOSRecoParam
91 // the new AliPHOSRecoParam functions, available from revision
7e88424f 92 fEmcClusteringThreshold = params->GetEMCClusteringThreshold();
93 fEmcMinEnergyThreshold = params->GetEMCMinE();
94 fLogWeight = params->GetEMCLogWeight();
ae1c1854 95#else
96 fEmcClusteringThreshold = params->GetClusteringThreshold();
97 fEmcMinEnergyThreshold = params->GetMinE();
98 fLogWeight = params->GetLogWeight();
99#endif
9cc0deb1 100}
aac22523 101
9cc0deb1 102void
8b035d03 103AliHLTPHOSClusterizer::SetOfflineMode(AliPHOSLoader* getter)
aac22523 104{
2374af72 105 //see header file for documentation
9cc0deb1 106 fRecPointContainerPtr = new AliHLTPHOSRecPointContainerStruct();
107 fDigitContainerPtr = new AliHLTPHOSDigitContainerDataStruct();
108 fGetterPtr = getter;
109 fDigitArrayPtr = fGetterPtr->Digits();
110 fEmcRecPointsPtr = fGetterPtr->EmcRecPoints();
111 fOnlineMode = false;
112}
aac22523 113
9cc0deb1 114Int_t
115AliHLTPHOSClusterizer::GetEvent(Int_t i)
116{
2374af72 117 //see header file for documentation
9cc0deb1 118 Int_t coord[4];
aac22523 119
8b035d03 120 // fGetterPtr->Event(i, "D");
121 fGetterPtr->GetEvent();
9cc0deb1 122 for(Int_t j = 0; j < fDigitArrayPtr->GetEntries(); j++)
aac22523 123 {
9cc0deb1 124 fDigitPtr = (AliPHOSDigit*)fDigitArrayPtr->At(j);
125 fPHOSGeometry->AbsToRelNumbering(fDigitPtr->GetId(), coord);
126 fDigitContainerPtr->fDigitDataStruct[j].fX = coord[3];
127 fDigitContainerPtr->fDigitDataStruct[j].fZ = coord[2];
128 fDigitContainerPtr->fDigitDataStruct[j].fModule = coord[0];
129 fDigitContainerPtr->fDigitDataStruct[j].fEnergy = fDigitPtr->GetEnergy();
130 fDigitContainerPtr->fDigitDataStruct[j].fTime = fDigitPtr->GetTime();
131 }
132 fDigitContainerPtr->fNDigits = fDigitArrayPtr->GetEntriesFast();
133 return 0;
134}
aac22523 135
9cc0deb1 136Int_t
137AliHLTPHOSClusterizer::GetNEvents()
138{
2374af72 139 //see header file for documentation
9cc0deb1 140 if(fOnlineMode)
141 {
8efbf5fe 142 // Logging(kHLTLogWarning, __FILE__ , "information not available" , "GetNEvents() Number of events not available in online mod");
9cc0deb1 143 return -1;
144 }
145 return fGetterPtr->MaxEvent();
146}
aac22523 147
aac22523 148
9cc0deb1 149Int_t
150AliHLTPHOSClusterizer::ClusterizeEvent()
aac22523 151{
2374af72 152 //see header file for documentation
aac22523 153 Int_t nRecPoints = 0;
9cc0deb1 154 UInt_t i = 0;
aac22523 155
9cc0deb1 156 AliHLTPHOSRecPointDataStruct *recPoint = 0;
d949e02e 157
9cc0deb1 158 //Clusterization starts
159 for(i = 0; i < fDigitContainerPtr->fNDigits; i++)
160 {
aac22523 161
d949e02e 162 fDigitsInCluster = 0;
9cc0deb1 163 if(fDigitContainerPtr->fDigitDataStruct[i].fEnergy < fEmcClusteringThreshold)
aac22523 164 {
9cc0deb1 165 continue;
aac22523 166 }
9cc0deb1 167 recPoint = &(fRecPointContainerPtr->fRecPointArray[nRecPoints]);
168 recPoint->fAmp = 0;
25b7f84c 169 //TODO!!!!!!!
170 recPoint->fModule = fDigitContainerPtr->fDigitDataStruct[i].fModule;
171 //TODO!!!!!!!
9cc0deb1 172 //recPoint->
173 recPoint->fDigitsList[fDigitsInCluster] = fDigitContainerPtr->fDigitDataStruct[i];
174 recPoint->fAmp += fDigitContainerPtr->fDigitDataStruct[i].fEnergy;
175 fDigitContainerPtr->fDigitDataStruct[i].fEnergy = 0;
176 fDigitsInCluster++;
177 nRecPoints++;
178 ScanForNeighbourDigits(i, recPoint);
179
180 recPoint->fMultiplicity = fDigitsInCluster;
d949e02e 181
9cc0deb1 182 }//end of clusterization
183 fRecPointContainerPtr->fNRecPoints = nRecPoints;
aac22523 184
9cc0deb1 185 return nRecPoints;
186}
aac22523 187
9cc0deb1 188void
189AliHLTPHOSClusterizer::ScanForNeighbourDigits(Int_t index, AliHLTPHOSRecPointDataStruct* recPoint)
aac22523 190
aac22523 191{
2374af72 192 //see header file for documentation
9cc0deb1 193
194 for(UInt_t j = 0; j < fDigitContainerPtr->fNDigits; j++)
aac22523 195 {
9cc0deb1 196 if(fDigitContainerPtr->fDigitDataStruct[j].fEnergy > fEmcMinEnergyThreshold)
197 {
198 switch(AreNeighbours(&(fDigitContainerPtr->fDigitDataStruct[index]),
199 &(fDigitContainerPtr->fDigitDataStruct[j])))
200 {
201 case 0:
202 break;
203 case 1:
204 recPoint->fDigitsList[fDigitsInCluster] = fDigitContainerPtr->fDigitDataStruct[j];
205 recPoint->fAmp += fDigitContainerPtr->fDigitDataStruct[j].fEnergy;
206 fDigitContainerPtr->fDigitDataStruct[j].fEnergy = 0;
207 fDigitsInCluster++;
208 ScanForNeighbourDigits(j, recPoint);
209 break;
210 case 2:
211 break;
212 }
aac22523 213 }
9cc0deb1 214 }
215 return;
216}
6e709a0d 217
aac22523 218
9cc0deb1 219Int_t
220AliHLTPHOSClusterizer::AreNeighbours(AliHLTPHOSDigitDataStruct* digit1,
221 AliHLTPHOSDigitDataStruct* digit2)
6e709a0d 222{
2374af72 223 //see header file for documentation
d2b84453 224
9cc0deb1 225 if ( (digit1->fModule == digit2->fModule) /*&& (coord1[1]==coord2[1])*/ ) // inside the same PHOS module
226 {
9cc0deb1 227 Int_t rowdiff = TMath::Abs( digit1->fZ - digit2->fZ );
228 Int_t coldiff = TMath::Abs( digit1->fX - digit2->fX );
229
230 if (( coldiff <= 1 ) && ( rowdiff <= 1 ))
6e709a0d 231 {
9cc0deb1 232 if(TMath::Abs(digit1->fTime - digit2->fTime ) < fEmcTimeGate)
d949e02e 233 {
d949e02e 234 return 1;
235 }
6e709a0d 236 }
6e709a0d 237 }
238 return 0;
239}
aac22523 240
9cc0deb1 241void
242AliHLTPHOSClusterizer::CalculateCenterOfGravity()
aac22523 243{
2374af72 244 //see header file for documentation
9cc0deb1 245 Float_t wtot = 0.;
9cc0deb1 246 Float_t x = 0.;
247 Float_t z = 0.;
248 Float_t xi = 0.;
249 Float_t zi = 0.;
aac22523 250
9cc0deb1 251 AliHLTPHOSRecPointDataStruct *recPoint = 0;
252 AliHLTPHOSDigitDataStruct *digit = 0;
1804b020 253 UInt_t iDigit = 0;
254 UInt_t iRecPoint = 0;
91b95d47 255
9cc0deb1 256 for(iRecPoint=0; iRecPoint<fRecPointContainerPtr->fNRecPoints; iRecPoint++)
aac22523 257 {
9cc0deb1 258 recPoint = &(fRecPointContainerPtr->fRecPointArray[iRecPoint]);
259 for(iDigit = 0; iDigit < recPoint->fMultiplicity; iDigit++)
aac22523 260 {
9cc0deb1 261 digit = &(recPoint->fDigitsList[iDigit]);
262
263 //fPHOSGeometry->AbsToRelNumbering(digit->fID, relid) ;
264 // fPHOSGeometry->RelPosInModule(relid, xi, zi);
265 xi = digit->fX;
266 zi = digit->fZ;
267
268 if (recPoint->fAmp > 0 && digit->fEnergy > 0)
269 {
270 Float_t w = TMath::Max( 0., fLogWeight + TMath::Log( digit->fEnergy / recPoint->fAmp ) ) ;
271 x += xi * w ;
272 z += zi * w ;
273 wtot += w ;
274 }
275 }
276
277 if (wtot>0)
278 {
279 recPoint->fX = x/wtot ;
280 recPoint->fZ = z/wtot ;
281 }
282 else
283 {
284 recPoint->fAmp = 0;
aac22523 285 }
286 }
9cc0deb1 287
288}
aac22523 289
aac22523 290