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