Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
sim::DumpGTruth Class Reference
Inheritance diagram for sim::DumpGTruth:
art::EDAnalyzer art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::detail::Analyzer art::detail::LegacyModule art::Observer art::Observer art::ModuleBase art::ModuleBase

Classes

struct  Config
 Collection of configuration parameters for the module. More...
 

Public Types

using Parameters = art::EDAnalyzer::Table< Config >
 Type to enable module parameters description by art. More...
 
using Parameters = art::EDAnalyzer::Table< Config >
 Type to enable module parameters description by art. More...
 
- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 

Public Member Functions

 DumpGTruth (Parameters const &config)
 Configuration-checking constructor. More...
 
 DumpGTruth (DumpGTruth const &)=delete
 
 DumpGTruth (DumpGTruth &&)=delete
 
DumpGTruthoperator= (DumpGTruth const &)=delete
 
DumpGTruthoperator= (DumpGTruth &&)=delete
 
virtual void analyze (art::Event const &event) override
 
 DumpGTruth (Parameters const &config)
 Configuration-checking constructor. More...
 
 DumpGTruth (DumpGTruth const &)=delete
 
 DumpGTruth (DumpGTruth &&)=delete
 
DumpGTruthoperator= (DumpGTruth const &)=delete
 
DumpGTruthoperator= (DumpGTruth &&)=delete
 
virtual void analyze (art::Event const &event) override
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
fhicl::ParameterSetID selectorConfig () const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Static Public Member Functions

template<typename Handle >
static std::string productName (Handle const &handle)
 Returns the name of the product in the form "module_instance_process". More...
 
template<typename Handle >
static std::string productName (Handle const &handle)
 Returns the name of the product in the form "module_instance_process". More...
 

Private Attributes

std::vector< art::InputTagfInputTruth
 Name of GTruth data products. More...
 
std::string fOutputCategory
 Name of the stream for output. More...
 
bool bAllTruth = false
 Whether to process all GTruth collections. More...
 
bool bAllowNoTruth = false
 Whether to forgive when no truth is present. More...
 

Additional Inherited Members

- Protected Member Functions inherited from art::Observer
std::string const & processName () const
 
bool wantAllEvents () const noexcept
 
bool wantEvent (ScheduleID id, Event const &e) const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &select_paths, std::vector< std::string > const &reject_paths, fhicl::ParameterSet const &config)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 39 of file DumpGTruth_module.cc.

Member Typedef Documentation

Type to enable module parameters description by art.

Definition at line 67 of file DumpGTruth_module.cc.

Type to enable module parameters description by art.

Definition at line 68 of file DumpGTruth_module.cc.

Constructor & Destructor Documentation

sim::DumpGTruth::DumpGTruth ( Parameters const &  config)
explicit

Configuration-checking constructor.

Definition at line 101 of file DumpGTruth_module.cc.

102  : EDAnalyzer(config)
103  , fInputTruth()
104  , fOutputCategory(config().OutputCategory())
105  , bAllTruth(!config().InputTruth(fInputTruth)) // true if InputTruth omitted
106  , bAllowNoTruth(config().AllowNoTruth())
107 {
108  if (!bAllTruth && bAllowNoTruth) {
110  << "'AllowNoTruth' is only allowed if no 'InputTruth' is specified.\n";
111  }
112 }
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
std::string fOutputCategory
Name of the stream for output.
static Config * config
Definition: config.cpp:1054
bool bAllTruth
Whether to process all GTruth collections.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::vector< art::InputTag > fInputTruth
Name of GTruth data products.
bool bAllowNoTruth
Whether to forgive when no truth is present.
sim::DumpGTruth::DumpGTruth ( DumpGTruth const &  )
delete
sim::DumpGTruth::DumpGTruth ( DumpGTruth &&  )
delete
sim::DumpGTruth::DumpGTruth ( Parameters const &  config)
explicit

Configuration-checking constructor.

sim::DumpGTruth::DumpGTruth ( DumpGTruth const &  )
delete
sim::DumpGTruth::DumpGTruth ( DumpGTruth &&  )
delete

Member Function Documentation

virtual void sim::DumpGTruth::analyze ( art::Event const &  event)
overridevirtual

Implements art::EDAnalyzer.

void sim::DumpGTruth::analyze ( art::Event const &  event)
overridevirtual

Implements art::EDAnalyzer.

Definition at line 116 of file DumpGTruth_module.cc.

