LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DumpSimEnergyDeposits_module.cc
Go to the documentation of this file.
1 
8 // LArSoft libraries
11 #include "lardataalg/MCDumpers/MCDumperUtils.h" // sim::ParticleName()
15 
16 // art libraries
22 
23 // support libraries
24 #include "fhiclcpp/types/Atom.h"
25 #include "fhiclcpp/types/Comment.h"
26 #include "fhiclcpp/types/Name.h"
28 
29 // C//C++ standard libraries
30 #include <memory> // std::unique_ptr<>
31 #include <string>
32 
33 // -----------------------------------------------------------------------------
34 namespace sim {
35  class DumpSimEnergyDeposits;
36 }
54 public:
55  struct Config {
56  using Name = fhicl::Name;
58 
60  Name("EnergyDepositTag"),
61  Comment("tag of data product containing the `sim::SimEnergyDeposit` to dump"),
62  art::InputTag{"largeant", "TPCActive"}};
63 
65  Comment("whether to show where the deposition took place"),
66  true};
67 
69  Name("ShowStep"),
70  Comment("whether to show start and end position of the particle step"),
71  false};
72 
74  Name("ShowEmission"),
75  Comment("whether to show the number of photons and electrons generated"),
76  true};
77 
79  Name("SplitPhotons"),
80  Comment("whether to list fast- and slow-emitted photons separately"),
81  [this]() { return ShowEmission(); },
82  true};
83 
85  Name("OutputCategory"),
86  Comment("the messagefacility category used for the output"),
87  "DumpSimEnergyDeposits"};
88 
89  }; // struct Config
90 
92 
94  explicit DumpSimEnergyDeposits(Parameters const& config);
95 
97  void analyze(art::Event const& evt);
98 
99 private:
101  std::string fOutputCategory;
102 
103  bool bShowLocation = true;
104  bool bShowStep = true;
105  bool bShowEmission = true;
106  bool bSplitPhotons = true;
107 
108  template <typename Stream>
109  void dumpEnergyDeposit(Stream& out, sim::SimEnergyDeposit const& dep) const;
110 
111 }; // class sim::DumpSimEnergyDeposits
112 
113 //------------------------------------------------------------------------------
114 //--- module implementation
115 //------------------------------------------------------------------------------
117  : EDAnalyzer(config)
118  , fEnergyDepositTag(config().EnergyDepositTag())
119  , fOutputCategory(config().OutputCategory())
120  , bShowLocation(config().ShowLocation())
121  , bShowStep(config().ShowStep())
122  , bShowEmission(config().ShowEmission())
123  , bSplitPhotons(config().SplitPhotons())
124 {}
125 
126 //------------------------------------------------------------------------------
128 {
129 
130  using namespace util::quantities::energy_literals;
131  using namespace util::quantities::space_literals;
134 
135  // fetch the data to be dumped on screen
136  auto const& Deps = *(event.getValidHandle<std::vector<sim::SimEnergyDeposit>>(fEnergyDepositTag));
137 
138  mf::LogVerbatim(fOutputCategory) << "Event " << event.id() << " contains " << Deps.size() << " '"
139  << fEnergyDepositTag.encode() << "' energy deposits";
140 
141  megaelectronvolt TotalE = 0_MeV;
142  centimeter TotalLength{0.0};
143  unsigned int TotalElectrons = 0U, TotalPhotons = 0U, TotalPhotonsFast = 0U, TotalPhotonsSlow = 0U;
144 
145  for (auto const& [iDep, dep] : util::enumerate(Deps)) {
146 
147  // print a header for the cluster
149  log << "[#" << iDep << "] ";
150  dumpEnergyDeposit(log, dep);
151 
152  // collect statistics
153  TotalE += megaelectronvolt{dep.Energy()};
154  TotalLength += centimeter{dep.StepLength()};
155  TotalElectrons += dep.NumElectrons();
156  TotalPhotons += dep.NumPhotons();
157  TotalPhotonsSlow += dep.NumSPhotons();
158  TotalPhotonsFast += dep.NumFPhotons();
159 
160  } // for depositions
161 
163  << "Event " << event.id() << " energy deposits '" << fEnergyDepositTag.encode() << "' include "
164  << TotalE << " worth of energy, " << TotalElectrons << " electrons and " << TotalPhotons
165  << " photons (" << TotalPhotonsFast << " fast and " << TotalPhotonsSlow
166  << " slow); tracked particles crossed " << TotalLength << " of space.";
167 
168 } // sim::DumpSimEnergyDeposits::analyze()
169 
170 // -----------------------------------------------------------------------------
171 template <typename Stream>
173  sim::SimEnergyDeposit const& dep) const
174 {
178 
179  auto const time{nanosecond(dep.Time())};
180  auto const energy{megaelectronvolt(dep.Energy())};
181  auto const length{centimeter(dep.StepLength())};
182 
183  out << "TrkID=" << dep.TrackID() << " (" << sim::ParticleName(dep.PdgCode()) << "): " << energy
184  << " on " << time;
185  if (bShowLocation) out << " at " << dep.MidPoint();
186  if (bShowStep) out << " from " << dep.Start() << " to " << dep.End();
187  out << " (step: " << length << ")";
188  if (bShowEmission) {
189  out << "; electrons: " << dep.NumElectrons();
190  if (bSplitPhotons) {
191  out << "; photons: " << dep.NumFPhotons() << " (fast), " << dep.NumSPhotons() << " (slow)";
192  }
193  else
194  out << "; photons: " << dep.NumPhotons();
195  }
196 
197 } // sim::DumpSimEnergyDeposits::dumpEnergyDeposit()
198 
199 // -----------------------------------------------------------------------------
201 
202 // -----------------------------------------------------------------------------
DumpSimEnergyDeposits(Parameters const &config)
Constructor: reads the configuration.
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
geo::Length_t StepLength() const
Definition of util::enumerate().
Literal constants for energy quantities.
Definition: energy.h:154
bool bSplitPhotons
Print photons by emission speed.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
Prints the content of all the deposited energies on screen.
std::string encode() const
Definition: InputTag.cc:97
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:65
art::InputTag fEnergyDepositTag
Tag for input data product.
geo::Point_t Start() const
geo::Point_t End() const
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
Definitions of geometry vector data types.
megaelectronvolt_as<> megaelectronvolt
Type of energy stored in megaelectronvolt, in double precision.
Definition: energy.h:112
void analyze(art::Event const &evt)
Does the printing.
std::string ParticleName(int pigid)
Returns a string with the name of particle the specified with PDG ID.
double energy
Definition: plottest35.C:25
double Time() const
geo::Point_t MidPoint() const
gigaelectronvolt_as<> gigaelectronvolt
Type of energy stored in gigaelectronvolt, in double precision.
Definition: energy.h:122
Monte Carlo Simulation.
bool bShowEmission
Print the photons and electrons emitted.
void dumpEnergyDeposit(Stream &out, sim::SimEnergyDeposit const &dep) const
Dimensioned variables representing energy.
Utility functions to print MC truth information.
Dimensioned variables representing space or time quantities.
contains information for a single step in the detector simulation
Energy deposition in the active material.
nanosecond_as<> nanosecond
Type of time stored in nanoseconds, in double precision.
Definition: spacetime.h:133
double Energy() const
TCEvent evt
Definition: DataStructs.cxx:8
centimeter_as<> centimeter
Type of space stored in centimeters, in double precision.
Definition: spacetime.h:441
bool bShowLocation
Print the center of the deposition.
Literal constants for space quantities.
Definition: spacetime.h:550
std::string fOutputCategory
Category for LogInfo output.
Event finding and building.