External instead of internal covariance matrix used
[u/mrichter/AliRoot.git] / HLT / src / AliL3Track.cxx
CommitLineData
3e87ef69 1// @(#) $Id$
6d4f1901 2
2d04dcbf 3// Author: Anders Vestbo <mailto:vestbo$fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>
3e87ef69 4//*-- Copyright &copy ALICE HLT Group
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
3e87ef69 14#if GCCVERSION == 3
15using namespace std;
16#endif
108615fc 17
3e87ef69 18/** \class AliL3Track
19//<pre>
2d04dcbf 20//_____________________________________________________________
21// AliL3Track
22//
23// Track base class
02cb36b2 24//Begin_Html
3e87ef69 25//<img src="track_coordinates.gif">
02cb36b2 26//End_Html
3e87ef69 27</pre>
28*/
0391971c 29
108615fc 30ClassImp(AliL3Track)
31
32Float_t AliL3Track::BFACT = 0.0029980;
108615fc 33Double_t AliL3Track::pi=3.14159265358979323846;
34
35AliL3Track::AliL3Track()
36{
37 //Constructor
38
39 fNHits = 0;
40 fMCid = -1;
41 fKappa=0;
42 fRadius=0;
43 fCenterX=0;
44 fCenterY=0;
45 ComesFromMainVertex(false);
46 fQ = 0;
47 fPhi0=0;
48 fPsi=0;
49 fR0=0;
50 fTanl=0;
51 fZ0=0;
52 fPt=0;
53 fLength=0;
54 fIsLocal=true;
55 fRowRange[0]=0;
56 fRowRange[1]=0;
3e87ef69 57 SetFirstPoint(0,0,0);
58 SetLastPoint(0,0,0);
68a27388 59 memset(fHitNumbers,0,159*sizeof(UInt_t));
108615fc 60}
61
62void AliL3Track::Set(AliL3Track *tpt){
63
3a735e00 64 SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
65 SetPhi0(tpt->GetPhi0());
66 SetKappa(tpt->GetKappa());
67 SetNHits(tpt->GetNHits());
68 SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
69 SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
70 SetPt(tpt->GetPt());
71 SetPsi(tpt->GetPsi());
72 SetTgl(tpt->GetTgl());
73 SetCharge(tpt->GetCharge());
74 SetHits(tpt->GetNHits(),(UInt_t *)tpt->GetHitNumbers());
4a0bee4e 75#ifdef do_mc
76 SetMCid(tpt->GetMCid());
77#endif
108615fc 78}
79
203925a9 80Int_t AliL3Track::Compare(const AliL3Track *track) const
81{
82 if(track->GetNHits() < GetNHits()) return 1;
83 if(track->GetNHits() > GetNHits()) return -1;
84 return 0;
85}
108615fc 86
87AliL3Track::~AliL3Track()
88{
203925a9 89 //Nothing to do
108615fc 90}
91
92Double_t AliL3Track::GetP() const
93{
203925a9 94 // Returns total momentum.
108615fc 95 return fabs(GetPt())*sqrt(1. + GetTgl()*GetTgl());
108615fc 96}
97
98Double_t AliL3Track::GetPseudoRapidity() const
99{
100 return 0.5 * log((GetP() + GetPz()) / (GetP() - GetPz()));
101}
eeddc64d 102
203925a9 103/*
108615fc 104Double_t AliL3Track::GetEta() const
105{
106 return GetPseudoRapidity();
107}
203925a9 108*/
eeddc64d 109
108615fc 110Double_t AliL3Track::GetRapidity() const
111{
112 Double_t m_pi = 0.13957;
113 return 0.5 * log((m_pi + GetPz()) / (m_pi - GetPz()));
114}
115
203925a9 116void AliL3Track::Rotate(Int_t slice,Bool_t tolocal)
0391971c 117{
0391971c 118 //Rotate track to global parameters
203925a9 119 //If flag tolocal is set, the track is rotated
120 //to local coordinates.
0391971c 121
0391971c 122
123 Float_t psi[1] = {GetPsi()};
203925a9 124 if(!tolocal)
494fad94 125 AliL3Transform::Local2GlobalAngle(psi,slice);
203925a9 126 else
494fad94 127 AliL3Transform::Global2LocalAngle(psi,slice);
0391971c 128 SetPsi(psi[0]);
129 Float_t first[3];
130 first[0] = GetFirstPointX();
131 first[1] = GetFirstPointY();
132 first[2] = GetFirstPointZ();
203925a9 133 if(!tolocal)
494fad94 134 AliL3Transform::Local2Global(first,slice);
203925a9 135 else
494fad94 136 AliL3Transform::Global2Local(first,slice,kTRUE);
203925a9 137
0391971c 138 SetFirstPoint(first[0],first[1],first[2]);
139 Float_t last[3];
140 last[0] = GetLastPointX();
141 last[1] = GetLastPointY();
142 last[2] = GetLastPointZ();
203925a9 143 if(!tolocal)
494fad94 144 AliL3Transform::Local2Global(last,slice);
203925a9 145 else
494fad94 146 AliL3Transform::Global2Local(last,slice,kTRUE);
0391971c 147 SetLastPoint(last[0],last[1],last[2]);
203925a9 148
6d4f1901 149 Float_t center[3] = {GetCenterX(),GetCenterY(),0};
150 if(!tolocal)
494fad94 151 AliL3Transform::Local2Global(center,slice);
6d4f1901 152 else
494fad94 153 AliL3Transform::Global2Local(center,slice,kTRUE);
6d4f1901 154 SetCenterX(center[0]);
155 SetCenterY(center[1]);
156
3e87ef69 157 SetPhi0(atan2(fFirstPoint[1],fFirstPoint[0]));
158 SetR0(sqrt(fFirstPoint[0]*fFirstPoint[0]+fFirstPoint[1]*fFirstPoint[1]));
159
203925a9 160 if(!tolocal)
161 fIsLocal=kFALSE;
162 else
163 fIsLocal=kTRUE;
0391971c 164}
165
108615fc 166void AliL3Track::CalculateHelix(){
eeddc64d 167 //Calculate Radius, CenterX and CenterY from Psi, X0, Y0
108615fc 168 //
169
ef79795d 170 fRadius = fPt / (BFACT*AliL3Transform::GetBField());
3ceb3fe1 171 if(fRadius) fKappa = -fQ*1./fRadius;
108615fc 172 else fRadius = 999999; //just zero
173 Double_t trackPhi0 = fPsi + fQ *0.5 * pi;
174
175 fCenterX = fFirstPoint[0] - fRadius * cos(trackPhi0);
176 fCenterY = fFirstPoint[1] - fRadius * sin(trackPhi0);
3e87ef69 177
178 SetPhi0(atan2(fFirstPoint[1],fFirstPoint[0]));
179 SetR0(sqrt(fFirstPoint[0]*fFirstPoint[0]+fFirstPoint[1]*fFirstPoint[1]));
108615fc 180}
181
3e87ef69 182Double_t AliL3Track::GetCrossingAngle(Int_t padrow,Int_t slice)
0391971c 183{
184 //Calculate the crossing angle between track and given padrow.
0391971c 185 //Take the dot product of the tangent vector of the track, and
186 //vector perpendicular to the padrow.
dab230b2 187 //In order to do this, we need the tangent vector to the track at the
188 //point. This is done by rotating the radius vector by 90 degrees;
189 //rotation matrix: ( 0 1 )
190 // ( -1 0 )
3e87ef69 191
192 Float_t angle=0;//Angle perpendicular to the padrow in local coordinates
193 if(slice>=0)//Global coordinates
194 {
195 AliL3Transform::Local2GlobalAngle(&angle,slice);
196 if(!CalculateReferencePoint(angle,AliL3Transform::Row2X(padrow)))
197 cerr<<"AliL3Track::GetCrossingAngle : Track does not cross line in slice "<<slice<<" row "<<padrow<<endl;
198 }
199 else //should be in local coordinates
200 {
201 Float_t xyz[3];
202 GetCrossingPoint(padrow,xyz);
203 fPoint[0] = xyz[0];
204 fPoint[1] = xyz[1];
205 fPoint[2] = xyz[2];
206 }
207
0391971c 208 Double_t tangent[2];
dab230b2 209
3e87ef69 210 tangent[0] = (fPoint[1] - GetCenterY())/GetRadius();
211 tangent[1] = -1.*(fPoint[0] - GetCenterX())/GetRadius();
212
213 Double_t perp_padrow[2] = {cos(angle),sin(angle)};
23f26160 214
0391971c 215 Double_t cos_beta = fabs(tangent[0]*perp_padrow[0] + tangent[1]*perp_padrow[1]);
23f26160 216 if(cos_beta > 1) cos_beta=1;
0391971c 217 return acos(cos_beta);
0391971c 218}
219
3e87ef69 220Bool_t AliL3Track::GetCrossingPoint(Int_t padrow,Float_t *xyz)
0391971c 221{
222 //Assumes the track is given in local coordinates
3e87ef69 223
0391971c 224 if(!IsLocal())
225 {
3e87ef69 226 cerr<<"GetCrossingPoint: Track is given on global coordinates"<<endl;
0391971c 227 return false;
228 }
229
494fad94 230 Double_t xHit = AliL3Transform::Row2X(padrow);
0391971c 231
232 xyz[0] = xHit;
233 Double_t aa = (xHit - GetCenterX())*(xHit - GetCenterX());
234 Double_t r2 = GetRadius()*GetRadius();
235 if(aa > r2)
236 return false;
237
238 Double_t aa2 = sqrt(r2 - aa);
239 Double_t y1 = GetCenterY() + aa2;
240 Double_t y2 = GetCenterY() - aa2;
241 xyz[1] = y1;
242 if(fabs(y2) < fabs(y1)) xyz[1] = y2;
3e87ef69 243
0391971c 244 Double_t yHit = xyz[1];
245 Double_t angle1 = atan2((yHit - GetCenterY()),(xHit - GetCenterX()));
9ca67380 246 if(angle1 < 0) angle1 += 2.*AliL3Transform::Pi();
0391971c 247 Double_t angle2 = atan2((GetFirstPointY() - GetCenterY()),(GetFirstPointX() - GetCenterX()));
9ca67380 248 if(angle2 < 0) angle2 += 2.*AliL3Transform::Pi();
0391971c 249 Double_t diff_angle = angle1 - angle2;
9ca67380 250 diff_angle = fmod(diff_angle,2*AliL3Transform::Pi());
251 if((GetCharge()*diff_angle) > 0) diff_angle = diff_angle - GetCharge()*2.*AliL3Transform::Pi();
0391971c 252 Double_t s_tot = fabs(diff_angle)*GetRadius();
253 Double_t zHit = GetFirstPointZ() + s_tot*GetTgl();
254 xyz[2] = zHit;
3e87ef69 255
0391971c 256 return true;
3e87ef69 257
0391971c 258}
259
260
6d4f1901 261Bool_t AliL3Track::CalculateReferencePoint(Double_t angle,Double_t radius){
9ca67380 262 // Global coordinate: crossing point with y = ax+ b; a=tan(angle-AliL3Transform::Pi()/2);
108615fc 263 //
eeddc64d 264 const Double_t rr=radius;//132; //position of reference plane
265 const Double_t xr = cos(angle) * rr;
266 const Double_t yr = sin(angle) * rr;
6d4f1901 267
108615fc 268 Double_t a = tan(angle-pi/2);
269 Double_t b = yr - a * xr;
270
271 Double_t pp=(fCenterX+a*fCenterY-a*b)/(1+pow(a,2));
272 Double_t qq=(pow(fCenterX,2)+pow(fCenterY,2)-2*fCenterY*b+pow(b,2)-pow(fRadius,2))/(1+pow(a,2));
273
274 Double_t racine = pp*pp-qq;
275 if(racine<0) return IsPoint(kFALSE); //no Point
276
277 Double_t rootRacine = sqrt(racine);
278 Double_t x0 = pp+rootRacine;
279 Double_t x1 = pp-rootRacine;
280 Double_t y0 = a*x0 + b;
281 Double_t y1 = a*x1 + b;
282
283 Double_t diff0 = sqrt(pow(x0-xr,2)+pow(y0-yr,2));
284 Double_t diff1 = sqrt(pow(x1-xr,2)+pow(y1-yr,2));
285
286 if(diff0<diff1){
287 fPoint[0]=x0;
288 fPoint[1]=y0;
289 }
290 else{
291 fPoint[0]=x1;
292 fPoint[1]=y1;
293 }
294
295 Double_t pointPhi0 = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
296 Double_t trackPhi0 = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
297 if(fabs(trackPhi0-pointPhi0)>pi){
298 if(trackPhi0<pointPhi0) trackPhi0 += 2*pi;
299 else pointPhi0 += 2*pi;
300 }
301 Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
302 fPoint[2] = fFirstPoint[2] + stot * fTanl;
303
304 fPointPsi = pointPhi0 - fQ * 0.5 * pi;
305 if(fPointPsi<0.) fPointPsi+= 2*pi;
306 fPointPsi = fmod(fPointPsi, 2*pi);
307
308 return IsPoint(kTRUE);
309}
310
311Bool_t AliL3Track::CalculateEdgePoint(Double_t angle){
312 // Global coordinate: crossing point with y = ax; a=tan(angle);
313 //
4a0bee4e 314 Double_t rmin=AliL3Transform::Row2X(AliL3Transform::GetFirstRow(-1)); //min Radius of TPC
315 Double_t rmax=AliL3Transform::Row2X(AliL3Transform::GetLastRow(-1)); //max Radius of TPC
108615fc 316
317 Double_t a = tan(angle);
318 Double_t pp=(fCenterX+a*fCenterY)/(1+pow(a,2));
319 Double_t qq=(pow(fCenterX,2)+pow(fCenterY,2)-pow(fRadius,2))/(1+pow(a,2));
320 Double_t racine = pp*pp-qq;
321 if(racine<0) return IsPoint(kFALSE); //no Point
322 Double_t rootRacine = sqrt(racine);
323 Double_t x0 = pp+rootRacine;
324 Double_t x1 = pp-rootRacine;
325 Double_t y0 = a*x0;
326 Double_t y1 = a*x1;
327
328 Double_t r0 = sqrt(pow(x0,2)+pow(y0,2));
329 Double_t r1 = sqrt(pow(x1,2)+pow(y1,2));
330 //find the right crossing point:
331 //inside the TPC modules
332 Bool_t ok0 = kFALSE;
333 Bool_t ok1 = kFALSE;
472d9e24 334
108615fc 335 if(r0>rmin&&r0<rmax){
336 Double_t da=atan2(y0,x0);
472d9e24 337 if(da<0) da+=2*pi;
108615fc 338 if(fabs(da-angle)<0.5)
339 ok0 = kTRUE;
340 }
341 if(r1>rmin&&r1<rmax){
472d9e24 342 Double_t da=atan2(y1,x1);
343 if(da<0) da+=2*pi;
108615fc 344 if(fabs(da-angle)<0.5)
345 ok1 = kTRUE;
346 }
347 if(!(ok0||ok1)) return IsPoint(kFALSE); //no Point
348
349 if(ok0&&ok1){
350 Double_t diff0 = sqrt(pow(fFirstPoint[0]-x0,2)+pow(fFirstPoint[1]-y0,2));
351 Double_t diff1 = sqrt(pow(fFirstPoint[0]-x1,2)+pow(fFirstPoint[1]-y1,2));
352 if(diff0<diff1) ok1 = kFALSE; //use ok0
353 else ok0 = kFALSE; //use ok1
354 }
355 if(ok0){fPoint[0]=x0; fPoint[1]=y0;}
356 else {fPoint[0]=x1; fPoint[1]=y1;}
357
358 Double_t pointPhi0 = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
359 Double_t trackPhi0 = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
360 if(fabs(trackPhi0-pointPhi0)>pi){
361 if(trackPhi0<pointPhi0) trackPhi0 += 2*pi;
362 else pointPhi0 += 2*pi;
363 }
364 Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
365 fPoint[2] = fFirstPoint[2] + stot * fTanl;
366
367 fPointPsi = pointPhi0 - fQ * 0.5 * pi;
368 if(fPointPsi<0.) fPointPsi+= 2*pi;
369 fPointPsi = fmod(fPointPsi, 2*pi);
370
371 return IsPoint(kTRUE);
372}
373
374Bool_t AliL3Track::CalculatePoint(Double_t xplane){
375 // Local coordinate: crossing point with x plane
376 //
377 Double_t racine = pow(fRadius,2)-pow(xplane-fCenterX,2);
378 if(racine<0) return IsPoint(kFALSE);
379 Double_t rootRacine = sqrt(racine);
380
381 Double_t y0 = fCenterY + rootRacine;
382 Double_t y1 = fCenterY - rootRacine;
383 //Double_t diff0 = sqrt(pow(fFirstPoint[0]-xplane)+pow(fFirstPoint[1]-y0));
384 //Double_t diff1 = sqrt(pow(fFirstPoint[0]-xplane)+pow(fFirstPoint[1]-y1));
385 Double_t diff0 = fabs(y0-fFirstPoint[1]);
386 Double_t diff1 = fabs(y1-fFirstPoint[1]);
387
388 fPoint[0]=xplane;
389 if(diff0<diff1) fPoint[1]=y0;
390 else fPoint[1]=y1;
391
392 Double_t pointPhi0 = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
393 Double_t trackPhi0 = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
394 if(fabs(trackPhi0-pointPhi0)>pi){
395 if(trackPhi0<pointPhi0) trackPhi0 += 2*pi;
396 else pointPhi0 += 2*pi;
397 }
398 Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
399 fPoint[2] = fFirstPoint[2] + stot * fTanl;
400
401 fPointPsi = pointPhi0 - fQ * 0.5 * pi;
402 if(fPointPsi<0.) fPointPsi+= 2*pi;
403 fPointPsi = fmod(fPointPsi, 2*pi);
404
405 return IsPoint(kTRUE);
406}
407
3e87ef69 408void AliL3Track::UpdateToFirstPoint()
409{
410 //Update track parameters to the innermost point on the track.
1f1942b8 411 //This means that the parameters of the track will be given in the point
412 //of closest approach to the first innermost point, i.e. the point
413 //lying on the track fit (and not the coordinates of the innermost point itself).
414 //This function assumes that fFirstPoint is already set to the coordinates of the innermost
415 //assigned cluster.
416 //
417 //During the helix-fit, the first point on the track is set to the coordinates
418 //of the innermost assigned cluster. This may be ok, if you just want a fast
419 //estimate of the "global" track parameters; such as the momentum etc.
420 //However, if you later on want to do more precise local calculations, such
421 //as impact parameter, residuals etc, you need to give the track parameters
422 //according to the actual fit.
3e87ef69 423
1f1942b8 424 Double_t xc = GetCenterX() - GetFirstPointX();
425 Double_t yc = GetCenterY() - GetFirstPointY();
3e87ef69 426
1f1942b8 427 Double_t dist_x1 = xc*(1 + GetRadius()/sqrt(xc*xc + yc*yc));
428 Double_t dist_y1 = yc*(1 + GetRadius()/sqrt(xc*xc + yc*yc));
429 Double_t distance1 = sqrt(dist_x1*dist_x1 + dist_y1*dist_y1);
3e87ef69 430
1f1942b8 431 Double_t dist_x2 = xc*(1 - GetRadius()/sqrt(xc*xc + yc*yc));
432 Double_t dist_y2 = yc*(1 - GetRadius()/sqrt(xc*xc + yc*yc));
433 Double_t distance2 = sqrt(dist_x2*dist_x2 + dist_y2*dist_y2);
3e87ef69 434
1f1942b8 435 //Choose the closest:
436 Double_t point[2];
437 if(distance1 < distance2)
438 {
439 point[0] = dist_x1 + GetFirstPointX();
440 point[1] = dist_y1 + GetFirstPointY();
441 }
442 else
443 {
444 point[0] = dist_x2 + GetFirstPointX();
445 point[1] = dist_y2 + GetFirstPointY();
446 }
447
448 Double_t pointpsi = atan2(point[1]-GetCenterY(),point[0]-GetCenterX());
449 pointpsi -= GetCharge()*0.5*AliL3Transform::Pi();
450 if(pointpsi < 0) pointpsi += 2*AliL3Transform::Pi();
3e87ef69 451
1f1942b8 452 //Update the track parameters
453 SetR0(sqrt(point[0]*point[0]+point[1]*point[1]));
454 SetPhi0(atan2(point[1],point[0]));
455 SetFirstPoint(point[0],point[1],GetZ0());
456 SetPsi(pointpsi);
3e87ef69 457
3e87ef69 458}
459
6d4f1901 460void AliL3Track::GetClosestPoint(AliL3Vertex *vertex,Double_t &closest_x,Double_t &closest_y,Double_t &closest_z)
461{
462 //Calculate the point of closest approach to the vertex
1f1942b8 463 //This function calculates the minimum distance from the helix to the vertex, and choose
464 //the corresponding point lying on the helix as the point of closest approach.
6d4f1901 465
1f1942b8 466 Double_t xc = GetCenterX() - vertex->GetX();
6d4f1901 467 Double_t yc = GetCenterY() - vertex->GetY();
468
469 Double_t dist_x1 = xc*(1 + GetRadius()/sqrt(xc*xc + yc*yc));
470 Double_t dist_y1 = yc*(1 + GetRadius()/sqrt(xc*xc + yc*yc));
471 Double_t distance1 = sqrt(dist_x1*dist_x1 + dist_y1*dist_y1);
472
473 Double_t dist_x2 = xc*(1 - GetRadius()/sqrt(xc*xc + yc*yc));
474 Double_t dist_y2 = yc*(1 - GetRadius()/sqrt(xc*xc + yc*yc));
475 Double_t distance2 = sqrt(dist_x2*dist_x2 + dist_y2*dist_y2);
476
477 //Choose the closest:
478 if(distance1 < distance2)
479 {
480 closest_x = dist_x1 + vertex->GetX();
481 closest_y = dist_y1 + vertex->GetY();
482 }
483 else
484 {
485 closest_x = dist_x2 + vertex->GetX();
486 closest_y = dist_y2 + vertex->GetY();
487 }
488
489 //Get the z coordinate:
490 Double_t angle1 = atan2((closest_y-GetCenterY()),(closest_x-GetCenterX()));
9ca67380 491 if(angle1 < 0) angle1 = angle1 + 2*AliL3Transform::Pi();
6d4f1901 492
493 Double_t angle2 = atan2((GetFirstPointY()-GetCenterY()),(GetFirstPointX()-GetCenterX()));
9ca67380 494 if(angle2 < 0) angle2 = angle2 + 2*AliL3Transform::Pi();
6d4f1901 495
496 Double_t diff_angle = angle1 - angle2;
9ca67380 497 diff_angle = fmod(diff_angle,2*AliL3Transform::Pi());
6d4f1901 498
9ca67380 499 if((GetCharge()*diff_angle) < 0) diff_angle = diff_angle + GetCharge()*2*AliL3Transform::Pi();
6d4f1901 500 Double_t s_tot = fabs(diff_angle)*GetRadius();
501
502 closest_z = GetFirstPointZ() - s_tot*GetTgl();
503}