ChargedSpacePointProxyInputMaker_module.cc
Go to the documentation of this file.
1 /**
2  * @file ChargedSpacePointProxyInputMaker_module.cc
3  * @brief Test producer creating a few dummy space points and charges.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date December 20, 2017
6  *
7  */
8 
9 // LArSoft libraries
13 
14 // framework libraries
18 
20 #include "fhiclcpp/types/Atom.h"
21 #include "fhiclcpp/types/Name.h"
22 #include "fhiclcpp/types/Comment.h"
23 
24 // Boost libraries
25 #include "boost/test/unit_test.hpp"
26 
27 // C/C++ standard libraries
28 #include <memory> // std::make_unique()
29 
30 
31 namespace lar {
32  namespace test {
33 
34  // -------------------------------------------------------------------------
35  /**
36  * @brief Creates some dummy space points and charge.
37  *
38  * The produced space points and charges have completely dummy content.
39  * They are implicitly associated and the amount of charge is as much as
40  * the ID of the space point.
41  *
42  * Configuration parameters
43  * =========================
44  *
45  * * *nPoints* (unsigned integer, default: 10): number of space points to
46  * generate
47  *
48  */
50  public:
51 
52  struct Config {
53  using Name = fhicl::Name;
55 
57  Name("nPoints"),
58  Comment("number of points to generate."),
59  10U // default
60  };
61 
62  }; // struct Config
63 
65 
67 
68  virtual void produce(art::Event& event) override;
69 
70  private:
71  unsigned int nPoints; ///< Number of points to generate.
72 
73  }; // ChargedSpacePointProxyInputMaker
74 
75  // -------------------------------------------------------------------------
76 
77 
78  } // namespace test
79 } // namespace lar
80 
81 
82 // -----------------------------------------------------------------------------
84  (Parameters const& config)
85  : EDProducer{config}
86  , nPoints(config().nPoints())
87 {
88 
89  // declare production of recob::SpacePoint and recob::PointCharge collections:
91 
92 } // ChargedSpacePointProxyInputMaker::ChargedSpacePointProxyInputMaker()
93 
94 // -----------------------------------------------------------------------------
96 
98 
99  BOOST_TEST(spacePoints.empty());
100 
101  const double err[6U] = { 1.0, 0.0, 1.0, 0.0, 0.0, 1.0 };
102 
103  for (unsigned int iPoint = 0; iPoint < nPoints; ++iPoint) {
104  BOOST_TEST(spacePoints.size() == (std::size_t) iPoint);
105 
106  double const pos[3U]
107  = { double(iPoint), double(2.0 * iPoint), double(4.0 * iPoint) };
108 
109  spacePoints.add(
110  { pos, err, 1.0 /* chisq */, int(iPoint) /* id */ }, // space point
111  { recob::PointCharge::Charge_t(iPoint) } // charge
112  );
113 
114  mf::LogVerbatim("ChargedSpacePointProxyInputMaker")
115  << "[#" << iPoint << "] point: " << spacePoints.lastSpacePoint()
116  << " (ptr: " << spacePoints.lastSpacePointPtr()
117  << "); charge: " << spacePoints.lastCharge()
118  << " (ptr: " << spacePoints.lastChargePtr() << ")";
119 
120  } // for (iPoint)
121  BOOST_TEST(spacePoints.size() == (std::size_t) nPoints);
122 
123  mf::LogInfo("ChargedSpacePointProxyInputMaker")
124  << "Produced " << spacePoints.size() << " points and charges.";
125 
126  spacePoints.put();
127  BOOST_TEST(spacePoints.empty());
128 
129 } // lar::test::ChargedSpacePointProxyInputMaker::produce()
130 
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
static void produces(art::ProducesCollector &producesCollector, std::string const &instanceName={})
Declares the data products being produced.
ChannelGroupService::Name Name
Information about charge reconstructed in the active volume.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
static Config * config
Definition: config.cpp:1054
float Charge_t
Type for the amount of reconstructed charge.
Definition: PointCharge.h:35
void err(const char *fmt,...)
Definition: message.cpp:226
ProducesCollector & producesCollector() noexcept
static ChargedSpacePointCollectionCreator forPtrs(art::Event &event, std::string const &instanceName={})
Static function binding a new object to a specific art event.
#define Comment
LArSoft-specific namespace.
Helpers to create space points with associated charge.
Event finding and building.