All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SpacePointIsolationAlg.h
Go to the documentation of this file.
1 /**
2  * @file SpacePointIsolationAlg.h
3  * @brief Algorithm(s) dealing with space point isolation in space
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date May 26, 2016
6  * @ingroup RemoveIsolatedSpacePoints
7  *
8  */
9 
10 #ifndef LAREXAMPLES_ALGORITHMS_REMOVEISOLATEDSPACEPOINTS_SPACEPOINTISOLATIONALG_H
11 #define LAREXAMPLES_ALGORITHMS_REMOVEISOLATEDSPACEPOINTS_SPACEPOINTISOLATIONALG_H
12 
13 
14 // LArSoft libraries
17 
18 
19 // infrastructure and utilities
20 #include "cetlib/pow.h" // cet::square()
21 #include "fhiclcpp/types/Comment.h"
22 #include "fhiclcpp/types/Name.h"
23 #include "fhiclcpp/types/Atom.h"
24 #include "fhiclcpp/types/Table.h"
25 #include "fhiclcpp/ParameterSet.h"
26 
27 // C/C++ standard libraries
28 #include <vector>
29 #include <type_traits> // std::decay_t<>, std::is_base_of<>
30 #include <memory> // std::unique_ptr<>
31 
32 
33 // forward declarations
34 namespace geo { class GeometryCore; }
35 
36 
37 namespace lar {
38  namespace example {
39 
40  // BEGIN RemoveIsolatedSpacePoints group -----------------------------------
41  /// @ingroup RemoveIsolatedSpacePoints
42  /// @{
43  /**
44  * @brief Algorithm to detect isolated space points.
45  * @see @ref RemoveIsolatedSpacePoints "RemoveIsolatedSpacePoints example overview"
46  *
47  * This algorithm applies the isolation algorithm implemented in
48  * `PointIsolationAlg` to a collection of `recob::SpacePoint` objects.
49  *
50  * Usage example
51  * --------------
52  *
53  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54  * //
55  * // preparation
56  * //
57  *
58  * // get the algorithm configuration; in art:
59  * fhicl::ParameterSet config
60  * = pset.get<fhicl::ParameterSet>("isolation");
61  *
62  * // get the geometry service provider; in art:
63  * geo::GeometryCore const* geom = lar::providerFrom<geo::Geometry>();
64  *
65  * // get the input data; in art:
66  * std::vector<recob::SpacePoint> const& points
67  * = *(event.getValidHandle<std::vector<recob::SpacePoint>>("sps"));
68  *
69  * //
70  * // algorithm execution
71  * //
72  *
73  * // construct and configure
74  * lar::examples::SpacePointIsolationAlg algo(config);
75  *
76  * // set up
77  * // (might be needed again if geometry changed, e.g. between runs)
78  * algo.Setup(*geom);
79  *
80  * // execution
81  * std::vector<size_t> nonIsolatedPointIndices
82  * = algo.removeIsolatedPoints(points);
83  *
84  * //
85  * // use of results
86  * //
87  *
88  * // e.g. create a collection of pointers to non-isolated points
89  * std::vector<recob::SpacePoint const*> nonIsolatedPoints;
90  * nonIsolatedPoints.reserve(nonIsolatedPointIndices.size());
91  * recob::SpacePoint const* basePoint = &(points.front());
92  * for (size_t index: nonIsolatedPointIndices)
93  * nonIsolatedPoints.push_back(basePoint + index);
94  *
95  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96  *
97  *
98  * Configuration parameters
99  * =========================
100  *
101  * * *radius* (real, mandatory): isolation radius [cm]
102  *
103  */
105 
106  public:
107  /// Type of coordinate in recob::SpacePoint (`double` in LArSoft 5)
108  using Coord_t = std::decay_t<decltype(recob::SpacePoint().XYZ()[0])>;
109 
110 
111  /// Algorithm configuration
112  struct Config {
113 
114  using Name = fhicl::Name;
115  using Comment = fhicl::Comment;
116 
117  fhicl::Atom<double> radius{
118  Name("radius"),
119  Comment("the radius for the isolation [cm]")
120  };
121 
122  }; // Config
123 
124 
125  /// @{
126  /// @name Construction and configuration
127 
128  /**
129  * @brief Constructor with configuration validation
130  * @param config configuration parameter structure
131  *
132  * For the configuration, see `SpacePointIsolationAlg` documentation.
133  */
135  : radius2(cet::square(config.radius()))
136  {}
137 
138  /**
139  * @brief Constructor with configuration validation
140  * @param pset FHiCL configuration parameter set
141  * @see SpacePointIsolationAlg(Config const&)
142  *
143  * Translates the parameter set into a configuration object and uses the
144  * validating constructor to initialise the object.
145  *
146  * For the configuration, see `SpacePointIsolationAlg` documentation.
147  */
148  SpacePointIsolationAlg(fhicl::ParameterSet const& pset)
149  : SpacePointIsolationAlg(fhicl::Table<Config>(pset, {})())
150  {}
151 
152  /// @}
153 
154  /// @{
155  /// @name Set up
156 
157  /**
158  * @brief Sets up the algorithm
159  * @param geometry the geometry service provider
160  *
161  * Acquires the geometry description.
162  * This method must be called every time the geometry is changed.
163  */
164  void setup(geo::GeometryCore const& geometry)
165  { geom = &geometry; initialize(); }
166 
167  /// @}
168 
169 
170  /**
171  * @brief Returns the set of reconstructed 3D points that are not isolated
172  * @tparam PointIter random access iterator to a space point
173  * @param begin iterator to the first point to be considered
174  * @param end iterator after the last point to be considered
175  * @return a list of indices of non-isolated points in the input range
176  * @see PointIsolationAlg::removeIsolatedPoints(PointIter, PointIter) const
177  *
178  * This method can use iterators from any collection of input space
179  * points.
180  */
181  template <typename PointIter>
182  std::vector<size_t> removeIsolatedPoints
183  (PointIter begin, PointIter end) const
184  {
185  static_assert(
186  std::is_base_of<recob::SpacePoint, std::decay_t<decltype(*begin)>>::value,
187  "iterator does not point to recob::SpacePoint"
188  );
189  return isolationAlg->removeIsolatedPoints(begin, end);
190  }
191 
192 
193  /**
194  * @brief Returns the set of reconstructed 3D points that are not isolated
195  * @param points list of the reconstructed space points
196  * @return a list of indices of non-isolated points in the vector
197  * @see removeIsolatedPoints(PointIter, PointIter) const
198  */
199  std::vector<size_t> removeIsolatedPoints
200  (std::vector<recob::SpacePoint> const& points) const
201  { return removeIsolatedPoints(points.begin(), points.end()); }
202 
203 
204 
205  private:
206  /// Type of isolation algorithm
207  using PointIsolationAlg_t = PointIsolationAlg<Coord_t>;
208 
209  /// Pointer to the geometry to be used
210  geo::GeometryCore const* geom = nullptr;
211 
212  Coord_t radius2; ///< square of isolation radius [cm^2]
213 
214  /// the actual generic algorithm
215  std::unique_ptr<PointIsolationAlg_t> isolationAlg;
216 
217  /// Initialises the algorithm with the current configuration and setup
218  void initialize();
219 
220  /// Detects the boundaries of the volume to be sorted from the geometry
222  (PointIsolationAlg_t::Configuration_t& config);
223 
224  }; // class SpacePointIsolationAlg
225 
226 
227  //--------------------------------------------------------------------------
228  //--- PositionExtractor<recob::SpacePoint>
229 
230  /**
231  * @brief Specialization of PositionExtractor for recob::SpacePoint
232  *
233  * This class extracts coordinates from `recob::SpacePoint::XYZ()` method.
234  */
235  template <>
236  struct PositionExtractor<recob::SpacePoint> {
237 
238  /// Return x coordinate of the space point position
239  static double x(recob::SpacePoint const& p) { return p.XYZ()[0]; }
240 
241  /// Return y coordinate of the space point position
242  static double y(recob::SpacePoint const& p) { return p.XYZ()[1]; }
243 
244  /// Return z coordinate of the space point position
245  static double z(recob::SpacePoint const& p) { return p.XYZ()[2]; }
246 
247  }; // PositionExtractor<recob::SpacePoint>
248 
249  /// @}
250  // END RemoveIsolatedSpacePoints group -------------------------------------
251 
252  } // namespace example
253 } // namespace lar
254 
255 
256 
257 
258 
259 #endif // LAREXAMPLES_ALGORITHMS_REMOVEISOLATEDSPACEPOINTS_SPACEPOINTISOLATIONALG_H
then source grid fermiapp products dune setup_dune_fermiapp sh exit else echo No setup file found exit fi setup
SpacePointIsolationAlg(fhicl::ParameterSet const &pset)
Constructor with configuration validation.
Coord_t radius2
square of isolation radius [cm^2]
const geo::GeometryCore * geometry
static double x(recob::SpacePoint const &p)
Return x coordinate of the space point position.
std::decay_t< decltype(recob::SpacePoint().XYZ()[0])> Coord_t
Type of coordinate in recob::SpacePoint (double in LArSoft 5)
pdgs p
Definition: selectors.fcl:22
Helper extractor for point coordinates.
void initialize()
Initialises the algorithm with the current configuration and setup.
Algorithm to detect isolated space points.
void fillAlgConfigFromGeometry(PointIsolationAlg_t::Configuration_t &config)
Detects the boundaries of the volume to be sorted from the geometry.
std::unique_ptr< PointIsolationAlg_t > isolationAlg
the actual generic algorithm
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
BEGIN_PROLOG vertical distance to the surface Name
const Double32_t * XYZ() const
Definition: SpacePoint.h:76
Description of geometry of one entire detector.
static double y(recob::SpacePoint const &p)
Return y coordinate of the space point position.
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
Algorithm(s) dealing with point isolation in space.
temporary value
static double z(recob::SpacePoint const &p)
Return z coordinate of the space point position.
SpacePointIsolationAlg(Config const &config)
Constructor with configuration validation.
geo::GeometryCore const * geom
Pointer to the geometry to be used.