ATLAS Offline Software
METHelpers.cxx
Go to the documentation of this file.
1 
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
17 #include "xAODMuon/MuonContainer.h"
18 
19 // Electron EDM
22 
23 // Jet EDM
24 #include "xAODJet/JetContainer.h"
25 
27 
28 #include <iostream>
29 
30 namespace 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,
65  xAOD::MissingETContainer* metCont)
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,
90  xAOD::MissingETContainer* metCont,
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 }
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
MissingETBase::Source::hasPattern
static bool hasPattern(E bits, F mask)
Generic check for given pattern.
Definition: MissingETBase.h:382
xAODP4Helpers.h
MissingETBase::Source::isTotalTerm
static bool isTotalTerm(Types::bitmask_t bits, Region reg=Region::FullAcceptance)
Definition: MissingETBase.h:405
xAOD::MissingET
MissingET_v1 MissingET
Version control by type defintion.
Definition: Event/xAOD/xAODMissingET/xAODMissingET/MissingET.h:15
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
MissingETBase::Types::bitmask_t
uint64_t bitmask_t
Type for status word bit mask.
Definition: MissingETBase.h:39
xAOD::P4Helpers::deltaR2
double deltaR2(double rapidity1, double phi1, double rapidity2, double phi2)
from bare rapidity,phi
Definition: xAODP4Helpers.h:111
met::buildMETSum
StatusCode buildMETSum(const std::string &totalName, xAOD::MissingETContainer *metCont)
Definition: METHelpers.cxx:64
xAOD::MissingETContainer_v1::find
const_iterator find(const std::string &name) const
Find non-modifiable MET object by name.
Definition: MissingETContainer_v1.cxx:52
METHelpers.h
EgammaxAODHelpers.h
met
Definition: IMETSignificance.h:24
met::addGhostMuonsToJets
void addGhostMuonsToJets(const xAOD::MuonContainer &muons, xAOD::JetContainer &jets)
Definition: METHelpers.cxx:34
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ElectronContainer.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::MissingET_v1
Principal data object for Missing ET.
Definition: MissingET_v1.h:25
xAOD::MissingET_v1::mpx
float mpx() const
Returns .
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
ANA_MSG_SOURCE
#define ANA_MSG_SOURCE(NAME, TITLE)
the source code part of ANA_MSG_SOURCE
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:133
ANA_MSG_VERBOSE
#define ANA_MSG_VERBOSE(xmsg)
Macro printing verbose messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:286
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
MuonContainer.h
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
JetContainer.h
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
MissingETBase::Source::total
static Types::bitmask_t total(Region reg=Region::FullAcceptance)
Standard full reconstructed MET.
Definition: MissingETBase.h:271
met::fillMET
StatusCode fillMET(xAOD::MissingET *&met, xAOD::MissingETContainer *metCont, const std::string &metKey, const MissingETBase::Types::bitmask_t metSource)
Definition: METHelpers.cxx:123
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
xAOD::MissingET_v1::mpy
float mpy() const
Returns .
MissingETBase::Source::isSoftTerm
static bool isSoftTerm(Types::bitmask_t bits, Region reg=Region::FullAcceptance)
Definition: MissingETBase.h:403
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288