]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSClusterizerv1.cxx
Data member fGeom added
[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 //_________________________________________________________________________
19 //  Implementation version 1 of the clusterization algorithm 
20 // 
21 //*-- Author: Yves Schutz (SUBATECH) 
22 //////////////////////////////////////////////////////////////////////////////
23
24 // --- ROOT system ---
25
26 #include "TMath.h" 
27
28 // --- Standard library ---
29
30 #include <iostream.h>
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
41 ClassImp(AliPHOSClusterizerv1)
42
43 //____________________________________________________________________________
44 AliPHOSClusterizerv1::AliPHOSClusterizerv1()
45 {
46   // default ctor (to be used)
47
48   fA                       = 0.;
49   fB                       = 0.01 ;
50   fGeom                    = AliPHOSGeometry::GetInstance();
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 //____________________________________________________________________________
62 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)
63 {
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
71   Int_t rv = 0 ; 
72
73   Int_t relid1[4] ; 
74   fGeom->AbsToRelNumbering(d1->GetId(), relid1) ; 
75
76   Int_t relid2[4] ; 
77   fGeom->AbsToRelNumbering(d2->GetId(), relid2) ; 
78  
79   if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module and the same PPSD Module 
80     Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;  
81     Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;  
82     
83     if (( coldiff <= 1 )  && ( rowdiff <= 1 )){
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   }
98   
99   return rv ; 
100 }
101
102 //____________________________________________________________________________
103 void AliPHOSClusterizerv1::FillandSort(const DigitsList * dl, TObjArray * tl) 
104 {
105   // Copies the digits with energy above thershold and sorts the list
106   // according to increasing Id number
107
108   Int_t relid[4] ;  
109   
110   TIter next(dl) ; 
111   AliPHOSDigit * digit ;
112   
113  
114  
115
116   while ( (digit = (AliPHOSDigit *)next()) ) { 
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
124     Int_t id    = digit->GetId() ; 
125     Float_t ene = Calibrate(digit->GetAmp()) ; 
126     fGeom->AbsToRelNumbering(id, relid) ;
127     if(relid[1]==0){ // EMC
128       if ( ene > fEmcEnergyThreshold )
129         tl->Add(digit) ;
130     }
131
132     else { //Ppsd
133       if ( ene > fPpsdEnergyThreshold )
134         tl->Add(digit) ; 
135     }
136
137   }
138   tl->Sort() ; 
139 }
140
141 //____________________________________________________________________________
142 void AliPHOSClusterizerv1:: GetNumberOfClustersFound(Int_t * numb) 
143 {
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 ; 
149 }
150
151 //____________________________________________________________________________
152 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) 
153 {
154   // Tells if (true) or not (false) the digit is in a PHOS-EMC module
155  
156   Bool_t rv = kFALSE ; 
157
158   Int_t relid[4] ; 
159   fGeom->AbsToRelNumbering(digit->GetId(), relid) ; 
160
161   if ( relid[1] == 0  )
162     rv = kTRUE; 
163
164   return rv ; 
165 }
166
167 //____________________________________________________________________________
168 void AliPHOSClusterizerv1::MakeClusters(const DigitsList * dl, 
169                                         AliPHOSRecPoint::RecPointsList * emcl, 
170                                         AliPHOSRecPoint::RecPointsList * ppsdl)
171 {
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
174   
175   // Fill and sort the working digits list
176   TObjArray tempodigitslist( dl->GetEntries() ) ;
177   FillandSort(dl, &tempodigitslist) ; 
178
179   // Clusterization starts  
180   TIter nextdigit(&tempodigitslist) ; 
181   AliPHOSDigit * digit ; 
182   Bool_t notremoved = kTRUE ;
183
184   while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digits
185     AliPHOSRecPoint * clu ; 
186    
187     AliPHOSDigit ** clusterdigitslist = new AliPHOSDigit*[dl->GetEntries()] ;   
188     Int_t index ;
189     if (( ( IsInEmc(digit) ) && ( Calibrate(digit->GetAmp() ) > fEmcClusteringThreshold ) ) || 
190         ( ( !IsInEmc(digit) ) && ( Calibrate(digit->GetAmp() ) > fPpsdClusteringThreshold ) ) ) {
191   
192       Int_t iDigitInCluster = 0 ; 
193
194       if  ( IsInEmc(digit) ) {   
195         // start a new EMC RecPoint
196         //        new ((*emcl)[fNumberOfEmcClusters]) AliPHOSEmcRecPoint(fW0, fLocMaxCut) ; if TClonesArray
197         (*emcl)[fNumberOfEmcClusters] = new  AliPHOSEmcRecPoint(fW0, fLocMaxCut) ;
198
199         clu = (AliPHOSEmcRecPoint *) emcl->At(fNumberOfEmcClusters) ; 
200         fNumberOfEmcClusters++ ; 
201         clu->AddDigit(*digit, Calibrate(digit->GetAmp())) ; 
202         clusterdigitslist[iDigitInCluster] = digit ;    
203         iDigitInCluster++ ; 
204         tempodigitslist.Remove(digit) ; 
205
206       }
207
208       else { 
209         
210         // start a new PPSD cluster
211         // new ((*ppsdl)[fNumberOfPpsdClusters]) AliPHOSPpsdRecPoint() ;  if TClonesArray
212         (*ppsdl)[fNumberOfPpsdClusters] = new AliPHOSPpsdRecPoint() ;
213         
214         clu =  (AliPHOSPpsdRecPoint *) ppsdl->At(fNumberOfPpsdClusters)  ;  
215         fNumberOfPpsdClusters++ ; 
216         clu->AddDigit(*digit, Calibrate(digit->GetAmp()) ) ;    
217         clusterdigitslist[iDigitInCluster] = digit  ;   
218         iDigitInCluster++ ; 
219         tempodigitslist.Remove(digit) ; 
220         nextdigit.Reset() ;
221         
222         // Here we remove resting EMC digits, which cannot make cluster
223
224         if( notremoved ) { 
225           
226           while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
227             
228             if( IsInEmc(digit) ) 
229               tempodigitslist.Remove(digit) ;
230             else 
231               break ;
232           
233           } // while digit  
234           
235         } // if notremoved 
236         
237       } // else        
238       
239       nextdigit.Reset() ;
240
241       AliPHOSDigit * digitN ; 
242       index = 0 ;
243       while (index < iDigitInCluster){ // scan over digits already in cluster 
244         digit =  clusterdigitslist[index]  ;      
245         index++ ; 
246         while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits 
247           Int_t ineb = AreNeighbours(digit, digitN);   //  call (digit,digitN) in THAT oder !!!!!
248           switch (ineb ) {
249           case 0 :   // not a neighbour
250             break ;      
251           case 1 :   // are neighbours 
252             clu->AddDigit(*digitN, Calibrate( digitN->GetAmp() ) ) ;
253             clusterdigitslist[iDigitInCluster] = digitN ; 
254             iDigitInCluster++ ; 
255             tempodigitslist.Remove(digitN) ;
256             break ;
257           case 2 :   // too far from each other
258             goto endofloop;   
259           } // switch
260           
261         } // while digitN
262
263       endofloop: ;
264         nextdigit.Reset() ; 
265         
266       } // loop over cluster     
267  
268    }  //below energy theshold  
269   
270     delete[] clusterdigitslist ; 
271     
272   } // while digit
273
274   tempodigitslist.Clear() ; 
275
276 }
277
278 //____________________________________________________________________________
279 void AliPHOSClusterizerv1::PrintParameters() 
280 {
281   // Print the energy thresholds 
282
283   cout << "PHOS Clusterizer version 1 :" << endl 
284        << "                       EMC  Clustering threshold = " << fEmcClusteringThreshold << endl
285        << "                       EMC  Energy threshold     = " << fEmcEnergyThreshold << endl                  
286        << "                      PPSD  Clustering threshold = " << fPpsdClusteringThreshold << endl
287        << "                      PPSD  Energy threshold     = " << fPpsdEnergyThreshold << endl ;                
288 }