Public Types | Public Member Functions | Private Attributes | List of all members
trkf::Propagator Class Referenceabstract

#include <Propagator.h>

Inheritance diagram for trkf::Propagator:
trkf::PropAny trkf::PropXYZPlane trkf::PropYZLine trkf::PropYZPlane

Public Types

enum  PropDirection { FORWARD, BACKWARD, UNKNOWN }
 Propagation direction enum. More...
 

Public Member Functions

 Propagator (detinfo::DetectorPropertiesData const &detProp, double tcut, bool doDedx, const std::shared_ptr< const Interactor > &interactor)
 Constructor. More...
 
virtual ~Propagator ()
 Destructor. More...
 
double getTcut () const
 
bool getDoDedx () const
 
const std::shared_ptr< const Interactor > & getInteractor () const
 
virtual Propagatorclone () const =0
 Clone method. More...
 
virtual std::optional< double > short_vec_prop (KTrack &trk, const std::shared_ptr< const Surface > &psurf, PropDirection dir, bool doDedx, TrackMatrix *prop_matrix=0, TrackError *noise_matrix=0) const =0
 Propagate without error (short distance). More...
 
virtual std::optional< double > origin_vec_prop (KTrack &trk, const std::shared_ptr< const Surface > &porient, TrackMatrix *prop_matrix=0) const =0
 Propagate without error to surface whose origin parameters coincide with track position. More...
 
std::optional< double > vec_prop (KTrack &trk, const std::shared_ptr< const Surface > &psurf, PropDirection dir, bool doDedx, TrackMatrix *prop_matrix=0, TrackError *noise_matrix=0) const
 Propagate without error (long distance). More...
 
std::optional< double > lin_prop (KTrack &trk, const std::shared_ptr< const Surface > &psurf, PropDirection dir, bool doDedx, KTrack *ref=0, TrackMatrix *prop_matrix=0, TrackError *noise_matrix=0) const
 Linearized propagate without error. More...
 
std::optional< double > err_prop (KETrack &tre, const std::shared_ptr< const Surface > &psurf, PropDirection dir, bool doDedx, KTrack *ref=0, TrackMatrix *prop_matrix=0) const
 Propagate with error, but without noise. More...
 
std::optional< double > noise_prop (KETrack &tre, const std::shared_ptr< const Surface > &psurf, PropDirection dir, bool doDedx, KTrack *ref=0) const
 Propagate with error and noise. More...
 
std::optional< double > dedx_prop (double pinv, double mass, double s, double *deriv=0) const
 Method to calculate updated momentum due to dE/dx. More...
 

Private Attributes

detinfo::DetectorPropertiesData const & fDetProp
 
double fTcut
 Maximum delta ray energy for dE/dx. More...
 
bool fDoDedx
 Energy loss enable flag. More...
 
std::shared_ptr< const InteractorfInteractor
 Interactor (for calculating noise). More...
 

Detailed Description

Definition at line 91 of file Propagator.h.

Member Enumeration Documentation

Propagation direction enum.

Enumerator
FORWARD 
BACKWARD 
UNKNOWN 

Definition at line 94 of file Propagator.h.

Constructor & Destructor Documentation

trkf::Propagator::Propagator ( detinfo::DetectorPropertiesData const &  detProp,
double  tcut,
bool  doDedx,
const std::shared_ptr< const Interactor > &  interactor 
)

Constructor.

Constructor.

Arguments:

tcut - Maximum delta ray energy. doDedx - dE/dx enable flag.

Definition at line 26 of file Propagator.cxx.

30  : fDetProp{detProp}, fTcut(tcut), fDoDedx(doDedx), fInteractor(interactor)
31  {}
double fTcut
Maximum delta ray energy for dE/dx.
Definition: Propagator.h:177
detinfo::DetectorPropertiesData const & fDetProp
Definition: Propagator.h:176
std::shared_ptr< const Interactor > fInteractor
Interactor (for calculating noise).
Definition: Propagator.h:179
bool fDoDedx
Energy loss enable flag.
Definition: Propagator.h:178
trkf::Propagator::~Propagator ( )
virtualdefault

Destructor.

Member Function Documentation

virtual Propagator* trkf::Propagator::clone ( ) const
pure virtual
std::optional< double > trkf::Propagator::dedx_prop ( double  pinv,
double  mass,
double  s,
double *  deriv = 0 
) const

Method to calculate updated momentum due to dE/dx.

Method to calculate updated momentum due to dE/dx.

Arguments:

pinv - Initial inverse momentum (units c/GeV). mass - Particle mass (GeV/c^2). s - Path distance. deriv - Pointer to store derivative d(pinv2)/d(pinv1) if nonzero.

Returns: Final inverse momentum (pinv2) + success flag.

Failure is returned in case of range out.

Inverse momentum can be signed (q/p). Returned inverse momentum has the same sign as the input.

In this method, we are solving the differential equation in terms of energy.

dE/dx = -f(E)

where f(E) is the stopping power returned by method LArProperties::Eloss.

We expect that this method will be called exclusively for short distance propagation. The differential equation is solved using the midpoint method using a single step, which requires two evaluations of f(E).

dE = -s*f(E1) E2 = E1 - s*f(E1 + 0.5*dE)

The derivative is calculated assuming E2 = E1 + constant, giving

d(pinv2)/d(pinv1) = pinv2^3 E2 / (pinv1^3 E1).

Definition at line 452 of file Propagator.cxx.

453  {
454  // For infinite initial momentum, return with success status,
455  // still infinite momentum.
456 
457  if (pinv == 0.) return std::make_optional(0.);
458 
459  // Set the default return value to be uninitialized with value 0.
460 
461  std::optional<double> result{std::nullopt};
462 
463  // Calculate final energy.
464 
465  double p1 = 1. / std::abs(pinv);
466  double e1 = std::hypot(p1, mass);
467  double de = -0.001 * s * fDetProp.Eloss(p1, mass, fTcut);
468  double emid = e1 + 0.5 * de;
469  if (emid > mass) {
470  double pmid = std::sqrt(emid * emid - mass * mass);
471  double e2 = e1 - 0.001 * s * fDetProp.Eloss(pmid, mass, fTcut);
472  if (e2 > mass) {
473  double p2 = std::sqrt(e2 * e2 - mass * mass);
474  double pinv2 = 1. / p2;
475  if (pinv < 0.) pinv2 = -pinv2;
476 
477  // Calculation was successful, update result.
478 
479  result = std::make_optional(pinv2);
480 
481  // Also calculate derivative, if requested.
482 
483  if (deriv != 0) *deriv = pinv2 * pinv2 * pinv2 * e2 / (pinv * pinv * pinv * e1);
484  }
485  }
486 
487  // Done.
488 
489  return result;
490  }
static QCString result
double fTcut
Maximum delta ray energy for dE/dx.
Definition: Propagator.h:177
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
Definition: hypot.h:60
detinfo::DetectorPropertiesData const & fDetProp
Definition: Propagator.h:176
T abs(T value)
double Eloss(double mom, double mass, double tcut) const
Restricted mean energy loss (dE/dx)
static QCString * s
Definition: config.cpp:1042
std::optional< double > trkf::Propagator::err_prop ( KETrack tre,
const std::shared_ptr< const Surface > &  psurf,
PropDirection  dir,
bool  doDedx,
KTrack ref = 0,
TrackMatrix prop_matrix = 0 
) const

Propagate with error, but without noise.

Propagate with error, but without noise (i.e. reversibly).

Arguments:

tre - Track to propagate. psurf - Destination surface. dir - Propagation direction (FORWARD, BACKWARD, or UNKNOWN). doDedx - dE/dx enable/disable flag. ref - Reference track (for linearized propagation). Can be null. prop_matrix - Return propagation matrix if not null.

Returned value: propagation distance + success flag.

Definition at line 346 of file Propagator.cxx.

