ATLAS Offline Software
Loading...
Searching...
No Matches
JetOriginCorrectionTool.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// JetOriginCorrectionTool.cxx
6
8
11
12
13
14
15//**********************************************************************
16
18: asg::AsgTool(myname) {
19
20}
21
22
23//**********************************************************************
24
26 ATH_CHECK(m_vertexContainer_key.initialize());
27 ATH_CHECK(m_eventInfo_key.initialize());
28 if(m_jetContainerName.empty()) {
29 ATH_MSG_ERROR("JetOriginCorrectionTool needs to have its input jet container configured!");
30 return StatusCode::FAILURE;
31 }
32
38
39 ATH_CHECK(m_scaleMomentumPtKey.initialize());
40 ATH_CHECK(m_scaleMomentumPhiKey.initialize());
41 ATH_CHECK(m_scaleMomentumEtaKey.initialize());
42 ATH_CHECK(m_scaleMomentumMKey.initialize());
43 ATH_CHECK(m_originVertexKey.initialize());
44
45 return StatusCode::SUCCESS;
46}
47
48//**********************************************************************
49
50StatusCode JetOriginCorrectionTool::decorate(const xAOD::JetContainer& jetCont) const {
56
57 // static accessor for PV index access
58 static const SG::AuxElement::ConstAccessor<int> PVIndexAccessor("PVIndex");
59
60
61
62 // retrieve the VertexContainer. if fails, fill the jets with null vector
64 if (!handle.isValid()){
65 ATH_MSG_WARNING("Invalid VertexContainer datahandle: "
67 << ": filling jet with -1");
69 for(const xAOD::Jet * j : jetCont) {
70 scaleMomentumPtHandle(*j) = -1;
71 scaleMomentumPhiHandle(*j) = -1;
72 scaleMomentumEtaHandle(*j) = -1;
73 scaleMomentumMHandle(*j) = -1;
74 }
75 return StatusCode::SUCCESS;
76 }
77
78 const auto *vxContainer = handle.cptr();
79
80
81 // Retrieve EventInfo to check for a PV# specification != PV0
82 // No errors if EventInfo or PV index is not specified,
83 // as this is the standard scenario
84 // Warn if EventInfo is specified but cannot be retrieved
85 // Specifying the PV index is only for special cases
86 int PVindex = 0;
87 //if (m_eventInfoName.key() != "") {
88 if (!m_eventInfo_key.key().empty()) {
89 // retrieve the VertexContainer. if fails, fill the jets with null vector
90
91 auto eInfo = SG::makeHandle (m_eventInfo_key);
92 if (!eInfo.isValid()){
93 ATH_MSG_WARNING("Invalid eventInfo datahandle. Defaulting to PV0 for "
95 } else if (PVIndexAccessor.isAvailable(*(eInfo.cptr()))) {
96 PVindex = PVIndexAccessor(*(eInfo.cptr()));
97 ATH_MSG_DEBUG("Found PVIndex value of " << PVindex << " for " << m_correctionName);
98
99 if (PVindex < 0 || static_cast<size_t>(PVindex) >= vxContainer->size()){
100 ATH_MSG_WARNING("Specified PV index of "
101 << PVindex << " is out of bounds. Filling jet with -1"
104 for (const xAOD::Jet* j : jetCont) {
105 scaleMomentumPtHandle(*j) = -1;
106 scaleMomentumPhiHandle(*j) = -1;
107 scaleMomentumEtaHandle(*j) = -1;
108 scaleMomentumMHandle(*j) = -1;
109 }
110 return StatusCode::SUCCESS;
111 }
112
113 }
114 }
115
116 // choose PV.
117 const xAOD::Vertex *vx = vxContainer->at(PVindex);
118
119 ATH_MSG_DEBUG(" correcting jets ");
120 for(const xAOD::Jet * jet : jetCont){
121 ATH_MSG_DEBUG(" ----> jet "<< jet);
122 ATH_MSG_DEBUG(" jet pT: "<< jet->pt());
123
124 if(!m_onlyAssignPV) {
128 ATH_MSG_DEBUG(" " << m_correctionName << " pT: " << fv.pt());
129 scaleMomentumPtHandle(*jet) = fv.pt();
130 scaleMomentumPhiHandle(*jet) = fv.phi();
131 scaleMomentumEtaHandle(*jet) = fv.eta();
132 scaleMomentumMHandle(*jet) = fv.M();
133 }
134 originVertexHandle(*jet) = ElementLink<xAOD::VertexContainer>(*vxContainer, vxContainer->at(PVindex)->index());
135
136 }
137 return StatusCode::SUCCESS;
138}
139
140//**********************************************************************
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for adding a decoration to an object.
Helpers to calculate corrected 4-vectors w.r.t to a given orign.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo_key
SG::WriteDecorHandleKey< xAOD::JetContainer > m_scaleMomentumPhiKey
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
StatusCode decorate(const xAOD::JetContainer &jet) const override
Inherited method to modify a jet container.
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainer_key
Gaudi::Property< std::string > m_scaleMomentumName
SG::WriteDecorHandleKey< xAOD::JetContainer > m_scaleMomentumPtKey
JetOriginCorrectionTool(const std::string &myname)
Constructor from tool name.
SG::WriteDecorHandleKey< xAOD::JetContainer > m_scaleMomentumMKey
Gaudi::Property< std::string > m_correctionName
Gaudi::Property< bool > m_onlyAssignPV
SG::WriteDecorHandleKey< xAOD::JetContainer > m_originVertexKey
Gaudi::Property< bool > m_forceEMScale
Gaudi::Property< std::string > m_jetContainerName
SG::WriteDecorHandleKey< xAOD::JetContainer > m_scaleMomentumEtaKey
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
Handle class for adding a decoration to an object.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
State
enum of possible signal states.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
xAOD::JetFourMom_t clusterOriginCorrection(const xAOD::Jet &jet, const xAOD::Vertex &vx)
returns 4-vector of the jet relative to the vertex
Jet_v1 Jet
Definition of the current "jet version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition JetTypes.h:17