LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
trkf::KETrack Class Reference

#include "KETrack.h"

Inheritance diagram for trkf::KETrack:
trkf::KTrack trkf::KFitTrack trkf::KHitsTrack trkf::KHitTrack

Public Member Functions

 KETrack ()
 Default constructor. More...
 
 KETrack (const std::shared_ptr< const Surface > &psurf)
 Constructor - specify surface only. More...
 
 KETrack (const std::shared_ptr< const Surface > &psurf, const TrackVector &vec, const TrackError &err, Surface::TrackDirection dir=Surface::UNKNOWN, int pdg=0)
 Constructor - surface + track parameters + error matrix. More...
 
 KETrack (const KTrack &trk, const TrackError &err)
 Constructor - KTrack + error matrix. More...
 
virtual ~KETrack ()
 Destructor. More...
 
const TrackErrorgetError () const
 Track error matrix. More...
 
double PointingError () const
 Pointing error (radians). More...
 
TrackErrorgetError ()
 Modifiable error matrix. More...
 
void setError (const TrackError &err)
 Set error matrix. More...
 
std::optional< double > combineTrack (const KETrack &tre)
 Combine two tracks. More...
 
virtual std::ostream & Print (std::ostream &out, bool doTitle=true) const
 Printout. More...
 
const std::shared_ptr< const Surface > & getSurface () const
 Surface. More...
 
const TrackVectorgetVector () const
 Track state vector. More...
 
TrackVectorgetVector ()
 Modifiable state vector. More...
 
Surface::TrackDirection getDirection () const
 Track direction. More...
 
int PdgCode () const
 Pdg code. More...
 
double Mass () const
 Based on pdg code. More...
 
void setSurface (const std::shared_ptr< const Surface > &psurf)
 Set surface. More...
 
void setVector (const TrackVector &vec)
 Set state vector. More...
 
void setDirection (Surface::TrackDirection dir)
 Set direction. More...
 
void setPdgCode (int pdg)
 Set pdg code. More...
 
bool isValid () const
 Test if track is valid. More...
 
void getPosition (double xyz[3]) const
 Get position of track. More...
 
void getMomentum (double mom[3]) const
 Get momentum vector of track. More...
 
double XLatitude () const
 Get x-latitude. More...
 
double XLongitude () const
 Get x-longitude. More...
 

Private Attributes

TrackError fErr
 Track error matrix. More...
 

Detailed Description

Definition at line 29 of file KETrack.h.

Constructor & Destructor Documentation

trkf::KETrack::KETrack ( )

Default constructor.

Definition at line 18 of file KETrack.cxx.

18 {}
trkf::KETrack::KETrack ( const std::shared_ptr< const Surface > &  psurf)

Constructor - specify surface only.

Constructor - specify surface only.

Arguments:

psurf - Surface pointer.

Definition at line 26 of file KETrack.cxx.

26 : KTrack(psurf) {}
KTrack()
Enum.
Definition: KTrack.cxx:29
trkf::KETrack::KETrack ( const std::shared_ptr< const Surface > &  psurf,
const TrackVector vec,
const TrackError err,
Surface::TrackDirection  dir = Surface::UNKNOWN,
int  pdg = 0 
)

Constructor - surface + track parameters + error matrix.

Constructor - surface + track parameters + error matrix.

Arguments:

psurf - Surface pointer. vec - Track state vector. err - Track error matrix. dir - Track direction. pdg - Pdg code.

Definition at line 38 of file KETrack.cxx.

43  : KTrack(psurf, vec, dir, pdg), fErr(err)
44  {}
KTrack()
Enum.
Definition: KTrack.cxx:29
TDirectory * dir
Definition: macro.C:5
TrackError fErr
Track error matrix.
Definition: KETrack.h:69
trkf::KETrack::KETrack ( const KTrack trk,
const TrackError err 
)

Constructor - KTrack + error matrix.

Constructor - KTrack + error matrix.

Arguments:

trk - KTrack. err - Track error matrix.

Definition at line 53 of file KETrack.cxx.

53 : KTrack(trk), fErr(err) {}
KTrack()
Enum.
Definition: KTrack.cxx:29
TrackError fErr
Track error matrix.
Definition: KETrack.h:69
trkf::KETrack::~KETrack ( )
virtual

Destructor.

Definition at line 56 of file KETrack.cxx.

56 {}

Member Function Documentation

std::optional< double > trkf::KETrack::combineTrack ( const KETrack tre)

Combine two tracks.

Combine two tracks.

Arguments:

tre - Another track.

Returns: Chisquare + success flag.

