26 #include "streamlog/streamlog.h"
35 using namespace lcio ;
36 using namespace UTIL ;
114 int return_error = 0;
123 return_error =
createPrefit(hit_list, &pre_fit, bfield_z, fit_direction);
127 streamlog_out( DEBUG3 ) <<
" **** createFinalisedLCIOTrack - created pre-fit: " <<
toString( &pre_fit ) <<
std::endl ;
134 if( return_error == 0 ) {
136 return_error =
createFinalisedLCIOTrack( marlinTrk, hit_list, track, fit_direction, &pre_fit, bfield_z, maxChi2Increment);
139 streamlog_out(DEBUG3) <<
"MarlinTrk::createFinalisedLCIOTrack : Prefit failed error = " << return_error <<
std::endl;
164 int fit_status =
createFit(hit_list, marlinTrk, pre_fit, bfield_z, fit_direction, maxChi2Increment);
168 streamlog_out(DEBUG3) <<
"MarlinTrk::createFinalisedLCIOTrack fit failed: fit_status = " << fit_status <<
std::endl;
192 if( marlinTrk == 0 ){
200 int return_error = 0;
223 EVENT::TrackerHitVec::iterator it = hit_list.
begin();
226 streamlog_out(DEBUG2) <<
"MarlinTrk::createFit Start Fit: AddHits: number of hits to fit " << hit_list.
size() <<
std::endl;
229 unsigned int ndof_added = 0;
231 for( it = hit_list.
begin() ; it != hit_list.
end() ; ++it ) {
234 bool isSuccessful =
false;
241 for(
unsigned k=0; k< rawObjects.
size(); k++ ){
249 streamlog_out(DEBUG4) <<
"MarlinTrk::createFit ndof_added = " << ndof_added <<
std::endl;
258 streamlog_out(DEBUG4) <<
"MarlinTrk::createFit ndof_added = " << ndof_added <<
std::endl;
266 streamlog_out(DEBUG2) <<
"Hit " << it - hit_list.
begin() <<
" Dropped " <<
std::endl;
272 streamlog_out(DEBUG2) <<
"MarlinTrk::createFit : Cannot fit less with less than " <<
MIN_NDF <<
" degrees of freedom. Number of hits = " << added_hits.
size() <<
" ndof = " << ndof_added <<
std::endl;
285 streamlog_out(DEBUG5) <<
"MarlinTrk::createFit : null pointer for pre_fit given - will fall back "
286 <<
" to default initialisation ..." <<
std::endl ;
288 return_error = marlinTrk->
initialise( fit_direction ) ;
292 return_error = marlinTrk->
initialise( *pre_fit, bfield_z, fit_direction ) ;
298 streamlog_out(DEBUG5) <<
"MarlinTrk::createFit Initialisation of track fit failed with error : " << return_error <<
std::endl;
312 streamlog_out(DEBUG5) <<
" MarlinTrk::createFit: pre-fit, propagated to the IP : " << ts <<
std::endl ;
323 return marlinTrk->
fit(maxChi2Increment) ;
346 for (
unsigned ihit=0; ihit < hit_list.
size(); ++ihit) {
359 if (twoD_hits.
size() < 3) {
360 streamlog_out(WARNING) <<
"MarlinTrk::createFinalisedLCIOTrack Cannot create helix from less than 3 2-D hits" <<
std::endl;
369 const double* x1 = twoD_hits[0]->getPosition();
370 const double* x2 = twoD_hits[ twoD_hits.
size()/2 ]->getPosition();
371 const double* x3 = twoD_hits.
back()->getPosition();
404 if( marlintrk == 0 ){
412 if( atCaloFace && atLastHit == 0 ){
416 if( atLastHit && atCaloFace == 0 ){
425 int return_error = 0;
428 double chi2 = -DBL_MAX;
435 return_error = marlintrk->
getNDF(ndf);
438 streamlog_out(DEBUG3) <<
"MarlinTrk::finaliseLCIOTrack: getNDF returns " << return_error <<
std::endl;
440 }
else if( ndf < 0 ) {
441 streamlog_out(DEBUG8) <<
"MarlinTrk::finaliseLCIOTrack: number of degrees of freedom less than 0 track dropped : NDF = " << ndf <<
std::endl;
444 streamlog_out(DEBUG4) <<
"MarlinTrk::finaliseLCIOTrack: NDF = " << ndf <<
std::endl;
470 for (
unsigned ihit = 0; ihit < hit_list.
size(); ++ihit) {
479 for(
unsigned k=0; k< rawObjects.
size(); k++ ){
483 bool is_outlier =
false;
486 for (
unsigned ohit = 0; ohit < outliers.
size(); ++ohit) {
488 if ( rawHit == outliers[ohit].first ) {
494 if (is_outlier ==
false) {
502 bool is_outlier =
false;
505 for (
unsigned ohit = 0; ohit < outliers.
size(); ++ohit) {
507 if ( trkHit == outliers[ohit].first ) {
513 if (is_outlier ==
false) {
548 streamlog_out(DEBUG3) <<
"MarlinTrk::finaliseLCIOTrack: firstHit : " <<
toString( firstHit )
549 <<
" lastHit: " <<
toString( lastHit )
550 <<
" last constrained hit: " <<
toString( last_constrained_hit )
551 <<
" fit direction is forward : " << fit_direction <<
std::endl ;
554 return_error = marlintrk->
smooth( last_constrained_hit );
556 streamlog_out(DEBUG4) <<
"MarlinTrk::finaliseLCIOTrack: return_code for smoothing to last constrained hit "
557 << last_constrained_hit <<
" = " << return_error <<
" NDF = " << ndf <<
std::endl;
560 delete trkStateAtFirstHit;
562 return return_error ;
576 streamlog_out(DEBUG4) <<
"MarlinTrk::finaliseLCIOTrack: finalised kaltest track : "
587 bool usingAidaTT = ( trksystem->
name() ==
"AidaTT" ) ;
593 return_error = marlintrk->
propagate(point, firstHit, *trkStateIP, chi2, ndf ) ;
608 return_error = marlintrk->
getTrackState( last_constrained_hit, ts , chi2 , ndf ) ;
610 streamlog_out( DEBUG3 ) <<
" MarlinTrk::finaliseLCIOTrack:-- TrackState at last constrained hit : " << std::endl
614 mTrk->addHit( last_constrained_hit ) ;
616 double _bfield = 42.0 ;
618 mTrk->initialise( ts , _bfield , fit_direction ) ;
622 while( (*hI).first != last_constrained_hit ){
624 streamlog_out( DEBUG0 ) <<
" MarlinTrk::finaliseLCIOTrack:-- hit in reverse_iterator : " << std::endl
631 while( hI != hits_in_fit.
rend() ){
637 double maxChi2Increment = 1e10 ;
639 int addHit = mTrk->addAndFit( h , deltaChi, maxChi2Increment ) ;
642 streamlog_out( DEBUG3 ) <<
" MarlinTrk::finaliseLCIOTrack: hit " <<
toString( h )
644 <<
" deltaChi2: " << deltaChi
649 streamlog_out( ERROR ) <<
" **** MarlinTrk::finaliseLCIOTrack: could not add inner hit to track !!! " <<
std::endl ;
656 streamlog_out(DEBUG4) <<
"MarlinTrk::finaliseLCIOTrack: temporary kaltest track for track state at the IP: "
660 return_error = mTrk->propagate( point, firstHit, *trkStateIP, chi2Tmp, ndfTmp ) ;
663 streamlog_out( DEBUG4 ) <<
" *** MarlinTrk::finaliseLCIOTrack: - propagated temporary track fromfirst hit to IP : " <<
toString( trkStateIP ) <<
std::endl ;
668 streamlog_out(DEBUG4) <<
"MarlinTrk::finaliseLCIOTrack: return_code for propagation = " << return_error <<
" NDF = " << ndf <<
std::endl;
670 delete trkStateAtFirstHit;
673 return return_error ;
676 trkStateIP->
setLocation( lcio::TrackState::AtIP ) ;
690 streamlog_out( DEBUG5 ) <<
" >>>>>>>>>>>MarlinTrk::finaliseLCIOTrack: create TrackState AtFirstHit" <<
std::endl ;
693 return_error = marlintrk->
getTrackState(firstHit, *trkStateAtFirstHit, chi2, ndf ) ;
696 trkStateAtFirstHit->
setLocation( lcio::TrackState::AtFirstHit ) ;
699 streamlog_out( WARNING ) <<
" >>>>>>>>>>>MarlinTrk::finaliseLCIOTrack: MarlinTrk::finaliseLCIOTrack: could not get TrackState at First Hit " << firstHit <<
std::endl ;
700 delete trkStateAtFirstHit;
707 if ( atLastHit == 0 && atCaloFace == 0 ) {
713 streamlog_out( DEBUG5 ) <<
" >>>>>>>>>>> MarlinTrk::finaliseLCIOTrack: create TrackState AtLastHit : using trkhit " << last_constrained_hit <<
std::endl ;
719 return_error = marlintrk->
propagate(last_hit_pos, last_constrained_hit, *trkStateAtLastHit, chi2, ndf);
724 trkStateAtLastHit->setLocation( lcio::TrackState::AtLastHit ) ;
727 streamlog_out( DEBUG5 ) <<
" >>>>>>>>>>> MarlinTrk::finaliseLCIOTrack: could not get TrackState at Last Hit " << last_constrained_hit <<
std::endl ;
728 delete trkStateAtLastHit;
748 trkStateCalo->
setLocation( lcio::TrackState::AtCalorimeter ) ;
751 streamlog_out( DEBUG9 ) <<
" >>>>>>>>>>> MarlinTrk::finaliseLCIOTrack: could not get TrackState at Calo Face " <<
std::endl ;
757 streamlog_out( DEBUG9 ) <<
" MarlinTrk::finaliseLCIOTrack: ignore missing TrackState at Calo Face for debugging " <<
std::endl ;
785 streamlog_out( DEBUG5 ) <<
" >>>>>>>>>>> createTrackStateAtCaloFace : using trkhit "
791 if( marlintrk == 0 ){
795 if( trkStateCalo == 0 ){
803 int return_error = 0;
805 double chi2 = -DBL_MAX;
813 unsigned ecal_barrel_face_ID = lcio::ILDDetID::ECAL ;
814 unsigned ecal_endcap_face_ID = lcio::ILDDetID::ECAL_ENDCAP ;
818 encoder[lcio::LCTrackerCellID::subdet()] = ecal_barrel_face_ID ;
819 encoder[lcio::LCTrackerCellID::side()] = lcio::ILDDetID::barrel;
820 encoder[lcio::LCTrackerCellID::layer()] = 0 ;
822 int detElementID = 0;
828 encoder[lcio::LCTrackerCellID::subdet()] = ecal_endcap_face_ID ;
830 if (tanL_is_positive) {
831 encoder[lcio::LCTrackerCellID::side()] = lcio::ILDDetID::fwd;
834 encoder[lcio::LCTrackerCellID::side()] = lcio::ILDDetID::bwd;
840 if( std::abs( trkStateCalo->getZ0() ) > std::abs( 2.*
M_PI/trkStateCalo->getOmega() * trkStateCalo->getTanLambda() ) ){
842 streamlog_out( DEBUG2 ) <<
" >>>>>>>>>>> createTrackStateAtCaloFace : setting z0 to 0. for track state at calorimeter : "
845 trkStateCalo->setZ0( 0. ) ;
849 streamlog_out( DEBUG5 ) <<
" >>>>>>>>>>> createTrackStateAtCaloFace : could not get TrackState at Calo Face: return_error = " << return_error <<
std::endl ;
869 for(
unsigned int j=0; j<hit_list.
size(); ++j) {
877 if ( hits_in_fit ==
false ) {
886 it != hitNumbers.
end() ; ++it ){
888 int detIndex = it->first ;
906 for(
unsigned int j=0; j<hit_list.
size(); ++j) {
915 if ( hits_in_fit ==
false ) {
925 it != hitNumbers.
end() ; ++it ){
927 int detIndex = it->first ;
virtual void addHit(EVENT::TrackerHit *hit)
virtual EVENT::TrackStateVec & trackStates()
virtual void setD0(float d0)
virtual const double * getPosition() const =0
virtual void setNdf(int ndf)
double getRefPointZ() const
virtual int smooth()=0
smooth all track states
virtual int getType() const =0
std::string toString(const T *obj)
virtual int propagateToLayer(int layerID, IMPL::TrackStateImpl &ts, double &chi2, int &ndf, int &detElementID, int mode=modeClosest)=0
propagate fit to numbered sensitive layer, returning TrackState, chi2, ndf and integer ID of the inte...
virtual int getTrackState(IMPL::TrackStateImpl &ts, double &chi2, int &ndf)=0
get track state, returning TrackState, chi2 and ndf via reference
virtual EVENT::IntVec & subdetectorHitNumbers()
static const bool backward
boolean constant for defining backward direction - to be used for intitialise
virtual int getNDF(int &ndf)=0
get the current number of degrees of freedom for the fit.
virtual void setTanLambda(float tanLambda)
virtual std::string toString()
Dump this track to a string for debugging - implementation dependant.
virtual int propagate(const Vector3D &point, IMPL::TrackStateImpl &ts, double &chi2, int &ndf)=0
propagate the fit to the point of closest approach to the given point, returning TrackState, chi2 and ndf via reference
static const int bad_intputs
dd4hep::rec::Vector3D Vector3D
the Vector3D used for the tracking interface
virtual void setReferencePoint(const float *rPnt)
int createTrackStateAtCaloFace(IMarlinTrack *marlinTrk, IMPL::TrackStateImpl *track, EVENT::TrackerHit *trkhit, bool tanL_is_positive)
virtual void setLocation(int location)
double getRefPointX() const
int createFit(std::vector< EVENT::TrackerHit * > &hit_list, IMarlinTrack *marlinTrk, EVENT::TrackState *pre_fit, float bfield_z, bool fit_direction, double maxChi2Increment=DBL_MAX)
Takes a list of hits and uses the IMarlinTrack inferface to fit them using a supplied prefit containi...
virtual int getTrackerHitAtPositiveNDF(EVENT::TrackerHit *&trkhit)=0
get TrackeHit at which fit became constrained, i.e.
virtual void setRadiusOfInnermostHit(float r)
virtual std::string name()
the name of the implementation
int finaliseLCIOTrack(IMarlinTrack *marlinTrk, IMPL::TrackImpl *track, std::vector< EVENT::TrackerHit * > &hit_list, bool fit_direction, IMPL::TrackStateImpl *atLastHit=0, IMPL::TrackStateImpl *atCaloFace=0)
Takes a fitted MarlinTrack, TrackImpl to record the fit and the hits which have been added to the fit...
Interface for generic tracks in MarlinTrk.
virtual void setCovMatrix(const float *cov)
virtual int fit(double maxChi2Increment=DBL_MAX)=0
perform the fit of all current hits, returns error code ( IMarlinTrack::success if no error ) ...
int createFinalisedLCIOTrack(IMarlinTrack *marlinTrk, std::vector< EVENT::TrackerHit * > &hit_list, IMPL::TrackImpl *track, bool fit_direction, EVENT::TrackState *pre_fit, float bfield_z, double maxChi2Increment=DBL_MAX)
Takes a list of hits and uses the IMarlinTrack inferface to fit them using a supplied prefit containi...
virtual int getOutliers(std::vector< std::pair< EVENT::TrackerHit *, double > > &hits)=0
get the list of hits which have been rejected by from the fit due to the a chi2 increment greater tha...
virtual float getTanLambda() const
virtual void setZ0(float z0)
virtual int getHitsInFit(std::vector< std::pair< EVENT::TrackerHit *, double > > &hits)=0
get the list of hits included in the fit, together with the chi2 contributions of the hits...
void setValue(lcio::long64 value)
virtual int getCellID0() const =0
virtual int addHit(EVENT::TrackerHit *hit)=0
add hit to track - the hits have to be added ordered in time ( i.e.
void addHitNumbersToTrack(IMPL::TrackImpl *track, std::vector< EVENT::TrackerHit * > &hit_list, bool hits_in_fit, UTIL::BitField64 &cellID_encoder)
Set the subdetector hit numbers for the TrackImpl.
static const int no_intersection
virtual void setChi2(float chi2)
virtual void setPhi(float phi)
static IMarlinTrkSystem * getCurrentMarlinTrkSystem()
Return the current MarlinTrkSystem, i.e.
int createPrefit(std::vector< EVENT::TrackerHit * > &hit_list, IMPL::TrackStateImpl *pre_fit, float bfield_z, bool fit_direction)
Provides the values of a track state from the first, middle and last hits in the hit_list.
std::string errorCode(int error)
Helper function to convert error return code to string.
double moveRefPoint(double x, double y, double z)
static const int modeForward
Base class for tracking system implementations in MarlinTrk.
virtual MarlinTrk::IMarlinTrack * createTrack()=0
Return an instance of IMarlinTrack corresponding to the current implementation.
virtual void setOmega(float omega)
double getRefPointY() const
double getTanLambda() const
static const int COMPOSITE_SPACEPOINT
static const int ONE_DIMENSIONAL
virtual const LCObjectVec & getRawHits() const =0
virtual int initialise(bool fitDirection)=0
initialise the fit using the hits added up to this point - the fit direction has to be specified usin...