diff --git a/MuonSpectrometer/MuonDigitization/RPC_Digitization/RPC_Digitization/RpcDigitizationTool.h b/MuonSpectrometer/MuonDigitization/RPC_Digitization/RPC_Digitization/RpcDigitizationTool.h index d12a6f79b8d8652ab005d3b19978bc146a20ea19..0801038f167d7a6dff09b402f3603e89f4425362 100644 --- a/MuonSpectrometer/MuonDigitization/RPC_Digitization/RPC_Digitization/RpcDigitizationTool.h +++ b/MuonSpectrometer/MuonDigitization/RPC_Digitization/RPC_Digitization/RpcDigitizationTool.h @@ -56,7 +56,6 @@ class RpcHitIdHelper; class RpcIdHelper; -class ITagInfoMgr; namespace CLHEP { class HepRandomEngine; @@ -87,7 +86,8 @@ public: virtual StatusCode processAllSubEvents(const EventContext& ctx) override final; private: - + StatusCode initializeRunDependentParameters(); + template <class CondType> StatusCode retrieveCondData(const EventContext& ctx, const SG::ReadCondHandleKey<CondType>& key, const CondType* & condPtr) const; @@ -223,7 +223,6 @@ protected: SG::WriteHandleKey<RPCSimHitCollection> m_simHitValidKey{this, "SimHitValidationKey", "InputRpcHits"}; ServiceHandle<IAthRNGSvc> m_rndmSvc{this, "RndmSvc", "AthRNGSvc", ""}; // Random number service - ITagInfoMgr* m_tagInfoMgr{}; // Tag Info Manager Gaudi::Property<std::string> m_RPC_TimeSchema{this, "RPC_TimeSchema", "RPC_TimeSchema", "Tag info name of Rpc Time Info"}; Gaudi::Property<bool> m_sdoAreOnlyDigits{this, "RPCSDOareRPCDigits", true, "decide is SDO deposits are saved for all G4 hits or only for those accepted as digits"}; diff --git a/MuonSpectrometer/MuonDigitization/RPC_Digitization/src/RpcDigitizationTool.cxx b/MuonSpectrometer/MuonDigitization/RPC_Digitization/src/RpcDigitizationTool.cxx index 683ce0cfc721e4a746fe1171c0aaf3a05a9a25fa..39a6293a058158c49ff8dd20360e3c24e5111fb5 100644 --- a/MuonSpectrometer/MuonDigitization/RPC_Digitization/src/RpcDigitizationTool.cxx +++ b/MuonSpectrometer/MuonDigitization/RPC_Digitization/src/RpcDigitizationTool.cxx @@ -150,52 +150,85 @@ StatusCode RpcDigitizationTool::initialize() { ATH_MSG_DEBUG("Output digits: '" << m_outputDigitCollectionKey.key() << "'"); // set the configuration based on run1/run2 - // Retrieve geometry config information from the database (RUN1, RUN2, etc...) - IRDBAccessSvc* rdbAccess(nullptr); - ATH_CHECK(service("RDBAccessSvc", rdbAccess)); - - enum DataPeriod {Unknown, Run1, Run2, Run3, Run4 }; - DataPeriod run = Unknown; - - std::string configVal = ""; - const IGeoModelSvc* geoModel(nullptr); - ATH_CHECK(service("GeoModelSvc", geoModel)); - // check the DetDescr version - std::string atlasVersion = geoModel->atlasVersion(); - - IRDBRecordset_ptr atlasCommonRec = rdbAccess->getRecordsetPtr("AtlasCommon", atlasVersion, "ATLAS"); - if (atlasCommonRec->size() == 0) { - run = Run1; - } else { - configVal = (*atlasCommonRec)[0]->getString("CONFIG"); - ATH_MSG_INFO("From DD Database, Configuration is " << configVal); - if (configVal == "RUN1") { - run = Run1; - } else if (configVal == "RUN2") { - run = Run2; - } else if (configVal == "RUN3") { - run = Run3; - } else if (configVal == "RUN4") { - run = Run4; - } - if (run == DataPeriod::Unknown) { - ATH_MSG_FATAL("Unexpected value for geometry config read from the database: " << configVal); - return StatusCode::FAILURE; - } - } - if (run == Run3 && m_idHelper->gasGapMax() < 3) - ATH_MSG_WARNING("Run3, configVal = " << configVal << " and GasGapMax =" << m_idHelper->gasGapMax()); + ATH_CHECK(initializeRunDependentParameters()); - if (run == Run1) - ATH_MSG_INFO("From Geometry DB: MuonSpectrometer configuration is: RUN1 or MuonGeometry = R.06"); - else if (run == Run2) - ATH_MSG_INFO("From Geometry DB: MuonSpectrometer configuration is: RUN2 or MuonGeometry = R.07"); - else if (run == Run3) - ATH_MSG_INFO("From Geometry DB: MuonSpectrometer configuration is: RUN3 or MuonGeometry = R.09"); - else if (run == Run4) - ATH_MSG_INFO("From Geometry DB: MuonSpectrometer configuration is: RUN4 or MuonGeometry = R.10"); - - if (m_ignoreRunDepConfig == false) { + ATH_MSG_DEBUG("Ready to read parameters for cluster simulation from file"); + + ATH_CHECK(m_rndmSvc.retrieve()); + + // fill the taginfo information + ATH_CHECK(fillTagInfo()); + + ATH_CHECK(m_readKey.initialize(m_RPCInfoFromDb)); + + ///////////////////// special test + // m_turnON_clustersize=false; + m_BOF_id = m_idHelper->stationNameIndex("BOF"); + m_BOG_id = m_idHelper->stationNameIndex("BOG"); + m_BOS_id = m_idHelper->stationNameIndex("BOS"); + m_BIL_id = m_idHelper->stationNameIndex("BIL"); + m_BIS_id = m_idHelper->stationNameIndex("BIS"); + m_muonHelper = RpcHitIdHelper::GetHelper(m_idHelper->gasGapMax()); + + return StatusCode::SUCCESS; +} + +StatusCode RpcDigitizationTool::initializeRunDependentParameters() { + // TODO This should all be in a conditions Alg + // Retrieve geometry config information from the database (RUN1, RUN2, etc...) + SmartIF<IGeoModelSvc> geoModel{Gaudi::svcLocator()->service("GeoModelSvc")}; + if ( !geoModel ) { + ATH_MSG_ERROR("Could not locate GeoModelSvc"); + return StatusCode::FAILURE; + } + + // check the DetDescr version + std::string atlasVersion = geoModel->atlasVersion(); + + SmartIF<IRDBAccessSvc> rdbAccess{Gaudi::svcLocator()->service("RDBAccessSvc")}; + if ( !rdbAccess ) { + ATH_MSG_ERROR("Could not locate RDBAccessSvc"); + return StatusCode::FAILURE; + } + + enum DataPeriod {Unknown, Run1, Run2, Run3, Run4 }; + DataPeriod run = Unknown; + + std::string configVal = ""; + + IRDBRecordset_ptr atlasCommonRec = rdbAccess->getRecordsetPtr("AtlasCommon", atlasVersion, "ATLAS"); + if (atlasCommonRec->size() == 0) { + run = Run1; + } else { + configVal = (*atlasCommonRec)[0]->getString("CONFIG"); + ATH_MSG_INFO("From DD Database, Configuration is " << configVal); + if (configVal == "RUN1") { + run = Run1; + } else if (configVal == "RUN2") { + run = Run2; + } else if (configVal == "RUN3") { + run = Run3; + } else if (configVal == "RUN4") { + run = Run4; + } + if (run == DataPeriod::Unknown) { + ATH_MSG_FATAL("Unexpected value for geometry config read from the database: " << configVal); + return StatusCode::FAILURE; + } + } + if (run == Run3 && m_idHelper->gasGapMax() < 3) + ATH_MSG_WARNING("Run3, configVal = " << configVal << " and GasGapMax =" << m_idHelper->gasGapMax()); + + if (run == Run1) + ATH_MSG_INFO("From Geometry DB: MuonSpectrometer configuration is: RUN1 or MuonGeometry = R.06"); + else if (run == Run2) + ATH_MSG_INFO("From Geometry DB: MuonSpectrometer configuration is: RUN2 or MuonGeometry = R.07"); + else if (run == Run3) + ATH_MSG_INFO("From Geometry DB: MuonSpectrometer configuration is: RUN3 or MuonGeometry = R.09"); + else if (run == Run4) + ATH_MSG_INFO("From Geometry DB: MuonSpectrometer configuration is: RUN4 or MuonGeometry = R.10"); + + if (m_ignoreRunDepConfig == false) { m_BOG_BOF_DoubletR2_OFF = false; m_Efficiency_fromCOOL = false; m_ClusterSize_fromCOOL = false; @@ -244,26 +277,6 @@ StatusCode RpcDigitizationTool::initialize() { ATH_MSG_DEBUG("......RPC KillDeadStrips " << m_kill_deadstrips); ATH_MSG_DEBUG("......RPC CutProjectedTracks " << m_CutProjectedTracks); - ATH_MSG_DEBUG("Ready to read parameters for cluster simulation from file"); - - ATH_CHECK(m_rndmSvc.retrieve()); - - // get TagInfoMgr - ATH_CHECK(service("TagInfoMgr", m_tagInfoMgr)); - - // fill the taginfo information - ATH_CHECK(fillTagInfo()); - - ATH_CHECK(m_readKey.initialize(m_RPCInfoFromDb)); - - ///////////////////// special test - // m_turnON_clustersize=false; - m_BOF_id = m_idHelper->stationNameIndex("BOF"); - m_BOG_id = m_idHelper->stationNameIndex("BOG"); - m_BOS_id = m_idHelper->stationNameIndex("BOS"); - m_BIL_id = m_idHelper->stationNameIndex("BIL"); - m_BIS_id = m_idHelper->stationNameIndex("BIS"); - m_muonHelper = RpcHitIdHelper::GetHelper(m_idHelper->gasGapMax()); return StatusCode::SUCCESS; } @@ -1043,7 +1056,9 @@ void RpcDigitizationTool::UnPackMCTruth(double theWord, float& proptime, float& //-------------------------------------------- StatusCode RpcDigitizationTool::fillTagInfo() { - if (!m_tagInfoMgr) return StatusCode::FAILURE; + // get TagInfoMgr + SmartIF<ITagInfoMgr> tagInfoMgr{Gaudi::svcLocator()->service("TagInfoMgr")}; // Tag Info Manager + if (!tagInfoMgr) { return StatusCode::FAILURE; } std::string RpctimeSchema = ""; std::stringstream RpctimeShift; @@ -1055,15 +1070,15 @@ StatusCode RpcDigitizationTool::fillTagInfo() { RpctimeSchema = "G4like_TOFon_TimeShift" + RpctimeShift.str() + "nsec"; } - StatusCode sc = m_tagInfoMgr->addTag(m_RPC_TimeSchema, RpctimeSchema); + StatusCode sc = tagInfoMgr->addTag(m_RPC_TimeSchema, RpctimeSchema); if (sc.isFailure()) { ATH_MSG_WARNING(m_RPC_TimeSchema << " " << RpctimeSchema << " not added to TagInfo "); return sc; - } else { - ATH_MSG_DEBUG(m_RPC_TimeSchema << " " << RpctimeSchema << " added to TagInfo "); } + ATH_MSG_DEBUG(m_RPC_TimeSchema << " " << RpctimeSchema << " added to TagInfo "); + return StatusCode::SUCCESS; } diff --git a/MuonSpectrometer/MuonDigitization/TGC_Digitization/src/TgcDigitMaker.cxx b/MuonSpectrometer/MuonDigitization/TGC_Digitization/src/TgcDigitMaker.cxx index 0d377020b9a37ee9dd2b9446754b9a6a4571ee6f..7e391c41ce5549bfebb54d610057f738a8b38d19 100644 --- a/MuonSpectrometer/MuonDigitization/TGC_Digitization/src/TgcDigitMaker.cxx +++ b/MuonSpectrometer/MuonDigitization/TGC_Digitization/src/TgcDigitMaker.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "TgcDigitMaker.h" @@ -22,6 +22,12 @@ #include "MuonSimEvent/TgcHitIdHelper.h" #include "PathResolver/PathResolver.h" +// run number from geometry DB +#include "GaudiKernel/Bootstrap.h" +#include "GeoModelInterfaces/IGeoModelSvc.h" +#include "RDBAccessSvc/IRDBAccessSvc.h" +#include "RDBAccessSvc/IRDBRecord.h" +#include "RDBAccessSvc/IRDBRecordset.h" //--------------------------------------------------- // Constructor and Destructor @@ -29,12 +35,10 @@ //----- Constructor TgcDigitMaker::TgcDigitMaker(const TgcHitIdHelper* hitIdHelper, - const MuonGM::MuonDetectorManager* mdManager, - unsigned int runperiod, const bool doFourBunch) + const MuonGM::MuonDetectorManager* mdManager, const bool doFourBunch) : AthMessaging("TgcDigitMaker"), m_doFourBunchDigitization(doFourBunch) { m_hitIdHelper = hitIdHelper; m_mdManager = mdManager; - m_runperiod = runperiod; m_idHelper = nullptr; m_efficiency[kWIRE] = m_efficiency[kSTRIP] = 1.000; // 100% efficiency for TGCSimHit_p1 @@ -49,9 +53,6 @@ TgcDigitMaker::TgcDigitMaker(const TgcHitIdHelper* hitIdHelper, m_bunchCrossingTime = 24.95; // 24.95 ns =(40.08 MHz)^(-1) } -//----- Destructor -TgcDigitMaker::~TgcDigitMaker() = default; - //------------------------------------------------------ // Initialize //------------------------------------------------------ @@ -768,7 +769,53 @@ StatusCode TgcDigitMaker::readFileOfEnergyThreshold() { return StatusCode::SUCCESS; } +//-------------------------------------------- +unsigned int TgcDigitMaker::getRunPeriod() const +{ + // Used to determine the version of the TGC Dead Chambers text file to read. + // TODO There must be a better way of doing this -> ConditionsAlg? + SmartIF<IGeoModelSvc> geoModel{Gaudi::svcLocator()->service("GeoModelSvc")}; + if (!geoModel) { + ATH_MSG_ERROR("getRunPeriod() Failed to find GeoModelSvc"); + return 0; + } + std::string atlasVersion = geoModel->atlasVersion(); + + SmartIF<IRDBAccessSvc> rdbAccess{Gaudi::svcLocator()->service("RDBAccessSvc")}; + if (!rdbAccess) { + ATH_MSG_ERROR("getRunPeriod() Failed to find RDBAccessSvc"); + return 0; + } + + IRDBRecordset_ptr atlasCommonRec = + rdbAccess->getRecordsetPtr("AtlasCommon", atlasVersion, "ATLAS"); + unsigned int runperiod = 1; + if (atlasCommonRec->size() == 0) + runperiod = 1; + else { + std::string configVal = (*atlasCommonRec)[0]->getString("CONFIG"); + if (configVal == "RUN1") + runperiod = 1; + else if (configVal == "RUN2") + runperiod = 2; + else if (configVal == "RUN3") + runperiod = + 3; // currently runperiod 3 means no masking => ok for upgrade + else if (configVal == "RUN4") + runperiod = + 3; // currently runperiod 3 means no masking => ok for upgrade + else { + runperiod = 0; + ATH_MSG_ERROR( + "Unexpected value for geometry config read from the database: " + << configVal); + } + } + return runperiod; +} + StatusCode TgcDigitMaker::readFileOfDeadChamber() { + // TODO There must be a better way of doing this -> ConditionsAlg? // Indices to be used int iStationName, stationEta, stationPhi, gasGap; @@ -783,16 +830,22 @@ StatusCode TgcDigitMaker::readFileOfDeadChamber() { } } + unsigned int runperiod = getRunPeriod(); + if (runperiod==0) { + ATH_MSG_FATAL("Could not determine run period."); + return StatusCode::FAILURE; + } + // Find path to the TGC_Digitization_deadChamber.dat file std::string fileName; - if (m_runperiod == 1) + if (runperiod == 1) fileName = "TGC_Digitization_deadChamber.dat"; - else if (m_runperiod == 2) + else if (runperiod == 2) fileName = "TGC_Digitization_2016deadChamber.dat"; - else if (m_runperiod == 3) + else if (runperiod == 3) fileName = "TGC_Digitization_NOdeadChamber.dat"; else { - ATH_MSG_ERROR("Run Period " << m_runperiod + ATH_MSG_ERROR("Run Period " << runperiod << " is unexpected in TgcDigitMaker - " "using NOdeadChamber configuration."); return StatusCode::FAILURE; diff --git a/MuonSpectrometer/MuonDigitization/TGC_Digitization/src/TgcDigitMaker.h b/MuonSpectrometer/MuonDigitization/TGC_Digitization/src/TgcDigitMaker.h index d411d133d6e333e189b5d799f0e0ef11ca2bd6c3..0f20868305682db87f92f817d52cf26535860df3 100644 --- a/MuonSpectrometer/MuonDigitization/TGC_Digitization/src/TgcDigitMaker.h +++ b/MuonSpectrometer/MuonDigitization/TGC_Digitization/src/TgcDigitMaker.h @@ -41,9 +41,9 @@ class TgcDigitMaker : public AthMessaging { public: TgcDigitMaker(const TgcHitIdHelper* hitIdHelper, const MuonGM::MuonDetectorManager* mdManager, - unsigned int runperiod, const bool doFourBunch); + const bool doFourBunch); - virtual ~TgcDigitMaker(); + virtual ~TgcDigitMaker() = default; /** Initializes TgcHitIdHelper, TgcIdHelper and random number @@ -175,7 +175,9 @@ class TgcDigitMaker : public AthMessaging { const TgcSensor sensor, const unsigned int index_prob) ; - private: + /** Determine the run period */ + unsigned int getRunPeriod() const; + /** Energy threshold value for each chamber */ double m_energyThreshold[N_STATIONNAME][N_STATIONETA][N_STATIONPHI] [N_GASGAP][N_ISSTRIP]{}; @@ -187,11 +189,10 @@ class TgcDigitMaker : public AthMessaging { std::vector<std::vector<float> > m_vecAngle_Time; - const TgcHitIdHelper* m_hitIdHelper; - unsigned int m_runperiod; + const TgcHitIdHelper* m_hitIdHelper{}; const MuonGM::MuonDetectorManager* - m_mdManager; // cannot use ReadCondHandleKey since no athena component - const TgcIdHelper* m_idHelper; + m_mdManager{}; // cannot use ReadCondHandleKey since no athena component + const TgcIdHelper* m_idHelper{}; float m_efficiency[N_SENSOR]{}; /** diff --git a/MuonSpectrometer/MuonDigitization/TGC_Digitization/src/TgcDigitizationTool.cxx b/MuonSpectrometer/MuonDigitization/TGC_Digitization/src/TgcDigitizationTool.cxx index b6f2e8bf682a06afca0c7b6c3626980ec2d91420..a6cf75a8b8b40170f1c4ced8149ee6b9ea696237 100644 --- a/MuonSpectrometer/MuonDigitization/TGC_Digitization/src/TgcDigitizationTool.cxx +++ b/MuonSpectrometer/MuonDigitization/TGC_Digitization/src/TgcDigitizationTool.cxx @@ -20,12 +20,6 @@ #include "TgcDigitMaker.h" #include "xAODEventInfo/EventInfo.h" -// run number from geometry DB -#include "GeoModelInterfaces/IGeoModelSvc.h" -#include "RDBAccessSvc/IRDBAccessSvc.h" -#include "RDBAccessSvc/IRDBRecord.h" -#include "RDBAccessSvc/IRDBRecordset.h" - TgcDigitizationTool::TgcDigitizationTool(const std::string& type, const std::string& name, const IInterface* parent) @@ -78,40 +72,8 @@ StatusCode TgcDigitizationTool::initialize() { ATH_MSG_DEBUG("IncludePileUpTruth: " << m_includePileUpTruth); ATH_MSG_DEBUG("VetoPileUpTruthLinks: " << m_vetoPileUpTruthLinks); - const IGeoModelSvc* geoModel = nullptr; - CHECK(service("GeoModelSvc", geoModel)); - std::string atlasVersion = geoModel->atlasVersion(); - - IRDBAccessSvc* rdbAccess = nullptr; - CHECK(service("RDBAccessSvc", rdbAccess)); - - IRDBRecordset_ptr atlasCommonRec = - rdbAccess->getRecordsetPtr("AtlasCommon", atlasVersion, "ATLAS"); - unsigned int runperiod = 1; - if (atlasCommonRec->size() == 0) - runperiod = 1; - else { - std::string configVal = (*atlasCommonRec)[0]->getString("CONFIG"); - if (configVal == "RUN1") - runperiod = 1; - else if (configVal == "RUN2") - runperiod = 2; - else if (configVal == "RUN3") - runperiod = - 3; // currently runperiod 3 means no masking => ok for upgrade - else if (configVal == "RUN4") - runperiod = - 3; // currently runperiod 3 means no masking => ok for upgrade - else { - ATH_MSG_FATAL( - "Unexpected value for geometry config read from the database: " - << configVal); - return StatusCode::FAILURE; - } - } - // initialize class to execute digitization - m_digitizer = new TgcDigitMaker(m_hitIdHelper, m_mdManager, runperiod, + m_digitizer = new TgcDigitMaker(m_hitIdHelper, m_mdManager, m_doFourBunchDigitization); m_digitizer->setLevel(static_cast<MSG::Level>(msgLevel())); ATH_CHECK(m_rndmSvc.retrieve());