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>
117 struct ProductInfo_t {
118 using Thruths_t = std::vector<simb::MCTruth>;
119 Thruths_t
const* truths;
123 : truths(handle.provenance()->isPresent()? handle.product(): nullptr)
132 std::vector<ProductInfo_t> AllTruths;
136 auto handles =
event.getMany<std::vector<simb::MCTruth>>();
137 std::copy(handles.begin(), handles.end(), std::back_inserter(AllTruths));
141 AllTruths.emplace_back
149 if (AllTruths.empty()) {
151 <<
"No MC truth found to be dumped!\n";
157 unsigned int const nTruths = std::accumulate(
158 AllTruths.begin(), AllTruths.end(), 0U,
160 {
return total + (
info.truths?
info.truths->size(): 0); }
165 <<
" contains " << nTruths <<
" MC truth blocks in " 166 << AllTruths.size() <<
" collections";
168 else if (AllTruths.size() == 1) {
173 <<
" MC truth blocks from " << AllTruths.size()
174 <<
" collections in event " <<
event.id();
180 unsigned int nParticles = 0, nNeutrinos = 0;
181 for (ProductInfo_t
const& truths_info: AllTruths) {
183 auto const* truths = truths_info.truths;
188 <<
"Data product '" << productName
189 <<
"' has been dropped. No information available.";
192 if (AllTruths.size() > 1) {
194 <<
"Data product '" << productName
195 <<
"' contains " << truths->size() <<
" truth blocks:";
197 else if (truths->size() > 1) {
199 << truths->size() <<
" truth blocks:";
205 unsigned int iTruth = 0;
206 for (
auto const& truth: *truths) {
210 if (truths->size() > 1) log <<
"(#" << iTruth <<
") ";
217 nParticles += truth.NParticles();
218 if (truth.NeutrinoSet()) ++nNeutrinos;
228 <<
" neutrinos generated, " << nParticles
229 <<
" generated particles to be simulated downstream.";
235 template <
typename Handle>
237 auto const* prov = handle.provenance();
238 return prov->moduleLabel()
239 +
'_' + prov->productInstanceName()
240 +
'_' + prov->processName()
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
DumpMCTruth & operator=(DumpMCTruth const &)=delete
fhicl::OptionalSequence< art::InputTag > InputTruth
ChannelGroupService::Name Name
EDAnalyzer(fhicl::ParameterSet const &pset)
unsigned int fPointsPerLine
trajectory points per output line
void analyze(art::Event const &event) override
Utility functions to print MC truth information.
typename config_impl< T >::type Config
fhicl::Atom< unsigned int > PointsPerLine
#define DEFINE_ART_MODULE(klass)
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.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
bool bAllTruth
Whether to process all MCTruth collections.
DumpMCTruth(Parameters const &config)
Configuration-checking constructor.
Code to link reconstructed objects back to the MC truth information.
std::vector< art::InputTag > fInputTruth
Name of MCTruth data products.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::string fOutputCategory
Name of the stream for output.
fhicl::Atom< std::string > OutputCategory
static std::string productName(Handle const &handle)
Returns the name of the product in the form "module_instance_process".
Event finding and building.