47 Comment(
"data product with the collection of MC truth to be dumped")
51 Name(
"OutputCategory"),
52 Comment(
"name of the output stream (managed by the message facility)"),
57 Name(
"PointsPerLine"),
58 Comment(
"trajectory points printed per line (default: 2; 0 = skip them)"),
82 template <
typename Handle>
83 static std::string
productName(Handle
const& handle);
117 struct ProductInfo_t {
118 using Thruths_t = std::vector<simb::MCTruth>;
119 Thruths_t
const* truths;
132 std::vector<ProductInfo_t> AllTruths;
134 std::vector<art::Handle<std::vector<simb::MCTruth>>> handles;
135 event.getManyByType(handles);
136 std::copy(handles.begin(), handles.end(), std::back_inserter(AllTruths));
140 AllTruths.emplace_back
148 if (AllTruths.empty()) {
150 <<
"No MC truth found to be dumped!\n";
156 unsigned int const nTruths = std::accumulate(
157 AllTruths.begin(), AllTruths.end(), 0U,
158 [](
unsigned int total,
auto const& info)
159 {
return total + (info.truths? info.truths->size(): 0); }
164 <<
" contains " << nTruths <<
" MC truth blocks in " 165 << AllTruths.size() <<
" collections";
167 else if (AllTruths.size() == 1) {
172 <<
" MC truth blocks from " << AllTruths.size()
173 <<
" collections in event " <<
event.id();
179 unsigned int nParticles = 0, nNeutrinos = 0;
180 for (ProductInfo_t
const& truths_info: AllTruths) {
182 auto const* truths = truths_info.truths;
187 <<
"Data product '" << productName
188 <<
"' has been dropped. No information available.";
191 if (AllTruths.size() > 1) {
193 <<
"Data product '" << productName
194 <<
"' contains " << truths->size() <<
" truth blocks:";
196 else if (truths->size() > 1) {
198 << truths->size() <<
" truth blocks:";
204 unsigned int iTruth = 0;
205 for (
auto const& truth: *truths) {
209 if (truths->size() > 1) log <<
"(#" << iTruth <<
") ";
216 nParticles += truth.NParticles();
217 if (truth.NeutrinoSet()) ++nNeutrinos;
227 <<
" neutrinos generated, " << nParticles
228 <<
" generated particles to be simulated downstream.";
234 template <
typename Handle>
236 auto const* prov = handle.provenance();
237 return prov->moduleLabel()
238 +
'_' + prov->productInstanceName()
239 +
'_' + 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.
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.
EDAnalyzer(Table< Config > const &config)
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.