]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCTrack.cxx
added sample macro for TPC reconstruction
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCTrack.cxx
CommitLineData
a6c02c85 1// @(#) $Id$
4aa41877 2// Original: AliHLTTrack.cxx,v 1.32 2005/06/14 10:55:21 cvetan
a6c02c85 3
3cde846d 4/**************************************************************************
d53596be 5 * This file is property of and copyright by the ALICE HLT Project *
6 * ALICE Experiment at CERN, All rights reserved. *
3cde846d 7 * *
d53596be 8 * Primary Authors: Anders Vestbo, Uli Frankenfeld, maintained by *
9 * Matthias Richter <Matthias.Richter@ift.uib.no> *
10 * for The ALICE HLT Project. *
3cde846d 11 * *
12 * Permission to use, copy, modify and distribute this software and its *
13 * documentation strictly for non-commercial purposes is hereby granted *
14 * without fee, provided that the above copyright notice appears in all *
15 * copies and that both the copyright notice and this permission notice *
16 * appear in the supporting documentation. The authors make no claims *
17 * about the suitability of this software for any purpose. It is *
18 * provided "as is" without express or implied warranty. *
19 **************************************************************************/
20
21/** @file AliHLTTPCTrack.cxx
4fdaad1e 22 @author Anders Vestbo, Uli Frankenfeld, maintained by Matthias Richter
3cde846d 23 @date
24 @brief HLT TPC track implementation (conformal mapping) */
25
a6c02c85 26
a6c02c85 27#include "AliHLTTPCLogging.h"
28#include "AliHLTTPCTrack.h"
29#include "AliHLTTPCTransform.h"
30#include "AliHLTTPCVertex.h"
31#include "AliHLTTPCSpacePointData.h"
32
33#if __GNUC__ >= 3
34using namespace std;
35#endif
36
a6c02c85 37ClassImp(AliHLTTPCTrack)
38
39
40AliHLTTPCTrack::AliHLTTPCTrack()
4fdaad1e 41 :
42 fNHits(0),
43 fMCid(-1),
44 fKappa(0),
45 fRadius(0),
46 fCenterX(0),
47 fCenterY(0),
48 fFromMainVertex(0),
2a083ac4 49 fSector(0),
4fdaad1e 50 fQ(0),
2a083ac4 51
4fdaad1e 52 fTanl(0),
2a083ac4 53 fPsi(0),
4fdaad1e 54 fPt(0),
55 fLength(0),
4fdaad1e 56
4fdaad1e 57 fPterr(0),
58 fPsierr(0),
59 fZ0err(0),
60 fTanlerr(0),
2a083ac4 61
62 fPhi0(0),
63 fR0(0),
64 fZ0(0),
65
4fdaad1e 66 // fPoint({0,0,0}),
2a083ac4 67 fPointPsi(0),
68
69 fIsPoint(0),
70 fIsLocal(true),
71 // fRowRange({0,0}),
72
73 fPID(0)
a6c02c85 74{
75 //Constructor
a6c02c85 76 fRowRange[0]=0;
77 fRowRange[1]=0;
4fdaad1e 78 fPoint[0]=0;
79 fPoint[1]=0;
80 fPoint[2]=0;
81
a6c02c85 82 SetFirstPoint(0,0,0);
83 SetLastPoint(0,0,0);
84 memset(fHitNumbers,0,159*sizeof(UInt_t));
a6c02c85 85}
86
3cde846d 87void AliHLTTPCTrack::Copy(AliHLTTPCTrack *tpt)
a6c02c85 88{
89 //setter
90 SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
91 SetPhi0(tpt->GetPhi0());
92 SetKappa(tpt->GetKappa());
93 SetNHits(tpt->GetNHits());
94 SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
95 SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
96 SetPt(tpt->GetPt());
97 SetPsi(tpt->GetPsi());
98 SetTgl(tpt->GetTgl());
99 SetPterr(tpt->GetPterr());
100 SetPsierr(tpt->GetPsierr());
101 SetTglerr(tpt->GetTglerr());
102 SetCharge(tpt->GetCharge());
103 SetHits(tpt->GetNHits(),(UInt_t *)tpt->GetHitNumbers());
104#ifdef do_mc
105 SetMCid(tpt->GetMCid());
106#endif
107 SetPID(tpt->GetPID());
108 SetSector(tpt->GetSector());
109}
110
111Int_t AliHLTTPCTrack::Compare(const AliHLTTPCTrack *track) const
112{
113 // compare tracks
114 if(track->GetNHits() < GetNHits()) return 1;
115 if(track->GetNHits() > GetNHits()) return -1;
116 return 0;
117}
118
119AliHLTTPCTrack::~AliHLTTPCTrack()
120{
121 //Nothing to do
122}
123
124Double_t AliHLTTPCTrack::GetP() const
125{
126 // Returns total momentum.
127 return fabs(GetPt())*sqrt(1. + GetTgl()*GetTgl());
128}
129
130Double_t AliHLTTPCTrack::GetPseudoRapidity() const
131{ //get pseudo rap
132 return 0.5 * log((GetP() + GetPz()) / (GetP() - GetPz()));
133}
134
135/*
136Double_t AliHLTTPCTrack::GetEta() const
137{
138 return GetPseudoRapidity();
139}
140*/
141
142Double_t AliHLTTPCTrack::GetRapidity() const
143{
144 //get rap
145 const Double_t kmpi = 0.13957;
146 return 0.5 * log((kmpi + GetPz()) / (kmpi - GetPz()));
147}
148
149void AliHLTTPCTrack::Rotate(Int_t slice,Bool_t tolocal)
150{
151 //Rotate track to global parameters
152 //If flag tolocal is set, the track is rotated
153 //to local coordinates.
154
155 Float_t psi[1] = {GetPsi()};
156 if(!tolocal)
157 AliHLTTPCTransform::Local2GlobalAngle(psi,slice);
158 else
159 AliHLTTPCTransform::Global2LocalAngle(psi,slice);
160 SetPsi(psi[0]);
161 Float_t first[3];
162 first[0] = GetFirstPointX();
163 first[1] = GetFirstPointY();
164 first[2] = GetFirstPointZ();
165 if(!tolocal)
166 AliHLTTPCTransform::Local2Global(first,slice);
167 else
168 AliHLTTPCTransform::Global2LocHLT(first,slice);
169 //AliHLTTPCTransform::Global2Local(first,slice,kTRUE);
170
171 SetFirstPoint(first[0],first[1],first[2]);
172 Float_t last[3];
173 last[0] = GetLastPointX();
174 last[1] = GetLastPointY();
175 last[2] = GetLastPointZ();
176 if(!tolocal)
177 AliHLTTPCTransform::Local2Global(last,slice);
178 else
179 AliHLTTPCTransform::Global2LocHLT(last,slice);
180 //AliHLTTPCTransform::Global2Local(last,slice,kTRUE);
181 SetLastPoint(last[0],last[1],last[2]);
182
183 Float_t center[3] = {GetCenterX(),GetCenterY(),0};
184 if(!tolocal)
185 AliHLTTPCTransform::Local2Global(center,slice);
186 else
187 AliHLTTPCTransform::Global2LocHLT(center,slice);
188 //AliHLTTPCTransform::Global2Local(center,slice,kTRUE);
189 SetCenterX(center[0]);
190 SetCenterY(center[1]);
191
192 SetPhi0(atan2(fFirstPoint[1],fFirstPoint[0]));
193 SetR0(sqrt(fFirstPoint[0]*fFirstPoint[0]+fFirstPoint[1]*fFirstPoint[1]));
194
195 if(!tolocal)
196 fIsLocal=kFALSE;
197 else
198 fIsLocal=kTRUE;
199}
200
201void AliHLTTPCTrack::CalculateHelix()
202{
4fdaad1e 203 // fit assigned clusters to helix
437e8e54 204 // for straight line fit
205 if (AliHLTTPCTransform::GetBFieldValue() == 0.0 ){
206 fRadius = 999999; //just zero
207
208 SetPhi0(atan2(fFirstPoint[1],fFirstPoint[0]));
209 SetR0(sqrt(fFirstPoint[0]*fFirstPoint[0]+fFirstPoint[1]*fFirstPoint[1]));
210 }
211 // for helix fit
212 else {
213 //Calculate Radius, CenterX and CenterY from Psi, X0, Y0
214 fRadius = fPt / (AliHLTTPCTransform::GetBFieldValue());
215 if(fRadius) fKappa = -fQ*1./fRadius;
216 else fRadius = 999999; //just zero
217 Double_t trackPhi0 = fPsi + fQ * AliHLTTPCTransform::PiHalf();
218
219 fCenterX = fFirstPoint[0] - fRadius * cos(trackPhi0);
220 fCenterY = fFirstPoint[1] - fRadius * sin(trackPhi0);
221
222 SetPhi0(atan2(fFirstPoint[1],fFirstPoint[0]));
223 SetR0(sqrt(fFirstPoint[0]*fFirstPoint[0]+fFirstPoint[1]*fFirstPoint[1]));
224 }
a6c02c85 225}
226
227Double_t AliHLTTPCTrack::GetCrossingAngle(Int_t padrow,Int_t slice)
228{
229 //Calculate the crossing angle between track and given padrow.
230 //Take the dot product of the tangent vector of the track, and
231 //vector perpendicular to the padrow.
232 //In order to do this, we need the tangent vector to the track at the
233 //point. This is done by rotating the radius vector by 90 degrees;
234 //rotation matrix: ( 0 1 )
235 // ( -1 0 )
236
237 Float_t angle=0;//Angle perpendicular to the padrow in local coordinates
238 if(slice>=0)//Global coordinates
239 {
240 AliHLTTPCTransform::Local2GlobalAngle(&angle,slice);
241 if(!CalculateReferencePoint(angle,AliHLTTPCTransform::Row2X(padrow)))
242 cerr<<"AliHLTTPCTrack::GetCrossingAngle : Track does not cross line in slice "<<slice<<" row "<<padrow<<endl;
243 }
244 else //should be in local coordinates
245 {
246 Float_t xyz[3];
247 GetCrossingPoint(padrow,xyz);
248 fPoint[0] = xyz[0];
249 fPoint[1] = xyz[1];
250 fPoint[2] = xyz[2];
251 }
252
253 Double_t tangent[2];
254
255 tangent[0] = (fPoint[1] - GetCenterY())/GetRadius();
256 tangent[1] = -1.*(fPoint[0] - GetCenterX())/GetRadius();
257
258 Double_t perppadrow[2] = {cos(angle),sin(angle)};
259 Double_t cosbeta = fabs(tangent[0]*perppadrow[0] + tangent[1]*perppadrow[1]);
260 if(cosbeta > 1) cosbeta=1;
261 return acos(cosbeta);
262}
263
264Bool_t AliHLTTPCTrack::GetCrossingPoint(Int_t padrow,Float_t *xyz)
265{
266 //Assumes the track is given in local coordinates
a6c02c85 267 if(!IsLocal())
268 {
269 cerr<<"GetCrossingPoint: Track is given on global coordinates"<<endl;
270 return false;
271 }
272
273 Double_t xHit = AliHLTTPCTransform::Row2X(padrow);
274
db16520a 275//if (xHit < xyz[0]){
276// LOG(AliHLTTPCLog::kError,"AliHLTTPCTRACK::GetCrossingPoint","")<< "Track doesn't cross padrow "
277// << padrow <<"(x=" << xHit << "). Smallest x=" << xyz[0] << ENDLOG;
278// return false;
279//}
738c049f 280
db16520a 281 // for straight line fit
437e8e54 282 if (AliHLTTPCTransform::GetBFieldValue() == 0.0 ){
283
284 Double_t yHit = GetFirstPointY() + (Double_t) tan( GetPsi() ) * (xHit - GetFirstPointX());
285
286 Double_t s = (xHit - GetFirstPointX())*(xHit - GetFirstPointX()) + (yHit - GetFirstPointY())*(yHit - GetFirstPointY());
287
288 Double_t zHit = GetFirstPointZ() + s * GetTgl();
289
290 xyz[0] = xHit;
291 xyz[1] = yHit;
292 xyz[2] = zHit;
293 }
294 // for helix fit
db16520a 295 else {
437e8e54 296 xyz[0] = xHit;
297 Double_t aa = (xHit - GetCenterX())*(xHit - GetCenterX());
298 Double_t r2 = GetRadius()*GetRadius();
299 if(aa > r2)
300 return false;
301
302 Double_t aa2 = sqrt(r2 - aa);
303 Double_t y1 = GetCenterY() + aa2;
304 Double_t y2 = GetCenterY() - aa2;
305 xyz[1] = y1;
306 if(fabs(y2) < fabs(y1)) xyz[1] = y2;
307
308 Double_t yHit = xyz[1];
309 Double_t angle1 = atan2((yHit - GetCenterY()),(xHit - GetCenterX()));
310 if(angle1 < 0) angle1 += 2.*AliHLTTPCTransform::Pi();
311 Double_t angle2 = atan2((GetFirstPointY() - GetCenterY()),(GetFirstPointX() - GetCenterX()));
312 if(angle2 < 0) angle2 += AliHLTTPCTransform::TwoPi();
313
314 Double_t diffangle = angle1 - angle2;
315 diffangle = fmod(diffangle,AliHLTTPCTransform::TwoPi());
316 if((GetCharge()*diffangle) > 0) diffangle = diffangle - GetCharge()*AliHLTTPCTransform::TwoPi();
317
318 Double_t stot = fabs(diffangle)*GetRadius();
319
320 Double_t zHit = GetFirstPointZ() + stot*GetTgl();
321
322 xyz[2] = zHit;
db16520a 323 }
437e8e54 324
325 return true;
a6c02c85 326}
327
328Bool_t AliHLTTPCTrack::CalculateReferencePoint(Double_t angle,Double_t radius)
329{
330 // Global coordinate: crossing point with y = ax+ b;
331 // a=tan(angle-AliHLTTPCTransform::PiHalf());
332 //
333 const Double_t krr=radius; //position of reference plane
334 const Double_t kxr = cos(angle) * krr;
335 const Double_t kyr = sin(angle) * krr;
336
337 Double_t a = tan(angle-AliHLTTPCTransform::PiHalf());
338 Double_t b = kyr - a * kxr;
339
340 Double_t pp=(fCenterX+a*fCenterY-a*b)/(1+pow(a,2));
341 Double_t qq=(pow(fCenterX,2)+pow(fCenterY,2)-2*fCenterY*b+pow(b,2)-pow(fRadius,2))/(1+pow(a,2));
342
343 Double_t racine = pp*pp-qq;
344 if(racine<0) return IsPoint(kFALSE); //no Point
345
346 Double_t rootRacine = sqrt(racine);
347 Double_t x0 = pp+rootRacine;
348 Double_t x1 = pp-rootRacine;
349 Double_t y0 = a*x0 + b;
350 Double_t y1 = a*x1 + b;
351
352 Double_t diff0 = sqrt(pow(x0-kxr,2)+pow(y0-kyr,2));
353 Double_t diff1 = sqrt(pow(x1-kxr,2)+pow(y1-kyr,2));
354
355 if(diff0<diff1){
356 fPoint[0]=x0;
357 fPoint[1]=y0;
358 }
359 else{
360 fPoint[0]=x1;
361 fPoint[1]=y1;
362 }
363
364 Double_t pointPhi0 = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
365 Double_t trackPhi0 = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
366 if(fabs(trackPhi0-pointPhi0)>AliHLTTPCTransform::Pi()){
367 if(trackPhi0<pointPhi0) trackPhi0 += AliHLTTPCTransform::TwoPi();
368 else pointPhi0 += AliHLTTPCTransform::TwoPi();
369 }
370 Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
371 fPoint[2] = fFirstPoint[2] + stot * fTanl;
372
373 fPointPsi = pointPhi0 - fQ * AliHLTTPCTransform::PiHalf();
374 if(fPointPsi<0.) fPointPsi+= AliHLTTPCTransform::TwoPi();
375 fPointPsi = fmod(fPointPsi, AliHLTTPCTransform::TwoPi());
376
377 return IsPoint(kTRUE);
378}
379
380Bool_t AliHLTTPCTrack::CalculateEdgePoint(Double_t angle)
381{
382 // Global coordinate: crossing point with y = ax; a=tan(angle);
383 //
384 Double_t rmin=AliHLTTPCTransform::Row2X(AliHLTTPCTransform::GetFirstRow(-1)); //min Radius of TPC
385 Double_t rmax=AliHLTTPCTransform::Row2X(AliHLTTPCTransform::GetLastRow(-1)); //max Radius of TPC
386
387 Double_t a = tan(angle);
388 Double_t pp=(fCenterX+a*fCenterY)/(1+pow(a,2));
389 Double_t qq=(pow(fCenterX,2)+pow(fCenterY,2)-pow(fRadius,2))/(1+pow(a,2));
390 Double_t racine = pp*pp-qq;
391 if(racine<0) return IsPoint(kFALSE); //no Point
392 Double_t rootRacine = sqrt(racine);
393 Double_t x0 = pp+rootRacine;
394 Double_t x1 = pp-rootRacine;
395 Double_t y0 = a*x0;
396 Double_t y1 = a*x1;
397
398 Double_t r0 = sqrt(pow(x0,2)+pow(y0,2));
399 Double_t r1 = sqrt(pow(x1,2)+pow(y1,2));
400 //find the right crossing point:
401 //inside the TPC modules
402 Bool_t ok0 = kFALSE;
403 Bool_t ok1 = kFALSE;
404
405 if(r0>rmin&&r0<rmax){
406 Double_t da=atan2(y0,x0);
407 if(da<0) da+=AliHLTTPCTransform::TwoPi();
408 if(fabs(da-angle)<0.5)
409 ok0 = kTRUE;
410 }
411 if(r1>rmin&&r1<rmax){
412 Double_t da=atan2(y1,x1);
413 if(da<0) da+=AliHLTTPCTransform::TwoPi();
414 if(fabs(da-angle)<0.5)
415 ok1 = kTRUE;
416 }
417 if(!(ok0||ok1)) return IsPoint(kFALSE); //no Point
418
419 if(ok0&&ok1){
420 Double_t diff0 = sqrt(pow(fFirstPoint[0]-x0,2)+pow(fFirstPoint[1]-y0,2));
421 Double_t diff1 = sqrt(pow(fFirstPoint[0]-x1,2)+pow(fFirstPoint[1]-y1,2));
422 if(diff0<diff1) ok1 = kFALSE; //use ok0
423 else ok0 = kFALSE; //use ok1
424 }
425 if(ok0){fPoint[0]=x0; fPoint[1]=y0;}
426 else {fPoint[0]=x1; fPoint[1]=y1;}
427
428 Double_t pointPhi0 = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
429 Double_t trackPhi0 = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
430 if(fabs(trackPhi0-pointPhi0)>AliHLTTPCTransform::Pi()){
431 if(trackPhi0<pointPhi0) trackPhi0 += AliHLTTPCTransform::TwoPi();
432 else pointPhi0 += AliHLTTPCTransform::TwoPi();
433 }
434 Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
435 fPoint[2] = fFirstPoint[2] + stot * fTanl;
436
437 fPointPsi = pointPhi0 - fQ * AliHLTTPCTransform::PiHalf();
438 if(fPointPsi<0.) fPointPsi+= AliHLTTPCTransform::TwoPi();
439 fPointPsi = fmod(fPointPsi, AliHLTTPCTransform::TwoPi());
440
441 return IsPoint(kTRUE);
442}
443
444Bool_t AliHLTTPCTrack::CalculatePoint(Double_t xplane)
445{
446 // Local coordinate: crossing point with x plane
447 //
448 Double_t racine = pow(fRadius,2)-pow(xplane-fCenterX,2);
449 if(racine<0) return IsPoint(kFALSE);
450 Double_t rootRacine = sqrt(racine);
451
452 Double_t y0 = fCenterY + rootRacine;
453 Double_t y1 = fCenterY - rootRacine;
454 //Double_t diff0 = sqrt(pow(fFirstPoint[0]-xplane)+pow(fFirstPoint[1]-y0));
455 //Double_t diff1 = sqrt(pow(fFirstPoint[0]-xplane)+pow(fFirstPoint[1]-y1));
456 Double_t diff0 = fabs(y0-fFirstPoint[1]);
457 Double_t diff1 = fabs(y1-fFirstPoint[1]);
458
459 fPoint[0]=xplane;
460 if(diff0<diff1) fPoint[1]=y0;
461 else fPoint[1]=y1;
462
463 Double_t pointPhi0 = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
464 Double_t trackPhi0 = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
465 if(fabs(trackPhi0-pointPhi0)>AliHLTTPCTransform::Pi()){
466 if(trackPhi0<pointPhi0) trackPhi0 += AliHLTTPCTransform::TwoPi();
467 else pointPhi0 += AliHLTTPCTransform::TwoPi();
468 }
469 Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
470 fPoint[2] = fFirstPoint[2] + stot * fTanl;
471
472 fPointPsi = pointPhi0 - fQ * AliHLTTPCTransform::PiHalf();
473 if(fPointPsi<0.) fPointPsi+= AliHLTTPCTransform::TwoPi();
474 fPointPsi = fmod(fPointPsi, AliHLTTPCTransform::TwoPi());
475
476 return IsPoint(kTRUE);
477}
478
479void AliHLTTPCTrack::UpdateToFirstPoint()
480{
481 //Update track parameters to the innermost point on the track.
482 //This means that the parameters of the track will be given in the point
483 //of closest approach to the first innermost point, i.e. the point
484 //lying on the track fit (and not the coordinates of the innermost point itself).
485 //This function assumes that fFirstPoint is already set to the coordinates of the innermost
486 //assigned cluster.
487 //
488 //During the helix-fit, the first point on the track is set to the coordinates
489 //of the innermost assigned cluster. This may be ok, if you just want a fast
490 //estimate of the "global" track parameters; such as the momentum etc.
491 //However, if you later on want to do more precise local calculations, such
492 //as impact parameter, residuals etc, you need to give the track parameters
493 //according to the actual fit.
437e8e54 494 // for straight line fit
495 if (AliHLTTPCTransform::GetBFieldValue() == 0.0 ){
496 Double_t xc = GetCenterX() - GetFirstPointX();
497 Double_t yc = GetCenterY() - GetFirstPointY();
498
499 Double_t xn = (Double_t) sin( GetPsi() );
500 Double_t yn = -1. * (Double_t) cos( GetPsi() );
501
502 Double_t d = xc*xn + yc*yn;
503
504 Double_t distx = d * xn;
505 Double_t disty = d * yn;
506
507 Double_t point[2];
508
509 point[0] = distx + GetFirstPointX();
510 point[1] = disty + GetFirstPointY();
511
512 //Update the track parameters
513 SetR0(sqrt(point[0]*point[0]+point[1]*point[1]));
514 SetPhi0(atan2(point[1],point[0]));
515 SetFirstPoint(point[0],point[1],GetZ0());
516 }
517 // for helix fit
518 else {
519 Double_t xc = GetCenterX() - GetFirstPointX();
520 Double_t yc = GetCenterY() - GetFirstPointY();
521
522 Double_t distx1 = xc*(1 + GetRadius()/sqrt(xc*xc + yc*yc));
523 Double_t disty1 = yc*(1 + GetRadius()/sqrt(xc*xc + yc*yc));
524 Double_t distance1 = sqrt(distx1*distx1 + disty1*disty1);
525
526 Double_t distx2 = xc*(1 - GetRadius()/sqrt(xc*xc + yc*yc));
527 Double_t disty2 = yc*(1 - GetRadius()/sqrt(xc*xc + yc*yc));
528 Double_t distance2 = sqrt(distx2*distx2 + disty2*disty2);
529
530 //Choose the closest:
531 Double_t point[2];
532 if(distance1 < distance2)
533 {
534 point[0] = distx1 + GetFirstPointX();
535 point[1] = disty1 + GetFirstPointY();
536 }
537 else
538 {
539 point[0] = distx2 + GetFirstPointX();
540 point[1] = disty2 + GetFirstPointY();
541 }
542
543 Double_t pointpsi = atan2(point[1]-GetCenterY(),point[0]-GetCenterX());
544 pointpsi -= GetCharge()*AliHLTTPCTransform::PiHalf();
545 if(pointpsi < 0) pointpsi += AliHLTTPCTransform::TwoPi();
546
547 //Update the track parameters
548 SetR0(sqrt(point[0]*point[0]+point[1]*point[1]));
549 SetPhi0(atan2(point[1],point[0]));
550 SetFirstPoint(point[0],point[1],GetZ0());
551 SetPsi(pointpsi);
552 }
a6c02c85 553}
554
2a083ac4 555void AliHLTTPCTrack::GetClosestPoint(AliHLTTPCVertex *vertex,Double_t &closestX,Double_t &closestY,Double_t &closestZ)
a6c02c85 556{
557 //Calculate the point of closest approach to the vertex
558 //This function calculates the minimum distance from the helix to the vertex, and choose
559 //the corresponding point lying on the helix as the point of closest approach.
560
561 Double_t xc = GetCenterX() - vertex->GetX();
562 Double_t yc = GetCenterY() - vertex->GetY();
563
564 Double_t distx1 = xc*(1 + GetRadius()/sqrt(xc*xc + yc*yc));
565 Double_t disty1 = yc*(1 + GetRadius()/sqrt(xc*xc + yc*yc));
566 Double_t distance1 = sqrt(distx1*distx1 + disty1*disty1);
567
568 Double_t distx2 = xc*(1 - GetRadius()/sqrt(xc*xc + yc*yc));
569 Double_t disty2 = yc*(1 - GetRadius()/sqrt(xc*xc + yc*yc));
570 Double_t distance2 = sqrt(distx2*distx2 + disty2*disty2);
571
572 //Choose the closest:
573 if(distance1 < distance2)
574 {
2a083ac4 575 closestX = distx1 + vertex->GetX();
576 closestY = disty1 + vertex->GetY();
a6c02c85 577 }
578 else
579 {
2a083ac4 580 closestX = distx2 + vertex->GetX();
581 closestY = disty2 + vertex->GetY();
a6c02c85 582 }
583
584 //Get the z coordinate:
2a083ac4 585 Double_t angle1 = atan2((closestY-GetCenterY()),(closestX-GetCenterX()));
a6c02c85 586 if(angle1 < 0) angle1 = angle1 + AliHLTTPCTransform::TwoPi();
587
588 Double_t angle2 = atan2((GetFirstPointY()-GetCenterY()),(GetFirstPointX()-GetCenterX()));
589 if(angle2 < 0) angle2 = angle2 + AliHLTTPCTransform::TwoPi();
590
2a083ac4 591 Double_t diffAngle = angle1 - angle2;
592 diffAngle = fmod(diffAngle,AliHLTTPCTransform::TwoPi());
a6c02c85 593
2a083ac4 594 if((GetCharge()*diffAngle) < 0) diffAngle = diffAngle + GetCharge()*AliHLTTPCTransform::TwoPi();
595 Double_t stot = fabs(diffAngle)*GetRadius();
596 closestZ = GetFirstPointZ() - stot*GetTgl();
a6c02c85 597}
598
5d2abf3b 599void AliHLTTPCTrack::Print(Option_t* /*option*/) const
2a083ac4 600{
601//print out parameters of track
738c049f 602
738c049f 603 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrack::Print","Print values")
604 <<"NH="<<fNHits<<" "<<fMCid<<" K="<<fKappa<<" R="<<fRadius<<" Cx="<<fCenterX<<" Cy="<<fCenterY<<" MVT="
605 <<fFromMainVertex<<" Row0="<<fRowRange[0]<<" Row1="<<fRowRange[1]<<" Sector="<<fSector<<" Q="<<fQ<<" TgLam="
606 <<fTanl<<" psi="<<fPsi<<" pt="<<fPt<<" L="<<fLength<<" "<<fPterr<<" "<<fPsierr<<" "<<fZ0err<<" "
4fdaad1e 607 <<fTanlerr<<" phi0="<<fPhi0<<" R0="<<fR0<<" Z0="<<fZ0<<" X0="<<fFirstPoint[0]<<" Y0="<<fFirstPoint[1]<<" Z0="
608 <<fFirstPoint[2]<<" XL="<<fLastPoint[0]<<" YL="<<fLastPoint[1]<<" ZL="<<fLastPoint[2]<<" "
738c049f 609 <<fPoint[0]<<" "<<fPoint[1]<<" "<<fPoint[2]<<" "<<fPointPsi<<" "<<fIsPoint<<" local="
610 <<fIsLocal<<" "<<fPID<<ENDLOG;
611
a6c02c85 612}
3cde846d 613
614int AliHLTTPCTrack::Convert2AliKalmanTrack()
615{
3cde846d 616 // The method has been copied from AliHLTHoughKalmanTrack and adapted
617 // to the TPC conformal mapping track parametrization
4fdaad1e 618 int iResult=0;
3cde846d 619
4fdaad1e 620 // sector A00 starts at 3 o'clock, sectors are counted counterclockwise
621 // median of sector 00 is at 10 degrees, median of sector A04 at 90
622 //
d53596be 623 Double_t xhit;
624 Double_t charge=-1.0 * (double) GetCharge();
625 Double_t xx[5];
626 xx[1] = GetFirstPointZ();
627 xx[3] = GetTgl();
628 xx[4] = charge*(1.0/GetPt());
629
4fdaad1e 630 Double_t alpha = 0;
d53596be 631 if(GetSector() == -1){
632 alpha = TMath::ATan(fabs(GetFirstPointY())/fabs(GetFirstPointX()));
3cde846d 633
d53596be 634 if(GetFirstPointX()<0 && GetFirstPointY()>=0){
635 alpha = alpha + TMath::PiOver2();
636 }
637 else if(GetFirstPointX()<0 && GetFirstPointY()<0){
638 alpha = -TMath::Pi() + alpha;
639 }
640 else if(GetFirstPointX()>=0 && GetFirstPointY()<0){
641 alpha = -alpha;
642 }
643 xhit = GetFirstPointX()*TMath::Cos(alpha) + GetFirstPointY()*TMath::Sin(alpha);
644 xx[0] = -(GetFirstPointX()*TMath::Sin(alpha)) + GetFirstPointY()*TMath::Cos(alpha);
645 xx[2] = TMath::Sin(GetPsi()-alpha);
646 }
647 else{
648 alpha = fmod((2*GetSector()+1)*(TMath::Pi()/18),2*TMath::Pi());
649 if (alpha < -TMath::Pi()) alpha += 2*TMath::Pi();
650 else if (alpha >= TMath::Pi()) alpha -= 2*TMath::Pi();
651
652 xhit = GetFirstPointX();
653 xx[0] = GetFirstPointY();
654 xx[2] = TMath::Sin(GetPsi());
655 }
656
657
3cde846d 658 //covariance matrix
659 Double_t cov[15]={
660 0.,
661 0., 0.,
662 0., 0., 0.,
663 0., 0., 0., 0.,
664 0., 0., 0., 0., 0.
665 };
666
23b1c01c 667 Int_t nCluster = GetNHits();
668 fdEdx=0;
669
670 // the Set function was not available in earlier versions, check done
d53596be 671 // during configure; for the AliRoot build, by default ON
04dbc9e4 672#ifdef EXTERNALTRACKPARAM_V1
673#warning track conversion to ESD format needs AliRoot version > v4-05-04
674 //TODO (Feb 07): make this a real warning when logging system is adapted
675 //HLTWarning("track conversion to ESD format needs AliRoot version > v4-05-04");
676#else
677 Set(xhit,alpha,xx,cov);
23b1c01c 678 SetNumberOfClusters(nCluster);
679 SetChi2(0.);
680 SetFakeRatio(0.);
681 SetMass(0.13957);
04dbc9e4 682#endif
3cde846d 683
684 return iResult;
685}
25097926 686
687void AliHLTTPCTrack::SetHits(Int_t nhits,UInt_t *hits)
688{
689 // set hit array
690 if (!hits) return;
691 if (nhits>fgkHitArraySize) {
692 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCTrack::SetHits","too many hits")
693 << "too many hits (" << nhits << ") for hit array of size " << fgkHitArraySize << ENDLOG;
694 }
695 memcpy(fHitNumbers,hits,(nhits<=fgkHitArraySize?nhits:fgkHitArraySize)*sizeof(UInt_t));
696}