4 #include "AliL3Logging.h"
5 #include "AliL3Transform.h"
7 #include "AliL3HoughTrack.h"
9 ClassImp(AliL3HoughTrack)
12 AliL3HoughTrack::AliL3HoughTrack()
18 fTransform = new AliL3Transform();
26 AliL3HoughTrack::~AliL3HoughTrack()
33 void AliL3HoughTrack::Set(AliL3Track *track)
36 AliL3HoughTrack *tpt = (AliL3HoughTrack*)track;
37 SetTrackParameters(tpt->GetKappa(),tpt->GetPhi0(),tpt->GetWeight());
38 SetEtaIndex(tpt->GetEtaIndex());
39 SetEta(tpt->GetEta());
40 SetPsi(tpt->GetPsi());
41 SetCenterX(tpt->GetCenterX());
42 SetCenterY(tpt->GetCenterY());
43 SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
44 SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
45 SetCharge(tpt->GetCharge());
46 SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
49 fWeight = tpt->GetWeight();
50 fDLine = tpt->GetDLine();
51 fPsiLine = tpt->GetPsiLine();
52 SetNHits(tpt->GetWeight());
53 SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
59 Int_t AliL3HoughTrack::Compare(const AliL3Track *tpt) const
61 AliL3HoughTrack *track = (AliL3HoughTrack*)tpt;
62 if(track->GetWeight() < GetWeight()) return 1;
63 if(track->GetWeight() > GetWeight()) return -1;
67 void AliL3HoughTrack::SetEta(Double_t f)
71 Double_t theta = 2*atan(exp(-1.*fEta));
72 Double_t dipangle = Pi/2 - theta;
73 Double_t tgl = tan(dipangle);
77 void AliL3HoughTrack::CalculateHelix()
82 void AliL3HoughTrack::UpdateToFirstRow()
84 //Update the track parameters to the point where track cross
87 //Get the crossing point with the first padrow:
89 if(!GetCrossingPoint(GetFirstRow(),xyz))
90 LOG(AliL3Log::kWarning,"AliL3HoughTrack::UpdateToFirstRow()","Track parameters")
91 <<AliL3Log::kDec<<"Track does not cross padrow "<<GetFirstRow()<<" centerx "
92 <<GetCenterX()<<" centery "<<GetCenterY()<<" Radius "<<GetRadius()<<" tgl "<<GetTgl()<<ENDLOG;
94 //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());
95 //printf("Before: first %f %f %f tgl %f center %f %f charge %d\n",GetFirstPointX(),GetFirstPointY(),GetFirstPointZ(),GetTgl(),GetCenterX(),GetCenterY(),GetCharge());
97 Double_t radius = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
99 //Get the track parameters
100 Double_t tPhi0 = GetPsi() + GetCharge() * 0.5 * pi / fabs(GetCharge()) ;
101 Double_t x0 = GetR0() * cos(GetPhi0()) ;
102 Double_t y0 = GetR0() * sin(GetPhi0()) ;
103 Double_t rc = fabs(GetPt()) / ( BFACT * bField ) ;
104 Double_t xc = x0 - rc * cos(tPhi0) ;
105 Double_t yc = y0 - rc * sin(tPhi0) ;
107 //Check helix and cylinder intersect
108 Double_t fac1 = xc*xc + yc*yc ;
109 Double_t sfac = sqrt( fac1 ) ;
111 if ( fabs(sfac-rc) > radius || fabs(sfac+rc) < radius ) {
112 LOG(AliL3Log::kError,"AliL3HoughTrack::UpdateToFirstRow","Tracks")<<AliL3Log::kDec<<
113 "Track does not intersect"<<ENDLOG;
118 Double_t fac2 = ( radius*radius + fac1 - rc*rc) / (2.00 * radius * sfac ) ;
119 Double_t phi = atan2(yc,xc) + GetCharge()*acos(fac2) ;
120 Double_t td = atan2(radius*sin(phi) - yc,radius*cos(phi) - xc) ;
123 if ( td < 0 ) td = td + 2. * pi ;
124 Double_t deltat = fmod((-GetCharge()*td + GetCharge()*tPhi0),2*pi) ;
125 if ( deltat < 0. ) deltat += 2. * pi ;
126 if ( deltat > 2.*pi ) deltat -= 2. * pi ;
127 Double_t z = GetZ0() + rc * GetTgl() * deltat ;
130 Double_t xExtra = radius * cos(phi) ;
131 Double_t yExtra = radius * sin(phi) ;
133 Double_t tPhi = atan2(yExtra-yc,xExtra-xc);
135 //if ( tPhi < 0 ) tPhi += 2. * M_PI ;
137 Double_t tPsi = tPhi - GetCharge() * 0.5 * pi / fabs(GetCharge()) ;
138 if ( tPsi > 2. * pi ) tPsi -= 2. * pi ;
139 if ( tPsi < 0. ) tPsi += 2. * pi ;
141 //And finally, update the track parameters
146 SetFirstPoint(xyz[0],xyz[1],z);
147 //printf("After: first %f %f %f tgl %f center %f %f charge %d\n",GetFirstPointX(),GetFirstPointY(),GetFirstPointZ(),GetTgl(),GetCenterX(),GetCenterY(),GetCharge());
149 //printf("First point set %f %f %f\n",xyz[0],xyz[1],z);
151 //Also, set the coordinates of the point where track crosses last padrow:
152 GetCrossingPoint(GetLastRow(),xyz);
153 SetLastPoint(xyz[0],xyz[1],xyz[2]);
154 //printf("last point %f %f %f\n",xyz[0],xyz[1],xyz[2]);
157 void AliL3HoughTrack::SetTrackParameters(Double_t kappa,Double_t phi,Int_t weight)
164 Double_t pt = fabs(BFACT*bField/kappa);
166 Double_t radius = 1/fabs(kappa);
168 SetFirstPoint(0,0,0);
169 SetPsi(phi); //Psi = Phi when first point is vertex
171 Double_t charge = -1.*kappa;
172 SetCharge((Int_t)copysign(1.,charge));
174 Double_t trackPhi0 = GetPsi() + charge*0.5*Pi/fabs(charge);
175 Double_t xc = GetFirstPointX() - GetRadius() * cos(trackPhi0) ;
176 Double_t yc = GetFirstPointY() - GetRadius() * sin(trackPhi0) ;
183 void AliL3HoughTrack::SetLineParameters(Double_t psi,Double_t D,Int_t weight,Int_t *rowrange,Int_t ref_row)
185 //Initialize a track piece, not yet a track
186 //Used in case of straight line transformation
188 //Transform line parameters to coordinate system of slice:
190 D = D + fTransform->Row2X(ref_row)*cos(psi);
196 SetRowRange(rowrange[0],rowrange[1]);
201 void AliL3HoughTrack::SetBestMCid(Int_t mcid,Double_t min_dist)
204 if(min_dist < fMinDist)
212 void AliL3HoughTrack::GetLineCrossingPoint(Int_t padrow,Double_t *xy)
218 printf("AliL3HoughTrack::GetLineCrossingPoint : Track is not a line\n");
222 Double_t xhit = fTransform->Row2X(padrow);
223 Double_t a = -1/tan(fPsiLine);
224 Double_t b = fDLine/sin(fPsiLine);
226 Double_t yhit = a*xhit + b;
233 Double_t AliL3HoughTrack::GetCrossingAngle(Int_t padrow)
235 //Calculate the crossing angle between track and given padrow.
239 printf("AliL3HoughTrack::GetCrossingAngle : Track is not a helix\n");
245 printf("Track is not given in local coordinates\n");
250 if(!GetCrossingPoint(padrow,xyz))
251 printf("AliL3HoughTrack::GetCrossingPoint : Track does not cross line!!\n");
254 //Convert center of curvature to local coordinates:
255 //Float_t xyz_coc[3] = {GetCenterX(),GetCenterY(),0};
256 //fTransform->Global2Local(xyz_coc,slice);
258 //Take the dot product of the tangent vector of the track, and
259 //vector perpendicular to the padrow.
262 //tangent[1] = (xyz[0] - xyz_coc[0])/GetRadius();
263 //tangent[0] = -1.*(xyz[1] - xyz_coc[1])/GetRadius();
264 tangent[1] = (xyz[0] - GetCenterX())/GetRadius();
265 tangent[0] = -1.*(xyz[1] - GetCenterY())/GetRadius();
267 Double_t perp_padrow[2] = {1,0}; //locally in slice
269 Double_t cos_beta = fabs(tangent[0]*perp_padrow[0] + tangent[1]*perp_padrow[1]);
270 return acos(cos_beta);
274 Bool_t AliL3HoughTrack::GetCrossingPoint(Int_t padrow,Float_t *xyz)
276 //Assumes the track is given in local coordinates
280 printf("AliL3HoughTrack::GetCrossingPoint : Track is not a helix\n");
287 printf("GetCrossingPoint: Track is given on global coordinates\n");
291 Double_t xHit = fTransform->Row2X(padrow);
293 //xyz[0] = fTransform->Row2X(padrow);
295 Double_t aa = (xHit - GetCenterX())*(xHit - GetCenterX());
296 Double_t r2 = GetRadius()*GetRadius();
300 Double_t aa2 = sqrt(r2 - aa);
301 Double_t y1 = GetCenterY() + aa2;
302 Double_t y2 = GetCenterY() - aa2;
304 if(fabs(y2) < fabs(y1)) xyz[1] = y2;
305 xyz[2] = 0; //only consider transverse plane
311 Bool_t AliL3HoughTrack::GetCrossingPoint(Int_t slice,Int_t padrow,Float_t *xyz)
313 //Calculate the crossing point in transverse plane of this track and given
314 //padrow (y = a*x + b). Point is given in local coordinates in slice.
315 //Assumes the track is given in global coordinates.
319 printf("AliL3HoughTrack::GetCrossingPoint : Track is not a helix\n");
326 printf("GetCrossingPoint: Track is given in local coordintes!!!\n");
330 Double_t padrowradii = fTransform->Row2X(padrow);
333 Float_t rotation_angle = (slice*20)*ToRad;
336 cs = cos(rotation_angle);
337 sn = sin(rotation_angle);
339 Double_t a = -1.*cs/sn;
340 Double_t b = padrowradii/sn;
342 Double_t ycPrime = GetCenterY() - b ;
343 Double_t aa = ( 1. + a * a ) ;
344 Double_t bb = -2. * ( GetCenterX() + a * ycPrime ) ;
345 Double_t cc = ( GetCenterX() * GetCenterX() + ycPrime * ycPrime - GetRadius() * GetRadius() ) ;
347 Double_t racine = bb * bb - 4. * aa * cc ;
348 if ( racine < 0 ) return false ;
349 Double_t rootRacine = sqrt(racine) ;
351 Double_t oneOverA = 1./aa;
355 Double_t x1 = 0.5 * oneOverA * ( -1. * bb + rootRacine ) ;
356 Double_t y1 = a * x1 + b ;
357 Double_t r1 = sqrt(x1*x1+y1*y1);
361 Double_t x2 = 0.5 * oneOverA * ( -1. * bb - rootRacine ) ;
362 Double_t y2 = a * x2 + b ;
363 Double_t r2 = sqrt(x2*x2+y2*y2);
365 // Choose close to (0,0)
382 fTransform->Global2Local(xyz,slice);