All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DumpSimPhotonsLite_module.cc
Go to the documentation of this file.
1 /**
2  * @file DumpSimPhotonsLite_module.cc
3  * @brief Module dumping SimPhotonsLite information on screen
4  * @date March 8, 2017
5  * @author Gianluca Petrillo (petrillo@fnal.gov)
6  *
7  */
8 
9 
10 // LArSoft libraries
12 
13 // framework libraries
14 #include "art/Framework/Core/EDAnalyzer.h"
15 #include "art/Framework/Core/ModuleMacros.h"
16 #include "art/Framework/Principal/Event.h"
17 #include "art/Framework/Principal/Handle.h"
18 #include "canvas/Utilities/InputTag.h"
19 #include "fhiclcpp/types/Atom.h"
20 #include "messagefacility/MessageLogger/MessageLogger.h"
21 
22 // C/C++ standard libraries
23 #include <string>
24 #include <iomanip> // std::setw()
25 #include <numeric> // std::accumulate()
26 #include <utility> // std::forward()
27 
28 
29 namespace sim {
30  class DumpSimPhotonsLite;
31 } // namespace sim
32 
33 
34 namespace {
35  using namespace fhicl;
36 
37  /// Collection of configuration parameters for the module
38  struct Config {
39  using Name = fhicl::Name;
40  using Comment = fhicl::Comment;
41 
42  fhicl::Atom<art::InputTag> InputPhotons {
43  Name("InputPhotons"),
44  Comment("data product with the SimPhotonsLite to be dumped")
45  };
46 
47  fhicl::Atom<std::string> OutputCategory {
48  Name("OutputCategory"),
49  Comment("name of the output stream (managed by the message facility)"),
50  "DumpSimPhotonsLite" /* default value */
51  };
52 
53  }; // struct Config
54 
55 
56 } // local namespace
57 
58 
59 class sim::DumpSimPhotonsLite: public art::EDAnalyzer {
60  public:
61  // type to enable module parameters description by art
62  using Parameters = art::EDAnalyzer::Table<Config>;
63 
64  /// Configuration-checking constructor
65  explicit DumpSimPhotonsLite(Parameters const& config);
66 
67  // Plugins should not be copied or assigned.
68  DumpSimPhotonsLite(DumpSimPhotonsLite const&) = delete;
70  DumpSimPhotonsLite& operator = (DumpSimPhotonsLite const&) = delete;
71  DumpSimPhotonsLite& operator = (DumpSimPhotonsLite &&) = delete;
72 
73 
74  // Operates on the event
75  void analyze(art::Event const& event) override;
76 
77 
78  /**
79  * @brief Dumps the content of specified SimPhotonsLite in the output stream.
80  * @tparam Stream the type of output stream
81  * @param out the output stream
82  * @param photons the SimPhotonsLite to be dumped
83  * @param indent base indentation string _(default: none)_
84  * @param firstIndent if first output line should be indented _(default: yes)_
85  *
86  * The indent string is prepended to every line of output, with the possible
87  * exception of the first one, in case bIndentFirst is true.
88  *
89  * The output starts on the current line, and the last line is *not* broken.
90  */
91  template <typename Stream>
92  void DumpPhoton(
93  Stream&& out, sim::SimPhotonsLite const& photons,
94  std::string indent, std::string firstIndent
95  ) const;
96 
97  template <typename Stream>
98  void DumpPhoton
99  (Stream&& out, sim::SimPhotonsLite const& photons, std::string indent = "")
100  const
101  { DumpPhoton(std::forward<Stream>(out), photons, indent, indent); }
102 
103 
104  private:
105 
106  art::InputTag fInputPhotons; ///< name of SimPhotons's data product
107  std::string fOutputCategory; ///< name of the stream for output
108 
109 }; // class sim::DumpSimPhotonsLite
110 
111 
112 //------------------------------------------------------------------------------
113 //--- module implementation
114 //---
115 //------------------------------------------------------------------------------
117  : EDAnalyzer(config)
118  , fInputPhotons(config().InputPhotons())
119  , fOutputCategory(config().OutputCategory())
120 {}
121 
122 //------------------------------------------------------------------------------
123 template <typename Stream>
125  Stream&& out, sim::SimPhotonsLite const& photons,
126  std::string indent, std::string firstIndent
127 ) const {
128 
129  unsigned int const nPhotons = std::accumulate(
130  photons.DetectedPhotons.begin(), photons.DetectedPhotons.end(),
131  0U, [](auto sum, auto const& entry){ return sum + entry.second; }
132  );
133 
134  out << firstIndent
135  << "channel=" << photons.OpChannel << " has ";
136  if (nPhotons) {
137  out << nPhotons << " photons (format: [tick] photons):";
138  constexpr unsigned int PageSize = 5;
139  unsigned int pager = 0;
140  for (auto const& pair: photons.DetectedPhotons) {
141  if (pager-- == 0) {
142  pager = PageSize - 1;
143  out << "\n" << indent << " ";
144  }
145  out << " [" << pair.first << "] " << std::setw(6) << pair.second;
146  } // for
147  }
148  else {
149  out << "no photons";
150  }
151 
152 } // sim::DumpSimPhotonsLite::DumpPhoton()
153 
154 
155 //------------------------------------------------------------------------------
156 void sim::DumpSimPhotonsLite::analyze(art::Event const& event) {
157 
158  // get the particles from the event
159  auto const& Photons
160  = *(event.getValidHandle<std::vector<sim::SimPhotonsLite>>(fInputPhotons));
161 
162  mf::LogVerbatim(fOutputCategory) << "Event " << event.id()
163  << " : data product '" << fInputPhotons.encode() << "' contains "
164  << Photons.size() << " SimPhotonsLite";
165 
166  unsigned int iChannel = 0;
167  for (sim::SimPhotonsLite const& photons: Photons) {
168 
169  mf::LogVerbatim log(fOutputCategory);
170  // a bit of a header
171  log << "[#" << (iChannel++) << "] ";
172  DumpPhoton(log, photons, " ");
173 
174  } // for
175  mf::LogVerbatim(fOutputCategory) << "\n"; // just an empty line
176 
177 } // sim::DumpSimPhotonsLite::analyze()
178 
179 
180 //------------------------------------------------------------------------------
181 DEFINE_ART_MODULE(sim::DumpSimPhotonsLite)
182 
183 //------------------------------------------------------------------------------
process_name opflashCryo1 flashfilter analyze
art::EDAnalyzer::Table< Config > Parameters
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 -&gt; photons.
Definition: SimPhotons.h:117
Simulation objects for optical detectors.
DumpSimPhotonsLite(Parameters const &config)
Configuration-checking constructor.
int OpChannel
Optical detector channel associated to this data.
Definition: SimPhotons.h:114
BEGIN_PROLOG vertical distance to the surface Name
Compact representation of photons on a channel.
Definition: SimPhotons.h:103
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.
bnb BNB Stream
std::string fOutputCategory
name of the stream for output