diff --git a/InnerDetector/InDetValidation/InDetPhysValMonitoring/scripts/runIDPVM.py b/InnerDetector/InDetValidation/InDetPhysValMonitoring/scripts/runIDPVM.py index fd5de58118cb65b6450986b507ce2e64853e1e33..52506a9de30de899d959c3f1f42e951555892e53 100755 --- a/InnerDetector/InDetValidation/InDetPhysValMonitoring/scripts/runIDPVM.py +++ b/InnerDetector/InDetValidation/InDetPhysValMonitoring/scripts/runIDPVM.py @@ -107,6 +107,11 @@ acc = MainServicesCfg(flags) from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg acc.merge(PoolReadCfg(flags)) +# Schedule ACTS data pool if requested +if flags.PhysVal.IDPVM.doActs: + from ActsConfig.ActsCollectionsConfig import ActsPoolReadCfg + acc.merge(ActsPoolReadCfg(flags)) + if flags.PhysVal.IDPVM.doPRW: acc.addService(CompFactory.CP.SystematicsSvc("SystematicsSvc")) from AsgAnalysisAlgorithms.PileupReweightingAlgConfig import PileupReweightingAlgCfg diff --git a/Tracking/Acts/ActsCollectionAlgs/CMakeLists.txt b/Tracking/Acts/ActsCollectionAlgs/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9436ede8b3b2d78238e651b8277321e32b4150ea --- /dev/null +++ b/Tracking/Acts/ActsCollectionAlgs/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + +# Declare the package name: +atlas_subdir( ActsCollectionAlgs ) + +# Component(s) in the package: +atlas_add_component( ActsCollectionAlgs + src/*.h src/*.cxx + src/components/*.cxx + LINK_LIBRARIES + AthenaBaseComps + AthLinks + GaudiKernel + StoreGateLib + xAODInDetMeasurement + xAODMeasurementBase + ) diff --git a/Tracking/Acts/ActsCollectionAlgs/src/SpacePointReader.cxx b/Tracking/Acts/ActsCollectionAlgs/src/SpacePointReader.cxx new file mode 100644 index 0000000000000000000000000000000000000000..543bca02a0069a745dadb825f9f73cd8b477a499 --- /dev/null +++ b/Tracking/Acts/ActsCollectionAlgs/src/SpacePointReader.cxx @@ -0,0 +1,70 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +#include "SpacePointReader.h" +#include "xAODMeasurementBase/UncalibratedMeasurementContainer.h" +#include "AthLinks/ElementLink.h" +#include "StoreGate/WriteDecorHandle.h" + +namespace ActsTrk { + + SpacePointReader::SpacePointReader(const std::string& name, + ISvcLocator* pSvcLocator) + : AthReentrantAlgorithm(name, pSvcLocator) + {} + + StatusCode SpacePointReader::initialize() + { + ATH_MSG_DEBUG("Initializing " << name() << " ... "); + + m_clusterDecoration = m_spacePointKey.key() + "." + m_clusterDecoration.key(); + + ATH_MSG_DEBUG("Properties:"); + ATH_MSG_DEBUG(m_spacePointKey); + ATH_MSG_DEBUG(m_clusterDecoration); + + ATH_CHECK(m_spacePointKey.initialize()); + ATH_CHECK(m_clusterDecoration.initialize()); + + return StatusCode::SUCCESS; + } + + StatusCode SpacePointReader::execute(const EventContext& ctx) const + { + ATH_MSG_DEBUG("Executing " << name() << " ..."); + + ATH_MSG_DEBUG("Retrieving input space point collection with key: " << m_spacePointKey.key()); + SG::ReadHandle< xAOD::SpacePointContainer > spHandle = SG::makeHandle( m_spacePointKey, ctx ); + ATH_CHECK(spHandle.isValid()); + const xAOD::SpacePointContainer* spacePoints = spHandle.cptr(); + ATH_MSG_DEBUG("Retrieved " << spacePoints->size() << " elements from space point container"); + + ATH_MSG_DEBUG("Adding decoration to space point collection: bare pointers to clusters"); + ATH_MSG_DEBUG("Decoration name: " << m_clusterDecoration.key()); + using decoration_type = std::vector<const xAOD::UncalibratedMeasurement*>; + SG::WriteDecorHandle< xAOD::SpacePointContainer, + decoration_type > barePointersToClusters( m_clusterDecoration, ctx ); + + ATH_MSG_DEBUG("Retrieving Element Links to Clusters from the Space Points and attaching the bare pointers to the object"); + static const SG::AuxElement::Accessor< std::vector<ElementLink<xAOD::UncalibratedMeasurementContainer>> > accesor("measurementLink"); + for (const xAOD::SpacePoint* sp : *spacePoints) { + if (not accesor.isAvailable(*sp)) { + ATH_MSG_ERROR("Space point does not possess element link to cluster. Decoration `measurementLink` is not available and this should not happen!"); + return StatusCode::FAILURE; + } + + const std::vector< ElementLink< xAOD::UncalibratedMeasurementContainer > >& els = accesor(*sp); + std::vector< const xAOD::UncalibratedMeasurement* > meas; + meas.reserve(els.size()); + for (const ElementLink< xAOD::UncalibratedMeasurementContainer >& el : els) { + meas.push_back(*el); + } + + barePointersToClusters(*sp) = meas; + } + + return StatusCode::SUCCESS; + } + +} diff --git a/Tracking/Acts/ActsCollectionAlgs/src/SpacePointReader.h b/Tracking/Acts/ActsCollectionAlgs/src/SpacePointReader.h new file mode 100644 index 0000000000000000000000000000000000000000..b1b7bd7f727f286cbd1a82197d7931f0c95d6968 --- /dev/null +++ b/Tracking/Acts/ActsCollectionAlgs/src/SpacePointReader.h @@ -0,0 +1,39 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ACTS_COLLECTIONALGS_SPACEPOINTS_H +#define ACTS_COLLECTIONALGS_SPACEPOINTS_H + +#include "AthenaBaseComps/AthReentrantAlgorithm.h" +#include "GaudiKernel/EventContext.h" +#include "StoreGate/ReadHandleKey.h" +#include "StoreGate/WriteDecorHandleKey.h" + +// EDM +#include "xAODInDetMeasurement/SpacePointContainer.h" + +namespace ActsTrk { + +class SpacePointReader + : public AthReentrantAlgorithm { + public: + SpacePointReader(const std::string& name, ISvcLocator* pSvcLocator); + virtual ~SpacePointReader() override = default; + + virtual StatusCode initialize() override; + virtual StatusCode execute(const EventContext&) const override; + + private: + SG::ReadHandleKey< xAOD::SpacePointContainer > m_spacePointKey + {this, "SpacePointKey", "", + "Key for input space point container"}; + + SG::WriteDecorHandleKey< xAOD::SpacePointContainer > m_clusterDecoration + {this, "ClusterDecorationKey", "measurements", + "Decoration key for the cluster bare pointer"}; +}; + +} // namespace ActsTrk + +#endif diff --git a/Tracking/Acts/ActsCollectionAlgs/src/components/ActsCollectionAlgs_entries.cxx b/Tracking/Acts/ActsCollectionAlgs/src/components/ActsCollectionAlgs_entries.cxx new file mode 100644 index 0000000000000000000000000000000000000000..7915b775863e7501669690cad2d97dbe6bb792f3 --- /dev/null +++ b/Tracking/Acts/ActsCollectionAlgs/src/components/ActsCollectionAlgs_entries.cxx @@ -0,0 +1,7 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +#include "src/SpacePointReader.h" + +DECLARE_COMPONENT( ActsTrk::SpacePointReader ) diff --git a/Tracking/Acts/ActsConfig/python/ActsCollectionsConfig.py b/Tracking/Acts/ActsConfig/python/ActsCollectionsConfig.py new file mode 100644 index 0000000000000000000000000000000000000000..706148dbdb52c7174595cd51f72d001fffebe831 --- /dev/null +++ b/Tracking/Acts/ActsConfig/python/ActsCollectionsConfig.py @@ -0,0 +1,26 @@ +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + +from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator +from AthenaConfiguration.ComponentFactory import CompFactory + +def SpacePointReaderCfg(flags, + name: str, + **kwargs) -> ComponentAccumulator: + acc = ComponentAccumulator() + acc.addEventAlgo(CompFactory.ActsTrk.SpacePointReader(name=name, **kwargs)) + return acc + +def ActsPoolReadCfg(flags) -> ComponentAccumulator: + acc = ComponentAccumulator() + + import re + typedCollections = flags.Input.TypedCollections + for col in typedCollections: + match = re.findall(r"xAOD::SpacePointContainer#(\S+)", col) + if match: + spCol = match[0] + acc.merge(SpacePointReaderCfg(flags, + name=f"{spCol}Reader", + SpacePointKey=spCol)) + + return acc diff --git a/Tracking/Acts/ActsMonitoring/src/SpacePointAnalysisAlg.cxx b/Tracking/Acts/ActsMonitoring/src/SpacePointAnalysisAlg.cxx index 6a84096caa903459792bdcbb6d4e356f666bc6ed..19dbe831c1086f7e7666366072c79ff7faf67503 100644 --- a/Tracking/Acts/ActsMonitoring/src/SpacePointAnalysisAlg.cxx +++ b/Tracking/Acts/ActsMonitoring/src/SpacePointAnalysisAlg.cxx @@ -57,12 +57,14 @@ namespace ActsTrk { [[maybe_unused]] const auto idHash = el->identifierHash(); } } else if (sp->isAvailable< std::vector< ElementLink<xAOD::UncalibratedMeasurementContainer> > >("measurementLink")) { - // For now this is still allowed. Once we have a Space Point reader algorithm, thi will imply an error instead - static const SG::AuxElement::Accessor< std::vector< ElementLink<xAOD::UncalibratedMeasurementContainer> > > accCluster("measurementLink"); - const auto& els = accCluster(*sp); - for (const auto& el : els) { - [[maybe_unused]] const auto idHash = (*el)->identifierHash(); - } + // if we are here, that means the bare pointers are not available + // This should not happen + ATH_MSG_ERROR("Space point has Element links but not bare pointers to cluster. This should not happen!"); + return StatusCode::FAILURE; + } else { + // This should never happen + ATH_MSG_ERROR("There are no decorations that link the space point to the original clusters"); + return StatusCode::FAILURE; } } diff --git a/Tracking/Acts/ActsMonitoring/test/ActsReadEDM.py b/Tracking/Acts/ActsMonitoring/test/ActsReadEDM.py index 9f1b03a7cffa9e19c43a31c87fdc2668aae714f5..d6ee59b4016aa4f96acd5065bfe870ed8a4aaee3 100755 --- a/Tracking/Acts/ActsMonitoring/test/ActsReadEDM.py +++ b/Tracking/Acts/ActsMonitoring/test/ActsReadEDM.py @@ -27,6 +27,9 @@ if __name__ == "__main__": from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg acc.merge(PoolReadCfg(flags)) + + from ActsConfig.ActsCollectionsConfig import ActsPoolReadCfg + acc.merge(ActsPoolReadCfg(flags)) if flags.readClusters: if flags.Detector.EnableITkPixel: