13#include "TrkBase/TrkDifPieceTraj.h"
14#include "CLHEP/Geometry/Point3D.h"
15#include "CLHEP/Matrix/Matrix.h"
16#include "CLHEP/Vector/ThreeVector.h"
17#include "MdcRecoUtil/BesCollectionUtils.h"
18#include "MdcRecoUtil/DifPoint.h"
19#include "MdcRecoUtil/DifVector.h"
20#include "TrkBase/TrkErrCode.h"
21#include "TrkBase/TrkPoca.h"
25static const double STEPEPSILON = 1.0e-6;
26static const double _TOL = 1.0e-5;
35 assert( lowlim < hilim );
41 locrange[1] = hilim - lowlim + locrange[0];
48 assert( lowlim < hilim );
54 locrange[1] = hilim - lowlim + locrange[0];
68 typedef std::deque<TrkSimpTraj*>::const_iterator iter_t;
69 iter_t end = other._localtraj.end();
70 for ( iter_t i = other._localtraj.begin(); i != end; ++i )
78 for ( std::vector<TrkSimpTraj*>::const_iterator itraj = trajs.begin(); itraj != trajs.end();
82 assert( newtraj != 0 );
89 else add =
prepend( newtraj, gap );
92#ifdef MDCPATREC_WARNING
93 std::cout <<
"ErrMsg(warning) "
94 <<
"construction from vector of trajs failed" << add << std::endl;
123 double localflight( 0.0 );
133 double localflight( 0.0 );
139 if ( &other ==
this )
return *
this;
148 typedef std::deque<TrkSimpTraj*>::const_iterator iter_t;
149 for ( iter_t i = other._localtraj.begin(); i != other._localtraj.end(); ++i )
167#ifdef MDCPATREC_WARNING
168 std::cout <<
"ErrMsg(warning)"
169 <<
"append removed " << nremoved <<
" old trajectories" << std::endl;
173 HepPoint3D endpoint =
position( glen );
175 gap = newend.distance( endpoint );
189 gap = endpoca.
doca();
216#ifdef MDCPATREC_WARNING
217 std::cout <<
"ErrMsg(warning) "
218 <<
" prepend removed " << nremoved <<
" old trajectories" << std::endl;
222 HepPoint3D endpoint =
position( glen );
224 gap = newend.distance( endpoint );
231 TrkPoca endpoca( *nexttraj, nexttraj->
hiRange(), endpoint, _TOL );
238 gap = endpoca.
doca();
272 HepPoint3D myend =
position( mylen );
273 double otherlen = other.lowRange();
274 HepPoint3D otherstart = other.position( otherlen );
275 gap = otherstart.distance( myend );
278 TrkPoca endpoca( other, other.lowRange(), myend, _TOL );
284 gap = endpoca.
doca();
285 otherlen = endpoca.
flt1();
291 for (
int itraj = other.trajIndex( otherlen, loclen ); itraj < other._localtraj.size();
295 retval =
append( mylen, *( other._localtraj[itraj] ), piecegap );
309 HepPoint3D mystart =
position( mylen );
310 double otherlen = other.hiRange();
311 HepPoint3D otherend = other.position( otherlen );
312 gap = otherend.distance( mystart );
315 TrkPoca endpoca( other, other.hiRange(), mystart, _TOL );
321 gap = endpoca.
doca();
322 otherlen = endpoca.
flt1();
328 for (
int itraj = other.trajIndex( otherlen, loclen ); itraj >= 0; itraj-- )
331 retval =
prepend( mylen, *( other._localtraj[itraj] ), piecegap );
342 std::deque<TrkSimpTraj*> trajcopy;
344 std::deque<double> rangecopy;
351 for (
int itraj = trajcopy.size() - 1; itraj >= 0; itraj-- )
386 while ( index != oldindex )
392 index -=
max( 1, ( index - lorange ) / 2 );
397 index +=
max( 1, ( hirange - index ) / 2 );
411 localflight =
localDist( index, flightdist );
421 double localflight( 0.0 );
423 return loctraj->
position( localflight );
430 double localflight( 0.0 );
432 return loctraj->
direction( localflight );
439 double localflight( 0.0 );
441 return loctraj->
curvature( localflight );
448 double localflight( 0.0 );
450 return loctraj->
delDirect( localflight );
457 double localflight( 0.0 );
459 loctraj->
getInfo( localflight, point, dir );
463 Hep3Vector& deldirect )
const {
467 double localflight( 0.0 );
469 loctraj->
getInfo( localflight, point, dir, deldirect );
476 double localflight( 0.0 );
477 int index =
trajIndex( flightdist, localflight );
483 double localdist = loctraj->
distTo1stError( localflight, tol, dir );
486 double dist = localdist;
490 dist =
min( localdist,
_globalrange[index + 1] - flightdist ) + STEPEPSILON;
494 if ( index > 0 ) dist =
min( localdist, flightdist -
_globalrange[index] ) + STEPEPSILON;
503 double localflight( 0.0 );
504 int index =
trajIndex( flightdist, localflight );
510 double localdist = loctraj->
distTo2ndError( localflight, tol, dir );
513 double dist = localdist;
517 dist =
min( localdist,
_globalrange[index + 1] - flightdist ) + STEPEPSILON;
521 if ( index > 0 ) dist =
min( localdist, flightdist -
_globalrange[index] ) + STEPEPSILON;
527 double& localflight )
const {
531 int index =
trajIndex( flightdist, localflight );
540 double oldend, locdist;
593 os <<
"TrkDifPieceTraj has " <<
_localtraj.size() <<
" pieces "
594 <<
", total flight range of " <<
hiRange();
598 os <<
"TrkDifPieceTraj has " <<
_localtraj.size() <<
" pieces "
599 <<
", total flight range from " <<
lowRange() <<
" to " <<
hiRange() << endl;
600 for (
int ipiece = 0; ipiece <
_localtraj.size(); ipiece++ )
604 double phi = tpiece->
hiRange();
605 os <<
"Piece " << ipiece <<
" has global range from " <<
_globalrange[ipiece] <<
" to "
606 <<
_globalrange[ipiece + 1] <<
" and local range from " << plow <<
" to " << phi
611 os <<
"Piece " << ipiece <<
" starts at point " << start.x() <<
"," << start.y() <<
","
612 << start.z() <<
" and ends at point " << end.x() <<
"," << end.y() <<
"," << end.z()
613 <<
" and references point " << refp.x() <<
"," << refp.y() <<
"," << refp.z() << endl;
626 if ( newrange[1] > newrange[0] && newrange[0] <
flightrange[1] &&
632 else if ( newrange[1] < newrange[0] )
634#ifdef MDCPATREC_ERROR
635 std::cout <<
"ErrMsg(error) "
636 <<
"cannot resize -- invalid range" << std::endl;
681 double localflight( 0.0 );
687 double localflight( 0.0 );
693 double localflight( 0.0 );
715 double gapend = poca.
flt1();
716 double gapmid = ( gapend + gapstart ) / 2.0;
717 HepPoint3D mid =
position( gapmid );
719 double locmid = newtraj->
lowRange() - gapend + gapmid;
720 TrkPoca midpoca( *newtraj, locmid, mid, _TOL );
726 assert( gaptraj != 0 );
741 gap = mid.distance( newtraj->
position( midpoca.
flt1() ) );
767 double gapstart = poca.
flt1();
769 double gapmid = ( gapend + gapstart ) / 2.0;
770 HepPoint3D mid =
position( gapmid );
772 double locmid = newtraj->
hiRange() - gapstart + gapmid;
773 TrkPoca midpoca( *newtraj, locmid, mid, _TOL );
779 assert( gaptraj != 0 );
793 gap = mid.distance( newtraj->
position( midpoca.
flt1() ) );
804 double localflight( 0.0 );
806 return loctraj != 0 &&
807 localflight - tol <= loctraj->
hiRange() & localflight + tol >= loctraj->
lowRange();
812 if ( retval ) retval =
_globalrange == other._globalrange;
813 if ( retval ) retval =
_localtraj.size() == other._localtraj.size();
815 std::deque<TrkSimpTraj*>::const_iterator miter =
_localtraj.begin();
816 std::deque<TrkSimpTraj*>::const_iterator oiter = other._localtraj.begin();
817 while ( retval && miter !=
_localtraj.end() && oiter != other._localtraj.end() )
819 retval = ( *oiter )->parameters()->parameter() == ( *miter )->parameters()->parameter() &&
820 ( *oiter )->parameters()->covariance() == ( *miter )->parameters()->covariance();
HepGeom::Point3D< double > HepPoint3D
virtual HepPoint3D position(double) const =0
virtual double distTo2ndError(double s, double tol, int pathDir) const =0
virtual Hep3Vector delDirect(double) const =0
virtual void getInfo(double fltLen, HepPoint3D &pos, Hep3Vector &direction) const =0
virtual double distTo1stError(double s, double tol, int pathDir) const =0
virtual void setFlightRange(double newrange[2])
virtual Hep3Vector direction(double) const =0
bool validFlightDistance(double f, double tolerance=0.0) const
virtual double curvature(double) const =0
void printAll(std::ostream &os) const
TrkDifPieceTraj(const TrkSimpTraj &, const double lowlim, const double hilim)
HepPoint3D position(double) const
Hep3Vector direction(double) const
HepMatrix derivDeflect(double fltlen, deflectDirection) const
int trajIndex(const double &global, double &local) const
void getDFInfo(double fltLen, DifPoint &pos, DifVector &direction, DifVector &delDirect) const
TrkDifPieceTraj & invert()
void getInfo(double fltLen, HepPoint3D &, Hep3Vector &direction) const
int resize(double len, trkDirection)
double globalDist(int index, double locdist) const
void getDFInfo2(double fltlen, DifPoint &pos, DifVector &direction) const
double curvature(double f=0.) const
double distTo2ndError(double s, double tol, int pathDir) const
TrkDifPieceTraj & operator=(const TrkDifPieceTraj &)
std::deque< TrkSimpTraj * > _localtraj
std::deque< double > _globalrange
bool locallyValid(double glen, double tol=0.0) const
void print(std::ostream &os) const
double localDist(int index, double globdist) const
Hep3Vector delDirect(double) const
double distTo1stError(double s, double tol, int pathDir) const
virtual ~TrkDifPieceTraj()
const TrkErrCode & append(double gfltlen, const TrkSimpTraj &, double &gap)
HepMatrix derivPFract(double fltlen) const
const TrkSimpTraj * localTrajectory(double, double &) const
HepMatrix derivDisplace(double fltlen, deflectDirection idir) const
const TrkErrCode & prepend(double gfltlen, const TrkSimpTraj &, double &gap)
void setFlightRange(double newrange[2])
bool operator==(const TrkDifPieceTraj &other) const
virtual void getDFInfo2(double fltLen, DifPoint &pos, DifVector &direction) const
TrkDifTraj(const double lowlim=-99999., const double hilim=99999.)
virtual void getDFInfo(double fltLen, DifPoint &pos, DifVector &direction, DifVector &delDirect) const =0
virtual HepMatrix derivDeflect(double fltlen, deflectDirection idir) const =0
virtual HepMatrix derivDisplace(double fltlen, deflectDirection idir) const =0
virtual HepMatrix derivPFract(double fltlen) const =0
const TrkErrCode & status() const
const HepPoint3D & referencePoint() const
virtual TrkSimpTraj * clone() const =0