Public Member Functions | Private Attributes | List of all members
trkf::KHit< N > Class Template Referenceabstract

#include <KHit.h>

Inheritance diagram for trkf::KHit< N >:
trkf::KHitBase

Public Member Functions

 KHit ()
 Default constructor. More...
 
 KHit (const std::shared_ptr< const Surface > &psurf)
 Initializing Constructor – surface only. More...
 
 KHit (const std::shared_ptr< const Surface > &psurf, const typename KVector< N >::type &mvec, const typename KSymMatrix< N >::type &merr)
 Fully Initializing Constructor. More...
 
virtual ~KHit ()
 Destructor. More...
 
void setMeasVector (const typename KVector< N >::type &mvec)
 Set measurement vector. More...
 
void setMeasError (const typename KSymMatrix< N >::type &merr)
 Set measurement error. More...
 
const KVector< N >::typegetMeasVector () const
 Measurement vector. More...
 
const KSymMatrix< N >::typegetMeasError () const
 Measurement error matrix. More...
 
const KVector< N >::typegetPredVector () const
 Prediction vector. More...
 
const KSymMatrix< N >::typegetPredError () const
 Prediction matrix. More...
 
const KVector< N >::typegetResVector () const
 Residual vector. More...
 
const KSymMatrix< N >::typegetResError () const
 Residual error matrix. More...
 
const KSymMatrix< N >::typegetResInvError () const
 Residual inv. error matrix. More...
 
const KHMatrix< N >::typegetH () const
 Kalman H-matrix. More...
 
double getChisq () const
 Incremental chisquare. More...
 
bool predict (const KETrack &tre, const Propagator &prop, const KTrack *ref=0) const
 Prediction method (return false if fail). More...
 
void update (KETrack &tre) const
 Update track method. More...
 
virtual bool subpredict (const KETrack &tre, typename KVector< N >::type &pvec, typename KSymMatrix< N >::type &perr, typename KHMatrix< N >::type &hmatrix) const =0
 Calculate prediction function (return via arguments). More...
 
virtual std::ostream & Print (std::ostream &out, bool doTitle=true) const
 Printout. More...
 
- Public Member Functions inherited from trkf::KHitBase
 KHitBase ()
 Default constructor. More...
 
 KHitBase (const std::shared_ptr< const Surface > &psurf, int plane=-1)
 Initializing Constructor. More...
 
virtual ~KHitBase ()=default
 Destructor. More...
 
const std::shared_ptr< const Surface > & getPredSurface () const
 Predition surface. More...
 
double getPredDistance () const
 Prediction distance. More...
 
const std::shared_ptr< const Surface > & getMeasSurface () const
 Measurement surface. More...
 
int getMeasPlane () const
 Measurement plane index. More...
 
int getID () const
 Unique id. More...
 
void setMeasSurface (const std::shared_ptr< const Surface > &psurf)
 Measurement surface. More...
 
void setMeasPlane (int plane)
 Measurement plane. More...
 

Private Attributes

KVector< N >::type fMvec
 Measurement vector. More...
 
KSymMatrix< N >::type fMerr
 Measurement error matrix. More...
 
KVector< N >::type fPvec
 Prediction vector. More...
 
KSymMatrix< N >::type fPerr
 Prediction error matrix. More...
 
KVector< N >::type fRvec
 Residual vector. More...
 
KSymMatrix< N >::type fRerr
 Residual error matrix. More...
 
KSymMatrix< N >::type fRinv
 Residual inverse error matrix. More...
 
KHMatrix< N >::type fH
 Kalman H-matrix. More...
 
double fChisq
 Incremental chisquare. More...
 

Additional Inherited Members

- Protected Attributes inherited from trkf::KHitBase
std::shared_ptr< const SurfacefPredSurf
 Prediction surface. More...
 
double fPredDist
 Prediction distance. More...
 
int fID
 Unique id. More...
 

Detailed Description

template<int N>
class trkf::KHit< N >

Definition at line 74 of file KHit.h.

Constructor & Destructor Documentation

template<int N>
trkf::KHit< N >::KHit ( )

