ATLAS Offline Software
Loading...
Searching...
No Matches
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
11using namespace xAOD;
12using 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
50}
51
53// Constructors and destructors //
55
57 : SG::AuxElement(){
58
59 if( createStore ) createPrivateStore();
60}
61
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
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
122bool 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 {
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);
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);
176 std::vector<double>::iterator fWpx(this->f_wpx().begin()); std::advance<std::vector<double>::iterator>(fWpx,pIdx);
177 this->f_wpx().erase(fWpx);
178 std::vector<double>::iterator fWpy(this->f_wpy().begin()); std::advance<std::vector<double>::iterator>(fWpy,pIdx);
179 this->f_wpy().erase(fWpy);
180 std::vector<double>::iterator fWet(this->f_wet().begin()); std::advance<std::vector<double>::iterator>(fWet,pIdx);
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
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
226bool 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(); }
228bool 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(); }
230bool 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?
235bool 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; } }
237bool 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; } }
239bool 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; } }
241bool 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);
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());
275 for(MissingETBase::Types::objlink_vector_t::iterator iLink=this->f_objectLinks().begin();
276 iLink!=this->f_objectLinks().end(); ++iLink) {
278 }
279 }
280 return wasSet;
281}
282
283
285// Getters //
287
288double MissingETComponent_v1::wpx(size_t pIdx) const
289{ return pIdx != MissingETBase::Numerical::invalidIndex() && pIdx < this->size() ? this->wpx()[pIdx] : MissingETBase::Numerical::wpxError(); }
290double MissingETComponent_v1::wpy(size_t pIdx) const
291{ return pIdx != MissingETBase::Numerical::invalidIndex() && pIdx < this->size() ? this->wpy()[pIdx] : MissingETBase::Numerical::wpyError(); }
292double MissingETComponent_v1::wet(size_t pIdx) const
293{ return pIdx != MissingETBase::Numerical::invalidIndex() && pIdx < this->size() ? this->wet()[pIdx] : MissingETBase::Numerical::wetError(); }
294
295std::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
302std::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
312std::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
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}
void makePrivateStore()
Create a new (empty) private store for this object.
AuxElement()
Default constructor.
Class providing the definition of the 4-vector interface.
Weight & operator-=(const Weight &wght)
Subtract another weight.
bool operator==(const Weight &wght) const
Equality comparator.
double wpx() const
Returns .
Weight & operator*=(const Weight &wght)
Multiply two weights.
double wpy() const
Returns .
double wet() const
Returns .
Weight & operator+=(const Weight &wght)
Add another weight.
Weight & operator/=(const Weight &wght)
Divide two weights.
bool f_removeContrib(size_t pIdx)
Copy the contribution data from a source.
size_t size() const
[Deprecated] Update all internally used ElementLink instances
MissingETComponent_v1 & operator=(const MissingETComponent_v1 &compDescr)
const std::vector< double > & wpx() const
Get the vector of weight components.
MissingETBase::Types::bitmask_t & f_statusWord()
Weight weight(const IParticle *pPart) const
Get kinematic weight for a given object.
const std::vector< double > & wet() const
Get the vector of weight components.
std::vector< double > & f_wet()
MissingETBase::Types::bitmask_t statusWord() const
Get the statusword.
bool empty() const
Empty list of contributing objects indicator.
std::vector< const IParticle * > objects() const
Access contributing objects.
void f_setObject(const POBJ *pObj, LINK &elemLink)
Generalized link manager.
bool setWet(const std::vector< double > &wcv)
Set the vector of weight components.
bool addObject(const IParticle *pPart, const Weight &wght=Weight())
Add object (particle) from pointer reference with optional kinematic weight.
MissingETBase::Types::objlink_vector_t & f_objectLinks()
Non-const link reference.
bool setMET(const MissingET *pmetObj, MissingETBase::Types::bitmask_t sw=MissingETBase::Status::clearedStatus())
Set MET object by object pointer reference.
const MissingETBase::Types::objlink_vector_t & objectLinks() const
Get the vector of links to the contributing physics or signal objects.
std::vector< double > & f_wpx()
bool removeContrib()
Remove all contributions.
bool resetContrib()
Reset all contribution parameters.
size_t findIndex(const IParticle *pPart) const
Find index of given object in contributing object store.
MissingETBase::Types::metlink_t & f_metLink()
Non-const link reference.
virtual ~MissingETComponent_v1()
Assignment operator.
void createPrivateStore()
Function initialising the object to work in standalone mode.
bool operator==(const MissingETComponent_v1 &contrib) const
bool setObjectLinks(const MissingETBase::Types::objlink_vector_t &objLnks)
Set the vector of links to the contributing physics or signal objects.
const std::vector< double > & wpy() const
Get the vector of weight components.
MissingETComponent_v1(bool createStore=false)
Default constructor.
const MissingETBase::Types::metlink_t & metLink() const
Get the link to the MET object.
bool f_setLink(LINK &elemLink)
bool setStatusWord(MissingETBase::Types::bitmask_t sw=MissingETBase::Status::clearedStatus())
Set the statusword of a MET term.
bool setWpy(const std::vector< double > &wpyVector)
Set the vector of weight components.
bool setWpx(const std::vector< double > &wcv)
Set the vector of weight components.
bool setMetLink(const MissingETBase::Types::metlink_t &metLnk)
Set the link to the MET object.
bool setWeight(const IParticle *pPart, const Weight &wght=Weight())
Set the kinematic weight of an object contribution referenced by pointer.
std::vector< double > & f_wpy()
Container for xAOD::MissingET_v1 objects.
Namespace for generally used type definitions.
std::vector< weight_t > weight_vector_t
Vector type for kinematic weight containers.
uint64_t bitmask_t
Type for status word bit mask.
ElementLink< xAOD::MissingETContainer > metlink_t
Link to MissingET object.
std::vector< objlink_t > objlink_vector_t
Vector of object links type.
ElementLink< xAOD::IParticleContainer > objlink_t
Link to contributing object.
Forward declaration.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
MissingET_v1 MissingET
Version control by type defintion.
static double wpxDefault()
Access default kinematic weight .
static double wpyError()
Access error return value for kinematic weight .
static double wpxError()
Access error return value for kinematic weight .
static double wetDefault()
Access default kinematic weight .
static double divide(double x, double y)
Failsafe division.
static bool isEqual(double x, double y)
Test of equality.
static size_t invalidIndex()
Access invalid index indicator.
static double wetError()
Access error return value for kinematic weight .
static double wpyDefault()
Access default kinematic weight .
static Types::bitmask_t clearedStatus()
Cleared term tag accessor.