LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
DumpMCShowers_module.cc
Go to the documentation of this file.
1 
9 // 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 <iomanip>
26 #include <vector>
27 #include <algorithm> // std::max()
28 
29 
30 namespace sim {
31  class DumpMCShowers;
32 } // namespace sim
33 
34 namespace {
35  using namespace fhicl;
36 
38  struct Config {
39  using Name = fhicl::Name;
40  using Comment = fhicl::Comment;
41 
42  fhicl::Atom<art::InputTag> InputShowers {
43  Name("InputShowers"),
44  Comment("data product with the MC showers 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  "DumpMCShowers" /* default value */
51  };
52 
53  fhicl::Atom<unsigned int> DaughtersPerLine {
54  Name("DaughtersPerLine"),
55  Comment("daughter IDs to print on each output line"),
56  12 /* default value */
57  };
58 
59  }; // struct Config
60 
61 
63  std::string OriginDescription(simb::Origin_t origin) {
64  switch (origin) {
65  case simb::kUnknown: return "unknown";
66  case simb::kBeamNeutrino: return "beam neutrino";
67  case simb::kCosmicRay: return "cosmic rays";
68  case simb::kSuperNovaNeutrino: return "supernova neutrinos";
69  case simb::kSingleParticle: return "single particles thrown at the detector";
70  // default case is deliberately missing,
71  // so that on new additions in nutools the compiler will complain
72  } // switch
74  << "Unexpected origin type #" << ((int) origin) << "\n";
75  } // OriginDescription()
76 
77 
79  template <typename Stream>
80  void PrintMCStep(Stream&& out, sim::MCStep const& step) {
81  out << "("
82  << step.X() << ", " << step.Y() << ", " << step.Z() << ") cm, t="
83  << step.T() << " ns; momentum ("
84  << step.Px() << ", " << step.Py() << ", " << step.Pz() << "; "
85  << step.E() << ") MeV/c";
86  } // PrintMCStep()
87 
88 
89 } // local namespace
90 
91 
93  public:
94  // type to enable module parameters description by art
96 
98  explicit DumpMCShowers(Parameters const& config);
99 
100  // Plugins should not be copied or assigned.
101  DumpMCShowers(DumpMCShowers const&) = delete;
102  DumpMCShowers(DumpMCShowers &&) = delete;
103  DumpMCShowers& operator = (DumpMCShowers const&) = delete;
105 
106 
107  // Operates on the event
108  virtual void analyze(art::Event const& event) override;
109 
110 
124  template <typename Stream>
125  void DumpMCShower(
126  Stream&& out, sim::MCShower const& shower,
127  std::string indent = "", bool bIndentFirst = true
128  ) const;
129 
130 
131  private:
132 
134  std::string fOutputCategory;
135  unsigned int fDaughtersPerLine;
136 
137 }; // class sim::DumpMCShowers
138 
139 
140 //------------------------------------------------------------------------------
141 //--- module implementation
142 //---
143 //------------------------------------------------------------------------------
145  : EDAnalyzer(config)
146  , fInputShowers(config().InputShowers())
147  , fOutputCategory(config().OutputCategory())
148  , fDaughtersPerLine(config().DaughtersPerLine())
149 {}
150 
151 //------------------------------------------------------------------------------
152 template <typename Stream>
154  Stream&& out, sim::MCShower const& shower,
155  std::string indent /* = "" */, bool bIndentFirst /* = true */
156 ) const {
157  if (bIndentFirst) out << indent;
158  out
159  << "from GEANT track ID=" << shower.TrackID()
160  << " PDG ID=" << shower.PdgCode()
161  << " from " << OriginDescription(shower.Origin())
162  << " via '" << shower.Process() << "'";
163  out << "\n" << indent
164  << " starting at ";
165  ::PrintMCStep(out, shower.Start());
166  out << "\n" << indent
167  << " ending at ";
168  ::PrintMCStep(out, shower.End());
169 
170  TVector3 const& startDir = shower.StartDir();
171  out << "\n" << indent
172  << "pointing toward ("
173  << startDir.X() << ", " << startDir.Y() << ", " << startDir.Z() << ") cm";
174  std::vector<double> const& charges = shower.Charge();
175  std::vector<double> const& dQdx = shower.dQdx();
176  size_t const nQPlanes = dQdx.size(), nChPlanes = charges.size();
177  size_t const nPlanes = std::max(nQPlanes, nChPlanes);
178  out << "\n" << indent;
179  if (nPlanes > 0) {
180  out
181  << "dE/dx=" << shower.dEdx() << " MeV/cm and dQ/dx (charge) on "
182  << nPlanes << " planes:";
183  for (size_t iPlane = 0; iPlane < nPlanes; ++iPlane) {
184  out << " [#" << iPlane << "] ";
185  if (iPlane < dQdx.size()) out << dQdx[iPlane];
186  else out << "<N/A>";
187  if (iPlane < charges.size()) out << " (" << charges[iPlane] << ")";
188  else out << "<N/A>";
189  } // for plane
190  }
191  else out << "no energy or charge information available";
192 
193  std::vector<unsigned int> const& daughters = shower.DaughterTrackID();
194  out << "\n" << indent
195  << "combined energy deposition information: ";
196  ::PrintMCStep(out, shower.DetProfile());
197  out << "\n" << indent
198  << daughters.size() << " daughters, ID:";
199  for (size_t i = 0; i < daughters.size(); ++i) {
200  if ((i % fDaughtersPerLine) == 0) out << "\n" << indent << " ";
201  out << " " << std::setw(8) << daughters[i];
202  } // for
203 
204  out << "\n" << indent
205  << "mother ID=" << shower.MotherTrackID()
206  << " PDG ID=" << shower.MotherPdgCode()
207  << " via '" << shower.MotherProcess() << "'";
208  out << "\n" << indent
209  << " starting at ";
210  ::PrintMCStep(out, shower.MotherStart());
211  out << "\n" << indent
212  << " ending at ";
213  ::PrintMCStep(out, shower.MotherEnd());
214 
215  out << "\n" << indent
216  << "ancestor ID=" << shower.AncestorTrackID()
217  << " PDG ID=" << shower.AncestorPdgCode()
218  << " via '" << shower.AncestorProcess() << "'";
219  out << "\n" << indent
220  << " starting at ";
221  ::PrintMCStep(out, shower.AncestorStart());
222  out << "\n" << indent
223  << " ending at ";
224  ::PrintMCStep(out, shower.AncestorEnd());
225 
226 } // sim::DumpMCShowers::DumpMCShower()
227 
228 
229 //------------------------------------------------------------------------------
231 
232  // get the particles from the event
233  auto const& Showers
234  = *(event.getValidHandle<std::vector<sim::MCShower>>(fInputShowers));
235 
237  << "Event " << event.id() << ": data product '"
238  << fInputShowers.encode() << "' contains "
239  << Showers.size() << " MCShower objects";
240 
241  unsigned int iShower = 0;
243  for (sim::MCShower const& shower: Showers) {
244 
245  // a bit of a header
246  log << "\n[#" << (iShower++) << "] ";
247  DumpMCShower(log, shower, " ", false);
248 
249  } // for
250  log << "\n";
251 
252 } // sim::DumpMCShowers::analyze()
253 
254 
255 //------------------------------------------------------------------------------
257 
258 //------------------------------------------------------------------------------
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const MCStep & End() const
Definition: MCShower.h:56
art::InputTag fInputShowers
name of MCShower&#39;s data product
unsigned int TrackID() const
Definition: MCShower.h:53
std::string fOutputCategory
name of the stream for output
DumpMCShowers(Parameters const &config)
Configuration-checking constructor.
enum simb::_ev_origin Origin_t
event origin types
int PdgCode() const
Definition: MCShower.h:52
DumpMCShowers & operator=(DumpMCShowers const &)=delete
double T() const
Definition: MCStep.h:45
Class def header for mcstep data container.
const std::vector< unsigned int > & DaughterTrackID() const
Definition: MCShower.h:72
const TVector3 & StartDir() const
Definition: MCShower.h:82
Int_t max
Definition: plot.C:27
simb::Origin_t Origin() const
Definition: MCShower.h:50
double Px() const
Definition: MCStep.h:46
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
int MotherPdgCode() const
Definition: MCShower.h:58
const std::string & AncestorProcess() const
Definition: MCShower.h:66
single particles thrown at the detector
Definition: MCTruth.h:24
parameter set interface
std::string encode() const
Definition: InputTag.cc:36
std::string indent(std::size_t const i)
double Z() const
Definition: MCStep.h:44
unsigned int fDaughtersPerLine
number of daughter IDs printed per line
double Py() const
Definition: MCStep.h:47
double Y() const
Definition: MCStep.h:43
const MCStep & AncestorStart() const
Definition: MCShower.h:67
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
const std::string & MotherProcess() const
Definition: MCShower.h:60
Monte Carlo Simulation.
double dEdx() const
Definition: MCShower.h:81
unsigned int AncestorTrackID() const
Definition: MCShower.h:65
const MCStep & AncestorEnd() const
Definition: MCShower.h:68
const MCStep & DetProfile() const
Definition: MCShower.h:70
const MCStep & Start() const
Definition: MCShower.h:55
double Charge(size_t plane) const
Definition: MCShower.cxx:50
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
virtual void analyze(art::Event const &event) override
const MCStep & MotherEnd() const
Definition: MCShower.h:62
void DumpMCShower(Stream &&out, sim::MCShower const &shower, std::string indent="", bool bIndentFirst=true) const
Dumps the content of the specified particle in the output stream.
Supernova neutrinos.
Definition: MCTruth.h:23
double E() const
Definition: MCStep.h:49
Class def header for MCShower data container.
unsigned int MotherTrackID() const
Definition: MCShower.h:59
const std::string & Process() const
Definition: MCShower.h:54
double Pz() const
Definition: MCStep.h:48
const MCStep & MotherStart() const
Definition: MCShower.h:61
double X() const
Definition: MCStep.h:42
int AncestorPdgCode() const
Definition: MCShower.h:64
double dQdx(size_t plane) const
Definition: MCShower.cxx:59
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:230
Cosmic rays.
Definition: MCTruth.h:22
Event finding and building.
Beam neutrinos.
Definition: MCTruth.h:21