LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
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  assns_has_metadata
 Trait: value true if Assns (association or its node) has metadata. More...
 
struct  assns_iterator_type
 Trait: type is iterator of Assns. More...
 
struct  assns_iterator_type< art::Assns< L, R, D > >
 
struct  assns_iterator_type< art::Assns< L, R, void > >
 
struct  assns_metadata_type
 Trait: type is metadata in Assns (association 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< proxy::details::AssnsNode< ArtAssnsIterValue > >
 
struct  assns_metadata_type< std::pair< art::Ptr< L >, art::Ptr< R > > >
 
struct  assns_traits
 Data types for the specified association type (or its node). More...
 
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  dereferenced_type
 Class defining the dereferenced type of the specified type. More...
 
class  GaussianFit
 "Fast" Gaussian fit More...
 
struct  identity
 A unary functor returning its own argument (any type) More...
 
class  LinearFit
 Performs a linear regression of data. More...
 
class  MinMaxCollector
 Keeps track of the minimum and maximum value we observed. More...
 
class  QuadraticFit
 Performs a second-degree fit of data. More...
 
struct  RealComparisons
 Provides simple real number checks. More...
 
class  StatCollector
 Collects statistics on a single quantity (weighted) More...
 
class  StatCollector2D
 Collects statistics on two homogeneous quantities (weighted) More...
 
struct  Vector2DComparison
 Class comparing 2D vectors. More...
 
struct  Vector3DComparison
 Class comparing 2D vectors. 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=0)
 Provides projected wire pitch for the view. 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.

Definition at line 214 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.

Definition at line 228 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 260 of file DereferenceIterator.h.

References makeDereferenceIterator().

Referenced by dereferenceIteratorLoop().

261  { 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 386 of file DereferenceIterator.h.

References makeDereferenceConstIterator().

Referenced by dereferenceConstIteratorLoop().

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

Definition at line 391 of file DereferenceIterator.h.

References makeDereferenceConstIterator().

Referenced by dereferenceConstIteratorLoop().

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

Definition at line 396 of file DereferenceIterator.h.

References makeDereferenceConstIterator().

Referenced by dereferenceConstIteratorReverseLoop().

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

Definition at line 401 of file DereferenceIterator.h.

References makeDereferenceConstIterator().

Referenced by dereferenceConstIteratorReverseLoop().

402  { 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.

Referenced by util::PxHitConverter::ToPxHit().

255  {
256  return details::dereference_class
258  }
std::string value(boost::any const &)
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 427 of file DereferenceIterator.h.

References cbeginDereferenceIterator(), cendDereferenceIterator(), and lar::util::detail::makeIteratorBox().

428  {
431  } // 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 463 of file DereferenceIterator.h.

References crbeginDereferenceIterator(), crendDereferenceIterator(), and lar::util::detail::makeIteratorBox().

464  {
467  } // 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 331 of file DereferenceIterator.h.

References beginDereferenceIterator(), endDereferenceIterator(), and lar::util::detail::makeIteratorBox().

332  {
335  } // 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 367 of file DereferenceIterator.h.

References lar::util::detail::makeIteratorBox(), rbeginDereferenceIterator(), and rendDereferenceIterator().

368  {
371  } // 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 274 of file DereferenceIterator.h.

References makeDereferenceIterator().

Referenced by dereferenceIteratorLoop().

275  { 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.

Referenced by cluster::ClusterParamsImportWrapper< Algo >::ImportHits().

294  {
295  return details::make_pointer_class
297  }
std::string value(boost::any const &)
template<typename Iter >
auto lar::util::makeDereferenceConstIterator ( Iter &&  iter)
See also
makeDereferenceIterator

Definition at line 381 of file DereferenceIterator.h.

Referenced by cbeginDereferenceIterator(), cendDereferenceIterator(), crbeginDereferenceIterator(), and crendDereferenceIterator().

382  { 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 246 of file DereferenceIterator.h.

Referenced by beginDereferenceIterator(), endDereferenceIterator(), rbeginDereferenceIterator(), and rendDereferenceIterator().

247  { 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.

References lar::util::RealComparisons< RealType >::threshold.

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.

References lar::util::RealComparisons< RealType >::threshold.

Referenced by checkTPCcoords(), groupTPCsByDriftDir(), geo::TPCGeo::UpdateAfterSorting(), and geo::PlaneGeo::UpdateWireDir().

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 288 of file DereferenceIterator.h.

References makeDereferenceIterator().

Referenced by dereferenceIteratorReverseLoop().

289  { 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 302 of file DereferenceIterator.h.

References makeDereferenceIterator().

Referenced by dereferenceIteratorReverseLoop().

303  { 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 = 0 
)

Provides projected wire pitch for the view.

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, in centimetres

The point of the trajectory with the specified index (by default, the first point of the trajectory) is projected into the specified view, and the effective distance between two wires along the direction the track is pointing to at that point is computed and returned.

Definition at line 76 of file TrackUtils.cxx.

References geo::CryostatID::Cryostat, dir, recob::Track::DirectionAtPoint(), e, geo::CryostatID::isValid, geo::kUnknown, recob::Track::LocationAtPoint(), recob::Track::NumberTrajectoryPoints(), and geo::TPCID::TPC.

Referenced by calo::TrackCalorimetryAlg::AnalyzeHit(), shower::EMShowerAlg::FinddEdx(), calo::GeneralCalorimetry::produce(), calo::Calorimetry::produce(), and TrackProjectedLength().

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 TVector3& 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 TVector3& 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()
Unknown view.
Definition: geo_types.h:83
bool isValid
Whether this ID points to a valid element.
Definition: geo_types.h:129
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:130
The data type to uniquely identify a TPC.
Definition: geo_types.h:195
TDirectory * dir
Definition: macro.C:5
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
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
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 32 of file TrackUtils.cxx.

References recob::Track::DirectionAtPoint(), geo::kUnknown, recob::Track::LocationAtPoint(), recob::Track::NumberTrajectoryPoints(), and TrackPitchInView().

32  {
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 TVector3& pos_cur = track.LocationAtPoint(p);
54  const TVector3& 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 TVector3& 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()
Unknown view.
Definition: geo_types.h:83
Float_t track
Definition: plot.C:34
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33