Reconstruction part now handle all geometry options
[u/mrichter/AliRoot.git] / PHOS / AliPHOSClusterizerv1.cxx
CommitLineData
d15a28e7 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
15
b2a60966 16/* $Id$ */
17
d72dfbc3 18/* $Log:
19 1 October 2000. Yuri Kharlov:
20 AreNeighbours()
21 PPSD upper layer is considered if number of layers>1
22
23 18 October 2000. Yuri Kharlov:
24 AliPHOSClusterizerv1()
25 CPV clusterizing parameters added
26
27 MakeClusters()
28 After first PPSD digit remove EMC digits only once
29*/
30
d15a28e7 31//_________________________________________________________________________
b2a60966 32// Implementation version 1 of the clusterization algorithm
33//
34//*-- Author: Yves Schutz (SUBATECH)
d15a28e7 35//////////////////////////////////////////////////////////////////////////////
36
ed4205d8 37#include <assert.h>
38
d15a28e7 39// --- ROOT system ---
40
41#include "TMath.h"
42
43// --- Standard library ---
44
de9ec31b 45#include <iostream.h>
d15a28e7 46
47// --- AliRoot header files ---
48
49#include "AliPHOSClusterizerv1.h"
50#include "AliPHOSDigit.h"
51#include "AliPHOSEmcRecPoint.h"
52#include "AliPHOSPpsdRecPoint.h"
0b06c60d 53#include "AliPHOSCpvRecPoint.h"
d15a28e7 54#include "AliPHOSv0.h"
55#include "AliRun.h"
56
57ClassImp(AliPHOSClusterizerv1)
58
59//____________________________________________________________________________
60AliPHOSClusterizerv1::AliPHOSClusterizerv1()
61{
b2a60966 62 // default ctor (to be used)
63
d15a28e7 64 fA = 0.;
65 fB = 0.01 ;
6b9b768e 66 fGeom = AliPHOSGeometry::GetInstance();
d15a28e7 67 fNumberOfEmcClusters = 0 ;
68 fNumberOfPpsdClusters = 0 ;
69 fEmcClusteringThreshold = 0.1;
70 fEmcEnergyThreshold = 0.01;
d72dfbc3 71 fPpsdClusteringThreshold = 0.0;
72 fPpsdEnergyThreshold = 0.1;
ed4205d8 73 fCpvClusteringThreshold = 0.0;
74 fCpvEnergyThreshold = 0.1;
d15a28e7 75 fW0 = 4.5 ;
76 fLocMaxCut = 0.06 ;
d72dfbc3 77 fW0CPV = 4.5 ;
78 fLocMaxCutCPV = 0.06 ;
d15a28e7 79}
80
81//____________________________________________________________________________
82Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)
83{
b2a60966 84 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
85 // = 1 are neighbour
86 // = 2 are not neighbour but do not continue searching
87 // neighbours are defined as digits having at least common vertex
88 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
89 // which is compared to a digit (d2) not yet in a cluster
90
d15a28e7 91 Int_t rv = 0 ;
92
d15a28e7 93 Int_t relid1[4] ;
6b9b768e 94 fGeom->AbsToRelNumbering(d1->GetId(), relid1) ;
d15a28e7 95
96 Int_t relid2[4] ;
6b9b768e 97 fGeom->AbsToRelNumbering(d2->GetId(), relid2) ;
d15a28e7 98
99 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module and the same PPSD Module
92862013 100 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
101 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
d15a28e7 102
92862013 103 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
d15a28e7 104 rv = 1 ;
105 }
106 else {
107 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
108 rv = 2; // Difference in row numbers is too large to look further
109 }
110
111 }
112 else {
113
114 if( (relid1[0] < relid2[0]) || (relid1[1] < relid2[1]) )
115 rv=2 ;
116
117 }
d72dfbc3 118
119 //Do NOT clusterize upper PPSD
ed4205d8 120 if( IsInPpsd(d1) && IsInPpsd(d2) &&
121 relid1[1] > 0 &&
d72dfbc3 122 relid1[1] < fGeom->GetNumberOfPadsPhi()*fGeom->GetNumberOfPadsPhi() ) rv = 2 ;
123
d15a28e7 124 return rv ;
125}
126
127//____________________________________________________________________________
128void AliPHOSClusterizerv1::FillandSort(const DigitsList * dl, TObjArray * tl)
129{
b2a60966 130 // Copies the digits with energy above thershold and sorts the list
d15a28e7 131 // according to increasing Id number
132
d15a28e7 133 Int_t relid[4] ;
134
135 TIter next(dl) ;
136 AliPHOSDigit * digit ;
137
138 while ( (digit = (AliPHOSDigit *)next()) ) {
cf239357 139
d15a28e7 140 Int_t id = digit->GetId() ;
141 Float_t ene = Calibrate(digit->GetAmp()) ;
6b9b768e 142 fGeom->AbsToRelNumbering(id, relid) ;
d15a28e7 143 if(relid[1]==0){ // EMC
6a3f1304 144 if ( ene > fEmcEnergyThreshold )
d15a28e7 145 tl->Add(digit) ;
146 }
147
148 else { //Ppsd
149 if ( ene > fPpsdEnergyThreshold )
6a3f1304 150 tl->Add(digit) ;
d15a28e7 151 }
152
153 }
154 tl->Sort() ;
155}
156
157//____________________________________________________________________________
158void AliPHOSClusterizerv1:: GetNumberOfClustersFound(Int_t * numb)
159{
b2a60966 160 // Fills numb with the number of EMC (numb[0]) clusters found
161 // PPSD (numb[1]) clusters found
162
163 numb[0] = fNumberOfEmcClusters ;
164 numb[1] = fNumberOfPpsdClusters ;
d15a28e7 165}
166
167//____________________________________________________________________________
168Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit)
169{
b2a60966 170 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
171
9f616d61 172 Bool_t rv = kFALSE ;
d15a28e7 173
d15a28e7 174 Int_t relid[4] ;
6b9b768e 175 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
d15a28e7 176
ed4205d8 177 if ( relid[1] == 0 ) rv = kTRUE;
178
179 return rv ;
180}
181
182//____________________________________________________________________________
183Bool_t AliPHOSClusterizerv1::IsInPpsd(AliPHOSDigit * digit)
184{
fad3e5b9 185 // Tells if (true) or not (false) the digit is in a PHOS-PPSD module
ed4205d8 186
187 Bool_t rv = kFALSE ;
188
189 Int_t relid[4] ;
190 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
191
192 if ( relid[1] > 0 && relid[0] > fGeom->GetNCPVModules() ) rv = kTRUE;
193
194 return rv ;
195}
196
197//____________________________________________________________________________
198Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit)
199{
fad3e5b9 200 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
ed4205d8 201
202 Bool_t rv = kFALSE ;
203
204 Int_t relid[4] ;
205 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
206
207 if ( relid[1] > 0 && relid[0] <= fGeom->GetNCPVModules() ) rv = kTRUE;
d15a28e7 208
209 return rv ;
210}
211
212//____________________________________________________________________________
88714635 213void AliPHOSClusterizerv1::MakeClusters(const DigitsList * dl,
214 AliPHOSRecPoint::RecPointsList * emcl,
fad3e5b9 215 AliPHOSRecPoint::RecPointsList * ppsdl)
d15a28e7 216{
b2a60966 217 // Steering method to construct the clusters stored in a list of Reconstructed Points
218 // A cluster is defined as a list of neighbour digits
c161df70 219
b73f246d 220 fNumberOfEmcClusters = 0 ;
c161df70 221 fNumberOfPpsdClusters = 0 ;
b73f246d 222 fNumberOfCpvClusters = 0 ;
c161df70 223
d15a28e7 224 // Fill and sort the working digits list
92862013 225 TObjArray tempodigitslist( dl->GetEntries() ) ;
226 FillandSort(dl, &tempodigitslist) ;
d15a28e7 227
228 // Clusterization starts
92862013 229 TIter nextdigit(&tempodigitslist) ;
d15a28e7 230 AliPHOSDigit * digit ;
92862013 231 Bool_t notremoved = kTRUE ;
6ad0bfa0 232
d15a28e7 233 while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digits
234 AliPHOSRecPoint * clu ;
c161df70 235
83974468 236 AliPHOSDigit ** clusterdigitslist = new AliPHOSDigit*[dl->GetEntries()] ;
d15a28e7 237 Int_t index ;
b73f246d 238 if (( IsInEmc (digit) && Calibrate(digit->GetAmp()) > fEmcClusteringThreshold ) ||
239 ( IsInPpsd(digit) && Calibrate(digit->GetAmp()) > fPpsdClusteringThreshold ) ||
240 ( IsInCpv (digit) && Calibrate(digit->GetAmp()) > fCpvClusteringThreshold ) ) {
d15a28e7 241
242 Int_t iDigitInCluster = 0 ;
243
6ad0bfa0 244 if ( IsInEmc(digit) ) {
83974468 245 // start a new EMC RecPoint
d72dfbc3 246 if(fNumberOfEmcClusters >= emcl->GetSize()) emcl->Expand(2*fNumberOfEmcClusters+1) ;
83974468 247 (*emcl)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint(fW0, fLocMaxCut) ;
6b9b768e 248 clu = (AliPHOSEmcRecPoint *) emcl->At(fNumberOfEmcClusters) ;
9f616d61 249 fNumberOfEmcClusters++ ;
250 clu->AddDigit(*digit, Calibrate(digit->GetAmp())) ;
83974468 251 clusterdigitslist[iDigitInCluster] = digit ;
9f616d61 252 iDigitInCluster++ ;
92862013 253 tempodigitslist.Remove(digit) ;
ca77b032 254
d72dfbc3 255 } else {
83974468 256
fad3e5b9 257 // start a new PPSD/CPV cluster
d72dfbc3 258 if(fNumberOfPpsdClusters >= ppsdl->GetSize()) ppsdl->Expand(2*fNumberOfPpsdClusters+1);
fad3e5b9 259 if (IsInPpsd(digit))
d72dfbc3 260 (*ppsdl)[fNumberOfPpsdClusters] = new AliPHOSPpsdRecPoint() ;
fad3e5b9 261 else
262 (*ppsdl)[fNumberOfPpsdClusters] = new AliPHOSCpvRecPoint(fW0CPV, fLocMaxCutCPV) ;
263 clu = (AliPHOSPpsdRecPoint *) ppsdl->At(fNumberOfPpsdClusters) ;
264 fNumberOfPpsdClusters++ ;
265
6ad0bfa0 266 clu->AddDigit(*digit, Calibrate(digit->GetAmp()) ) ;
83974468 267 clusterdigitslist[iDigitInCluster] = digit ;
9f616d61 268 iDigitInCluster++ ;
92862013 269 tempodigitslist.Remove(digit) ;
d15a28e7 270 nextdigit.Reset() ;
271
9f616d61 272 // Here we remove resting EMC digits, which cannot make cluster
fad3e5b9 273
92862013 274 if( notremoved ) {
9f616d61 275 while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
9f616d61 276 if( IsInEmc(digit) )
92862013 277 tempodigitslist.Remove(digit) ;
d15a28e7 278 else
279 break ;
d72dfbc3 280 }
281 notremoved = kFALSE ;
282 }
d15a28e7 283
284 } // else
285
286 nextdigit.Reset() ;
fad3e5b9 287
d15a28e7 288 AliPHOSDigit * digitN ;
289 index = 0 ;
9f616d61 290 while (index < iDigitInCluster){ // scan over digits already in cluster
83974468 291 digit = clusterdigitslist[index] ;
9f616d61 292 index++ ;
d15a28e7 293 while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits
d72dfbc3 294 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
d15a28e7 295 switch (ineb ) {
9f616d61 296 case 0 : // not a neighbour
d72dfbc3 297 break ;
9f616d61 298 case 1 : // are neighbours
83974468 299 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp() ) ) ;
300 clusterdigitslist[iDigitInCluster] = digitN ;
9f616d61 301 iDigitInCluster++ ;
92862013 302 tempodigitslist.Remove(digitN) ;
d15a28e7 303 break ;
9f616d61 304 case 2 : // too far from each other
d15a28e7 305 goto endofloop;
306 } // switch
307
308 } // while digitN
fad3e5b9 309
d15a28e7 310 endofloop: ;
311 nextdigit.Reset() ;
312
313 } // loop over cluster
d72dfbc3 314 } //below energy theshold
315
31aa6d6c 316 delete[] clusterdigitslist ;
317
d15a28e7 318 } // while digit
319
92862013 320 tempodigitslist.Clear() ;
83974468 321
c161df70 322 ppsdl->Sort() ;
323 Int_t index ;
324 for(index = 0; index < ppsdl->GetEntries(); index++)
325 ((AliPHOSPpsdRecPoint *)ppsdl->At(index))->SetIndexInList(index) ;
d15a28e7 326}
327
328//____________________________________________________________________________
329void AliPHOSClusterizerv1::PrintParameters()
330{
b2a60966 331 // Print the energy thresholds
332
d15a28e7 333 cout << "PHOS Clusterizer version 1 :" << endl
334 << " EMC Clustering threshold = " << fEmcClusteringThreshold << endl
335 << " EMC Energy threshold = " << fEmcEnergyThreshold << endl
336 << " PPSD Clustering threshold = " << fPpsdClusteringThreshold << endl
ed4205d8 337 << " PPSD Energy threshold = " << fPpsdEnergyThreshold << endl
338 << " CPV Clustering threshold = " << fCpvClusteringThreshold << endl
339 << " CPV Energy threshold = " << fCpvEnergyThreshold << endl ;
d15a28e7 340}