LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
trkf::KHitMulti Class Reference

#include "KHitMulti.h"

Inheritance diagram for trkf::KHitMulti:
trkf::KHitBase

Public Member Functions

 KHitMulti ()
 Default constructor. More...
 
 KHitMulti (const std::shared_ptr< const Surface > &psurf)
 Initializing Constructor – measurement surface only. More...
 
virtual ~KHitMulti ()
 Destructor. More...
 
int getMeasDim () const
 Measurement space dimension. More...
 
const std::vector< std::shared_ptr< const KHit< 1 > > > & getMeasVec () const
 Measurement collection. More...
 
const ublas::vector< double > & getMeasVector () const
 Measurement vector. More...
 
const ublas::symmetric_matrix< double > & getMeasError () const
 Measurement error matrix. More...
 
const ublas::vector< double > & getPredVector () const
 Prediction vector. More...
 
const ublas::symmetric_matrix< double > & getPredError () const
 Prediction matrix. More...
 
const ublas::vector< double > & getResVector () const
 Residual vector. More...
 
const ublas::symmetric_matrix< double > & getResError () const
 Residual error matrix. More...
 
const ublas::symmetric_matrix< double > & getResInvError () const
 Residual inv. error matrix. More...
 
const ublas::matrix< double > & getH () const
 Kalman H-matrix. More...
 
double getChisq () const
 Incremental chisquare. More...
 
void addMeas (const std::shared_ptr< const KHitBase > &pmeas)
 Add a measurement of unknown type. More...
 
void addMeas (const std::shared_ptr< const KHit< 1 > > &pmeas)
 Add a one-dimensional measurement. More...
 
bool predict (const KETrack &tre, const Propagator *prop=0, const KTrack *ref=0) const
 Prediction method (return false if fail). More...
 
void update (KETrack &tre) const
 Update track method. More...
 
virtual std::ostream & Print (std::ostream &out, bool doTitle=true) const
 Printout. 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...
 

Protected Attributes

std::shared_ptr< const SurfacefPredSurf
 Prediction surface. More...
 
double fPredDist
 Prediction distance. More...
 
int fID
 Unique id. More...
 

Private Attributes

int fMeasDim
 Measurement space dimension. More...
 
std::vector< std::shared_ptr< const KHit< 1 > > > fMeasVec
 Underlying measurements. More...
 
ublas::vector< double > fMvec
 Measurement vector. More...
 
ublas::symmetric_matrix< double > fMerr
 Measurement error matrix. More...
 
ublas::vector< double > fPvec
 Prediction vector. More...
 
ublas::symmetric_matrix< double > fPerr
 Prediction error matrix. More...
 
ublas::vector< double > fRvec
 Residual vector. More...
 
ublas::symmetric_matrix< double > fRerr
 Residual error matrix. More...
 
ublas::symmetric_matrix< double > fRinv
 Residual inverse error matrix. More...
 
ublas::matrix< double > fH
 Kalman H-matrix. More...
 
double fChisq
 Incremental chisquare. More...
 

Detailed Description

Definition at line 53 of file KHitMulti.h.

Constructor & Destructor Documentation

trkf::KHitMulti::KHitMulti ( )

Default constructor.

Default Constructor.

Definition at line 17 of file KHitMulti.cxx.

17  :
18  fMeasDim(0),
19  fChisq(0.)
20  {}
double fChisq
Incremental chisquare.
Definition: KHitMulti.h:135
int fMeasDim
Measurement space dimension.
Definition: KHitMulti.h:125
trkf::KHitMulti::KHitMulti ( const std::shared_ptr< const Surface > &  psurf)

Initializing Constructor – measurement surface only.

Initializing Constructor.

Arguments:

psurf - Measurement surface pointer.

Definition at line 28 of file KHitMulti.cxx.

28  :
29  KHitBase(psurf),
30  fMeasDim(0),
31  fChisq(0.)
32  {}
KHitBase()
Default constructor.
Definition: KHitBase.cxx:16
double fChisq
Incremental chisquare.
Definition: KHitMulti.h:135
int fMeasDim
Measurement space dimension.
Definition: KHitMulti.h:125
trkf::KHitMulti::~KHitMulti ( )
virtual

