69 lines
1.9 KiB
C++
69 lines
1.9 KiB
C++
|
|
#include "SystemBuilder.hh"
|
|
|
|
void SystemBuilder::init(ConstructionWrapper &CW, bool gui){
|
|
|
|
char* argv[]={(char*)"dummy"};
|
|
|
|
// Construct the default run manager
|
|
//
|
|
runManager =
|
|
G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
|
|
runManager->SetNumberOfThreads(1);
|
|
|
|
G4String session;
|
|
ui = nullptr;
|
|
if ( gui ) {
|
|
ui = new G4UIExecutive((int)1, argv, session);
|
|
}
|
|
|
|
// Set mandatory initialization classes
|
|
//
|
|
detConstruction = new B4::DetectorConstruction(&CW);
|
|
|
|
runManager->SetUserInitialization(detConstruction);
|
|
|
|
auto physicsList = new FTFP_BERT;
|
|
runManager->SetUserInitialization(physicsList);
|
|
|
|
actionInitialization = new B4a::ActionInitialization(detConstruction);
|
|
runManager->SetUserInitialization(actionInitialization);
|
|
|
|
//actionInitialization->setGeneratorProperties(100, 10000, "e-");
|
|
|
|
// Initialize visualization
|
|
//
|
|
visManager = new G4VisExecutive;
|
|
// G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
|
|
// G4VisManager* visManager = new G4VisExecutive("Quiet");
|
|
visManager->Initialize();
|
|
|
|
// Get the pointer to the User Interface manager
|
|
UImanager = G4UImanager::GetUIpointer();
|
|
|
|
// Process macro or start UI session
|
|
//
|
|
}
|
|
|
|
void SystemBuilder::run_gui(){
|
|
if(ui == nullptr){
|
|
throw std::runtime_error("GUI not initialized");
|
|
}
|
|
if ( true ) {
|
|
// interactive mode : define UI session
|
|
UImanager->ApplyCommand("/control/execute init_vis.mac");
|
|
if (ui->IsGUI()) {
|
|
UImanager->ApplyCommand("/control/execute gui.mac");
|
|
}
|
|
ui->SessionStart();
|
|
}
|
|
}
|
|
|
|
void SystemBuilder::run_batch(int nEvents,const std::string& partSpecies, double minEnergy, double maxEnergy){
|
|
G4String partSpec = partSpecies;
|
|
G4cout << "running with particle species " << partSpec << G4endl;
|
|
UImanager->ApplyCommand("/run/initialize");
|
|
actionInitialization->setGeneratorProperties(minEnergy, maxEnergy, partSpec);
|
|
runManager->BeamOn(nEvents);
|
|
}
|