ATLAS Offline Software
Loading...
Searching...
No Matches
Trk::KalmanUpdator Class Referencefinal

Implementation of Trk::IUpdator based on gain formalism and Eigen. More...

#include <KalmanUpdator.h>

Inheritance diagram for Trk::KalmanUpdator:
Collaboration diagram for Trk::KalmanUpdator:

Public Member Functions

 KalmanUpdator (const std::string &, const std::string &, const IInterface *)
 AlgTool standard constuctor.
 ~KalmanUpdator ()
virtual StatusCode initialize () override final
 AlgTool initialisation.
virtual StatusCode finalize () override final
 AlgTool termination.
virtual std::unique_ptr< TrackParametersaddToState (const TrackParameters &, const Amg::Vector2D &, const Amg::MatrixX &) const override final
 measurement updator for the KalmanFitter getting the meas't coord'
virtual std::unique_ptr< TrackParametersaddToState (const TrackParameters &, const LocalParameters &, const Amg::MatrixX &) const override final
 measurement updator for the KalmanFitter getting the coordinates
virtual std::unique_ptr< TrackParametersaddToState (const TrackParameters &, const Amg::Vector2D &, const Amg::MatrixX &, FitQualityOnSurface *&) const override final
 measurement updator interface for the KalmanFitter returning the fit quality
virtual std::unique_ptr< TrackParametersaddToState (const TrackParameters &, const LocalParameters &, const Amg::MatrixX &, FitQualityOnSurface *&) const override final
 measurement updator interface for the KalmanFitter returning the fit quality
virtual std::unique_ptr< TrackParametersremoveFromState (const TrackParameters &, const Amg::Vector2D &, const Amg::MatrixX &) const override final
 reverse update eg for track property analysis (unbiased residuals)
virtual std::unique_ptr< TrackParametersremoveFromState (const TrackParameters &, const LocalParameters &, const Amg::MatrixX &) const override final
 reverse update eg for track property analysis (unbiased residuals)
virtual std::unique_ptr< TrackParametersremoveFromState (const TrackParameters &, const Amg::Vector2D &, const Amg::MatrixX &, FitQualityOnSurface *&) const override final
 reverse updator for the KalmanFitter and other fitters using the
virtual std::unique_ptr< TrackParametersremoveFromState (const TrackParameters &, const LocalParameters &, const Amg::MatrixX &, FitQualityOnSurface *&) const override final
 reverse updator for the KalmanFitter and other fitters using
virtual std::unique_ptr< TrackParameterscombineStates (const TrackParameters &, const TrackParameters &) const override final
 trajectory state updator which combines two parts of a trajectory on a common surface.
virtual std::unique_ptr< TrackParameterscombineStates (const TrackParameters &, const TrackParameters &, FitQualityOnSurface *&) const override final
 trajectory state updator which combines two parts of a trajectory on a common surface and provides the FitQuality.
virtual FitQualityOnSurface fullStateFitQuality (const TrackParameters &, const Amg::Vector2D &, const Amg::MatrixX &) const override final
 estimator for FitQuality on Surface from a full track state, that is a state
virtual FitQualityOnSurface fullStateFitQuality (const TrackParameters &, const LocalParameters &, const Amg::MatrixX &) const override final
 estimator for FitQuality on Surface from a full track state, that is
virtual FitQualityOnSurface predictedStateFitQuality (const TrackParameters &, const Amg::Vector2D &, const Amg::MatrixX &) const override final
 estimator for FitQuality on Surface from a predicted track state, that is a state
virtual FitQualityOnSurface predictedStateFitQuality (const TrackParameters &, const LocalParameters &, const Amg::MatrixX &) const override final
 estimator for FitQuality on Surface from a predicted track state, that is a state
virtual FitQualityOnSurface predictedStateFitQuality (const TrackParameters &, const TrackParameters &) const override final
 estimator for FitQuality on Surface for the situation when a track is fitted to
virtual std::pair< AmgVector(5), AmgSymMatrix(5)> * updateParameterDifference (const AmgVector(5) &, const AmgSymMatrix(5) &, const Amg::VectorX &, const Amg::MatrixX &, int, Trk::FitQualityOnSurface *&, bool) const override final
 interface for reference-track KF, not implemented.
virtual std::vector< double > initialErrors () const override final
 gives back how updator is configured for inital covariances
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const

Static Public Member Functions

static const InterfaceID & interfaceID ()
 Algtool infrastructure.

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

std::unique_ptr< TrackParameterscalculateFilterStep (const TrackParameters &, const Amg::Vector2D &, const Amg::MatrixX &, const int, FitQualityOnSurface *&, bool) const
 Common maths calculation code for addToState and removeFromState - Amg::Vector2D interface.
std::unique_ptr< TrackParameterscalculateFilterStep (const TrackParameters &, const LocalParameters &, const Amg::MatrixX &, const int, FitQualityOnSurface *&, bool) const
 Common maths calculation code for addToState and removeFromState - LocalParameters interface.
FitQualityOnSurface makeChi2Object (const Amg::VectorX &, const Amg::MatrixX &, const Amg::MatrixX &, const int, const int) const
 also the chi2 calculation and FitQuality object creation is combined in an extra method.
Amg::MatrixX projection (const Amg::MatrixX &, const int) const
 avoid CLHEP's empty math operations (H-matrix) by copying members out
void logStart (const std::string &, const TrackParameters &) const
 internal structuring: debugging output for start of method.
void logInputCov (const Amg::MatrixX &, const Amg::VectorX &, const Amg::MatrixX &) const
 internal structuring: common logfile output of the inputs
void logGainForm (int, const Amg::VectorX &, const Amg::MatrixX &, const Amg::MatrixX &, const Amg::MatrixX &) const
 internal structuring: common logfile output during calculation
void logResult (const std::string &, const Amg::VectorX &, const Amg::MatrixX &) const
 internal structuring: common logfile output after calculation
bool consistentParamDimensions (const LocalParameters &, int) const
 method testing correct use of LocalParameters *‍/
bool thetaPhiWithinRange (const Amg::VectorX &, const int key=31) const
 tests if ranges of abolute phi (-pi, pi) and theta (0, pi) are correct *‍/
bool diffThetaPhiWithinRange (const Amg::VectorX &, const int key=31) const
 tests if ranges of phi (-pi, pi) and theta (0, pi) residuals are correct *‍/
bool correctThetaPhiRange (Amg::VectorX &, AmgSymMatrix(5) &, const bool isDifference=false, const int key=31) const
 brings phi/theta back into valid range using 2pi periodicity
bool correctThetaPhiRange (Amg::VectorX &, Amg::MatrixX &, const bool isDifference=false, const int key=31) const
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

std::vector< double > m_cov0
 job option: initial covariance matrix
ProjectionMatricesSet m_projectionMatrices
 get the correct projection matrix
bool m_useFruehwirth8a
 job option: formula for cov update
int m_outputlevel
 MsgStream output level cached.
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Implementation of Trk::IUpdator based on gain formalism and Eigen.

Tool to provide calculations for Kalman filtering, i.e. to add or remove a measured hit to the state vector. Implemented fully in Eigen using dynamic matrices As a drawback due to using dynamic matrices this tool is generally slower than alternatives that are written based on fixed size objects.

Author
M. Elsing, W. Liebig http://consult.cern.ch/xwho

Definition at line 43 of file KalmanUpdator.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ KalmanUpdator()

Trk::KalmanUpdator::KalmanUpdator ( const std::string & t,
const std::string & n,
const IInterface * p )

AlgTool standard constuctor.

Definition at line 24 of file KalmanUpdator.cxx.

24 :
25 AthAlgTool (t,n,p),
26 m_cov0{250., 250.,0.25, 0.25, 0.000001}, // set defaults _before_ reading from job options
29{
30 // AlgTool stuff
31 declareProperty("InitialCovariances",m_cov0,"default covariance to be used at start of filter");
32 declareProperty("FastTrackStateCovCalculation",m_useFruehwirth8a=false,"toggles which formula to use for updated cov");
33 declareInterface<IUpdator>( this );
34}
AthAlgTool()
Default constructor:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ProjectionMatricesSet m_projectionMatrices
get the correct projection matrix
std::vector< double > m_cov0
job option: initial covariance matrix
int m_outputlevel
MsgStream output level cached.
bool m_useFruehwirth8a
job option: formula for cov update

