ATLAS Offline Software
Loading...
Searching...
No Matches
AsgViewFromSelectionAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8
9//
10// includes
11//
12
14
15#include <CxxUtils/fpcompare.h>
26
27//
28// method implementations
29//
30
31namespace CP
32{
33 template<typename Type> StatusCode AsgViewFromSelectionAlg ::
34 executeTemplate (const CP::SystematicSet& sys)
35 {
36 const Type *input = nullptr;
37 ANA_CHECK (evtStore()->retrieve (input, m_inputHandle.getName (sys)));
38 auto viewCopy = std::make_unique<ConstDataVector<Type>> (SG::VIEW_ELEMENTS);
39 for (const auto particle : *input)
40 {
41 bool keep = true;
42 for (const auto& accessor : m_accessors)
43 {
44 if ((accessor.first->getBits (*particle) | accessor.second) != selectionAccept())
45 {
46 keep = false;
47 break;
48 }
49 }
50 if (keep)
51 {
52 viewCopy->push_back (particle);
53 }
54 }
55
56 if (m_sortPt)
57 {
58 std::sort (viewCopy->begin(), viewCopy->end(), [] (const xAOD::IParticle *a, const xAOD::IParticle *b) {return CxxUtils::fpcompare::greater (a->pt(), b->pt());});
59 }
60
61 // If anyone might be concerned about efficiency here, this will
62 // add/sort a couple more entries than needed only to remove them
63 // from the vector afterwards, so there is a slight efficiency
64 // loss. However, this option is not expected to be used very
65 // often and the algorithm is still expected to run quickly, so I
66 // decided to keep the code above simpler and just do this as a
67 // separate step, instead of trying to optimize this by
68 // integrating it with the code above.
69 if (viewCopy->size() > m_sizeLimit)
70 viewCopy->resize (m_sizeLimit);
71
72 // In case we want to output a view copy, do that here.
73 if (!m_deepCopy)
74 {
75 ANA_CHECK (evtStore()->record (viewCopy.release(),
76 m_outputHandle.getName (sys)));
77 return StatusCode::SUCCESS;
78 }
79
80 // Apparently we want to make a deep copy. So set that one up.
81 auto deepCopy = std::make_unique<Type> ();
82 auto aux = std::make_unique<xAOD::AuxContainerBase> ();
83 deepCopy->setStore (aux.get());
84 deepCopy->reserve (viewCopy->size());
85 for (auto particle : *viewCopy)
86 {
87 typename Type::value_type pcopy = new typename Type::base_value_type();
88 deepCopy->push_back (pcopy);
89 *pcopy = *particle;
90 }
91
92 // Record the deep copy into the event store.
93 ANA_CHECK (evtStore()->record (deepCopy.release(),
94 m_outputHandle.getName (sys)));
95 ANA_CHECK (evtStore()->record (aux.release(),
96 m_outputHandle.getName (sys) + "Aux."));
97
98 return StatusCode::SUCCESS;
99 }
100
101
102
103
104 StatusCode AsgViewFromSelectionAlg ::
105 executeFindType (const CP::SystematicSet& sys)
106 {
107 if( m_allowMissing ) {
108 const std::string& name = m_inputHandle.getName( sys );
111 return StatusCode::SUCCESS;
112 }
113 }
114
115 const xAOD::IParticleContainer *input = nullptr;
116 ANA_CHECK (m_inputHandle.retrieve (input, sys));
117
118 if (dynamic_cast<const xAOD::ElectronContainer*> (input))
119 {
120 m_function =
122 }
123 else if (dynamic_cast<const xAOD::PhotonContainer*> (input))
124 {
125 m_function =
127 }
128 else if (dynamic_cast<const xAOD::JetContainer*> (input))
129 {
130 m_function =
132 }
133 else if (dynamic_cast<const xAOD::MuonContainer*> (input)) {
134 m_function =
136 }
137 else if (dynamic_cast<const xAOD::TauJetContainer*> (input))
138 {
139 m_function =
141 }
142 else if (dynamic_cast<const xAOD::DiTauJetContainer*> (input))
143 {
144 m_function =
146 }
147 else if (dynamic_cast<const xAOD::TrackParticleContainer*> (input))
148 {
149 m_function =
151 }
152 else if (dynamic_cast<const xAOD::TruthParticleContainer*> (input))
153 {
154 m_function =
156 }
157 else
158 {
159 ANA_MSG_ERROR ("unknown type contained in AsgViewFromSelectionAlg, please extend it");
160 return StatusCode::FAILURE;
161 }
162
163 return (this->*m_function) (sys);
164 }
165
166
167
168 StatusCode AsgViewFromSelectionAlg ::
169 executeMissing (const CP::SystematicSet&)
170 {
171 return StatusCode::SUCCESS;
172 }
173
174
175
176
177 StatusCode AsgViewFromSelectionAlg ::
178 initialize ()
179 {
180 ANA_CHECK (m_systematicsList.service().registerCopy (m_inputHandle.getNamePattern(), m_outputHandle.getNamePattern()));
183 ANA_CHECK (m_systematicsList.initialize());
184
185 if (m_ignore.size() > m_selection.size())
186 {
187 ANA_MSG_ERROR ("ignore property can't have more properties than selection property");
188 return StatusCode::FAILURE;
189 }
190 for (std::size_t iter = 0, end = m_selection.size(); iter != end; ++ iter)
191 {
192 SelectionType ignore = 0;
193 if (iter < m_ignore.size())
194 ignore = m_ignore[iter];
195 std::unique_ptr<ISelectionReadAccessor> accessor;
197 m_accessors.push_back (std::make_pair (std::move (accessor), ignore));
198 }
199
200 return StatusCode::SUCCESS;
201 }
202
203
204
205 StatusCode AsgViewFromSelectionAlg ::
206 execute ()
207 {
208 for (const auto& sys : m_systematicsList.systematicsVector())
209 {
210 ANA_CHECK ((this->*m_function) (sys));
211 }
212 return StatusCode::SUCCESS;
213 }
214}
DataVector adapter that acts like it holds const pointers.
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
static Double_t a
Gaudi::Property< std::vector< std::string > > m_selection
StatusCode executeTemplate(const CP::SystematicSet &sys)
the templated version of execute for a single systematic
Gaudi::Property< bool > m_sortPt
Sort the output (view) container by pT.
Gaudi::Property< std::size_t > m_sizeLimit
StatusCode(AsgViewFromSelectionAlg::* m_function)(const CP::SystematicSet &sys)
SysReadHandle< xAOD::IParticleContainer > m_inputHandle
the input collection we run on
Gaudi::Property< bool > m_allowMissing
Allow the input container to be missing.
StatusCode executeMissing(const CP::SystematicSet &sys)
The version of execute for missing input containers.
SysWriteHandle< xAOD::IParticleContainer > m_outputHandle
the output view container we produce
Gaudi::Property< std::vector< SelectionType > > m_ignore
Gaudi::Property< bool > m_deepCopy
Perform a deep copy for creating the output container.
std::vector< std::pair< std::unique_ptr< ISelectionReadAccessor >, SelectionType > > m_accessors
the list of accessors and cut ignore list
SysListHandle m_systematicsList
the systematics list we run
Class to wrap a set of SystematicVariations.
Class providing the definition of the 4-vector interface.
Workaround x86 precision issues for FP inequality comparisons.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
Select isolated Photons, Electrons and Muons.
StatusCode makeSelectionReadAccessor(const std::string &expr, std::unique_ptr< ISelectionReadAccessor > &accessor, bool defaultToChar)
make the ISelectionReadAccessor for the given name
uint32_t SelectionType
the type for selection decorations that are meant to hold a asg::AcceptData
constexpr SelectionType selectionAccept()
the selection decoration to apply for objects that are selected
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
DiTauJetContainer_v1 DiTauJetContainer
Definition of the current DiTauJet container version.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.