All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
21 #include "larcoreobj/SimpleTypesAndConstants/geo_vectors.h" // geo::Vector_t
23 
24 // framework libraries
25 #include "cetlib_except/exception.h"
26 
27 // ROOT libraries
28 
29 // C/C++ standard libraries
30 #include <cmath>
31 
32 
33 
34 //------------------------------------------------------------------------------
36 
37  if(view == geo::kUnknown) {
38  throw cet::exception("TrackProjectedLength") << "cannot provide projected length for "
39  << "unknown view\n";
40  }
41  double length = 0.;
42 
43  auto const* geom = lar::providerFrom<geo::Geometry>();
44  double angleToVert = 0.;
45  for(unsigned int i = 0; i < geom->Nplanes(); ++i){
46  if(geom->Plane(i).View() == view){
47  angleToVert = geom->Plane(i).Wire(0).ThetaZ(false) - 0.5*::util::pi<>();
48  break;
49  }
50  }
51 
52  // now loop over all points in the trajectory and add the contribution to the
53  // to the desired view
54 
55  for(size_t p = 1; p < track.NumberTrajectoryPoints(); ++p){
56  const auto& pos_cur = track.LocationAtPoint(p);
57  const auto& pos_prev = track.LocationAtPoint(p - 1);
58  double dist = std::sqrt( std::pow(pos_cur.x() - pos_prev.x(), 2) +
59  std::pow(pos_cur.y() - pos_prev.y(), 2) +
60  std::pow(pos_cur.z() - pos_prev.z(), 2) );
61 
62  // (sin(angleToVert),cos(angleToVert)) is the direction perpendicular to wire
63  // fDir[p-1] is the direction between the two relevant points
64  const auto& dir_prev = track.DirectionAtPoint(p - 1);
65  double cosgamma = std::abs(std::sin(angleToVert)*dir_prev.Y() +
66  std::cos(angleToVert)*dir_prev.Z() );
67 
68  /// @todo is this right, or should it be dist*cosgamma???
69  length += dist/cosgamma;
70  } // end loop over distances between trajectory points
71 
72  return length;
73 } // lar::util::TrackProjectedLength()
74 
75 
76 
77 //------------------------------------------------------------------------------
79  (recob::Track const& track, geo::View_t view, size_t trajectory_point /* = 0 */)
80 {
81  /*
82  * The plan:
83  * 1. find the wire plane we are talking about
84  * (in the right TPC and with the right view)
85  * 2. ask the plane the answer
86  *
87  */
88 
89 
90  if(trajectory_point >= track.NumberTrajectoryPoints()) {
91  cet::exception("TrackPitchInView") << "ERROR: Asking for trajectory point #"
92  << trajectory_point << " when trajectory vector size is of size "
93  << track.NumberTrajectoryPoints() << ".\n";
94  }
96  = track.TrajectoryPoint(trajectory_point);
97 
98  // this throws if the position is not in any TPC,
99  // or if there is no view with specified plane
100  auto const& geom = *(lar::providerFrom<geo::Geometry>());
101  geo::PlaneGeo const& plane = geom.PositionToTPC(point.position).Plane(view);
102 
103 #if 0 // this can be enabled after `geo::PlaneGeo::InterWireProjectedDistance()` becomes available in larcorealg
104  double const d = plane.InterWireProjectedDistance(point.direction());
105 
106  // do we prefer to just return the value and let the caller check it?
107  if (d > 50.0 * plane.WirePitch()) { // after many pitches track would scatter
108  throw cet::exception("Track")
109  << "track at point #" << trajectory_point
110  << " is almost parallel to the wires in view "
111  << geo::PlaneGeo::ViewName(view) << " (wire direction is "
112  << plane.GetWireDirection<geo::Vector_t>() << "; track direction is "
113  << point.direction()
114  << ").\n";
115  }
116  return d;
117 
118 #else // !0
119  //
120  // 2. project the direction of the track on that plane
121  //
122  // this is the projection of the direction of the track on the wire plane;
123  // it is 2D and its second component ("Y()") is on wire coordinate direction;
124  // remember that the projection modulus is smaller than 1 because it is
125  // the 3D direction versor, deprived of its drift direction component
126  auto const& proj = plane.Projection(point.direction());
127 
128  if (lar::util::RealComparisons(1e-4).zero(proj.Y())) {
129  throw cet::exception("Track")
130  << "track at point #" << trajectory_point
131  << " is almost parallel to the wires in view "
132  << geo::PlaneGeo::ViewName(view) << " (wire direction is "
133  << plane.GetWireDirection<geo::Vector_t>() << "; track direction is "
134  << point.direction()
135  << ", its projection on plane " << plane.ID() << " is " << proj
136  << ").\n";
137  }
138 
139  //
140  // 3. scale that projection so that it covers a wire pitch worth in the wire
141  // coordinate direction;
142  // WirePitch() is what gives this vector a physical size [cm]
143  //
144  return proj.R() / std::abs(proj.Y()) * plane.WirePitch();
145 #endif // ?0
146 
147 } // lar::util::TrackPitchInView()
148 
149 //------------------------------------------------------------------------------
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
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
Utilities related to art service access.
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
pdgs p
Definition: selectors.fcl:22
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:35
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
process_name use argoneut_mc_hitfinder track
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
Access the description of detector geometry.
T abs(T value)
Definitions of geometry vector data types.
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:82
TrajectoryPoint_t TrajectoryPoint(size_t i) const
Access to i-th TrajectoryPoint or its Flags.
Provides recob::Track data product.
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:79
do i e
Vector_t DirectionAtPoint(size_t i) const
Collection of Physical constants used in LArSoft.
Utility functions to extract information from recob::Track
art framework interface to geometry description
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track:
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