Default constructor.

Definition at line 209 of file KHit.h.

209  : fChisq(0.)
210  {}
double fChisq
Incremental chisquare.
Definition: KHit.h:202
template<int N>
trkf::KHit< N >::KHit ( const std::shared_ptr< const Surface > &  psurf)

Initializing Constructor – surface only.

Initializing Constructor – surface only.

Arguments:

psurf - Surface pointer.

Definition at line 219 of file KHit.h.

219  : KHitBase(psurf), fChisq(0.)
220  {}
KHitBase()
Default constructor.
Definition: KHitBase.cxx:18
double fChisq
Incremental chisquare.
Definition: KHit.h:202
template<int N>
trkf::KHit< N >::KHit ( const std::shared_ptr< const Surface > &  psurf,
const typename KVector< N >::type mvec,
const typename KSymMatrix< N >::type merr 
)

Fully Initializing Constructor.

Fully Initializing Constructor.

Arguments:

psurf - Surface pointer. mvec - Measurement vector. merr - Measurement error.

Definition at line 231 of file KHit.h.

234  : KHitBase(psurf), fMvec(mvec), fMerr(merr), fChisq(0.)
235  {}
KVector< N >::type fMvec
Measurement vector.
Definition: KHit.h:194
KHitBase()
Default constructor.
Definition: KHitBase.cxx:18
KSymMatrix< N >::type fMerr
Measurement error matrix.
Definition: KHit.h:195
double fChisq
Incremental chisquare.
Definition: KHit.h:202
template<int N>
trkf::KHit< N >::~KHit ( )
virtual

Destructor.

Definition at line 239 of file KHit.h.

240  {}

Member Function Documentation

template<int N>
double trkf::KHit< N >::getChisq ( ) const
inlinevirtual

Incremental chisquare.

Implements trkf::KHitBase.

Definition at line 166 of file KHit.h.

167  {
168  return fChisq;
169  }
double fChisq
Incremental chisquare.
Definition: KHit.h:202
template<int N>
const KHMatrix<N>::type& trkf::KHit< N >::getH ( ) const
inline

Kalman H-matrix.

Definition at line 159 of file KHit.h.

160  {
161  return fH;
162  }
KHMatrix< N >::type fH
Kalman H-matrix.
Definition: KHit.h:201
template<int N>
const KSymMatrix<N>::type& trkf::KHit< N >::getMeasError ( ) const
inline

Measurement error matrix.

Definition at line 117 of file KHit.h.

118  {
119  return fMerr;
120  }
KSymMatrix< N >::type fMerr
Measurement error matrix.
Definition: KHit.h:195
template<int N>
const KVector<N>::type& trkf::KHit< N >::getMeasVector ( ) const
inline

Measurement vector.

Definition at line 110 of file KHit.h.

111  {
112  return fMvec;
113  }
KVector< N >::type fMvec
Measurement vector.
Definition: KHit.h:194
template<int N>
const KSymMatrix<N>::type& trkf::KHit< N >::getPredError ( ) const
inline

Prediction matrix.

Definition at line 131 of file KHit.h.

132  {
133  return fPerr;
134  }
KSymMatrix< N >::type fPerr
Prediction error matrix.
Definition: KHit.h:197
template<int N>
const KVector<N>::type& trkf::KHit< N >::getPredVector ( ) const
inline

Prediction vector.

Definition at line 124 of file KHit.h.

125  {
126  return fPvec;
127  }
KVector< N >::type fPvec
Prediction vector.
Definition: KHit.h:196
template<int N>
const KSymMatrix<N>::type& trkf::KHit< N >::getResError ( ) const
inline

Residual error matrix.

Definition at line 145 of file KHit.h.

146  {
147  return fRerr;
148  }
KSymMatrix< N >::type fRerr
Residual error matrix.
Definition: KHit.h:199
template<int N>
const KSymMatrix<N>::type& trkf::KHit< N >::getResInvError ( ) const
inline

Residual inv. error matrix.

Definition at line 152 of file KHit.h.

