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