All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Namespaces | Classes | Typedefs | Functions | Variables
lar::util Namespace Reference

LArSoft utility namespace. More...

Namespaces

 detail
 
 details
 LArSoft utility implementation details.
 
 simple_geo
 Simple class definitions for geometry concepts.
 

Classes

struct  RealComparisons
 Provides simple real number checks. More...
 
struct  Vector2DComparison
 Class comparing 2D vectors. More...
 
struct  Vector3DComparison
 Class comparing 2D vectors. More...
 
struct  assns_has_metadata
 Trait: value true if Assns (association or its node) has metadata. More...
 
struct  assns_metadata_type
 Trait: type is metadata in Assns (association or its node). More...
 
struct  assns_iterator_type
 Trait: type is iterator of Assns. More...
 
struct  assns_traits
 Data types for the specified association type (or its node). More...
 
struct  assns_metadata_type< art::Assns< L, R, D > >
 
struct  assns_metadata_type< art::AssnsNode< L, R, D > >
 
struct  assns_metadata_type< std::pair< art::Ptr< L >, art::Ptr< R > > >
 
struct  assns_iterator_type< art::Assns< L, R, D > >
 
struct  assns_iterator_type< art::Assns< L, R, void > >
 
struct  assns_traits< art::Assns< L, R, D > >
 
struct  assns_traits< art::AssnsNode< L, R, D > >
 
struct  assns_traits< std::pair< art::Ptr< L >, art::Ptr< R > > >
 
struct  assns_metadata_type< proxy::details::AssnsNode< ArtAssnsIterValue > >
 
class  ChiSquareAccumulator
 Computes a χ from expectation function and data points. More...
 
struct  dereferenced_type
 Class defining the dereferenced type of the specified type. More...
 
class  LinearFit
 Performs a linear regression of data. More...
 
class  QuadraticFit
 Performs a second-degree fit of data. More...
 
class  GaussianFit
 "Fast" Gaussian fit More...
 
struct  identity
 A unary functor returning its own argument (any type) More...
 
class  StatCollector
 Collects statistics on a single quantity (weighted) More...
 
class  StatCollector2D
 Collects statistics on two homogeneous quantities (weighted) More...
 
class  MinMaxCollector
 Keeps track of the minimum and maximum value we observed. More...
 

Typedefs

template<typename Iter >
using DereferenceConstIterator = detail::DereferenceIteratorBase< Iter, std::add_const_t< std::decay_t< decltype(**(std::declval< Iter >()))>> >
 An iterator wrapper to dereference pointed values. More...
 
template<typename Iter >
using DereferenceIterator = detail::DereferenceIteratorBase< Iter, std::decay_t< decltype(**(std::declval< Iter >()))> >
 An iterator wrapper to dereferencing pointed values as constant. More...
 
using HitToWire = details::FindAllP< recob::Hit, recob::Wire >
 Query object connecting a hit to a wire. More...
 
template<typename Assns >
using assns_metadata_t = typename assns_metadata_type< Assns >::type
 Trait: type of metadata in Assns (association or its node). More...
 
template<typename Assns >
using assns_iterator_t = typename assns_iterator_type< Assns >::type
 Trait: type of iterator of Assns. More...
 

Functions

template<typename Iter >
auto makeDereferenceIterator (Iter &&iter)
 Returns a dereference iterator to the begin of specified container. More...
 
template<typename Cont >
auto beginDereferenceIterator (Cont &cont)
 Returns a dereference iterator to the begin of specified container. More...
 
template<typename Cont >
auto endDereferenceIterator (Cont &cont)
 Returns a dereference iterator to the end of specified container. More...
 
template<typename Cont >
auto rbeginDereferenceIterator (Cont &cont)
 Returns a dereference reverse iterator to the begin of container. More...
 
template<typename Cont >
auto rendDereferenceIterator (Cont &cont)
 Returns a dereference reverse iterator to the end of container. More...
 
template<typename Cont >
auto dereferenceIteratorLoop (Cont &cont)
 Returns an object enabling a dereferencing range-for loop. More...
 
template<typename Cont >
auto dereferenceIteratorReverseLoop (Cont &cont)
 Returns an object enabling a dereferencing reverse range-for loop. More...
 
