LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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...
 
boost::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.

19  {}
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 27 of file KETrack.cxx.

27  :
28  KTrack(psurf)
29  {}
KTrack()
Enum.
Definition: KTrack.cxx:28
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 41 of file KETrack.cxx.

45  :
46  KTrack(psurf, vec, dir, pdg),
47  fErr(err)
48  {}
KTrack()
Enum.
Definition: KTrack.cxx:28
TDirectory * dir
Definition: macro.C:5
TrackError fErr
Track error matrix.
Definition: KETrack.h:72
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 57 of file KETrack.cxx.

57  :
58  KTrack(trk),
59  fErr(err)
60  {}
KTrack()
Enum.
Definition: KTrack.cxx:28
TrackError fErr
Track error matrix.
Definition: KETrack.h:72
trkf::KETrack::~KETrack ( )
virtual

Destructor.

Definition at line 63 of file KETrack.cxx.

64  {}

Member Function Documentation

boost::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 95 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().

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

73  {
75  if(fSurf.get() != 0)
76  result = fSurf->getDirection(fVec, fDir);
77  return result;
78  }
TrackVector fVec
Track state vector.
Definition: KTrack.h:94
TrackDirection
Track direction enum.
Definition: Surface.h:56
std::shared_ptr< const Surface > fSurf
Track surface.
Definition: KTrack.h:93
Surface::TrackDirection fDir
Track direction.
Definition: KTrack.h:95
TrackError& trkf::KETrack::getError ( )
inline

Modifiable error matrix.

Definition at line 59 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 217 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().

218  {
219  if(!isValid())
220  throw cet::exception("KTrack") << "Momentum vector requested for invalid track.\n";
222  fSurf->getMomentum(fVec, mom, dir);
223  }
TrackVector fVec
Track state vector.
Definition: KTrack.h:94
TrackDirection
Track direction enum.
Definition: Surface.h:56
std::shared_ptr< const Surface > fSurf
Track surface.
Definition: KTrack.h:93
TDirectory * dir
Definition: macro.C:5
Surface::TrackDirection getDirection() const
Track direction.
Definition: KTrack.cxx:72
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool isValid() const
Test if track is valid.
Definition: KTrack.cxx:90
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 170 of file KTrack.cxx.

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

Referenced by trkf::KGTrack::fillTrack(), trkf::InteractGeneral::noise(), trkf::PropXYZPlane::origin_vec_prop(), trkf::PropYZLine::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().

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

Modifiable state vector.

Definition at line 63 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 90 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().

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

Based on pdg code.

Particle mass based on pdg code.

Definition at line 128 of file KTrack.cxx.

References 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().

129  {
130  double mass = 0.;
131  int apdg = std::abs(fPdgCode);
132 
133  // Muon
134 
135  if(apdg == 13)
136  mass = mumass;
137 
138  // Charged pion
139 
140  else if(apdg == 211)
141  mass = pimass;
142 
143  // Charged kaon
144 
145  else if(apdg == 321)
146  mass = kmass;
147 
148  // (Anti)proton
149 
150  else if(apdg == 2212)
151  mass = pmass;
152 
153  // Anything else throw exception
154 
155  else
156  throw cet::exception("KTrack") << "Mass requested for invalid pdg id = " << fPdgCode << "\n";
157 
158  // Done.
159 
160  return mass;
161  }
int fPdgCode
Pdg id. hypothesis.
Definition: KTrack.h:96
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
int trkf::KTrack::PdgCode ( ) const
inlineinherited

Pdg code.

Definition at line 58 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 74 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().

75  {
76  if(!isValid())
77  throw cet::exception("KETrack") << "Pointing error requested for invalid track.\n";
78  return getSurface()->PointingError(getVector(), fErr);
79  }
const std::shared_ptr< const Surface > & getSurface() const
Surface.
Definition: KTrack.h:55
const TrackVector & getVector() const
Track state vector.
Definition: KTrack.h:56
TrackError fErr
Track error matrix.
Definition: KETrack.h:72
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool isValid() const
Test if track is valid.
Definition: KTrack.cxx:90
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 188 of file KETrack.cxx.

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

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

189  {
190  if(doTitle)
191  out << "KETrack:\n";
192 
193  // Print base class.
194 
195  KTrack::Print(out, false);
196 
197  // Print diagonal errors.
198 
199  out << " Diagonal errors:\n"
200  << " [";
201  for(unsigned int i = 0; i < fErr.size1(); ++i) {
202  if(i != 0)
203  out << ", ";
204  double err = fErr(i,i);
205  err = (err >= 0. ? std::sqrt(err) : -std::sqrt(-err));
206  out << err;
207  }
208  out << "]\n";
209 
210  // Print correlations.
211 
212  out << " Correlation matrix:";
213  for(unsigned int i = 0; i < fErr.size1(); ++i) {
214  if(i == 0)
215  out << "\n [";
216  else
217  out << "\n ";
218  for(unsigned int j = 0; j <= i; ++j) {
219  if(j != 0)
220  out << ", ";
221  if(i == j)
222  out << 1.;
223  else {
224  double eiijj = fErr(i,i) * fErr(j,j);
225  double eij = fErr(i,j);
226  if(eiijj != 0.)
227  eij /= std::sqrt(std::abs(eiijj));
228  else
229  eij = 0.;
230  out << eij;
231  }
232  }
233  }
234  out << "]\n";
235  out << " Pointing error = " << PointingError() << "\n";
236  return out;
237  }
double PointingError() const
Pointing error (radians).
Definition: KETrack.cxx:74
STL namespace.
virtual std::ostream & Print(std::ostream &out, bool doTitle=true) const
Printout.
Definition: KTrack.cxx:226
TrackError fErr
Track error matrix.
Definition: KETrack.h:72
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 183 of file KTrack.cxx.

References trkf::KTrack::getMomentum().

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

184  {
185  double mom[3];
186  getMomentum(mom);
187  double ptx = std::sqrt(mom[1]*mom[1] + mom[2]*mom[2]);
188  double result = 0.;
189  if(ptx > 0. || mom[0] > 0.)
190  result = atan2(mom[0], ptx);
191  return result;
192  }
void getMomentum(double mom[3]) const
Get momentum vector of track.
Definition: KTrack.cxx:217
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 200 of file KTrack.cxx.

References trkf::KTrack::getMomentum().

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

201  {
202  double mom[3];
203  getMomentum(mom);
204  double result = 0.;
205  if(mom[1] != 0. || mom[2] != 0.)
206  result = atan2(mom[1], mom[2]);
207  return result;
208  }
void getMomentum(double mom[3]) const
Get momentum vector of track.
Definition: KTrack.cxx:217

Member Data Documentation

TrackError trkf::KETrack::fErr
private

Track error matrix.

Definition at line 72 of file KETrack.h.

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


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