Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
larg4::larg4Main Class Reference
Inheritance diagram for larg4::larg4Main:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 larg4Main (fhicl::ParameterSet const &p)
 
 ~larg4Main ()
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
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::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- 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)
 

Private Member Functions

void produce (art::Event &e) override
 
void beginJob () override
 
void beginRun (art::Run &r) override
 
void endRun (art::Run &) override
 
std::vector< art::Handle< MCTruthCollection > > inputCollections (art::Event const &e) const
 

Private Attributes

G4UIsession * session_ {nullptr}
 
G4UImanager * UI_ {nullptr}
 
long seed_
 
std::string macroPath_
 
cet::search_path pathFinder_
 
std::string g4MacroFile_
 
std::vector< art::InputTaginputCollectionTags_
 
bool pauseAfterEvent_ {false}
 
int rmvlevel_
 
bool uiAtBeginRun_
 
bool uiAtEndEvent_ {false}
 
std::string afterEvent_
 

Static Private Attributes

static std::unique_ptr< artg4tk::ArtG4RunManager > runManager_ {nullptr}
 
static bool initializeDetectors_ {true}
 
static std::atomic< int > processingRun_ {0}
 

Additional Inherited Members

- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- 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 52 of file larg4Main_module.cc.

Constructor & Destructor Documentation

larg4::larg4Main::larg4Main ( fhicl::ParameterSet const &  p)
explicit

Definition at line 124 of file larg4Main_module.cc.

125  : EDProducer{p}
126  , seed_(p.get<long>("seed", -1))
127  , macroPath_(p.get<std::string>("macroPath", "FW_SEARCH_PATH"))
129  , g4MacroFile_(p.get<std::string>("visMacro", "larg4.mac"))
130  , inputCollectionTags_{p.get<std::vector<art::InputTag>>("inputCollections", {})}
131  , rmvlevel_(p.get<int>("rmvlevel", 0))
132  , uiAtBeginRun_(p.get<bool>("uiAtBeginRun", false))
133  , afterEvent_(p.get<std::string>("afterEvent", "pass"))
134 {
135  produces<std::vector<simb::MCParticle>>();
136  produces<art::Assns<simb::MCTruth, simb::MCParticle, sim::GeneratedParticleInfo>>();
137 
138  // We need all of the services to run @produces@ on the data they will store. We do this
139  // by retrieving the holder services.
142 
143  if (initializeDetectors_) {
144  detectorHolder->initialize();
145  // Build the detectors' logical volumes
146  detectorHolder->constructAllLVs();
147  initializeDetectors_ = false;
148  }
149 
150  // And running @callArtProduces@ on each
151  actionHolder->callArtProduces(producesCollector());
152  detectorHolder->callArtProduces(producesCollector());
153 
154  // -- Check for invalid seed value
155  if (seed_ > 900000000) {
156  throw cet::exception("largeant:BadSeedValue")
157  << "The provided largeant seed value: " << seed_ << " is invalid! Maximum seed value is 9E8.";
158  }
159  // Set up the random number engine.
160  // -- D.R.: Use the NuRandomService engine for additional control over the seed generation policy
161  (void)art::ServiceHandle<rndm::NuRandomService>()->createEngine(*this, "G4Engine", p, "seed");
162 
163  // Handle the afterEvent setting
164  if (afterEvent_ == "ui") { uiAtEndEvent_ = true; }
165  else if (afterEvent_ == "pause") {
166  pauseAfterEvent_ = true;
167  }
168 }
static bool initializeDetectors_
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
cet::search_path pathFinder_
std::string afterEvent_
p
Definition: test.py:223
std::string g4MacroFile_
std::vector< art::InputTag > inputCollectionTags_
ProducesCollector & producesCollector() noexcept
std::string macroPath_
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
larg4::larg4Main::~larg4Main ( )

Definition at line 170 of file larg4Main_module.cc.

171 {
172  if (runManager_) {
173  runManager_.reset();
174  }
175 }
static std::unique_ptr< artg4tk::ArtG4RunManager > runManager_

Member Function Documentation

void larg4::larg4Main::beginJob ( )
overrideprivatevirtual

Reimplemented from art::EDProducer.

Definition at line 178 of file larg4Main_module.cc.

179 {
180  mf::LogDebug("Main_Run_Manager") << "In begin job";
181  if (runManager_) {
182  return;
183  }
184  runManager_.reset(new artg4tk::ArtG4RunManager);
185 }
static std::unique_ptr< artg4tk::ArtG4RunManager > runManager_
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
void larg4::larg4Main::beginRun ( art::Run r)
overrideprivatevirtual

Reimplemented from art::EDProducer.

Definition at line 188 of file larg4Main_module.cc.

189 {
190  if (processingRun_++ != 0) {
191  return;
192  }
193 
194  // Get the physics list and pass it to Geant and initialize the list if necessary
196  runManager_->SetUserInitialization(physicsListHolder->makePhysicsList());
197 
198  // Get all of the detectors and initialize them
199  // Declare the detector construction to Geant
200  auto detectorHolder = art::ServiceHandle<artg4tk::DetectorHolderService>().get();
201  runManager_->SetUserInitialization(
202  new artg4tk::ArtG4DetectorConstruction{detectorHolder->worldPhysicalVolume()});
203 
204  // Get all of the actions and initialize them
205  auto actionHolder = art::ServiceHandle<artg4tk::ActionHolderService>().get();
206  actionHolder->initialize();
207 
208  // Store the run in the action holder
209  actionHolder->setCurrArtRun(r);
210 
211  // Declare the primary generator action to Geant
212  runManager_->SetUserAction(new artg4tk::ArtG4PrimaryGeneratorAction{actionHolder});
213 
214  // Note that these actions (and ArtG4PrimaryGeneratorAction above) are all
215  // generic actions that really don't do much on their own. Rather, to
216  // use the power of actions, one must create action objects (derived from
217  // @ActionBase@) and register them with the Art @ActionHolder@ service.
218  // See @ActionBase@ and/or @ActionHolderService@ for more information.
219  runManager_->SetUserAction(new artg4tk::ArtG4SteppingAction{actionHolder});
220  runManager_->SetUserAction(new artg4tk::ArtG4StackingAction{actionHolder});
221  runManager_->SetUserAction(new artg4tk::ArtG4EventAction{actionHolder, detectorHolder});
222  runManager_->SetUserAction(new artg4tk::ArtG4TrackingAction{actionHolder});
223 
224  runManager_->Initialize();
225  physicsListHolder->initializePhysicsList();
226 
227  //get the pointer to the User Interface manager
228  UI_ = G4UImanager::GetUIpointer();
229 
230  // Find the macro (or try to) along the directory path.
231  std::string macroLocation = "";
232  bool macroWasFound = pathFinder_.find_file(g4MacroFile_, macroLocation);
233  mf::LogInfo("larg4Main") << "Finding path for " << g4MacroFile_ << "...\nSearch "
234  << (macroWasFound ? "successful " : "unsuccessful ") << "and path is: \n"
235  << macroLocation;
236 
237  // Execute the macro if we were able to find it
238  if (macroWasFound) {
239  // Create the string containing the execution command
240  mf::LogInfo("larg4Main") << "Executing macro: " << g4MacroFile_;
241  std::string commandToExecute = "/control/execute ";
242  commandToExecute.append(macroLocation);
243  UI_->ApplyCommand(commandToExecute);
244  }
245  else {
246  mf::LogInfo("larg4Main") << "Unable to find " << g4MacroFile_ << " in the path(s) "
247  << macroPath_;
248  }
249 
250  // Open a UI if asked
251  if (uiAtBeginRun_) {
252  session_ = new G4UIterminal;
253  session_->SessionStart();
254  delete session_;
255  }
256 
257  // Start the Geant run!
258  runManager_->BeamOnBeginRun(r.id().run());
259 }
G4UImanager * UI_
static std::atomic< int > processingRun_
RunID id() const
Definition: Run.cc:17
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
static std::unique_ptr< artg4tk::ArtG4RunManager > runManager_
G4UIsession * session_
cet::search_path pathFinder_
RunNumber_t run() const
Definition: RunID.h:64
std::string g4MacroFile_
std::string find_file(std::string const &filename) const
Definition: search_path.cc:96
std::string macroPath_
void larg4::larg4Main::endRun ( art::Run r)
overrideprivatevirtual

Reimplemented from art::EDProducer.

Definition at line 285 of file larg4Main_module.cc.

