LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
FilterSimPhotonTime_module.cc
Go to the documentation of this file.
1 // Class: FilterSimPhotonTime
3 // Module Type: filter
4 // File: FilterSimPhotonTime_module.cc
5 //
6 // Generated at Tue Jan 19 09:42:51 2016 by Wesley Ketchum using artmod
7 // from cetpkgsupport v1_10_01.
9 
14 #include "fhiclcpp/ParameterSet.h"
15 
16 #include <iostream>
17 #include <memory>
18 #include <string>
19 #include <utility>
20 #include <vector>
21 
23 
24 namespace simfilter {
25  class FilterSimPhotonTime;
26 }
27 
29 public:
31 
32  // Plugins should not be copied or assigned.
37 
38 private:
39  bool filter(art::Event& e, art::ProcessingFrame const&) override;
40 
41  std::string const fSimPhotonsCollectionLabel;
42  std::vector<std::pair<float, float>> const fTimeWindows;
43  float const fMinTotalEnergy;
44  float const fMinPhotonEnergy;
45  bool const fDebug;
46  std::size_t const fN;
48  std::string const fReflectedLabel;
49 
50  void CheckTimeWindows() const;
51 };
52 
54  art::ProcessingFrame const&)
55  : SharedFilter{p}
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"))
64 {
66 
67  // For printing out debug messages, we want to serialize the
68  // event-level calls so that the messages are not garbled.
69  // Otherwise, this module works well for asynchronous event-level
70  // calls.
71  if (fDebug) { serialize(); }
72  else {
73  async<art::InEvent>();
74  }
75 }
76 
78 {
79 
80  if (fDebug)
81  std::cout << "\tFilterSimPhotonTime: TimeWindows size is " << fTimeWindows.size() << std::endl;
82 
83  for (auto const& tw : fTimeWindows) {
84  if (fDebug)
85  std::cout << "\t\tTimeWindow "
86  << "[" << tw.first << "," << tw.second << "]" << std::endl;
87 
88  if (tw.first > tw.second)
89  throw cet::exception("FilterSimPhotonTime::CheckTimeWindows")
90  << "Bad time window initialization: tw.first>tw.second. Reverse the order!" << std::endl;
91  }
92 }
93 
95 {
96  auto const& simPhotonsCollection =
97  *e.getValidHandle<std::vector<sim::SimPhotons>>(fSimPhotonsCollectionLabel);
98 
99  std::vector<double> sumEnergyArray(fN, 0.0);
100 
101  const std::vector<sim::SimPhotons>& simPhotonsCollectionReflected =
102  fUseReflectedPhotons ? *e.getValidHandle<std::vector<sim::SimPhotons>>(
104  std::vector<sim::SimPhotons>();
105 
106  size_t n_sim_photons = simPhotonsCollection.size() + simPhotonsCollectionReflected.size();
107 
108  for (size_t i_pc = 0; i_pc < n_sim_photons; i_pc++) {
109  const sim::SimPhotons& simphotons =
110  (i_pc < simPhotonsCollection.size()) ?
111  simPhotonsCollection[i_pc] :
112  simPhotonsCollectionReflected[i_pc - simPhotonsCollection.size()];
113 
114  if (fDebug)
115  std::cout << "\tFilterSimPhotonTime: Processing simphotons channel " << simphotons.OpChannel()
116  << std::endl;
117 
118  for (auto const& photon : simphotons)
119  for (size_t i_tw = 0; i_tw < fN; i_tw++) {
120  auto const& tw(fTimeWindows[i_tw]);
121  if (photon.Time >= tw.first && photon.Time <= tw.second &&
122  photon.Energy > fMinPhotonEnergy) {
123 
124  if (fDebug) {
125  std::string photon_string =
126  (i_pc < simPhotonsCollection.size()) ? "Photon" : "Reflected Photon";
127  std::cout << "\t\t" << photon_string << " with time " << photon.Time << " detected. "
128  << "Energy is " << photon.Energy << "." << std::endl;
129  }
130 
131  sumEnergyArray[i_tw] += photon.Energy;
132 
133  if (fDebug)
134  std::cout << "\t\tTotal energy in this window (" << i_tw << ") is now "
135  << sumEnergyArray[i_tw] << std::endl;
136 
137  if (sumEnergyArray[i_tw] > fMinTotalEnergy) return true;
138  }
139  }
140  }
141 
142  if (fDebug) {
143  std::cout << "\tFilterSimPhotonTime: Final total energies are below min of " << fMinTotalEnergy
144  << ":" << std::endl;
145  for (size_t i_tw = 0; i_tw < fN; ++i_tw) {
146  std::cout << "\t\tTimeWindow "
147  << "[" << fTimeWindows[i_tw].first << "," << fTimeWindows[i_tw].second
148  << "]: " << sumEnergyArray[i_tw] << std::endl;
149  }
150  }
151 
152  return false;
153 }
154 
FilterSimPhotonTime(fhicl::ParameterSet const &p, art::ProcessingFrame const &)
int OpChannel() const
Returns the optical channel number this object is associated to.
Definition: SimPhotons.h:239
std::vector< std::pair< float, float > > const fTimeWindows
SharedFilter(fhicl::ParameterSet const &pset)
Definition: SharedFilter.cc:6
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
Simulation objects for optical detectors.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
bool filter(art::Event &e, art::ProcessingFrame const &) override
Collection of photons which recorded on one channel.
Definition: SimPhotons.h:127
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
void serialize(T const &...)
Framework includes.
Float_t e
Definition: plot.C:35
FilterSimPhotonTime & operator=(FilterSimPhotonTime const &)=delete
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33