Skip to content

Commit 7c5068f

Browse files
committed
feat(glad/test):Added macros for testing simulations with GLAD
Minor changes
1 parent 42562c5 commit 7c5068f

8 files changed

Lines changed: 232 additions & 8 deletions

field/R3BFieldConst.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
2-
* Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3-
* Copyright (C) 2019-2026 Members of R3B Collaboration *
2+
* Copyright (C) 2009 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3+
* Copyright (C) 2009-2026 Members of R3B Collaboration *
44
* *
55
* This software is distributed under the terms of the *
66
* GNU General Public Licence (GPL) version 3, *

field/R3BFieldConst.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
2-
* Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3-
* Copyright (C) 2019-2026 Members of R3B Collaboration *
2+
* Copyright (C) 2009 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3+
* Copyright (C) 2009-2026 Members of R3B Collaboration *
44
* *
55
* This software is distributed under the terms of the *
66
* GNU General Public Licence (GPL) version 3, *

field/R3BFieldContFact.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
2-
* Copyright (C) 2006 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3-
* Copyright (C) 2006-2026 Members of R3B Collaboration *
2+
* Copyright (C) 2009 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3+
* Copyright (C) 2009-2026 Members of R3B Collaboration *
44
* *
55
* This software is distributed under the terms of the *
66
* GNU General Public Licence (GPL) version 3, *

field/R3BFieldContFact.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
2-
* Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3-
* Copyright (C) 2019-2026 Members of R3B Collaboration *
2+
* Copyright (C) 2009 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3+
* Copyright (C) 2009-2026 Members of R3B Collaboration *
44
* *
55
* This software is distributed under the terms of the *
66
* GNU General Public Licence (GPL) version 3, *

glad/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ add_library_with_dictionary(
2727
R3BGladMagnet.h
2828
DEPENDENCIES
2929
R3BTracking)
30+
31+
add_subdirectory(test)

glad/test/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
##############################################################################
2+
# Copyright (C) 2025 GSI Helmholtzzentrum für Schwerionenforschung GmbH #
3+
# Copyright (C) 2025-2026 Members of R3B Collaboration #
4+
# #
5+
# This software is distributed under the terms of the #
6+
# GNU General Public Licence (GPL) version 3, #
7+
# copied verbatim in the file "LICENSE". #
8+
# #
9+
# In applying this license GSI does not waive the privileges and immunities #
10+
# granted to it by virtue of its status as an Intergovernmental Organization #
11+
# or submit itself to any jurisdiction. #
12+
##############################################################################
13+
14+
generate_root_test_script(${R3BROOT_SOURCE_DIR}/glad/test/testGladSimulation.C)
15+
add_test(NAME GladSimulation COMMAND ${R3BROOT_BINARY_DIR}/glad/test/testGladSimulation.sh)
16+
set_tests_properties(GladSimulation PROPERTIES TIMEOUT "300")
17+
set_tests_properties(GladSimulation PROPERTIES PASS_REGULAR_EXPRESSION
18+
"Macro finished successfully.")
19+
20+
generate_root_test_script(${R3BROOT_SOURCE_DIR}/glad/test/testGladHecSimulation.C)
21+
add_test(NAME GladHecSimulation COMMAND ${R3BROOT_BINARY_DIR}/glad/test/testGladHecSimulation.sh)
22+
set_tests_properties(GladHecSimulation PROPERTIES TIMEOUT "300")
23+
set_tests_properties(GladHecSimulation PROPERTIES PASS_REGULAR_EXPRESSION
24+
"Macro finished successfully.")

