3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright © ASV
8 #include "AliL3Logging.h"
10 #include "AliL3HoughTrack.h"
11 #include "AliL3Transform.h"
13 //_____________________________________________________________
16 // Track class for Hough tracklets
18 ClassImp(AliL3HoughTrack)
21 AliL3HoughTrack::AliL3HoughTrack()
34 AliL3HoughTrack::~AliL3HoughTrack()
39 void AliL3HoughTrack::Set(AliL3Track *track)
42 AliL3HoughTrack *tpt = (AliL3HoughTrack*)track;
43 SetTrackParameters(tpt->GetKappa(),tpt->GetPhi0(),tpt->GetWeight());
44 SetEtaIndex(tpt->GetEtaIndex());
45 SetEta(tpt->GetEta());
46 SetTgl(tpt->GetTgl());
47 SetPsi(tpt->GetPsi());
48 SetCenterX(tpt->GetCenterX());
49 SetCenterY(tpt->GetCenterY());
50 SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
51 SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
52 SetCharge(tpt->GetCharge());
53 SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
54 SetSlice(tpt->GetSlice());
58 fWeight = tpt->GetWeight();
59 fDLine = tpt->GetDLine();
60 fPsiLine = tpt->GetPsiLine();
61 SetNHits(tpt->GetWeight());
62 SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
68 Int_t AliL3HoughTrack::Compare(const AliL3Track *tpt) const
70 AliL3HoughTrack *track = (AliL3HoughTrack*)tpt;
71 if(track->GetWeight() < GetWeight()) return 1;
72 if(track->GetWeight() > GetWeight()) return -1;
76 void AliL3HoughTrack::SetEta(Double_t f)
78 //Set eta, and calculate fTanl, which is the tan of dipangle
81 Double_t theta = 2*atan(exp(-1.*fEta));
82 Double_t dipangle = Pi/2 - theta;
83 Double_t tgl = tan(dipangle);
87 void AliL3HoughTrack::CalculateHelix()
92 void AliL3HoughTrack::UpdateToFirstRow()
94 //Update the track parameters to the point where track cross
97 //Get the crossing point with the first padrow:
99 if(!GetCrossingPoint(GetFirstRow(),xyz))
100 LOG(AliL3Log::kWarning,"AliL3HoughTrack::UpdateToFirstRow()","Track parameters")
101 <<AliL3Log::kDec<<"Track does not cross padrow "<<GetFirstRow()<<" centerx "
102 <<GetCenterX()<<" centery "<<GetCenterY()<<" Radius "<<GetRadius()<<" tgl "<<GetTgl()<<ENDLOG;
104 //printf("Track with eta %f tgl %f crosses at x %f y %f z %f on padrow %d\n",GetEta(),GetTgl(),xyz[0],xyz[1],xyz[2],GetFirstRow());
105 //printf("Before: first %f %f %f tgl %f center %f %f charge %d\n",GetFirstPointX(),GetFirstPointY(),GetFirstPointZ(),GetTgl(),GetCenterX(),GetCenterY(),GetCharge());
107 Double_t radius = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
109 //Get the track parameters
112 Double_t x0 = GetR0() * cos(GetPhi0()) ;
113 Double_t y0 = GetR0() * sin(GetPhi0()) ;
115 Double_t rc = GetRadius();//fabs(GetPt()) / ( BFACT * AliL3Transform::GetBField() ) ;
116 Double_t tPhi0 = GetPsi() + GetCharge() * 0.5 * pi / fabs(GetCharge()) ;
117 Double_t xc = GetCenterX();//x0 - rc * cos(tPhi0) ;
118 Double_t yc = GetCenterY();//y0 - rc * sin(tPhi0) ;
120 //Check helix and cylinder intersect
121 Double_t fac1 = xc*xc + yc*yc ;
122 Double_t sfac = sqrt( fac1 ) ;
124 if ( fabs(sfac-rc) > radius || fabs(sfac+rc) < radius ) {
125 LOG(AliL3Log::kError,"AliL3HoughTrack::UpdateToFirstRow","Tracks")<<AliL3Log::kDec<<
126 "Track does not intersect"<<ENDLOG;
131 Double_t fac2 = ( radius*radius + fac1 - rc*rc) / (2.00 * radius * sfac ) ;
132 Double_t phi = atan2(yc,xc) + GetCharge()*acos(fac2) ;
133 Double_t td = atan2(radius*sin(phi) - yc,radius*cos(phi) - xc) ;
136 if ( td < 0 ) td = td + 2. * pi ;
137 Double_t deltat = fmod((-GetCharge()*td + GetCharge()*tPhi0),2*pi) ;
138 if ( deltat < 0. ) deltat += 2. * pi ;
139 if ( deltat > 2.*pi ) deltat -= 2. * pi ;
140 Double_t z = GetZ0() + rc * GetTgl() * deltat ;
143 Double_t xExtra = radius * cos(phi) ;
144 Double_t yExtra = radius * sin(phi) ;
146 Double_t tPhi = atan2(yExtra-yc,xExtra-xc);
148 //if ( tPhi < 0 ) tPhi += 2. * M_PI ;
150 Double_t tPsi = tPhi - GetCharge() * 0.5 * pi / fabs(GetCharge()) ;
151 if ( tPsi > 2. * pi ) tPsi -= 2. * pi ;
152 if ( tPsi < 0. ) tPsi += 2. * pi ;
154 //And finally, update the track parameters
159 SetFirstPoint(xyz[0],xyz[1],z);
160 //printf("After: first %f %f %f tgl %f center %f %f charge %d\n",GetFirstPointX(),GetFirstPointY(),GetFirstPointZ(),GetTgl(),GetCenterX(),GetCenterY(),GetCharge());
162 //printf("First point set %f %f %f\n",xyz[0],xyz[1],z);
164 //Also, set the coordinates of the point where track crosses last padrow:
165 GetCrossingPoint(GetLastRow(),xyz);
166 SetLastPoint(xyz[0],xyz[1],xyz[2]);
167 //printf("last point %f %f %f\n",xyz[0],xyz[1],xyz[2]);
170 void AliL3HoughTrack::SetTrackParameters(Double_t kappa,Double_t phi,Int_t weight)
177 Double_t pt = fabs(BFACT*AliL3Transform::GetBField()/kappa);
179 Double_t radius = 1/fabs(kappa);
181 SetFirstPoint(0,0,0);
182 SetPsi(phi); //Psi = Phi when first point is vertex
184 Double_t charge = -1.*kappa;
185 SetCharge((Int_t)copysign(1.,charge));
187 Double_t trackPhi0 = GetPsi() + charge*0.5*Pi/fabs(charge);
188 Double_t xc = GetFirstPointX() - GetRadius() * cos(trackPhi0) ;
189 Double_t yc = GetFirstPointY() - GetRadius() * sin(trackPhi0) ;
192 SetNHits(1); //just for the trackarray IO
198 void AliL3HoughTrack::SetLineParameters(Double_t psi,Double_t D,Int_t weight,Int_t *rowrange,Int_t ref_row)
200 //Initialize a track piece, not yet a track
201 //Used in case of straight line transformation
203 //Transform line parameters to coordinate system of slice:
206 D = D + fTransform->Row2X(ref_row)*cos(psi);
212 SetRowRange(rowrange[0],rowrange[1]);
217 void AliL3HoughTrack::SetBestMCid(Int_t mcid,Double_t min_dist)
220 if(min_dist < fMinDist)
228 void AliL3HoughTrack::GetLineCrossingPoint(Int_t padrow,Double_t *xy)
234 printf("AliL3HoughTrack::GetLineCrossingPoint : Track is not a line\n");
238 Double_t xhit = fTransform->Row2X(padrow);
239 Double_t a = -1/tan(fPsiLine);
240 Double_t b = fDLine/sin(fPsiLine);
242 Double_t yhit = a*xhit + b;
249 Double_t AliL3HoughTrack::GetCrossingAngle(Int_t padrow)
251 //Calculate the crossing angle between track and given padrow.
255 printf("AliL3HoughTrack::GetCrossingAngle : Track is not a helix\n");
261 printf("Track is not given in local coordinates\n");
266 if(!GetCrossingPoint(padrow,xyz))
267 printf("AliL3HoughTrack::GetCrossingPoint : Track does not cross line!!\n");
270 //Convert center of curvature to local coordinates:
271 //Float_t xyz_coc[3] = {GetCenterX(),GetCenterY(),0};
272 //fTransform->Global2Local(xyz_coc,slice);
274 //Take the dot product of the tangent vector of the track, and
275 //vector perpendicular to the padrow.
278 //tangent[1] = (xyz[0] - xyz_coc[0])/GetRadius();
279 //tangent[0] = -1.*(xyz[1] - xyz_coc[1])/GetRadius();
280 tangent[1] = (xyz[0] - GetCenterX())/GetRadius();
281 tangent[0] = -1.*(xyz[1] - GetCenterY())/GetRadius();
283 Double_t perp_padrow[2] = {1,0}; //locally in slice
285 Double_t cos_beta = fabs(tangent[0]*perp_padrow[0] + tangent[1]*perp_padrow[1]);
286 return acos(cos_beta);
290 Bool_t AliL3HoughTrack::GetCrossingPoint(Int_t padrow,Float_t *xyz)
292 //Assumes the track is given in local coordinates
296 printf("AliL3HoughTrack::GetCrossingPoint : Track is not a helix\n");
303 printf("GetCrossingPoint: Track is given on global coordinates\n");
307 Double_t xHit = fTransform->Row2X(padrow);
309 //xyz[0] = fTransform->Row2X(padrow);
311 Double_t aa = (xHit - GetCenterX())*(xHit - GetCenterX());
312 Double_t r2 = GetRadius()*GetRadius();
316 Double_t aa2 = sqrt(r2 - aa);
317 Double_t y1 = GetCenterY() + aa2;
318 Double_t y2 = GetCenterY() - aa2;
320 if(fabs(y2) < fabs(y1)) xyz[1] = y2;
321 xyz[2] = 0; //only consider transverse plane
327 Bool_t AliL3HoughTrack::GetCrossingPoint(Int_t slice,Int_t padrow,Float_t *xyz)
329 //Calculate the crossing point in transverse plane of this track and given
330 //padrow (y = a*x + b). Point is given in local coordinates in slice.
331 //Assumes the track is given in global coordinates.
335 printf("AliL3HoughTrack::GetCrossingPoint : Track is not a helix\n");
342 printf("GetCrossingPoint: Track is given in local coordintes!!!\n");
346 Double_t padrowradii = fTransform->Row2X(padrow);
349 Float_t rotation_angle = (slice*20)*ToRad;
352 cs = cos(rotation_angle);
353 sn = sin(rotation_angle);
355 Double_t a = -1.*cs/sn;
356 Double_t b = padrowradii/sn;
358 Double_t ycPrime = GetCenterY() - b ;
359 Double_t aa = ( 1. + a * a ) ;
360 Double_t bb = -2. * ( GetCenterX() + a * ycPrime ) ;
361 Double_t cc = ( GetCenterX() * GetCenterX() + ycPrime * ycPrime - GetRadius() * GetRadius() ) ;
363 Double_t racine = bb * bb - 4. * aa * cc ;
364 if ( racine < 0 ) return false ;
365 Double_t rootRacine = sqrt(racine) ;
367 Double_t oneOverA = 1./aa;
371 Double_t x1 = 0.5 * oneOverA * ( -1. * bb + rootRacine ) ;
372 Double_t y1 = a * x1 + b ;
373 Double_t r1 = sqrt(x1*x1+y1*y1);
377 Double_t x2 = 0.5 * oneOverA * ( -1. * bb - rootRacine ) ;
378 Double_t y2 = a * x2 + b ;
379 Double_t r2 = sqrt(x2*x2+y2*y2);
381 // Choose close to (0,0)
398 fTransform->Global2Local(xyz,slice);