45 Comment(
"data product with the collection of MC truth to be dumped")};
48 Name(
"OutputCategory"),
49 Comment(
"name of the output stream (managed by the message facility)"),
54 Name(
"PointsPerLine"),
55 Comment(
"trajectory points printed per line (default: 2; 0 = skip them)"),
77 template <
typename Handle>
78 static std::string
productName(Handle
const& handle);
108 struct ProductInfo_t {
109 using Thruths_t = std::vector<simb::MCTruth>;
110 Thruths_t
const* truths;
123 std::vector<ProductInfo_t> AllTruths;
127 auto handles =
event.getMany<std::vector<simb::MCTruth>>();
128 std::copy(handles.begin(), handles.end(), std::back_inserter(AllTruths));
132 AllTruths.emplace_back(event.
getValidHandle<std::vector<simb::MCTruth>>(inputTag));
139 if (AllTruths.empty()) {
146 unsigned int const nTruths = std::accumulate(
147 AllTruths.begin(), AllTruths.end(), 0U, [](
unsigned int total,
auto const& info) {
148 return total + (info.truths ? info.truths->size() : 0);
153 <<
"Event " <<
event.id() <<
" contains " << nTruths <<
" MC truth blocks in " 154 << AllTruths.size() <<
" collections";
156 else if (AllTruths.size() == 1) {
161 << AllTruths.size() <<
" collections in event " <<
event.id();
167 unsigned int nParticles = 0, nNeutrinos = 0;
168 for (ProductInfo_t
const& truths_info : AllTruths) {
170 auto const* truths = truths_info.truths;
175 <<
"Data product '" << productName <<
"' has been dropped. No information available.";
178 if (AllTruths.size() > 1) {
180 <<
"Data product '" << productName <<
"' contains " << truths->size() <<
" truth blocks:";
182 else if (truths->size() > 1) {
189 unsigned int iTruth = 0;
190 for (
auto const& truth : *truths) {
194 if (truths->size() > 1) log <<
"(#" << iTruth <<
") ";
201 nParticles += truth.NParticles();
202 if (truth.NeutrinoSet()) ++nNeutrinos;
212 <<
" generated particles to be simulated downstream.";
217 template <
typename Handle>
220 auto const* prov = handle.provenance();
221 return prov->moduleLabel() +
'_' + prov->productInstanceName() +
'_' + prov->processName();
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
fhicl::Atom< unsigned int > PointsPerLine
DumpMCTruth & operator=(DumpMCTruth const &)=delete
fhicl::OptionalSequence< art::InputTag > InputTruth
fhicl::Atom< std::string > OutputCategory
Collection of configuration parameters for the module.
EDAnalyzer(fhicl::ParameterSet const &pset)
unsigned int fPointsPerLine
trajectory points per output line
T const * product() const
void analyze(art::Event const &event) override
T const * product() const
Utility functions to print MC truth information.
#define DEFINE_ART_MODULE(klass)
Provenance const * provenance() const
void DumpMCTruth(Stream &&out, simb::MCTruth const &truth, unsigned int pointsPerLine, std::string indent, std::string firstIndent)
Dumps the content of the specified MC truth in the output stream.
bool bAllTruth
Whether to process all MCTruth collections.
DumpMCTruth(Parameters const &config)
Configuration-checking constructor.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::string fOutputCategory
Name of the stream for output.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
static std::string productName(Handle const &handle)
Returns the name of the product in the form "module_instance_process".
Event finding and building.
std::vector< art::InputTag > fInputTruth
Name of MCTruth data products.