Skip to content

Commit dff136e

Browse files
amorschsawenzel
authored andcommitted
Support for FLUKA VMC backend in O2
This commit provides support for FLUKA in O2. FLUKA compilation is optional for the moment. This backend can be selected via: ``` o2-sim -e TFluka ... ```
1 parent 5a763d1 commit dff136e

File tree

9 files changed

+150
-10
lines changed

9 files changed

+150
-10
lines changed

DataFormats/simulation/src/Stack.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ Stack::Stack(Int_t size)
7777
mIsG4Like(false)
7878
{
7979
auto vmc = TVirtualMC::GetMC();
80-
if (vmc && strcmp(vmc->GetName(), "TGeant4") == 0) {
81-
mIsG4Like = true;
80+
if (vmc) {
81+
mIsG4Like = !(vmc->SecondariesAreOrdered());
8282
}
8383

8484
auto& param = o2::sim::StackParam::Instance();

Detectors/gconfig/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ o2_add_library(G4Setup
1818
PUBLIC_LINK_LIBRARIES MC::Geant4VMC MC::Geant4 FairRoot::Base O2::SimulationDataFormat O2::Generators ROOT::EGPythia6
1919
)
2020

21+
if (FlukaVMC_FOUND)
22+
message(STATUS "BUILDING WITH FLUKA")
23+
o2_add_library(FLUKASetup
24+
SOURCES src/FlukaConfig.cxx
25+
PUBLIC_LINK_LIBRARIES MC::FlukaVMC FairRoot::Base O2::SimulationDataFormat O2::Generators ROOT::EGPythia6
26+
)
27+
else()
28+
message(STATUS "BUILDING WITHOUT FLUKA")
29+
endif (FlukaVMC_FOUND)
30+
2131
o2_add_library(SimSetup
2232
SOURCES src/GlobalProcessCutSimParam.cxx src/SimSetup.cxx src/SetCuts.cxx
2333
PUBLIC_LINK_LIBRARIES O2::CommonUtils O2::DetectorsBase
@@ -49,3 +59,5 @@ o2_add_test_root_macro(g3Config.C
4959
o2_add_test_root_macro(g4Config.C
5060
PUBLIC_LINK_LIBRARIES O2::SimSetup
5161
LABELS simsetup)
62+
63+
o2_data_file(COPY data DESTINATION Detectors/gconfig/)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
GLOBAL 50000. 4.0
2+
DEFAULTS NEW-DEFA
3+
OPEN 1. OLD
4+
random.dat
5+
GEOBEGIN COMBINAT
6+
GEOEND
7+
*
8+
*...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+
9+
*
10+
EVENTYPE 1.0
11+
BEAM 7000.0 MUON-
12+
MGNFIELD 10.0 0.001
13+
SOURCE
14+
*...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+
15+
USERDUMP 200. 37.0 -2.0 1.0 TRAKFILE
16+
START 42000.99999999.0 2.0
17+
STOP
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#include "FairRunSim.h"
12+
#include "TFluka.h"
13+
#include "SimulationDataFormat/Stack.h"
14+
#include "SimulationDataFormat/StackParam.h"
15+
#include <iostream>
16+
#include "FairLogger.h"
17+
#include "FairModule.h"
18+
#include "Generators/DecayerPythia8.h"
19+
#include "../commonConfig.C"
20+
21+
// these are used in commonConfig.C
22+
using o2::eventgen::DecayerPythia8;
23+
24+
namespace o2
25+
{
26+
namespace flukaconfig
27+
{
28+
29+
void linkFlukaFiles()
30+
{
31+
// Link here some special Fluka files needed
32+
gSystem->Exec("ln -s $FLUKADATA/neuxsc.bin .");
33+
gSystem->Exec("ln -s $FLUKADATA/elasct.bin .");
34+
gSystem->Exec("ln -s $FLUKADATA/gxsect.bin .");
35+
gSystem->Exec("ln -s $FLUKADATA/nuclear.bin .");
36+
gSystem->Exec("ln -s $FLUKADATA/sigmapi.bin .");
37+
gSystem->Exec("ln -s $FLUKADATA/brems_fin.bin .");
38+
gSystem->Exec("ln -s $FLUKADATA/cohff.bin .");
39+
gSystem->Exec("ln -s $FLUKADATA/fluodt.dat .");
40+
gSystem->Exec("ln -s $FLUKADATA/random.dat .");
41+
// Copy the random seed
42+
gSystem->Exec("cp $FLUKADATA/random.dat old.seed");
43+
// Give some meaningfull name to the output
44+
gSystem->Exec("ln -s fluka.out fort.11");
45+
gSystem->Exec("ln -s fluka.err fort.15");
46+
gSystem->Exec("ln -fs $ALICE_ROOT/TFluka/macro/FlukaConfig.C Config.C");
47+
gSystem->Exec("ln -fs $O2_ROOT/share/Detectors/gconfig/data/coreFlukaVmc.inp .");
48+
}
49+
50+
void Config()
51+
{
52+
linkFlukaFiles();
53+
FairRunSim* run = FairRunSim::Instance();
54+
TString* gModel = run->GetGeoModel();
55+
TFluka* fluka = new TFluka("C++ Interface to Fluka", 0);
56+
stackSetup(fluka, run);
57+
58+
// setup decayer
59+
decayerSetup(fluka);
60+
61+
// ******* FLUKA specific configuration for simulated Runs *******
62+
}
63+
64+
void FlukaConfig()
65+
{
66+
LOG(INFO) << "Setting up FLUKA sim from library code";
67+
Config();
68+
}
69+
} // namespace flukaconfig
70+
} // namespace o2

Detectors/gconfig/src/SimSetup.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ void SimSetup::setup(const char* engine)
5353
setupFromPlugin("libO2G3Setup", "_ZN2o28g3config8G3ConfigEv");
5454
} else if (strcmp(engine, "TGeant4") == 0) {
5555
setupFromPlugin("libO2G4Setup", "_ZN2o28g4config8G4ConfigEv");
56+
} else if (strcmp(engine, "TFluka") == 0) {
57+
setupFromPlugin("libO2FLUKASetup", "_ZN2o211flukaconfig11FlukaConfigEv");
5658
} else {
5759
LOG(FATAL) << "Unsupported engine " << engine;
5860
}

dependencies/FindFlukaVMC.cmake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright CERN and copyright holders of ALICE O2. This software is distributed
2+
# under the terms of the GNU General Public License v3 (GPL Version 3), copied
3+
# verbatim in the file "COPYING".
4+
#
5+
# See http://alice-o2.web.cern.ch/license for full licensing information.
6+
#
7+
# In applying this license CERN does not waive the privileges and immunities
8+
# granted to it by virtue of its status as an Intergovernmental Organization or
9+
# submit itself to any jurisdiction.
10+
11+
# use the GEANT4_VMCConfig.cmake provided by the Geant4VMC installation but
12+
# amend the target geant4vmc with the include directories
13+
14+
find_package(FlukaVMC NO_MODULE)
15+
if(NOT FlukaVMC_FOUND)
16+
return()
17+
endif()
18+
19+
set_target_properties(flukavmc
20+
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
21+
"${FlukaVMC_INCLUDE_DIRS}"
22+
INTERFACE_LINK_DIRECTORIES
23+
$<TARGET_FILE_DIR:flukavmc>)
24+
25+
# Promote the imported target to global visibility
26+
# (so we can alias it)
27+
set_target_properties(flukavmc PROPERTIES IMPORTED_GLOBAL TRUE)
28+
29+
add_library(MC::FlukaVMC ALIAS flukavmc)

dependencies/O2FindDependenciesFromAliBuild.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ function(o2_find_dependencies_from_alibuild)
154154
protected_set_root(Geant3 GEANT3)
155155
protected_set_root(Geant4 GEANT4)
156156
protected_set_root(Geant4VMC GEANT4_VMC)
157+
protected_set_root(FlukaVMC FLUKA_VMC)
157158
protected_set_root(VGM vgm)
158159
protected_set_root(HepMC HepMC3)
159160

dependencies/O2SimulationDependencies.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ set_package_properties(Geant4
6363
find_package(Geant4VMC MODULE)
6464
set_package_properties(Geant4VMC PROPERTIES TYPE ${mcPackageRequirement})
6565

66+
find_package(FlukaVMC MODULE)
67+
set_package_properties(FlukaVMC PROPERTIES TYPE OPTIONAL)
68+
6669
find_package(VGM MODULE)
6770
set_package_properties(VGM PROPERTIES TYPE ${mcPackageRequirement})
6871

run/O2SimDevice.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,8 @@ class O2SimDevice final : public FairMQDevice
188188
<< "part " << info.part << "/" << info.nparts;
189189
gRandom->SetSeed(chunk->mSubEventInfo.seed);
190190

191-
auto& conf = o2::conf::SimConfig::Instance();
192-
if (strcmp(conf.getMCEngine().c_str(), "TGeant4") == 0) {
193-
mVMC->ProcessEvent();
194-
} else {
195-
// for Geant3 at least calling ProcessEvent is not enough
196-
// as some hooks are not called
197-
mVMC->ProcessRun(1);
198-
}
191+
// Process one event
192+
mVMC->ProcessRun(1);
199193

200194
FairSystemInfo sysinfo;
201195
LOG(INFO) << "TIME-STAMP " << mTimer.RealTime() << "\t";

0 commit comments

Comments
 (0)