ATLAS Offline Software
Loading...
Searching...
No Matches
MetInput.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_INPUT_H
9#define COLUMNAR_MET_MET_INPUT_H
10
14#include <ColumnarMet/MetDef.h>
16
17namespace columnar
18{
19 namespace MetHelpers
20 {
30
31 template<ContainerIdConcept CI = ContainerId::particle,typename CM=ColumnarModeDefault>
33 {
35 : pt (columnarBase, "pt"),
36 eta (columnarBase, "eta"),
37 phi (columnarBase, "phi"),
38 m (columnarBase, "m")
39 {}
40
41 InputMomentumAccessors (ColumnarTool<CM>& columnarBase, const std::string& prefix)
42 : pt (columnarBase, prefix + "_pt"),
43 eta (columnarBase, prefix + "_eta"),
44 phi (columnarBase, prefix + "_phi"),
45 m (columnarBase, prefix + "_m")
46 {}
47
52
53 // IMPORTANT: These have to return float, not double, to match
54 // the xAOD interface. The internal calculations are done in
55 // double, and the caller immediately converts it back to double,
56 // but converting it to float here introduces a very tiny
57 // truncation error that we need to match the xAOD implementation.
58 [[nodiscard]] float px (ObjectId<CI,CM> object) const {
59 return pt(object) * std::cos(phi(object));}
60 [[nodiscard]] float py (ObjectId<CI,CM> object) const {
61 return pt(object) * std::sin(phi(object));}
62
64 {
66 }
67 };
68
69
70
71 template<ContainerIdConcept CI = ContainerId::particle,typename CM = ColumnarModeDefault> class OriginalObjectHandle;
72 template<ContainerIdConcept CI,typename CM> OriginalObjectHandle (const asg::AsgTool&,ObjectRange<CI,CM>) -> OriginalObjectHandle<CI,CM>;
73
74 template<ContainerIdConcept CI> class OriginalObjectHandle<CI,ColumnarModeXAOD> final
75 {
76 bool m_originalInputs = false;
77 bool m_isShallowCopy = false;
78
79 public:
80
82
84 {
85 if (!container.empty())
86 {
87 using namespace MetDef;
88 m_originalInputs = !acc_originalObject.isAvailable(*container.getXAODObject().front());
89 m_isShallowCopy = dynamic_cast<const xAOD::ShallowAuxContainer*>(container.getXAODObject().front()->container()->getConstStore());
90 if (tool.msgLvl(MSG::VERBOSE))
91 {
92 tool.msg(MSG::VERBOSE) << "const store = " << container.getXAODObject().front()->container()->getConstStore() << endmsg;
93 }
94 }
95 }
96
97 [[nodiscard]] bool originalInputs () const {
98 return m_originalInputs;
99 }
100
101 [[nodiscard]] bool isShallowCopy () const {
102 return m_isShallowCopy;
103 }
104
105 [[nodiscard]] ObjectId<CI,CM> getOriginal (const ObjectId<CI,CM>& id) const
106 {
108 {
109 return id;
110 } else
111 {
112 using namespace MetDef;
113 auto *originalObject = *acc_originalObject(id.getXAODObject());
114 if (!originalObject)
115 throw std::runtime_error ("originalObjectLink not available for MET input");
116 return ObjectId<CI,CM> (dynamic_cast<typename CI::xAODObjectIdType&>(*originalObject));
117 }
118 }
119
121 {
122 using namespace MetDef;
123 if (acc_nominalObject.isAvailable(jet.getXAODObject())) {
124 auto nominal = acc_nominalObject(jet.getXAODObject());
125 if (nominal && *nominal)
126 {
127 return ObjectId<CI,CM> {static_cast<CI::xAODObjectIdType&>(**nominal)};
128 }
129 }
130 std::ostringstream message;
131 message << "No nominal calibrated jet available for jet " << jet << ". Cannot simplify overlap removal!";
132 throw std::runtime_error (message.str());
133 }
134 };
135
136 template<ContainerIdConcept CI> class OriginalObjectHandle<CI,ColumnarModeArray> final
137 {
138 public:
139
141
142 explicit OriginalObjectHandle (const asg::AsgTool& /*tool*/, ObjectRange<CI,CM> /*container*/)
143 {};
144
145 [[nodiscard]] bool originalInputs () const {
146 return true;
147 }
148
149 [[nodiscard]] bool isShallowCopy () const {
150 return false;
151 }
152
153 [[nodiscard]] ObjectId<CI,CM> getOriginal (const ObjectId<CI,CM>& id) const
154 {
155 return id;
156 }
157
159 {
160 throw std::runtime_error ("no nominal object available in columnar mode");
161 }
162 };
163
164
165
168 template<ContainerIdConcept CI,typename CM=ColumnarModeDefault>
170
171 template<ContainerIdConcept CI>
173 {
175
176 ObjectTypeAccessor (ColumnarTool<CM>& /*columnBase*/, const std::string& /*columnName*/) {}
177
178 [[nodiscard]] xAODType::ObjectType operator() (ObjectId<CI,CM> object) const
179 {
180 return object.getXAODObject().type();
181 }
182
183 [[nodiscard]] std::optional<xAODType::ObjectType> operator() (ObjectRange<CI,CM> container) const
184 {
185 if (container.empty())
186 return std::nullopt;
187 return container.getXAODObject().front()->type();
188 }
189 };
190
191 template<ContainerIdConcept CI>
193 {
195
196 // FIX ME: ideally this should rely on a global column with a
197 // single type, not a type per object, but that functionality
198 // doesn't currently (13 Jan 25) exist.
200
201 ObjectTypeAccessor (ColumnarTool<CM>& columnBase, const std::string& columnName)
202 : typeAcc (columnBase, columnName) {}
203
204 [[nodiscard]] xAODType::ObjectType operator () (ObjectId<CI,CM> object) const
205 {
206 return typeAcc(object);
207 }
208
209 [[nodiscard]] std::optional<xAODType::ObjectType> operator() (ObjectRange<CI,CM> container) const
210 {
211 // Technically we may be able to return a type here, but for
212 // consistency with the xAOD mode we return nullopt if the
213 // container is empty.
214 if (container.empty())
215 return std::nullopt;
216 return typeAcc(container[0]);
217 }
218 };
219 }
220}
221
222#endif
#define endmsg
Base class for the dual-use tool implementation classes.
Definition AsgTool.h:47
the base class for all columnar components
OriginalObjectHandle(const asg::AsgTool &, ObjectRange< CI, CM >)
Definition MetInput.h:142
ObjectId< CI, CM > getNominalObject(const ObjectId< CI, CM > &) const
Definition MetInput.h:158
ObjectId< CI, CM > getOriginal(const ObjectId< CI, CM > &id) const
Definition MetInput.h:153
ObjectId< CI, CM > getNominalObject(const ObjectId< CI, CM > &jet) const
Definition MetInput.h:120
OriginalObjectHandle(const asg::AsgTool &tool, ObjectRange< CI, CM > container)
Definition MetInput.h:83
ObjectId< CI, CM > getOriginal(const ObjectId< CI, CM > &id) const
Definition MetInput.h:105
a class representing a single object (electron, muons, etc.)
a class representing a continuous sequence of objects (a.k.a. a container)
Class creating a shallow copy of an existing auxiliary container.
OriginalObjectHandle(const asg::AsgTool &, ObjectRange< CI, CM >) -> OriginalObjectHandle< CI, CM >
AccessorTemplate< CI, CT, ColumnAccessMode::input, CM > ColumnAccessor
ObjectType
Type of objects that have a representation in the xAOD EDM.
Definition ObjectType.h:32
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition JetTypes.h:17
ColumnAccessor< CI, RetypeColumn< double, float >, CM > pt
Definition MetInput.h:48
ColumnAccessor< CI, RetypeColumn< double, float >, CM > phi
Definition MetInput.h:50
ColumnAccessor< CI, RetypeColumn< double, float >, CM > m
Definition MetInput.h:51
float px(ObjectId< CI, CM > object) const
Definition MetInput.h:58
float py(ObjectId< CI, CM > object) const
Definition MetInput.h:60
ColumnAccessor< CI, RetypeColumn< double, float >, CM > eta
Definition MetInput.h:49
InputMomentumAccessors(ColumnarTool< CM > &columnarBase, const std::string &prefix)
Definition MetInput.h:41
xAOD::JetFourMom_t jetP4(ObjectId< CI, CM > jet) const
Definition MetInput.h:63
InputMomentumAccessors(ColumnarTool< CM > &columnarBase)
Definition MetInput.h:34
ColumnAccessor< CI, RetypeColumn< xAODType::ObjectType, std::uint16_t >, CM > typeAcc
Definition MetInput.h:199
ObjectTypeAccessor(ColumnarTool< CM > &columnBase, const std::string &columnName)
Definition MetInput.h:201
ObjectTypeAccessor(ColumnarTool< CM > &, const std::string &)
Definition MetInput.h:176
an accessor that allows to access the xAOD object type of an input object
Definition MetInput.h:169
std::map< std::string, HypoJetVector >::const_iterator CI