diff --git a/MuonSpectrometer/MuonCnv/MuonCSC_CnvTools/src/CscDigitToCscRDOTool.cxx b/MuonSpectrometer/MuonCnv/MuonCSC_CnvTools/src/CscDigitToCscRDOTool.cxx index 28d48717820f2139a9b2f8ad1a42d5e42a7433be..99aa1a67461f8ea3c98a797690806c0753169494 100644 --- a/MuonSpectrometer/MuonCnv/MuonCSC_CnvTools/src/CscDigitToCscRDOTool.cxx +++ b/MuonSpectrometer/MuonCnv/MuonCSC_CnvTools/src/CscDigitToCscRDOTool.cxx @@ -5,8 +5,8 @@ #include "GaudiKernel/ISvcLocator.h" #include "GaudiKernel/StatusCode.h" +#include "AthenaKernel/RNGWrapper.h" #include "CLHEP/Random/RandomEngine.h" -//#include "CLHEP/Random/RandGauss.h" #include "CLHEP/Random/RandGaussZiggurat.h" #include "CLHEP/Random/RandFlat.h" @@ -28,22 +28,11 @@ const uint16_t MAX_AMPL = 4095; // 12-bit ADC CscDigitToCscRDOTool::CscDigitToCscRDOTool (const std::string& type,const std::string& name,const IInterface* pIID) - : AthAlgTool(type, name, pIID), - m_cscCablingSvc("CSCcablingSvc", name), - m_cscCalibTool("CscCalibTool"), - m_rndmSvc("AtRndmGenSvc", name ), - m_rndmEngine(0), - m_rndmEngineName("CscDigitToCscRDOTool") + : base_class(type, name, pIID) { - - declareInterface<IMuonDigitizationTool>(this); - - declareProperty("NumSamples", m_numSamples = 4); - declareProperty("Latency", m_latency = 0); - declareProperty("RndmSvc", m_rndmSvc, "Random Number Service used for CscDigitToCscRDOTool" ); - declareProperty("RndmEngine", m_rndmEngineName, "Random engine name for CscDigitToCscRDOTool"); - declareProperty("addNoise", m_addNoise =true ); - declareProperty("cscCalibTool", m_cscCalibTool); + declareProperty("NumSamples", m_numSamples); + declareProperty("Latency", m_latency); + declareProperty("addNoise", m_addNoise); } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -53,41 +42,19 @@ StatusCode CscDigitToCscRDOTool::initialize() ATH_MSG_DEBUG ( " in initialize()" ); - if ( m_cscCablingSvc.retrieve().isFailure() ) { - ATH_MSG_ERROR ( " Cannot get CSC Cabling Service " ); - return StatusCode::FAILURE; - } - - if ( detStore()->retrieve(m_cscHelper, "CSCIDHELPER").isFailure()) { - ATH_MSG_FATAL ( "Could not get CscIdHelper !" ); - return StatusCode::FAILURE; - } - else { - ATH_MSG_DEBUG ( " Found the CscIdHelper. " ); - } - - + ATH_CHECK( m_cscCablingSvc.retrieve() ); + + ATH_CHECK( detStore()->retrieve(m_cscHelper, "CSCIDHELPER") ); + ATH_MSG_DEBUG ( " Found the CscIdHelper. " ); + /** CSC calibration tool for the Condtiions Data base access */ - if ( m_cscCalibTool.retrieve().isFailure() ) { - ATH_MSG_ERROR ( "Can't get handle on CSC calibration tools" ); - return StatusCode::FAILURE; - } + ATH_CHECK( m_cscCalibTool.retrieve() ); m_startTime = m_cscCalibTool->getTimeOffset();// StartTime=46.825, ATH_MSG_INFO (" m_startTims is set to be " << m_startTime << "from cscCalibTool->getTimeOffset()" ); //random number initialization - if ( m_rndmSvc.retrieve().isFailure() ) { - ATH_MSG_ERROR ( " Could not initialize Random Number Service" ); - } - - // getting our random numbers stream - m_rndmEngine = m_rndmSvc->GetEngine(m_rndmEngineName); - if (m_rndmEngine==0) { - ATH_MSG_ERROR ( "Could not find RndmEngine : " << m_rndmEngineName ); - return StatusCode::FAILURE; - } - + ATH_CHECK( m_rndmSvc.retrieve() ); /** initialization of CSC ROD Decoder */ m_samplingTime = static_cast<uint16_t>( m_cscCalibTool->getSamplingTime() ); // FIXME @@ -122,7 +89,10 @@ StatusCode CscDigitToCscRDOTool::fill_CSCdata() // according to cosmic data ~33% is phase =1 peak close to 3rd... // but let's start with half and half - + ATHRNG::RNGWrapper* rngWrapper = m_rndmSvc->getEngine(this); + rngWrapper->setSeed( name(), Gaudi::Hive::currentContext() ); + CLHEP::HepRandomEngine *rndmEngine = *rngWrapper; + CscRODReadOut rodReadOut(m_startTime, m_samplingTime, m_signalWidth, m_numberOfIntegration); // initialization but it will be updated per channel later 12/03/2009 WP // m_startTime is not related to rodReadOut at all but doesn't matter it's not used....by resetting later... @@ -223,7 +193,7 @@ StatusCode CscDigitToCscRDOTool::fill_CSCdata() cscRdoCollection->set_samplingPhase(); } } else { - double flat = CLHEP::RandFlat::shoot(m_rndmEngine, 0.0,1.0); // for other particles + double flat = CLHEP::RandFlat::shoot(rndmEngine, 0.0,1.0); // for other particles if (flat < 0.5) cscRdoCollection->set_samplingPhase(); } @@ -351,7 +321,7 @@ StatusCode CscDigitToCscRDOTool::fill_CSCdata() for (int i=0; i<m_numSamples; i++) { // double samplingTime = (i+1)*(1000/m_samplingRate) + m_startTime;// considered in CSC_Digitization - double theNoise = (m_addNoise) ? CLHEP::RandGaussZiggurat::shoot(m_rndmEngine, 0.0, noiseADC) : 0.0; + double theNoise = (m_addNoise) ? CLHEP::RandGaussZiggurat::shoot(rndmEngine, 0.0, noiseADC) : 0.0; double rawAmpl = cscDigitSamples[i]; double ampl = rawAmpl; double charge_to_adcCount = m_cscCalibTool->numberOfElectronsToADCCount(cscOfflineChannelHashId, ampl) + theNoise + pedestalADC; @@ -387,7 +357,7 @@ StatusCode CscDigitToCscRDOTool::fill_CSCdata() for (int i=0; i<m_numSamples; i++) { double samplingTime = (i+1)*(1000/m_samplingRate) + m_startTime; - double theNoise = (m_addNoise) ? CLHEP::RandGaussZiggurat::shoot(m_rndmEngine, 0.0, noiseADC) : 0.0; + double theNoise = (m_addNoise) ? CLHEP::RandGaussZiggurat::shoot(rndmEngine, 0.0, noiseADC) : 0.0; double rawAmpl = rodReadOut.signal_amplitude(samplingTime); //FIXME - to be updated still! double ampl = charge_to_adcCount*rawAmpl + theNoise + pedestalADC; diff --git a/MuonSpectrometer/MuonCnv/MuonCSC_CnvTools/src/CscDigitToCscRDOTool.h b/MuonSpectrometer/MuonCnv/MuonCSC_CnvTools/src/CscDigitToCscRDOTool.h index 9dd0d222a1f0e5441e1438978d20961d8d1716ce..367e0071f8afef5c5f8ab6373086ab86b43b27fd 100644 --- a/MuonSpectrometer/MuonCnv/MuonCSC_CnvTools/src/CscDigitToCscRDOTool.h +++ b/MuonSpectrometer/MuonCnv/MuonCSC_CnvTools/src/CscDigitToCscRDOTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #ifndef CSCDIGITTOCSCRDOTOOL_H @@ -19,7 +19,7 @@ #include "MuonIdHelpers/CscIdHelper.h" #include "CSCcabling/CSCcablingSvc.h" -#include "AthenaKernel/IAtRndmGenSvc.h" +#include "AthenaKernel/IAthRNGSvc.h" #include "MuonDigToolInterfaces/IMuonDigitizationTool.h" #include "CscCalibTools/ICscCalibTool.h" @@ -28,44 +28,40 @@ class ActiveStoreSvc; ///////////////////////////////////////////////////////////////////////////// -class CscDigitToCscRDOTool : virtual public IMuonDigitizationTool, public AthAlgTool { +class CscDigitToCscRDOTool final : public extends<AthAlgTool, IMuonDigitizationTool> { public: CscDigitToCscRDOTool (const std::string& type, const std::string& name, const IInterface* pIID); - ~CscDigitToCscRDOTool() {} + virtual ~CscDigitToCscRDOTool() = default; virtual StatusCode initialize() override; virtual StatusCode digitize() override; - private: - - std::map<uint16_t, CscRawDataCollection *> m_cscRdoMap; - uint16_t m_samplingRate; - uint16_t m_numSamples; - uint16_t m_latency; - double m_startTime; - double m_signalWidth; - bool m_addNoise; - private: StatusCode fill_CSCdata(); CscRawDataCollection * cscRdo(uint16_t subDetectorId, uint16_t rodId) ; - uint16_t m_samplingTime; - uint16_t m_numberOfIntegration; + + std::map<uint16_t, CscRawDataCollection *> m_cscRdoMap; + uint16_t m_samplingRate{}; //!< set during initialize from cscCalibTool + uint16_t m_numSamples{4}; + uint16_t m_latency{0}; + double m_startTime{}; //!< set during initialize from cscCalibTool + double m_signalWidth{}; //!< set during initialize from cscCalibTool + bool m_addNoise{true}; + uint16_t m_samplingTime; //!< set during initialize from cscCalibTool + uint16_t m_numberOfIntegration{}; //!< set during initialize from cscCalibTool protected: SG::WriteHandleKey<CscRawDataContainer> m_rdoContainerKey{this,"OutputObjectName","CSCRDO","WriteHandleKey for Output CswRawDataContainer"}; SG::ReadHandleKey<CscDigitContainer> m_digitContainerKey{this,"InputObjectName","CSC_DIGITS","ReadHandleKey for Input CscDigitContainer"}; - const CscIdHelper * m_cscHelper; - ServiceHandle<CSCcablingSvc> m_cscCablingSvc; - ToolHandle<ICscCalibTool> m_cscCalibTool; + const CscIdHelper * m_cscHelper{}; + ServiceHandle<CSCcablingSvc> m_cscCablingSvc{this, "CSCcablingSvc", "CSCcablingSvc", ""}; + PublicToolHandle<ICscCalibTool> m_cscCalibTool{this, "cscCalibTool", "CscCalibTool", ""}; - ServiceHandle <IAtRndmGenSvc> m_rndmSvc; // Random number service - CLHEP::HepRandomEngine *m_rndmEngine; // Random number engine used - not init in SiDigitization - std::string m_rndmEngineName;// name of random engine + ServiceHandle<IAthRNGSvc> m_rndmSvc{this, "RndmSvc", "AthRNGSvc", ""}; //!< Random number service }; #endif diff --git a/MuonSpectrometer/MuonCnv/MuonCnvExample/python/MuonCnvConfig.py b/MuonSpectrometer/MuonCnv/MuonCnvExample/python/MuonCnvConfig.py index 8ceb47d8e4bd37cef961765a75cb51262e27783f..4b19169e51eabd096a2ce1349b463c84e1b66283 100644 --- a/MuonSpectrometer/MuonCnv/MuonCnvExample/python/MuonCnvConfig.py +++ b/MuonSpectrometer/MuonCnv/MuonCnvExample/python/MuonCnvConfig.py @@ -6,28 +6,20 @@ def BaseCscDigitToCscRDOTool(name,**kwargs): kwargs.setdefault("Latency", 0) from Digitization.DigitizationFlags import digitizationFlags kwargs.setdefault("addNoise", digitizationFlags.doMuonNoise()) - kwargs.setdefault("RndmSvc", digitizationFlags.rndmSvc.get_Value()) kwargs.setdefault("cscCalibTool", "CscCalibTool") from AthenaCommon import CfgMgr return CfgMgr.CscDigitToCscRDOTool(name,**kwargs) def CscDigitToCscRDOTool(name,**kwargs): from Digitization.DigitizationFlags import digitizationFlags - digitizationFlags.rndmSeedList.addSeed("CscDigitToCscRDOTool", 49261510, 105132394 ) - if digitizationFlags.PileUpPremixing and 'OverlayMT' in digitizationFlags.experimentalDigi(): from OverlayCommonAlgs.OverlayFlags import overlayFlags kwargs.setdefault("OutputObjectName", overlayFlags.bkgPrefix() + "CSCRDO") else: kwargs.setdefault("OutputObjectName", "CSCRDO") - return BaseCscDigitToCscRDOTool(name,**kwargs) def CscDigitToCscRDOTool2(name,**kwargs): - # consider a separate random number stream - #from Digitization.DigitizationFlags import digitizationFlags - #digitizationFlags.rndmSeedList.addSeed("CscDigitToCscRDOTool2", 49261510, 105132394 ) - #kwargs.setdefault("RndmEngine","CscDigitToCscRDOTool2") kwargs.setdefault("NumSamples", 2) kwargs.setdefault("addNoise", False) from OverlayCommonAlgs.OverlayFlags import overlayFlags @@ -36,10 +28,6 @@ def CscDigitToCscRDOTool2(name,**kwargs): return BaseCscDigitToCscRDOTool(name,**kwargs) def CscDigitToCscRDOTool4(name,**kwargs): - # consider a separate random number stream - #from Digitization.DigitizationFlags import digitizationFlags - #digitizationFlags.rndmSeedList.addSeed("CscDigitToCscRDOTool4", 49261510, 105132394 ) - #kwargs.setdefault("RndmEngine","CscDigitToCscRDOTool4") kwargs.setdefault("NumSamples", 4) kwargs.setdefault("addNoise", False) from OverlayCommonAlgs.OverlayFlags import overlayFlags