This method updates the current track to be the weighted average of itself and another track. The chisquare of the combination is returned as the result value. The combination can fail because the sum of the two error matrices is singular, in which case the success flag embedded in the return value is false.

Definition at line 87 of file KETrack.cxx.

References getError(), trkf::KTrack::getSurface(), trkf::KTrack::getVector(), trkf::KTrack::isValid(), setError(), trkf::KTrack::setVector(), and trkf::syminvert().

Referenced by trkf::KFitTrack::combineFit(), and setError().

88  {
89  // Make sure that the two track surfaces are the same.
90  // Throw an exception if they are not.
91 
92  if (!getSurface()->isEqual(*tre.getSurface()))
93  throw cet::exception("KETrack") << "Track combination surfaces are not the same.\n";
94 
95  // Default result is failure.
96 
97  std::optional<double> result{std::nullopt};
98 
99  // We will use asymmetric versions of the updating formulas, such
100  // that the result is calculated as a perturbation on the
101  // better-measured track. We define the better measured track as
102  // the one with the smaller error matrix trace.
103 
104  // Extract the two state vectors and error matrices as pointers.
105 
106  const TrackVector* vec1 = &getVector();
107  const TrackError* err1 = &getError();
108  const TrackVector* vec2 = &tre.getVector();
109  const TrackError* err2 = &tre.getError();
110 
111  // Calculate the traces of the error matrices.
112 
113  double tr1 = 0;
114  for (unsigned int i = 0; i < err1->size1(); ++i)
115  tr1 += (*err1)(i, i);
116 
117  double tr2 = 0;
118  for (unsigned int i = 0; i < err2->size1(); ++i)
119  tr2 += (*err2)(i, i);
120 
121  // Define vec1, err1 as belong to the better measured track.
122  // Swap if necessary.
123 
124  if (tr1 > tr2) {
125  const TrackVector* tvec = vec1;
126  vec1 = vec2;
127  vec2 = tvec;
128  const TrackError* terr = err1;
129  err1 = err2;
130  err2 = terr;
131  }
132 
133  // Calculate the difference vector and difference error matrix.
134 
135  TrackVector dvec = *vec1 - *vec2;
136  TrackError derr = *err1 + *err2;
137 
138  // Invert the difference error matrix.
139  // This is the only place where a detectable failure can occur.
140 
141  bool ok = syminvert(derr);
142  if (ok) {
143 
144  // Calculate updated state vector.
145  // vec1 = vec1 - err1 * derr * dvec
146 
147  TrackVector tvec1 = prod(derr, dvec);
148  TrackVector tvec2 = prod(*err1, tvec1);
149  TrackVector tvec3 = *vec1 - tvec2;
150  setVector(tvec3);
151 
152  // Calculate updated error matrix.
153  // err1 = err1 - err1 * derr * err1
154 
155  TrackMatrix terr1 = prod(derr, *err1);
156  TrackMatrix terr2 = prod(*err1, terr1);
157  TrackError terr2s = ublas::symmetric_adaptor<TrackMatrix>(terr2);
158  TrackError terr3 = *err1 - terr2s;
159  setError(terr3);
160 
161  // Calculate chisquare.
162  // chisq = dvec^T * derr * dvec
163 
164  TrackVector dvec1 = prod(derr, dvec);
165  double chisq = inner_prod(dvec, dvec1);
166  result = std::make_optional(chisq);
167  }
168 
169  // Final validity check.
170 
171  if (!isValid()) result = std::nullopt;
172 
173  // Done.
174 
175  return result;
176  }
const TrackError & getError() const
Track error matrix.
Definition: KETrack.h:52
const std::shared_ptr< const Surface > & getSurface() const
Surface.
Definition: KTrack.h:53
KSymMatrix< 5 >::type TrackError
Track error matrix, dimension 5x5.
void setVector(const TrackVector &vec)
Set state vector.
Definition: KTrack.h:65
void setError(const TrackError &err)
Set error matrix.
Definition: KETrack.h:58
KMatrix< 5, 5 >::type TrackMatrix
General 5x5 matrix.
bool syminvert(ublas::symmetric_matrix< T, TRI, L, A > &m)
KVector< 5 >::type TrackVector
Track state vector, dimension 5.
const TrackVector & getVector() const
Track state vector.
Definition: KTrack.h:54
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool isValid() const
Test if track is valid.
Definition: KTrack.cxx:81
Surface::TrackDirection trkf::KTrack::getDirection ( ) const
inherited

Track direction.

