ATLAS Offline Software
Loading...
Searching...
No Matches
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
22namespace {
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
42namespace 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
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
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
Header file to be included by clients of the Monitored infrastructure.
#define x
bool msgLvl(const MSG::Level lvl) const
An algorithm that can be simultaneously executed in multiple threads.
virtual StatusCode flagMET(xAOD::TrigMissingET &met) const
Flag suspicious values in the output MET.
Definition FexBase.cxx:118
std::vector< std::string > m_componentNames
The names of the output MET components.
Definition FexBase.h:48
bool m_baseInitialised
Whether or not this class has been correctly initialised.
Definition FexBase.h:119
ToolHandle< GenericMonitoringTool > m_monTool
The monitoring tool.
Definition FexBase.h:106
Gaudi::Property< float > m_maxGlobalMETSumEtRatio
Definition FexBase.h:111
FexBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition FexBase.cxx:43
virtual StatusCode fillMET(xAOD::TrigMissingET &met, const EventContext &context, MonGroupBuilder &monitors) const =0
Calculate and fill the output MET value.
virtual StatusCode execute(const EventContext &context) const override
Run the algorithm.
Definition FexBase.cxx:60
Gaudi::Property< float > m_maxComponentMETSumEtRatio
Definition FexBase.h:108
SG::WriteHandleKey< xAOD::TrigMissingETContainer > m_metContainerKey
The output MET object.
Definition FexBase.h:103
StatusCode initializeBase(const std::vector< std::string > &componentNames)
Initialize the base class.
Definition FexBase.cxx:48
virtual StatusCode monitor(const xAOD::TrigMissingET &met, MonGroupBuilder &monitors) const
Add monitor variables from an xAOD::TrigMissingET object.
Definition FexBase.cxx:141
Helper struct to build up MET values before moving them into the EDM.
float mpx
Momentum components x momentum.
float sumE
Also store the sumE.
float mpz
z momentum
float sumEt
And the sumEt.
float mpy
y momentum
int status
The status flag.
float phi() const
The direction.
float magnitude() const
The magnitude of the missing 3-vector.
float met() const
The actual met.
void add(Monitored::IMonitoredVariable &variable)
Add a new monitored variable.
void increaseCapacity(std::size_t value, bool owned=false)
Increase the internal capacity.
Monitored::Group build(const ToolHandle< GenericMonitoringTool > &tool) const
Build the monitored group.
Declare a monitored scalar variable.
A monitored timer.
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
TrigMissingET_v1 TrigMissingET
Define the most recent version of the TrigMissingET class.