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