Track direction accessor. Track direction implied by track parameters has precedence over track direction attribute. If the surface pointer is null, return UNKNOWN.

Definition at line 64 of file KTrack.cxx.

References trkf::KTrack::fDir, trkf::KTrack::fSurf, trkf::KTrack::fVec, and trkf::Surface::UNKNOWN.

Referenced by trkf::KTrack::getMomentum(), trkf::KTrack::getVector(), trkf::KTrack::isValid(), trkf::Propagator::lin_prop(), trkf::InteractPlane::noise(), trkf::PropYZLine::origin_vec_prop(), trkf::PropYZPlane::origin_vec_prop(), trkf::PropXYZPlane::origin_vec_prop(), trkf::PropYZPlane::short_vec_prop(), and trkf::PropXYZPlane::short_vec_prop().

65  {
67  if (fSurf.get() != 0) result = fSurf->getDirection(fVec, fDir);
68  return result;
69  }
TrackVector fVec
Track state vector.
Definition: KTrack.h:91
TrackDirection
Track direction enum.
Definition: Surface.h:54
std::shared_ptr< const Surface > fSurf
Track surface.
Definition: KTrack.h:90
Surface::TrackDirection fDir
Track direction.
Definition: KTrack.h:92
TrackError& trkf::KETrack::getError ( )
inline

Modifiable error matrix.

Definition at line 57 of file KETrack.h.

References fErr.

void trkf::KTrack::getMomentum ( double  mom[3]) const
inherited

Get momentum vector of track.

Get momentum vector of track. Throw an exception if track is not valid.

Arguments:

mom - Momentum vector of track.

Definition at line 201 of file KTrack.cxx.

References dir, trkf::KTrack::fSurf, trkf::KTrack::fVec, trkf::KTrack::getDirection(), and trkf::KTrack::isValid().

Referenced by trkf::KGTrack::fillTrack(), trkf::InteractGeneral::noise(), trkf::KTrack::Print(), trkf::KGTrack::Print(), trkf::Track3DKalmanHitAlg::qualityCutsOnSeedTrack(), trkf::KTrack::setPdgCode(), trkf::Propagator::vec_prop(), trkf::KTrack::XLatitude(), and trkf::KTrack::XLongitude().

202  {
203  if (!isValid())
204  throw cet::exception("KTrack") << "Momentum vector requested for invalid track.\n";
206  fSurf->getMomentum(fVec, mom, dir);
207  }
TrackVector fVec
Track state vector.
Definition: KTrack.h:91
TrackDirection
Track direction enum.
Definition: Surface.h:54
std::shared_ptr< const Surface > fSurf
Track surface.
Definition: KTrack.h:90
TDirectory * dir
Definition: macro.C:5
Surface::TrackDirection getDirection() const
Track direction.
Definition: KTrack.cxx:64
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool isValid() const
Test if track is valid.
Definition: KTrack.cxx:81
void trkf::KTrack::getPosition ( double  xyz[3]) const
inherited

Get position of track.

Get position of track. Throw an exception if track is not valid.

Arguments:

xyz - Position vector.

Definition at line 157 of file KTrack.cxx.

References trkf::KTrack::fSurf, trkf::KTrack::fVec, and trkf::KTrack::isValid().

Referenced by trkf::KGTrack::fillTrack(), trkf::InteractGeneral::noise(), trkf::PropYZLine::origin_vec_prop(), trkf::PropXYZPlane::origin_vec_prop(), trkf::PropYZPlane::origin_vec_prop(), trkf::KTrack::Print(), trkf::KGTrack::Print(), trkf::KTrack::setPdgCode(), trkf::PropYZLine::short_vec_prop(), trkf::PropYZPlane::short_vec_prop(), trkf::PropXYZPlane::short_vec_prop(), and trkf::Propagator::vec_prop().

158  {
159  if (!isValid()) throw cet::exception("KTrack") << "Position requested for invalid track.\n";
160  fSurf->getPosition(fVec, xyz);
161  }
TrackVector fVec
Track state vector.
Definition: KTrack.h:91
std::shared_ptr< const Surface > fSurf
Track surface.
Definition: KTrack.h:90
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool isValid() const
Test if track is valid.
Definition: KTrack.cxx:81
TrackVector& trkf::KTrack::getVector ( )
inlineinherited

Modifiable state vector.

Definition at line 61 of file KTrack.h.

References trkf::KTrack::fVec.

bool trkf::KTrack::isValid ( ) const
inherited

Test if track is valid.

Test if track is valid.

A default-constructed or partially-constructed track, is invalid by virtue of having an unknown propagation direction or a null surface pointer.

