LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
TrackUtils.cxx
Go to the documentation of this file.
1 
10 // our header
12 
13 // LArSoft libraries
19 
20 // framework libraries
21 #include "cetlib_except/exception.h"
22 
23 // ROOT libraries
24 #include "TVector3.h"
25 
26 // C/C++ standard libraries
27 #include <cmath>
28 
29 
30 
31 //------------------------------------------------------------------------------
33 
34  if(view == geo::kUnknown) {
35  throw cet::exception("TrackProjectedLength") << "cannot provide projected length for "
36  << "unknown view\n";
37  }
38  double length = 0.;
39 
40  auto const* geom = lar::providerFrom<geo::Geometry>();
41  double angleToVert = 0.;
42  for(unsigned int i = 0; i < geom->Nplanes(); ++i){
43  if(geom->Plane(i).View() == view){
44  angleToVert = geom->Plane(i).Wire(0).ThetaZ(false) - 0.5*::util::pi<>();
45  break;
46  }
47  }
48 
49  // now loop over all points in the trajectory and add the contribution to the
50  // to the desired view
51 
52  for(size_t p = 1; p < track.NumberTrajectoryPoints(); ++p){
53  const auto& pos_cur = track.LocationAtPoint(p);
54  const auto& pos_prev = track.LocationAtPoint(p - 1);
55  double dist = std::sqrt( std::pow(pos_cur.x() - pos_prev.x(), 2) +
56  std::pow(pos_cur.y() - pos_prev.y(), 2) +
57  std::pow(pos_cur.z() - pos_prev.z(), 2) );
58 
59  // (sin(angleToVert),cos(angleToVert)) is the direction perpendicular to wire
60  // fDir[p-1] is the direction between the two relevant points
61  const auto& dir_prev = track.DirectionAtPoint(p - 1);
62  double cosgamma = std::abs(std::sin(angleToVert)*dir_prev.Y() +
63  std::cos(angleToVert)*dir_prev.Z() );
64 
66  length += dist/cosgamma;
67  } // end loop over distances between trajectory points
68 
69  return length;
70 } // lar::util::TrackProjectedLength()
71 
72 
73 
74 //------------------------------------------------------------------------------
76  (recob::Track const& track, geo::View_t view, size_t trajectory_point /* = 0 */)
77 {
78 
79  if(view == geo::kUnknown) {
80  throw cet::exception("TrackPitchInView") << "Warning cannot obtain pitch for unknown view\n";
81  }
82 
83  if(trajectory_point >= track.NumberTrajectoryPoints()) {
84  cet::exception("TrackPitchInView") << "ERROR: Asking for trajectory point #"
85  << trajectory_point << " when trajectory vector size is of size "
86  << track.NumberTrajectoryPoints() << ".\n";
87  }
88 
89  auto const* geom = lar::providerFrom<geo::Geometry>();
90  const auto& pos = track.LocationAtPoint(trajectory_point);
91  const double Position[3] = { pos.X(), pos.Y(), pos.Z() };
92  geo::TPCID tpcid = geom->FindTPCAtPosition ( Position );
93  if (!tpcid.isValid) {
94  cet::exception("TrackPitchInView") << "ERROR: invalid TPC " << std::string(tpcid)
95  << " for trajectory point #" << trajectory_point << ".\n";
96  }
97  double wirePitch = geom->WirePitch(view, tpcid.TPC, tpcid.Cryostat);
98  double angleToVert = geom->WireAngleToVertical(view, tpcid.TPC, tpcid.Cryostat) - 0.5*::util::pi<>();
99 
100  const auto& dir = track.DirectionAtPoint(trajectory_point);
101  //(sin(angleToVert),cos(angleToVert)) is the direction perpendicular to wire
102  double cosgamma = std::abs(std::sin(angleToVert)*dir.Y() +
103  std::cos(angleToVert)*dir.Z());
104 
105  if(cosgamma < 1.e-5)
106  throw cet::exception("Track") << "cosgamma is basically 0, that can't be right\n";
107  return wirePitch/cosgamma;
108 
109 } // lar::util::TrackPitchInView()
110 
111 //------------------------------------------------------------------------------
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Unknown view.
Definition: geo_types.h:83
Point_t const & LocationAtPoint(size_t i) const
Access to track position at different points.
Definition: Track.h:129
bool isValid
Whether this ID points to a valid element.
Definition: geo_types.h:129
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:32
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:105
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:130
Provides recob::Track data product.
The data type to uniquely identify a TPC.
Definition: geo_types.h:195
Encapsulate the geometry of a wire.
Encapsulate the construction of a single detector plane.
TDirectory * dir
Definition: macro.C:5
Vector_t DirectionAtPoint(size_t i) const
Access to track direction at different points.
Definition: Track.h:137
double TrackPitchInView(recob::Track const &track, geo::View_t view, size_t trajectory_point=0)
Provides projected wire pitch for the view.
Definition: TrackUtils.cxx:76
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:203
Float_t e
Definition: plot.C:34
Float_t track
Definition: plot.C:34
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 "fitted" track:
Definition: Track.h:52
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33