3 // Author: Anders Vestbo <mailto:vestbo$fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>
4 //*-- Copyright © ASV
6 #include "AliL3StandardIncludes.h"
8 #include "AliL3RootTypes.h"
9 #include "AliL3Logging.h"
10 #include "AliL3Track.h"
11 #include "AliL3Transform.h"
12 #include "AliL3Vertex.h"
15 //_____________________________________________________________
21 <img src="track_coordinates.gif">
27 Float_t AliL3Track::BFACT = 0.0029980;
28 Double_t AliL3Track::pi=3.14159265358979323846;
30 AliL3Track::AliL3Track()
40 ComesFromMainVertex(false);
52 memset(fHitNumbers,0,159*sizeof(UInt_t));
55 void AliL3Track::Set(AliL3Track *tpt){
57 SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
58 SetPhi0(tpt->GetPhi0());
59 SetKappa(tpt->GetKappa());
60 SetNHits(tpt->GetNHits());
61 SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
62 SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
64 SetPsi(tpt->GetPsi());
65 SetTgl(tpt->GetTgl());
66 SetCharge(tpt->GetCharge());
67 SetHits(tpt->GetNHits(),(UInt_t *)tpt->GetHitNumbers());
70 Int_t AliL3Track::Compare(const AliL3Track *track) const
72 if(track->GetNHits() < GetNHits()) return 1;
73 if(track->GetNHits() > GetNHits()) return -1;
77 AliL3Track::~AliL3Track()
82 Double_t AliL3Track::GetP() const
84 // Returns total momentum.
85 return fabs(GetPt())*sqrt(1. + GetTgl()*GetTgl());
88 Double_t AliL3Track::GetPseudoRapidity() const
90 return 0.5 * log((GetP() + GetPz()) / (GetP() - GetPz()));
94 Double_t AliL3Track::GetEta() const
96 return GetPseudoRapidity();
100 Double_t AliL3Track::GetRapidity() const
102 Double_t m_pi = 0.13957;
103 return 0.5 * log((m_pi + GetPz()) / (m_pi - GetPz()));
106 void AliL3Track::Rotate(Int_t slice,Bool_t tolocal)
108 //Rotate track to global parameters
109 //If flag tolocal is set, the track is rotated
110 //to local coordinates.
113 Float_t psi[1] = {GetPsi()};
115 AliL3Transform::Local2GlobalAngle(psi,slice);
117 AliL3Transform::Global2LocalAngle(psi,slice);
120 first[0] = GetFirstPointX();
121 first[1] = GetFirstPointY();
122 first[2] = GetFirstPointZ();
124 AliL3Transform::Local2Global(first,slice);
126 AliL3Transform::Global2Local(first,slice,kTRUE);
128 SetFirstPoint(first[0],first[1],first[2]);
130 last[0] = GetLastPointX();
131 last[1] = GetLastPointY();
132 last[2] = GetLastPointZ();
134 AliL3Transform::Local2Global(last,slice);
136 AliL3Transform::Global2Local(last,slice,kTRUE);
137 SetLastPoint(last[0],last[1],last[2]);
139 Float_t center[3] = {GetCenterX(),GetCenterY(),0};
141 AliL3Transform::Local2Global(center,slice);
143 AliL3Transform::Global2Local(center,slice,kTRUE);
144 SetCenterX(center[0]);
145 SetCenterY(center[1]);
153 void AliL3Track::CalculateHelix(){
154 //Calculate Radius, CenterX and CenterY from Psi, X0, Y0
157 fRadius = fPt / (BFACT*AliL3Transform::GetBField());
158 if(fRadius) fKappa = -fQ*1./fRadius;
159 else fRadius = 999999; //just zero
160 Double_t trackPhi0 = fPsi + fQ *0.5 * pi;
162 fCenterX = fFirstPoint[0] - fRadius * cos(trackPhi0);
163 fCenterY = fFirstPoint[1] - fRadius * sin(trackPhi0);
166 Double_t AliL3Track::GetCrossingAngle(Int_t padrow)
168 //Calculate the crossing angle between track and given padrow.
172 printf("Track is not given in local coordinates\n");
177 if(!GetCrossingPoint(padrow,xyz))
178 printf("AliL3HoughTrack::GetCrossingPoint : Track does not cross line!!\n");
180 //Take the dot product of the tangent vector of the track, and
181 //vector perpendicular to the padrow.
182 //In order to do this, we need the tangent vector to the track at the
183 //point. This is done by rotating the radius vector by 90 degrees;
184 //rotation matrix: ( 0 1 )
188 tangent[0] = -1.*(xyz[1] - GetCenterY())/GetRadius();
189 tangent[1] = (xyz[0] - GetCenterX())/GetRadius();
191 Double_t perp_padrow[2] = {1,0}; //locally in slice
193 Double_t cos_beta = fabs(tangent[0]*perp_padrow[0] + tangent[1]*perp_padrow[1]);
194 return acos(cos_beta);
197 Bool_t AliL3Track::GetCrossingPoint(Int_t padrow,Float_t *xyz)
199 //Assumes the track is given in local coordinates
203 printf("GetCrossingPoint: Track is given on global coordinates\n");
207 Double_t xHit = AliL3Transform::Row2X(padrow);
210 Double_t aa = (xHit - GetCenterX())*(xHit - GetCenterX());
211 Double_t r2 = GetRadius()*GetRadius();
215 Double_t aa2 = sqrt(r2 - aa);
216 Double_t y1 = GetCenterY() + aa2;
217 Double_t y2 = GetCenterY() - aa2;
219 if(fabs(y2) < fabs(y1)) xyz[1] = y2;
221 Double_t yHit = xyz[1];
222 Double_t angle1 = atan2((yHit - GetCenterY()),(xHit - GetCenterX()));
223 if(angle1 < 0) angle1 += 2.*AliL3Transform::Pi();
224 Double_t angle2 = atan2((GetFirstPointY() - GetCenterY()),(GetFirstPointX() - GetCenterX()));
225 if(angle2 < 0) angle2 += 2.*AliL3Transform::Pi();
226 Double_t diff_angle = angle1 - angle2;
227 diff_angle = fmod(diff_angle,2*AliL3Transform::Pi());
228 if((GetCharge()*diff_angle) > 0) diff_angle = diff_angle - GetCharge()*2.*AliL3Transform::Pi();
229 Double_t s_tot = fabs(diff_angle)*GetRadius();
230 Double_t zHit = GetFirstPointZ() + s_tot*GetTgl();
237 Bool_t AliL3Track::CalculateReferencePoint(Double_t angle,Double_t radius){
238 // Global coordinate: crossing point with y = ax+ b; a=tan(angle-AliL3Transform::Pi()/2);
240 const Double_t rr=radius;//132; //position of reference plane
241 const Double_t xr = cos(angle) * rr;
242 const Double_t yr = sin(angle) * rr;
244 Double_t a = tan(angle-pi/2);
245 Double_t b = yr - a * xr;
247 Double_t pp=(fCenterX+a*fCenterY-a*b)/(1+pow(a,2));
248 Double_t qq=(pow(fCenterX,2)+pow(fCenterY,2)-2*fCenterY*b+pow(b,2)-pow(fRadius,2))/(1+pow(a,2));
250 Double_t racine = pp*pp-qq;
251 if(racine<0) return IsPoint(kFALSE); //no Point
253 Double_t rootRacine = sqrt(racine);
254 Double_t x0 = pp+rootRacine;
255 Double_t x1 = pp-rootRacine;
256 Double_t y0 = a*x0 + b;
257 Double_t y1 = a*x1 + b;
259 Double_t diff0 = sqrt(pow(x0-xr,2)+pow(y0-yr,2));
260 Double_t diff1 = sqrt(pow(x1-xr,2)+pow(y1-yr,2));
271 Double_t pointPhi0 = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
272 Double_t trackPhi0 = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
273 if(fabs(trackPhi0-pointPhi0)>pi){
274 if(trackPhi0<pointPhi0) trackPhi0 += 2*pi;
275 else pointPhi0 += 2*pi;
277 Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
278 fPoint[2] = fFirstPoint[2] + stot * fTanl;
280 fPointPsi = pointPhi0 - fQ * 0.5 * pi;
281 if(fPointPsi<0.) fPointPsi+= 2*pi;
282 fPointPsi = fmod(fPointPsi, 2*pi);
284 return IsPoint(kTRUE);
287 Bool_t AliL3Track::CalculateEdgePoint(Double_t angle){
288 // Global coordinate: crossing point with y = ax; a=tan(angle);
290 Double_t rmin=80; //min Radius of TPC
291 Double_t rmax=260; //max Radius of TPC
293 Double_t a = tan(angle);
294 Double_t pp=(fCenterX+a*fCenterY)/(1+pow(a,2));
295 Double_t qq=(pow(fCenterX,2)+pow(fCenterY,2)-pow(fRadius,2))/(1+pow(a,2));
296 Double_t racine = pp*pp-qq;
297 if(racine<0) return IsPoint(kFALSE); //no Point
298 Double_t rootRacine = sqrt(racine);
299 Double_t x0 = pp+rootRacine;
300 Double_t x1 = pp-rootRacine;
304 Double_t r0 = sqrt(pow(x0,2)+pow(y0,2));
305 Double_t r1 = sqrt(pow(x1,2)+pow(y1,2));
306 //find the right crossing point:
307 //inside the TPC modules
311 if(r0>rmin&&r0<rmax){
312 Double_t da=atan2(y0,x0);
314 if(fabs(da-angle)<0.5)
317 if(r1>rmin&&r1<rmax){
318 Double_t da=atan2(y1,x1);
320 if(fabs(da-angle)<0.5)
323 if(!(ok0||ok1)) return IsPoint(kFALSE); //no Point
326 Double_t diff0 = sqrt(pow(fFirstPoint[0]-x0,2)+pow(fFirstPoint[1]-y0,2));
327 Double_t diff1 = sqrt(pow(fFirstPoint[0]-x1,2)+pow(fFirstPoint[1]-y1,2));
328 if(diff0<diff1) ok1 = kFALSE; //use ok0
329 else ok0 = kFALSE; //use ok1
331 if(ok0){fPoint[0]=x0; fPoint[1]=y0;}
332 else {fPoint[0]=x1; fPoint[1]=y1;}
334 Double_t pointPhi0 = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
335 Double_t trackPhi0 = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
336 if(fabs(trackPhi0-pointPhi0)>pi){
337 if(trackPhi0<pointPhi0) trackPhi0 += 2*pi;
338 else pointPhi0 += 2*pi;
340 Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
341 fPoint[2] = fFirstPoint[2] + stot * fTanl;
343 fPointPsi = pointPhi0 - fQ * 0.5 * pi;
344 if(fPointPsi<0.) fPointPsi+= 2*pi;
345 fPointPsi = fmod(fPointPsi, 2*pi);
347 return IsPoint(kTRUE);
350 Bool_t AliL3Track::CalculatePoint(Double_t xplane){
351 // Local coordinate: crossing point with x plane
353 Double_t racine = pow(fRadius,2)-pow(xplane-fCenterX,2);
354 if(racine<0) return IsPoint(kFALSE);
355 Double_t rootRacine = sqrt(racine);
357 Double_t y0 = fCenterY + rootRacine;
358 Double_t y1 = fCenterY - rootRacine;
359 //Double_t diff0 = sqrt(pow(fFirstPoint[0]-xplane)+pow(fFirstPoint[1]-y0));
360 //Double_t diff1 = sqrt(pow(fFirstPoint[0]-xplane)+pow(fFirstPoint[1]-y1));
361 Double_t diff0 = fabs(y0-fFirstPoint[1]);
362 Double_t diff1 = fabs(y1-fFirstPoint[1]);
365 if(diff0<diff1) fPoint[1]=y0;
368 Double_t pointPhi0 = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
369 Double_t trackPhi0 = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
370 if(fabs(trackPhi0-pointPhi0)>pi){
371 if(trackPhi0<pointPhi0) trackPhi0 += 2*pi;
372 else pointPhi0 += 2*pi;
374 Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
375 fPoint[2] = fFirstPoint[2] + stot * fTanl;
377 fPointPsi = pointPhi0 - fQ * 0.5 * pi;
378 if(fPointPsi<0.) fPointPsi+= 2*pi;
379 fPointPsi = fmod(fPointPsi, 2*pi);
381 return IsPoint(kTRUE);
384 void AliL3Track::GetClosestPoint(AliL3Vertex *vertex,Double_t &closest_x,Double_t &closest_y,Double_t &closest_z)
386 //Calculate the point of closest approach to the vertex
389 Double_t xc = GetCenterX() - vertex->GetX();//Shift the center of curvature with respect to the vertex
390 Double_t yc = GetCenterY() - vertex->GetY();
392 Double_t dist_x1 = xc*(1 + GetRadius()/sqrt(xc*xc + yc*yc));
393 Double_t dist_y1 = yc*(1 + GetRadius()/sqrt(xc*xc + yc*yc));
394 Double_t distance1 = sqrt(dist_x1*dist_x1 + dist_y1*dist_y1);
396 Double_t dist_x2 = xc*(1 - GetRadius()/sqrt(xc*xc + yc*yc));
397 Double_t dist_y2 = yc*(1 - GetRadius()/sqrt(xc*xc + yc*yc));
398 Double_t distance2 = sqrt(dist_x2*dist_x2 + dist_y2*dist_y2);
400 //Choose the closest:
401 if(distance1 < distance2)
403 closest_x = dist_x1 + vertex->GetX();
404 closest_y = dist_y1 + vertex->GetY();
408 closest_x = dist_x2 + vertex->GetX();
409 closest_y = dist_y2 + vertex->GetY();
412 //Get the z coordinate:
413 Double_t angle1 = atan2((closest_y-GetCenterY()),(closest_x-GetCenterX()));
414 if(angle1 < 0) angle1 = angle1 + 2*AliL3Transform::Pi();
416 Double_t angle2 = atan2((GetFirstPointY()-GetCenterY()),(GetFirstPointX()-GetCenterX()));
417 if(angle2 < 0) angle2 = angle2 + 2*AliL3Transform::Pi();
419 Double_t diff_angle = angle1 - angle2;
420 diff_angle = fmod(diff_angle,2*AliL3Transform::Pi());
422 if((GetCharge()*diff_angle) < 0) diff_angle = diff_angle + GetCharge()*2*AliL3Transform::Pi();
423 Double_t s_tot = fabs(diff_angle)*GetRadius();
425 closest_z = GetFirstPointZ() - s_tot*GetTgl();