Skip to content

Commit

Permalink
Check if the proper seed is saved in file
Browse files Browse the repository at this point in the history
ROOT changes the return value of the GetSeed function of TRandom3. FairRoot
uses this function to write the seed value used in the simulation to the
FairBaseParSet parameter container for later usage. With ROOT > 6.24 the
saved value is wrong due to the change in the ROOT code.
Add a test which fails if the used seed value isn't properly stored in the
parameter container.

(cherry picked from commit 812db13)
  • Loading branch information
fuhlig1 authored and ChristianTackeGSI committed Nov 16, 2023
1 parent e0a1514 commit 4cd6215
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
13 changes: 11 additions & 2 deletions examples/simulation/Tutorial2/macros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,30 @@ GENERATE_ROOT_TEST_SCRIPT(${CMAKE_CURRENT_SOURCE_DIR}/read_digis.C)
GENERATE_ROOT_TEST_SCRIPT(${CMAKE_CURRENT_SOURCE_DIR}/run_background.C)
GENERATE_ROOT_TEST_SCRIPT(${CMAKE_CURRENT_SOURCE_DIR}/run_signal.C)
GENERATE_ROOT_TEST_SCRIPT(${CMAKE_CURRENT_SOURCE_DIR}/run_tutorial2.C)
GENERATE_ROOT_TEST_SCRIPT(${CMAKE_CURRENT_SOURCE_DIR}/compare_seed_value.C)

set(maxTestTime 60)

add_test(NAME ex_sim_tutorial2
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/run_tutorial2.sh)
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/run_tutorial2.sh 10 \"TGeant4\" true 333)
set_tests_properties(ex_sim_tutorial2 PROPERTIES
TIMEOUT ${maxTestTime}
PASS_REGULAR_EXPRESSION "Macro finished successfully"
FIXTURES_SETUP fixtures.ex_sim_tutorial2_sim
)

add_test(NAME ex_compare_seed_value
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/compare_seed_value.sh \"tutorial2_pions.params_p2.000_t0_n10.root\" 333)
set_tests_properties(ex_compare_seed_value PROPERTIES
TIMEOUT ${maxTestTime}
FIXTURES_REQUIRED fixtures.ex_sim_tutorial2_sim
FIXTURES_SETUP fixtures.ex_compare_seed_value
)

add_test(NAME ex_sim_tutorial2_create_digis
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/create_digis.sh)
set_tests_properties(ex_sim_tutorial2_create_digis PROPERTIES
FIXTURES_REQUIRED fixtures.ex_sim_tutorial2_sim
FIXTURES_REQUIRED fixtures.ex_compare_seed_value
TIMEOUT ${maxTestTime}
PASS_REGULAR_EXPRESSION "Macro finished successfully"
FIXTURES_SETUP fixtures.ex_sim_tutorial2_digi
Expand Down
20 changes: 20 additions & 0 deletions examples/simulation/Tutorial2/macros/compare_seed_value.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
int compare_seed_value(TString filename, UInt_t initial_seed) {

// Open parameter file and get the stored random seed from the
// FairBaseParSet parameter container
// Compare the random seed with the expected one set during the
// transport run

std::unique_ptr<TFile> myFile( TFile::Open(filename) );
std::unique_ptr<FairBaseParSet> par(myFile->Get<FairBaseParSet>("FairBaseParSet"));
UInt_t seed = par->GetRndSeed();

if ( seed == initial_seed ) {
return 0;
}
else {
std::cout << "Expected seed value : " << initial_seed << std::endl;
std::cout << "Seed value from file : " << seed << std::endl;
return 1;
}
}
5 changes: 3 additions & 2 deletions examples/simulation/Tutorial2/macros/run_tutorial2.C
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include <TSystem.h>
#include <memory>

void run_tutorial2(Int_t nEvents = 10, TString mcEngine = "TGeant4", Bool_t isMT = true)
void run_tutorial2(Int_t nEvents = 10, TString mcEngine = "TGeant4",
Bool_t isMT = true, UInt_t initial_seed=98989)
{
TString dir = getenv("VMCWORKDIR");

Expand Down Expand Up @@ -49,7 +50,7 @@ void run_tutorial2(Int_t nEvents = 10, TString mcEngine = "TGeant4", Bool_t isMT
nEvents);

// Set the random seed
gRandom->SetSeed(98989);
gRandom->SetSeed(initial_seed);

// In general, the following parts need not be touched
// ========================================================================
Expand Down

0 comments on commit 4cd6215

Please sign in to comment.