34 class DumpMCParticles;
38 using namespace fhicl;
46 Name(
"InputParticles"),
47 Comment(
"data product with the MC particles to be dumped")};
50 Name(
"ParticleTruthInfo"),
51 Comment(
"label of the association to MCTruth (default: as `InputParticles`)")};
54 Name(
"OutputCategory"),
55 Comment(
"name of the output stream (managed by the message facility)"),
60 Name(
"PointsPerLine"),
61 Comment(
"trajectory points printed per line (default: 2; 0 = skip them)"),
109 template <
typename Stream>
115 bool bIndentFirst =
true)
const;
138 class ProductNameCache {
144 template <
typename T>
147 auto const iInfo = fNames.find(ptr.
id());
148 return (iInfo == fNames.end()) ? fetch(ptr) : iInfo->second;
153 std::map<art::ProductID, art::InputTag> fNames;
155 template <
typename T>
159 return provenance->inputTag();
164 template <
typename T>
168 return fNames.try_emplace(ptr.
id(), tag).first->second;
174 template <
typename Right,
typename Metadata,
typename Left>
175 std::unique_ptr<art::FindOneP<Right, Metadata>> makeFindOneP(
182 if (!event.
getByLabel(tag, assnsHandle))
return {};
184 return std::make_unique<art::FindOneP<Right, Metadata>>(handle, event, tag);
203 template <
typename Stream>
215 if (truthTag.
label().empty())
216 out <<
"unknown truth record";
218 out <<
"'" << truthTag.
encode() <<
"'";
225 std::forward<Stream>(out), particle, indent, bIndentFirst ? indent :
"");
242 ProductNameCache namesRegistry(event);
245 auto const& particleHandle =
event.getValidHandle<std::vector<simb::MCParticle>>(
fInputParticles);
251 auto particleToTruth = makeFindOneP<simb::MCTruth, sim::GeneratedParticleInfo>(
253 std::unique_ptr<art::FindOneP<simb::MCTruth>> particleToTruthLight;
254 if (!particleToTruth) {
256 particleToTruthLight =
263 << Particles.size() <<
" MCParticle's";
265 unsigned int iParticle = 0;
273 particleToTruthLight ?
274 particleToTruthLight->at(iParticle) :
280 particleToTruth->data(iParticle).ref() :
284 log <<
"\n[#" << (iParticle++) <<
"] ";
303 <<
" events lacked information of which particles of '"
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
unsigned int NumberTrajectoryPoints() const
static constexpr GeneratedParticleIndex_t NoGeneratedParticleIndex
Constant representing the absence of generator truth information.
bool hasGeneratedParticleIndex() const
Returns whether the specified one is an acceptable generator index.
std::string fOutputCategory
name of the stream for output
const simb::MCTrajectory & Trajectory() const
void DumpMCParticleTrajectory(Stream &&out, simb::MCTrajectory const &trajectory, unsigned int pointsPerLine, std::string indent)
Dumps the specified particle trajectory into the output stream.
Contains data associated to particles from detector simulation.
EDAnalyzer(fhicl::ParameterSet const &pset)
MaybeLogger_< ELseverityLevel::ELsev_error, true > LogProblem
unsigned int fNMissingTruthIndex
Count of events without truth index.
Utility functions to print MC truth information.
#define DEFINE_ART_MODULE(klass)
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.
std::string indent(std::size_t const i)
unsigned int fNMissingTruth
Count of events without truth association.
ProductID id() const noexcept
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Contains information about a generated particle.
unsigned int fPointsPerLine
trajectory points per output line
art::InputTag fParticleTruthInfo
name of MCParticle assns data product
void endJob() override
May print some warnings.
void analyze(art::Event const &event) override
art::InputTag fInputParticles
name of MCParticle's data product
GeneratedParticleIndex_t generatedParticleIndex() const
Returns the generated particle index.
DumpMCParticles & operator=(DumpMCParticles const &)=delete
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.
Event finding and building.
std::optional< Provenance const > getProductProvenance(ProductID) const
DumpMCParticles(Parameters const &config)
Configuration-checking constructor.