Public Member Functions | Private Attributes | List of all members
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...
 
- Public Member Functions inherited from trkf::KTrack
 KTrack ()
 Enum. More...
 
 KTrack (const std::shared_ptr< const Surface > &psurf)
 Constructor - specify surface only. More...
 
 KTrack (std::shared_ptr< const Surface > psurf, const TrackVector &vec, Surface::TrackDirection dir=Surface::UNKNOWN, int pdg=0)
 Constructor - surface + track parameters. More...
 
virtual ~KTrack ()
 Destructor. More...
 
const std::shared_ptr< const Surface > & getSurface () const
 Surface. More...
 
const TrackVectorgetVector () const
 Track state vector. More...
 
Surface::TrackDirection getDirection () const
 Track direction. More...
 
int PdgCode () const
 Pdg code. More...
 
double Mass () const
 Based on pdg code. More...
 
TrackVectorgetVector ()
 Modifiable state vector. 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  {}
string dir
KTrack()
Enum.
Definition: KTrack.cxx:29
void err(const char *fmt,...)
Definition: message.cpp:226
TrackError fErr
Track error matrix.
Definition: KETrack.h:81
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
void err(const char *fmt,...)
Definition: message.cpp:226
TrackError fErr
Track error matrix.
Definition: KETrack.h:81
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 89 of file KETrack.cxx.

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

Track error matrix.

Definition at line 53 of file KETrack.h.

TrackError& trkf::KETrack::getError ( )
inline

Modifiable error matrix.

Definition at line 62 of file KETrack.h.

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 67 of file KETrack.cxx.

68  {
69  if (!isValid())
70  throw cet::exception("KETrack") << "Pointing error requested for invalid track.\n";
71  return getSurface()->PointingError(getVector(), fErr);
72  }
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:81
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool isValid() const
Test if track is valid.
Definition: KTrack.cxx:91
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 182 of file KETrack.cxx.

183  {
184  if (doTitle) out << "KETrack:\n";
185 
186  // Print base class.
187 
188  KTrack::Print(out, false);
189 
190  // Print diagonal errors.
191 
192  out << " Diagonal errors:\n"
193  << " [";
194  for (unsigned int i = 0; i < fErr.size1(); ++i) {
195  if (i != 0) out << ", ";
196  double err = fErr(i, i);
197  err = (err >= 0. ? std::sqrt(err) : -std::sqrt(-err));
198  out << err;
199  }
200  out << "]\n";
201 
202  // Print correlations.
203 
204  out << " Correlation matrix:";
205  for (unsigned int i = 0; i < fErr.size1(); ++i) {
206  if (i == 0)
207  out << "\n [";
208  else
209  out << "\n ";
210  for (unsigned int j = 0; j <= i; ++j) {
211  if (j != 0) out << ", ";
212  if (i == j)
213  out << 1.;
214  else {
215  double eiijj = fErr(i, i) * fErr(j, j);
216  double eij = fErr(i, j);
217  if (eiijj != 0.)
218  eij /= std::sqrt(std::abs(eiijj));
219  else
220  eij = 0.;
221  out << eij;
222  }
223  }
224  }
225  out << "]\n";
226  out << " Pointing error = " << PointingError() << "\n";
227  return out;
228  }
double PointingError() const
Pointing error (radians).
Definition: KETrack.cxx:67
STL namespace.
T abs(T value)
virtual std::ostream & Print(std::ostream &out, bool doTitle=true) const
Printout.
Definition: KTrack.cxx:227
void err(const char *fmt,...)
Definition: message.cpp:226
TrackError fErr
Track error matrix.
Definition: KETrack.h:81
void trkf::KETrack::setError ( const TrackError err)
inline

Set error matrix.

Definition at line 67 of file KETrack.h.

Member Data Documentation

TrackError trkf::KETrack::fErr
private

Track error matrix.

Definition at line 81 of file KETrack.h.


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