153 lines
3.8 KiB
C++
153 lines
3.8 KiB
C++
|
|
#ifndef G4SYSTEM_HH
|
|
#define G4SYSTEM_HH
|
|
|
|
#include "GeometryDescriptor.hh"
|
|
#include <stdexcept>
|
|
#include "G4RunManagerFactory.hh"
|
|
#include "DetectorConstruction.hh"
|
|
#include "ActionInitialization.hh"
|
|
|
|
#include "G4RunManagerFactory.hh"
|
|
#include "G4SteppingVerbose.hh"
|
|
#include "G4UIcommand.hh"
|
|
#include "G4UImanager.hh"
|
|
#include "G4UIExecutive.hh"
|
|
#include "G4VisExecutive.hh"
|
|
|
|
#include "FTFP_BERT.hh"
|
|
#include "Randomize.hh"
|
|
#include <vector>
|
|
|
|
class G4System{
|
|
friend class GeometryDescriptor;
|
|
public:
|
|
|
|
G4System():gui(false){};
|
|
G4System(bool Gui):gui(Gui){};
|
|
~G4System(){
|
|
if(visManager != nullptr){
|
|
delete visManager;
|
|
delete runManager;
|
|
delete ui;
|
|
}
|
|
|
|
};
|
|
|
|
|
|
void init(GeometryDescriptor &cw, int seed=0);
|
|
//will use dawn for visualization, also wrap more in python
|
|
void run_visualize(const std::string& partSpecies, double minEnergy_GeV, double maxEnergy_GeV);
|
|
//runs the whole gui if available
|
|
void run_gui();
|
|
void run_batch(int nEvents, const std::vector<std::string>& partSpecies, double minEnergy_GeV,
|
|
double maxEnergy_GeV, std::string filename="_1234567890_Hits.root");
|
|
|
|
void applyUICommand(const std::string& command){
|
|
check();
|
|
UImanager->ApplyCommand(command);
|
|
}
|
|
|
|
void displayEvent()const{}; //just a placeholder, this will be implemented in python
|
|
|
|
void printMaterial(const std::string& name)const;
|
|
|
|
GeometryDescriptor& getGeometryDescriptor(){
|
|
check();
|
|
if ( assigned_cw == nullptr ){
|
|
throw std::runtime_error("GeometryDescriptor not assigned");
|
|
}
|
|
return *assigned_cw;
|
|
}
|
|
|
|
private:
|
|
|
|
void check()const;
|
|
GeometryDescriptor * assigned_cw=nullptr;
|
|
|
|
bool gui;
|
|
|
|
G4RunManager * runManager=nullptr;
|
|
B4::DetectorConstruction * detConstruction=nullptr;
|
|
B4a::ActionInitialization * actionInitialization=nullptr;
|
|
G4VisExecutive * visManager=nullptr;
|
|
G4UImanager * UImanager=nullptr;
|
|
G4UIExecutive * ui=nullptr;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
|
|
void run(GeometryDescriptor CW, int nEvents, std::string partSpecies, double minEnergy, double maxEnergy, bool gui=false){
|
|
|
|
char* argv[]={(char*)"dummy"};
|
|
|
|
// Construct the default run manager
|
|
//
|
|
auto* runManager =
|
|
G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
|
|
runManager->SetNumberOfThreads(1);
|
|
|
|
GeometryDescriptor * cw = &CW;
|
|
G4String session;
|
|
G4UIExecutive* ui = nullptr;
|
|
if ( gui ) {
|
|
ui = new G4UIExecutive((int)1, argv, session);
|
|
}
|
|
|
|
// Set mandatory initialization classes
|
|
//
|
|
auto detConstruction = new B4::DetectorConstruction(cw);
|
|
|
|
runManager->SetUserInitialization(detConstruction);
|
|
|
|
auto physicsList = new FTFP_BERT;
|
|
runManager->SetUserInitialization(physicsList);
|
|
|
|
auto actionInitialization = new B4a::ActionInitialization(detConstruction);
|
|
runManager->SetUserInitialization(actionInitialization);
|
|
|
|
actionInitialization->setGeneratorProperties(minEnergy, maxEnergy, partSpecies);
|
|
|
|
// Initialize visualization
|
|
//
|
|
auto 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
|
|
auto UImanager = G4UImanager::GetUIpointer();
|
|
|
|
// Process macro or start UI session
|
|
//
|
|
|
|
|
|
if ( gui ) {
|
|
// interactive mode : define UI session
|
|
UImanager->ApplyCommand("/control/execute init_vis.mac");
|
|
if (ui->IsGUI()) {
|
|
UImanager->ApplyCommand("/control/execute gui.mac");
|
|
}
|
|
ui->SessionStart();
|
|
delete ui;
|
|
}
|
|
else {
|
|
G4String command = "/control/execute run1.mac";
|
|
UImanager->ApplyCommand("/run/initialize");
|
|
UImanager->ApplyCommand("/run/beamOn "+ std::to_string(nEvents));
|
|
}
|
|
|
|
|
|
// Job termination
|
|
// Free the store: user actions, physics_list and detector_description are
|
|
// owned and deleted by the run manager, so they should not be deleted
|
|
// in the main() program !
|
|
delete visManager;
|
|
delete runManager;
|
|
|
|
}
|
|
*/ |