352  {
353  // Propagate without error, get propagation matrix.
354 
355  TrackMatrix prop_temp;
356  if (prop_matrix == 0) prop_matrix = &prop_temp;
357  std::optional<double> result = lin_prop(tre, psurf, dir, doDedx, ref, prop_matrix, 0);
358 
359  // If propagation succeeded, update track error matrix.
360 
361  if (!!result) {
362  TrackMatrix temp = prod(tre.getError(), trans(*prop_matrix));
363  TrackMatrix temp2 = prod(*prop_matrix, temp);
364  TrackError newerr = ublas::symmetric_adaptor<TrackMatrix>(temp2);
365  tre.setError(newerr);
366  }
367 
368  // Done.
369 
370  return result;
371  }
static QCString result
KSymMatrix< 5 >::type TrackError
Track error matrix, dimension 5x5.
string dir
std::optional< double > lin_prop(KTrack &trk, const std::shared_ptr< const Surface > &psurf, PropDirection dir, bool doDedx, KTrack *ref=0, TrackMatrix *prop_matrix=0, TrackError *noise_matrix=0) const
Linearized propagate without error.
Definition: Propagator.cxx:251
KMatrix< 5, 5 >::type TrackMatrix
General 5x5 matrix.
bool trkf::Propagator::getDoDedx ( ) const
inline

Definition at line 113 of file Propagator.h.

114  {
115  return fDoDedx;
116  }
bool fDoDedx
Energy loss enable flag.
Definition: Propagator.h:178
const std::shared_ptr<const Interactor>& trkf::Propagator::getInteractor ( ) const
inline

Definition at line 118 of file Propagator.h.

119  {
120  return fInteractor;
121  }
std::shared_ptr< const Interactor > fInteractor
Interactor (for calculating noise).
Definition: Propagator.h:179
double trkf::Propagator::getTcut ( ) const
inline

Definition at line 108 of file Propagator.h.

109  {
110  return fTcut;
111  }
double fTcut
Maximum delta ray energy for dE/dx.
Definition: Propagator.h:177
std::optional< double > trkf::Propagator::lin_prop ( KTrack trk,
const std::shared_ptr< const Surface > &  psurf,
PropDirection  dir,
bool  doDedx,
KTrack ref = 0,
TrackMatrix prop_matrix = 0,
TrackError noise_matrix = 0 
) const

Linearized propagate without error.

Linearized propagate without error.

Arguments:

trk - Track to propagate. psurf - Destination surface. dir - Propagation direction (FORWARD, BACKWARD, or UNKNOWN). doDedx - dE/dx enable/disable flag. ref - Reference track (for linearized propagation). Can be null. prop_matrix - Return propagation matrix if not null. noise_matrix - Return noise matrix if not null.

Returned value: Propagation distance & success flag.

If the reference track is null, this method simply calls vec_prop.

Definition at line 251 of file Propagator.cxx.

258  {
259  // Default result.
260 
261  std::optional<double> result;
262 
263  if (ref == 0)
264  result = vec_prop(trk, psurf, dir, doDedx, prop_matrix, noise_matrix);
265  else {
266 
267  // A reference track has been provided.
268 
269  // It is an error (throw exception) if the reference track and
270  // the track to be propagted are not on the same surface.
271 
272  if (!trk.getSurface()->isEqual(*(ref->getSurface())))
273  throw cet::exception("Propagator")
274  << "Input track and reference track not on same surface.\n";
275 
276  // Remember the starting track and reference track.
277 
278  KTrack trk0(trk);
279  KTrack ref0(*ref);
280 
281  // Propagate the reference track. Make sure we calculate the
282  // propagation matrix.
283 
284  TrackMatrix prop_temp;
285  if (prop_matrix == 0) prop_matrix = &prop_temp;
286 
287  // Do the propgation. The returned result will be the result of
288  // this propagatrion.
289 
290  result = vec_prop(*ref, psurf, dir, doDedx, prop_matrix, noise_matrix);
291  if (!!result) {
292 
293  // Propagation of reference track succeeded. Update the track
294  // state vector and surface of the track to be propagated.
295 
296  TrackVector diff = trk.getSurface()->getDiff(trk.getVector(), ref0.getVector());
297  TrackVector newvec = ref->getVector() + prod(*prop_matrix, diff);
298 
299  // Store updated state vector and surface.
300 
301  trk.setVector(newvec);
302  trk.setSurface(psurf);
303  trk.setDirection(ref->getDirection());
304  if (!trk.getSurface()->isEqual(*(ref->getSurface())))
305  throw cet::exception("Propagator") << __func__ << ": surface mismatch";
306 
307  // Final validity check. In case of failure, restore the track
308  // and reference track to their starting values.
309 
310  if (!trk.isValid()) {
311  result = std::nullopt;
312  trk = trk0;
313  *ref = ref0;
314  }
315  }
316  else {
317 
318  // Propagation failed.
319  // Restore the reference track to its starting value, so that we ensure
320  // the reference track and the actual track remain on the same surface.
321 
322  trk = trk0;
323  *ref = ref0;
324  }
325  }
326 
327  // Done.
328 
329  return result;
330  }
static QCString result
string dir
std::optional< double > vec_prop(KTrack &trk, const std::shared_ptr< const Surface > &psurf, PropDirection dir, bool doDedx, TrackMatrix *prop_matrix=0, TrackError *noise_matrix=0) const
Propagate without error (long distance).
Definition: Propagator.cxx:53
KVector< 5 >::type TrackVector
Track state vector, dimension 5.
KMatrix< 5, 5 >::type TrackMatrix
General 5x5 matrix.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::optional< double > trkf::Propagator::noise_prop ( KETrack tre,
const std::shared_ptr< const Surface > &  psurf,
PropDirection  dir,
bool  doDedx,
KTrack ref = 0 
) const

