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

#include "PropAny.h"

Inheritance diagram for trkf::PropAny:
trkf::Propagator

Public Types

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

Public Member Functions

 PropAny (detinfo::DetectorPropertiesData const &detProp, double tcut, bool doDedx)
 Constructor. More...
 
Propagatorclone () const override
 Clone method. More...
 
std::optional< double > short_vec_prop (KTrack &trk, const std::shared_ptr< const Surface > &surf, Propagator::PropDirection dir, bool doDedx, TrackMatrix *prop_matrix=0, TrackError *noise_matrix=0) const override
 Propagate without error. More...
 
virtual std::optional< double > origin_vec_prop (KTrack &trk, const std::shared_ptr< const Surface > &porient, TrackMatrix *prop_matrix=0) const override
 Propagate without error to surface whose origin parameters coincide with track position. More...
 
double getTcut () const
 
bool getDoDedx () const
 
const std::shared_ptr< const Interactor > & getInteractor () const
 
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

PropYZLine fPropYZLine
 Underlying propagators. More...
 
PropYZPlane fPropYZPlane
 
PropXYZPlane fPropXYZPlane
 

Detailed Description

Definition at line 25 of file PropAny.h.

Member Enumeration Documentation

Propagation direction enum.

Enumerator
FORWARD 
BACKWARD 
UNKNOWN 

Definition at line 94 of file Propagator.h.

Constructor & Destructor Documentation

trkf::PropAny::PropAny ( detinfo::DetectorPropertiesData const &  detProp,
double  tcut,
bool  doDedx 
)

Constructor.

Constructor.

Arguments.

tcut - Delta ray energy cutoff for calculating dE/dx. doDedx - dE/dx enable flag.

Definition at line 27 of file PropAny.cxx.

References fPropXYZPlane, fPropYZLine, and fPropYZPlane.

Referenced by clone().

28  : Propagator(detProp,
29  tcut,
30  doDedx,
31  (tcut >= 0 ? std::make_shared<InteractPlane const>(detProp, tcut) :
32  std::shared_ptr<Interactor const>{}))
33  , fPropYZLine(detProp, tcut, doDedx)
34  , fPropYZPlane(detProp, tcut, doDedx)
35  , fPropXYZPlane(detProp, tcut, doDedx)
36  {}
PropYZPlane fPropYZPlane
Definition: PropAny.h:49
PropYZLine fPropYZLine
Underlying propagators.
Definition: PropAny.h:48
PropXYZPlane fPropXYZPlane
Definition: PropAny.h:50
Propagator(detinfo::DetectorPropertiesData const &detProp, double tcut, bool doDedx, const std::shared_ptr< const Interactor > &interactor)
Constructor.
Definition: Propagator.cxx:26

Member Function Documentation

Propagator* trkf::PropAny::clone ( ) const
inlineoverridevirtual

Clone method.

Implements trkf::Propagator.

Definition at line 30 of file PropAny.h.

References dir, origin_vec_prop(), PropAny(), and short_vec_prop().

30 { return new PropAny(*this); }
PropAny(detinfo::DetectorPropertiesData const &detProp, double tcut, bool doDedx)
Constructor.
Definition: PropAny.cxx:27
std::optional< double > trkf::Propagator::dedx_prop ( double  pinv,
double  mass,
double  s,
double *  deriv = 0 
) const
inherited

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 447 of file Propagator.cxx.

References util::abs(), detinfo::DetectorPropertiesData::Eloss(), trkf::Propagator::fDetProp, and trkf::Propagator::fTcut.

Referenced by trkf::PropYZLine::short_vec_prop(), trkf::PropXYZPlane::short_vec_prop(), and trkf::PropYZPlane::short_vec_prop().

