15#include "TrkBase/TrkPocaBase.h"
16#include "TrkBase/TrkPoca.h"
17#include "CLHEP/Vector/ThreeVector.h"
18#include "CLHEP/Geometry/Point3D.h"
19#include "MdcGeom/Trajectory.h"
26 : _precision(prec), _flt1(
f1), _flt2(f2),_status(
TrkErrCode::fail)
36 const int maxnOscillStep = 5 ;
37 const int maxnDivergingStep = 5 ;
45 double delta(0), prevdelta(0) ;
47 int nDivergingStep(0) ;
48 bool finished =
false ;
51 for (istep=0; istep <
_maxTry && !finished; ++istep) {
52 double prevflt1 =
flt1();
53 double prevflt2 =
flt2() ;
54 double prevprevdelta = prevdelta ;
64 delta = (newPos1 - newPos2).mag();
65 double step1 =
flt1() - prevflt1;
66 double step2 =
flt2() - prevflt2;
67 int pathDir1 = (step1 > 0.) ? 1 : -1;
68 int pathDir2 = (step2 > 0.) ? 1 : -1;
76 (fabs(step1) < distToErr1 && fabs(step2) < distToErr2 ) ||
80 if( !finished && istep>2 &&
delta > prevdelta) {
81 if( prevdelta > prevprevdelta) {
83 if(++nDivergingStep>maxnDivergingStep) {
90 if(++nOscillStep>maxnOscillStep) {
101 _flt1 = prevflt1 + 0.5*step1 ;
102 _flt2 = prevflt2 + 0.5*step2 ;
105 delta = (newPos1 - newPos2).mag() ;
115 : _precision(prec), _flt1(
f1), _flt2(0), _status(
TrkErrCode::fail)
129 double fltLast = 0., fltBeforeLast = 0.;
130 for (
int i = 0; i <
_maxTry; i++) {
133 if (
status().failure())
return;
134 double step =
flt1() - fltLast;
135 pathDir = (step > 0.) ? 1 : -1;
138 bool mustStep = (fabs(step) > distToErr && step != 0.);
145 if (fabs(step) >= fabs(fltBeforeLast-fltLast) &&
146 fabs(fltBeforeLast-
flt1()) <= fabs(step)) {
148 double halfway = (fltBeforeLast + fltLast) / 2.;
154 if (nTinyStep > 3) mustStep =
false;
157#ifdef MDCPATREC_WARNING
158 std::cout<<
" ErrMsg(warning) "<<
"Alleged oscillation detected. "
159 << step <<
" " << fltLast-fltBeforeLast
160 <<
" " << i <<
" " << std::endl;
163 if (!mustStep)
return;
164 fltBeforeLast = fltLast;
181 static Hep3Vector dir1, dir2;
182 static Hep3Vector delDir1, delDir2;
187 Hep3Vector
delta = ((CLHEP::Hep3Vector)pos1) - ((CLHEP::Hep3Vector)pos2);
188 double ua = -
delta.dot(dir1);
189 double ub =
delta.dot(dir2);
190 double caa = dir1.mag2() +
delta.dot(delDir1);
191 double cbb = dir2.mag2() -
delta.dot(delDir2);
192 double cab = -dir1.dot(dir2);
193 double det = caa * cbb - cab * cab;
199 det = caa * cbb - cab * cab;
208 double df1 = (ua * cbb - ub * cab)/det;
209 int pathDir1 = (df1 > 0) ? 1 : -1;
210 double df2 = (ub * caa - ua * cab)/det;
211 int pathDir2 = (df2 > 0) ? 1 : -1;
222 const double smudge = 1.01 ;
223 if( fabs(df1) > smudge*distToErr1 ) {
225 df1 = smudge*distToErr1 * pathDir1 ;
227 df2 = (ub - df1*cab)/cbb ;
230 if( fabs(df2) > smudge*distToErr2 ) {
232 df2 = smudge*distToErr2 * pathDir2 ;
234 df1 = (ua - df2*cab)/cbb ;
236 if( fabs(df1) > smudge*distToErr1 ) {
237 df1 = smudge*distToErr1 * pathDir1 ;
253 static Hep3Vector dir, delDir;
257 Hep3Vector
delta = ((CLHEP::Hep3Vector)trajPos) - ((CLHEP::Hep3Vector)pt);
258 double denom = 1. +
delta.dot(delDir);
263 double df = -
delta.dot(dir) / fabs(denom);
264 int pathDir = (df > 0.) ? 1 : -1;
268 if (fabs(df)>distToErr) df = (df>0?distToErr:-distToErr);
virtual HepPoint3D position(double) const =0
virtual double distTo2ndError(double s, double tol, int pathDir) const =0
virtual void getInfo(double fltLen, HepPoint3D &pos, Hep3Vector &direction) const =0
virtual double distTo1stError(double s, double tol, int pathDir) const =0
void setSuccess(int i, const char *str=0)
void setFailure(int i, const char *str=0)
void stepToPointPoca(const Trajectory &traj, const HepPoint3D &pt)
TrkPocaBase(double flt1, double flt2, double precision)
const TrkErrCode & status() const
void minimize(const Trajectory &traj1, double f1, const Trajectory &traj2, double f2)
static double _extrapToler
void stepTowardPoca(const Trajectory &traj1, const Trajectory &traj2)