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