ATLAS Offline Software
Loading...
Searching...
No Matches
METHelpers.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2021 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// METUtilities includes
15
16// Muon EDM
18
19// Electron EDM
22
23// Jet EDM
25
27
28#include <iostream>
29
30namespace met {
31
32 ANA_MSG_SOURCE (msgMET, "METUtilities")
33
35 {
36 std::vector<const xAOD::TrackParticle*> jet_tracks;
37 for (xAOD::Jet* jet: jets) {
38 // Fill this with muons to be associated
39 std::vector<const xAOD::Muon*> muons_in_jet;
40 // Get the tracks associated to the jet
41 jet_tracks.clear();
42 if ( jet->getAssociatedObjects("GhostTrack", jet_tracks) ) {
43
44 for(const auto *const muon : muons) {
45 const xAOD::TrackParticle* idtrack = muon->trackParticle( xAOD::Muon::InnerDetectorTrackParticle );
46 if(!idtrack) continue;
47 // check if this is ghost associated to a jet
48 // make sure the jet is close first
49 if(xAOD::P4Helpers::deltaR2(*jet,*muon)>0.36) continue;
50
51 for(unsigned jtrk=0; jtrk<jet_tracks.size(); ++jtrk) {
52 // check if the track pointers match
53 if(jet_tracks.at(jtrk)==idtrack) {
54 muons_in_jet.push_back(muon);
55 break;
56 }
57 } // loop over jet tracks
58 } // loop over muons
59 } // jet has associated tracks
60 jet->setAssociatedObjects( "GhostMuon", muons_in_jet) ;
61 } // loop over jets
62 }
63
64 StatusCode buildMETSum(const std::string& totalName,
66 {
67 using namespace msgMET;
68 ANA_MSG_DEBUG("Build MET total: " << totalName);
69
70 xAOD::MissingET* metFinal = nullptr;
71 if(fillMET(metFinal, metCont, totalName, MissingETBase::Source::total()) != StatusCode::SUCCESS){
72 ANA_MSG_ERROR("failed to fill MET term");
73 return StatusCode::FAILURE;
74 }
75
76 for(xAOD::MissingETContainer::const_iterator iMET=metCont->begin(); iMET!=metCont->end(); ++iMET) {
77 if(*iMET==metFinal) continue;
78 *metFinal += **iMET;
79 }
80
81 ANA_MSG_DEBUG( "Rebuilt MET Final --"
82 << " mpx: " << metFinal->mpx()
83 << " mpy: " << metFinal->mpy()
84 );
85
86 return StatusCode::SUCCESS;
87 }
88
89 StatusCode buildMETSum(const std::string& totalName,
91 MissingETBase::Types::bitmask_t softTermsSource)
92 {
93 using namespace msgMET;
94 ANA_MSG_DEBUG("Build MET total: " << totalName);
95
96 xAOD::MissingET* metFinal = nullptr;
97 if( fillMET(metFinal, metCont, totalName, MissingETBase::Source::total()) != StatusCode::SUCCESS) {
98 ANA_MSG_ERROR("failed to fill MET term \"" << totalName << "\"");
99 return StatusCode::FAILURE;
100 }
101
102 // not using a reference, because the iterator doesn't return a reference
103 for(const auto met : *metCont) {
104 if(MissingETBase::Source::isTotalTerm(met->source())) continue;
105 if(met->source()==invisSource) continue;
106 if(softTermsSource && MissingETBase::Source::isSoftTerm(met->source())) {
107 if(!MissingETBase::Source::hasPattern(met->source(),softTermsSource)) continue;
108 }
109 ANA_MSG_VERBOSE("Add MET term " << met->name() );
110 *metFinal += *met;
111 }
112
113 ANA_MSG_DEBUG( "Rebuilt MET Final --"
114 << " mpx: " << metFinal->mpx()
115 << " mpy: " << metFinal->mpy()
116 );
117
118 return StatusCode::SUCCESS;
119 }
120
121 // This is used to avoid creating a private store
122 // It puts the given new MET object into the container
124 xAOD::MissingETContainer * metCont,
125 const std::string& metKey,
126 const MissingETBase::Types::bitmask_t metSource){
127 using namespace msgMET;
128 if(met != nullptr){
129 ANA_MSG_ERROR("You can't fill a filled MET value");
130 return StatusCode::FAILURE;
131 }
132 if(metCont->find(metKey)!=metCont->end()){
133 ANA_MSG_ERROR("Attempted to add a duplicate MET term: " << metKey);
134 return StatusCode::FAILURE;
135 }
136
137 met = new xAOD::MissingET();
138 metCont->push_back(met);
139
140 met->setName (metKey);
141 met->setSource(metSource);
142
143 return StatusCode::SUCCESS;
144 }
145
146}
#define ANA_MSG_ERROR(xmsg)
Macro printing error 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.
StatusCode buildMETSum(const std::string &totalName, xAOD::MissingETContainer *metCont)
void addGhostMuonsToJets(const xAOD::MuonContainer &muons, xAOD::JetContainer &jets)
static const MissingETBase::Types::bitmask_t invisSource
Definition METHelpers.h:27
StatusCode fillMET(xAOD::MissingET *&met, xAOD::MissingETContainer *metCont, const std::string &metKey, const MissingETBase::Types::bitmask_t metSource)
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)