ATLAS Offline Software
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 
21 using namespace xAOD;
22 
24 // Internally used constants //
26 
28 // Constructors and destructor //
30 
32  : DataVector<MissingETAssociation_v1>(own,trackIndices)
33 {
34 }
35 
39  : DataVector<MissingETAssociation_v1>(first,last,own,trackIndices)
40 {
41 }
42 
44 { }
45 
47 // Finders //
49 
51 {
52  return this->f_findConst(pJet);
53 }
54 
56 {
57  return this->f_find(pJet);
58 }
59 
60 size_t MissingETAssociationMap_v1::findIndex(const Jet* pJet) const
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 
93 {
94  m_jetConstLinks.clear();
95  m_jetConstLinks = std::move(map);
96 }
97 
99 {
100  m_jetConstLinks.clear();
101 }
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 
115 bool 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 {
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);
250  if(assocIndex==MissingETBase::Numerical::invalidIndex()) {
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);
276  if(assocIndex==MissingETBase::Numerical::invalidIndex()) {
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 }
xAOD::MissingETAssociationMap_v1::setJetConstituents
bool setJetConstituents(const Jet *pJet)
Set constituent map for a jet.
Definition: MissingETAssociationMap_v1.cxx:103
xAOD::MissingETAssociationMap_v1::findIndexByJetConst
size_t findIndexByJetConst(const IParticle *pConst) const
Definition: MissingETAssociationMap_v1.cxx:161
xAOD::MissingETAssociationMap_v1::m_jetConstLinks
std::map< ElementLink< IParticleContainer >, size_t > m_jetConstLinks
Map jet constituents to the jet index.
Definition: MissingETAssociationMap_v1.h:157
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
MissingETBase::UsageHandler::TruthParticle
@ TruthParticle
Truth particle based.
Definition: MissingETCompositionBase.h:189
ObjectType
ObjectType
Definition: BaseObject.h:11
xAOD::MissingETAssociation_v1
MET association descriptor contains object links and corresponding parameters.
Definition: MissingETAssociation_v1.h:29
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
xAOD::MissingETAssociationMap_v1::getOverlapRemovedSignals
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.
Definition: MissingETAssociationMap_v1.cxx:269
DataVector< MissingETAssociation_v1 >::rend
const_reverse_iterator rend() const noexcept
Return a const_reverse_iterator pointing at the beginning of the collection.
index
Definition: index.py:1
JetAttributes.h
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
xAOD::MissingETAssociation_v1::containsSignal
bool containsSignal(const IParticle *pSig) const
Check if this signal object matches the constituents of any contributing objects.
Definition: MissingETAssociation_v1.cxx:804
MissingETBase::Numerical::invalidIndex
static size_t invalidIndex()
Access invalid index indicator.
Definition: MissingETBase.h:103
MissingETBase::UsageHandler::OnlyCluster
@ OnlyCluster
CaloCluster based only.
Definition: MissingETCompositionBase.h:184
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
xAOD::MissingETAssociationMap_v1::f_findConst
const_iterator f_findConst(const Jet *pJet) const
Find contribution by reference jet pointer.
Definition: MissingETAssociationMap_v1.cxx:72
xAOD::MissingETAssociation_v1::testPolicy
static bool testPolicy(const xAOD::IParticle &part, MissingETBase::UsageHandler::Policy p)
Definition: MissingETAssociation_v1.cxx:875
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
ConstDataVector::asDataVector
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
SG::OwnershipPolicy
OwnershipPolicy
describes the possible element ownership policies (see e.g. DataVector)
Definition: OwnershipPolicy.h:16
runBeamSpotCalibration.helper
helper
Definition: runBeamSpotCalibration.py:112
xAOD::TrackParticle
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Definition: Event/xAOD/xAODTracking/xAODTracking/TrackParticle.h:13
xAOD::MissingETAssociationMap_v1::MissingETAssociationMap_v1
MissingETAssociationMap_v1(SG::OwnershipPolicy own=SG::OWN_ELEMENTS, SG::IndexTrackingPolicy trackIndices=SG::DEFAULT_TRACK_INDICES)
Default constructor.
Definition: MissingETAssociationMap_v1.cxx:31
DataVector< MissingETAssociation_v1 >::reverse_iterator
std::reverse_iterator< iterator > reverse_iterator
Standard reverse_iterator.
Definition: DataVector.h:851
xAOD::MissingETAssociationMap_v1::f_clearJetConstMap
void f_clearJetConstMap()
Definition: MissingETAssociationMap_v1.cxx:98
xAOD::MissingETAssociationMap_v1::f_setJetConstMap
void f_setJetConstMap(std::map< ElementLink< IParticleContainer >, size_t > map)
Definition: MissingETAssociationMap_v1.cxx:92
xAOD::MissingETAssociationMap_v1::findIndex
size_t findIndex(const Jet *pJet) const
Definition: MissingETAssociationMap_v1.cxx:60
ObjectType.h
xAOD::MissingETAssociationMap_v1::~MissingETAssociationMap_v1
virtual ~MissingETAssociationMap_v1()
Base class destructor.
Definition: MissingETAssociationMap_v1.cxx:43
FlowElement.h
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
MissingETBase::Types::const_signal_vector_t
ConstDataVector< xAOD::IParticleContainer > const_signal_vector_t
Definition: MissingETCompositionBase.h:50
IParticleContainer.h
xAOD::MissingETAssociationMap_v1::find
const_iterator find(const Jet *pJet) const
Find association from jet pointer.
Definition: MissingETAssociationMap_v1.cxx:50
xAOD::FlowElement
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition: FlowElement.h:16
xAOD::MissingETAssociationMap_v1::getUniqueSignals
const IParticleContainer * getUniqueSignals(const IParticleContainer *signals, MissingETBase::UsageHandler::Policy p=MissingETBase::UsageHandler::TrackCluster) const
Extract a container of constituents that are not in jets.
Definition: MissingETAssociationMap_v1.cxx:218
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
python.BuildSignatureFlags.sig
sig
Definition: BuildSignatureFlags.py:215
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
xAODType::ParticleFlow
@ ParticleFlow
The object is a particle-flow object.
Definition: ObjectType.h:41
xAOD::MissingETAssociationMap_v1::findByJetConst
const_iterator findByJetConst(const IParticle *pConst) const
Find association from jet constituent.
Definition: MissingETAssociationMap_v1.cxx:127
xAOD::MissingETAssociationMap_v1::getMiscAssociation
const MissingETAssociation_v1 * getMiscAssociation() const
Get an association for miscellaneous objects not associated to jets.
Definition: MissingETAssociationMap_v1.cxx:186
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
FEHelpers::signalToXAODType
xAOD::Type::ObjectType signalToXAODType(const xAOD::FlowElement &fe)
Definition: FEHelpers.cxx:178
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
DataVector< MissingETAssociation_v1 >::rbegin
const_reverse_iterator rbegin() const noexcept
Return a const_reverse_iterator pointing past the end of the collection.
python.L1.Config.LegacyTopoMergerMap.signals
signals
Definition: LegacyTopoMergerMap.py:13
MissingETBase::UsageHandler::TrackCluster
@ TrackCluster
Both cluster and track based.
Definition: MissingETCompositionBase.h:186
xAOD::Jet_v1::constituentLinks
const std::vector< ElementLink< IParticleContainer > > & constituentLinks() const
Direct access to constituents. WARNING expert use only.
Definition: Jet_v1.cxx:162
MissingETAssociationMap_v1.h
MissingETBase::UsageHandler::Policy
Policy
Policies on usage checks.
Definition: MissingETCompositionBase.h:182
MissingETBase::UsageHandler::AllCalo
@ AllCalo
Inclusive except tracks.
Definition: MissingETCompositionBase.h:183
FEHelpers.h
xAOD::MissingETAssociationMap_v1::f_find
iterator f_find(const Jet *pJet)
Definition: MissingETAssociationMap_v1.cxx:80
DataVector< MissingETAssociation_v1 >::const_reverse_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
Standard const_reverse_iterator.
Definition: DataVector.h:846
MissingETBase::UsageHandler::OnlyTrack
@ OnlyTrack
Track based only.
Definition: MissingETCompositionBase.h:185
ConstDataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::MissingETAssociationMap_v1::identifyOverlaps
bool identifyOverlaps()
Do overlap-finding in all associations.
Definition: MissingETAssociationMap_v1.cxx:202
xAOD::MissingETAssociationHelper
Definition: MissingETAssociationHelper.h:26
MissingETBase::UsageHandler::ParticleFlow
@ ParticleFlow
Particle Flow Object based.
Definition: MissingETCompositionBase.h:188
DataVector< MissingETAssociation_v1 >::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
TrackParticle.h
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
DeMoScan.index
string index
Definition: DeMoScan.py:362
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
xAOD::MissingETAssociationMap_v1::clearOverlaps
void clearOverlaps()
Definition: MissingETAssociationMap_v1.cxx:211
DeMoScan.first
bool first
Definition: DeMoScan.py:534
xAOD::MissingETAssociation_v1::checkUsage
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.
Definition: MissingETAssociation_v1.cxx:818
SG::AuxElement::container
const SG::AuxVectorData * container() const
Return the container holding this element.
SG::IndexTrackingPolicy
IndexTrackingPolicy
Definition: IndexTrackingPolicy.h:37
DataVector< MissingETAssociation_v1 >::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
xAOD::FlowElement_v1
A detector object made of other lower level object(s)
Definition: FlowElement_v1.h:25