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