]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/ITS/tracking/AliHLTITSTrack.cxx
bugfix (partially) #54670
[u/mrichter/AliRoot.git] / HLT / ITS / tracking / AliHLTITSTrack.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 //-------------------------------------------------------------------------
17 //                Implementation of the ITS track class
18 //
19 //          Origin: Marian Ivanov, CERN, Marian.Ivanov@cern.ch
20 //     dEdx analysis by: Boris Batyunya, JINR, Boris.Batiounia@cern.ch
21 //-------------------------------------------------------------------------
22
23 /* $Id: AliHLTITSTrack.cxx 30856 2009-02-02 11:12:50Z fca $ */
24
25 #include <TMatrixD.h>
26
27 #include <TMath.h>
28
29 #include "AliCluster.h"
30 #include "AliESDtrack.h"
31 #include "AliITSgeomTGeo.h"
32 #include "AliHLTITSTrack.h"
33 #include "AliTracker.h"
34 #include <TMath.h>
35
36 #include "AliCluster.h"
37 #include "AliESDtrack.h"
38 #include "AliESDVertex.h"
39 #include "AliITSReconstructor.h"
40 #include "AliITStrackV2.h"
41 #include "AliTracker.h"
42
43
44 ClassImp(AliHLTITSTrack)
45
46 //____________________________________________________________________________
47 AliHLTITSTrack::AliHLTITSTrack() : 
48   AliKalmanTrack(),  
49   fExpQ(40),
50   fTPCtrackId(0)
51 {
52   for(Int_t i=0; i<2*AliITSgeomTGeo::kNLayers; i++) {fIndex[i]=-1; }
53 }
54
55 //____________________________________________________________________________
56 AliHLTITSTrack::AliHLTITSTrack(const AliHLTITSTrack& t) : 
57   AliKalmanTrack(t),  
58   fExpQ(t.fExpQ),
59   fTPCtrackId( t.fTPCtrackId)
60 {
61   //------------------------------------------------------------------
62   //Copy constructor
63   //------------------------------------------------------------------
64   Int_t i;
65   for (i=0; i<2*AliITSgeomTGeo::GetNLayers(); i++) {
66     fIndex[i]=t.fIndex[i];
67   }
68   fLab = t.fLab;
69   fFakeRatio = t.fFakeRatio;
70 }
71
72 //____________________________________________________________________________
73 AliHLTITSTrack &AliHLTITSTrack::operator=(const AliHLTITSTrack& t)
74 {
75   //------------------------------------------------------------------
76   //Copy constructor
77   //------------------------------------------------------------------
78   *(AliKalmanTrack*)this = t;  
79   fExpQ = t.fExpQ;
80   fTPCtrackId = t.fTPCtrackId;
81   Int_t i;
82   for (i=0; i<2*AliITSgeomTGeo::GetNLayers(); i++) {
83     fIndex[i]=t.fIndex[i];
84   }
85   fLab = t.fLab;
86   fFakeRatio = t.fFakeRatio;
87   return *this;
88 }
89
90
91 //____________________________________________________________________________
92 AliHLTITSTrack::AliHLTITSTrack(AliESDtrack& t,Bool_t c) throw (const Char_t *) :
93   AliKalmanTrack(),
94   fExpQ(40),
95   fTPCtrackId( 0 )
96 {
97   //------------------------------------------------------------------
98   // Conversion ESD track -> ITS track.
99   // If c==kTRUE, create the ITS track out of the constrained params.
100   //------------------------------------------------------------------
101   const AliExternalTrackParam *par=&t;
102   if (c) {
103     par=t.GetConstrainedParam();
104     if (!par) throw "AliHLTITSTrack: conversion failed !\n";
105   }
106   Set(par->GetX(),par->GetAlpha(),par->GetParameter(),par->GetCovariance());
107
108   SetLabel(t.GetLabel());
109   //SetMass(t.GetMass());
110   SetNumberOfClusters(t.GetITSclusters(fIndex));
111 }
112
113 //____________________________________________________________________________
114 AliHLTITSTrack::AliHLTITSTrack(AliExternalTrackParam& t ) throw (const Char_t *) :
115   AliKalmanTrack(),  
116   fExpQ(40),
117   fTPCtrackId( 0 )
118 {
119   //------------------------------------------------------------------
120   // Conversion ESD track -> ITS track.
121   // If c==kTRUE, create the ITS track out of the constrained params.
122   //------------------------------------------------------------------
123   const AliExternalTrackParam *par=&t;
124   Set(par->GetX(),par->GetAlpha(),par->GetParameter(),par->GetCovariance());
125   SetLabel(t.GetLabel());
126   //SetMass(t.GetMass());
127   SetNumberOfClusters(0);
128 }
129
130
131 Double_t AliHLTITSTrack::GetPredictedChi2(const AliCluster* c) const
132 {
133   return GetPredictedChi2(c->GetY(), c->GetZ(), c->GetSigmaY2(), c->GetSigmaZ2() );
134 }
135
136 Double_t AliHLTITSTrack::GetPredictedChi2(Double_t cy, Double_t cz, Double_t cerr2Y, Double_t cerr2Z) const
137 {
138   //-----------------------------------------------------------------
139   // This function calculates a predicted chi2 increment.
140   //-----------------------------------------------------------------
141   Double_t p[2]={cy, cz};
142   Double_t cov[3]={cerr2Y, 0., cerr2Z};
143   return AliExternalTrackParam::GetPredictedChi2(p,cov);
144 }
145
146
147
148
149 Int_t AliHLTITSTrack::GetProlongationFast(Double_t alp, Double_t xk,Double_t &y, Double_t &z)
150 {
151   //-----------------------------------------------------------------------------
152   //get fast prolongation 
153   //-----------------------------------------------------------------------------
154   Double_t ca=TMath::Cos(alp-GetAlpha()), sa=TMath::Sin(alp-GetAlpha());
155   Double_t cf=TMath::Sqrt((1.-GetSnp())*(1.+GetSnp()));  
156   // **** rotation **********************  
157   y= -GetX()*sa + GetY()*ca;
158   // **** translation ******************  
159   Double_t dx = xk- GetX()*ca - GetY()*sa;
160   Double_t f1=GetSnp()*ca - cf*sa, f2=f1 + GetC()*dx;
161   if (TMath::Abs(f2) >= 0.9999) {
162     return 0;
163   }
164   Double_t r1=TMath::Sqrt((1.-f1)*(1.+f1)), r2=TMath::Sqrt((1.-f2)*(1.+f2));  
165   y += dx*(f1+f2)/(r1+r2);
166   z  = GetZ()+dx*(f1+f2)/(f1*r2 + f2*r1)*GetTgl();  
167   return 1;
168 }
169
170
171
172 //____________________________________________________________________________
173 void AliHLTITSTrack::ResetClusters() {
174   //------------------------------------------------------------------
175   // Reset the array of attached clusters.
176   //------------------------------------------------------------------
177   for (Int_t i=0; i<2*AliITSgeomTGeo::kNLayers; i++) fIndex[i]=-1;
178   SetChi2(0.); 
179   SetNumberOfClusters(0);
180
181
182
183
184
185 //____________________________________________________________________________
186
187
188 //____________________________________________________________________________
189 Bool_t AliHLTITSTrack::
190 GetGlobalXYZat(Double_t xloc, Double_t &x, Double_t &y, Double_t &z) const {
191   //------------------------------------------------------------------
192   //This function returns a track position in the global system
193   //------------------------------------------------------------------
194   Double_t r[3];
195   Bool_t rc=GetXYZAt(xloc, GetBz(), r);
196   x=r[0]; y=r[1]; z=r[2]; 
197   return rc;
198 }
199
200
201 //____________________________________________________________________________
202 Bool_t AliHLTITSTrack::PropagateTo(Double_t xk, Double_t d, Double_t x0) {
203   //------------------------------------------------------------------
204   //This function propagates a track
205   //------------------------------------------------------------------
206
207   Double_t oldX=GetX(), oldY=GetY(), oldZ=GetZ();
208   
209   Double_t bz=GetBz();
210   if (!AliExternalTrackParam::PropagateTo(xk,bz)) return kFALSE;
211   Double_t xOverX0,xTimesRho; 
212   xOverX0 = d; xTimesRho = d*x0;
213   if (!CorrectForMeanMaterial(xOverX0,xTimesRho,kTRUE)) return kFALSE;
214
215   Double_t x=GetX(), y=GetY(), z=GetZ();
216   if (IsStartedTimeIntegral() && x>oldX) {
217     Double_t l2 = (x-oldX)*(x-oldX) + (y-oldY)*(y-oldY) + (z-oldZ)*(z-oldZ);
218     AddTimeStep(TMath::Sqrt(l2));
219   }
220
221   return kTRUE;
222 }
223
224 //____________________________________________________________________________
225 Bool_t AliHLTITSTrack::PropagateToTGeo(Double_t xToGo, Int_t nstep, Double_t &xOverX0, Double_t &xTimesRho, Bool_t addTime) {
226   //-------------------------------------------------------------------
227   //  Propagates the track to a reference plane x=xToGo in n steps.
228   //  These n steps are only used to take into account the curvature.
229   //  The material is calculated with TGeo. (L.Gaudichet)
230   //-------------------------------------------------------------------
231   
232   Double_t startx = GetX(), starty = GetY(), startz = GetZ();
233   Double_t sign = (startx<xToGo) ? -1.:1.;
234   Double_t step = (xToGo-startx)/TMath::Abs(nstep);
235
236   Double_t start[3], end[3], mparam[7], bz = GetBz();
237   Double_t x = startx;
238   
239   for (Int_t i=0; i<nstep; i++) {
240     
241     GetXYZ(start);   //starting global position
242     x += step;
243     if (!GetXYZAt(x, bz, end)) return kFALSE;
244     if (!AliExternalTrackParam::PropagateTo(x, bz)) return kFALSE;
245     AliTracker::MeanMaterialBudget(start, end, mparam);
246     xTimesRho = sign*mparam[4]*mparam[0];
247     xOverX0   = mparam[1];
248     if (mparam[1]<900000) {
249       if (!AliExternalTrackParam::CorrectForMeanMaterial(xOverX0,
250                                                          xTimesRho,GetMass())) return kFALSE;
251     } else { // this happens when MeanMaterialBudget cannot cross a boundary
252       return kFALSE;
253     }
254   }
255
256   if (addTime && IsStartedTimeIntegral() && GetX()>startx) {
257     Double_t l2 = ( (GetX()-startx)*(GetX()-startx) +
258                     (GetY()-starty)*(GetY()-starty) +
259                     (GetZ()-startz)*(GetZ()-startz) );
260     AddTimeStep(TMath::Sqrt(l2));
261   }
262
263   return kTRUE;
264 }
265
266 //____________________________________________________________________________
267 Bool_t AliHLTITSTrack::Update(const AliCluster* c, Double_t chi2, Int_t index) 
268 {
269   //------------------------------------------------------------------
270   //This function updates track parameters
271   //------------------------------------------------------------------
272   Double_t p[2]={c->GetY(), c->GetZ()};
273   Double_t cov[3]={c->GetSigmaY2(), 0., c->GetSigmaZ2()};
274
275   if (!AliExternalTrackParam::Update(p,cov)) return kFALSE;
276
277   Int_t n=GetNumberOfClusters();
278
279   if (chi2<0) return kTRUE;
280
281   fIndex[n]=index;
282   SetNumberOfClusters(n+1);
283   SetChi2(GetChi2()+chi2);
284
285   return kTRUE;
286 }
287
288
289
290 //____________________________________________________________________________
291 Bool_t AliHLTITSTrack::Propagate(Double_t alp,Double_t xk) {
292   //------------------------------------------------------------------
293   //This function propagates a track
294   //------------------------------------------------------------------
295   Double_t bz=GetBz();
296   if (!AliExternalTrackParam::Propagate(alp,xk,bz)) return kFALSE;
297
298   return kTRUE;
299 }
300
301
302
303
304
305 //____________________________________________________________________________
306 Bool_t AliHLTITSTrack::
307 GetPhiZat(Double_t r, Double_t &phi, Double_t &z) const {
308   //------------------------------------------------------------------
309   // This function returns the global cylindrical (phi,z) of the track 
310   // position estimated at the radius r. 
311   // The track curvature is neglected.
312   //------------------------------------------------------------------
313   Double_t d=GetD(0.,0.);
314   if (TMath::Abs(d) > r) {
315     if (r>1e-1) return kFALSE;
316     r = TMath::Abs(d);
317   }
318
319   Double_t rcurr=TMath::Sqrt(GetX()*GetX() + GetY()*GetY());
320   if (TMath::Abs(d) > rcurr) return kFALSE;
321   Double_t globXYZcurr[3]; GetXYZ(globXYZcurr); 
322   Double_t phicurr=TMath::ATan2(globXYZcurr[1],globXYZcurr[0]);
323
324   if (GetX()>=0.) {
325     phi=phicurr+TMath::ASin(d/r)-TMath::ASin(d/rcurr);
326   } else {
327     phi=phicurr+TMath::ASin(d/r)+TMath::ASin(d/rcurr)-TMath::Pi();
328   }
329
330   // return a phi in [0,2pi[ 
331   if (phi<0.) phi+=2.*TMath::Pi();
332   else if (phi>=2.*TMath::Pi()) phi-=2.*TMath::Pi();
333   z=GetZ()+GetTgl()*(TMath::Sqrt((r-d)*(r+d))-TMath::Sqrt((rcurr-d)*(rcurr+d)));
334   return kTRUE;
335 }
336
337 //____________________________________________________________________________
338 Bool_t AliHLTITSTrack::
339 GetLocalXat(Double_t r,Double_t &xloc) const {
340   //------------------------------------------------------------------
341   // This function returns the local x of the track 
342   // position estimated at the radius r. 
343   // The track curvature is neglected.
344   //------------------------------------------------------------------
345   Double_t d=GetD(0.,0.);
346   if (TMath::Abs(d) > r) { 
347     if (r>1e-1) return kFALSE; 
348     r = TMath::Abs(d); 
349   } 
350
351   Double_t rcurr=TMath::Sqrt(GetX()*GetX() + GetY()*GetY());
352   Double_t globXYZcurr[3]; GetXYZ(globXYZcurr); 
353   Double_t phicurr=TMath::ATan2(globXYZcurr[1],globXYZcurr[0]);
354   Double_t phi;
355   if (GetX()>=0.) {
356     phi=phicurr+TMath::ASin(d/r)-TMath::ASin(d/rcurr);
357   } else {
358     phi=phicurr+TMath::ASin(d/r)+TMath::ASin(d/rcurr)-TMath::Pi();
359   }
360
361   xloc=r*(TMath::Cos(phi)*TMath::Cos(GetAlpha())
362          +TMath::Sin(phi)*TMath::Sin(GetAlpha())); 
363
364   return kTRUE;
365 }