10 #include "art/Framework/Core/EDProducer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "canvas/Utilities/InputTag.h"
17 #include "fhiclcpp/ParameterSet.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
43 void produce(art::Event&
e)
override;
58 _merge_period =
p.get<
double>(
"MergePeriod");
59 _simph_producer =
p.get<std::string>(
"SimPhotonsProducer");
60 _spe_area =
p.get<
double>(
"SPEArea");
61 _spe_amp =
p.get<
double>(
"SPEAmplitude");
62 produces<std::vector<recob::OpHit> >();
67 auto oph_v = std::unique_ptr<std::vector<recob::OpHit> >(
new std::vector<recob::OpHit>());
71 art::Handle< std::vector< sim::SimPhotons > > simph_h;
76 art::Handle< std::vector< sim::SimPhotonsLite > > simphlite_h;
81 if(!simph_h.isValid() && !simphlite_h.isValid()) {
82 std::cerr <<
"Could not retrieve sim::SimPhotons or sim::SimPhotonsLite from producer label: " <<
_simph_producer << std::endl;
83 throw std::exception();
85 if(simph_h.isValid() && simphlite_h.isValid()) {
86 std::cerr <<
"Found both sim::SimPhotons and sim::SimPhotonsLite from producer label: " <<
_simph_producer << std::endl;
87 throw std::exception();
92 typedef std::variant<const sim::SimPhotons*, const sim::SimPhotonsLite*> EitherSimPhoton;
93 std::vector<EitherSimPhoton> sim_photons;
94 if(simph_h.isValid()) {
95 sim_photons.reserve(simph_h->size());
96 for(
auto const& simph : *simph_h) {
97 sim_photons.push_back(&simph);
100 else if(simphlite_h.isValid()) {
101 sim_photons.reserve(simphlite_h->size());
102 for(
auto const& simphlite : *simphlite_h) {
103 sim_photons.push_back(&simphlite);
109 std::vector<bool> processed_v;
110 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
111 for(
auto const& simph : sim_photons) {
114 if(simph_h.isValid())
115 opch = std::get<const sim::SimPhotons*>(simph)->OpChannel();
116 else if(simphlite_h.isValid())
117 opch = std::get<const sim::SimPhotonsLite*>(simph)->OpChannel;
119 if(opch >= processed_v.size()) processed_v.resize(opch+1,
false);
120 if(processed_v[opch]) {
121 std::cerr <<
"Found duplicate channels in std::vector<sim::SimPhotons>! not expected (logic will fail).."<<std::endl;
122 throw std::exception();
125 processed_v[opch] =
true;
126 bool in_window =
false;
127 double oph_time = -1.e9;
130 std::map<double,size_t> time_m;
131 if(simph_h.isValid()) {
132 for(
auto const& oneph : *std::get<const sim::SimPhotons*>(simph)) {
133 double this_time = clockData.G4ToElecTime(oneph.Time) - clockData.TriggerTime();
134 time_m[this_time] += 1;
137 else if(simphlite_h.isValid()) {
138 for(
auto const& [ time_ns, nphotons ] : std::get<const sim::SimPhotonsLite*>(simph)->DetectedPhotons) {
139 double this_time = clockData.G4ToElecTime(time_ns + 0.5) - clockData.TriggerTime();
140 time_m[this_time] += nphotons;
145 for(
auto const& time_photon_pair : time_m) {
147 auto const& this_time = time_photon_pair.first;
152 oph_time + clockData.TriggerTime(),
159 oph_v->emplace_back(std::move(oph));
164 if(!in_window) oph_time = this_time;
166 pe += time_photon_pair.second;
171 oph_time + clockData.TriggerTime(),
178 oph_v->emplace_back(std::move(oph));
182 e.put(std::move(oph_v));
BEGIN_PROLOG could also be cerr
std::string _simph_producer
Simulation objects for optical detectors.
ICARUSMCOpHit(fhicl::ParameterSet const &p)
void produce(art::Event &e) override
art framework interface to geometry description
ICARUSMCOpHit & operator=(ICARUSMCOpHit const &)=delete