451  {
452  // For infinite initial momentum, return with success status,
453  // still infinite momentum.
454 
455  if (pinv == 0.) return std::make_optional(0.);
456 
457  // Set the default return value to be uninitialized with value 0.
458 
459  std::optional<double> result{std::nullopt};
460 
461  // Calculate final energy.
462 
463  double p1 = 1. / std::abs(pinv);
464  double e1 = std::hypot(p1, mass);
465  double de = -0.001 * s * fDetProp.Eloss(p1, mass, fTcut);
466  double emid = e1 + 0.5 * de;
467  if (emid > mass) {
468  double pmid = std::sqrt(emid * emid - mass * mass);
469  double e2 = e1 - 0.001 * s * fDetProp.Eloss(pmid, mass, fTcut);
470  if (e2 > mass) {
471  double p2 = std::sqrt(e2 * e2 - mass * mass);
472  double pinv2 = 1. / p2;
473  if (pinv < 0.) pinv2 = -pinv2;
474 
475  // Calculation was successful, update result.
476 
477  result = std::make_optional(pinv2);
478 
479  // Also calculate derivative, if requested.
480 
481  if (deriv != 0) *deriv = pinv2 * pinv2 * pinv2 * e2 / (pinv * pinv * pinv * e1);
482  }
483  }
484 
485  // Done.
486 
487  return result;
488  }
constexpr auto abs(T v)
Returns the absolute value of the argument.
double fTcut
Maximum delta ray energy for dE/dx.
Definition: Propagator.h:165
detinfo::DetectorPropertiesData const & fDetProp
Definition: Propagator.h:164
double Eloss(double mom, double mass, double tcut) const
Restricted mean energy loss (dE/dx)
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
inherited

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 343 of file Propagator.cxx.

References trkf::KETrack::getError(), trkf::Propagator::lin_prop(), and trkf::KETrack::setError().

Referenced by trkf::KGTrack::fillTrack(), trkf::KalmanFilterAlg::fitMomentumMS(), and trkf::KHit< N >::predict().

349  {
350  // Propagate without error, get propagation matrix.
351 
352  TrackMatrix prop_temp;
353  if (prop_matrix == 0) prop_matrix = &prop_temp;
354  std::optional<double> result = lin_prop(tre, psurf, dir, doDedx, ref, prop_matrix, 0);
355 
356  // If propagation succeeded, update track error matrix.
357 
358  if (!!result) {
359  TrackMatrix temp = prod(tre.getError(), trans(*prop_matrix));
360  TrackMatrix temp2 = prod(*prop_matrix, temp);
361  TrackError newerr = ublas::symmetric_adaptor<TrackMatrix>(temp2);
362  tre.setError(newerr);
363  }
364 
365  // Done.
366 
367  return result;
368  }
KSymMatrix< 5 >::type TrackError
Track error matrix, dimension 5x5.
KMatrix< 5, 5 >::type TrackMatrix
General 5x5 matrix.
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:249
TDirectory * dir
Definition: macro.C:5
bool trkf::Propagator::getDoDedx ( ) const
inlineinherited
const std::shared_ptr<const Interactor>& trkf::Propagator::getInteractor ( ) const
inlineinherited

Definition at line 109 of file Propagator.h.

References dir.

Referenced by trkf::PropYZLine::short_vec_prop(), trkf::PropXYZPlane::short_vec_prop(), and trkf::PropYZPlane::short_vec_prop().

109 { return fInteractor; }
std::shared_ptr< const Interactor > fInteractor
Interactor (for calculating noise).
Definition: Propagator.h:167
double trkf::Propagator::getTcut ( ) const
inlineinherited

Definition at line 107 of file Propagator.h.

107 { return fTcut; }
double fTcut
Maximum delta ray energy for dE/dx.
Definition: Propagator.h:165
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
inherited

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 249 of file Propagator.cxx.

References trkf::KTrack::getDirection(), trkf::KTrack::getSurface(), trkf::KTrack::getVector(), trkf::KTrack::isValid(), trkf::KTrack::setDirection(), trkf::KTrack::setSurface(), trkf::KTrack::setVector(), and trkf::Propagator::vec_prop().

Referenced by trkf::Propagator::err_prop(), and trkf::Propagator::noise_prop().

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

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 382 of file Propagator.cxx.

References trkf::KETrack::getError(), trkf::Propagator::lin_prop(), and trkf::KETrack::setError().

