ATLAS Offline Software
FexBase.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 /******************************************************************************
6  * @package Trigger/TrigAlgorithms/TrigEFMissingET
7  * @file FexBase.cxx
8  *
9  * Implementation of base Fex class
10  * @author Jon Burr
11  *****************************************************************************/
12 
13 #include "FexBase.h"
18 #include <memory>
19 #include <algorithm>
20 #include <iterator>
21 
22 namespace {
23  // Convert from MeV to GeV if above threshold, else fallback value
24  float toLinGeV(float x, float fallback=0, float epsilon=1e-6)
25  {
26  float xGeV = x / Gaudi::Units::GeV;
27  if (std::fabs(xGeV) < epsilon)
28  return fallback;
29  return xGeV;
30  }
31  // convert from MeV to GeV and then log10, preserving the sign and the minimum
32  // dictated by monitoring histograms
33  float toLog10GeV(float x, float fallback=0, float epsilon=1e-6)
34  {
35  float absXGeV = std::fabs(x / Gaudi::Units::GeV);
36  if (absXGeV < epsilon)
37  return fallback;
38  return std::copysign(std::log10(absXGeV), x);
39  }
40 } //> end anonymous namespace
41 
42 namespace HLT { namespace MET {
43  FexBase::FexBase(const std::string& name, ISvcLocator* pSvcLocator) :
44  AthReentrantAlgorithm(name, pSvcLocator)
45  {
46  }
47 
49  const std::vector<std::string>& componentNames)
50  {
51  ATH_MSG_DEBUG("Initialising FexBase base class");
52  m_baseInitialised = true;
53  m_componentNames = componentNames;
54  CHECK( m_metContainerKey.initialize() );
55  if (!m_monTool.empty())
56  CHECK( m_monTool.retrieve() );
57  return StatusCode::SUCCESS;
58  }
59 
60  StatusCode FexBase::execute( const EventContext& context ) const
61  {
62  if (!m_baseInitialised) {
63  ATH_MSG_ERROR("Base class was not initialised! This means that the "
64  << "derived class was not correctly written!");
65  return StatusCode::FAILURE;
66  }
67  ATH_MSG_DEBUG("Executing " << name() << "...");
68  Monitored::Timer totalTimer("TIME_Total");
69  // Create the output
70  auto metCont = std::make_unique<xAOD::TrigMissingETContainer>();
71  auto metContAux = std::make_unique<xAOD::TrigMissingETAuxContainer>();
72  metCont->setStore(metContAux.get() );
73 
74  // Create the actual output object
75  metCont->push_back(std::make_unique<xAOD::TrigMissingET>());
76  xAOD::TrigMissingET* met = metCont->back();
77 
78  // Initialise the components
79  met->defineComponents(m_componentNames);
80  // We also need to initialise all of the values. This is not done by the EDM
81  // class so you can easily get missing aux element errors if you don't do
82  // this
83  met->setEx(0);
84  met->setEy(0);
85  met->setEz(0);
86  met->setSumEt(0);
87  met->setSumE(0);
88  met->setFlag(0);
89  met->setRoiWord(0);
90 
91  MonGroupBuilder monitors;
92  CHECK( fillMET(*met, context, monitors) );
93  // Add flags
94  CHECK( flagMET(*met) );
95  // Add extra monitors
96  CHECK( monitor(*met, monitors) );
97  // Create the actual group and trigger the monitoring
98  monitors.build(m_monTool);
99 
100  // Output REGTEST information
101  if (msgLvl(MSG::DEBUG) ) {
102  ATH_MSG_DEBUG( "REGTEST " << METComponent(*met) );
103  ATH_MSG_DEBUG( "REGTEST flag = " << met->flag() );
104  ATH_MSG_DEBUG( "REGTEST Name, status, values: ");
105  for (std::size_t ii = 0; ii < met->getNumberOfComponents(); ++ii)
106  ATH_MSG_DEBUG( "REGTEST "
107  << met->nameOfComponent(ii) << ", "
108  << met->statusComponent(ii) << ", "
109  << METComponent(ii, *met) );
110  }
111 
112  // Push this output to the store
113  auto handle = SG::makeHandle(m_metContainerKey, context);
114  CHECK( handle.record( std::move(metCont), std::move(metContAux) ) );
115  return StatusCode::SUCCESS;
116  }
117 
119  {
120  // Start with the components
121  // Keep a flag to OR into the main value
122  int overall = 0;
123  for (std::size_t ii = 0; ii < met.getNumberOfComponents(); ++ii) {
124  METComponent component(ii, met);
125  if (component.sumEt > 0 &&
126  component.met() / component.sumEt > m_maxComponentMETSumEtRatio) {
129  }
130  met.setStatusComponent(ii, component.status);
131  }
132  METComponent total(met);
133  total.status |= overall;
134  if (total.sumEt > 0 &&
135  total.met() / total.sumEt > m_maxGlobalMETSumEtRatio)
137  met.setFlag(total.status);
138  return StatusCode::SUCCESS;
139  }
140 
142  const xAOD::TrigMissingET& met,
143  MonGroupBuilder& monitors) const
144  {
145  METComponent metComponent(met);
146  // Increase the capacity of the vector
147  monitors.increaseCapacity(16, true);
148  // Add the standard variables
149  monitors.add(Monitored::Scalar("EF_MEx_log", toLog10GeV(metComponent.mpx) ) );
150  monitors.add(Monitored::Scalar("EF_MEy_log", toLog10GeV(metComponent.mpy) ) );
151  monitors.add(Monitored::Scalar("EF_MEz_log", toLog10GeV(metComponent.mpz) ) );
152  monitors.add(Monitored::Scalar("EF_MET_log", toLog10GeV(metComponent.met() ) ) );
153  monitors.add(Monitored::Scalar("EF_ME_log", toLog10GeV(metComponent.magnitude() ) ) );
154  monitors.add(Monitored::Scalar("EF_SumEt_log", toLog10GeV(metComponent.sumEt) ) );
155  monitors.add(Monitored::Scalar("EF_SumE_log", toLog10GeV(metComponent.sumE, -9e9) ) );
156  monitors.add(Monitored::Scalar("EF_MEx_lin", toLinGeV(metComponent.mpx) ) );
157  monitors.add(Monitored::Scalar("EF_MEy_lin", toLinGeV(metComponent.mpy) ) );
158  monitors.add(Monitored::Scalar("EF_MEz_lin", toLinGeV(metComponent.mpz) ) );
159  monitors.add(Monitored::Scalar("EF_MET_lin", toLinGeV(metComponent.met() ) ) );
160  monitors.add(Monitored::Scalar("EF_ME_lin", toLinGeV(metComponent.magnitude() ) ) );
161  monitors.add(Monitored::Scalar("EF_SumEt_lin", toLinGeV(metComponent.sumEt) ) );
162  monitors.add(Monitored::Scalar("EF_SumE_lin", toLinGeV(metComponent.sumE) ) );
163  monitors.add(Monitored::Scalar(
164  "EF_XS", toLinGeV(metComponent.met() ) / toLinGeV(metComponent.sumEt, 1) ) );
165  monitors.add(Monitored::Scalar("EF_MET_phi", metComponent.phi() ) );
166  return StatusCode::SUCCESS;
167  }
168 } } //> end namespace HLT::MET
METComponent.h
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
HLT::MET::FexBase::execute
virtual StatusCode execute(const EventContext &context) const override
Run the algorithm.
Definition: FexBase.cxx:60
HLT::MET::METComponent::mpx
float mpx
Momentum components x momentum.
Definition: METComponent.h:55
HLT::MET::FexBase::FexBase
FexBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: FexBase.cxx:43
HLT::MET::METComponent::sumEt
float sumEt
And the sumEt.
Definition: METComponent.h:72
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
HLT::MET::FexBase::m_componentNames
std::vector< std::string > m_componentNames
The names of the output MET components.
Definition: FexBase.h:72
HLT::MET::FexBase::m_maxComponentMETSumEtRatio
Gaudi::Property< float > m_maxComponentMETSumEtRatio
Definition: FexBase.h:132
HLT::MET::METComponent::status
int status
The status flag.
Definition: METComponent.h:74
x
#define x
HLT::MET::FexBase::fillMET
virtual StatusCode fillMET(xAOD::TrigMissingET &met, const EventContext &context, MonGroupBuilder &monitors) const =0
Calculate and fill the output MET value.
HLT::MET::StatusFlag::GlobalBigMEtSEtRatio
@ GlobalBigMEtSEtRatio
Definition: StatusFlags.h:61
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
HLT::MET::METComponent::sumE
float sumE
Also store the sumE.
Definition: METComponent.h:70
HLT::MET::FexBase::m_baseInitialised
bool m_baseInitialised
Whether or not this class has been correctly initialised.
Definition: FexBase.h:143
HLT::MET::FexBase::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
The monitoring tool.
Definition: FexBase.h:130
HLT::MET::FexBase::monitor
virtual StatusCode monitor(const xAOD::TrigMissingET &met, MonGroupBuilder &monitors) const
Add monitor variables from an xAOD::TrigMissingET object.
Definition: FexBase.cxx:141
met
Definition: IMETSignificance.h:24
HLT::MET::METComponent::magnitude
float magnitude() const
The magnitude of the missing 3-vector.
Definition: METComponent.cxx:32
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HLT::MET::MonGroupBuilder::build
Monitored::Group build(const ToolHandle< GenericMonitoringTool > &tool) const
Build the monitored group.
Definition: MonGroupBuilder.cxx:33
FexBase.h
HLT
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition: HLTResultReader.h:26
HLT::MET::FexBase::m_metContainerKey
SG::WriteHandleKey< xAOD::TrigMissingETContainer > m_metContainerKey
The output MET object.
Definition: FexBase.h:127
StatusFlags.h
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
HLT::MET::FexBase::m_maxGlobalMETSumEtRatio
Gaudi::Property< float > m_maxGlobalMETSumEtRatio
Definition: FexBase.h:135
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
HLT::MET::FexBase::flagMET
virtual StatusCode flagMET(xAOD::TrigMissingET &met) const
Flag suspicious values in the output MET.
Definition: FexBase.cxx:118
HLT::MET::METComponent::phi
float phi() const
The direction.
Definition: METComponent.cxx:36
HLT::MET::MonGroupBuilder::add
void add(Monitored::IMonitoredVariable &variable)
Add a new monitored variable.
Definition: MonGroupBuilder.cxx:28
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
HLT::MET::FexBase::initializeBase
StatusCode initializeBase(const std::vector< std::string > &componentNames)
Initialize the base class.
Definition: FexBase.cxx:48
HLT::MET::METComponent::mpy
float mpy
y momentum
Definition: METComponent.h:57
HLT::MET::METComponent
Helper struct to build up MET values before moving them into the EDM.
Definition: METComponent.h:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MET
Definition: MET.py:1
HLT::MET::StatusFlag::ComponentBigMEtSEtRatio
@ ComponentBigMEtSEtRatio
Definition: StatusFlags.h:47
HLT::MET::MonGroupBuilder
Definition: MonGroupBuilder.h:45
HLT::MET::MonGroupBuilder::increaseCapacity
void increaseCapacity(std::size_t value, bool owned=false)
Increase the internal capacity.
Definition: MonGroupBuilder.cxx:39
HLT::MET::METComponent::met
float met() const
The actual met.
Definition: METComponent.cxx:28
xAOD::TrigMissingET_v1
Class holding the Missing ET trigger fex results.
Definition: TrigMissingET_v1.h:32
DEBUG
#define DEBUG
Definition: page_access.h:11
TrigMissingETAuxContainer.h
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
HLT::MET::METComponent::mpz
float mpz
z momentum
Definition: METComponent.h:59