ATLAS Offline Software
JetWidthTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // JetWidthTool.cxx
6 
12 
13 //**********************************************************************
14 
15 JetWidthTool::JetWidthTool(const std::string& myname)
16  : asg::AsgTool(myname)
17 {
18 }
19 
20 //**********************************************************************
21 
23 
24  if(m_jetContainerName.empty()){
25  ATH_MSG_ERROR("JetWidthTool needs to have its input jet container name configured!");
26  return StatusCode::FAILURE;
27  }
28 
29  // Prepend jet container name
32 
33  ATH_CHECK(m_widthKey.initialize());
34  ATH_CHECK(m_widthPhiKey.initialize());
35  return StatusCode::SUCCESS;
36 }
37 
38 //**********************************************************************
39 
41 
44 
45  for(const xAOD::Jet* jet : jets){
46  float widthEta = 0, widthPhi = 0;
47  widthHandle(*jet) = width(*jet,widthEta,widthPhi);
48  widthPhiHandle(*jet) = widthPhi;
49  }
50  return StatusCode::SUCCESS;
51 }
52 
53 //**********************************************************************
54 
55 float JetWidthTool::width(const xAOD::Jet& jet, float& widthEta, float& widthPhi) const {
56 
57  // Calculate the pt weighted width
58  const float jetEta = jet.eta();
59  const float jetPhi = jet.phi();
60  float weightedWidth = 0;
61  float weightedWidthEta = 0;
62  float weightedWidthPhi = 0;
63  float ptSum = 0;
64 
65  const xAOD::JetConstituentVector constituents = jet.getConstituents();
66  for (const auto *const constituent : constituents) {
67  const float dR = xAOD::P4Helpers::deltaR(jetEta, jetPhi, constituent->eta(), constituent->phi());
68  const float dEta = std::abs(jet.eta()-constituent->eta());
69  const float dPhi = std::abs(xAOD::P4Helpers::deltaPhi(jetPhi, constituent->phi()));
70  const float pt = constituent->pt();
71 
72  weightedWidth += dR * pt;
73  weightedWidthEta += dEta * pt;
74  weightedWidthPhi += dPhi * pt;
75 
76  ptSum += pt;
77  }
78 
79  widthEta = ptSum > 0 ? weightedWidthEta/ptSum : -1;
80  widthPhi = ptSum > 0 ? weightedWidthPhi/ptSum : -1;
81 
82  return ptSum > 0 ? weightedWidth/ptSum : -1;
83 }
JetWidthTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: JetWidthTool.cxx:22
JetWidthTool::m_widthPhiKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_widthPhiKey
Definition: JetWidthTool.h:48
xAODP4Helpers.h
JetWidthTool::m_widthKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_widthKey
Definition: JetWidthTool.h:46
asg
Definition: DataHandleTestTool.h:28
test_pyathena.pt
pt
Definition: test_pyathena.py:11
xAOD::P4Helpers::deltaPhi
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition: xAODP4Helpers.h:69
JetWidthTool::JetWidthTool
JetWidthTool(const std::string &myname)
Definition: JetWidthTool.cxx:15
IWeightPFOTool.h
JetConstituentVector.h
This file defines helper classes to deal with jet constituents.
JetWidthTool::m_jetContainerName
Gaudi::Property< std::string > m_jetContainerName
Definition: JetWidthTool.h:43
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::P4Helpers::deltaR
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi
Definition: xAODP4Helpers.h:150
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TauGNNUtils::Variables::Track::dPhi
bool dPhi(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:538
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
WriteDecorHandle.h
Handle class for adding a decoration to an object.
JetWidthTool::width
float width(const xAOD::Jet &jet, float &widthEta, float &widthPhi) const
Definition: JetWidthTool.cxx:55
JetWidthTool.h
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
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
JetWidthTool::decorate
virtual StatusCode decorate(const xAOD::JetContainer &jets) const override
Decorate a jet collection without otherwise modifying it.
Definition: JetWidthTool.cxx:40
TauGNNUtils::Variables::Track::dEta
bool dEta(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:527