ATLAS Offline Software
METTriggerAugmentationTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include <xAODTrigger/JetRoI.h>
9 #include <vector>
10 #include <string>
11 
12 #include <TFile.h>
13 
14 namespace DerivationFramework {
15 
17  const std::string& n,
18  const IInterface* p) :
19  base_class(t,n,p)
20  {
21  }
22 
24  {
25  ATH_CHECK(m_L1METName.initialize());
26  ATH_CHECK(m_L1JetName.initialize());
27  ATH_CHECK(m_outputName.initialize());
28  std::string fullLUTFileName = PathResolver::find_file(m_LUTFileName, "DATAPATH");
29 
30  if (fullLUTFileName.empty() ) {
31  ATH_MSG_ERROR( "File " << m_LUTFileName << " not found!" );
32  return StatusCode::FAILURE;
33  }
34 
35  TFile* lutFile = TFile::Open(fullLUTFileName.c_str() );
36  if (lutFile->IsZombie() ) return StatusCode::FAILURE;
37 
38  TH2* lutFromFile{};
39  lutFile->GetObject("LUT", lutFromFile);
40  if (!lutFromFile) {
41  ATH_MSG_ERROR( "LUT file doesn't contain a 'LUT' object!" );
42  return StatusCode::FAILURE;
43  }
44 
45  m_LUT.reset(dynamic_cast<TH2*>(lutFromFile->Clone() ) );
46  m_LUT->SetDirectory(0);
47  lutFile->Close();
48  return StatusCode::SUCCESS;
49  }
50 
51  StatusCode METTriggerAugmentationTool::addBranches(const EventContext& ctx) const
52  {
53  ATH_MSG_DEBUG(" In L1KF_METMaker::makeKFMET()" );
54  // if the output has already been written we don't need to do anything
55  if (evtStore()->contains<xAOD::EnergySumRoI>(m_outputName.key()) ) return StatusCode::SUCCESS; // FIXME tool should not have been configured in this case
56 
58  if (!originalL1.isValid()){
59  ATH_MSG_ERROR("Unable to retrieve EnergySumRoI: " << m_L1METName << "!");
60  return StatusCode::FAILURE;
61  }
62 
64  if (!originalL1.isValid()){
65  ATH_MSG_ERROR("Unable to retrieve JetRoIContainer: " << m_L1JetName << "!");
66  return StatusCode::FAILURE;
67  }
68 
70  if (!originalL1.isValid()){
71  ATH_MSG_ERROR("Invalid WriteHandle for EnergySumRoI: " << m_outputName << "!");
72  return StatusCode::FAILURE;
73  }
74  ATH_CHECK(l1_kf.record(std::make_unique<xAOD::EnergySumRoI>(), std::make_unique<xAOD::EnergySumRoIAuxInfo>()));
75 
76  ATH_MSG_DEBUG( "Making deep copy" );
77  // copy across the info
78  *l1_kf = *originalL1;
79 
80  ATH_MSG_DEBUG( "Building KF MET" );
81  float KFMETx = l1_kf->exMiss();
82  float KFMETy = l1_kf->eyMiss();
83  float KFSumEt = l1_kf->energyT();
84 
85  for (const auto jet : *l1Jets) {
86  int etaBin = m_LUT->GetXaxis()->FindBin( fabs( jet->eta() ) );
87  int ptBin = m_LUT->GetYaxis()->FindBin( log2( jet->et8x8() / 1000.) );
88  if (ptBin==0) ptBin=1;
89  float KFweight = m_LUT->GetBinContent(etaBin, ptBin);
90  float jetContribution = jet->et8x8() * KFweight;
91 
92  KFMETx -= jetContribution * cos( jet->phi() );
93  KFMETy -= jetContribution * sin( jet->phi() );
94  KFSumEt += jetContribution;
95  }
96  l1_kf->setEnergyX(-KFMETx);
97  l1_kf->setEnergyY(-KFMETy);
98  l1_kf->setEnergyT(KFSumEt);
99 
100  ATH_MSG_DEBUG( "Built KF MET" );
101  return StatusCode::SUCCESS;
102  }
103 }
DerivationFramework::METTriggerAugmentationTool::m_LUT
std::unique_ptr< TH2 > m_LUT
Definition: METTriggerAugmentationTool.h:29
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
DerivationFramework::METTriggerAugmentationTool::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition: METTriggerAugmentationTool.cxx:51
EnergySumRoIAuxInfo.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
DerivationFramework::METTriggerAugmentationTool::initialize
virtual StatusCode initialize() override final
Definition: METTriggerAugmentationTool.cxx:23
DerivationFramework::METTriggerAugmentationTool::m_L1METName
SG::ReadHandleKey< xAOD::EnergySumRoI > m_L1METName
Definition: METTriggerAugmentationTool.h:25
xAOD::etaBin
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap etaBin
Definition: L2StandAloneMuon_v1.cxx:149
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:727
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
PathResolver.h
DerivationFramework::METTriggerAugmentationTool::METTriggerAugmentationTool
METTriggerAugmentationTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: METTriggerAugmentationTool.cxx:16
METTriggerAugmentationTool.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
Definition: PathResolver.cxx:221
JetRoI.h
DerivationFramework::METTriggerAugmentationTool::m_outputName
SG::WriteHandleKey< xAOD::EnergySumRoI > m_outputName
Definition: METTriggerAugmentationTool.h:27
DerivationFramework::METTriggerAugmentationTool::m_LUTFileName
Gaudi::Property< std::string > m_LUTFileName
Definition: METTriggerAugmentationTool.h:28
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
DerivationFramework::METTriggerAugmentationTool::m_L1JetName
SG::ReadHandleKey< xAOD::JetRoIContainer > m_L1JetName
Definition: METTriggerAugmentationTool.h:26