Public Types | Public Member Functions | Static 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::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Public Types

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

Public Member Functions

 TruthSlim (fhicl::ParameterSet const &pset)
 
virtual ~TruthSlim ()
 
void produce (art::Event &evt)
 
void beginRun (art::Run &run)
 
template<typename PROD , BranchType B = InEvent>
ProductID getProductID (std::string const &instanceName={}) const
 
template<typename PROD , BranchType B>
ProductID getProductID (ModuleDescription const &moduleDescription, std::string const &instanceName) const
 
bool modifiesEvent () const
 
template<typename T , BranchType = InEvent>
ProductToken< Tconsumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< Tconsumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TconsumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< TmayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< TmayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TmayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

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

using art::EDProducer::ModuleType = EDProducer
inherited

Definition at line 34 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::EDProducer::Table = ProducerBase::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 43 of file EDProducer.h.

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

Definition at line 35 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  : fTruthLabel(pset.get< std::string >("TruthLabel"))
59  , fGeantLabel(pset.get< std::string >("GeantLabel"))
60  {
61 
62  // Start counting the time
63  fStopwatch.Start();
64 
65  // Produce new (slimmed) truth containers
66  produces< std::vector<simb::MCTruth> >();
67  produces< std::vector<simb::MCFlux> >();
68  produces< std::vector<simb::GTruth> >();
69  produces< art::Assns<simb::MCTruth, simb::MCFlux> >();
70  produces< art::Assns<simb::MCTruth, simb::GTruth> >();
71 
72  }// end of constructor
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 76 of file TruthSlim_module.cc.

References fStopwatch.

77  {
78  fStopwatch.Stop();
79  mf::LogVerbatim("TruthSlim") << "real time to run truth slimming: " << fStopwatch.RealTime();
80  }// 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 83 of file TruthSlim_module.cc.

84  {
85  return;
86  }// end of begin job
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 146 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

147 {
148  if (!moduleContext_)
149  return ProductToken<T>::invalid();
150 
151  consumables_[BT].emplace_back(ConsumableType::Product,
152  TypeID{typeid(T)},
153  it.label(),
154  it.instance(),
155  it.process());
156  return ProductToken<T>{it};
157 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 161 of file Consumer.h.

References T.

162 {
163  if (!moduleContext_)
164  return;
165 
166  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
167 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 171 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

172 {
173  if (!moduleContext_)
174  return ViewToken<T>::invalid();
175 
176  consumables_[BT].emplace_back(ConsumableType::ViewElement,
177  TypeID{typeid(T)},
178  it.label(),
179  it.instance(),
180  it.process());
181  return ViewToken<T>{it};
182 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited
CurrentProcessingContext const* art::EDProducer::currentContext ( ) const
protectedinherited
seed_t art::EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited
template<typename PROD , BranchType B>
ProductID art::EDProducer::getProductID ( std::string const &  instanceName = {}) const
inlineinherited

Definition at line 123 of file EDProducer.h.

References art::EDProducer::moduleDescription_.

Referenced by skim::NueSkimmer::CopyMichelSlice(), and skim::NueSkimmer::CopyMichelTrack().

124  {
125  return ProducerBase::getProductID<PROD, B>(moduleDescription_,
126  instanceName);
127  }
ModuleDescription moduleDescription_
Definition: EDProducer.h:115
template<typename PROD , BranchType B>
ProductID art::ProducerBase::getProductID ( ModuleDescription const &  moduleDescription,
std::string const &  instanceName 
) const
inherited

Definition at line 56 of file ProducerBase.h.

References art::ModuleDescription::moduleLabel().

Referenced by art::ProducerBase::modifiesEvent().

58  {
59  auto const& pd =
60  get_ProductDescription<PROD>(B, md.moduleLabel(), instanceName);
61  return pd.productID();
62  }
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 189 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

190 {
191  if (!moduleContext_)
192  return ProductToken<T>::invalid();
193 
194  consumables_[BT].emplace_back(ConsumableType::Product,
195  TypeID{typeid(T)},
196  it.label(),
197  it.instance(),
198  it.process());
199  return ProductToken<T>{it};
200 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 204 of file Consumer.h.

References T.

205 {
206  if (!moduleContext_)
207  return;
208 
209  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
210 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 214 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

215 {
216  if (!moduleContext_)
217  return ViewToken<T>::invalid();
218 
219  consumables_[BT].emplace_back(ConsumableType::ViewElement,
220  TypeID{typeid(T)},
221  it.label(),
222  it.instance(),
223  it.process());
224  return ViewToken<T>{it};
225 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID(), and string.

41  {
42  return true;
43  }
static cet::exempt_ptr<Consumer> art::Consumer::non_module_context ( )
staticinherited
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited
void g4n::TruthSlim::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 89 of file TruthSlim_module.cc.

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

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

Referenced by art::RootOutput::endJob().

void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

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: