]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/hough/AliL3HoughTrack.cxx
Merged HLT tag v1-2 with ALIROOT tag v3-09-Release.
[u/mrichter/AliRoot.git] / HLT / hough / AliL3HoughTrack.cxx
1 // @(#) $Id$
2
3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright &copy ALICE HLT Group
5
6 #include "AliL3StandardIncludes.h"
7
8 #include "AliL3Logging.h"
9 #include "AliL3HoughTrack.h"
10 #include "AliL3Transform.h"
11
12 #if GCCVERSION == 3
13 using namespace std;
14 #endif
15
16 //_____________________________________________________________
17 // AliL3HoughTrack
18 //
19 // Track class for Hough tracklets
20
21 ClassImp(AliL3HoughTrack)
22
23
24 AliL3HoughTrack::AliL3HoughTrack()
25 {
26   //Constructor
27   
28   fWeight = 0;
29   fMinDist=0;
30   fDLine = 0;
31   fPsiLine = 0;
32   fIsHelix = true;
33   fEtaIndex = -1;
34   fEta = 0;
35   
36 }
37
38
39 AliL3HoughTrack::~AliL3HoughTrack()
40 {
41   
42 }
43
44 void AliL3HoughTrack::Set(AliL3Track *track)
45 {
46   
47   AliL3HoughTrack *tpt = (AliL3HoughTrack*)track;
48   SetTrackParameters(tpt->GetKappa(),tpt->GetPsi(),tpt->GetWeight());
49   SetEtaIndex(tpt->GetEtaIndex());
50   SetEta(tpt->GetEta());
51   SetTgl(tpt->GetTgl());
52   SetPsi(tpt->GetPsi());
53   SetCenterX(tpt->GetCenterX());
54   SetCenterY(tpt->GetCenterY());
55   SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
56   SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
57   SetCharge(tpt->GetCharge());
58   SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
59   SetSlice(tpt->GetSlice());
60   SetHits(tpt->GetNHits(),(UInt_t *)tpt->GetHitNumbers());
61   return;
62
63   fWeight = tpt->GetWeight();
64   fDLine = tpt->GetDLine();
65   fPsiLine = tpt->GetPsiLine();
66   SetNHits(tpt->GetWeight());
67   SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
68   fIsHelix = false;
69 }
70
71 Int_t AliL3HoughTrack::Compare(const AliL3Track *tpt) const
72 {
73   AliL3HoughTrack *track = (AliL3HoughTrack*)tpt;
74   if(track->GetWeight() < GetWeight()) return 1;
75   if(track->GetWeight() > GetWeight()) return -1;
76   return 0;
77 }
78
79 void AliL3HoughTrack::SetEta(Double_t f)
80 {
81   //Set eta, and calculate fTanl, which is the tan of dipangle
82
83   fEta = f;
84   Double_t theta = 2*atan(exp(-1.*fEta));
85   Double_t dipangle = AliL3Transform::Pi()/2 - theta;
86   Double_t tgl = tan(dipangle);
87   SetTgl(tgl);
88 }
89
90
91 void AliL3HoughTrack::UpdateToFirstRow()
92 {
93   //Update the track parameters to the point where track cross
94   //its first padrow.
95   
96   //Get the crossing point with the first padrow:
97   Float_t xyz[3];
98   if(!GetCrossingPoint(GetFirstRow(),xyz))
99     LOG(AliL3Log::kWarning,"AliL3HoughTrack::UpdateToFirstRow()","Track parameters")
100       <<AliL3Log::kDec<<"Track does not cross padrow "<<GetFirstRow()<<" centerx "
101       <<GetCenterX()<<" centery "<<GetCenterY()<<" Radius "<<GetRadius()<<" tgl "<<GetTgl()<<ENDLOG;
102   
103   //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());
104   //printf("Before: first %f %f %f tgl %f center %f %f charge %d\n",GetFirstPointX(),GetFirstPointY(),GetFirstPointZ(),GetTgl(),GetCenterX(),GetCenterY(),GetCharge());
105   
106   Double_t radius = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
107
108   //Get the track parameters
109   
110   /*
111     Double_t x0    = GetR0() * cos(GetPhi0()) ;
112     Double_t y0    = GetR0() * sin(GetPhi0()) ;
113   */
114   Double_t rc    = GetRadius();//fabs(GetPt()) / ( BFACT * AliL3Transform::GetBField() )  ;
115   Double_t tPhi0 = GetPsi() + GetCharge() * 0.5 * pi / abs(GetCharge()) ;
116   Double_t xc    = GetCenterX();//x0 - rc * cos(tPhi0) ;
117   Double_t yc    = GetCenterY();//y0 - rc * sin(tPhi0) ;
118   
119   //Check helix and cylinder intersect
120   Double_t fac1 = xc*xc + yc*yc ;
121   Double_t sfac = sqrt( fac1 ) ;
122   
123   if ( fabs(sfac-rc) > radius || fabs(sfac+rc) < radius ) {
124     LOG(AliL3Log::kError,"AliL3HoughTrack::UpdateToFirstRow","Tracks")<<AliL3Log::kDec<<
125       "Track does not intersect"<<ENDLOG;
126     return;
127   }
128   
129   //Find intersection
130   Double_t fac2   = (radius*radius + fac1 - rc*rc) / (2.00 * radius * sfac ) ;
131   Double_t phi    = atan2(yc,xc) + GetCharge()*acos(fac2) ;
132   Double_t td     = atan2(radius*sin(phi) - yc,radius*cos(phi) - xc) ;
133   
134   //Intersection in z
135   if ( td < 0 ) td = td + 2. * pi ;
136   Double_t deltat = fmod((-GetCharge()*td + GetCharge()*tPhi0),2*pi) ;
137   if ( deltat < 0.      ) deltat += 2. * pi ;
138   if ( deltat > 2.*pi ) deltat -= 2. * pi ;
139   Double_t z = GetZ0() + rc * GetTgl() * deltat ;
140   
141   
142   Double_t xExtra = radius * cos(phi) ;
143   Double_t yExtra = radius * sin(phi) ;
144   
145   Double_t tPhi = atan2(yExtra-yc,xExtra-xc);
146   
147   //if ( tPhi < 0 ) tPhi += 2. * M_PI ;
148   
149   Double_t tPsi = tPhi - GetCharge() * 0.5 * pi / abs(GetCharge()) ;
150   if ( tPsi > 2. * pi ) tPsi -= 2. * pi ;
151   if ( tPsi < 0.        ) tPsi += 2. * pi ;
152   
153   //And finally, update the track parameters
154   SetR0(radius);
155   SetPhi0(phi);
156   SetZ0(z);
157   SetPsi(tPsi);
158   SetFirstPoint(xyz[0],xyz[1],z);
159   //printf("After: first %f %f %f tgl %f center %f %f charge %d\n",GetFirstPointX(),GetFirstPointY(),GetFirstPointZ(),GetTgl(),GetCenterX(),GetCenterY(),GetCharge());
160   
161   //printf("First point set %f %f %f\n",xyz[0],xyz[1],z);
162   
163   //Also, set the coordinates of the point where track crosses last padrow:
164   GetCrossingPoint(GetLastRow(),xyz);
165   SetLastPoint(xyz[0],xyz[1],xyz[2]);
166   //printf("last point %f %f %f\n",xyz[0],xyz[1],xyz[2]);
167 }
168
169 void AliL3HoughTrack::SetTrackParameters(Double_t kappa,Double_t eangle,Int_t weight)
170 {
171
172   fWeight = weight;
173   fMinDist = 100000;
174   SetKappa(kappa);
175   Double_t pt = fabs(BFACT*AliL3Transform::GetBField()/kappa);
176   SetPt(pt);
177   Double_t radius = 1/fabs(kappa);
178   SetRadius(radius);
179   SetFirstPoint(0,0,0);
180   SetPsi(eangle); //Psi = emission angle when first point is vertex
181   SetPhi0(0);     //not defined for vertex reference point
182   SetR0(0);
183   Double_t charge = -1.*kappa;
184   SetCharge((Int_t)copysign(1.,charge));
185   Double_t trackPhi0 = GetPsi() + charge*0.5*AliL3Transform::Pi()/fabs(charge);
186   Double_t xc = GetFirstPointX() - GetRadius() * cos(trackPhi0) ;
187   Double_t yc = GetFirstPointY() - GetRadius() * sin(trackPhi0) ;
188   SetCenterX(xc);
189   SetCenterY(yc);
190   SetNHits(1); //just for the trackarray IO
191   fIsHelix = true;
192 }
193
194 void AliL3HoughTrack::SetLineParameters(Double_t psi,Double_t D,Int_t weight,Int_t *rowrange,Int_t ref_row)
195 {
196   //Initialize a track piece, not yet a track
197   //Used in case of straight line transformation
198
199   //Transform line parameters to coordinate system of slice:
200   
201   //  D = D + fTransform->Row2X(ref_row)*cos(psi);
202
203   fDLine = D;
204   fPsiLine = psi;
205   fWeight = weight;
206   SetNHits(1);
207   SetRowRange(rowrange[0],rowrange[1]);
208   fIsHelix = false;
209
210 }
211
212 void AliL3HoughTrack::SetBestMCid(Int_t mcid,Double_t min_dist)
213 {
214   
215   if(min_dist < fMinDist)
216     {
217       fMinDist = min_dist;
218       SetMCid(mcid);
219     }
220   
221 }
222
223 void AliL3HoughTrack::GetLineCrossingPoint(Int_t padrow,Float_t *xy)
224 {
225   
226   if(fIsHelix)
227     {
228       printf("AliL3HoughTrack::GetLineCrossingPoint : Track is not a line\n");
229       return;
230     }
231
232   Float_t xhit = AliL3Transform::Row2X(padrow) - AliL3Transform::Row2X(GetFirstRow());
233   Float_t a = -1/tan(fPsiLine);
234   Float_t b = fDLine/sin(fPsiLine);
235   Float_t yhit = a*xhit + b;
236   xy[0] = xhit;
237   xy[1] = yhit;
238
239 }
240