ATLAS Offline Software
Loading...
Searching...
No Matches
Event/xAOD/xAODMissingET/Root/MissingETComposition.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#include <cstdio>
9#include <utility>
10
11
12namespace xAOD {
13
14 // ------------------------------------------------------ generate contribution
15
16 // MissingETComponent* MissingETComposition::Contribution::generate()
17 // { return new MissingETComponent(); }
18
19 // MissingETComponent* MissingETComposition::Contribution::generate(const MissingET* pMET)
20 // { return new MissingETComponent(pMET); }
21
22 // MissingETComponent* MissingETComposition::Contribution::generate(const MissingET* pMET,const IParticle* pPart,const MissingETBase::Types::weight_t& weight,MissingETBase::Types::bitmask_t status)
23 // { return new MissingETComponent(pMET,pPart,weight,status); }
24
25 // MissingETComponent* MissingETComposition::Contribution::generate(const MissingET* pMET,const IParticle* pPart,double wpx,double wpy,double wet,MissingETBase::Types::bitmask_t status)
26 // { return new MissingETComponent(pMET,pPart,wpx,wpy,wet,status); }
27
28 // -------------------------------------------------------- insert contribution
30 {
31 // input check
32 if ( pMap == nullptr || pMET == nullptr )
33 { printf("MissingETComposition::add - ERROR - possible invalid pointer values: MissingETComponentMap* = %p, MissingET* = %p\n",(void*)pMap,(void*)pMET); return false; }
34 // check if MET object already in map
35 if ( pMap->find(pMET) != pMap->end() )
36 { printf("MissingETComposition::add - WARNING - MissingET object \042%s\042 already in map, not added again\n",pMET->name().c_str()); return false; }
37 // insert object
38 pMap->push_back(new MissingETComponent(pMET,sw));
39 return pMap->back() != nullptr;
40 }
41
43 { return insert(pMap,pMET,pPart,weight.wpx(),weight.wpy(),weight.wet()); }
44
45 bool MissingETComposition::insert(MissingETComponentMap* pMap,const MissingET* pMET,const IParticle* pPart,double wpx,double wpy,double wet)
46 {
47 // input check
48 if ( pMap == nullptr || pMET == nullptr )
49 { printf("MissingETComposition::insert - ERROR - possible invalid pointer values: MissingETComponentMap* = %p, MissingET* = %p\n",(void*)pMap,(void*)pMET); return false; }
50 // check if MET object already in map
51 MissingETComponentMap::iterator fMap(pMap->find(pMET));
52 if ( fMap == pMap->end() )
53 { printf("MissingETComposition::insert - ERROR - referenced MissingET object \042%%%s\042 not yet in map, add first!\n",pMET->name().c_str()); return false; }
54
55 (*fMap)->addObject(pPart,wpx,wpy,wet);
56 return true;
57 }
58
61 { return insert(pMap,pMET,pPart,signalList,weight.wpx(),weight.wpy(),weight.wet(),p); }
62
64 const MissingETBase::Types::object_vector_t& signalList,double wpx,double wpy,double wet,MissingETBase::UsageHandler::Policy p)
65 {
66 bool flag(insert(pMap,pMET,pPart,wpx,wpy,wet));
67 if ( flag && !signalList.empty() ) { flag = pMap->addObjects(pMET,pPart,signalList,p); }
68 return flag;
69 }
70
71 // ------------------------------------------ find contribution from a particle
72
73 // It is assumed that the default constructor for DataVector<MissingETComponent>::(const_)iterator initalizes
74 // with a (const MissingETComponent*)0 value (correct according to bits/stl_iterator.h). A test of the return
75 // value of the functions below should then be:
76 //
77 // MissingETComponentMap::iterator f = MissingETComposition::find(pMap,pMET);
78 // if ( *f == 0 ) { printf("MissingET object <%s> not found in map\n",pMET->name().c_str()); }
79 //
80 // Note that this should work because the payload of DataVector<MissingETComponent> is actually a pointer.
81
84
87
89 { return pMap !=nullptr ? pMap->find(metName) : MissingETComponentMap::const_iterator(); }
90
92 { return pMap !=nullptr ? pMap->find(metName) : MissingETComponentMap::iterator(); }
93
96
99
101 {
102 if ( pMap == nullptr ) { return MissingETComponentMap::const_iterator(); }
103 // linear search - FIXME: method find(const IParticle*) in MissingETComponentMap ??
106 bool found(false);
107 while ( fCont != lCont && !found ) { found = (*fCont)->findIndex(pPart) != MissingETBase::Numerical::invalidIndex(); if ( !found ) { ++fCont; } }
108 return fCont;
109 }
110
112 {
113 if ( pMap == nullptr ) { return MissingETComponentMap::iterator(); }
114 // linear search - FIXME: method find(const IParticle*) in MissingETComponentMap ??
117 bool found(false);
118 while ( fCont != lCont && !found ) { found = (*fCont)->findIndex(pPart) != MissingETBase::Numerical::invalidIndex(); if ( !found ) { ++fCont; } }
119 return fCont;
120 }
121
123 {
124 if ( pMap == nullptr ) { return (const MissingETComponent*)nullptr; }
125 else { MissingETComponentMap::const_iterator fCont(find(pMap,pPart)); return fCont != pMap->end() ? *fCont : (const MissingETComponent*)nullptr; }
126 }
127
129 {
130 if ( pMap == nullptr ) { return (MissingETComponent*)nullptr; }
131 else { MissingETComponentMap::iterator fCont(find(pMap,pPart)); return fCont != pMap->end() ? *fCont : (MissingETComponent*)nullptr; }
132 }
133
135 { MissingETComponentMap::const_iterator fCont(find(pMap,pMET)); return fCont != pMap->end() ? *fCont : (const MissingETComponent*)nullptr; }
136
138 { MissingETComponentMap::iterator fCont(find(pMap,pMET)); return fCont != pMap->end() ? *fCont : (MissingETComponent*)nullptr; }
139
141 { MissingETComponentMap::const_iterator fCont(find(pMap,metName)); return fCont != pMap->end() ? *fCont : (const MissingETComponent*)nullptr; }
142
144 { MissingETComponentMap::iterator fCont(find(pMap,metName)); return fCont != pMap->end() ? *fCont : (MissingETComponent*)nullptr; }
145
148
151
152 // ------------------------------------------------------------- accessing data
153
154 // -- kinematic weights
156 //{ return getWeight(pMap,find(pMap,pPart,status)); }
157 { MissingETComponentMap::const_iterator fCont(find(pMap,pPart)); return fCont == pMap->end() ? MissingETBase::Types::weight_t(0.,0.,0.) : (*fCont)->weight(pPart); }
158
160 { return *fCont != nullptr ? (*fCont)->weight(pPart) : MissingETBase::Types::weight_t(0.,0.,0.); }
161
162 // -- status word
164 { MissingETComponentMap::const_iterator fCont(find(pMap,pmetObj)); return fCont == pMap->end() ? MissingETBase::Status::clearedStatus() : (*fCont)->statusWord(); }
165
168
169 // -- MissingET object
171 { return getMissingET(find(pMap,pPart)); }
172
174 { return *fCont != nullptr ? (*fCont)->metObject() : (const MissingET*)nullptr; }
175
177 { return getMissingET(find(pMap,name)); }
178
181
182 // -------------------------------------------------------- filling MET objects
183
184
185
186 bool MissingETComposition::add(MissingETAssociationMap* pMap,const Jet* pJet, const std::vector<ElementLink<IParticleContainer> >& jetconst,
188 {
189 // input check
190 if ( pMap == nullptr || pJet == nullptr )
191 { printf("MissingETComposition::add - ERROR - possible invalid pointer values: MissingETAssociationMap* = %p, Jet* = %p\n",(void*)pMap,(void*)pJet); return false; }
192 // check if jet already in map
193 if ( pMap->find(pJet) != pMap->end() )
194 { printf("MissingETComposition::add - WARNING - jet with index %zu already in map, not added again\n",pJet->index()); return false; }
195 // insert object
196 size_t nextIdx = pMap->size();
197 pMap->push_back(new MissingETAssociation(pJet));
198 pMap->setJetConstituents(jetconst,nextIdx);
199 // printf("Jet track vector: px %f, py %f\n",trkvec.cpx(),trkvec.cpy());
200 pMap->back()->setJetTrkVec(trkvec);
201 return pMap->back() != nullptr;
202 }
203
204 bool MissingETComposition::add(MissingETAssociationMap* pMap,const Jet* pJet, const std::vector<const IParticle*>& jettracks)
205 {
206 // input check
207 if ( pMap == nullptr || pJet == nullptr )
208 { printf("MissingETComposition::add - ERROR - possible invalid pointer values: MissingETAssociationMap* = %p, Jet* = %p\n",(void*)pMap,(void*)pJet); return false; }
209 // check if jet already in map
210 if ( pMap->find(pJet) != pMap->end() )
211 { printf("MissingETComposition::add - WARNING - jet with index %zu already in map, not added again\n",pJet->index()); return false; }
212 // insert object
213 // size_t nextIdx = pMap->size();
214 std::vector<ElementLink<IParticleContainer> > jetconst = pJet->constituentLinks();
216 if(!jettracks.empty()) {
217 const IParticleContainer* pTrkCont = static_cast<const IParticleContainer*>(jettracks.front()->container());
218 for(const auto& trk : jettracks) {
219 ElementLink<IParticleContainer> link(*pTrkCont,trk->index());
220 jetconst.push_back(link);
221 trkvec += *trk;
222 }
223 }
224 return add(pMap,pJet,jetconst,trkvec);
225 }
226
228 {
229 // input check
230 if ( pMap == nullptr )
231 { printf("MissingETComposition::addMiscAssociation - ERROR - possible invalid pointer values: MissingETAssociationMap* = %p\n",(void*)pMap); return false; }
232 // insert object
233 pMap->push_back(new MissingETAssociation((const Jet*)nullptr,true));
234 return pMap->back() != nullptr;
235 }
236
237 bool MissingETComposition::insert(MissingETAssociationMap* pMap,size_t jetIndex,const IParticle* pPart,const std::vector<const IParticle*>& constlist)
238 {
239 // input check
240 if ( pMap == nullptr )
241 { printf("MissingETComposition::insert - ERROR - possible invalid pointer value: MissingETAssociationMap* = %p\n",(void*)pMap); return false; }
242 // check if MET object already in map
243
244 // printf("MissingETComposition::insert - INFO - associated to jet %lu\n",jetIndex);
245
246 if ( jetIndex==MissingETBase::Numerical::invalidIndex() || jetIndex>=pMap->size())
247 { printf("MissingETComposition::insert - WARNING - no MissingETAssociation matching this jet, could not add\n"); return false; }
248
249 (*pMap)[jetIndex]->addObject(pPart,constlist);
250 return true;
251 }
252
253 bool MissingETComposition::insert(MissingETAssociationMap* pMap,const Jet* pJet,const IParticle* pPart,const std::vector<const IParticle*>& constlist)
254 {
255 // input check
256 if ( pMap == nullptr || pJet == nullptr )
257 { printf("MissingETComposition::insert - ERROR - possible invalid pointer values: MissingETAssociationMap* = %p, Jet* = %p\n",(void*)pMap,(void*)pJet); return false; }
258 // check if jet already in map
259 size_t jetIndex(pMap->findIndex(pJet));
261 { printf("MissingETComposition::insert - WARNING - jet with pointer %p not in map, could not add\n",(void*)pJet); return false; }
262
263 return insert(pMap,jetIndex,pPart,constlist);
264 }
265
266 bool MissingETComposition::insert(MissingETAssociationMap* pMap,const IParticle* pPart,const std::vector<const IParticle*>& constlist,
267 std::map<const IParticle*,MissingETBase::Types::constvec_t> pOverride)
268 {
269 // input check
270 if ( pMap == nullptr )
271 { printf("MissingETComposition::insert - ERROR - possible invalid pointer values: MissingETAssociationMap* = %p\n",(void*)pMap); return false; }
272
273 // loop over constituents and try to identify an appropriate association
274 // FIXME: check in case more than one appropriate index found?
275 std::map<size_t,std::vector<const IParticle*> > constMap;
276 for(const auto& signal : constlist) {
277 size_t jetIndex = pMap->findIndexByJetConst(signal);
278 // printf("Constituent type %i, jetIndex %lu\n",signal->type(),jetIndex);
279 constMap[jetIndex].push_back(signal);
280 }
281 std::map<size_t,std::vector<const IParticle*> >::iterator jetIter;
282 for(auto& jetIter : constMap) {
283 if(jetIter.first!=MissingETBase::Numerical::invalidIndex()) {
284 insert(pMap,jetIter.first,pPart,jetIter.second);
285 // printf("Associated object (type %d, pt %f) with jet %lu\n",pPart->type(),pPart->pt(),jetIter.first);
286 (*pMap)[jetIter.first]->addOverrideMom(pOverride);
287 } else {
288 insertMisc(pMap,pPart,jetIter.second);
289 pMap->getMiscAssociation()->addOverrideMom(pOverride);
290 }
291 }
292 if (constMap.empty()) insertMisc(pMap,pPart,std::vector<const IParticle*>());
293 return true;
294 }
295
296 bool MissingETComposition::setJetConstSum(MissingETAssociationMap* metMap,const Jet* jet,const std::vector<const IParticle*>& altConsts,
297 std::map<const IParticle*,MissingETBase::Types::constvec_t> pOverride) {
298 std::vector<ElementLink<IParticleContainer> > jetconst;
299 if(!altConsts.empty()) {
300 for(const auto& alt : altConsts) {
301 const IParticleContainer* pCont = static_cast<const IParticleContainer*>(alt->container());
302 ElementLink<IParticleContainer> link(*pCont,alt->index());
303 jetconst.push_back(link);
304 }
305 }
306 metMap->setJetConstituents(jetconst,jet);
307 if (!altConsts.empty()) insert(metMap,jet,altConsts,std::move(pOverride));
308 else insert(metMap,jet,jet,altConsts);
309 return true;
310 }
311
312 bool MissingETComposition::insertMisc(MissingETAssociationMap* pMap,const IParticle* pPart,const std::vector<const IParticle*>& constlist)
313 {
314 // input check
315 if ( pMap == nullptr )
316 { printf("MissingETComposition::insertMisc - ERROR - possible invalid pointer values: MissingETAssociationMap* = %p\n",(void*)pMap); return false; }
317
319 // loop over constituents and make sure these don't belong to some other association
320 // printf("Associated object (type %d, pt %f) with no jet\n",pPart->type(),pPart->pt());
321 for(const auto& signal : constlist) {
322 // printf("MissingETComposition::insertMisc - INFO - constituent pt %f\n", signal->pt());
323 jetIndex = pMap->findIndexByJetConst(signal);
325 printf("MissingETComposition::insertMisc - ERROR - object %p with constituent %p is associated to jet %zu, will not place in misc association\n",(void*)pPart,(void*)signal,jetIndex); return false;
326 }
327 }
328 pMap->getMiscAssociation()->addObject(pPart,constlist);
329
330 return true;
331 }
332
335
338
340 {
341 if ( pMap == nullptr ) { return MissingETAssociationMap::const_iterator(); }
342 // linear search - FIXME: method find(const IParticle*) in MissingETAssociationMap ??
345 bool found(false);
346 while ( fAssoc != lAssoc && !found ) { found = (*fAssoc)->findIndex(pPart) != MissingETBase::Numerical::invalidIndex(); if ( !found ) { ++fAssoc; } }
347 return fAssoc;
348 }
349
351 {
352 if ( pMap == nullptr ) { return MissingETAssociationMap::iterator(); }
353 // linear search - FIXME: method find(const IParticle*) in MissingETAssociationMap ??
354 MissingETAssociationMap::iterator fAssoc(pMap->begin());
355 MissingETAssociationMap::iterator lAssoc(pMap->end());
356 bool found(false);
357 while ( fAssoc != lAssoc && !found ) { found = (*fAssoc)->findIndex(pPart) != MissingETBase::Numerical::invalidIndex(); if ( !found ) { ++fAssoc; } }
358 return fAssoc;
359 }
360
362 {
364 std::vector<const MissingETAssociation*> assocs = getAssociations(pMap,pPart);
365 for (size_t i = 0; i < assocs.size(); i++) {
367 totalvec += assocs[i]->trkVec(pPart);
368 } else {
369 totalvec += assocs[i]->calVec(pPart);
370 }
371 }
372 return totalvec;
373 }
374
376 std::vector<const MissingETAssociation*> assocs = getAssociations(helper.map(),obj);
377 for(size_t i = 0; i < assocs.size(); i++) if(helper.objSelected(assocs[i],obj)) return true;
378 return false;
379 }
380
381
383 std::vector<const MissingETAssociation*> assocs = getAssociations(helper.map(),obj);
384 bool overlaps(false);
385 for(size_t i = 0; i < assocs.size(); i++) overlaps |= assocs[i]->hasOverlaps(helper,obj,p);
386 if (overlaps) return false;
387 for(size_t i = 0; i < assocs.size(); i++) helper.setObjSelectionFlag(assocs[i],obj,true);
388 return true;
389 }
390
391 std::vector<const MissingETAssociation*> MissingETComposition::getAssociations(const MissingETAssociationMap* pMap,const IParticle* pPart)
392 {
393 std::vector<const MissingETAssociation*> assocs;
394 if ( pMap == nullptr ) { return assocs; }
395 else {
396 for (const auto fAssoc : *pMap) {
397 if (fAssoc->findIndex(pPart) != MissingETBase::Numerical::invalidIndex()) assocs.push_back(fAssoc);
398 }
399 }
400 return assocs;
401 }
402
403 std::vector<MissingETAssociation*> MissingETComposition::getAssociations(MissingETAssociationMap* pMap,const IParticle* pPart)
404 {
405 std::vector<MissingETAssociation*> assocs;
406 if ( pMap == nullptr ) { return assocs; }
407 else {
408 for (const auto fAssoc : *pMap) {
409 if (fAssoc->findIndex(pPart) != MissingETBase::Numerical::invalidIndex()) assocs.push_back(fAssoc);
410 }
411 }
412 return assocs;
413 }
414
416 { MissingETAssociationMap::const_iterator fAssoc(find(pMap,pJet)); return fAssoc != pMap->end() ? *fAssoc : (const MissingETAssociation*)nullptr; }
417
419 { MissingETAssociationMap::iterator fAssoc(find(pMap,pJet)); return fAssoc != pMap->end() ? *fAssoc : (MissingETAssociation*)nullptr; }
420
421 // MissingETBase::Types::constvec_t MissingETComposition::getConstVec(const MissingETAssociationMap* pMap,const IParticle* pPart);
422
423 // MissingETBase::Types::constvec_t MissingETComposition::getConstVec(MissingETAssociationMap::const_iterator fAssoc,const IParticle* pPart);
424
426 {
428 return fAssoc==pMap->end() ? nullptr : getRefJet(fAssoc);
429 }
430
432 { return *fAssoc != nullptr ? (*fAssoc)->refJet() : (const Jet*) nullptr; }
433}
Defines enum to access jet attribute and associated particles/objects.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const T * back() const
Access the last element in the collection as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
size_t index() const
Return the index of this element within its container.
Class providing the definition of the 4-vector interface.
const std::vector< ElementLink< IParticleContainer > > & constituentLinks() const
Direct access to constituents. WARNING expert use only.
Definition Jet_v1.cxx:162
bool setJetConstituents(const Jet *pJet)
Set constituent map for a jet.
const_iterator find(const Jet *pJet) const
Find association from jet pointer.
size_t findIndexByJetConst(const IParticle *pConst) const
const MissingETAssociation_v1 * getMiscAssociation() const
Get an association for miscellaneous objects not associated to jets.
void addOverrideMom(std::map< const IParticle *, ConstVec > &pOverride)
Extend override momentum map.
bool addObject(const IParticle *pPart, const std::vector< const IParticle * > &constlist)
Add object (particle) from pointer reference with individual constituent vectors.
bool addObjects(const MissingET *pMET, const IParticle *pPart, const MissingETBase::Types::object_vector_t &signalList, MissingETBase::UsageHandler::Policy p=MissingETBase::UsageHandler::OnlyCluster)
const_iterator find(const MissingET *pMET) const
Find MET object referenced by pointer.
const std::string & name() const
Identifier getters.
std::vector< const xAOD::IParticle * > object_vector_t
Vector of object type.
xAOD::MissingETAssociation_v1::ConstVec constvec_t
Type for constituent vector.
uint64_t bitmask_t
Type for status word bit mask.
xAOD::MissingETComponent_v1::Weight weight_t
Type for kinematic weight.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Jet_v1 Jet
Definition of the current "jet version".
MissingETComponent_v1 MissingETComponent
Version control by type definition.
MissingETAssociation_v1 MissingETAssociation
Version control by type definition.
MissingETComponentMap_v1 MissingETComponentMap
Version control by type definition.
MissingET_v1 MissingET
Version control by type defintion.
JetConstituentVector::iterator iterator
MissingETAssociationMap_v1 MissingETAssociationMap
Version control by type defintion.
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.
static size_t invalidIndex()
Access invalid index indicator.
static Types::bitmask_t clearedStatus()
Cleared term tag accessor.
static MissingETComponentMap::const_iterator find(const MissingETComponentMap *pMap, const MissingET *pmetObj)
Find non-modifiable contribution for a given MET object.
static bool addMiscAssociation(MissingETAssociationMap *pMap)
Add an association to hold objects not associated to any jet.
static std::vector< const MissingETAssociation * > getAssociations(const MissingETAssociationMap *pMap, const IParticle *pPart)
Access non-modifiable contribution object.
static bool setJetConstSum(MissingETAssociationMap *metMap, const Jet *jet, const std::vector< const IParticle * > &altConsts, std::map< const IParticle *, MissingETBase::Types::constvec_t > pOverride)
static MissingETBase::Types::bitmask_t getStatusWord(const MissingETComponentMap *pMap, const MissingET *pmetObj)
static const Jet * getRefJet(const MissingETAssociationMap *pMap, const IParticle *pPart)
static bool insert(MissingETComponentMap *pMap, const MissingET *pMET, const IParticle *pPart, MissingETBase::Types::weight_t weight=MissingETBase::Types::weight_t())
Insert contributing signal or physics object by pointer, with optional kinematic weight object.
static bool insertMisc(MissingETAssociationMap *pMap, const IParticle *pPart, const std::vector< const IParticle * > &constlist)
Insert contributing object into miscellaneous association.
static bool objSelected(const MissingETAssociationHelper &helper, const IParticle *obj)
static const MissingETComponent * getComponent(const MissingETComponentMap *pMap, const IParticle *pPart)
Access non-modifiable contribution object.
static MissingETBase::Types::constvec_t getConstVec(const MissingETAssociationMap *pMap, const IParticle *pPart, MissingETBase::UsageHandler::Policy p)
static bool selectIfNoOverlaps(MissingETAssociationHelper &helper, const IParticle *obj, MissingETBase::UsageHandler::Policy p)
static MissingETBase::Types::weight_t getWeight(const MissingETComponentMap *pMap, const IParticle *pPart)
static const MissingET * getMissingET(const MissingETComponentMap *pMap, const IParticle *pPart)
static const MissingETAssociation * getAssociation(const MissingETAssociationMap *pMap, const Jet *pJet)
static bool add(MissingETComponentMap *pMap, const MissingET *pMET, MissingETBase::Types::bitmask_t sw=MissingETBase::Status::clearedStatus())
Adding a MissingET object to the map.