LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
DumpSimPhotonsLite_module.cc
Go to the documentation of this file.
1 
10 // LArSoft libraries
12 
13 // framework libraries
19 #include "fhiclcpp/ParameterSet.h"
20 #include "fhiclcpp/types/Atom.h"
22 
23 // C/C++ standard libraries
24 #include <string>
25 #include <vector>
26 #include <iomanip> // std::setw()
27 #include <algorithm> // std::accumulate()
28 #include <utility> // std::forward()
29 
30 
31 namespace sim {
32  class DumpSimPhotonsLite;
33 } // namespace sim
34 
35 
36 namespace {
37  using namespace fhicl;
38 
40  struct Config {
41  using Name = fhicl::Name;
42  using Comment = fhicl::Comment;
43 
44  fhicl::Atom<art::InputTag> InputPhotons {
45  Name("InputPhotons"),
46  Comment("data product with the SimPhotonsLite to be dumped")
47  };
48 
49  fhicl::Atom<std::string> OutputCategory {
50  Name("OutputCategory"),
51  Comment("name of the output stream (managed by the message facility)"),
52  "DumpSimPhotonsLite" /* default value */
53  };
54 
55  }; // struct Config
56 
57 
58 } // local namespace
59 
60 
62  public:
63  // type to enable module parameters description by art
65 
67  explicit DumpSimPhotonsLite(Parameters const& config);
68 
69  // Plugins should not be copied or assigned.
70  DumpSimPhotonsLite(DumpSimPhotonsLite const&) = delete;
74 
75 
76  // Operates on the event
77  void analyze(art::Event const& event) override;
78 
79 
93  template <typename Stream>
94  void DumpPhoton(
95  Stream&& out, sim::SimPhotonsLite const& photons,
96  std::string indent, std::string firstIndent
97  ) const;
98 
99  template <typename Stream>
100  void DumpPhoton
101  (Stream&& out, sim::SimPhotonsLite const& photons, std::string indent = "")
102  const
103  { DumpPhoton(std::forward<Stream>(out), photons, indent, indent); }
104 
105 
106  private:
107 
109  std::string fOutputCategory;
110 
111 }; // class sim::DumpSimPhotonsLite
112 
113 
114 //------------------------------------------------------------------------------
115 //--- module implementation
116 //---
117 //------------------------------------------------------------------------------
119  : EDAnalyzer(config)
120  , fInputPhotons(config().InputPhotons())
121  , fOutputCategory(config().OutputCategory())
122 {}
123 
124 //------------------------------------------------------------------------------
125 template <typename Stream>
127  Stream&& out, sim::SimPhotonsLite const& photons,
128  std::string indent, std::string firstIndent
129 ) const {
130 
131  unsigned int const nPhotons = std::accumulate(
132  photons.DetectedPhotons.begin(), photons.DetectedPhotons.end(),
133  0U, [](auto sum, auto const& entry){ return sum + entry.second; }
134  );
135 
136  out << firstIndent
137  << "channel=" << photons.OpChannel << " has ";
138  if (nPhotons) {
139  out << nPhotons << " photons (format: [tick] photons):";
140  constexpr unsigned int PageSize = 5;
141  unsigned int pager = 0;
142  for (auto const& pair: photons.DetectedPhotons) {
143  if (pager-- == 0) {
144  pager = PageSize - 1;
145  out << "\n" << indent << " ";
146  }
147  out << " [" << pair.first << "] " << std::setw(6) << pair.second;
148  } // for
149  }
150  else {
151  out << "no photons";
152  }
153 
154 } // sim::DumpSimPhotonsLite::DumpPhoton()
155 
156 
157 //------------------------------------------------------------------------------
159 
160  // get the particles from the event
161  auto const& Photons
162  = *(event.getValidHandle<std::vector<sim::SimPhotonsLite>>(fInputPhotons));
163 
164  mf::LogVerbatim(fOutputCategory) << "Event " << event.id()
165  << " : data product '" << fInputPhotons.encode() << "' contains "
166  << Photons.size() << " SimPhotonsLite";
167 
168  unsigned int iChannel = 0;
169  for (sim::SimPhotonsLite const& photons: Photons) {
170 
172  // a bit of a header
173  log << "[#" << (iChannel++) << "] ";
174  DumpPhoton(log, photons, " ");
175 
176  } // for
177  mf::LogVerbatim(fOutputCategory) << "\n"; // just an empty line
178 
179 } // sim::DumpSimPhotonsLite::analyze()
180 
181 
182 //------------------------------------------------------------------------------
184 
185 //------------------------------------------------------------------------------
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
DumpSimPhotonsLite & operator=(DumpSimPhotonsLite const &)=delete
art::InputTag fInputPhotons
name of SimPhotons&#39;s data product
std::map< int, int > DetectedPhotons
Definition: SimPhotons.h:65
contains objects relating to OpDet hits
DumpSimPhotonsLite(Parameters const &config)
Configuration-checking constructor.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
parameter set interface
std::string encode() const
Definition: InputTag.cc:36
std::string indent(std::size_t const i)
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
Monte Carlo Simulation.
void analyze(art::Event const &event) override
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