Referenced by trkf::KalmanFilterAlg::buildTrack(), trkf::KalmanFilterAlg::extendTrack(), trkf::KalmanFilterAlg::fitMomentumMS(), trkf::KalmanFilterAlg::smoothTrack(), and trkf::KalmanFilterAlg::updateMomentum().

387  {
388  // Propagate without error, get propagation matrix and noise matrix.
389 
390  TrackMatrix prop_matrix;
391  TrackError noise_matrix;
392  std::optional<double> result =
393  lin_prop(tre, psurf, dir, doDedx, ref, &prop_matrix, &noise_matrix);
394 
395  // If propagation succeeded, update track error matrix.
396 
397  if (!!result) {
398  TrackMatrix temp = prod(tre.getError(), trans(prop_matrix));
399  TrackMatrix temp2 = prod(prop_matrix, temp);
400  TrackError newerr = ublas::symmetric_adaptor<TrackMatrix>(temp2);
401  newerr += noise_matrix;
402  tre.setError(newerr);
403  }
404 
405  // Done.
406 
407  return result;
408  }
KSymMatrix< 5 >::type TrackError
Track error matrix, dimension 5x5.
KMatrix< 5, 5 >::type TrackMatrix
General 5x5 matrix.
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:249
TDirectory * dir
Definition: macro.C:5
std::optional< double > trkf::PropAny::origin_vec_prop ( KTrack trk,
const std::shared_ptr< const Surface > &  porient,
TrackMatrix prop_matrix = 0 
) const
overridevirtual

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

Propagate without error to dynamically generated origin surface. Optionally return propagation matrix.

Arguments:

trk - Track to propagate. porient - Orientation surface. prop_matrix - Pointer to optional propagation matrix.

Returned value: propagation distance + success flag.

Propagation distance is always zero after successful propagation.

Implements trkf::Propagator.

Definition at line 94 of file PropAny.cxx.

References fPropXYZPlane, fPropYZLine, fPropYZPlane, trkf::PropYZLine::origin_vec_prop(), trkf::PropXYZPlane::origin_vec_prop(), and trkf::PropYZPlane::origin_vec_prop().

Referenced by clone().

97  {
98  // Default result.
99 
100  std::optional<double> result{std::nullopt};
101 
102  // Test the type of the destination surface.
103 
104  if (dynamic_cast<const SurfYZLine*>(&*porient))
105  result = fPropYZLine.origin_vec_prop(trk, porient, prop_matrix);
106  else if (dynamic_cast<const SurfYZPlane*>(&*porient))
107  result = fPropYZPlane.origin_vec_prop(trk, porient, prop_matrix);
108  else if (dynamic_cast<const SurfXYZPlane*>(&*porient))
109  result = fPropXYZPlane.origin_vec_prop(trk, porient, prop_matrix);
110  else
111  throw cet::exception("PropAny") << "Destination surface has unknown type.\n";
112 
113  // Done.
114 
115  return result;
116  }
std::optional< double > origin_vec_prop(KTrack &trk, const std::shared_ptr< const Surface > &porient, TrackMatrix *prop_matrix=0) const override
Propagate without error to surface whose origin parameters coincide with track position.
Definition: PropYZLine.cxx:265
std::optional< double > origin_vec_prop(KTrack &trk, const std::shared_ptr< const Surface > &porient, TrackMatrix *prop_matrix=0) const override
Propagate without error to surface whose origin parameters coincide with track position.
PropYZPlane fPropYZPlane
Definition: PropAny.h:49
PropYZLine fPropYZLine
Underlying propagators.
Definition: PropAny.h:48
PropXYZPlane fPropXYZPlane
Definition: PropAny.h:50
std::optional< double > origin_vec_prop(KTrack &trk, const std::shared_ptr< const Surface > &porient, TrackMatrix *prop_matrix=0) const override
Propagate without error to surface whose origin parameters coincide with track position.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::optional< double > trkf::PropAny::short_vec_prop ( KTrack trk,
const std::shared_ptr< const Surface > &  psurf,
Propagator::PropDirection  dir,
bool  doDedx,
TrackMatrix prop_matrix = 0,
TrackError noise_matrix = 0 
) const
overridevirtual

