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