Propagate with error and noise.

Propagate with error and noise.

Arguments:

tre - Track to propagate. psurf - Destination surface. dir - Propagation direction (FORWARD, BACKWARD, or UNKNOWN). doDedx - dE/dx enable/disable flag. ref - Reference track (for linearized propagation). Can be null.

Returned value: propagation distance + success flag.

Definition at line 386 of file Propagator.cxx.

391  {
392  // Propagate without error, get propagation matrix and noise matrix.
393 
394  TrackMatrix prop_matrix;
395  TrackError noise_matrix;
396  std::optional<double> result =
397  lin_prop(tre, psurf, dir, doDedx, ref, &prop_matrix, &noise_matrix);
398 
399  // If propagation succeeded, update track error matrix.
400 
401  if (!!result) {
402  TrackMatrix temp = prod(tre.getError(), trans(prop_matrix));
403  TrackMatrix temp2 = prod(prop_matrix, temp);
404  TrackError newerr = ublas::symmetric_adaptor<TrackMatrix>(temp2);
405  newerr += noise_matrix;
406  tre.setError(newerr);
407  }
408 
409  // Done.
410 
411  return result;
412  }
static QCString result
KSymMatrix< 5 >::type TrackError
Track error matrix, dimension 5x5.
string dir
std::optional< double > lin_prop(KTrack &trk, const std::shared_ptr< const Surface > &psurf, PropDirection dir, bool doDedx, KTrack *ref=0, TrackMatrix *prop_matrix=0, TrackError *noise_matrix=0) const
Linearized propagate without error.
Definition: Propagator.cxx:251
KMatrix< 5, 5 >::type TrackMatrix
General 5x5 matrix.
virtual std::optional<double> trkf::Propagator::origin_vec_prop ( KTrack trk,
const std::shared_ptr< const Surface > &  porient,
TrackMatrix prop_matrix = 0 
) const
pure virtual

Propagate without error to surface whose origin parameters coincide with track position.

Implemented in trkf::PropAny, trkf::PropXYZPlane, trkf::PropYZPlane, and trkf::PropYZLine.

virtual std::optional<double> trkf::Propagator::short_vec_prop ( KTrack trk,
const std::shared_ptr< const Surface > &  psurf,
PropDirection  dir,
bool  doDedx,
TrackMatrix prop_matrix = 0,
TrackError noise_matrix = 0 
) const
pure virtual

Propagate without error (short distance).

Implemented in trkf::PropAny, trkf::PropXYZPlane, trkf::PropYZPlane, and trkf::PropYZLine.

