14 #include "art/Framework/Core/ModuleMacros.h"
15 #include "art/Framework/Core/SharedFilter.h"
16 #include "art/Framework/Principal/Event.h"
17 #include "art/Framework/Principal/Handle.h"
18 #include "fhiclcpp/ParameterSet.h"
29 class FilterSimPhotonLiteTime;
43 bool filter(art::Event&
e, art::ProcessingFrame
const&)
override;
47 std::vector<std::pair<int, int>>
const
59 art::ProcessingFrame
const&)
61 , fSimPhotonsLiteCollectionLabel(
p.get<std::string>(
"SimPhotonsLiteCollectionLabel"))
62 , fTimeWindows(
p.get<
std::vector<std::pair<int, int>>>(
"TimeWindows"))
63 , fMinTotalPhotons(
p.get<
int>(
"MinTotalPhotons"))
64 , fDebug(
p.get<
bool>(
"Debug",
false))
65 , fN(fTimeWindows.size())
66 , fUseReflectedPhotons(
p.get<
bool>(
"UseReflectedPhotons",
false))
67 , fReflectedLabel(
p.get<std::string>(
"ReflectedLabel",
"Reflected"))
75 if (fDebug) { serialize(); }
77 async<art::InEvent>();
86 std::cout <<
"\tFilterSimPhotonLiteTime: TimeWindows size is " << fTimeWindows.size()
89 for (
auto const& tw : fTimeWindows) {
92 <<
"[" << tw.first <<
"," << tw.second <<
"]" << std::endl;
94 if (tw.first > tw.second)
95 throw cet::exception(
"FilterSimPhotonLiteTime::CheckTimeWindows")
96 <<
"Bad time window initialization: tw.first>tw.second. Reverse the order!" << std::endl;
103 auto const& simPhotonsLiteCollection =
104 *e.getValidHandle<std::vector<sim::SimPhotonsLite>>(fSimPhotonsLiteCollectionLabel);
106 std::vector<int> sumNPhotonArray(fN, 0);
108 const std::vector<sim::SimPhotonsLite>& simPhotonsLiteCollectionReflected =
109 fUseReflectedPhotons ? *e.getValidHandle<std::vector<sim::SimPhotonsLite>>(
110 {fSimPhotonsLiteCollectionLabel, fReflectedLabel}) :
111 std::vector<sim::SimPhotonsLite>();
113 size_t n_sim_photons = simPhotonsLiteCollection.size() + simPhotonsLiteCollectionReflected.size();
116 std::cout <<
"New event to filter with total # sim photons: " << n_sim_photons << std::endl;
119 for (
size_t i_pc = 0; i_pc < n_sim_photons; i_pc++) {
121 (i_pc < simPhotonsLiteCollection.size()) ?
122 simPhotonsLiteCollection[i_pc] :
123 simPhotonsLiteCollectionReflected[i_pc - simPhotonsLiteCollection.size()];
126 std::cout <<
"\tFilterSimPhotonLiteTime: Processing simphotonslite channel "
127 << simphotonslite.
OpChannel << std::endl;
130 for (
size_t i_tw = 0; i_tw < fN; i_tw++) {
131 auto const& tw(fTimeWindows[i_tw]);
132 if (photon_pair.first >= tw.first && photon_pair.first <= tw.second) {
135 std::string photon_string =
136 (i_pc < simPhotonsLiteCollection.size()) ?
"Photon" :
"Reflected Photon";
137 std::cout <<
"\t\t" << photon_string <<
" with number " << photon_pair.second
138 <<
" at time " << photon_pair.first <<
" detected." << std::endl;
141 sumNPhotonArray[i_tw] += photon_pair.second;
144 std::cout <<
"\t\tTotal number of photons in this window (" << i_tw <<
") is now "
145 << sumNPhotonArray[i_tw] << std::endl;
147 if (sumNPhotonArray[i_tw] >= fMinTotalPhotons)
return true;
154 std::cout <<
"\tFilterSimPhotonLiteTime: Final total numbers are below min of "
155 << fMinTotalPhotons <<
":" << std::endl;
156 for (
size_t i_tw = 0; i_tw < fN; ++i_tw) {
158 <<
"[" << fTimeWindows[i_tw].first <<
"," << fTimeWindows[i_tw].second
159 <<
"]: " << sumNPhotonArray[i_tw] << std::endl;
FilterSimPhotonLiteTime & operator=(FilterSimPhotonLiteTime const &)=delete
bool filter(art::Event &e, art::ProcessingFrame const &) override
int const fMinTotalPhotons
Minimum number of photons inside a window to pass the filter.
bool const fUseReflectedPhotons
Whether to include reflected photons in the filter.
std::map< int, int > DetectedPhotons
Number of photons detected at each given time: time tick -> photons.
bool const fDebug
Set to true to print (a lot of) debug information.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Simulation objects for optical detectors.
std::string const fReflectedLabel
Label for the reflected photons – "Reflected" by default.
int OpChannel
Optical detector channel associated to this data.
Compact representation of photons on a channel.
std::size_t const fN
Number of time winows.
FilterSimPhotonLiteTime(fhicl::ParameterSet const &p, art::ProcessingFrame const &)
std::string const fSimPhotonsLiteCollectionLabel
Label for the sim::SimPhotonsLite data product.
void CheckTimeWindows() const
BEGIN_PROLOG could also be cout
std::vector< std::pair< int, int > > const fTimeWindows
Time windows used for filtering. Units are the same as in the sim::SimPhotonsLite.