diff --git a/Simulation/ISF/ISF_Acts/ISF_ActsTools/src/ActsFatrasSimTool.h b/Simulation/ISF/ISF_Acts/ISF_ActsTools/src/ActsFatrasSimTool.h index 10cb77e979baf6ef96efebd38d2049eb7826facb..83fd2091dbe459aea1d62ebcc5a11f1fa621490e 100644 --- a/Simulation/ISF/ISF_Acts/ISF_ActsTools/src/ActsFatrasSimTool.h +++ b/Simulation/ISF/ISF_Acts/ISF_ActsTools/src/ActsFatrasSimTool.h @@ -2,10 +2,6 @@ Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ -/////////////////////////////////////////////////////////////////// -// ActsFatrasSimTool.h, (c) ATLAS Detector software -/////////////////////////////////////////////////////////////////// - #ifndef ISF_ACTSTOOLS_ACTSFATRASSIMTOOL_H #define ISF_ACTSTOOLS_ACTSFATRASSIMTOOL_H @@ -110,8 +106,8 @@ class ActsFatrasSimTool : public BaseSimulatorTool { virtual StatusCode initialize() override; virtual StatusCode simulate(const ISFParticle& isp, ISFParticleContainer&, McEventCollection*) const override; - virtual StatusCode setupEvent() override { return StatusCode::SUCCESS; }; - virtual StatusCode releaseEvent() override { return StatusCode::SUCCESS; }; + virtual StatusCode setupEvent(const EventContext&) override { return StatusCode::SUCCESS; }; + virtual StatusCode releaseEvent(const EventContext&) override { return StatusCode::SUCCESS; }; virtual ISF::SimulationFlavor simFlavor() const override { return ISF::Fatras; }; virtual ISF::ISFParticle* process(const ISFParticle& isp) const; diff --git a/Simulation/ISF/ISF_Core/ISF_Algorithms/src/SimKernelMT.cxx b/Simulation/ISF/ISF_Core/ISF_Algorithms/src/SimKernelMT.cxx index 1df564504963609d376a5a9070a9a3bdca3eeadf..549379ae3b62d2bf45f9003a96e3641b35d649f7 100644 --- a/Simulation/ISF/ISF_Core/ISF_Algorithms/src/SimKernelMT.cxx +++ b/Simulation/ISF/ISF_Core/ISF_Algorithms/src/SimKernelMT.cxx @@ -130,10 +130,11 @@ StatusCode ISF::SimKernelMT::initialize() { StatusCode ISF::SimKernelMT::execute() { + const EventContext& ctx = Gaudi::Hive::currentContext(); // Call setupEvent for all simulators (TODO: make the tools do this) for (auto& curSimTool: m_simulationTools) { if ( curSimTool ) { - ATH_CHECK(curSimTool->setupEvent()); + ATH_CHECK(curSimTool->setupEvent(ctx)); ATH_MSG_DEBUG( "Event setup done for " << curSimTool->name() ); } } @@ -145,7 +146,7 @@ StatusCode ISF::SimKernelMT::execute() { } // copy input Evgen collection to output Truth collection - SG::WriteHandle<McEventCollection> outputTruth(m_outputTruthKey); + SG::WriteHandle<McEventCollection> outputTruth(m_outputTruthKey, ctx); outputTruth = std::make_unique<McEventCollection>(*inputEvgen); // Apply QS patch if required @@ -159,13 +160,13 @@ StatusCode ISF::SimKernelMT::execute() { ATH_CHECK(m_truthRecordSvc->initializeTruthCollection()); // Create TrackRecordCollections and pass them to the entryLayerTool - SG::WriteHandle<TrackRecordCollection> caloEntryLayer(m_caloEntryLayerKey); + SG::WriteHandle<TrackRecordCollection> caloEntryLayer(m_caloEntryLayerKey, ctx); caloEntryLayer = std::make_unique<TrackRecordCollection>(caloEntryLayer.name()); ATH_CHECK(m_entryLayerTool->registerTrackRecordCollection(caloEntryLayer.ptr(), fAtlasCaloEntry)); - SG::WriteHandle<TrackRecordCollection> muonEntryLayer(m_muonEntryLayerKey); + SG::WriteHandle<TrackRecordCollection> muonEntryLayer(m_muonEntryLayerKey, ctx); muonEntryLayer = std::make_unique<TrackRecordCollection>(muonEntryLayer.name()); ATH_CHECK(m_entryLayerTool->registerTrackRecordCollection(muonEntryLayer.ptr(), fAtlasMuonEntry)); - SG::WriteHandle<TrackRecordCollection> muonExitLayer(m_muonExitLayerKey); + SG::WriteHandle<TrackRecordCollection> muonExitLayer(m_muonExitLayerKey, ctx); muonExitLayer = std::make_unique<TrackRecordCollection>(muonExitLayer.name()); ATH_CHECK(m_entryLayerTool->registerTrackRecordCollection(muonExitLayer.ptr(), fAtlasMuonExit)); @@ -272,7 +273,7 @@ StatusCode ISF::SimKernelMT::execute() { // Release the event from all simulators (TODO: make the tools do this) for (auto& curSimTool: m_simulationTools) { if ( curSimTool ) { - ATH_CHECK(curSimTool->releaseEvent()); + ATH_CHECK(curSimTool->releaseEvent(ctx)); ATH_MSG_DEBUG( "releaseEvent() completed for " << curSimTool->name() ); } } diff --git a/Simulation/ISF/ISF_Core/ISF_Algorithms/test/SimKernelMT_test.cxx b/Simulation/ISF/ISF_Core/ISF_Algorithms/test/SimKernelMT_test.cxx index 662aab17cd6004777748bbc47ed8c426d27b0c49..afe68d6cce8c9a6a2721b90d96cc5381a164bbab 100644 --- a/Simulation/ISF/ISF_Core/ISF_Algorithms/test/SimKernelMT_test.cxx +++ b/Simulation/ISF/ISF_Core/ISF_Algorithms/test/SimKernelMT_test.cxx @@ -164,10 +164,10 @@ public: virtual ~MockSimulatorTool() { }; MOCK_METHOD0(finalize, StatusCode()); - MOCK_METHOD0(setupEvent, StatusCode()); + MOCK_METHOD1(setupEvent, StatusCode(const EventContext&)); MOCK_CONST_METHOD3(simulate, StatusCode(const ISF::ISFParticle&, ISF::ISFParticleContainer&, McEventCollection*)); MOCK_CONST_METHOD3(simulateVector, StatusCode(const ISF::ConstISFParticleVector&, ISF::ISFParticleContainer&, McEventCollection*)); - MOCK_METHOD0(releaseEvent, StatusCode()); + MOCK_METHOD1(releaseEvent, StatusCode(const EventContext&)); MOCK_CONST_METHOD1(bid, int(const ISF::ISFParticle&)); // dummy methods implementing in pure virtual interface methods (to make class non-abstract) @@ -289,6 +289,7 @@ protected: m_mockSimulatorTool = retrieveTool<MockSimulatorTool>(mockSimulatorToolName); m_mockSimulationSelector = retrieveTool<MockSimulationSelector>(mockSimulationSelectorName); m_mockEntryLayerTool = retrieveTool<MockEntryLayerTool>(mockEntryLayerToolName); + ASSERT_TRUE( m_svcLoc->service("StoreGateSvc", m_sg) ); } virtual void TearDown() override { @@ -345,10 +346,15 @@ protected: } void setEmptyInputOutputCollections() { + // create a dummy EventContext + EventContext ctx; + ctx.setExtension( Atlas::ExtendedEventContext( m_sg ) ); + Gaudi::Hive::setCurrentContext( ctx ); auto inputEvgen = std::make_unique<McEventCollection>(); - SG::WriteHandle<McEventCollection> inputEvgenHandle{"emptyTestInputEvgenCollection"}; - EXPECT_TRUE( inputEvgenHandle.record( std::move(inputEvgen) ).isSuccess() ); - + SG::WriteHandleKey<McEventCollection> testInputEvgenKey{"emptyTestInputEvgenCollection"}; + ASSERT_TRUE(testInputEvgenKey.initialize().isSuccess()); + SG::WriteHandle<McEventCollection> testInputEvgenHandle(testInputEvgenKey, ctx); + EXPECT_TRUE( testInputEvgenHandle.record( std::move(inputEvgen) ).isSuccess() ); EXPECT_TRUE( m_alg->setProperty("InputEvgenCollection", "emptyTestInputEvgenCollection").isSuccess() ); EXPECT_TRUE( m_alg->setProperty("OutputTruthCollection", "testOutputTruthCollection").isSuccess() ); EXPECT_TRUE( m_alg->setProperty("InputConverter", mockInputConverterName).isSuccess() ); @@ -371,6 +377,8 @@ protected: // the tested AthAlgorithm ISF::SimKernelMT* m_alg; + StoreGateSvc* m_sg{}; + // mocked Athena components ISFTesting::MockGeoIDSvc* m_mockGeoIDSvc = nullptr; ISFTesting::MockTruthSvc* m_mockTruthSvc = nullptr; @@ -486,8 +494,15 @@ protected: EXPECT_TRUE( m_alg->setProperty("OutputTruthCollection", "testOutputTruthCollection").isSuccess() ); EXPECT_TRUE( m_alg->setProperty("InputConverter", mockInputConverterName).isSuccess() ); + // create a dummy EventContext + EventContext ctx; + ctx.setExtension( Atlas::ExtendedEventContext( m_sg ) ); + Gaudi::Hive::setCurrentContext( ctx ); + auto inputEvgen = std::make_unique<McEventCollection>(); - SG::WriteHandle<McEventCollection> testInputEvgenHandle{"testInputEvgenCollection"}; + SG::WriteHandleKey<McEventCollection> testInputEvgenKey{"testInputEvgenCollection"}; + ASSERT_TRUE(testInputEvgenKey.initialize().isSuccess()); + SG::WriteHandle<McEventCollection> testInputEvgenHandle(testInputEvgenKey, ctx); EXPECT_TRUE( testInputEvgenHandle.record( std::move(inputEvgen) ).isSuccess() ); ASSERT_TRUE( m_alg->initialize().isSuccess() ); @@ -498,12 +513,19 @@ protected: TEST_F(SimKernelMT_test, emptyInputCollection_expectSuccess) { + // create a dummy EventContext + EventContext ctx; + ctx.setExtension( Atlas::ExtendedEventContext( m_sg ) ); + Gaudi::Hive::setCurrentContext( ctx ); + auto inputEvgen = std::make_unique<McEventCollection>(); auto* genEvent = new HepMC::GenEvent{}; inputEvgen->push_back(genEvent); - SG::WriteHandle<McEventCollection> inputEvgenHandle{"testInputEvgenCollection"}; - EXPECT_TRUE( inputEvgenHandle.record( std::move(inputEvgen) ).isSuccess() ); + SG::WriteHandleKey<McEventCollection> testInputEvgenKey{"testInputEvgenCollection"}; + ASSERT_TRUE(testInputEvgenKey.initialize().isSuccess()); + SG::WriteHandle<McEventCollection> testInputEvgenHandle(testInputEvgenKey, ctx); + EXPECT_TRUE( testInputEvgenHandle.record( std::move(inputEvgen) ).isSuccess() ); EXPECT_TRUE( m_alg->setProperty("InputEvgenCollection", "testInputEvgenCollection").isSuccess() ); EXPECT_TRUE( m_alg->setProperty("OutputTruthCollection", "testOutputTruthCollection").isSuccess() ); @@ -515,6 +537,11 @@ protected: TEST_F(SimKernelMT_test, filledInputCollection_expectFullConversion) { + // create a dummy EventContext + EventContext ctx; + ctx.setExtension( Atlas::ExtendedEventContext( m_sg ) ); + Gaudi::Hive::setCurrentContext( ctx ); + auto* genEvent = new HepMC::GenEvent{}; HepMC::GenParticlePtr genPart = HepMC::newGenParticlePtr(); HepMC::FourVector mom{12.3, 45.6, 78.9, 0.12}; @@ -529,8 +556,10 @@ protected: auto inputEvgen = std::make_unique<McEventCollection>(); inputEvgen->push_back(genEvent); - SG::WriteHandle<McEventCollection> inputEvgenHandle{"testInputEvgenCollection"}; - EXPECT_TRUE( inputEvgenHandle.record( std::move(inputEvgen) ).isSuccess() ); + SG::WriteHandleKey<McEventCollection> testInputEvgenKey{"testInputEvgenCollection"}; + ASSERT_TRUE(testInputEvgenKey.initialize().isSuccess()); + SG::WriteHandle<McEventCollection> testInputEvgenHandle(testInputEvgenKey, ctx); + EXPECT_TRUE( testInputEvgenHandle.record( std::move(inputEvgen) ).isSuccess() ); EXPECT_TRUE( m_alg->setProperty("InputEvgenCollection", "testInputEvgenCollection").isSuccess() ); EXPECT_TRUE( m_alg->setProperty("OutputTruthCollection", "testOutputTruthCollection").isSuccess() ); @@ -731,6 +760,11 @@ protected: TEST_F(SimKernelMT_test, filledInputCollectionAndEmptySimulationTools_expectConvertedParticleSentToParticleKiller) { + // create a dummy EventContext + EventContext ctx; + ctx.setExtension( Atlas::ExtendedEventContext( m_sg ) ); + Gaudi::Hive::setCurrentContext( ctx ); + auto* genEvent = new HepMC::GenEvent{}; HepMC::FourVector mom{12.3, 45.6, 78.9, 1234.5}; HepMC::GenParticlePtr genPart = HepMC::newGenParticlePtr(mom, @@ -744,8 +778,10 @@ protected: auto inputEvgen = std::make_unique<McEventCollection>(); inputEvgen->push_back(genEvent); - SG::WriteHandle<McEventCollection> inputEvgenHandle{"testInputEvgenCollection"}; - EXPECT_TRUE( inputEvgenHandle.record( std::move(inputEvgen) ).isSuccess() ); + SG::WriteHandleKey<McEventCollection> testInputEvgenKey{"testInputEvgenCollection"}; + ASSERT_TRUE(testInputEvgenKey.initialize().isSuccess()); + SG::WriteHandle<McEventCollection> testInputEvgenHandle(testInputEvgenKey, ctx); + EXPECT_TRUE( testInputEvgenHandle.record( std::move(inputEvgen) ).isSuccess() ); EXPECT_TRUE( m_alg->setProperty("InputEvgenCollection", "testInputEvgenCollection").isSuccess() ); EXPECT_TRUE( m_alg->setProperty("OutputTruthCollection", "testOutputTruthCollection").isSuccess() ); diff --git a/Simulation/ISF/ISF_Core/ISF_Interfaces/ISF_Interfaces/BaseSimulatorTool.h b/Simulation/ISF/ISF_Core/ISF_Interfaces/ISF_Interfaces/BaseSimulatorTool.h index f759b59640739ba402e8907e7005716bf7584a42..fea0c9dcf4f6b0a004ea6f81557fa647aac6561f 100644 --- a/Simulation/ISF/ISF_Core/ISF_Interfaces/ISF_Interfaces/BaseSimulatorTool.h +++ b/Simulation/ISF/ISF_Core/ISF_Interfaces/ISF_Interfaces/BaseSimulatorTool.h @@ -62,12 +62,12 @@ namespace ISF { } /** Setup Event chain - in case of a begin-of event action is needed */ - virtual StatusCode setupEvent() override + virtual StatusCode setupEvent(const EventContext&) override { return StatusCode::FAILURE; } /** Setup Event chain - in case of a begin-of event action is needed (called by ISimulationSvc) */ virtual StatusCode setupEventST() override - { return setupEvent(); } + { return setupEvent(Gaudi::Hive::currentContext()); } /** */ virtual StatusCode simulate( const ISFParticle& , ISFParticleContainer&, McEventCollection*) const override @@ -89,12 +89,12 @@ namespace ISF { } /** Release Event chain - in case of an end-of event action is needed */ - virtual StatusCode releaseEvent() override + virtual StatusCode releaseEvent(const EventContext&) override { return StatusCode::FAILURE; } /** Release Event chain - in case of an end-of event action is needed (called by ISimulationSvc) */ virtual StatusCode releaseEventST() override - { return releaseEvent(); } + { return releaseEvent(Gaudi::Hive::currentContext()); } /** wrapper call to start chrono with given tag */ const ChronoEntity* chronoStart(const IChronoSvc::ChronoTag& tag ) { diff --git a/Simulation/ISF/ISF_Core/ISF_Interfaces/ISF_Interfaces/ISimulatorTool.h b/Simulation/ISF/ISF_Core/ISF_Interfaces/ISF_Interfaces/ISimulatorTool.h index 96aa337e0b96ca7d225244e79dfcc5da45a48c66..b18b25947e6934fb20e9b7b39a204386251d9243 100644 --- a/Simulation/ISF/ISF_Core/ISF_Interfaces/ISF_Interfaces/ISimulatorTool.h +++ b/Simulation/ISF/ISF_Core/ISF_Interfaces/ISF_Interfaces/ISimulatorTool.h @@ -32,13 +32,13 @@ public: virtual StatusCode simulateVector(const ConstISFParticleVector &particles, ISFParticleContainer& secondaries, McEventCollection* mcEventCollection) const = 0; /** Create data containers for an event */ - virtual StatusCode setupEvent() = 0; + virtual StatusCode setupEvent(const EventContext&) = 0; /** Create data containers for an event (called by ISimulationSvc) */ virtual StatusCode setupEventST() = 0; /** Finalise data containers for an event */ - virtual StatusCode releaseEvent() = 0; + virtual StatusCode releaseEvent(const EventContext&) = 0; /** Finalise data containers for an event (called by ISimulationSvc) */ virtual StatusCode releaseEventST() = 0; diff --git a/Simulation/ISF/ISF_Core/ISF_Tools/src/ParticleKillerSimTool.h b/Simulation/ISF/ISF_Core/ISF_Tools/src/ParticleKillerSimTool.h index 746990df0a780d10610eb3287feae81b2de676ae..86bf5a3d6fda0042ddbec3305d2bdaa4ee2e1011 100644 --- a/Simulation/ISF/ISF_Core/ISF_Tools/src/ParticleKillerSimTool.h +++ b/Simulation/ISF/ISF_Core/ISF_Tools/src/ParticleKillerSimTool.h @@ -32,9 +32,9 @@ public: /** */ virtual StatusCode simulateVector(const ConstISFParticleVector& particles, ISFParticleContainer&, McEventCollection* ) const override; - virtual StatusCode setupEvent() override { return StatusCode::SUCCESS; }; + virtual StatusCode setupEvent(const EventContext&) override { return StatusCode::SUCCESS; }; - virtual StatusCode releaseEvent() override { return StatusCode::SUCCESS; }; + virtual StatusCode releaseEvent(const EventContext&) override { return StatusCode::SUCCESS; }; virtual ISF::SimulationFlavor simFlavor() const override { return ISF::ParticleKiller; }; }; diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughTool.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughTool.h index 5cab36a27162115343ca92fde24993d059279d6b..565f4ad2f43ad352a27682dd194c1727cc53556d 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughTool.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimInterfaces/ISF_FastCaloSimInterfaces/IPunchThroughTool.h @@ -15,7 +15,9 @@ namespace Trk{ class Track; } - +namespace CLHEP { + class HepRandomEngine; +} namespace ISF { /** @@ -37,7 +39,7 @@ namespace ISF { DeclareInterfaceID(IPunchThroughTool, 1, 0); /** Creates new vector of ISFParticle out of a given ISFParticle */ - virtual const ISF::ISFParticleVector* computePunchThroughParticles(const ISFParticle& isfp ) const = 0; + virtual const ISF::ISFParticleVector* computePunchThroughParticles(const ISFParticle& isfp, CLHEP::HepRandomEngine* rndmEngine) const = 0; }; } // end of namespace diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/AdditionalConfig.py b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/AdditionalConfig.py index 10f0b3be0e8ea28b65dfdab13c2e4ee150fb7952..04c9656bd33d9505d52b8d8ad14e22bb93728a34 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/AdditionalConfig.py +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/AdditionalConfig.py @@ -657,8 +657,6 @@ def setAdditionalParticleParametrizationFileNames( FastShowerCellBuilderTool ): def getPunchThroughTool(name="ISF_PunchThroughTool", **kwargs): from G4AtlasApps.SimFlags import simFlags - kwargs.setdefault("RandomNumberService" , simFlags.RandomSvc() ) - kwargs.setdefault("RandomStreamName" , ISF_FastCaloSimFlags.RandomStreamName() ) kwargs.setdefault("FilenameLookupTable" , ISF_FastCaloSimFlags.PunchThroughParamsInputFilename()) kwargs.setdefault("PunchThroughInitiators" , [ 211 ] ) kwargs.setdefault("InitiatorsMinEnergy" , [ 65536 ] ) diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimServicesConfigNew.py b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimServicesConfigNew.py index 85af048adbd684391e979d6e84277c5c02f08124..d8c6ff272e88a2b23453009159af932a14682a5e 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimServicesConfigNew.py +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/python/ISF_FastCaloSimServicesConfigNew.py @@ -4,7 +4,7 @@ Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration """ from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory -from RngComps.RandomServices import RNG, dSFMT +from RngComps.RandomServices import RNG from ISF_Services.ISF_ServicesConfigNew import TruthServiceCfg ################################################################################################### @@ -20,10 +20,6 @@ def PunchThroughToolCfg(flags, name="ISF_PunchThroughTool", **kwargs): from BarcodeServices.BarcodeServicesConfigNew import BarcodeSvcCfg from SubDetectorEnvelopes.SubDetectorEnvelopesConfigNew import EnvelopeDefSvcCfg acc = ComponentAccumulator() - seed = 'FastCaloSimRnd OFFSET 0 98346412 12461240' - acc.merge(dSFMT(seed)) - kwargs.setdefault("RandomNumberService", acc.getService("AtDSFMTGenSvc")) - kwargs.setdefault("RandomStreamName", "FastCaloSimRnd") kwargs.setdefault("FilenameLookupTable", "FastCaloSim/MC16/TFCSparam_mpt_v01.root") kwargs.setdefault("PunchThroughInitiators", [211]) kwargs.setdefault("InitiatorsMinEnergy" , [ 65536 ] ) diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimV2Tool.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimV2Tool.cxx index c842f5db907df38ea525d1a0a7d778f2484586b8..8808b43acd9b3ced1ae24160963548cd66b0e904 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimV2Tool.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimV2Tool.cxx @@ -85,25 +85,25 @@ StatusCode ISF::FastCaloSimV2Tool::setupEventST() ATH_CHECK(evtStore()->record(m_theContainer, m_caloCellsOutputName)); - return this->commonSetup(); + const EventContext& ctx = Gaudi::Hive::currentContext(); + return this->commonSetup(ctx); } -StatusCode ISF::FastCaloSimV2Tool::setupEvent() +StatusCode ISF::FastCaloSimV2Tool::setupEvent(const EventContext& ctx) { ATH_MSG_DEBUG ("setupEvent"); m_theContainer = new CaloCellContainer(SG::VIEW_ELEMENTS); - return this->commonSetup(); + return this->commonSetup(ctx); } -StatusCode ISF::FastCaloSimV2Tool::commonSetup() +StatusCode ISF::FastCaloSimV2Tool::commonSetup(const EventContext& ctx) { - const EventContext& ctx = Gaudi::Hive::currentContext(); - // Set the RNG to use for this event. We need to reset it for MT jobs + // Set the RNGs 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, m_randomEngineName); - rngWrapper->setSeed( m_randomEngineName, Gaudi::Hive::currentContext() ); + rngWrapper->setSeed( m_randomEngineName, ctx ); for (const ToolHandle<ICaloCellMakerTool>& tool : m_caloCellMakerToolsSetup) { @@ -125,7 +125,7 @@ StatusCode ISF::FastCaloSimV2Tool::commonSetup() return StatusCode::SUCCESS; } -StatusCode ISF::FastCaloSimV2Tool::releaseEvent() +StatusCode ISF::FastCaloSimV2Tool::releaseEvent(const EventContext& ctx) { ATH_MSG_VERBOSE( "FastCaloSimV2Tool " << name() << " releaseEvent() " ); // Run the version of releaseEvent that returns the output collection @@ -134,7 +134,7 @@ StatusCode ISF::FastCaloSimV2Tool::releaseEvent() if ( m_theContainer ) { // Record with WriteHandle - SG::WriteHandle< CaloCellContainer > caloCellHandle( m_caloCellKey, Gaudi::Hive::currentContext() ); + SG::WriteHandle< CaloCellContainer > caloCellHandle( m_caloCellKey, ctx ); ATH_CHECK( caloCellHandle.record( std::make_unique< CaloCellContainer >( *m_theContainer ) ) ); return StatusCode::SUCCESS; } @@ -167,10 +167,12 @@ StatusCode ISF::FastCaloSimV2Tool::simulate(const ISF::ISFParticle& isfp, ISFPar Amg::Vector3D particle_position = isfp.position(); Amg::Vector3D particle_direction(isfp.momentum().x(),isfp.momentum().y(),isfp.momentum().z()); + ATHRNG::RNGWrapper* rngWrapper = m_rndmGenSvc->getEngine(this, m_randomEngineName); // TODO ideally would pass the event context to this method + if (m_doPunchThrough) { Barcode::PhysicsProcessCode process = 201; // call punch-through simulation - const ISF::ISFParticleVector *someSecondaries = m_punchThroughTool->computePunchThroughParticles(isfp); + const ISF::ISFParticleVector *someSecondaries = m_punchThroughTool->computePunchThroughParticles(isfp, *rngWrapper); if (someSecondaries) { //Record truth incident for created punch through particles ISF::ISFTruthIncident truth( const_cast<ISF::ISFParticle&>(isfp), @@ -214,7 +216,6 @@ StatusCode ISF::FastCaloSimV2Tool::simulate(const ISF::ISFParticle& isfp, ISFPar //only simulate if extrapolation to calo surface succeeded if(extrapol.CaloSurface_eta() != -999){ - ATHRNG::RNGWrapper* rngWrapper = m_rndmGenSvc->getEngine(this, m_randomEngineName); TFCSSimulationState simulstate(*rngWrapper); ATH_CHECK(m_paramSvc->simulate(simulstate, &truth, &extrapol)); diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimV2Tool.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimV2Tool.h index 7fa002e357c09f9a1af740d40f0d15a75c5ca84d..90d707e5bb2c0e4c0678e11cfd2b26c2b4d57ca9 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimV2Tool.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimV2Tool.h @@ -54,18 +54,18 @@ namespace ISF { virtual StatusCode simulate(const ISFParticle& isp, ISFParticleContainer&, McEventCollection* mcEventCollection) const override final; /** Setup Event chain - in case of a begin-of event action is needed */ - virtual StatusCode setupEvent() override final; + virtual StatusCode setupEvent(const EventContext&) override final; virtual StatusCode setupEventST() override final; /** Release Event chain - in case of an end-of event action is needed */ - virtual StatusCode releaseEvent() override final; + virtual StatusCode releaseEvent(const EventContext&) override final; virtual StatusCode releaseEventST() override final; virtual SimulationFlavor simFlavor() const override final { return ISF::FastCaloSimV2; }; private: - StatusCode commonSetup(); + StatusCode commonSetup(const EventContext& ctx); ServiceHandle<IFastCaloSimParamSvc> m_paramSvc{this, "ParamSvc", "ISF_FastCaloSimV2ParamSvc"}; bool m_doPunchThrough{false}; diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.cxx index 6a79e4dce8f533986aaa9b0c170115aaeb8674f6..fd3e7dacd148e9ee9b49cca33ea24300ab3018c9 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.cxx @@ -137,7 +137,7 @@ StatusCode ISF::FastCaloTool::setupEventST() return this->commonSetup(); } -StatusCode ISF::FastCaloTool::setupEvent() +StatusCode ISF::FastCaloTool::setupEvent(const EventContext&) { ATH_MSG_DEBUG ( "setupEvent"); @@ -355,7 +355,7 @@ std::vector<Trk::HitInfo>* ISF::FastCaloTool::caloHits(const ISF::ISFParticle& i } -StatusCode ISF::FastCaloTool::releaseEvent() { +StatusCode ISF::FastCaloTool::releaseEvent(const EventContext& ctx) { ATH_MSG_VERBOSE( "FastCaloTool " << name() << " releaseEvent() " ); @@ -365,7 +365,7 @@ StatusCode ISF::FastCaloTool::releaseEvent() { if ( m_theContainer ) { // Record with WriteHandle - SG::WriteHandle< CaloCellContainer > caloCellHandle( m_caloCellKey, Gaudi::Hive::currentContext() ); + SG::WriteHandle< CaloCellContainer > caloCellHandle( m_caloCellKey, ctx ); ATH_CHECK( caloCellHandle.record( std::make_unique< CaloCellContainer >( *m_theContainer ) ) ); return StatusCode::SUCCESS; } diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.h index ee0247cb60b700f7c9cea17f01467ee5d67df9ef..74c61ebf6934dc3a1a70d373f2db4b994cf7e1c4 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.h @@ -60,11 +60,11 @@ public: virtual StatusCode setupEventST() override; - virtual StatusCode setupEvent() override; + virtual StatusCode setupEvent(const EventContext&) override; virtual StatusCode releaseEventST() override; - virtual StatusCode releaseEvent() override; + virtual StatusCode releaseEvent(const EventContext&) override; virtual SimulationFlavor simFlavor() const override { return ISF::FastCaloSim; }; private: diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PDFcreator.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PDFcreator.cxx index 0b06376e774973f85cbcb871e6a6413449275570..b9034c3e8a597d58a318f74993f5382813e4361c 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PDFcreator.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PDFcreator.cxx @@ -1,11 +1,7 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ -/////////////////////////////////////////////////////////////////// -// PDFcreator.cxx, (c) ATLAS Detector software -/////////////////////////////////////////////////////////////////// - // class header #include "PDFcreator.h" @@ -51,7 +47,7 @@ void ISF::PDFcreator::addToEnergyEtaRangeHist2DMap(double energy, std::vector<do } } -double ISF::PDFcreator::getRand(const std::vector<double>& inputParameters, const double& outEnergy, const double& randMin, const double& randMax) const +double ISF::PDFcreator::getRand(CLHEP::HepRandomEngine* rndmEngine, const std::vector<double>& inputParameters, const double& outEnergy, const double& randMin, const double& randMax) const { //define variable to return from getRand call, should never return zero @@ -107,7 +103,7 @@ double ISF::PDFcreator::getRand(const std::vector<double>& inputParameters, cons double distance = std::fabs(energyBinEdge - inputParameters.at(0))/std::fabs(selectedEnergy->first - energyBinEdge); //if we get a random number larger than the distance then choose other energy. - double rand = CLHEP::RandFlat::shoot(m_randomEngine); + double rand = CLHEP::RandFlat::shoot(rndmEngine); if(rand > distance){ selectedEnergy = secondSelectedEnergy; } @@ -159,7 +155,7 @@ double ISF::PDFcreator::getRand(const std::vector<double>& inputParameters, cons //calculate a distance of the input eta to the bin edge double distance = std::fabs(etaBinEdge - inputParameters.at(1))/std::fabs(itSelectedEtaWindow->first.at(0) - itSelectedEtaWindow->first.at(1)); //if we get a random number larger than the distance then choose other energy. - double rand = CLHEP::RandFlat::shoot(m_randomEngine); + double rand = CLHEP::RandFlat::shoot(rndmEngine); if(rand > distance){ itSelectedEtaWindow = itSecondEtaWindow; } @@ -170,15 +166,15 @@ double ISF::PDFcreator::getRand(const std::vector<double>& inputParameters, cons TFCS1DFunction* hist = itSelectedEtaWindow->second; //Draw randomly from the histogram distribution. //if obj is 1D histogram just draw randomly from it - random = hist->rnd_to_fct(CLHEP::RandFlat::shoot(m_randomEngine)); + random = hist->rnd_to_fct(CLHEP::RandFlat::shoot(rndmEngine)); if(randMax != 0.){ while (random < randMin || random > randMax){ - random = hist->rnd_to_fct(CLHEP::RandFlat::shoot(m_randomEngine)); + random = hist->rnd_to_fct(CLHEP::RandFlat::shoot(rndmEngine)); } } else{ while (random < randMin){ - random = hist->rnd_to_fct(CLHEP::RandFlat::shoot(m_randomEngine)); + random = hist->rnd_to_fct(CLHEP::RandFlat::shoot(rndmEngine)); } } @@ -235,7 +231,7 @@ double ISF::PDFcreator::getRand(const std::vector<double>& inputParameters, cons double distance = std::fabs(energyBinEdge - inputParameters.at(0))/std::fabs(selectedEnergy->first - energyBinEdge); //if we get a random number larger than the distance then choose other energy. - double rand = CLHEP::RandFlat::shoot(m_randomEngine); + double rand = CLHEP::RandFlat::shoot(rndmEngine); if(rand > distance){ selectedEnergy = secondSelectedEnergy; } @@ -286,7 +282,7 @@ double ISF::PDFcreator::getRand(const std::vector<double>& inputParameters, cons //calculate a distance of the input eta to the bin edge double distance = std::fabs(etaBinEdge - inputParameters.at(1))/std::fabs(itSelectedEtaWindow->first.at(0) - itSelectedEtaWindow->first.at(1)); //if we get a random number larger than the distance then choose other energy. - double rand = CLHEP::RandFlat::shoot(m_randomEngine); + double rand = CLHEP::RandFlat::shoot(rndmEngine); if(rand > distance){ itSelectedEtaWindow = itSecondEtaWindow; } @@ -315,15 +311,15 @@ double ISF::PDFcreator::getRand(const std::vector<double>& inputParameters, cons TFCS1DFunction* hist = chosenBin->second; //draw random number from chosen hist - random = hist->rnd_to_fct(CLHEP::RandFlat::shoot(m_randomEngine)); + random = hist->rnd_to_fct(CLHEP::RandFlat::shoot(rndmEngine)); if(randMax != 0.){ while (random < randMin || random > randMax){ - random = hist->rnd_to_fct(CLHEP::RandFlat::shoot(m_randomEngine)); + random = hist->rnd_to_fct(CLHEP::RandFlat::shoot(rndmEngine)); } } else{ while (random < randMin){ - random = hist->rnd_to_fct(CLHEP::RandFlat::shoot(m_randomEngine)); + random = hist->rnd_to_fct(CLHEP::RandFlat::shoot(rndmEngine)); } } diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PDFcreator.h b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PDFcreator.h index cc13b3caba3ba77f92e492eaf23354c7898f7e1e..b7707131d2ebc7c3c9ba56aa85c60bf5cecd0d13 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PDFcreator.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PDFcreator.h @@ -5,18 +5,17 @@ #ifndef ISF_PUNCHTHROUGHTOOLS_SRC_PDFCREATOR_H #define ISF_PUNCHTHROUGHTOOLS_SRC_PDFCREATOR_H -// Athena Base -#include "AthenaKernel/IAtRndmGenSvc.h" - // ROOT includes #include "TH1F.h" #include "TH2F.h" +#include <map> //ISF includes #include "ISF_FastCaloSimEvent/TFCS1DFunction.h" - - +namespace CLHEP { + class HepRandomEngine; +} namespace ISF { @@ -34,17 +33,17 @@ namespace ISF public: /** construct the class with a given TF1 and a random engine */ - PDFcreator(CLHEP::HepRandomEngine *engine):m_randomEngine(engine) {} ; + PDFcreator() {} ; ~PDFcreator() { }; /** all following is used to set up the class */ - void setName( std::string PDFname ){ m_name = PDFname; }; //get the pdf's name + void setName( std::string PDFname ) { m_name = PDFname; }; // set the pdf's name void addToEnergyEtaRangeHist1DMap(double energy, std::vector<double> etaMinEtaMax, TFCS1DFunction *hist); //add entry to map linking energy, eta window and histogram void addToEnergyEtaRangeHist2DMap(double energy, std::vector<double> etaMinEtaMax, std::map< double , TFCS1DFunction* > *hist); //add entry to map linking energy, eta window and histogram /** get the random value with this method, by providing the input parameters */ - double getRand( const std::vector<double>& inputPar, const double& outEnergy = 0., const double& randMin = 0., const double& randMax = 0.) const; + double getRand(CLHEP::HepRandomEngine* rndmEngine, const std::vector<double>& inputPar, const double& outEnergy = 0., const double& randMin = 0., const double& randMax = 0.) const; std::string getName() const {return m_name;}; static bool compareEnergy1D(const std::pair< double , std::map< std::vector<double>, TFCS1DFunction*> > map, const double value){ return map.first < value; }; static bool compareEnergy2D(const std::pair< double , std::map< std::vector<double>, std::map< double , TFCS1DFunction* >* > > map, const double value){ return map.first < value; }; @@ -52,7 +51,6 @@ namespace ISF static bool compareEtaMax2D(const std::pair< std::vector<double>, std::map< double , TFCS1DFunction* >* > map, const double value){ return map.first.at(1) < value; }; private: - CLHEP::HepRandomEngine *m_randomEngine; //!< Random Engine std::string m_name; //!< Give pdf a name for debug purposes std::map< double , std::map< std::vector<double>, TFCS1DFunction*> > m_energy_etaRange_hists1D; //!< map of energies to map of eta ranges to 1D histograms std::map< double , std::map< std::vector<double>, std::map< double , TFCS1DFunction* >* > > m_energy_etaRange_hists2D; //!< map of energies to map of eta ranges to 2D histograms diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.cxx index 867756841295ce8508d6b05e5346753bf380d744..7ebd77cb107c46de5e72cba953c8904c0a3b9239 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.cxx @@ -1,11 +1,7 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ -/////////////////////////////////////////////////////////////////// -// PunchThroughTool.cxx, (c) ATLAS Detector software -/////////////////////////////////////////////////////////////////// - // class header #include "PunchThroughTool.h" @@ -22,9 +18,6 @@ // Control #include "AthContainers/DataVector.h" -// Gaudi & StoreGate -#include "GaudiKernel/IPartPropSvc.h" - // HepMC #include "AtlasHepMC/SimpleVector.h" #include "AtlasHepMC/GenVertex.h" @@ -52,17 +45,8 @@ #include "ISF_Event/ISFParticle.h" #include "PDFcreator.h" #include "PunchThroughParticle.h" -#include "ISF_Interfaces/IGeoIDSvc.h" #include "ISF_FastCaloSimEvent/TFCS1DFunctionInt32Histogram.h" - - -//Barcode -#include "BarcodeInterfaces/IBarcodeSvc.h" - -//Geometry -#include "SubDetectorEnvelopes/IEnvelopeDefSvc.h" - //Amg #include "GeoPrimitives/GeoPrimitivesHelpers.h" @@ -75,7 +59,6 @@ ISF::PunchThroughTool::PunchThroughTool( const std::string& type, const std::string& name, const IInterface* parent ) : base_class(type, name, parent), - m_randomSvc("AtDSFMTGenSvc", name), m_pdgInitiators(), m_initiatorsMinEnergy(), m_initiatorsEtaRange(), @@ -112,21 +95,11 @@ ISF::PunchThroughTool::PunchThroughTool( const std::string& type, declareProperty( "MaxNumParticles", m_maxNumParticles ); declareProperty( "NumParticlesFactor", m_numParticlesFactor ); declareProperty( "EnergyFactor", m_energyFactor ); - declareProperty( "RandomNumberService", m_randomSvc, "Random number generator" ); - declareProperty( "RandomStreamName", m_randomEngineName, "Name of the random number stream"); declareProperty( "BarcodeSvc", m_barcodeSvc ); declareProperty( "EnvelopeDefSvc", m_envDefSvc ); declareProperty( "BeamPipeRadius", m_beamPipe ); } -/*========================================================================= - * DESCRIPTION OF FUNCTION: - * ==> see headerfile - *=======================================================================*/ - -ISF::PunchThroughTool::~PunchThroughTool() -{} - /*========================================================================= * DESCRIPTION OF FUNCTION: * ==> see headerfile @@ -138,60 +111,35 @@ StatusCode ISF::PunchThroughTool::initialize() // resolving lookuptable file std::string resolvedFileName = PathResolverFindCalibFile (m_filenameLookupTable); - if (resolvedFileName != "") - { - ATH_MSG_INFO( "[ punchthrough ] Parameterisation file found: " << resolvedFileName ); - } - else - { - ATH_MSG_ERROR( "[ punchthrough ] Parameterisation file not found" ); - return StatusCode::FAILURE; - } + if (resolvedFileName == "") { + ATH_MSG_ERROR( "[ punchthrough ] Parameterisation file not found" ); + return StatusCode::FAILURE; + } + ATH_MSG_INFO( "[ punchthrough ] Parameterisation file found: " << resolvedFileName ); // open the LookupTable file m_fileLookupTable = new TFile( resolvedFileName.c_str(), "READ"); - if (!m_fileLookupTable) - { - ATH_MSG_WARNING("[ punchthrough ] unable to open the lookup-tabel for the punch-through simulation (file does not exist)"); - return StatusCode::FAILURE; - } + if (!m_fileLookupTable) { + ATH_MSG_WARNING("[ punchthrough ] unable to open the lookup-tabel for the punch-through simulation (file does not exist)"); + return StatusCode::FAILURE; + } - if (!m_fileLookupTable->IsOpen()) - { - ATH_MSG_WARNING("[ punchthrough ] unable to open the lookup-tabel for the punch-through simulation (wrong or empty file?)"); - return StatusCode::FAILURE; - } + if (!m_fileLookupTable->IsOpen()) { + ATH_MSG_WARNING("[ punchthrough ] unable to open the lookup-tabel for the punch-through simulation (wrong or empty file?)"); + return StatusCode::FAILURE; + } // retrieve the ParticleProperties handle - if ( m_particlePropSvc.retrieve().isFailure() ) - { - ATH_MSG_FATAL( "[ punchthrough ] Can not retrieve " << m_particlePropSvc << " ! Abort. " ); - return StatusCode::FAILURE; - } + ATH_CHECK( m_particlePropSvc.retrieve() ); // and the particle data table m_particleDataTable = m_particlePropSvc->PDT(); - if (m_particleDataTable==0) + if (!m_particleDataTable) { ATH_MSG_FATAL( " [ punchthrough ] Could not get ParticleDataTable! Cannot associate pdg code with charge! Abort. " ); return StatusCode::FAILURE; } - // Random number service - if ( m_randomSvc.retrieve().isFailure() ) - { - ATH_MSG_ERROR( "[ punchthrough ] Could not retrieve " << m_randomSvc ); - return StatusCode::FAILURE; - } - - // Get own engine with own seeds: - m_randomEngine = m_randomSvc->GetEngine(m_randomEngineName); - if (!m_randomEngine) - { - ATH_MSG_ERROR( "[ punchthrough ] Could not get random engine '" << m_randomEngineName << "'" ); - return StatusCode::FAILURE; - } - // Geometry identifier service if ( !m_geoIDSvc.empty() && m_geoIDSvc.retrieve().isFailure()) { @@ -346,7 +294,7 @@ StatusCode ISF::PunchThroughTool::finalize() * ==> see headerfile *=======================================================================*/ -const ISF::ISFParticleVector* ISF::PunchThroughTool::computePunchThroughParticles(const ISF::ISFParticle &isfp) const +const ISF::ISFParticleVector* ISF::PunchThroughTool::computePunchThroughParticles(const ISF::ISFParticle &isfp, CLHEP::HepRandomEngine* rndmEngine) const { ATH_MSG_DEBUG( "[ punchthrough ] starting punch-through simulation"); @@ -462,10 +410,10 @@ const ISF::ISFParticleVector* ISF::PunchThroughTool::computePunchThroughParticle if ( pos == corrPdgNumDone.end() ) { // -> roll a dice if we create this particle or its correlated one - if ( CLHEP::RandFlat::shoot(m_randomEngine) > 0.5 ) doPdg = corrPdg; + if ( CLHEP::RandFlat::shoot(rndmEngine) > 0.5 ) doPdg = corrPdg; // now create the particles with the given pdg and note how many // particles of this pdg are created - corrPdgNumDone[doPdg] = getAllParticles(doPdg); + corrPdgNumDone[doPdg] = getAllParticles(rndmEngine, doPdg); } // one of the two correlated particle types was already simulated @@ -480,7 +428,7 @@ const ISF::ISFParticleVector* ISF::PunchThroughTool::computePunchThroughParticle if (donePdg == doPdg) doPdg = corrPdg; // now create the correlated particles - getCorrelatedParticles(doPdg, doneNumPart); + getCorrelatedParticles(doPdg, doneNumPart, rndmEngine); // note: no need to take note, that this particle type is now simulated, // since this is the second of two correlated particles, which is // simulated and we do not have correlations of more than two particles. @@ -489,7 +437,7 @@ const ISF::ISFParticleVector* ISF::PunchThroughTool::computePunchThroughParticle // if no correlation for this particle // -> directly create all particles with the current pdg } - else getAllParticles(doPdg); + else getAllParticles(rndmEngine, doPdg); } // for-loop over all particle pdgs @@ -510,7 +458,7 @@ const ISF::ISFParticleVector* ISF::PunchThroughTool::computePunchThroughParticle * DESCRIPTION OF FUNCTION: * ==> see headerfile *=======================================================================*/ -int ISF::PunchThroughTool::getAllParticles(int pdg, int numParticles) const +int ISF::PunchThroughTool::getAllParticles(CLHEP::HepRandomEngine* rndmEngine, int pdg, int numParticles) const { // first check if the ISF particle vector already exists if (!m_isfpCont) m_isfpCont = new ISFParticleVector(); @@ -534,7 +482,7 @@ int ISF::PunchThroughTool::getAllParticles(int pdg, int numParticles) const // and ensure that we do not create too many particles do { - numParticles = lround( p->getNumParticlesPDF()->getRand(parameters) ); + numParticles = lround( p->getNumParticlesPDF()->getRand(rndmEngine, parameters) ); // scale the number of particles if requested numParticles = lround( numParticles *= p->getNumParticlesFactor() ); @@ -552,7 +500,7 @@ int ISF::PunchThroughTool::getAllParticles(int pdg, int numParticles) const for ( numCreated = 0; (numCreated < numParticles) && (energyRest > minEnergy); numCreated++ ) { // create one particle which fullfills the right energy distribution - ISF::ISFParticle *par = getOneParticle(pdg, energyRest); + ISF::ISFParticle *par = getOneParticle(pdg, energyRest, rndmEngine); // if something went wrong if (!par) @@ -582,19 +530,19 @@ int ISF::PunchThroughTool::getAllParticles(int pdg, int numParticles) const * ==> see headerfile *=======================================================================*/ -int ISF::PunchThroughTool::getCorrelatedParticles(int pdg, int corrParticles) const +int ISF::PunchThroughTool::getCorrelatedParticles(int pdg, int corrParticles, CLHEP::HepRandomEngine* rndmEngine) const { // get the PunchThroughParticle class PunchThroughParticle *p = m_particles[pdg]; // (1.) decide if we do correlation or not - double rand = CLHEP::RandFlat::shoot(m_randomEngine) + double rand = CLHEP::RandFlat::shoot(rndmEngine) *(p->getFullCorrelationEnergy()-p->getMinCorrelationEnergy()) + p->getMinCorrelationEnergy(); if ( m_initEnergy < rand ) { // here we do not do correlation - return getAllParticles(pdg); + return getAllParticles(rndmEngine, pdg); } // (2.) if this point is reached, we do correlation @@ -611,7 +559,7 @@ int ISF::PunchThroughTool::getCorrelatedParticles(int pdg, int corrParticles) co } else { - double rand = CLHEP::RandFlat::shoot(m_randomEngine)*(histDomains[2]-histDomains[1]) + double rand = CLHEP::RandFlat::shoot(rndmEngine)*(histDomains[2]-histDomains[1]) + histDomains[1]; hist2d = ( m_initEnergy < rand) ? p->getCorrelationLowEHist() : p->getCorrelationHighEHist(); @@ -628,7 +576,7 @@ int ISF::PunchThroughTool::getCorrelatedParticles(int pdg, int corrParticles) co // of 'pdg' particles do { - double rand = CLHEP::RandFlat::shoot(m_randomEngine); + double rand = CLHEP::RandFlat::shoot(rndmEngine); double sum = 0.; for ( int ybin = 1; ybin <= hist2d->GetNbinsY(); ybin++ ) { @@ -646,7 +594,7 @@ int ISF::PunchThroughTool::getCorrelatedParticles(int pdg, int corrParticles) co while ( (maxParticles >= 0.) && (numParticles > maxParticles) ); // finally create this exact number of particles - return getAllParticles(pdg, numParticles); + return getAllParticles(rndmEngine, pdg, numParticles); } /*========================================================================= @@ -654,7 +602,7 @@ int ISF::PunchThroughTool::getCorrelatedParticles(int pdg, int corrParticles) co * ==> see headerfile *=======================================================================*/ -ISF::ISFParticle *ISF::PunchThroughTool::getOneParticle(int pdg, double maxEnergy) const +ISF::ISFParticle *ISF::PunchThroughTool::getOneParticle(int pdg, double maxEnergy, CLHEP::HepRandomEngine* rndmEngine) const { // get a local copy of the needed punch-through particle class PunchThroughParticle *p = m_particles[pdg]; @@ -664,7 +612,7 @@ ISF::ISFParticle *ISF::PunchThroughTool::getOneParticle(int pdg, double maxEnerg if ( p->getdoAnti() ) { // get a random-value - double rand = CLHEP::RandFlat::shoot(m_randomEngine); + double rand = CLHEP::RandFlat::shoot(rndmEngine); // 50/50 chance to be a particle or its anti-particle if (rand > 0.5) anti = -1; } @@ -676,7 +624,7 @@ ISF::ISFParticle *ISF::PunchThroughTool::getOneParticle(int pdg, double maxEnerg parInitEnergyEta.push_back( std::fabs(m_initEta) ); // (2.1) get the energy - double energy = p->getExitEnergyPDF()->getRand( + double energy = p->getExitEnergyPDF()->getRand( rndmEngine, parInitEnergyEta, 0., p->getMinEnergy(), maxEnergy/p->getEnergyFactor() ); energy *= p->getEnergyFactor(); // scale the energy if requested @@ -686,10 +634,10 @@ ISF::ISFParticle *ISF::PunchThroughTool::getOneParticle(int pdg, double maxEnerg do { // get random value - double deltaTheta = p->getExitDeltaThetaPDF()->getRand( + double deltaTheta = p->getExitDeltaThetaPDF()->getRand( rndmEngine, parInitEnergyEta, energy); // decide if delta positive/negative - deltaTheta *= ( CLHEP::RandFlat::shoot(m_randomEngine) > 0.5 ) ? 1. : -1.; + deltaTheta *= ( CLHEP::RandFlat::shoot(rndmEngine) > 0.5 ) ? 1. : -1.; // calculate the exact theta value of the later created // punch-through particle theta = m_initTheta + deltaTheta*p->getPosAngleFactor(); @@ -698,9 +646,9 @@ ISF::ISFParticle *ISF::PunchThroughTool::getOneParticle(int pdg, double maxEnerg while ( (theta > M_PI) || (theta < 0.) ); // (2.3) get the particle's delta phi relative to the incoming particle - double deltaPhi = p->getExitDeltaPhiPDF()->getRand( + double deltaPhi = p->getExitDeltaPhiPDF()->getRand( rndmEngine, parInitEnergyEta, energy); - deltaPhi *= ( CLHEP::RandFlat::shoot(m_randomEngine) > 0.5 ) ? 1. : -1.; + deltaPhi *= ( CLHEP::RandFlat::shoot(rndmEngine) > 0.5 ) ? 1. : -1.; // keep phi within range [-PI,PI] double phi = m_initPhi + deltaPhi*p->getPosAngleFactor(); @@ -716,10 +664,10 @@ ISF::ISFParticle *ISF::PunchThroughTool::getOneParticle(int pdg, double maxEnerg do { // get random value - double momDeltaTheta = p->getMomDeltaThetaPDF()->getRand( + double momDeltaTheta = p->getMomDeltaThetaPDF()->getRand( rndmEngine, parInitEnergyEta, energy); // decide if delta positive/negative - momDeltaTheta *= ( CLHEP::RandFlat::shoot(m_randomEngine) > 0.5 ) ? 1. : -1.; + momDeltaTheta *= ( CLHEP::RandFlat::shoot(rndmEngine) > 0.5 ) ? 1. : -1.; // calculate the exact momentum theta value of the later created // punch-through particle momTheta = theta + momDeltaTheta*p->getMomAngleFactor(); @@ -729,9 +677,9 @@ ISF::ISFParticle *ISF::PunchThroughTool::getOneParticle(int pdg, double maxEnerg // (2.5) get the particle momentum delta phi, relative to its position - double momDeltaPhi = p->getMomDeltaPhiPDF()->getRand( + double momDeltaPhi = p->getMomDeltaPhiPDF()->getRand( rndmEngine, parInitEnergyEta, energy); - momDeltaPhi *= ( CLHEP::RandFlat::shoot(m_randomEngine) > 0.5 ) ? 1. : -1.; + momDeltaPhi *= ( CLHEP::RandFlat::shoot(rndmEngine) > 0.5 ) ? 1. : -1.; double momPhi = phi + momDeltaPhi*p->getMomAngleFactor(); // keep momPhi within range [-PI,PI] @@ -897,8 +845,8 @@ std::unique_ptr<ISF::PDFcreator> ISF::PunchThroughTool::readLookuptablePDF(int p // will hold the PDFcreator class which will be returned at the end // this will store the distributions for the punch through particles // (as map of energy & eta of the incoming particle) - //PDFcreator *pdf = new PDFcreator(m_randomEngine); - std::unique_ptr<ISF::PDFcreator> pdf = std::make_unique<ISF::PDFcreator>(m_randomEngine); + + std::unique_ptr<ISF::PDFcreator> pdf = std::make_unique<ISF::PDFcreator>(); //Get directory object std::stringstream dirName; diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.h b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.h index 5754a1f5e0277b9caf6963c3f0572211c22b579c..2aac4123749ddd6c063142f6cf1721fff6e1d21b 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_PunchThroughTools/src/PunchThroughTool.h @@ -11,6 +11,17 @@ // Athena Base #include "AthenaBaseComps/AthAlgTool.h" +//Barcode +#include "BarcodeInterfaces/IBarcodeSvc.h" + +//Geometry +#include "SubDetectorEnvelopes/IEnvelopeDefSvc.h" + +#include "ISF_Interfaces/IGeoIDSvc.h" + +// Gaudi & StoreGate +#include "GaudiKernel/IPartPropSvc.h" + #include "BarcodeEvent/Barcode.h" #include "BarcodeEvent/PhysicsProcessCode.h" #include "GeoPrimitives/GeoPrimitives.h" @@ -23,28 +34,15 @@ * Forward declarations *-------------------------------------------------------------------------*/ -class IPartPropSvc; -class IAtRndmGenSvc; class TFile; -class IEnvelopeDefSvc; - -namespace CLHEP { - class HepRandomEngine; -} namespace HepPDT { class ParticleDataTable; } -namespace Barcode { - class IBarcodeSvc; -} - namespace ISF { - class PunchThroughParticle; class PDFcreator; - class IGeoIDSvc; } namespace ISF { @@ -56,14 +54,14 @@ namespace ISF { PunchThroughTool(const std::string&,const std::string&,const IInterface*); /** Destructor */ - virtual ~PunchThroughTool (); + virtual ~PunchThroughTool () = default; /** AlgTool initialize method */ virtual StatusCode initialize(); /** AlgTool finalize method */ virtual StatusCode finalize (); /** interface function: fill a vector with the punch-through particles */ - const ISF::ISFParticleVector* computePunchThroughParticles(const ISF::ISFParticle &isfp) const; + const ISF::ISFParticleVector* computePunchThroughParticles(const ISF::ISFParticle &isfp, CLHEP::HepRandomEngine* rndmEngine) const; private: /*--------------------------------------------------------------------- @@ -87,15 +85,15 @@ namespace ISF { * particles with the right distributions (energy, theta, phi). * if a second argument is given, create exactly this number of particles * (also with the right energy,theta,phi distributions */ - int getAllParticles(int pdg, int numParticles = -1) const; + int getAllParticles(CLHEP::HepRandomEngine* rndmEngine, int pdg, int numParticles = -1) const; /** get the right number of particles for the given pdg while considering * the correlation to an other particle type, which has already created * 'corrParticles' number of particles */ - int getCorrelatedParticles(int doPdg, int corrParticles ) const; + int getCorrelatedParticles(int doPdg, int corrParticles, CLHEP::HepRandomEngine* rndmEngine) const; /** create exactly one punch-through particle with the given pdg and the given max energy */ - ISF::ISFParticle *getOneParticle(int pdg, double maxEnergy) const; + ISF::ISFParticle *getOneParticle(int pdg, double maxEnergy, CLHEP::HepRandomEngine* rndmEngine) const; /** create a ISF Particle state at the MS entrace containing a particle with the given properties */ ISF::ISFParticle *createExitPs(int PDGcode, double energy, double theta, double phi, double momTheta, double momPhi) const; @@ -131,13 +129,9 @@ namespace ISF { /** ParticleDataTable needed to get connection pdg_code <-> charge */ const HepPDT::ParticleDataTable* m_particleDataTable{nullptr}; - /** random generator service */ - ServiceHandle<IAtRndmGenSvc> m_randomSvc; //!< Random Svc - std::string m_randomEngineName{"ISFRnd"}; //!< Name of the random number stream - CLHEP::HepRandomEngine* m_randomEngine{nullptr}; //!< Random Engine - /** ROOT objects */ TFile* m_fileLookupTable{nullptr}; //!< the punch-through lookup table file + /** general information of the punch-through particles which will be created */ mutable std::map<int, bool> m_doAntiParticleMap; /*!< stores information, if anti-particles are created for any given PDG id */ diff --git a/Simulation/ISF/ISF_Fatras/ISF_FatrasServices/src/FatrasSimTool.h b/Simulation/ISF/ISF_Fatras/ISF_FatrasServices/src/FatrasSimTool.h index d35b7fcd9bfc6f7f7e6c39229f67c638e70d4b2b..db97e3e2873920ae3f0d68c14d38384e1443b864 100644 --- a/Simulation/ISF/ISF_Fatras/ISF_FatrasServices/src/FatrasSimTool.h +++ b/Simulation/ISF/ISF_Fatras/ISF_FatrasServices/src/FatrasSimTool.h @@ -28,9 +28,9 @@ namespace ISF { virtual StatusCode simulate( const ISFParticle& isp, ISFParticleContainer&, McEventCollection* ) const override; - virtual StatusCode setupEvent() override { return StatusCode::SUCCESS; }; + virtual StatusCode setupEvent(const EventContext&) override { return StatusCode::SUCCESS; }; - virtual StatusCode releaseEvent() override { return StatusCode::SUCCESS; }; + virtual StatusCode releaseEvent(const EventContext&) override { return StatusCode::SUCCESS; }; virtual ISF::SimulationFlavor simFlavor() const override { return ISF::Fatras; }; diff --git a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/G4LegacyTransportTool.cxx b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/G4LegacyTransportTool.cxx index 2333b936f16c40521bff16315896d2da84210e22..8eeef22d61be5dc83e53780a7bd2619be4ec45f9 100644 --- a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/G4LegacyTransportTool.cxx +++ b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/G4LegacyTransportTool.cxx @@ -307,15 +307,15 @@ StatusCode iGeant4::G4LegacyTransportTool::simulateVector( const ISF::ConstISFPa } //________________________________________________________________________ -StatusCode iGeant4::G4LegacyTransportTool::setupEvent() +StatusCode iGeant4::G4LegacyTransportTool::setupEvent(const EventContext& ctx) { 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, m_randomStreamName); - rngWrapper->setSeed( m_randomStreamName, Gaudi::Hive::currentContext() ); - G4Random::setTheEngine(*rngWrapper); + rngWrapper->setSeed( m_randomStreamName, ctx ); + G4Random::setTheEngine(rngWrapper->getEngine(ctx)); ATH_CHECK(m_senDetTool->BeginOfAthenaEvent()); @@ -329,7 +329,7 @@ StatusCode iGeant4::G4LegacyTransportTool::setupEvent() } //________________________________________________________________________ -StatusCode iGeant4::G4LegacyTransportTool::releaseEvent() +StatusCode iGeant4::G4LegacyTransportTool::releaseEvent(const EventContext&) { ATH_MSG_DEBUG ( "release Event" ); /** @todo : strip hits of the tracks ... */ diff --git a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/G4LegacyTransportTool.h b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/G4LegacyTransportTool.h index bcd3769187bf53a477a92a6e9b156b895f01c859..4c313d5009e6ff1f96c2f5e8907b0a48dcdce31f 100644 --- a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/G4LegacyTransportTool.h +++ b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/G4LegacyTransportTool.h @@ -81,9 +81,9 @@ namespace iGeant4 virtual StatusCode simulateVector( const ISF::ConstISFParticleVector& particles, ISF::ISFParticleContainer& secondaries, McEventCollection* mcEventCollection ) const override; - virtual StatusCode setupEvent() override; + virtual StatusCode setupEvent(const EventContext&) override; - virtual StatusCode releaseEvent() override; + virtual StatusCode releaseEvent(const EventContext&) override; virtual ISF::SimulationFlavor simFlavor() const override { return ISF::Geant4; }; diff --git a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx index b986098758aa77d73c5cfb6944658a88997c9e0a..fb28db9d30faf071df7c019f1955a91ebfcb9ef3 100644 --- a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx +++ b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx @@ -356,7 +356,7 @@ StatusCode iGeant4::G4TransportTool::simulateVector( const ISF::ConstISFParticle } //________________________________________________________________________ -StatusCode iGeant4::G4TransportTool::setupEvent() +StatusCode iGeant4::G4TransportTool::setupEvent(const EventContext& ctx) { ATH_MSG_DEBUG ( "setup Event" ); @@ -377,8 +377,8 @@ StatusCode iGeant4::G4TransportTool::setupEvent() // 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, m_randomStreamName); - rngWrapper->setSeed( m_randomStreamName, Gaudi::Hive::currentContext() ); - G4Random::setTheEngine(*rngWrapper); + rngWrapper->setSeed( m_randomStreamName, ctx ); + G4Random::setTheEngine(rngWrapper->getEngine(ctx)); ATH_CHECK(m_senDetTool->BeginOfAthenaEvent()); @@ -392,7 +392,7 @@ StatusCode iGeant4::G4TransportTool::setupEvent() } //________________________________________________________________________ -StatusCode iGeant4::G4TransportTool::releaseEvent() +StatusCode iGeant4::G4TransportTool::releaseEvent(const EventContext&) { ATH_MSG_DEBUG ( "release Event" ); /** @todo : strip hits of the tracks ... */ diff --git a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h index 467885919856bb117935a14e9fee8b28d30ca5a4..4baa978ea717fa67e583f0af68c2da622baa815a 100644 --- a/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h +++ b/Simulation/ISF/ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h @@ -86,9 +86,9 @@ namespace iGeant4 virtual StatusCode simulateVector( const ISF::ConstISFParticleVector& particles, ISF::ISFParticleContainer& secondaries, McEventCollection* mcEventCollection ) const override; - virtual StatusCode setupEvent() override; + virtual StatusCode setupEvent(const EventContext&) override; - virtual StatusCode releaseEvent() override; + virtual StatusCode releaseEvent(const EventContext&) override; virtual ISF::SimulationFlavor simFlavor() const override { return ISF::Geant4; };