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