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
14
15// METUtilities includes
17
18// Muon EDM
20
21// Electron EDM
24
25// Jet EDM
27
29#include <iostream>
30
31namespace met {
32 ANA_MSG_SOURCE (msgMET, "METUtilities")
33
35 {
36 std::vector<const xAOD::TrackParticle*> jet_tracks;
37 const std::string ghostMuonStr{"GhostMuon"};
38 for (xAOD::Jet* jet: jets) {
39 // Fill this with muons to be associated
40 std::vector<const xAOD::Muon*> muons_in_jet;
41 // Get the tracks associated to the jet
42 jet_tracks.clear();
43 if ( jet->getAssociatedObjects("GhostTrack", jet_tracks) ) {
44
45 for(const auto *const muon : muons) {
46 const xAOD::TrackParticle* idtrack = muon->trackParticle( xAOD::Muon::InnerDetectorTrackParticle );
47 if(!idtrack) continue;
48 // check if this is ghost associated to a jet
49 // make sure the jet is close first
50 if(xAOD::P4Helpers::deltaR2(*jet,*muon)>0.36) continue;
51
52 for(unsigned jtrk=0; jtrk<jet_tracks.size(); ++jtrk) {
53 // check if the track pointers match
54 if(jet_tracks.at(jtrk)==idtrack) {
55 muons_in_jet.push_back(muon);
56 break;
57 }
58 } // loop over jet tracks
59 } // loop over muons
60 } // jet has associated tracks
61 jet->setAssociatedObjects( ghostMuonStr, muons_in_jet) ;
62 } // loop over jets
63 }
64
65 StatusCode buildMETSum(const std::string& totalName,
67 {
68 using namespace msgMET;
69 ANA_MSG_DEBUG("Build MET total: " << totalName);
70
71 xAOD::MissingET* metFinal = nullptr;
72 if(fillMET(metFinal, metCont, totalName, MissingETBase::Source::total()) != StatusCode::SUCCESS){
73 ANA_MSG_ERROR("failed to fill MET term");
74 return StatusCode::FAILURE;
75 }
76
77 for(xAOD::MissingETContainer::const_iterator iMET=metCont->begin(); iMET!=metCont->end(); ++iMET) {
78 if(*iMET==metFinal) continue;
79 *metFinal += **iMET;
80 }
81
82 ANA_MSG_DEBUG( "Rebuilt MET Final --"
83 << " mpx: " << metFinal->mpx()
84 << " mpy: " << metFinal->mpy()
85 );
86
87 return StatusCode::SUCCESS;
88 }
89
90 StatusCode buildMETSum(const std::string& totalName,
92 MissingETBase::Types::bitmask_t softTermsSource)
93 {
94 using namespace msgMET;
95 ANA_MSG_DEBUG("Build MET total: " << totalName);
96
97 xAOD::MissingET* metFinal = nullptr;
98 if( fillMET(metFinal, metCont, totalName, MissingETBase::Source::total()) != StatusCode::SUCCESS) {
99 ANA_MSG_ERROR("failed to fill MET term \"" << totalName << "\"");
100 return StatusCode::FAILURE;
101 }
102
103 // not using a reference, because the iterator doesn't return a reference
104 for(const auto met : *metCont) {
105 if(MissingETBase::Source::isTotalTerm(met->source())) continue;
106 if(met->source()==invisSource) continue;
107 if(softTermsSource && MissingETBase::Source::isSoftTerm(met->source())) {
108 if(!MissingETBase::Source::hasPattern(met->source(),softTermsSource)) continue;
109 }
110 ANA_MSG_VERBOSE("Add MET term " << met->name() );
111 *metFinal += *met;
112 }
113
114 ANA_MSG_DEBUG( "Rebuilt MET Final --"
115 << " mpx: " << metFinal->mpx()
116 << " mpy: " << metFinal->mpy()
117 );
118
119 return StatusCode::SUCCESS;
120 }
121
122 // This is used to avoid creating a private store
123 // It puts the given new MET object into the container
125 xAOD::MissingETContainer * metCont,
126 const std::string& metKey,
127 const MissingETBase::Types::bitmask_t metSource){
128 using namespace msgMET;
129 if(met != nullptr){
130 ANA_MSG_ERROR("You can't fill a filled MET value");
131 return StatusCode::FAILURE;
132 }
133 if(metCont->find(metKey)!=metCont->end()){
134 ANA_MSG_ERROR("Attempted to add a duplicate MET term: " << metKey);
135 return StatusCode::FAILURE;
136 }
137
138 met = new xAOD::MissingET();
139 metCont->push_back(met);
140
141 met->setName (metKey);
142 met->setSource(metSource);
143
144 return StatusCode::SUCCESS;
145 }
146
147
148 // Explicit template instantiation for all the relevant classes
149 extern template std::vector<const xAOD::Electron*> getMETElements<xAOD::Electron>(const xAOD::MissingET& met);
150 extern template std::vector<const xAOD::Photon*> getMETElements<xAOD::Photon>(const xAOD::MissingET& met);
151 extern template std::vector<const xAOD::Muon*> getMETElements<xAOD::Muon>(const xAOD::MissingET& met);
152 extern template std::vector<const xAOD::TauJet*> getMETElements<xAOD::TauJet>(const xAOD::MissingET& met);
153 extern template std::vector<const xAOD::Jet*> getMETElements<xAOD::Jet>(const xAOD::MissingET& met);
154
155 extern template std::vector<std::pair<const xAOD::Electron*,float> > getMETElementsWeights<xAOD::Electron>(const xAOD::MissingET& met);
156 extern template std::vector<std::pair<const xAOD::Photon*,float> > getMETElementsWeights<xAOD::Photon>(const xAOD::MissingET& met);
157 extern template std::vector<std::pair<const xAOD::Muon*,float> > getMETElementsWeights<xAOD::Muon>(const xAOD::MissingET& met);
158 extern template std::vector<std::pair<const xAOD::TauJet*,float> > getMETElementsWeights<xAOD::TauJet>(const xAOD::MissingET& met);
159 extern template std::vector<std::pair<const xAOD::Jet*,float> > getMETElementsWeights<xAOD::Jet>(const xAOD::MissingET& met);
160
161
162 // Specialisation, no need for cast
163 template <>
164 std::vector<const xAOD::IParticle*> getMETElements(const xAOD::MissingET& met) {
165 using namespace msgMET;
166
167 const auto& uniqueLinks = accessors::constitObjLinks(met);
168 std::vector<const xAOD::IParticle*> objs_out{};
169 objs_out.reserve(uniqueLinks.size());
170 // Loop through links
171 for (const auto& link: uniqueLinks){
172 if (link.isValid()) {
173 objs_out.push_back(*link);
174 } else {
175 ANA_MSG_WARNING("Invalid ElementLink from MET term " << met.name());
176 objs_out.push_back(nullptr);
177 }
178 }
179
180 return objs_out;
181 }
182
183
184 template <>
185 std::vector<std::pair<const xAOD::IParticle*,float> > getMETElementsWeights(const xAOD::MissingET& met) {
186 using namespace msgMET;
187
188 const auto& uniqueLinks = accessors::constitObjLinks(met);
189 const auto& uniqueWeights = accessors::constitObjWeights(met);
190 std::vector<std::pair<const xAOD::IParticle*,float> > objs_weights_out{};
191 objs_weights_out.reserve(uniqueLinks.size());
192 // Loop through links
193 for (size_t i=0; i<uniqueLinks.size(); ++i) {
194 auto& link = uniqueLinks[i];
195 float weight = uniqueWeights[i];
196 if (link.isValid()) {
197 objs_weights_out.push_back(std::make_pair(*link,weight));
198 } else {
199 ANA_MSG_WARNING("Invalid ElementLink from MET term " << met.name());
200 objs_weights_out.push_back(std::make_pair(nullptr,0));
201 }
202 }
203
204 return objs_weights_out;
205 }
206
207}
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
#define ANA_MSG_DEBUG(xmsg,...)
Macro printing debug messages.
#define ANA_MSG_VERBOSE(xmsg,...)
Macro printing verbose messages.
#define ANA_MSG_WARNING(xmsg,...)
Macro printing warning 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)