template<typename RealType >
auto makeVector2DComparison (RealType threshold)
 Creates a Vector2DComparison from a RealComparisons object. More...
 
template<typename RealType >
auto makeVector2DComparison (lar::util::RealComparisons< RealType > const &comp)
 Creates a Vector2DComparison from a RealComparisons object. More...
 
template<typename RealType >
auto makeVector3DComparison (RealType threshold)
 Creates a Vector3DComparison from a RealComparisons object. More...
 
template<typename RealType >
auto makeVector3DComparison (lar::util::RealComparisons< RealType > const &comp)
 Creates a Vector3DComparison from a RealComparisons object. More...
 
double TrackProjectedLength (recob::Track const &track, geo::View_t view)
 Returns the length of the projection of a track on a view. More...
 
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]. More...
 
template<typename F >
auto makeChiSquareAccumulator (F &&e)
 Creates a ChiSquareAccumulator object with the specified function. More...
 
template<typename T , typename F >
auto makeChiSquareAccumulator (F &&e)
 Creates a ChiSquareAccumulator object with the specified function. More...
 
template<typename T >
details::dereference_class< T,
details::has_dereference_class
< T >::value >::reference_type 
dereference (T &v)
 Returns the value pointed by the argument, or the argument itself. More...
 
template<typename T >
details::make_pointer_class< T,
details::has_dereference_class
< T >::value >::pointer_type 
make_pointer (T &v)
 Returns a pointer to the value of argument, or the argument itself. More...
 
Constant iterator functions

See the documentation of the similar non-const ones.

template<typename Iter >
auto makeDereferenceConstIterator (Iter &&iter)
 
template<typename Cont >
auto cbeginDereferenceIterator (Cont &cont)
 
template<typename Cont >
auto cendDereferenceIterator (Cont &cont)
 
template<typename Cont >
auto crbeginDereferenceIterator (Cont &cont)
 
template<typename Cont >
auto crendDereferenceIterator (Cont &cont)
 
template<typename Cont >
auto dereferenceConstIteratorLoop (Cont &cont)
 Returns an object enabling a dereferencing range-for loop. More...
 
template<typename Cont >
auto dereferenceConstIteratorReverseLoop (Cont &cont)
 Returns an object enabling a dereferencing reverse range-for loop. More...
 

Variables

template<typename Assns >
constexpr bool assns_has_metadata_v = assns_has_metadata<Assns>::value
 Trait: true if Assns (association or its node) has metadata. More...
 

Detailed Description

LArSoft utility namespace.

LArSoft utilities namespace.

Typedef Documentation

template<typename Iter >
using lar::util::DereferenceConstIterator = typedef detail::DereferenceIteratorBase< Iter, std::add_const_t<std::decay_t<decltype(**(std::declval<Iter>()))>> >

An iterator wrapper to dereference pointed values.


Template Parameters
Itertype of iterator being wrapped
See Also
beginDereferenceIterator(), endDereferenceIterator(), dereferenceIteratorLoop()

This iterator is useful to iterate a collection of pointers accessing directly the pointed values.

It's probably easier to use cbeginDereferenceIterator(), cendDereferenceIterator() and dereferenceConstIteratorLoop() rather than instantiating this class directly.

Note
Note the bizarre construction mechanism, needed to differentiate from copy constructor. This allows nesting iterators.
Deprecated:
Just use boost::indirect_iterator instead (boost/iterator/indirect_iterator.hpp).

Definition at line 220 of file DereferenceIterator.h.

template<typename Iter >
using lar::util::DereferenceIterator = typedef detail::DereferenceIteratorBase< Iter, std::decay_t<decltype(**(std::declval<Iter>()))> >

An iterator wrapper to dereferencing pointed values as constant.

Template Parameters
Itertype of iterator being wrapped
See Also
DereferenceConstIterator

This class behaves like DereferenceConstIterator, except that it returns mutable references to values.

Deprecated:
Just use boost::indirect_iterator instead (boost/iterator/indirect_iterator.hpp).

Definition at line 237 of file DereferenceIterator.h.

Query object connecting a hit to a wire.


