Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
sim::DumpMCTruth Class Reference
Inheritance diagram for sim::DumpMCTruth:
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

 DumpMCTruth (Parameters const &config)
 Configuration-checking constructor. More...
 
 DumpMCTruth (DumpMCTruth const &)=delete
 
 DumpMCTruth (DumpMCTruth &&)=delete
 
DumpMCTruthoperator= (DumpMCTruth const &)=delete
 
DumpMCTruthoperator= (DumpMCTruth &&)=delete
 
void analyze (art::Event const &event) override
 
 DumpMCTruth (Parameters const &config)
 Configuration-checking constructor. More...
 
 DumpMCTruth (DumpMCTruth const &)=delete
 
 DumpMCTruth (DumpMCTruth &&)=delete
 
DumpMCTruthoperator= (DumpMCTruth const &)=delete
 
DumpMCTruthoperator= (DumpMCTruth &&)=delete
 
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 MCTruth data products. More...
 
std::string fOutputCategory
 Name of the stream for output. More...
 
bool bAllTruth = false
 Whether to process all MCTruth collections. More...
 
unsigned int fPointsPerLine
 trajectory points per output line 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 37 of file DumpMCTruth_module.cc.

Member Typedef Documentation

Type to enable module parameters description by art.

Definition at line 65 of file DumpMCTruth_module.cc.

Type to enable module parameters description by art.

Definition at line 65 of file DumpMCTruth_module.cc.

Constructor & Destructor Documentation

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

Configuration-checking constructor.

Definition at line 102 of file DumpMCTruth_module.cc.

103  : EDAnalyzer(config)
104  , fInputTruth()
105  , fOutputCategory(config().OutputCategory())
106  , bAllTruth(!config().InputTruth(fInputTruth)) // true if InputTruth omitted
107  , fPointsPerLine(config().PointsPerLine())
108  {}
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
unsigned int fPointsPerLine
trajectory points per output line
static Config * config
Definition: config.cpp:1054
bool bAllTruth
Whether to process all MCTruth collections.
std::vector< art::InputTag > fInputTruth
Name of MCTruth data products.
std::string fOutputCategory
Name of the stream for output.
sim::DumpMCTruth::DumpMCTruth ( DumpMCTruth const &  )
delete
sim::DumpMCTruth::DumpMCTruth ( DumpMCTruth &&  )
delete
sim::DumpMCTruth::DumpMCTruth ( Parameters const &  config)
explicit

Configuration-checking constructor.

sim::DumpMCTruth::DumpMCTruth ( DumpMCTruth const &  )
delete
sim::DumpMCTruth::DumpMCTruth ( DumpMCTruth &&  )
delete

Member Function Documentation

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

Implements art::EDAnalyzer.

Definition at line 112 of file DumpMCTruth_module.cc.

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

Implements art::EDAnalyzer.

DumpMCTruth& sim::DumpMCTruth::operator= ( DumpMCTruth const &  )
delete
DumpMCTruth& sim::DumpMCTruth::operator= ( DumpMCTruth const &  )
delete
DumpMCTruth& sim::DumpMCTruth::operator= ( DumpMCTruth &&  )
delete
DumpMCTruth& sim::DumpMCTruth::operator= ( DumpMCTruth &&  )
delete
template<typename Handle >
std::string sim::DumpMCTruth::productName ( Handle const &  handle)
static

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

Definition at line 234 of file DumpMCTruth_module.cc.

234  {
235  auto const* prov = handle.provenance();
236  return prov->moduleLabel()
237  + '_' + prov->productInstanceName()
238  + '_' + prov->processName()
239  ;
240 } // sim::DumpMCTruth::productName()
template<typename Handle >
static std::string sim::DumpMCTruth::productName ( Handle const &  handle)
static

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

Member Data Documentation

bool sim::DumpMCTruth::bAllTruth = false
private

Whether to process all MCTruth collections.

Definition at line 90 of file DumpMCTruth_module.cc.

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

Name of MCTruth data products.

Definition at line 88 of file DumpMCTruth_module.cc.

std::string sim::DumpMCTruth::fOutputCategory
private

Name of the stream for output.

Definition at line 89 of file DumpMCTruth_module.cc.

unsigned int sim::DumpMCTruth::fPointsPerLine
private

trajectory points per output line

Definition at line 92 of file DumpMCTruth_module.cc.


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