ATLAS Offline Software
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 
12 #include <ColumnarMet/MetInput.h>
14 
15 namespace 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 
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 
128  SG::sgkey_t m_collectionSgKey = 0;
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 
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
asg::AsgTool
Base class for the dual-use tool implementation classes.
Definition: AsgTool.h:47
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:79
columnar::MetHelpers::ObjectWeightHandle< CI_MET, CI_OBJ, ColumnarModeXAOD >::uniqueLinks
std::vector< iplink_t > & uniqueLinks() noexcept
Definition: MetOutput.h:133
get_generator_info.result
result
Definition: get_generator_info.py:21
columnar::MetDef::iplink_t
ElementLink< xAOD::IParticleContainer > iplink_t
Definition: MetDef.h:20
columnar::MetHelpers::ObjectWeightHandle
a "handle" for recording object weights via ObjectWeightDecorator
Definition: MetOutput.h:70
columnar::MetHelpers::ObjectWeightHandle< CI_MET, CI_OBJ, ColumnarModeArray >::size
std::size_t size() const noexcept
Definition: MetOutput.h:167
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
columnar::ObjectRange
a class representing a continuous sequence of objects (a.k.a. a container)
Definition: ContainerId.h:175
ReweightUtils.message
message
Definition: ReweightUtils.py:15
columnar::MetHelpers::ObjectWeightDecorator
a special "decorator" for decorating the weight an object contributes to a MET term
Definition: MetOutput.h:31
columnar::MetHelpers::ObjectWeightHandle< CI_MET, CI_OBJ, ColumnarModeArray >::emplace_back
void emplace_back(const ObjectId< CI_OBJ, CM > &particle, float weight)
Definition: MetOutput.h:176
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:190
columnar::MetHelpers::ObjectWeightDecorator< CI_MET, CI_OBJ, ColumnarModeXAOD >::ObjectWeightDecorator
ObjectWeightDecorator(ColumnarTool< CM > &, const std::string &, bool val_writeWeights)
Definition: MetOutput.h:42
METHelpers.h
met
Definition: IMETSignificance.h:24
SG::OWN_ELEMENTS
@ OWN_ELEMENTS
this data object owns its elements
Definition: OwnershipPolicy.h:17
columnar::MetHelpers::ObjectWeightHandle< CI_MET, CI_OBJ, ColumnarModeArray >::m_weights
std::span< float > m_weights
Definition: MetOutput.h:187
columnar::MetHelpers::ObjectWeightHandle< CI_MET, CI_OBJ, ColumnarModeXAOD >::ObjectWeightHandle
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
columnar::final
CM final
Definition: ColumnAccessor.h:106
columnar::ObjectId
a class representing a single object (electron, muons, etc.)
Definition: ContainerId.h:176
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:452
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition: CxxUtils/CxxUtils/sgkey_t.h:32
columnar::ColumnarModeArray
Definition: ColumnarDef.h:30
columnar::MetHelpers::ObjectWeightDecorator< CI_MET, CI_OBJ, ColumnarModeXAOD >::writeWeights
bool writeWeights
Definition: MetOutput.h:44
columnar::MetHelpers::ObjectWeightHandle< CI_MET, CI_OBJ, ColumnarModeXAOD >::emplace_back
void emplace_back(const iplink_t &link, float weight)
Definition: MetOutput.h:140
columnar
Definition: ClusterDef.h:16
ContainerId.h
columnar::ColumnarTool
the base class for all columnar components
Definition: ColumnAccessorDataArray.h:17
columnar::ColumnarModeXAOD
Definition: ColumnarDef.h:15
iplink_t
ElementLink< xAOD::IParticleContainer > iplink_t
Definition: SystObjectLinkerAlg.cxx:14
columnar::MetHelpers::ObjectWeightDecorator< CI_MET, CI_OBJ, ColumnarModeArray >::ObjectWeightDecorator
ObjectWeightDecorator(ColumnarTool< CM > &columnarBase, const std::string &weightSuffix, bool)
Definition: MetOutput.h:56
columnar::MetHelpers::ObjectWeightHandle< CI_MET, CI_OBJ, ColumnarModeXAOD >::uniqueWeights
std::vector< float > & uniqueWeights()
Definition: MetOutput.h:135
columnar::AccessorTemplate
the raw column accessor template class
Definition: ColumnAccessor.h:81
columnar::MetHelpers::ObjectWeightHandle< CI_MET, CI_OBJ, ColumnarModeArray >::ObjectWeightHandle
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
columnar::MetHelpers::ObjectWeightHandle< CI_MET, CI_OBJ, ColumnarModeXAOD >::size
std::size_t size() const noexcept
Definition: MetOutput.h:107
columnar::MetHelpers::ObjectWeightHandle< CI_MET, CI_OBJ, ColumnarModeXAOD >::emplace_back
void emplace_back(const ObjectId< CI_OBJ, CM > &particle, float weight)
Definition: MetOutput.h:110
MetInput.h
columnar::MetHelpers::ObjectWeightDecorator< CI_MET, CI_OBJ, ColumnarModeArray >::weightDec
ColumnDecorator< CI_OBJ, float, CM > weightDec
Definition: MetOutput.h:58