ATLAS Offline Software
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 
21 namespace 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;
51  for (const SG::ReadHandleKey<xAOD::TrigMissingETContainer> &key : m_triggerMETs)
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
METComponent.h
PathResolver::find_calib_file
static std::string find_calib_file(const std::string &logical_file_name)
Definition: PathResolver.cxx:384
xAOD::TrigMissingET_v1::sumEt
float sumEt() const
Get the sum of the ET of the missing energy.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
initialize
void initialize()
Definition: run_EoverP.cxx:894
WriteCellNoiseToCool.fullName
fullName
Definition: WriteCellNoiseToCool.py:461
xAOD::TrigMissingET_v1::ex
float ex() const
Get the x component of the missing energy.
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
postInclude.inputs
inputs
Definition: postInclude.SortInput.py:15
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
met
Definition: IMETSignificance.h:24
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
NNHLTFex.h
HLT::MET::NNHLTFex::NNHLTFex
NNHLTFex(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: NNHLTFex.cxx:29
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
HLT::MET
Definition: METComponent.cxx:8
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
lwtDev::parse_json_graph
GraphConfig parse_json_graph(std::istream &json)
Definition: parse_json.cxx:71
xAOD::TrigMissingET_v1
Class holding the Missing ET trigger fex results.
Definition: TrigMissingET_v1.h:32
xAOD::TrigMissingET_v1::ey
float ey() const
Get the y component of the missing energy.
met::fillMET
StatusCode fillMET(xAOD::MissingET *&met, xAOD::MissingETContainer *metCont, const std::string &metKey, const MissingETBase::Types::bitmask_t metSource)
Definition: METHelpers.cxx:123
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37