diff --git a/FullSimLight/include/FSLConfigurator.hh b/FullSimLight/include/FSLConfigurator.hh index bc678af605db6c47fcfae46360a3c41da9fa9ce9..4e8d133af9479a112aede80202883498091aabac 100644 --- a/FullSimLight/include/FSLConfigurator.hh +++ b/FullSimLight/include/FSLConfigurator.hh @@ -67,60 +67,24 @@ struct fslConfig{ std::vector<std::string> g4UiCommands; }; -fslConfig fsl; -regionConfig rc; -json jf; +extern fslConfig fsl; +extern regionConfig rc; +extern json jf; -inline void to_json(json& j, const fslConfig& p) { - j = json{{"Geometry", p.geometry},{"Physics list name", p.physicsList},{"Number of events", p.nEvents},{"Magnetic Field Intensity", p.magFieldIntensity},{"Generator", p.eventGeneratorName},{"Event input file", p.eventInputFile},{"Type of event", p.typeOfEvent},{"Sensitive Detector Extensions", p.sensitiveDetectors},{"Output Hits file", p.outputHitsFile},{"Output Histo file", p.outputHistoFile},{"Magnetic Field Type", p.magFieldType},{"Magnetic Field Map", p.magFieldMap},{"Magnetic Field Plugin", p.magFieldPlugin},{"User Action Extensions", p.userActions},{"g4ui_commands", p.g4UiCommands}}; - -} -inline void to_json(json& j, const regionConfig& r) { - j = json{{"RegionName", r.regionName},{"RootLVNames", r.rootLVNames},{"GammaCut", r.gammaCut},{"ElectronCut", r.electronCut},{"PositronCut", r.positronCut},{"ProtonCut", r.protonCut}}; -} -inline void from_json(const json& j, fslConfig& p) { - p.geometry=j.at("Geometry").get<std::string>(); - p.physicsList=j.at("Physics list name").get<std::string>(); - p.nEvents=j.at("Number of events").get<int>(); - p.magFieldType=j.at("Magnetic Field Type").get<std::string>(); - p.magFieldIntensity=j.at("Magnetic Field Intensity").get<std::string>(); - p.eventGeneratorName=j.at("Generator").get<std::string>(); - p.eventInputFile=j.at("Event input file").get<std::string>(); - p.typeOfEvent=j.at("Type of event").get<std::string>(); - p.sensitiveDetectors=j.at("Sensitive Detector Extensions").get<std::vector<std::string>>(); - p.outputHitsFile=j.at("Output Hits file").get<std::string>(); - p.outputHistoFile=j.at("Output Histo file").get<std::string>(); - p.magFieldMap=j.at("Magnetic Field Map").get<std::string>(); - p.magFieldPlugin=j.at("Magnetic Field Plugin").get<std::string>(); - p.userActions=j.at("User Action Extensions").get<std::vector<std::string>>(); - - p.g4UiCommands=j.at("g4ui_commands").get<std::vector<std::string>>(); - -} - -inline void from_json(const json& j, regionConfig& r) { - r.regionName=j.at("RegionName").get<std::string>(); - r.rootLVNames=j.at("RootLVNames").get<std::vector<G4String>>(); - r.gammaCut=j.at("GammaCut").get<double>(); - r.electronCut=j.at("ElectronCut").get<double>(); - r.positronCut=j.at("PositronCut").get<double>(); - r.protonCut=j.at("ProtonCut").get<double>(); - -} - -auto parse_json_file(std::string config_file_name) -{ - std::ifstream ifs(config_file_name); - jf=json::parse(ifs); - - //read and store the configuration into the fslConfig struct - simConfig::from_json(jf, fsl); +void to_json(json& j, const fslConfig& p); + +void to_json(json& j, const regionConfig& r); + +void from_json(const json& j, fslConfig& p); + +void from_json(const json& j, regionConfig& r); + +void parse_json_file(std::string config_file_name); -} +} // namespace simConfig -} // namespace fslconf //class FSLConfigurator { // diff --git a/FullSimLight/include/FSLUserActionPlugin.h b/FullSimLight/include/FSLUserActionPlugin.h index 729c260e5acc3d98af8bf29b3cab2abcc6cbf3a2..11e5f5aac055b7b760f485a0c7df186d1c7016f7 100644 --- a/FullSimLight/include/FSLUserActionPlugin.h +++ b/FullSimLight/include/FSLUserActionPlugin.h @@ -6,6 +6,9 @@ class G4UserSteppingAction; class G4UserTrackingAction; class G4UserStackingAction; +class G4VUserPrimaryGeneratorAction; + + class FSLUserActionPlugin { public: @@ -24,6 +27,8 @@ class FSLUserActionPlugin { virtual G4UserTrackingAction *getTrackingAction() const { return nullptr;} virtual G4UserStackingAction *getStackingAction() const { return nullptr;} + virtual G4VUserPrimaryGeneratorAction *getPrimaryGeneratorAction() const {return nullptr;} + private: diff --git a/FullSimLight/src/FSLActionInitialization.cc b/FullSimLight/src/FSLActionInitialization.cc index a7a8c9943af116e9dd3971325b54bbb7f4e587a7..e4d48eed8af79b1f513eb2e630d0ed8042c2d1fb 100644 --- a/FullSimLight/src/FSLActionInitialization.cc +++ b/FullSimLight/src/FSLActionInitialization.cc @@ -7,6 +7,7 @@ #include "FSLSteppingAction.hh" #include "FSLTrackingAction.hh" #include "PythiaPrimaryGeneratorAction.hh" +#include "FSLConfigurator.hh" #include "FSLUserActionPlugin.h" #include "FSLUserRunActionPlugin.h" #include "FSLUserEventActionPlugin.h" @@ -25,7 +26,7 @@ #include "FSLLengthIntegratorSteppingAction.hh" #endif - +#include <iostream> //const G4AnalysisManager* FSLActionInitialization::fMasterAnalysisManager = nullptr; @@ -71,14 +72,18 @@ void FSLActionInitialization::BuildForMaster() const { void FSLActionInitialization::Build() const { #if !USE_PYTHIA - SetUserAction(new FSLPrimaryGeneratorAction()); + if(simConfig::fsl.eventGeneratorName == "Particle Gun") + { + SetUserAction(new FSLPrimaryGeneratorAction()); + } #else if (use_pythia()) { // seed each generator/thread by 1234 if perfomance mode run and use the event // ID+1 as seed otherwise (guaranted reproducibility while having different events) G4int pythiaSeed = fIsPerformance ? -1 : 0; SetUserAction(new PythiaPrimaryGeneratorAction(pythiaSeed)); - } else { + + } else if (simConfig::fsl.eventGeneratorName == "Particle Gun"){ SetUserAction(new FSLPrimaryGeneratorAction()); } #endif @@ -145,6 +150,20 @@ void FSLActionInitialization::Build() const { if (plugin->getStackingAction()) SetUserAction(plugin->getStackingAction()); if (plugin->getSteppingAction()) SetUserAction(plugin->getSteppingAction()); + if (plugin->getPrimaryGeneratorAction()) + { + if(simConfig::fsl.eventGeneratorName == "User Primary Generator") + { + SetUserAction(plugin->getPrimaryGeneratorAction()); + std::cout << "Ussing user primary generation acction" << std::endl; + } + else + { + std::cout << "### WARNING: The plugin " << element << " contains the user primary generation action " + << "but the generator name in the FSL configuration file is different from \"User Primary Generator\". " + << "Ignoring the plugin's primary generator" << std::endl; + } + } } } } diff --git a/FullSimLight/src/FSLConfigurator.cc b/FullSimLight/src/FSLConfigurator.cc new file mode 100644 index 0000000000000000000000000000000000000000..95371f9e38032a76bc025964e061c1acf139631e --- /dev/null +++ b/FullSimLight/src/FSLConfigurator.cc @@ -0,0 +1,56 @@ +#include "FSLConfigurator.hh" + +simConfig::fslConfig simConfig::fsl; +simConfig::regionConfig simConfig::rc; +json simConfig::jf; + +void simConfig::to_json(json& j, const fslConfig& p) { + j = json{{"Geometry", p.geometry},{"Physics list name", p.physicsList},{"Number of events", p.nEvents},{"Magnetic Field Intensity", p.magFieldIntensity},{"Generator", p.eventGeneratorName},{"Event input file", p.eventInputFile},{"Type of event", p.typeOfEvent},{"Sensitive Detector Extensions", p.sensitiveDetectors},{"Output Hits file", p.outputHitsFile},{"Output Histo file", p.outputHistoFile},{"Magnetic Field Type", p.magFieldType},{"Magnetic Field Map", p.magFieldMap},{"Magnetic Field Plugin", p.magFieldPlugin},{"User Action Extensions", p.userActions},{"g4ui_commands", p.g4UiCommands}}; +} + +void simConfig::to_json(json& j, const regionConfig& r) { + j = json{{"RegionName", r.regionName},{"RootLVNames", r.rootLVNames},{"GammaCut", r.gammaCut},{"ElectronCut", r.electronCut},{"PositronCut", r.positronCut},{"ProtonCut", r.protonCut}}; +} + +void simConfig::from_json(const json& j, fslConfig& p) { + p.geometry=j.at("Geometry").get<std::string>(); + p.physicsList=j.at("Physics list name").get<std::string>(); + p.nEvents=j.at("Number of events").get<int>(); + p.magFieldType=j.at("Magnetic Field Type").get<std::string>(); + p.magFieldIntensity=j.at("Magnetic Field Intensity").get<std::string>(); + p.eventGeneratorName=j.at("Generator").get<std::string>(); + p.eventInputFile=j.at("Event input file").get<std::string>(); + p.typeOfEvent=j.at("Type of event").get<std::string>(); + p.sensitiveDetectors=j.at("Sensitive Detector Extensions").get<std::vector<std::string>>(); + p.outputHitsFile=j.at("Output Hits file").get<std::string>(); + p.outputHistoFile=j.at("Output Histo file").get<std::string>(); + p.magFieldMap=j.at("Magnetic Field Map").get<std::string>(); + p.magFieldPlugin=j.at("Magnetic Field Plugin").get<std::string>(); + p.userActions=j.at("User Action Extensions").get<std::vector<std::string>>(); + + p.g4UiCommands=j.at("g4ui_commands").get<std::vector<std::string>>(); + +} + +void simConfig::from_json(const json& j, regionConfig& r) { + r.regionName=j.at("RegionName").get<std::string>(); + r.rootLVNames=j.at("RootLVNames").get<std::vector<G4String>>(); + r.gammaCut=j.at("GammaCut").get<double>(); + r.electronCut=j.at("ElectronCut").get<double>(); + r.positronCut=j.at("PositronCut").get<double>(); + r.protonCut=j.at("ProtonCut").get<double>(); + +} + +void simConfig::parse_json_file(std::string config_file_name) +{ + using simConfig::fsl; + using simConfig::jf; + + std::ifstream ifs(config_file_name); + jf=json::parse(ifs); + + //read and store the configuration into the fslConfig struct + simConfig::from_json(jf, fsl); + +} \ No newline at end of file