Destructor.

Definition at line 35 of file KHitMulti.cxx.

36  {}

Member Function Documentation

void trkf::KHitMulti::addMeas ( const std::shared_ptr< const KHitBase > &  pmeas)

Add a measurement of unknown type.

Add a measurement.

Arguments:

pmeas - Measurement.

This method tries to dynamic cast the measurement to a supported type. If the dynamic cast fails, throw an exception.

Definition at line 47 of file KHitMulti.cxx.

Referenced by getChisq().

48  {
49  // It is an error to pass in a null pointer.
50 
51  if(pmeas.get() == 0)
52  throw cet::exception("KHitMulti") << "Attempt to add null measurement pointer.\n";
53 
54  // Do the dynamic cast.
55 
56  std::shared_ptr<const KHit<1> > pmeas1 =
57  std::dynamic_pointer_cast<const KHit<1>, const KHitBase>(pmeas);
58 
59  // Throw an exception if dynamic cast failed.
60 
61  if(pmeas1.get() == 0)
62  throw cet::exception("KHitMulti") << "Dynamic cast for KHitBase pointer failed.\n";
63  addMeas(pmeas1);
64  }
KHitBase()
Default constructor.
Definition: KHitBase.cxx:16
void addMeas(const std::shared_ptr< const KHitBase > &pmeas)
Add a measurement of unknown type.
Definition: KHitMulti.cxx:47
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void trkf::KHitMulti::addMeas ( const std::shared_ptr< const KHit< 1 > > &  pmeas)

Add a one-dimensional measurement.

Add a measurement.

Arguments:

pmeas - Measurement.

Definition at line 72 of file KHitMulti.cxx.

References fMeasDim, and fMeasVec.

73  {
74  // It is an error to pass in a null pointer.
75 
76  if(pmeas.get() == 0)
77  throw cet::exception("KHitMulti") << "Attempt to add null measurement pointer.\n";
78 
79  // Add the measurement.
80 
81  ++fMeasDim;
82  fMeasVec.push_back(pmeas);
83  }
std::vector< std::shared_ptr< const KHit< 1 > > > fMeasVec
Underlying measurements.
Definition: KHitMulti.h:126
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
int fMeasDim
Measurement space dimension.
Definition: KHitMulti.h:125
double trkf::KHitMulti::getChisq ( ) const
inlinevirtual

Incremental chisquare.

Implements trkf::KHitBase.

Definition at line 99 of file KHitMulti.h.

References addMeas(), fChisq, predict(), Print(), and update().

99 {return fChisq;}
double fChisq
Incremental chisquare.
Definition: KHitMulti.h:135
const ublas::matrix<double>& trkf::KHitMulti::getH ( ) const
inline

Kalman H-matrix.

Definition at line 96 of file KHitMulti.h.

References fH.

96 {return fH;}
ublas::matrix< double > fH
Kalman H-matrix.
Definition: KHitMulti.h:134
int trkf::KHitBase::getID ( ) const
inlineinherited
int trkf::KHitMulti::getMeasDim ( ) const
inline

Measurement space dimension.

Definition at line 69 of file KHitMulti.h.

References fMeasDim.

69 {return fMeasDim;}
int fMeasDim
Measurement space dimension.
Definition: KHitMulti.h:125
const ublas::symmetric_matrix<double>& trkf::KHitMulti::getMeasError ( ) const
inline

Measurement error matrix.

Definition at line 78 of file KHitMulti.h.

References fMerr.

78 {return fMerr;}
ublas::symmetric_matrix< double > fMerr
Measurement error matrix.
Definition: KHitMulti.h:128
int trkf::KHitBase::getMeasPlane ( ) const
inlineinherited

Measurement plane index.

Definition at line 84 of file KHitBase.h.

References trkf::KHitBase::fMeasPlane.

Referenced by trkf::KalmanFilterAlg::buildTrack(), trkf::KalmanFilterAlg::cleanTrack(), trkf::KalmanFilterAlg::extendTrack(), and trkf::KGTrack::Print().

84 {return fMeasPlane;}
int fMeasPlane
Measurement plane index.
Definition: KHitBase.h:123
const std::shared_ptr<const Surface>& trkf::KHitBase::getMeasSurface ( ) const
inlineinherited

Measurement surface.

Definition at line 81 of file KHitBase.h.

References trkf::KHitBase::fMeasSurf.

Referenced by trkf::KHit< N >::predict(), trkf::KHitWireX::subpredict(), and trkf::KHitWireLine::subpredict().

81 {return fMeasSurf;}
std::shared_ptr< const Surface > fMeasSurf
Measurement surface.
Definition: KHitBase.h:122
const std::vector<std::shared_ptr<const KHit<1> > >& trkf::KHitMulti::getMeasVec ( ) const
inline

Measurement collection.

Definition at line 72 of file KHitMulti.h.

References fMeasVec.

72 {return fMeasVec;}
std::vector< std::shared_ptr< const KHit< 1 > > > fMeasVec
Underlying measurements.
Definition: KHitMulti.h:126
const ublas::vector<double>& trkf::KHitMulti::getMeasVector ( ) const
inline

Measurement vector.

Definition at line 75 of file KHitMulti.h.

References fMvec.

75 {return fMvec;}
ublas::vector< double > fMvec
Measurement vector.
Definition: KHitMulti.h:127
double trkf::KHitBase::getPredDistance ( ) const
inlineinherited

Prediction distance.

Definition at line 78 of file KHitBase.h.

References trkf::KHitBase::fPredDist.

Referenced by trkf::KalmanFilterAlg::buildTrack(), and trkf::KalmanFilterAlg::extendTrack().

78 {return fPredDist;}
double fPredDist
Prediction distance.
Definition: KHitBase.h:117
const ublas::symmetric_matrix<double>& trkf::KHitMulti::getPredError ( ) const
inline

Prediction matrix.

Definition at line 84 of file KHitMulti.h.

References fPerr.

84 {return fPerr;}
ublas::symmetric_matrix< double > fPerr
Prediction error matrix.
Definition: KHitMulti.h:130
const std::shared_ptr<const Surface>& trkf::KHitBase::getPredSurface ( ) const
inlineinherited

Predition surface.

Definition at line 75 of file KHitBase.h.

References trkf::KHitBase::fPredSurf.

Referenced by update(), and trkf::KHit< N >::update().

75 {return fPredSurf;}
std::shared_ptr< const Surface > fPredSurf
Prediction surface.
Definition: KHitBase.h:116
const ublas::vector<double>& trkf::KHitMulti::getPredVector ( ) const
inline

Prediction vector.

Definition at line 81 of file KHitMulti.h.

References fPvec.

81 {return fPvec;}
ublas::vector< double > fPvec
Prediction vector.
Definition: KHitMulti.h:129
const ublas::symmetric_matrix<double>& trkf::KHitMulti::getResError ( ) const
inline

Residual error matrix.

Definition at line 90 of file KHitMulti.h.

References fRerr.

90 {return fRerr;}
ublas::symmetric_matrix< double > fRerr
Residual error matrix.
Definition: KHitMulti.h:132
const ublas::symmetric_matrix<double>& trkf::KHitMulti::getResInvError ( ) const
inline

Residual inv. error matrix.

Definition at line 93 of file KHitMulti.h.

References fRinv.

93 {return fRinv;}
ublas::symmetric_matrix< double > fRinv
Residual inverse error matrix.
Definition: KHitMulti.h:133
const ublas::vector<double>& trkf::KHitMulti::getResVector ( ) const
inline

Residual vector.

Definition at line 87 of file KHitMulti.h.

References fRvec.

87 {return fRvec;}
ublas::vector< double > fRvec
Residual vector.
Definition: KHitMulti.h:131
bool trkf::KHitMulti::predict ( const KETrack tre,
const Propagator prop = 0,
const KTrack ref = 0 
) const
virtual

Prediction method (return false if fail).

Prediction method (return false if fail).

Arguments:

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

Returns: True if success.

This class calls the predict method of each underlying measurement and updates the combined prediction attributes.

Implements trkf::KHitBase.