◆ ~KalmanUpdator()

Trk::KalmanUpdator::~KalmanUpdator ( )
default

Member Function Documentation

◆ addToState() [1/4]

std::unique_ptr< Trk::TrackParameters > Trk::KalmanUpdator::addToState ( const TrackParameters & trkPar,
const Amg::Vector2D & measmtPos,
const Amg::MatrixX & measmtErr ) const
finaloverridevirtual

measurement updator for the KalmanFitter getting the meas't coord'

Implements Trk::IUpdator.

Definition at line 59 of file KalmanUpdator.cxx.

61 {
62 if (m_outputlevel <= 0) logStart("addToState(TP,LPOS,ERR)",trkPar);
63 FitQualityOnSurface* fitQoS = nullptr;
64 return calculateFilterStep (trkPar, measmtPos, measmtErr,1,fitQoS,false);
65}
std::unique_ptr< TrackParameters > calculateFilterStep(const TrackParameters &, const Amg::Vector2D &, const Amg::MatrixX &, const int, FitQualityOnSurface *&, bool) const
Common maths calculation code for addToState and removeFromState - Amg::Vector2D interface.
void logStart(const std::string &, const TrackParameters &) const
internal structuring: debugging output for start of method.

◆ addToState() [2/4]

std::unique_ptr< Trk::TrackParameters > Trk::KalmanUpdator::addToState ( const TrackParameters & trkPar,
const Amg::Vector2D & measmtPos,
const Amg::MatrixX & measmtErr,
FitQualityOnSurface *& fitQoS ) const
finaloverridevirtual

measurement updator interface for the KalmanFitter returning the fit quality

Implements Trk::IUpdator.

Definition at line 76 of file KalmanUpdator.cxx.

79 {
80 if (m_outputlevel <= 0) logStart("addToState(TP,LPOS,ERR,FQ)",trkPar);
81 if (fitQoS) {
82 ATH_MSG_WARNING( "expect nil FitQuality pointer, refuse operation to avoid mem leak!" );
83 return nullptr;
84 }
85 return calculateFilterStep (trkPar, measmtPos, measmtErr, 1, fitQoS, true);
86
87}
#define ATH_MSG_WARNING(x)

◆ addToState() [3/4]

std::unique_ptr< Trk::TrackParameters > Trk::KalmanUpdator::addToState ( const TrackParameters & trkPar,
const LocalParameters & measmtPar,
const Amg::MatrixX & measmtErr ) const
finaloverridevirtual

measurement updator for the KalmanFitter getting the coordinates

Implements Trk::IUpdator.

Definition at line 68 of file KalmanUpdator.cxx.

70 {
71 if (m_outputlevel <= 0) logStart("addToState(TP,LPAR,ERR)",trkPar);
72 FitQualityOnSurface* fitQoS = nullptr;
73 return calculateFilterStep (trkPar, measmtPar, measmtErr,1,fitQoS, false);
74}

◆ addToState() [4/4]

std::unique_ptr< Trk::TrackParameters > Trk::KalmanUpdator::addToState ( const TrackParameters & trkPar,
const LocalParameters & measmtPar,
const Amg::MatrixX & measmtErr,
FitQualityOnSurface *& fitQoS ) const
finaloverridevirtual

measurement updator interface for the KalmanFitter returning the fit quality

Implements Trk::IUpdator.

Definition at line 90 of file KalmanUpdator.cxx.

93 {
94 if (m_outputlevel <= 0) logStart("addToState(TP,LPAR,ERR,FQ)",trkPar);
95 if (fitQoS) {
96 ATH_MSG_WARNING( "expect nil FitQuality pointer, refuse operation to avoid mem leak!" );
97 return nullptr;
98 }
99 return calculateFilterStep (trkPar, measmtPar, measmtErr, 1, fitQoS, true);
100
101}

◆ calculateFilterStep() [1/2]

std::unique_ptr< Trk::TrackParameters > Trk::KalmanUpdator::calculateFilterStep ( const TrackParameters & trkPar,
const Amg::Vector2D & locPos,
const Amg::MatrixX & covRio,
const int sign,
Trk::FitQualityOnSurface *& fitQoS,
bool createFQoS ) const
private

Common maths calculation code for addToState and removeFromState - Amg::Vector2D interface.

Definition at line 434 of file KalmanUpdator.cxx.