glad/test/testGladHecSimulation.C

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/******************************************************************************
2+
* Copyright (C) 2025 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3+
* Copyright (C) 2025-2026 Members of R3B Collaboration *
4+
* *
5+
* This software is distributed under the terms of the *
6+
* GNU General Public Licence (GPL) version 3, *
7+
* copied verbatim in the file "LICENSE". *
8+
* *
9+
* In applying this license GSI does not waive the privileges and immunities *
10+
* granted to it by virtue of its status as an Intergovernmental Organization *
11+
* or submit itself to any jurisdiction. *
12+
******************************************************************************/
13+
14+
#include <TStopwatch.h>
15+
#include <TString.h>
16+
#include <TSystem.h>
17+
#include <memory>
18+
19+
void testGladHecSimulation(const int nbevents = 100)
20+
{
21+
// Timer
22+
TStopwatch timer;
23+
timer.Start();
24+
25+
// Logging
26+
auto logger = FairLogger::GetLogger();
27+
logger->SetLogVerbosityLevel("low");
28+
logger->SetLogScreenLevel("warn");
29+
logger->SetColoredLog(true);
30+
31+
// System paths
32+
const TString workDirectory = getenv("VMCWORKDIR");
33+
gSystem->Setenv("GEOMPATH", workDirectory + "/geometry");
34+
gSystem->Setenv("CONFIG_DIR", workDirectory + "/gconfig");
35+
36+
// Output files
37+
const TString simufile = "gladhec.simu.root";
38+
const TString parafile = "gladhec.para.root";
39+
40+
// Input GLAD geometry
41+
const TString fGladGeo = "glad_hec14_v2025.1.geo.root";
42+
43+
// Basic simulation setup
44+
auto run = std::make_unique<FairRunSim>();
45+
run->SetName("TGeant4");
46+
run->SetStoreTraj(false);
47+
run->SetMaterials("media_r3b.geo");
48+
49+
auto config = std::make_unique<FairGenericVMCConfig>();
50+
run->SetSimulationConfig(std::move(config));
51+
run->SetSink(std::make_unique<FairRootFileSink>(simufile.Data()));
52+
53+
// ----- Runtime data base --------------------------------------------
54+
auto* rtdb = run->GetRuntimeDb();
55+
UInt_t runId = 1;
56+
rtdb->initContainers(runId);
57+
58+
// Primary particle generator
59+
auto ionGen = std::make_unique<FairIonGenerator>(92, 238, 92, 1, 0., 0., 1.09, 0., 0., 0.);
60+
auto primGen = std::make_unique<FairPrimaryGenerator>();
61+
primGen->AddGenerator(ionGen.release());
62+
run->SetGenerator(primGen.release());
63+
64+
// Geometry: Cave
65+
auto cave = std::make_unique<R3BCave>("CAVE");
66+
cave->SetGeometryFileName("r3b_cave_vacuum.geo");
67+
run->AddModule(cave.release());
68+
69+
// Geometry: GLAD
70+
run->AddModule(new R3BGladMagnet(fGladGeo.Data(), R3BGladMagnet::HEC14));
71+
72+
// GLAD Filed
73+
auto* GladField = new R3BGladFieldMap("R3BGladMap", "A", R3BGladFieldMap::HEC14);
74+
GladField->SetFieldfromCurrent(2600.); // Current in Amperes
75+
run->SetField(GladField);
76+
77+
// Init
78+
run->Init();
79+
80+
// Save field parameters
81+
auto* fieldPar = dynamic_cast<R3BFieldPar*>(rtdb->getContainer("R3BFieldPar"));
82+
fieldPar->SetParameters(GladField);
83+
fieldPar->setChanged();
84+
85+
// Output file with parameters
86+
auto parOut = std::make_unique<FairParRootFileIo>(true);
87+
parOut->open(parafile.Data());
88+
rtdb->setOutput(parOut.release());
89+
rtdb->saveOutput();
90+
rtdb->print();
91+
92+
// Simulate
93+
run->Run(nbevents);
94+
95+
// Report
96+
timer.Stop();
97+
std::cout << "Real time: " << timer.RealTime() << "s, CPU time: " << timer.CpuTime() << "s" << std::endl;
98+
std::cout << "Macro finished successfully." << std::endl;
99+
}

