Public Types | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
g4n::TruthSlim Class Reference

A module to slim the generator output. More...

Inheritance diagram for g4n::TruthSlim:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 TruthSlim (fhicl::ParameterSet const &pset)
 
virtual ~TruthSlim ()
 
void produce (art::Event &evt)
 
void beginRun (art::Run &run)
 
std::string workerType () const
 
void doBeginJob ()
 
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)
 
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< TconsumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< TmayConsumeView (InputTag const &tag)
 

Protected Member Functions

ConsumesCollector & consumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< Tconsumes (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< TmayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Private Attributes

TStopwatch fStopwatch
 keep track of how long it takes to run the job More...
 
std::string fTruthLabel
 label used for the Monte Carlo generator module More...
 
std::string fGeantLabel
 label used for the Geant simulation module More...
 

Detailed Description

A module to slim the generator output.

Definition at line 38 of file TruthSlim_module.cc.

Member Typedef Documentation

Definition at line 17 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::detail::Producer::Table = Modifier::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 25 of file Producer.h.

using art::EDProducer::WorkerType = WorkerT<EDProducer>
inherited

Definition at line 18 of file EDProducer.h.

Constructor & Destructor Documentation

g4n::TruthSlim::TruthSlim ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 57 of file TruthSlim_module.cc.

References fStopwatch.

58  : EDProducer(pset)
59  , fTruthLabel(pset.get< std::string >("TruthLabel"))
60  , fGeantLabel(pset.get< std::string >("GeantLabel"))
61  {
62 
63  // Start counting the time
64  fStopwatch.Start();
65 
66  // Produce new (slimmed) truth containers
67  produces< std::vector<simb::MCTruth> >();
68  produces< std::vector<simb::MCFlux> >();
69  produces< std::vector<simb::GTruth> >();
70  produces< art::Assns<simb::MCTruth, simb::MCFlux> >();
71  produces< art::Assns<simb::MCTruth, simb::GTruth> >();
72 
73  }// end of constructor
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
std::string fGeantLabel
label used for the Geant simulation module
std::string fTruthLabel
label used for the Monte Carlo generator module
TStopwatch fStopwatch
keep track of how long it takes to run the job
enum BeamMode string
g4n::TruthSlim::~TruthSlim ( )
virtual

Definition at line 77 of file TruthSlim_module.cc.

References fStopwatch.

78  {
79  fStopwatch.Stop();
80  mf::LogVerbatim("TruthSlim") << "real time to run truth slimming: " << fStopwatch.RealTime();
81  }// end of destructor
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
TStopwatch fStopwatch
keep track of how long it takes to run the job

Member Function Documentation

void g4n::TruthSlim::beginRun ( art::Run run)
virtual

Reimplemented from art::EDProducer.

Definition at line 84 of file TruthSlim_module.cc.

85  {
86  return;
87  }// end of begin job
template<typename T , BranchType BT>
ProductToken< T > art::ModuleBase::consumes ( InputTag const &  tag)
protectedinherited

Definition at line 55 of file ModuleBase.h.

References art::ModuleBase::collector_, art::ConsumesCollector::consumes(), T, and getGoodRuns4SAM::tag.

56  {
57  return collector_.consumes<T, BT>(tag);
58  }
ConsumesCollector collector_
Definition: ModuleBase.h:50
ProductToken< T > consumes(InputTag const &)
double T
Definition: Xdiff_gwt.C:5
ConsumesCollector& art::ModuleBase::consumesCollector ( )
protectedinherited
template<typename T , BranchType BT>
void art::ModuleBase::consumesMany ( )
protectedinherited

Definition at line 69 of file ModuleBase.h.

References art::ModuleBase::collector_, art::ConsumesCollector::consumesMany(), and T.

70  {
71  collector_.consumesMany<T, BT>();
72  }
ConsumesCollector collector_
Definition: ModuleBase.h:50
double T
Definition: Xdiff_gwt.C:5
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::ModuleBase::consumesView ( InputTag const &  )
protectedinherited
template<typename T , BranchType BT>
ViewToken<T> art::ModuleBase::consumesView ( InputTag const &  tag)
inherited

Definition at line 62 of file ModuleBase.h.

References art::ModuleBase::collector_, art::ConsumesCollector::consumesView(), T, and getGoodRuns4SAM::tag.

63  {
64  return collector_.consumesView<T, BT>(tag);
65  }
ConsumesCollector collector_
Definition: ModuleBase.h:50
ViewToken< Element > consumesView(InputTag const &)
double T
Definition: Xdiff_gwt.C:5
void art::detail::Producer::doBeginJob ( )
inherited
bool art::detail::Producer::doBeginRun ( RunPrincipal rp,
ModuleContext const &  mc 
)
inherited
bool art::detail::Producer::doBeginSubRun ( SubRunPrincipal srp,
ModuleContext const &  mc 
)
inherited
void art::detail::Producer::doEndJob ( )
inherited
bool art::detail::Producer::doEndRun ( RunPrincipal rp,
ModuleContext const &  mc 
)
inherited
bool art::detail::Producer::doEndSubRun ( SubRunPrincipal srp,
ModuleContext const &  mc 
)
inherited
bool art::detail::Producer::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 
)
inherited
void art::detail::Producer::doRespondToCloseInputFile ( FileBlock const &  fb)
inherited
void art::detail::Producer::doRespondToCloseOutputFiles ( FileBlock const &  fb)
inherited
void art::detail::Producer::doRespondToOpenInputFile ( FileBlock const &  fb)
inherited
void art::detail::Producer::doRespondToOpenOutputFiles ( FileBlock const &  fb)
inherited
std::array<std::vector<ProductInfo>, NumBranchTypes> const& art::ModuleBase::getConsumables ( ) const
inherited
template<typename T , BranchType BT>
ProductToken< T > art::ModuleBase::mayConsume ( InputTag const &  tag)
protectedinherited

