Public Types | Public Member Functions | Private Attributes | List of all members
sim::DumpMCParticles Class Reference
Inheritance diagram for sim::DumpMCParticles:
art::EDAnalyzer art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::detail::Analyzer art::detail::LegacyModule art::Observer art::Observer art::ModuleBase art::ModuleBase

Public Types

using Parameters = art::EDAnalyzer::Table< Config >
 
using Parameters = art::EDAnalyzer::Table< Config >
 
- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 

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...
 
 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...
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
fhicl::ParameterSetID selectorConfig () const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

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...
 

Additional Inherited Members

- Protected Member Functions inherited from art::Observer
std::string const & processName () const
 
bool wantAllEvents () const noexcept
 
bool wantEvent (ScheduleID id, Event const &e) const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &select_paths, std::vector< std::string > const &reject_paths, fhicl::ParameterSet const &config)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 78 of file DumpMCParticles_module.cc.

Member Typedef Documentation

Definition at line 77 of file DumpMCParticles_module.cc.

Definition at line 81 of file DumpMCParticles_module.cc.

Constructor & Destructor Documentation

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

Configuration-checking constructor.

Definition at line 210 of file DumpMCParticles_module.cc.

211  : EDAnalyzer(config)
212  , fInputParticles(config().InputParticles())
213  , fOutputCategory(config().OutputCategory())
214  , fPointsPerLine(config().PointsPerLine())
215 {
216  if (!config().ParticleTruthInfo(fParticleTruthInfo))
218 
219 }
std::string fOutputCategory
name of the stream for output
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
static Config * config
Definition: config.cpp:1054
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
sim::DumpMCParticles::DumpMCParticles ( Parameters const &  config)
explicit

Configuration-checking constructor.

sim::DumpMCParticles::DumpMCParticles ( DumpMCParticles const &  )
delete
sim::DumpMCParticles::DumpMCParticles ( DumpMCParticles &&  )
delete

Member Function Documentation

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

Implements art::EDAnalyzer.

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

Implements art::EDAnalyzer.

Definition at line 254 of file DumpMCParticles_module.cc.

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

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 223 of file DumpMCParticles_module.cc.

227  {
228 
229  if (!truthTag.label().empty() || truthInfo.hasGeneratedParticleIndex()) {
230  out << "(from ";
231  if (truthTag.label().empty()) out << "unknown truth record";
232  else out << "'" << truthTag.encode() << "'";
233  if (truthInfo.hasGeneratedParticleIndex())
234  out << " particle #" << truthInfo.generatedParticleIndex();
235  out << ") ";
236  }
237 
239  (std::forward<Stream>(out), particle, indent, bIndentFirst? indent: "");
240 
241  const unsigned int nPoints = particle.NumberTrajectoryPoints();
242  if ((nPoints > 0) && (fPointsPerLine > 0)) {
243  out << ":";
245  std::forward<Stream>(out), particle.Trajectory(),
246  fPointsPerLine, indent + " "
247  );
248  } // if has points
249 
250 } // 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:288
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:227
void sim::DumpMCParticles::endJob ( )
overridevirtual

May print some warnings.

Reimplemented from art::EDAnalyzer.

void sim::DumpMCParticles::endJob ( )
overridevirtual

May print some warnings.

Reimplemented from art::EDAnalyzer.

Definition at line 315 of file DumpMCParticles_module.cc.

315  {
316 
317  if (fNMissingTruth > 0) {
319  << "Warning: " << fNMissingTruth << "/" << fNEvents
320  << " events lacked event generator information for '"
321  << fParticleTruthInfo << "'.";
322  }
323  else if (fNMissingTruthIndex > 0) {
325  << "Warning: " << fNMissingTruthIndex << "/" << fNEvents
326  << " events lacked information of which particles of '"
327  << fParticleTruthInfo << "' are generator particles.";
328  }
329 
330 } // sim::DumpMCParticles::endJob()
std::string fOutputCategory
name of the stream for output
MaybeLogger_< ELseverityLevel::ELsev_error, true > LogProblem
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
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 129 of file DumpMCParticles_module.cc.

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

Count of processed events.

Definition at line 134 of file DumpMCParticles_module.cc.

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

Count of events without truth association.

Definition at line 136 of file DumpMCParticles_module.cc.

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

Count of events without truth index.

Definition at line 138 of file DumpMCParticles_module.cc.

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

name of the stream for output

Definition at line 131 of file DumpMCParticles_module.cc.

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

name of MCParticle assns data product

Definition at line 130 of file DumpMCParticles_module.cc.

unsigned int sim::DumpMCParticles::fPointsPerLine
private

trajectory points per output line

Definition at line 132 of file DumpMCParticles_module.cc.


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