]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSClusterizerv1.cxx
Correct for incompabilities with HP-UX and compaq (!) (on request by fca)
[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>
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   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 //____________________________________________________________________________
61 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)
62 {
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
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 
81     Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;  
82     Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;  
83     
84     if (( coldiff <= 1 )  && ( rowdiff <= 1 )){
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 //____________________________________________________________________________
104 void AliPHOSClusterizerv1::FillandSort(const DigitsList * dl, TObjArray * tl) 
105 {
106   // Copies the digits with energy above thershold and sorts the list
107   // according to increasing Id number
108
109   AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
110   Int_t relid[4] ;  
111   
112   TIter next(dl) ; 
113   AliPHOSDigit * digit ;
114   
115  
116  
117
118   while ( (digit = (AliPHOSDigit *)next()) ) { 
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
126     Int_t id    = digit->GetId() ; 
127     Float_t ene = Calibrate(digit->GetAmp()) ; 
128     geom->AbsToRelNumbering(id, relid) ;
129     if(relid[1]==0){ // EMC
130       if ( ene > fEmcEnergyThreshold )
131         tl->Add(digit) ;
132     }
133
134     else { //Ppsd
135       if ( ene > fPpsdEnergyThreshold )
136         tl->Add(digit) ; 
137     }
138
139   }
140   tl->Sort() ; 
141 }
142
143 //____________________________________________________________________________
144 void AliPHOSClusterizerv1:: GetNumberOfClustersFound(Int_t * numb) 
145 {
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 ; 
151 }
152
153 //____________________________________________________________________________
154 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) 
155 {
156   // Tells if (true) or not (false) the digit is in a PHOS-EMC module
157  
158   Bool_t rv = kFALSE ; 
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 //____________________________________________________________________________
172 void AliPHOSClusterizerv1::MakeClusters(const DigitsList * dl, RecPointsList * emcl, RecPointsList * ppsdl)
173 {
174   // Steering method to construct the clusters stored in a list of Reconstructed Points
175   // A cluster is defined as a list of neighbour digits
176   
177   // Fill and sort the working digits list
178   TObjArray tempodigitslist( dl->GetEntries() ) ;
179   FillandSort(dl, &tempodigitslist) ; 
180
181   // Clusterization starts  
182   TIter nextdigit(&tempodigitslist) ; 
183   AliPHOSDigit * digit ; 
184   Bool_t notremoved = kTRUE ;
185
186
187   while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digits
188     AliPHOSRecPoint * clu ; 
189    
190     int ** clusterdigitslist = new int * [dl->GetEntries()] ;   
191     Int_t index ;
192     if (( ( IsInEmc(digit) ) && ( Calibrate(digit->GetAmp() ) > fEmcClusteringThreshold ) ) || 
193         ( ( !IsInEmc(digit) ) && ( Calibrate(digit->GetAmp() ) > fPpsdClusteringThreshold ) ) ) {
194   
195       Int_t iDigitInCluster = 0 ; 
196
197       if  ( IsInEmc(digit) ) {   
198         new ((*emcl)[fNumberOfEmcClusters]) AliPHOSEmcRecPoint(fW0, fLocMaxCut) ; // start a new EMC RecPoint
199         clu = (AliPHOSEmcRecPoint *) (*emcl)[fNumberOfEmcClusters] ; 
200         fNumberOfEmcClusters++ ; 
201         clu->AddDigit(*digit, Calibrate(digit->GetAmp())) ; 
202
203         clusterdigitslist[iDigitInCluster] = (int* ) digit ;    
204         iDigitInCluster++ ; 
205         tempodigitslist.Remove(digit) ; 
206
207
208       }
209
210       else { 
211         new ((*ppsdl)[fNumberOfPpsdClusters]) AliPHOSPpsdRecPoint() ; // start a new PPSD cluster
212         clu =  (AliPHOSPpsdRecPoint *) ppsdl->At(fNumberOfPpsdClusters)  ;  
213         fNumberOfPpsdClusters++ ; 
214         clu->AddDigit(*digit, Calibrate(digit->GetAmp()) ) ;    
215         clusterdigitslist[iDigitInCluster] = (int* ) digit ;    
216         iDigitInCluster++ ; 
217         tempodigitslist.Remove(digit) ; 
218         nextdigit.Reset() ;
219         
220         // Here we remove resting EMC digits, which cannot make cluster
221
222         if( notremoved ) { 
223           
224           while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
225             
226             if( IsInEmc(digit) ) 
227               tempodigitslist.Remove(digit) ;
228             else 
229               break ;
230           
231           } // while digit  
232           
233         } // if notremoved 
234         
235       } // else        
236       
237       nextdigit.Reset() ;
238
239       AliPHOSDigit * digitN ; 
240       index = 0 ;
241       while (index < iDigitInCluster){ // scan over digits already in cluster 
242         digit = (AliPHOSDigit *) clusterdigitslist[index]  ;      
243         index++ ; 
244         while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits 
245           Int_t ineb = AreNeighbours(digit, digitN);   //  call (digit,digitN) in THAT oder !!!!!
246           switch (ineb ) {
247           case 0 :   // not a neighbour
248             break ;      
249           case 1 :   // are neighbours 
250             clu->AddDigit( *digitN, Calibrate( digitN->GetAmp() ) ) ;
251             clusterdigitslist[iDigitInCluster] =(int*) digitN ; 
252             iDigitInCluster++ ; 
253             tempodigitslist.Remove(digitN) ;
254             break ;
255           case 2 :   // too far from each other
256             goto endofloop;   
257           } // switch
258           
259         } // while digitN
260
261       endofloop: ;
262         nextdigit.Reset() ; 
263         
264       } // loop over cluster     
265  
266    }  //below energy theshold  
267   
268     delete[] clusterdigitslist ; 
269     
270   } // while digit
271
272   tempodigitslist.Clear() ; 
273 }
274
275 //____________________________________________________________________________
276 void AliPHOSClusterizerv1::PrintParameters() 
277 {
278   // Print the energy thresholds 
279
280   cout << "PHOS Clusterizer version 1 :" << endl 
281        << "                       EMC  Clustering threshold = " << fEmcClusteringThreshold << endl
282        << "                       EMC  Energy threshold     = " << fEmcEnergyThreshold << endl                  
283        << "                      PPSD  Clustering threshold = " << fPpsdClusteringThreshold << endl
284        << "                      PPSD  Energy threshold     = " << fPpsdEnergyThreshold << endl ;                
285 }