23 #include "canvas/Persistency/Common/FindOneP.h" 34 class DumpMCParticles;
38 using namespace fhicl;
46 Name(
"InputParticles"),
47 Comment(
"data product with the MC particles to be dumped")
51 Name(
"ParticleTruthInfo"),
53 (
"label of the association to MCTruth (default: as `InputParticles`)")
57 Name(
"OutputCategory"),
58 Comment(
"name of the output stream (managed by the message facility)"),
63 Name(
"PointsPerLine"),
64 Comment(
"trajectory points printed per line (default: 2; 0 = skip them)"),
115 template <
typename Stream>
146 class ProductNameCache {
152 template <
typename T>
155 auto const iInfo = fNames.find(ptr.
id());
156 return (iInfo == fNames.end())? fetch(ptr): iInfo->second;
161 std::map<art::ProductID, art::InputTag> fNames;
163 template <
typename T>
167 return fEvent.
get(ptr.
id(), handle)
173 template <
typename T>
177 return fNames.emplace(ptr.
id(), tag).first->second;
184 template <
typename Right,
typename Metadata,
typename Left>
185 std::unique_ptr<art::FindOneP<Right, Metadata>> makeFindOneP(
192 if (!event.
getByLabel(tag, assnsHandle))
return {};
194 return std::make_unique<art::FindOneP<Right, Metadata>>
195 (handle,
event, tag);
218 template <
typename Stream>
227 if (truthTag.
label().empty()) out <<
"unknown truth record";
228 else out <<
"'" << truthTag.
encode() <<
"'";
235 (std::forward<Stream>(out), particle, indent, bIndentFirst? indent:
"");
241 std::forward<Stream>(out), particle.
Trajectory(),
254 ProductNameCache namesRegistry(event);
257 auto const& particleHandle
258 =
event.getValidHandle<std::vector<simb::MCParticle>>(
fInputParticles);
259 auto const& Particles = *particleHandle;
264 auto particleToTruth = makeFindOneP<simb::MCTruth, sim::GeneratedParticleInfo>
266 std::unique_ptr<art::FindOneP<simb::MCTruth>> particleToTruthLight;
267 if (!particleToTruth) {
269 particleToTruthLight = makeFindOneP<simb::MCTruth, void>
276 << Particles.size() <<
" MCParticle's";
278 unsigned int iParticle = 0;
286 ? particleToTruth->at(iParticle)
287 : particleToTruthLight
288 ? particleToTruthLight->at(iParticle)
296 ? particleToTruth->data(iParticle).ref()
301 log <<
"\n[#" << (iParticle++) <<
"] ";
316 <<
" events lacked event generator information for '" 322 <<
" events lacked information of which particles of '"
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
unsigned int NumberTrajectoryPoints() const
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.
ChannelGroupService::Name Name
bool get(SelectorBase const &, Handle< PROD > &result) const
EDAnalyzer(fhicl::ParameterSet const &pset)
Utility functions to print MC truth information.
MaybeLogger_< ELseverityLevel::ELsev_error, true > LogProblem
typename config_impl< T >::type Config
unsigned int fNMissingTruthIndex
Count of events without truth index.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
#define DEFINE_ART_MODULE(klass)
Provenance const * provenance() const
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.
ProductID id() const noexcept
Code to link reconstructed objects back to the MC truth information.
Contains data associated to particles from detector simulation.
art::EDAnalyzer::Table< Config > Parameters
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.
DumpMCParticles(Parameters const &config)
Configuration-checking constructor.