Skip to content

Commit 56f1e18

Browse files
committed
fix(mcconfigurator): Fix to run without TGeant3
The MCConfigurator required TGeant3 and TGeant4 to run. Added compiler flags to enable running without any given transport engine.
1 parent e22c961 commit 56f1e18

File tree

4 files changed

+76
-24
lines changed

4 files changed

+76
-24
lines changed

examples/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
################################################################################
2-
# Copyright (C) 2014-2022 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, #
@@ -11,17 +11,17 @@ add_subdirectory(common/mcstack)
1111

1212
set(mcEngine_list TGeant4)
1313

14+
if(TARGET MCConfigurator)
15+
add_subdirectory(common/gconfig)
16+
endif()
17+
1418
if(Geant3_FOUND)
1519
if(ENABLE_GEANT3_TESTING)
1620
list(APPEND mcEngine_list TGeant3)
1721
endif()
1822
if(TARGET FairRoot::EventDisplay)
1923
add_subdirectory(common/eventdisplay)
2024
endif()
21-
if(TARGET MCConfigurator)
22-
add_subdirectory(common/gconfig)
23-
endif()
24-
2525
endif()
2626

2727
if(TARGET FairRoot::FastSim AND TARGET Boost::program_options)

fairroot/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ else()
4040
message(STATUS "eventdisplay will not be built, because ROOT has no opengl support.")
4141
endif()
4242

43-
if(Geant3_FOUND AND Geant4VMC_FOUND AND yaml-cpp_FOUND
44-
AND TARGET FairRoot::FastSim)
43+
if(yaml-cpp_FOUND)
4544
add_subdirectory(mcconfigurator)
4645
endif()
4746

fairroot/mcconfigurator/CMakeLists.txt

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
################################################################################
2-
# Copyright (C) 2014-2022 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, #
@@ -22,22 +22,44 @@ target_include_directories(${target} PUBLIC
2222
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
2323
)
2424

25+
# Set compile definition
26+
if(Geant3_FOUND)
27+
target_compile_definitions(${target} PUBLIC FAIRROOT_HAS_GEANT3)
28+
endif()
29+
if(Geant4VMC_FOUND)
30+
target_compile_definitions(${target} PUBLIC FAIRROOT_HAS_GEANT4)
31+
endif()
32+
if(TARGET FairRoot::FastSim)
33+
target_compile_definitions(${target} PUBLIC FAIRROOT_HAS_FASTSIM)
34+
endif()
35+
2536
target_link_libraries(${target}
2637
PUBLIC
2738
FairRoot::Base # FairGenericVMCConfig
2839
yaml-cpp::yaml-cpp
2940

3041
PRIVATE
3142
FairRoot::Tools
32-
FairRoot::FastSim # FairFastSimRunConfiguration
33-
34-
geant321
35-
geant4vmc
3643

3744
ROOT::Core
3845
${VMCLIB}
3946
)
4047

48+
if(Geant3_FOUND)
49+
target_link_libraries(${target}
50+
PUBLIC
51+
geant321
52+
)
53+
endif()
54+
55+
if(Geant4VMC_FOUND)
56+
target_link_libraries(${target}
57+
PUBLIC
58+
geant4vmc
59+
$<IF:$<TARGET_EXISTS:FairRoot::FastSim>,FairRoot::FastSim,> # FairFastSimRunConfiguration
60+
)
61+
endif()
62+
4163
fairroot_target_root_dictionary(${target}
4264
HEADERS ${headers}
4365
LINKDEF LinkDef.h

fairroot/mcconfigurator/FairYamlVMCConfig.cxx

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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, *
@@ -11,15 +11,11 @@
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>
@@ -32,11 +28,21 @@
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+
3542
FairYamlVMCConfig::FairYamlVMCConfig()
3643
: FairGenericVMCConfig()
3744
, fMCEngine("")
38-
{
39-
}
45+
{}
4046

4147
void FairYamlVMCConfig::Setup(const char* mcEngine)
4248
{
@@ -61,7 +67,8 @@ void FairYamlVMCConfig::Setup(const char* mcEngine)
6167

6268
void 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

119133
void 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

161183
void 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

220251
void FairYamlVMCConfig::SetCuts()

0 commit comments

Comments
 (0)