All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Private Attributes | List of all members
sim::DumpMCParticles Class Reference
Inheritance diagram for sim::DumpMCParticles:

Public Types

using Parameters = art::EDAnalyzer::Table< Config >
 

Public Member Functions

 DumpMCParticles (Parameters const &config)
 Configuration-checking constructor. More...
 
 DumpMCParticles (DumpMCParticles const &)=delete
 
 DumpMCParticles (DumpMCParticles &&)=delete
 
DumpMCParticlesoperator= (DumpMCParticles const &)=delete
 
DumpMCParticlesoperator= (DumpMCParticles &&)=delete
 
void analyze (art::Event const &event) override
 
void endJob () override
 May print some warnings. More...
 
template<typename Stream >
void DumpMCParticle (Stream &&out, simb::MCParticle const &particle, art::InputTag const &truthTag, sim::GeneratedParticleInfo const &truthInfo, std::string indent="", bool bIndentFirst=true) const
 Dumps the content of the specified particle in the output stream. More...
 

Private Attributes

art::InputTag fInputParticles
 name of MCParticle's data product More...
 
art::InputTag fParticleTruthInfo
 name of MCParticle assns data product More...
 
std::string fOutputCategory
 name of the stream for output More...
 
unsigned int fPointsPerLine
 trajectory points per output line More...
 
unsigned int fNEvents = 0U
 
unsigned int fNMissingTruth = 0U
 Count of events without truth association. More...
 
unsigned int fNMissingTruthIndex = 0U
 Count of events without truth index. More...
 

Detailed Description

Definition at line 74 of file DumpMCParticles_module.cc.

Member Typedef Documentation

using sim::DumpMCParticles::Parameters = art::EDAnalyzer::Table<Config>

Definition at line 77 of file DumpMCParticles_module.cc.

Constructor & Destructor Documentation

sim::DumpMCParticles::DumpMCParticles ( Parameters const &  config)
explicit

Configuration-checking constructor.

Definition at line 206 of file DumpMCParticles_module.cc.

207  : EDAnalyzer(config)
208  , fInputParticles(config().InputParticles())
209  , fOutputCategory(config().OutputCategory())
210  , fPointsPerLine(config().PointsPerLine())
211 {
212  if (!config().ParticleTruthInfo(fParticleTruthInfo))
214 
215 }
std::string fOutputCategory
name of the stream for output
unsigned int fPointsPerLine
trajectory points per output line
art::InputTag fParticleTruthInfo
name of MCParticle assns data product
art::InputTag fInputParticles
name of MCParticle&#39;s data product
sim::DumpMCParticles::DumpMCParticles ( DumpMCParticles const &  )
delete
sim::DumpMCParticles::DumpMCParticles ( DumpMCParticles &&  )
delete

Member Function Documentation

void sim::DumpMCParticles::analyze ( art::Event const &  event)
override

Definition at line 250 of file DumpMCParticles_module.cc.

250  {
251 
252  ++fNEvents;
253 
254  ProductNameCache namesRegistry(event);
255 
256  // get the particles from the event
257  auto const& particleHandle
258  = event.getValidHandle<std::vector<simb::MCParticle>>(fInputParticles);
259  auto const& Particles = *particleHandle;
260 
261  // get the association to MCTruth
262  // - try first the more complete one, with true particle indices
263  // - as a fallback, go without true particle indices
264  auto particleToTruth = makeFindOneP<simb::MCTruth, sim::GeneratedParticleInfo>
265  (particleHandle, event, fParticleTruthInfo);
266  std::unique_ptr<art::FindOneP<simb::MCTruth>> particleToTruthLight;
267  if (!particleToTruth) {
269  particleToTruthLight = makeFindOneP<simb::MCTruth, void>
270  (particleHandle, event, fParticleTruthInfo);
271  if (!particleToTruthLight) ++fNMissingTruth;
272  }
273 
274  mf::LogVerbatim(fOutputCategory) << "Event " << event.id()
275  << ": data product '" << fInputParticles.encode() << "' contains "
276  << Particles.size() << " MCParticle's";
277 
278  unsigned int iParticle = 0;
279  for (simb::MCParticle const& particle: Particles) {
280  // flush on every particle,
281  // since the output buffer might grow too large otherwise
282  mf::LogVerbatim log(fOutputCategory);
283 
284  // fetch the input tag of the truth information (if any)
285  art::Ptr<simb::MCTruth> const& truth = particleToTruth
286  ? particleToTruth->at(iParticle)
287  : particleToTruthLight
288  ? particleToTruthLight->at(iParticle)
289  : art::Ptr<simb::MCTruth>{}
290  ;
291  art::InputTag const& truthTag
292  = truth? namesRegistry[truth]: art::InputTag{};
293 
294  // fetch the index of the true particle in the truth record (if any)
295  sim::GeneratedParticleInfo truthInfo = particleToTruth
296  ? particleToTruth->data(iParticle).ref()
298  ;
299 
300  // a bit of a header
301  log << "\n[#" << (iParticle++) << "] ";
302  DumpMCParticle(log, particle, truthTag, truthInfo, " ", false);
303  } // for
304 
305  mf::LogVerbatim(fOutputCategory) << "\n";
306 
307 } // sim::DumpMCParticles::analyze()
static constexpr GeneratedParticleIndex_t NoGeneratedParticleIndex
Constant representing the absence of generator truth information.
std::string fOutputCategory
name of the stream for output
unsigned int fNMissingTruthIndex
Count of events without truth index.
void DumpMCParticle(Stream &&out, simb::MCParticle const &particle, art::InputTag const &truthTag, sim::GeneratedParticleInfo const &truthInfo, std::string indent="", bool bIndentFirst=true) const
Dumps the content of the specified particle in the output stream.
unsigned int fNMissingTruth
Count of events without truth association.
Contains information about a generated particle.
art::InputTag fParticleTruthInfo
name of MCParticle assns data product
art::InputTag fInputParticles
name of MCParticle&#39;s data product
template<typename Stream >
void sim::DumpMCParticles::DumpMCParticle ( Stream &&  out,
simb::MCParticle const &  particle,
art::InputTag const &  truthTag,
sim::GeneratedParticleInfo const &  truthInfo,
std::string  indent = "",
bool  bIndentFirst = true 
) const

