]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliExternalTrackParam.cxx
Added methods for finding a given module in the DDL map (F. Prino)
[u/mrichter/AliRoot.git] / STEER / AliExternalTrackParam.cxx
index dde326a83bb9fd0c8c094546d6288ba15e8d09d9..eeb599e21776a8b5927aba7d592eb1dcc6d77d13 100644 (file)
@@ -28,6 +28,7 @@
 #include <TMatrixDSym.h>
 #include "AliExternalTrackParam.h"
 #include "AliESDVertex.h"
+#include "TPolyMarker3D.h"
 #include "AliLog.h"
 
 ClassImp(AliExternalTrackParam)
@@ -201,8 +202,8 @@ Double_t AliExternalTrackParam::GetLinearD(Double_t xv,Double_t yv) const {
 }
 
 Bool_t AliExternalTrackParam::CorrectForMeanMaterial
-(Double_t xOverX0,  Double_t xTimesRho, Double_t mass, 
-Double_t (*Bethe)(Double_t)) {
+(Double_t xOverX0,  Double_t xTimesRho, Double_t mass, Bool_t anglecorr, 
+ Double_t (*Bethe)(Double_t)) {
   //------------------------------------------------------------------
   // This function corrects the track parameters for the crossed material.
   // "xOverX0"   - X/X0, the thickness in units of the radiation length.
@@ -218,6 +219,13 @@ Double_t (*Bethe)(Double_t)) {
   Double_t &fC43=fC[13];
   Double_t &fC44=fC[14];
 
+  //Apply angle correction, if requested
+  if(anglecorr) {
+    Double_t angle=TMath::Sqrt((1.+ fP3*fP3)/(1.- fP2*fP2));
+    xOverX0 *=angle;
+    xTimesRho *=angle;
+  } 
+
   Double_t p=GetP();
   Double_t p2=p*p;
   Double_t beta2=p2/(p2 + mass*mass);
@@ -309,6 +317,8 @@ Double_t ApproximateBetheBloch(Double_t beta2) {
   // the density effect taken into account at beta*gamma > 3.5
   // (the approximation is reasonable only for solid materials) 
   //------------------------------------------------------------------
+  if (beta2 >= 1) return kVeryBig;
+
   if (beta2/(1-beta2)>3.5*3.5)
      return 0.153e-3/beta2*(log(3.5*5940)+0.5*log(beta2/(1-beta2)) - beta2);
 
@@ -640,6 +650,40 @@ PropagateTo(Double_t p[3],Double_t covyz[3],Double_t covxyz[3],Double_t bz) {
   return kTRUE;  
 }
 
+Double_t *AliExternalTrackParam::GetResiduals(
+Double_t *p,Double_t *cov,Bool_t updated) const {
+  //------------------------------------------------------------------
+  // Returns the track residuals with the space point "p" having
+  // the covariance matrix "cov".
+  // If "updated" is kTRUE, the track parameters expected to be updated,
+  // otherwise they must be predicted.  
+  //------------------------------------------------------------------
+  static Double_t res[2];
+
+  Double_t r00=cov[0], r01=cov[1], r11=cov[2];
+  if (updated) {
+     r00-=fC[0]; r01-=fC[1]; r11-=fC[2];
+  } else {
+     r00+=fC[0]; r01+=fC[1]; r11+=fC[2];
+  }
+  Double_t det=r00*r11 - r01*r01;
+
+  if (TMath::Abs(det) < kAlmost0) return 0;
+
+  Double_t tmp=r00; r00=r11/det; r11=tmp/det;
+
+  if (r00 < 0.) return 0;
+  if (r11 < 0.) return 0;
+
+  Double_t dy = fP[0] - p[0];
+  Double_t dz = fP[1] - p[1];
+
+  res[0]=dy*TMath::Sqrt(r00);
+  res[1]=dz*TMath::Sqrt(r11);
+
+  return res;
+}
+
 Bool_t AliExternalTrackParam::Update(Double_t p[2], Double_t cov[3]) {
   //------------------------------------------------------------------
   // Update the track parameters with the space point "p" having
@@ -861,11 +905,10 @@ PropagateToDCA(AliExternalTrackParam *p, Double_t b) {
 }
 
 
-
-
-Bool_t AliExternalTrackParam::PropagateToDCA(const AliESDVertex *vtx, Double_t b, Double_t maxd){
+Bool_t AliExternalTrackParam::PropagateToDCA(const AliESDVertex *vtx, 
+Double_t b, Double_t maxd, Double_t dz[2], Double_t covar[3]) {
   //
-  // Try to relate this track to the vertex "vtx", 
+  // Propagate this track to the DCA to vertex "vtx", 
   // if the (rough) transverse impact parameter is not bigger then "maxd". 
   //            Magnetic field is "b" (kG).
   //
@@ -879,7 +922,7 @@ Bool_t AliExternalTrackParam::PropagateToDCA(const AliESDVertex *vtx, Double_t b
   Double_t sn=TMath::Sin(alpha), cs=TMath::Cos(alpha);
   Double_t x=GetX(), y=GetParameter()[0], snp=GetParameter()[2];
   Double_t xv= vtx->GetXv()*cs + vtx->GetYv()*sn;
-  Double_t yv=-vtx->GetXv()*sn + vtx->GetYv()*cs;
+  Double_t yv=-vtx->GetXv()*sn + vtx->GetYv()*cs, zv=vtx->GetZv();
   x-=xv; y-=yv;
 
   //Estimate the impact parameter neglecting the track curvature
@@ -887,65 +930,37 @@ Bool_t AliExternalTrackParam::PropagateToDCA(const AliESDVertex *vtx, Double_t b
   if (d > maxd) return kFALSE; 
 
   //Propagate to the DCA
-  Double_t crv=0.299792458e-3*b*GetParameter()[4];
+  Double_t crv=kB2C*b*GetParameter()[4];
+  if (TMath::Abs(b) < kAlmost0Field) crv=0.;
+
   Double_t tgfv=-(crv*x - snp)/(crv*y + TMath::Sqrt(1.-snp*snp));
   sn=tgfv/TMath::Sqrt(1.+ tgfv*tgfv); cs=TMath::Sqrt(1.- sn*sn);
+  if (TMath::Abs(tgfv)>0.) cs = sn/tgfv;
+  else cs=1.;
 
   x = xv*cs + yv*sn;
   yv=-xv*sn + yv*cs; xv=x;
 
   if (!Propagate(alpha+TMath::ASin(sn),xv,b)) return kFALSE;
-  return kTRUE;
-}
-
-
 
+  if (dz==0) return kTRUE;
+  dz[0] = GetParameter()[0] - yv;
+  dz[1] = GetParameter()[1] - zv;
+  
+  if (covar==0) return kTRUE;
+  Double_t cov[6]; vtx->GetCovMatrix(cov);
 
-Bool_t Local2GlobalMomentum(Double_t p[3],Double_t alpha) {
-  //----------------------------------------------------------------
-  // This function performs local->global transformation of the
-  // track momentum.
-  // When called, the arguments are:
-  //    p[0] = 1/pt of the track;
-  //    p[1] = sine of local azim. angle of the track momentum;
-  //    p[2] = tangent of the track momentum dip angle;
-  //   alpha - rotation angle. 
-  // The result is returned as:
-  //    p[0] = px
-  //    p[1] = py
-  //    p[2] = pz
-  // Results for (nearly) straight tracks are meaningless !
-  //----------------------------------------------------------------
-  if (TMath::Abs(p[0])<=kAlmost0) return kFALSE;
-  if (TMath::Abs(p[1])> kAlmost1) return kFALSE;
-
-  Double_t pt=1./TMath::Abs(p[0]);
-  Double_t cs=TMath::Cos(alpha), sn=TMath::Sin(alpha);
-  Double_t r=TMath::Sqrt(1 - p[1]*p[1]);
-  p[0]=pt*(r*cs - p[1]*sn); p[1]=pt*(p[1]*cs + r*sn); p[2]=pt*p[2];
+  //***** Improvements by A.Dainese
+  alpha=GetAlpha(); sn=TMath::Sin(alpha); cs=TMath::Cos(alpha);
+  Double_t s2ylocvtx = cov[0]*sn*sn + cov[2]*cs*cs - 2.*cov[1]*cs*sn;
+  covar[0] = GetCovariance()[0] + s2ylocvtx;   // neglecting correlations
+  covar[1] = GetCovariance()[1];               // between (x,y) and z
+  covar[2] = GetCovariance()[2] + cov[5];      // in vertex's covariance matrix
+  //*****
 
   return kTRUE;
 }
 
-Bool_t Local2GlobalPosition(Double_t r[3],Double_t alpha) {
-  //----------------------------------------------------------------
-  // This function performs local->global transformation of the
-  // track position.
-  // When called, the arguments are:
-  //    r[0] = local x
-  //    r[1] = local y
-  //    r[2] = local z
-  //   alpha - rotation angle. 
-  // The result is returned as:
-  //    r[0] = global x
-  //    r[1] = global y
-  //    r[2] = global z
-  //----------------------------------------------------------------
-  Double_t cs=TMath::Cos(alpha), sn=TMath::Sin(alpha), x=r[0];
-  r[0]=x*cs - r[1]*sn; r[1]=x*sn + r[1]*cs;
-
-  return kTRUE;
-}
 
 void AliExternalTrackParam::GetDirection(Double_t d[3]) const {
   //----------------------------------------------------------------
@@ -961,7 +976,7 @@ void AliExternalTrackParam::GetDirection(Double_t d[3]) const {
   d[2]=fP[3]/norm;
 }
 
-Bool_t AliExternalTrackParam::GetPxPyPz(Double_t *p) const {
+Bool_t AliExternalTrackParam::GetPxPyPz(Double_t p[3]) const {
   //---------------------------------------------------------------------
   // This function returns the global track momentum components
   // Results for (nearly) straight tracks are meaningless !
@@ -971,45 +986,91 @@ Bool_t AliExternalTrackParam::GetPxPyPz(Double_t *p) const {
 }
 
 Double_t AliExternalTrackParam::Px() const {
-  // return x-component of momentum
+  //---------------------------------------------------------------------
+  // Returns x-component of momentum
+  // Result for (nearly) straight tracks is meaningless !
+  //---------------------------------------------------------------------
 
-  Double_t p[3];
+  Double_t p[3]={kVeryBig,kVeryBig,kVeryBig};
   GetPxPyPz(p);
 
   return p[0];
 }
 
 Double_t AliExternalTrackParam::Py() const {
-  // return y-component of momentum
+  //---------------------------------------------------------------------
+  // Returns y-component of momentum
+  // Result for (nearly) straight tracks is meaningless !
+  //---------------------------------------------------------------------
 
-  Double_t p[3];
+  Double_t p[3]={kVeryBig,kVeryBig,kVeryBig};
   GetPxPyPz(p);
 
   return p[1];
 }
 
 Double_t AliExternalTrackParam::Pz() const {
-  // return z-component of momentum
+  //---------------------------------------------------------------------
+  // Returns z-component of momentum
+  // Result for (nearly) straight tracks is meaningless !
+  //---------------------------------------------------------------------
 
-  Double_t p[3];
+  Double_t p[3]={kVeryBig,kVeryBig,kVeryBig};
   GetPxPyPz(p);
 
   return p[2];
 }
 
+Double_t AliExternalTrackParam::Xv() const {
+  //---------------------------------------------------------------------
+  // Returns x-component of first track point
+  //---------------------------------------------------------------------
+
+  Double_t r[3]={0.,0.,0.};
+  GetXYZ(r);
+
+  return r[0];
+}
+
+Double_t AliExternalTrackParam::Yv() const {
+  //---------------------------------------------------------------------
+  // Returns y-component of first track point
+  //---------------------------------------------------------------------
+
+  Double_t r[3]={0.,0.,0.};
+  GetXYZ(r);
+
+  return r[1];
+}
+
+Double_t AliExternalTrackParam::Zv() const {
+  //---------------------------------------------------------------------
+  // Returns z-component of first track point
+  //---------------------------------------------------------------------
+
+  Double_t r[3]={0.,0.,0.};
+  GetXYZ(r);
+
+  return r[2];
+}
+
 Double_t AliExternalTrackParam::Theta() const {
   // return theta angle of momentum
 
-  return TMath::ATan2(Pt(), Pz());
+  return 0.5*TMath::Pi() - TMath::ATan(fP[3]);
 }
 
 Double_t AliExternalTrackParam::Phi() const {
-  // return phi angle of momentum
-
-  Double_t p[3];
-  GetPxPyPz(p);
+  //---------------------------------------------------------------------
+  // Returns the azimuthal angle of momentum
+  // 0 <= phi < 2*pi
+  //---------------------------------------------------------------------
 
-  return TMath::ATan2(p[1], p[0]);
+  Double_t phi=TMath::ASin(fP[2]) + fAlpha;
+  if (phi<0.) phi+=2.*TMath::Pi();
+  else if (phi>=2.*TMath::Pi()) phi-=2.*TMath::Pi();
+  return phi;
 }
 
 Double_t AliExternalTrackParam::M() const {
@@ -1213,3 +1274,77 @@ Double_t AliExternalTrackParam::GetSnpAt(Double_t x,Double_t b) const {
   Double_t res = fP[2]+dx*crv;
   return res;
 }
+
+Bool_t AliExternalTrackParam::GetDistance(AliExternalTrackParam *param2, Double_t x, Double_t dist[3], Double_t bz){
+  //------------------------------------------------------------------------
+  // Get the distance between two tracks at the local position x 
+  // working in the local frame of this track.
+  // Origin :   Marian.Ivanov@cern.ch
+  //-----------------------------------------------------------------------
+  Double_t xyz[3];
+  Double_t xyz2[3];
+  xyz[0]=x;
+  if (!GetYAt(x,bz,xyz[1])) return kFALSE;
+  if (!GetZAt(x,bz,xyz[2])) return kFALSE;
+  //  
+  //
+  if (TMath::Abs(GetAlpha()-param2->GetAlpha())<kAlmost0){
+    xyz2[0]=x;
+    if (!param2->GetYAt(x,bz,xyz2[1])) return kFALSE;
+    if (!param2->GetZAt(x,bz,xyz2[2])) return kFALSE;
+  }else{
+    //
+    Double_t xyz1[3];
+    Double_t dfi = param2->GetAlpha()-GetAlpha();
+    Double_t ca = TMath::Cos(dfi), sa = TMath::Sin(dfi);
+    xyz2[0] =  xyz[0]*ca+xyz[1]*sa;
+    xyz2[1] = -xyz[0]*sa+xyz[1]*ca;
+    //
+    xyz1[0]=xyz2[0];
+    if (!param2->GetYAt(xyz2[0],bz,xyz1[1])) return kFALSE;
+    if (!param2->GetZAt(xyz2[0],bz,xyz1[2])) return kFALSE;
+    //
+    xyz2[0] =  xyz1[0]*ca-xyz1[1]*sa;
+    xyz2[1] = +xyz1[0]*sa+xyz1[1]*ca;
+    xyz2[2] = xyz1[2];
+  }
+  dist[0] = xyz[0]-xyz2[0];
+  dist[1] = xyz[1]-xyz2[1];
+  dist[2] = xyz[2]-xyz2[2];
+
+  return kTRUE;
+}
+
+
+//
+// Draw functionality.
+// Origin: Marian Ivanov, Marian.Ivanov@cern.ch
+//
+
+void  AliExternalTrackParam::DrawTrack(Float_t magf, Float_t minR, Float_t maxR, Float_t stepR){
+  //
+  // Draw track line
+  //
+  if (minR>maxR) return ;
+  if (stepR<=0) return ;
+  Int_t npoints = TMath::Nint((maxR-minR)/stepR)+1;
+  if (npoints<1) return;
+  TPolyMarker3D *polymarker = new TPolyMarker3D(npoints);
+  FillPolymarker(polymarker, magf,minR,maxR,stepR);
+  polymarker->Draw();
+}
+
+//
+void AliExternalTrackParam::FillPolymarker(TPolyMarker3D *pol, Float_t magF, Float_t minR, Float_t maxR, Float_t stepR){
+  //
+  // Fill points in the polymarker
+  //
+  Int_t counter=0;
+  for (Double_t r=minR; r<maxR; r+=stepR){
+    Double_t point[3];
+    GetXYZAt(r,magF,point);
+    pol->SetPoint(counter,point[0],point[1], point[2]);
+    printf("xyz\t%f\t%f\t%f\n",point[0], point[1],point[2]);
+    counter++;
+  }
+}