glad/test/testGladSimulation.C

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/******************************************************************************
2+
* Copyright (C) 2025 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3+
* Copyright (C) 2025-2026 Members of R3B Collaboration *
4+
* *
5+
* This software is distributed under the terms of the *
6+
* GNU General Public Licence (GPL) version 3, *
7+
* copied verbatim in the file "LICENSE". *
8+
* *
9+
* In applying this license GSI does not waive the privileges and immunities *
10+
* granted to it by virtue of its status as an Intergovernmental Organization *
11+
* or submit itself to any jurisdiction. *
12+
******************************************************************************/
13+
14+
#include <TStopwatch.h>
15+
#include <TString.h>
16+
#include <TSystem.h>
17+
#include <memory>
18+
19+
void testGladSimulation(const int nbevents = 100)
20+
{
21+
// Timer
22+
TStopwatch timer;
23+
timer.Start();
24+
25+
// Logging
26+
auto logger = FairLogger::GetLogger();
27+
logger->SetLogVerbosityLevel("low");
28+
logger->SetLogScreenLevel("warn");
29+
logger->SetColoredLog(true);
30+
31+
// System paths
32+
const TString workDirectory = getenv("VMCWORKDIR");
33+
gSystem->Setenv("GEOMPATH", workDirectory + "/geometry");
34+
gSystem->Setenv("CONFIG_DIR", workDirectory + "/gconfig");
35+
36+
// Output files
37+
const TString simufile = "glad.simu.root";
38+
const TString parafile = "glad.para.root";
39+
40+
// Input GLAD geometry
41+
const TString fGladGeo = "glad_v2025.1.geo.root";
42+
43+
// Basic simulation setup
44+
auto run = std::make_unique<FairRunSim>();
45+
run->SetName("TGeant4");
46+
run->SetStoreTraj(false);
47+
run->SetMaterials("media_r3b.geo");
48+
49+
auto config = std::make_unique<FairGenericVMCConfig>();
50+
run->SetSimulationConfig(std::move(config));
51+
run->SetSink(std::make_unique<FairRootFileSink>(simufile.Data()));
52+
53+
// ----- Runtime data base --------------------------------------------
54+
auto* rtdb = run->GetRuntimeDb();
55+
UInt_t runId = 1;
56+
rtdb->initContainers(runId);
57+
58+
// Primary particle generator
59+
auto ionGen = std::make_unique<FairIonGenerator>(92, 238, 92, 1, 0., 0., 1.09, 0., 0., 0.);
60+
auto primGen = std::make_unique<FairPrimaryGenerator>();
61+
primGen->AddGenerator(ionGen.release());
62+
run->SetGenerator(primGen.release());
63+
64+
// Geometry: Cave
65+
auto cave = std::make_unique<R3BCave>("CAVE");
66+
cave->SetGeometryFileName("r3b_cave_vacuum.geo");
67+
run->AddModule(cave.release());
68+
69+
// Geometry: GLAD
70+
run->AddModule(new R3BGladMagnet(fGladGeo.Data()));
71+
72+
// GLAD Filed
73+
auto* GladField = new R3BGladFieldMap("R3BGladMap");
74+
GladField->SetFieldfromCurrent(2600.); // Current in Amperes
75+
run->SetField(GladField);
76+
77+
// Init
78+
run->Init();
79+
80+
// Save field parameters
81+
auto* fieldPar = dynamic_cast<R3BFieldPar*>(rtdb->getContainer("R3BFieldPar"));
82+
fieldPar->SetParameters(GladField);
83+
fieldPar->setChanged();
84+
85+
// Output file with parameters
86+
auto parOut = std::make_unique<FairParRootFileIo>(true);
87+
parOut->open(parafile.Data());
88+
rtdb->setOutput(parOut.release());
89+
rtdb->saveOutput();
90+
rtdb->print();
91+
92+
// Simulate
93+
run->Run(nbevents);
94+
95+
// Report
96+
timer.Stop();
97+
std::cout << "Real time: " << timer.RealTime() << "s, CPU time: " << timer.CpuTime() << "s" << std::endl;
98+
std::cout << "Macro finished successfully." << std::endl;
99+
}

0 commit comments

Comments
 (0)