Dumps the content of the specified particle in the output stream.

Template Parameters
Streamthe type of output stream
Parameters
outthe output stream
particlethe particle to be dumped
truthTaginput tag of the truth record the particle derived from
truthIndexindex of particle in the truth record this derived from
indentbase indentation string (default: none)
bIndentFirstif first output line should be indented (default: yes)

The indent string is prepended to every line of output, with the possible exception of the first one, in case bIndentFirst is true.

If truthTag module label is empty, it is assumed that this information could not be retrieved, and it will be silently omitted. If truthIndex is sim::NoGeneratorIndex, it is assumed that this information could not be retrieved, and it will be silently omitted.

The output starts on the current line, and the last line is NOT broken.

Definition at line 219 of file DumpMCParticles_module.cc.

223  {
224 
225  if (!truthTag.label().empty() || truthInfo.hasGeneratedParticleIndex()) {
226  out << "(from ";
227  if (truthTag.label().empty()) out << "unknown truth record";
228  else out << "'" << truthTag.encode() << "'";
229  if (truthInfo.hasGeneratedParticleIndex())
230  out << " particle #" << truthInfo.generatedParticleIndex();
231  out << ") ";
232  }
233 
235  (std::forward<Stream>(out), particle, indent, bIndentFirst? indent: "");
236 
237  const unsigned int nPoints = particle.NumberTrajectoryPoints();
238  if ((nPoints > 0) && (fPointsPerLine > 0)) {
239  out << ":";
241  std::forward<Stream>(out), particle.Trajectory(),
242  fPointsPerLine, indent + " "
243  );
244  } // if has points
245 
246 } // sim::DumpMCParticles::DumpMCParticle()
void DumpMCParticleTrajectory(Stream &&out, simb::MCTrajectory const &trajectory, unsigned int pointsPerLine, std::string indent)
Dumps the specified particle trajectory into the output stream.
Definition: MCDumpers.h:289
unsigned int fPointsPerLine
trajectory points per output line
void DumpMCParticle(Stream &&out, simb::MCParticle const &particle, std::string indent, std::string firstIndent)
Dumps the content of the specified particle in the output stream.
Definition: MCDumpers.h:228
void sim::DumpMCParticles::endJob ( )
override

May print some warnings.

Definition at line 311 of file DumpMCParticles_module.cc.

311  {
312 
313  if (fNMissingTruth > 0) {
314  mf::LogProblem(fOutputCategory)
315  << "Warning: " << fNMissingTruth << "/" << fNEvents
316  << " events lacked event generator information for '"
317  << fParticleTruthInfo << "'.";
318  }
319  else if (fNMissingTruthIndex > 0) {
320  mf::LogProblem(fOutputCategory)
321  << "Warning: " << fNMissingTruthIndex << "/" << fNEvents
322  << " events lacked information of which particles of '"
323  << fParticleTruthInfo << "' are generator particles.";
324  }
325 
326 } // sim::DumpMCParticles::endJob()
std::string fOutputCategory
name of the stream for output
unsigned int fNMissingTruthIndex
Count of events without truth index.
unsigned int fNMissingTruth
Count of events without truth association.
art::InputTag fParticleTruthInfo
name of MCParticle assns data product
DumpMCParticles& sim::DumpMCParticles::operator= ( DumpMCParticles const &  )
delete
DumpMCParticles& sim::DumpMCParticles::operator= ( DumpMCParticles &&  )
delete

Member Data Documentation

art::InputTag sim::DumpMCParticles::fInputParticles
private

name of MCParticle's data product

Definition at line 125 of file DumpMCParticles_module.cc.

unsigned int sim::DumpMCParticles::fNEvents = 0U
private

Count of processed events.

Definition at line 130 of file DumpMCParticles_module.cc.

unsigned int sim::DumpMCParticles::fNMissingTruth = 0U
private

Count of events without truth association.

Definition at line 132 of file DumpMCParticles_module.cc.

unsigned int sim::DumpMCParticles::fNMissingTruthIndex = 0U
private

Count of events without truth index.

Definition at line 134 of file DumpMCParticles_module.cc.

std::string sim::DumpMCParticles::fOutputCategory
private

name of the stream for output

Definition at line 127 of file DumpMCParticles_module.cc.

art::InputTag sim::DumpMCParticles::fParticleTruthInfo
private

name of MCParticle assns data product

Definition at line 126 of file DumpMCParticles_module.cc.

unsigned int sim::DumpMCParticles::fPointsPerLine
private

trajectory points per output line

Definition at line 128 of file DumpMCParticles_module.cc.


The documentation for this class was generated from the following file: