39 class DumpMCParticles;
43 using namespace fhicl;
51 Name(
"InputParticles"),
52 Comment(
"data product with the MC particles to be dumped")
56 Name(
"ParticleTruthInfo"),
58 (
"label of the association to MCTruth (default: as `InputParticles`)")
62 Name(
"OutputCategory"),
63 Comment(
"name of the output stream (managed by the message facility)"),
68 Name(
"PointsPerLine"),
69 Comment(
"trajectory points printed per line (default: 2; 0 = skip them)"),
120 template <
typename Stream>
124 std::string
indent =
"",
bool bIndentFirst =
true 151 class ProductNameCache {
157 template <
typename T>
160 auto const iInfo = fNames.find(ptr.
id());
161 return (iInfo == fNames.end())? fetch(ptr): iInfo->second;
166 std::map<art::ProductID, art::InputTag> fNames;
168 template <
typename T>
172 return fEvent.
get(ptr.
id(), handle)
178 template <
typename T>
182 return fNames.emplace(ptr.
id(), tag).first->second;
189 template <
typename Right,
typename Metadata,
typename Left>
190 std::unique_ptr<art::FindOneP<Right, Metadata>> makeFindOneP(
197 if (!event.
getByLabel(tag, assnsHandle))
return {};
199 return std::make_unique<art::FindOneP<Right, Metadata>>
200 (handle, event, tag);
223 template <
typename Stream>
227 std::string
indent ,
bool bIndentFirst
232 if (truthTag.
label().empty()) out <<
"unknown truth record";
233 else out <<
"'" << truthTag.
encode() <<
"'";
240 (std::forward<Stream>(out), particle, indent, bIndentFirst? indent:
"");
246 std::forward<Stream>(out), particle.
Trajectory(),
259 ProductNameCache namesRegistry(event);
262 auto const& particleHandle
263 =
event.getValidHandle<std::vector<simb::MCParticle>>(
fInputParticles);
269 auto particleToTruth = makeFindOneP<simb::MCTruth, sim::GeneratedParticleInfo>
271 std::unique_ptr<art::FindOneP<simb::MCTruth>> particleToTruthLight;
272 if (!particleToTruth) {
274 particleToTruthLight = makeFindOneP<simb::MCTruth, void>
281 << Particles.size() <<
" MCParticle's";
283 unsigned int iParticle = 0;
291 ? particleToTruth->at(iParticle)
292 : particleToTruthLight
293 ? particleToTruthLight->at(iParticle)
301 ? particleToTruth->data(iParticle).ref()
306 log <<
"\n[#" << (iParticle++) <<
"] ";
321 <<
" events lacked event generator information for '" 327 <<
" 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.
bool get(SelectorBase const &, Handle< PROD > &result) const
Contains data associated to particles from detector simulation.
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)
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.
std::string indent(std::size_t const i)
unsigned int fNMissingTruth
Count of events without truth association.
EDAnalyzer(Table< Config > const &config)
bool getByLabel(std::string const &label, std::string const &productInstanceName, 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
Common type definitions for data products (and a bit beyond).
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.