ATLAS Offline Software
Loading...
Searching...
No Matches
MissingETAssociationMap_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
6
10
12#include "xAODBase/ObjectType.h"
13
14#include "xAODPFlow/FEHelpers.h"
15
16#include <cstdio>
17#include <iterator>
18#include <utility>
19
20
21using namespace xAOD;
22
24// Internally used constants //
26
28// Constructors and destructor //
30
35
42
45
47// Finders //
49
54
59
61{
62 const_iterator fAssoc = this->f_findConst(pJet);
63 if(fAssoc != this->end() && !(*fAssoc)->isMisc())
64 return std::distance<const_iterator>(this->begin(),fAssoc);
66}
67
69// Protected finders //
71
73{
74 const_iterator fAssoc(this->begin());
75 const_iterator lAssoc(this->end());
76 while ( fAssoc != lAssoc && !(*fAssoc)->isMisc() && (*fAssoc)->refJet() != pJet ) { ++fAssoc; }
77 return fAssoc;
78}
79
81{
82 iterator fAssoc(this->begin());
83 iterator lAssoc(this->end());
84 while ( fAssoc != lAssoc && !(*fAssoc)->isMisc() && (*fAssoc)->refJet() != pJet ) { ++fAssoc; }
85 return fAssoc;
86}
87
89// Cache of jet links //
91
97
102
104{
105 std::vector<ElementLink<IParticleContainer> > jetconst = pJet->constituentLinks();
106 return this->setJetConstituents(jetconst,pJet);
107}
108
110{
111 size_t jetIdx = findIndex(pJet);
112 return this->setJetConstituents(constLinks,jetIdx);
113}
114
115bool MissingETAssociationMap_v1::setJetConstituents(const std::vector<ElementLink<IParticleContainer> >& constLinks, size_t jetIndex)
116{
117 bool setConst = (jetIndex!=MissingETBase::Numerical::invalidIndex());
118 if(setConst) {
119 for(std::vector<ElementLink<IParticleContainer> >::const_iterator iEL=constLinks.begin();
120 iEL!=constLinks.end(); ++iEL) {
121 m_jetConstLinks[*iEL] = jetIndex;
122 }
123 }
124 return setConst;
125}
126
128{
129 const IParticleContainer* pCont = static_cast<const IParticleContainer*>(pConst->container());
130 ElementLink<IParticleContainer> el(*pCont,pConst->index());
131 return findByJetConst(el);
132}
133
135{
136 const IParticleContainer* pCont = static_cast<const IParticleContainer*>(pConst->container());
137 ElementLink<IParticleContainer> el(*pCont,pConst->index());
138 return findByJetConst(el);
139}
140
142{
144 size_t index = findIndexByJetConst(constLink);
146 iAssoc = this->begin() + index;
147 }
148 return iAssoc;
149}
150
152{
154 size_t index = findIndexByJetConst(constLink);
156 iAssoc = this->begin() + index;
157 }
158 return iAssoc;
159}
160
162{
163 const IParticleContainer* pCont = static_cast<const IParticleContainer*>(pConst->container());
164 ElementLink<IParticleContainer> el(*pCont,pConst->index());
165 return findIndexByJetConst(el);
166}
167
169{
171 std::map<ElementLink<IParticleContainer>, size_t>::const_iterator iConstMap = m_jetConstLinks.find(constLink);
172 if (iConstMap==m_jetConstLinks.end()) {
173 for (std::map<ElementLink<IParticleContainer>, size_t>::const_iterator jConstMap = m_jetConstLinks.begin(); jConstMap!=m_jetConstLinks.end(); ++jConstMap)
174 {
175 if (*(jConstMap->first)==*constLink) iConstMap = jConstMap;
176 }
177 }
178 if(iConstMap!=m_jetConstLinks.end()) {
179 index = iConstMap->second;
180 const_iterator fAssoc(this->begin());
181 std::advance<const_iterator>(fAssoc,index);
182 }
183 return index;
184}
185
187{
190 while ( rIter != fAssoc && !(*rIter)->isMisc() ) { ++rIter; }
191 return rIter != fAssoc ? *rIter : (MissingETAssociation_v1*)nullptr;
192}
193
195{
198 while ( rIter != fAssoc && !(*rIter)->isMisc() ) { ++rIter; }
199 return rIter != fAssoc ? *rIter : (MissingETAssociation_v1*)nullptr;
200}
201
203{
204 bool foundOverlaps(false);
205 for(iterator iAssoc=this->begin(); iAssoc!=this->end(); ++iAssoc) {
206 foundOverlaps |= (*iAssoc)->identifyOverlaps();
207 }
208 return foundOverlaps;
209}
210
212{
213 for(iterator iAssoc=this->begin(); iAssoc!=this->end(); ++iAssoc) {
214 (*iAssoc)->clearOverlaps();
215 }
216}
217
219{
221 for(IParticleContainer::const_iterator iSig=signals->begin();
222 iSig!=signals->end(); ++iSig) {
223 xAOD::Type::ObjectType objType = (*iSig)->type();
224 if(objType == xAOD::Type::FlowElement) objType = FEHelpers::signalToXAODType(static_cast<const xAOD::FlowElement&>(**iSig));
225 switch(p) {
227 if(objType==xAOD::Type::CaloCluster
228 || objType==xAOD::Type::TrackParticle) {break;}
229 else {continue;}
231 if(objType==xAOD::Type::CaloCluster) {break;}
232 else {continue;}
234 if(objType==xAOD::Type::TrackParticle) {break;}
235 else {continue;}
237 if(objType==xAOD::Type::ParticleFlow) {break;}
238 else {continue;}
240 if(objType==xAOD::Type::TruthParticle) {break;}
241 else {continue;}
243 if(objType!=xAOD::Type::TrackParticle) {break;}
244 else {continue;}
245 default: {continue;}
246 }
247
248 size_t assocIndex = findIndexByJetConst(*iSig);
249 // printf("Cluster %lu (%p) ==> assoc %lu\n",(*iSig)->index(), (void*) *iSig, assocIndex);
251 // test misc association
252 const MissingETAssociation_v1* assoc = this->getMiscAssociation();
253 if(!assoc) {
254 uniques->push_back(*iSig);
255 } else {
256 if(!assoc->containsSignal(*iSig)) {
257 // printf("Cluster is unique\n");
258 uniques->push_back(*iSig);
259 } else {
260 // printf("Cluster is in misc\n");
261 }
262 }
263 } // add if not associated to any jet
264 }
265
266 return uniques->asDataVector();
267}
268
270{
272 for(const auto *const sig : *signals) {
273 if(!MissingETAssociation_v1::testPolicy(*sig,p)) continue;
274
275 size_t assocIndex = findIndexByJetConst(sig);
277 // test misc association
278 const MissingETAssociation_v1* assoc = this->getMiscAssociation();
279 if(!assoc) {
280 uniques->push_back(sig);
281 } else {
282 if(!assoc->checkUsage(helper,sig,p)) {
283 uniques->push_back(sig);
284 }
285 }
286 } // add if not associated to any jet
287 else {
288 if(!(*this)[assocIndex]->checkUsage(helper,sig,p)) {
289 uniques->push_back(sig);
290 } // add if not associated to any selected object in its parent jet
291 }
292 }
293
294 return uniques->asDataVector();
295}
Defines enum to access jet attribute and associated particles/objects.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_reverse_iterator rend() const noexcept
std::reverse_iterator< iterator > reverse_iterator
Definition DataVector.h:852
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
DataVector(SG::OwnershipPolicy ownPolicy=SG::OWN_ELEMENTS, SG::IndexTrackingPolicy trackIndices=SG::DEFAULT_TRACK_INDICES)
const_iterator end() const noexcept
const_reverse_iterator rbegin() const noexcept
const_iterator begin() const noexcept
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition DataVector.h:847
const SG::AuxVectorData * container() const
Return the container holding this element.
size_t index() const
Return the index of this element within its container.
STL class.
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.
void f_setJetConstMap(std::map< ElementLink< IParticleContainer >, size_t > map)
MissingETAssociationMap_v1(SG::OwnershipPolicy own=SG::OWN_ELEMENTS, SG::IndexTrackingPolicy trackIndices=SG::DEFAULT_TRACK_INDICES)
Default constructor.
std::map< ElementLink< IParticleContainer >, size_t > m_jetConstLinks
Map jet constituents to the jet index.
const_iterator find(const Jet *pJet) const
Find association from jet pointer.
const IParticleContainer * getUniqueSignals(const IParticleContainer *signals, MissingETBase::UsageHandler::Policy p=MissingETBase::UsageHandler::TrackCluster) const
Extract a container of constituents that are not in jets.
virtual ~MissingETAssociationMap_v1()
Base class destructor.
size_t findIndexByJetConst(const IParticle *pConst) const
const MissingETAssociation_v1 * getMiscAssociation() const
Get an association for miscellaneous objects not associated to jets.
const_iterator f_findConst(const Jet *pJet) const
Find contribution by reference jet pointer.
const IParticleContainer * getOverlapRemovedSignals(const MissingETAssociationHelper &helper, const IParticleContainer *signals, MissingETBase::UsageHandler::Policy p=MissingETBase::UsageHandler::TrackCluster) const
Extract a container of constituents that do not overlap physics objects.
const_iterator findByJetConst(const IParticle *pConst) const
Find association from jet constituent.
bool identifyOverlaps()
Do overlap-finding in all associations.
MET association descriptor contains object links and corresponding parameters.
bool checkUsage(const MissingETAssociationHelper &helper, const IParticle *pSig, MissingETBase::UsageHandler::Policy p) const
Check if this signal object matches the constituents of any flagged contributing objects.
bool containsSignal(const IParticle *pSig) const
Check if this signal object matches the constituents of any contributing objects.
static bool testPolicy(const xAOD::IParticle &part, MissingETBase::UsageHandler::Policy p)
xAOD::Type::ObjectType signalToXAODType(const xAOD::FlowElement &fe)
ConstDataVector< xAOD::IParticleContainer > const_signal_vector_t
@ AllCalo
Inclusive except tracks.
@ OnlyCluster
CaloCluster based only.
@ ParticleFlow
Particle Flow Object based.
@ TrackCluster
Both cluster and track based.
OwnershipPolicy
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition index.py:1
ObjectType
Type of objects that have a representation in the xAOD EDM.
Definition ObjectType.h:32
@ TrackParticle
The object is a charged track particle.
Definition ObjectType.h:43
@ ParticleFlow
The object is a particle-flow object.
Definition ObjectType.h:41
@ FlowElement
The object is a track-calo-cluster.
Definition ObjectType.h:52
@ CaloCluster
The object is a calorimeter cluster.
Definition ObjectType.h:39
@ TruthParticle
The object is a truth particle.
Definition ObjectType.h:67
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Jet_v1 Jet
Definition of the current "jet version".
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition FlowElement.h:16
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.
static size_t invalidIndex()
Access invalid index indicator.