ATLAS Offline Software
Loading...
Searching...
No Matches
AsgUnionSelectionAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7//
8// includes
9//
10
12
13#include <xAODBase/IParticle.h>
14
15#include <algorithm>
16
17//
18// method implementations
19//
20
21namespace CP
22{
23
24 StatusCode AsgUnionSelectionAlg ::
25 initialize ()
26 {
27 if (m_selectionDecoration.empty())
28 {
29 ANA_MSG_ERROR("Selection decoration can not be empty.");
30 return StatusCode::FAILURE;
31 }
32
34
37 ANA_CHECK (m_systematicsList.initialize());
38
39 return StatusCode::SUCCESS;
40 }
41
42
43
44 StatusCode AsgUnionSelectionAlg ::
45 execute (const EventContext& ctx)
46 {
47 std::vector<bool> selections;
48
49 // first loop through systematics and define if particle passes each of them
50 for (const auto& sys : m_systematicsList.systematicsVector())
51 {
52 const xAOD::IParticleContainer *particles{};
53 ANA_CHECK (m_particlesHandle.retrieve (particles, sys, ctx));
54
55 if (selections.empty())
56 {
57 selections.resize(particles->size(), false);
58 }
59 else if (selections.size() != particles->size())
60 {
61 ANA_MSG_ERROR("All input containers should have the same size.");
62 return StatusCode::FAILURE;
63 }
64
65 for (size_t i{}; i < particles->size(); i++)
66 {
67 selections[i] = selections[i] || m_preselection.getBool (*(*particles)[i], sys);
68 }
69 }
70
71 // Now decorate the selection decoration
72 // Looping over systematics is needed to ensure all containers are processed
73 std::vector<const xAOD::IParticleContainer*> decorated;
74 for (const auto& sys : m_systematicsList.systematicsVector())
75 {
76 const xAOD::IParticleContainer *particles{};
77 ANA_CHECK (m_particlesHandle.retrieve (particles, sys, ctx));
78
79 if (std::find (decorated.begin(), decorated.end(), particles) != decorated.end())
80 continue;
81 decorated.push_back (particles);
82
83 for (size_t i{}; i < particles->size(); i++)
84 {
85 m_selectionAccessor->setBool (*(*particles)[i], selections[i]);
86 }
87 }
88
89 return StatusCode::SUCCESS;
90 }
91
92} // namespace CP
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
SysReadSelectionHandle m_preselection
the preselection we apply to our input
Gaudi::Property< std::string > m_selectionDecoration
the decoration of the selection
std::unique_ptr< ISelectionWriteAccessor > m_selectionAccessor
the accessor for m_selectionDecoration
SysListHandle m_systematicsList
the systematics list we run and have containers
SysReadHandle< xAOD::IParticleContainer > m_particlesHandle
the particle continer we run on
Select isolated Photons, Electrons and Muons.
StatusCode makeSelectionWriteAccessor(const std::string &name, std::unique_ptr< ISelectionWriteAccessor > &accessor, bool defaultToChar)
Produces a simple ISelectionWriteAccessor accessing the given decoration.
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.