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
19 #include "fhiclcpp/types/Atom.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 
60  public:
61  // type to enable module parameters description by art
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;
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 //------------------------------------------------------------------------------
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 
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 //------------------------------------------------------------------------------
182 
183 //------------------------------------------------------------------------------
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
QList< Entry > entry
std::string string
Definition: nybbler.cc:12
ChannelGroupService::Name Name
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
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:117
typename config_impl< T >::type Config
Definition: ModuleMacros.h:52
Simulation objects for optical detectors.
DumpSimPhotonsLite(Parameters const &config)
Configuration-checking constructor.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
static Config * config
Definition: config.cpp:1054
int OpChannel
Optical detector channel associated to this data.
Definition: SimPhotons.h:114
Code to link reconstructed objects back to the MC truth information.
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
Compact representation of photons on a channel.
Definition: SimPhotons.h:103
#define Comment
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