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

 G4Gen (fhicl::ParameterSet const &pset)
 
virtual ~G4Gen ()
 
void produce (art::Event &evt)
 
void beginRun (art::Run &run)
 
void endJob ()
 
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

std::string fGeneratorLabel
 
g4n::G4AlgfG4Alg
 G4Helper object. More...
 
fhicl::ParameterSet fG4AlgPSet
 parameter set to configure the G4Alg object More...
 
TStopwatch fStopwatch
 keep track of how long it takes to run the job More...
 
bool fPrintTables
 Print the dE/dx tables and other info for debugging etc.? More...
 

Detailed Description

A module to pass interaction information to Geant4 and create hits and particle lists

Definition at line 56 of file G4Gen_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::G4Gen::G4Gen ( fhicl::ParameterSet const &  pset)
explicit

Setup the FLSHitList debugger

Definition at line 83 of file G4Gen_module.cc.

References art::EngineCreator::createEngine(), fG4AlgPSet, fGeneratorLabel, fPrintTables, fStopwatch, fhicl::ParameterSet::get(), sim::GetRandomNumberSeed(), seed, and string.

84  : fG4Alg(0)
85  , fG4AlgPSet(pset.get< fhicl::ParameterSet >("G4AlgPSet") )
86  {
87  fGeneratorLabel = fG4AlgPSet.get<std::string>("GenModuleLabel");
88  fPrintTables = fG4AlgPSet.get<bool> ("PrintTables" );
89 
90  // get the random number seed, use a random default if not specified
91  // in the configuration file.
92  unsigned int seed = pset.get< unsigned int >("Seed", sim::GetRandomNumberSeed());
93  // setup the random number service for Geant4, the "G4Engine" label is a
94  // special tag setting up a global engine for use by Geant4/CLHEP
95  createEngine(seed, "G4Engine");
96 
97  // Start counting the time
98  fStopwatch.Start();
99 
100  produces< std::vector<sim::G4Status> >();
101  produces< std::vector<sim::FLSHitList > >();
102  produces< std::vector<sim::Particle> >();
103  produces< art::Assns<sim::Particle, simb::MCTruth> >();
104  produces< std::vector<sim::TrueEnergy> >();
105  produces< art::Assns<sim::TrueEnergy, sim::Particle> >();
106 
107  /// Setup the FLSHitList debugger
108  //fDoFLSHitListDebug = doG4Debug<FLSHitListDebug>();
109  // if(fDoFLSHitListDebug){
110 // mf::LogVerbatim("G4Gen") << "Will be Debugging FLSHitLists";
111 // }
112 // else{
113 // mf::LogVerbatim("G4Gen") << "Will NOT be Debugging FLSHitLists";
114 // }
115 
116 
117  }// end of constructor
bool fPrintTables
Print the dE/dx tables and other info for debugging etc.?
Definition: G4Gen_module.cc:72
base_engine_t & createEngine(seed_t seed)
unsigned int seed
Definition: runWimpSim.h:102
g4n::G4Alg * fG4Alg
G4Helper object.
Definition: G4Gen_module.cc:68
T get(std::string const &key) const
Definition: ParameterSet.h:231
unsigned int GetRandomNumberSeed()
Definition: Simulation.cxx:13
TStopwatch fStopwatch
keep track of how long it takes to run the job
Definition: G4Gen_module.cc:70
std::string fGeneratorLabel
Definition: G4Gen_module.cc:66
fhicl::ParameterSet fG4AlgPSet
parameter set to configure the G4Alg object
Definition: G4Gen_module.cc:69
enum BeamMode string
g4n::G4Gen::~G4Gen ( )
virtual

Definition at line 121 of file G4Gen_module.cc.

References fG4Alg, and fStopwatch.

122  {
123  fStopwatch.Stop();
124  mf::LogVerbatim("G4Gen") << "real time to run through Geant4: "
125  << fStopwatch.RealTime();
126  if(fG4Alg) delete fG4Alg;
127  }// end of destructor
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
g4n::G4Alg * fG4Alg
G4Helper object.
Definition: G4Gen_module.cc:68
TStopwatch fStopwatch
keep track of how long it takes to run the job
Definition: G4Gen_module.cc:70

Member Function Documentation

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

Reimplemented from art::EDProducer.

Definition at line 130 of file G4Gen_module.cc.

