]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/src/AliL3Track.cxx
added the delete of EMCAL object posted in the folder when new file is opened
[u/mrichter/AliRoot.git] / HLT / src / AliL3Track.cxx
1 //$Id$
2
3 // Author: Anders Vestbo <mailto:vestbo$fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>
4 //*-- Copyright &copy ASV
5
6 #include "AliL3StandardIncludes.h"
7
8 #include "AliL3RootTypes.h"
9 #include "AliL3Logging.h"
10 #include "AliL3Track.h"
11 #include "AliL3Transform.h"
12 #include "AliL3Vertex.h"
13
14
15 //_____________________________________________________________
16 // AliL3Track
17 //
18 // Track base class
19 //Begin_Html
20 /*
21 <img src="track_coordinates.gif">
22 */
23 //End_Html
24
25 ClassImp(AliL3Track)
26
27 Float_t AliL3Track::BFACT = 0.0029980;
28 Double_t AliL3Track::pi=3.14159265358979323846;
29
30 AliL3Track::AliL3Track()
31 {
32   //Constructor
33
34   fNHits = 0;
35   fMCid = -1;
36   fKappa=0;
37   fRadius=0;
38   fCenterX=0;
39   fCenterY=0;
40   ComesFromMainVertex(false);
41   fQ = 0;
42   fPhi0=0;
43   fPsi=0;
44   fR0=0;
45   fTanl=0;
46   fZ0=0;
47   fPt=0;
48   fLength=0;
49   fIsLocal=true;
50   fRowRange[0]=0;
51   fRowRange[1]=0;
52   memset(fHitNumbers,0,159*sizeof(UInt_t));
53 }
54
55 void AliL3Track::Set(AliL3Track *tpt){
56   
57   SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
58   SetPhi0(tpt->GetPhi0());
59   SetKappa(tpt->GetKappa());
60   SetNHits(tpt->GetNHits());
61   SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
62   SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
63   SetPt(tpt->GetPt());
64   SetPsi(tpt->GetPsi());
65   SetTgl(tpt->GetTgl());
66   SetCharge(tpt->GetCharge());
67   SetHits(tpt->GetNHits(),(UInt_t *)tpt->GetHitNumbers());
68 #ifdef do_mc
69   SetMCid(tpt->GetMCid());
70 #endif
71 }
72
73 Int_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 }
79
80 AliL3Track::~AliL3Track()
81 {
82   //Nothing to do
83 }
84
85 Double_t AliL3Track::GetP() const
86 {
87   // Returns total momentum.  
88   return fabs(GetPt())*sqrt(1. + GetTgl()*GetTgl());
89 }
90
91 Double_t AliL3Track::GetPseudoRapidity() const
92 {
93   return 0.5 * log((GetP() + GetPz()) / (GetP() - GetPz()));
94 }
95
96 /*
97 Double_t AliL3Track::GetEta() const
98 {
99   return GetPseudoRapidity();
100 }
101 */
102
103 Double_t AliL3Track::GetRapidity() const
104 {
105   Double_t m_pi = 0.13957;
106   return 0.5 * log((m_pi + GetPz()) / (m_pi - GetPz()));
107 }
108
109 void AliL3Track::Rotate(Int_t slice,Bool_t tolocal)
110 {
111   //Rotate track to global parameters
112   //If flag tolocal is set, the track is rotated
113   //to local coordinates.
114
115   
116   Float_t psi[1] = {GetPsi()};
117   if(!tolocal)
118     AliL3Transform::Local2GlobalAngle(psi,slice);
119   else
120     AliL3Transform::Global2LocalAngle(psi,slice);
121   SetPsi(psi[0]);
122   Float_t first[3];
123   first[0] = GetFirstPointX();
124   first[1] = GetFirstPointY();
125   first[2] = GetFirstPointZ();
126   if(!tolocal)
127     AliL3Transform::Local2Global(first,slice);
128   else
129     AliL3Transform::Global2Local(first,slice,kTRUE);
130   
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();
136   if(!tolocal)
137     AliL3Transform::Local2Global(last,slice);
138   else
139     AliL3Transform::Global2Local(last,slice,kTRUE);
140   SetLastPoint(last[0],last[1],last[2]);
141   
142   Float_t center[3] = {GetCenterX(),GetCenterY(),0};
143   if(!tolocal)
144     AliL3Transform::Local2Global(center,slice);
145   else
146     AliL3Transform::Global2Local(center,slice,kTRUE);
147   SetCenterX(center[0]);
148   SetCenterY(center[1]);
149   
150   if(!tolocal)
151     fIsLocal=kFALSE;
152   else
153     fIsLocal=kTRUE;
154 }
155
156 void AliL3Track::CalculateHelix(){
157   //Calculate Radius, CenterX and CenterY from Psi, X0, Y0
158   //
159   
160   fRadius = fPt / (BFACT*AliL3Transform::GetBField());
161   if(fRadius) fKappa = -fQ*1./fRadius;
162   else fRadius = 999999;  //just zero
163   Double_t trackPhi0 = fPsi + fQ *0.5 * pi;
164
165   fCenterX = fFirstPoint[0] - fRadius *  cos(trackPhi0);
166   fCenterY = fFirstPoint[1] - fRadius *  sin(trackPhi0);
167 }
168
169 Double_t AliL3Track::GetCrossingAngle(Int_t padrow) 
170 {
171   //Calculate the crossing angle between track and given padrow.
172   
173   if(!IsLocal())
174     {
175       printf("Track is not given in local coordinates\n");
176       return 0;
177     }
178   
179   Float_t xyz[3];
180   if(!GetCrossingPoint(padrow,xyz))
181     printf("AliL3HoughTrack::GetCrossingPoint : Track does not cross line!!\n");
182   
183   //Take the dot product of the tangent vector of the track, and
184   //vector perpendicular to the padrow.
185   //In order to do this, we need the tangent vector to the track at the
186   //point. This is done by rotating the radius vector by 90 degrees;
187   //rotation matrix: (  0  1 )
188   //                 ( -1  0 )
189   
190   Double_t tangent[2];
191   tangent[0] = -1.*(xyz[1] - GetCenterY())/GetRadius();
192   tangent[1] = (xyz[0] - GetCenterX())/GetRadius();
193   
194   Double_t perp_padrow[2] = {1,0}; //locally in slice
195   
196   Double_t cos_beta = fabs(tangent[0]*perp_padrow[0] + tangent[1]*perp_padrow[1]);
197   if(cos_beta > 1) cos_beta=1;
198   return acos(cos_beta);
199 }
200
201 Bool_t AliL3Track::GetCrossingPoint(Int_t padrow,Float_t *xyz) 
202 {
203   //Assumes the track is given in local coordinates
204
205   if(!IsLocal())
206     {
207       printf("GetCrossingPoint: Track is given on global coordinates\n");
208       return false;
209     }
210   
211   Double_t xHit = AliL3Transform::Row2X(padrow);
212
213   xyz[0] = xHit;
214   Double_t aa = (xHit - GetCenterX())*(xHit - GetCenterX());
215   Double_t r2 = GetRadius()*GetRadius();
216   if(aa > r2)
217     return false;
218
219   Double_t aa2 = sqrt(r2 - aa);
220   Double_t y1 = GetCenterY() + aa2;
221   Double_t y2 = GetCenterY() - aa2;
222   xyz[1] = y1;
223   if(fabs(y2) < fabs(y1)) xyz[1] = y2;
224   
225   Double_t yHit = xyz[1];
226   Double_t angle1 = atan2((yHit - GetCenterY()),(xHit - GetCenterX()));
227   if(angle1 < 0) angle1 += 2.*AliL3Transform::Pi();
228   Double_t angle2 = atan2((GetFirstPointY() - GetCenterY()),(GetFirstPointX() - GetCenterX()));
229   if(angle2 < 0) angle2 += 2.*AliL3Transform::Pi();
230   Double_t diff_angle = angle1 - angle2;
231   diff_angle = fmod(diff_angle,2*AliL3Transform::Pi());
232   if((GetCharge()*diff_angle) > 0) diff_angle = diff_angle - GetCharge()*2.*AliL3Transform::Pi();
233   Double_t s_tot = fabs(diff_angle)*GetRadius();
234   Double_t zHit = GetFirstPointZ() + s_tot*GetTgl();
235   xyz[2] = zHit;
236   
237   return true;
238 }
239
240
241 Bool_t AliL3Track::CalculateReferencePoint(Double_t angle,Double_t radius){
242   // Global coordinate: crossing point with y = ax+ b; a=tan(angle-AliL3Transform::Pi()/2);
243   //
244   const Double_t rr=radius;//132; //position of reference plane
245   const Double_t xr = cos(angle) * rr;
246   const Double_t yr = sin(angle) * rr;
247   
248   Double_t a = tan(angle-pi/2);
249   Double_t b = yr - a * xr;
250
251   Double_t pp=(fCenterX+a*fCenterY-a*b)/(1+pow(a,2));
252   Double_t qq=(pow(fCenterX,2)+pow(fCenterY,2)-2*fCenterY*b+pow(b,2)-pow(fRadius,2))/(1+pow(a,2));
253
254   Double_t racine = pp*pp-qq;
255   if(racine<0) return IsPoint(kFALSE);      //no Point
256
257   Double_t rootRacine = sqrt(racine);
258   Double_t x0 = pp+rootRacine;
259   Double_t x1 = pp-rootRacine;
260   Double_t y0 = a*x0 + b;
261   Double_t y1 = a*x1 + b;
262
263   Double_t diff0 = sqrt(pow(x0-xr,2)+pow(y0-yr,2));
264   Double_t diff1 = sqrt(pow(x1-xr,2)+pow(y1-yr,2));
265  
266   if(diff0<diff1){
267     fPoint[0]=x0;
268     fPoint[1]=y0;
269   }
270   else{
271     fPoint[0]=x1;
272     fPoint[1]=y1;
273   }
274
275   Double_t pointPhi0  = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
276   Double_t trackPhi0  = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
277   if(fabs(trackPhi0-pointPhi0)>pi){
278     if(trackPhi0<pointPhi0) trackPhi0 += 2*pi;
279     else                    pointPhi0 += 2*pi;
280   }
281   Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
282   fPoint[2]   = fFirstPoint[2] + stot * fTanl;
283
284   fPointPsi = pointPhi0 - fQ * 0.5 * pi;
285   if(fPointPsi<0.)  fPointPsi+= 2*pi;
286   fPointPsi = fmod(fPointPsi, 2*pi);
287
288   return IsPoint(kTRUE);
289 }
290
291 Bool_t AliL3Track::CalculateEdgePoint(Double_t angle){
292   // Global coordinate: crossing point with y = ax; a=tan(angle);
293   //
294   Double_t rmin=AliL3Transform::Row2X(AliL3Transform::GetFirstRow(-1));  //min Radius of TPC
295   Double_t rmax=AliL3Transform::Row2X(AliL3Transform::GetLastRow(-1)); //max Radius of TPC
296
297   Double_t a = tan(angle);
298   Double_t pp=(fCenterX+a*fCenterY)/(1+pow(a,2));
299   Double_t qq=(pow(fCenterX,2)+pow(fCenterY,2)-pow(fRadius,2))/(1+pow(a,2));
300   Double_t racine = pp*pp-qq;
301   if(racine<0) return IsPoint(kFALSE);     //no Point
302   Double_t rootRacine = sqrt(racine);
303   Double_t x0 = pp+rootRacine;
304   Double_t x1 = pp-rootRacine;
305   Double_t y0 = a*x0;
306   Double_t y1 = a*x1;
307
308   Double_t r0 = sqrt(pow(x0,2)+pow(y0,2));
309   Double_t r1 = sqrt(pow(x1,2)+pow(y1,2)); 
310   //find the right crossing point:
311   //inside the TPC modules
312   Bool_t ok0 = kFALSE;
313   Bool_t ok1 = kFALSE;
314
315   if(r0>rmin&&r0<rmax){
316     Double_t da=atan2(y0,x0);
317     if(da<0) da+=2*pi;
318     if(fabs(da-angle)<0.5)
319       ok0 = kTRUE;
320   }
321   if(r1>rmin&&r1<rmax){
322     Double_t da=atan2(y1,x1);
323     if(da<0) da+=2*pi;
324     if(fabs(da-angle)<0.5)
325       ok1 = kTRUE;
326   }
327   if(!(ok0||ok1)) return IsPoint(kFALSE);   //no Point
328   
329   if(ok0&&ok1){
330     Double_t diff0 = sqrt(pow(fFirstPoint[0]-x0,2)+pow(fFirstPoint[1]-y0,2));
331     Double_t diff1 = sqrt(pow(fFirstPoint[0]-x1,2)+pow(fFirstPoint[1]-y1,2));
332     if(diff0<diff1) ok1 = kFALSE; //use ok0
333     else ok0 = kFALSE;            //use ok1
334   }
335   if(ok0){fPoint[0]=x0; fPoint[1]=y0;}
336   else   {fPoint[0]=x1; fPoint[1]=y1;}
337
338   Double_t pointPhi0  = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
339   Double_t trackPhi0  = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
340   if(fabs(trackPhi0-pointPhi0)>pi){
341     if(trackPhi0<pointPhi0) trackPhi0 += 2*pi;
342     else                    pointPhi0 += 2*pi;
343   }
344   Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;
345   fPoint[2]   = fFirstPoint[2] + stot * fTanl;
346
347   fPointPsi = pointPhi0 - fQ * 0.5 * pi;
348   if(fPointPsi<0.)  fPointPsi+= 2*pi;
349   fPointPsi = fmod(fPointPsi, 2*pi);
350
351   return IsPoint(kTRUE);
352 }
353
354 Bool_t AliL3Track::CalculatePoint(Double_t xplane){
355   // Local coordinate: crossing point with x plane
356   //
357   Double_t racine = pow(fRadius,2)-pow(xplane-fCenterX,2);
358   if(racine<0) return IsPoint(kFALSE);
359   Double_t rootRacine = sqrt(racine);
360
361   Double_t y0 = fCenterY + rootRacine;
362   Double_t y1 = fCenterY - rootRacine;
363   //Double_t diff0 = sqrt(pow(fFirstPoint[0]-xplane)+pow(fFirstPoint[1]-y0));
364   //Double_t diff1 = sqrt(pow(fFirstPoint[0]-xplane)+pow(fFirstPoint[1]-y1));
365   Double_t diff0 = fabs(y0-fFirstPoint[1]);
366   Double_t diff1 = fabs(y1-fFirstPoint[1]);
367
368   fPoint[0]=xplane;
369   if(diff0<diff1) fPoint[1]=y0;
370   else            fPoint[1]=y1;
371
372   Double_t pointPhi0  = atan2(fPoint[1]-fCenterY,fPoint[0]-fCenterX);
373   Double_t trackPhi0  = atan2(fFirstPoint[1]-fCenterY,fFirstPoint[0]-fCenterX);
374   if(fabs(trackPhi0-pointPhi0)>pi){
375     if(trackPhi0<pointPhi0) trackPhi0 += 2*pi;
376     else                    pointPhi0 += 2*pi;
377   }
378   Double_t stot = -fQ * (pointPhi0-trackPhi0) * fRadius ;  
379   fPoint[2]   = fFirstPoint[2] + stot * fTanl;
380
381   fPointPsi = pointPhi0 - fQ * 0.5 * pi;
382   if(fPointPsi<0.)  fPointPsi+= 2*pi;
383   fPointPsi = fmod(fPointPsi, 2*pi);
384
385   return IsPoint(kTRUE);
386 }
387
388 void AliL3Track::GetClosestPoint(AliL3Vertex *vertex,Double_t &closest_x,Double_t &closest_y,Double_t &closest_z)
389 {
390   //Calculate the point of closest approach to the vertex
391   
392   
393   Double_t xc = GetCenterX() - vertex->GetX();//Shift the center of curvature with respect to the vertex
394   Double_t yc = GetCenterY() - vertex->GetY();
395   
396   Double_t dist_x1 = xc*(1 + GetRadius()/sqrt(xc*xc + yc*yc));
397   Double_t dist_y1 = yc*(1 + GetRadius()/sqrt(xc*xc + yc*yc));
398   Double_t distance1 = sqrt(dist_x1*dist_x1 + dist_y1*dist_y1);
399   
400   Double_t dist_x2 = xc*(1 - GetRadius()/sqrt(xc*xc + yc*yc));
401   Double_t dist_y2 = yc*(1 - GetRadius()/sqrt(xc*xc + yc*yc));
402   Double_t distance2 = sqrt(dist_x2*dist_x2 + dist_y2*dist_y2);
403   
404   //Choose the closest:
405   if(distance1 < distance2)
406     {
407       closest_x = dist_x1 + vertex->GetX();
408       closest_y = dist_y1 + vertex->GetY();
409     }
410   else
411     {
412       closest_x = dist_x2 + vertex->GetX();
413       closest_y = dist_y2 + vertex->GetY();
414     }
415   
416   //Get the z coordinate:
417   Double_t angle1 = atan2((closest_y-GetCenterY()),(closest_x-GetCenterX()));
418   if(angle1 < 0) angle1 = angle1 + 2*AliL3Transform::Pi();
419  
420   Double_t angle2 = atan2((GetFirstPointY()-GetCenterY()),(GetFirstPointX()-GetCenterX()));
421   if(angle2 < 0) angle2 = angle2 + 2*AliL3Transform::Pi();
422   
423   Double_t diff_angle = angle1 - angle2;
424   diff_angle = fmod(diff_angle,2*AliL3Transform::Pi());
425   
426   if((GetCharge()*diff_angle) < 0) diff_angle = diff_angle + GetCharge()*2*AliL3Transform::Pi();
427   Double_t s_tot = fabs(diff_angle)*GetRadius();
428   
429   closest_z = GetFirstPointZ() - s_tot*GetTgl();
430 }