]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSRecPoint.cxx
Updated PID with pi0 identification
[u/mrichter/AliRoot.git] / PHOS / AliPHOSRecPoint.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 /* $Id$ */
16 //_________________________________________________________________________
17 //  Base Class for PHOS Reconstructed Points  
18 //  Why should I put meaningless comments
19 //  just to satisfy
20 //  the code checker                
21 //*-- Author: Gines Martinez (SUBATECH)
22
23 // --- ROOT system ---
24 #include "TPad.h"
25 #include "TClonesArray.h"
26
27 // --- Standard library ---
28
29 // --- AliRoot header files ---
30
31 #include "AliPHOSGeometry.h"
32 #include "AliPHOSDigit.h"
33 #include "AliPHOSRecPoint.h"
34 #include "AliPHOSGetter.h"
35
36 ClassImp(AliPHOSRecPoint)
37
38
39 //____________________________________________________________________________
40 AliPHOSRecPoint::AliPHOSRecPoint()
41   : AliRecPoint()
42 {
43   // ctor
44
45   fMaxTrack = 200 ;
46   fPHOSMod = 0;
47
48 }
49
50 //____________________________________________________________________________
51 AliPHOSRecPoint::AliPHOSRecPoint(const char * opt) : AliRecPoint(opt)
52 {
53   // ctor
54   
55   fMaxTrack = 200 ;
56   fPHOSMod = 0;
57   
58 }
59
60 //____________________________________________________________________________
61 Int_t AliPHOSRecPoint::DistancetoPrimitive(Int_t px, Int_t py)
62 {
63   // Compute distance from point px,py to  a AliPHOSRecPoint considered as a Tmarker
64   // Compute the closest distance of approach from point px,py to this marker.
65   // The distance is computed in pixels units.
66
67   TVector3 pos(0.,0.,0.) ;
68   GetLocalPosition( pos) ;
69   Float_t x =  pos.X() ;
70   Float_t y =  pos.Z() ;
71   const Int_t kMaxDiff = 10;
72   Int_t pxm  = gPad->XtoAbsPixel(x);
73   Int_t pym  = gPad->YtoAbsPixel(y);
74   Int_t dist = (px-pxm)*(px-pxm) + (py-pym)*(py-pym);
75   
76   if (dist > kMaxDiff) return 9999;
77   return dist;
78 }
79
80 //___________________________________________________________________________
81  void AliPHOSRecPoint::Draw(Option_t *option)
82  {
83    // Draw this AliPHOSRecPoint with its current attributes
84    
85    AppendPad(option);
86  }
87
88 //______________________________________________________________________________
89 void AliPHOSRecPoint::ExecuteEvent(Int_t event, Int_t px, Int_t py) const
90 {
91   // Execute action corresponding to one event
92   // This member function is called when a AliPHOSRecPoint is clicked with the locator
93   //
94   // If Left button is clicked on AliPHOSRecPoint, the digits are switched on    
95   // and switched off when the mouse button is released.
96
97   //  static Int_t pxold, pyold;
98
99   static TGraph *  digitgraph = 0 ;
100   static TPaveText* clustertext = 0 ;
101   
102   if (!gPad->IsEditable()) return;
103   
104   switch (event) {
105     
106     
107   case kButton1Down:{
108     AliPHOSDigit * digit ;
109     AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
110     AliPHOSGeometry * phosgeom =  const_cast<AliPHOSGeometry*>(gime->PHOSGeometry());
111
112     Int_t iDigit;
113     Int_t relid[4] ;
114   
115     const Int_t kMulDigit=AliPHOSRecPoint::GetDigitsMultiplicity() ;
116     Float_t * xi = new Float_t [kMulDigit] ; 
117     Float_t * zi = new Float_t [kMulDigit] ;
118     
119     for(iDigit = 0; iDigit < kMulDigit; iDigit++) {
120       Fatal("AliPHOSRecPoint::ExecuteEvent", "-> Something wrong with the code"); 
121       digit = 0 ; //dynamic_cast<AliPHOSDigit *>((fDigitsList)[iDigit]);
122       phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
123       phosgeom->RelPosInModule(relid, xi[iDigit], zi[iDigit]) ;
124     }
125     
126     if (!digitgraph) {
127       digitgraph = new TGraph(fMulDigit,xi,zi);
128       digitgraph-> SetMarkerStyle(5) ; 
129       digitgraph-> SetMarkerSize(1.) ;
130       digitgraph-> SetMarkerColor(1) ;
131       digitgraph-> Draw("P") ;
132     }
133     if (!clustertext) {
134       
135       TVector3 pos(0.,0.,0.) ;
136       GetLocalPosition(pos) ;
137       clustertext = new TPaveText(pos.X()-10,pos.Z()+10,pos.X()+50,pos.Z()+35,"") ;
138       Text_t  line1[40] ;
139       Text_t  line2[40] ;
140       sprintf(line1,"Energy=%1.2f GeV",GetEnergy()) ;
141       sprintf(line2,"%d Digits",GetDigitsMultiplicity()) ;
142       clustertext ->AddText(line1) ;
143       clustertext ->AddText(line2) ;
144       clustertext ->Draw("");
145     }
146     gPad->Update() ; 
147     Print() ;
148     delete[] xi ; 
149     delete[] zi ; 
150    }
151   
152 break;
153   
154   case kButton1Up:
155     if (digitgraph) {
156       delete digitgraph  ;
157       digitgraph = 0 ;
158     }
159     if (clustertext) {
160       delete clustertext ;
161       clustertext = 0 ;
162     }
163     
164     break;
165     
166   }
167 }
168 //____________________________________________________________________________
169 void AliPHOSRecPoint::EvalAll(Float_t logWeight,TClonesArray * digits) {
170   //evaluates (if necessary) all RecPoint data members 
171
172   EvalPrimaries(digits) ;
173 }
174 //____________________________________________________________________________
175 void AliPHOSRecPoint::EvalPHOSMod(AliPHOSDigit * digit) 
176 {
177   // Returns the PHOS module in which the RecPoint is found
178
179   if( fPHOSMod == 0){
180   Int_t relid[4] ; 
181   
182   AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
183   AliPHOSGeometry * phosgeom =  const_cast<AliPHOSGeometry*>(gime->PHOSGeometry());
184
185   phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
186   fPHOSMod = relid[0];
187   }
188 }
189
190 //______________________________________________________________________________
191 void  AliPHOSRecPoint::EvalPrimaries(TClonesArray * digits)
192 {
193   // Constructs the list of primary particles (tracks) which have contributed to this RecPoint
194   // First in the list - primary, made strongest contribution to the center
195
196   
197   AliPHOSDigit * digit ;
198   Int_t * tempo    = new Int_t[fMaxTrack] ;
199
200   //Find digit in center
201   AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance("IHEP","") ;
202   if(!geom){
203     Error("EvalPrimaries","Can not instantiate PHOS geometry") ;
204     return ;
205   }
206   TVector3  pos ;
207   TMatrix  mat ;
208   GetGlobalPosition(pos,mat) ;
209   Int_t module ;
210   Double_t x,z ;
211   geom->ImpactOnEmc(pos.Theta(),pos.Phi(),module,z,x);
212   Int_t absId ;
213   geom->RelPosToAbsId(module,x,z,absId) ;
214   //copy primaries
215   Int_t index ;  
216   for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
217     digit = dynamic_cast<AliPHOSDigit *>(digits->At( fDigitsList[index] )) ; 
218     if(digit->GetId() == absId){ 
219       fMulTrack = digit->GetNprimary() ;
220       for(Int_t ii = 0 ; ii < fMulTrack ; ii++)
221         tempo[ii] = digit->GetPrimary(ii+1) ; 
222     }
223   }
224   
225   for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
226     digit = dynamic_cast<AliPHOSDigit *>(digits->At( fDigitsList[index] )) ; 
227     if(digit->GetId()!=absId){ //already done
228       Int_t nprimaries = digit->GetNprimary() ;
229       if(nprimaries){
230         Int_t * newprimaryarray = new Int_t[nprimaries] ;
231         Int_t ii ; 
232         for ( ii = 0 ; ii < nprimaries ; ii++)
233           newprimaryarray[ii] = digit->GetPrimary(ii+1) ; 
234         
235         Int_t jndex ;
236         for ( jndex = 0 ; jndex < nprimaries ; jndex++ ) { // all primaries in digit
237           if ( fMulTrack > fMaxTrack ) {
238             fMulTrack = - 1 ;
239             Error("EvalPrimaries", "GetNprimaries ERROR > increase fMaxTrack" ) ;
240             break ;
241           }
242           Int_t newprimary = newprimaryarray[jndex] ;
243           Int_t kndex ;
244           Bool_t already = kFALSE ;
245           for ( kndex = 0 ; kndex < fMulTrack ; kndex++ ) { //check if not already stored
246             if ( newprimary == tempo[kndex] ){
247               already = kTRUE ;
248               break ;
249             }
250           } // end of check
251           if ( !already) { // store it
252             tempo[fMulTrack] = newprimary ; 
253             fMulTrack++ ;
254           } // store it
255         } // all primaries in digit
256         delete [] newprimaryarray ; 
257       }
258     }
259   } // all digits
260
261   if(fMulTrack)
262     fTracksList = new Int_t[fMulTrack] ;
263   for(index = 0; index < fMulTrack; index++)
264     fTracksList[index] = tempo[index] ;
265   
266   delete [] tempo ;
267   
268 }
269 //____________________________________________________________________________
270 void AliPHOSRecPoint::GetGlobalPosition(TVector3 & gpos, TMatrix & gmat) const
271 {
272   // returns the position of the cluster in the global reference system of ALICE
273   // and the uncertainty on this position
274   
275   
276   AliPHOSGetter::GetInstance()->PHOSGeometry()->GetGlobal(this, gpos, gmat) ;
277  
278 }
279
280
281 //______________________________________________________________________________
282 void AliPHOSRecPoint::Paint(Option_t *)
283 {
284   // Paint this ALiRecPoint as a TMarker  with its current attributes
285   
286   TVector3 pos(0.,0.,0.)  ;
287   GetLocalPosition(pos)   ;
288   Coord_t x = pos.X()     ;
289   Coord_t y = pos.Z()     ;
290   Color_t markercolor = 1 ;
291   Size_t  markersize = 1. ;
292   Style_t markerstyle = 5 ;
293   
294   if (!gPad->IsBatch()) {
295     gVirtualX->SetMarkerColor(markercolor) ;
296     gVirtualX->SetMarkerSize (markersize)  ;
297     gVirtualX->SetMarkerStyle(markerstyle) ;
298   }
299   gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
300   gPad->PaintPolyMarker(1,&x,&y,"") ;
301 }