From f9c8106b406f30026ae79dcf259c3ad0429506a9 Mon Sep 17 00:00:00 2001
From: lintao <lintao51@gmail.com>
Date: Thu, 21 Jan 2021 22:23:04 +0800
Subject: [PATCH] WIP: as the random seed will be reset in the initialization
 of Gaudi's HEP random engine, we need to set the seed again.

---
 Simulation/DetSimCore/src/DetSimAlg.cpp | 11 +++++++++++
 Simulation/DetSimCore/src/DetSimAlg.h   |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/Simulation/DetSimCore/src/DetSimAlg.cpp b/Simulation/DetSimCore/src/DetSimAlg.cpp
index 31583d82..ae8d5506 100644
--- a/Simulation/DetSimCore/src/DetSimAlg.cpp
+++ b/Simulation/DetSimCore/src/DetSimAlg.cpp
@@ -2,12 +2,14 @@
 #include "GaudiKernel/IEventProcessor.h"
 #include "GaudiKernel/IAppMgrUI.h"
 #include "GaudiKernel/GaudiException.h"
+#include "GaudiKernel/IRndmEngine.h"
 
 #include "G4RunManager.hh"
 #include "G4UImanager.hh"
 #include "G4VisExecutive.hh"
 #include "G4UIExecutive.hh"
 
+#include "Randomize.hh"
 #include "DetectorConstruction.h"
 #include "G4PhysListFactory.hh"
 #include "G4EmParameters.hh"
@@ -30,6 +32,15 @@ DetSimAlg::initialize() {
 
     info() << "Initialize DetSimAlg... " << endmsg;
 
+    // Initialize random seed
+    if (not m_randomSeeds.empty()) {
+        randSvc()->engine()->setSeeds( m_randomSeeds );
+    }
+
+    info() << "Random Seed is initialized to "
+           << G4Random::getTheSeed()
+           << " in Geant4" << std::endl;
+
     m_detsimsvc = service("DetSimSvc");
     if (!m_detsimsvc) {
         error() << "Failed to find DetSimSvc. " << endmsg;
diff --git a/Simulation/DetSimCore/src/DetSimAlg.h b/Simulation/DetSimCore/src/DetSimAlg.h
index 36646d9e..bb4571c7 100644
--- a/Simulation/DetSimCore/src/DetSimAlg.h
+++ b/Simulation/DetSimCore/src/DetSimAlg.h
@@ -31,6 +31,8 @@ private:
 
 private:
 
+    Gaudi::Property<std::vector<long>> m_randomSeeds{this, "RandomSeeds", {}};
+
     Gaudi::Property<std::vector<std::string>> m_run_macs{this, "RunMacs"};
     Gaudi::Property<std::vector<std::string>> m_run_cmds{this, "RunCmds"};
     Gaudi::Property<std::vector<std::string>> m_vis_macs{this, "VisMacs"};
-- 
GitLab