153  {
154  return fRinv;
155  }
KSymMatrix< N >::type fRinv
Residual inverse error matrix.
Definition: KHit.h:200
template<int N>
const KVector<N>::type& trkf::KHit< N >::getResVector ( ) const
inline

Residual vector.

Definition at line 138 of file KHit.h.

139  {
140  return fRvec;
141  }
KVector< N >::type fRvec
Residual vector.
Definition: KHit.h:198
template<int N>
bool trkf::KHit< N >::predict ( const KETrack tre,
const Propagator prop,
const KTrack ref = 0 
) const
virtual

Prediction method (return false if fail).

Prediction method.

Arguments;

tre - Track prediction. prop - Propagator. ref - Reference track.

Implements trkf::KHitBase.

Definition at line 252 of file KHit.h.

253  {
254  // Update the prediction surface to be the track surface.
255 
256  fPredSurf = tre.getSurface();
257  fPredDist = 0.;
258 
259  // Default result.
260 
261  bool ok = false;
262 
263  // Update prediction vector, error matrox, and H-matrix.
264 
265  // First test whether the prediction surface matches the
266  // measurement surface.
267 
268  if (getMeasSurface()->isEqual(*fPredSurf)) {
269 
270  // Prediction and measurement surfaces agree.
271  //Just call subpredict method (don't do propagation).
272 
273  ok = subpredict(tre, fPvec, fPerr, fH);
274  }
275  else {
276 
277  // Track surface does not match the prediction surface, so an
278  // internal propagation will be required. Throw an exception if
279  // no propagator was provided.
280 
281  // First make a copy of the original KETrack.
282 
283  KETrack treprop(tre);
284 
285  // Also make a copy of the reference track (if specified).
286 
287  KTrack refprop;
288  KTrack* prefprop = 0;
289  if (ref != 0) {
290  refprop = *ref;
291  prefprop = &refprop;
292  }
293 
294  // Make a no-noise, no-dE/dx propagation to the measurement
295  // surface. But do calculate the propagation matrix, which we
296  // will use to update the H-matrix calculated in the derived
297  // class.
298 
299  TrackMatrix prop_matrix;
300  std::optional<double> dist = prop.err_prop(
301  treprop, getMeasSurface(), Propagator::UNKNOWN, false, prefprop, &prop_matrix);
302  if (dist) {
303 
304  // Update prediction distance.
305 
306  fPredDist = *dist;
307 
308  // Now we are ready to calculate the prediction on the
309  // measurement surface.
310 
311  typename KHMatrix<N>::type hmatrix;
312  ok = subpredict(treprop, fPvec, fPerr, hmatrix);
313  if (ok) {
314 
315  // Use the propagation matrix to transform the H-matrix back
316  // to the prediction surface.
317 
318  fH = prod(hmatrix, prop_matrix);
319  }
320  }
321  }
322  if (ok) {
323 
324  // Update residual
325 
326  fRvec = fMvec - fPvec;
327  fRerr = fMerr + fPerr;
328  fRinv = fRerr;
329  ok = syminvert(fRinv);
330  if (ok) {
331 
332  // Calculate incremental chisquare.
333 
334  // (workaround: if we use the copy constructor, gcc emits a spurious warning)
335  // typename KVector<N>::type rtemp = prod(fRinv, fRvec);
336  fChisq = inner_prod(fRvec, prod(fRinv, fRvec));
337  }
338  }
339 
340  // If a problem occured at any step, clear the prediction surface pointer.
341 
342  if (!ok) {
343  fPredSurf.reset();
344  fPredDist = 0.;
345  }
346 
347  // Done.
348 
349  return ok;
350  }
virtual bool subpredict(const KETrack &tre, typename KVector< N >::type &pvec, typename KSymMatrix< N >::type &perr, typename KHMatrix< N >::type &hmatrix) const =0
Calculate prediction function (return via arguments).
bool isEqual(float x1, float x2)
KVector< N >::type fPvec
Prediction vector.
Definition: KHit.h:196
KMatrix< N, 5 >::type type
KVector< N >::type fMvec
Measurement vector.
Definition: KHit.h:194
KVector< N >::type fRvec
Residual vector.
Definition: KHit.h:198
std::shared_ptr< const Surface > fPredSurf
Prediction surface.
Definition: KHitBase.h:145
bool syminvert(ublas::symmetric_matrix< T, TRI, L, A > &m)
KHMatrix< N >::type fH
Kalman H-matrix.
Definition: KHit.h:201
KSymMatrix< N >::type fRinv
Residual inverse error matrix.
Definition: KHit.h:200
double fPredDist
Prediction distance.
Definition: KHitBase.h:146
KSymMatrix< N >::type fRerr
Residual error matrix.
Definition: KHit.h:199
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
KMatrix< 5, 5 >::type TrackMatrix
General 5x5 matrix.
KSymMatrix< N >::type fPerr
Prediction error matrix.
Definition: KHit.h:197
KSymMatrix< N >::type fMerr
Measurement error matrix.
Definition: KHit.h:195
const std::shared_ptr< const Surface > & getMeasSurface() const
Measurement surface.
Definition: KHitBase.h:91
double fChisq
Incremental chisquare.
Definition: KHit.h:202
template<int N>
std::ostream & trkf::KHit< N >::Print ( std::ostream &  out,
bool  doTitle = true 
) const
virtual

Printout.

Reimplemented from trkf::KHitBase.

Definition at line 404 of file KHit.h.

405  {
406  if (doTitle) out << "KHit<" << N << ">:\n";
407 
408  // Print base class.
409 
410  KHitBase::Print(out, false);
411 
412  // Print measurement vector.
413 
414  out << " Measurement vector:\n"
415  << " [";
416  for (unsigned int i = 0; i < fMvec.size(); ++i) {
417  if (i != 0) out << ", ";
418  out << fMvec(i);
419  }
420  out << "]\n";
421 
422  // Print diagonal measurement errors.
423 
424  out << " Diagonal measurement errors:\n"
425  << " [";
426  for (unsigned int i = 0; i < fMerr.size1(); ++i) {
427  if (i != 0) out << ", ";
428  double err = fMerr(i, i);
429  err = (err >= 0. ? std::sqrt(err) : -std::sqrt(-err));
430  out << err;
431  }
432  out << "]\n";
433 
434  // Print measurement correlations.
435 
436  if (fMerr.size1() > 1) {
437  out << " Measurement correlation matrix:";
438  for (unsigned int i = 0; i < fMerr.size1(); ++i) {
439  if (i == 0)
440  out << "\n [";
441  else
442  out << "\n ";
443  for (unsigned int j = 0; j <= i; ++j) {
444  if (j != 0) out << ", ";
445  if (i == j)
446  out << 1.;
447  else {
448  double eiijj = fMerr(i, i) * fMerr(j, j);
449  double eij = fMerr(i, j);
450  if (eiijj != 0.)
451  eij /= std::sqrt(std::abs(eiijj));
452  else
453  eij = 0.;
454  out << eij;
455  }
456  }
457  }
458  out << "]\n";
459  }
460 
461  // Print prediction vector.
462 
463  out << " Prediction vector:\n"
464  << " [";
465  for (unsigned int i = 0; i < fPvec.size(); ++i) {
466  if (i != 0) out << ", ";
467  out << fPvec(i);
468  }
469  out << "]\n";
470 
471  // Print diagonal prediction errors.
472 
473  out << " Diagonal prediction errors:\n"
474  << " [";
475  for (unsigned int i = 0; i < fPerr.size1(); ++i) {
476  if (i != 0) out << ", ";
477  double err = fPerr(i, i);
478  err = (err >= 0. ? std::sqrt(err) : -std::sqrt(-err));
479  out << err;
480  }
481  out << "]\n";
482 
483  // Print prediction correlations.
484 
485  if (fPerr.size1() > 1) {
486  out << " Prediction correlation matrix:";
487  for (unsigned int i = 0; i < fPerr.size1(); ++i) {
488  if (i == 0)
489  out << "\n [";
490  else
491  out << "\n ";
492  for (unsigned int j = 0; j <= i; ++j) {
493  if (j != 0) out << ", ";
494  if (i == j)
495  out << 1.;
496  else {
497  double eiijj = fPerr(i, i) * fPerr(j, j);
498  double eij = fPerr(i, j);
499  if (eiijj != 0.)
500  eij /= std::sqrt(std::abs(eiijj));
501  else
502  eij = 0.;
503  out << eij;
504  }
505  }
506  }
507  out << "]\n";
508  }
509 
510  // Print residual vector.
511 
512  out << " Residual vector:\n"
513  << " [";
514  for (unsigned int i = 0; i < fRvec.size(); ++i) {
515  if (i != 0) out << ", ";
516  out << fRvec(i);
517  }
518  out << "]\n";
519 
520  // Print diagonal residual errors.
521 
522  out << " Diagonal residual errors:\n"
523  << " [";
524  for (unsigned int i = 0; i < fRerr.size1(); ++i) {
525  if (i != 0) out << ", ";
526  double err = fRerr(i, i);
527  err = (err >= 0. ? std::sqrt(err) : -std::sqrt(-err));
528  out << err;
529  }
530  out << "]\n";
531 
532  // Print residual correlations.
533 
534  if (fRerr.size1() > 1) {
535  out << " Residual correlation matrix:";
536  for (unsigned int i = 0; i < fRerr.size1(); ++i) {
537  if (i == 0)
538  out << "\n [";
539  else
540  out << "\n ";
541  for (unsigned int j = 0; j <= i; ++j) {
542  if (j != 0) out << ", ";
543  if (i == j)
544  out << 1.;
545  else {
546  double eiijj = fRerr(i, i) * fRerr(j, j);
547  double eij = fRerr(i, j);
548  if (eiijj != 0.)
549  eij /= std::sqrt(std::abs(eiijj));
550  else
551  eij = 0.;
552  out << eij;
553  }
554  }
555  }
556  out << "]\n";
557  }
558 
559  // Print incremental chisquare.
560 
561  out << " Incremental chisquare = " << fChisq << "\n";
562 
563  // Done.
564 
565  return out;
566  }
STL namespace.
virtual std::ostream & Print(std::ostream &out, bool doTitle=true) const
Printout.
Definition: KHitBase.cxx:32
KVector< N >::type fPvec
Prediction vector.
Definition: KHit.h:196
KVector< N >::type fMvec
Measurement vector.
Definition: KHit.h:194
KVector< N >::type fRvec
Residual vector.
Definition: KHit.h:198
T abs(T value)
void err(const char *fmt,...)
Definition: message.cpp:226
KSymMatrix< N >::type fRerr
Residual error matrix.
Definition: KHit.h:199
KSymMatrix< N >::type fPerr
Prediction error matrix.
Definition: KHit.h:197
KSymMatrix< N >::type fMerr
Measurement error matrix.
Definition: KHit.h:195
double fChisq
Incremental chisquare.
Definition: KHit.h:202
template<int N>
void trkf::KHit< N >::setMeasError ( const typename KSymMatrix< N >::type merr)
inline

Set measurement error.

Definition at line 101 of file KHit.h.

102  {
103  fMerr = merr;
104  }
KSymMatrix< N >::type fMerr
Measurement error matrix.
Definition: KHit.h:195
template<int N>
void trkf::KHit< N >::setMeasVector ( const typename KVector< N >::type mvec)
inline

Set measurement vector.

Definition at line 94 of file KHit.h.

95  {
96  fMvec = mvec;
97  }
KVector< N >::type fMvec
Measurement vector.
Definition: KHit.h:194
template<int N>
virtual bool trkf::KHit< N >::subpredict ( const KETrack tre,
typename KVector< N >::type pvec,
typename KSymMatrix< N >::type perr,
typename KHMatrix< N >::type hmatrix 
) const
pure virtual

Calculate prediction function (return via arguments).

template<int N>
void trkf::KHit< N >::update ( KETrack tre) const
virtual

Update track method.

Update track method.

Arguments:

tre - Track to be updated.

Implements trkf::KHitBase.

Definition at line 360 of file KHit.h.

361  {
362  // Make sure that the track surface and the prediction surface are the same.
363  // Throw an exception if they are not.
364 
365  if (!getPredSurface()->isEqual(*tre.getSurface()))
366  throw cet::exception("KHit") << "Track surface not the same as prediction surface.\n";
367 
368  const TrackVector& tvec = tre.getVector();
369  const TrackError& terr = tre.getError();
370  TrackVector::size_type size = tvec.size();
371 
372  // Calculate gain matrix.
373 
374  typename KGMatrix<N>::type temp(size, N);
375  typename KGMatrix<N>::type gain(size, N);
376  temp = prod(trans(fH), fRinv);
377  gain = prod(terr, temp);
378 
379  // Calculate updated track state.
380 
381  TrackVector newvec = tre.getVector() + prod(gain, fRvec);
382 
383  // Calculate updated error matrix.
384 
385  TrackMatrix fact = ublas::identity_matrix<TrackVector::value_type>(size);
386  fact -= prod(gain, fH);
387  TrackMatrix errtemp1 = prod(terr, trans(fact));
388  TrackMatrix errtemp2 = prod(fact, errtemp1);
389  TrackError errtemp2s = ublas::symmetric_adaptor<TrackMatrix>(errtemp2);
390  typename KHMatrix<N>::type errtemp3 = prod(fMerr, trans(gain));
391  TrackMatrix errtemp4 = prod(gain, errtemp3);
392  TrackError errtemp4s = ublas::symmetric_adaptor<TrackMatrix>(errtemp4);
393  TrackError newerr = errtemp2s + errtemp4s;
394 
395  // Update track.
396 
397  tre.setVector(newvec);
398  tre.setError(newerr);
399  }
bool isEqual(float x1, float x2)
KSymMatrix< 5 >::type TrackError
Track error matrix, dimension 5x5.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
KMatrix< N, 5 >::type type
KVector< N >::type fRvec
Residual vector.
Definition: KHit.h:198
KHMatrix< N >::type fH
Kalman H-matrix.
Definition: KHit.h:201
KSymMatrix< N >::type fRinv
Residual inverse error matrix.
Definition: KHit.h:200
KVector< 5 >::type TrackVector
Track state vector, dimension 5.
KMatrix< 5, 5 >::type TrackMatrix
General 5x5 matrix.
KMatrix< 5, N >::type type
KSymMatrix< N >::type fMerr
Measurement error matrix.
Definition: KHit.h:195
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
const std::shared_ptr< const Surface > & getPredSurface() const
Predition surface.
Definition: KHitBase.h:77

