BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TrkDifPoca.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: TrkDifPoca.cxx,v 1.1.1.1 2005/04/21 06:01:42 zhangy Exp $
4//
5// Description:
6//
7//
8// Environment:
9// Software developed for the BaBar Detector at the SLAC B-Factory.
10//
11// Author(s): Steve Schaffner, largely taken from Art Snyder
12//
13//------------------------------------------------------------------------
14#include "TrkBase/TrkDifPoca.h"
15#include "CLHEP/Geometry/Point3D.h"
16#include "CLHEP/Matrix/Vector.h"
17#include "CLHEP/Vector/ThreeVector.h"
18#include "MdcRecoUtil/DifNumber.h"
19#include "MdcRecoUtil/DifPoint.h"
20#include "MdcRecoUtil/DifVector.h"
21#include "TrkBase/TrkDifTraj.h"
22#include "TrkBase/TrkErrCode.h"
23#include "TrkBase/TrkPoca.h"
24
25TrkDifPoca::TrkDifPoca( const TrkDifTraj& traj1, double f1, const Trajectory& traj2, double f2,
26 double prec )
27 : TrkPocaBase( f1, f2, prec ), _doca( -9999., 0 ) {
28 minimize( traj1, f1, traj2, f2 );
29 if ( status().failure() ) return;
30 calcDist( traj1, traj2 );
31}
32
33TrkDifPoca::TrkDifPoca( const TrkDifTraj& traj, double f1, const HepPoint3D& pt, double prec )
34 : TrkPocaBase( f1, prec ), _doca( -9999., 0 ) {
35 minimize( traj, f1, pt );
36 if ( status().failure() ) return;
37 calcDist( traj, pt );
38}
39
40void TrkDifPoca::calcDist( const TrkDifTraj& traj1, const Trajectory& traj2 ) {
41 // Does a final calculation of the distance -- better behaved derivs than
42 // stepTowardPoca for zero dist. In case of (nearly) parallel, returns
43 // distance calculated at whatever point we happen to be at.
44 // Derivatives are taken (of dist) w/r/t traj2
45 // parameters, using DifNumbers for the calculation.
46
47 // A bunch of unsightly uninitialized variables:
48 static DifVector dir1;
49 static DifPoint pos1;
50 static Hep3Vector dirTem2;
51 static HepPoint3D posTem2;
52
53 // Request DifNumber info from traj1, ordinary info from traj2, and then
54 // convert ordinary info into DifNumber
55 traj2.getInfo( flt2(), posTem2, dirTem2 );
56 traj1.getDFInfo2( flt1(), pos1, dir1 );
57 DifVector dir2( dirTem2 );
58 DifPoint pos2( posTem2 );
59
60 DifVector delta = pos2 - pos1;
61 if ( status().success() != 3 )
62 { // Not parallel:
63 DifVector between = cross( dir1, dir2 ); // cross-product
64 between.normalize();
65 _doca = delta * between;
66 }
67 else
68 { // Parallel: Arbitrary sign convention
69 _doca = ( delta - delta.dot( dir1 ) * dir1 ).length();
70 if ( dir1.dot( dir2 ) > 0. ) _doca.flipsign();
71 if ( fabs( _doca.number() ) < 0.0001 * precision() )
72 {
73 // Parallel and on top of each other (derivatives singular)
74 _doca = 0;
75 _status.setFailure( 3 );
76 }
77 }
78}
79
80void TrkDifPoca::calcDist( const TrkDifTraj& traj, const HepPoint3D& pt ) {
81 // Does a final calculation of the distance -- and handles singularity
82 // in derivs when d = 0.
83
84 // A bunch of unsightly uninitialized variables:
85 static DifVector dir;
86 static DifPoint posTraj;
87
88 DifPoint posPoint( pt );
89 traj.getDFInfo2( flt1(), posTraj, dir ); // call faster one, if exists
90 DifVector delta = posTraj - posPoint;
91 // delta -= dir*delta; // note: dir*delta is zero, but the derivatives are NOT
92
93 DifNumber dist = delta.length();
94 if ( dist.number() > 0.01 * precision() )
95 { // d != 0
96 _doca = dist;
97 }
98 else
99 {
100 // d = 0. Fudge like mad: pick a direction (not parallel to traj) and
101 // move the point slightly. This should not happen very often.
102 Hep3Vector fudgeVec( 0., 0.1 * precision(), 0.0 );
103 if ( dir.x.number() == 0.0 && dir.z.number() == 0.0 )
104 { fudgeVec = Hep3Vector( 0.1 * precision(), 0., 0. ); }
105 posPoint += fudgeVec;
106 delta = posTraj - posPoint;
107 _doca = dist;
108 _status.setSuccess( 20, "TrkDifPoca: distance zero, calculation fudged." );
109 }
110}
HepGeom::Point3D< double > HepPoint3D
TFile * f1
EvtVector3R cross(const EvtVector3R &p1, const EvtVector3R &p2)
DifVector & normalize()
DifNumber dot(const DifVector &v) const
DifNumber length() const
virtual void getInfo(double fltLen, HepPoint3D &pos, Hep3Vector &direction) const =0
TrkDifPoca(const TrkDifTraj &traj1, double flt1, const Trajectory &traj2, double flt2, double precision=1.e-5)
virtual void getDFInfo2(double fltLen, DifPoint &pos, DifVector &direction) const
TrkPocaBase(double flt1, double flt2, double precision)
void minimize(const Trajectory &traj1, double f1, const Trajectory &traj2, double f2)