48 Comment(
"data product with the collection of GENIE truth to be dumped")
52 Name(
"OutputCategory"),
53 Comment(
"name of the output stream (managed by the message facility)"),
59 Comment(
"when InputTruth is empty, allow for no truth to be found"),
84 template <
typename Handle>
109 <<
"'AllowNoTruth' is only allowed if no 'InputTruth' is specified.\n";
120 struct ProductInfo_t {
121 using Thruths_t = std::vector<simb::GTruth>;
122 Thruths_t
const* truths;
126 : truths(handle.provenance()->isPresent()? handle.product(): nullptr)
135 std::vector<ProductInfo_t> AllTruths;
139 auto handles =
event.getMany<std::vector<simb::GTruth>>();
140 std::copy(handles.begin(), handles.end(), std::back_inserter(AllTruths));
144 AllTruths.emplace_back
154 <<
"No GENIE truth found to be dumped!\n";
160 unsigned int const nTruths = std::accumulate(
161 AllTruths.begin(), AllTruths.end(), 0U,
163 {
return total + (
info.truths?
info.truths->size(): 0); }
168 <<
" contains " << nTruths <<
" GENIE truth blocks in " 169 << AllTruths.size() <<
" collections";
171 else if (AllTruths.size() == 1) {
176 <<
" GENIE truth blocks from " << AllTruths.size()
177 <<
" collections in event " <<
event.id();
183 for (ProductInfo_t
const& truths_info: AllTruths) {
185 auto const* truths = truths_info.truths;
190 <<
"Data product '" << productName
191 <<
"' has been dropped. No information available.";
194 if (AllTruths.size() > 1) {
196 <<
"Data product '" << productName
197 <<
"' contains " << truths->size() <<
" truth blocks:";
199 else if (truths->size() > 1) {
201 << truths->size() <<
" truth blocks:";
207 unsigned int iTruth = 0;
208 for (
auto const& truth: *truths) {
212 if (truths->size() > 1) log <<
"(#" << iTruth <<
") ";
232 template <
typename Handle>
234 auto const* prov = handle.provenance();
235 return prov->moduleLabel()
236 +
'_' + prov->productInstanceName()
237 +
'_' + prov->processName()
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
void DumpGTruth(Stream &&out, simb::GTruth const &truth, std::string indent, std::string firstIndent)
Dumps the content of the GENIE truth in the output stream.
ChannelGroupService::Name Name
EDAnalyzer(fhicl::ParameterSet const &pset)
static std::string productName(Handle const &handle)
Returns the name of the product in the form "module_instance_process".
virtual void analyze(art::Event const &event) override
Utility functions to print MC truth information.
typename config_impl< T >::type Config
std::string fOutputCategory
Name of the stream for output.
#define DEFINE_ART_MODULE(klass)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
bool bAllTruth
Whether to process all GTruth collections.
Code to link reconstructed objects back to the MC truth information.
DumpGTruth(Parameters const &config)
Configuration-checking constructor.
fhicl::OptionalSequence< art::InputTag > InputTruth
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::vector< art::InputTag > fInputTruth
Name of GTruth data products.
fhicl::Atom< bool > AllowNoTruth
fhicl::Atom< std::string > OutputCategory
bool bAllowNoTruth
Whether to forgive when no truth is present.
DumpGTruth & operator=(DumpGTruth const &)=delete
Event finding and building.