Member Data Documentation

template<int N>
double trkf::KHit< N >::fChisq
mutableprivate

Incremental chisquare.

Definition at line 202 of file KHit.h.

template<int N>
KHMatrix<N>::type trkf::KHit< N >::fH
mutableprivate

Kalman H-matrix.

Definition at line 201 of file KHit.h.

template<int N>
KSymMatrix<N>::type trkf::KHit< N >::fMerr
private

Measurement error matrix.

Definition at line 195 of file KHit.h.

template<int N>
KVector<N>::type trkf::KHit< N >::fMvec
private

Measurement vector.

Definition at line 194 of file KHit.h.

template<int N>
KSymMatrix<N>::type trkf::KHit< N >::fPerr
mutableprivate

Prediction error matrix.

Definition at line 197 of file KHit.h.

template<int N>
KVector<N>::type trkf::KHit< N >::fPvec
mutableprivate

Prediction vector.

Definition at line 196 of file KHit.h.

template<int N>
KSymMatrix<N>::type trkf::KHit< N >::fRerr
mutableprivate

Residual error matrix.

Definition at line 199 of file KHit.h.

template<int N>
KSymMatrix<N>::type trkf::KHit< N >::fRinv
mutableprivate

Residual inverse error matrix.

Definition at line 200 of file KHit.h.

template<int N>
KVector<N>::type trkf::KHit< N >::fRvec
mutableprivate

Residual vector.

Definition at line 198 of file KHit.h.


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