ATLAS Offline Software
Loading...
Searching...
No Matches
NNHLTFex.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4
5/******************************************************************************
6 * @package Trigger/TrigAlgorithms/TrigEFMissingET
7 * @file NNHLTFex.cxx
8 *
9 * Implementation of the HLT NN combination fex class
10 * @author Zhelun Li
11 *****************************************************************************/
12
13#include "NNHLTFex.h"
15#include <array>
17#include "GaudiKernel/SystemOfUnits.h"
18#include <istream>
19#include <fstream>
20
21namespace HLT::MET {
22
23 NNHLTFex::NNHLTFex(const std::string& name, ISvcLocator* pSvcLocator) :
24 FexBase(name, pSvcLocator),
25 m_graphNN(nullptr)
26 {
27 }
28
30 {
31 std::string fullName = PathResolver::find_calib_file(m_filename);
32 if (fullName.empty()){
33 ATH_MSG_ERROR("Failed to find NN configuration file'" << m_filename << "'!");
34 return StatusCode::FAILURE;
35 }
36 std::ifstream inputNN(fullName);
37 m_configNN = lwt::parse_json_graph(inputNN);
38 if (m_configNN.inputs.size() != 1) return StatusCode::FAILURE;//only one input node allowed
39 m_graphNN = std::make_unique<lwt::LightweightGraph>(m_configNN);
40 CHECK(m_triggerMETs.initialize());
41 return initializeBase({"HLTMET"});
42 }
43
46 const EventContext& context,
47 MonGroupBuilder&) const
48 {
49 //for lwtnn:
50 std::map<std::string, std::map<std::string, double> > inputs;
52 {
53 std::string name = key.key();
55 if (!met.isValid())
56 {
57 ATH_MSG_ERROR("Failed to retrieve " << key);
58 return StatusCode::FAILURE;
59 }
60
61 if (met->size() == 0)
62 {
63 inputs["node_0"].insert(std::pair<std::string, double>(name+".met",-1) );
64 inputs["node_0"].insert(std::pair<std::string, double>(name+".sumet",-1) );
65 }
66 else
67 {
68 const xAOD::TrigMissingET &metObj = *(met->at(0));
69 float mpx = metObj.ex();
70 float mpy = metObj.ey();
71 inputs["node_0"].insert(std::pair<std::string, double>(name+".met",sqrt(mpx * mpx + mpy * mpy)/Gaudi::Units::GeV) );
72 inputs["node_0"].insert(std::pair<std::string, double>(name+".sumet",metObj.sumEt()/Gaudi::Units::GeV) );
73 }
74 }
75
76 std::map<std::string, double> outputNN = m_graphNN->compute(inputs);
77 auto NN_MET=outputNN["out_0"]*Gaudi::Units::GeV;
78 //The NN only estimates the MET. Setting to mpx. But this means that only the total MET makes sense. mpx,mpy,mpz,sumEt
79 // are no available. Be careful!
80 met.setEx(NN_MET);
81
82 return StatusCode::SUCCESS;
83 }
84} //> end namespace HLT::MET
#define ATH_MSG_ERROR(x)
#define CHECK(...)
Evaluate an expression and check for errors.
FexBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition FexBase.cxx:43
StatusCode initializeBase(const std::vector< std::string > &componentNames)
Initialize the base class.
Definition FexBase.cxx:48
virtual StatusCode initialize() override
Initialize the fex.
Definition NNHLTFex.cxx:29
lwt::GraphConfig m_configNN
Definition NNHLTFex.h:52
std::unique_ptr< lwt::LightweightGraph > m_graphNN
Definition NNHLTFex.h:53
NNHLTFex(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition NNHLTFex.cxx:23
Gaudi::Property< std::string > m_filename
Definition NNHLTFex.h:49
virtual StatusCode fillMET(xAOD::TrigMissingET &met, const EventContext &context, MonGroupBuilder &monitors) const override
Calculate and fill the output MET value.
Definition NNHLTFex.cxx:44
SG::ReadHandleKeyArray< xAOD::TrigMissingETContainer > m_triggerMETs
Definition NNHLTFex.h:47
static std::string find_calib_file(const std::string &logical_file_name)
Property holding a SG store/key/clid from which a ReadHandle is made.
float ex() const
Get the x component of the missing energy.
float sumEt() const
Get the sum of the ET of the missing energy.
float ey() const
Get the y component of the missing energy.
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.