ATLAS Offline Software
JetManagerTool.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 #include "src/JetManagerTool.h"
6 
7 namespace Trig {
8 
9 //**********************************************************************
10 
12  const std::string& name,
13  const IInterface* parent)
15 {}
16 
18  ATH_MSG_DEBUG( "Initializing " << name() );
19 
20  m_jetInputKey = m_jetcontainer.value();
21  m_bjetInputKey = m_jetcontainer.value() + "_bJets";
22 
23  ATH_CHECK(m_jetInputKey.initialize());
24  ATH_CHECK(m_bjetInputKey.initialize());
25 
26  return StatusCode::SUCCESS;
27 }
28 
30  EmulContext& emulCtx) const
31 {
32  ATH_MSG_DEBUG( "Retrieving via Container ..." );
33 
34  auto outputJets = std::make_unique<std::vector<TrigBtagEmulationJet>>();
35  auto sortedPreselJets = std::make_unique<std::vector<TrigBtagEmulationJet>>();
36 
37  // Get Jet Objects
38  // We are retrieving xAOD::Jet object
39  // This will first retrieve the jets in the event given the jet input key <jet-key>
40  // then it retrieves the corresponding b-jet collection <jet-key>_bJets
41  // replacing the non-b-jets with the b-jets
42 
43  // Retrieve jets
44  ATH_MSG_DEBUG("Retrieving jet collection: " << m_jetInputKey.key());
46  ATH_CHECK(jetContainerHandle.isValid());
47  const xAOD::JetContainer* theJetContainer = jetContainerHandle.cptr();
48  // Put in storage
49  outputJets->reserve(theJetContainer->size());
50  sortedPreselJets->reserve(theJetContainer->size());
51  for ( const xAOD::Jet *jet : *theJetContainer ) {
53  outputJets->push_back( toAdd );
54  }
55 
56  // Retrieve b-Jets
57  ATH_MSG_DEBUG("Retrieving b-jet collection: " << m_bjetInputKey.key());
59  // if not valid, it means there is no corresponding b-jet collection
60  // this happens for instance for presel jets
61  // so this is ok
62  if ( bjetContainerHandle.isValid() ) {
63  ATH_CHECK( bjetContainerHandle.isValid() );
64  const xAOD::JetContainer* theBJetContainer = bjetContainerHandle.cptr();
65 
66  // Replace jets with b-jets
67  // - loop on bjets
68  for ( const xAOD::Jet *bjet : *theBJetContainer ) {
69  // - loop on stored jets
70  for (std::size_t ijet(0); ijet < outputJets->size(); ijet++) {
71  const auto& emuljet = outputJets->at(ijet);
72  const xAOD::Jet* jet = emuljet.jet();
73 
74  // To-Do: find better way
75  if ( bjet->pt() == jet->pt() &&
76  bjet->eta() == jet->eta() &&
77  bjet->phi() == jet->phi() ) {
78  outputJets->at(ijet) = TrigBtagEmulationJet(*bjet, m_btagging_link.value());
79  break;
80  }
81  }
82  }
83  } // is valid
84 
85  // Prepare presel jets
86  for ( const auto& jet : *outputJets.get() ) {
87  const xAOD::Jet *theJet = jet.jet();
88  sortedPreselJets->push_back( TrigBtagEmulationJet(*theJet) );
89  }
90 
91 
92  // Sort presel jets
93  sort(sortedPreselJets->begin(), sortedPreselJets->end(),
94  [] (const auto& lhs, const auto& rhs) -> bool
95  { return lhs.pt() > rhs.pt(); }
96  );
97 
98  ATH_MSG_DEBUG( " - Ten largest jets:");
99  for(unsigned int i = 0; i < 10 and i < sortedPreselJets->size(); i++) {
100  ATH_MSG_DEBUG( " - pt=" << (sortedPreselJets->at(i).pt() / Gaudi::Units::GeV) << " eta=" << sortedPreselJets->at(i).eta() );
101  }
102 
103  // Store objects
104  const std::string storage_name = m_jetInputKey.key();
105  emulCtx.store( storage_name, std::move(outputJets) );
106  emulCtx.store( storage_name + "_presel", std::move(sortedPreselJets) );
107 
108  return StatusCode::SUCCESS;
109 }
110 
111 const std::vector<TrigBtagEmulationJet>& JetManagerTool::getJets(const EmulContext& emulCtx) const
112 {
113  return *emulCtx.get<std::vector<TrigBtagEmulationJet>>(m_jetcontainer.value());
114 }
115 const std::vector<TrigBtagEmulationJet>& JetManagerTool::getSortedPreselJets(const EmulContext& emulCtx) const
116 {
117  return *emulCtx.get<std::vector<TrigBtagEmulationJet>>(m_jetcontainer.value() + "_presel");
118 }
119 
120 }
121 
122 //**********************************************************************
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
Trig::JetManagerTool::m_btagging_link
Gaudi::Property< std::string > m_btagging_link
Definition: JetManagerTool.h:53
python.BuildSignatureFlags.bjet
AthConfigFlags bjet(AthConfigFlags flags, str instanceName, str recoMode)
Definition: BuildSignatureFlags.py:338
Trig::JetManagerTool::JetManagerTool
JetManagerTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: JetManagerTool.cxx:11
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
Trig
The common trigger namespace for trigger analysis tools.
Definition: LArCellMonAlg.h:33
Trig::TrigBtagEmulationJet
Definition: TrigBtagEmulationJet.h:17
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
Trig::JetManagerTool::m_bjetInputKey
SG::ReadHandleKey< xAOD::JetContainer > m_bjetInputKey
Definition: JetManagerTool.h:51
Trig::JetManagerTool::retrieveByContainer
StatusCode retrieveByContainer(const EventContext &ctx, EmulContext &emulCtx) const
Definition: JetManagerTool.cxx:29
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
Trig::EmulContext::get
const T * get(const std::string &name) const
Definition: EmulContext.h:94
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trig::EmulContext
Definition: EmulContext.h:16
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
DeMoUpdate.toAdd
bool toAdd
Definition: DeMoUpdate.py:1304
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
Trig::EmulContext::store
void store(const std::string &name, std::unique_ptr< T > &&object)
Definition: EmulContext.h:77
JetManagerTool.h
Trig::JetManagerTool::initialize
virtual StatusCode initialize() override
Definition: JetManagerTool.cxx:17
Trig::JetManagerTool::m_jetInputKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetInputKey
Definition: JetManagerTool.h:50
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Trig::JetManagerTool::getJets
const std::vector< TrigBtagEmulationJet > & getJets(const EmulContext &emulCtx) const
Definition: JetManagerTool.cxx:111
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
AthAlgTool
Definition: AthAlgTool.h:26
Trig::JetManagerTool::m_jetcontainer
Gaudi::Property< std::string > m_jetcontainer
Definition: JetManagerTool.h:54
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
Trig::JetManagerTool::getSortedPreselJets
const std::vector< TrigBtagEmulationJet > & getSortedPreselJets(const EmulContext &emulCtx) const
Definition: JetManagerTool.cxx:115