TrackUtils.cxx
Go to the documentation of this file.
1 /**
2  * @file lardata/ArtDataHelper/TrackUtils.cxx
3  * @brief Utility functions to extract information from `recob::Track` - implementation
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date March 8th, 2016
6  * @see lardata/ArtDataHelper/TrackUtils.h
7  *
8  */
9 
10 // our header
12 
13 // LArSoft libraries
20 #include "larcoreobj/SimpleTypesAndConstants/geo_vectors.h" // geo::Vector_t
22 
23 // framework libraries
24 #include "cetlib_except/exception.h"
25 
26 // ROOT libraries
27 
28 // C/C++ standard libraries
29 #include <cmath>
30 
31 
32 
33 //------------------------------------------------------------------------------
35 
36  if(view == geo::kUnknown) {
37  throw cet::exception("TrackProjectedLength") << "cannot provide projected length for "
38  << "unknown view\n";
39  }
40  double length = 0.;
41 
42  auto const* geom = lar::providerFrom<geo::Geometry>();
43  double angleToVert = 0.;
44  for(unsigned int i = 0; i < geom->Nplanes(); ++i){
45  if(geom->Plane(i).View() == view){
46  angleToVert = geom->Plane(i).Wire(0).ThetaZ(false) - 0.5*::util::pi<>();
47  break;
48  }
49  }
50 
51  // now loop over all points in the trajectory and add the contribution to the
52  // to the desired view
53 
54  for(size_t p = 1; p < track.NumberTrajectoryPoints(); ++p){
55  const auto& pos_cur = track.LocationAtPoint(p);
56  const auto& pos_prev = track.LocationAtPoint(p - 1);
57  double dist = std::sqrt( std::pow(pos_cur.x() - pos_prev.x(), 2) +
58  std::pow(pos_cur.y() - pos_prev.y(), 2) +
59  std::pow(pos_cur.z() - pos_prev.z(), 2) );
60 
61  // (sin(angleToVert),cos(angleToVert)) is the direction perpendicular to wire
62  // fDir[p-1] is the direction between the two relevant points
63  const auto& dir_prev = track.DirectionAtPoint(p - 1);
64  double cosgamma = std::abs(std::sin(angleToVert)*dir_prev.Y() +
65  std::cos(angleToVert)*dir_prev.Z() );
66 
67  /// @todo is this right, or should it be dist*cosgamma???
68  length += dist/cosgamma;
69  } // end loop over distances between trajectory points
70 
71  return length;
72 } // lar::util::TrackProjectedLength()
73 
74 
75 
76 //------------------------------------------------------------------------------
78  (recob::Track const& track, geo::View_t view, size_t trajectory_point /* = 0 */)
79 {
80  /*
81  * The plan:
82  * 1. find the wire plane we are talking about
83  * (in the right TPC and with the right view)
84  * 2. ask the plane the answer
85  *
86  */
87 
88 
89  if(trajectory_point >= track.NumberTrajectoryPoints()) {
90  cet::exception("TrackPitchInView") << "ERROR: Asking for trajectory point #"
91  << trajectory_point << " when trajectory vector size is of size "
92  << track.NumberTrajectoryPoints() << ".\n";
93  }
95  = track.TrajectoryPoint(trajectory_point);
96 
97  // this throws if the position is not in any TPC,
98  // or if there is no view with specified plane
99  auto const& geom = *(lar::providerFrom<geo::Geometry>());
100  geo::PlaneGeo const& plane = geom.PositionToTPC(point.position).Plane(view);
101 
102 #if 0 // this can be enabled after `geo::PlaneGeo::InterWireProjectedDistance()` becomes available in larcorealg
103  double const d = plane.InterWireProjectedDistance(point.direction());
104 
105  // do we prefer to just return the value and let the caller check it?
106  if (d > 50.0 * plane.WirePitch()) { // after many pitches track would scatter
107  throw cet::exception("Track")
108  << "track at point #" << trajectory_point
109  << " is almost parallel to the wires in view "
110  << geo::PlaneGeo::ViewName(view) << " (wire direction is "
111  << plane.GetWireDirection<geo::Vector_t>() << "; track direction is "
112  << point.direction()
113  << ").\n";
114  }
115  return d;
116 
117 #else // !0
118  //
119  // 2. project the direction of the track on that plane
120  //
121  // this is the projection of the direction of the track on the wire plane;
122  // it is 2D and its second component ("Y()") is on wire coordinate direction;
123  // remember that the projection modulus is smaller than 1 because it is
124  // the 3D direction versor, deprived of its drift direction component
125  auto const& proj = plane.Projection(point.direction());
126 
127  if (lar::util::RealComparisons(1e-4).zero(proj.Y())) {
128  throw cet::exception("Track")
129  << "track at point #" << trajectory_point
130  << " is almost parallel to the wires in view "
131  << geo::PlaneGeo::ViewName(view) << " (wire direction is "
132  << plane.GetWireDirection<geo::Vector_t>() << "; track direction is "
133  << point.direction()
134  << ", its projection on plane " << plane.ID() << " is " << proj
135  << ").\n";
136  }
137 
138  //
139  // 3. scale that projection so that it covers a wire pitch worth in the wire
140  // coordinate direction;
141  // WirePitch() is what gives this vector a physical size [cm]
142  //
143  return proj.R() / std::abs(proj.Y()) * plane.WirePitch();
144 #endif // ?0
145 
146 } // lar::util::TrackPitchInView()
147 
148 //------------------------------------------------------------------------------
A point in the trajectory, with position and momentum.
Definition: TrackingTypes.h:63
static std::string ViewName(geo::View_t view)
Returns the name of the specified view.
Definition: PlaneGeo.cxx:763
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Unknown view.
Definition: geo_types.h:136
Provides simple real number checks.
constexpr bool zero(Value_t value) const
Returns whether the value is no farther from 0 than the threshold.
Point_t const & LocationAtPoint(size_t i) const
Definition: Track.h:126
constexpr T pow(T x)
Definition: pow.h:72
double TrackProjectedLength(recob::Track const &track, geo::View_t view)
Returns the length of the projection of a track on a view.
Definition: TrackUtils.cxx:34
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:102
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
WireCoordProjection_t Projection(geo::Point_t const &point) const
Returns the projection of the specified point on the plane.
Definition: PlaneGeo.h:940
Class for approximate comparisons.
double InterWireProjectedDistance(WireCoordProjection_t const &projDir) const
Returns the distance between wires along the specified direction.
Definition: PlaneGeo.cxx:705
art framework interface to geometry description
T abs(T value)
const double e
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:82
p
Definition: test.py:223
TrajectoryPoint_t TrajectoryPoint(size_t i) const
Access to i-th TrajectoryPoint or its Flags.
Definition: Track.h:117
Vector_t direction() const
Returns the direction of the trajectory (unit vector of the momentum).
Definition: TrackingTypes.h:76
Encapsulate the construction of a single detector plane.
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
geo::PlaneID const & ID() const
Returns the identifier of this plane.
Definition: PlaneGeo.h:203
double TrackPitchInView(recob::Track const &track, geo::View_t view, size_t trajectory_point=0U)
Returns the projected length of track on a wire pitch step [cm].
Definition: TrackUtils.cxx:78
Provides recob::Track data product.
Definitions of geometry vector data types.
Access the description of detector geometry.
Vector_t DirectionAtPoint(size_t i) const
Definition: Track.h:134
Collection of Physical constants used in LArSoft.
Utility functions to extract information from recob::Track
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
double WirePitch() const
Return the wire pitch (in centimeters). It is assumed constant.
Definition: PlaneGeo.h:411
Encapsulate the construction of a single detector plane.
Vector GetWireDirection() const
Returns the direction of the wires.
Definition: PlaneGeo.h:513
Point_t position
position in the trajectory [cm].
Definition: TrackingTypes.h:65