]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSTrackSegment.cxx
parameters have been redistributed; Hits2SDigits etc ... introduce
[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->GetTotalEnergy() ;
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   // Correction for the depth of the shower starting point (TDR p 127) 
255
256   Float_t energy = emcrp->GetEnergy() ; 
257   Float_t para = 0.925 ; 
258   Float_t parb = 6.52 ; 
259
260   TVector3 localpos ; 
261   emcrp->GetLocalPosition(localpos) ; 
262
263   AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ; 
264   Float_t radius = geom->GetIPtoOuterCoverDistance() + geom->GetOuterBoxSize(1) ; 
265   Float_t incidencephi = TMath::ATan(localpos.X() / radius) ; 
266   Float_t incidencetheta = TMath::ATan(localpos.Z() / radius) ;
267  
268   Float_t depthx =  ( para * TMath::Log(energy) + parb ) * TMath::Sin(incidencephi) ; 
269   Float_t depthz =  ( para * TMath::Log(energy) + parb ) * TMath::Sin(incidencetheta) ; 
270   
271   localpos.SetX(localpos.X() - depthx ) ;
272   localpos.SetZ(localpos.Z() - depthz ) ;
273  
274   TVector3 emcglobalpos ;
275   TMatrix  dummy ;
276
277   emcrp->GetGlobalPosition(emcglobalpos, dummy) ;
278
279   emcglobalpos.SetX( emcglobalpos.X() - depthx ) ;  
280   emcglobalpos.SetZ( emcglobalpos.Z() - depthz ) ;   
281   
282   // The following commeneted code becomes valid once the PPSD provides 
283   // a reasonable position resolution, at least as good as EMC !
284  
285 //   TVector3 ppsdlglobalpos ;
286 //   TVector3 ppsduglobalpos ;
287
288 //   if( fPpsdLowRecPoint ){ // certainly a photon that has concerted
289         
290 //     fPpsdLowRecPoint->GetGlobalPosition(ppsdlglobalpos, mdummy) ; 
291 //     dir = emcglobalpos -  ppsdlglobalpos ; 
292      
293 //     if( fPpsdUpRecPoint ){ // nop looks like a charged
294        
295 //        fPpsdUpRecPoint->GetGlobalPosition(ppsduglobalpos, mdummy) ; 
296 //        dir = ( dir +  emcglobalpos -  ppsduglobalpos ) * 0.5 ; 
297 //      }
298 //   }
299  
300 //   else { // looks like a neutral
301
302     dir = emcglobalpos ;  
303 //  }
304
305   dir.SetZ( -dir.Z() ) ;   // why ?  
306   dir.SetMag(1.) ;
307     
308   return dir ;  
309 }
310
311 //____________________________________________________________________________
312 Int_t AliPHOSTrackSegment:: GetPHOSMod(void) 
313 {
314   // Returns the phos module which contains this track
315  
316   AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
317   
318   return emcrp->GetPHOSMod();  
319 }
320
321 //____________________________________________________________________________
322 AliPHOSPpsdRecPoint * AliPHOSTrackSegment::GetPpsdLowRecPoint() const 
323 {
324   // Returns the lower PPSD rec point at the origin of this track
325   
326   AliPHOSIndexToObject * please =  AliPHOSIndexToObject::GetInstance() ;
327   AliPHOSPpsdRecPoint * rv = 0 ;
328   
329   if ( fPpsdLowRecPoint > -1 )
330     rv = (AliPHOSPpsdRecPoint *)please->GimeRecPoint( fPpsdLowRecPoint, TString("ppsd") ) ;
331   
332   return rv ; 
333 }
334
335 //____________________________________________________________________________
336 AliPHOSPpsdRecPoint * AliPHOSTrackSegment::GetPpsdUpRecPoint() const 
337 {
338   // Returns the lower PPSD rec point at the origin of this track
339
340   AliPHOSIndexToObject * please =  AliPHOSIndexToObject::GetInstance() ;
341   AliPHOSPpsdRecPoint * rv = 0 ;
342  
343   if ( fPpsdUpRecPoint > -1 )
344     rv =  (AliPHOSPpsdRecPoint *)please->GimeRecPoint( fPpsdUpRecPoint, TString("ppsd") ) ;
345
346   return rv ;
347 }
348
349 //____________________________________________________________________________
350 Int_t *  AliPHOSTrackSegment::GetPrimariesEmc(Int_t & number) 
351
352   // Retrieves the primary particle(s) at the origin of the EMC RecPoint
353     
354   AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
355
356   Int_t * rv = 0 ; 
357   number = 0 ;
358   if ( emcrp )
359     rv =  emcrp->GetPrimaries(number) ; 
360
361   return rv ; 
362 }
363
364 //____________________________________________________________________________
365 Int_t *  AliPHOSTrackSegment::GetPrimariesPpsdLow(Int_t & number) 
366
367   // Retrieves the primary particle(s) at the origin of the lower PPSD RecPoint
368   
369   AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ; 
370
371   Int_t * rv = 0 ; 
372   number = 0 ;
373   if ( ppsdlrp )
374     rv =  ppsdlrp->GetPrimaries(number) ; 
375
376   return rv ; 
377 }
378
379 //____________________________________________________________________________
380 Int_t *  AliPHOSTrackSegment::GetPrimariesPpsdUp(Int_t & number) 
381
382   // Retrieves the primary particle(s) at the origin of the upper PPSD  RecPoint
383   
384   AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ; 
385
386   Int_t * rv = 0 ; 
387   number = 0 ;
388   if ( ppsdurp )
389     rv =  ppsdurp->GetPrimaries(number) ; 
390
391   return rv ; 
392 }
393
394 //____________________________________________________________________________
395 void AliPHOSTrackSegment::GetPosition( TVector3 & pos ) 
396 {  
397   // Returns position of the EMC RecPoint
398   
399   AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
400  
401   TMatrix dummy ;
402   emcrp->GetGlobalPosition(pos, dummy) ;
403 }
404
405
406 //______________________________________________________________________________
407 void AliPHOSTrackSegment::Paint(Option_t *)
408 {
409   // Paint this AliPHOSTrackSegment as a TMarker  with its current attributes
410
411   AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
412   AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ; 
413   AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ; 
414
415   TVector3 posemc(999., 999., 999.) ;
416   TVector3 posppsdl(999., 999., 999.) ;
417   TVector3 posppsdu(999., 999., 999.) ;
418   
419   emcrp->GetLocalPosition(posemc) ;
420   if (ppsdlrp !=0 ) 
421     ppsdlrp->GetLocalPosition(posppsdl) ;
422   if (ppsdurp !=0 ) 
423     ppsdurp->GetLocalPosition(posppsdu) ;
424   
425   Coord_t xemc   = posemc.X() ;
426   Coord_t yemc   = posemc.Z() ;
427   
428   Coord_t yppsdl = posppsdl.Z() ;
429   Coord_t xppsdl = posppsdl.X() ;
430   
431   Coord_t yppsdu = posppsdu.Z() ;
432   Coord_t xppsdu = posppsdu.X() ;
433   
434   Color_t markercolor = 1 ;
435   Size_t  markersize  = 1.5 ;
436   Style_t markerstyle = 20 ;
437   
438   if (!gPad->IsBatch()) {
439     gVirtualX->SetMarkerColor(markercolor) ;
440     gVirtualX->SetMarkerSize (markersize)  ;
441     gVirtualX->SetMarkerStyle(markerstyle) ;
442   }
443   gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
444   gPad->PaintPolyMarker(1, &xemc, &yemc, "") ;
445   
446   if (xppsdl != 999. && yppsdl != 999. ) {
447     
448     markercolor = 2 ;
449     markersize  = 1.25 ;
450     markerstyle = 21 ;
451     
452     if (!gPad->IsBatch()) {
453       gVirtualX->SetMarkerColor(markercolor) ;
454       gVirtualX->SetMarkerSize (markersize)  ;
455       gVirtualX->SetMarkerStyle(markerstyle) ;
456     }
457     gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
458     gPad->PaintPolyMarker(1, &xppsdl, &yppsdl, "") ;
459   }
460   
461   if (xppsdu != 999. && yppsdu != 999. ) {
462     
463     markercolor = 3 ;
464     markersize  = 1. ;
465     markerstyle = 22 ;
466     
467     if (!gPad->IsBatch()) {
468       gVirtualX->SetMarkerColor(markercolor) ;
469       gVirtualX->SetMarkerSize (markersize)  ;
470       gVirtualX->SetMarkerStyle(markerstyle) ;
471     }
472     gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
473     gPad->PaintPolyMarker(1, &xppsdu, &yppsdu, "") ;
474   }
475 }
476
477 //____________________________________________________________________________
478 void AliPHOSTrackSegment::Print(const char * opt)
479 {
480   // Print all information on this track Segment
481   
482   AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
483   AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ; 
484   AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ; 
485   
486   TVector3 pos ;
487   TMatrix dummy ;  
488
489   cout << "--------AliPHOSTrackSegment-------- "<<endl ;
490
491   if ( emcrp != 0 ) {
492     cout << "******** EMC Reconstructed Point: " << endl;
493     emcrp->Print() ; 
494     
495     emcrp->GetGlobalPosition( pos, dummy ) ;
496     
497     cout << " Global position " << pos.X() << "   " << pos.Y() << "  " << pos.Z() << "      Energy " << emcrp->GetTotalEnergy() << endl ;
498   }
499   
500   if ( ppsdlrp != 0 ) {
501     cout << "******** PPSD Low Reconstructed Point: " << endl;
502     
503     ppsdlrp->Print() ; 
504     ppsdlrp->GetGlobalPosition( pos , dummy ) ;
505     cout << "    position " << pos.X() << "   " << pos.Y() << "  " << pos.Z() << endl ;
506   }
507
508    if( ppsdurp != 0 ) {
509      cout << "******** PPSD Up Reconstructed Point: " << endl;
510      
511      ppsdurp->Print() ; 
512      ppsdurp->GetGlobalPosition( pos, dummy ) ;
513      cout << "    position " << pos.X() << "   " << pos.Y() << "  " << pos.Z()  << endl ;
514    }
515    
516 }
517 //____________________________________________________________________________
518 void AliPHOSTrackSegment::SetPpsdUpRecPoint(AliPHOSPpsdRecPoint * PpsdUpRecPoint) 
519 {
520   // gives an id from its position in the list
521   if( PpsdUpRecPoint )  
522     fPpsdUpRecPoint = PpsdUpRecPoint->GetIndexInList() ;
523  else 
524     fPpsdUpRecPoint = -1 ;
525 }
526