ParticleSimulator_module.cc
Go to the documentation of this file.
1 //--------------------------------------------------------------------
2 //
3 // Main motivation for RunProductProducer is to test product
4 // aggregation.
5 //
6 //--------------------------------------------------------------------
7 
13 #include "fhiclcpp/types/TupleAs.h"
14 
15 #include <cmath>
16 
17 namespace {
18 
19  struct Config {
21  fhicl::Name("inputTag")};
22  };
23 
24  auto
25  get_energies(std::vector<int> const& particle_ids)
26  {
27  // The energy is arbitrarily calculated to be:
28  // abs(pdg_id) + particle_ids.size();
29  auto energies = std::make_unique<std::vector<double>>();
30  auto const energy_offset = static_cast<double>(particle_ids.size());
32  particle_ids, back_inserter(*energies), [&energy_offset](auto const pid) {
33  return std::abs(pid) + energy_offset;
34  });
35  return energies;
36  }
37 
38  class ParticleSimulator : public art::EDProducer {
39  art::ProductToken<std::vector<int>> genParticlesTkn_;
40 
41  public:
42  using Parameters = EDProducer::Table<Config>;
43  explicit ParticleSimulator(Parameters const& config)
44  : EDProducer{config}
45  , genParticlesTkn_{consumes<std::vector<int>>(config().inputTag())}
46  {
47  produces<std::vector<double>>("particleEnergies");
48  produces<arttest::Geometry, art::InRun>("Geometry");
49  }
50 
51  private:
52  void
53  beginRun(art::Run& r) override
54  {
55  r.put(std::make_unique<arttest::Geometry>(r.run()),
56  "Geometry",
57  art::fullRun());
58  }
59 
60  void
61  produce(art::Event& e) override
62  {
63  auto const& genParticles = e.getValidHandle(genParticlesTkn_);
64  e.put(get_energies(*genParticles), "particleEnergies");
65  }
66 
67  }; // ParticleSimulator
68 
69 } // namespace
70 
71 DEFINE_ART_MODULE(ParticleSimulator)
constexpr auto fullRun()
Definition: Run.h:21
T abs(T value)
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:480
RunNumber_t run() const
Definition: DataViewImpl.cc:82
auto transform_all(Container &, OutputIt, UnaryOp)
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:692
AdcRoiViewer::Name Name