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