adding map include file to solve compilation issue (bug https://savannah.cern.ch...
[u/mrichter/AliRoot.git] / HLT / ITS / tracking / AliHLTITSTrack.cxx
CommitLineData
2f399afc 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
133288b9 44ClassImp(AliHLTITSTrack)
2f399afc 45
46//____________________________________________________________________________
47AliHLTITSTrack::AliHLTITSTrack() :
6edb0fb5 48 AliKalmanTrack(),
49 fExpQ(40),
50 fTPCtrackId(0)
2f399afc 51{
52 for(Int_t i=0; i<2*AliITSgeomTGeo::kNLayers; i++) {fIndex[i]=-1; }
53}
54
55//____________________________________________________________________________
56AliHLTITSTrack::AliHLTITSTrack(const AliHLTITSTrack& t) :
6edb0fb5 57 AliKalmanTrack(t),
58 fExpQ(t.fExpQ),
59 fTPCtrackId( t.fTPCtrackId)
2f399afc 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//____________________________________________________________________________
73AliHLTITSTrack &AliHLTITSTrack::operator=(const AliHLTITSTrack& t)
74{
75 //------------------------------------------------------------------
76 //Copy constructor
77 //------------------------------------------------------------------
6edb0fb5 78 *(AliKalmanTrack*)this = t;
2f399afc 79 fExpQ = t.fExpQ;
6edb0fb5 80 fTPCtrackId = t.fTPCtrackId;
2f399afc 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;
133288b9 87 return *this;
2f399afc 88}
89
90
91//____________________________________________________________________________
92AliHLTITSTrack::AliHLTITSTrack(AliESDtrack& t,Bool_t c) throw (const Char_t *) :
93 AliKalmanTrack(),
6edb0fb5 94 fExpQ(40),
95 fTPCtrackId( 0 )
2f399afc 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());
6edb0fb5 109 //SetMass(t.GetMass());
2f399afc 110 SetNumberOfClusters(t.GetITSclusters(fIndex));
6edb0fb5 111}
2f399afc 112
6edb0fb5 113//____________________________________________________________________________
114AliHLTITSTrack::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);
2f399afc 128}
129
6edb0fb5 130
2f399afc 131Double_t AliHLTITSTrack::GetPredictedChi2(const AliCluster* c) const
132{
133 return GetPredictedChi2(c->GetY(), c->GetZ(), c->GetSigmaY2(), c->GetSigmaZ2() );
134}
135
136Double_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
149Int_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//____________________________________________________________________________
173void 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
2f399afc 182
183
184
185//____________________________________________________________________________
186
187
188//____________________________________________________________________________
189Bool_t AliHLTITSTrack::
190GetGlobalXYZat(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
ef6e2aa2 200Bool_t AliHLTITSTrack::GetLocalYZat(Double_t xloc, Double_t &y, Double_t &z) const
201{
202 // local YZ at x
203 Double_t dx=xloc - GetX();
204 Double_t f1=GetSnp(), f2=f1 + dx*GetC( GetBz() );
205 if (TMath::Abs(f1) >= kAlmost1) return kFALSE;
206 if (TMath::Abs(f2) >= kAlmost1) return kFALSE;
207 Double_t r1=TMath::Sqrt((1.-f1)*(1.+f1)), r2=TMath::Sqrt((1.-f2)*(1.+f2));
208 y = GetY() + dx*(f1+f2)/(r1+r2);
209 z = GetZ() + dx*(r2 + f2*(f1+f2)/(r1+r2))*GetTgl();
210 return 1;
211}
2f399afc 212
213//____________________________________________________________________________
214Bool_t AliHLTITSTrack::PropagateTo(Double_t xk, Double_t d, Double_t x0) {
215 //------------------------------------------------------------------
216 //This function propagates a track
217 //------------------------------------------------------------------
218
219 Double_t oldX=GetX(), oldY=GetY(), oldZ=GetZ();
220
221 Double_t bz=GetBz();
222 if (!AliExternalTrackParam::PropagateTo(xk,bz)) return kFALSE;
223 Double_t xOverX0,xTimesRho;
224 xOverX0 = d; xTimesRho = d*x0;
225 if (!CorrectForMeanMaterial(xOverX0,xTimesRho,kTRUE)) return kFALSE;
226
227 Double_t x=GetX(), y=GetY(), z=GetZ();
228 if (IsStartedTimeIntegral() && x>oldX) {
229 Double_t l2 = (x-oldX)*(x-oldX) + (y-oldY)*(y-oldY) + (z-oldZ)*(z-oldZ);
230 AddTimeStep(TMath::Sqrt(l2));
231 }
232
233 return kTRUE;
234}
235
236//____________________________________________________________________________
237Bool_t AliHLTITSTrack::PropagateToTGeo(Double_t xToGo, Int_t nstep, Double_t &xOverX0, Double_t &xTimesRho, Bool_t addTime) {
238 //-------------------------------------------------------------------
239 // Propagates the track to a reference plane x=xToGo in n steps.
240 // These n steps are only used to take into account the curvature.
241 // The material is calculated with TGeo. (L.Gaudichet)
242 //-------------------------------------------------------------------
ef6e2aa2 243
2f399afc 244 Double_t startx = GetX(), starty = GetY(), startz = GetZ();
245 Double_t sign = (startx<xToGo) ? -1.:1.;
246 Double_t step = (xToGo-startx)/TMath::Abs(nstep);
247
248 Double_t start[3], end[3], mparam[7], bz = GetBz();
249 Double_t x = startx;
250
251 for (Int_t i=0; i<nstep; i++) {
252
253 GetXYZ(start); //starting global position
254 x += step;
255 if (!GetXYZAt(x, bz, end)) return kFALSE;
256 if (!AliExternalTrackParam::PropagateTo(x, bz)) return kFALSE;
257 AliTracker::MeanMaterialBudget(start, end, mparam);
258 xTimesRho = sign*mparam[4]*mparam[0];
259 xOverX0 = mparam[1];
260 if (mparam[1]<900000) {
261 if (!AliExternalTrackParam::CorrectForMeanMaterial(xOverX0,
262 xTimesRho,GetMass())) return kFALSE;
263 } else { // this happens when MeanMaterialBudget cannot cross a boundary
264 return kFALSE;
265 }
266 }
267
268 if (addTime && IsStartedTimeIntegral() && GetX()>startx) {
269 Double_t l2 = ( (GetX()-startx)*(GetX()-startx) +
270 (GetY()-starty)*(GetY()-starty) +
271 (GetZ()-startz)*(GetZ()-startz) );
272 AddTimeStep(TMath::Sqrt(l2));
273 }
274
275 return kTRUE;
276}
277
278//____________________________________________________________________________
279Bool_t AliHLTITSTrack::Update(const AliCluster* c, Double_t chi2, Int_t index)
280{
281 //------------------------------------------------------------------
282 //This function updates track parameters
283 //------------------------------------------------------------------
284 Double_t p[2]={c->GetY(), c->GetZ()};
285 Double_t cov[3]={c->GetSigmaY2(), 0., c->GetSigmaZ2()};
286
287 if (!AliExternalTrackParam::Update(p,cov)) return kFALSE;
288
289 Int_t n=GetNumberOfClusters();
290
291 if (chi2<0) return kTRUE;
292
2f399afc 293 fIndex[n]=index;
294 SetNumberOfClusters(n+1);
295 SetChi2(GetChi2()+chi2);
296
297 return kTRUE;
298}
299
300
301
302//____________________________________________________________________________
303Bool_t AliHLTITSTrack::Propagate(Double_t alp,Double_t xk) {
304 //------------------------------------------------------------------
305 //This function propagates a track
306 //------------------------------------------------------------------
307 Double_t bz=GetBz();
308 if (!AliExternalTrackParam::Propagate(alp,xk,bz)) return kFALSE;
309
310 return kTRUE;
311}
312
313
314
315
316
317//____________________________________________________________________________
318Bool_t AliHLTITSTrack::
319GetPhiZat(Double_t r, Double_t &phi, Double_t &z) const {
320 //------------------------------------------------------------------
321 // This function returns the global cylindrical (phi,z) of the track
322 // position estimated at the radius r.
323 // The track curvature is neglected.
324 //------------------------------------------------------------------
325 Double_t d=GetD(0.,0.);
326 if (TMath::Abs(d) > r) {
327 if (r>1e-1) return kFALSE;
328 r = TMath::Abs(d);
329 }
330
331 Double_t rcurr=TMath::Sqrt(GetX()*GetX() + GetY()*GetY());
332 if (TMath::Abs(d) > rcurr) return kFALSE;
333 Double_t globXYZcurr[3]; GetXYZ(globXYZcurr);
334 Double_t phicurr=TMath::ATan2(globXYZcurr[1],globXYZcurr[0]);
335
336 if (GetX()>=0.) {
337 phi=phicurr+TMath::ASin(d/r)-TMath::ASin(d/rcurr);
338 } else {
339 phi=phicurr+TMath::ASin(d/r)+TMath::ASin(d/rcurr)-TMath::Pi();
340 }
341
342 // return a phi in [0,2pi[
343 if (phi<0.) phi+=2.*TMath::Pi();
344 else if (phi>=2.*TMath::Pi()) phi-=2.*TMath::Pi();
345 z=GetZ()+GetTgl()*(TMath::Sqrt((r-d)*(r+d))-TMath::Sqrt((rcurr-d)*(rcurr+d)));
346 return kTRUE;
347}
348
349//____________________________________________________________________________
350Bool_t AliHLTITSTrack::
ef6e2aa2 351GetLocalXPhiZat(Double_t r,Double_t &xloc, double &phi, double &z ) const
352{
353 // This function returns the local x of the track position estimated at the radius r.
2f399afc 354
ef6e2aa2 355 double s = GetSnp();
356 double c = 1-s*s;
357 if( c<kAlmost0 ) return 0;
358 c = TMath::Sqrt(c);
359 double k = GetC( GetBz() );
2f399afc 360
ef6e2aa2 361 double xc = GetX()*k - s; // center of the circle * curvature
362 double yc = GetY()*k + c;
363 double l2 = xc*xc + yc*yc;
2f399afc 364
ef6e2aa2 365 if( l2<kAlmost0 ) return 0; // the track is curved and the center is close to (0,0)
366
367 // a = (r^2+ l2/k^2 -1/k^2)/2 * k
368 double r2 = r*r;
369 double a = k*(r2 + GetX()*GetX() + GetY()*GetY())/2 + GetY()*c - GetX()*s;
370 double d = r2*l2-a*a;
371 if( d<kAlmost0 ) return 0; // no intersection
372
373 xloc = ( a*xc + yc*TMath::Sqrt(d) )/l2;
374
375 // transport to xloc
376
377 Double_t dx = xloc - GetX();
378
379 Double_t f1=s, f2= s + k*dx;
380 if (TMath::Abs(f2) >= kAlmost1) return kFALSE;
381
bfd20868 382 Double_t c2=TMath::Sqrt((1.-f2)*(1.+f2));
ef6e2aa2 383
384 double yloc = GetY() + dx*(f1+f2)/(c+c2);
385 double zloc = GetZ() + dx*(c2 + f2*(f1+f2)/(c+c2))*GetTgl();
386
387 phi = GetAlpha() + TMath::ATan2(yloc, xloc);
388
389 // return the phi in [0,2pi]
390 phi -= ( (int) (phi/TMath::TwoPi()) )*TMath::TwoPi();
391 z = zloc;
392
393 return 1;
394}
395
396
397Bool_t AliHLTITSTrack::GetYZAtPhiX( double phi, double x,
398 double &y, double&z, double &snp, double cov[3] ) const
399{
400 double bz = GetBz();
401 AliExternalTrackParam t(*this);
ef6e2aa2 402
b54a5088 403 // check for the angle to suppress call of AliError() in AliExternalTrackParam::Rotate()
404 {
405 double da = phi - GetAlpha();
406 Double_t ca=TMath::Cos(da), sa=TMath::Sin(da);
bfd20868 407 Double_t sf=GetSnp(), cf=TMath::Sqrt((1.-sf)*(1.+sf));
b54a5088 408 Double_t tmp=sf*ca - cf*sa;
409 if (TMath::Abs(tmp) >= kAlmost1) return 0;
410 }
ef6e2aa2 411
b54a5088 412 if (!t.Rotate(phi)) return 0;
ef6e2aa2 413 if (!t.PropagateTo(x,bz)) return 0;
414
415 y = t.GetY();
416 z = t.GetZ();
417 snp = t.GetSnp();
418 if( t.GetSigmaY2()<0 || t.GetSigmaZ2()<=0 ) return 0;
419
420 cov[0] = t.GetCovariance()[0];
421 cov[1] = t.GetCovariance()[1];
422 cov[2] = t.GetCovariance()[2];
423 return 1;
2f399afc 424}