Definition at line 98 of file KHitMulti.cxx.

References fChisq, fH, fMeasDim, fMeasVec, fMerr, fMvec, fPerr, trkf::KHitBase::fPredDist, trkf::KHitBase::fPredSurf, fPvec, fRerr, fRinv, fRvec, trkf::KETrack::getError(), trkf::KHit< N >::getH(), trkf::KHit< N >::getMeasError(), trkf::KHit< N >::getMeasVector(), trkf::KHit< N >::getPredVector(), trkf::KTrack::getSurface(), trkf::KTrack::getVector(), trkf::KHit< N >::predict(), and trkf::syminvert().

Referenced by getChisq().

99  {
100  // Resize and clear all linear algebra objects.
101 
102  fMvec.resize(fMeasDim, false);
103  fMvec.clear();
104 
105  fMerr.resize(fMeasDim, false);
106  fMerr.clear();
107 
108  fPvec.resize(fMeasDim, false);
109  fPvec.clear();
110 
111  fPerr.resize(fMeasDim, false);
112  fPerr.clear();
113 
114  fRvec.resize(fMeasDim, false);
115  fRvec.clear();
116 
117  fRerr.resize(fMeasDim, false);
118  fRerr.clear();
119 
120  fRinv.resize(fMeasDim, false);
121  fRinv.clear();
122 
123  fH.resize(fMeasDim, tre.getVector().size());
124  fH.clear();
125 
126  // Update the prediction surface to be the track surface.
127 
128  fPredSurf = tre.getSurface();
129  fPredDist = 0.;
130 
131  // Result.
132 
133  bool ok = true;
134 
135  // Loop over one-dimensional measurements.
136 
137  for(unsigned int im = 0; ok && im < fMeasVec.size(); ++im) {
138  const KHit<1>& meas = *(fMeasVec[im]);
139 
140  // Update prediction for this measurement.
141 
142  ok = meas.predict(tre, prop, ref);
143  if(!ok)
144  break;
145 
146  //
147 
148  // Update objects that are concatenations of underlying measurements.
149 
150  fMvec(im) = meas.getMeasVector()(0); // Measurement vector.
151  fMerr(im, im) = meas.getMeasError()(0, 0); // Measurement error matrix.
152  fPvec(im) = meas.getPredVector()(0); // Prediction vector.
153 
154  // H-matrix.
155 
156  for(unsigned int j = 0; j < meas.getH().size2(); ++j)
157  fH(im, j) = meas.getH()(0, j);
158  }
159  if(ok) {
160 
161  // Calculate prediction error matrix.
162  // T = H C H^T.
163 
164  ublas::matrix<double> temp(fH.size2(), fMeasDim);
165  ublas::matrix<double> temp2(fMeasDim, fMeasDim);
166  temp = prod(tre.getError(), trans(fH));
167  temp2 = prod(fH, temp);
168  fPerr = ublas::symmetric_adaptor<ublas::matrix<double> >(temp2);
169 
170  // Update residual
171 
172  fRvec = fMvec - fPvec;
173  fRerr = fMerr + fPerr;
174  fRinv = fRerr;
175  ok = syminvert(fRinv);
176  if(ok) {
177 
178  // Calculate incremental chisquare.
179 
180  ublas::vector<double> rtemp = prod(fRinv, fRvec);
181  fChisq = inner_prod(fRvec, rtemp);
182  }
183  }
184 
185  // If a problem occured at any step, clear the prediction surface pointer.
186 
187  if(!ok) {
188  fPredSurf.reset();
189  fPredDist = 0.;
190  }
191 
192  // Done.
193 
194  return ok;
195  }
ublas::vector< double > fPvec
Prediction vector.
Definition: KHitMulti.h:129
std::vector< std::shared_ptr< const KHit< 1 > > > fMeasVec
Underlying measurements.
Definition: KHitMulti.h:126
std::shared_ptr< const Surface > fPredSurf
Prediction surface.
Definition: KHitBase.h:116
bool syminvert(ublas::symmetric_matrix< T, TRI, L, A > &m)
ublas::symmetric_matrix< double > fRinv
Residual inverse error matrix.
Definition: KHitMulti.h:133
ublas::symmetric_matrix< double > fPerr
Prediction error matrix.
Definition: KHitMulti.h:130
double fPredDist
Prediction distance.
Definition: KHitBase.h:117
ublas::vector< double > fRvec
Residual vector.
Definition: KHitMulti.h:131
ublas::matrix< double > fH
Kalman H-matrix.
Definition: KHitMulti.h:134
ublas::symmetric_matrix< double > fRerr
Residual error matrix.
Definition: KHitMulti.h:132
ublas::symmetric_matrix< double > fMerr
Measurement error matrix.
Definition: KHitMulti.h:128
double fChisq
Incremental chisquare.
Definition: KHitMulti.h:135
ublas::vector< double > fMvec
Measurement vector.
Definition: KHitMulti.h:127
int fMeasDim
Measurement space dimension.
Definition: KHitMulti.h:125
std::ostream & trkf::KHitMulti::Print ( std::ostream &  out,
bool  doTitle = true 
) const
virtual