Once upon a time, recob::Hit had a art::Ptr<recob::Wire> in it, and life was easy. When it was discovered that art pointers in data products were evil, they were banned from recob::Hit. As always, evil turns out to be convenient. This query object tries to provide in an efficient way a connection between a hit and the wire that has generated it.

This object expects

Example of usage: let hit_ptr be a valid art::Ptr<recob::Hit>. Then

HitToWire HtoW(evt);
art::Ptr<recob::Wire> wire_ptr = HtoW[hit_ptr];

If the association label is known, it can be used to selectively load that association:

HitToWire HtoW(evt, AssociationInputTag);
art::Ptr<recob::Wire> wire_ptr = HtoW[hit_ptr];

that has little advantage (in fact, it is possibly slower) respect to using art::FindOneP.

Definition at line 56 of file HitUtils.h.

Function Documentation

template<typename Cont >
auto lar::util::beginDereferenceIterator ( Cont &  cont)

Returns a dereference iterator to the begin of specified container.

Template Parameters
Conttype of the container (may be constant)
Parameters
contcontainer to extract the iterator from
Returns
a dereference iterator of cont.begin()

If the type is constant, the iterator will likely be constant too. This wrapper is quite blind to the meaning of iterators and their constantness.

Definition at line 269 of file DereferenceIterator.h.

270  { return makeDereferenceIterator(cont.begin()); }
auto makeDereferenceIterator(Iter &&iter)
Returns a dereference iterator to the begin of specified container.
template<typename Cont >
auto lar::util::cbeginDereferenceIterator ( Cont &  cont)
See Also
beginDereferenceIterator

Definition at line 395 of file DereferenceIterator.h.

396  { return makeDereferenceConstIterator(cont.cbegin()); }
auto makeDereferenceConstIterator(Iter &&iter)
template<typename Cont >
auto lar::util::cendDereferenceIterator ( Cont &  cont)
See Also
endDereferenceIterator

Definition at line 400 of file DereferenceIterator.h.

401  { return makeDereferenceConstIterator(cont.cend()); }
auto makeDereferenceConstIterator(Iter &&iter)
template<typename Cont >
auto lar::util::crbeginDereferenceIterator ( Cont &  cont)
See Also
rbeginDereferenceIterator

Definition at line 405 of file DereferenceIterator.h.

406  { return makeDereferenceConstIterator(cont.crbegin()); }
auto makeDereferenceConstIterator(Iter &&iter)
template<typename Cont >
auto lar::util::crendDereferenceIterator ( Cont &  cont)
See Also
crendDereferenceIterator

Definition at line 410 of file DereferenceIterator.h.

411  { return makeDereferenceConstIterator(cont.crend()); }
auto makeDereferenceConstIterator(Iter &&iter)
template<typename T >
details::dereference_class<T, details::has_dereference_class<T>::value>::reference_type lar::util::dereference ( T &  v)
inline

Returns the value pointed by the argument, or the argument itself.


Template Parameters
Tthe type of the argument
Parameters
vthe value to be dereferenced
Returns
the value v points to, if any, or v itself

This function allows the use of the same template code to process both pointers and pointed values. For example:

template <typename T>
std::vector<int> extract_int(std::vector<T> const& from) {
  std::vector<int> v;
  v.reserve(from.size());
  std::transform(from.begin(), from.end(), std::back_inserter(v),
    util::dereference);
  return v;
}

int value = 10;
std::vector<int> v(10, value);
std::vector<int*> v_ptr(10, &value);

extract_int(v);
extract_int(v_ptr);

shows that the same function can be used on vectors of integers and of their pointers.

Definition at line 254 of file Dereference.h.

255  {
256  return details::dereference_class
258  }
temporary value
template<typename Cont >
auto lar::util::dereferenceConstIteratorLoop ( Cont &  cont)

Returns an object enabling a dereferencing range-for loop.

Template Parameters
Conttype of the container (may be constant)
Parameters
contcontainer to extract the iterator from
Returns
an object enabling a dereferencing range-for loop
See Also
dereferenceIteratorReverseLoop()

Example of usage:

std::vector<std::unique_ptr<int>> v;
// fill the vector
for (int const& i: dereferenceConstIteratorLoop(v)) {
std::cout << i << std::endl;
} // for i