440{
441
442 // try if Track Parameters are measured ones ?
443 AmgSymMatrix(5) covTrk;
444 if (!trkPar.covariance()) {
445 if (sign<0) {
446 ATH_MSG_WARNING( "MeasuredTrackParameters == Null, can not calculate updated parameter state" );
447 return nullptr;
448 }
449 // no error given - use a huge error matrix for the time
450 // covTrk = Amg::MatrixX(5, 1) * 1000.f;
451 ATH_MSG_VERBOSE( "-U- no covTrk at input - assign large error matrix for the time being." );
452 covTrk(0,0) = m_cov0[0];
453 covTrk(1,1) = m_cov0[1];
454 covTrk(2,2) = m_cov0[2];
455 covTrk(3,3) = m_cov0[3];
456 covTrk(4,4) = m_cov0[4];
457
458 }else {
459 covTrk = (*trkPar.covariance());
460 }
461
462
463 // covariance matrix and parameters of track
464 Amg::VectorX parTrk = trkPar.parameters();
465 if (!thetaPhiWithinRange(parTrk)) {
466 ATH_MSG_WARNING( (sign>0?"addToState(TP,LPOS,ERR..)":"removeFromState(TP,LPOS,ERR..)")
467 << ": undefined phi,theta range in input parameters." );
468 return nullptr;
469 }
470
471 // measurement vector of RIO_OnTrack - needs more care for # local par?
472 int nLocCoord = covRio.cols();
473 if ( (nLocCoord < 1) || (nLocCoord > 2 ) ) {
474 ATH_MSG_WARNING( " number of local coordinates must be 1 or 2, but it is "
475 << nLocCoord );
476 }
477 Amg::VectorX rioPar(nLocCoord);
478 for (int iLocCoord=0; iLocCoord < nLocCoord; iLocCoord++) {
479 rioPar[iLocCoord] = locPos[iLocCoord];
480 }
481 if (m_outputlevel<0) logInputCov(covTrk,rioPar,covRio);
482
483 // measurement Matrix ( n x m )
484 Amg::MatrixX H(covRio.cols(),covTrk.cols());
485 H.setZero();
486 for (int i=0; i < nLocCoord; i++) H(i,i)=1.f;
487
488 // residual from reconstructed hit wrt. predicted state
489 Amg::VectorX r = rioPar - H * parTrk;
490
491 // compute covariance on of residual R = +/- covRIO + H * covTrk * H.T()
492 Amg::MatrixX R = (sign * covRio) + projection(covTrk,(nLocCoord==1 ? 1 : 3) ); // .similarity(H);
493 // compute Kalman gain matrix
494 Amg::MatrixX K = covTrk * H.transpose() * R.inverse();
495 AmgSymMatrix(5) I; // 5x5 unit matrix
496 I.setIdentity();
497 AmgSymMatrix(5) M = I - K * H;
498 if (m_outputlevel<0) {logGainForm (nLocCoord,r,R.inverse(),K,M);}
499
500 // compute local filtered state
501 Amg::VectorX par = parTrk + K * r;
502
503 // compute covariance matrix of local filteres state:
504 AmgSymMatrix(5) covPar;
506 // one can use as well: covPar = M * covTrk; see A.Gelb why.
507 covPar = AmgSymMatrix(5)(M*covTrk);
508 } else {
509 // C = M*covTrk*M.T() +/- K*covRio*K.T(), supposedly more robust Gelb form.
510 // bad_alloc: covPar = new AmgSymMatrix(5)(covTrk.similarity(M) + (sign * covRio.similarity(K)));
511 covPar = AmgSymMatrix(5)(M*covTrk*M.transpose() + sign*K*covRio*K.transpose());
512 }
513 if ( (!thetaPhiWithinRange(par)) ? !correctThetaPhiRange(par,covPar) : false ) {
514 ATH_MSG_WARNING( "calculateFS(TP,LPOS,ERR): bad angles in filtered state!" );
515 return nullptr;
516 }
517 if (m_outputlevel<=0) logResult(createFQoS?
518 (sign>0?"addToState(TP,LPOS,ERR,FQ)":"removeFromState(TP,LPOS,ERR,FQ)"):
519 (sign>0?"addToState(TP,LPOS,ERR)":"removeFromState(TP,LPOS,ERR)"),
520 par,covPar);
521
522 // if a pointer is given, compute chi2
523 if (createFQoS) {
524 if (sign<0) {
525 // when removing, the input are updated par
526 fitQoS = new Trk::FitQualityOnSurface(makeChi2Object(r,covTrk,covRio,-1,(nLocCoord==1?1:3)));
527 } else {
528 // when adding chi2 is made from the updated par
529 const Amg::VectorX r_upd = rioPar - H * par;
530 fitQoS = new FitQualityOnSurface(makeChi2Object(r_upd,covPar,covRio,-1,(nLocCoord==1?1:3)));
531 }
532 }
533 // return cloned version of Track Parameters (MeasuredPerigee, MeasuredAtA...)
534 auto updated =
535 trkPar.associatedSurface().createUniqueTrackParameters(par[Trk::loc1],
536 par[Trk::loc2],
537 par[Trk::phi],
538 par[Trk::theta],
539 par[Trk::qOverP],
540 std::move(covPar));
541 return updated;
542}
#define ATH_MSG_VERBOSE(x)
#define AmgSymMatrix(dim)
if(febId1==febId2)
#define I(x, y, z)
Definition MD5.cxx:116
#define H(x, y, z)
Definition MD5.cxx:114
int sign(int a)
Amg::MatrixX projection(const Amg::MatrixX &, const int) const
avoid CLHEP's empty math operations (H-matrix) by copying members out
void logInputCov(const Amg::MatrixX &, const Amg::VectorX &, const Amg::MatrixX &) const
internal structuring: common logfile output of the inputs
FitQualityOnSurface makeChi2Object(const Amg::VectorX &, const Amg::MatrixX &, const Amg::MatrixX &, const int, const int) const
also the chi2 calculation and FitQuality object creation is combined in an extra method.
void logGainForm(int, const Amg::VectorX &, const Amg::MatrixX &, const Amg::MatrixX &, const Amg::MatrixX &) const
internal structuring: common logfile output during calculation
bool thetaPhiWithinRange(const Amg::VectorX &, const int key=31) const
tests if ranges of abolute phi (-pi, pi) and theta (0, pi) are correct *‍/
bool correctThetaPhiRange(Amg::VectorX &, AmgSymMatrix(5) &, const bool isDifference=false, const int key=31) const
brings phi/theta back into valid range using 2pi periodicity
void logResult(const std::string &, const Amg::VectorX &, const Amg::MatrixX &) const
internal structuring: common logfile output after calculation
int r
Definition globals.cxx:22
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
double R(const INavigable4Momentum *p1, const double v_eta, const double v_phi)
@ theta
Definition ParamDefs.h:66
@ qOverP
perigee
Definition ParamDefs.h:67
@ loc2
generic first and second local coordinate
Definition ParamDefs.h:35
@ phi
Definition ParamDefs.h:75
@ loc1
Definition ParamDefs.h:34

◆ calculateFilterStep() [2/2]

std::unique_ptr< Trk::TrackParameters > Trk::KalmanUpdator::calculateFilterStep ( const TrackParameters & trkPar,
const LocalParameters & rioPar,
const Amg::MatrixX & covRio,
const int sign,
Trk::FitQualityOnSurface *& fitQoS,
bool createFQoS ) const
private

Common maths calculation code for addToState and removeFromState - LocalParameters interface.

Definition at line 546 of file KalmanUpdator.cxx.

552{
553
554 // try if Track Parameters are measured ones ?
555 AmgSymMatrix(5) covTrk;
556 if (!trkPar.covariance()) {
557 if (sign<0) {
558 ATH_MSG_WARNING( "MeasuredTrackParameters == Null, can not calculate "
559 << "updated parameter state." );
560 return nullptr;
561 }
562 // no error given - use a huge error matrix for the time
563 // covTrk = Amg::MatrixX(5, 1) * 1000.f;
564 ATH_MSG_VERBOSE( "-U- no covTrk at input - "
565 << "assign large error matrix for the time being." );
566 covTrk(0,0) = m_cov0[0];
567 covTrk(1,1) = m_cov0[1];
568 covTrk(2,2) = m_cov0[2];
569 covTrk(3,3) = m_cov0[3];
570 covTrk(4,4) = m_cov0[4];
571
572 } else {
573 covTrk = (*trkPar.covariance());
574 }
575
576 // LocalParameters parTrk = trkPar.parameters();
577 Amg::VectorX parTrk = trkPar.parameters();
578 if (!thetaPhiWithinRange(parTrk)) {
579 ATH_MSG_WARNING( (sign>0?"addToState(TP,LPAR,ERR..)":"removeFromState(TP,LPAR,ERR..)")
580 << ": undefined phi,theta range in input parameters." );
581 return nullptr;
582 }
583 if (!thetaPhiWithinRange(rioPar,rioPar.parameterKey())) {
584 ATH_MSG_WARNING( (sign>0?"addToState(TP,LPAR,ERR..)":"removeFromState(TP,LPAR,ERR..)")
585 << ": undefined phi,theta range in input measurement !!" );
586 return nullptr;
587 }
588
589 // measurement vector of RIO_OnTrack - needs more care for # local par?
590 int nLocCoord = covRio.cols();
591 if ( ! consistentParamDimensions(rioPar,covRio.cols()) ) return nullptr;
592 if (m_outputlevel<0) logInputCov(covTrk,rioPar,covRio);
593
594 // State to measurement dimensional reduction Matrix ( n x m )
595 Amg::MatrixX H(rioPar.expansionMatrix());
596
597 // residual from reconstructed hit wrt. predicted state
598 Amg::VectorX r = rioPar - H * parTrk;
599 // compute covariance of residual R = +/- covRIO + H * covTrk * H.T()
600 Amg::MatrixX R = (sign * covRio) + projection(covTrk,rioPar.parameterKey()); // .similarity(H);
601 // catch [-pi,pi] phi boundary problems to keep chi2 under control
602 if (!diffThetaPhiWithinRange(r,rioPar.parameterKey()) )
603 correctThetaPhiRange(r,R,true,rioPar.parameterKey());
604
605 // compute Kalman gain matrix
606 if (R.determinant()==0.) return nullptr;
607 Amg::MatrixX K = covTrk * H.transpose() * R.inverse();
608 AmgSymMatrix(5) I; // 5x5 unit matrix
609 I.setIdentity();
610 AmgSymMatrix(5) M = I - K * H;
611 if (m_outputlevel<0) {logGainForm (nLocCoord,r,R.inverse(),K,M);}
612 // compute local filtered state
613 Amg::VectorX par = parTrk + K * r;
614
615 // compute covariance matrix of local filteres state
616 AmgSymMatrix(5) covPar;
618 // one can use as well: covPar = M * covTrk; see A.Gelb why.
619 covPar = AmgSymMatrix(5)(M*covTrk);
620 } else {
621 covPar = AmgSymMatrix(5)(M*covTrk*M.transpose() + sign*K*covRio*K.transpose());
622 }
623 if ( (!thetaPhiWithinRange(par)) ? !correctThetaPhiRange(par,covPar) : false ) {
624 ATH_MSG_WARNING( "calculateFS(TP,LPAR,ERR): bad angles in filtered state!" );
625 return nullptr;
626 }
627 if (m_outputlevel<=0) logResult(createFQoS?
628 (sign>0?"addToState(TP,LPAR,ERR,FQ)":"removeFromState(TP,LPAR,ERR,FQ)"):
629 (sign>0?"addToState(TP,LPAR,ERR)":"removeFromState(TP,LPAR,ERR)"),
630 par,covPar);
631
632 // if a pointer is given, compute chi2
633 if (createFQoS) {
634 if (sign<0) {
635 // when removing, the input are updated par
636 fitQoS = new Trk::FitQualityOnSurface(makeChi2Object(r,covTrk,covRio,-1,rioPar.parameterKey()));
637 } else {
638 // when adding chi2 is made from the updated par
639 Amg::VectorX r_upd = rioPar - H * par;
640 fitQoS = new Trk::FitQualityOnSurface(makeChi2Object(r_upd,covPar,covRio,-1,rioPar.parameterKey()));
641 }
642 }
643 // return cloned version of Track Parameters (MeasuredPerigee, MeasuredAtA...)
644 return trkPar.associatedSurface().createUniqueTrackParameters(
645 par[Trk::loc1],
646 par[Trk::loc2],
647 par[Trk::phi],
648 par[Trk::theta],
649 par[Trk::qOverP],
650 std::move(covPar));
651}
bool diffThetaPhiWithinRange(const Amg::VectorX &, const int key=31) const
tests if ranges of phi (-pi, pi) and theta (0, pi) residuals are correct *‍/
bool consistentParamDimensions(const LocalParameters &, int) const
method testing correct use of LocalParameters *‍/