Tracks can become invaliddynamically for other reasons. This method also does the following checks: a) Check for invalid floating point values (inf and nan). b) Surface-dependent checks via virtual method Surface::isTrackValid.

Definition at line 81 of file KTrack.cxx.

References trkf::KTrack::fSurf, trkf::KTrack::fVec, trkf::KTrack::getDirection(), geo::vect::isfinite(), and trkf::Surface::UNKNOWN.

Referenced by trkf::KGTrack::addTrack(), trkf::KalmanFilterAlg::buildTrack(), combineTrack(), trkf::KalmanFilterAlg::extendTrack(), trkf::KTrack::getMomentum(), trkf::KTrack::getPosition(), trkf::Propagator::lin_prop(), trkf::PropYZLine::origin_vec_prop(), trkf::PropXYZPlane::origin_vec_prop(), trkf::PropYZPlane::origin_vec_prop(), PointingError(), trkf::KTrack::setPdgCode(), and trkf::KalmanFilterAlg::smoothTrack().

82  {
83  bool result = true;
84 
85  // Check for valid direction.
86 
87  if (getDirection() == Surface::UNKNOWN) result = false;
88 
89  // Check for non-null surface pointer (for safety, should be redundant
90  // with previous check.
91 
92  if (result && fSurf.get() == 0) result = false;
93 
94  // Check for track parameters containing invalid floating point
95  // values.
96 
97  if (result) {
98  for (unsigned int i = 0; i < fVec.size(); ++i) {
99  if (!std::isfinite(fVec(i))) {
100  result = false;
101  break;
102  }
103  }
104  }
105 
106  // Surface-dependent check on track validity.
107 
108  if (result && !fSurf->isTrackValid(fVec)) result = false;
109 
110  // Done.
111 
112  return result;
113  }
TrackVector fVec
Track state vector.
Definition: KTrack.h:91
std::shared_ptr< const Surface > fSurf
Track surface.
Definition: KTrack.h:90
bool isfinite(Vector const &v)
Returns whether all components of the vector are finite.
Surface::TrackDirection getDirection() const
Track direction.
Definition: KTrack.cxx:64
double trkf::KTrack::Mass ( ) const
inherited

Based on pdg code.

Particle mass based on pdg code.

Definition at line 116 of file KTrack.cxx.

References util::abs(), and trkf::KTrack::fPdgCode.

Referenced by trkf::KalmanFilterAlg::fitMomentumMS(), trkf::InteractPlane::noise(), trkf::KTrack::PdgCode(), trkf::PropYZLine::short_vec_prop(), trkf::PropXYZPlane::short_vec_prop(), trkf::PropYZPlane::short_vec_prop(), and trkf::Propagator::vec_prop().

117  {
118  double mass = 0.;
119  int apdg = std::abs(fPdgCode);
120 
121  // Muon
122 
123  if (apdg == 13) mass = mumass;
124 
125  // Charged pion
126 
127  else if (apdg == 211)
128  mass = pimass;
129 
130  // Charged kaon
131 
132  else if (apdg == 321)
133  mass = kmass;
134 
135  // (Anti)proton
136 
137  else if (apdg == 2212)
138  mass = pmass;
139 
140  // Anything else throw exception
141 
142  else
143  throw cet::exception("KTrack") << "Mass requested for invalid pdg id = " << fPdgCode << "\n";
144 
145  // Done.
146 
147  return mass;
148  }
constexpr auto abs(T v)
Returns the absolute value of the argument.
int fPdgCode
Pdg id. hypothesis.
Definition: KTrack.h:93
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
int trkf::KTrack::PdgCode ( ) const
inlineinherited

Pdg code.

Definition at line 56 of file KTrack.h.

References trkf::KTrack::fPdgCode, and trkf::KTrack::Mass().

double trkf::KETrack::PointingError ( ) const

Pointing error (radians).

Calculate track pointing error (sigma, in radians).

This method calculates a single pointing error (sigma, in radians) based on the track parameters and error matrix. The actual calculation is done by the similarly names method of the surface class, since this class doesn't know what the track parameters mean.

Definition at line 66 of file KETrack.cxx.

References fErr, trkf::KTrack::getSurface(), trkf::KTrack::getVector(), and trkf::KTrack::isValid().

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