Printout.

Reimplemented from trkf::KHitBase.

Definition at line 247 of file KHitMulti.cxx.

Referenced by getChisq().

248  {
249  if(doTitle)
250  out << "KHitMulti:\n";
251  return out;
252  }
void trkf::KHitBase::setMeasPlane ( int  plane)
inlineinherited
void trkf::KHitBase::setMeasSurface ( const std::shared_ptr< const Surface > &  psurf)
inlineinherited

Measurement surface.

Definition at line 92 of file KHitBase.h.

References trkf::KHitBase::fMeasSurf.

Referenced by trkf::KHitWireLine::KHitWireLine(), and trkf::KHitWireX::KHitWireX().

92 {fMeasSurf = psurf;}
std::shared_ptr< const Surface > fMeasSurf
Measurement surface.
Definition: KHitBase.h:122
void trkf::KHitMulti::update ( KETrack tre) const
virtual

Update track method.

Update track method.

Arguments:

tre - Track to be updated.

This method is almost an exact copy of the update method in KHit<N>.

Implements trkf::KHitBase.

Definition at line 205 of file KHitMulti.cxx.

References fH, fMeasDim, fMerr, fRinv, fRvec, trkf::KETrack::getError(), trkf::KHitBase::getPredSurface(), trkf::KTrack::getSurface(), trkf::KTrack::getVector(), trkf::KETrack::setError(), and trkf::KTrack::setVector().

Referenced by getChisq().

206  {
207  // Make sure that the track surface and the prediction surface are the same.
208  // Throw an exception if they are not.
209 
210  if(!getPredSurface()->isEqual(*tre.getSurface()))
211  throw cet::exception("KHitMulti") << "Track surface not the same as prediction surface.\n";
212 
213  const TrackVector& tvec = tre.getVector();
214  const TrackError& terr = tre.getError();
215  TrackVector::size_type size = tvec.size();
216 
217  // Calculate gain matrix.
218 
219  ublas::matrix<double> temp(size, fMeasDim);
220  ublas::matrix<double> gain(size, fMeasDim);
221  temp = prod(trans(fH), fRinv);
222  gain = prod(terr, temp);
223 
224  // Calculate updated track state.
225 
226  TrackVector newvec = tre.getVector() + prod(gain, fRvec);
227 
228  // Calculate updated error matrix.
229 
230  TrackMatrix fact = ublas::identity_matrix<TrackVector::value_type>(size);
231  fact -= prod(gain, fH);
232  TrackMatrix errtemp1 = prod(terr, trans(fact));
233  TrackMatrix errtemp2 = prod(fact, errtemp1);
234  TrackError errtemp2s = ublas::symmetric_adaptor<TrackMatrix>(errtemp2);
235  ublas::matrix<double> errtemp3 = prod(fMerr, trans(gain));
236  TrackMatrix errtemp4 = prod(gain, errtemp3);
237  TrackError errtemp4s = ublas::symmetric_adaptor<TrackMatrix>(errtemp4);
238  TrackError newerr = errtemp2s + errtemp4s;
239 
240  // Update track.
241 
242  tre.setVector(newvec);
243  tre.setError(newerr);
244  }
KSymMatrix< 5 >::type TrackError
Track error matrix, dimension 5x5.
ublas::symmetric_matrix< double > fRinv
Residual inverse error matrix.
Definition: KHitMulti.h:133
KVector< 5 >::type TrackVector
Track state vector, dimension 5.
ublas::vector< double > fRvec
Residual vector.
Definition: KHitMulti.h:131
ublas::matrix< double > fH
Kalman H-matrix.
Definition: KHitMulti.h:134
KMatrix< 5, 5 >::type TrackMatrix
General 5x5 matrix.
ublas::symmetric_matrix< double > fMerr
Measurement error matrix.
Definition: KHitMulti.h:128
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
const std::shared_ptr< const Surface > & getPredSurface() const
Predition surface.
Definition: KHitBase.h:75
int fMeasDim
Measurement space dimension.
Definition: KHitMulti.h:125

