diff --git a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithmsDict.h b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithmsDict.h index 5a07aec0b3a51ede12c83e920784befa275713c7..9f772efab8170384410cc28c029408315044334a 100644 --- a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithmsDict.h +++ b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithmsDict.h @@ -12,6 +12,7 @@ #include <AsgAnalysisAlgorithms/AsgFlagSelectionTool.h> #include <AsgAnalysisAlgorithms/AsgPtEtaSelectionTool.h> #include <AsgAnalysisAlgorithms/AsgClassificationDecorationAlg.h> +#include <AsgAnalysisAlgorithms/AsgPriorityDecorationAlg.h> #include <AsgAnalysisAlgorithms/AsgCutBookkeeperAlg.h> #include <AsgAnalysisAlgorithms/AsgEventScaleFactorAlg.h> #include <AsgAnalysisAlgorithms/AsgLeptonTrackSelectionAlg.h> diff --git a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgPriorityDecorationAlg.h b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgPriorityDecorationAlg.h new file mode 100644 index 0000000000000000000000000000000000000000..4a16b6a44c180704f6af25735785c782797eb194 --- /dev/null +++ b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/AsgPriorityDecorationAlg.h @@ -0,0 +1,65 @@ +/* + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration +*/ + +/// @author Tadej Novak <tadej@cern.ch> + +#ifndef ASG_ANALYSIS_ALGORITHMS__ASG_PRIORITY_DECORATION_ALG_H +#define ASG_ANALYSIS_ALGORITHMS__ASG_PRIORITY_DECORATION_ALG_H + +#include <AnaAlgorithm/AnaAlgorithm.h> +#include <SelectionHelpers/SysReadSelectionHandle.h> +#include <SystematicsHandles/SysListHandle.h> +#include <SystematicsHandles/SysReadHandle.h> +#include <xAODBase/IParticleContainer.h> + + +namespace CP +{ + +/// \brief an algorithm for decorating priorities +class AsgPriorityDecorationAlg final : public EL::AnaAlgorithm +{ + /// \brief the standard constructor +public: + AsgPriorityDecorationAlg(const std::string& name, + ISvcLocator* pSvcLocator); + + +public: + virtual StatusCode initialize() override; + +public: + virtual StatusCode execute() override; + + + /// \brief the systematics list we run +private: + SysListHandle m_systematicsList {this}; + + /// \brief the preselection we apply to our input +private: + SysReadSelectionHandleArray m_preselections { + this, "preselections", {}, "the preselections to apply with the highest priority first"}; + + /// \brief particles container handle +private: + SysReadHandle<xAOD::IParticleContainer> m_particlesHandle { + this, "particles", "", "the container to use"}; + + /// \brief the values of the priorities +private: + std::vector<int> m_priorities {}; + + /// \brief the decoration for the priority +private: + std::string m_priorityDecoration {}; + + /// \brief the accessor for \ref m_priorityDecoration +private: + std::unique_ptr<const SG::AuxElement::Decorator<char> > m_priorityDecorator {}; +}; + +} // namespace CP + +#endif diff --git a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/selection.xml b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/selection.xml index f50c3eacb3577567ba96b066bae1484eba746e64..f1944d63ec6b8b82f48c19c8b706d9c55a585725 100644 --- a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/selection.xml +++ b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/AsgAnalysisAlgorithms/selection.xml @@ -9,6 +9,7 @@ <class name="CP::AsgEventScaleFactorAlg" /> <class name="CP::AsgLeptonTrackSelectionAlg" /> <class name="CP::AsgOriginalObjectLinkAlg" /> + <class name="CP::AsgPriorityDecorationAlg" /> <class name="CP::AsgSelectionAlg" /> <class name="CP::AsgViewFromSelectionAlg" /> <class name="CP::AsgxAODNTupleMakerAlg" /> diff --git a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/Root/AsgPriorityDecorationAlg.cxx b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/Root/AsgPriorityDecorationAlg.cxx new file mode 100644 index 0000000000000000000000000000000000000000..544a3033c9cdbb3e01203c4f1fc2c12b31a2e9b4 --- /dev/null +++ b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/Root/AsgPriorityDecorationAlg.cxx @@ -0,0 +1,85 @@ +/* + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration +*/ + +/// @author Tadej Novak <tadej@cern.ch> + + +#include <AsgAnalysisAlgorithms/AsgPriorityDecorationAlg.h> + + +namespace CP +{ + +AsgPriorityDecorationAlg::AsgPriorityDecorationAlg(const std::string &name, + ISvcLocator *pSvcLocator) + : AnaAlgorithm(name, pSvcLocator) +{ + declareProperty ("priorityDecoration", m_priorityDecoration, "the decoration for the priority"); + declareProperty ("priorities", m_priorities, "priorities to use with the highest one first"); +} + + + +StatusCode AsgPriorityDecorationAlg::initialize() +{ + if (m_priorityDecoration.empty()) + { + ANA_MSG_ERROR ("Priority decoration name should not be empty."); + return StatusCode::FAILURE; + } + + if (m_priorities.size() != m_preselections.size()) + { + ANA_MSG_ERROR ("Preselections and priority values need to be of the same size."); + return StatusCode::FAILURE; + } + + if (!std::is_sorted(std::rbegin(m_priorities), std::rend(m_priorities))) + { + ANA_MSG_ERROR ("Priorities need to be provided in reverse order."); + return StatusCode::FAILURE; + } + + m_priorityDecorator = std::make_unique<SG::AuxElement::Decorator<char> > (m_priorityDecoration); + + ANA_CHECK (m_particlesHandle.initialize (m_systematicsList)); + ANA_CHECK (m_preselections.initialize (m_systematicsList, m_particlesHandle)); + ANA_CHECK (m_systematicsList.initialize()); + + return StatusCode::SUCCESS; +} + + + +StatusCode AsgPriorityDecorationAlg::execute() +{ + for (const auto& sys : m_systematicsList.systematicsVector()) + { + const xAOD::IParticleContainer *particles{}; + ANA_CHECK(m_particlesHandle.retrieve(particles, sys)); + + for (const xAOD::IParticle *particle : *particles) + { + bool passed{}; + for (size_t i{}; i < m_preselections.size(); i++) + { + if (m_preselections.at(i).getBool (*particle, sys)) + { + (*m_priorityDecorator)(*particle) = m_priorities[i]; + passed = true; + break; + } + } + + // decorate default priority + if (!passed) + { + (*m_priorityDecorator)(*particle) = 0; + } + } + } + return StatusCode::SUCCESS; +} + +} // namespace CP diff --git a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/src/components/AsgAnalysisAlgorithms_entries.cxx b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/src/components/AsgAnalysisAlgorithms_entries.cxx index 95d84cf630e7f78a2107fb57d122767344e1a092..d9fdd31c0847c98a087dff706c3baa8d6fd1d4a6 100644 --- a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/src/components/AsgAnalysisAlgorithms_entries.cxx +++ b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/src/components/AsgAnalysisAlgorithms_entries.cxx @@ -11,7 +11,8 @@ #include <AsgAnalysisAlgorithms/AsgFlagSelectionTool.h> #include <AsgAnalysisAlgorithms/AsgPtEtaSelectionTool.h> #include <AsgAnalysisAlgorithms/AsgCutBookkeeperAlg.h> -#include <AsgAnalysisAlgorithms/AsgCutBookkeeperAlg.h> +#include <AsgAnalysisAlgorithms/AsgClassificationDecorationAlg.h> +#include <AsgAnalysisAlgorithms/AsgPriorityDecorationAlg.h> #include <AsgAnalysisAlgorithms/AsgEventScaleFactorAlg.h> #include <AsgAnalysisAlgorithms/AsgLeptonTrackSelectionAlg.h> #include <AsgAnalysisAlgorithms/AsgOriginalObjectLinkAlg.h> @@ -35,7 +36,8 @@ DECLARE_NAMESPACE_TOOL_FACTORY (CP, AsgIntValueSelectionTool) DECLARE_NAMESPACE_TOOL_FACTORY (CP, AsgFlagSelectionTool) DECLARE_NAMESPACE_TOOL_FACTORY (CP, AsgPtEtaSelectionTool) DECLARE_NAMESPACE_ALGORITHM_FACTORY (CP, AsgCutBookkeeperAlg) -DECLARE_NAMESPACE_ALGORITHM_FACTORY (CP, AsgCutBookkeeperAlg) +DECLARE_NAMESPACE_ALGORITHM_FACTORY (CP, AsgClassificationDecorationAlg) +DECLARE_NAMESPACE_ALGORITHM_FACTORY (CP, AsgPriorityDecorationAlg) DECLARE_NAMESPACE_ALGORITHM_FACTORY (CP, AsgEventScaleFactorAlg) DECLARE_NAMESPACE_ALGORITHM_FACTORY (CP, AsgLeptonTrackSelectionAlg) DECLARE_NAMESPACE_ALGORITHM_FACTORY (CP, AsgOriginalObjectLinkAlg) @@ -60,6 +62,8 @@ DECLARE_FACTORY_ENTRIES(AsgAnalysisAlgorithms) { DECLARE_NAMESPACE_ALGTOOL (CP, AsgFlagSelectionTool) DECLARE_NAMESPACE_ALGTOOL (CP, AsgPtEtaSelectionTool) DECLARE_NAMESPACE_ALGORITHM (CP, AsgCutBookkeeperAlg) + DECLARE_NAMESPACE_ALGORITHM (CP, AsgClassificationDecorationAlg) + DECLARE_NAMESPACE_ALGORITHM (CP, AsgPriorityDecorationAlg) DECLARE_NAMESPACE_ALGORITHM (CP, AsgEventScaleFactorAlg) DECLARE_NAMESPACE_ALGORITHM (CP, AsgLeptonTrackSelectionAlg) DECLARE_NAMESPACE_ALGORITHM (CP, AsgOriginalObjectLinkAlg)