◆ combineStates() [1/2]

std::unique_ptr< Trk::TrackParameters > Trk::KalmanUpdator::combineStates ( const TrackParameters & one,
const TrackParameters & two ) const
finaloverridevirtual

trajectory state updator which combines two parts of a trajectory on a common surface.

Make sure that the TPs' surfaces are identical and that the local hit is not duplicated in both trajectories!

Implements Trk::IUpdator.

Definition at line 152 of file KalmanUpdator.cxx.

154{
155 // remember, either one OR two might have no error, but not both !
156 if (!one.covariance() && !two.covariance()) {
157 ATH_MSG_WARNING( "both parameters have no errors, invalid "
158 << "use of Updator::combineStates()" );
159 return nullptr;
160 }
161 // if only one of two has an error, return that one
162 if (!one.covariance()) {
163 if (m_outputlevel<=0) logResult("combineStates(TP,TP)",two.parameters(),
164 *two.covariance());
165 return std::unique_ptr<Trk::TrackParameters>(two.clone());
166 }
167 if (!two.covariance()) {
168 if (m_outputlevel<=0) logResult("combineStates(TP,TP)",one.parameters(),
169 *one.covariance());
170 return std::unique_ptr<Trk::TrackParameters>(one.clone());
171 }
172
173 // ... FIXME - TRT is so difficult, need to check that both parameters are in the same frame
174 // otherwise go into frame of one !
175 // ok, normal, let's combine using gain matrix formalism
176 const AmgSymMatrix(5)& covTrkOne = (*one.covariance());
177 const AmgSymMatrix(5)& covTrkTwo = (*two.covariance());
178
179 AmgSymMatrix(5) sumCov = covTrkOne + covTrkTwo;
180 AmgSymMatrix(5) K = covTrkOne * sumCov.inverse();
181
182 Amg::VectorX r = two.parameters() - one.parameters();
183 // catch [-pi,pi] phi boundary problems
185 Amg::VectorX par = one.parameters() + K * r;
186 AmgSymMatrix(5) covPar = AmgSymMatrix(5)( K * covTrkTwo );
187 if ( (!thetaPhiWithinRange(par)) ? !correctThetaPhiRange(par,covPar,false) : false ) {
188 ATH_MSG_WARNING( "combineStates(TP,TP): could not combine angular values." );
189 return nullptr;
190 }
191
192 // return cloned version of Track Parameters (MeasuredPerigee, MeasuredAtA...)
193 auto comb =
194 one.associatedSurface().createUniqueTrackParameters(par[Trk::loc1],
195 par[Trk::loc2],
196 par[Trk::phi],
197 par[Trk::theta],
198 par[Trk::qOverP],
199 covPar);
200 if (m_outputlevel <= 0){
201 logResult("combineStates(TP,TP)", par, covPar);
202 }
203 return comb;
204}

◆ combineStates() [2/2]

std::unique_ptr< Trk::TrackParameters > Trk::KalmanUpdator::combineStates ( const TrackParameters & one,
const TrackParameters & two,
FitQualityOnSurface *& fitQoS ) const
finaloverridevirtual

trajectory state updator which combines two parts of a trajectory on a common surface and provides the FitQuality.

Make sure that the TPs' surfaces are identical and that the local hit is not duplicated!

Implements Trk::IUpdator.

Definition at line 207 of file KalmanUpdator.cxx.

209 {
210 // try if both Track Parameters are measured ones ?
211 // remember, either one OR two might have no error, but not both !
212 if (!one.covariance() && !two.covariance()) {
213 ATH_MSG_WARNING( "both parameters have no errors, invalid use of Updator::combineStates()" );
214 return nullptr;
215 }
216 if (fitQoS) {
217 ATH_MSG_WARNING( "expect nil FitQuality pointer, refuse operation to avoid mem leak!" );
218 return nullptr;
219 }
220 // if only one of two has an error, return that one
221 if (!one.covariance()) {
222 fitQoS = new FitQualityOnSurface(0.f, 5);
223 if (m_outputlevel<=0) logResult("combineStates(TP,TP,FQ)", one.parameters(),
224 (*two.covariance()));
225 return std::unique_ptr<Trk::TrackParameters>(two.clone());
226 }
227 if (!two.covariance()) {
228 fitQoS = new FitQualityOnSurface(0.f, 5);
229 if (m_outputlevel<=0) logResult("combineStates(TP,TP,FQ)", one.parameters(),
230 (*one.covariance()));
231 return std::unique_ptr<Trk::TrackParameters>(one.clone());
232 }
233
234 // covariance matrix for prediction and the state to be added
235 const AmgSymMatrix(5)& covTrkOne = (*one.covariance());
236 const AmgSymMatrix(5)& covTrkTwo = (*two.covariance());
237
238 // chi2 calculation and Kalman Gain preparation
239 Amg::VectorX r = two.parameters() - one.parameters();
240 AmgSymMatrix(5) R = covTrkOne + covTrkTwo;
241 // catch [-pi,pi] phi boundary problems to keep chi2 under control
243 AmgSymMatrix(5) R_inv = R.inverse();
244 AmgSymMatrix(5) K = covTrkOne * R_inv;
245 Amg::VectorX par = one.parameters() + K * r;
246 AmgSymMatrix(5) covPar = AmgSymMatrix(5)(K * covTrkTwo);
247 if ( (!thetaPhiWithinRange(par)) ? !correctThetaPhiRange(par,covPar) : false ) {
248 ATH_MSG_WARNING( "combineStates(TP,TP,FQ): could not combine angular values." );
249 return nullptr;
250 }
251
252 // compute fit quality
253 fitQoS = new FitQualityOnSurface(Amg::chi2(R_inv, r), 5);
254
255 // return cloned version of Track Parameters (MeasuredPerigee, MeasuredAtA...)
256 auto comb =
257 one.associatedSurface().createUniqueTrackParameters(par[Trk::loc1],
258 par[Trk::loc2],
259 par[Trk::phi],
260 par[Trk::theta],
261 par[Trk::qOverP],
262 covPar);
263 if (m_outputlevel <= 0){
264 logResult("combineStates(TP,TP,FQ)", par, covPar);
265 }
266 return comb;
267
268}
double chi2(const T &precision, const U &residual, const int sign=1)

◆ consistentParamDimensions()

bool Trk::KalmanUpdator::consistentParamDimensions ( const LocalParameters & P,
int dimCov ) const
private

method testing correct use of LocalParameters *‍/

Definition at line 666 of file KalmanUpdator.cxx.

