117 struct ProductInfo_t {
118 using Thruths_t = std::vector<simb::MCTruth>;
119 Thruths_t
const* truths;
122 ProductInfo_t(art::Handle<Thruths_t>
const& handle)
123 : truths(handle.provenance()->isPresent()? handle.product(): nullptr)
126 ProductInfo_t(art::ValidHandle<Thruths_t>
const& handle)
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
142 (event.getValidHandle<std::vector<simb::MCTruth>>(inputTag));
149 if (AllTruths.empty()) {
150 throw art::Exception(art::errors::ProductNotFound)
151 <<
"No MC truth found to be dumped!\n";
157 unsigned int const nTruths = std::accumulate(
158 AllTruths.begin(), AllTruths.end(), 0U,
159 [](
unsigned int total,
auto const&
info)
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.";
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.
std::string fOutputCategory
Name of the stream for output.
static std::string productName(Handle const &handle)
Returns the name of the product in the form "module_instance_process".
std::vector< art::InputTag > fInputTruth
Name of MCTruth data products.