All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RemoveIsolatedSpacePoints_module.cc
Go to the documentation of this file.
1 /**
2  * @file RemoveIsolatedSpacePoints_module.cc
3  * @brief Module running `lar::example::SpacePointIsolationAlg` algorithm
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date June 3, 2016
6  * @ingroup RemoveIsolatedSpacePoints
7  *
8  * Provides:
9  *
10  * * `lar::example::RemoveIsolatedSpacePoints` module
11  *
12  */
13 
14 // LArSoft libraries
19 
20 // framework libraries
21 #include "art/Framework/Core/EDProducer.h"
22 #include "art/Framework/Core/ModuleMacros.h"
23 #include "art/Framework/Principal/Event.h"
24 #include "art/Framework/Principal/Handle.h" // art::ValidHandle
25 #include "canvas/Utilities/InputTag.h"
26 #include "messagefacility/MessageLogger/MessageLogger.h"
27 #include "fhiclcpp/types/Atom.h"
28 #include "fhiclcpp/types/Table.h"
29 
30 // C/C++ standard libraries
31 #include <memory> // std::make_unique()
32 
33 
34 namespace lar {
35  namespace example {
36 
37  /**
38  * @brief _art_ module: removes isolated space points.
39  * @see @ref RemoveIsolatedSpacePoints "RemoveIsolatedSpacePoints example overview"
40  * @ingroup RemoveIsolatedSpacePoints
41  *
42  * A new collection of space points is added to the event, that contains
43  * only the space points that are not isolated.
44  *
45  * Isolation is determined by the `SpacePointIsolationAlg` algorithm.
46  *
47  * The space points are not associated to anything.
48  *
49  * Input
50  * ------
51  *
52  * A collection of `recob::SpacePoint` is required.
53  *
54  *
55  * Output
56  * ------
57  *
58  * A collection of `recob::SpacePoint` is produced, containing copies of
59  * the non-isolated inpt points.
60  *
61  *
62  * Configuration parameters
63  * =========================
64  *
65  * * *spacePoints* (input tag, _mandatory_): label of the data product with
66  * input space points
67  * * *isolation* (parameter set, _mandatory_): configuration for the
68  * isolation algorithm (see `SpacePointIsolationAlg` documentation)
69  *
70  */
71  class RemoveIsolatedSpacePoints: public art::EDProducer {
72 
73  public:
74 
75  /// Module configuration data
76  struct Config {
77 
78  using Name = fhicl::Name;
79  using Comment = fhicl::Comment;
80 
81  fhicl::Atom<art::InputTag> spacePoints{
82  Name("spacePoints"),
83  Comment("the space points to be filtered")
84  };
85 
86  fhicl::Table<SpacePointIsolationAlg::Config> isolation{
87  Name("isolation"),
88  Comment("settings for the isolation algorithm")
89  };
90 
91  }; // Config
92 
93  /// Standard _art_ alias for module configuration table
94  using Parameters = art::EDProducer::Table<Config>;
95 
96  /// Constructor; see the class documentation for the configuration
97  explicit RemoveIsolatedSpacePoints(Parameters const& config);
98 
99 
100  virtual void produce(art::Event& event) override;
101 
102 
103  private:
104  art::InputTag spacePointsLabel; ///< label of the input data product
105 
106  SpacePointIsolationAlg isolAlg; ///< instance of the algorithm
107 
108  }; // class RemoveIsolatedSpacePoints
109 
110 
111  } // namespace example
112 } // namespace lar
113 
114 
115 
116 //------------------------------------------------------------------------------
117 //--- RemoveIsolatedSpacePoints
118 //---
120  (Parameters const& config)
121  : EDProducer{config}
122  , spacePointsLabel(config().spacePoints())
123  , isolAlg(config().isolation())
124 {
125  consumes<std::vector<recob::SpacePoint>>(spacePointsLabel);
126  produces<std::vector<recob::SpacePoint>>();
127 } // lar::example::RemoveIsolatedSpacePoints::RemoveIsolatedSpacePoints()
128 
129 
130 //------------------------------------------------------------------------------
132 
133  //
134  // read the input
135  //
136  auto spacePointHandle
137  = event.getValidHandle<std::vector<recob::SpacePoint>>(spacePointsLabel);
138 
139  //
140  // set up the algorithm
141  //
142  auto const* geom = lar::providerFrom<geo::Geometry>();
143  isolAlg.setup(*geom);
144 
145  //
146  // run the algorithm
147  //
148 
149  // the return value is a list of indices of non-isolated space points
150  auto const& spacePoints = *spacePointHandle;
151  std::vector<size_t> socialPointIndices
152  = isolAlg.removeIsolatedPoints(spacePoints);
153 
154  //
155  // extract and save the results
156  //
157  auto socialSpacePoints = std::make_unique<std::vector<recob::SpacePoint>>();
158 
159  socialSpacePoints->reserve(socialPointIndices.size()); // preallocate
160  for (size_t index: socialPointIndices)
161  socialSpacePoints->push_back(spacePoints[index]);
162 
163  mf::LogInfo("RemoveIsolatedSpacePoints")
164  << "Found " << socialSpacePoints->size() << "/" << spacePoints.size()
165  << " isolated space points in '" << spacePointsLabel.encode() << "'";
166 
167  event.put(std::move(socialSpacePoints));
168 
169 } // lar::example::RemoveIsolatedSpacePoints::produce()
170 
171 
172 //------------------------------------------------------------------------------
174 
175 
176 //------------------------------------------------------------------------------
Utilities related to art service access.
fhicl::Table< SpacePointIsolationAlg::Config > isolation
art::InputTag spacePointsLabel
label of the input data product
art module: removes isolated space points.
Algorithm(s) dealing with space point isolation in space.
Algorithm to detect isolated space points.
SpacePointIsolationAlg isolAlg
instance of the algorithm
RemoveIsolatedSpacePoints(Parameters const &config)
Constructor; see the class documentation for the configuration.
BEGIN_PROLOG vertical distance to the surface Name
virtual void produce(art::Event &event) override
art::EDProducer::Table< Config > Parameters
Standard art alias for module configuration table.
art framework interface to geometry description