667 {
668 if (P.dimension() != dimCov ) {
669 ATH_MSG_WARNING( "Inconsistency in dimension of local coord - problem with LocalParameters object?" );
670 ATH_MSG_WARNING( "dim of local parameters: "<< P.dimension()<< " vs. dim of error matrix: "<<dimCov );
671 return false;
672 }
673 if ( (dimCov < 1) || (dimCov > 5 ) ) {
674 ATH_MSG_WARNING( "invalid dimension for local coordinates: " << dimCov );
675 return false;
676 }
677 return true;
678}
static Double_t P(Double_t *tt, Double_t *par)

◆ correctThetaPhiRange() [1/2]

bool Trk::KalmanUpdator::correctThetaPhiRange ( Amg::VectorX & V,
Amg::MatrixX & C,
const bool isDifference = false,
const int key = 31 ) const
private

Definition at line 763 of file KalmanUpdator.cxx.

765{
766 // get phi and theta coordinate
767 int jphi = -1;
768 int jtheta = -1;
769 double thetaMin = (isDifference ? -M_PI : 0);
770 if (key == 31) jphi = Trk::phi;
771 else if (key & 4) { // phi is within localParameter and a measured coordinate
772 for (int itag = 0, ipos=1 ; itag<Trk::phi; ++itag, ipos*=2) if (key & ipos) ++jphi;
773 }
774 if (key == 31) jtheta = Trk::theta;
775 else if (key & 8) { // theta is within localParameter and a measured coordinate
776 for (int itag = 0, ipos=1 ; itag<Trk::theta; ++itag, ipos*=2) if (key & ipos) ++jtheta;
777 }
778
779 // correct theta and phi coordinate
780 if ((jtheta>=0) && (V[jtheta]<thetaMin || V[jtheta]> M_PI) ) {
781 if (m_outputlevel <= 0 ) {
782 if (key !=31) ATH_MSG_WARNING( "-U- key: "<<key << " jphi: "<<jphi << " jtheta: "<<jtheta );
783 msg() << MSG::WARNING << "-U- " << (isDifference?"diff. ":" ") << "angles out of range, phi = ";
784 if (jphi>=0) msg() << V[jphi]; else msg() <<"free";
785 msg() << " theta = " << V[jtheta] <<endmsg;
786 }
787 // absolute theta: repair if between -pi and +2pi.
788 // differential theta: repair if between -pi and +pi
789 if ( ( V(jtheta) < -M_PI ) ||
790 ( V(jtheta) > (isDifference? M_PI : 2*M_PI) )
791 ) {
792 ATH_MSG_WARNING( "-U- track theta too far from defined range, stop update." );
793 msg() << MSG::WARNING << "-U- " << (isDifference?"diff. ":" ") << "angles out of range, phi = ";
794 if (jphi>=0) msg() << V[jphi]; else msg() <<"free";
795 msg() << " theta = " << V[jtheta] <<endmsg;
796 return false;
797 }
798 if (V[jtheta] > M_PI) {
799 V[jtheta] = 2*M_PI - V[jtheta];
800 if (jphi>=0) V[jphi] += (V[jphi]>0.0) ? -M_PI : M_PI;
801 }
802 if (V[jtheta] < 0.0) {
803 V[jtheta] = -V[jtheta];
804 if (jphi>=0) V[jphi] += (V[jphi]>0.0) ? -M_PI : M_PI;
805 }
806 if (jtheta==0 && key==24) C(jtheta,1) = -C(jtheta,1);
807 if (jtheta==1) {
808 C(0,jtheta) = -C(0,jtheta);
809 if (key>15) C(2,1) = -C(2,1);
810 }
811 if (jtheta==2) {
812 C(0,jtheta) = -C(0,jtheta);
813 C(1,jtheta) = -C(1,jtheta);
814 if (key>15) C(3,jtheta) = -C(3,jtheta);
815 }
816 if (jtheta==3) {
817 C(0,jtheta) = -C(0,jtheta);
818 C(1,jtheta) = -C(1,jtheta);
819 C(2,jtheta) = -C(2,jtheta);
820 if (key>15) C(4,jtheta) = -C(4,jtheta);
821 }
822
823 if (m_outputlevel <=0) {
824 msg() << MSG::DEBUG << "-U- now use corrected " << (isDifference?"diff. ":" ") << "value phi= ";
825 if (jphi>=0) msg() << V[jphi]; else msg() <<"free";
826 msg() << " theta = " << V[jtheta] <<endmsg;
827 }
828 }
829
830 // correct phi coordinate if necessary
831 if ((jphi>=0) && (V[jphi] > M_PI) ) {
832 if (m_outputlevel <=0) msg() << MSG::DEBUG << "-U- phi= " << V[jphi];
833 V[jphi] = std::fmod(V[jphi]+M_PI,2*M_PI)-M_PI;
834 if (m_outputlevel <=0) ATH_MSG_DEBUG( " out of range, now "
835 << "corrected to " << V[jphi] );
836 } else if ((jphi>=0) && (V[jphi] < -M_PI) ) {
837 if (m_outputlevel <=0) msg() << MSG::DEBUG << "-U- phi= " << V[jphi];
838 V[jphi] = std::fmod(V[jphi]-M_PI,2*M_PI)+M_PI;
839 if (m_outputlevel <=0) ATH_MSG_DEBUG( " out of range, now "
840 << "corrected to " << V[jphi] );
841 }
842 return true;
843}
#define M_PI
#define endmsg
#define ATH_MSG_DEBUG(x)
MsgStream & msg() const
struct color C

◆ correctThetaPhiRange() [2/2]

bool Trk::KalmanUpdator::correctThetaPhiRange ( Amg::VectorX & ,
AmgSymMatrix(5) & ,
const bool isDifference = false,
const int key = 31 ) const
private

brings phi/theta back into valid range using 2pi periodicity

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ diffThetaPhiWithinRange()

bool Trk::KalmanUpdator::diffThetaPhiWithinRange ( const Amg::VectorX & V,
const int key = 31 ) const
inlineprivate

tests if ranges of phi (-pi, pi) and theta (0, pi) residuals are correct *‍/

Definition at line 291 of file KalmanUpdator.h.

293{
294 if (!(key & 4 || key & 8))
295 return true; // in case no angles measured.
296 if (key == 31)
297 return ((std::abs(V[Trk::phi]) <= M_PI) && (V[Trk::theta] >= -M_PI) &&
298 (V[Trk::theta] <= M_PI));
299
300 else { // if vector is compressed (i.e. localParameters) need to extract
301 // phi,theta first.
302 bool okay = true;
303 if (key & 4) { // phi is being measured
304 int jphi = 0;
305 for (int itag = 0, ipos = 1; itag < Trk::phi; ++itag, ipos *= 2)
306 if (key & ipos)
307 ++jphi;
308 okay = okay && (std::abs(V[jphi]) <= M_PI);
309 }
310 if (key & 8) { // theta is being measured
311 int jtheta = 0;
312 for (int itag = 0, ipos = 1; itag <= Trk::theta; ++itag, ipos *= 2)
313 if (key & ipos)
314 ++jtheta;
315 okay = okay && (std::abs(V[jtheta]) <= M_PI);
316 }
317 return okay;
318 }
319}

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ finalize()

StatusCode Trk::KalmanUpdator::finalize ( )
finaloverridevirtual

AlgTool termination.

Definition at line 53 of file KalmanUpdator.cxx.

54{
55 return StatusCode::SUCCESS;
56}

◆ fullStateFitQuality() [1/2]

Trk::FitQualityOnSurface Trk::KalmanUpdator::fullStateFitQuality ( const TrackParameters & trkPar,
const Amg::Vector2D & locPos,
const Amg::MatrixX & rioErr ) const
finaloverridevirtual

estimator for FitQuality on Surface from a full track state, that is a state

Implements Trk::IUpdator.

Definition at line 273 of file KalmanUpdator.cxx.

