LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
DumpSimPhotons_module.cc
Go to the documentation of this file.
1 
10 // nutools libraries
12 
13 // framework libraries
19 #include "fhiclcpp/ParameterSet.h"
20 #include "fhiclcpp/types/Atom.h"
22 
23 
24 namespace sim {
25  class DumpSimPhotons;
26 } // namespace sim
27 
28 namespace {
29  using namespace fhicl;
30 
32  struct Config {
33  using Name = fhicl::Name;
34  using Comment = fhicl::Comment;
35 
36  fhicl::Atom<art::InputTag> InputPhotons {
37  Name("InputPhotons"),
38  Comment("data product with the SimPhotons to be dumped")
39  };
40 
41  fhicl::Atom<std::string> OutputCategory {
42  Name("OutputCategory"),
43  Comment("name of the output stream (managed by the message facility)"),
44  "DumpSimPhotons" /* default value */
45  };
46 
47  }; // struct Config
48 
49 
50 } // local namespace
51 
52 
54  public:
55  // type to enable module parameters description by art
57 
59  explicit DumpSimPhotons(Parameters const& config);
60 
61  // Plugins should not be copied or assigned.
62  DumpSimPhotons(DumpSimPhotons const&) = delete;
63  DumpSimPhotons(DumpSimPhotons &&) = delete;
64  DumpSimPhotons& operator = (DumpSimPhotons const&) = delete;
66 
67 
68  // Operates on the event
69  void analyze(art::Event const& event) override;
70 
71 
85  template <typename Stream>
86  void DumpElement(
87  Stream&& out, sim::SimPhotons const& simphotons,
88  std::string indent = "", bool bIndentFirst = true
89  ) const;
90 
92  template <typename Stream>
93  void DumpOnePhoton(Stream&& out, sim::OnePhoton const& photon) const;
94 
95 
96  private:
97 
99  std::string fOutputCategory;
100 
101 }; // class sim::DumpSimPhotons
102 
103 
104 //------------------------------------------------------------------------------
105 //--- module implementation
106 //---
107 //------------------------------------------------------------------------------
109  : EDAnalyzer(config)
110  , fInputPhotons(config().InputPhotons())
111  , fOutputCategory(config().OutputCategory())
112 {}
113 
114 //------------------------------------------------------------------------------
115 template <typename Stream>
117  (Stream&& out, sim::OnePhoton const& onephoton) const
118 {
119  out << "E=" << onephoton.Energy << " t=" << onephoton.Time
120  << " from (" << onephoton.InitialPosition.X()
121  << ", " << onephoton.InitialPosition.Y()
122  << ", " << onephoton.InitialPosition.Z() << ") cm"
123  << " to (" << onephoton.FinalLocalPosition.X()
124  << ", " << onephoton.FinalLocalPosition.Y()
125  << ", " << onephoton.FinalLocalPosition.Z() << ") cm"
126  ;
127  if (onephoton.SetInSD) out << " [in SD]"; // in sensitive detector?
128 } // sim::DumpSimPhotons::DumpOnePhoton()
129 
130 
131 //------------------------------------------------------------------------------
132 template <typename Stream>
134  Stream&& out, sim::SimPhotons const& simphotons,
135  std::string indent /* = "" */, bool bIndentFirst /* = true */
136 ) const {
137  if (bIndentFirst) out << indent;
138  out << "channel=" << simphotons.OpChannel() << " has ";
139  if (simphotons.empty()) {
140  out << simphotons.size() << " no photons";
141  }
142  else {
143  out << simphotons.size() << " photons:";
144  for (auto const& onephoton: simphotons) {
145  out << "\n" << indent << " ";
146  DumpOnePhoton(out, onephoton);
147  } // for
148  }
149 
150 } // sim::DumpSimPhotons::DumpSimPhotons()
151 
152 
153 //------------------------------------------------------------------------------
155 
156  // get the particles from the event
157  auto const& SimPhotons
158  = *(event.getValidHandle<std::vector<sim::SimPhotons>>(fInputPhotons));
159 
160  mf::LogVerbatim(fOutputCategory) << "Event " << event.id()
161  << " : data product '" << fInputPhotons.encode() << "' contains "
162  << SimPhotons.size() << " SimPhotons";
163 
164  unsigned int iPhoton = 0;
165  for (sim::SimPhotons const& photons: SimPhotons) {
166 
168  // a bit of a header
169  log << "[#" << (iPhoton++) << "] ";
170  DumpElement(log, photons, " ", false);
171 
172  } // for
173  mf::LogVerbatim(fOutputCategory) << "\n"; // just an empty line
174 
175 } // sim::DumpSimPhotons::analyze()
176 
177 
178 //------------------------------------------------------------------------------
180 
181 //------------------------------------------------------------------------------
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
int OpChannel() const
Definition: SimPhotons.h:161
void DumpElement(Stream &&out, sim::SimPhotons const &simphotons, std::string indent="", bool bIndentFirst=true) const
Dumps the content of the specified SimPhotons in the output stream.
art::InputTag fInputPhotons
name of SimPhotons&#39;s data product
contains objects relating to OpDet hits
#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)
std::string fOutputCategory
name of the stream for output
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
void DumpOnePhoton(Stream &&out, sim::OnePhoton const &photon) const
Dumps a sim::OnePhoton on a single line.
DumpSimPhotons & operator=(DumpSimPhotons const &)=delete
void analyze(art::Event const &event) override
Monte Carlo Simulation.
DumpSimPhotons(Parameters const &config)
Configuration-checking constructor.
TVector3 InitialPosition
Definition: SimPhotons.h:49
TVector3 FinalLocalPosition
Definition: SimPhotons.h:50
Event finding and building.