This wrapper forces the iteration variable to be constant.

Definition at line 436 of file DereferenceIterator.h.

437  {
440  } // dereferenceConstIteratorLoop()
auto makeIteratorBox(BeginIter b, EndIter e)
auto cendDereferenceIterator(Cont &cont)
auto cbeginDereferenceIterator(Cont &cont)
template<typename Cont >
auto lar::util::dereferenceConstIteratorReverseLoop ( Cont &  cont)

Returns an object enabling a dereferencing reverse range-for loop.

Template Parameters
Conttype of the container (may be constant)
Parameters
contcontainer to extract the iterator from
Returns
an object enabling a dereferencing range-for loop
See Also
dereferenceConstIteratorLoop()

This function is similar to dereferenceConstIteratorLoop(), but the order of iteration is reversed.

Example of usage:

std::vector<std::unique_ptr<int>> v;
// fill the vector
for (int const& i: dereferenceConstIteratorReverseLoop(v)) {
std::cout << i << std::endl;
} // for i

If the type is constant, the loop variable will likely be constant too. This wrapper is quite blind to the meaning of iterators and their constantness.

Definition at line 472 of file DereferenceIterator.h.

473  {
476  } // dereferenceConstIteratorReverseLoop()
auto crbeginDereferenceIterator(Cont &cont)
auto crendDereferenceIterator(Cont &cont)
auto makeIteratorBox(BeginIter b, EndIter e)
template<typename Cont >
auto lar::util::dereferenceIteratorLoop ( Cont &  cont)

Returns an object enabling a dereferencing range-for loop.

Template Parameters
Conttype of the container (may be constant)
Parameters
contcontainer to extract the iterator from
Returns
an object enabling a dereferencing range-for loop
See Also
dereferenceIteratorReverseLoop()

Example of usage:

std::vector<std::unique_ptr<int>> v;
// fill the vector
for (int& i: dereferenceIteratorLoop(v)) {
std::cout << i << std::endl;
} // for i

If the type is constant, the loop variable will likely be constant too. This wrapper is quite blind to the meaning of iterators and their constantness.

Definition at line 340 of file DereferenceIterator.h.

341  {
344  } // dereferenceIteratorLoop()
auto beginDereferenceIterator(Cont &cont)
Returns a dereference iterator to the begin of specified container.
auto makeIteratorBox(BeginIter b, EndIter e)
auto endDereferenceIterator(Cont &cont)
Returns a dereference iterator to the end of specified container.
template<typename Cont >
auto lar::util::dereferenceIteratorReverseLoop ( Cont &  cont)

Returns an object enabling a dereferencing reverse range-for loop.

Template Parameters
Conttype of the container (may be constant)
Parameters
contcontainer to extract the iterator from
Returns
an object enabling a dereferencing range-for loop
See Also
dereferenceIteratorLoop()

This function is similar to dereferenceIteratorLoop(), but the order of iteration is reversed.

Example of usage:

std::vector<std::unique_ptr<int>> v;
// fill the vector
std::cout << i << std::endl;
} // for i

If the type is constant, the loop variable will likely be constant too. This wrapper is quite blind to the meaning of iterators and their constantness.

Definition at line 376 of file DereferenceIterator.h.

377  {
380  } // dereferenceIteratorReverseLoop()
auto rendDereferenceIterator(Cont &cont)
Returns a dereference reverse iterator to the end of container.
auto makeIteratorBox(BeginIter b, EndIter e)
auto rbeginDereferenceIterator(Cont &cont)
Returns a dereference reverse iterator to the begin of container.
template<typename Cont >
auto lar::util::endDereferenceIterator ( Cont &  cont)

Returns a dereference iterator to the end of specified container.

Template Parameters
Conttype of the container (may be constant)
Parameters
contcontainer to extract the iterator from
Returns
a dereference iterator of cont.end()

If the type is constant, the iterator will likely be constant too. This wrapper is quite blind to the meaning of iterators and their constantness.

Definition at line 283 of file DereferenceIterator.h.

284  { return makeDereferenceIterator(cont.end()); }
auto makeDereferenceIterator(Iter &&iter)
Returns a dereference iterator to the begin of specified container.
template<typename T >
details::make_pointer_class<T, details::has_dereference_class<T>::value>::pointer_type lar::util::make_pointer ( T &  v)
inline

