ATLAS Offline Software
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());
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 
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
63  auto handle = SG::makeHandle (m_vertexContainer_key);
64  if (!handle.isValid()){
65  ATH_MSG_WARNING("Invalid VertexContainer datahandle: "
67  << ": filling jet with -1");
68  xAOD::JetFourMom_t null;
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 "
94  << m_correctionName);
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"
102  <<m_correctionName);
103  xAOD::JetFourMom_t null;
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 //**********************************************************************
JetOriginCorrectionTool::m_jetContainerName
Gaudi::Property< std::string > m_jetContainerName
Definition: JetOriginCorrectionTool.h:52
JetOriginCorrectionTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: JetOriginCorrectionTool.cxx:25
xAOD::CaloCluster_v1::State
State
enum of possible signal states.
Definition: CaloCluster_v1.h:304
JetOriginCorrectionTool::m_correctionName
Gaudi::Property< std::string > m_correctionName
Definition: JetOriginCorrectionTool.h:51
asg
Definition: DataHandleTestTool.h:28
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
JetOriginCorrectionTool::m_scaleMomentumEtaKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_scaleMomentumEtaKey
Definition: JetOriginCorrectionTool.h:64
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
jet::clusterOriginCorrection
xAOD::JetFourMom_t clusterOriginCorrection(const xAOD::Jet &jet, const xAOD::Vertex &vx)
returns 4-vector of the jet relative to the vertex
JetOriginCorrectionTool::JetOriginCorrectionTool
JetOriginCorrectionTool(const std::string &myname)
Constructor from tool name.
Definition: JetOriginCorrectionTool.cxx:17
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
JetOriginCorrectionTool::m_originVertexKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_originVertexKey
Definition: JetOriginCorrectionTool.h:66
JetOriginCorrectionTool::m_eventInfo_key
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo_key
Definition: JetOriginCorrectionTool.h:59
JetOriginCorrectionTool::m_scaleMomentumName
Gaudi::Property< std::string > m_scaleMomentumName
Definition: JetOriginCorrectionTool.h:61
JetOriginCorrectionTool::m_scaleMomentumPhiKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_scaleMomentumPhiKey
Definition: JetOriginCorrectionTool.h:63
JetOriginCorrectionTool::m_vertexContainer_key
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainer_key
Definition: JetOriginCorrectionTool.h:58
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
JetOriginHelpers.h
Helpers to calculate corrected 4-vectors w.r.t to a given orign.
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
JetOriginCorrectionTool::m_onlyAssignPV
Gaudi::Property< bool > m_onlyAssignPV
Definition: JetOriginCorrectionTool.h:53
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
WriteDecorHandle.h
Handle class for adding a decoration to an object.
xAOD::CaloCluster_v1::UNCALIBRATED
@ UNCALIBRATED
Definition: CaloCluster_v1.h:306
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
JetOriginCorrectionTool::decorate
StatusCode decorate(const xAOD::JetContainer &jet) const override
Inherited method to modify a jet container.
Definition: JetOriginCorrectionTool.cxx:50
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
JetOriginCorrectionTool::m_scaleMomentumPtKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_scaleMomentumPtKey
Definition: JetOriginCorrectionTool.h:62
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
JetOriginCorrectionTool::m_scaleMomentumMKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_scaleMomentumMKey
Definition: JetOriginCorrectionTool.h:65
JetOriginCorrectionTool::m_forceEMScale
Gaudi::Property< bool > m_forceEMScale
Definition: JetOriginCorrectionTool.h:54
xAOD::CaloCluster_v1::UNKNOWN
@ UNKNOWN
Definition: CaloCluster_v1.h:305
JetOriginCorrectionTool.h