ATLAS Offline Software
METAssocTestAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "METAssocTestAlg.h"
8 
9 using namespace xAOD;
10 
11 // allow for differences due to float compression
12 static const float f_tolerance = 1;
13 
14 namespace met {
15 
16  METAssocTestAlg::METAssocTestAlg(const std::string& name, ISvcLocator* pSvcLocator) :
17  ::AthAlgorithm( name, pSvcLocator ) {
18  declareProperty( "METMapSuffix", m_mapsuffix="AntiKt4EMTopo" );
19  declareProperty( "JetCollection", m_jetname="" );
20 
21  declareProperty( "FailOnInconsistency", m_failOnInconsistency=false );
22  }
23 
25  {
26  if(m_mapsuffix.empty()) {
27  ATH_MSG_FATAL( "METMapSuffix (e.g. AntiKt4EMTopo) must be set!" );
28  return StatusCode::FAILURE;
29  }
30  m_mapname = "METAssoc_"+m_mapsuffix;
31  if(m_jetname.empty()) { m_jetname = m_mapsuffix+"Jets"; }
32 
33  ATH_MSG_INFO( "Initialising " << name() );
34  ATH_MSG_INFO( "MET map name: " << m_mapname );
35 
36  return StatusCode::SUCCESS;
37  }
38 
39  StatusCode METAssocTestAlg::finalize() { return StatusCode::SUCCESS; }
40 
42  {
43 
44 
46  if (!map.isValid()) {
47  ATH_MSG_WARNING("Unable to retrieve met association map");
48  return StatusCode::FAILURE;
49  }
50 
51  for(const auto *const assoc : *map) {
52  if(assoc->isMisc()) { // misc association gets special treatment
53  ATH_MSG_VERBOSE( " Now on MET misc association" );
54  ATH_CHECK( checkMiscAssoc(*assoc) );
55  } else {
56  ATH_MSG_VERBOSE( " Now on MET association for jet " << assoc->refJet()->index() );
57  // Test jets for consistency with the map
58  ATH_CHECK( checkJet(*assoc) );
59  // Test associated objects for consistency with the map
60  ATH_CHECK( checkObjects(*assoc) );
61  // Test association for self-consistency based on stored keys
62  ATH_CHECK( checkAssoc(*assoc) );
63  }
64  }
65 
66  return StatusCode::SUCCESS;
67  }
68 
70  {
71  const auto& jet = *assoc.refJet();
72  JetFourMom_t jetconstp4 = jet.jetP4(JetConstitScaleMomentum);
73  MissingETBase::Types::constvec_t jettrkvec = assoc.jetTrkVec();
74 
76 
77  // switch on all overlapping objects
78  for(size_t iobj=0; iobj<assoc.objects().size(); ++iobj) {
79  helper.setObjSelectionFlag(&assoc,iobj,true);
80  }
81  // get cluster/inclusive pflow and track/charged pflow constituent sums
84 
85  ATH_MSG_VERBOSE(" Jet constituent-scale pt: " << jetconstp4.pt() << ", E: " << jetconstp4.e() );
86  ATH_MSG_VERBOSE(" Max constituent overlap pt: " << overlapcalvec.cpt() << ", E: " << overlapcalvec.ce() );
87 
88  ATH_MSG_VERBOSE(" Jet track pt: " << jettrkvec.cpt() << ", E: " << jettrkvec.ce() );
89  ATH_MSG_VERBOSE(" Max track overlap pt: " << overlaptrkvec.cpt() << ", E: " << overlaptrkvec.ce() );
90 
91  // optionally quit and fail if overlap-removal exceeds original jet constituent-scale energy
92  if(overlapcalvec.ce()-jetconstp4.e()>f_tolerance) {
93  ATH_MSG_ERROR("Too-large overlapcalvec!");
94  if(m_failOnInconsistency) return StatusCode::FAILURE;
95  }
96  if(overlaptrkvec.ce()-jettrkvec.ce()>f_tolerance) {
97  ATH_MSG_ERROR("Too-large overlaptrkvec!");
98  if(m_failOnInconsistency) return StatusCode::FAILURE;
99  }
100 
101  return StatusCode::SUCCESS;
102  }
103 
105  {
106  const auto& jet = *assoc.refJet();
107  JetFourMom_t jetconstp4 = jet.jetP4(JetConstitScaleMomentum);
108  MissingETBase::Types::constvec_t jettrkvec = assoc.jetTrkVec();
109 
111 
112  // loop over individual objects and check that none of them has a larger
113  // associated constituent sum than the jet
114  for(size_t iobj=0; iobj<assoc.objects().size(); ++iobj) {
115  ATH_MSG_VERBOSE(" Now on constituent " << iobj );
116  const IParticle* obj = assoc.objects()[iobj];
117  if(!obj) continue; // invalid ElementLink -- thinned?
118  helper.resetObjSelectionFlags();
119  helper.setObjSelectionFlag(&assoc,iobj,true);
122 
123  ATH_MSG_VERBOSE(" Object pt: " << obj->pt() << ", E: " << obj->e() << ", type: " << obj->type());
124  ATH_MSG_VERBOSE(" Constituent pt: " << overlapcalvec.cpt() << ", E: " << overlapcalvec.ce() );
125  ATH_MSG_VERBOSE(" Track pt: " << overlaptrkvec.cpt() << ", E: " << overlaptrkvec.ce() );
126 
127  // optionally quit and fail if overlap-removal exceeds original jet constituent-scale energy
128  if(overlapcalvec.ce()-jetconstp4.e()>f_tolerance) {
129  ATH_MSG_ERROR("Too-large overlapcalvec!");
130  ATH_MSG_ERROR(" Object pt: " << obj->pt() << ", E: " << obj->e() << ", type: " << obj->type());
131  if(m_failOnInconsistency) return StatusCode::FAILURE;
132  }
133  if(overlaptrkvec.ce()-jettrkvec.ce()>f_tolerance) {
134  ATH_MSG_ERROR("Too-large overlaptrkvec!");
135  ATH_MSG_ERROR(" Object pt: " << obj->pt() << ", E: " << obj->e() << ", type: " << obj->type());
136  if(m_failOnInconsistency) return StatusCode::FAILURE;
137  }
138  }
139 
140  return StatusCode::SUCCESS;
141  }
142 
144  {
145  const auto& jet = *assoc.refJet();
146  JetFourMom_t jetconstp4 = jet.jetP4(JetConstitScaleMomentum);
147  MissingETBase::Types::constvec_t jettrkvec = assoc.jetTrkVec();
148 
149  // loop over the encoded cluster/inclusive pflow constituent sums and check that these are
150  // all smaller than the jet constituent-scale pt
151  for(size_t ikey=0; ikey<assoc.calkey().size(); ++ikey) {
152  ATH_MSG_VERBOSE(" Now on calkey " << ikey << ": " << assoc.calkey()[ikey] );
153  MissingETBase::Types::constvec_t calvec = assoc.calVec(ikey);
154  ATH_MSG_VERBOSE(" Constituent pt: " << calvec.cpt() << ", E: " << calvec.ce() );
155 
156  if(calvec.ce()-jetconstp4.e()>f_tolerance) {
157  ATH_MSG_ERROR("Too-large calvec!");
158  for(size_t iobj=0; iobj<assoc.objects().size(); ++iobj) {
159  if( ((1<<iobj)&assoc.calkey()[ikey]) == 0 ) {
160  const IParticle* obj = assoc.objects()[iobj];
161  if(!obj) continue; // invalid ElementLink -- thinned?
162  ATH_MSG_ERROR(" Object pt: " << obj->pt() << ", E: " << obj->e() << ", type: " << obj->type());
163  }
164  }
165  if(m_failOnInconsistency) return StatusCode::FAILURE;
166  }
167  }
168 
169  // loop over the encoded track/charged pflow constituent sums and check that these are
170  // all smaller than the jet track sum
171  for(size_t ikey=0; ikey<assoc.trkkey().size(); ++ikey) {
172  ATH_MSG_VERBOSE(" Now on trkkey " << ikey << ": " << assoc.trkkey()[ikey] );
173  MissingETBase::Types::constvec_t trkvec = assoc.trkVec(ikey);
174  ATH_MSG_VERBOSE(" Track pt: " << trkvec.cpt() << ", E: " << trkvec.ce() );
175 
176  if(trkvec.ce()-jettrkvec.ce()>f_tolerance) {
177  ATH_MSG_ERROR("Too-large trkvec!");
178  for(size_t iobj=0; iobj<assoc.objects().size(); ++iobj) {
179  if( ((1<<iobj)&assoc.trkkey()[ikey]) == 0 ) {
180  const IParticle* obj = assoc.objects()[iobj];
181  if(!obj) continue; // invalid ElementLink -- thinned?
182  ATH_MSG_ERROR(" Object pt: " << obj->pt() << ", E: " << obj->e() << ", type: " << obj->type());
183  }
184  }
185  if(m_failOnInconsistency) return StatusCode::FAILURE;
186  }
187  }
188 
189  return StatusCode::SUCCESS;
190  }
191 
193  {
194  // loop over the encoded cluster/inclusive pflow constituent sums
195  for(size_t ikey=0; ikey<assoc.calkey().size(); ++ikey) {
196  ATH_MSG_VERBOSE(" Now on calkey " << ikey << ": " << assoc.calkey()[ikey] );
197  MissingETBase::Types::constvec_t calvec = assoc.calVec(ikey);
198  ATH_MSG_VERBOSE(" Constituent pt: " << calvec.cpt() << ", E: " << calvec.ce() );
199  }
200 
201  // loop over the encoded track/charged pflow constituent sums
202  for(size_t ikey=0; ikey<assoc.trkkey().size(); ++ikey) {
203  ATH_MSG_VERBOSE(" Now on trkkey " << ikey << ": " << assoc.trkkey()[ikey] );
204  MissingETBase::Types::constvec_t trkvec = assoc.trkVec(ikey);
205  ATH_MSG_VERBOSE(" Track pt: " << trkvec.cpt() << ", E: " << trkvec.ce() );
206  }
207 
208  return StatusCode::SUCCESS;
209  }
210 }
xAOD::name
name
Definition: TriggerMenuJson_v1.cxx:29
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
xAOD::MissingETAssociation_v1::overlapCalVec
ConstVec overlapCalVec(const MissingETAssociationHelper &helper) const
Retrieve total cluster-based vector to be subtracted from the jet.
Definition: MissingETAssociation_v1.cxx:772
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::MissingETAssociation_v1
MET association descriptor contains object links and corresponding parameters.
Definition: MissingETAssociation_v1.h:29
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
met::METAssocTestAlg::m_jetname
std::string m_jetname
Definition: METAssocTestAlg.h:32
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
met::METAssocTestAlg::initialize
StatusCode initialize()
Definition: METAssocTestAlg.cxx:24
met::METAssocTestAlg::checkAssoc
StatusCode checkAssoc(const xAOD::MissingETAssociation &)
Definition: METAssocTestAlg.cxx:143
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
met::METAssocTestAlg::m_mapname
std::string m_mapname
Definition: METAssocTestAlg.h:31
xAOD::MissingETAssociation_v1::ConstVec
Vector sum of constituents for subtractive overlap removal.
Definition: MissingETAssociation_v1.h:36
met::METAssocTestAlg::checkMiscAssoc
StatusCode checkMiscAssoc(const xAOD::MissingETAssociation &)
Definition: METAssocTestAlg.cxx:192
runBeamSpotCalibration.helper
helper
Definition: runBeamSpotCalibration.py:112
xAOD::JetConstitScaleMomentum
@ JetConstitScaleMomentum
Definition: JetTypes.h:29
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
met
Definition: IMETSignificance.h:24
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
METAssocTestAlg.h
xAOD::MissingETAssociation_v1::trkkey
const std::vector< MissingETBase::Types::bitmask_t > & trkkey() const
Get the vector of trk keys.
met::METAssocTestAlg::finalize
StatusCode finalize()
Definition: METAssocTestAlg.cxx:39
met::METAssocTestAlg::m_mapsuffix
std::string m_mapsuffix
Definition: METAssocTestAlg.h:35
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
met::METAssocTestAlg::checkObjects
StatusCode checkObjects(const xAOD::MissingETAssociation &)
Definition: METAssocTestAlg.cxx:104
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::MissingETAssociation_v1::calVec
ConstVec calVec(const IParticle *pPart) const
Get calo constituent vector for a given object.
Definition: MissingETAssociation_v1.cxx:540
xAOD::MissingETAssociation_v1::jetTrkVec
ConstVec jetTrkVec() const
Get track constituent vector for the reference jet.
Definition: MissingETAssociation_v1.cxx:570
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAOD::MissingETAssociationHelper
Definition: MissingETAssociationHelper.h:26
xAOD::MissingETAssociation_v1::overlapTrkVec
ConstVec overlapTrkVec(const MissingETAssociationHelper &helper) const
Retrieve total track-based vector to be subtracted from the jet.
Definition: MissingETAssociation_v1.cxx:782
xAOD::MissingETAssociation_v1::calkey
const std::vector< MissingETBase::Types::bitmask_t > & calkey() const
Get the vector of cal keys.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::MissingETAssociation_v1::ConstVec::cpt
float cpt() const
Returns .
Definition: MissingETAssociation_v1.cxx:87
met::METAssocTestAlg::checkJet
StatusCode checkJet(const xAOD::MissingETAssociation &)
Definition: METAssocTestAlg.cxx:69
met::METAssocTestAlg::execute
StatusCode execute()
Definition: METAssocTestAlg.cxx:41
met::METAssocTestAlg::m_failOnInconsistency
bool m_failOnInconsistency
Definition: METAssocTestAlg.h:36
xAOD::MissingETAssociation_v1::trkVec
ConstVec trkVec(const IParticle *pPart) const
Get track constituent vector for a given object.
Definition: MissingETAssociation_v1.cxx:550
MissingETAssociationMap.h
python.PyAthena.obj
obj
Definition: PyAthena.py:135
MissingETAssociationHelper.h
xAOD::MissingETAssociation_v1::refJet
const Jet * refJet() const
Access reference jet.
xAOD::MissingETAssociation_v1::ConstVec::ce
float ce() const
Returns .
xAOD::MissingETAssociation_v1::objects
std::vector< const IParticle * > objects() const
Access contributing objects.
Definition: MissingETAssociation_v1.cxx:505