the MIXT geometry (IHEP+GPS2) has been introduced
[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,
b73f246d 221 AliPHOSRecPoint::RecPointsList * ppsdl,
222 AliPHOSRecPoint::RecPointsList * cpvl)
d15a28e7 223{
b2a60966 224 // Steering method to construct the clusters stored in a list of Reconstructed Points
225 // A cluster is defined as a list of neighbour digits
c161df70 226
b73f246d 227 fNumberOfEmcClusters = 0 ;
c161df70 228 fNumberOfPpsdClusters = 0 ;
b73f246d 229 fNumberOfCpvClusters = 0 ;
c161df70 230
d15a28e7 231 // Fill and sort the working digits list
92862013 232 TObjArray tempodigitslist( dl->GetEntries() ) ;
233 FillandSort(dl, &tempodigitslist) ;
d15a28e7 234
235 // Clusterization starts
92862013 236 TIter nextdigit(&tempodigitslist) ;
d15a28e7 237 AliPHOSDigit * digit ;
92862013 238 Bool_t notremoved = kTRUE ;
6ad0bfa0 239
d15a28e7 240 while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digits
241 AliPHOSRecPoint * clu ;
c161df70 242
83974468 243 AliPHOSDigit ** clusterdigitslist = new AliPHOSDigit*[dl->GetEntries()] ;
d15a28e7 244 Int_t index ;
b73f246d 245 if (( IsInEmc (digit) && Calibrate(digit->GetAmp()) > fEmcClusteringThreshold ) ||
246 ( IsInPpsd(digit) && Calibrate(digit->GetAmp()) > fPpsdClusteringThreshold ) ||
247 ( IsInCpv (digit) && Calibrate(digit->GetAmp()) > fCpvClusteringThreshold ) ) {
d15a28e7 248
249 Int_t iDigitInCluster = 0 ;
250
6ad0bfa0 251 if ( IsInEmc(digit) ) {
83974468 252 // start a new EMC RecPoint
d72dfbc3 253 if(fNumberOfEmcClusters >= emcl->GetSize()) emcl->Expand(2*fNumberOfEmcClusters+1) ;
83974468 254 (*emcl)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint(fW0, fLocMaxCut) ;
6b9b768e 255 clu = (AliPHOSEmcRecPoint *) emcl->At(fNumberOfEmcClusters) ;
9f616d61 256 fNumberOfEmcClusters++ ;
257 clu->AddDigit(*digit, Calibrate(digit->GetAmp())) ;
83974468 258 clusterdigitslist[iDigitInCluster] = digit ;
9f616d61 259 iDigitInCluster++ ;
92862013 260 tempodigitslist.Remove(digit) ;
ca77b032 261
d72dfbc3 262 } else {
83974468 263
264 // start a new PPSD cluster
d72dfbc3 265 if(fNumberOfPpsdClusters >= ppsdl->GetSize()) ppsdl->Expand(2*fNumberOfPpsdClusters+1);
b73f246d 266 if(fNumberOfCpvClusters >= cpvl ->GetSize()) cpvl ->Expand(2*fNumberOfCpvClusters +1);
ed4205d8 267 if (IsInPpsd(digit)) {
d72dfbc3 268 (*ppsdl)[fNumberOfPpsdClusters] = new AliPHOSPpsdRecPoint() ;
269 clu = (AliPHOSPpsdRecPoint *) ppsdl->At(fNumberOfPpsdClusters) ;
b73f246d 270 fNumberOfPpsdClusters++ ;
d72dfbc3 271 }
ed4205d8 272 else if (IsInCpv(digit) ) {
b73f246d 273 (*cpvl) [fNumberOfCpvClusters] = new AliPHOSCpvRecPoint(fW0CPV, fLocMaxCutCPV) ;
274 clu = (AliPHOSCpvRecPoint *) cpvl ->At(fNumberOfCpvClusters) ;
275 fNumberOfCpvClusters++ ;
d72dfbc3 276 }
ed4205d8 277 else {
278 cout << "AliPHOSClusterizerv1::MakeClusters: unknown configuration " << fGeom->GetName() << endl;
279 assert(0==1);
280 }
6ad0bfa0 281 clu->AddDigit(*digit, Calibrate(digit->GetAmp()) ) ;
83974468 282 clusterdigitslist[iDigitInCluster] = digit ;
9f616d61 283 iDigitInCluster++ ;
92862013 284 tempodigitslist.Remove(digit) ;
d15a28e7 285 nextdigit.Reset() ;
286
9f616d61 287 // Here we remove resting EMC digits, which cannot make cluster
288
92862013 289 if( notremoved ) {
9f616d61 290 while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
9f616d61 291 if( IsInEmc(digit) )
92862013 292 tempodigitslist.Remove(digit) ;
d15a28e7 293 else
294 break ;
d72dfbc3 295 }
296 notremoved = kFALSE ;
297 }
d15a28e7 298
299 } // else
300
301 nextdigit.Reset() ;
302
303 AliPHOSDigit * digitN ;
304 index = 0 ;
9f616d61 305 while (index < iDigitInCluster){ // scan over digits already in cluster
83974468 306 digit = clusterdigitslist[index] ;
9f616d61 307 index++ ;
d15a28e7 308 while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits
d72dfbc3 309 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
d15a28e7 310 switch (ineb ) {
9f616d61 311 case 0 : // not a neighbour
d72dfbc3 312 break ;
9f616d61 313 case 1 : // are neighbours
83974468 314 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp() ) ) ;
315 clusterdigitslist[iDigitInCluster] = digitN ;
9f616d61 316 iDigitInCluster++ ;
92862013 317 tempodigitslist.Remove(digitN) ;
d15a28e7 318 break ;
9f616d61 319 case 2 : // too far from each other
d15a28e7 320 goto endofloop;
321 } // switch
322
323 } // while digitN
324
325 endofloop: ;
326 nextdigit.Reset() ;
327
328 } // loop over cluster
d72dfbc3 329 } //below energy theshold
330
31aa6d6c 331 delete[] clusterdigitslist ;
332
d15a28e7 333 } // while digit
334
92862013 335 tempodigitslist.Clear() ;
83974468 336
c161df70 337 ppsdl->Sort() ;
338 Int_t index ;
339 for(index = 0; index < ppsdl->GetEntries(); index++)
340 ((AliPHOSPpsdRecPoint *)ppsdl->At(index))->SetIndexInList(index) ;
d15a28e7 341}
342
343//____________________________________________________________________________
344void AliPHOSClusterizerv1::PrintParameters()
345{
b2a60966 346 // Print the energy thresholds
347
d15a28e7 348 cout << "PHOS Clusterizer version 1 :" << endl
349 << " EMC Clustering threshold = " << fEmcClusteringThreshold << endl
350 << " EMC Energy threshold = " << fEmcEnergyThreshold << endl
351 << " PPSD Clustering threshold = " << fPpsdClusteringThreshold << endl
ed4205d8 352 << " PPSD Energy threshold = " << fPpsdEnergyThreshold << endl
353 << " CPV Clustering threshold = " << fCpvClusteringThreshold << endl
354 << " CPV Energy threshold = " << fCpvEnergyThreshold << endl ;
d15a28e7 355}