ATLAS Offline Software
MissingETComponent_v1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 #include <iterator>
10 
11 using namespace xAOD;
12 using namespace MissingETBase::Types;
13 
15 // MissingETComponent_v1::Weight Implementations //
17 
19 { this->wpx() += wght.wpx(); this->wpy() += wght.wpy(); this->wet() += wght.wet(); return *this; }
20 
22 { this->wpx() -= wght.wpx(); this->wpy() -= wght.wpy(); this->wet() -= wght.wet(); return *this; }
23 
25 { this->wpx() *= wght.wpx(); this->wpy() *= wght.wpy(); this->wet() *= wght.wet(); return *this; }
26 
28 { this->wpx() *= scale; this->wpy() *= scale; this->wet() *= scale; return *this; }
29 
31 {
32  this->wpx() = MissingETBase::Numerical::divide(this->wpx(),wght.wpx());
33  this->wpy() = MissingETBase::Numerical::divide(this->wpy(),wght.wpy());
34  this->wet() = MissingETBase::Numerical::divide(this->wet(),wght.wet());
35  return *this;
36 }
37 
39 {
40  if ( scale == 0. ) { this->wpx() = 0.; this->wpy() = 0.; this->wet() = 0.; return *this; }
41  else { return this->operator*=(1./scale); }
42 }
43 
45 {
46  return
47  MissingETBase::Numerical::isEqual(this->wpx(),wght.wpx()) &&
48  MissingETBase::Numerical::isEqual(this->wpy(),wght.wpy()) &&
49  MissingETBase::Numerical::isEqual(this->wet(),wght.wet());
50 }
51 
53 // Constructors and destructors //
55 
57  : SG::AuxElement(){
58 
59  if( createStore ) createPrivateStore();
60 }
61 
64  : SG::AuxElement(){
65 
67  setMET( pmetObj );
68  setStatusWord( sw );
69 }
70 
72  const IParticle* pPart,
73  double wpx, double wpy, double wet,
75  : SG::AuxElement(){
76 
78  setMET( pmetObj );
79  setStatusWord( sw );
80  addObject( pPart, wpx, wpy, wet );
81 }
82 
84  const IParticle* pPart,
85  const Weight& wght,
87  : SG::AuxElement(){
88 
90  setMET( pmetObj );
91  setStatusWord( sw );
92  addObject( pPart, wght );
93 }
94 
96  : SG::AuxElement(compDescr)
97 { this->makePrivateStore(&compDescr); }
98 
100  : SG::AuxElement()
101 { this->makePrivateStore(compDescr); this->setStatusWord(sw); }
102 
104 {
105  if((&compDescr) != this) {
106  this->setStatusWord(compDescr.statusWord());
107  this->setMetLink(compDescr.metLink());
108  this->setObjectLinks(compDescr.objectLinks());
109  this->setWpx(compDescr.wpx());
110  this->setWpy(compDescr.wpy());
111  this->setWet(compDescr.wet());
112  }
113  return *this;
114 }
115 
117 
119 // Data store management //
121 
122 bool MissingETComponent_v1::addObject(const IParticle* pPart,double wpx,double wpy,double wet)
123 {
124  // check if object is in store
125  size_t idx(this->findIndex(pPart));
126  // found - add weights
128  { this->f_wpx()[idx] += wpx; this->f_wpy()[idx] += wpy; this->f_wet()[idx] += wet; return false; }
129  // new object
130  else
131  {
132  MissingETBase::Types::objlink_t oLnk; f_setObject<IParticle,MissingETBase::Types::objlink_t>(pPart,oLnk);
133  // add to stores
134  this->f_objectLinks().push_back(oLnk);this->f_wpx().push_back(wpx);this->f_wpy().push_back(wpy);this->f_wet().push_back(wet);
135  bool linkset = f_setLink<MissingETBase::Types::objlink_t>(oLnk);
136  return linkset;
137  }
138 }
139 
140 // void MissingETComponent_v1::updateLinks()
141 // {
142 // this->updateMETLink();
143 // static SG::AuxElement::Accessor<MissingETBase::Types::objlink_vector_t> acc("objectLinks");
144 // if(acc.isAvailableWritable(*this)) {
145 // MissingETBase::Types::objlink_vector_t::iterator fLnk(this->f_objectLinks().begin());
146 // MissingETBase::Types::objlink_vector_t::iterator lLnk(this->f_objectLinks().end());
147 // for ( ; fLnk != lLnk; ++fLnk ) {
148 // // avoid validity check to prevent crashes due to thinning
149 // // if(f_setLink<MissingETBase::Types::objlink_t>(*fLnk)){
150 // fLnk->toPersistent();
151 // // }
152 // }
153 // }
154 // }
155 
156 // void MissingETComponent_v1::updateMETLink() {
157 // static SG::AuxElement::Accessor<MissingETBase::Types::metlink_t> acc("metLink");
158 // if(acc.isAvailableWritable(*this)) {
159 // if(f_setLink<MissingETBase::Types::metlink_t>(this->f_metLink())) {
160 // this->f_metLink().toPersistent();
161 // }
162 // }
163 // }
164 
166 {
167  if ( this->empty() ) { return false; }
168  else
169  { size_t nEnt(this->size()); for ( size_t pIdx(0); pIdx<nEnt; ++pIdx ) { this->f_removeContrib(pIdx); } return true; }
170 }
171 
173 {
174  objlink_vector_t::iterator fCon(this->f_objectLinks().begin()); std::advance<objlink_vector_t::iterator>(fCon,pIdx);
175  this->f_objectLinks().erase(fCon);
177  this->f_wpx().erase(fWpx);
179  this->f_wpy().erase(fWpy);
181  this->f_wet().erase(fWet);
182  return true;
183 }
184 
186 {
187  if ( pIdx != MissingETBase::Numerical::invalidIndex() && pIdx < this->size() )
188  {
192  return true;
193  }
194  return false;
195 }
196 
198 {
199  if ( this->empty() ) { return false; }
200  else
201  {
202  size_t nEnt(this->size());
203  for ( size_t pIdx(0); pIdx < nEnt; ++pIdx)
204  {
208  }
209  return true;
210  }
211 }
212 
213 size_t MissingETComponent_v1::findIndex(const IParticle* pPart) const
214 {
215  objlink_vector_t::const_iterator fLnk(this->objectLinks().begin());
216  while(fLnk != this->objectLinks().end() && *(*fLnk) != pPart){ ++fLnk; }
217  if(fLnk != this->objectLinks().end())
218  return std::distance(this->objectLinks().begin(),fLnk);
220 }
221 
223 // Setters //
225 
226 bool MissingETComponent_v1::setWpx(const std::vector<double>& wcv)
227 { this->f_wpx().clear(); this->f_wpx().insert(this->f_wpx().end(),wcv.begin(),wcv.end()); return !this->f_wpx().empty(); }
228 bool MissingETComponent_v1::setWpy(const std::vector<double>& wcv)
229 { this->f_wpy().clear(); this->f_wpy().insert(this->f_wpy().end(),wcv.begin(),wcv.end()); return !this->f_wpy().empty(); }
230 bool MissingETComponent_v1::setWet(const std::vector<double>& wcv)
231 { this->f_wet().clear(); this->f_wet().insert(this->f_wet().end(),wcv.begin(),wcv.end()); return !this->f_wet().empty(); }
232 
234 // FIXME: failsafe implementation checks on invalidKey and vector index - vector index may be sufficient?
235 bool MissingETComponent_v1::setWpx(size_t pIdx,double wpx)
236 { if ( pIdx != MissingETBase::Numerical::invalidIndex() && pIdx < this->f_wpx().size() ) { this->f_wpx()[pIdx] = wpx; return true; } else { return false; } }
237 bool MissingETComponent_v1::setWpy(size_t pIdx,double wpy)
238 { if ( pIdx != MissingETBase::Numerical::invalidIndex() && pIdx < this->f_wpy().size() ) { this->f_wpy()[pIdx] = wpy; return true; } else { return false; } }
239 bool MissingETComponent_v1::setWet(size_t pIdx,double wet)
240 { if ( pIdx != MissingETBase::Numerical::invalidIndex() && pIdx < this->f_wet().size() ) { this->f_wet()[pIdx] = wet; return true; } else { return false; } }
241 bool MissingETComponent_v1::setWeight(size_t pIdx,double wpx,double wpy,double wet)
242 {
243  if ( pIdx != MissingETBase::Numerical::invalidIndex() && pIdx < this->f_wet().size() )
244  { this->f_wpx()[pIdx] = wpx; this->f_wpy()[pIdx] = wpy; this->f_wet()[pIdx] = wet; return true; }
245  else
246  { return false; }
247 }
248 
250 {
251  bool wasSet(this->f_metLink().getStorableObjectPointer() != nullptr);
252  f_setObject<MissingET,MissingETBase::Types::metlink_t>(pmetObj,this->f_metLink());
253  this->f_statusWord() = sw;
254  return wasSet;
255 }
256 
258 {
259  bool wasSet(this->f_metLink().getStorableObjectPointer() != nullptr);
260  this->f_metLink().toIndexedElement(*pmetCont,pmetIdx);
261  this->f_statusWord() = sw;
262  return wasSet; }
263 
265 {
266  bool wasSet(this->f_metLink().getStorableObjectPointer() != nullptr);
267  this->f_metLink() = metLnk;
268  return wasSet; }
269 
271 {
272  bool wasSet(!this->f_objectLinks().empty());
273  if ( wasSet ) {
274  this->f_objectLinks().clear(); this->f_objectLinks().insert(this->f_objectLinks().end(),objLnks.begin(),objLnks.end());
276  iLink!=this->f_objectLinks().end(); ++iLink) {
277  this->f_setLink<MissingETBase::Types::objlink_t>(*iLink);
278  }
279  }
280  return wasSet;
281 }
282 
283 
285 // Getters //
287 
288 double MissingETComponent_v1::wpx(size_t pIdx) const
289 { return pIdx != MissingETBase::Numerical::invalidIndex() && pIdx < this->size() ? this->wpx()[pIdx] : MissingETBase::Numerical::wpxError(); }
290 double MissingETComponent_v1::wpy(size_t pIdx) const
291 { return pIdx != MissingETBase::Numerical::invalidIndex() && pIdx < this->size() ? this->wpy()[pIdx] : MissingETBase::Numerical::wpyError(); }
292 double MissingETComponent_v1::wet(size_t pIdx) const
293 { return pIdx != MissingETBase::Numerical::invalidIndex() && pIdx < this->size() ? this->wet()[pIdx] : MissingETBase::Numerical::wetError(); }
294 
295 std::vector<const IParticle*> MissingETComponent_v1::objects() const
296 {
297  std::vector<const IParticle*> pVec;
298  for ( objlink_vector_t::const_iterator fLnk(this->objectLinks().begin()); fLnk != this->objectLinks().end(); ++fLnk) { pVec.push_back(*(*fLnk)); }
299  return pVec;
300 }
301 
302 std::vector<const IParticle*> MissingETComponent_v1::objects(MissingETBase::Types::weight_vector_t& kinePars) const
303 {
304  size_t nEnt(this->objectLinks().size());
305  std::vector<const IParticle*> pVec(nEnt,(const IParticle*)nullptr);
306  kinePars.clear(); kinePars.resize(nEnt,Weight(0.,0.,0.));
307  for ( size_t idx(0); idx < nEnt; ++idx )
308  { pVec[idx] = *(this->objectLinks().at(idx)); kinePars.at(idx) = Weight(this->wpx().at(idx),this->wpy().at(idx),this->wet().at(idx)); }
309  return pVec;
310 }
311 
312 std::vector<const IParticle*> MissingETComponent_v1::objects(const std::vector<double>*& wpxPtr,const std::vector<double>*& wpyPtr,const std::vector<double>*& wetPtr) const
313 { wpxPtr = &(this->wpx()); wpyPtr = &(this->wpy()); wetPtr = &(this->wet()); return this->objects(); }
314 
316 // Weight object generators //
318 
320 { return pIdx != MissingETBase::Numerical::invalidIndex() && pIdx < this->size()
321  ? Weight(this->wpx().at(pIdx),this->wpy().at(pIdx),this->wet(pIdx))
323 
325 // Comparators //
327 
329 {
330  // FIXME compare only MET object link, statusword, and number of contributing particles
331  return
332  this->metLink() == compDescr.metLink() &&
333  this->statusWord() == compDescr.statusWord() &&
334  this->size() == compDescr.size();
335 }
336 
338 // Other function(s) //
340 
342 
344  f_metLink() = metlink_t();
346  f_wpx().clear();
347  f_wpy().clear();
348  f_wet().clear();
349  f_objectLinks().clear();
350 
351  return;
352 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
MissingETComponent_v1.h
xAOD::MissingETComponent_v1::setMET
bool setMET(const MissingET *pmetObj, MissingETBase::Types::bitmask_t sw=MissingETBase::Status::clearedStatus())
Set MET object by object pointer reference.
Definition: MissingETComponent_v1.cxx:249
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
xAOD::MissingETComponent_v1::setWeight
bool setWeight(const IParticle *pPart, const Weight &wght=Weight())
Set the kinematic weight of an object contribution referenced by pointer.
MissingETBase::Numerical::divide
static double divide(double x, double y)
Failsafe division.
Definition: MissingETBase.h:125
xAOD::MissingETComponent_v1::setWpy
bool setWpy(const std::vector< double > &wpyVector)
Set the vector of weight components
Definition: MissingETComponent_v1.cxx:228
xAOD::MissingETComponent_v1::operator==
bool operator==(const MissingETComponent_v1 &contrib) const
Definition: MissingETComponent_v1.cxx:328
xAOD::MissingETComponent_v1::~MissingETComponent_v1
virtual ~MissingETComponent_v1()
Assignment operator.
Definition: MissingETComponent_v1.cxx:116
xAOD::MissingETComponent_v1::weight
Weight weight(const IParticle *pPart) const
Get kinematic weight for a given object.
xAOD::MissingETComponent_v1::setWpx
bool setWpx(const std::vector< double > &wcv)
Set the vector of weight components
Definition: MissingETComponent_v1.cxx:226
xAOD::MissingETComponent_v1::resetContrib
bool resetContrib()
Reset all contribution parameters.
Definition: MissingETComponent_v1.cxx:197
xAOD::MissingETComponent_v1::Weight::wet
double wet() const
Returns .
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
MissingETCompositionBase.h
xAOD::MissingETComponent_v1::Weight::operator/=
Weight & operator/=(const Weight &wght)
Divide two weights.
Definition: MissingETComponent_v1.cxx:30
xAOD::MissingETComponent_v1::wpx
const std::vector< double > & wpx() const
Get the vector of weight components
xAOD::MissingETComponent_v1::wet
const std::vector< double > & wet() const
Get the vector of weight components
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
MissingETBase::Numerical::invalidIndex
static size_t invalidIndex()
Access invalid index indicator.
Definition: MissingETBase.h:103
MissingETBase::Types::weight_vector_t
std::vector< weight_t > weight_vector_t
Vector type for kinematic weight containers.
Definition: MissingETComponent_v1.h:265
MissingETBase::Types::bitmask_t
uint64_t bitmask_t
Type for status word bit mask.
Definition: MissingETBase.h:39
MissingETContainer_v1.h
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
xAOD::MissingETComponent_v1::Weight::operator+=
Weight & operator+=(const Weight &wght)
Add another weight.
Definition: MissingETComponent_v1.cxx:18
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
xAOD::MissingETComponent_v1::setStatusWord
bool setStatusWord(MissingETBase::Types::bitmask_t sw=MissingETBase::Status::clearedStatus())
Set the statusword of a MET term.
xAOD::MissingETComponent_v1::operator=
MissingETComponent_v1 & operator=(const MissingETComponent_v1 &compDescr)
Definition: MissingETComponent_v1.cxx:103
xAOD::MissingETComponent_v1::size
size_t size() const
[Deprecated] Update all internally used ElementLink instances
xAOD::MissingETComponent_v1::f_wpx
std::vector< double > & f_wpx()
xAOD::MissingETComponent_v1::createPrivateStore
void createPrivateStore()
Function initialising the object to work in standalone mode.
Definition: MissingETComponent_v1.cxx:341
MissingETBase::Numerical::wpxError
static double wpxError()
Access error return value for kinematic weight .
Definition: MissingETBase.h:90
xAOD::MissingETComponent_v1::f_wpy
std::vector< double > & f_wpy()
xAOD::MissingETComponent_v1::setMetLink
bool setMetLink(const MissingETBase::Types::metlink_t &metLnk)
Set the link to the MET object.
Definition: MissingETComponent_v1.cxx:264
MissingETBase::Types::objlink_vector_t
std::vector< objlink_t > objlink_vector_t
Vector of object links type.
Definition: MissingETCompositionBase.h:58
xAOD::MissingETComponent_v1::MissingETComponent_v1
MissingETComponent_v1(bool createStore=false)
Default constructor.
Definition: MissingETComponent_v1.cxx:56
xAOD::MissingETComponent_v1::setWet
bool setWet(const std::vector< double > &wcv)
Set the vector of weight components
Definition: MissingETComponent_v1.cxx:230
xAOD::MissingET_v1
Principal data object for Missing ET.
Definition: MissingET_v1.h:25
xAOD::MissingETComponent_v1::addObject
bool addObject(const IParticle *pPart, const Weight &wght=Weight())
Add object (particle) from pointer reference with optional kinematic weight.
xAOD::MissingETComponent_v1::f_statusWord
MissingETBase::Types::bitmask_t & f_statusWord()
xAOD::MissingETComponent_v1::Weight::wpy
double wpy() const
Returns .
xAOD::MissingETComponent_v1::Weight::operator-=
Weight & operator-=(const Weight &wght)
Subtract another weight.
Definition: MissingETComponent_v1.cxx:21
MissingETBase::Numerical::wpxDefault
static double wpxDefault()
Access default kinematic weight .
Definition: MissingETBase.h:87
xAOD::MissingETComponent_v1::objectLinks
const MissingETBase::Types::objlink_vector_t & objectLinks() const
Get the vector of links to the contributing physics or signal objects.
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
xAOD::MissingETComponent_v1::f_objectLinks
MissingETBase::Types::objlink_vector_t & f_objectLinks()
Non-const link reference.
MissingETBase::Numerical::isEqual
static bool isEqual(double x, double y)
Test of equality.
Definition: MissingETBase.h:119
xAOD::MissingETComponent_v1::setObjectLinks
bool setObjectLinks(const MissingETBase::Types::objlink_vector_t &objLnks)
Set the vector of links to the contributing physics or signal objects.
Definition: MissingETComponent_v1.cxx:270
xAOD::MissingETComponent_v1::f_metLink
MissingETBase::Types::metlink_t & f_metLink()
Non-const link reference
MissingETBase::Numerical::wetError
static double wetError()
Access error return value for kinematic weight .
Definition: MissingETBase.h:92
SG::AuxElement::makePrivateStore
void makePrivateStore()
Create a new (empty) private store for this object.
Definition: AuxElement.cxx:192
xAOD::MissingETComponent_v1::statusWord
MissingETBase::Types::bitmask_t statusWord() const
Get the statusword.
xAOD::MissingETComponent_v1::findIndex
size_t findIndex(const IParticle *pPart) const
Find index of given object in contributing object store.
Definition: MissingETComponent_v1.cxx:213
xAOD::MissingETComponent_v1::Weight::wpx
double wpx() const
Returns .
xAOD::MissingETComponent_v1::removeContrib
bool removeContrib()
Remove all contributions.
Definition: MissingETComponent_v1.cxx:165
xAOD::MissingETComponent_v1::f_wet
std::vector< double > & f_wet()
xAOD::MissingETComponent_v1::wpy
const std::vector< double > & wpy() const
Get the vector of weight components
xAOD::MissingETComponent_v1::Weight::operator==
bool operator==(const Weight &wght) const
Equality comparator.
Definition: MissingETComponent_v1.cxx:44
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
xAOD::MissingETComponent_v1::Weight
Kinematic weight descriptor.
Definition: MissingETComponent_v1.h:28
MissingETBase::Types::metlink_t
ElementLink< xAOD::MissingETContainer > metlink_t
Link to MissingET object.
Definition: MissingETCompositionBase.h:37
xAOD::MissingETComponent_v1::Weight::operator*=
Weight & operator*=(const Weight &wght)
Multiply two weights.
Definition: MissingETComponent_v1.cxx:24
xAOD::MissingETComponent_v1::metLink
const MissingETBase::Types::metlink_t & metLink() const
Get the link to the MET object.
MissingETBase::Numerical::wetDefault
static double wetDefault()
Access default kinematic weight .
Definition: MissingETBase.h:89
xAOD::MissingETComponent_v1::f_removeContrib
bool f_removeContrib(size_t pIdx)
Copy the contribution data from a source.
Definition: MissingETComponent_v1.cxx:172
MissingETBase::Status::clearedStatus
static Types::bitmask_t clearedStatus()
Cleared term tag accessor.
Definition: MissingETCompositionBase.h:115
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
MissingETBase::Numerical::wpyError
static double wpyError()
Access error return value for kinematic weight .
Definition: MissingETBase.h:91
MissingETBase::Types
Namespace for generally used type definitions.
Definition: MissingETAssociation_v1.h:456
xAOD::MissingETComponent_v1
MET component descriptor contains object links and corresponding parameters.
Definition: MissingETComponent_v1.h:24
MissingETBase::Numerical::wpyDefault
static double wpyDefault()
Access default kinematic weight .
Definition: MissingETBase.h:88
xAOD::MissingETComponent_v1::empty
bool empty() const
Empty list of contributing objects indicator.
xAOD::MissingETComponent_v1::objects
std::vector< const IParticle * > objects() const
Access contributing objects.
Definition: MissingETComponent_v1.cxx:295