ATLAS Offline Software
METMonitorAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
8 #include "xAODJet/Jet.h"
9 #include "GaudiKernel/SystemOfUnits.h"
10 
11 
12 static const std::map<std::string, std::pair<std::string, std::string> > key2SubSkeyMap( {
13  { "MET_RefFinal", { "MET_Reference_AntiKt4EMTopo", "FinalTrk" } },// add track
14  { "MET_RefEle", { "MET_Reference_AntiKt4EMTopo", "RefEle" } },
15  { "MET_RefGamma", { "MET_Reference_AntiKt4EMTopo", "RefGamma" } } ,
16  { "MET_RefTau", { "MET_Reference_AntiKt4EMTopo", "RefTau" } },
17  { "MET_SoftClus", { "MET_Reference_AntiKt4EMTopo", "SoftClus" } },
18  { "MET_SoftTrk", { "MET_Reference_AntiKt4EMTopo", "FinalTrk" } },
19  { "MET_PVSoftTrk", { "MET_Reference_AntiKt4EMTopo", "PVSoftTrk" } },
20  { "MET_RefJet_JVFCut", { "MET_Reference_AntiKt4EMTopo", "RefJet" } }, // RefJet_JVFCut
21  { "MET_RefJet", { "MET_Reference_AntiKt4EMTopo", "RefJet" } },
22  { "MET_Muon", { "MET_Reference_AntiKt4EMTopo", "Muons" } },
23  { "MET_PFlow", { "MET_Reference_AntiKt4EMPFlow", "FinalTrk" } }, // add track
24  { "MET_PFlow_RefEle", { "MET_Reference_AntiKt4EMPFlow", "RefEle" } },
25  { "MET_PFlow_RefGamma", { "MET_Reference_AntiKt4EMPFlow", "RefGamma" } },
26  { "MET_PFlow_RefTau", { "MET_Reference_AntiKt4EMPFlow", "RefTau" } },
27  { "MET_PFlow_SoftClus", { "MET_Reference_AntiKt4EMPFlow", "SoftClus" } },
28  { "MET_PFlow_SoftTrk", { "MET_Reference_AntiKt4EMPFlow", "FinalTrk" } },
29  { "MET_PFlow_PVSoftTrk", { "MET_Reference_AntiKt4EMPFlow", "PVSoftTrk" } },
30  { "MET_PFlow_RefJet_JVFCut", { "MET_Reference_AntiKt4EMPFlow", "RefJet" } }, // RefJet_JVFCut
31  { "MET_PFlow_RefJet", { "MET_Reference_AntiKt4EMPFlow", "RefJet" } },
32  { "MET_PFlow_Muon", { "MET_Reference_AntiKt4EMPFlow", "Muons" } },
33  { "MET_LocalHadTopo", { "MET_LocHadTopo", "LocHadTopo" } },
34  { "MET_LocHadTopo", { "MET_LocHadTopo", "LocHadTopo" } }, // same as above
35  { "MET_Topo", { "MET_EMTopo", "EMTopo" } },
36  { "MET_Track", { "MET_Track", "Track" } },
37  { "MET_PFlow", { "MET_Reference_AntiKt4EMPFlow", "FinalClus" } } } );
38 
39 
40 METMonitoringAlg::METMonitoringAlg( const std::string& name, ISvcLocator* pSvcLocator ) :AthMonitorAlgorithm(name,pSvcLocator) {
41 
42 }
43 
44 
46 
48  for (const auto& key : m_metKeys) {
49  auto foundIterator = key2SubSkeyMap.find( key );
50  if ( foundIterator == key2SubSkeyMap.end() ) {
51  ATH_MSG_FATAL("Unable to find MET key " << key << " in lookup table; quit");
52  return StatusCode::FAILURE;
53  }
54  if (foundIterator->second.first != m_metContainerKey.key()) {
55  ATH_MSG_FATAL("Mismatch of requested MET key " << key << ", which comes from "
56  << foundIterator->second.first
57  << ", with configured container key " << m_metContainerKey
58  << "; quit");
59  return StatusCode::FAILURE;
60  }
61  }
62  ATH_CHECK(m_metContainerKey.initialize());
63  ATH_CHECK(m_metCaloContainerKey.initialize());
65 
67  if (m_doJetCleaning) {
68  ATH_MSG_DEBUG("::initializing JetCleaningTool");
69  ATH_CHECK(m_jetCleaningTool.retrieve());
70  ATH_MSG_DEBUG("::initialized JetCleaningTool");
71  } else {
72 
73  m_jetCleaningTool.disable();
74  }
75 
77 }
78 
79 StatusCode METMonitoringAlg::fillHistograms( const EventContext& ctx ) const {
80  using namespace Monitored;
81  using Gaudi::Units::GeV;
82 
84  if (!metContainer.isValid() ) {
85  ATH_MSG_ERROR("evtStore() does not contain MET Collection with name "<< m_metContainerKey);
86  return StatusCode::FAILURE;
87  }
89  if (!metCaloContainer.isValid() ) {
90  ATH_MSG_ERROR("evtStore() does not contain METCalo Collection with name "<< m_metCaloContainerKey);
91  return StatusCode::FAILURE;
92  }
93 
95  if (!metCaloContainer.isValid() ) {
96  ATH_MSG_ERROR("evtStore() does not contain METAKt4EMTopo Collection with name "<< m_metAKt4EMTopoContainerKey);
97  return StatusCode::FAILURE;
98  }
99  const auto* trigDecTool = (getTrigDecisionTool().empty() ?
100  nullptr : getTrigDecisionTool().operator->());
101  bool isMETtopocalo = false;
102  for (const auto& key : m_metKeys) {
103  if (key == "MET_Topo") isMETtopocalo = true;
104  }
105  if (isMETtopocalo){
106  if (m_dometcut && (*metAKt4EMTopoContainer)[m_metTotalKey]->met() < m_metcut*GeV) return StatusCode::SUCCESS;
107 
108  } else {
109  if (m_dometcut && (*metContainer)[m_metTotalKey]->met() < m_metcut*GeV) return StatusCode::SUCCESS;
110 
111  }
112 
113  if (m_dotrig) {
114  if (trigDecTool !=0 && !(trigDecTool->isPassed("L1_jXE100")))
115  return StatusCode::SUCCESS;
116  }
117 
118  for (const auto& metKey : m_metKeys)
119  {
120  const std::string& xaod_subkey = key2SubSkeyMap.at(metKey).second;
121  const xAOD::MissingET* xMissEt = (*metContainer)[xaod_subkey];
122  if (xMissEt) {
123  std::string name = metKey + "_et";
124  auto et = Monitored::Scalar<double>(name,-1.0);
125  name = metKey + "_ex";
126  auto ex = Monitored::Scalar<double>(name,-1.0);
127  name = metKey + "_ey";
128  auto ey = Monitored::Scalar<double>(name,-1.0);
129  name = metKey + "_phi";
130  auto phi = Monitored::Scalar<double>(name,-1.0);
131  name = metKey + "_sumet";
132  auto sumet = Monitored::Scalar<double>(name,-1.0);
133  ex = xMissEt->mpx() / GeV;
134  ey = xMissEt->mpy() / GeV;
135  et = xMissEt->met() / GeV;
136  phi = xMissEt->phi();
137  sumet = xMissEt->sumet() / GeV;
138 
139  if (m_alltrigger && m_doBadJets == false) {
140  fill("METMonitor",ex,ey,et,phi,sumet);
141  } else if (m_doBadJets) {
142  if (!isGoodEvent(ctx)) {
143  fill("METMonitor",ex,ey,et,phi,sumet);
144  }
145  } else if (m_doJetCleaning && m_doBadJets == false) {
146  if (isGoodEvent(ctx)) {
147  fill("METMonitor",ex,ey,et,phi,sumet);
148  }
149  } else {
150  fill("METMonitor",ex,ey,et,phi,sumet);
151  }
152  }
153  }
154 
155  for (const auto& calString : m_calStrings) {
156  const xAOD::MissingET* xmetCal = (*metCaloContainer)[calString];
157  if (xmetCal){
158  std::string name = "MET_"+calString + "_et";
159  auto et = Monitored::Scalar<double>(name,-1.0);
160  name = "MET_" + calString + "_ex";
161  auto ex = Monitored::Scalar<double>(name,-1.0);
162  name = "MET_" +calString + "_ey";
163  auto ey = Monitored::Scalar<double>(name,-1.0);
164  name = "MET_" +calString + "_phi";
165  auto phi = Monitored::Scalar<double>(name,-1.0);
166  name = "MET_" +calString + "_sumet";
167  auto sumet = Monitored::Scalar<double>(name,-1.0);
168  ex = xmetCal->mpx() / GeV;
169  ey = xmetCal->mpy() / GeV;
170  et = xmetCal->met() / GeV;
171  phi = xmetCal->phi();
172  sumet = xmetCal->sumet() / GeV;
173 
174  if (m_alltrigger && m_doBadJets == false) {
175  fill("METMonitor",ex,ey,et,phi,sumet);
176  } else if (m_doBadJets) {
177  if (!isGoodEvent(ctx)) {
178  fill("METMonitor",ex,ey,et,phi,sumet);
179  }
180  } else if (m_doJetCleaning && m_doBadJets == false) {
181  if (isGoodEvent(ctx)) {
182  fill("METMonitor",ex,ey,et,phi,sumet);
183 
184  }
185  } else {
186  fill("METMonitor",ex,ey,et,phi,sumet);
187  }
188 
189  }
190  }
191  return StatusCode::SUCCESS;
192 }
193 
194 
195 bool METMonitoringAlg::isGoodEvent( const EventContext& ctx ) const {
196  if (! m_doJetCleaning) return true;
197 
199  if (! jetContainer.isValid() ) {
200  ATH_MSG_ERROR("evtStore() does not contain jet Collection with name "<< m_jetContainerKey);
201  return false;
202  }
203 
204  for (const xAOD::Jet* jet : *jetContainer) {
205  if (m_jetCleaningTool->keep(*jet) == false) return false;
206  }
207  return true;
208 }
METMonitoringAlg::METMonitoringAlg
METMonitoringAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: METMonitorAlgorithm.cxx:40
Jet.h
et
Extra patterns decribing particle interation process.
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
METMonitoringAlg::~METMonitoringAlg
virtual ~METMonitoringAlg()
Definition: METMonitorAlgorithm.cxx:45
METMonitoringAlg::isGoodEvent
bool isGoodEvent(const EventContext &ctx) const
Definition: METMonitorAlgorithm.cxx:195
METMonitoringAlg::m_metTotalKey
Gaudi::Property< std::string > m_metTotalKey
Definition: METMonitorAlgorithm.h:32
xAOD::MissingET_v1::sumet
float sumet() const
Returns.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
METMonitoringAlg::m_dotrig
Gaudi::Property< bool > m_dotrig
Definition: METMonitorAlgorithm.h:46
xAOD::MissingET_v1::phi
float phi() const
Returns .
AthMonitorAlgorithm::getTrigDecisionTool
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
Definition: AthMonitorAlgorithm.cxx:194
METMonitoringAlg::m_metcut
Gaudi::Property< double > m_metcut
Definition: METMonitorAlgorithm.h:45
METMonitoringAlg::m_metKeys
Gaudi::Property< std::vector< std::string > > m_metKeys
Definition: METMonitorAlgorithm.h:40
TrigDecisionTool.h
METMonitoringAlg::m_metContainerKey
SG::ReadHandleKey< xAOD::MissingETContainer > m_metContainerKey
Definition: METMonitorAlgorithm.h:27
METMonitoringAlg::initialize
StatusCode initialize() override
initialize
Definition: METMonitorAlgorithm.cxx:47
METMonitorAlgorithm.h
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
METMonitoringAlg::m_doJetCleaning
Gaudi::Property< bool > m_doJetCleaning
Definition: METMonitorAlgorithm.h:47
METMonitoringAlg::m_metAKt4EMTopoContainerKey
SG::ReadHandleKey< xAOD::MissingETContainer > m_metAKt4EMTopoContainerKey
Definition: METMonitorAlgorithm.h:29
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:28
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
METMonitoringAlg::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: METMonitorAlgorithm.cxx:79
xAOD::MissingET_v1
Principal data object for Missing ET.
Definition: MissingET_v1.h:25
xAOD::MissingET_v1::mpx
float mpx() const
Returns .
METMonitoringAlg::m_doBadJets
Gaudi::Property< bool > m_doBadJets
Definition: METMonitorAlgorithm.h:44
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthMonitorAlgorithm::fill
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable >> &&variables) const
Fills a vector of variables to a group by reference.
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
METMonitoringAlg::m_jetCleaningTool
ToolHandle< IJetSelector > m_jetCleaningTool
Definition: METMonitorAlgorithm.h:48
METMonitoringAlg::m_metCaloContainerKey
SG::ReadHandleKey< xAOD::MissingETContainer > m_metCaloContainerKey
Definition: METMonitorAlgorithm.h:28
METMonitoringAlg::m_calStrings
Gaudi::Property< std::vector< std::string > > m_calStrings
Definition: METMonitorAlgorithm.h:37
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
MissingET.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
METMonitoringAlg::m_dometcut
Gaudi::Property< bool > m_dometcut
Definition: METMonitorAlgorithm.h:43
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
xAOD::MissingET_v1::mpy
float mpy() const
Returns .
METMonitoringAlg::m_jetContainerKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetContainerKey
Definition: METMonitorAlgorithm.h:34
METMonitoringAlg::m_alltrigger
Gaudi::Property< bool > m_alltrigger
Definition: METMonitorAlgorithm.h:42
xAOD::MissingET_v1::met
float met() const
Returns .
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37