]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/hough/AliL3HoughTrack.cxx
New Recpoints
[u/mrichter/AliRoot.git] / HLT / hough / AliL3HoughTrack.cxx
CommitLineData
b1886074 1//$Id$
2
3// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4//*-- Copyright &copy ASV
d712b5b8 5
6#include <math.h>
7
8#include "AliL3Logging.h"
9#include "AliL3Transform.h"
10#include "AliL3Defs.h"
11#include "AliL3HoughTrack.h"
12
b1886074 13//_____________________________________________________________
14// AliL3HoughTrack
15//
16// Track class for Hough tracklets
17
d712b5b8 18ClassImp(AliL3HoughTrack)
19
20
21AliL3HoughTrack::AliL3HoughTrack()
22{
23 //Constructor
24
25 fWeight = 0;
26 fMinDist=0;
27 fTransform = new AliL3Transform();
28 fDLine = 0;
29 fPsiLine = 0;
30 fIsHelix = true;
31 fEtaIndex = -1;
32}
33
34
35AliL3HoughTrack::~AliL3HoughTrack()
36{
37 //Destructor
38 if(fTransform)
39 delete fTransform;
40}
41
42void AliL3HoughTrack::Set(AliL3Track *track)
43{
44
45 AliL3HoughTrack *tpt = (AliL3HoughTrack*)track;
46 SetTrackParameters(tpt->GetKappa(),tpt->GetPhi0(),tpt->GetWeight());
47 SetEtaIndex(tpt->GetEtaIndex());
48 SetEta(tpt->GetEta());
ae4d5136 49 SetTgl(tpt->GetTgl());
d712b5b8 50 SetPsi(tpt->GetPsi());
51 SetCenterX(tpt->GetCenterX());
52 SetCenterY(tpt->GetCenterY());
53 SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
54 SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
55 SetCharge(tpt->GetCharge());
56 SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
b1886074 57 SetSlice(tpt->GetSlice());
d712b5b8 58 return;
59
60 fWeight = tpt->GetWeight();
61 fDLine = tpt->GetDLine();
62 fPsiLine = tpt->GetPsiLine();
63 SetNHits(tpt->GetWeight());
64 SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
65 fIsHelix = false;
66
67
68}
69
70Int_t AliL3HoughTrack::Compare(const AliL3Track *tpt) const
71{
72 AliL3HoughTrack *track = (AliL3HoughTrack*)tpt;
73 if(track->GetWeight() < GetWeight()) return 1;
74 if(track->GetWeight() > GetWeight()) return -1;
75 return 0;
76}
77
78void AliL3HoughTrack::SetEta(Double_t f)
79{
b1886074 80 //Set eta, and calculate fTanl, which is the tan of dipangle
81
d712b5b8 82 fEta = f;
83 Double_t theta = 2*atan(exp(-1.*fEta));
8b007a2d 84 Double_t dipangle = Pi/2 - theta;
85 Double_t tgl = tan(dipangle);
d712b5b8 86 SetTgl(tgl);
87}
88
89void AliL3HoughTrack::CalculateHelix()
90{
91 return;
92}
93
94void AliL3HoughTrack::UpdateToFirstRow()
95{
96 //Update the track parameters to the point where track cross
97 //its first padrow.
98
99 //Get the crossing point with the first padrow:
100 Float_t xyz[3];
101 if(!GetCrossingPoint(GetFirstRow(),xyz))
102 LOG(AliL3Log::kWarning,"AliL3HoughTrack::UpdateToFirstRow()","Track parameters")
103 <<AliL3Log::kDec<<"Track does not cross padrow "<<GetFirstRow()<<" centerx "
104 <<GetCenterX()<<" centery "<<GetCenterY()<<" Radius "<<GetRadius()<<" tgl "<<GetTgl()<<ENDLOG;
105
8b007a2d 106 //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());
107 //printf("Before: first %f %f %f tgl %f center %f %f charge %d\n",GetFirstPointX(),GetFirstPointY(),GetFirstPointZ(),GetTgl(),GetCenterX(),GetCenterY(),GetCharge());
108
d712b5b8 109 Double_t radius = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
110
111 //Get the track parameters
b1886074 112
113 /*
114 Double_t x0 = GetR0() * cos(GetPhi0()) ;
115 Double_t y0 = GetR0() * sin(GetPhi0()) ;
116 */
117 Double_t rc = GetRadius();//fabs(GetPt()) / ( BFACT * BField ) ;
d712b5b8 118 Double_t tPhi0 = GetPsi() + GetCharge() * 0.5 * pi / fabs(GetCharge()) ;
b1886074 119 Double_t xc = GetCenterX();//x0 - rc * cos(tPhi0) ;
120 Double_t yc = GetCenterY();//y0 - rc * sin(tPhi0) ;
d712b5b8 121
122 //Check helix and cylinder intersect
123 Double_t fac1 = xc*xc + yc*yc ;
124 Double_t sfac = sqrt( fac1 ) ;
b1886074 125
d712b5b8 126 if ( fabs(sfac-rc) > radius || fabs(sfac+rc) < radius ) {
127 LOG(AliL3Log::kError,"AliL3HoughTrack::UpdateToFirstRow","Tracks")<<AliL3Log::kDec<<
128 "Track does not intersect"<<ENDLOG;
129 return;
130 }
131
132 //Find intersection
133 Double_t fac2 = ( radius*radius + fac1 - rc*rc) / (2.00 * radius * sfac ) ;
134 Double_t phi = atan2(yc,xc) + GetCharge()*acos(fac2) ;
135 Double_t td = atan2(radius*sin(phi) - yc,radius*cos(phi) - xc) ;
136
137 //Intersection in z
138 if ( td < 0 ) td = td + 2. * pi ;
139 Double_t deltat = fmod((-GetCharge()*td + GetCharge()*tPhi0),2*pi) ;
140 if ( deltat < 0. ) deltat += 2. * pi ;
141 if ( deltat > 2.*pi ) deltat -= 2. * pi ;
142 Double_t z = GetZ0() + rc * GetTgl() * deltat ;
8b007a2d 143
d712b5b8 144
145 Double_t xExtra = radius * cos(phi) ;
146 Double_t yExtra = radius * sin(phi) ;
147
148 Double_t tPhi = atan2(yExtra-yc,xExtra-xc);
149
150 //if ( tPhi < 0 ) tPhi += 2. * M_PI ;
151
152 Double_t tPsi = tPhi - GetCharge() * 0.5 * pi / fabs(GetCharge()) ;
153 if ( tPsi > 2. * pi ) tPsi -= 2. * pi ;
154 if ( tPsi < 0. ) tPsi += 2. * pi ;
155
156 //And finally, update the track parameters
d712b5b8 157 SetR0(radius);
158 SetPhi0(phi);
159 SetZ0(z);
160 SetPsi(tPsi);
161 SetFirstPoint(xyz[0],xyz[1],z);
8b007a2d 162 //printf("After: first %f %f %f tgl %f center %f %f charge %d\n",GetFirstPointX(),GetFirstPointY(),GetFirstPointZ(),GetTgl(),GetCenterX(),GetCenterY(),GetCharge());
163
164 //printf("First point set %f %f %f\n",xyz[0],xyz[1],z);
d712b5b8 165
166 //Also, set the coordinates of the point where track crosses last padrow:
167 GetCrossingPoint(GetLastRow(),xyz);
168 SetLastPoint(xyz[0],xyz[1],xyz[2]);
8b007a2d 169 //printf("last point %f %f %f\n",xyz[0],xyz[1],xyz[2]);
d712b5b8 170}
171
172void AliL3HoughTrack::SetTrackParameters(Double_t kappa,Double_t phi,Int_t weight)
173{
174
175 fWeight = weight;
176 fMinDist = 100000;
177 SetKappa(kappa);
178 SetPhi0(phi);
b1886074 179 Double_t pt = fabs(BFACT*BField/kappa);
d712b5b8 180 SetPt(pt);
181 Double_t radius = 1/fabs(kappa);
182 SetRadius(radius);
183 SetFirstPoint(0,0,0);
8b007a2d 184 SetPsi(phi); //Psi = Phi when first point is vertex
185 SetR0(0);
d712b5b8 186 Double_t charge = -1.*kappa;
8b007a2d 187 SetCharge((Int_t)copysign(1.,charge));
188
189 Double_t trackPhi0 = GetPsi() + charge*0.5*Pi/fabs(charge);
190 Double_t xc = GetFirstPointX() - GetRadius() * cos(trackPhi0) ;
191 Double_t yc = GetFirstPointY() - GetRadius() * sin(trackPhi0) ;
d712b5b8 192 SetCenterX(xc);
193 SetCenterY(yc);
194 fIsHelix = true;
8b007a2d 195
d712b5b8 196}
197
198void AliL3HoughTrack::SetLineParameters(Double_t psi,Double_t D,Int_t weight,Int_t *rowrange,Int_t ref_row)
199{
200 //Initialize a track piece, not yet a track
201 //Used in case of straight line transformation
202
203 //Transform line parameters to coordinate system of slice:
204
205 D = D + fTransform->Row2X(ref_row)*cos(psi);
206
207 fDLine = D;
208 fPsiLine = psi;
209 fWeight = weight;
210 SetNHits(weight);
211 SetRowRange(rowrange[0],rowrange[1]);
212 fIsHelix = false;
213
214}
215
216void AliL3HoughTrack::SetBestMCid(Int_t mcid,Double_t min_dist)
217{
218
219 if(min_dist < fMinDist)
220 {
221 fMinDist = min_dist;
222 SetMCid(mcid);
223 }
224
225}
226
227void AliL3HoughTrack::GetLineCrossingPoint(Int_t padrow,Double_t *xy)
228{
229
230
231 if(fIsHelix)
232 {
233 printf("AliL3HoughTrack::GetLineCrossingPoint : Track is not a line\n");
234 return;
235 }
236
237 Double_t xhit = fTransform->Row2X(padrow);
238 Double_t a = -1/tan(fPsiLine);
239 Double_t b = fDLine/sin(fPsiLine);
240
241 Double_t yhit = a*xhit + b;
242 xy[0] = xhit;
243 xy[1] = yhit;
244
245}
246
247/*
248Double_t AliL3HoughTrack::GetCrossingAngle(Int_t padrow)
249{
250 //Calculate the crossing angle between track and given padrow.
251
252 if(!fIsHelix)
253 {
254 printf("AliL3HoughTrack::GetCrossingAngle : Track is not a helix\n");
255 return 0;
256 }
257
258 if(!IsLocal())
259 {
260 printf("Track is not given in local coordinates\n");
261 return 0;
262 }
263
264 Float_t xyz[3];
265 if(!GetCrossingPoint(padrow,xyz))
266 printf("AliL3HoughTrack::GetCrossingPoint : Track does not cross line!!\n");
267
268
269 //Convert center of curvature to local coordinates:
270 //Float_t xyz_coc[3] = {GetCenterX(),GetCenterY(),0};
271 //fTransform->Global2Local(xyz_coc,slice);
272
273 //Take the dot product of the tangent vector of the track, and
274 //vector perpendicular to the padrow.
275
276 Double_t tangent[2];
277 //tangent[1] = (xyz[0] - xyz_coc[0])/GetRadius();
278 //tangent[0] = -1.*(xyz[1] - xyz_coc[1])/GetRadius();
279 tangent[1] = (xyz[0] - GetCenterX())/GetRadius();
280 tangent[0] = -1.*(xyz[1] - GetCenterY())/GetRadius();
281
282 Double_t perp_padrow[2] = {1,0}; //locally in slice
283
284 Double_t cos_beta = fabs(tangent[0]*perp_padrow[0] + tangent[1]*perp_padrow[1]);
285 return acos(cos_beta);
286
287}
288
289Bool_t AliL3HoughTrack::GetCrossingPoint(Int_t padrow,Float_t *xyz)
290{
291 //Assumes the track is given in local coordinates
292
293 if(!fIsHelix)
294 {
295 printf("AliL3HoughTrack::GetCrossingPoint : Track is not a helix\n");
296 return 0;
297 }
298
299
300 if(!IsLocal())
301 {
302 printf("GetCrossingPoint: Track is given on global coordinates\n");
303 return false;
304 }
305
306 Double_t xHit = fTransform->Row2X(padrow);
307
308 //xyz[0] = fTransform->Row2X(padrow);
309 xyz[0] = xHit;
310 Double_t aa = (xHit - GetCenterX())*(xHit - GetCenterX());
311 Double_t r2 = GetRadius()*GetRadius();
312 if(aa > r2)
313 return false;
314
315 Double_t aa2 = sqrt(r2 - aa);
316 Double_t y1 = GetCenterY() + aa2;
317 Double_t y2 = GetCenterY() - aa2;
318 xyz[1] = y1;
319 if(fabs(y2) < fabs(y1)) xyz[1] = y2;
320 xyz[2] = 0; //only consider transverse plane
321
322 return true;
323}
324
325
326Bool_t AliL3HoughTrack::GetCrossingPoint(Int_t slice,Int_t padrow,Float_t *xyz)
327{
328 //Calculate the crossing point in transverse plane of this track and given
329 //padrow (y = a*x + b). Point is given in local coordinates in slice.
330 //Assumes the track is given in global coordinates.
331
332 if(!fIsHelix)
333 {
334 printf("AliL3HoughTrack::GetCrossingPoint : Track is not a helix\n");
335 return 0;
336 }
337
338
339 if(IsLocal())
340 {
341 printf("GetCrossingPoint: Track is given in local coordintes!!!\n");
342 return false;
343 }
344
345 Double_t padrowradii = fTransform->Row2X(padrow);
346
347
348 Float_t rotation_angle = (slice*20)*ToRad;
349
350 Float_t cs,sn;
351 cs = cos(rotation_angle);
352 sn = sin(rotation_angle);
353
354 Double_t a = -1.*cs/sn;
355 Double_t b = padrowradii/sn;
356
357 Double_t ycPrime = GetCenterY() - b ;
358 Double_t aa = ( 1. + a * a ) ;
359 Double_t bb = -2. * ( GetCenterX() + a * ycPrime ) ;
360 Double_t cc = ( GetCenterX() * GetCenterX() + ycPrime * ycPrime - GetRadius() * GetRadius() ) ;
361
362 Double_t racine = bb * bb - 4. * aa * cc ;
363 if ( racine < 0 ) return false ;
364 Double_t rootRacine = sqrt(racine) ;
365
366 Double_t oneOverA = 1./aa;
367//
368// First solution
369//
370 Double_t x1 = 0.5 * oneOverA * ( -1. * bb + rootRacine ) ;
371 Double_t y1 = a * x1 + b ;
372 Double_t r1 = sqrt(x1*x1+y1*y1);
373//
374// Second solution
375//
376 Double_t x2 = 0.5 * oneOverA * ( -1. * bb - rootRacine ) ;
377 Double_t y2 = a * x2 + b ;
378 Double_t r2 = sqrt(x2*x2+y2*y2);
379//
380// Choose close to (0,0)
381//
382 Double_t xHit ;
383 Double_t yHit ;
384 if ( r1 < r2 ) {
385 xHit = x1 ;
386 yHit = y1 ;
387 }
388 else {
389 xHit = x2 ;
390 yHit = y2 ;
391 }
392
393 xyz[0] = xHit;
394 xyz[1] = yHit;
395 xyz[2] = 0;
396
397 fTransform->Global2Local(xyz,slice);
398
399 return true;
400}
401*/