LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DumpSimPhotonsLite_module.cc
Go to the documentation of this file.
1 
9 // LArSoft libraries
11 
12 // framework libraries
18 #include "fhiclcpp/types/Atom.h"
20 
21 // C/C++ standard libraries
22 #include <iomanip> // std::setw()
23 #include <numeric> // std::accumulate()
24 #include <string>
25 #include <utility> // std::forward()
26 
27 namespace sim {
28  class DumpSimPhotonsLite;
29 } // namespace sim
30 
31 namespace {
32  using namespace fhicl;
33 
35  struct Config {
36  using Name = fhicl::Name;
37  using Comment = fhicl::Comment;
38 
39  fhicl::Atom<art::InputTag> InputPhotons{
40  Name("InputPhotons"),
41  Comment("data product with the SimPhotonsLite to be dumped")};
42 
43  fhicl::Atom<std::string> OutputCategory{
44  Name("OutputCategory"),
45  Comment("name of the output stream (managed by the message facility)"),
46  "DumpSimPhotonsLite" /* default value */
47  };
48 
49  }; // struct Config
50 
51 } // local namespace
52 
54 public:
55  // type to enable module parameters description by art
57 
59  explicit DumpSimPhotonsLite(Parameters const& config);
60 
61  // Plugins should not be copied or assigned.
62  DumpSimPhotonsLite(DumpSimPhotonsLite const&) = delete;
66 
67  // Operates on the event
68  void analyze(art::Event const& event) override;
69 
83  template <typename Stream>
84  void DumpPhoton(Stream&& out,
85  sim::SimPhotonsLite const& photons,
86  std::string indent,
87  std::string firstIndent) const;
88 
89  template <typename Stream>
90  void DumpPhoton(Stream&& out, sim::SimPhotonsLite const& photons, std::string indent = "") const
91  {
92  DumpPhoton(std::forward<Stream>(out), photons, indent, indent);
93  }
94 
95 private:
97  std::string fOutputCategory;
98 
99 }; // class sim::DumpSimPhotonsLite
100 
101 //------------------------------------------------------------------------------
102 //--- module implementation
103 //---
104 //------------------------------------------------------------------------------
106  : EDAnalyzer(config)
107  , fInputPhotons(config().InputPhotons())
108  , fOutputCategory(config().OutputCategory())
109 {}
110 
111 //------------------------------------------------------------------------------
112 template <typename Stream>
114  sim::SimPhotonsLite const& photons,
115  std::string indent,
116  std::string firstIndent) const
117 {
118 
119  unsigned int const nPhotons =
120  std::accumulate(photons.DetectedPhotons.begin(),
121  photons.DetectedPhotons.end(),
122  0U,
123  [](auto sum, auto const& entry) { return sum + entry.second; });
124 
125  out << firstIndent << "channel=" << photons.OpChannel << " has ";
126  if (nPhotons) {
127  out << nPhotons << " photons (format: [tick] photons):";
128  constexpr unsigned int PageSize = 5;
129  unsigned int pager = 0;
130  for (auto const& pair : photons.DetectedPhotons) {
131  if (pager-- == 0) {
132  pager = PageSize - 1;
133  out << "\n" << indent << " ";
134  }
135  out << " [" << pair.first << "] " << std::setw(6) << pair.second;
136  } // for
137  }
138  else {
139  out << "no photons";
140  }
141 
142 } // sim::DumpSimPhotonsLite::DumpPhoton()
143 
144 //------------------------------------------------------------------------------
146 {
147 
148  // get the particles from the event
149  auto const& Photons = *(event.getValidHandle<std::vector<sim::SimPhotonsLite>>(fInputPhotons));
150 
152  << "Event " << event.id() << " : data product '" << fInputPhotons.encode() << "' contains "
153  << Photons.size() << " SimPhotonsLite";
154 
155  unsigned int iChannel = 0;
156  for (sim::SimPhotonsLite const& photons : Photons) {
157 
159  // a bit of a header
160  log << "[#" << (iChannel++) << "] ";
161  DumpPhoton(log, photons, " ");
162 
163  } // for
164  mf::LogVerbatim(fOutputCategory) << "\n"; // just an empty line
165 
166 } // sim::DumpSimPhotonsLite::analyze()
167 
168 //------------------------------------------------------------------------------
170 
171 //------------------------------------------------------------------------------
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
DumpSimPhotonsLite & operator=(DumpSimPhotonsLite const &)=delete
std::string encode() const
Definition: InputTag.cc:97
art::InputTag fInputPhotons
name of SimPhotons&#39;s data product
std::map< int, int > DetectedPhotons
Number of photons detected at each given time: time tick -> photons.
Definition: SimPhotons.h:109
Simulation objects for optical detectors.
DumpSimPhotonsLite(Parameters const &config)
Configuration-checking constructor.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
parameter set interface
std::string indent(std::size_t const i)
int OpChannel
Optical detector channel associated to this data.
Definition: SimPhotons.h:106
Monte Carlo Simulation.
void DumpPhoton(Stream &&out, sim::SimPhotonsLite const &photons, std::string indent="") const
Compact representation of photons on a channel.
Definition: SimPhotons.h:98
void analyze(art::Event const &event) override
Double_t sum
Definition: plot.C:31
void DumpPhoton(Stream &&out, sim::SimPhotonsLite const &photons, std::string indent, std::string firstIndent) const
Dumps the content of specified SimPhotonsLite in the output stream.
Event finding and building.
std::string fOutputCategory
name of the stream for output