Skip to content
Snippets Groups Projects
Commit 0441cf82 authored by Florian Uhlig's avatar Florian Uhlig Committed by Volker Friese
Browse files

Fix Geant4 random number initialisation

parent 06942549
No related branches found
No related tags found
1 merge request!1207Fix Geant4 random number initialisation
Pipeline #22836 passed
...@@ -62,8 +62,10 @@ void Config() ...@@ -62,8 +62,10 @@ void Config()
//set geant4 specific stuff //set geant4 specific stuff
// Get the infomation about the seed value defined by SetSeed from the base class.
// Since ROOT 6.24 the derived classes return a differnt value.
Text_t buffer[50]; Text_t buffer[50];
sprintf(buffer, "/random/setSeeds %i %i ", gRandom->GetSeed(), gRandom->GetSeed()); sprintf(buffer, "/random/setSeeds %i %i ", gRandom->TRandom::GetSeed(), gRandom->TRandom::GetSeed());
geant4->ProcessGeantCommand(buffer); geant4->ProcessGeantCommand(buffer);
geant4->SetMaxNStep(10000); // default is 30000 geant4->SetMaxNStep(10000); // default is 30000
......
...@@ -34,8 +34,11 @@ void CbmGeant4Settings::Init(TVirtualMC* vmc) ...@@ -34,8 +34,11 @@ void CbmGeant4Settings::Init(TVirtualMC* vmc)
// --- Random seed and maximum number of steps // --- Random seed and maximum number of steps
size_t buf_size = 100; size_t buf_size = 100;
Text_t buffer[buf_size]; Text_t buffer[buf_size];
int result_length = // Get the infomation about the seed value defined by SetSeed from the base class.
snprintf(buffer, buf_size - 1, "/random/setSeeds %i %i ", gRandom->GetSeed(), gRandom->GetSeed()); // Since ROOT 6.24 the derrived classes return a differnt value.
fRandomSeed = gRandom->TRandom::GetSeed();
LOG(info) << "Set Geant4 random seed to " << fRandomSeed;
int result_length = snprintf(buffer, buf_size - 1, "/random/setSeeds %i %i ", fRandomSeed, fRandomSeed);
if (!(result_length > 0 && result_length < static_cast<int>(buf_size))) { if (!(result_length > 0 && result_length < static_cast<int>(buf_size))) {
LOG(fatal) << "Buffer overrun. Random seed for Geant4 would be improper."; LOG(fatal) << "Buffer overrun. Random seed for Geant4 would be improper.";
} }
......
...@@ -55,6 +55,12 @@ public: ...@@ -55,6 +55,12 @@ public:
**/ **/
std::array<std::string, 3> GetG4RunConfig() { return fG4RunConfig; } std::array<std::string, 3> GetG4RunConfig() { return fG4RunConfig; }
/** @brief Get the Geant4 random seed
** @return Initial seed value
**
**/
Int_t GetG4Seed() { return fRandomSeed; }
/** @brief Set a new command which should be passsed to Geant4. The call will /** @brief Set a new command which should be passsed to Geant4. The call will
** remove the current list of commands ** remove the current list of commands
** @param[in] Geant4 command string ** @param[in] Geant4 command string
...@@ -71,12 +77,23 @@ public: ...@@ -71,12 +77,23 @@ public:
**/ **/
void AddG4Command(std::string command) { fG4Commands.push_back(command); } void AddG4Command(std::string command) { fG4Commands.push_back(command); }
/** @brief Get the Geant4 commands
** @return Vector with the commands passed to Geant4
**
**/
std::vector<std::string> GetG4Commands() { return fG4Commands; }
/** @brief Set the maximum number of steps after which the transport is stopped /** @brief Set the maximum number of steps after which the transport is stopped
** list of commands ** list of commands
** @param[in] Number of steps ** @param[in] Number of steps
**/ **/
void SetMaximumNumberOfSteps(Int_t numSteps) { fMaxNumSteps = numSteps; } void SetMaximumNumberOfSteps(Int_t numSteps) { fMaxNumSteps = numSteps; }
/** @brief Get the maximum number of steps
** @return Number of steps after which the transport is stopped
**/
Int_t GetMaximumNumberOfSteps() { return fMaxNumSteps; }
private: private:
std::array<std::string, 3> fG4RunConfig {{"geomRoot", "QGSP_BERT_EMV+optical", "stepLimiter"}}; std::array<std::string, 3> fG4RunConfig {{"geomRoot", "QGSP_BERT_EMV+optical", "stepLimiter"}};
...@@ -90,7 +107,9 @@ private: ...@@ -90,7 +107,9 @@ private:
Int_t fMaxNumSteps {10000000}; Int_t fMaxNumSteps {10000000};
ClassDef(CbmGeant4Settings, 3); Int_t fRandomSeed {0};
ClassDef(CbmGeant4Settings, 4);
}; };
#endif /* CBMGEANT4SETTINGS_H */ #endif /* CBMGEANT4SETTINGS_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment