ATLAS Offline Software
JetEMScaleMomTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <functional>
7 
10 
11 struct p4Decorator {
12 
17 
22  ptHandle(ptKey),
23  etaHandle(etaKey),
24  phiHandle(phiKey),
25  massHandle(massKey)
26  {}
27 
28  void decorateP4(const xAOD::Jet& jet, const xAOD::JetFourMom_t& p4) {
29  ptHandle(jet) = p4.Pt();
30  etaHandle(jet) = p4.Eta();
31  phiHandle(jet) = p4.Phi();
32  massHandle(jet) = p4.M();
33  }
34 
35 };
36 
38 
39  xAOD::JetFourMom_t emscaleSum;
40  // just sum 4-vectors:
41  for (auto iconstit=constits.begin(xAOD::UncalibratedJetConstituent); iconstit!=constits.end(xAOD::UncalibratedJetConstituent); ++iconstit) {
42  emscaleSum += **iconstit;
43  }
44  return emscaleSum;
45 }
46 
47 //**********************************************************************
48 
50 : AsgTool(name) { }
51 
52 //**********************************************************************
53 
55  ATH_MSG_INFO("Initializing JetEMScaleMomTool " << name());
56 
57  if(m_jetContainerName.empty()){
58  ATH_MSG_ERROR("JetEMScaleMomTool needs to have its input jet container configured!");
59  return StatusCode::FAILURE;
60  }
61 
62  std::vector<std::reference_wrapper<SG::WriteDecorHandleKey<xAOD::JetContainer> > > keys = {m_emscalePtKey, m_emscaleEtaKey, m_emscalePhiKey, m_emscaleMassKey};
64  key = m_jetContainerName + "." + key.key();
65  ATH_CHECK( key.initialize() );
66  }
67 
68  ATH_MSG_DEBUG("Operating on jets with " << (m_useUncalibConstits ? "" : "un") << "calibrated constituents." );
69 
70  return StatusCode::SUCCESS;
71 }
72 
73 //**********************************************************************
74 
76  ATH_MSG_VERBOSE("Begin decorating jets.");
78 
79  for(const xAOD::Jet* jet : jets) {
81  // Need to loop and sum the constituents
82  xAOD::JetConstituentVector constits = jet->getConstituents();
83  if(! constits.isValid() ) {
84  ATH_MSG_WARNING("Jet constituent vector is invalid. Can't set EM scale momentum");
85  return StatusCode::FAILURE;
86  }
87  xAOD::JetFourMom_t em_p4 = getEMScaleP4(constits);
88  emscale_decor.decorateP4(*jet,em_p4);
89  } else {
90  // Simply add the constituent-level p4
92  emscale_decor.decorateP4(*jet,constit_p4);
93  }
94 
95  }
96 
97  return StatusCode::SUCCESS;
98 }
99 
100 
101 //**********************************************************************
SG::WriteDecorHandleKey
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Definition: StoreGate/StoreGate/WriteDecorHandleKey.h:89
JetEMScaleMomTool::JetEMScaleMomTool
JetEMScaleMomTool(const std::string &t)
Definition: JetEMScaleMomTool.cxx:49
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::JetConstituentVector::end
iterator end() const
iterator after the last constituent
Definition: JetConstituentVector.cxx:104
JetEMScaleMomTool::m_emscaleEtaKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_emscaleEtaKey
Definition: JetEMScaleMomTool.h:35
xAOD::JetConstituentVector::isValid
bool isValid() const
Check if element links are valid.
Definition: JetConstituentVector.cxx:92
JetEMScaleMomTool::m_useUncalibConstits
Gaudi::Property< bool > m_useUncalibConstits
Definition: JetEMScaleMomTool.h:32
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
JetAccessorMap.h
p4Decorator::massHandle
SG::WriteDecorHandle< xAOD::JetContainer, float > massHandle
Definition: JetEMScaleMomTool.cxx:16
xAOD::JetConstitScaleMomentum
@ JetConstitScaleMomentum
Definition: JetTypes.h:29
xAOD::JetConstituentVector::begin
iterator begin() const
iterator on the first constituent
Definition: JetConstituentVector.cxx:103
JetEMScaleMomTool::m_emscalePtKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_emscalePtKey
Definition: JetEMScaleMomTool.h:34
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
JetEMScaleMomTool::decorate
virtual StatusCode decorate(const xAOD::JetContainer &jets) const override
Decorate a jet collection without otherwise modifying it.
Definition: JetEMScaleMomTool.cxx:75
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
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
JetEMScaleMomTool.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
WriteDecorHandle.h
Handle class for adding a decoration to an object.
p4Decorator::phiHandle
SG::WriteDecorHandle< xAOD::JetContainer, float > phiHandle
Definition: JetEMScaleMomTool.cxx:15
JetEMScaleMomTool::m_emscalePhiKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_emscalePhiKey
Definition: JetEMScaleMomTool.h:36
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
JetEMScaleMomTool::m_jetContainerName
Gaudi::Property< std::string > m_jetContainerName
Definition: JetEMScaleMomTool.h:29
p4Decorator
Definition: JetEMScaleMomTool.cxx:11
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
JetEMScaleMomTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: JetEMScaleMomTool.cxx:54
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
xAOD::UncalibratedJetConstituent
@ UncalibratedJetConstituent
Definition: JetTypes.h:21
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
p4Decorator::ptHandle
SG::WriteDecorHandle< xAOD::JetContainer, float > ptHandle
Definition: JetEMScaleMomTool.cxx:13
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
xAOD::JetConstituentVector
A vector of jet constituents at the scale used during jet finding.
Definition: JetConstituentVector.h:117
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
JetEMScaleMomTool::m_emscaleMassKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_emscaleMassKey
Definition: JetEMScaleMomTool.h:37
p4Decorator::p4Decorator
p4Decorator(const SG::WriteDecorHandleKey< xAOD::JetContainer > &ptKey, const SG::WriteDecorHandleKey< xAOD::JetContainer > &etaKey, const SG::WriteDecorHandleKey< xAOD::JetContainer > &phiKey, const SG::WriteDecorHandleKey< xAOD::JetContainer > &massKey)
Definition: JetEMScaleMomTool.cxx:18
p4Decorator::etaHandle
SG::WriteDecorHandle< xAOD::JetContainer, float > etaHandle
Definition: JetEMScaleMomTool.cxx:14
p4Decorator::decorateP4
void decorateP4(const xAOD::Jet &jet, const xAOD::JetFourMom_t &p4)
Definition: JetEMScaleMomTool.cxx:28
getEMScaleP4
xAOD::JetFourMom_t getEMScaleP4(xAOD::JetConstituentVector &constits)
Definition: JetEMScaleMomTool.cxx:37
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37