]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSCpvRecPoint.cxx
DP:absId calculation fixed
[u/mrichter/AliRoot.git] / PHOS / AliPHOSCpvRecPoint.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 /* History of cvs commits:
19  *
20  * $Log$
21  * Revision 1.24  2006/08/28 10:01:56  kharlov
22  * Effective C++ warnings fixed (Timur Pocheptsov)
23  *
24  * Revision 1.23  2005/12/20 14:28:47  hristov
25  * Additional protection
26  *
27  * Revision 1.22  2005/05/28 14:19:04  schutz
28  * Compilation warnings fixed by T.P.
29  *
30  */
31
32 //_________________________________________________________________________
33 //  RecPoint implementation for PHOS-CPV
34 //  An CpvRecPoint is a cluster of digits   
35 //*-- Author: Yuri Kharlov
36 //  (after Dmitri Peressounko (RRC KI & SUBATECH))
37 //  30 October 2000 
38
39 // --- ROOT system ---
40
41 #include "TMath.h" 
42 #include "TClonesArray.h" 
43
44 // --- Standard library ---
45
46 // --- AliRoot header files ---
47 #include "AliLog.h"
48 #include "AliPHOSGeometry.h" 
49 #include "AliPHOSDigit.h"
50 #include "AliPHOSCpvRecPoint.h"
51 #include "AliPHOSLoader.h"
52
53 ClassImp(AliPHOSCpvRecPoint)
54
55 //____________________________________________________________________________
56 AliPHOSCpvRecPoint::AliPHOSCpvRecPoint() : 
57   AliPHOSEmcRecPoint(),
58   fLengX(-1),
59   fLengZ(-1)
60 {
61   // ctor
62 }
63
64 //____________________________________________________________________________
65 AliPHOSCpvRecPoint::AliPHOSCpvRecPoint(const char * opt) : 
66   AliPHOSEmcRecPoint(opt),
67   fLengX(-1),
68   fLengZ(-1)
69 {
70    // ctor
71 }
72
73 //____________________________________________________________________________
74 AliPHOSCpvRecPoint::~AliPHOSCpvRecPoint()
75 {
76   // dtor
77 }
78
79 //____________________________________________________________________________
80 Bool_t AliPHOSCpvRecPoint::AreNeighbours(AliPHOSDigit * digit1, AliPHOSDigit * digit2 ) const
81 {
82   // Tells if (true) or not (false) two digits are neighbors)
83   
84   Bool_t aren = kFALSE ;
85   
86   AliPHOSGeometry * phosgeom =  AliPHOSLoader::GetPHOSGeometry();
87
88   Int_t relid1[4] ; 
89   phosgeom->AbsToRelNumbering(digit1->GetId(), relid1) ; 
90
91   Int_t relid2[4] ; 
92   phosgeom->AbsToRelNumbering(digit2->GetId(), relid2) ; 
93   
94   Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;  
95   Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;  
96
97   if (( coldiff <= 1 )  && ( rowdiff <= 1 ) && (coldiff + rowdiff > 0)) 
98     aren = kTRUE ;
99   
100   return aren ;
101 }
102
103 //____________________________________________________________________________
104 Int_t AliPHOSCpvRecPoint::Compare(const TObject * obj) const
105 {
106   // Compares two RecPoints according to their position in the PHOS modules
107
108   Float_t delta = 1 ; //Width of "Sorting row". If you changibg this 
109                       //value (what is senseless) change as vell delta in
110                       //AliPHOSTrackSegmentMakerv* and other RecPoints...
111
112   Int_t rv ; 
113
114   AliPHOSCpvRecPoint * clu  = (AliPHOSCpvRecPoint *) obj ; 
115   
116   Int_t phosmod1 = GetPHOSMod() ;
117   Int_t phosmod2 = clu->GetPHOSMod() ;
118   
119   TVector3 locpos1; 
120   GetLocalPosition(locpos1) ;
121   TVector3 locpos2;  
122   clu->GetLocalPosition(locpos2) ;  
123   
124   if(phosmod1 == phosmod2 ) {
125     Int_t rowdif = (Int_t)TMath::Ceil(locpos1.X()/delta)-(Int_t)TMath::Ceil(locpos2.X()/delta) ;
126     if (rowdif> 0) 
127       rv = 1 ;
128     else if(rowdif < 0) 
129       rv = -1 ;
130     else if(locpos1.Z()>locpos2.Z()) 
131       rv = -1 ;
132     else 
133       rv = 1 ; 
134   }
135   
136   else {
137     if(phosmod1 < phosmod2 ) 
138       rv = -1 ;
139     else 
140       rv = 1 ;
141   }
142   
143   return rv ; 
144
145 }
146
147 //______________________________________________________________________________
148 void AliPHOSCpvRecPoint::ExecuteEvent(Int_t, Int_t, Int_t ) /*const*/
149 {
150 //   // Execute action corresponding to one event
151 //   //  This member function is called when a AliPHOSRecPoint is clicked with the locator
152 //   //
153 //   //  If Left button is clicked on AliPHOSRecPoint, the digits are switched on    
154 //   //  and switched off when the mouse button is released.
155 //   //
156
157 //   //   static Int_t pxold, pyold;
158
159 //   AliPHOSLoader * gime =  AliPHOSLoader::GetInstance() ; 
160   
161 //   static TGraph *  digitgraph = 0 ;
162   
163 //   if (!gPad->IsEditable()) return;
164   
165 //   TH2F * histo = 0 ;
166 //   TCanvas * histocanvas ; 
167   
168 //   switch (event) {
169     
170 //   case kButton1Down: {
171 //     AliPHOSDigit * digit ;
172 //     AliPHOSGeometry * phosgeom =  (AliPHOSGeometry *) fGeom ;
173 //     Int_t iDigit;
174 //     Int_t relid[4] ;
175     
176 //     const Int_t kMulDigit = AliPHOSCpvRecPoint::GetDigitsMultiplicity() ; 
177 //     Float_t * xi = new Float_t[kMulDigit] ; 
178 //     Float_t * zi = new Float_t[kMulDigit] ; 
179     
180 //     // create the histogram for the single cluster 
181 //     // 1. gets histogram boundaries
182 //     Float_t ximax = -999. ; 
183 //     Float_t zimax = -999. ; 
184 //     Float_t ximin = 999. ; 
185 //     Float_t zimin = 999. ;
186     
187 //     for(iDigit=0; iDigit<kMulDigit; iDigit++) {
188 //       digit = (AliPHOSDigit *) ( gime->Digit(fDigitsList[iDigit]) ) ;
189 //       phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
190 //       phosgeom->RelPosInModule(relid, xi[iDigit], zi[iDigit]);
191 //       if ( xi[iDigit] > ximax )
192 //      ximax = xi[iDigit] ; 
193 //       if ( xi[iDigit] < ximin )
194 //      ximin = xi[iDigit] ; 
195 //       if ( zi[iDigit] > zimax )
196 //      zimax = zi[iDigit] ; 
197 //       if ( zi[iDigit] < zimin )
198 //      zimin = zi[iDigit] ;     
199 //     }
200 //     ximax += phosgeom->GetCrystalSize(0) / 2. ;
201 //     zimax += phosgeom->GetCrystalSize(2) / 2. ;
202 //     ximin -= phosgeom->GetCrystalSize(0) / 2. ;
203 //     zimin -= phosgeom->GetCrystalSize(2) / 2. ;
204 //     Int_t xdim = (int)( (ximax - ximin ) / phosgeom->GetCrystalSize(0) + 0.5  ) ; 
205 //     Int_t zdim = (int)( (zimax - zimin ) / phosgeom->GetCrystalSize(2) + 0.5 ) ;
206     
207 //     // 2. gets the histogram title
208     
209 //     Text_t title[100] ; 
210 //     sprintf(title,"Energy=%1.2f GeV ; Digits ; %d ", GetEnergy(), GetDigitsMultiplicity()) ;
211     
212 //     if (!histo) {
213 //       delete histo ; 
214 //       histo = 0 ; 
215 //     }
216 //     histo = new TH2F("cluster3D", title,  xdim, ximin, ximax, zdim, zimin, zimax)  ;
217     
218 //     Float_t x, z ; 
219 //     for(iDigit=0; iDigit<kMulDigit; iDigit++) {
220 //       digit = (AliPHOSDigit *) ( gime->Digit(fDigitsList[iDigit]) ) ;
221 //       phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
222 //       phosgeom->RelPosInModule(relid, x, z);
223 //       histo->Fill(x, z, fEnergyList[iDigit] ) ;
224 //     }
225     
226 //     if (!digitgraph) {
227 //       digitgraph = new TGraph(kMulDigit,xi,zi);
228 //       digitgraph-> SetMarkerStyle(5) ; 
229 //       digitgraph-> SetMarkerSize(1.) ;
230 //       digitgraph-> SetMarkerColor(1) ;
231 //       digitgraph-> Paint("P") ;
232 //     }
233     
234 //     Print() ;
235 //     histocanvas = new TCanvas("cluser", "a single cluster", 600, 500) ; 
236 //     histocanvas->Draw() ; 
237 //     histo->Draw("lego1") ; 
238     
239 //     delete[] xi ; 
240 //     delete[] zi ; 
241     
242 //     break;
243 //   }
244   
245 //   case kButton1Up: 
246 //     if (digitgraph) {
247 //       delete digitgraph  ;
248 //       digitgraph = 0 ;
249 //     }
250 //     break;
251   
252 //    }
253 }
254
255 //____________________________________________________________________________
256 void AliPHOSCpvRecPoint::EvalAll(Float_t logWeight, TClonesArray * digits)
257 {
258   AliPHOSEmcRecPoint::EvalAll(logWeight,digits) ;
259   EvalClusterLengths(digits) ;
260 }
261 //____________________________________________________________________________
262 void AliPHOSCpvRecPoint::EvalAll(Float_t logWeight, TVector3 &vtx, TClonesArray * digits)
263 {
264   // wraps other methods
265   AliPHOSEmcRecPoint::EvalAll(logWeight,vtx,digits) ;
266 }
267 //____________________________________________________________________________
268 void AliPHOSCpvRecPoint::EvalLocalPosition(Float_t logWeight, TVector3 & /*vtx */, TClonesArray * digits)
269 {
270   // Calculates the center of gravity in the local PHOS-module coordinates 
271
272   Float_t wtot = 0. ;
273  
274   Int_t relid[4] ;
275
276   Float_t x = 0. ;
277   Float_t z = 0. ;
278   
279   AliPHOSDigit * digit ;
280
281   AliPHOSGeometry * phosgeom =  AliPHOSLoader::GetPHOSGeometry();
282   
283   Int_t iDigit;
284
285   for(iDigit=0; iDigit<fMulDigit; iDigit++) {
286     digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]);
287
288     Float_t xi ;
289     Float_t zi ;
290     phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
291     phosgeom->RelPosInModule(relid, xi, zi);
292     if (fAmp>0 && fEnergyList[iDigit]>0) {
293       Float_t w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ) ) ;
294       x    += xi * w ;
295       z    += zi * w ;
296       wtot += w ;
297     }
298     else
299       AliError(Form("Wrong energy %f and/or amplitude %f\n", fEnergyList[iDigit], fAmp));
300   }
301
302   if (wtot != 0) {
303     x /= wtot ;
304     z /= wtot ;
305   } else {
306     x = -1e6 ;
307     z = -1e6 ;
308     if (fMulDigit != 0) 
309       AliWarning(Form("Too low log weight factor to evaluate cluster's center" )) ;
310   }
311   fLocPos.SetX(x)  ;
312   fLocPos.SetY(0.) ;
313   fLocPos.SetZ(z)  ;
314   fLocPosM = 0 ;
315
316 }
317
318 //____________________________________________________________________________
319 void AliPHOSCpvRecPoint::EvalClusterLengths(TClonesArray * digits)
320 {
321   //Modified 15.03.2001 by Dmitri Peressounko
322   
323   // Calculates the cluster lengths along X and Z axes
324   // These characteristics are needed for CPV to tune
325   // digitization+reconstruction to experimental data
326   // Yuri Kharlov. 24 October 2000
327
328   Int_t relid[4] ;
329
330   AliPHOSDigit * digit ;
331
332   AliPHOSGeometry * phosgeom =  AliPHOSLoader::GetPHOSGeometry();
333
334   const Int_t kMaxLeng=20;
335   Int_t idX[kMaxLeng], idZ[kMaxLeng];
336   fLengX = 0;
337   fLengZ = 0;
338   Bool_t dejavu;
339
340   for(Int_t iDigit=0; iDigit<fMulDigit; iDigit++) {
341     digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
342     Int_t absId = digit->GetId();
343     phosgeom->AbsToRelNumbering(absId, relid) ;
344
345     Int_t i;
346     dejavu=kFALSE;
347     for (i=0; i<fLengX; i++) if (relid[2]==idX[i]) { dejavu=kTRUE; break; }
348     if (!dejavu) {
349       idX[fLengX]=relid[2];
350       fLengX++;
351       fLengX = TMath::Min(fLengX,kMaxLeng);
352     }
353
354     dejavu=kFALSE;
355     for (i=0; i<fLengZ; i++) if (relid[3]==idZ[i]) { dejavu=kTRUE; break; }
356     if (!dejavu) {
357       idZ[fLengZ]=relid[3];
358       fLengZ++;
359       fLengZ = TMath::Min(fLengZ,kMaxLeng);
360     }
361   }
362 }
363
364 //____________________________________________________________________________
365 void AliPHOSCpvRecPoint::Print(const Option_t *) const
366 {
367   // Print the list of digits belonging to the cluster
368   
369   TString message ; 
370   message  =  "AliPHOSCpvRecPoint: " ;
371   message +=  "Digits #   " ;
372   AliInfo(Form(message.Data())) ; 
373   
374   Int_t iDigit;
375
376   for(iDigit=0; iDigit<fMulDigit; iDigit++) 
377     printf(" %d \n", fDigitsList[iDigit]) ; 
378
379   printf("Energies: \n")  ;
380   for(iDigit=0; iDigit<fMulDigit; iDigit++) 
381     printf(" %f ", fEnergyList[iDigit]) ; 
382   
383   message  = "       Multiplicity    = %d\n" ;
384   message += "       Cluster Energy  = %f\n" ;
385   message += "       Stored at position %d\n" ; 
386  
387   printf(message.Data(), fMulDigit, fAmp, GetIndexInList() ) ; 
388
389 }