6 #include <kaltest/TKalDetCradle.h>
7 #include <kaltest/TKalTrack.h>
8 #include <kaltest/TKalTrackState.h>
9 #include "kaltest/TKalTrackSite.h"
10 #include "TKalFilterCond.h"
20 #include "DDKalTest/DDCylinderMeasLayer.h"
21 #include "DDKalTest/DDCylinderHit.h"
22 #include "DDKalTest/DDPlanarHit.h"
27 #include "streamlog/streamlog.h"
44 double deltaChi2 = site.GetDeltaChi2();
69 bf.setValue( detElementID ) ;
70 return bf.valueString() ;
92 #ifdef MARLINTRK_DIAGNOSTICS_ON
93 _ktest->_diagnostics.new_track(
this) ;
102 #ifdef MARLINTRK_DIAGNOSTICS_ON
103 _ktest->_diagnostics.end_track() ;
123 streamlog_out(DEBUG1) <<
"MarlinDDKalTestTrack::addHit: trkhit = " << trkhit->id() <<
" addr: " << trkhit <<
" ml = " << ml <<
std::endl ;
126 return this->
addHit( trkhit, ml->ConvertLCIOTrkHit(trkhit), ml) ;
129 streamlog_out( ERROR ) <<
" MarlinDDKalTestTrack::addHit - bad inputs " << trkhit <<
" ml : " << ml <<
std::endl ;
147 streamlog_out(DEBUG1) <<
"MarlinDDKalTestTrack::addHit: hit added "
148 <<
"number of hits for track = " <<
_kalhits->GetEntries()
169 streamlog_out( ERROR) <<
"<<<<<< MarlinDDKalTestTrack::initialise: Shortage of Hits! nhits = "
191 TVTrackHit *startingHit =
dynamic_cast<TVTrackHit *
>(
_kalhits->At(i1));
198 TVTrackHit* pDummyHit = 0;
200 if ( (pDummyHit = dynamic_cast<DDCylinderHit *>( startingHit )) ) {
201 pDummyHit = (
new DDCylinderHit(*static_cast<DDCylinderHit*>( startingHit )));
203 else if ( (pDummyHit = dynamic_cast<DDPlanarHit *>( startingHit )) ) {
204 pDummyHit = (
new DDPlanarHit(*static_cast<DDPlanarHit*>( startingHit )));
210 streamlog_out( ERROR) <<
"<<<<<<<<< MarlinDDKalTestTrack::initialise: dynamic_cast failed for hit type >>>>>>>" <<
std::endl;
214 TVTrackHit& dummyHit = *pDummyHit;
218 dummyHit(0,1) = 1.e16;
219 dummyHit(1,1) = 1.e16;
222 TKalTrackSite& initialSite = *
new TKalTrackSite(dummyHit);
224 initialSite.SetHitOwner();
225 initialSite.SetOwner();
231 TVTrackHit &h1 = *
dynamic_cast<TVTrackHit *
>(
_kalhits->At(i1));
232 TVTrackHit &h2 = *
dynamic_cast<TVTrackHit *
>(
_kalhits->At(i2));
233 TVTrackHit &h3 = *
dynamic_cast<TVTrackHit *
>(
_kalhits->At(i3));
234 TVector3 x1 = h1.GetMeasLayer().HitToXv(h1);
235 TVector3 x2 = h2.GetMeasLayer().HitToXv(h2);
236 TVector3 x3 = h3.GetMeasLayer().HitToXv(h3);
238 if ( h1.GetDimension() == 1 || h2.GetDimension() == 1 || h3.GetDimension() == 1 ) {
240 throw MarlinTrk::Exception(
"Track fit cannot be initialised from 1 Dimensional hits. Use method MarlinDDKalTestTrack::initialise( bool fitDirection )");
245 streamlog_out(DEBUG2) <<
"MarlinDDKalTestTrack::initialise Create initial helix from hits: \n "
246 <<
"P1 x = " << x1.x() <<
" y = " << x1.y() <<
" z = " << x1.z() <<
" r = " << x1.Perp() <<
"\n "
247 <<
"P2 x = " << x2.x() <<
" y = " << x2.y() <<
" z = " << x2.z() <<
" r = " << x2.Perp() <<
"\n "
248 <<
"P3 x = " << x3.x() <<
" y = " << x3.y() <<
" z = " << x3.z() <<
" r = " << x3.Perp() <<
"\n "
249 <<
"Bz = " << h1.GetBfield() <<
" direction = " <<
_fitDirection
253 THelicalTrack helstart(x1, x2, x3, h1.GetBfield(),
_fitDirection);
259 static TKalMatrix initialState(kSdim,1) ;
260 initialState(0,0) = 0.0 ;
261 initialState(1,0) = helstart.GetPhi0() ;
262 initialState(2,0) = helstart.GetKappa() ;
263 initialState(3,0) = 0.0 ;
264 initialState(4,0) = helstart.GetTanLambda() ;
265 if (kSdim == 6) initialState(5,0) = 0.;
272 TKalMatrix Cov(kSdim,kSdim);
275 for (
int i=0; i<kSdim*kSdim; ++i) {
276 Cov.GetMatrixArray()[i] = 0.0;
292 if (kSdim == 6) Cov(5,5) = 1.e2;
295 initialSite.Add(
new TKalTrackState(initialState,Cov,initialSite,TVKalSite::kPredicted));
296 initialSite.Add(
new TKalTrackState(initialState,Cov,initialSite,TVKalSite::kFiltered));
307 <<
"\t Omega " << 1. /helstart.GetRho()
309 <<
"\t tan(Lambda) " << helstart.GetTanLambda()
311 <<
"\t pivot : [" << helstart.GetPivot().X() <<
", " << helstart.GetPivot().Y() <<
", " << helstart.GetPivot().Z()
312 <<
" - r: " <<
std::sqrt( helstart.GetPivot().X()*helstart.GetPivot().X()+helstart.GetPivot().Y()*helstart.GetPivot().Y() ) <<
"]"
315 #ifdef MARLINTRK_DIAGNOSTICS_ON
321 double omega = 1. /helstart.GetRho() ;
323 double tanLambda = helstart.GetTanLambda() ;
327 _ktest->_diagnostics.set_intial_track_parameters(d0,
332 helstart.GetPivot().X(),
333 helstart.GetPivot().Y(),
334 helstart.GetPivot().Z(),
353 streamlog_out( ERROR) <<
"<<<<<< MarlinDDKalTestTrack::Initialise: Number of Hits is Zero. Cannot Initialise >>>>>>>" <<
std::endl;
366 streamlog_out( DEBUG2 ) <<
"MarlinDDKalTestTrack::initialise using TrackState: track parameters used for init : "
367 <<
"\t D0 " << ts.
getD0()
368 <<
"\t Phi :" << ts.
getPhi()
370 <<
"\t Z0 " << ts.
getZ0()
381 TVTrackHit &h1 = *
dynamic_cast<TVTrackHit *
>(
_kalhits->At(0));
382 double Bz = h1.GetBfield() ;
385 double alpha = Bz * 2.99792458E-4 ;
387 double kappa = ( Bz == 0.0 ? DBL_MAX : ts.
getOmega() / alpha ) ;
389 THelicalTrack helix( -ts.
getD0(),
403 cov( 0 , 0 ) = covLCIO[ 0] ;
404 cov( 0 , 1 ) = - covLCIO[ 1] ;
405 cov( 0 , 2 ) = - covLCIO[ 3] / alpha ;
406 cov( 0 , 3 ) = - covLCIO[ 6] ;
407 cov( 0 , 4 ) = - covLCIO[10] ;
409 cov( 1 , 0 ) = - covLCIO[ 1] ;
410 cov( 1 , 1 ) = covLCIO[ 2] ;
411 cov( 1 , 2 ) = covLCIO[ 4] / alpha ;
412 cov( 1 , 3 ) = covLCIO[ 7] ;
413 cov( 1 , 4 ) = covLCIO[11] ;
415 cov( 2 , 0 ) = - covLCIO[ 3] / alpha ;
416 cov( 2 , 1 ) = covLCIO[ 4] / alpha ;
417 cov( 2 , 2 ) = covLCIO[ 5] / (alpha * alpha) ;
418 cov( 2 , 3 ) = covLCIO[ 8] / alpha ;
419 cov( 2 , 4 ) = covLCIO[12] / alpha ;
421 cov( 3 , 0 ) = - covLCIO[ 6] ;
422 cov( 3 , 1 ) = covLCIO[ 7] ;
423 cov( 3 , 2 ) = covLCIO[ 8] / alpha ;
424 cov( 3 , 3 ) = covLCIO[ 9] ;
425 cov( 3 , 4 ) = covLCIO[13] ;
427 cov( 4 , 0 ) = - covLCIO[10] ;
428 cov( 4 , 1 ) = covLCIO[11] ;
429 cov( 4 , 2 ) = covLCIO[12] / alpha ;
430 cov( 4 , 3 ) = covLCIO[13] ;
431 cov( 4 , 4 ) = covLCIO[14] ;
438 int index =
_kalhits->GetEntries() - 1 ;
444 TVTrackHit* kalhit =
dynamic_cast<TVTrackHit *
>(
_kalhits->At(index));
448 TVector3 initial_pivot ;
451 if (kalhit->GetDimension() > 1) {
453 initial_pivot = kalhit->GetMeasLayer().HitToXv(*kalhit) ;
456 initial_pivot = TVector3(0.0,0.0,0.0);
465 TVTrackHit* pDummyHit = 0;
467 if ( (pDummyHit = dynamic_cast<DDCylinderHit *>( kalhit )) ) {
468 pDummyHit = (
new DDCylinderHit(*static_cast<DDCylinderHit*>( kalhit )));
471 else if ( (pDummyHit = dynamic_cast<DDPlanarHit *>( kalhit )) ) {
472 pDummyHit = (
new DDPlanarHit(*static_cast<DDPlanarHit*>( kalhit )));
476 if( pDummyHit->GetDimension() == 1 ) {
478 const TVMeasLayer *ml = &pDummyHit->GetMeasLayer();
480 const TVSurface* surf =
dynamic_cast<const TVSurface*
>(ml);
485 surf->CalcXingPointWith(helix, initial_pivot, phi);
486 streamlog_out( DEBUG ) <<
" MarlinDDKalTestTrack::initialise - CalcXingPointWith called for 1d hit ... " <<
std::endl ;
489 streamlog_out( ERROR) <<
"<<<<<<<<< MarlinDDKalTestTrack::initialise: dynamic_cast failed for TVSurface >>>>>>>" <<
std::endl;
496 streamlog_out( ERROR) <<
"<<<<<<<<< MarlinDDKalTestTrack::initialise: dynamic_cast failed for hit type >>>>>>>" <<
std::endl;
500 TVTrackHit& dummyHit = *pDummyHit;
504 dummyHit(0,1) = 1.e16;
506 if(dummyHit.GetDimension()>1) dummyHit(1,1) = 1.e16;
509 TKalTrackSite& initialSite = *
new TKalTrackSite(dummyHit);
511 initialSite.SetHitOwner();
512 initialSite.SetOwner();
518 helix.MoveTo( initial_pivot, dphi, 0, &cov );
520 static TKalMatrix initialState(kSdim,1) ;
521 initialState(0,0) = helix.GetDrho() ;
522 initialState(1,0) = helix.GetPhi0() ;
523 initialState(2,0) = helix.GetKappa() ;
524 initialState(3,0) = helix.GetDz();
525 initialState(4,0) = helix.GetTanLambda() ;
526 if (kSdim == 6) initialState(5,0) = 0.;
529 initialSite.SetPivot(initial_pivot);
535 TKalMatrix covK(kSdim,kSdim) ;
536 for(
int i=0;i<5;++i) {
537 for(
int j=0;j<5;++j) {
538 covK[i][j] = cov[i][j] ;
541 if (kSdim == 6) covK(5,5) = 1.e6;
546 initialSite.Add(
new TKalTrackState(initialState,covK,initialSite,TVKalSite::kPredicted));
547 initialSite.Add(
new TKalTrackState(initialState,covK,initialSite,TVKalSite::kFiltered));
556 #ifdef MARLINTRK_DIAGNOSTICS_ON
560 double d0 = - helix.GetDrho() ;
562 double omega = 1. /helix.GetRho() ;
563 double z0 = helix.GetDz() ;
564 double tanLambda = helix.GetTanLambda() ;
566 _ktest->_diagnostics.set_intial_track_parameters(d0,
571 helix.GetPivot().X(),
572 helix.GetPivot().Y(),
573 helix.GetPivot().Z(),
586 streamlog_out(DEBUG1) <<
"MarlinDDKalTestTrack::addAndFit called : maxChi2Increment = " <<
std::scientific << maxChi2Increment <<
std::endl ;
596 streamlog_out( DEBUG1 ) <<
"Kaltrack::addAndFit : add site to track at index : "
597 << (
dynamic_cast<const DDVMeasLayer*
>( &(kalhit->GetMeasLayer() ) ))->GetIndex()
599 <<
dynamic_cast<const DDVMeasLayer*
>( &(kalhit->GetMeasLayer() ) )->GetName() ;
600 streamlog_out( DEBUG0 ) <<
" with CellIDs:";
602 for (
unsigned int i = 0; i < (dynamic_cast<const DDVMeasLayer*>( &(kalhit->GetMeasLayer() ) )->getNCellIDs());++i) {
603 streamlog_out( DEBUG0 ) <<
" : "
604 <<
dynamic_cast<const DDVMeasLayer*
>( &(kalhit->GetMeasLayer() ) )->getCellIDs()[i] ;
610 TKalTrackSite* temp_site =
new TKalTrackSite(*kalhit);
615 temp_site->SetFilterCond( &filter ) ;
624 if (!
_kaltrack->AddAndFilter(*temp_site)) {
626 chi2increment = temp_site->GetDeltaChi2() ;
628 const DDVMeasLayer* ml =
dynamic_cast<const DDVMeasLayer*
>( &(kalhit->GetMeasLayer() ) ) ;
629 TVector3 pos = ml->HitToXv(*kalhit);
630 streamlog_out( DEBUG2 ) <<
"Kaltrack::addAndFit : site discarded! at index : " << ml->GetIndex()
631 <<
" for type " << ml->GetName()
632 <<
" chi2increment = " << chi2increment
633 <<
" maxChi2Increment = " << maxChi2Increment
634 <<
" x = " << pos.x()
635 <<
" y = " << pos.y()
636 <<
" z = " << pos.z()
639 for (
unsigned int i = 0; i < (dynamic_cast<const DDVMeasLayer*>( &(kalhit->GetMeasLayer() ) )->getNCellIDs());++i) {
640 streamlog_out( DEBUG1 ) <<
" CellID = "
641 <<
dynamic_cast<const DDVMeasLayer*
>( &(kalhit->GetMeasLayer() ) )->getCellIDs()[i]
646 #ifdef MARLINTRK_DIAGNOSTICS_ON
647 _ktest->_diagnostics.record_rejected_site(kalhit, temp_site);
680 chi2increment = site->GetDeltaChi2() ;
682 #ifdef MARLINTRK_DIAGNOSTICS_ON
683 _ktest->_diagnostics.record_site(kalhit, site);
693 streamlog_out( ERROR) <<
"MarlinDDKalTestTrack::addAndFit( EVENT::TrackerHit* trkhit, double& chi2increment, double maxChi2Increment): trkhit == 0" <<
std::endl;
703 streamlog_out( ERROR ) <<
">>>>>>>>>>> no measurment layer found for trkhit cellid0 : "
710 DDVTrackHit* kalhit = ml->ConvertLCIOTrkHit(trkhit) ;
716 TKalTrackSite* site = 0 ;
717 int error_code = this->
addAndFit( kalhit, chi2increment, site, maxChi2Increment);
725 chi2increment = DBL_MAX;
730 streamlog_out( DEBUG2 ) <<
">>>>>>>>>>> addAndFit Number of Outliers : "
736 this->
addHit( trkhit, kalhit, ml ) ;
747 streamlog_out( DEBUG2 ) <<
">>>>>>>>>>> Fit is now constrained at : "
766 streamlog_out( ERROR) <<
"MarlinDDKalTestTrack::addAndFit( EVENT::TrackerHit* trkhit, double& chi2increment, double maxChi2Increment): trkhit == 0" <<
std::endl;
776 streamlog_out( ERROR ) <<
">>>>>>>>>>> no measurment layer found for trkhit cellid0 : "
784 DDVTrackHit* kalhit = ml->ConvertLCIOTrkHit(trkhit) ;
791 TKalTrackSite* site = 0 ;
792 int error_code = this->
addAndFit( kalhit, chi2increment, site, -DBL_MAX);
810 streamlog_out(DEBUG2) <<
"MarlinDDKalTestTrack::fit() called " <<
std::endl ;
828 DDVTrackHit *kalhit = 0;
830 while ( (kalhit = dynamic_cast<DDVTrackHit *>( next() ) ) ) {
832 double chi2increment;
833 TKalTrackSite* site=
nullptr;
834 int error_code = this->
addAndFit( kalhit, chi2increment, site, maxChi2Increment );
839 if( error_code == 0 ){
849 streamlog_out( DEBUG2 ) <<
">>>>>>>>>>> Fit is now constrained at : "
864 chi2increment = DBL_MAX;
868 streamlog_out( DEBUG2 ) <<
">>>>>>>>>>> fit(): Number of Outliers : "
878 streamlog_out( DEBUG2 ) <<
"Perform Smoothing for All Previous Measurement Sites " <<
std::endl ;
901 streamlog_out( DEBUG2 ) <<
"MarlinDDKalTestTrack::smooth() " <<
std::endl ;
925 streamlog_out( DEBUG2 ) <<
"MarlinDDKalTestTrack::smooth( EVENT::TrackerHit* " << trkhit <<
" ) " <<
std::endl ;
936 TKalTrackSite* site = 0 ;
939 if( error_code !=
success )
return error_code ;
954 streamlog_out( DEBUG2 ) <<
"MarlinDDKalTestTrack::getTrackState( IMPL::TrackStateImpl& ts ) " <<
std::endl ;
957 const TKalTrackSite& site = *(
dynamic_cast<const TKalTrackSite*
>(
_kaltrack->Last())) ;
969 streamlog_out( DEBUG2 ) <<
"MarlinDDKalTestTrack::getTrackState( EVENT::TrackerHit* trkhit, IMPL::TrackStateImpl& ts ) using hit: " << trkhit <<
" with cellID0 = " << trkhit->
getCellID0() <<
std::endl ;
971 TKalTrackSite* site = 0 ;
974 if( error_code !=
success )
return error_code ;
976 streamlog_out( DEBUG1 ) <<
"MarlinDDKalTestTrack::getTrackState: site " << site <<
std::endl;
1049 const TKalTrackSite& site = *(
dynamic_cast<const TKalTrackSite*
>(
_kaltrack->Last())) ;
1051 return this->
extrapolate( point, site, ts, chi2, ndf ) ;
1057 TKalTrackSite* site = 0 ;
1060 if( error_code !=
success )
return error_code;
1062 return this->
extrapolate( point, *site, ts, chi2, ndf ) ;
1068 streamlog_out(DEBUG2) <<
"MarlinDDKalTestTrack::extrapolate( const Vector3D& point, IMPL::TrackStateImpl& ts, double& chi2, int& ndf ) called " <<
std::endl ;
1070 TKalTrackState& trkState = (TKalTrackState&) site.GetCurState();
1072 THelicalTrack helix = trkState.GetHelix() ;
1075 const TVector3 tpoint( point.
x(), point.
y(), point.
z() ) ;
1077 Int_t sdim = trkState.GetDimension();
1078 TKalMatrix sv(sdim,1);
1081 TKalMatrix DF(sdim,sdim);
1083 helix.MoveTo( tpoint , dPhi , &DF , 0) ;
1085 TMatrixD c0(trkState.GetCovMat());
1087 TKalMatrix DFt = TKalMatrix(TMatrixD::kTransposed, DF);
1088 c0 = DF * c0 * DFt ;
1099 const TKalTrackSite& site = *(
dynamic_cast<const TKalTrackSite*
>(
_kaltrack->Last())) ;
1101 return this->
extrapolateToLayer( layerID, site, ts, chi2, ndf, detElementID, mode ) ;
1108 TKalTrackSite* site = 0;
1111 if( error_code !=
success )
return error_code ;
1113 return this->
extrapolateToLayer( layerID, *site, ts, chi2, ndf, detElementID, mode ) ;
1120 streamlog_out(DEBUG2) <<
"MarlinDDKalTestTrack::extrapolateToLayer( int layerID, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int& detElementID ) called " <<
std::endl ;
1123 const DDVMeasLayer* ml = 0;
1125 int error_code = this->
intersectionWithLayer( layerID, site, crossing_point, detElementID, ml, mode ) ;
1127 if( error_code != 0 )
return error_code ;
1129 return this->
extrapolate( crossing_point, site, ts, chi2, ndf ) ;
1136 const TKalTrackSite& site = *(
dynamic_cast<const TKalTrackSite*
>(
_kaltrack->Last())) ;
1145 TKalTrackSite* site = 0;
1148 if( error_code !=
success )
return error_code ;
1157 streamlog_out(DEBUG2) <<
"MarlinDDKalTestTrack::extrapolateToDetElement( int detElementID, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int mode ) called " <<
std::endl ;
1161 const DDVMeasLayer* ml = 0;
1164 if( error_code != 0 )
return error_code ;
1166 return this->
extrapolate( crossing_point, site, ts, chi2, ndf ) ;
1174 const TKalTrackSite& site = *(
dynamic_cast<const TKalTrackSite*
>(
_kaltrack->Last())) ;
1180 return this->
propagate( point, site, ts, chi2, ndf, ml ) ;
1186 TKalTrackSite* site = 0;
1189 if( error_code !=
success )
return error_code ;
1201 return this->
propagate( point, *site, ts, chi2, ndf, ml ) ;
1207 streamlog_out(DEBUG2) <<
"MarlinDDKalTestTrack::propagate( const Vector3D& point, const TKalTrackSite& site, IMPL::TrackStateImpl& ts, double& chi2, int& ndf ) called " <<
std::endl ;
1209 const TVector3 tpoint( point.
x(), point.
y(), point.
z() ) ;
1211 TKalTrackState& trkState = (TKalTrackState&) site.GetCurState();
1213 THelicalTrack helix = trkState.GetHelix() ;
1217 Int_t sdim = trkState.GetDimension();
1218 TKalMatrix sv(sdim,1);
1220 TKalMatrix F(sdim,sdim);
1223 TKalMatrix Q(sdim,sdim);
1227 TMatrixD c0(trkState.GetCovMat());
1236 _ktest->
_det->Transport(site, *ml, x0, sv, F, Q ) ;
1243 TKalMatrix Ft = TKalMatrix(TMatrixD::kTransposed, F);
1244 c0 = F * c0 * Ft + Q;
1246 helix.MoveTo( x0 , dPhi , 0 , 0 ) ;
1252 ml =
dynamic_cast<const DDVMeasLayer*
>(&(site.GetHit().GetMeasLayer())) ;
1257 const TVSurface *sfp =
dynamic_cast<const TVSurface *
>(ml);
1259 TMatrixD dxdphi = helix.CalcDxDphi(0);
1260 TVector3 dxdphiv(dxdphi(0,0),dxdphi(1,0),dxdphi(2,0));
1263 Bool_t isout = -dPhi*dxdphiv.Dot(sfp->GetOutwardNormal(x0)) < 0 ? kTRUE : kFALSE;
1266 TKalMatrix DF(sdim,sdim);
1268 helix.MoveTo( tpoint , dPhi , &DF , 0) ;
1270 TKalMatrix Qms(sdim, sdim);
1271 ml->CalcQms(isout, helix, dPhi, Qms);
1273 TKalMatrix DFt = TKalMatrix(TMatrixD::kTransposed, DF);
1274 c0 = DF * c0 * DFt + Qms ;
1286 const TKalTrackSite& site = *(
dynamic_cast<const TKalTrackSite*
>(
_kaltrack->Last())) ;
1288 return this->
propagateToLayer( layerID, site, ts, chi2, ndf, detElementID, mode ) ;
1295 TKalTrackSite* site = 0;
1298 if( error_code !=
success )
return error_code ;
1300 return this->
propagateToLayer( layerID, *site, ts, chi2, ndf, detElementID, mode ) ;
1307 streamlog_out(DEBUG2) <<
"MarlinDDKalTestTrack::propagateToLayer( int layerID, const TKalTrackSite& site, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int& detElementID ) called " <<
std::endl;
1311 const DDVMeasLayer* ml = 0;
1313 int error_code = this->
intersectionWithLayer( layerID, site, crossing_point, detElementID, ml, mode) ;
1315 if( error_code !=
success )
return error_code ;
1317 return this->
propagate( crossing_point, site, ts, chi2, ndf , ml) ;
1324 const TKalTrackSite& site = *(
dynamic_cast<const TKalTrackSite*
>(
_kaltrack->Last())) ;
1333 TKalTrackSite* site = 0;
1336 if( error_code !=
success )
return error_code ;
1345 streamlog_out(DEBUG2) <<
"MarlinDDKalTestTrack::propagateToDetElement( int detElementID, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int mode ) called " <<
std::endl ;
1349 const DDVMeasLayer* ml = 0;
1352 if( error_code != 0 )
return error_code ;
1354 return this->
propagate( crossing_point, site, ts, chi2, ndf, ml ) ;
1361 const TKalTrackSite& site = *(
dynamic_cast<const TKalTrackSite*
>(
_kaltrack->Last())) ;
1363 const DDVMeasLayer* ml = 0;
1371 TKalTrackSite* site = 0;
1374 if( error_code !=
success )
return error_code ;
1376 const DDVMeasLayer* ml = 0;
1383 streamlog_out(DEBUG2) <<
"MarlinDDKalTestTrack::intersectionWithDetElement( int detElementID, const TKalTrackSite& site, Vector3D& point, const DDVMeasLayer*& ml, int mode) called " <<
std::endl;
1388 if( meas_modules.
size() == 0 ) {
1391 errorMsg <<
"MarlinDDKalTestTrack::intersectionWithDetElement detector element id unkown: detElementID = "
1398 int dummy_detElementID;
1399 int error_code = this->
findIntersection( meas_modules, site, point, dummy_detElementID, ml, mode ) ;
1404 streamlog_out(DEBUG1) <<
"MarlinDDKalTestTrack::intersectionWithDetElement intersection with detElementID = "
1406 <<
": at x = " << point.
x()
1407 <<
" y = " << point.
y()
1408 <<
" z = " << point.
z()
1416 streamlog_out(DEBUG1) <<
"MarlinDDKalTestTrack::intersectionWithDetElement No intersection with detElementID = "
1428 const TKalTrackSite& site = *(
dynamic_cast<const TKalTrackSite*
>(
_kaltrack->Last())) ;
1429 const DDVMeasLayer* ml = 0;
1437 TKalTrackSite* site = 0;
1440 if( error_code !=
success )
return error_code ;
1442 const DDVMeasLayer* ml = 0;
1450 streamlog_out(DEBUG2) <<
"MarlinDDKalTestTrack::intersectionWithLayer( int layerID, const TKalTrackSite& site, Vector3D& point, int& detElementID, int mode) called layerID = " << layerID <<
std::endl;
1455 if( meas_modules.
size() == 0 ) {
1457 streamlog_out(DEBUG5)<<
"MarlinDDKalTestTrack::intersectionWithLayer layer id unknown: layerID = " <<
cellIDString( layerID ) <<
std::endl ;
1463 int error_code = this->
findIntersection( meas_modules, site, point, detElementID, ml, mode ) ;
1468 streamlog_out(DEBUG1) <<
"MarlinDDKalTestTrack::intersectionWithLayer intersection with layerID = "
1470 <<
": at x = " << point.
x()
1471 <<
" y = " << point.
y()
1472 <<
" z = " << point.
z()
1473 <<
" r = " << point.
rho()
1474 <<
" detElementID = " << detElementID
1482 streamlog_out(DEBUG1) <<
"MarlinDDKalTestTrack::intersectionWithLayer No intersection with layerID = "
1498 TKalTrackState& trkState = (TKalTrackState&) site.GetCurState();
1514 THelicalTrack helix = trkState.GetHelix() ;
1518 int crossing_exist = meas_module.getIntersectionAndCellID(helix, xto, dphi, detElementID, mode);
1521 streamlog_out(DEBUG1) <<
"MarlinDDKalTestTrack::intersectionWithLayer crossing_exist = " << crossing_exist <<
" dphi " << dphi <<
" with detElementIDs: " << detElementID ;
1526 if( crossing_exist == 0 ) {
1545 unsigned int n_modules = meas_modules.
size() ;
1547 double dphi_min = DBL_MAX;
1548 bool surf_found(
false);
1550 for(
unsigned int i = 0 ; i < n_modules ; ++i ){
1556 int temp_detElementID;
1558 int error_code =
findIntersection( *meas_modules[i], site, point_temp, dphi, temp_detElementID, mode ) ;
1563 if( fabs(dphi) < dphi_min ) {
1565 dphi_min = fabs(dphi) ;
1567 ml = meas_modules[i];
1568 detElementID = temp_detElementID;
1569 point = point_temp ;
1602 TMatrixD covK(5,5) ;
for(
int i=0;i<5;++i)
for(
int j=0;j<5;++j) covK[i][j] = cov[i][j] ;
1606 double omega = 1. /helix.GetRho() ;
1607 double d0 = - helix.GetDrho() ;
1608 double z0 = helix.GetDz() ;
1609 double tanLambda = helix.GetTanLambda() ;
1617 Double_t cpa = helix.GetKappa();
1618 double alpha = omega / cpa ;
1621 covLCIO[ 0] = covK( 0 , 0 ) ;
1623 covLCIO[ 1] = - covK( 1 , 0 ) ;
1624 covLCIO[ 2] = covK( 1 , 1 ) ;
1626 covLCIO[ 3] = - covK( 2 , 0 ) * alpha ;
1627 covLCIO[ 4] = covK( 2 , 1 ) * alpha ;
1628 covLCIO[ 5] = covK( 2 , 2 ) * alpha * alpha ;
1630 covLCIO[ 6] = - covK( 3 , 0 ) ;
1631 covLCIO[ 7] = covK( 3 , 1 ) ;
1632 covLCIO[ 8] = covK( 3 , 2 ) * alpha ;
1633 covLCIO[ 9] = covK( 3 , 3 ) ;
1635 covLCIO[10] = - covK( 4 , 0 ) ;
1636 covLCIO[11] = covK( 4 , 1 ) ;
1637 covLCIO[12] = covK( 4 , 2 ) * alpha ;
1638 covLCIO[13] = covK( 4 , 3 ) ;
1639 covLCIO[14] = covK( 4 , 4 ) ;
1647 pivot[0] = helix.GetPivot().X() ;
1648 pivot[1] = helix.GetPivot().Y() ;
1649 pivot[2] = helix.GetPivot().Z() ;
1653 streamlog_out( DEBUG2 ) <<
" kaltest track parameters: "
1654 <<
" chi2/ndf " << chi2 / ndf
1657 <<
" prob " << TMath::Prob(chi2, ndf)
1660 <<
"\t D0 " << d0 <<
"[+/-" << sqrt( covLCIO[0] ) <<
"] "
1661 <<
"\t Phi :" << phi <<
"[+/-" << sqrt( covLCIO[2] ) <<
"] "
1662 <<
"\t Omega " << omega <<
"[+/-" << sqrt( covLCIO[5] ) <<
"] "
1663 <<
"\t Z0 " << z0 <<
"[+/-" << sqrt( covLCIO[9] ) <<
"] "
1664 <<
"\t tan(Lambda) " << tanLambda <<
"[+/-" << sqrt( covLCIO[14]) <<
"] "
1666 <<
"\t pivot : [" << pivot[0] <<
", " << pivot[1] <<
", " << pivot[2]
1667 <<
" - r: " <<
std::sqrt( pivot[0]*pivot[0]+pivot[1]*pivot[1] ) <<
"]"
1676 TKalTrackState& trkState = (TKalTrackState&) site.GetCurState();
1684 THelicalTrack helix = trkState.GetHelix() ;
1686 TMatrixD c0(trkState.GetCovMat());
1701 str <<
" --------------------- " <<
std::endl ;
1721 streamlog_out( DEBUG2 ) <<
"MarlinDDKalTestTrack::getSiteFromLCIOHit: hit was rejected during filtering" <<
std::endl ;
1725 streamlog_out( DEBUG2 ) <<
"MarlinDDKalTestTrack::getSiteFromLCIOHit: hit " << trkhit <<
" not in list of supplied hits" <<
std::endl ;
1733 streamlog_out( DEBUG1 ) <<
"MarlinDDKalTestTrack::getSiteFromLCIOHit: site " << site <<
" found for hit " << trkhit <<
std::endl ;
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...
MarlinDDKalTestTrack(MarlinDDKalTest *ktest)
int intersectionWithDetElement(int detElementID, Vector3D &point, int mode=modeClosest)
extrapolate the fit to numbered sensitive detector element, returning intersection point in global co...
int getSiteFromLCIOHit(EVENT::TrackerHit *trkhit, TKalTrackSite *&site) const
get the measurement site associated with the given lcio TrackerHit trkhit
virtual void setD0(float d0)
virtual const double * getPosition() const =0
virtual float getTanLambda() const =0
std::string toString()
Dump this track to a string for debugging.
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 ...
int findIntersection(std::vector< DDVMeasLayer const * > &meas_modules, const TKalTrackSite &site, Vector3D &point, int &detElementID, const DDVMeasLayer *&ml, int mode=modeClosest)
extrapolate the fit at the measurement site, to sensitive detector elements contained in the std::vec...
KalTrackFilter(double maxDeltaChi2=DBL_MAX)
C'tor - takes as optional argument the maximum allowed delta chi2 for adding the hit (in IsAccepted()...
virtual void setTanLambda(float tanLambda)
virtual float getOmega() const =0
virtual const FloatVec & getCovMatrix() const =0
std::string cellIDString(int detElementID)
std::map< EVENT::TrackerHit *, DDVTrackHit * > _lcio_hits_to_kaltest_hits
map to store relation between lcio hits kaltest hits
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...
Helper class for defining a filter condition based on the delta chi2 in the AddAndFilter step...
static const bool forward
boolean constant for defining backward direction - to be used for intitialise
static const unsigned useSmoothing
Use smoothing when calling fit( bool fitDirection )
const DDVMeasLayer * getLastMeasLayer(THelicalTrack const &helix, TVector3 const &point) const
bool _fitDirection
used to store the fit direction supplied to intialise
virtual std::string toString()
Dump this track to a string for debugging - implementation dependant.
void ToLCIOTrackState(const TKalTrackSite &site, IMPL::TrackStateImpl &ts, double &chi2, int &ndf) const
fill LCIO Track State with parameters from helix and cov matrix
int getNDF(int &ndf)
get the current number of degrees of freedom for the fit.
void getSensitiveMeasurementModulesForLayer(int layerID, std::vector< const DDVMeasLayer * > &measmodules) const
Store active measurement module IDs needed for navigation.
static const int bad_intputs
int fit(double maxChi2Increment=DBL_MAX)
perform the fit of all current hits, returns error code ( IMarlinTrack::success if no error ) ...
dd4hep::rec::Vector3D Vector3D
the Vector3D used for the tracking interface
virtual void setReferencePoint(const float *rPnt)
int addHit(EVENT::TrackerHit *hit)
add hit to track - the hits have to be added ordered in time ( i.e.
std::map< EVENT::TrackerHit *, TKalTrackSite * > _hit_used_for_sites
map to store relation between lcio hits and measurement sites
virtual float getD0() const =0
void setMass(double mass)
set the mass of the charged particle (GeV) that is used for energy loss and multiple scattering - def...
bool _initialised
used to store whether initial track state has been supplied or created
int _hitIndexAtPositiveNDF
int testChi2Increment(EVENT::TrackerHit *hit, double &chi2increment)
obtain the chi2 increment which would result in adding the hit to the fit.
void getSensitiveMeasurementModules(int detElementID, std::vector< const DDVMeasLayer * > &measmodules) const
Store active measurement module IDs needed for navigation.
bool passedLastFilterStep() const
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 ...
static const int all_sites_fail_fit
virtual void setCovMatrix(const float *cov)
static const std::string & encoding_string()
virtual const float * getReferencePoint() const =0
static const int site_discarded
virtual void setZ0(float z0)
bool getOption(unsigned CFGOption)
Return the option's current value - false if option not defined.
bool _passed_last_filter_step
virtual int getCellID0() const =0
double getMass()
return the of the charged particle (GeV) that is used for energy loss and multiple scattering...
const DDVMeasLayer * findMeasLayer(EVENT::TrackerHit *trkhit) const
virtual float getZ0() const =0
static const int no_intersection
int initialise(bool fitDirection)
initialise the fit using the hits added up to this point - the fit direction has to be specified usin...
int getTrackerHitAtPositiveNDF(EVENT::TrackerHit *&trkhit)
get TrackeHit at which fit became constrained, i.e.
virtual void setPhi(float phi)
virtual ~KalTrackFilter()
EVENT::TrackerHit * _trackHitAtPositiveNDF
static const int site_fails_chi2_cut
std::vector< std::pair< EVENT::TrackerHit *, double > > _outlier_chi2_values
vector to store the chi-sqaure increment for measurement sites
T back_inserter(T...args)
double toBaseRange(double phi) const
helper function to restrict the range of the azimuthal angle to ]-pi,pi]
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
Interface to KaltTest Kalman fitter - instantiates and holds the detector geometry.
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()
smooth all track states
int getOutliers(std::vector< std::pair< EVENT::TrackerHit *, double > > &hits)
get the list of hits which have been rejected by from the fit due to the a chi2 increment greater tha...
virtual void setOmega(float omega)
Exception thrown in IMarlinTrk namespace (implemetations of IMarlinTrkSystem and IMarlinTrack).
int addAndFit(EVENT::TrackerHit *hit, double &chi2increment, double maxChi2Increment=DBL_MAX)
update the current fit using the supplied hit, return code via int.
std::vector< EVENT::TrackerHit * > _hit_not_used_for_sites
vector to store lcio hits rejected for measurement sites
virtual float getPhi() const =0
const DDCylinderMeasLayer * getIPLayer() const
std::vector< std::pair< EVENT::TrackerHit *, double > > _hit_chi2_values
vector to store the chi-sqaure increment for measurement sites
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 ...
bool _smoothed
used to store whether smoothing has been performed
virtual Bool_t IsAccepted(const TKalTrackSite &site)
int getTrackState(IMPL::TrackStateImpl &ts, double &chi2, int &ndf)
get track state, returning TrackState, chi2 and ndf via reference
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...