std::optional< double > trkf::Propagator::vec_prop ( KTrack trk,
const std::shared_ptr< const Surface > &  psurf,
PropDirection  dir,
bool  doDedx,
TrackMatrix prop_matrix = 0,
TrackError noise_matrix = 0 
) const

Propagate without error (long distance).

Propagate without error (long distance).

Arguments:

trk - Track to propagate. psurf - Destination surface. dir - Propagation direction (FORWARD, BACKWARD, or UNKNOWN). doDedx - dE/dx enable/disable flag. prop_matrix - Return propagation matrix if not null. noise_matrix - Return noise matrix if not null.

Returned value: Propagation distance & success flag.

This method calls virtual method short_vec_prop in steps of some maximum size.

Definition at line 53 of file Propagator.cxx.

59  {
60  std::optional<double> result{std::nullopt};
61 
62  // Get the inverse momentum (assumed to be track parameter four).
63 
64  double pinv = trk.getVector()(4);
65 
66  // If dE/dx is not requested, or if inverse momentum is zero, then
67  // it is safe to propagate in one step. In this case, just pass
68  // the call to short_vec_prop with unlimited distance.
69 
70  bool dedx = getDoDedx() && doDedx;
71  if (!dedx || pinv == 0.)
72  result = short_vec_prop(trk, psurf, dir, dedx, prop_matrix, noise_matrix);
73 
74  else {
75 
76  // dE/dx is requested. In this case we limit the maximum
77  // propagation distance such that the kinetic energy of the
78  // particle should not change by more thatn 10%.
79 
80  // Initialize propagation matrix to unit matrix (if specified).
81 
82  int nvec = trk.getVector().size();
83  if (prop_matrix) *prop_matrix = ublas::identity_matrix<TrackVector::value_type>(nvec);
84 
85  // Initialize noise matrix to zero matrix (if specified).
86 
87  if (noise_matrix) {
88  noise_matrix->resize(nvec, nvec, false);
89  noise_matrix->clear();
90  }
91 
92  // Remember the starting track.
93 
94  KTrack trk0(trk);
95 
96  // Make pointer variables pointing to local versions of the
97  // propagation and noise matrices, or null if not specified.
98 
99  TrackMatrix local_prop_matrix;
100  TrackMatrix* plocal_prop_matrix = (prop_matrix == 0 ? 0 : &local_prop_matrix);
101  TrackError local_noise_matrix;
102  TrackError* plocal_noise_matrix = (noise_matrix == 0 ? 0 : &local_noise_matrix);
103 
104  // Cumulative propagation distance.
105 
106  double s = 0.;
107 
108  // Begin stepping loop.
109  // We put a maximum iteration count to prevent infinite loops caused by
110  // floating point pathologies. The iteration count is large enough to reach
111  // any point in the tpc using the minimum step size (for a reasonable tpc).
112 
113  bool done = false;
114  int nitmax = 10000; // Maximum number of iterations.
115  int nit = 0; // Iteration count.
116  while (!done) {
117 
118  // If the iteration count exceeds the maximum, return failure.
119 
120  ++nit;
121  if (nit > nitmax) {
122  trk = trk0;
123  result = std::nullopt;
124  return result;
125  }
126 
127  // Estimate maximum step distance according to the above
128  // stated principle.
129 
130  pinv = trk.getVector()(4);
131  double mass = trk.Mass();
132  double p = 1. / std::abs(pinv);
133  double e = std::hypot(p, mass);
134  double t = p * p / (e + mass);
135  double dedx = 0.001 * fDetProp.Eloss(p, mass, fTcut);
136  double smax = 0.1 * t / dedx;
137  if (smax <= 0.)
138  throw cet::exception("Propagator") << __func__ << ": maximum step " << smax << "\n";
139 
140  // Always allow a step of at least 0.3 cm (about one wire spacing).
141 
142  if (smax < 0.3) smax = 0.3;
143 
144  // First do a test propagation (without dE/dx and errors) to
145  // find the distance to the destination surface.
146 
147  KTrack trktest(trk);
148  std::optional<double> dist = short_vec_prop(trktest, psurf, dir, false, 0, 0);
149 
150  // If the test propagation failed, return failure.
151 
152  if (!dist) {
153  trk = trk0;
154  return dist;
155  }
156 
157  // Generate destionation surface for this step (either final
158  // destination, or some intermediate surface).
159 
160  std::shared_ptr<const Surface> pstep;
161  if (std::abs(*dist) <= smax) {
162  done = true;
163  pstep = psurf;
164  }
165  else {
166 
167  // Generate intermediate surface.
168  // First get point where track will intersect intermediate surface.
169 
170  double xyz0[3]; // Starting point.
171  trk.getPosition(xyz0);
172  double xyz1[3]; // Destination point.
173  trktest.getPosition(xyz1);
174  double frac = smax / std::abs(*dist);
175  double xyz[3]; // Intermediate point.
176  xyz[0] = xyz0[0] + frac * (xyz1[0] - xyz0[0]);
177  xyz[1] = xyz0[1] + frac * (xyz1[1] - xyz0[1]);
178  xyz[2] = xyz0[2] + frac * (xyz1[2] - xyz0[2]);
179 
180  // Choose orientation of intermediate surface perpendicular
181  // to track.
182 
183  double mom[3];
184  trk.getMomentum(mom);
185 
186  // Make intermediate surface object.
187 
188  pstep = std::shared_ptr<const Surface>(
189  new SurfXYZPlane(xyz[0], xyz[1], xyz[2], mom[0], mom[1], mom[2]));
190  }
191 
192  // Do the actual step propagation.
193 
194  dist = short_vec_prop(trk, pstep, dir, doDedx, plocal_prop_matrix, plocal_noise_matrix);
195 
196  // If the step propagation failed, return failure.
197 
198  if (!dist) {
199  trk = trk0;
200  return dist;
201  }
202 
203  // Update cumulative propagation distance.
204 
205  s += *dist;
206 
207  // Update cumulative propagation matrix (left-multiply).
208 
209  if (prop_matrix != 0) {
210  TrackMatrix temp = prod(*plocal_prop_matrix, *prop_matrix);
211  *prop_matrix = temp;
212  }
213 
214  // Update cumulative noise matrix.
215 
216  if (noise_matrix != 0) {
217  TrackMatrix temp = prod(*noise_matrix, trans(*plocal_prop_matrix));
218  TrackMatrix temp2 = prod(*plocal_prop_matrix, temp);
219  *noise_matrix = ublas::symmetric_adaptor<TrackMatrix>(temp2);
220  *noise_matrix += *plocal_noise_matrix;
221  }
222  }
223 
224  // Set the final result (distance + success).
225 
226  result = std::make_optional(s);
227  }
228 
229  // Done.
230 
231  return result;
232  }
static QCString result
KSymMatrix< 5 >::type TrackError
Track error matrix, dimension 5x5.
double fTcut
Maximum delta ray energy for dE/dx.
Definition: Propagator.h:177
string dir
virtual std::optional< double > short_vec_prop(KTrack &trk, const std::shared_ptr< const Surface > &psurf, PropDirection dir, bool doDedx, TrackMatrix *prop_matrix=0, TrackError *noise_matrix=0) const =0
Propagate without error (short distance).
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
Definition: hypot.h:60
detinfo::DetectorPropertiesData const & fDetProp
Definition: Propagator.h:176
T abs(T value)
const double e
p
Definition: test.py:223
double Eloss(double mom, double mass, double tcut) const
Restricted mean energy loss (dE/dx)
bool getDoDedx() const
Definition: Propagator.h:113
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
KMatrix< 5, 5 >::type TrackMatrix
General 5x5 matrix.
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Data Documentation

detinfo::DetectorPropertiesData const& trkf::Propagator::fDetProp
private

Definition at line 176 of file Propagator.h.

bool trkf::Propagator::fDoDedx
private

Energy loss enable flag.

Definition at line 178 of file Propagator.h.

std::shared_ptr<const Interactor> trkf::Propagator::fInteractor
private

Interactor (for calculating noise).

Definition at line 179 of file Propagator.h.

double trkf::Propagator::fTcut
private

Maximum delta ray energy for dE/dx.

Definition at line 177 of file Propagator.h.


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