Skip to content
Snippets Groups Projects
Commit 5c7e4a88 authored by Denys Klekots's avatar Denys Klekots
Browse files

Added fullSimLight functionality for PrimaryGeneratorAction plugin

parent 01ea27d6
Branches
No related tags found
1 merge request!145User primary generator action adding plugin functionality
......@@ -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 {
//
......
......@@ -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:
......
......@@ -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;
}
}
}
}
}
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment