23 #include "canvas/Persistency/Common/FindOneP.h" 38 class DumpMCParticles;
42 using namespace fhicl;
50 Name(
"InputParticles"),
51 Comment(
"data product with the MC particles to be dumped")
55 Name(
"ParticleTruthInfo"),
57 (
"label of the association to MCTruth (default: as `InputParticles`)")
61 Name(
"OutputCategory"),
62 Comment(
"name of the output stream (managed by the message facility)"),
67 Name(
"PointsPerLine"),
68 Comment(
"trajectory points printed per line (default: 2; 0 = skip them)"),
119 template <
typename Stream>
150 class ProductNameCache {
156 template <
typename T>
159 auto const iInfo = fNames.find(ptr.
id());
160 return (iInfo == fNames.end())? fetch(ptr): iInfo->second;
165 std::map<art::ProductID, art::InputTag> fNames;
167 template <
typename T>
171 return fEvent.
get(ptr.
id(), handle)
177 template <
typename T>
181 return fNames.emplace(ptr.
id(), tag).first->second;
188 template <
typename Right,
typename Metadata,
typename Left>
189 std::unique_ptr<art::FindOneP<Right, Metadata>> makeFindOneP(
196 if (!assnsHandle)
return {};
198 return std::make_unique<art::FindOneP<Right, Metadata>>
199 (handle,
event, tag);
222 template <
typename Stream>
231 if (truthTag.
label().empty()) out <<
"unknown truth record";
232 else out <<
"'" << truthTag.
encode() <<
"'";
239 (std::forward<Stream>(out), particle, indent, bIndentFirst? indent:
"");
245 std::forward<Stream>(out), particle.
Trajectory(),
258 ProductNameCache namesRegistry(event);
261 auto const& particleHandle
262 =
event.getValidHandle<std::vector<simb::MCParticle>>(
fInputParticles);
263 auto const& Particles = *particleHandle;
268 auto particleToTruth = makeFindOneP<simb::MCTruth, sim::GeneratedParticleInfo>
270 std::unique_ptr<art::FindOneP<simb::MCTruth>> particleToTruthLight;
271 if (!particleToTruth) {
273 particleToTruthLight = makeFindOneP<simb::MCTruth, void>
280 << Particles.size() <<
" MCParticle's";
282 unsigned int iParticle = 0;
290 ? particleToTruth->at(iParticle)
291 : particleToTruthLight
292 ? particleToTruthLight->at(iParticle)
300 ? particleToTruth->data(iParticle).ref()
305 log <<
"\n[#" << (iParticle++) <<
"] ";
320 <<
" events lacked event generator information for '" 326 <<
" 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)
MaybeLogger_< ELseverityLevel::ELsev_error, true > LogProblem
typename config_impl< T >::type Config
unsigned int fNMissingTruthIndex
Count of events without truth index.
#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.
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.