ATLAS Offline Software
METMonitorAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
7 #include "xAODJet/Jet.h"
8 
9 
10 static const std::map<std::string, std::pair<std::string, std::string> > key2SubSkeyMap( {
11  { "MET_RefFinal", { "MET_Reference_AntiKt4EMTopo", "FinalTrk" } },// add track
12  { "MET_RefEle", { "MET_Reference_AntiKt4EMTopo", "RefEle" } },
13  { "MET_RefGamma", { "MET_Reference_AntiKt4EMTopo", "RefGamma" } } ,
14  { "MET_RefTau", { "MET_Reference_AntiKt4EMTopo", "RefTau" } },
15  { "MET_SoftClus", { "MET_Reference_AntiKt4EMTopo", "SoftClus" } },
16  { "MET_SoftTrk", { "MET_Reference_AntiKt4EMTopo", "FinalTrk" } },
17  { "MET_PVSoftTrk", { "MET_Reference_AntiKt4EMTopo", "PVSoftTrk" } },
18  { "MET_RefJet_JVFCut", { "MET_Reference_AntiKt4EMTopo", "RefJet" } }, // RefJet_JVFCut
19  { "MET_RefJet", { "MET_Reference_AntiKt4EMTopo", "RefJet" } },
20  { "MET_Muon", { "MET_Reference_AntiKt4EMTopo", "Muons" } },
21  { "MET_PFlow", { "MET_Reference_AntiKt4EMPFlow", "FinalTrk" } }, // add track
22  { "MET_PFlow_RefEle", { "MET_Reference_AntiKt4EMPFlow", "RefEle" } },
23  { "MET_PFlow_RefGamma", { "MET_Reference_AntiKt4EMPFlow", "RefGamma" } },
24  { "MET_PFlow_RefTau", { "MET_Reference_AntiKt4EMPFlow", "RefTau" } },
25  { "MET_PFlow_SoftClus", { "MET_Reference_AntiKt4EMPFlow", "SoftClus" } },
26  { "MET_PFlow_SoftTrk", { "MET_Reference_AntiKt4EMPFlow", "FinalTrk" } },
27  { "MET_PFlow_PVSoftTrk", { "MET_Reference_AntiKt4EMPFlow", "PVSoftTrk" } },
28  { "MET_PFlow_RefJet_JVFCut", { "MET_Reference_AntiKt4EMPFlow", "RefJet" } }, // RefJet_JVFCut
29  { "MET_PFlow_RefJet", { "MET_Reference_AntiKt4EMPFlow", "RefJet" } },
30  { "MET_PFlow_Muon", { "MET_Reference_AntiKt4EMPFlow", "Muons" } },
31  { "MET_LocalHadTopo", { "MET_LocHadTopo", "LocHadTopo" } },
32  { "MET_LocHadTopo", { "MET_LocHadTopo", "LocHadTopo" } }, // same as above
33  { "MET_Topo", { "MET_EMTopo", "EMTopo" } },
34  { "MET_Track", { "MET_Track", "Track" } },
35  { "MET_PFlow", { "MET_Reference_AntiKt4EMPFlow", "FinalClus" } } } );
36 
37 
38 METMonitoringAlg::METMonitoringAlg( const std::string& name, ISvcLocator* pSvcLocator ) :AthMonitorAlgorithm(name,pSvcLocator) {
39 
40 }
41 
42 
44 
46  for (const auto& key : m_metKeys) {
47  auto foundIterator = key2SubSkeyMap.find( key );
48  if ( foundIterator == key2SubSkeyMap.end() ) {
49  ATH_MSG_FATAL("Unable to find MET key " << key << " in lookup table; quit");
50  return StatusCode::FAILURE;
51  }
52  if (foundIterator->second.first != m_metContainerKey.key()) {
53  ATH_MSG_FATAL("Mismatch of requested MET key " << key << ", which comes from "
54  << foundIterator->second.first
55  << ", with configured container key " << m_metContainerKey
56  << "; quit");
57  return StatusCode::FAILURE;
58  }
59  }
60  ATH_CHECK(m_metContainerKey.initialize());
61  ATH_CHECK(m_metCaloContainerKey.initialize());
63 
64  ATH_CHECK(m_jetContainerKey.initialize());
65  if (m_doJetCleaning) {
66  ATH_MSG_DEBUG("::initializing JetCleaningTool");
67  ATH_CHECK(m_jetCleaningTool.retrieve());
68  ATH_MSG_DEBUG("::initialized JetCleaningTool");
69  } else {
70 
71  m_jetCleaningTool.disable();
72  }
73 
75 }
76 
77 StatusCode METMonitoringAlg::fillHistograms( const EventContext& ctx ) const {
78  using namespace Monitored;
79  using Gaudi::Units::GeV;
80 
82  if (!metContainer.isValid() ) {
83  ATH_MSG_ERROR("evtStore() does not contain MET Collection with name "<< m_metContainerKey);
84  return StatusCode::FAILURE;
85  }
87  if (!metCaloContainer.isValid() ) {
88  ATH_MSG_ERROR("evtStore() does not contain METCalo Collection with name "<< m_metCaloContainerKey);
89  return StatusCode::FAILURE;
90  }
91 
93  if (!metCaloContainer.isValid() ) {
94  ATH_MSG_ERROR("evtStore() does not contain METAKt4EMTopo Collection with name "<< m_metAKt4EMTopoContainerKey);
95  return StatusCode::FAILURE;
96  }
97  const auto* trigDecTool = (getTrigDecisionTool().empty() ?
98  nullptr : getTrigDecisionTool().operator->());
99  bool isMETtopocalo = false;
100  for (const auto& key : m_metKeys) {
101  if (key == "MET_Topo") isMETtopocalo = true;
102  }
103  if (isMETtopocalo){
104  if (m_dometcut && (*metAKt4EMTopoContainer)[m_metTotalKey]->met() < m_metcut*GeV) return StatusCode::SUCCESS;
105 
106  } else {
107  if (m_dometcut && (*metContainer)[m_metTotalKey]->met() < m_metcut*GeV) return StatusCode::SUCCESS;
108 
109  }
110 
111  if (m_dotrig) {
112  if (trigDecTool !=0 && !(trigDecTool->isPassed("L1_jXE100")))
113  return StatusCode::SUCCESS;
114  }
115 
116  for (const auto& metKey : m_metKeys)
117  {
118  const std::string& xaod_subkey = key2SubSkeyMap.at(metKey).second;
119  const xAOD::MissingET* xMissEt = (*metContainer)[xaod_subkey];
120  if (xMissEt) {
121  std::string name = metKey + "_et";
122  auto et = Monitored::Scalar<double>(name,-1.0);
123  name = metKey + "_ex";
124  auto ex = Monitored::Scalar<double>(name,-1.0);
125  name = metKey + "_ey";
126  auto ey = Monitored::Scalar<double>(name,-1.0);
127  name = metKey + "_phi";
128  auto phi = Monitored::Scalar<double>(name,-1.0);
129  name = metKey + "_sumet";
130  auto sumet = Monitored::Scalar<double>(name,-1.0);
131  ex = xMissEt->mpx() / GeV;
132  ey = xMissEt->mpy() / GeV;
133  et = xMissEt->met() / GeV;
134  phi = xMissEt->phi();
135  sumet = xMissEt->sumet() / GeV;
136 
137  if (m_alltrigger && m_doBadJets == false) {
138  fill("METMonitor",ex,ey,et,phi,sumet);
139  } else if (m_doBadJets) {
140  if (!isGoodEvent(ctx)) {
141  fill("METMonitor",ex,ey,et,phi,sumet);
142  }
143  } else if (m_doJetCleaning && m_doBadJets == false) {
144  if (isGoodEvent(ctx)) {
145  fill("METMonitor",ex,ey,et,phi,sumet);
146  }
147  } else {
148  fill("METMonitor",ex,ey,et,phi,sumet);
149  }
150  }
151  }
152 
153  for (const auto& calString : m_calStrings) {
154  const xAOD::MissingET* xmetCal = (*metCaloContainer)[calString];
155  if (xmetCal){
156  std::string name = "MET_"+calString + "_et";
157  auto et = Monitored::Scalar<double>(name,-1.0);
158  name = "MET_" + calString + "_ex";
159  auto ex = Monitored::Scalar<double>(name,-1.0);
160  name = "MET_" +calString + "_ey";
161  auto ey = Monitored::Scalar<double>(name,-1.0);
162  name = "MET_" +calString + "_phi";
163  auto phi = Monitored::Scalar<double>(name,-1.0);
164  name = "MET_" +calString + "_sumet";
165  auto sumet = Monitored::Scalar<double>(name,-1.0);
166  ex = xmetCal->mpx() / GeV;
167  ey = xmetCal->mpy() / GeV;
168  et = xmetCal->met() / GeV;
169  phi = xmetCal->phi();
170  sumet = xmetCal->sumet() / GeV;
171 
172  if (m_alltrigger && m_doBadJets == false) {
173  fill("METMonitor",ex,ey,et,phi,sumet);
174  } else if (m_doBadJets) {
175  if (!isGoodEvent(ctx)) {
176  fill("METMonitor",ex,ey,et,phi,sumet);
177  }
178  } else if (m_doJetCleaning && m_doBadJets == false) {
179  if (isGoodEvent(ctx)) {
180  fill("METMonitor",ex,ey,et,phi,sumet);
181 
182  }
183  } else {
184  fill("METMonitor",ex,ey,et,phi,sumet);
185  }
186 
187  }
188  }
189  return StatusCode::SUCCESS;
190 }
191 
192 
193 bool METMonitoringAlg::isGoodEvent( const EventContext& ctx ) const {
194  if (! m_doJetCleaning) return true;
195 
197  if (! jetContainer.isValid() ) {
198  ATH_MSG_ERROR("evtStore() does not contain jet Collection with name "<< m_jetContainerKey);
199  return false;
200  }
201 
202  for (const xAOD::Jet* jet : *jetContainer) {
203  if (m_jetCleaningTool->keep(*jet) == false) return false;
204  }
205  return true;
206 }
METMonitoringAlg::METMonitoringAlg
METMonitoringAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: METMonitorAlgorithm.cxx:38
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:43
METMonitoringAlg::isGoodEvent
bool isGoodEvent(const EventContext &ctx) const
Definition: METMonitorAlgorithm.cxx:193
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:70
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:189
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
METMonitoringAlg::m_metContainerKey
SG::ReadHandleKey< xAOD::MissingETContainer > m_metContainerKey
Definition: METMonitorAlgorithm.h:27
METMonitoringAlg::initialize
StatusCode initialize() override
initialize
Definition: METMonitorAlgorithm.cxx:45
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:30
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:77
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.
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:221
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