ATLAS Offline Software
Loading...
Searching...
No Matches
MetOutput.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8#ifndef COLUMNAR_MET_MET_OUTPUT_H
9#define COLUMNAR_MET_MET_OUTPUT_H
10
14
15namespace columnar
16{
17 namespace MetHelpers
18 {
30
31 template<ContainerIdConcept CI_MET=ContainerId::mutableMet,ContainerIdConcept CI_OBJ=ContainerId::particle,typename CM=ColumnarModeDefault> class ObjectWeightDecorator;
32
33
34 template<ContainerIdConcept CI_MET,ContainerIdConcept CI_OBJ> class ObjectWeightDecorator<CI_MET,CI_OBJ,ColumnarModeXAOD> final
35 {
38 public:
39
41
42 ObjectWeightDecorator (ColumnarTool<CM>& /*columnarBase*/, const std::string& /*weightSuffix*/, bool val_writeWeights) : writeWeights (val_writeWeights) {}
43
45 };
46
47
48 template<ContainerIdConcept CI_MET,ContainerIdConcept CI_OBJ> class ObjectWeightDecorator<CI_MET,CI_OBJ,ColumnarModeArray> final
49 {
52 public:
53
55
56 ObjectWeightDecorator (ColumnarTool<CM>& columnarBase, const std::string& weightSuffix, bool /*writeWeights*/) : weightDec (columnarBase, "MetObjectWeight" + weightSuffix, {.isOptional = true}) {}
57
59 };
60
61
62
69
70 template<ContainerIdConcept CI_MET=ContainerId::mutableMet,ContainerIdConcept CI_OBJ=ContainerId::particle,typename CM=ColumnarModeDefault> class ObjectWeightHandle;
71
72 template<ContainerIdConcept CI_MET,ContainerIdConcept CI_OBJ> class ObjectWeightHandle<CI_MET,CI_OBJ,ColumnarModeXAOD> final
73 {
76 public:
77
79
81
83 {
84 using namespace MetDef;
85
86 dec_constitObjLinks(met.getXAODObject()) = std::vector<iplink_t>(0);
87 m_uniqueLinks = &dec_constitObjLinks(met.getXAODObject());
88 m_uniqueLinks->reserve (container.size());
89 if (decorator.writeWeights)
90 {
91 dec_constitObjWeights(met.getXAODObject()) = std::vector<float>(0);
92 m_uniqueWeights = &dec_constitObjWeights(met.getXAODObject());
93 m_uniqueWeights->reserve (container.size());
94 }
95
96 if(container.getXAODObject().ownPolicy() == SG::OWN_ELEMENTS) {
97 m_collectionSgKey = tool.getKey(&container.getXAODObject());
98 if(m_collectionSgKey == 0) {
99 std::ostringstream message;
100 message << "Could not get the SG key for the collection with pointer: "
101 << &container.getXAODObject();
102 throw std::runtime_error(message.str());
103 }
104 }
105 }
106
107 [[nodiscard]] std::size_t size () const noexcept {
108 return m_uniqueLinks->size();}
109
110 void emplace_back (const ObjectId<CI_OBJ,CM>& particle,float weight) {
112 iplink_t objLink;
113
114 if(m_collectionSgKey == 0) {
115 const xAOD::IParticleContainer* ipc = static_cast<const xAOD::IParticleContainer*>(particle.getXAODObject().container());
116 objLink = iplink_t(*ipc, particle.getXAODObject().index());
117 } else {
118 objLink = iplink_t(m_collectionSgKey, particle.getXAODObject().index());
119 }
120 emplace_back (objLink, weight);
121 }
122
123
126 private:
127
129
130 std::vector<iplink_t>* m_uniqueLinks = nullptr;
131 std::vector<float>* m_uniqueWeights = nullptr;
132
133 std::vector<iplink_t>& uniqueLinks () noexcept {
134 return *m_uniqueLinks;}
135 std::vector<float>& uniqueWeights () {
136 if (!m_uniqueWeights)
137 throw std::runtime_error ("weights not enabled");
138 return *m_uniqueWeights;}
139
140 void emplace_back (const iplink_t& link,float weight) {
141 m_uniqueLinks->emplace_back (link);
142 if (m_uniqueWeights)
143 m_uniqueWeights->emplace_back (weight);}
144 };
145
146
147
148 template<ContainerIdConcept CI_MET,ContainerIdConcept CI_OBJ> class ObjectWeightHandle<CI_MET,CI_OBJ,ColumnarModeArray> final
149 {
152 public:
153
155
157 {
158 if (!decorator.weightDec.isAvailable(container))
159 throw std::runtime_error ("weights column not provided");
160
161 m_weights = decorator.weightDec(container);
162 for (auto& weight : m_weights)
163 weight = 0;
164 m_offset = container.beginIndex();
165 }
166
167 [[nodiscard]] std::size_t size () const noexcept
168 {
169 std::size_t result = 0;
170 for (auto weight : m_weights)
171 if (weight != 0)
172 ++ result;
173 return result;
174 }
175
176 void emplace_back (const ObjectId<CI_OBJ,CM>& particle,float weight)
177 {
178 m_weights[particle.getIndex() - m_offset] = weight;
179 }
180
181
182
185 private:
186
187 std::span<float> m_weights;
188 std::size_t m_offset = 0;
189 };
190 }
191}
192
193#endif
ElementLink< xAOD::IParticleContainer > iplink_t
Base class for the dual-use tool implementation classes.
Definition AsgTool.h:47
the base class for all columnar components
ObjectWeightDecorator(ColumnarTool< CM > &columnarBase, const std::string &weightSuffix, bool)
Definition MetOutput.h:56
ObjectWeightDecorator(ColumnarTool< CM > &, const std::string &, bool val_writeWeights)
Definition MetOutput.h:42
a special "decorator" for decorating the weight an object contributes to a MET term
Definition MetOutput.h:31
void emplace_back(const ObjectId< CI_OBJ, CM > &particle, float weight)
Definition MetOutput.h:176
ObjectWeightHandle(const asg::AsgTool &, const ObjectWeightDecorator< CI_MET, CI_OBJ, CM > &decorator, ObjectId< CI_MET, CM >, const ObjectRange< CI_OBJ, CM > &container)
Definition MetOutput.h:156
void emplace_back(const ObjectId< CI_OBJ, CM > &particle, float weight)
Definition MetOutput.h:110
ObjectWeightHandle(const asg::AsgTool &tool, const ObjectWeightDecorator< CI_MET, CI_OBJ, CM > &decorator, ObjectId< CI_MET, CM > met, const ObjectRange< CI_OBJ, CM > &container)
Definition MetOutput.h:82
a "handle" for recording object weights via ObjectWeightDecorator
Definition MetOutput.h:70
a class representing a single object (electron, muons, etc.)
a class representing a continuous sequence of objects (a.k.a. a container)
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
@ OWN_ELEMENTS
this data object owns its elements
ElementLink< xAOD::IParticleContainer > iplink_t
Definition MetDef.h:20
AccessorTemplate< CI, CT, ColumnAccessMode::output, CM > ColumnDecorator
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.