275 {
276 ATH_MSG_DEBUG( "--> entered KalmanUpdator::fullStateFitQuality(TP,LPOS,ERR)" );
277
278 // try if Track Parameters are measured ones ?
279 if (!trkPar.covariance()) {
280 ATH_MSG_ERROR( "updated smoother/trajectory has no error matrix" );
281 return {};
282 }
283 // covariance matrix for prediction
284 const AmgSymMatrix(5)& covTrk = (*trkPar.covariance());
285
286 // For the Amg::Vector2D version, need to know # meas. coord. from covariance matrix.
287 int nLocCoord = rioErr.cols();
288 Amg::VectorX rioPar(nLocCoord);
289 for (int iLocCoord=0; iLocCoord < nLocCoord; iLocCoord++) {
290 rioPar[iLocCoord] = locPos[iLocCoord];
291 }
292
293 // measurement Matrix ( n x m )
294 Amg::MatrixX H(rioErr.cols(),covTrk.cols());
295 H.setZero();
296 for (int i=0; i < nLocCoord; i++) H(i,i)=1.f;
297
298 // residuals
299 Amg::VectorX r = rioPar - H * trkPar.parameters();
300
301 // all the rest is outsourced to a common chi2 routine
302 return makeChi2Object(r,covTrk,rioErr,-1,(nLocCoord==1?1:3));
303}
#define ATH_MSG_ERROR(x)

◆ fullStateFitQuality() [2/2]

Trk::FitQualityOnSurface Trk::KalmanUpdator::fullStateFitQuality ( const TrackParameters & trkPar,
const LocalParameters & rioPar,
const Amg::MatrixX & rioErr ) const
finaloverridevirtual

estimator for FitQuality on Surface from a full track state, that is

Implements Trk::IUpdator.

Definition at line 308 of file KalmanUpdator.cxx.

310 {
311 ATH_MSG_VERBOSE( "--> entered KalmanUpdator::fullStateFitQuality(TP,LPAR,ERR)" );
312
313 // try if Track Parameters are measured ones ?
314 if (!trkPar.covariance()) {
315 ATH_MSG_ERROR( "updated smoother/trajectory has no error matrix" );
316 return {};
317 }
318 if ( !consistentParamDimensions(rioPar,rioErr.cols()) ) return {};
319
320 // covariance matrix for prediction
321 const AmgSymMatrix(5)& covTrk = (*trkPar.covariance());
322
323 // State to measurement dimensional reduction Matrix ( n x m )
324 const Amg::MatrixX& H(rioPar.expansionMatrix());
325
326 // residuals
327 Amg::VectorX r = rioPar;
328 if( rioPar.parameterKey()==31 ) r -= trkPar.parameters();
329 else r -= H*trkPar.parameters();
330
331 // all the rest is outsourced to a common chi2 routine
332 return makeChi2Object(r,covTrk,rioErr,-1,rioPar.parameterKey());
333}

◆ initialErrors()

std::vector< double > Trk::KalmanUpdator::initialErrors ( ) const
finaloverridevirtual

gives back how updator is configured for inital covariances

Implements Trk::IUpdator.

Definition at line 426 of file KalmanUpdator.cxx.

426 {
427 std::vector<double> E(5);
428 for (int i=0; i<5; ++i) E[i] = std::sqrt(m_cov0[i]);
429 return E;
430}

◆ initialize()

StatusCode Trk::KalmanUpdator::initialize ( )
finaloverridevirtual

AlgTool initialisation.

Definition at line 41 of file KalmanUpdator.cxx.

42{
43 // pass individual outputlevel to message stream
44 m_outputlevel = msg().level()-MSG::DEBUG;
45 if (m_cov0.size() < 5) {
46 ATH_MSG_WARNING( "Wrong-sized initial covariance given, so set to default: " );
47 m_cov0 = {250.,250,0.25,0.25, 0.000001};
48 }
49 return StatusCode::SUCCESS;
50}

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ interfaceID()

const InterfaceID & Trk::IUpdator::interfaceID ( )
inlinestaticinherited

Algtool infrastructure.

Definition at line 227 of file IUpdator.h.

228{
229 return IID_IUpdator;
230}
static const InterfaceID IID_IUpdator("Trk::IUpdator", 1, 0)

◆ logGainForm()

void Trk::KalmanUpdator::logGainForm ( int nc,
const Amg::VectorX & r,
const Amg::MatrixX & R,
const Amg::MatrixX & K,
const Amg::MatrixX & M ) const
private

internal structuring: common logfile output during calculation

Definition at line 882 of file KalmanUpdator.cxx.

884{
885 // again some verbose debug output showing internals of updating
886 msg() << MSG::VERBOSE << "-U- residual: r=("<<r[0];
887 for (int i=1; i<nc; i++) msg() <<","<<r[i];
888 msg() << ")" << endmsg;
889 msg() << MSG::VERBOSE << "-U- inv. sigmaR=("<< R(0,0);
890 for (int i=1; i<nc; i++) msg() << "," << R(i,i);
891 msg() << ")" << endmsg;
892 for (int i=0; i<nc; i++) msg() << MSG::VERBOSE // K is a row x col = 5 x nc matrix.
893 << ( i==0 ? "-U- gain mtx K=(" : " (" )
894 << std::setiosflags(std::ios::fixed | std::ios::showpoint | std::ios::right )
895 << std::setw(7) << std::setprecision(4) << K(0,i)<<", "
896 << std::setw(7) << std::setprecision(4) << K(1,i)<<", "
897 << std::setw(7) << std::setprecision(4) << K(2,i)<<", "
898 << std::setw(7) << std::setprecision(4) << K(3,i)<<", "
899 << std::setw(7) << std::setprecision(4) << K(4,i)<<")"
900 << std::resetiosflags(std::ios::fixed) << endmsg;
901 msg() << MSG::VERBOSE << "-U- matrix M: diag=("
902 << M(0,0)<<"," << M(1,1)<<","
903 << M(2,2)<<"," << M(3,3)<<","
904 << M(4,4) <<")" << endmsg;
905}

◆ logInputCov()

void Trk::KalmanUpdator::logInputCov ( const Amg::MatrixX & covTrk,
const Amg::VectorX & rioPar,
const Amg::MatrixX & covRio ) const
private

internal structuring: common logfile output of the inputs

Definition at line 855 of file KalmanUpdator.cxx.

857{
858 msg() << MSG::VERBOSE << "-U- cov "<<std::setiosflags(std::ios::right)<<std::setprecision(3)
859 << std::setw(9)<<covTrk(0,0)<<" "<< std::setw(9)<<covTrk(0,1)<<" "
860 << std::setw(9)<<covTrk(0,2)<<" "<< std::setw(9)<<covTrk(0,3)<<" "
861 << std::setw(9)<<covTrk(0,4)<<"\n";
862 msg() << " " << " " << " "
863 << std::setw(9)<<covTrk(1,1)<<" "<< std::setw(9)<<covTrk(1,2)<<" "
864 << std::setw(9)<<covTrk(1,3)<<" "<< std::setw(9)<<covTrk(1,4)<<"\n";
865 msg() << " covariance matrix " << " " << " "
866 << std::setw(9)<<covTrk(2,2)<<" "<< std::setw(9)<<covTrk(2,3)<<" "
867 << std::setw(9)<<covTrk(2,4)<< "\n" ;
868 msg() << " of the PREDICTED track pars " << " " << " "
869 << std::setw(9)<<covTrk(3,3)<<" "<< std::setw(9)<<covTrk(3,4)<<"\n" ;
870 msg() << " " << " " << " "
871 << std::setw(9)<<covTrk(4,4)<<std::setprecision(6)<< endmsg;
872
873 int nLocCoord = covRio.cols();
874 msg() << MSG::VERBOSE << "-U- measurement locPos: ";
875 for (int i=0; i<nLocCoord; i++) msg() << rioPar[i] << " ";
876 msg() << endmsg;
877 msg() << MSG::VERBOSE << "-U- measurement (err)^2: " <<std::setprecision(4)<<covRio(0,0);
878 for (int i=1; i<nLocCoord; i++) msg() << ", "<<covRio(i,i);
879 msg() << std::setprecision(6)<<endmsg;
880}

