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