Definition at line 76 of file ModuleBase.h.

References art::ModuleBase::collector_, art::ConsumesCollector::mayConsume(), T, and getGoodRuns4SAM::tag.

77  {
78  return collector_.mayConsume<T, BT>(tag);
79  }
ProductToken< T > mayConsume(InputTag const &)
ConsumesCollector collector_
Definition: ModuleBase.h:50
double T
Definition: Xdiff_gwt.C:5
template<typename T , BranchType BT>
void art::ModuleBase::mayConsumeMany ( )
protectedinherited

Definition at line 90 of file ModuleBase.h.

References art::ModuleBase::collector_, art::ConsumesCollector::mayConsumeMany(), and T.

91  {
93  }
ConsumesCollector collector_
Definition: ModuleBase.h:50
double T
Definition: Xdiff_gwt.C:5
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::ModuleBase::mayConsumeView ( InputTag const &  )
protectedinherited
template<typename T , BranchType BT>
ViewToken<T> art::ModuleBase::mayConsumeView ( InputTag const &  tag)
inherited

Definition at line 83 of file ModuleBase.h.

References art::ModuleBase::collector_, art::ConsumesCollector::mayConsumeView(), T, and getGoodRuns4SAM::tag.

84  {
85  return collector_.mayConsumeView<T, BT>(tag);
86  }
ConsumesCollector collector_
Definition: ModuleBase.h:50
ViewToken< Element > mayConsumeView(InputTag const &)
double T
Definition: Xdiff_gwt.C:5
ModuleDescription const& art::ModuleBase::moduleDescription ( ) const
inherited
void g4n::TruthSlim::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 90 of file TruthSlim_module.cc.

References util::CreateAssn(), DEFINE_ART_MODULE(), fGeantLabel, fTruthLabel, art::DataViewImpl::getByLabel(), art::DataViewImpl::getManyByType(), MECModelEnuComparisons::i, calib::j, art::DataViewImpl::put(), and confusionMatrixTree::t.

91  {
92  // Get the Particle vector.
94  evt.getByLabel(fGeantLabel,particles);
95 
96  // Compile a list of MCTruth associated with the
97  // sim::Particles in this event
98  std::set<art::Ptr<simb::MCTruth> > truthToKeep;
99  // Retrieve the associated MCTruth(s)
100  /* each element is a *list* of MCTruths associated with each particle */
101  art::FindManyP<simb::MCTruth> truthAssn(particles,evt,fGeantLabel);
102  // Loop through MCTruth objects to accumulate list of keepers
103  for ( size_t p = 0; p < particles->size(); ++p ) {
104  for ( size_t t = 0; t < truthAssn.at(p).size(); ++t ) {
105  art::Ptr<simb::MCTruth> mcTru = truthAssn.at(p)[t];
106  truthToKeep.insert(mcTru);
107  }
108  }
109 
110  // Retrieve the MCTruth information for this event
111  std::vector< art::Handle< std::vector<simb::MCTruth> > > mclists;
112  evt.getManyByType(mclists);
113 
114  // Create the associated (slimmed) truth data containers
115  for(size_t mcl = 0; mcl < mclists.size(); ++mcl){
116  std::unique_ptr<std::vector<simb::MCTruth> > slimMCTruth (new std::vector<simb::MCTruth> );
117  std::unique_ptr<std::vector<simb::MCFlux> > slimMCFlux (new std::vector<simb::MCFlux> );
118  std::unique_ptr<std::vector<simb::GTruth> > slimGTruth (new std::vector<simb::GTruth> );
119  std::unique_ptr<art::Assns<simb::MCTruth, simb::MCFlux > > slimFluxAssns (new art::Assns<simb::MCTruth, simb::MCFlux> );
120  std::unique_ptr<art::Assns<simb::MCTruth, simb::GTruth > > slimGTruAssns (new art::Assns<simb::MCTruth, simb::GTruth> );
121  // Loop through MCTruth container(s)
122  art::Handle< std::vector<simb::MCTruth> > mclistHandle = mclists[mcl];
123  // Get MCFlux and GTruth associations
124  art::FindManyP<simb::MCFlux> fluxAssn(mclistHandle,evt,fTruthLabel);
125  art::FindManyP<simb::GTruth> gtruAssn(mclistHandle,evt,fTruthLabel);
126 
127  // Loop through MCTruth objects to veto those with no associated sim::Particles.
128  for(size_t i = 0; i < mclistHandle->size(); ++i){
129  art::Ptr<simb::MCTruth> mct(mclistHandle, i);
130  // Skip this MCTruth if it's not in the list of keepers
131  // (Only works if fSlimSimParticles was true)
132  if ( truthToKeep.find(mct) == truthToKeep.end() ) continue;
133  // Pack everything into slimmed containers and build new associations
134  slimMCTruth->push_back(*mct);
135  for ( size_t j = 0; j < fluxAssn.at(i).size(); ++j ) {
136  art::Ptr<simb::MCFlux> theFlux = fluxAssn.at(i)[j];
137  slimMCFlux->push_back(*theFlux);
138  util::CreateAssn(evt, *slimMCTruth, theFlux, *slimFluxAssns, i);
139  }
140  for ( size_t j = 0; j < gtruAssn.at(i).size(); ++j ) {
141  art::Ptr<simb::GTruth> theGTru = gtruAssn.at(i)[j];
142  slimGTruth->push_back(*theGTru);
143  util::CreateAssn(evt, *slimMCTruth, theGTru, *slimGTruAssns, i);
144  }
145  }
146  evt.put(std::move(slimMCTruth));
147  evt.put(std::move(slimMCFlux ));
148  evt.put(std::move(slimGTruth ));
149  evt.put(std::move(slimFluxAssns));
150  evt.put(std::move(slimGTruAssns));
151  }// end loop through MCTruth container(s)
152 
153  return;
154  }// end of produce
static bool CreateAssn(art::EDProducer const &prod, art::Event &evt, std::vector< T > &a, art::Ptr< U > b, art::Assns< T, U > &assn, size_t indx=UINT_MAX, std::string const &instance=std::string())
Create a 1 to 1 association between a new product and one already in the event.
const char * p
Definition: xmltok.h:285
std::string fGeantLabel
label used for the Geant simulation module
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:558
std::string fTruthLabel
label used for the Monte Carlo generator module
const double j
Definition: BetheBloch.cxx:29
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:730
void art::ModuleBase::setModuleDescription ( ModuleDescription const &  )
inherited
void art::ModuleBase::sortConsumables ( std::string const &  current_process_name)
inherited
std::string art::EDProducer::workerType ( ) const
inherited

Member Data Documentation

std::string g4n::TruthSlim::fGeantLabel
private

label used for the Geant simulation module

Definition at line 51 of file TruthSlim_module.cc.

Referenced by produce().

TStopwatch g4n::TruthSlim::fStopwatch
private

keep track of how long it takes to run the job

Definition at line 49 of file TruthSlim_module.cc.

Referenced by TruthSlim(), and ~TruthSlim().

std::string g4n::TruthSlim::fTruthLabel
private

label used for the Monte Carlo generator module

Definition at line 50 of file TruthSlim_module.cc.

Referenced by produce().


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