diff --git a/Simulation/FastShower/FastCaloSim/FastCaloSim/FastShowerCellBuilderTool.h b/Simulation/FastShower/FastCaloSim/FastCaloSim/FastShowerCellBuilderTool.h index 46889d41f6130d4a34e4d60e8b0ce4080cfb5444..d0219ddee68bedd3c464538e702bdc27381174e5 100755 --- a/Simulation/FastShower/FastCaloSim/FastCaloSim/FastShowerCellBuilderTool.h +++ b/Simulation/FastShower/FastCaloSim/FastCaloSim/FastShowerCellBuilderTool.h @@ -99,13 +99,15 @@ public: // update theCellContainer virtual StatusCode process(CaloCellContainer* theCellContainer) override final; - StatusCode setupEvent(); + StatusCode setupEvent (const EventContext& ctx, + TRandom3& rndm) const; StatusCode releaseEvent (Stats& stats) const; // the actual simulation code for one particle can run standalone without process(CaloCellContainer* theCellContainer), // but setupEvent() should be called before the first particle and releaseEvent() after the last particle StatusCode process_particle(CaloCellContainer* theCellContainer, std::vector<Trk::HitInfo>* hitVector, Amg::Vector3D initMom, double mass, int pdgId, int barcode, FastShowerInfoContainer* fastShowerInfoContainer, + TRandom3& rndm, Stats& stats, const EventContext& ctx) const; @@ -172,8 +174,6 @@ private: HepPDT::ParticleDataTable* m_particleDataTable{}; - TRandom* m_rndm{}; - std::vector< int > m_invisibles; // TGraphErrors* geometry[CaloCell_ID_FCS::MaxSample][3]; diff --git a/Simulation/FastShower/FastCaloSim/src/FastShowerCellBuilderTool.cxx b/Simulation/FastShower/FastCaloSim/src/FastShowerCellBuilderTool.cxx index 99d0a9b128a9f5ee28cbd49c43b4a542b46af184..a6f9d6b9db12494fb53055c9920aef942d2360cc 100755 --- a/Simulation/FastShower/FastCaloSim/src/FastShowerCellBuilderTool.cxx +++ b/Simulation/FastShower/FastCaloSim/src/FastShowerCellBuilderTool.cxx @@ -131,7 +131,6 @@ FastShowerCellBuilderTool::FastShowerCellBuilderTool(const std::string& type, co }; m_n_surfacelist=n_surfacelist; for(int i=0;i<n_surfacelist;++i) m_surfacelist[i]=surfacelist[i]; - m_rndm=new TRandom3(); declareProperty("ParticleParametrizationFileName",m_ParticleParametrizationFileName); declareProperty("AdditionalParticleParametrizationFileNames",m_AdditionalParticleParametrizationFileNames); @@ -1175,6 +1174,7 @@ FastShowerCellBuilderTool::process_particle(CaloCellContainer* theCellContainer, int pdgid, int barcode, FastShowerInfoContainer* fastShowerInfoContainer, + TRandom3& rndm, Stats& stats, const EventContext& /*ctx*/) const { @@ -1424,7 +1424,7 @@ FastShowerCellBuilderTool::process_particle(CaloCellContainer* theCellContainer, if(Epara) { Epara_E = Epara->E(); ATH_MSG_DEBUG("take : "<< Epara->GetTitle()); - Epara->DiceParticle(p,*m_rndm); + Epara->DiceParticle(p,rndm); if(m_storeFastShowerInfo) Epara->CopyDebugInfo(fastshowerinfo); // old version: fastshowerinfo->SetParticleEnergyParam( *Epara ); @@ -2294,7 +2294,8 @@ StatusCode FastShowerCellBuilderTool::process(CaloCellContainer* theCellContaine ATH_MSG_DEBUG("Executing start calo size=" <<theCellContainer->size()<<" Event="<<ctx.evt()); - if(setupEvent().isFailure() ) { + TRandom3 rndm; + if(setupEvent(ctx, rndm).isFailure() ) { ATH_MSG_ERROR("setupEvent() failed"); return StatusCode::FAILURE; } @@ -2494,6 +2495,7 @@ StatusCode FastShowerCellBuilderTool::process(CaloCellContainer* theCellContaine (*part)->pdg_id(), (*part)->barcode(), fastShowerInfoContainer.get(), + rndm, stats, ctx)) { @@ -2551,7 +2553,8 @@ StatusCode FastShowerCellBuilderTool::process(CaloCellContainer* theCellContaine return StatusCode::SUCCESS; } -StatusCode FastShowerCellBuilderTool::setupEvent() +StatusCode FastShowerCellBuilderTool::setupEvent (const EventContext& /*ctx*/, + TRandom3& rndm) const { m_rndmSvc->print(m_randomEngineName); unsigned int rseed=0; @@ -2559,10 +2562,10 @@ StatusCode FastShowerCellBuilderTool::setupEvent() rseed=(unsigned int)( CLHEP::RandFlat::shoot(m_randomEngine) * std::numeric_limits<unsigned int>::max() ); } gRandom->SetSeed(rseed); - m_rndm->SetSeed(rseed); + rndm.SetSeed(rseed); //if(gRandom) log<<" seed(gRandom="<<gRandom->ClassName()<<")="<<gRandom->GetSeed(); - //if(m_rndm) log<<" seed(m_rndm="<<m_rndm->ClassName()<<")="<<m_rndm->GetSeed(); + // log<<" seed(rndm="<<rndm.ClassName()<<")="<<rndm.GetSeed(); //log<< endmsg; return StatusCode::SUCCESS; diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimSvcPU.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimSvcPU.cxx index cf1caaf002e2e70cf2179c602a4e37e72d185236..81bd1de5382cab6da5c3fb59fd0e38b303142e5f 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimSvcPU.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimSvcPU.cxx @@ -296,11 +296,14 @@ StatusCode ISF::FastCaloSimSvcPU::setupEvent() FastShowerCellBuilderTool* fcs=dynamic_cast< FastShowerCellBuilderTool* >(&(*(*itrTool))); if(fcs) { - if(fcs->setupEvent().isFailure()) + const EventContext& ctx = Gaudi::Hive::currentContext(); + if(fcs->setupEvent(ctx, m_rndm).isFailure()) { ATH_MSG_ERROR( m_screenOutputPrefix << "Error executing tool " << itrTool->name() << " in setupEvent"); return StatusCode::FAILURE; - } + } + // Don't need to seed m_rndm more than once. + break; } } @@ -583,7 +586,7 @@ StatusCode ISF::FastCaloSimSvcPU::processOneParticle( const ISF::ISFParticle& is //->PU Development: ATH_MSG_INFO(m_screenOutputPrefix<<" now call fcs->process_particle with [bcid-1]="<<bcid-1<<" for pdgid "<<isfp.pdgCode()); - if(fcs->process_particle(m_puCellContainer[bcid-1],hitVector,isfp.momentum(),isfp.mass(),isfp.pdgCode(),isfp.barcode(), nullptr, stats, ctx).isFailure()) + if(fcs->process_particle(m_puCellContainer[bcid-1],hitVector,isfp.momentum(),isfp.mass(),isfp.pdgCode(),isfp.barcode(), nullptr, m_rndm, stats, ctx).isFailure()) { ATH_MSG_WARNING( m_screenOutputPrefix << "simulation of particle pdgid=" << isfp.pdgCode()<< " in bcid "<<bcid<<" failed" ); return StatusCode::FAILURE; diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimSvcPU.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimSvcPU.h index 4fde7943b03abdcc68f6c74d2e1ff61f4ad3092e..4daad381356331bb39163e622295e34bb6651511 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimSvcPU.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloSimSvcPU.h @@ -1,5 +1,5 @@ /* - 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_FASTCALOSIMSVCPU_H @@ -26,6 +26,8 @@ #include "AtlasDetDescr/AtlasDetectorID.h" #include "CaloIdentifier/LArEM_ID.h" +#include "TRandom3.h" + // forward declarations class ITrackingGeometrySvc; class CaloCellContainer; @@ -126,6 +128,7 @@ namespace ISF std::vector<float> m_puEnergyWeights_tile; //<- + TRandom3 m_rndm; }; } diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.cxx b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.cxx index f6b3fbf2f0494c3f7c86860f45f3e2640c8b14de..dc013b1a49a08cb3c43b7e6bd21abaaba9cedda4 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.cxx +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.cxx @@ -186,10 +186,13 @@ StatusCode ISF::FastCaloTool::commonSetup() for ( auto tool : m_caloCellMakerTools_simulate) { FastShowerCellBuilderTool* fcs=dynamic_cast< FastShowerCellBuilderTool* >(&(*tool)); if(fcs) { - if(fcs->setupEvent().isFailure()) { + const EventContext& ctx = Gaudi::Hive::currentContext(); + if(fcs->setupEvent(ctx, m_rndm).isFailure()) { ATH_MSG_ERROR( "Error executing tool " << tool->name() << " in setupEvent"); return StatusCode::FAILURE; } + // Don't need to seed m_rndm more than once. + break; } } @@ -269,7 +272,7 @@ StatusCode ISF::FastCaloTool::processOneParticle( const ISF::ISFParticle& isfp) //sc = tool->process(m_theContainer); if(fcs->process_particle(m_theContainer,hitVector, isfp.momentum(),isfp.mass(),isfp.pdgCode(),isfp.barcode(), - nullptr, stats, ctx).isFailure()) { + nullptr, m_rndm, stats, ctx).isFailure()) { ATH_MSG_WARNING( "simulation of particle pdgid=" << isfp.pdgCode()<< " failed" ); return StatusCode::FAILURE; } diff --git a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.h b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.h index 749dc4c5a7cc0ce6fc4c7cb438056e69099a6e52..91f4f3a638c8c48353734be933c7024b24dfe3a2 100644 --- a/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.h +++ b/Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimServices/src/FastCaloTool.h @@ -1,7 +1,7 @@ // -*- c++ -*- /* - 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_FASTCALOTOOL_h @@ -29,6 +29,8 @@ #include "TrkExInterfaces/ITimedExtrapolator.h" #include "TrkEventPrimitives/PdgToParticleHypothesis.h" +#include "TRandom3.h" + // forward declarations class ITrackingGeometrySvc; class CaloCellContainer; @@ -105,6 +107,7 @@ private: SG::WriteHandleKey< CaloCellContainer > m_caloCellKey{ this, "CaloCells", "DefaultCaloCellContainer", "The name of the output CaloCellContainer" }; + TRandom3 m_rndm; }; }