11/* *******************************************************************************
2- * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
2+ * Copyright (C) 2014-2025 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
33 * *
44 * This software is distributed under the terms of the *
55 * GNU Lesser General Public Licence (LGPL) version 3, *
1111// -------------------------------------------------------------------------
1212#include " FairYamlVMCConfig.h"
1313
14- #include " FairFastSimRunConfiguration.h"
1514#include " FairLogger.h"
1615#include " FairRunSim.h"
1716#include " FairSink.h" // for FairSink
1817
1918#include < Rtypes.h>
20- #include < TGeant3.h>
21- #include < TGeant3TGeo.h>
22- #include < TGeant4.h>
2319#include < TObjString.h> // for TObjString
2420#include < TObject.h> // for TObject, TObject::kSingleKey
2521#include < TString.h>
3228#include < string> // for string, basic_string, cha...
3329#include < vector> // for vector
3430
31+ #ifdef FAIRROOT_HAS_FASTSIM
32+ #include " FairFastSimRunConfiguration.h"
33+ #endif
34+ #ifdef FAIRROOT_HAS_GEANT3
35+ #include < TGeant3.h>
36+ #include < TGeant3TGeo.h>
37+ #endif
38+ #ifdef FAIRROOT_HAS_GEANT4
39+ #include < TGeant4.h>
40+ #endif
41+
3542FairYamlVMCConfig::FairYamlVMCConfig ()
3643 : FairGenericVMCConfig()
3744 , fMCEngine(" " )
38- {
39- }
45+ {}
4046
4147void FairYamlVMCConfig::Setup (const char * mcEngine)
4248{
@@ -61,7 +67,8 @@ void FairYamlVMCConfig::Setup(const char* mcEngine)
6167
6268void FairYamlVMCConfig::SetupPostInit (const char * mcEngine)
6369{
64- if ( !fPostInitFlag ) {
70+ #ifdef FAIRROOT_HAS_GEANT4
71+ if (!fPostInitFlag ) {
6572 LOG (info) << " FairYamlVMCConfig::SetupPostInit() OFF." << fPostInitName ;
6673 return ;
6774 }
@@ -85,7 +92,7 @@ void FairYamlVMCConfig::SetupPostInit(const char* mcEngine)
8592 g4Macro = " g4ConfigPostInit.C" ;
8693 fPostInitName = g4Macro;
8794 } else {
88- if (fPostInitName .find (" /" )!= std::string::npos) {
95+ if (fPostInitName .find (" /" ) != std::string::npos) {
8996 AbsPath = kTRUE ;
9097 }
9198 g4Macro = fPostInitName ;
@@ -105,19 +112,27 @@ void FairYamlVMCConfig::SetupPostInit(const char* mcEngine)
105112 fYamlConfigPostInit = YAML::LoadFile (ConfigMacro.Data ());
106113
107114 if (fYamlConfigPostInit [" Geant4_PostInit_Commands" ]) {
108- std::vector<std::string> g4commands = fYamlConfigPostInit [" Geant4_PostInit_Commands" ].as <std::vector<std::string>>();
109- for ( const auto & value: g4commands ) {
115+ std::vector<std::string> g4commands =
116+ fYamlConfigPostInit [" Geant4_PostInit_Commands" ].as <std::vector<std::string>>();
117+ for (const auto & value : g4commands) {
110118 LOG (info) << " execute command \" " << value << " \" " ;
111119 TGeant4* geant4 = dynamic_cast <TGeant4*>(TVirtualMC::GetMC ());
112120 geant4->ProcessGeantCommand (value.c_str ());
113121 }
114122 }
115123
116124 LOG (info) << " got info from " << fPostInitName ;
125+ #else
126+ LOG (fatal) << " FairYamlVMCConfig::SetupPostInit() - Geant4 support is not available! "
127+ << " FairRoot was compiled without Geant4. "
128+ << " Please use TGeant3 or recompile FairRoot with Geant4 support." ;
129+
130+ #endif
117131}
118132
119133void FairYamlVMCConfig::SetupGeant3 ()
120134{
135+ #ifdef FAIRROOT_HAS_GEANT3
121136 LOG (info) << " FairYamlVMCConfig::SetupGeant3() called" ;
122137 FairRunSim* fRun = FairRunSim::Instance ();
123138 TString* gModel = fRun ->GetGeoModel ();
@@ -156,10 +171,18 @@ void FairYamlVMCConfig::SetupGeant3()
156171 geant3->SetERAN (fYamlConfig [" G3_ERAN" ].as <double >());
157172 if (fYamlConfig [" G3_CKOV" ])
158173 geant3->SetCKOV (fYamlConfig [" G3_CKOV" ].as <int >());
174+
175+ LOG (info) << geant3->GetName () << " MonteCarlo engine created!." ;
176+ #else
177+ LOG (fatal) << " FairYamlVMCConfig::SetupGeant3() - Geant3 support is not available! "
178+ << " FairRoot was compiled without Geant3. "
179+ << " Please use TGeant4 or recompile FairRoot with Geant3 support." ;
180+ #endif
159181}
160182
161183void FairYamlVMCConfig::SetupGeant4 ()
162184{
185+ #ifdef FAIRROOT_HAS_GEANT4
163186 LOG (info) << " FairYamlVMCConfig::SetupGeant4() called" ;
164187
165188 if (!fYamlConfig [" Geant4_UserGeometry" ]) {
@@ -191,10 +214,13 @@ void FairYamlVMCConfig::SetupGeant4()
191214
192215 auto const useFastSim (fYamlConfig [" UseFastSim" ] ? fYamlConfig [" UseFastSim" ].as <bool >() : fUseFastSimDefault );
193216 std::unique_ptr<TG4RunConfiguration> runConfiguration;
217+ #ifdef FAIRROOT_HAS_FASTSIM
194218 if (useFastSim) {
195219 runConfiguration = std::make_unique<FairFastSimRunConfiguration>(
196220 g4UserGeometry, g4PhysicsList, g4SpecialProcess, specialStacking, mtMode);
197- } else {
221+ } else
222+ #endif
223+ {
198224 runConfiguration = std::make_unique<TG4RunConfiguration>(
199225 g4UserGeometry, g4PhysicsList, g4SpecialProcess, specialStacking, mtMode);
200226 }
@@ -215,6 +241,11 @@ void FairYamlVMCConfig::SetupGeant4()
215241 }
216242
217243 LOG (info) << geant4->GetName () << " MonteCarlo engine created!." ;
244+ #else
245+ LOG (fatal) << " FairYamlVMCConfig::SetupGeant4() - Geant4 support is not available! "
246+ << " FairRoot was compiled without Geant4. "
247+ << " Please use TGeant3 or recompile FairRoot with Geant4 support." ;
248+ #endif
218249}
219250
220251void FairYamlVMCConfig::SetCuts ()
0 commit comments