]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSClusterizerv1.cxx
Correct particle type for gamma and neutrons
[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 //_________________________________________________________________________
17 // A brief description of the class
18 //*-- Author : Yves Schutz  SUBATECH 
19 //////////////////////////////////////////////////////////////////////////////
20
21 // --- ROOT system ---
22
23 #include "TMath.h" 
24
25 // --- Standard library ---
26
27 #include <iostream>
28
29 // --- AliRoot header files ---
30
31 #include "AliPHOSClusterizerv1.h"
32 #include "AliPHOSDigit.h"
33 #include "AliPHOSEmcRecPoint.h"
34 #include "AliPHOSPpsdRecPoint.h"
35 #include "AliPHOSv0.h" 
36 #include "AliRun.h" 
37
38 ClassImp(AliPHOSClusterizerv1)
39
40 //____________________________________________________________________________
41 AliPHOSClusterizerv1::AliPHOSClusterizerv1()
42 {
43   fA                       = 0.;
44   fB                       = 0.01 ;
45   fNumberOfEmcClusters     = 0 ; 
46   fNumberOfPpsdClusters    = 0 ; 
47   fEmcClusteringThreshold  = 0.1;   
48   fEmcEnergyThreshold      = 0.01;    
49   fPpsdClusteringThreshold = 0.00000015; 
50   fPpsdEnergyThreshold     = 0.0000001;  
51   fW0                      = 4.5 ;
52   fLocMaxCut               = 0.06 ;
53 }
54
55 //____________________________________________________________________________
56 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)
57 {
58   // neigbours are defined as digits having at least common vertex
59   // The order of A and B in AreNeighbours(A,B) is important: first (A) should be digit 
60   // in cluster, which compared with digits not clusterized yet  
61   Int_t rv = 0 ; 
62
63   AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
64
65   Int_t relid1[4] ; 
66   geom->AbsToRelNumbering(d1->GetId(), relid1) ; 
67
68   Int_t relid2[4] ; 
69   geom->AbsToRelNumbering(d2->GetId(), relid2) ; 
70  
71   if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module and the same PPSD Module 
72     Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;  
73     Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;  
74     
75     if (( coldiff <= 1 )  && ( rowdiff <= 1 )){
76       rv = 1 ; 
77     }
78     else {
79       if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1)) 
80         rv = 2; //  Difference in row numbers is too large to look further 
81     }
82
83   } 
84   else {
85     
86     if( (relid1[0] < relid2[0]) || (relid1[1] < relid2[1]) )  
87       rv=2 ;
88
89   }
90   
91   return rv ; 
92 }
93
94 //____________________________________________________________________________
95 void AliPHOSClusterizerv1::FillandSort(const DigitsList * dl, TObjArray * tl) 
96 {
97   // copies the digits with energy above thershold and sorts the list
98   // according to increasing Id number
99
100   AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
101   Int_t relid[4] ;  
102   
103   TIter next(dl) ; 
104   AliPHOSDigit * digit ;
105   
106   while ( (digit = (AliPHOSDigit *)next()) ) { 
107     
108     Int_t id    = digit->GetId() ; 
109     Float_t ene = Calibrate(digit->GetAmp()) ; 
110     geom->AbsToRelNumbering(id, relid) ;
111     
112     if(relid[1]==0){ // EMC
113       if ( ene > fEmcEnergyThreshold ) 
114         tl->Add(digit) ;
115     }
116
117     else { //Ppsd
118       if ( ene > fPpsdEnergyThreshold )
119         tl->Add(digit) ;        
120     }
121
122   }
123   tl->Sort() ; 
124 }
125
126 //____________________________________________________________________________
127 void AliPHOSClusterizerv1:: GetNumberOfClustersFound(Int_t * numb) 
128 {
129  numb[0] = fNumberOfEmcClusters ; 
130  numb[1] = fNumberOfPpsdClusters ; 
131 }
132
133 //____________________________________________________________________________
134 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) 
135 {
136   Bool_t rv = kFALSE ; 
137
138   AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;  
139
140   Int_t relid[4] ; 
141   geom->AbsToRelNumbering(digit->GetId(), relid) ; 
142
143   if ( relid[1] == 0  )
144     rv = kTRUE; 
145
146   return rv ; 
147 }
148
149 //____________________________________________________________________________
150 void AliPHOSClusterizerv1::MakeClusters(const DigitsList * dl, RecPointsList * emcl, RecPointsList * ppsdl)
151 {
152   // Fill and sort the working digits list
153   TObjArray tempodigitslist( dl->GetEntries() ) ;
154   FillandSort(dl, &tempodigitslist) ; 
155
156   // Clusterization starts  
157   TIter nextdigit(&tempodigitslist) ; 
158   AliPHOSDigit * digit ; 
159   Bool_t notremoved = kTRUE ;
160
161   while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digits
162     AliPHOSRecPoint * clu ; 
163    
164     int * clusterdigitslist[dl->GetEntries()] ;   
165     Int_t index ;
166     if (( ( IsInEmc(digit) ) && ( Calibrate(digit->GetAmp() ) > fEmcClusteringThreshold ) ) || 
167         ( ( !IsInEmc(digit) ) && ( Calibrate(digit->GetAmp() ) > fPpsdClusteringThreshold ) ) ) {
168   
169       Int_t iDigitInCluster = 0 ; 
170
171       if  ( IsInEmc(digit) ) {   
172         new ((*emcl)[fNumberOfEmcClusters]) AliPHOSEmcRecPoint(fW0, fLocMaxCut) ; // start a new EMC RecPoint
173         clu = (AliPHOSEmcRecPoint *) (*emcl)[fNumberOfEmcClusters] ; 
174         fNumberOfEmcClusters++ ; 
175         clu->AddDigit(*digit, Calibrate(digit->GetAmp())) ; 
176
177         clusterdigitslist[iDigitInCluster] = (int* ) digit ;    
178         iDigitInCluster++ ; 
179         tempodigitslist.Remove(digit) ; 
180       }
181
182       else { 
183         new ((*ppsdl)[fNumberOfPpsdClusters]) AliPHOSPpsdRecPoint() ; // start a new PPSD cluster
184         clu =  (AliPHOSPpsdRecPoint *) ppsdl->At(fNumberOfPpsdClusters)  ;  
185         fNumberOfPpsdClusters++ ; 
186         clu->AddDigit(*digit, Calibrate(digit->GetAmp()) ) ;    
187         clusterdigitslist[iDigitInCluster] = (int* ) digit ;    
188         iDigitInCluster++ ; 
189         tempodigitslist.Remove(digit) ; 
190         nextdigit.Reset() ;
191         
192         // Here we remove resting EMC digits, which cannot make cluster
193
194         if( notremoved ) { 
195           
196           while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
197             
198             if( IsInEmc(digit) ) 
199               tempodigitslist.Remove(digit) ;
200             else 
201               break ;
202           
203           } // while digit  
204           
205         } // if notremoved 
206         
207       } // else        
208       
209       nextdigit.Reset() ;
210
211       AliPHOSDigit * digitN ; 
212       index = 0 ;
213       while (index < iDigitInCluster){ // scan over digits already in cluster 
214         digit = (AliPHOSDigit *) clusterdigitslist[index]  ;      
215         index++ ; 
216         while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits 
217           Int_t ineb = AreNeighbours(digit, digitN);   //  call (digit,digitN) in THAT oder !!!!!
218           switch (ineb ) {
219           case 0 :   // not a neighbour
220             break ;      
221           case 1 :   // are neighbours 
222             clu->AddDigit( *digitN, Calibrate( digitN->GetAmp() ) ) ;
223             clusterdigitslist[iDigitInCluster] =(int*) digitN ; 
224             iDigitInCluster++ ; 
225             tempodigitslist.Remove(digitN) ;
226             break ;
227           case 2 :   // too far from each other
228             goto endofloop;   
229           } // switch
230           
231         } // while digitN
232
233       endofloop: ;
234         nextdigit.Reset() ; 
235         
236       } // loop over cluster     
237  
238    }  //below energy theshold  
239   
240   } // while digit
241
242   tempodigitslist.Clear() ; 
243 }
244
245 //____________________________________________________________________________
246 void AliPHOSClusterizerv1::PrintParameters() 
247 {
248   cout << "PHOS Clusterizer version 1 :" << endl 
249        << "                       EMC  Clustering threshold = " << fEmcClusteringThreshold << endl
250        << "                       EMC  Energy threshold     = " << fEmcEnergyThreshold << endl                  
251        << "                      PPSD  Clustering threshold = " << fPpsdClusteringThreshold << endl
252        << "                      PPSD  Energy threshold     = " << fPpsdEnergyThreshold << endl ;                
253 }