I would like to set my simulation up such that the seed is always the same. I need to test the results from 2 detector configurations in detail (number for number) and so would like the generated particles to be identical even after re-compiling.
Is there a way to do this? I tried to set the seed so a specific value in the main but this didn’t work.
Thanks for the reply! I tried to use your solution from the thread you suggest and I have a problem linking filesystem. Because of my gcc version I used the boost library but see the following linker error :
CMakeFiles/task.dir/src/PrimaryGeneratorAction.cc.o: In function PrimaryGeneratorAction::GeneratePrimaries(G4Event*)': PrimaryGeneratorAction.cc:(.text+0x99): undefined reference to boost::system::system_category()’
PrimaryGeneratorAction.cc:(.text+0x14e): undefined reference to boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)' CMakeFiles/task.dir/src/PrimaryGeneratorAction.cc.o: In function _GLOBAL__sub_I__ZN22PrimaryGeneratorActionC2Ev’:
PrimaryGeneratorAction.cc:(.text.startup+0x13a): undefined reference to boost::system::generic_category()' PrimaryGeneratorAction.cc:(.text.startup+0x146): undefined reference to boost::system::generic_category()’
PrimaryGeneratorAction.cc:(.text.startup+0x152): undefined reference to `boost::system::system_category()’
collect2: error: ld returned 1 exit status
make[2]: *** [task] Error 1
make[1]: *** [CMakeFiles/task.dir/all] Error 2
make: *** [all] Error 2
Code :
#include <boost/filesystem.hpp>
void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
// Task 2a.2: Include the position randomization
boost::system::error_code ec;
std::string fileName = “random/event_”+std::to_string(anEvent->GetEventID())+".rndm.stat";
if (boost::filesystem::exists(fileName, ec)) {
CLHEP::HepRandom::getTheEngine()->restoreStatus (fileName.c_str());
} else {
CLHEP::HepRandom::getTheEngine()->saveStatus (fileName.c_str());
}
Did you link boost libraries to your project?
But if you use boost only for that reason, there is no need, one can check otherwise if file exists, I believe this should work:
Yeah, of course. I think I have been staring at this so long that my mind has gone blank to anything else Anyway your solution worked for me, thanks a lot!