Returns a pointer to the value of argument, or the argument itself.


Template Parameters
Tthe type of the argument
Parameters
vthe value to be taken the pointer of
Returns
a pointer to v, or v itself if it is already a C pointer

This function allows the use of the same template code to process both pointers and pointed values. For example:

template <typename T>
std::vector<int*> extract_int(std::vector<T> const& from) {
  std::vector<int*> v;
  v.reserve(from.size());
  std::transform(from.begin(), from.end(), std::back_inserter(v),
    util::make_pointer);
  return v;
}

int value = 10;
std::vector<int> v(10, value);
std::vector<int*> v_ptr(10, &value);

extract_int(v);
extract_int(v_ptr);

shows that the same function can be used on vectors of integers and of their pointers.

Definition at line 293 of file Dereference.h.

294  {
295  return details::make_pointer_class
297  }
temporary value
template<typename F >
auto lar::util::makeChiSquareAccumulator ( F &&  e)

Creates a ChiSquareAccumulator object with the specified function.

Template Parameters
Ftype of function (deduced from e)
Parameters
eexpectation function
Returns
a ChiSquareAccumulator<F> instance with specified expectation

Example of usage:

auto zero = [](double){ return 0.0; }; // expectation function
auto chiSquare = lar::util::makeChiSquareAccumulator(zero);

declare chiSquare in a way equivalent to: lar::util::ChiSquareAccumulator<decltype(zero)> chiSquare(zero).

Definition at line 161 of file ChiSquareAccumulator.h.

162  { return lar::util::ChiSquareAccumulator<F>(std::forward<F>(e)); }
Computes a χ from expectation function and data points.
do i e
template<typename T , typename F >
auto lar::util::makeChiSquareAccumulator ( F &&  e)

Creates a ChiSquareAccumulator object with the specified function.

Template Parameters
Ttype of data (default: double)
Ftype of function (deduced from e)
Parameters
eexpectation function
Returns
a ChiSquareAccumulator<F,T> instance with specified expectation

Example of usage:

auto zero = [](float){ return 0.0F; }; // expectation function
auto chiSquare = lar::util::makeChiSquareAccumulator<float>(zero);

declare chiSquare in a way equivalent to: lar::util::ChiSquareAccumulator<decltype(zero), float> chiSquare(zero).

Definition at line 180 of file ChiSquareAccumulator.h.

181  { return lar::util::ChiSquareAccumulator<F, T>(std::forward<F>(e)); }
Computes a χ from expectation function and data points.
do i e
template<typename Iter >
auto lar::util::makeDereferenceConstIterator ( Iter &&  iter)
See Also
makeDereferenceIterator

Definition at line 390 of file DereferenceIterator.h.

391  { return DereferenceConstIterator<Iter>(std::forward<Iter>(iter), {}); }
template<typename Iter >
auto lar::util::makeDereferenceIterator ( Iter &&  iter)

Returns a dereference iterator to the begin of specified container.

Template Parameters
Itertype of the iterator to be wrapped (may be constant)
Parameters
iterthe iterator to be wrapped
Returns
a dereference iterator of iter
See Also
beginDereferenceIterator(), endDereferenceIterator(), rbeginDereferenceIterator(), rendDereferenceIterator(), dereferenceIteratorLoop(), dereferenceIteratorReverseLoop()

If the type is constant, the iterator will likely be constant too. This wrapper is quite blind to the meaning of iterators and their constantness.

Definition at line 255 of file DereferenceIterator.h.

256  { return DereferenceIterator<Iter>(std::forward<Iter>(iter), {}); }
template<typename RealType >
auto lar::util::makeVector2DComparison ( RealType  threshold)

Creates a Vector2DComparison from a RealComparisons object.

Definition at line 187 of file RealComparisons.h.

188  { return Vector2DComparison<RealType>(threshold); }
template<typename RealType >
auto lar::util::makeVector2DComparison ( lar::util::RealComparisons< RealType > const &  comp)

Creates a Vector2DComparison from a RealComparisons object.

Definition at line 193 of file RealComparisons.h.

