]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/src/AliL3Track.cxx
Inserted image on top.
[u/mrichter/AliRoot.git] / HLT / src / AliL3Track.cxx
1 //$Id$
2
3 // Author: Anders Vestbo <mailto:vestbo$fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>
4 //*-- Copyright &copy ASV
5
6
7 #include "AliL3RootTypes.h"
8
9 #include "AliL3Defs.h"
10 #include "AliL3Logging.h"
11 #include "AliL3Track.h"
12 #include "AliL3Transform.h"
13 #include "AliL3Vertex.h"
14 #include <math.h>
15
16 //_____________________________________________________________
17 // AliL3Track
18 //
19 // Track base class
20 //Begin_Html
21 /*
22 <img src="track_coordinates.gif">
23 */
24 //End_Html
25
26 ClassImp(AliL3Track)
27
28 Float_t AliL3Track::BFACT = 0.0029980;
29 Double_t AliL3Track::pi=3.14159265358979323846;
30
31 AliL3Track::AliL3Track()
32 {
33   //Constructor
34
35   fNHits = 0;
36   fMCid = -1;
37   fKappa=0;
38   fRadius=0;
39   fCenterX=0;
40   fCenterY=0;
41   ComesFromMainVertex(false);
42   fQ = 0;
43   fPhi0=0;
44   fPsi=0;
45   fR0=0;
46   fTanl=0;
47   fZ0=0;
48   fPt=0;
49   fLength=0;
50   fIsLocal=true;
51   fRowRange[0]=0;
52   fRowRange[1]=0;
53   memset(fHitNumbers,0,176*sizeof(UInt_t));
54 }
55
56 void AliL3Track::Set(AliL3Track *tpt){
57   
58   SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
59   SetPhi0(tpt->GetPhi0());
60   SetKappa(tpt->GetKappa());
61   SetNHits(tpt->GetNHits());
62   SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
63   SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
64   SetPt(tpt->GetPt());
65   SetPsi(tpt->GetPsi());
66   SetTgl(tpt->GetTgl());
67   SetCharge(tpt->GetCharge());
68   SetHits(tpt->GetNHits(),(UInt_t *)tpt->GetHitNumbers());
69
70 }
71
72 Int_t AliL3Track::Compare(const AliL3Track *track) const
73 {
74   if(track->GetNHits() < GetNHits()) return 1;
75   if(track->GetNHits() > GetNHits()) return -1;
76   return 0;
77 }
78
79 AliL3Track::~AliL3Track()
80 {
81   //Nothing to do
82 }
83
84 Double_t AliL3Track::GetP() const
85 {
86   // Returns total momentum.  
87   return fabs(GetPt())*sqrt(1. + GetTgl()*GetTgl());
88
89 }
90
91 Double_t AliL3Track::GetPseudoRapidity() const
92 {
93   return 0.5 * log((GetP() + GetPz()) / (GetP() - GetPz()));
94 }
95 /*
96 Double_t AliL3Track::GetEta() const
97 {
98   return GetPseudoRapidity();
99 }
100 */
101 Double_t AliL3Track::GetRapidity() const
102 {
103   Double_t m_pi = 0.13957;
104   return 0.5 * log((m_pi + GetPz()) / (m_pi - GetPz()));
105 }
106
107 void AliL3Track::Rotate(Int_t slice,Bool_t tolocal)
108 {
109   //Rotate track to global parameters
110   //If flag tolocal is set, the track is rotated
111   //to local coordinates.
112
113   AliL3Transform *transform = new AliL3Transform();
114   
115   Float_t psi[1] = {GetPsi()};
116   if(!tolocal)
117     transform->Local2GlobalAngle(psi,slice);
118   else
119     transform->Global2LocalAngle(psi,slice);
120   SetPsi(psi[0]);
121   Float_t first[3];
122   first[0] = GetFirstPointX();
123   first[1] = GetFirstPointY();
124   first[2] = GetFirstPointZ();
125   if(!tolocal)
126     transform->Local2Global(first,slice);
127   else
128     transform->Global2Local(first,slice,kTRUE);
129   
130   SetFirstPoint(first[0],first[1],first[2]);
131   Float_t last[3];
132   last[0] = GetLastPointX();
133   last[1] = GetLastPointY();
134   last[2] = GetLastPointZ();
135   if(!tolocal)
136     transform->Local2Global(last,slice);
137   else
138     transform->Global2Local(last,slice,kTRUE);
139   SetLastPoint(last[0],last[1],last[2]);
140   
141   Float_t center[3] = {GetCenterX(),GetCenterY(),0};
142   if(!tolocal)
143     transform->Local2Global(center,slice);
144   else
145     transform->Global2Local(center,slice,kTRUE);
146   SetCenterX(center[0]);
147   SetCenterY(center[1]);
148   
149   if(!tolocal)
150     fIsLocal=kFALSE;
151   else
152     fIsLocal=kTRUE;
153   delete transform;
154 }
155
156 void AliL3Track::CalculateHelix(){
157   //Calculate Radius, CenterX and Centery from Psi, X0, Y0
158   //
159   
160   fRadius = fPt / (BFACT*BField);
161   if(fRadius) fKappa = -fQ*1./fRadius;
162   else fRadius = 999999;  //just zero
163   Double_t trackPhi0 = fPsi + fQ *0.5 * pi;
164
165   fCenterX = fFirstPoint[0] - fRadius *  cos(trackPhi0);
166   fCenterY = fFirstPoint[1] - fRadius *  sin(trackPhi0);
167 }
168
169 Double_t AliL3Track::GetCrossingAngle(Int_t padrow) 
170 {
171   //Calculate the crossing angle between track and given padrow.
172   
173   if(!IsLocal())
174     {
175       printf("Track is not given in local coordinates\n");
176       return 0;
177     }
178   
179   Float_t xyz[3];
180   if(!GetCrossingPoint(padrow,xyz))
181     printf("AliL3HoughTrack::GetCrossingPoint : Track does not cross line!!\n");
182   
183   //Take the dot product of the tangent vector of the track, and
184   //vector perpendicular to the padrow.
185   
186   Double_t tangent[2];
187   tangent[1] = (xyz[0] - GetCenterX())/GetRadius();
188   tangent[0] = -1.*(xyz[1] - GetCenterY())/GetRadius();
189
190   Double_t perp_padrow[2] = {1,0}; //locally in slice
191
192   Double_t cos_beta = fabs(tangent[0]*perp_padrow[0] + tangent[1]*perp_padrow[1]);
193   return acos(cos_beta);
194   
195 }
196
197 Bool_t AliL3Track::GetCrossingPoint(Int_t padrow,Float_t *xyz) 
198 {
199   //Assumes the track is given in local coordinates
200
201   AliL3Transform *transform = new AliL3Transform();
202   
203   if(!IsLocal())
204     {
205       printf("GetCrossingPoint: Track is given on global coordinates\n");
206       return false;
207     }
208   
209   Double_t xHit = transform->Row2X(padrow);
210
211   xyz[0] = xHit;
212   Double_t aa = (xHit - GetCenterX())*(xHit - GetCenterX());
213   Double_t r2 = GetRadius()*GetRadius();
214   if(aa > r2)
215     return false;
216
217   Double_t aa2 = sqrt(r2 - aa);
218   Double_t y1 = GetCenterY() + aa2;
219   Double_t y2 = GetCenterY() - aa2;
220   xyz[1] = y1;
221   if(fabs(y2) < fabs(y1)) xyz[1] = y2;
222   
223   Double_t yHit = xyz[1];
224   Double_t angle1 = atan2((yHit - GetCenterY()),(xHit - GetCenterX()));
225   if(angle1 < 0) angle1 += 2.*Pi;
226   Double_t angle2 = atan2((GetFirstPointY() - GetCenterY()),(GetFirstPointX() - GetCenterX()));
227   if(angle2 < 0) angle2 += 2.*Pi;
228   Double_t diff_angle = angle1 - angle2;
229   diff_angle = fmod(diff_angle,2*Pi);
230   if((GetCharge()*diff_angle) > 0) diff_angle = diff_angle - GetCharge()*2.*Pi;
231   Double_t s_tot = fabs(diff_angle)*GetRadius();
232   Double_t zHit = GetFirstPointZ() + s_tot*GetTgl();
233   xyz[2] = zHit;
234   
235   delete transform;
236   return true;
237 }
238
239
240 Bool_t AliL3Track::CalculateReferencePoint(Double_t angle,Double_t radius){
241   // Global coordinate: crossing point with y = ax+ b; a=tan(angle-Pi/2);
242   //
243   const Double_t rr=radius;//132; //position of referece plane
244   const Double_t xr = cos(angle) *rr;
245   const Double_t yr = sin(angle) *rr;
246   
247   Double_t a = tan(angle-pi/2);
248   Double_t b = yr - a * xr;
249
250   Double_t pp=(fCenterX+a*fCenterY-a*b)/(1+pow(a,2));
251   Double_t qq=(pow(fCenterX,2)+pow(fCenterY,2)-2*fCenterY*b+pow(b,2)-pow(fRadius,2))/(1+pow(a,2));
252
253   Double_t racine = pp*pp-qq;
254   if(racine<0) return IsPoint(kFALSE);      //no Point
255
256   Double_t rootRacine = sqrt(racine);
257   Double_t x0 = pp+rootRacine;
258   Double_t x1 = pp-rootRacine;
259   Double_t y0 = a*x0 + b;
260   Double_t y1 = a*x1 + b;
261
262   Double_t diff0 = sqrt(pow(x0-xr,2)+pow(y0-yr,2));
263   Double_t diff1 = sqrt(pow(x1-xr,2)+pow(y1-yr,2));
264  
265   if(diff0<diff1){
266     fPoint[0]=x0;
267     fPoint[1]=y0;
268   }
269   else{
270     fPoint[0]=x1;
271     fPoint[1]=y1;
272   }
273
274   Double_t pointPhi0  = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
275   Double_t trackPhi0  = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
276   if(fabs(trackPhi0-pointPhi0)>pi){
277     if(trackPhi0<pointPhi0) trackPhi0 += 2*pi;
278     else                    pointPhi0 += 2*pi;
279   }
280   Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
281   fPoint[2]   = fFirstPoint[2] + stot * fTanl;
282
283   fPointPsi = pointPhi0 - fQ * 0.5 * pi;
284   if(fPointPsi<0.)  fPointPsi+= 2*pi;
285   fPointPsi = fmod(fPointPsi, 2*pi);
286
287   return IsPoint(kTRUE);
288 }
289
290 Bool_t AliL3Track::CalculateEdgePoint(Double_t angle){
291   // Global coordinate: crossing point with y = ax; a=tan(angle);
292   //
293   Double_t rmin=80;  //min Radius of TPC
294   Double_t rmax=260; //max Radius of TPC
295
296   Double_t a = tan(angle);
297   Double_t pp=(fCenterX+a*fCenterY)/(1+pow(a,2));
298   Double_t qq=(pow(fCenterX,2)+pow(fCenterY,2)-pow(fRadius,2))/(1+pow(a,2));
299   Double_t racine = pp*pp-qq;
300   if(racine<0) return IsPoint(kFALSE);     //no Point
301   Double_t rootRacine = sqrt(racine);
302   Double_t x0 = pp+rootRacine;
303   Double_t x1 = pp-rootRacine;
304   Double_t y0 = a*x0;
305   Double_t y1 = a*x1;
306
307   Double_t r0 = sqrt(pow(x0,2)+pow(y0,2));
308   Double_t r1 = sqrt(pow(x1,2)+pow(y1,2)); 
309   //find the right crossing point:
310   //inside the TPC modules
311   Bool_t ok0 = kFALSE;
312   Bool_t ok1 = kFALSE;
313
314   if(r0>rmin&&r0<rmax){
315     Double_t da=atan2(y0,x0);
316     if(da<0) da+=2*pi;
317     if(fabs(da-angle)<0.5)
318       ok0 = kTRUE;
319   }
320   if(r1>rmin&&r1<rmax){
321     Double_t da=atan2(y1,x1);
322     if(da<0) da+=2*pi;
323     if(fabs(da-angle)<0.5)
324       ok1 = kTRUE;
325   }
326   if(!(ok0||ok1)) return IsPoint(kFALSE);   //no Point
327   
328   if(ok0&&ok1){
329     Double_t diff0 = sqrt(pow(fFirstPoint[0]-x0,2)+pow(fFirstPoint[1]-y0,2));
330     Double_t diff1 = sqrt(pow(fFirstPoint[0]-x1,2)+pow(fFirstPoint[1]-y1,2));
331     if(diff0<diff1) ok1 = kFALSE; //use ok0
332     else ok0 = kFALSE;            //use ok1
333   }
334   if(ok0){fPoint[0]=x0; fPoint[1]=y0;}
335   else   {fPoint[0]=x1; fPoint[1]=y1;}
336
337   Double_t pointPhi0  = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
338   Double_t trackPhi0  = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
339   if(fabs(trackPhi0-pointPhi0)>pi){
340     if(trackPhi0<pointPhi0) trackPhi0 += 2*pi;
341     else                    pointPhi0 += 2*pi;
342   }
343   Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
344   fPoint[2]   = fFirstPoint[2] + stot * fTanl;
345
346   fPointPsi = pointPhi0 - fQ * 0.5 * pi;
347   if(fPointPsi<0.)  fPointPsi+= 2*pi;
348   fPointPsi = fmod(fPointPsi, 2*pi);
349
350   return IsPoint(kTRUE);
351 }
352
353 Bool_t AliL3Track::CalculatePoint(Double_t xplane){
354   // Local coordinate: crossing point with x plane
355   //
356   Double_t racine = pow(fRadius,2)-pow(xplane-fCenterX,2);
357   if(racine<0) return IsPoint(kFALSE);
358   Double_t rootRacine = sqrt(racine);
359
360   Double_t y0 = fCenterY + rootRacine;
361   Double_t y1 = fCenterY - rootRacine;
362   //Double_t diff0 = sqrt(pow(fFirstPoint[0]-xplane)+pow(fFirstPoint[1]-y0));
363   //Double_t diff1 = sqrt(pow(fFirstPoint[0]-xplane)+pow(fFirstPoint[1]-y1));
364   Double_t diff0 = fabs(y0-fFirstPoint[1]);
365   Double_t diff1 = fabs(y1-fFirstPoint[1]);
366
367   fPoint[0]=xplane;
368   if(diff0<diff1) fPoint[1]=y0;
369   else            fPoint[1]=y1;
370
371   Double_t pointPhi0  = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
372   Double_t trackPhi0  = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
373   if(fabs(trackPhi0-pointPhi0)>pi){
374     if(trackPhi0<pointPhi0) trackPhi0 += 2*pi;
375     else                    pointPhi0 += 2*pi;
376   }
377   Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;  
378   fPoint[2]   = fFirstPoint[2] + stot * fTanl;
379
380   fPointPsi = pointPhi0 - fQ * 0.5 * pi;
381   if(fPointPsi<0.)  fPointPsi+= 2*pi;
382   fPointPsi = fmod(fPointPsi, 2*pi);
383
384   return IsPoint(kTRUE);
385 }
386
387 void AliL3Track::GetClosestPoint(AliL3Vertex *vertex,Double_t &closest_x,Double_t &closest_y,Double_t &closest_z)
388 {
389   //Calculate the point of closest approach to the vertex
390   
391   
392   Double_t xc = GetCenterX() - vertex->GetX();//Shift the center of curvature with respect to the vertex
393   Double_t yc = GetCenterY() - vertex->GetY();
394   
395   Double_t dist_x1 = xc*(1 + GetRadius()/sqrt(xc*xc + yc*yc));
396   Double_t dist_y1 = yc*(1 + GetRadius()/sqrt(xc*xc + yc*yc));
397   Double_t distance1 = sqrt(dist_x1*dist_x1 + dist_y1*dist_y1);
398   
399   Double_t dist_x2 = xc*(1 - GetRadius()/sqrt(xc*xc + yc*yc));
400   Double_t dist_y2 = yc*(1 - GetRadius()/sqrt(xc*xc + yc*yc));
401   Double_t distance2 = sqrt(dist_x2*dist_x2 + dist_y2*dist_y2);
402   
403   //Choose the closest:
404   if(distance1 < distance2)
405     {
406       closest_x = dist_x1 + vertex->GetX();
407       closest_y = dist_y1 + vertex->GetY();
408     }
409   else
410     {
411       closest_x = dist_x2 + vertex->GetX();
412       closest_y = dist_y2 + vertex->GetY();
413     }
414   
415   //Get the z coordinate:
416   Double_t angle1 = atan2((closest_y-GetCenterY()),(closest_x-GetCenterX()));
417   if(angle1 < 0) angle1 = angle1 + 2*Pi;
418  
419   Double_t angle2 = atan2((GetFirstPointY()-GetCenterY()),(GetFirstPointX()-GetCenterX()));
420   if(angle2 < 0) angle2 = angle2 + 2*Pi;
421   
422   Double_t diff_angle = angle1 - angle2;
423   diff_angle = fmod(diff_angle,2*Pi);
424   
425   if((GetCharge()*diff_angle) < 0) diff_angle = diff_angle + GetCharge()*2*Pi;
426   Double_t s_tot = fabs(diff_angle)*GetRadius();
427   
428   closest_z = GetFirstPointZ() - s_tot*GetTgl();
429 }