◆ logResult()

void Trk::KalmanUpdator::logResult ( const std::string & methodName,
const Amg::VectorX & par,
const Amg::MatrixX & covPar ) const
private

internal structuring: common logfile output after calculation

Definition at line 907 of file KalmanUpdator.cxx.

909{
910 // again some verbose debug output
911 msg() << MSG::VERBOSE << "-U- ==> result for KalmanUpdator::"<<methodName<<endmsg;
912 msg() << MSG::VERBOSE << "-U- new par"<<std::setiosflags(std::ios::right)<<std::setprecision(4)
913 << std::setw( 9)<<par[0]<< std::setw(10)<<par[1]<<std::setprecision(5)
914 << std::setw(10)<<par[2]<< std::setw(10)<<par[3]<<std::setprecision(4)
915 << std::setw(10)<<par[4] <<endmsg;
916 msg() << MSG::VERBOSE << "-U- new cov" <<std::setiosflags(std::ios::right)<<std::setprecision(3)
917 << std::setw(9)<<(covPar)(0,0)<<" "<< std::setw(9)<<(covPar)(0,1)<<" "
918 << std::setw(9)<<(covPar)(0,2)<<" "<< std::setw(9)<<(covPar)(0,3)
919 << " " << std::setw(9)<<(covPar)(0,4)<< "\n";
920 msg() << " " << " " << " "
921 << std::setw(9)<<(covPar)(1,1)<<" "<< std::setw(9)<<(covPar)(1,2)<<" "
922 << std::setw(9)<<(covPar)(1,3)<<" "<< std::setw(9)<<(covPar)(1,4)<< "\n";
923 msg() << " covariance matrix " << " " << " "
924 << std::setw(9)<<(covPar)(2,2)<<" "<< std::setw(9)<<(covPar)(2,3)<<" "
925 << std::setw(9)<<(covPar)(2,4)<< "\n";
926 msg() << " of the UPDATED track pars " << " "
927 << " " <<std::setw(9)<<(covPar)(3,3)<< " "
928 << std::setw(9)<<(covPar)(3,4)<< "\n";
929 msg() << " " << " "
930 << " "
931 << std::setw(9)<<(covPar)(4,4)<<std::setprecision(6)<< endmsg;
932}

◆ logStart()

void Trk::KalmanUpdator::logStart ( const std::string & IDstring,
const TrackParameters & tp ) const
private

internal structuring: debugging output for start of method.

Definition at line 845 of file KalmanUpdator.cxx.

847{
848 ATH_MSG_DEBUG( "--> entered KalmanUpdator::" << IDstring );
849 ATH_MSG_VERBOSE( "-U- TrkPar:" << std::setiosflags(std::ios::right)<<std::setprecision(4)
850 << std::setw( 9)<<tp.parameters()[0]<< std::setw(10)<<tp.parameters()[1]<<std::setprecision(5)
851 << std::setw(10)<<tp.parameters()[2]<< std::setw(10)<<tp.parameters()[3]<<std::setprecision(4)
852 << std::setw(10)<<tp.parameters()[4] );
853}

◆ makeChi2Object()

FitQualityOnSurface Trk::KalmanUpdator::makeChi2Object ( const Amg::VectorX & residual,
const Amg::MatrixX & covTrk,
const Amg::MatrixX & covRio,
const int sign,
const int key ) const
inlineprivate

also the chi2 calculation and FitQuality object creation is combined in an extra method.

It is called by ___FitQuality() and calculateFilterStep() The sign controls the calculation in case a predicted input track state (sign=+1) or smoothed/updated input track state (sign=-1).

Definition at line 322 of file KalmanUpdator.h.

327{ // sign: -1 = updated, +1 = predicted parameters.
328 Amg::MatrixX R = covRio + sign * projection(covTrk, key); // .similarity(H);
329 if (R.determinant() == 0) {
330 ATH_MSG_DEBUG("matrix inversion failed");
331 return FitQualityOnSurface(0.0, (int)covRio.cols());
332 }
333 // get chi2 = r.T() * R^-1 * r
334 const double chiSquared = Amg::chi2(R.inverse(), residual);
335 ATH_MSG_VERBOSE("-U- fitQuality of " << (sign > 0 ? "predicted" : "updated")
336 << " state, chi2 :" << chiSquared
337 << " / ndof= " << covRio.cols());
338 // return the FitQualityOnSurface object
339 return FitQualityOnSurface(chiSquared, int(covRio.cols()));
340}
float chiSquared(const U &p)

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ predictedStateFitQuality() [1/3]

Trk::FitQualityOnSurface Trk::KalmanUpdator::predictedStateFitQuality ( const TrackParameters & predPar,
const Amg::Vector2D & rioLocPos,
const Amg::MatrixX & rioLocErr ) const
finaloverridevirtual

estimator for FitQuality on Surface from a predicted track state, that is a state

Implements Trk::IUpdator.

Definition at line 337 of file KalmanUpdator.cxx.

339 {
340 ATH_MSG_VERBOSE( "--> entered KalmanUpdator::predictedStateFitQuality(TP,LPOS,ERR)" );
341 // try if Track Parameters are measured ones ?
342 if (predPar.covariance() == nullptr) {
343 ATH_MSG_WARNING( "input state has no error matrix in predictedStateFitQuality()" );
344 return {};
345 }
346 // covariance matrix for prediction
347 const AmgSymMatrix(5)& covPred = (*predPar.covariance());
348
349 // For the Amg::Vector2D version, need to know # meas. coord. from covariance matrix.
350 int nLocCoord = rioLocErr.cols();
351 Amg::VectorX rioPar(nLocCoord);
352 for (int iLocCoord=0; iLocCoord < nLocCoord; iLocCoord++) {
353 rioPar[iLocCoord] = rioLocPos[iLocCoord];
354 }
355
356 // measurement Matrix ( n x m )
357 Amg::MatrixX H(rioLocErr.cols(),covPred.cols());
358 H.setZero();
359 for (int i=0; i < nLocCoord; i++) H(i,i)=1.f;
360
361 // residuals
362 Amg::VectorX r = rioPar - H * predPar.parameters();
363
364 // all the rest is outsourced to a common chi2 routine
365 return makeChi2Object(r,covPred,rioLocErr,+1,(nLocCoord==1?1:3));
366}

◆ predictedStateFitQuality() [2/3]

Trk::FitQualityOnSurface Trk::KalmanUpdator::predictedStateFitQuality ( const TrackParameters & predPar,
const LocalParameters & rioPar,
const Amg::MatrixX & rioErr ) const
finaloverridevirtual

estimator for FitQuality on Surface from a predicted track state, that is a state

Implements Trk::IUpdator.

Definition at line 370 of file KalmanUpdator.cxx.

372 {
373 ATH_MSG_VERBOSE( "--> entered KalmanUpdator::predictedStateFitQuality(TP,LPAR,ERR)" );
374
375 // try if Track Parameters are measured ones ?
376 if (predPar.covariance() == nullptr) {
377 ATH_MSG_WARNING( "input state has no error matrix in predictedStateFitQuality()" );
378 return {};
379 }
380
381 if ( ! consistentParamDimensions(rioPar,rioErr.cols()) ) return {};
382
383 // covariance matrix for prediction
384 const AmgSymMatrix(5)& covPred = (*predPar.covariance());
385
386 // State to measurement dimensional reduction Matrix ( n x m )
387 const Amg::MatrixX& H(rioPar.expansionMatrix());
388
389 // residuals
390 Amg::VectorX r = rioPar;
391 if(rioPar.parameterKey()==31) r -= predPar.parameters();
392 else r -= H * predPar.parameters();
393
394 // all the rest is outsourced to a common chi2 routine
395 return makeChi2Object(r,covPred,rioErr,+1,rioPar.parameterKey());
396}

◆ predictedStateFitQuality() [3/3]

Trk::FitQualityOnSurface Trk::KalmanUpdator::predictedStateFitQuality ( const TrackParameters & one,
const TrackParameters & two ) const
finaloverridevirtual

