10 #include "art/Framework/Core/ModuleMacros.h"
11 #include "art/Framework/Core/SharedFilter.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "fhiclcpp/ParameterSet.h"
25 class FilterSimPhotonTime;
39 bool filter(art::Event&
e, art::ProcessingFrame
const&)
override;
54 art::ProcessingFrame
const&)
56 , fSimPhotonsCollectionLabel(
p.get<std::string>(
"SimPhotonsCollectionLabel"))
57 , fTimeWindows(
p.get<
std::vector<std::pair<float, float>>>(
"TimeWindows"))
58 , fMinTotalEnergy(
p.get<
float>(
"MinTotalEnergy", 0.0))
59 , fMinPhotonEnergy(
p.get<
float>(
"MinPhotonEnergy", -1))
60 , fDebug(
p.get<
bool>(
"Debug",
false))
61 , fN(fTimeWindows.size())
62 , fUseReflectedPhotons(
p.get<
bool>(
"UseReflectedPhotons",
false))
63 , fReflectedLabel(
p.get<std::string>(
"ReflectedLabel",
"Reflected"))
71 if (fDebug) { serialize(); }
73 async<art::InEvent>();
82 std::cout <<
"\tFilterSimPhotonTime: TimeWindows size is " << fTimeWindows.size() << std::endl;
84 for (
auto const& tw : fTimeWindows) {
87 <<
"[" << tw.first <<
"," << tw.second <<
"]" << std::endl;
89 if (tw.first > tw.second)
90 throw cet::exception(
"FilterSimPhotonTime::CheckTimeWindows")
91 <<
"Bad time window initialization: tw.first>tw.second. Reverse the order!" << std::endl;
98 auto const& simPhotonsCollection =
99 *e.getValidHandle<std::vector<sim::SimPhotons>>(fSimPhotonsCollectionLabel);
101 std::vector<double> sumEnergyArray(fN, 0.0);
103 const std::vector<sim::SimPhotons>& simPhotonsCollectionReflected =
104 fUseReflectedPhotons ? *e.getValidHandle<std::vector<sim::SimPhotons>>(
105 {fSimPhotonsCollectionLabel, fReflectedLabel}) :
106 std::vector<sim::SimPhotons>();
108 size_t n_sim_photons = simPhotonsCollection.size() + simPhotonsCollectionReflected.size();
110 for (
size_t i_pc = 0; i_pc < n_sim_photons; i_pc++) {
112 (i_pc < simPhotonsCollection.size()) ?
113 simPhotonsCollection[i_pc] :
114 simPhotonsCollectionReflected[i_pc - simPhotonsCollection.size()];
117 std::cout <<
"\tFilterSimPhotonTime: Processing simphotons channel " << simphotons.
OpChannel()
120 for (
auto const&
photon : simphotons)
121 for (
size_t i_tw = 0; i_tw < fN; i_tw++) {
122 auto const& tw(fTimeWindows[i_tw]);
123 if (
photon.Time >= tw.first &&
photon.Time <= tw.second &&
124 photon.Energy > fMinPhotonEnergy) {
127 std::string photon_string =
128 (i_pc < simPhotonsCollection.size()) ?
"Photon" :
"Reflected Photon";
129 std::cout <<
"\t\t" << photon_string <<
" with time " <<
photon.Time <<
" detected. "
130 <<
"Energy is " <<
photon.Energy <<
"." << std::endl;
133 sumEnergyArray[i_tw] +=
photon.Energy;
136 std::cout <<
"\t\tTotal energy in this window (" << i_tw <<
") is now "
137 << sumEnergyArray[i_tw] << std::endl;
139 if (sumEnergyArray[i_tw] > fMinTotalEnergy)
return true;
145 std::cout <<
"\tFilterSimPhotonTime: Final total energies are below min of " << fMinTotalEnergy
147 for (
size_t i_tw = 0; i_tw < fN; ++i_tw) {
149 <<
"[" << fTimeWindows[i_tw].first <<
"," << fTimeWindows[i_tw].second
150 <<
"]: " << sumEnergyArray[i_tw] << std::endl;
float const fMinTotalEnergy
process_name can override from command line with o or output photon
FilterSimPhotonTime(fhicl::ParameterSet const &p, art::ProcessingFrame const &)
int OpChannel() const
Returns the optical channel number this object is associated to.
std::vector< std::pair< float, float > > const fTimeWindows
std::string const fReflectedLabel
std::string const fSimPhotonsCollectionLabel
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Simulation objects for optical detectors.
float const fMinPhotonEnergy
bool filter(art::Event &e, art::ProcessingFrame const &) override
Collection of photons which recorded on one channel.
void CheckTimeWindows() const
bool const fUseReflectedPhotons
FilterSimPhotonTime & operator=(FilterSimPhotonTime const &)=delete
BEGIN_PROLOG could also be cout