ATLAS Offline Software
Loading...
Searching...
No Matches
METHelpers.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
7// METHelpers.cxx
8// Implementation file for standalone METHelpers functions
9// Author: T.J.Khoo<khoo@cern.ch>
10// Author: Bill Balunas <bill.balunas@cern.ch>
12
13#include <iostream>
14
15// METUtilities includes
17
18// Muon EDM
20
21// Electron EDM
24
25// Jet EDM
27
29
30namespace met {
31 ANA_MSG_SOURCE (msgMET, "METUtilities")
32
34 {
35 std::vector<const xAOD::TrackParticle*> jet_tracks;
36 for (xAOD::Jet* jet: jets) {
37 // Fill this with muons to be associated
38 std::vector<const xAOD::Muon*> muons_in_jet;
39 // Get the tracks associated to the jet
40 jet_tracks.clear();
41 if ( jet->getAssociatedObjects("GhostTrack", jet_tracks) ) {
42
43 for(const auto *const muon : muons) {
44 const xAOD::TrackParticle* idtrack = muon->trackParticle( xAOD::Muon::InnerDetectorTrackParticle );
45 if(!idtrack) continue;
46 // check if this is ghost associated to a jet
47 // make sure the jet is close first
48 if(xAOD::P4Helpers::deltaR2(*jet,*muon)>0.36) continue;
49
50 for(unsigned jtrk=0; jtrk<jet_tracks.size(); ++jtrk) {
51 // check if the track pointers match
52 if(jet_tracks.at(jtrk)==idtrack) {
53 muons_in_jet.push_back(muon);
54 break;
55 }
56 } // loop over jet tracks
57 } // loop over muons
58 } // jet has associated tracks
59 jet->setAssociatedObjects( "GhostMuon", muons_in_jet) ;
60 } // loop over jets
61 }
62
63 StatusCode buildMETSum(const std::string& totalName,
65 {
66 using namespace msgMET;
67 ANA_MSG_DEBUG("Build MET total: " << totalName);
68
69 xAOD::MissingET* metFinal = nullptr;
70 if(fillMET(metFinal, metCont, totalName, MissingETBase::Source::total()) != StatusCode::SUCCESS){
71 ANA_MSG_ERROR("failed to fill MET term");
72 return StatusCode::FAILURE;
73 }
74
75 for(xAOD::MissingETContainer::const_iterator iMET=metCont->begin(); iMET!=metCont->end(); ++iMET) {
76 if(*iMET==metFinal) continue;
77 *metFinal += **iMET;
78 }
79
80 ANA_MSG_DEBUG( "Rebuilt MET Final --"
81 << " mpx: " << metFinal->mpx()
82 << " mpy: " << metFinal->mpy()
83 );
84
85 return StatusCode::SUCCESS;
86 }
87
88 StatusCode buildMETSum(const std::string& totalName,
90 MissingETBase::Types::bitmask_t softTermsSource)
91 {
92 using namespace msgMET;
93 ANA_MSG_DEBUG("Build MET total: " << totalName);
94
95 xAOD::MissingET* metFinal = nullptr;
96 if( fillMET(metFinal, metCont, totalName, MissingETBase::Source::total()) != StatusCode::SUCCESS) {
97 ANA_MSG_ERROR("failed to fill MET term \"" << totalName << "\"");
98 return StatusCode::FAILURE;
99 }
100
101 // not using a reference, because the iterator doesn't return a reference
102 for(const auto met : *metCont) {
103 if(MissingETBase::Source::isTotalTerm(met->source())) continue;
104 if(met->source()==invisSource) continue;
105 if(softTermsSource && MissingETBase::Source::isSoftTerm(met->source())) {
106 if(!MissingETBase::Source::hasPattern(met->source(),softTermsSource)) continue;
107 }
108 ANA_MSG_VERBOSE("Add MET term " << met->name() );
109 *metFinal += *met;
110 }
111
112 ANA_MSG_DEBUG( "Rebuilt MET Final --"
113 << " mpx: " << metFinal->mpx()
114 << " mpy: " << metFinal->mpy()
115 );
116
117 return StatusCode::SUCCESS;
118 }
119
120 // This is used to avoid creating a private store
121 // It puts the given new MET object into the container
123 xAOD::MissingETContainer * metCont,
124 const std::string& metKey,
125 const MissingETBase::Types::bitmask_t metSource){
126 using namespace msgMET;
127 if(met != nullptr){
128 ANA_MSG_ERROR("You can't fill a filled MET value");
129 return StatusCode::FAILURE;
130 }
131 if(metCont->find(metKey)!=metCont->end()){
132 ANA_MSG_ERROR("Attempted to add a duplicate MET term: " << metKey);
133 return StatusCode::FAILURE;
134 }
135
136 met = new xAOD::MissingET();
137 metCont->push_back(met);
138
139 met->setName (metKey);
140 met->setSource(metSource);
141
142 return StatusCode::SUCCESS;
143 }
144
145
146 // Explicit template instantiation for all the relevant classes
147 extern template std::vector<const xAOD::Electron*> getMETElements<xAOD::Electron>(const xAOD::MissingET& met);
148 extern template std::vector<const xAOD::Photon*> getMETElements<xAOD::Photon>(const xAOD::MissingET& met);
149 extern template std::vector<const xAOD::Muon*> getMETElements<xAOD::Muon>(const xAOD::MissingET& met);
150 extern template std::vector<const xAOD::TauJet*> getMETElements<xAOD::TauJet>(const xAOD::MissingET& met);
151 extern template std::vector<const xAOD::Jet*> getMETElements<xAOD::Jet>(const xAOD::MissingET& met);
152
153 extern template std::vector<std::pair<const xAOD::Electron*,float> > getMETElementsWeights<xAOD::Electron>(const xAOD::MissingET& met);
154 extern template std::vector<std::pair<const xAOD::Photon*,float> > getMETElementsWeights<xAOD::Photon>(const xAOD::MissingET& met);
155 extern template std::vector<std::pair<const xAOD::Muon*,float> > getMETElementsWeights<xAOD::Muon>(const xAOD::MissingET& met);
156 extern template std::vector<std::pair<const xAOD::TauJet*,float> > getMETElementsWeights<xAOD::TauJet>(const xAOD::MissingET& met);
157 extern template std::vector<std::pair<const xAOD::Jet*,float> > getMETElementsWeights<xAOD::Jet>(const xAOD::MissingET& met);
158
159
160 // Specialisation, no need for cast
161 template <>
162 std::vector<const xAOD::IParticle*> getMETElements(const xAOD::MissingET& met) {
163 using namespace msgMET;
164
165 const auto& uniqueLinks = accessors::constitObjLinks(met);
166 std::vector<const xAOD::IParticle*> objs_out{};
167 objs_out.reserve(uniqueLinks.size());
168 // Loop through links
169 for (const auto& link: uniqueLinks){
170 if (link.isValid()) {
171 objs_out.push_back(*link);
172 } else {
173 ANA_MSG_WARNING("Invalid ElementLink from MET term " << met.name());
174 objs_out.push_back(nullptr);
175 }
176 }
177
178 return objs_out;
179 }
180
181
182 template <>
183 std::vector<std::pair<const xAOD::IParticle*,float> > getMETElementsWeights(const xAOD::MissingET& met) {
184 using namespace msgMET;
185
186 const auto& uniqueLinks = accessors::constitObjLinks(met);
187 const auto& uniqueWeights = accessors::constitObjWeights(met);
188 std::vector<std::pair<const xAOD::IParticle*,float> > objs_weights_out{};
189 objs_weights_out.reserve(uniqueLinks.size());
190 // Loop through links
191 for (size_t i=0; i<uniqueLinks.size(); ++i) {
192 auto& link = uniqueLinks[i];
193 float weight = uniqueWeights[i];
194 if (link.isValid()) {
195 objs_weights_out.push_back(std::make_pair(*link,weight));
196 } else {
197 ANA_MSG_WARNING("Invalid ElementLink from MET term " << met.name());
198 objs_weights_out.push_back(std::make_pair(nullptr,0));
199 }
200 }
201
202 return objs_weights_out;
203 }
204
205}
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
#define ANA_MSG_VERBOSE(xmsg)
Macro printing verbose messages.
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
#define ANA_MSG_SOURCE(NAME, TITLE)
the source code part of ANA_MSG_SOURCE
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
value_type push_back(value_type pElem)
Add an element to the end of the collection.
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.
const_iterator find(const std::string &name) const
Find non-modifiable MET object by name.
float mpx() const
Returns .
float mpy() const
Returns .
uint64_t bitmask_t
Type for status word bit mask.
template std::vector< const xAOD::Photon * > getMETElements< xAOD::Photon >(const xAOD::MissingET &met)
template std::vector< std::pair< const xAOD::Jet *, float > > getMETElementsWeights< xAOD::Jet >(const xAOD::MissingET &met)
StatusCode buildMETSum(const std::string &totalName, xAOD::MissingETContainer *metCont)
template std::vector< const xAOD::Jet * > getMETElements< xAOD::Jet >(const xAOD::MissingET &met)
template std::vector< std::pair< const xAOD::Photon *, float > > getMETElementsWeights< xAOD::Photon >(const xAOD::MissingET &met)
void addGhostMuonsToJets(const xAOD::MuonContainer &muons, xAOD::JetContainer &jets)
std::vector< const T * > getMETElements(const xAOD::MissingET &met)
std::vector< std::pair< const T *, float > > getMETElementsWeights(const xAOD::MissingET &met)
static const MissingETBase::Types::bitmask_t invisSource
Definition METHelpers.h:38
template std::vector< std::pair< const xAOD::TauJet *, float > > getMETElementsWeights< xAOD::TauJet >(const xAOD::MissingET &met)
template std::vector< std::pair< const xAOD::Muon *, float > > getMETElementsWeights< xAOD::Muon >(const xAOD::MissingET &met)
template std::vector< const xAOD::Electron * > getMETElements< xAOD::Electron >(const xAOD::MissingET &met)
template std::vector< std::pair< const xAOD::Electron *, float > > getMETElementsWeights< xAOD::Electron >(const xAOD::MissingET &met)
StatusCode fillMET(xAOD::MissingET *&met, xAOD::MissingETContainer *metCont, const std::string &metKey, const MissingETBase::Types::bitmask_t metSource)
template std::vector< const xAOD::Muon * > getMETElements< xAOD::Muon >(const xAOD::MissingET &met)
template std::vector< const xAOD::TauJet * > getMETElements< xAOD::TauJet >(const xAOD::MissingET &met)
double deltaR2(double rapidity1, double phi1, double rapidity2, double phi2)
from bare rapidity,phi
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Jet_v1 Jet
Definition of the current "jet version".
MissingET_v1 MissingET
Version control by type defintion.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
JetContainer_v1 JetContainer
Definition of the current "jet container version".
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
static Types::bitmask_t total(Region reg=Region::FullAcceptance)
Standard full reconstructed MET.
static bool isSoftTerm(Types::bitmask_t bits, Region reg=Region::FullAcceptance)
static bool hasPattern(E bits, F mask)
Generic check for given pattern.
static bool isTotalTerm(Types::bitmask_t bits, Region reg=Region::FullAcceptance)