Addons for html documentation
[u/mrichter/AliRoot.git] / HLT / src / AliL3Track.cxx
CommitLineData
108615fc 1//Author: Anders Strand Vestbo
2//Author: Uli Frankenfeld
3//Last Modified: 06.03.2001
4
5//____________________________________
6// AliL3Track
7//
8// Base track class for L3
9
10//Changes:
11
12//14.03.01: Moved fHitNumbers from protected to private.-ASV
13// Set memory to zero in ctor.
14// Moved fNHits 2 private. Protected data members not a good idea after all.
15//19.03.01: Made the method void Set(AliL3Track) virtual.
16
17#include "AliL3RootTypes.h"
18
0391971c 19#include "AliL3Defs.h"
108615fc 20#include "AliL3Logging.h"
21#include "AliL3Track.h"
0391971c 22#include "AliL3Transform.h"
108615fc 23#include <math.h>
24
0391971c 25
108615fc 26ClassImp(AliL3Track)
27
28Float_t AliL3Track::BFACT = 0.0029980;
29Float_t AliL3Track::bField = 0.2;
30Double_t AliL3Track::pi=3.14159265358979323846;
31
32AliL3Track::AliL3Track()
33{
34 //Constructor
35
36 fNHits = 0;
37 fMCid = -1;
38 fKappa=0;
39 fRadius=0;
40 fCenterX=0;
41 fCenterY=0;
42 ComesFromMainVertex(false);
43 fQ = 0;
44 fPhi0=0;
45 fPsi=0;
46 fR0=0;
47 fTanl=0;
48 fZ0=0;
49 fPt=0;
50 fLength=0;
51 fIsLocal=true;
52 fRowRange[0]=0;
53 fRowRange[1]=0;
ae97a0b9 54 memset(fHitNumbers,0,176*sizeof(UInt_t));
108615fc 55}
56
57void AliL3Track::Set(AliL3Track *tpt){
58
3a735e00 59 SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
60 SetPhi0(tpt->GetPhi0());
61 SetKappa(tpt->GetKappa());
62 SetNHits(tpt->GetNHits());
63 SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
64 SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
65 SetPt(tpt->GetPt());
66 SetPsi(tpt->GetPsi());
67 SetTgl(tpt->GetTgl());
68 SetCharge(tpt->GetCharge());
69 SetHits(tpt->GetNHits(),(UInt_t *)tpt->GetHitNumbers());
108615fc 70
108615fc 71}
72
203925a9 73Int_t AliL3Track::Compare(const AliL3Track *track) const
74{
75 if(track->GetNHits() < GetNHits()) return 1;
76 if(track->GetNHits() > GetNHits()) return -1;
77 return 0;
78}
108615fc 79
80AliL3Track::~AliL3Track()
81{
203925a9 82 //Nothing to do
108615fc 83}
84
85Double_t AliL3Track::GetP() const
86{
203925a9 87 // Returns total momentum.
108615fc 88 return fabs(GetPt())*sqrt(1. + GetTgl()*GetTgl());
89
90}
91
92Double_t AliL3Track::GetPseudoRapidity() const
93{
94 return 0.5 * log((GetP() + GetPz()) / (GetP() - GetPz()));
95}
203925a9 96/*
108615fc 97Double_t AliL3Track::GetEta() const
98{
99 return GetPseudoRapidity();
100}
203925a9 101*/
108615fc 102Double_t AliL3Track::GetRapidity() const
103{
104 Double_t m_pi = 0.13957;
105 return 0.5 * log((m_pi + GetPz()) / (m_pi - GetPz()));
106}
107
203925a9 108void AliL3Track::Rotate(Int_t slice,Bool_t tolocal)
0391971c 109{
0391971c 110 //Rotate track to global parameters
203925a9 111 //If flag tolocal is set, the track is rotated
112 //to local coordinates.
0391971c 113
114 AliL3Transform *transform = new AliL3Transform();
115
116 Float_t psi[1] = {GetPsi()};
203925a9 117 if(!tolocal)
118 transform->Local2GlobalAngle(psi,slice);
119 else
120 transform->Global2LocalAngle(psi,slice);
0391971c 121 SetPsi(psi[0]);
122 Float_t first[3];
123 first[0] = GetFirstPointX();
124 first[1] = GetFirstPointY();
125 first[2] = GetFirstPointZ();
203925a9 126 if(!tolocal)
127 transform->Local2Global(first,slice);
128 else
129 transform->Global2Local(first,slice,kTRUE);
130
0391971c 131 SetFirstPoint(first[0],first[1],first[2]);
132 Float_t last[3];
133 last[0] = GetLastPointX();
134 last[1] = GetLastPointY();
135 last[2] = GetLastPointZ();
203925a9 136 if(!tolocal)
137 transform->Local2Global(last,slice);
138 else
139 transform->Global2Local(last,slice,kTRUE);
0391971c 140 SetLastPoint(last[0],last[1],last[2]);
203925a9 141
142 if(!tolocal)
143 fIsLocal=kFALSE;
144 else
145 fIsLocal=kTRUE;
0391971c 146 delete transform;
147}
148
108615fc 149void AliL3Track::CalculateHelix(){
150 //Calculate Radius, CenterX and Centery from Psi, X0, Y0
151 //
152
153 fRadius = fPt / (BFACT*bField);
154 if(fRadius) fKappa = 1./fRadius;
155 else fRadius = 999999; //just zero
156 Double_t trackPhi0 = fPsi + fQ *0.5 * pi;
157
158 fCenterX = fFirstPoint[0] - fRadius * cos(trackPhi0);
159 fCenterY = fFirstPoint[1] - fRadius * sin(trackPhi0);
160}
161
0391971c 162Double_t AliL3Track::GetCrossingAngle(Int_t padrow)
163{
164 //Calculate the crossing angle between track and given padrow.
165
166 if(!IsLocal())
167 {
168 printf("Track is not given in local coordinates\n");
169 return 0;
170 }
171
172 Float_t xyz[3];
173 if(!GetCrossingPoint(padrow,xyz))
174 printf("AliL3HoughTrack::GetCrossingPoint : Track does not cross line!!\n");
175
176 //Take the dot product of the tangent vector of the track, and
177 //vector perpendicular to the padrow.
178
179 Double_t tangent[2];
180 tangent[1] = (xyz[0] - GetCenterX())/GetRadius();
181 tangent[0] = -1.*(xyz[1] - GetCenterY())/GetRadius();
182
183 Double_t perp_padrow[2] = {1,0}; //locally in slice
184
185 Double_t cos_beta = fabs(tangent[0]*perp_padrow[0] + tangent[1]*perp_padrow[1]);
186 return acos(cos_beta);
187
188}
189
190Bool_t AliL3Track::GetCrossingPoint(Int_t padrow,Float_t *xyz)
191{
192 //Assumes the track is given in local coordinates
193
194 AliL3Transform *transform = new AliL3Transform();
195 if(!IsLocal())
196 {
197 printf("GetCrossingPoint: Track is given on global coordinates\n");
198 return false;
199 }
200
201 Double_t xHit = transform->Row2X(padrow);
202
203 xyz[0] = xHit;
204 Double_t aa = (xHit - GetCenterX())*(xHit - GetCenterX());
205 Double_t r2 = GetRadius()*GetRadius();
206 if(aa > r2)
207 return false;
208
209 Double_t aa2 = sqrt(r2 - aa);
210 Double_t y1 = GetCenterY() + aa2;
211 Double_t y2 = GetCenterY() - aa2;
212 xyz[1] = y1;
213 if(fabs(y2) < fabs(y1)) xyz[1] = y2;
214
215 Double_t yHit = xyz[1];
216 Double_t angle1 = atan2((yHit - GetCenterY()),(xHit - GetCenterX()));
217 if(angle1 < 0) angle1 += 2.*Pi;
218 Double_t angle2 = atan2((GetFirstPointY() - GetCenterY()),(GetFirstPointX() - GetCenterX()));
219 if(angle2 < 0) angle2 += 2.*Pi;
220 Double_t diff_angle = angle1 - angle2;
221 diff_angle = fmod(diff_angle,2*Pi);
222 if((GetCharge()*diff_angle) > 0) diff_angle = diff_angle - GetCharge()*2.*Pi;
223 Double_t s_tot = fabs(diff_angle)*GetRadius();
224 Double_t zHit = GetFirstPointZ() + s_tot*GetTgl();
225 xyz[2] = zHit;
226
227 delete transform;
228 return true;
229}
230
231
108615fc 232Bool_t AliL3Track::CalculateReferencePoint(Double_t angle){
233 // Global coordinate: crossing point with y = ax+ b; a=tan(angle-Pi/2);
234 //
235 const Double_t rr=132; //position of referece plane
236 const Double_t xr = cos(angle) *rr;
237 const Double_t yr = sin(angle) *rr;
238
239 Double_t a = tan(angle-pi/2);
240 Double_t b = yr - a * xr;
241
242 Double_t pp=(fCenterX+a*fCenterY-a*b)/(1+pow(a,2));
243 Double_t qq=(pow(fCenterX,2)+pow(fCenterY,2)-2*fCenterY*b+pow(b,2)-pow(fRadius,2))/(1+pow(a,2));
244
245 Double_t racine = pp*pp-qq;
246 if(racine<0) return IsPoint(kFALSE); //no Point
247
248 Double_t rootRacine = sqrt(racine);
249 Double_t x0 = pp+rootRacine;
250 Double_t x1 = pp-rootRacine;
251 Double_t y0 = a*x0 + b;
252 Double_t y1 = a*x1 + b;
253
254 Double_t diff0 = sqrt(pow(x0-xr,2)+pow(y0-yr,2));
255 Double_t diff1 = sqrt(pow(x1-xr,2)+pow(y1-yr,2));
256
257 if(diff0<diff1){
258 fPoint[0]=x0;
259 fPoint[1]=y0;
260 }
261 else{
262 fPoint[0]=x1;
263 fPoint[1]=y1;
264 }
265
266 Double_t pointPhi0 = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
267 Double_t trackPhi0 = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
268 if(fabs(trackPhi0-pointPhi0)>pi){
269 if(trackPhi0<pointPhi0) trackPhi0 += 2*pi;
270 else pointPhi0 += 2*pi;
271 }
272 Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
273 fPoint[2] = fFirstPoint[2] + stot * fTanl;
274
275 fPointPsi = pointPhi0 - fQ * 0.5 * pi;
276 if(fPointPsi<0.) fPointPsi+= 2*pi;
277 fPointPsi = fmod(fPointPsi, 2*pi);
278
279 return IsPoint(kTRUE);
280}
281
282Bool_t AliL3Track::CalculateEdgePoint(Double_t angle){
283 // Global coordinate: crossing point with y = ax; a=tan(angle);
284 //
285 Double_t rmin=80; //min Radius of TPC
286 Double_t rmax=260; //max Radius of TPC
287
288 Double_t a = tan(angle);
289 Double_t pp=(fCenterX+a*fCenterY)/(1+pow(a,2));
290 Double_t qq=(pow(fCenterX,2)+pow(fCenterY,2)-pow(fRadius,2))/(1+pow(a,2));
291 Double_t racine = pp*pp-qq;
292 if(racine<0) return IsPoint(kFALSE); //no Point
293 Double_t rootRacine = sqrt(racine);
294 Double_t x0 = pp+rootRacine;
295 Double_t x1 = pp-rootRacine;
296 Double_t y0 = a*x0;
297 Double_t y1 = a*x1;
298
299 Double_t r0 = sqrt(pow(x0,2)+pow(y0,2));
300 Double_t r1 = sqrt(pow(x1,2)+pow(y1,2));
301 //find the right crossing point:
302 //inside the TPC modules
303 Bool_t ok0 = kFALSE;
304 Bool_t ok1 = kFALSE;
472d9e24 305
108615fc 306 if(r0>rmin&&r0<rmax){
307 Double_t da=atan2(y0,x0);
472d9e24 308 if(da<0) da+=2*pi;
108615fc 309 if(fabs(da-angle)<0.5)
310 ok0 = kTRUE;
311 }
312 if(r1>rmin&&r1<rmax){
472d9e24 313 Double_t da=atan2(y1,x1);
314 if(da<0) da+=2*pi;
108615fc 315 if(fabs(da-angle)<0.5)
316 ok1 = kTRUE;
317 }
318 if(!(ok0||ok1)) return IsPoint(kFALSE); //no Point
319
320 if(ok0&&ok1){
321 Double_t diff0 = sqrt(pow(fFirstPoint[0]-x0,2)+pow(fFirstPoint[1]-y0,2));
322 Double_t diff1 = sqrt(pow(fFirstPoint[0]-x1,2)+pow(fFirstPoint[1]-y1,2));
323 if(diff0<diff1) ok1 = kFALSE; //use ok0
324 else ok0 = kFALSE; //use ok1
325 }
326 if(ok0){fPoint[0]=x0; fPoint[1]=y0;}
327 else {fPoint[0]=x1; fPoint[1]=y1;}
328
329 Double_t pointPhi0 = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
330 Double_t trackPhi0 = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
331 if(fabs(trackPhi0-pointPhi0)>pi){
332 if(trackPhi0<pointPhi0) trackPhi0 += 2*pi;
333 else pointPhi0 += 2*pi;
334 }
335 Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
336 fPoint[2] = fFirstPoint[2] + stot * fTanl;
337
338 fPointPsi = pointPhi0 - fQ * 0.5 * pi;
339 if(fPointPsi<0.) fPointPsi+= 2*pi;
340 fPointPsi = fmod(fPointPsi, 2*pi);
341
342 return IsPoint(kTRUE);
343}
344
345Bool_t AliL3Track::CalculatePoint(Double_t xplane){
346 // Local coordinate: crossing point with x plane
347 //
348 Double_t racine = pow(fRadius,2)-pow(xplane-fCenterX,2);
349 if(racine<0) return IsPoint(kFALSE);
350 Double_t rootRacine = sqrt(racine);
351
352 Double_t y0 = fCenterY + rootRacine;
353 Double_t y1 = fCenterY - rootRacine;
354 //Double_t diff0 = sqrt(pow(fFirstPoint[0]-xplane)+pow(fFirstPoint[1]-y0));
355 //Double_t diff1 = sqrt(pow(fFirstPoint[0]-xplane)+pow(fFirstPoint[1]-y1));
356 Double_t diff0 = fabs(y0-fFirstPoint[1]);
357 Double_t diff1 = fabs(y1-fFirstPoint[1]);
358
359 fPoint[0]=xplane;
360 if(diff0<diff1) fPoint[1]=y0;
361 else fPoint[1]=y1;
362
363 Double_t pointPhi0 = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
364 Double_t trackPhi0 = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
365 if(fabs(trackPhi0-pointPhi0)>pi){
366 if(trackPhi0<pointPhi0) trackPhi0 += 2*pi;
367 else pointPhi0 += 2*pi;
368 }
369 Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
370 fPoint[2] = fFirstPoint[2] + stot * fTanl;
371
372 fPointPsi = pointPhi0 - fQ * 0.5 * pi;
373 if(fPointPsi<0.) fPointPsi+= 2*pi;
374 fPointPsi = fmod(fPointPsi, 2*pi);
375
376 return IsPoint(kTRUE);
377}
378