galice.cuts was not read any more
[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
140// cout << " clusterizerv1 " << endl ;
141// int nprim = digit->GetNprimary() ;
142// int * aprim = digit->GetPrimary() ;
143// for ( int ii = 0 ; ii < nprim ; ii++)
144// cout << ii << " prim = " << aprim[ii] << endl ;
145
d15a28e7 146 Int_t id = digit->GetId() ;
147 Float_t ene = Calibrate(digit->GetAmp()) ;
6b9b768e 148 fGeom->AbsToRelNumbering(id, relid) ;
d15a28e7 149 if(relid[1]==0){ // EMC
6a3f1304 150 if ( ene > fEmcEnergyThreshold )
d15a28e7 151 tl->Add(digit) ;
152 }
153
154 else { //Ppsd
155 if ( ene > fPpsdEnergyThreshold )
6a3f1304 156 tl->Add(digit) ;
d15a28e7 157 }
158
159 }
160 tl->Sort() ;
161}
162
163//____________________________________________________________________________
164void AliPHOSClusterizerv1:: GetNumberOfClustersFound(Int_t * numb)
165{
b2a60966 166 // Fills numb with the number of EMC (numb[0]) clusters found
167 // PPSD (numb[1]) clusters found
168
169 numb[0] = fNumberOfEmcClusters ;
170 numb[1] = fNumberOfPpsdClusters ;
d15a28e7 171}
172
173//____________________________________________________________________________
174Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit)
175{
b2a60966 176 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
177
9f616d61 178 Bool_t rv = kFALSE ;
d15a28e7 179
d15a28e7 180 Int_t relid[4] ;
6b9b768e 181 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
d15a28e7 182
ed4205d8 183 if ( relid[1] == 0 ) rv = kTRUE;
184
185 return rv ;
186}
187
188//____________________________________________________________________________
189Bool_t AliPHOSClusterizerv1::IsInPpsd(AliPHOSDigit * digit)
190{
191 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
192
193 Bool_t rv = kFALSE ;
194
195 Int_t relid[4] ;
196 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
197
198 if ( relid[1] > 0 && relid[0] > fGeom->GetNCPVModules() ) rv = kTRUE;
199
200 return rv ;
201}
202
203//____________________________________________________________________________
204Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit)
205{
206 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
207
208 Bool_t rv = kFALSE ;
209
210 Int_t relid[4] ;
211 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
212
213 if ( relid[1] > 0 && relid[0] <= fGeom->GetNCPVModules() ) rv = kTRUE;
d15a28e7 214
215 return rv ;
216}
217
218//____________________________________________________________________________
88714635 219void AliPHOSClusterizerv1::MakeClusters(const DigitsList * dl,
220 AliPHOSRecPoint::RecPointsList * emcl,
221 AliPHOSRecPoint::RecPointsList * ppsdl)
d15a28e7 222{
b2a60966 223 // Steering method to construct the clusters stored in a list of Reconstructed Points
224 // A cluster is defined as a list of neighbour digits
c161df70 225
226 fNumberOfEmcClusters = 0 ;
227 fNumberOfPpsdClusters = 0 ;
228
d15a28e7 229 // Fill and sort the working digits list
92862013 230 TObjArray tempodigitslist( dl->GetEntries() ) ;
231 FillandSort(dl, &tempodigitslist) ;
d15a28e7 232
233 // Clusterization starts
92862013 234 TIter nextdigit(&tempodigitslist) ;
d15a28e7 235 AliPHOSDigit * digit ;
92862013 236 Bool_t notremoved = kTRUE ;
6ad0bfa0 237
d15a28e7 238 while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digits
239 AliPHOSRecPoint * clu ;
c161df70 240
83974468 241 AliPHOSDigit ** clusterdigitslist = new AliPHOSDigit*[dl->GetEntries()] ;
d15a28e7 242 Int_t index ;
ed4205d8 243 if (( ( IsInEmc (digit) ) && ( Calibrate(digit->GetAmp() ) > fEmcClusteringThreshold ) ) ||
244 ( ( IsInPpsd(digit) ) && ( Calibrate(digit->GetAmp() ) > fPpsdClusteringThreshold ) ) ||
245 ( ( IsInCpv (digit) ) && ( Calibrate(digit->GetAmp() ) > fCpvClusteringThreshold ) ) ) {
d15a28e7 246
247 Int_t iDigitInCluster = 0 ;
248
6ad0bfa0 249 if ( IsInEmc(digit) ) {
83974468 250 // start a new EMC RecPoint
d72dfbc3 251 if(fNumberOfEmcClusters >= emcl->GetSize()) emcl->Expand(2*fNumberOfEmcClusters+1) ;
83974468 252 (*emcl)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint(fW0, fLocMaxCut) ;
6b9b768e 253 clu = (AliPHOSEmcRecPoint *) emcl->At(fNumberOfEmcClusters) ;
9f616d61 254 fNumberOfEmcClusters++ ;
255 clu->AddDigit(*digit, Calibrate(digit->GetAmp())) ;
83974468 256 clusterdigitslist[iDigitInCluster] = digit ;
9f616d61 257 iDigitInCluster++ ;
92862013 258 tempodigitslist.Remove(digit) ;
ca77b032 259
d72dfbc3 260 } else {
83974468 261
262 // start a new PPSD cluster
d72dfbc3 263 if(fNumberOfPpsdClusters >= ppsdl->GetSize()) ppsdl->Expand(2*fNumberOfPpsdClusters+1);
ed4205d8 264 if (IsInPpsd(digit)) {
d72dfbc3 265 (*ppsdl)[fNumberOfPpsdClusters] = new AliPHOSPpsdRecPoint() ;
266 clu = (AliPHOSPpsdRecPoint *) ppsdl->At(fNumberOfPpsdClusters) ;
267 }
ed4205d8 268 else if (IsInCpv(digit) ) {
0b06c60d 269 (*ppsdl)[fNumberOfPpsdClusters] = new AliPHOSCpvRecPoint(fW0CPV, fLocMaxCutCPV) ;
270 clu = (AliPHOSCpvRecPoint *) ppsdl->At(fNumberOfPpsdClusters) ;
d72dfbc3 271 }
ed4205d8 272 else {
273 cout << "AliPHOSClusterizerv1::MakeClusters: unknown configuration " << fGeom->GetName() << endl;
274 assert(0==1);
275 }
9f616d61 276 fNumberOfPpsdClusters++ ;
6ad0bfa0 277 clu->AddDigit(*digit, Calibrate(digit->GetAmp()) ) ;
83974468 278 clusterdigitslist[iDigitInCluster] = digit ;
9f616d61 279 iDigitInCluster++ ;
92862013 280 tempodigitslist.Remove(digit) ;
d15a28e7 281 nextdigit.Reset() ;
282
9f616d61 283 // Here we remove resting EMC digits, which cannot make cluster
284
92862013 285 if( notremoved ) {
9f616d61 286 while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
9f616d61 287 if( IsInEmc(digit) )
92862013 288 tempodigitslist.Remove(digit) ;
d15a28e7 289 else
290 break ;
d72dfbc3 291 }
292 notremoved = kFALSE ;
293 }
d15a28e7 294
295 } // else
296
297 nextdigit.Reset() ;
298
299 AliPHOSDigit * digitN ;
300 index = 0 ;
9f616d61 301 while (index < iDigitInCluster){ // scan over digits already in cluster
83974468 302 digit = clusterdigitslist[index] ;
9f616d61 303 index++ ;
d15a28e7 304 while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits
d72dfbc3 305 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
d15a28e7 306 switch (ineb ) {
9f616d61 307 case 0 : // not a neighbour
d72dfbc3 308 break ;
9f616d61 309 case 1 : // are neighbours
83974468 310 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp() ) ) ;
311 clusterdigitslist[iDigitInCluster] = digitN ;
9f616d61 312 iDigitInCluster++ ;
92862013 313 tempodigitslist.Remove(digitN) ;
d15a28e7 314 break ;
9f616d61 315 case 2 : // too far from each other
d15a28e7 316 goto endofloop;
317 } // switch
318
319 } // while digitN
320
321 endofloop: ;
322 nextdigit.Reset() ;
323
324 } // loop over cluster
d72dfbc3 325 } //below energy theshold
326
31aa6d6c 327 delete[] clusterdigitslist ;
328
d15a28e7 329 } // while digit
330
92862013 331 tempodigitslist.Clear() ;
83974468 332
c161df70 333 ppsdl->Sort() ;
334 Int_t index ;
335 for(index = 0; index < ppsdl->GetEntries(); index++)
336 ((AliPHOSPpsdRecPoint *)ppsdl->At(index))->SetIndexInList(index) ;
d15a28e7 337}
338
339//____________________________________________________________________________
340void AliPHOSClusterizerv1::PrintParameters()
341{
b2a60966 342 // Print the energy thresholds
343
d15a28e7 344 cout << "PHOS Clusterizer version 1 :" << endl
345 << " EMC Clustering threshold = " << fEmcClusteringThreshold << endl
346 << " EMC Energy threshold = " << fEmcEnergyThreshold << endl
347 << " PPSD Clustering threshold = " << fPpsdClusteringThreshold << endl
ed4205d8 348 << " PPSD Energy threshold = " << fPpsdEnergyThreshold << endl
349 << " CPV Clustering threshold = " << fCpvClusteringThreshold << endl
350 << " CPV Energy threshold = " << fCpvEnergyThreshold << endl ;
d15a28e7 351}