DumpSimEnergyDeposits_module.cc
Go to the documentation of this file.
1 /**
2  * @file DumpSimEnergyDeposits_module.cc
3  * @brief Dumps on screen the content of the `sim::SimEnergyDeposit` objects.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date January 11, 2020
6  */
7 
8 // LArSoft libraries
9 #include "lardataalg/MCDumpers/MCDumperUtils.h" // sim::ParticleName()
15 
16 // art libraries
22 
23 // support libraries
25 #include "fhiclcpp/types/Atom.h"
26 #include "fhiclcpp/types/Name.h"
27 #include "fhiclcpp/types/Comment.h"
28 
29 // C//C++ standard libraries
30 #include <string>
31 #include <memory> // std::unique_ptr<>
32 
33 
34 // -----------------------------------------------------------------------------
35 namespace sim { class DumpSimEnergyDeposits; }
36 /**
37  * @brief Prints the content of all the deposited energies on screen.
38  *
39  * This analyzer prints the content of all the hits into the
40  * LogInfo/LogVerbatim stream.
41  *
42  * Configuration parameters
43  * =========================
44  *
45  * - *EnergyDepositTag* (input tag, default: `"largeant:TPCActive"`):
46  * tag of data product containing the deposits to dump (memento: format is
47  * `"moduleLabel:instanceName"`;
48  * - *OutputCategory* (string, default: "DumpSimEnergyDeposits"): the category
49  * used for the output (useful for filtering)
50  *
51  */
53  public:
54 
55  struct Config {
56  using Name = fhicl::Name;
58 
60  Name("EnergyDepositTag"),
61  Comment
62  ("tag of data product containing the `sim::SimEnergyDeposit` to dump"),
63  art::InputTag{ "largeant", "TPCActive" }
64  };
65 
67  Name("ShowLocation"),
68  Comment("whether to show where the deposition took place"),
69  true
70  };
71 
73  Name("ShowStep"),
74  Comment("whether to show start and end position of the particle step"),
75  false
76  };
77 
79  Name("ShowEmission"),
80  Comment("whether to show the number of photons and electrons generated"),
81  true
82  };
83 
85  Name("SplitPhotons"),
86  Comment("whether to list fast- and slow-emitted photons separately"),
87  [this](){ return ShowEmission(); },
88  true
89  };
90 
92  Name("OutputCategory"),
93  Comment("the messagefacility category used for the output"),
94  "DumpSimEnergyDeposits"
95  };
96 
97  }; // struct Config
98 
100 
101 
102  /// Constructor: reads the configuration.
103  explicit DumpSimEnergyDeposits(Parameters const& config);
104 
105  /// Does the printing.
106  void analyze(art::Event const& evt);
107 
108  private:
109 
110  art::InputTag fEnergyDepositTag; ///< Tag for input data product.
111  std::string fOutputCategory; ///< Category for LogInfo output.
112 
113  bool bShowLocation = true; ///< Print the center of the deposition.
114  bool bShowStep = true; ///< Print the step ends.
115  bool bShowEmission = true; ///< Print the photons and electrons emitted.
116  bool bSplitPhotons = true; ///< Print photons by emission speed.
117 
118  template <typename Stream>
119  void dumpEnergyDeposit(Stream& out, sim::SimEnergyDeposit const& dep) const;
120 
121 }; // class sim::DumpSimEnergyDeposits
122 
123 
124 //------------------------------------------------------------------------------
125 //--- module implementation
126 //------------------------------------------------------------------------------
128  : EDAnalyzer (config)
129  , fEnergyDepositTag(config().EnergyDepositTag())
130  , fOutputCategory (config().OutputCategory())
131  , bShowLocation(config().ShowLocation())
132  , bShowStep (config().ShowStep())
133  , bShowEmission(config().ShowEmission())
134  , bSplitPhotons(config().SplitPhotons())
135  {}
136 
137 
138 //------------------------------------------------------------------------------
140 
141  using namespace util::quantities::energy_literals;
142  using namespace util::quantities::space_literals;
145 
146  // fetch the data to be dumped on screen
147  auto const& Deps = *(
148  event.getValidHandle<std::vector<sim::SimEnergyDeposit>>(fEnergyDepositTag)
149  );
150 
152  << "Event " << event.id() << " contains " << Deps.size() << " '"
153  << fEnergyDepositTag.encode() << "' energy deposits";
154 
155  megaelectronvolt TotalE = 0_MeV;
156  centimeter TotalLength { 0.0 };
157  unsigned int TotalElectrons = 0U, TotalPhotons = 0U,
158  TotalPhotonsFast = 0U, TotalPhotonsSlow = 0U;
159 
160  for (auto const& [ iDep, dep ]: util::enumerate(Deps)) {
161 
162  // print a header for the cluster
164  log << "[#" << iDep << "] ";
165  dumpEnergyDeposit(log, dep);
166 
167  // collect statistics
168  TotalE += megaelectronvolt{ dep.Energy() };
169  TotalLength += centimeter{ dep.StepLength() };
170  TotalElectrons += dep.NumElectrons();
171  TotalPhotons += dep.NumPhotons();
172  TotalPhotonsSlow += dep.NumSPhotons();
173  TotalPhotonsFast += dep.NumFPhotons();
174 
175  } // for depositions
176 
178  << "Event " << event.id() << " energy deposits '"
179  << fEnergyDepositTag.encode() << "' include "
180  << TotalE << " worth of energy, " << TotalElectrons
181  << " electrons and " << TotalPhotons << " photons ("
182  << TotalPhotonsFast << " fast and " << TotalPhotonsSlow
183  << " slow); tracked particles crossed " << TotalLength << " of space."
184  ;
185 
186 } // sim::DumpSimEnergyDeposits::analyze()
187 
188 
189 // -----------------------------------------------------------------------------
190 template <typename Stream>
192  (Stream& out, sim::SimEnergyDeposit const& dep) const
193 {
197 
198  auto const time { nanosecond(dep.Time()) };
199  auto const energy { megaelectronvolt(dep.Energy()) };
200  auto const length { centimeter(dep.StepLength()) };
201 
202  out << "TrkID=" << dep.TrackID()
203  << " (" << sim::ParticleName(dep.PdgCode()) << "): "
204  << energy << " on " << time;
205  if (bShowLocation) out << " at " << dep.MidPoint();
206  if (bShowStep) out << " from " << dep.Start() << " to " << dep.End();
207  out << " (step: " << length << ")";
208  if (bShowEmission) {
209  out << "; electrons: " << dep.NumElectrons();
210  if (bSplitPhotons) {
211  out << "; photons: " << dep.NumFPhotons() << " (fast), "
212  << dep.NumSPhotons() << " (slow)";
213  }
214  else out << "; photons: " << dep.NumPhotons();
215  }
216 
217 } // sim::DumpSimEnergyDeposits::dumpEnergyDeposit()
218 
219 
220 // -----------------------------------------------------------------------------
222 
223 // -----------------------------------------------------------------------------
DumpSimEnergyDeposits(Parameters const &config)
Constructor: reads the configuration.
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
geo::Length_t StepLength() const
Definition of util::enumerate().
std::string string
Definition: nybbler.cc:12
Literal constants for energy quantities.
Definition: energy.h:162
ChannelGroupService::Name Name
bool bSplitPhotons
Print photons by emission speed.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
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:69
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:67
static Config * config
Definition: config.cpp:1054
megaelectronvolt_as<> megaelectronvolt
Type of energy stored in megaelectronvolt, in double precision.
Definition: energy.h:119
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.
geo::Point_t MidPoint() const
gigaelectronvolt_as<> gigaelectronvolt
Type of energy stored in gigaelectronvolt, in double precision.
Definition: energy.h:129
Code to link reconstructed objects back to the MC truth information.
bool bShowEmission
Print the photons and electrons emitted.
void dumpEnergyDeposit(Stream &out, sim::SimEnergyDeposit const &dep) const
#define Comment
Dimensioned variables representing energy.
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:136
Utility functions to print MC truth information.
Definitions of geometry vector data types.
double Energy() const
TCEvent evt
Definition: DataStructs.cxx:7
centimeter_as<> centimeter
Type of space stored in centimeters, in double precision.
Definition: spacetime.h:434
bool bShowLocation
Print the center of the deposition.
Literal constants for space quantities.
Definition: spacetime.h:543
std::string fOutputCategory
Category for LogInfo output.
Event finding and building.