13#include "TrkBase/TrkDifPieceTraj.h"
14#include "CLHEP/Matrix/Matrix.h"
15#include "CLHEP/Vector/ThreeVector.h"
16#include "CLHEP/Geometry/Point3D.h"
17#include "MdcRecoUtil/DifPoint.h"
18#include "MdcRecoUtil/DifVector.h"
19#include "TrkBase/TrkPoca.h"
20#include "TrkBase/TrkErrCode.h"
22#include "MdcRecoUtil/BesCollectionUtils.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];
49 assert(lowlim < hilim);
55 locrange[1] = hilim-lowlim+locrange[0];
63 _globalrange(other._globalrange),
64 _lastIndex(other._lastIndex)
70 typedef std::deque<TrkSimpTraj *>::const_iterator iter_t;
71 iter_t end = other._localtraj.end();
72 for(iter_t i=other._localtraj.begin();i!=end; ++i)
81 for(std::vector<TrkSimpTraj*>::const_iterator itraj=trajs.begin();itraj!=trajs.end();++itraj){
93#ifdef MDCPATREC_WARNING
94 std::cout<<
"ErrMsg(warning) "
95 <<
"construction from vector of trajs failed"
128 double localflight(0.0);
140 double localflight(0.0);
148 if (&other ==
this)
return *
this;
157 typedef std::deque<TrkSimpTraj*>::const_iterator iter_t;
158 for(iter_t i=other._localtraj.begin();i!=other._localtraj.end();++i)
176#ifdef MDCPATREC_WARNING
177 std::cout<<
"ErrMsg(warning)" <<
"append removed "
178 << nremoved <<
" old trajectories" << std::endl;
184 gap = newend.distance(endpoint);
196 gap = endpoca.
doca();
222#ifdef MDCPATREC_WARNING
223 std::cout<<
"ErrMsg(warning) "<<
" prepend removed "
224 << nremoved <<
" old trajectories" << std::endl;
230 gap = newend.distance(endpoint);
242 gap = endpoca.
doca();
279 double otherlen = other.lowRange();
280 HepPoint3D otherstart = other.position(otherlen);
281 gap = otherstart.distance(myend);
283 TrkPoca endpoca(other,other.lowRange(),myend,_TOL);
288 gap = endpoca.
doca();
289 otherlen = endpoca.
flt1();
295 for(
int itraj = other.trajIndex(otherlen,loclen);
296 itraj < other._localtraj.size();itraj++){
298 retval =
append(mylen,*(other._localtraj[itraj]),piecegap);
315 double otherlen = other.hiRange();
316 HepPoint3D otherend = other.position(otherlen);
317 gap = otherend.distance(mystart);
319 TrkPoca endpoca(other,other.hiRange(),mystart,_TOL);
324 gap = endpoca.
doca();
325 otherlen = endpoca.
flt1();
331 for(
int itraj = other.trajIndex(otherlen,loclen);
332 itraj >= 0;itraj--) {
334 retval =
prepend(mylen,*(other._localtraj[itraj]),piecegap);
348 std::deque<TrkSimpTraj*> trajcopy; trajcopy.swap(
_localtraj);
349 std::deque<double> rangecopy; rangecopy.swap(
_globalrange);
355 for(
int itraj=trajcopy.size()-1;itraj>=0;itraj--){
389 while(index != oldindex){
393 index -=
max(1,(index-lorange)/2);
396 index +=
max(1,(hirange-index)/2);
408 localflight =
localDist(index,flightdist);
420 double localflight(0.0);
422 return loctraj->
position(localflight);
431 double localflight(0.0);
442 double localflight(0.0);
453 double localflight(0.0);
461 Hep3Vector& dir)
const
466 double localflight(0.0);
468 loctraj->
getInfo(localflight,point,dir);
475 Hep3Vector& deldirect)
const
480 double localflight(0.0);
482 loctraj->
getInfo(localflight,point,dir,deldirect);
491 double localflight(0.0);
492 int index =
trajIndex(flightdist,localflight);
501 double dist = localdist;
518 double localflight(0.0);
519 int index =
trajIndex(flightdist,localflight);
528 double dist = localdist;
546 int index =
trajIndex(flightdist,localflight);
557 double oldend,locdist;
605 os <<
"TrkDifPieceTraj has " <<
_localtraj.size() <<
" pieces "
606 <<
", total flight range of " <<
hiRange();
612 os <<
"TrkDifPieceTraj has " <<
_localtraj.size() <<
" pieces "
613 <<
", total flight range from "
615 for(
int ipiece=0;ipiece<
_localtraj.size();ipiece++){
618 double phi = tpiece->
hiRange();
619 os <<
"Piece " << ipiece <<
" has global range from "
621 <<
" and local range from " << plow <<
" to " << phi << endl;
625 os <<
"Piece " << ipiece <<
" starts at point "
626 << start.x() <<
","<< start.y()<<
","<< start.z()
627 <<
" and ends at point "
628 << end.x()<<
"," << end.y()<<
"," << end.z()
629 <<
" and references point "
630 << refp.x()<<
"," << refp.y()<<
"," << refp.z()
646 if( newrange[1] > newrange[0] &&
651 }
else if(newrange[1] < newrange[0] ){
652#ifdef MDCPATREC_ERROR
653 std::cout<<
"ErrMsg(error) "<<
"cannot resize -- invalid range" << std::endl;
689 double localflight(0.0);
697 double localflight(0.0);
705 double localflight(0.0);
728 double gapend = poca.
flt1();
729 double gapmid = (gapend+gapstart)/2.0;
732 double locmid = newtraj->
lowRange() - gapend + gapmid;
733 TrkPoca midpoca(*newtraj,locmid,mid,_TOL);
738 assert(gaptraj != 0);
780 double gapstart = poca.
flt1();
782 double gapmid = (gapend+gapstart)/2.0;
785 double locmid = newtraj->
hiRange() - gapstart + gapmid;
786 TrkPoca midpoca(*newtraj,locmid,mid,_TOL);
791 assert(gaptraj != 0);
818 double localflight(0.0);
820 return loctraj != 0 &&
821 localflight-tol <= loctraj->
hiRange() &
822 localflight+tol >= loctraj->
lowRange();
829 if(retval) retval =
_localtraj.size() == other._localtraj.size();
831 std::deque<TrkSimpTraj*>::const_iterator miter =
_localtraj.begin();
832 std::deque<TrkSimpTraj*>::const_iterator oiter = other._localtraj.begin();
833 while(retval && miter !=
_localtraj.end() && oiter != other._localtraj.end()){
834 retval = (*oiter)->parameters()->parameter() == (*miter)->parameters()->parameter() &&
835 (*oiter)->parameters()->covariance() == (*miter)->parameters()->covariance();
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
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