67  {
68  if (!isValid())
69  throw cet::exception("KETrack") << "Pointing error requested for invalid track.\n";
70  return getSurface()->PointingError(getVector(), fErr);
71  }
const std::shared_ptr< const Surface > & getSurface() const
Surface.
Definition: KTrack.h:53
const TrackVector & getVector() const
Track state vector.
Definition: KTrack.h:54
TrackError fErr
Track error matrix.
Definition: KETrack.h:69
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool isValid() const
Test if track is valid.
Definition: KTrack.cxx:81
std::ostream & trkf::KETrack::Print ( std::ostream &  out,
bool  doTitle = true 
) const
virtual

Printout.

Reimplemented from trkf::KTrack.

Reimplemented in trkf::KFitTrack, trkf::KHitsTrack, and trkf::KHitTrack.

Definition at line 179 of file KETrack.cxx.

References util::abs(), fErr, PointingError(), and trkf::KTrack::Print().

Referenced by trkf::KFitTrack::Print(), and setError().

180  {
181  if (doTitle) out << "KETrack:\n";
182 
183  // Print base class.
184 
185  KTrack::Print(out, false);
186 
187  // Print diagonal errors.
188 
189  out << " Diagonal errors:\n"
190  << " [";
191  for (unsigned int i = 0; i < fErr.size1(); ++i) {
192  if (i != 0) out << ", ";
193  double err = fErr(i, i);
194  err = (err >= 0. ? std::sqrt(err) : -std::sqrt(-err));
195  out << err;
196  }
197  out << "]\n";
198 
199  // Print correlations.
200 
201  out << " Correlation matrix:";
202  for (unsigned int i = 0; i < fErr.size1(); ++i) {
203  if (i == 0)
204  out << "\n [";
205  else
206  out << "\n ";
207  for (unsigned int j = 0; j <= i; ++j) {
208  if (j != 0) out << ", ";
209  if (i == j)
210  out << 1.;
211  else {
212  double eiijj = fErr(i, i) * fErr(j, j);
213  double eij = fErr(i, j);
214  if (eiijj != 0.)
215  eij /= std::sqrt(std::abs(eiijj));
216  else
217  eij = 0.;
218  out << eij;
219  }
220  }
221  }
222  out << "]\n";
223  out << " Pointing error = " << PointingError() << "\n";
224  return out;
225  }
double PointingError() const
Pointing error (radians).
Definition: KETrack.cxx:66
constexpr auto abs(T v)
Returns the absolute value of the argument.
STL namespace.
virtual std::ostream & Print(std::ostream &out, bool doTitle=true) const
Printout.
Definition: KTrack.cxx:210
TrackError fErr
Track error matrix.
Definition: KETrack.h:69
void trkf::KTrack::setDirection ( Surface::TrackDirection  dir)
inlineinherited
void trkf::KETrack::setError ( const TrackError err)
inline
void trkf::KTrack::setPdgCode ( int  pdg)
inlineinherited
void trkf::KTrack::setSurface ( const std::shared_ptr< const Surface > &  psurf)
inlineinherited
double trkf::KTrack::XLatitude ( ) const
inherited

Get x-latitude.

Get x-latitude.

The x-latitude is the latitude defined with respect to the x-axis. The x-latitude is zero of the track is traveling parallel to the wire planes.

Definition at line 169 of file KTrack.cxx.

References trkf::KTrack::getMomentum().

Referenced by trkf::KTrack::Print(), and trkf::KTrack::setPdgCode().

170  {
171  double mom[3];
172  getMomentum(mom);
173  double ptx = std::sqrt(mom[1] * mom[1] + mom[2] * mom[2]);
174  double result = 0.;
175  if (ptx > 0. || mom[0] > 0.) result = atan2(mom[0], ptx);
176  return result;
177  }
void getMomentum(double mom[3]) const
Get momentum vector of track.
Definition: KTrack.cxx:201
double trkf::KTrack::XLongitude ( ) const
inherited

Get x-longitude.

Get x-longitude.

The x-longitude is the longitude defined with respect to the y- and z-axes. The x-longitude is zero of the track is parallel to the z-axis in the yz-plane.

Definition at line 185 of file KTrack.cxx.

References trkf::KTrack::getMomentum().

Referenced by trkf::KTrack::Print(), and trkf::KTrack::setPdgCode().

186  {
187  double mom[3];
188  getMomentum(mom);
189  double result = 0.;
190  if (mom[1] != 0. || mom[2] != 0.) result = atan2(mom[1], mom[2]);
191  return result;
192  }
void getMomentum(double mom[3]) const
Get momentum vector of track.
Definition: KTrack.cxx:201

Member Data Documentation

TrackError trkf::KETrack::fErr
private

Track error matrix.

Definition at line 69 of file KETrack.h.

Referenced by getError(), PointingError(), Print(), and setError().


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