PxHitConverter.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file PxHitConverter.h
3 //
4 // \brief conversion utulities from recob::Hit to PxHit
5 //
6 // \author andrzej.szelc@yale.edu, based on LarLite code by Kazu
7 //
8 ////////////////////////////////////////////////////////////////////////
9 
10 #ifndef UTIL_PXHITCONVERTER_H
11 #define UTIL_PXHITCONVERTER_H
12 
13 #include "PxUtils.h"
16 
18 
19 #include <algorithm>
20 #include <type_traits>
21 #include <vector>
22 
23 ///General LArSoft Utilities
24 namespace util {
25  class GeometryUtilities;
26 
28  public:
29  explicit PxHitConverter(GeometryUtilities const& geomUtils);
30 
31  /// Generate: from 1 set of hits => 1 set of PxHits using indexes (association)
32  void GeneratePxHit(const std::vector<unsigned int>& hit_index,
34  std::vector<PxHit>& pxhits) const;
35 
36  /// Generate: from 1 set of hits => 1 set of PxHits using using all hits
38  std::vector<PxHit>& pxhits) const;
39 
40  void GenerateSinglePxHit(art::Ptr<recob::Hit> const& hit, PxHit& pxhits) const;
41 
42  /// Generates and returns a PxHit out of a recob::Hit
43  PxHit HitToPxHit(recob::Hit const& hit) const;
44 
45  /// Generates and returns a PxHit out of a pointer to recob::Hit
46  /// or a hit itself
47  template <typename HitObj>
48  PxHit ToPxHit(HitObj const& hit) const;
49 
50  /// Returns a vector of PxHit out of a vector of hits
51  template <typename Cont, typename Hit = typename Cont::value_type>
52  std::vector<PxHit> ToPxHitVector(Cont const& hits) const;
53 
54  private:
56  }; // class PxHitConverter
57 
58 } //namespace util
59 
60 //******************************************************************************
61 //*** Template implementation
62 //***
63 template <typename HitObj>
65 util::PxHitConverter::ToPxHit(HitObj const& hit) const
66 {
67  // check that the argument is an object convertible to a recob::Hit,
68  // or it is a pointer to such an object
69  static_assert(
70  std::is_convertible<typename lar::util::dereferenced_type<HitObj>::type, recob::Hit>::value,
71  "The argument to PxHitConverter::ToPxHit() does not point to a recob::Hit");
73 } // PxHitConverter::ToPxHit()
74 
75 template <typename Cont, typename Hit /* = typename Cont::value_type */>
76 std::vector<util::PxHit>
77 util::PxHitConverter::ToPxHitVector(Cont const& hits) const
78 {
79  std::vector<PxHit> pxhits;
80  pxhits.reserve(hits.size());
81  std::transform(hits.begin(), hits.end(), std::back_inserter(pxhits), [this](Hit const& hit) {
82  return this->ToPxHit(hit);
83  });
84  return pxhits;
85 } // util::PxHitConverter::ToPxHitVector()
86 
87 #endif // UTIL_PXHITCONVERTER_H
Namespace for general, non-LArSoft-specific utilities.
GeometryUtilities const & fGeomUtils
struct vector vector
PxHit ToPxHit(HitObj const &hit) const
PxHitConverter(GeometryUtilities const &geomUtils)
void GenerateSinglePxHit(art::Ptr< recob::Hit > const &hit, PxHit &pxhits) const
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.
Definition: Dereference.h:254
void GeneratePxHit(const std::vector< unsigned int > &hit_index, const std::vector< art::Ptr< recob::Hit >> hits, std::vector< PxHit > &pxhits) const
Generate: from 1 set of hits => 1 set of PxHits using indexes (association)
std::vector< PxHit > ToPxHitVector(Cont const &hits) const
Returns a vector of PxHit out of a vector of hits.
PxHit HitToPxHit(recob::Hit const &hit) const
Generates and returns a PxHit out of a recob::Hit.
Detector simulation of raw signals on wires.
Declaration of signal hit object.
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48