116  {
117 
118  //
119  // prepare the data products to be dumped
120  //
121  struct ProductInfo_t {
122  using Thruths_t = std::vector<simb::GTruth>;
123  Thruths_t const* truths;
125 
126  ProductInfo_t(art::Handle<Thruths_t> const& handle)
127  : truths(handle.provenance()->isPresent()? handle.product(): nullptr)
128  , name(sim::DumpGTruth::productName(handle))
129  {}
130  ProductInfo_t(art::ValidHandle<Thruths_t> const& handle)
131  : truths(handle.product()), name(sim::DumpGTruth::productName(handle))
132  {}
133 
134  }; // ProductInfo_t
135 
136  std::vector<ProductInfo_t> AllTruths;
137  if (bAllTruth) {
138  auto handles = event.getMany<std::vector<simb::GTruth> >();
139  std::copy(handles.begin(), handles.end(), std::back_inserter(AllTruths));
140  }
141  else {
142  for (auto const& inputTag: fInputTruth) {
143  AllTruths.emplace_back
144  (event.getValidHandle<std::vector<simb::GTruth>>(inputTag));
145  } // for
146  }
147 
148  //
149  // sanity check
150  //
151  if (AllTruths.empty() && !bAllowNoTruth) {
153  << "No GENIE truth found to be dumped!\n";
154  }
155 
156  //
157  // print an introduction
158  //
159  unsigned int const nTruths = std::accumulate(
160  AllTruths.begin(), AllTruths.end(), 0U,
161  [](unsigned int total, auto const& info)
162  { return total + (info.truths? info.truths->size(): 0); }
163  );
164 
165  if (bAllTruth) {
166  mf::LogVerbatim(fOutputCategory) << "Event " << event.id()
167  << " contains " << nTruths << " GENIE truth blocks in "
168  << AllTruths.size() << " collections";
169  }
170  else if (AllTruths.size() == 1) {
171  mf::LogVerbatim(fOutputCategory) << "Event " << event.id();
172  }
173  else {
174  mf::LogVerbatim(fOutputCategory) << "Dumping " << nTruths
175  << " GENIE truth blocks from " << AllTruths.size()
176  << " collections in event " << event.id();
177  }
178 
179  //
180  // dump data product by data product
181  //
182  for (ProductInfo_t const& truths_info: AllTruths) {
183 
184  auto const* truths = truths_info.truths;
185  std::string productName = truths_info.name;
186 
187  if (!truths) {
189  << "Data product '" << productName
190  << "' has been dropped. No information available.";
191  }
192 
193  if (AllTruths.size() > 1) {
195  << "Data product '" << productName
196  << "' contains " << truths->size() << " truth blocks:";
197  }
198  else if (truths->size() > 1) {
200  << truths->size() << " truth blocks:";
201  }
202 
203  //
204  // dump each GENIE truth in the data product
205  //
206  unsigned int iTruth = 0;
207  for (auto const& truth: *truths) {
208 
210 
211  if (truths->size() > 1) log << "(#" << iTruth << ") ";
212  sim::dump::DumpGTruth(log, truth, " ", "");
213 
214  //
215  // update counters
216  //
217  ++iTruth;
218 
219  } // for each truth in data product
220 
221  } // for truth data products
222 
223  //
224  // all done
225  //
226 
227 } // sim::DumpGTruth::analyze()
static QCString name
Definition: declinfo.cpp:673
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.
Definition: MCDumpers.h:378
std::string string
Definition: nybbler.cc:12
static std::string productName(Handle const &handle)
Returns the name of the product in the form "module_instance_process".
std::string fOutputCategory
Name of the stream for output.
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.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::vector< art::InputTag > fInputTruth
Name of GTruth data products.
T copy(T const &v)
bool bAllowNoTruth
Whether to forgive when no truth is present.
Event finding and building.
DumpGTruth& sim::DumpGTruth::operator= ( DumpGTruth const &  )
delete
DumpGTruth& sim::DumpGTruth::operator= ( DumpGTruth const &  )
delete
DumpGTruth& sim::DumpGTruth::operator= ( DumpGTruth &&  )
delete
DumpGTruth& sim::DumpGTruth::operator= ( DumpGTruth &&  )
delete
template<typename Handle >
static std::string sim::DumpGTruth::productName ( Handle const &  handle)
static

Returns the name of the product in the form "module_instance_process".

template<typename Handle >
std::string sim::DumpGTruth::productName ( Handle const &  handle)
static

Returns the name of the product in the form "module_instance_process".

Definition at line 232 of file DumpGTruth_module.cc.

232  {
233  auto const* prov = handle.provenance();
234  return prov->moduleLabel()
235  + '_' + prov->productInstanceName()
236  + '_' + prov->processName()
237  ;
238 } // sim::DumpGTruth::productName()

Member Data Documentation

bool sim::DumpGTruth::bAllowNoTruth = false
private

Whether to forgive when no truth is present.

Definition at line 93 of file DumpGTruth_module.cc.

bool sim::DumpGTruth::bAllTruth = false
private

Whether to process all GTruth collections.

Definition at line 92 of file DumpGTruth_module.cc.

std::vector< art::InputTag > sim::DumpGTruth::fInputTruth
private

Name of GTruth data products.

Definition at line 90 of file DumpGTruth_module.cc.

std::string sim::DumpGTruth::fOutputCategory
private

Name of the stream for output.

Definition at line 91 of file DumpGTruth_module.cc.


The documentation for this class was generated from the following file: