From d273d7f9b23db023848462ea448e1e6ce2396277 Mon Sep 17 00:00:00 2001 From: Paul Nathaniel Swallow <paul.nathaniel.swallow@cern.ch> Date: Wed, 8 May 2024 09:26:41 +0200 Subject: [PATCH] Improving hashing for BIL Improving hashing for BIL with adding the zIndex and changing multidimensional array to a std_unordered map with some input from Johannes --- .../MuonIdHelpers/MuonIdHelpers/RpcIdHelper.h | 6 +- .../MuonIdHelpers/src/MuonIdHelperSvc.cxx | 4 +- .../MuonIdHelpers/src/RpcIdHelper.cxx | 96 ++++++++++--------- .../MuonGeoModelTestR4/python/testGeoModel.py | 6 +- 4 files changed, 59 insertions(+), 53 deletions(-) diff --git a/MuonSpectrometer/MuonIdHelpers/MuonIdHelpers/RpcIdHelper.h b/MuonSpectrometer/MuonIdHelpers/MuonIdHelpers/RpcIdHelper.h index eda09ac60cc5..8b5c6017e725 100644 --- a/MuonSpectrometer/MuonIdHelpers/MuonIdHelpers/RpcIdHelper.h +++ b/MuonSpectrometer/MuonIdHelpers/MuonIdHelpers/RpcIdHelper.h @@ -180,8 +180,8 @@ private: int init_id_to_hashes(); int zIndex(const Identifier& id) const; static int zIndex(const std::string& name, int eta, int dR, int dZ, int dP) ; - unsigned int m_module_hashes[60][20][8][2]{}; - unsigned int m_detectorElement_hashes[60][20][8][2][4]{}; + std::unordered_map<Identifier, unsigned int> m_module_hashes; + std::unordered_map<Identifier, unsigned int > m_detectorElement_hashes; // compact id indices size_type m_DOUBLETR_INDEX{0}; @@ -233,6 +233,8 @@ private: StripMax = 99 }; unsigned int m_gasGapMax{UINT_MAX}; // maximum number of gas gaps + int m_st_BMS{-1}; + int m_st_BIL{-1}; }; // For backwards compatibility diff --git a/MuonSpectrometer/MuonIdHelpers/src/MuonIdHelperSvc.cxx b/MuonSpectrometer/MuonIdHelpers/src/MuonIdHelperSvc.cxx index d92d19f387cc..7b1fa464c72f 100644 --- a/MuonSpectrometer/MuonIdHelpers/src/MuonIdHelperSvc.cxx +++ b/MuonSpectrometer/MuonIdHelpers/src/MuonIdHelperSvc.cxx @@ -775,7 +775,7 @@ namespace Muon { else if (isMM(id)) return moduleHash(*m_mmIdHelper, id); else if (issTgc(id)) return moduleHash(*m_stgcIdHelper, id); else if (isCsc(id)) return moduleHash(*m_cscIdHelper, id); - ATH_MSG_WARNING("No muon Identifier "<<id); + ATH_MSG_WARNING("moduleHash(): No muon Identifier "<<id); return IdentifierHash{}; } IdentifierHash MuonIdHelperSvc::detElementHash(const Identifier& id) const { @@ -785,7 +785,7 @@ namespace Muon { else if (isMM(id)) return detElementHash(*m_mmIdHelper, id); else if (issTgc(id)) return detElementHash(*m_stgcIdHelper, id); else if (isCsc(id)) return detElementHash(*m_cscIdHelper, id); - ATH_MSG_WARNING("No muon Identifier "<<id); + ATH_MSG_WARNING("detElementHash(): No muon Identifier "<<id); return IdentifierHash{}; } diff --git a/MuonSpectrometer/MuonIdHelpers/src/RpcIdHelper.cxx b/MuonSpectrometer/MuonIdHelpers/src/RpcIdHelper.cxx index 8227e5f78973..21c363b49e57 100644 --- a/MuonSpectrometer/MuonIdHelpers/src/RpcIdHelper.cxx +++ b/MuonSpectrometer/MuonIdHelpers/src/RpcIdHelper.cxx @@ -2,22 +2,13 @@ Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ +#include <iostream> #include "MuonIdHelpers/RpcIdHelper.h" RpcIdHelper::RpcIdHelper() : MuonIdHelper("RpcIdHelper") {} // Initialize dictionary int RpcIdHelper::initialize_from_dictionary(const IdDictMgr& dict_mgr) { - int status = 0; - constexpr int detHashSize = sizeof(m_detectorElement_hashes) / sizeof(unsigned int); - constexpr int modHashSize = sizeof(m_module_hashes) / sizeof(unsigned int); - for (int h = 0; h < detHashSize ; ++h) { - unsigned int* e = &(m_detectorElement_hashes[0][0][0][0][0])+ h; - (*e) = -1; - } - for (int h = 0; h < modHashSize ; ++h) { - unsigned int* e = &(m_module_hashes[0][0][0][0])+ h; - (*e) = -1; - } + int status = 0; // Check whether this helper should be reinitialized if (!reinitialize(dict_mgr)) { @@ -281,50 +272,64 @@ int RpcIdHelper::initialize_from_dictionary(const IdDictMgr& dict_mgr) { int RpcIdHelper::init_id_to_hashes() { unsigned int hash_max = module_hash_max(); - for (unsigned int i = 0; i < hash_max; ++i) { - Identifier id = m_module_vec[i]; - int station = stationName(id); - int eta = stationEta(id) + 10; // for negative etas - int phi = stationPhi(id); - int dR = doubletR(id); - m_module_hashes[station][eta - 1][phi - 1][dR - 1] = i; + for (unsigned int i = 0; i < hash_max; ++i) { + const Identifier& id = m_module_vec[i]; + m_module_hashes[id] = i; } hash_max = detectorElement_hash_max(); for (unsigned int i = 0; i < hash_max; ++i) { - Identifier id = m_detectorElement_vec[i]; - int station = stationName(id); - int eta = stationEta(id) + 10; // for negative eta - int phi = stationPhi(id); - int dR = doubletR(id); - int zIdx = zIndex(id); - m_detectorElement_hashes[station][eta - 1][phi - 1][dR - 1][zIdx - 1] = i; + const Identifier& id = m_detectorElement_vec[i]; + m_detectorElement_hashes[id] = i; } + m_st_BMS = stationNameIndex("BMS"); + m_st_BIL = stationNameIndex("BIL"); return 0; } int RpcIdHelper::get_module_hash(const Identifier& id, IdentifierHash& hash_id) const { - // Identifier moduleId = elementID(id); - // IdContext context = module_context(); - // return get_hash(moduleId,hash_id,&context); - int station = stationName(id); - int eta = stationEta(id) + 10; // for negative etas - int phi = stationPhi(id); - int dR = doubletR(id); - hash_id = m_module_hashes[station][eta - 1][phi - 1][dR - 1]; + const auto itr = m_module_hashes.find(parentID(id)); + if (itr == m_module_hashes.end()) { + hash_id = IdentifierHash(-1); + return 1; + } + hash_id = itr->second; return 0; } int RpcIdHelper::get_detectorElement_hash(const Identifier& id, IdentifierHash& hash_id) const { - // Identifier detectorElementId = detectorElementID(id); - // IdContext context = detectorElement_context(); - // return get_hash(detectorElementId,hash_id,&context); - int station = stationName(id); - int eta = stationEta(id) + 10; // for negative eta - int phi = stationPhi(id); - int dR = doubletR(id); - int zIdx = zIndex(id); - hash_id = m_detectorElement_hashes[station][eta - 1][phi - 1][dR - 1][zIdx - 1]; + Identifier detElId = id; + // Certain chambers require doublet Phi in hashing (See zIndex()) - do not reset m_dpb_impl in these cases + bool reset_dbp = true; + const int station = stationName(id); + + if (m_st_BMS == station) { + int eta = stationEta(id); + int dR = doubletR(id); + int dZ = doubletZ(id); + if (std::abs(eta) == 2 && dZ == 3) { + reset_dbp = false; + } else if (std::abs(eta) == 4 && dR == 2 && dZ == 3) { + reset_dbp = false; + } else if (std::abs(eta) == 4 && dR == 1 && dZ == 2) { + reset_dbp = false; + } + } else if (m_st_BIL == station && std::abs(stationEta(id)) == 2) { + reset_dbp = false; + } + + if (reset_dbp) m_dbp_impl.reset(detElId); + m_gap_impl.reset(detElId); + m_mea_impl.reset(detElId); + m_str_impl.reset(detElId); + + auto itr = m_detectorElement_hashes.find(detElId); + if (itr == m_detectorElement_hashes.end()) { + ATH_MSG_VERBOSE("Cannot find a valid detector element hash for "<<print_to_string(id)); + hash_id = IdentifierHash(-1); + return 1; + } + hash_id = itr->second; return 0; } @@ -871,7 +876,7 @@ Identifier RpcIdHelper::elementID(const Identifier& id) const { return parentID( /* Identifier panelID (const Identifier& padID, int gasGap,) const; */ /* Identifier panelID (const Identifier& channelID) const; */ /* Identifier panelID (int stationName, int stationEta, int stationPhi, int doubletR, */ -/* int doubletZ, int doubletPhi,int gasGap,) const; */ +/* int doubletZ, int doubletPhi,int gasGap,) const; */ Identifier RpcIdHelper::panelID(int stationName, int stationEta, int stationPhi, int doubletR, int doubletZ, int doubletPhi, int gasGap, int measuresPhi) const { @@ -1188,6 +1193,9 @@ int RpcIdHelper::zIndex(const std::string& name, int eta, int dR, int dZ, int dP } else if (abs(eta) == 4 && dR == 1 && dZ == 2) { if (dP == 2) dbz_index++; } + } else if (name == "BIL") { + if (abs(eta) == 2 && dP == 2) dbz_index++; } + return dbz_index; -} \ No newline at end of file +} diff --git a/MuonSpectrometer/MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py b/MuonSpectrometer/MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py index 640e9ccccdbc..9fa95788d183 100644 --- a/MuonSpectrometer/MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py +++ b/MuonSpectrometer/MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/python/testGeoModel.py @@ -147,7 +147,6 @@ def setupGeoR4TestCfg(args, setupSimJob = False): flags.Scheduler.AutoLoadUnmetDependencies = True flags.PerfMon.doFullMonMT = True - flags.lock() flags.dump(evaluate = True) if not flags.Muon.usePhaseIIGeoSetup: @@ -166,15 +165,12 @@ def executeTest(cfg, num_events = 1): cfg.printConfig(withDetails=True, summariseProps=True) if not cfg.run(num_events).isSuccess(): exit(1) + if __name__=="__main__": args = SetupArgParser().parse_args() flags, cfg = setupGeoR4TestCfg(args) cfg.merge(setupHistSvcCfg(flags, out_file = args.outRootFile)) chambToTest = args.chambers if len([x for x in args.chambers if x =="all"]) ==0 else [] - - cfg.getService("MessageSvc").setVerbose = [] - cfg.getService("MessageSvc").warningLimit = 1000000 - cfg.getService("MessageSvc").verboseLimit = 1000000 if flags.Detector.GeometryMDT: cfg.merge(GeoModelMdtTestCfg(flags, -- GitLab