Skip to content
Snippets Groups Projects
Commit d2abf0f8 authored by Florian Uhlig's avatar Florian Uhlig Committed by Administrator
Browse files

Fix Geant4 random number initialisation

This is a cherry-pick of 0441cf82.
This also changes the usage of sprintf to snprintf.
parent 08003b56
No related branches found
No related tags found
No related merge requests found
...@@ -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
......
...@@ -32,8 +32,16 @@ void CbmGeant4Settings::Init(TVirtualMC* vmc) ...@@ -32,8 +32,16 @@ void CbmGeant4Settings::Init(TVirtualMC* vmc)
} }
// --- Random seed and maximum number of steps // --- Random seed and maximum number of steps
Text_t buffer[50]; size_t buf_size = 100;
sprintf(buffer, "/random/setSeeds %i %i ", gRandom->GetSeed(), gRandom->GetSeed()); Text_t buffer[buf_size];
// Get the infomation about the seed value defined by SetSeed from the base class.
// 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))) {
LOG(fatal) << "Buffer overrun. Random seed for Geant4 would be improper.";
}
vmcg4->ProcessGeantCommand(buffer); vmcg4->ProcessGeantCommand(buffer);
vmcg4->SetMaxNStep(fMaxNumSteps); vmcg4->SetMaxNStep(fMaxNumSteps);
......
...@@ -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