21 #include <TGeant3TGeo.h>
23 #include <TObjString.h>
27 #include <TVirtualMC.h>
44 if (!((strcmp(mcEngine,
"TGeant4") == 0) || (strcmp(mcEngine,
"TGeant3") == 0))) {
45 LOG(fatal) <<
"FairYamlVMCConfig::Setup() Engine \"" << mcEngine <<
"\" unknown!";
48 string yamlFileName = ObtainYamlFileName(mcEngine);
51 if (strcmp(mcEngine,
"TGeant4") == 0) {
53 }
else if (strcmp(mcEngine,
"TGeant3") == 0) {
65 LOG(info) <<
"FairYamlVMCConfig::SetupPostInit() OFF." <<
fPostInitName;
69 if (!((strcmp(mcEngine,
"TGeant4") == 0))) {
70 LOG(fatal) <<
"FairYamlVMCConfig::SetupPostInit() only valid for TGeant4.";
73 TString work = getenv(
"VMCWORKDIR");
74 TString work_config = work +
"/gconfig/";
75 work_config.ReplaceAll(
"//",
"/");
77 TString config_dir = getenv(
"CONFIG_DIR");
78 config_dir.ReplaceAll(
"//",
"/");
80 Bool_t AbsPath = kFALSE;
85 g4Macro =
"g4ConfigPostInit.C";
92 LOG(info) <<
"---------------User config is used: " << g4Macro.Data();
94 if (!AbsPath && TString(gSystem->FindFile(config_dir.Data(), g4Macro)) != TString(
"")) {
95 LOG(info) <<
"---User path for Configuration (" <<
fPostInitName <<
") is used: " << config_dir.Data();
96 ConfigMacro = g4Macro;
108 std::vector<std::string> g4commands =
fYamlConfigPostInit[
"Geant4_PostInit_Commands"].as<std::vector<std::string>>();
109 for (
const auto& value: g4commands ) {
110 LOG(info) <<
" execute command \"" << value <<
"\"";
111 TGeant4* geant4 =
dynamic_cast<TGeant4*
>(TVirtualMC::GetMC());
112 geant4->ProcessGeantCommand(value.data());
121 LOG(info) <<
"FairYamlVMCConfig::SetupGeant3() called";
124 TGeant3* geant3 =
nullptr;
125 if (strncmp(gModel->Data(),
"TGeo", 4) == 0) {
126 geant3 =
new TGeant3TGeo(
"C++ Interface to Geant3");
128 geant3 =
new TGeant3(
"C++ Interface to Geant3");
134 std::vector<int> intVect =
fYamlConfig[
"G3_SWIT"].as<std::vector<int>>();
135 if (intVect.size() != 2)
136 LOG(fatal) <<
"FairSetupGeant3: expecting 2 integers to setup G3_SWIT";
137 geant3->SetSWIT(intVect[0], intVect[1]);
140 std::vector<int> intVect =
fYamlConfig[
"G3_DEBU"].as<std::vector<int>>();
141 if (intVect.size() != 3)
142 LOG(fatal) <<
"FairSetupGeant3: expecting 3 integers to setup G3_DEBU";
143 geant3->SetDEBU(intVect[0], intVect[1], intVect[2]);
156 geant3->SetERAN(
fYamlConfig[
"G3_ERAN"].as<double>());
163 LOG(info) <<
"FairYamlVMCConfig::SetupGeant4() called";
166 LOG(fatal) <<
"User geometry not provided";
169 LOG(fatal) <<
"Physics list not provided";
172 LOG(fatal) <<
"Special processy not provided";
174 bool specialStacking =
false;
177 specialStacking =
fYamlConfig[
"Geant4_SpecialStacking"].as<
bool>();
182 mtMode =
fYamlConfig[
"Geant4_Multithreaded"].as<
bool>();
188 fYamlConfig[
"Geant4_PhysicsList"].as<std::string>(),
189 fYamlConfig[
"Geant4_SpecialProcess"].as<std::string>(),
193 TGeant4* geant4 =
new TGeant4(
"TGeant4",
"The Geant4 Monte Carlo", runConfiguration);
196 LOG(info) <<
" execute SetMaxNStep (" <<
fYamlConfig[
"Geant4_MaxNStep"].as<
int>() <<
")";
197 geant4->SetMaxNStep(
fYamlConfig[
"Geant4_MaxNStep"].as<int>());
200 std::vector<std::string> g4commands =
fYamlConfig[
"Geant4_Commands"].as<std::vector<std::string>>();
201 for (
const auto& value: g4commands ) {
202 LOG(info) <<
" execute command \"" << value <<
"\"";
203 geant4->ProcessGeantCommand(value.data());
207 LOG(info) << geant4->GetName() <<
" MonteCarlo engine created!.";
212 LOG(info) <<
"FairYamlVMCConfig::SetCuts() called";
214 YAML::Node mcProcess =
fYamlConfig[
"MonteCarlo_Process"];
215 TVirtualMC* MC = TVirtualMC::GetMC();
216 for (
auto it = mcProcess.begin(); it != mcProcess.end(); ++it) {
218 MC->SetProcess(it->first.as<std::string>().c_str(), it->second.as<
int>());
223 YAML::Node mcProcess =
fYamlConfig[
"MonteCarlo_Cut"];
224 TVirtualMC* MC = TVirtualMC::GetMC();
225 for (
auto it = mcProcess.begin(); it != mcProcess.end(); ++it) {
227 MC->SetCut(it->first.as<std::string>().c_str(), it->second.as<
double>());
232 string FairYamlVMCConfig::ObtainYamlFileName(
const char* mcEngine)
236 TString work = getenv(
"VMCWORKDIR");
237 TString work_config = work +
"/gconfig/";
238 work_config.ReplaceAll(
"//",
"/");
240 TString config_dir = getenv(
"CONFIG_DIR");
241 config_dir.ReplaceAll(
"//",
"/");
243 Bool_t AbsPath = kFALSE;
245 TString configFileWithPath;
248 if (lUserConfig.IsNull()) {
249 if (strcmp(mcEngine,
"TGeant4") == 0) {
250 configFile =
"g4Config.yaml";
252 if (strcmp(mcEngine,
"TGeant3") == 0) {
253 configFile =
"g3Config.yaml";
255 lUserConfig = configFile;
257 if (lUserConfig.Contains(
"/")) {
260 configFile = lUserConfig;
261 LOG(info) <<
"---------------User config is used: " << configFile.Data();
263 if (!AbsPath && TString(gSystem->FindFile(config_dir.Data(), configFile)) != TString(
"")) {
264 LOG(info) <<
"---------------CONFIG_DIR is used: " << config_dir.Data() <<
" to get \"" << configFile.Data()
266 configFileWithPath = configFile;
269 configFileWithPath = lUserConfig;
271 configFileWithPath = work_config + lUserConfig;
274 return configFileWithPath.Data();
277 void FairYamlVMCConfig::StoreYamlInfo()
279 std::ostringstream nodestring;
280 nodestring << fMCEngine <<
"\n";
283 TObjString* configObject =
new TObjString(nodestring.str().c_str());
286 LOG(info) <<
"FairYamlVMCConfig::StoreYamlInfo() done.";
YAML::Node fYamlConfigPostInit
virtual void SetupStack()=0
virtual void Setup(const char *mcEngine)
static FairRunSim * Instance()
ClassImp(FairEventBuilder)
std::string fPostInitName
virtual void UsePostInitConfig(bool useC=true, const char *stringC="g4ConfigPostInit.yaml")
virtual void WriteObject(TObject *f, const char *, Int_t option=0)=0
virtual void SetupPostInit(const char *mcEngine)