8 #include "aidaTT/IBField.hh"
9 #include "aidaTT/ConstantSolenoidBField.hh"
10 #include "aidaTT/analyticalPropagation.hh"
11 #include "aidaTT/simplifiedPropagation.hh"
12 #include "aidaTT/GBLInterface.hh"
13 #include "aidaTT/fitResults.hh"
14 #include "aidaTT/Vector5.hh"
15 #include "aidaTT/utilities.hh"
16 #include "aidaTT/LCIOPersistency.hh"
17 #include "aidaTT/Vector3D.hh"
18 #include "aidaTT/DD4hepGeometry.hh"
19 #include "aidaTT/materialUtils.hh"
21 #include "DD4hep/DD4hepUnits.h"
34 #include "streamlog/streamlog.h"
37 using namespace UTIL ;
38 using namespace lcio ;
47 bf.setValue( detElementID ) ;
48 return bf.valueString() ;
55 : _aidaTT( mAidaTT ) , _initialised( false ) , _mass( aidaTT::pionMass ) {
83 streamlog_out( ERROR) <<
"<<<<<< MarlinAidaTTTrack::initialise: Shortage of Hits! nhits = "
89 bool backwards = false ;
92 lcio::TrackerHit* h2 =
_lcioHits[ (nHits+1) / 2 ] ;
95 const double* pos1 = h1->getPosition() ;
96 const double* pos2 = h2->getPosition() ;
97 const double* pos3 = h3->getPosition() ;
99 aidaTT::Vector3D x1( pos1[0] * dd4hep::mm, pos1[1] * dd4hep::mm , pos1[2] * dd4hep::mm ) ;
100 aidaTT::Vector3D x2( pos2[0] * dd4hep::mm, pos2[1] * dd4hep::mm , pos2[2] * dd4hep::mm ) ;
101 aidaTT::Vector3D x3( pos3[0] * dd4hep::mm, pos3[1] * dd4hep::mm , pos3[2] * dd4hep::mm ) ;
104 aidaTT::trackParameters tp ;
105 calculateStartHelix( x1, x2, x3 , tp , backwards ) ;
107 streamlog_out( DEBUG3 ) <<
" start helix from three points : " << tp <<
std::endl ;
110 #if 1 // create prefit from this helix
126 #if 0 // debug code - initialize with hits and a prefit ....
167 streamlog_out( DEBUG ) <<
"MarlinAidaTTTrack::addAndFit: nothing to be done ... " <<
std::endl ;
173 streamlog_out( DEBUG ) <<
"MarlinAidaTTTrack::testChi2Increment: nothing to be done ... " <<
std::endl ;
179 streamlog_out(DEBUG2) <<
"MarlinAidaTTTrack::fit() called " <<
std::endl ;
187 streamlog_out( ERROR) <<
"<<<<<< MarlinAidaTTTrack::initialise: Shortage of Hits! nhits = "
194 for(
unsigned i=0 ; i < nHits ; ++i){
195 hitMap[
_lcioHits[i]->getCellID0() ] = _lcioHits[i] ;
207 const aidaTT::ISurface* surf = it->second ;
211 streamlog_out(DEBUG7) <<
"MarlinAidaTTTrack::fit() - intersection - current pointLabel : " << pointLabel
212 <<
": at s = " << it->first <<
" surface id : "
225 streamlog_out(DEBUG) <<
"MarlinAidaTTTrack::fit() addMeasurement called for pointLabel : " << pointLabel <<
std::endl ;
233 if( ! ( surf->innerMaterial().density() < 1e-6 &&
234 surf->outerMaterial().density() < 1e-6 ) ) {
239 streamlog_out(DEBUG) <<
"MarlinAidaTTTrack::fit() addScatterer called for pointLabel : " << pointLabel <<
std::endl ;
251 streamlog_out( DEBUG4 ) <<
"MarlinAidaTTTrack::fit() - fit worked " << fit_ok
255 #if 0 // ---------------- try to run a refit --- does not work really ....
257 const aidaTT::fitResults* result =
_fitTrajectory->getFitResults();
258 const aidaTT::trackParameters& tp = result->estimatedParameters() ;
260 streamlog_out( MESSAGE ) <<
" --- first fit result : " << tp <<
std::endl ;
265 streamlog_out( DEBUG4 ) <<
"MarlinAidaTTTrack::fit() - refit worked " << fit_ok <<
std::endl ;
268 const aidaTT::trackParameters& tp1 = result->estimatedParameters() ;
270 streamlog_out( MESSAGE ) <<
" --- second fit result : " << tp1 <<
std::endl ;
286 traj.setMass(
_mass ) ;
297 int step = ( nHits <= 25 ? 1 : int( 1.*nHits/25. ) ) ;
299 streamlog_out( DEBUG1 ) <<
" MarlinAidaTTTrack::createPreFit() : will use every "
300 << step <<
"-th hit for prefit ! " <<
std::endl ;
302 for(
unsigned i=0 ; i < nHits ; i+= step ){
312 streamlog_out( DEBUG1 ) <<
" MarlinAidaTTTrack::createPreFit() : no surface found for id : "
317 const aidaTT::ISurface* surf = it->second ;
323 streamlog_out( DEBUG1 ) <<
" MarlinAidaTTTrack::createPreFit() : adding hit for "
329 traj.addMeasurement( hitpos, precision, *surf, hit );
332 traj.prepareForFitting();
339 const aidaTT::fitResults* result = traj.getFitResults();
341 const aidaTT::trackParameters& newTP = result->estimatedParameters() ;
343 streamlog_out( DEBUG4 ) <<
" MarlinAidaTTTrack::createPreFit() : prefit tp: "
351 streamlog_out( WARNING ) <<
" MarlinAidaTTTrack::createPreFit() : prefit failed for tp: "
364 for(
unsigned int i = 0; i < 3; ++i) hitpos[i] = hit->
getPosition()[i] * dd4hep::mm;
369 const TrackerHitPlane* planarhit =
dynamic_cast<const TrackerHitPlane*
>( hit );
370 if( planarhit != 0 ) {
372 du = planarhit->getdU() * dd4hep::mm ;
373 dv = planarhit->getdV() * dd4hep::mm ;
379 du = sqrt( cov[0] + cov[2] ) * dd4hep::mm ;
380 dv = sqrt( cov[5] ) * dd4hep::mm ;
385 if( ! surf->type().isMeasurement1D() )
399 streamlog_out( DEBUG2 ) <<
"MarlinAidaTTTrack::smooth() - nothing to do ...." <<
std::endl ;
408 streamlog_out( DEBUG2 ) <<
"MarlinAidaTTTrack::smooth() - nothing to do ...." <<
std::endl ;
415 const aidaTT::fitResults& result = *
_fitTrajectory->getFitResults();
417 ts = *aidaTT::createLCIO( result.estimatedParameters() );
421 chi2 = result.chiSquare() ;
435 streamlog_out( DEBUG2 ) <<
" MarlinAidaTTTrack::getTrackState(): "
436 <<
" no surface intersection for given hit "
448 const aidaTT::fitResults* result =
_fitTrajectory->getFitResults( label );
452 streamlog_out( DEBUG2 ) <<
" MarlinAidaTTTrack::getTrackState(): "
453 <<
" no result at label " << label
454 <<
" close to " << refPoint <<
std::endl ;
459 aidaTT::trackParameters resTS = result->estimatedParameters() ;
462 const double* pos = refPoint ;
463 aidaTT::Vector3D hitPos( pos[0] * dd4hep::mm, pos[1] * dd4hep::mm , pos[2] * dd4hep::mm ) ;
466 streamlog_out( DEBUG2 ) <<
" MarlinAidaTTTrack::getTrackState(): "
467 <<
" moving helix to " << hitPos <<
std::endl ;
469 bool calcCovMat = true ;
470 moveHelixTo( resTS , hitPos , calcCovMat ) ;
472 ts = *aidaTT::createLCIO( resTS );
474 chi2 = result->chiSquare() ;
476 ndf = result->ndf() ;
484 streamlog_out( DEBUG2 ) <<
"MarlinAidaTTTrack::getHitsInFit() - returning all hits used ..." <<
std::endl ;
497 streamlog_out( DEBUG2 ) <<
"MarlinAidaTTTrack::getOutliers() - nothing to do ..." <<
std::endl ;
504 const aidaTT::fitResults& result = *
_fitTrajectory->getFitResults();
520 return propagate( point, ts, chi2, ndf ) ;
525 return propagate( point, trkhit, ts, chi2, ndf ) ;
537 return propagateToLayer( layerID, trkhit, ts, chi2, ndf, detElementID, mode ) ;
558 if( point[0] == 0.0 && point[1] == 0.0 && point[2] == 0.0 ) {
565 aidaTT::Vector3D thePoint( point[0]*dd4hep::mm,point[1]*dd4hep::mm, point[2]*dd4hep::mm ) ;
595 double minDist2 = 1.e99 ;
597 for(
unsigned i=0,N=elemVec.
size() ; i < N ; ++i ){
598 const aidaTT::Vector3D& rp = elemVec[i]->getTrackParameters()->referencePoint() ;
600 double dist2 = dv.
r2() ;
601 if( dist2 < minDist2 ){
608 label, ts, chi2, ndf ) ;
615 return this->
propagate( point, ts, chi2, ndf ) ;
628 mask |= encoder[lcio::LCTrackerCellID::subdet()].mask() ;
629 mask |= encoder[lcio::LCTrackerCellID::side() ].mask() ;
630 mask |= encoder[lcio::LCTrackerCellID::layer() ].mask() ;
654 streamlog_out( DEBUG ) <<
"MarlinAidaTTTrack::propagate(): looking for cellID " <<
cellIDString( layerID ) <<
std::endl ;
661 for(
unsigned i=1,N=elemVec.
size() ; i < N ; ++i ){
663 int id = elemVec[i]->surface().id() ;
666 streamlog_out( DEBUG ) <<
"MarlinAidaTTTrack::propagate(): comparing to cellID " <<
cellIDString(
id ) <<
std::endl ;
668 if( layerID == (
id & mask ) ){
676 streamlog_out( ERROR ) <<
"MarlinAidaTTTrack::propagate(): no intersection "
682 detElementID = theID ;
687 aidaTT::Vector3D point( position[0]/dd4hep::mm, position[1]/dd4hep::mm,position[2]/dd4hep::mm ) ;
697 double& chi2,
int& ndf,
int& detElementID,
int ) {
709 streamlog_out( DEBUG2 ) <<
" MarlinAidaTTTrack::propagateToDetElement(): "
710 <<
" no surface intersection for given DetElementID "
726 int label = it->second ;
731 aidaTT::Vector3D point( position[0]/dd4hep::mm, position[1]/dd4hep::mm,position[2]/dd4hep::mm ) ;
759 streamlog_out( DEBUG2 ) <<
" MarlinAidaTTTrack::intersectionWithDetElement(): "
760 <<
" no surface intersection for given DetElementID "
764 int label = it->second ;
769 point =
aidaTT::Vector3D( position[0]/dd4hep::mm, position[1]/dd4hep::mm,position[2]/dd4hep::mm ) ;
789 mask |= encoder[lcio::LCTrackerCellID::subdet()].mask() ;
790 mask |= encoder[lcio::LCTrackerCellID::side() ].mask() ;
791 mask |= encoder[lcio::LCTrackerCellID::layer() ].mask() ;
797 int id = it->second->id() ;
799 if( layerID == (
id & mask ) ){
806 streamlog_out( ERROR ) <<
"MarlinAidaTTTrack::intersectionWithLayer(): no intersection "
812 detElementID = theID ;
825 return std::string(
" AidaTTTrack - to String ... " ) ;
int fit(double maxChi2Increment=DBL_MAX)
perform the fit of all current hits, returns error code ( IMarlinTrack::success if no error ) ...
int initialise(bool)
initialise the fit using the hits added up to this point - the fit direction has to be specified usin...
aidaTT::IPropagation * _propagation
int extrapolateToDetElement(int detElementID, IMPL::TrackStateImpl &ts, double &chi2, int &ndf, int mode=modeClosest)
extrapolate the fit to sensitive detector element, returning TrackState, chi2 and ndf via reference ...
virtual const double * getPosition() const =0
int intersectionWithLayer(int layerID, Vector3D &point, int &detElementID, int mode=modeClosest)
extrapolate the fit to numbered sensitive layer, returning intersection point in global coordinates a...
int getTrackState(IMPL::TrackStateImpl &ts, double &chi2, int &ndf)
get track state, returning TrackState, chi2 and ndf via reference
void getHitInfo(const EVENT::TrackerHit *hit, double *hitpos, std::vector< double > &precision, const aidaTT::ISurface *surf)
Interface to KaltTest Kalman fitter - instantiates and holds the detector geometry.
int propagateToLayer(int layerID, IMPL::TrackStateImpl &ts, double &chi2, int &ndf, int &detElementID, int mode=modeClosest)
propagate the fit to the numbered sensitive layer, returning TrackState, chi2, ndf and integer ID of ...
std::string cellIDString(int detElementID)
int myInit()
common initialization
aidaTT::IFittingAlgorithm * _fitter
bool _useQMS
take multiple scattering into account during the fit
int intersectionWithDetElement(int detElementID, Vector3D &point, int mode=modeClosest)
extrapolate the fit to numbered sensitive detector element, returning intersection point in global co...
std::string toString()
Dump this track to a string for debugging.
int extrapolate(const Vector3D &point, IMPL::TrackStateImpl &ts, double &chi2, int &ndf)
extrapolate the fit to the point of closest approach to the given point, returning TrackState...
int testChi2Increment(EVENT::TrackerHit *, double &)
this method has no effect for aidaTT/GBL ...
dd4hep::rec::Vector3D Vector3D
the Vector3D used for the tracking interface
aidaTT::trackParameters createPreFit(aidaTT::trackParameters &tp)
virtual const FloatVec & getCovMatrix() const =0
const std::vector< std::pair< double, const aidaTT::ISurface * > > * _intersections
virtual void setLocation(int location)
int getOutliers(std::vector< std::pair< EVENT::TrackerHit *, double > > &)
this method has no effect for aidaTT/GBL ...
std::map< int, int > _indexMap
int getHitsInFit(std::vector< std::pair< EVENT::TrackerHit *, double > > &hits)
get the list of hits included in the fit, together with the chi2 contributions of the hits...
aidaTT::trajectory * _fitTrajectory
int propagateToDetElement(int detElementID, IMPL::TrackStateImpl &ts, double &chi2, int &ndf, int mode=modeClosest)
propagate the fit to sensitive detector element, returning TrackState, chi2 and ndf via reference ...
int smooth()
this method has no effect for aidaTT/GBL ...
int addAndFit(EVENT::TrackerHit *, double &, double)
this method has no effect for aidaTT/GBL ...
static const std::string & encoding_string()
int getTrackerHitAtPositiveNDF(EVENT::TrackerHit *&trkhit)
get TrackeHit at which fit became constrained, i.e.
const aidaTT::IGeometry * _geom
int extrapolateToLayer(int layerID, IMPL::TrackStateImpl &ts, double &chi2, int &ndf, int &detElementID, int mode=modeClosest)
extrapolate the fit to numbered sensitive layer, returning TrackState via provided reference ...
int propagate(const Vector3D &point, IMPL::TrackStateImpl &ts, double &chi2, int &ndf)
propagate the fit to the point of closest approach to the given point, returning TrackState, chi2 and ndf via reference
virtual int getCellID0() const =0
SurfMap _surfMap
multi-map of surfaces
int getNDF(int &ndf)
get the current number of degrees of freedom for the fit.
static const int no_intersection
void setMass(double mass)
set the mass of the charged particle (GeV) that is used for energy loss and multiple scattering - def...
std::vector< EVENT::TrackerHit * > _lcioHits
bool _initialised
used to store whether initial track state has been supplied or created
Exception thrown in IMarlinTrk namespace (implemetations of IMarlinTrkSystem and IMarlinTrack).
double getMass()
return the of the charged particle (GeV) that is used for energy loss and multiple scattering...
int addHit(EVENT::TrackerHit *hit)
add hit to track - the hits have to be added ordered in time ( i.e.
aidaTT::trackParameters _initialTrackParams