Propagate without error.

Propagate without error. Optionally return propagation matrix and noise matrix. This method tests the type of the destination surface, and calls the corresponding typed propagator.

Arguments:

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

Returned value: propagation distance + success flag.

Implements trkf::Propagator.

Definition at line 54 of file PropAny.cxx.

References fPropXYZPlane, fPropYZLine, fPropYZPlane, trkf::PropYZLine::short_vec_prop(), trkf::PropXYZPlane::short_vec_prop(), and trkf::PropYZPlane::short_vec_prop().

Referenced by clone(), and trkf::InteractGeneral::noise().

60  {
61  // Default result.
62 
63  std::optional<double> result{std::nullopt};
64 
65  // Test the type of the destination surface.
66 
67  if (dynamic_cast<const SurfYZLine*>(&*psurf))
68  result = fPropYZLine.short_vec_prop(trk, psurf, dir, doDedx, prop_matrix, noise_matrix);
69  else if (dynamic_cast<const SurfYZPlane*>(&*psurf))
70  result = fPropYZPlane.short_vec_prop(trk, psurf, dir, doDedx, prop_matrix, noise_matrix);
71  else if (dynamic_cast<const SurfXYZPlane*>(&*psurf))
72  result = fPropXYZPlane.short_vec_prop(trk, psurf, dir, doDedx, prop_matrix, noise_matrix);
73  else
74  throw cet::exception("PropAny") << "Destination surface has unknown type.\n";
75 
76  // Done.
77 
78  return result;
79  }
PropYZPlane fPropYZPlane
Definition: PropAny.h:49
std::optional< double > short_vec_prop(KTrack &trk, const std::shared_ptr< const Surface > &surf, Propagator::PropDirection dir, bool doDedx, TrackMatrix *prop_matrix=0, TrackError *noise_matrix=0) const override
Propagate without error.
PropYZLine fPropYZLine
Underlying propagators.
Definition: PropAny.h:48
std::optional< double > short_vec_prop(KTrack &trk, const std::shared_ptr< const Surface > &surf, Propagator::PropDirection dir, bool doDedx, TrackMatrix *prop_matrix=0, TrackError *noise_matrix=0) const override
Propagate without error.
Definition: PropYZLine.cxx:50
PropXYZPlane fPropXYZPlane
Definition: PropAny.h:50
TDirectory * dir
Definition: macro.C:5
std::optional< double > short_vec_prop(KTrack &trk, const std::shared_ptr< const Surface > &surf, Propagator::PropDirection dir, bool doDedx, TrackMatrix *prop_matrix=0, TrackError *noise_matrix=0) const override
Propagate without error.
Definition: PropYZPlane.cxx:50
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
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
inherited

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 52 of file Propagator.cxx.

References util::abs(), larg4::dist(), e, detinfo::DetectorPropertiesData::Eloss(), trkf::Propagator::fDetProp, trkf::Propagator::fTcut, trkf::Propagator::getDoDedx(), trkf::KTrack::getMomentum(), trkf::KTrack::getPosition(), trkf::KTrack::getVector(), trkf::KTrack::Mass(), and trkf::Propagator::short_vec_prop().

Referenced by trkf::KalmanFilterAlg::fitMomentumMS(), trkf::Propagator::lin_prop(), trkf::KHitContainer::sort(), and trkf::KalmanFilterAlg::updateMomentum().

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

Member Data Documentation

PropXYZPlane trkf::PropAny::fPropXYZPlane
private

Definition at line 50 of file PropAny.h.

Referenced by origin_vec_prop(), PropAny(), and short_vec_prop().

PropYZLine trkf::PropAny::fPropYZLine
private

Underlying propagators.

Definition at line 48 of file PropAny.h.

Referenced by origin_vec_prop(), PropAny(), and short_vec_prop().

PropYZPlane trkf::PropAny::fPropYZPlane
private

Definition at line 49 of file PropAny.h.

Referenced by origin_vec_prop(), PropAny(), and short_vec_prop().


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