286 {
287  if (--processingRun_ != 0) {
288  return;
289  }
290 
291  runManager_->BeamOnEndRun();
292 }
static std::atomic< int > processingRun_
static std::unique_ptr< artg4tk::ArtG4RunManager > runManager_
std::vector< art::Handle< MCTruthCollection > > larg4::larg4Main::inputCollections ( art::Event const &  e) const
private

Definition at line 295 of file larg4Main_module.cc.

296 {
298  return e.getMany<std::vector<simb::MCTruth>>();
299  }
300 
301  std::vector<art::Handle<MCTruthCollection>> result;
302  for (auto const& tag : inputCollectionTags_) {
303  result.push_back(e.getHandle<MCTruthCollection>(tag));
304  }
305  return result;
306 }
static QCString result
const double e
std::vector< simb::MCTruth > MCTruthCollection
std::vector< art::InputTag > inputCollectionTags_
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:97
void larg4::larg4Main::produce ( art::Event e)
overrideprivatevirtual

Implements art::EDProducer.

Definition at line 263 of file larg4Main_module.cc.

264 {
265  // The holder services need the event
268 
269  auto const mclists = inputCollections(e);
270  art::ServiceHandle<larg4::MCTruthEventActionService>()->setInputCollections(mclists);
271 
273  pla->setInputCollections(mclists);
274  auto const pid = e.getProductID<std::vector<simb::MCParticle>>();
275  pla->setPtrInfo(pid, e.productGetter(pid));
276 
277  runManager_->BeamOnDoOneEvent(e.id().event());
278  runManager_->BeamOnEndEvent();
279 
280  e.put(pla->ParticleCollection());
281  e.put(pla->AssnsMCTruthToMCParticle());
282 }
ProductID getProductID(std::string const &instance_name="") const
Definition: DataViewImpl.h:338
static std::unique_ptr< artg4tk::ArtG4RunManager > runManager_
std::vector< art::Handle< MCTruthCollection > > inputCollections(art::Event const &e) const
std::unique_ptr< std::vector< simb::MCParticle > > ParticleCollection()
std::unique_ptr< art::Assns< simb::MCTruth, simb::MCParticle, sim::GeneratedParticleInfo > > AssnsMCTruthToMCParticle()
void setInputCollections(std::vector< art::Handle< std::vector< simb::MCTruth >>> const &mclists)
EDProductGetter const * productGetter(ProductID const pid) const
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
EventNumber_t event() const
Definition: EventID.h:116
void setPtrInfo(art::ProductID pid, art::EDProductGetter const *productGetter)
EventID id() const
Definition: Event.cc:34

Member Data Documentation

std::string larg4::larg4Main::afterEvent_
private

Definition at line 112 of file larg4Main_module.cc.

std::string larg4::larg4Main::g4MacroFile_
private

Definition at line 89 of file larg4Main_module.cc.

bool larg4::larg4Main::initializeDetectors_ {true}
staticprivate

Definition at line 114 of file larg4Main_module.cc.

std::vector<art::InputTag> larg4::larg4Main::inputCollectionTags_
private

Definition at line 92 of file larg4Main_module.cc.

std::string larg4::larg4Main::macroPath_
private

Definition at line 82 of file larg4Main_module.cc.

cet::search_path larg4::larg4Main::pathFinder_
private

Definition at line 86 of file larg4Main_module.cc.

bool larg4::larg4Main::pauseAfterEvent_ {false}
private

Definition at line 98 of file larg4Main_module.cc.

std::atomic< int > larg4::larg4Main::processingRun_ {0}
staticprivate

Definition at line 115 of file larg4Main_module.cc.

int larg4::larg4Main::rmvlevel_
private

Definition at line 101 of file larg4Main_module.cc.

std::unique_ptr< artg4tk::ArtG4RunManager > larg4::larg4Main::runManager_ {nullptr}
staticprivate

Definition at line 66 of file larg4Main_module.cc.

long larg4::larg4Main::seed_
private

Definition at line 76 of file larg4Main_module.cc.

G4UIsession* larg4::larg4Main::session_ {nullptr}
private

Definition at line 69 of file larg4Main_module.cc.

G4UImanager* larg4::larg4Main::UI_ {nullptr}
private

Definition at line 70 of file larg4Main_module.cc.

bool larg4::larg4Main::uiAtBeginRun_
private

Definition at line 104 of file larg4Main_module.cc.

bool larg4::larg4Main::uiAtEndEvent_ {false}
private

Definition at line 105 of file larg4Main_module.cc.


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