Member Data Documentation

double trkf::KHitMulti::fChisq
mutableprivate

Incremental chisquare.

Definition at line 135 of file KHitMulti.h.

Referenced by getChisq(), and predict().

ublas::matrix<double> trkf::KHitMulti::fH
mutableprivate

Kalman H-matrix.

Definition at line 134 of file KHitMulti.h.

Referenced by getH(), predict(), and update().

int trkf::KHitBase::fID
protectedinherited

Unique id.

Definition at line 118 of file KHitBase.h.

Referenced by trkf::KHitBase::getID(), trkf::KHitWireLine::KHitWireLine(), and trkf::KHitWireX::KHitWireX().

int trkf::KHitMulti::fMeasDim
private

Measurement space dimension.

Definition at line 125 of file KHitMulti.h.

Referenced by addMeas(), getMeasDim(), predict(), and update().

std::vector<std::shared_ptr<const KHit<1> > > trkf::KHitMulti::fMeasVec
private

Underlying measurements.

Definition at line 126 of file KHitMulti.h.

Referenced by addMeas(), getMeasVec(), and predict().

ublas::symmetric_matrix<double> trkf::KHitMulti::fMerr
mutableprivate

Measurement error matrix.

Definition at line 128 of file KHitMulti.h.

Referenced by getMeasError(), predict(), and update().

ublas::vector<double> trkf::KHitMulti::fMvec
mutableprivate

Measurement vector.

Definition at line 127 of file KHitMulti.h.

Referenced by getMeasVector(), and predict().

ublas::symmetric_matrix<double> trkf::KHitMulti::fPerr
mutableprivate

Prediction error matrix.

Definition at line 130 of file KHitMulti.h.

Referenced by getPredError(), and predict().

double trkf::KHitBase::fPredDist
mutableprotectedinherited

Prediction distance.

Definition at line 117 of file KHitBase.h.

Referenced by trkf::KHitBase::getPredDistance(), predict(), trkf::KHit< N >::predict(), and trkf::KHitBase::Print().

std::shared_ptr<const Surface> trkf::KHitBase::fPredSurf
mutableprotectedinherited

Prediction surface.

Definition at line 116 of file KHitBase.h.

Referenced by trkf::KHitBase::getPredSurface(), predict(), trkf::KHit< N >::predict(), and trkf::KHitBase::Print().

ublas::vector<double> trkf::KHitMulti::fPvec
mutableprivate

Prediction vector.

Definition at line 129 of file KHitMulti.h.

Referenced by getPredVector(), and predict().

ublas::symmetric_matrix<double> trkf::KHitMulti::fRerr
mutableprivate

Residual error matrix.

Definition at line 132 of file KHitMulti.h.

Referenced by getResError(), and predict().

ublas::symmetric_matrix<double> trkf::KHitMulti::fRinv
mutableprivate

Residual inverse error matrix.

Definition at line 133 of file KHitMulti.h.

Referenced by getResInvError(), predict(), and update().

ublas::vector<double> trkf::KHitMulti::fRvec
mutableprivate

Residual vector.

Definition at line 131 of file KHitMulti.h.

Referenced by getResVector(), predict(), and update().


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