commented out methods to be adapted to the new design
[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.;
c3c187e5 65 fB = 0.0000001 ;
6b9b768e 66 fGeom = AliPHOSGeometry::GetInstance();
d15a28e7 67 fNumberOfEmcClusters = 0 ;
68 fNumberOfPpsdClusters = 0 ;
c3c187e5 69 fEmcClusteringThreshold = 0.2;
70 fEmcEnergyThreshold = 0.05;
71 fPpsdClusteringThreshold = 0.0000002 ;
72 fPpsdEnergyThreshold = 0.0000002 ;
ed4205d8 73 fCpvClusteringThreshold = 0.0;
c3c187e5 74 fCpvEnergyThreshold = 0.09;
d15a28e7 75 fW0 = 4.5 ;
c3c187e5 76 fLocMaxCut = 0.03 ;
77 fW0CPV = 4.0 ;
78 fLocMaxCutCPV = 0.03 ;
79
d15a28e7 80}
81
82//____________________________________________________________________________
83Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)
84{
b2a60966 85 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
86 // = 1 are neighbour
87 // = 2 are not neighbour but do not continue searching
88 // neighbours are defined as digits having at least common vertex
89 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
90 // which is compared to a digit (d2) not yet in a cluster
91
d15a28e7 92 Int_t rv = 0 ;
93
d15a28e7 94 Int_t relid1[4] ;
6b9b768e 95 fGeom->AbsToRelNumbering(d1->GetId(), relid1) ;
d15a28e7 96
97 Int_t relid2[4] ;
6b9b768e 98 fGeom->AbsToRelNumbering(d2->GetId(), relid2) ;
d15a28e7 99
100 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module and the same PPSD Module
92862013 101 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
102 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
d15a28e7 103
92862013 104 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
d15a28e7 105 rv = 1 ;
106 }
107 else {
108 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
109 rv = 2; // Difference in row numbers is too large to look further
110 }
111
112 }
113 else {
114
115 if( (relid1[0] < relid2[0]) || (relid1[1] < relid2[1]) )
116 rv=2 ;
117
118 }
d72dfbc3 119
120 //Do NOT clusterize upper PPSD
ed4205d8 121 if( IsInPpsd(d1) && IsInPpsd(d2) &&
122 relid1[1] > 0 &&
d72dfbc3 123 relid1[1] < fGeom->GetNumberOfPadsPhi()*fGeom->GetNumberOfPadsPhi() ) rv = 2 ;
124
d15a28e7 125 return rv ;
126}
127
128//____________________________________________________________________________
129void AliPHOSClusterizerv1::FillandSort(const DigitsList * dl, TObjArray * tl)
130{
b2a60966 131 // Copies the digits with energy above thershold and sorts the list
d15a28e7 132 // according to increasing Id number
133
d15a28e7 134 TIter next(dl) ;
135 AliPHOSDigit * digit ;
136
137 while ( (digit = (AliPHOSDigit *)next()) ) {
d15a28e7 138 Float_t ene = Calibrate(digit->GetAmp()) ;
f2bc1b87 139 if ( IsInEmc (digit) && ene > fEmcEnergyThreshold )
140 tl->Add(digit) ;
141 else if ( IsInPpsd (digit) && ene > fPpsdEnergyThreshold )
142 tl->Add(digit) ;
143 else if ( IsInCpv (digit) && ene > fCpvEnergyThreshold )
144 tl->Add(digit) ;
d15a28e7 145 }
146 tl->Sort() ;
147}
148
149//____________________________________________________________________________
150void AliPHOSClusterizerv1:: GetNumberOfClustersFound(Int_t * numb)
151{
b2a60966 152 // Fills numb with the number of EMC (numb[0]) clusters found
153 // PPSD (numb[1]) clusters found
154
155 numb[0] = fNumberOfEmcClusters ;
156 numb[1] = fNumberOfPpsdClusters ;
d15a28e7 157}
158
159//____________________________________________________________________________
160Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit)
161{
b2a60966 162 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
163
9f616d61 164 Bool_t rv = kFALSE ;
d15a28e7 165
d15a28e7 166 Int_t relid[4] ;
6b9b768e 167 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
d15a28e7 168
ed4205d8 169 if ( relid[1] == 0 ) rv = kTRUE;
170
171 return rv ;
172}
173
174//____________________________________________________________________________
175Bool_t AliPHOSClusterizerv1::IsInPpsd(AliPHOSDigit * digit)
176{
fad3e5b9 177 // Tells if (true) or not (false) the digit is in a PHOS-PPSD module
ed4205d8 178
179 Bool_t rv = kFALSE ;
180
181 Int_t relid[4] ;
182 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
183
184 if ( relid[1] > 0 && relid[0] > fGeom->GetNCPVModules() ) rv = kTRUE;
185
186 return rv ;
187}
188
189//____________________________________________________________________________
190Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit)
191{
fad3e5b9 192 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
ed4205d8 193
194 Bool_t rv = kFALSE ;
195
196 Int_t relid[4] ;
197 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
198
199 if ( relid[1] > 0 && relid[0] <= fGeom->GetNCPVModules() ) rv = kTRUE;
d15a28e7 200
201 return rv ;
202}
203
204//____________________________________________________________________________
88714635 205void AliPHOSClusterizerv1::MakeClusters(const DigitsList * dl,
206 AliPHOSRecPoint::RecPointsList * emcl,
fad3e5b9 207 AliPHOSRecPoint::RecPointsList * ppsdl)
d15a28e7 208{
b2a60966 209 // Steering method to construct the clusters stored in a list of Reconstructed Points
210 // A cluster is defined as a list of neighbour digits
c161df70 211
b73f246d 212 fNumberOfEmcClusters = 0 ;
c161df70 213 fNumberOfPpsdClusters = 0 ;
b73f246d 214 fNumberOfCpvClusters = 0 ;
c161df70 215
d15a28e7 216 // Fill and sort the working digits list
92862013 217 TObjArray tempodigitslist( dl->GetEntries() ) ;
218 FillandSort(dl, &tempodigitslist) ;
d15a28e7 219
220 // Clusterization starts
92862013 221 TIter nextdigit(&tempodigitslist) ;
d15a28e7 222 AliPHOSDigit * digit ;
92862013 223 Bool_t notremoved = kTRUE ;
6ad0bfa0 224
d15a28e7 225 while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digits
226 AliPHOSRecPoint * clu ;
c161df70 227
83974468 228 AliPHOSDigit ** clusterdigitslist = new AliPHOSDigit*[dl->GetEntries()] ;
d15a28e7 229 Int_t index ;
f2bc1b87 230
b73f246d 231 if (( IsInEmc (digit) && Calibrate(digit->GetAmp()) > fEmcClusteringThreshold ) ||
232 ( IsInPpsd(digit) && Calibrate(digit->GetAmp()) > fPpsdClusteringThreshold ) ||
233 ( IsInCpv (digit) && Calibrate(digit->GetAmp()) > fCpvClusteringThreshold ) ) {
f2bc1b87 234
d15a28e7 235 Int_t iDigitInCluster = 0 ;
236
6ad0bfa0 237 if ( IsInEmc(digit) ) {
83974468 238 // start a new EMC RecPoint
d72dfbc3 239 if(fNumberOfEmcClusters >= emcl->GetSize()) emcl->Expand(2*fNumberOfEmcClusters+1) ;
83974468 240 (*emcl)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint(fW0, fLocMaxCut) ;
6b9b768e 241 clu = (AliPHOSEmcRecPoint *) emcl->At(fNumberOfEmcClusters) ;
9f616d61 242 fNumberOfEmcClusters++ ;
243 clu->AddDigit(*digit, Calibrate(digit->GetAmp())) ;
83974468 244 clusterdigitslist[iDigitInCluster] = digit ;
9f616d61 245 iDigitInCluster++ ;
92862013 246 tempodigitslist.Remove(digit) ;
ca77b032 247
d72dfbc3 248 } else {
83974468 249
fad3e5b9 250 // start a new PPSD/CPV cluster
d72dfbc3 251 if(fNumberOfPpsdClusters >= ppsdl->GetSize()) ppsdl->Expand(2*fNumberOfPpsdClusters+1);
fad3e5b9 252 if (IsInPpsd(digit))
d72dfbc3 253 (*ppsdl)[fNumberOfPpsdClusters] = new AliPHOSPpsdRecPoint() ;
fad3e5b9 254 else
255 (*ppsdl)[fNumberOfPpsdClusters] = new AliPHOSCpvRecPoint(fW0CPV, fLocMaxCutCPV) ;
256 clu = (AliPHOSPpsdRecPoint *) ppsdl->At(fNumberOfPpsdClusters) ;
257 fNumberOfPpsdClusters++ ;
258
6ad0bfa0 259 clu->AddDigit(*digit, Calibrate(digit->GetAmp()) ) ;
83974468 260 clusterdigitslist[iDigitInCluster] = digit ;
9f616d61 261 iDigitInCluster++ ;
92862013 262 tempodigitslist.Remove(digit) ;
d15a28e7 263 nextdigit.Reset() ;
264
9f616d61 265 // Here we remove resting EMC digits, which cannot make cluster
fad3e5b9 266
92862013 267 if( notremoved ) {
9f616d61 268 while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
9f616d61 269 if( IsInEmc(digit) )
92862013 270 tempodigitslist.Remove(digit) ;
d15a28e7 271 else
272 break ;
d72dfbc3 273 }
274 notremoved = kFALSE ;
275 }
d15a28e7 276
277 } // else
278
279 nextdigit.Reset() ;
fad3e5b9 280
d15a28e7 281 AliPHOSDigit * digitN ;
282 index = 0 ;
9f616d61 283 while (index < iDigitInCluster){ // scan over digits already in cluster
83974468 284 digit = clusterdigitslist[index] ;
9f616d61 285 index++ ;
d15a28e7 286 while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits
d72dfbc3 287 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
d15a28e7 288 switch (ineb ) {
9f616d61 289 case 0 : // not a neighbour
d72dfbc3 290 break ;
9f616d61 291 case 1 : // are neighbours
83974468 292 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp() ) ) ;
293 clusterdigitslist[iDigitInCluster] = digitN ;
9f616d61 294 iDigitInCluster++ ;
92862013 295 tempodigitslist.Remove(digitN) ;
d15a28e7 296 break ;
9f616d61 297 case 2 : // too far from each other
d15a28e7 298 goto endofloop;
299 } // switch
300
301 } // while digitN
fad3e5b9 302
d15a28e7 303 endofloop: ;
304 nextdigit.Reset() ;
305
306 } // loop over cluster
ad8cfaf4 307
308 clu->EvalAll() ;
309 } // energy theshold
d72dfbc3 310
31aa6d6c 311 delete[] clusterdigitslist ;
ad8cfaf4 312
31aa6d6c 313
d15a28e7 314 } // while digit
315
92862013 316 tempodigitslist.Clear() ;
83974468 317
c161df70 318 ppsdl->Sort() ;
319 Int_t index ;
320 for(index = 0; index < ppsdl->GetEntries(); index++)
321 ((AliPHOSPpsdRecPoint *)ppsdl->At(index))->SetIndexInList(index) ;
d15a28e7 322}
323
324//____________________________________________________________________________
325void AliPHOSClusterizerv1::PrintParameters()
326{
b2a60966 327 // Print the energy thresholds
328
d15a28e7 329 cout << "PHOS Clusterizer version 1 :" << endl
330 << " EMC Clustering threshold = " << fEmcClusteringThreshold << endl
331 << " EMC Energy threshold = " << fEmcEnergyThreshold << endl
332 << " PPSD Clustering threshold = " << fPpsdClusteringThreshold << endl
ed4205d8 333 << " PPSD Energy threshold = " << fPpsdEnergyThreshold << endl
334 << " CPV Clustering threshold = " << fCpvClusteringThreshold << endl
335 << " CPV Energy threshold = " << fCpvEnergyThreshold << endl ;
d15a28e7 336}