194  { return Vector2DComparison<RealType>(comp); }
template<typename RealType >
auto lar::util::makeVector3DComparison ( RealType  threshold)

Creates a Vector3DComparison from a RealComparisons object.

Definition at line 252 of file RealComparisons.h.

253  { return Vector3DComparison<RealType>(threshold); }
template<typename RealType >
auto lar::util::makeVector3DComparison ( lar::util::RealComparisons< RealType > const &  comp)

Creates a Vector3DComparison from a RealComparisons object.

Definition at line 258 of file RealComparisons.h.

259  { return Vector3DComparison<RealType>(comp); }
template<typename Cont >
auto lar::util::rbeginDereferenceIterator ( Cont &  cont)

Returns a dereference reverse iterator to the begin of container.

Template Parameters
Conttype of the container (may be constant)
Parameters
contcontainer to extract the iterator from
Returns
a dereference iterator of cont.rbegin()

If the type is constant, the iterator will likely be constant too. This wrapper is quite blind to the meaning of iterators and their constantness.

Definition at line 297 of file DereferenceIterator.h.

298  { return makeDereferenceIterator(cont.rbegin()); }
auto makeDereferenceIterator(Iter &&iter)
Returns a dereference iterator to the begin of specified container.
template<typename Cont >
auto lar::util::rendDereferenceIterator ( Cont &  cont)

Returns a dereference reverse iterator to the end of container.

Template Parameters
Conttype of the container (may be constant)
Parameters
contcontainer to extract the iterator from
Returns
a dereference iterator of cont.rend()

If the type is constant, the iterator will likely be constant too. This wrapper is quite blind to the meaning of iterators and their constantness.

Definition at line 311 of file DereferenceIterator.h.

312  { return makeDereferenceIterator(cont.rend()); }
auto makeDereferenceIterator(Iter &&iter)
Returns a dereference iterator to the begin of specified container.
double lar::util::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].

Parameters
trackthe track to be projected on a view
viewthe view for track projection
trajectory_pointat which point of the track to look for the pitch (default: 0)
Returns
wire pitch along the track direction at its specified point [cm]
Exceptions
cet::exception(category "TrackPitchInView") if the trajectory_point index is not valid in track
cet::exception(category "Geometry") if the point is in no TPC
cet::exception(category "TPCGeo") if the view is unknown, not available or otherwise invalid
cet::exception(category "Track") if the track projection on the wire plane is parallel to the wires (< 0.01%)

This function returns the distance covered by the track between two wires, projected on the wire plane. The direction of the track is the one at the specified trajectory point (the first one by default). That direction is projected on the wire plane with the specified view within the TPC that contains that point.

The returned value is the distance, in centimeters, between two consecutive wires on that projected direction. This is always a positive number, regardless the direction of the track, and never smaller than the wire pitch on the projection wire plane.

Definition at line 79 of file TrackUtils.cxx.

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()
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
Provides simple real number checks.
constexpr bool zero(Value_t value) const
Returns whether the value is no farther from 0 than the threshold.
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
double InterWireProjectedDistance(WireCoordProjection_t const &projDir) const
Returns the distance between wires along the specified direction.
Definition: PlaneGeo.cxx:705
T abs(T value)
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:82
Vector_t direction() const
Returns the direction of the trajectory (unit vector of the momentum).
Definition: TrackingTypes.h:76
geo::PlaneID const & ID() const
Returns the identifier of this plane.
Definition: PlaneGeo.h:203
do i e
double WirePitch() const
Return the wire pitch (in centimeters). It is assumed constant.
Definition: PlaneGeo.h:411
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
double lar::util::TrackProjectedLength ( recob::Track const &  track,
geo::View_t  view 
)

Returns the length of the projection of a track on a view.

Parameters
trackthe track to be projected on a view
viewthe view to project the track on
Returns
length of the projection, in centimetres
Todo:
CAREFUL: using view to determine projected length does not work for DUNE. Need to think more about this.
Todo:
is this right, or should it be dist*cosgamma???

Definition at line 35 of file TrackUtils.cxx.

35  {
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()
Unknown view.
Definition: geo_types.h:136
pdgs p
Definition: selectors.fcl:22
process_name use argoneut_mc_hitfinder track
T abs(T value)
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)