diff --git a/Examples/options/tut_detsim.py b/Examples/options/tut_detsim.py index 27622a1671527fe2cc78e2844aee201fc47104b8..ededb9965cfeb4b78a928de4633b20d8952f8bbd 100644 --- a/Examples/options/tut_detsim.py +++ b/Examples/options/tut_detsim.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import os -print(os.environ["DD4HEP_LIBRARY_PATH"]) import sys # sys.exit(0) @@ -12,13 +11,15 @@ from Gaudi.Configuration import * ############################################################################## from Configurables import RndmGenSvc, HepRndm__Engine_CLHEP__RanluxEngine_ +seed = [42] + # rndmengine = HepRndm__Engine_CLHEP__RanluxEngine_() # The default engine in Gaudi -rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_() # The default engine in Geant4 +rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_("RndmGenSvc.Engine") # The default engine in Geant4 rndmengine.SetSingleton = True -rndmengine.Seeds = [42] +rndmengine.Seeds = seed -# rndmgensvc = RndmGenSvc("RndmGenSvc") -# rndmgensvc.Engine = rndmengine.name() +rndmgensvc = RndmGenSvc("RndmGenSvc") +rndmgensvc.Engine = rndmengine.name() ############################################################################## @@ -100,6 +101,7 @@ detsimsvc = DetSimSvc("DetSimSvc") from Configurables import DetSimAlg detsimalg = DetSimAlg("DetSimAlg") +detsimalg.RandomSeeds = seed # detsimalg.VisMacs = ["vis.mac"] @@ -133,5 +135,5 @@ from Configurables import ApplicationMgr ApplicationMgr( TopAlg = [genalg, detsimalg, out], EvtSel = 'NONE', EvtMax = 10, - ExtSvc = [rndmengine, dsvc, geosvc], + ExtSvc = [rndmengine, rndmgensvc, dsvc, geosvc], ) diff --git a/Examples/options/tut_detsim_SDT.py b/Examples/options/tut_detsim_SDT.py index d040cbd404134e03eda3f52604e6dcf3eb3b0e0b..268e317b2a206775ceea32e72b8bd566143b5cd2 100644 --- a/Examples/options/tut_detsim_SDT.py +++ b/Examples/options/tut_detsim_SDT.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import os -print(os.environ["DD4HEP_LIBRARY_PATH"]) import sys # sys.exit(0) @@ -12,13 +11,15 @@ from Gaudi.Configuration import * ############################################################################## from Configurables import RndmGenSvc, HepRndm__Engine_CLHEP__RanluxEngine_ +seed = [42] + # rndmengine = HepRndm__Engine_CLHEP__RanluxEngine_() # The default engine in Gaudi -rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_() # The default engine in Geant4 +rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_("RndmGenSvc.Engine") # The default engine in Geant4 rndmengine.SetSingleton = True -rndmengine.Seeds = [42] +rndmengine.Seeds = seed -# rndmgensvc = RndmGenSvc("RndmGenSvc") -# rndmgensvc.Engine = rndmengine.name() +rndmgensvc = RndmGenSvc("RndmGenSvc") +rndmgensvc.Engine = rndmengine.name() ############################################################################## @@ -110,6 +111,7 @@ detsimsvc = DetSimSvc("DetSimSvc") from Configurables import DetSimAlg detsimalg = DetSimAlg("DetSimAlg") +detsimalg.RandomSeeds = seed if int(os.environ.get("VIS", 0)): detsimalg.VisMacs = ["vis.mac"] @@ -173,5 +175,5 @@ from Configurables import ApplicationMgr ApplicationMgr( TopAlg = [genalg, detsimalg, out], EvtSel = 'NONE', EvtMax = 10, - ExtSvc = [rndmengine, dsvc, geosvc], + ExtSvc = [rndmengine, rndmgensvc, dsvc, geosvc], ) diff --git a/Examples/options/tut_detsim_digi_SDT.py b/Examples/options/tut_detsim_digi_SDT.py index df2f7672f93691a0fb23521e8a589d13d582f770..1dfd75ec1872c0300903afe6d1cdf5fd30318445 100644 --- a/Examples/options/tut_detsim_digi_SDT.py +++ b/Examples/options/tut_detsim_digi_SDT.py @@ -12,13 +12,15 @@ from Gaudi.Configuration import * ############################################################################## from Configurables import RndmGenSvc, HepRndm__Engine_CLHEP__RanluxEngine_ +seed = [42] + # rndmengine = HepRndm__Engine_CLHEP__RanluxEngine_() # The default engine in Gaudi -rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_() # The default engine in Geant4 +rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_("RndmGenSvc.Engine") # The default engine in Geant4 rndmengine.SetSingleton = True -rndmengine.Seeds = [42] +rndmengine.Seeds = seed -# rndmgensvc = RndmGenSvc("RndmGenSvc") -# rndmgensvc.Engine = rndmengine.name() +rndmgensvc = RndmGenSvc("RndmGenSvc") +rndmgensvc.Engine = rndmengine.name() ############################################################################## @@ -112,6 +114,7 @@ detsimsvc = DetSimSvc("DetSimSvc") from Configurables import DetSimAlg detsimalg = DetSimAlg("DetSimAlg") +detsimalg.RandomSeeds = seed if int(os.environ.get("VIS", 0)): detsimalg.VisMacs = ["vis.mac"] @@ -183,7 +186,7 @@ from Configurables import ApplicationMgr ApplicationMgr( TopAlg = [genalg, detsimalg, dCHDigiAlg, out], EvtSel = 'NONE', EvtMax = 10, - ExtSvc = [rndmengine, dsvc, geosvc], + ExtSvc = [rndmengine, rndmgensvc, dsvc, geosvc], HistogramPersistency = "ROOT", OutputLevel=INFO ) diff --git a/Examples/options/tut_detsim_digi_fit_DC.py b/Examples/options/tut_detsim_digi_fit_DC.py index 770bf4267256f540decd991517a4afb37634e57d..aec8695f5714de62ab4413f5ef9fc90d397dde7e 100644 --- a/Examples/options/tut_detsim_digi_fit_DC.py +++ b/Examples/options/tut_detsim_digi_fit_DC.py @@ -12,13 +12,15 @@ from Gaudi.Configuration import * ############################################################################## from Configurables import RndmGenSvc, HepRndm__Engine_CLHEP__RanluxEngine_ +seed = [42] + # rndmengine = HepRndm__Engine_CLHEP__RanluxEngine_() # The default engine in Gaudi -rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_() # The default engine in Geant4 +rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_("RndmGenSvc.Engine") # The default engine in Geant4 rndmengine.SetSingleton = True -rndmengine.Seeds = [42] +rndmengine.Seeds = seed -# rndmgensvc = RndmGenSvc("RndmGenSvc") -# rndmgensvc.Engine = rndmengine.name() +rndmgensvc = RndmGenSvc("RndmGenSvc") +rndmgensvc.Engine = rndmengine.name() ############################################################################## @@ -112,6 +114,7 @@ detsimsvc = DetSimSvc("DetSimSvc") from Configurables import DetSimAlg detsimalg = DetSimAlg("DetSimAlg") +detsimalg.RandomSeeds = seed if int(os.environ.get("VIS", 0)): detsimalg.VisMacs = ["vis.mac"] @@ -193,7 +196,7 @@ ApplicationMgr( TopAlg = [genalg, detsimalg, dCHDigiAlg, truthTrackerAlg, recGenfitAlgDC,out], EvtSel = 'NONE', EvtMax = 10, - ExtSvc = [rndmengine, dsvc, geosvc, ntsvc], + ExtSvc = [rndmengine, rndmgensvc, dsvc, geosvc, ntsvc], HistogramPersistency = "ROOT", OutputLevel=ERROR ) diff --git a/Examples/options/tut_detsim_digi_truthTracker_SDT.py b/Examples/options/tut_detsim_digi_truthTracker_SDT.py index a5fd439aa790627b439c51e0146b233b5069399a..cbef316570dd61d203d7dfc4885eb5be2af070f0 100644 --- a/Examples/options/tut_detsim_digi_truthTracker_SDT.py +++ b/Examples/options/tut_detsim_digi_truthTracker_SDT.py @@ -12,13 +12,15 @@ from Gaudi.Configuration import * ############################################################################## from Configurables import RndmGenSvc, HepRndm__Engine_CLHEP__RanluxEngine_ +seed = [42] + # rndmengine = HepRndm__Engine_CLHEP__RanluxEngine_() # The default engine in Gaudi -rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_() # The default engine in Geant4 +rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_("RndmGenSvc.Engine") # The default engine in Geant4 rndmengine.SetSingleton = True -rndmengine.Seeds = [42] +rndmengine.Seeds = seed -# rndmgensvc = RndmGenSvc("RndmGenSvc") -# rndmgensvc.Engine = rndmengine.name() +rndmgensvc = RndmGenSvc("RndmGenSvc") +rndmgensvc.Engine = rndmengine.name() ############################################################################## @@ -112,6 +114,7 @@ detsimsvc = DetSimSvc("DetSimSvc") from Configurables import DetSimAlg detsimalg = DetSimAlg("DetSimAlg") +detsimalg.RandomSeeds = seed if int(os.environ.get("VIS", 0)): detsimalg.VisMacs = ["vis.mac"] @@ -176,7 +179,7 @@ dCHDigiAlg.WriteAna = True from Configurables import TruthTrackerAlg truthTrackerAlg = TruthTrackerAlg("TruthTrackerAlg") truthTrackerAlg.DCHitAssociationCollection="DCHAssociationCollectio" -truthTrackerAlg.debug = 1 +# truthTrackerAlg.debug = 1 ############################################################################## # POD I/O @@ -194,7 +197,7 @@ from Configurables import ApplicationMgr ApplicationMgr( TopAlg = [genalg, detsimalg, dCHDigiAlg, truthTrackerAlg, out], EvtSel = 'NONE', EvtMax = 10, - ExtSvc = [rndmengine, dsvc, geosvc], + ExtSvc = [rndmengine, rndmgensvc, dsvc, geosvc], HistogramPersistency = "ROOT", OutputLevel=INFO ) diff --git a/Examples/options/tut_detsim_digi_truthTracker_SDT_dedx.py b/Examples/options/tut_detsim_digi_truthTracker_SDT_dedx.py index 892572df60aac3d093d145135c7872e4506e9409..84bf326d6d3a887ca7515f6dc3a4cd61e3b65964 100644 --- a/Examples/options/tut_detsim_digi_truthTracker_SDT_dedx.py +++ b/Examples/options/tut_detsim_digi_truthTracker_SDT_dedx.py @@ -12,13 +12,15 @@ from Gaudi.Configuration import * ############################################################################## from Configurables import RndmGenSvc, HepRndm__Engine_CLHEP__RanluxEngine_ +seed = [42] + # rndmengine = HepRndm__Engine_CLHEP__RanluxEngine_() # The default engine in Gaudi -rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_() # The default engine in Geant4 +rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_("RndmGenSvc.Engine") # The default engine in Geant4 rndmengine.SetSingleton = True -rndmengine.Seeds = [42] +rndmengine.Seeds = seed -# rndmgensvc = RndmGenSvc("RndmGenSvc") -# rndmgensvc.Engine = rndmengine.name() +rndmgensvc = RndmGenSvc("RndmGenSvc") +rndmgensvc.Engine = rndmengine.name() ############################################################################## @@ -113,6 +115,7 @@ detsimsvc = DetSimSvc("DetSimSvc") from Configurables import DetSimAlg detsimalg = DetSimAlg("DetSimAlg") +detsimalg.RandomSeeds = seed #detsimalg.RunMacs = ["Examples/options/noDecay.mac"] #detsimalg.RunCmds = ["Examples/options/noDecay.mac"] @@ -216,7 +219,7 @@ from Configurables import ApplicationMgr ApplicationMgr( TopAlg = [genalg, detsimalg, dCHDigiAlg, truthTrackerAlg, dedxAlg], EvtSel = 'NONE', EvtMax = 10, - ExtSvc = [rndmengine, dsvc, geosvc], + ExtSvc = [rndmengine, rndmgensvc, dsvc, geosvc], HistogramPersistency = "ROOT", OutputLevel=INFO ) diff --git a/Examples/options/tut_detsim_pan_matrix.py b/Examples/options/tut_detsim_pan_matrix.py index ccc5b3e1cc277f535e3b566181f24f5067d2ada0..7340454f1055e011ad561f40be130acba0acc4f6 100644 --- a/Examples/options/tut_detsim_pan_matrix.py +++ b/Examples/options/tut_detsim_pan_matrix.py @@ -11,9 +11,14 @@ from Gaudi.Configuration import * ############################################################################## from Configurables import RndmGenSvc, HepRndm__Engine_CLHEP__RanluxEngine_ -rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_() # The default engine in Geant4 +seed = [42] + +rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_("RndmGenSvc.Engine") # The default engine in Geant4 rndmengine.SetSingleton = True -rndmengine.Seeds = [42] +rndmengine.Seeds = seed + +rndmgensvc = RndmGenSvc("RndmGenSvc") +rndmgensvc.Engine = rndmengine.name() ############################################################################## # Event Data Svc @@ -87,7 +92,9 @@ from Configurables import DetSimSvc detsimsvc = DetSimSvc("DetSimSvc") from Configurables import DetSimAlg detsimalg = DetSimAlg("DetSimAlg") -detsimalg.VisMacs = ["Examples/options/vis.mac"] +detsimalg.RandomSeeds = seed + +# detsimalg.VisMacs = ["Examples/options/vis.mac"] detsimalg.RunCmds = [ # "/tracking/verbose 1", ] @@ -173,6 +180,6 @@ ApplicationMgr( #TopAlg = [genalg, detsimalg, example_CaloDigiAlg, pandoralg], EvtSel = 'NONE', EvtMax = 50, - ExtSvc = [rndmengine, dsvc, geosvc, gearSvc,detsimsvc], + ExtSvc = [rndmengine, rndmgensvc, dsvc, geosvc, gearSvc,detsimsvc], OutputLevel=INFO ) diff --git a/Examples/options/tut_detsim_pandora.py b/Examples/options/tut_detsim_pandora.py index 2768ea499d7259f85fdf03099d593c82e81ed895..d6be9779536ca104ede45df6114aece9411b5625 100644 --- a/Examples/options/tut_detsim_pandora.py +++ b/Examples/options/tut_detsim_pandora.py @@ -11,10 +11,15 @@ from Gaudi.Configuration import * ############################################################################## from Configurables import RndmGenSvc, HepRndm__Engine_CLHEP__RanluxEngine_ +seed = [42] + # rndmengine = HepRndm__Engine_CLHEP__RanluxEngine_() # The default engine in Gaudi -rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_() # The default engine in Geant4 +rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_("RndmGenSvc.Engine") # The default engine in Geant4 rndmengine.SetSingleton = True -rndmengine.Seeds = [42] +rndmengine.Seeds = seed + +rndmgensvc = RndmGenSvc("RndmGenSvc") +rndmgensvc.Engine = rndmengine.name() ############################################################################## # Event Data Svc @@ -90,6 +95,7 @@ detsimsvc = DetSimSvc("DetSimSvc") from Configurables import DetSimAlg detsimalg = DetSimAlg("DetSimAlg") +detsimalg.RandomSeeds = seed # detsimalg.VisMacs = ["vis.mac"] @@ -217,7 +223,7 @@ ApplicationMgr( TopAlg = [genalg, detsimalg, simHitMerge, caloDigi, pandoralg, write], EvtSel = 'NONE', EvtMax = 10, - ExtSvc = [rndmengine, dsvc, geosvc, gearSvc,detsimsvc], + ExtSvc = [rndmengine, rndmgensvc, dsvc, geosvc, gearSvc,detsimsvc], HistogramPersistency = "ROOT", OutputLevel=INFO ) diff --git a/Simulation/DetSimCore/src/DetSimAlg.cpp b/Simulation/DetSimCore/src/DetSimAlg.cpp index 31583d82135590f33f4ed712740df02505d8199e..29e32f62b86866fd7d5d575dc500e0c579e6c547 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" << endmsg; + 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 36646d9e8b449058aa7588cc8bbe89d3acff5342..bb4571c74ad2dceddab2fea70a551bea292ddea7 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"};