References fG4Alg, and fG4AlgPSet.

131  {
132  fG4Alg = new G4Alg(fG4AlgPSet);
133 
134  return;
135  }// end of begin job
g4n::G4Alg * fG4Alg
G4Helper object.
Definition: G4Gen_module.cc:68
fhicl::ParameterSet fG4AlgPSet
parameter set to configure the G4Alg object
Definition: G4Gen_module.cc:69
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
void g4n::G4Gen::endJob ( )
virtual

Reimplemented from art::EDProducer.

Definition at line 138 of file G4Gen_module.cc.

References g4n::PrintTables::dEdx(), fPrintTables, and g4n::PrintTables::Materials().

139  {
140  if(fPrintTables) {
141  PrintTables PT;
142  PT.Materials();
143  PT.dEdx();
144  }
145 
146  return;
147  }// end of endJob
bool fPrintTables
Print the dE/dx tables and other info for debugging etc.?
Definition: G4Gen_module.cc:72
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::G4Gen::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 150 of file G4Gen_module.cc.

References om::cout, util::CreateAssn(), DEFINE_ART_MODULE(), allTimeWatchdog::endl, fG4Alg, fGeneratorLabel, g4n::ParticleListAction::fTrueDepMap, art::Ptr< T >::get(), art::DataViewImpl::getByLabel(), MECModelEnuComparisons::i, g4n::G4Alg::IsAborted(), part, art::Event::put(), g4n::G4Alg::RunGeant(), simb::MCParticle::TrackId(), and trackID.

