All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
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, 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...
 
- 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

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...
 

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

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 : fMeasDim(0), fChisq(0.) {}
double fChisq
Incremental chisquare.
Definition: KHitMulti.h:175
int fMeasDim
Measurement space dimension.
Definition: KHitMulti.h:165
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 25 of file KHitMulti.cxx.

26  : KHitBase(psurf), fMeasDim(0), fChisq(0.)
27  {}
KHitBase()
Default constructor.
Definition: KHitBase.cxx:18
double fChisq
Incremental chisquare.
Definition: KHitMulti.h:175
int fMeasDim
Measurement space dimension.
Definition: KHitMulti.h:165
trkf::KHitMulti::~KHitMulti ( )
virtual

Destructor.

Definition at line 30 of file KHitMulti.cxx.

30 {}

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 42 of file KHitMulti.cxx.

43  {
44  // It is an error to pass in a null pointer.
45 
46  if (pmeas.get() == 0)
47  throw cet::exception("KHitMulti") << "Attempt to add null measurement pointer.\n";
48 
49  // Do the dynamic cast.
50 
51  std::shared_ptr<const KHit<1>> pmeas1 =
52  std::dynamic_pointer_cast<const KHit<1>, const KHitBase>(pmeas);
53 
54  // Throw an exception if dynamic cast failed.
55 
56  if (pmeas1.get() == 0)
57  throw cet::exception("KHitMulti") << "Dynamic cast for KHitBase pointer failed.\n";
58  addMeas(pmeas1);
59  }
KHitBase()
Default constructor.
Definition: KHitBase.cxx:18
void addMeas(const std::shared_ptr< const KHitBase > &pmeas)
Add a measurement of unknown type.
Definition: KHitMulti.cxx:42
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 68 of file KHitMulti.cxx.

69  {
70  // It is an error to pass in a null pointer.
71 
72  if (pmeas.get() == 0)
73  throw cet::exception("KHitMulti") << "Attempt to add null measurement pointer.\n";
74 
75  // Add the measurement.
76 
77  ++fMeasDim;
78  fMeasVec.push_back(pmeas);
79  }
std::vector< std::shared_ptr< const KHit< 1 > > > fMeasVec
Underlying measurements.
Definition: KHitMulti.h:166
int fMeasDim
Measurement space dimension.
Definition: KHitMulti.h:165
double trkf::KHitMulti::getChisq ( ) const
inlinevirtual

Incremental chisquare.

Implements trkf::KHitBase.

Definition at line 138 of file KHitMulti.h.

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

Kalman H-matrix.

Definition at line 131 of file KHitMulti.h.

132  {
133  return fH;
134  }
ublas::matrix< double > fH
Kalman H-matrix.
Definition: KHitMulti.h:174
int trkf::KHitMulti::getMeasDim ( ) const
inline

Measurement space dimension.

Definition at line 68 of file KHitMulti.h.

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

Measurement error matrix.

Definition at line 89 of file KHitMulti.h.

90  {
91  return fMerr;
92  }
ublas::symmetric_matrix< double > fMerr
Measurement error matrix.
Definition: KHitMulti.h:168
const std::vector<std::shared_ptr<const KHit<1> > >& trkf::KHitMulti::getMeasVec ( ) const
inline

Measurement collection.

Definition at line 75 of file KHitMulti.h.

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

Measurement vector.

Definition at line 82 of file KHitMulti.h.

83  {
84  return fMvec;
85  }
ublas::vector< double > fMvec
Measurement vector.
Definition: KHitMulti.h:167
const ublas::symmetric_matrix<double>& trkf::KHitMulti::getPredError ( ) const
inline

Prediction matrix.

Definition at line 103 of file KHitMulti.h.

104  {
105  return fPerr;
106  }
ublas::symmetric_matrix< double > fPerr
Prediction error matrix.
Definition: KHitMulti.h:170
const ublas::vector<double>& trkf::KHitMulti::getPredVector ( ) const
inline

Prediction vector.

Definition at line 96 of file KHitMulti.h.

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

Residual error matrix.

Definition at line 117 of file KHitMulti.h.

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

Residual inv. error matrix.

Definition at line 124 of file KHitMulti.h.

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

Residual vector.

Definition at line 110 of file KHitMulti.h.

111  {
112  return fRvec;
113  }
ublas::vector< double > fRvec
Residual vector.
Definition: KHitMulti.h:171
bool trkf::KHitMulti::predict ( const KETrack tre,
const Propagator prop,
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 95 of file KHitMulti.cxx.

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

Printout.

Reimplemented from trkf::KHitBase.

Definition at line 245 of file KHitMulti.cxx.

246  {
247  if (doTitle) out << "KHitMulti:\n";
248  return out;
249  }
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 202 of file KHitMulti.cxx.

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

Member Data Documentation

double trkf::KHitMulti::fChisq
mutableprivate

Incremental chisquare.

Definition at line 175 of file KHitMulti.h.

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

Kalman H-matrix.

Definition at line 174 of file KHitMulti.h.

int trkf::KHitMulti::fMeasDim
private

Measurement space dimension.

Definition at line 165 of file KHitMulti.h.

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

Underlying measurements.

Definition at line 166 of file KHitMulti.h.

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

Measurement error matrix.

Definition at line 168 of file KHitMulti.h.

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

Measurement vector.

Definition at line 167 of file KHitMulti.h.

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

Prediction error matrix.

Definition at line 170 of file KHitMulti.h.

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

Prediction vector.

Definition at line 169 of file KHitMulti.h.

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

Residual error matrix.

Definition at line 172 of file KHitMulti.h.

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

Residual inverse error matrix.

Definition at line 173 of file KHitMulti.h.

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

Residual vector.

Definition at line 171 of file KHitMulti.h.


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