]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSTrackSegment.cxx
Compare() changed to Compare() const
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrackSegment.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 //  Track segment in PHOS
18 //  Can be : 1 EmcRecPoint
19 //           1 EmcRecPoint + 1 PPSD
20 //           1 EmcRecPoint + 1 PPSD + 1 PPSD     
21 //                  
22 //*-- Author:  Dmitri Peressounko (RRC KI & SUBATECH)
23
24 // --- ROOT system ---
25  
26 #include "TVector3.h"
27 #include "TPad.h"
28
29 // --- Standard library ---
30
31 #include <iostream.h>
32
33 // --- AliRoot header files ---
34
35 #include "AliPHOSTrackSegment.h" 
36 #include "AliPHOSv0.h"
37 #include "AliPHOSIndexToObject.h"
38
39 ClassImp(AliPHOSTrackSegment)
40
41 //____________________________________________________________________________
42 AliPHOSTrackSegment::AliPHOSTrackSegment( AliPHOSEmcRecPoint * emc , 
43                                           AliPHOSPpsdRecPoint * ppsdrp1,
44                                           AliPHOSPpsdRecPoint * ppsdrp2  ) 
45 {
46   // ctor
47
48   if( emc )   
49     fEmcRecPoint =  emc->GetIndexInList() ;
50   else 
51     fEmcRecPoint = -1 ;
52
53   if( ppsdrp1 )  
54     fPpsdUpRecPoint = ppsdrp1->GetIndexInList() ;
55  else 
56     fPpsdUpRecPoint = -1 ;
57
58   if( ppsdrp2  ) 
59     fPpsdLowRecPoint = ppsdrp2->GetIndexInList() ;
60   else 
61     fPpsdLowRecPoint = -1 ;
62
63   fIndexInList = -1 ;
64 }
65
66 //____________________________________________________________________________
67 AliPHOSTrackSegment::AliPHOSTrackSegment( const AliPHOSTrackSegment & ts) 
68 {
69   // Copy ctor
70
71   ( (AliPHOSTrackSegment &)ts ).Copy(*this) ; 
72 }
73
74
75 //____________________________________________________________________________
76 void AliPHOSTrackSegment::Copy(TObject & obj) 
77 {
78   // Copy of a track segment into another track segment
79
80    TObject::Copy(obj) ;
81    ( (AliPHOSTrackSegment &)obj ).fEmcRecPoint     = fEmcRecPoint ; 
82    ( (AliPHOSTrackSegment &)obj ).fPpsdLowRecPoint = fPpsdLowRecPoint ; 
83    ( (AliPHOSTrackSegment &)obj ).fPpsdUpRecPoint  = fPpsdUpRecPoint ; 
84    ( (AliPHOSTrackSegment &)obj ).fIndexInList     = fIndexInList ; 
85 }
86 //____________________________________________________________________________
87 Int_t AliPHOSTrackSegment::DistancetoPrimitive(Int_t px, Int_t py)
88 {
89   // Compute distance from point px,py to  a AliPHOSTrackSegment considered as a Tmarker
90   // Compute the closest distance of approach from point px,py to this marker.
91   // The distance is computed in pixels units.
92   
93   Int_t div = 1 ;  
94   Int_t dist = 9999 ; 
95   
96   TVector3 pos(0.,0.,0.) ;
97   
98   AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
99   AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ; 
100   AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ; 
101   
102   if ( emcrp != 0 ) {
103     emcrp->GetLocalPosition( pos) ;
104     Float_t x =  pos.X() ;
105     Float_t y =  pos.Z() ;
106     if ( ppsdlrp != 0 ) {
107       ppsdlrp->GetLocalPosition( pos ) ;
108       x +=  pos.X() ;
109       y +=  pos.Z() ;
110       div++ ; 
111     }
112     if ( ppsdurp != 0 ) {
113       ppsdurp->GetLocalPosition( pos ) ;
114       x +=  pos.X() ;
115       y +=  pos.Z() ;
116       div++ ; 
117     }
118     x /= div ; 
119     y /= div ; 
120
121     const Int_t kMaxDiff = 10;
122     Int_t pxm  = gPad->XtoAbsPixel(x);
123     Int_t pym  = gPad->YtoAbsPixel(y);
124     dist = (px-pxm)*(px-pxm) + (py-pym)*(py-pym);
125     
126     if (dist > kMaxDiff) return 9999;
127   }
128   return dist;
129 }
130
131 //___________________________________________________________________________
132  void AliPHOSTrackSegment::Draw(Option_t *option)
133  {
134    // Draw this AliPHOSTrackSegment with its current attribute
135    
136    AppendPad(option);
137  }
138
139 //______________________________________________________________________________
140 void AliPHOSTrackSegment::ExecuteEvent(Int_t event, Int_t px, Int_t py)
141 {
142   // Execute action corresponding to one event
143   //  This member function is called when a AliPHOSTrackSegment is clicked with the locator
144   //
145   //  If Left button is clicked on AliPHOSRecPoint, the digits are switched on    
146   //  and switched off when the mouse button is released.
147  
148   static TPaveText* textTS = 0 ;
149   
150   AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
151
152   if (!gPad->IsEditable()) 
153     return;
154   
155   switch (event) {
156     
157   case kButton1Down:{
158     
159     if (!textTS) {
160       
161       TVector3 pos(0.,0.,0.) ;
162       emcrp->GetLocalPosition(pos) ;
163       textTS = new TPaveText(pos.X()-10,pos.Z()+10,pos.X()+5,pos.Z()+15,"") ;
164       Text_t  line1[40] ;
165       sprintf(line1,"See RecParticle for ID") ;
166       textTS ->AddText(line1) ;
167       textTS ->Draw("");
168       gPad->Update() ; 
169     }
170   }
171   
172   break;
173   
174   case kButton1Up:
175     if (textTS) {
176       delete textTS ;
177       textTS = 0 ;
178     }
179     break;  
180   }
181 }
182
183 //____________________________________________________________________________
184 Float_t AliPHOSTrackSegment::GetDistanceInPHOSPlane()
185 {
186   // Calculates the distance between the EMC RecPoint and PPSD RecPoint
187   
188   AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
189   AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ; 
190
191   TVector3 vecEmc ;
192   emcrp->GetLocalPosition(vecEmc) ;
193   
194   TVector3 vecPpsd ;
195   if ( ppsdlrp !=0 ) {
196     if( ppsdlrp->GetMultiplicity() )  
197       ppsdlrp->GetLocalPosition(vecPpsd)  ; 
198     else { 
199       vecPpsd.SetX(10000.) ;
200     } 
201     vecEmc -= vecPpsd ;
202   }
203   Float_t r = vecEmc.Mag();;
204
205   return r ;
206 }
207
208 //____________________________________________________________________________
209 AliPHOSEmcRecPoint * AliPHOSTrackSegment::GetEmcRecPoint() const 
210 {
211   // get the EMC recpoint at the origin of this track
212  
213   AliPHOSIndexToObject * please =  AliPHOSIndexToObject::GetInstance() ;
214   AliPHOSEmcRecPoint * rv = 0 ;
215   if (  fEmcRecPoint > -1 )
216     rv = (AliPHOSEmcRecPoint *)please->GimeRecPoint( fEmcRecPoint, TString("emc") );
217   
218   return rv ;
219
220 }
221   
222 //____________________________________________________________________________
223  Float_t AliPHOSTrackSegment::GetEnergy()
224
225   // Returns energy in EMC
226   
227   AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
228   
229   return emcrp->GetEnergy() ;
230 }   
231
232 //____________________________________________________________________________
233 TVector3 AliPHOSTrackSegment::GetMomentumDirection() 
234
235   // Calculates the momentum direction:
236   //   1. if only a EMC RecPoint, direction is given by IP and this RecPoint
237   //   2. if a EMC RecPoint and one PPSD RecPoint, direction is given by the line through the 2 recpoints 
238   //   3. if a EMC RecPoint and two PPSD RecPoints, dirrection is given by the average line through 
239   //      the 2 pairs of recpoints  
240   // However because of the poor position resolution of PPSD the direction is always taken as if we were 
241   //  in case 1.
242
243
244   AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
245   // AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ; 
246   // AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ; 
247
248   TVector3 dir(0,0,0) ; 
249   TMatrix mdummy ;
250
251   TVector3 posEmc ;
252   emcrp->GetGlobalPosition(posEmc, mdummy) ;
253  
254   TVector3 emcglobalpos ;
255   TMatrix  dummy ;
256
257   emcrp->GetGlobalPosition(emcglobalpos, dummy) ;
258
259   
260 // The following commeneted code becomes valid once the PPSD provides 
261 // a reasonable position resolution, at least as good as EMC ! 
262 //   TVector3 ppsdlglobalpos ;
263 //   TVector3 ppsduglobalpos ;
264 //   if( fPpsdLowRecPoint ){ // certainly a photon that has concerted
265 //     fPpsdLowRecPoint->GetGlobalPosition(ppsdlglobalpos, mdummy) ; 
266 //     dir = emcglobalpos -  ppsdlglobalpos ; 
267 //     if( fPpsdUpRecPoint ){ // not looks like a charged       
268 //        fPpsdUpRecPoint->GetGlobalPosition(ppsduglobalpos, mdummy) ; 
269 //        dir = ( dir +  emcglobalpos -  ppsduglobalpos ) * 0.5 ; 
270 //      }
271 //   }
272 //   else { // looks like a neutral
273 //    dir = emcglobalpos ;  
274 //  }
275
276   dir = emcglobalpos ;  
277   dir.SetZ( -dir.Z() ) ;   // why ?  
278   dir.SetMag(1.) ;
279     
280   return dir ;  
281 }
282
283 //____________________________________________________________________________
284 Int_t AliPHOSTrackSegment:: GetPHOSMod(void) 
285 {
286   // Returns the phos module which contains this track
287  
288   AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
289   
290   return emcrp->GetPHOSMod();  
291 }
292
293 //____________________________________________________________________________
294 AliPHOSPpsdRecPoint * AliPHOSTrackSegment::GetPpsdLowRecPoint() const 
295 {
296   // Returns the lower PPSD rec point at the origin of this track
297   
298   AliPHOSIndexToObject * please =  AliPHOSIndexToObject::GetInstance() ;
299   AliPHOSPpsdRecPoint * rv = 0 ;
300   
301   if ( fPpsdLowRecPoint > -1 )
302     rv = (AliPHOSPpsdRecPoint *)please->GimeRecPoint( fPpsdLowRecPoint, TString("ppsd") ) ;
303   
304   return rv ; 
305 }
306
307 //____________________________________________________________________________
308 AliPHOSPpsdRecPoint * AliPHOSTrackSegment::GetPpsdUpRecPoint() const 
309 {
310   // Returns the lower PPSD rec point at the origin of this track
311
312   AliPHOSIndexToObject * please =  AliPHOSIndexToObject::GetInstance() ;
313   AliPHOSPpsdRecPoint * rv = 0 ;
314  
315   if ( fPpsdUpRecPoint > -1 )
316     rv =  (AliPHOSPpsdRecPoint *)please->GimeRecPoint( fPpsdUpRecPoint, TString("ppsd") ) ;
317
318   return rv ;
319 }
320
321 //____________________________________________________________________________
322 Int_t *  AliPHOSTrackSegment::GetPrimariesEmc(Int_t & number) 
323
324   // Retrieves the primary particle(s) at the origin of the EMC RecPoint
325     
326   AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
327
328   Int_t * rv = 0 ; 
329   number = 0 ;
330   if ( emcrp )
331     rv =  emcrp->GetPrimaries(number) ; 
332
333   return rv ; 
334 }
335
336 //____________________________________________________________________________
337 Int_t *  AliPHOSTrackSegment::GetPrimariesPpsdLow(Int_t & number) 
338
339   // Retrieves the primary particle(s) at the origin of the lower PPSD RecPoint
340   
341   AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ; 
342
343   Int_t * rv = 0 ; 
344   number = 0 ;
345   if ( ppsdlrp )
346     rv =  ppsdlrp->GetPrimaries(number) ; 
347
348   return rv ; 
349 }
350
351 //____________________________________________________________________________
352 Int_t *  AliPHOSTrackSegment::GetPrimariesPpsdUp(Int_t & number) 
353
354   // Retrieves the primary particle(s) at the origin of the upper PPSD  RecPoint
355   
356   AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ; 
357
358   Int_t * rv = 0 ; 
359   number = 0 ;
360   if ( ppsdurp )
361     rv =  ppsdurp->GetPrimaries(number) ; 
362
363   return rv ; 
364 }
365
366 //____________________________________________________________________________
367 void AliPHOSTrackSegment::GetPosition( TVector3 & pos ) 
368 {  
369   // Returns position of the EMC RecPoint
370   
371   AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
372  
373   TMatrix dummy ;
374   emcrp->GetGlobalPosition(pos, dummy) ;
375 }
376
377
378 //______________________________________________________________________________
379 void AliPHOSTrackSegment::Paint(Option_t *)
380 {
381   // Paint this AliPHOSTrackSegment as a TMarker  with its current attributes
382
383   AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
384   AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ; 
385   AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ; 
386
387   TVector3 posemc(999., 999., 999.) ;
388   TVector3 posppsdl(999., 999., 999.) ;
389   TVector3 posppsdu(999., 999., 999.) ;
390   
391   emcrp->GetLocalPosition(posemc) ;
392   if (ppsdlrp !=0 ) 
393     ppsdlrp->GetLocalPosition(posppsdl) ;
394   if (ppsdurp !=0 ) 
395     ppsdurp->GetLocalPosition(posppsdu) ;
396   
397   Coord_t xemc   = posemc.X() ;
398   Coord_t yemc   = posemc.Z() ;
399   
400   Coord_t yppsdl = posppsdl.Z() ;
401   Coord_t xppsdl = posppsdl.X() ;
402   
403   Coord_t yppsdu = posppsdu.Z() ;
404   Coord_t xppsdu = posppsdu.X() ;
405   
406   Color_t markercolor = 1 ;
407   Size_t  markersize  = 1.5 ;
408   Style_t markerstyle = 20 ;
409   
410   if (!gPad->IsBatch()) {
411     gVirtualX->SetMarkerColor(markercolor) ;
412     gVirtualX->SetMarkerSize (markersize)  ;
413     gVirtualX->SetMarkerStyle(markerstyle) ;
414   }
415   gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
416   gPad->PaintPolyMarker(1, &xemc, &yemc, "") ;
417   
418   if (xppsdl != 999. && yppsdl != 999. ) {
419     
420     markercolor = 2 ;
421     markersize  = 1.25 ;
422     markerstyle = 21 ;
423     
424     if (!gPad->IsBatch()) {
425       gVirtualX->SetMarkerColor(markercolor) ;
426       gVirtualX->SetMarkerSize (markersize)  ;
427       gVirtualX->SetMarkerStyle(markerstyle) ;
428     }
429     gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
430     gPad->PaintPolyMarker(1, &xppsdl, &yppsdl, "") ;
431   }
432   
433   if (xppsdu != 999. && yppsdu != 999. ) {
434     
435     markercolor = 3 ;
436     markersize  = 1. ;
437     markerstyle = 22 ;
438     
439     if (!gPad->IsBatch()) {
440       gVirtualX->SetMarkerColor(markercolor) ;
441       gVirtualX->SetMarkerSize (markersize)  ;
442       gVirtualX->SetMarkerStyle(markerstyle) ;
443     }
444     gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
445     gPad->PaintPolyMarker(1, &xppsdu, &yppsdu, "") ;
446   }
447 }
448
449 //____________________________________________________________________________
450 void AliPHOSTrackSegment::Print(const char * opt)
451 {
452   // Print all information on this track Segment
453   
454   AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
455   AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ; 
456   AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ; 
457   
458   TVector3 pos ;
459   TMatrix dummy ;  
460
461   cout << "--------AliPHOSTrackSegment-------- "<<endl ;
462
463   if ( emcrp != 0 ) {
464     cout << "******** EMC Reconstructed Point: " << endl;
465     emcrp->Print() ; 
466     
467     emcrp->GetGlobalPosition( pos, dummy ) ;
468     
469     cout << " Global position " << pos.X() << "   " << pos.Y() << "  " << pos.Z() << "      Energy " << emcrp->GetEnergy() << endl ;
470   }
471   
472   if ( ppsdlrp != 0 ) {
473     cout << "******** PPSD Low Reconstructed Point: " << endl;
474     
475     ppsdlrp->Print() ; 
476     ppsdlrp->GetGlobalPosition( pos , dummy ) ;
477     cout << "    position " << pos.X() << "   " << pos.Y() << "  " << pos.Z() << endl ;
478   }
479
480    if( ppsdurp != 0 ) {
481      cout << "******** PPSD Up Reconstructed Point: " << endl;
482      
483      ppsdurp->Print() ; 
484      ppsdurp->GetGlobalPosition( pos, dummy ) ;
485      cout << "    position " << pos.X() << "   " << pos.Y() << "  " << pos.Z()  << endl ;
486    }
487    
488 }
489 //____________________________________________________________________________
490 void AliPHOSTrackSegment::SetPpsdUpRecPoint(AliPHOSPpsdRecPoint * PpsdUpRecPoint) 
491 {
492   // gives an id from its position in the list
493   if( PpsdUpRecPoint )  
494     fPpsdUpRecPoint = PpsdUpRecPoint->GetIndexInList() ;
495  else 
496     fPpsdUpRecPoint = -1 ;
497 }
498