151  {
152  // need to instantiate the G4Helper in order to make the
153  // G4RunManager and pass it the physics list - G4 really dislikes
154  // it if you try to make a G4UserRunAction (ie UserActionManager)
155  // before passing a physics list to the run manager
156 
157  // Define the FLSHitList and Particle vectors.
158  std::unique_ptr<std::vector<sim::G4Status> > g4status(new std::vector<sim::G4Status>(1) );
159  std::unique_ptr<std::vector<sim::FLSHitList> > flshlcol(new std::vector<sim::FLSHitList> );
160  std::unique_ptr<std::vector<sim::Particle> > pcol (new std::vector<sim::Particle> );
161  std::unique_ptr< art::Assns<sim::Particle, simb::MCTruth> > tpassn (new art::Assns<sim::Particle, simb::MCTruth>);
162 
163  std::unique_ptr<std::vector<sim::TrueEnergy> > trueens (new std::vector<sim::TrueEnergy>);
164  std::unique_ptr<art::Assns<sim::TrueEnergy, sim::Particle> > treassn (new art::Assns<sim::TrueEnergy, sim::Particle>);
165 
166  //look to see if there is any MCTruth information for this event
168  evt.getByLabel(fGeneratorLabel, mclist);
169 
170  // the next steps are a little clunky. Make a vector of art::Ptr<MCTruth>
171  // objects to use when making the associations and another of just
172  // const* MCTruth objects to pass to G4Alg
173  std::vector< art::Ptr< simb::MCTruth > > mctp;
174  std::vector< const simb::MCTruth* > mct;
175 
176  for(size_t i = 0; i < mclist->size(); ++i){
177  art::Ptr<simb::MCTruth> ptr(mclist, i);
178  mctp.push_back(ptr);
179  mct .push_back(ptr.get());
180  }
181 
182  // make a map to keep track of which G4 track ID goes with which MCTruth object
183  std::map<int, size_t> trackIDToMCTruthIndex;
184  fG4Alg->RunGeant(mct, *flshlcol, *pcol, trackIDToMCTruthIndex);
185 
186  // Check to see if Geant4 aborted during processing
187  g4status->at(0).SetAborted(fG4Alg->IsAborted());
188  if (g4status->at(0).IsAborted()) {
189  std::cout << "Geant4 aborted during processing. Flagged in G4Status data product." << std::endl;
190  }
191 
192  // Karl::Containment -- Let's look at the map which I have just made...
193  // --- Make an iterator to loop over fTrueDepMap
194  std::map< int, std::vector<float> >::iterator TrueMapIt;
195  // --- Iterate through my fTrueDepMap and create assns to the MCParticle list.
196  for (TrueMapIt = ParticleListAction::fTrueDepMap.begin(); TrueMapIt != ParticleListAction::fTrueDepMap.end(); ++TrueMapIt) {
197  // --- Loop through pcol until I find the right MCParticle.
198  for (unsigned int pp=0; pp<pcol->size(); ++pp) {
199  // --- Check if I have the correct MCParticle.
200  if ( (*pcol)[pp].TrackId() != TrueMapIt->first ) continue;
201  // --- If I'm here I should have the right particle so lets get it
202  sim::Particle &part = (*pcol)[ pp ];
203  // --- Check that I have done this correctly.
204  if (part.TrackId() != TrueMapIt->first) {
205  mf::LogVerbatim("G4Gen") << "Why doesn't TrueMapIt->first " << TrueMapIt->first << " equal part.TrackId() " << part.TrackId() << std::endl;
206  continue;
207  }
208  // Make a sim::TrueEnergy( TrackID, Entering Energy, Escaping Energy, Total Deposited Energy, Total Escaping energy )
209  sim::TrueEnergy ThisEn(TrueMapIt->first, TrueMapIt->second[0], TrueMapIt->second[1], TrueMapIt->second[2], TrueMapIt->second[3]);
210  (*trueens).push_back( ThisEn );
211  // And make the association!
212  util::CreateAssn( *this, evt, *treassn, *trueens, *pcol, pp, (trueens->size()-1) );
213  // --- Don't want to carry on looping through all of the particles!
214  break;
215  } // Loop through particles.
216  } // Iterator through my map.
217  // Karl::Containment -- Let's look at the map which I have just made...
218 
219  // make associations for the particles and MCTruth objects
220  int trackID = INT_MAX;
221  size_t mctidx = 0;
222 
223  for(size_t p = 0; p < pcol->size(); ++p){
224 
225  sim::Particle &part = (*pcol)[p];
226  trackID = part.TrackId();
227 
228  if( trackIDToMCTruthIndex.count(trackID) > 0){
229  mctidx = trackIDToMCTruthIndex.find(trackID)->second;
230  util::CreateAssn(*this, evt, *pcol, mctp[mctidx], *tpassn, p);
231  }
232  else
233  throw cet::exception("G4Gen") << "Cannot find MCTruth for Track Id: "
234  << trackID
235  << " to create association between Particle and MCTruth";
236 
237  }// end loop over handles
238 
239  // Put the data products into the event
240  evt.put(std::move(g4status));
241  evt.put(std::move(flshlcol));
242  evt.put(std::move(pcol));
243  evt.put(std::move(tpassn));
244 
245  evt.put(std::move(trueens));
246  evt.put(std::move(treassn));
247 
248  return;
249  }// end of produce
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
void RunGeant(std::vector< art::Handle< std::vector< simb::MCTruth > > > &mclists, std::vector< sim::FLSHitList > &flshitlist, std::vector< sim::Particle > &particlelist, std::vector< std::vector< std::pair< size_t, size_t > > > &pListLimits)
Definition: G4Alg.cxx:280
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
bool IsAborted()
Definition: G4Alg.cxx:375
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
static std::map< int, std::vector< float > > fTrueDepMap
int TrackId() const
Definition: MCParticle.h:209
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
TString part[npart]
Definition: Style.C:32
g4n::G4Alg * fG4Alg
G4Helper object.
Definition: G4Gen_module.cc:68
OStream cout
Definition: OStream.cxx:6
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
Int_t trackID
Definition: plot.C:84
std::string fGeneratorLabel
Definition: G4Gen_module.cc:66
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

g4n::G4Alg* g4n::G4Gen::fG4Alg
private

G4Helper object.

Definition at line 68 of file G4Gen_module.cc.

Referenced by beginRun(), produce(), and ~G4Gen().

fhicl::ParameterSet g4n::G4Gen::fG4AlgPSet
private

parameter set to configure the G4Alg object

Definition at line 69 of file G4Gen_module.cc.

Referenced by beginRun(), and G4Gen().

std::string g4n::G4Gen::fGeneratorLabel
private

Definition at line 66 of file G4Gen_module.cc.

Referenced by G4Gen(), and produce().

bool g4n::G4Gen::fPrintTables
private

Print the dE/dx tables and other info for debugging etc.?

Definition at line 72 of file G4Gen_module.cc.

Referenced by endJob(), and G4Gen().

TStopwatch g4n::G4Gen::fStopwatch
private

keep track of how long it takes to run the job

Definition at line 70 of file G4Gen_module.cc.

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


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