All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
larg4::larg4Main Class Reference
Inheritance diagram for larg4::larg4Main:

Public Member Functions

 larg4Main (fhicl::ParameterSet const &p)
 
 ~larg4Main ()
 

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::InputTag > inputCollectionTags_
 
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}
 

Detailed Description

Definition at line 56 of file larg4Main_module.cc.

Constructor & Destructor Documentation

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

Definition at line 128 of file larg4Main_module.cc.

129  : EDProducer{p}
130  , seed_(p.get<long>("seed", -1))
131  , macroPath_(p.get<std::string>("macroPath", "FW_SEARCH_PATH"))
133  , g4MacroFile_(p.get<std::string>("visMacro", "larg4.mac"))
134  , inputCollectionTags_{p.get<std::vector<art::InputTag>>("inputCollections", {})}
pdgs p
Definition: selectors.fcl:22
cet::search_path pathFinder_
std::string g4MacroFile_
std::vector< art::InputTag > inputCollectionTags_
std::string macroPath_
larg4::larg4Main::~larg4Main ( )

Definition at line 175 of file larg4Main_module.cc.

176 {
177  if (runManager_) {
178  runManager_.reset();
179  }
180 }
static std::unique_ptr< artg4tk::ArtG4RunManager > runManager_

Member Function Documentation

void larg4::larg4Main::beginJob ( )
overrideprivate

Definition at line 183 of file larg4Main_module.cc.

184 {
185  mf::LogDebug("Main_Run_Manager") << "In begin job";
186  if (runManager_) {
187  return;
188  }
189  runManager_.reset(new artg4tk::ArtG4RunManager);
190 }
static std::unique_ptr< artg4tk::ArtG4RunManager > runManager_
void larg4::larg4Main::beginRun ( art::Run &  r)
overrideprivate

Definition at line 193 of file larg4Main_module.cc.

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

Definition at line 291 of file larg4Main_module.cc.

292 {
293  if (--processingRun_ != 0) {
294  return;
295  }
296 
297  runManager_->BeamOnEndRun();
298 }
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 301 of file larg4Main_module.cc.

302 {
304  return e.getMany<std::vector<simb::MCTruth>>();
305  }
306 
307  std::vector<art::Handle<MCTruthCollection>> result;
308  for (auto const& tag : inputCollectionTags_) {
309  result.push_back(e.getHandle<MCTruthCollection>(tag));
310  }
311  return result;
312 }
std::vector< simb::MCTruth > MCTruthCollection
std::vector< art::InputTag > inputCollectionTags_
do i e
bool empty(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:555
void larg4::larg4Main::produce ( art::Event &  e)
overrideprivate

Definition at line 268 of file larg4Main_module.cc.

269 {
270  // The holder services need the event
271  art::ServiceHandle<artg4tk::ActionHolderService>()->setCurrArtEvent(e);
272  art::ServiceHandle<artg4tk::DetectorHolderService>()->setCurrArtEvent(e);
273 
274  auto const mclists = inputCollections(e);
275  art::ServiceHandle<larg4::MCTruthEventActionService>()->setInputCollections(mclists);
276 
277  art::ServiceHandle<larg4::ParticleListActionService> pla;
278  pla->setInputCollections(mclists);
279  auto const pid = e.getProductID<std::vector<simb::MCParticle>>();
280  pla->setPtrInfo(pid, e.productGetter(pid));
281 
282  runManager_->BeamOnDoOneEvent(e.id().event());
283  runManager_->BeamOnEndEvent();
284 
285  e.put(pla->ParticleCollection());
286  e.put(pla->AssnsMCTruthToMCParticle());
287  e.put(pla->DroppedTracksCollection());
288 }
static std::unique_ptr< artg4tk::ArtG4RunManager > runManager_
std::vector< art::Handle< MCTruthCollection > > inputCollections(art::Event const &e) const
do i e

Member Data Documentation

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

Definition at line 116 of file larg4Main_module.cc.

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

Definition at line 93 of file larg4Main_module.cc.

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

Definition at line 118 of file larg4Main_module.cc.

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

Definition at line 96 of file larg4Main_module.cc.

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

Definition at line 86 of file larg4Main_module.cc.

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

Definition at line 90 of file larg4Main_module.cc.

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

Definition at line 102 of file larg4Main_module.cc.

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

Definition at line 119 of file larg4Main_module.cc.

int larg4::larg4Main::rmvlevel_
private

Definition at line 105 of file larg4Main_module.cc.

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

Definition at line 70 of file larg4Main_module.cc.

long larg4::larg4Main::seed_
private

Definition at line 80 of file larg4Main_module.cc.

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

Definition at line 73 of file larg4Main_module.cc.

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

Definition at line 74 of file larg4Main_module.cc.

bool larg4::larg4Main::uiAtBeginRun_
private

Definition at line 108 of file larg4Main_module.cc.

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

Definition at line 109 of file larg4Main_module.cc.


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