]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSClusterizerv1.cxx
default thresholds are changed to faster reconstruction
[u/mrichter/AliRoot.git] / PHOS / AliPHOSClusterizerv1.cxx
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
16 /* $Id$ */
17
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
31 //_________________________________________________________________________
32 //  Implementation version 1 of the clusterization algorithm 
33 // 
34 //*-- Author: Yves Schutz (SUBATECH) 
35 //////////////////////////////////////////////////////////////////////////////
36
37 #include <assert.h>
38
39 // --- ROOT system ---
40
41 #include "TMath.h" 
42
43 // --- Standard library ---
44
45 #include <iostream.h>
46
47 // --- AliRoot header files ---
48
49 #include "AliPHOSClusterizerv1.h"
50 #include "AliPHOSDigit.h"
51 #include "AliPHOSEmcRecPoint.h"
52 #include "AliPHOSPpsdRecPoint.h"
53 #include "AliPHOSCpvRecPoint.h"
54 #include "AliPHOSv0.h" 
55 #include "AliRun.h" 
56
57 ClassImp(AliPHOSClusterizerv1)
58
59 //____________________________________________________________________________
60 AliPHOSClusterizerv1::AliPHOSClusterizerv1()
61 {
62   // default ctor (to be used)
63
64   fA                       = 0.;
65   fB                       = 0.01 ;
66   fGeom                    = AliPHOSGeometry::GetInstance();
67   fNumberOfEmcClusters     = 0 ; 
68   fNumberOfPpsdClusters    = 0 ; 
69   fEmcClusteringThreshold  = 0.1;   
70   fEmcEnergyThreshold      = 0.01;    
71   fPpsdClusteringThreshold = 0.0;
72   fPpsdEnergyThreshold     = 0.1;  
73   fCpvClusteringThreshold  = 0.0;
74   fCpvEnergyThreshold      = 0.1;  
75   fW0                      = 4.5 ;
76   fLocMaxCut               = 0.06 ;
77   fW0CPV                   = 4.5 ;
78   fLocMaxCutCPV            = 0.06 ;
79 }
80
81 //____________________________________________________________________________
82 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)
83 {
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
91   Int_t rv = 0 ; 
92
93   Int_t relid1[4] ; 
94   fGeom->AbsToRelNumbering(d1->GetId(), relid1) ; 
95
96   Int_t relid2[4] ; 
97   fGeom->AbsToRelNumbering(d2->GetId(), relid2) ; 
98  
99   if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module and the same PPSD Module 
100     Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;  
101     Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;  
102     
103     if (( coldiff <= 1 )  && ( rowdiff <= 1 )){
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   }
118
119   //Do NOT clusterize upper PPSD  
120   if( IsInPpsd(d1) && IsInPpsd(d2) &&
121      relid1[1] > 0                 &&
122      relid1[1] < fGeom->GetNumberOfPadsPhi()*fGeom->GetNumberOfPadsPhi() ) rv = 2 ;
123
124   return rv ; 
125 }
126
127 //____________________________________________________________________________
128 void AliPHOSClusterizerv1::FillandSort(const DigitsList * dl, TObjArray * tl) 
129 {
130   // Copies the digits with energy above thershold and sorts the list
131   // according to increasing Id number
132
133   TIter next(dl) ; 
134   AliPHOSDigit * digit ;
135   
136   while ( (digit = (AliPHOSDigit *)next()) ) { 
137     Float_t ene = Calibrate(digit->GetAmp()) ; 
138     if      ( IsInEmc  (digit) && ene > fEmcEnergyThreshold  )
139       tl->Add(digit) ;
140     else if ( IsInPpsd (digit) && ene > fPpsdEnergyThreshold )
141       tl->Add(digit) ;
142     else if ( IsInCpv  (digit) && ene > fCpvEnergyThreshold  )
143       tl->Add(digit) ;
144   }
145   tl->Sort() ; 
146 }
147
148 //____________________________________________________________________________
149 void AliPHOSClusterizerv1:: GetNumberOfClustersFound(Int_t * numb) 
150 {
151   // Fills numb with the number of EMC  (numb[0]) clusters found
152   //                               PPSD (numb[1]) clusters found
153
154   numb[0] = fNumberOfEmcClusters ; 
155   numb[1] = fNumberOfPpsdClusters ; 
156 }
157
158 //____________________________________________________________________________
159 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) 
160 {
161   // Tells if (true) or not (false) the digit is in a PHOS-EMC module
162  
163   Bool_t rv = kFALSE ; 
164
165   Int_t relid[4] ; 
166   fGeom->AbsToRelNumbering(digit->GetId(), relid) ; 
167
168   if ( relid[1] == 0  ) rv = kTRUE; 
169
170   return rv ; 
171 }
172
173 //____________________________________________________________________________
174 Bool_t AliPHOSClusterizerv1::IsInPpsd(AliPHOSDigit * digit) 
175 {
176   // Tells if (true) or not (false) the digit is in a PHOS-PPSD module
177  
178   Bool_t rv = kFALSE ; 
179
180   Int_t relid[4] ; 
181   fGeom->AbsToRelNumbering(digit->GetId(), relid) ; 
182
183   if ( relid[1] > 0 && relid[0] > fGeom->GetNCPVModules() ) rv = kTRUE; 
184
185   return rv ; 
186 }
187
188 //____________________________________________________________________________
189 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) 
190 {
191   // Tells if (true) or not (false) the digit is in a PHOS-CPV 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 //____________________________________________________________________________
204 void AliPHOSClusterizerv1::MakeClusters(const DigitsList * dl, 
205                                         AliPHOSRecPoint::RecPointsList * emcl, 
206                                         AliPHOSRecPoint::RecPointsList * ppsdl)
207 {
208   // Steering method to construct the clusters stored in a list of Reconstructed Points
209   // A cluster is defined as a list of neighbour digits
210
211   fNumberOfEmcClusters  = 0 ;
212   fNumberOfPpsdClusters = 0 ;
213   fNumberOfCpvClusters  = 0 ;
214
215   // Fill and sort the working digits list
216   TObjArray tempodigitslist( dl->GetEntries() ) ;
217   FillandSort(dl, &tempodigitslist) ; 
218
219   // Clusterization starts  
220   TIter nextdigit(&tempodigitslist) ; 
221   AliPHOSDigit * digit ; 
222   Bool_t notremoved = kTRUE ;
223
224   while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digits
225     AliPHOSRecPoint * clu ; 
226
227     AliPHOSDigit ** clusterdigitslist = new AliPHOSDigit*[dl->GetEntries()] ;   
228     Int_t index ;
229
230     if (( IsInEmc (digit) && Calibrate(digit->GetAmp()) > fEmcClusteringThreshold  ) || 
231         ( IsInPpsd(digit) && Calibrate(digit->GetAmp()) > fPpsdClusteringThreshold ) ||
232         ( IsInCpv (digit) && Calibrate(digit->GetAmp()) > fCpvClusteringThreshold  ) ) {
233       
234       Int_t iDigitInCluster = 0 ; 
235
236       if  ( IsInEmc(digit) ) {   
237         // start a new EMC RecPoint
238         if(fNumberOfEmcClusters >= emcl->GetSize()) emcl->Expand(2*fNumberOfEmcClusters+1) ;
239         (*emcl)[fNumberOfEmcClusters] = new  AliPHOSEmcRecPoint(fW0, fLocMaxCut) ;
240         clu = (AliPHOSEmcRecPoint *) emcl->At(fNumberOfEmcClusters) ; 
241         fNumberOfEmcClusters++ ; 
242         clu->AddDigit(*digit, Calibrate(digit->GetAmp())) ; 
243         clusterdigitslist[iDigitInCluster] = digit ;    
244         iDigitInCluster++ ; 
245         tempodigitslist.Remove(digit) ; 
246
247       } else { 
248         
249         // start a new PPSD/CPV cluster
250         if(fNumberOfPpsdClusters >= ppsdl->GetSize()) ppsdl->Expand(2*fNumberOfPpsdClusters+1);
251         if      (IsInPpsd(digit)) 
252           (*ppsdl)[fNumberOfPpsdClusters] = new AliPHOSPpsdRecPoint() ;
253         else
254           (*ppsdl)[fNumberOfPpsdClusters] = new AliPHOSCpvRecPoint(fW0CPV, fLocMaxCutCPV) ;
255         clu =  (AliPHOSPpsdRecPoint *) ppsdl->At(fNumberOfPpsdClusters)  ;  
256         fNumberOfPpsdClusters++ ; 
257
258         clu->AddDigit(*digit, Calibrate(digit->GetAmp()) ) ;    
259         clusterdigitslist[iDigitInCluster] = digit  ;   
260         iDigitInCluster++ ; 
261         tempodigitslist.Remove(digit) ; 
262         nextdigit.Reset() ;
263         
264         // Here we remove resting EMC digits, which cannot make cluster
265         
266         if( notremoved ) { 
267           while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
268             if( IsInEmc(digit) ) 
269               tempodigitslist.Remove(digit) ;
270             else 
271               break ;
272           }
273           notremoved = kFALSE ;
274         }
275         
276       } // else        
277       
278       nextdigit.Reset() ;
279       
280       AliPHOSDigit * digitN ; 
281       index = 0 ;
282       while (index < iDigitInCluster){ // scan over digits already in cluster 
283         digit =  clusterdigitslist[index]  ;      
284         index++ ; 
285         while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits 
286           Int_t ineb = AreNeighbours(digit, digitN);       // call (digit,digitN) in THAT oder !!!!!
287           switch (ineb ) {
288           case 0 :   // not a neighbour
289             break ;
290           case 1 :   // are neighbours 
291             clu->AddDigit(*digitN, Calibrate( digitN->GetAmp() ) ) ;
292             clusterdigitslist[iDigitInCluster] = digitN ; 
293             iDigitInCluster++ ; 
294             tempodigitslist.Remove(digitN) ;
295             break ;
296           case 2 :   // too far from each other
297             goto endofloop;   
298           } // switch
299           
300         } // while digitN
301         
302       endofloop: ;
303         nextdigit.Reset() ; 
304         
305       } // loop over cluster     
306     }  //below energy theshold  
307     
308     delete[] clusterdigitslist ; 
309     
310   } // while digit
311
312   tempodigitslist.Clear() ; 
313
314   ppsdl->Sort() ;
315   Int_t index ;
316   for(index = 0; index < ppsdl->GetEntries(); index++)
317     ((AliPHOSPpsdRecPoint *)ppsdl->At(index))->SetIndexInList(index) ;
318 }
319
320 //____________________________________________________________________________
321 void AliPHOSClusterizerv1::PrintParameters() 
322 {
323   // Print the energy thresholds 
324
325   cout << "PHOS Clusterizer version 1 :" << endl 
326        << "                       EMC  Clustering threshold = " << fEmcClusteringThreshold << endl
327        << "                       EMC  Energy threshold     = " << fEmcEnergyThreshold << endl                  
328        << "                      PPSD  Clustering threshold = " << fPpsdClusteringThreshold << endl
329        << "                      PPSD  Energy threshold     = " << fPpsdEnergyThreshold << endl
330        << "                       CPV  Clustering threshold = " << fCpvClusteringThreshold << endl
331        << "                       CPV  Energy threshold     = " << fCpvEnergyThreshold << endl ;                
332 }