FindManySpeedTestProducer_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: FindManySpeedTestProducer
3 // Module Type: producer
4 // File: FindManySpeedTestProducer_module.cc
5 //
6 // Generated at Wed Sep 10 13:46:46 2014 by Christopher Green using artmod
7 // from cetpkgsupport v1_07_01.
8 ////////////////////////////////////////////////////////////////////////
9 
18 #include "fhiclcpp/ParameterSet.h"
20 
21 #include <chrono>
22 #include <memory>
23 #include <random>
24 
25 namespace arttest {
26  class FindManySpeedTestProducer;
27 }
28 
30 public:
32 
33 private:
34  void produce(art::Event& e) override;
35 
36  size_t const nTracks_;
37  size_t const nHits_;
38  size_t const pmHitsPerTrack_;
39  std::mt19937_64 gen_;
40 };
41 
43  fhicl::ParameterSet const& p)
44  : EDProducer{p}
45  , nTracks_{p.get<size_t>("nTracks")}
46  , nHits_{p.get<size_t>("nHits")}
47  , pmHitsPerTrack_{p.get<size_t>("pmHitsPerTrack")}
48  , gen_{p.get<size_t>(
49  "randomSeed",
50  std::chrono::system_clock::now().time_since_epoch().count())}
51 {
52  produces<std::vector<arttest::Hit>>();
53  produces<std::vector<arttest::Track>>();
54  produces<art::Assns<arttest::Track, arttest::Hit>>();
55 }
56 
57 void
59 {
60  auto vh_pid = e.getProductID<std::vector<arttest::Hit>>();
61  auto vt_pid = e.getProductID<std::vector<arttest::Track>>();
62 
63  // Hits.
64  auto hits = std::make_unique<std::vector<arttest::Hit>>(nHits_);
65  std::iota(hits->begin(), hits->end(), 0ul);
66  e.put(std::move(hits));
67 
68  // Tracks.
69  auto tracks = std::make_unique<std::vector<arttest::Track>>(nTracks_);
70  std::iota(tracks->begin(), tracks->end(), 0ul);
71  e.put(std::move(tracks));
72 
73  // Assns.
74  auto assns = std::make_unique<art::Assns<arttest::Hit, arttest::Track>>();
75  std::poisson_distribution<size_t> pdist(pmHitsPerTrack_);
76  std::uniform_int_distribution<size_t> udist(0, nHits_);
77  auto pdice = std::bind(pdist, gen_);
78  auto udice = std::bind(udist, gen_);
79  auto hPG = e.productGetter(vh_pid);
80  auto tPG = e.productGetter(vt_pid);
81  for (size_t iTrack = 0; iTrack != nTracks_; ++iTrack) {
82  art::Ptr<arttest::Track> trackPtr(vt_pid, iTrack, tPG);
83 
84  for (size_t i = 0, nHitsTrack = pdice(); i != nHitsTrack; ++i) {
85  assns->addSingle(art::Ptr<arttest::Hit>(vh_pid, udice(), hPG), trackPtr);
86  }
87  }
88  e.put(std::move(assns));
89 }
90 
ProductID getProductID(std::string const &instance_name="") const
Definition: DataViewImpl.h:347
EDProducer()=default
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
EDProductGetter const * productGetter(ProductID const pid) const
FindManySpeedTestProducer(fhicl::ParameterSet const &p)
p
Definition: test.py:228
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:692
Definition: fwd.h:26