Skip to content
Snippets Groups Projects
Commit 961f2d7a authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

Merge branch 'TransportTool_AthRNGSvc_master' into 'master'

Migrate ISF_Geant4Tools/TransportTool to use the thread-safe random number service

See merge request atlas/athena!20704
parents 194b1650 fc2ac5fc
No related branches found
No related tags found
No related merge requests found
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
## -----------------------------------------------------------------------------
### Base Version
......@@ -71,8 +71,7 @@ def getAFII_G4TrackProcessorUserActionTool(name='AFII_G4TrackProcessorUserAction
### Base Version
def getGeant4Tool(name="ISF_Geant4Tool", **kwargs):
from G4AtlasApps.SimFlags import simFlags
kwargs.setdefault('RandomGenerator', 'athena')
kwargs.setdefault('RandomNumberService', simFlags.RandomSvc())
kwargs.setdefault('RandomNumberService', simFlags.RandomSvcMT())
kwargs.setdefault('InputConverter', 'ISF_InputConverter')
kwargs.setdefault('UserActionSvc','G4UA::ISFUserActionSvc')
if hasattr(simFlags, 'RecordFlux') and simFlags.RecordFlux.statusOn:
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
// class header
......@@ -9,6 +9,8 @@
#include "G4AtlasAlg/G4AtlasRunManager.h"
#include "ISFFluxRecorder.h"
#include "AthenaKernel/RNGWrapper.h"
// ISF classes
#include "ISF_Event/ISFParticle.h"
#include "ISF_Event/ISFParticleVector.h"
......@@ -53,7 +55,6 @@ iGeant4::G4TransportTool::G4TransportTool(const std::string& type,
declareProperty("Dll", m_libList);
declareProperty("Physics", m_physList);
declareProperty("FieldMap", m_fieldMap);
declareProperty("RandomGenerator", m_rndmGen);
declareProperty("ReleaseGeoModel", m_releaseGeoModel);
declareProperty("RecordFlux", m_recordFlux);
declareProperty("McEventCollection", m_mcEventCollectionName);
......@@ -93,6 +94,8 @@ StatusCode iGeant4::G4TransportTool::initialize()
ATH_MSG_ERROR("Failure in iGeant4::G4TransportTool::initializeOnce: " << e.what());
return StatusCode::FAILURE;
}
ATH_CHECK( m_rndmGenSvc.retrieve() );
ATH_CHECK( m_userActionSvc.retrieve() );
ATH_CHECK(m_g4atlasSvc.retrieve());
......@@ -157,19 +160,6 @@ void iGeant4::G4TransportTool::initializeOnce()
ui->ApplyCommand("/MagneticField/Initialize");
}
if (m_rndmGen=="athena" || m_rndmGen=="ranecu") {
// Set the random number generator to AtRndmGen
if (m_rndmGenSvc.retrieve().isFailure()) {
throw std::runtime_error("Could not initialize ATLAS Random Generator Service");
}
CLHEP::HepRandomEngine* engine = m_rndmGenSvc->GetEngine("AtlasG4");
CLHEP::HepRandom::setTheEngine(engine);
ATH_MSG_DEBUG("Random nr. generator is set to Athena");
}
else if (m_rndmGen=="geant4" || m_rndmGen.empty()) {
ATH_MSG_INFO("Random nr. generator is set to Geant4");
}
// Send UI commands
ATH_MSG_DEBUG("G4 Command: Trying at the end of initializeOnce()");
for (auto g4command : m_g4commands) {
......@@ -298,6 +288,12 @@ StatusCode iGeant4::G4TransportTool::setupEvent()
{
ATH_MSG_DEBUG ( "setup Event" );
// Set the RNG to use for this event. We need to reset it for MT jobs
// because of the mismatch between Gaudi slot-local and G4 thread-local RNG.
ATHRNG::RNGWrapper* rngWrapper = m_rndmGenSvc->getEngine(this);
rngWrapper->setSeed( name(), Gaudi::Hive::currentContext() );
G4Random::setTheEngine(*rngWrapper);
ATH_CHECK(m_senDetTool->BeginOfAthenaEvent());
m_nrOfEntries++;
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ISF_GEANT4TOOLS_TRANSPORTTOOL_H
......@@ -17,7 +17,7 @@
#include "AtlasDetDescr/AtlasRegion.h"
// Athena headers
#include "AthenaKernel/IAtRndmGenSvc.h"
#include "AthenaKernel/IAthRNGSvc.h"
#include "G4AtlasInterfaces/IG4AtlasSvc.h"
#include "G4AtlasInterfaces/IUserActionSvc.h"
#include "G4AtlasInterfaces/IDetectorGeometrySvc.h"
......@@ -123,7 +123,6 @@ namespace iGeant4
std::string m_libList{""};
std::string m_physList{""};
std::string m_fieldMap{""};
std::string m_rndmGen{"athena"};
bool m_releaseGeoModel{true};
bool m_recordFlux{false};
/// Commands to send to the G4 UI
......@@ -131,7 +130,7 @@ namespace iGeant4
/// Activate multi-threading configuration
bool m_useMT{false};
// Random number service
ServiceHandle<IAtRndmGenSvc> m_rndmGenSvc{this, "RandomNumberService", "AtDSFMTGenSvc", ""};
ServiceHandle<IAthRNGSvc> m_rndmGenSvc{this, "RandomNumberService", "AthRNGSvc", ""};
/// G4AtlasSvc
ServiceHandle<IG4AtlasSvc> m_g4atlasSvc{this, "G4AtlasSvc", "G4AtlasSvc", ""};
/// user action service
......
......@@ -21,7 +21,7 @@ ciRefFileMap = {
's3126-21.0' : 'v1',
's3126-21.3' : 'v1',
's3126-21.9' : 'v1',
's3126-22.0' : 'v1',
's3126-22.0' : 'v2',
# OverlayTier0Test_required-test
'overlay-d1498-21.0' : 'v1',
'overlay-d1498-22.0' : 'v2',
......
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