From a0d919ef5728c6b8f8db907c0e5bb583c3c4b43c Mon Sep 17 00:00:00 2001 From: Juraj Smiesko <34742917+kjvbrt@users.noreply.github.com> Date: Thu, 26 Oct 2023 10:33:07 +0200 Subject: [PATCH] Removing specialized handles for positions tool (#53) --- .../CreateCaloCellPositionsFCCee.cpp | 71 +++---------------- .../components/CreateCaloCellPositionsFCCee.h | 51 ++----------- .../tests/options/reproduceSegfault.py | 4 +- .../tests/options/runCaloSim.py | 4 +- 4 files changed, 20 insertions(+), 110 deletions(-) diff --git a/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.cpp b/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.cpp index 5609ab12..40503a05 100644 --- a/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.cpp +++ b/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.cpp @@ -15,49 +15,20 @@ DECLARE_COMPONENT(CreateCaloCellPositionsFCCee) CreateCaloCellPositionsFCCee::CreateCaloCellPositionsFCCee(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) { declareProperty("hits", m_hits, "Hit collection (input)"); - declareProperty("positionsECalBarrelTool", m_cellPositionsECalBarrelTool, - "Handle for tool to retrieve cell positions in ECal Barrel"); - declareProperty("positionsHCalBarrelTool", m_cellPositionsHCalBarrelTool, - "Handle for tool to retrieve cell positions in HCal Barrel and ext Barrel"); - declareProperty("positionsHCalExtBarrelTool", m_cellPositionsHCalExtBarrelTool, - "Handle for tool to retrieve cell positions in HCal Barrel and ext Barrel"); - declareProperty("positionsEMECTool", m_cellPositionsEMECTool, "Handle for tool to retrieve cell positions in EMEC"); - declareProperty("positionsHECTool", m_cellPositionsHECTool, "Handle for tool to retrieve cell positions in HEC"); - declareProperty("positionsEMFwdTool", m_cellPositionsEMFwdTool, "Handle for tool to retrieve cell positions EM Fwd"); - declareProperty("positionsHFwdTool", m_cellPositionsHFwdTool, "Handle for tool to retrieve cell positions Had Fwd"); - declareProperty("positionedHits", m_positionedHits, "Output cell positions collection"); + declareProperty("positionsTool", m_cellPositionsTool, + "Handle for tool to retrieve cell positions from"); + declareProperty("positionedHits", m_positionedHits, + "Output cell positions collection"); } StatusCode CreateCaloCellPositionsFCCee::initialize() { - StatusCode sc = GaudiAlgorithm::initialize(); - if (sc.isFailure()) return sc; - - if (!m_cellPositionsECalBarrelTool) { - error() << "CellPositionsTool for ECal Barrel is missing!" << endmsg; - return StatusCode::FAILURE; - } - if (!m_cellPositionsHCalBarrelTool) { - error() << "CellPositionsTool for HCal Barrel is missing!" << endmsg; - return StatusCode::FAILURE; + { + StatusCode sc = GaudiAlgorithm::initialize(); + if (sc.isFailure()) return sc; } - if (!m_cellPositionsHCalExtBarrelTool) { - error() << "CellPositionsTool for HCal Ext Barrel is missing!" << endmsg; - return StatusCode::FAILURE; - } - if (!m_cellPositionsEMECTool) { - error() << "CellPositionsTool for EMEC is missing!" << endmsg; - return StatusCode::FAILURE; - } - if (!m_cellPositionsHECTool) { - error() << "CellPositionsTool for HEC is missing!" << endmsg; - return StatusCode::FAILURE; - } - if (!m_cellPositionsEMFwdTool) { - error() << "CellPositionsTool for EMFwd is missing!" << endmsg; - return StatusCode::FAILURE; - } - if (!m_cellPositionsHFwdTool) { - error() << "CellPositionsTool for HFwd is missing!" << endmsg; + + if (!m_cellPositionsTool) { + error() << "CellPositionsTool is missing!" << endmsg; return StatusCode::FAILURE; } @@ -82,27 +53,7 @@ StatusCode CreateCaloCellPositionsFCCee::execute() { auto cached_pos = m_positions_cache.find(cellId); if(cached_pos == m_positions_cache.end()) { // identify calo system - auto systemId = m_decoder->get(cellId, m_system_id); - dd4hep::Position posCell; - - if (systemId == m_systemIdECalBarrel) { // ECAL BARREL system id - posCell = m_cellPositionsECalBarrelTool->xyzPosition(cellId); - } else if (systemId == m_systemIdHCalBarrel) { // HCAL BARREL system id - posCell = m_cellPositionsHCalBarrelTool->xyzPosition(cellId); - } else if (systemId == m_systemIdHCalExtBarrel) { // HCAL EXT BARREL - posCell = m_cellPositionsHCalExtBarrelTool->xyzPosition(cellId); - } else if (systemId == m_systemIdEMEC) { // EMEC system id - posCell = m_cellPositionsEMECTool->xyzPosition(cellId); - } else if (systemId == m_systemIdHEC) { // HEC system id - posCell = m_cellPositionsHECTool->xyzPosition(cellId); - } else if (systemId == m_systemIdEMFwd) { // EMFWD system id - posCell = m_cellPositionsEMFwdTool->xyzPosition(cellId); - } else if (systemId == m_systemIdHFwd) { // HFWD system id - posCell = m_cellPositionsHFwdTool->xyzPosition(cellId); - } else { - error() << "Unknown system ID!" << endmsg; - return StatusCode::FAILURE; - } + dd4hep::Position posCell = m_cellPositionsTool->xyzPosition(cellId); edm4hep::Vector3f edmPos; edmPos.x = posCell.x() / dd4hep::mm; diff --git a/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.h b/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.h index 0c8084f8..ee3ec5af 100644 --- a/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.h +++ b/RecFCCeeCalorimeter/src/components/CreateCaloCellPositionsFCCee.h @@ -45,59 +45,18 @@ class CreateCaloCellPositionsFCCee : public GaudiAlgorithm { StatusCode finalize(); private: - /// ECal Barrel System ID - Gaudi::Property m_systemIdECalBarrel { - this, "systemIdECalBarrel", 4, "System ID of ECal Barrel" - }; - /// HCal Barrel System ID - Gaudi::Property m_systemIdHCalBarrel { - this, "systemIdHCalBarrel", 8, "System ID of HCal Barrel" - }; - /// HCal Extended Barrel System ID - Gaudi::Property m_systemIdHCalExtBarrel { - this, "systemIdHCalExtBarrel", 9, "System ID of HCal Extended Barrel" - }; - /// EMEC System ID - Gaudi::Property m_systemIdEMEC { - this, "systemIdEMEC", 6, "System ID of EMEC" - }; - /// HEC System ID - Gaudi::Property m_systemIdHEC { - this, "systemIdHEC", 7, "System ID of HEC" - }; - /// EMFwd System ID - Gaudi::Property m_systemIdEMFwd { - this, "systemIdEMFwd", 999, "System ID of EMFwd" - }; - /// HFwd System ID - Gaudi::Property m_systemIdHFwd { - this, "systemIdHFwd", 999, "System ID of HFwd" - }; - - /// Handle for tool to get positions in ECal Barrel - ToolHandle m_cellPositionsECalBarrelTool{"CellPositionsECalBarrelTool/CellPositionsTool"}; - /// Handle for tool to get positions in HCal Barrel and Ext Barrel, no Segmentation - ToolHandle m_cellPositionsHCalBarrelTool{"CellPositionsHCalBarrelTool/CellPositionsTool"}; - /// Handle for tool to get positions in HCal Barrel and Ext Barrel, no Segmentation - ToolHandle m_cellPositionsHCalExtBarrelTool{"CellPositionsHCalBarrelNoSegTool/CellPositionsTool"}; - /// Handle for tool to get positions in Calo Discs - ToolHandle m_cellPositionsEMECTool{"CellPositionsCaloDiscsTool/CellPositionsTool"}; - /// Handle for tool to get positions in Calo Discs - ToolHandle m_cellPositionsHECTool{"CellPositionsCaloDiscsTool/CellPositionsTool"}; - /// Handle for tool to get positions in Calo Discs - ToolHandle m_cellPositionsEMFwdTool{"CellPositionsCaloDiscsTool/CellPositionsTool"}; - /// Handle for tool to get positions in Calo Discs - ToolHandle m_cellPositionsHFwdTool{"CellPositionsCaloDiscsTool/CellPositionsTool"}; - /// Decoder for system ID - dd4hep::DDSegmentation::BitFieldCoder* m_decoder = new dd4hep::DDSegmentation::BitFieldCoder("system:4"); + /// Handle for tool to get positions width + ToolHandle m_cellPositionsTool{}; /// Input collection DataHandle m_hits{"hits/hits", Gaudi::DataHandle::Reader, this}; + /// Input collection metadata handle MetaDataHandle m_hitsCellIDEncoding{m_hits, "CellIDEncodingString", Gaudi::DataHandle::Reader}; /// Output collection DataHandle m_positionedHits{"hits/positionedHits", Gaudi::DataHandle::Writer, this}; + /// Output collection metadata handle MetaDataHandle m_positionedHitsCellIDEncoding{m_positionedHits, "CellIDEncodingString", Gaudi::DataHandle::Writer}; - int m_system_id = m_decoder->index("system"); + // Cache std::unordered_map m_positions_cache{}; }; diff --git a/RecFCCeeCalorimeter/tests/options/reproduceSegfault.py b/RecFCCeeCalorimeter/tests/options/reproduceSegfault.py index 68966850..e6ca7dae 100644 --- a/RecFCCeeCalorimeter/tests/options/reproduceSegfault.py +++ b/RecFCCeeCalorimeter/tests/options/reproduceSegfault.py @@ -183,7 +183,7 @@ from Configurables import CreateCaloCellPositionsFCCee createEcalBarrelPositionedCells = CreateCaloCellPositionsFCCee("ECalBarrelPositionedCells", OutputLevel = INFO) -createEcalBarrelPositionedCells.positionsECalBarrelTool = cellPositionEcalBarrelTool +createEcalBarrelPositionedCells.positionsTool = cellPositionEcalBarrelTool createEcalBarrelPositionedCells.hits.Path = EcalBarrelCellsName createEcalBarrelPositionedCells.positionedHits.Path = "ECalBarrelPositionedCells" @@ -269,7 +269,7 @@ createEcalBarrelPositionedCaloClusterCells = CreateCaloCellPositionsFCCee("ECalBarrelPositionedCaloClusterCells", OutputLevel = INFO) -createEcalBarrelPositionedCaloClusterCells.positionsECalBarrelTool = cellPositionEcalBarrelTool +createEcalBarrelPositionedCaloClusterCells.positionsTool = cellPositionEcalBarrelTool createEcalBarrelPositionedCaloClusterCells.hits.Path = "CaloClusterCells" createEcalBarrelPositionedCaloClusterCells.positionedHits.Path = "PositionedCaloClusterCells" diff --git a/RecFCCeeCalorimeter/tests/options/runCaloSim.py b/RecFCCeeCalorimeter/tests/options/runCaloSim.py index 9df0ce54..ca67b283 100644 --- a/RecFCCeeCalorimeter/tests/options/runCaloSim.py +++ b/RecFCCeeCalorimeter/tests/options/runCaloSim.py @@ -197,7 +197,7 @@ from Configurables import CreateCaloCellPositionsFCCee createEcalBarrelPositionedCells = CreateCaloCellPositionsFCCee("ECalBarrelPositionedCells") -createEcalBarrelPositionedCells.positionsECalBarrelTool = cellPositionEcalBarrelTool +createEcalBarrelPositionedCells.positionsTool = cellPositionEcalBarrelTool createEcalBarrelPositionedCells.hits.Path = "ECalBarrelCells" createEcalBarrelPositionedCells.positionedHits.Path = "ECalBarrelPositionedCells" ApplicationMgr().TopAlg += [createEcalBarrelPositionedCells] @@ -272,7 +272,7 @@ # Add position to the cells attached to the cluster createEcalBarrelPositionedCaloClusterCells = CreateCaloCellPositionsFCCee("ECalBarrelPositionedCaloClusterCells") -createEcalBarrelPositionedCaloClusterCells.positionsECalBarrelTool = cellPositionEcalBarrelTool +createEcalBarrelPositionedCaloClusterCells.positionsTool = cellPositionEcalBarrelTool createEcalBarrelPositionedCaloClusterCells.hits.Path = "CaloClusterCells" createEcalBarrelPositionedCaloClusterCells.positionedHits.Path = "PositionedCaloClusterCells"