diff --git a/ForwardDetectors/AFP/AFP_Digitization/AFP_Digitization/AFP_PileUpTool.h b/ForwardDetectors/AFP/AFP_Digitization/AFP_Digitization/AFP_PileUpTool.h index f4e3584436b103af5a6b1ddbd871816b574f481f..68668d9580163dedef9c2bd020437cf618e43ec5 100644 --- a/ForwardDetectors/AFP/AFP_Digitization/AFP_Digitization/AFP_PileUpTool.h +++ b/ForwardDetectors/AFP/AFP_Digitization/AFP_Digitization/AFP_PileUpTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef AFP_DIGITIZATION_TOOL_H @@ -13,7 +13,7 @@ #include "Gaudi/Property.h" #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/ITHistSvc.h" -#include "AthenaKernel/IAtRndmGenSvc.h" +#include "AthenaKernel/IAthRNGSvc.h" #include "AFP_SimEv/AFP_TDSimHitCollection.h" #include "AFP_SimEv/AFP_SIDSimHitCollection.h" #include "HitManagement/TimedHitCollection.h" @@ -32,15 +32,13 @@ #include <vector> #include <utility> /* pair */ -class IAtRndmGenSvc; -// class PileUpMergeSvc; - -static const InterfaceID IID_IAFP_PileUpTool ("AFP_PileUpTool",1,0); //Temporary for back-compatibility with 17.3.X.Y +namespace CLHEP { + class HepRandomEngine; +} class AFP_PileUpTool: public PileUpToolBase { public: - static const InterfaceID& interfaceID(); //Temporary for back-compatibility with 17.3.X.Y AFP_PileUpTool(const std::string& type, const std::string& name, const IInterface* parent); @@ -88,9 +86,9 @@ class AFP_PileUpTool: public PileUpToolBase { double SignalFun(double Time, double RiseTime, double FallTime); // double SiSignalFun(double Time, double RiseTime, double FallTime); - ServiceHandle<PileUpMergeSvc> m_mergeSvc; - ServiceHandle<IAtRndmGenSvc> m_atRndmGenSvc; - CLHEP::HepRandomEngine *m_rndEngine; + ServiceHandle<PileUpMergeSvc> m_mergeSvc{this, "mergeSvc", "PileUpMergeSvc", ""}; + ServiceHandle<IAthRNGSvc> m_randomSvc{this, "RndmSvc", "AthRNGSvc", ""}; + Gaudi::Property<std::string> m_randomStreamName{this, "RandomStreamName", "AFPRndEng", ""}; std::string m_TDSimHitCollectionName; std::string m_TDDigiCollectionName; @@ -123,9 +121,4 @@ class AFP_PileUpTool: public PileUpToolBase { }; -inline const InterfaceID& AFP_PileUpTool::interfaceID() //Temporary for back-compatibility with 17.3.X.Y -{ //Temporary for back-compatibility with 17.3.X.Y - return IID_IAFP_PileUpTool; //Temporary for back-compatibility with 17.3.X.Y -} //Temporary for back-compatibility with 17.3.X.Y - #endif diff --git a/ForwardDetectors/AFP/AFP_Digitization/src/AFP_PileUpTool.cxx b/ForwardDetectors/AFP/AFP_Digitization/src/AFP_PileUpTool.cxx index a96f9826539f3006b83f6b82517607ae97a165d3..a4322642572a0a39da99e8e5bb60f4ddfdc2b2b9 100644 --- a/ForwardDetectors/AFP/AFP_Digitization/src/AFP_PileUpTool.cxx +++ b/ForwardDetectors/AFP/AFP_Digitization/src/AFP_PileUpTool.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ @@ -12,6 +12,8 @@ #include "Identifier/Identifier.h" #include "AthenaBaseComps/AthMsgStreamMacros.h" #include <map> +#include "AthenaKernel/RNGWrapper.h" +#include "CLHEP/Random/RandomEngine.h" #include "CLHEP/Random/RandFlat.h" #include "CLHEP/Random/RandGaussQ.h" #include "CLHEP/Random/RandPoissonQ.h" @@ -20,9 +22,6 @@ AFP_PileUpTool::AFP_PileUpTool(const std::string& type, const std::string& name, const IInterface* parent) : PileUpToolBase(type, name, parent), - m_mergeSvc ("PileUpMergeSvc", name), - m_atRndmGenSvc("AtRndmGenSvc", name), - m_rndEngine(0), m_CollectionEff(0.6), // Collection efficincy m_ConversionSpr(40.0), // Photon-Electron conversion spread in ps m_Gain(50000.), // Gain @@ -30,9 +29,6 @@ AFP_PileUpTool::AFP_PileUpTool(const std::string& type, m_FallTime(1200.), // Pulse fall time in ps m_CfdThr(0.5) // Constant fraction threshold { - declareInterface<AFP_PileUpTool>(this); //Temporary for back-compatibility with 17.3.X.Y - //declareInterface<IPileUpTool>(this); //Temporary for back-compatibility with 17.3.X.Y - // NOTE: The following variables are actually re-initialized by AFP_DigiTop::initialize() or AFP_PileUpTool::initialize() // Quantum efficincy of PMT in 100 nm steps int(WeaveLength-100)/100 @@ -68,8 +64,6 @@ AFP_PileUpTool::AFP_PileUpTool(const std::string& type, declareProperty("SiDigiCollectionName", m_SiDigiCollectionName, "Name of the Collection to hold the output from the AFP digitization, SiD part"); - declareProperty("RndmSvc", m_atRndmGenSvc, "Random Number Service used in AFP digitization" ); - declareProperty("mergeSvc", m_mergeSvc, "Store to hold the pile-ups"); declareProperty("CollectionEff", m_CollectionEff); @@ -116,13 +110,11 @@ StatusCode AFP_PileUpTool::initialize() { // << " ScalePixel: " << m_ScalePixel << endmsg ); - if (m_atRndmGenSvc.retrieve().isFailure()) { - ATH_MSG_FATAL ( "Could not retrieve RandomNumber Service!" ); - return StatusCode::FAILURE; - } - else { - ATH_MSG_DEBUG ( "Retrieved RandomNumber Service" ); - } + ATH_CHECK (m_randomSvc.retrieve()); + ATH_MSG_DEBUG ( "Retrieved RandomNumber Service" ); + + ATH_CHECK (m_mergeSvc.retrieve()); + ATH_MSG_DEBUG("Retrieved PileUpMergeSvc"); m_mergedTDSimHitList = new AFP_TDSimHitCollection("mergedTDSimHitList"); m_mergedSIDSimHitList = new AFP_SIDSimHitCollection("mergedSIDSimHitList"); @@ -131,20 +123,10 @@ StatusCode AFP_PileUpTool::initialize() { return StatusCode::SUCCESS; } -StatusCode AFP_PileUpTool::processAllSubEvents(const EventContext& /*ctx*/) { +StatusCode AFP_PileUpTool::processAllSubEvents(const EventContext& ctx) { ATH_MSG_DEBUG ( "AFP_PileUpTool::processAllSubEvents()" ); - //retrieve the PileUpMergeSvc if necessary - if(!m_mergeSvc) { - if(!m_mergeSvc.retrieve().isSuccess() || !m_mergeSvc) { - ATH_MSG_FATAL("digitize: Could not find PileUpMergeSvc"); - return StatusCode::FAILURE; - } - else ATH_MSG_DEBUG("digitize: retrieved PileUpMergeSvc"); - } - else ATH_MSG_DEBUG("digitize: PileUpMergeSvc already available"); - typedef PileUpMergeSvc::TimedList<AFP_TDSimHitCollection>::type TimedTDSimHitCollList; typedef PileUpMergeSvc::TimedList<AFP_SIDSimHitCollection>::type TimedSIDSimHitCollList; @@ -206,8 +188,6 @@ StatusCode AFP_PileUpTool::processAllSubEvents(const EventContext& /*ctx*/) { - m_rndEngine = m_atRndmGenSvc->GetEngine("AFPRndEng"); - if (recordContainers(this->evtStore(), m_TDDigiCollectionName).isFailure()) { ATH_MSG_FATAL ( " AFP DigiTop :: Could not record the empty TiD digit container in StoreGate " ); return StatusCode::FAILURE; @@ -222,8 +202,11 @@ StatusCode AFP_PileUpTool::processAllSubEvents(const EventContext& /*ctx*/) { else { ATH_MSG_DEBUG ( " AFP DigiTop :: SiD digit container is recorded in StoreGate " ); } - - fillTDDigiCollection(thpcAFP_TDPmt, m_rndEngine); + + ATHRNG::RNGWrapper* rngWrapper = m_randomSvc->getEngine(this, m_randomStreamName); + rngWrapper->setSeed( m_randomStreamName, ctx ); + CLHEP::HepRandomEngine* rngEngine = rngWrapper->getEngine(ctx); + fillTDDigiCollection(thpcAFP_TDPmt, rngEngine); fillSiDigiCollection(thpcAFP_SiPmt); @@ -303,16 +286,17 @@ StatusCode AFP_PileUpTool::processBunchXing(int bunchXing, for (; iSiPmt!=eSiPmt; ++iSiPmt) m_mergedSIDSimHitList->push_back((*iSiPmt)); - m_rndEngine = m_atRndmGenSvc->GetEngine("AFPRndEng"); - } return StatusCode::SUCCESS; } -StatusCode AFP_PileUpTool::mergeEvent(const EventContext& /*ctx*/){ +StatusCode AFP_PileUpTool::mergeEvent(const EventContext& ctx){ - fillTDDigiCollection(m_mergedTDSimHitList, m_rndEngine); + ATHRNG::RNGWrapper* rngWrapper = m_randomSvc->getEngine(this, m_randomStreamName); + rngWrapper->setSeed( m_randomStreamName, ctx ); + CLHEP::HepRandomEngine* rngEngine = rngWrapper->getEngine(ctx); + fillTDDigiCollection(m_mergedTDSimHitList, rngEngine); fillSiDigiCollection(m_mergedSIDSimHitList); return StatusCode::SUCCESS; diff --git a/ForwardDetectors/ALFA/ALFA_Digitization/ALFA_Digitization/ALFA_PileUpTool.h b/ForwardDetectors/ALFA/ALFA_Digitization/ALFA_Digitization/ALFA_PileUpTool.h index 4e39ff15e863e60509c049c35b215036c94a67a4..ad0b326d463832f8785b8b9dc28aa8e303457866 100644 --- a/ForwardDetectors/ALFA/ALFA_Digitization/ALFA_Digitization/ALFA_PileUpTool.h +++ b/ForwardDetectors/ALFA/ALFA_Digitization/ALFA_Digitization/ALFA_PileUpTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef ALFA_PILEUP_TOOL_H @@ -10,7 +10,7 @@ #include "Gaudi/Property.h" #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/ITHistSvc.h" -#include "AthenaKernel/IAtRndmGenSvc.h" +#include "AthenaKernel/IAthRNGSvc.h" #include "HitManagement/TimedHitCollection.h" @@ -29,7 +29,9 @@ #include <vector> #include <utility> /* pair */ -class IAtRndmGenSvc; +namespace CLHEP { + class HepRandomEngine; +} class ALFA_PileUpTool: public PileUpToolBase { @@ -106,9 +108,9 @@ class ALFA_PileUpTool: public PileUpToolBase { void SetDumps(bool, bool); */ - ServiceHandle<PileUpMergeSvc> m_mergeSvc; - ServiceHandle<IAtRndmGenSvc> m_atRndmGenSvc; - CLHEP::HepRandomEngine *m_rndEngine; + ServiceHandle<PileUpMergeSvc> m_mergeSvc{this, "mergeSvc", "PileUpMergeSvc", ""}; + ServiceHandle<IAthRNGSvc> m_randomSvc{this, "RndmSvc", "AthRNGSvc", ""}; + Gaudi::Property<std::string> m_randomStreamName{this, "RandomStreamName", "ALFARndEng", ""}; double m_E_fib[8][20][64]; double m_E_ODfib[8][2][3][30]; diff --git a/ForwardDetectors/ALFA/ALFA_Digitization/src/ALFA_PileUpTool.cxx b/ForwardDetectors/ALFA/ALFA_Digitization/src/ALFA_PileUpTool.cxx index c2931c4de7898f319331be4844c8bbefb423a800..7fe76c24a29e6ead476f0e6c2d48430ac22d1167 100644 --- a/ForwardDetectors/ALFA/ALFA_Digitization/src/ALFA_PileUpTool.cxx +++ b/ForwardDetectors/ALFA/ALFA_Digitization/src/ALFA_PileUpTool.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #include "ALFA_Digitization/ALFA_PileUpTool.h" @@ -12,6 +12,8 @@ #include "ALFA_SimEv/ALFA_ODHit.h" #include "ALFA_RawEv/ALFA_ODDigitCollection.h" +#include "AthenaKernel/RNGWrapper.h" +#include "CLHEP/Random/RandomEngine.h" #include "CLHEP/Random/RandFlat.h" #include "CLHEP/Random/RandGaussZiggurat.h" #include "CLHEP/Random/RandPoissonQ.h" @@ -20,7 +22,6 @@ #include <map> -#include "PileUpTools/PileUpMergeSvc.h" #include "Identifier/Identifier.h" #include "AthenaBaseComps/AthMsgStreamMacros.h" @@ -49,9 +50,6 @@ ALFA_PileUpTool::ALFA_PileUpTool(const std::string& type, const std::string& name, const IInterface* parent) : PileUpToolBase(type, name, parent), - m_mergeSvc ("PileUpMergeSvc", name), - m_atRndmGenSvc ("AtRndmGenSvc" , name), - m_rndEngine (0), m_sigma0 (0.1), m_sigma1 (1.0), m_meanE_dep (0.0863), //MeV @@ -81,8 +79,6 @@ ALFA_PileUpTool::ALFA_PileUpTool(const std::string& type, declareProperty("ALFA_DigitCollection", m_key_DigitCollection, "Name of the Collection to hold the output from the ALFA main detector digitization"); declareProperty("ALFA_ODDigitCollection", m_key_ODDigitCollection, "Name of the Collection to hold the output from the ALFA OD digitization"); - declareProperty("RndmSvc", m_atRndmGenSvc, "Random Number Service used in ALFA digitization"); - declareProperty("mergeSvc", m_mergeSvc, "Store to hold the pile-ups"); // declareProperty("fillRootTree", m_fillRootTree); @@ -106,14 +102,12 @@ StatusCode ALFA_PileUpTool::initialize(){ ATH_MSG_DEBUG (" Pedestal: " << m_AmplitudeCut); - if (m_atRndmGenSvc.retrieve().isFailure()) { - ATH_MSG_FATAL ( "Could not retrieve RandomNumber Service!" ); - return StatusCode::FAILURE; - } - else { - ATH_MSG_DEBUG ( "Retrieved RandomNumber Service" ); - } - + ATH_CHECK (m_randomSvc.retrieve()); + ATH_MSG_DEBUG ( "Retrieved RandomNumber Service" ); + + ATH_CHECK (m_mergeSvc.retrieve()); + ATH_MSG_DEBUG("Retrieved PileUpMergeSvc"); + m_mergedALFA_HitList = new ALFA_HitCollection(); m_mergedALFA_ODHitList = new ALFA_ODHitCollection(); @@ -125,20 +119,10 @@ StatusCode ALFA_PileUpTool::initialize(){ // ********************************************************************************* -StatusCode ALFA_PileUpTool::processAllSubEvents(const EventContext& /*ctx*/) { +StatusCode ALFA_PileUpTool::processAllSubEvents(const EventContext& ctx) { ATH_MSG_DEBUG ("ALFA_PileUpTool::processAllSubEvents()"); - //retrieve the PileUpMergeSvc if necessary - if(!m_mergeSvc) { - if(!m_mergeSvc.retrieve().isSuccess() || !m_mergeSvc) { - ATH_MSG_FATAL("digitize: Could not find PileUpMergeSvc"); - return StatusCode::FAILURE; - } - else ATH_MSG_DEBUG("digitize: retrieved PileUpMergeSvc"); - } - else ATH_MSG_DEBUG("digitize: PileUpMergeSvc already available"); - typedef PileUpMergeSvc::TimedList<ALFA_HitCollection>::type TimedALFAHitCollList; typedef PileUpMergeSvc::TimedList<ALFA_ODHitCollection>::type TimedALFAODHitCollList; @@ -198,9 +182,6 @@ StatusCode ALFA_PileUpTool::processAllSubEvents(const EventContext& /*ctx*/) { // preparing containers - m_rndEngine = m_atRndmGenSvc->GetEngine("ALFARndEng"); - - if (recordCollection(this->evtStore(), m_key_DigitCollection).isFailure()) { ATH_MSG_FATAL ( " ALFA_PileUpTool::processAllSubEvents(): Could not record the empty ALFA digit container in StoreGate " ); return StatusCode::FAILURE; @@ -218,8 +199,12 @@ StatusCode ALFA_PileUpTool::processAllSubEvents(const EventContext& /*ctx*/) { // filling containers ALFA_MD_info(tALFAhit); - - StatusCode sc = fill_MD_DigitCollection(m_rndEngine); + + // Prepare RNG Service + ATHRNG::RNGWrapper* rngWrapper = m_randomSvc->getEngine(this, m_randomStreamName); + rngWrapper->setSeed( m_randomStreamName, ctx ); + CLHEP::HepRandomEngine* rngEngine = rngWrapper->getEngine(ctx); + StatusCode sc = fill_MD_DigitCollection(rngEngine); if (sc.isFailure()) { ATH_MSG_WARNING ("ALFA_PileUpTool::fill_MD_DigitCollection() failed"); return StatusCode::SUCCESS; @@ -228,7 +213,7 @@ StatusCode ALFA_PileUpTool::processAllSubEvents(const EventContext& /*ctx*/) { ALFA_OD_info(tALFAODhit); - sc = fill_OD_DigitCollection(m_rndEngine); + sc = fill_OD_DigitCollection(rngEngine); if (sc.isFailure()) { ATH_MSG_WARNING ("ALFA_PileUpTool::fill_OD_DigitCollection() failed"); return StatusCode::SUCCESS; @@ -308,8 +293,6 @@ StatusCode ALFA_PileUpTool::processBunchXing(int bunchXing, ALFA_ODHitCollection::const_iterator eODHitColl = tmpODHitColl->end(); for (; iODHitColl!=eODHitColl; ++iODHitColl) m_mergedALFA_ODHitList->push_back((*iODHitColl)); - - m_rndEngine = m_atRndmGenSvc->GetEngine("ALFARndEng"); } return StatusCode::SUCCESS; @@ -318,12 +301,16 @@ StatusCode ALFA_PileUpTool::processBunchXing(int bunchXing, -StatusCode ALFA_PileUpTool::mergeEvent(const EventContext& /*ctx*/){ +StatusCode ALFA_PileUpTool::mergeEvent(const EventContext& ctx){ ALFA_MD_info(m_mergedALFA_HitList); - - StatusCode sc = fill_MD_DigitCollection(m_rndEngine); + + // Prepare RNG Service + ATHRNG::RNGWrapper* rngWrapper = m_randomSvc->getEngine(this, m_randomStreamName); + rngWrapper->setSeed( m_randomStreamName, ctx ); + CLHEP::HepRandomEngine* rngEngine = rngWrapper->getEngine(ctx); + StatusCode sc = fill_MD_DigitCollection(rngEngine); if (sc.isFailure()) { ATH_MSG_WARNING ("ALFA_PileUpTool::fill_MD_DigitCollection() failed"); return StatusCode::SUCCESS; @@ -332,7 +319,7 @@ StatusCode ALFA_PileUpTool::mergeEvent(const EventContext& /*ctx*/){ ALFA_OD_info(m_mergedALFA_ODHitList); - sc = fill_OD_DigitCollection(m_rndEngine); + sc = fill_OD_DigitCollection(rngEngine); if (sc.isFailure()) { ATH_MSG_WARNING ("ALFA_PileUpTool::fill_OD_DigitCollection() failed"); return StatusCode::SUCCESS; @@ -580,10 +567,10 @@ StatusCode ALFA_PileUpTool::fill_MD_DigitCollection(CLHEP::HepRandomEngine* rndE // + noise_1 // + noise_2; - amplitude = CLHEP::RandGaussZiggurat::shoot(m_rndEngine, N_photo, sqrt(pow(m_sigma0,2)+N_photo*pow(m_sigma1,2))); + amplitude = CLHEP::RandGaussZiggurat::shoot(rndEngine, N_photo, sqrt(pow(m_sigma0,2)+N_photo*pow(m_sigma1,2))); - //N_photo_CT = CLHEP::RandPoisson::shoot(m_rndEngine,0.08*m_E_fib[l][i][j]*m_meanN_photo/m_meanE_dep); - //amplitude_CT = CLHEP::RandGaussQ::shoot (m_rndEngine, N_photo_CT, sqrt(pow(m_sigma0,2)+N_photo_CT*pow(m_sigma1,2))); + //N_photo_CT = CLHEP::RandPoisson::shoot(rndEngine,0.08*m_E_fib[l][i][j]*m_meanN_photo/m_meanE_dep); + //amplitude_CT = CLHEP::RandGaussQ::shoot (rndEngine, N_photo_CT, sqrt(pow(m_sigma0,2)+N_photo_CT*pow(m_sigma1,2))); if (amplitude >= m_AmplitudeCut ) @@ -610,7 +597,7 @@ StatusCode ALFA_PileUpTool::fill_MD_DigitCollection(CLHEP::HepRandomEngine* rndE { for (int f = j+1; f < 64; f++) { - rand_fib = CLHEP::RandFlat::shoot(m_rndEngine,0.,1.); + rand_fib = CLHEP::RandFlat::shoot(rndEngine,0.,1.); if ( m_fibres[l][i][f] == 0) { @@ -623,7 +610,7 @@ StatusCode ALFA_PileUpTool::fill_MD_DigitCollection(CLHEP::HepRandomEngine* rndE for (int f = j-1; f > -1; f--) { - rand_fib = CLHEP::RandFlat::shoot(m_rndEngine,0.,1.); + rand_fib = CLHEP::RandFlat::shoot(rndEngine,0.,1.); if ( m_fibres[l][i][f] == 0) { diff --git a/ForwardDetectors/LUCID/LUCID_Digitization/src/LUCID_DigitizationToolBox.h b/ForwardDetectors/LUCID/LUCID_Digitization/src/LUCID_DigitizationToolBox.h index e2c79600cfbb14aa7899438ca879a7102a0d03b5..436c85e69212845df569ead7d5e0df1ad2729876 100644 --- a/ForwardDetectors/LUCID/LUCID_Digitization/src/LUCID_DigitizationToolBox.h +++ b/ForwardDetectors/LUCID/LUCID_Digitization/src/LUCID_DigitizationToolBox.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef LUCID_DIGITIZATION_TOOLBOX_H @@ -13,7 +13,6 @@ #include "HitManagement/TimedHitCollection.h" #include "LUCID_SimEvent/LUCID_SimHitCollection.h" #include "LUCID_RawEvent/LUCID_DigitContainer.h" -#include "AthenaKernel/IAtRndmGenSvc.h" class StoreGateSvc; diff --git a/ForwardDetectors/LUCID/LUCID_Digitization/src/LUCID_PileUpTool.cxx b/ForwardDetectors/LUCID/LUCID_Digitization/src/LUCID_PileUpTool.cxx index f2407ca941e3919bcaea752e833cd3e1ddd335de..54c9b47ea3d34fae8a30819558e625ffe5c71b95 100644 --- a/ForwardDetectors/LUCID/LUCID_Digitization/src/LUCID_PileUpTool.cxx +++ b/ForwardDetectors/LUCID/LUCID_Digitization/src/LUCID_PileUpTool.cxx @@ -1,13 +1,14 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #include "LUCID_PileUpTool.h" #include "AthenaKernel/errorcheck.h" -#include "AthenaKernel/IAtRndmGenSvc.h" +#include "AthenaKernel/RNGWrapper.h" +#include "CLHEP/Random/RandomEngine.h" #include "GeneratorObjects/HepMcParticleLink.h" -#include "PileUpTools/PileUpMergeSvc.h" + #include "GaudiKernel/ITHistSvc.h" @@ -19,8 +20,6 @@ LUCID_PileUpTool::LUCID_PileUpTool(const std::string& type, const std::string& name, const IInterface* parent) : PileUpToolBase (type, name, parent), - m_atRndmGenSvc ("AtDSFMTGenSvc", name), - m_mergeSvc ("PileUpMergeSvc", name), m_numTubes (40), m_qdcChannelsPerPE (15.0), m_qdcPedestal (150.0), @@ -46,8 +45,6 @@ LUCID_PileUpTool::LUCID_PileUpTool(const std::string& type, declareProperty("SimHitCollection" , m_SimHitCollectionName, "Name of the input Collection of simulated hits"); declareProperty("LucidDigitsContainer", m_digitsContainerName , "Name of the Container to hold the output from the digitization"); - declareProperty("RndmSvc" , m_atRndmGenSvc , "Random Number Service used in LUCID digitization" ); - declareProperty("mergeSvc" , m_mergeSvc , "Store to hold the pile-ups"); declareProperty("numTubes" , m_numTubes); declareProperty("qdcChannelsPerPE" , m_qdcChannelsPerPE); @@ -84,9 +81,12 @@ StatusCode LUCID_PileUpTool::initialize() << " tdcFedNoiseFactor: " << m_tdcFedNoiseFactor << endmsg << " fillRootTree : " << m_fillRootTree ); - CHECK(m_atRndmGenSvc.retrieve()); + ATH_CHECK(m_randomSvc.retrieve()); ATH_MSG_DEBUG ( "Retrieved RandomNumber Service" ); + ATH_CHECK(m_mergeSvc.retrieve()); + ATH_MSG_DEBUG ( "Retrieved PileUpMergeSvc" ); + m_digitToolBox = new LUCID_DigitizationToolBox(m_numTubes, m_qdcChannelsPerPE, m_qdcPedestal, @@ -168,35 +168,33 @@ StatusCode LUCID_PileUpTool::processBunchXing(int bunchXing, for (; i!=e; ++i) m_mergedhitList->push_back((*i)); - m_rndEngine = m_atRndmGenSvc->GetEngine("LUCIDRndEng"); } return StatusCode::SUCCESS; } /// ---------------------------------------------------------------------------------------------------- -StatusCode LUCID_PileUpTool::mergeEvent(const EventContext& /*ctx*/) +StatusCode LUCID_PileUpTool::mergeEvent(const EventContext& ctx) { - CHECK(m_digitToolBox->fillDigitContainer(m_mergedhitList, m_rndEngine)); + ATHRNG::RNGWrapper* rngWrapper = m_randomSvc->getEngine(this, m_randomStreamName); + rngWrapper->setSeed( m_randomStreamName, ctx ); + CLHEP::HepRandomEngine* rngEngine = rngWrapper->getEngine(ctx); + ATH_CHECK(m_digitToolBox->fillDigitContainer(m_mergedhitList, rngEngine)); ATH_MSG_DEBUG ( " LUCID_DigitContainer successfully registered in StoreGate " ); return StatusCode::SUCCESS; } /// ---------------------------------------------------------------------------------------------------- -StatusCode LUCID_PileUpTool::processAllSubEvents(const EventContext& /*ctx*/) +StatusCode LUCID_PileUpTool::processAllSubEvents(const EventContext& ctx) { ATH_MSG_VERBOSE ( "processAllSubEvents()" ); - if(!m_mergeSvc) - { - CHECK(m_mergeSvc.retrieve()); - } typedef PileUpMergeSvc::TimedList<LUCID_SimHitCollection>::type TimedHitCollList; TimedHitCollList hitCollList; - CHECK(m_mergeSvc->retrieveSubEvtsData(m_SimHitCollectionName, hitCollList)); + ATH_CHECK(m_mergeSvc->retrieveSubEvtsData(m_SimHitCollectionName, hitCollList)); ATH_MSG_DEBUG ( "Retrieved TimedHitCollList" ); ATH_MSG_DEBUG ( " PileUp: Merge " << hitCollList.size() << " LUCID_SimHitCollection with key " << m_SimHitCollectionName ); @@ -217,12 +215,14 @@ StatusCode LUCID_PileUpTool::processAllSubEvents(const EventContext& /*ctx*/) ++iColl; } - m_rndEngine = m_atRndmGenSvc->GetEngine("LUCIDRndEng"); - CHECK(m_digitToolBox->recordContainers(this->evtStore(), m_key_digitCnt)); + ATH_CHECK(m_digitToolBox->recordContainers(this->evtStore(), m_key_digitCnt)); ATH_MSG_DEBUG ( " Digit container is recorded in StoreGate " ); - CHECK(m_digitToolBox->fillDigitContainer(thpclucid, m_rndEngine)); + ATHRNG::RNGWrapper* rngWrapper = m_randomSvc->getEngine(this, m_randomStreamName); + rngWrapper->setSeed( m_randomStreamName, ctx ); + CLHEP::HepRandomEngine* rngEngine = rngWrapper->getEngine(ctx); + ATH_CHECK(m_digitToolBox->fillDigitContainer(thpclucid, rngEngine)); ATH_MSG_DEBUG ( " Digit container was filled successfully " ); return StatusCode::SUCCESS; diff --git a/ForwardDetectors/LUCID/LUCID_Digitization/src/LUCID_PileUpTool.h b/ForwardDetectors/LUCID/LUCID_Digitization/src/LUCID_PileUpTool.h index ea82d17884ec1ac82e66cd9db8ccd6add7913a9e..bd9f887db7a0428b092f77bef993560a03373ef2 100644 --- a/ForwardDetectors/LUCID/LUCID_Digitization/src/LUCID_PileUpTool.h +++ b/ForwardDetectors/LUCID/LUCID_Digitization/src/LUCID_PileUpTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef LUCID_DIGITIZATION_TOOL_H @@ -15,6 +15,7 @@ #include "xAODEventInfo/EventInfo.h" // SubEventIterator #include "xAODEventInfo/EventAuxInfo.h"// SubEventIterator +#include "AthenaKernel/IAthRNGSvc.h" #include "PileUpTools/PileUpMergeSvc.h" #include "Gaudi/Property.h" @@ -23,10 +24,9 @@ #include <vector> #include <utility> /* pair */ -class StoreGateSvc; -class IAtRndmGenSvc; -//class PileUpMergeSvc; -class IHistSvc; +namespace CLHEP { + class HepRandomEngine; +} class LUCID_PileUpTool: public PileUpToolBase, public LUCID_DigitizationToolBox { @@ -58,8 +58,9 @@ public: private: - ServiceHandle<IAtRndmGenSvc> m_atRndmGenSvc; - ServiceHandle<PileUpMergeSvc> m_mergeSvc; + ServiceHandle<PileUpMergeSvc> m_mergeSvc{this, "mergeSvc", "PileUpMergeSvc", ""}; + ServiceHandle<IAthRNGSvc> m_randomSvc{this, "RndmSvc", "AthRNGSvc", ""}; + Gaudi::Property<std::string> m_randomStreamName{this, "RandomStreamName", "LUCIDRndEng", ""}; std::string m_dataObjectName; std::string m_SimHitCollectionName; @@ -68,8 +69,6 @@ private: LUCID_DigitizationToolBox *m_digitToolBox; - CLHEP::HepRandomEngine *m_rndEngine; - //LUCID_DigitContainer *m_digitContainer; ITHistSvc *m_digitHistSvc; LUCID_SimHitCollection* m_mergedhitList; diff --git a/ForwardDetectors/ZDC/ZDC_SimuDigitization/ZDC_SimuDigitization/ZDC_PileUpTool.h b/ForwardDetectors/ZDC/ZDC_SimuDigitization/ZDC_SimuDigitization/ZDC_PileUpTool.h index 4fd5d394caa08173856957902b6a19bbb7bfda0c..797edf7e65501dfda0041c279c46d35fbb691522 100644 --- a/ForwardDetectors/ZDC/ZDC_SimuDigitization/ZDC_SimuDigitization/ZDC_PileUpTool.h +++ b/ForwardDetectors/ZDC/ZDC_SimuDigitization/ZDC_SimuDigitization/ZDC_PileUpTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef ZDC_DIGITIZATION_TOOL_H @@ -9,7 +9,7 @@ #include "Gaudi/Property.h" #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/ITHistSvc.h" -#include "AthenaKernel/IAtRndmGenSvc.h" +#include "AthenaKernel/IAthRNGSvc.h" #include "ZDC_SimEvent/ZDC_SimStripHit_Collection.h" #include "ZDC_SimEvent/ZDC_SimPixelHit_Collection.h" #include "HitManagement/TimedHitCollection.h" @@ -23,7 +23,9 @@ #include <vector> #include <utility> /* pair */ -class IAtRndmGenSvc; +namespace CLHEP { + class HepRandomEngine; +} class ZDC_PileUpTool: public PileUpToolBase { @@ -70,9 +72,8 @@ class ZDC_PileUpTool: public PileUpToolBase { void SetDumps(bool, bool); ServiceHandle<PileUpMergeSvc> m_mergeSvc{this, "mergeSvc", "PileUpMergeSvc", ""}; - ServiceHandle<IAtRndmGenSvc> m_atRndmGenSvc{this, "RndmSvc", "AtRndmGenSvc", - "Random Number Service used in ZDC digitization"}; - CLHEP::HepRandomEngine *m_rndEngine{nullptr}; + ServiceHandle<IAthRNGSvc> m_randomSvc{this, "RndmSvc", "AthRNGSvc", ""}; + Gaudi::Property<std::string> m_randomStreamName{this, "RandomStreamName", "ZDCRndEng", ""}; Gaudi::Property<std::string> m_SimStripHitCollectionName{this, "SimStripHitCollection" , "ZDC_SimStripHit_Collection", "Name of the input Collection of the simulated Strip Hits"}; diff --git a/ForwardDetectors/ZDC/ZDC_SimuDigitization/src/ZDC_PileUpTool.cxx b/ForwardDetectors/ZDC/ZDC_SimuDigitization/src/ZDC_PileUpTool.cxx index 88328727d8eb9b952ffe1e11cbbbc96bc200abc5..1e3e60127ede9e95d184d8328db62de562cf446c 100644 --- a/ForwardDetectors/ZDC/ZDC_SimuDigitization/src/ZDC_PileUpTool.cxx +++ b/ForwardDetectors/ZDC/ZDC_SimuDigitization/src/ZDC_PileUpTool.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ @@ -10,10 +10,11 @@ #include "ZDC_SimEvent/ZDC_SimStripHit.h" #include "ZDC_SimEvent/ZDC_SimPixelHit.h" #include "ZdcEvent/ZdcDigitsCollection.h" -#include "PileUpTools/PileUpMergeSvc.h" #include "Identifier/Identifier.h" #include "AthenaBaseComps/AthMsgStreamMacros.h" #include <map> +#include "AthenaKernel/RNGWrapper.h" +#include "CLHEP/Random/RandomEngine.h" #include "CLHEP/Random/RandFlat.h" #include "CLHEP/Random/RandGaussQ.h" #include "CLHEP/Random/RandPoissonQ.h" @@ -46,7 +47,7 @@ StatusCode ZDC_PileUpTool::initialize() { << " MaxTimeBin: " << m_MaxTimeBin << endmsg << " Pedestal : " << m_Pedestal ); - ATH_CHECK(m_atRndmGenSvc.retrieve()); + ATH_CHECK(m_randomSvc.retrieve()); ATH_MSG_DEBUG ( "Retrieved RandomNumber Service" ); ATH_CHECK(m_mergeSvc.retrieve()); @@ -57,7 +58,7 @@ StatusCode ZDC_PileUpTool::initialize() { return StatusCode::SUCCESS; } -StatusCode ZDC_PileUpTool::processAllSubEvents(const EventContext& /*ctx*/) { +StatusCode ZDC_PileUpTool::processAllSubEvents(const EventContext& ctx) { ATH_MSG_DEBUG ( "ZDC_PileUpTool::processAllSubEvents()" ); @@ -115,16 +116,17 @@ StatusCode ZDC_PileUpTool::processAllSubEvents(const EventContext& /*ctx*/) { ++iPixelColl; } - m_rndEngine = m_atRndmGenSvc->GetEngine("ZDCRndEng"); - if (recordContainers(this->evtStore(), m_ZdcDigitsContainerName).isFailure()) { ATH_MSG_FATAL ( " ZDC DigiTop :: Could not record the empty digit container in StoreGate " ); return StatusCode::FAILURE; } else { ATH_MSG_DEBUG ( " ZDC DigiTop :: Digit container is recorded in StoreGate " ); } - fillStripDigitContainer(thpczdcstrip, m_rndEngine); - fillPixelDigitContainer(thpczdcpixel, m_rndEngine); + ATHRNG::RNGWrapper* rngWrapper = m_randomSvc->getEngine(this, m_randomStreamName); + rngWrapper->setSeed( m_randomStreamName, ctx ); + CLHEP::HepRandomEngine* rngEngine = rngWrapper->getEngine(ctx); + fillStripDigitContainer(thpczdcstrip, rngEngine); + fillPixelDigitContainer(thpczdcpixel, rngEngine); return StatusCode::SUCCESS; } @@ -189,17 +191,18 @@ StatusCode ZDC_PileUpTool::processBunchXing(int bunchXing, ZDC_SimPixelHit_Collection::const_iterator ePixel = tmpCollPixel->end(); for (; iPixel!=ePixel; ++iPixel) m_mergedPixelHitList->push_back((*iPixel)); - - m_rndEngine = m_atRndmGenSvc->GetEngine("ZDCRndEng"); } return StatusCode::SUCCESS; } -StatusCode ZDC_PileUpTool::mergeEvent(const EventContext& /*ctx*/){ +StatusCode ZDC_PileUpTool::mergeEvent(const EventContext& ctx){ - fillStripDigitContainer(m_mergedStripHitList, m_rndEngine); - fillPixelDigitContainer(m_mergedPixelHitList, m_rndEngine); + ATHRNG::RNGWrapper* rngWrapper = m_randomSvc->getEngine(this, m_randomStreamName); + rngWrapper->setSeed( m_randomStreamName, ctx ); + CLHEP::HepRandomEngine* rngEngine = rngWrapper->getEngine(ctx); + fillStripDigitContainer(m_mergedStripHitList, rngEngine); + fillPixelDigitContainer(m_mergedPixelHitList, rngEngine); return StatusCode::SUCCESS; }