estimator for FitQuality on Surface for the situation when a track is fitted to

Implements Trk::IUpdator.

Definition at line 400 of file KalmanUpdator.cxx.

401 {
402 ATH_MSG_VERBOSE( "--> entered KalmanUpdator::predictedStateFitQuality(TP,TP)" );
403 // remember, either one OR two might have no error, but not both !
404 if (!one.covariance() && !two.covariance()) {
405 ATH_MSG_WARNING( "both parameters have no errors, invalid "
406 << "use of Updator::fitQuality()" );
407 return {};
408 }
409 // if only one of two has an error, place a message.
410 if (!one.covariance() || !two.covariance()) {
411 ATH_MSG_DEBUG( "One parameter does not have uncertainties, "
412 << "assume initial state and return chi2=0.0" );
413 return {0.f, 5};
414 }
415
416 // covariance matrix for prediction and the state to be added
417 const AmgSymMatrix(5)& covTrkOne = (*one.covariance());
418 const AmgSymMatrix(5)& covTrkTwo = (*two.covariance());
419 // residuals
420 Amg::VectorX r = two.parameters() - one.parameters();
421 AmgSymMatrix(5) R = (covTrkOne + covTrkTwo).inverse();
422 // chi2 calculation
423 return {Amg::chi2(R, r), 5};
424}

◆ projection()

Amg::MatrixX Trk::KalmanUpdator::projection ( const Amg::MatrixX & M,
const int key ) const
private

avoid CLHEP's empty math operations (H-matrix) by copying members out

Definition at line 653 of file KalmanUpdator.cxx.

654{
655 // ATH_MSG_DEBUG( "projection("<<M[0][0]<<", "<<key<<")" );
656 if (key == 31) return M;
657 // reduction matrix
658 const Amg::MatrixX& redMatrix = m_projectionMatrices.reductionMatrix(key);
659 Amg::MatrixX R = redMatrix.transpose()*M*redMatrix;
660 return R;
661
662}

◆ removeFromState() [1/4]

std::unique_ptr< Trk::TrackParameters > Trk::KalmanUpdator::removeFromState ( const TrackParameters & trkPar,
const Amg::Vector2D & measmtPos,
const Amg::MatrixX & measmtErr ) const
finaloverridevirtual

reverse update eg for track property analysis (unbiased residuals)

Implements Trk::IUpdator.

Definition at line 104 of file KalmanUpdator.cxx.

106 {
107 if (m_outputlevel<=0) logStart("removeFromState(TP,LPOS,ERR)",trkPar);
108 FitQualityOnSurface* fitQoS = nullptr;
109 return calculateFilterStep (trkPar, measmtPos, measmtErr,-1,fitQoS, false);
110}

◆ removeFromState() [2/4]

std::unique_ptr< Trk::TrackParameters > Trk::KalmanUpdator::removeFromState ( const TrackParameters & trkPar,
const Amg::Vector2D & measmtPos,
const Amg::MatrixX & measmtErr,
FitQualityOnSurface *& fitQoS ) const
finaloverridevirtual

reverse updator for the KalmanFitter and other fitters using the

Implements Trk::IUpdator.

Definition at line 122 of file KalmanUpdator.cxx.

125 {
126 if (m_outputlevel<=0) logStart("removeFromState(TP,LPOS,ERR,FQ)",trkPar);
127 if (fitQoS) {
128 ATH_MSG_WARNING( "expect nil FitQuality pointer, refuse operation to"
129 << " avoid mem leak!" );
130 return nullptr;
131 }
132 return calculateFilterStep (trkPar, measmtPos, measmtErr, -1, fitQoS, true);
133
134}

◆ removeFromState() [3/4]

std::unique_ptr< Trk::TrackParameters > Trk::KalmanUpdator::removeFromState ( const TrackParameters & trkPar,
const LocalParameters & measmtPar,
const Amg::MatrixX & measmtErr ) const
finaloverridevirtual

reverse update eg for track property analysis (unbiased residuals)

Implements Trk::IUpdator.

Definition at line 113 of file KalmanUpdator.cxx.

115 {
116 if (m_outputlevel) logStart("removeFromState(TP,LPAR,ERR)",trkPar);
117 FitQualityOnSurface* fitQoS = nullptr;
118 return calculateFilterStep (trkPar, measmtPar, measmtErr,-1,fitQoS, false);
119}

◆ removeFromState() [4/4]

std::unique_ptr< Trk::TrackParameters > Trk::KalmanUpdator::removeFromState ( const TrackParameters & trkPar,
const LocalParameters & measmtPar,
const Amg::MatrixX & measmtErr,
FitQualityOnSurface *& fitQoS ) const
finaloverridevirtual

reverse updator for the KalmanFitter and other fitters using

Implements Trk::IUpdator.

Definition at line 137 of file KalmanUpdator.cxx.

140 {
141 if (m_outputlevel<=0) logStart("removeFromState(TP,LPAR,ERR,FQ)",trkPar);
142 if (fitQoS) {
143 ATH_MSG_WARNING( "expect nil FitQuality pointer, refuse operation to"
144 << " avoid mem leak!" );
145 return nullptr;
146 }
147 return calculateFilterStep (trkPar, measmtPar, measmtErr, -1, fitQoS, true);
148}

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, AthCheckedComponent<::AthAlgTool >, and DerivationFramework::CfAthAlgTool.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ thetaPhiWithinRange()

bool Trk::KalmanUpdator::thetaPhiWithinRange ( const Amg::VectorX & V,
const int key = 31 ) const
inlineprivate

tests if ranges of abolute phi (-pi, pi) and theta (0, pi) are correct *‍/

Definition at line 258 of file KalmanUpdator.h.

259{
260 if (!(key & 4 || key & 8))
261 return true; // in case no angles measured.
262 if (key == 31)
263 return ((std::abs(V[Trk::phi]) <= M_PI) && (V[Trk::theta] >= 0.0) &&
264 (V[Trk::theta] <= M_PI));
265 else { // if vector is compressed (i.e. localParameters) need to extract
266 // phi,theta first.
267 bool okay = true;
268 if (key & 4) { // phi is being measured
269 int jphi = 0;
270 for (int itag = 0, ipos = 1; itag < Trk::phi; ++itag, ipos *= 2)
271 if (key & ipos)
272 ++jphi;
273 okay = okay && (std::abs(V[jphi]) <= M_PI);
274 }
275 if (key & 8) { // theta is being measured
276 int jtheta = 0;
277 for (int itag = 0, ipos = 1; itag <= Trk::theta; ++itag, ipos *= 2)
278 if (key & ipos)
279 ++jtheta;
280 okay = okay && (std::abs(V[jtheta] - M_PI_2) <= M_PI_2);
281 }
282 return okay;
283 }
284}

◆ updateParameterDifference()

virtual std::pair< AmgVector(5), AmgSymMatrix(5)> * Trk::KalmanUpdator::updateParameterDifference ( const AmgVector(5) & ,
const AmgSymMatrix(5) & ,
const Amg::VectorX & ,
const Amg::MatrixX & ,
int ,
Trk::FitQualityOnSurface *& ,
bool  ) const
inlinefinaloverridevirtual

interface for reference-track KF, not implemented.

Implements Trk::IUpdator.

Definition at line 169 of file KalmanUpdator.h.

177 {
178 return nullptr;
179 }

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_cov0

std::vector<double> Trk::KalmanUpdator::m_cov0
private

job option: initial covariance matrix

Definition at line 250 of file KalmanUpdator.h.

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_outputlevel

int Trk::KalmanUpdator::m_outputlevel
private

MsgStream output level cached.

Definition at line 254 of file KalmanUpdator.h.

◆ m_projectionMatrices

ProjectionMatricesSet Trk::KalmanUpdator::m_projectionMatrices
private

get the correct projection matrix

Definition at line 252 of file KalmanUpdator.h.

◆ m_useFruehwirth8a

bool Trk::KalmanUpdator::m_useFruehwirth8a
private

job option: formula for cov update

Definition at line 253 of file KalmanUpdator.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


The documentation for this class was generated from the following files: