ATLAS Offline Software
JetWidthTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // JetWidthTool.cxx
6 
10 #include "JetUtils/JetDistances.h"
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  // Get the constituents of the jet
58  // TODO: Switch to using helper function once JetUtils has been updated
59  // Set the width
60  // jetWidth = JetKinematics::ptWeightedWidth(iter,iEnd,&jet);
61 
62  // Calculate the pt weighted width
63  const float jetEta = jet.eta();
64  const float jetPhi = jet.phi();
65  float weightedWidth = 0;
66  float weightedWidthEta = 0;
67  float weightedWidthPhi = 0;
68  float ptSum = 0;
69 
70  const xAOD::JetConstituentVector constituents = jet.getConstituents();
71  for (const auto *const constituent : constituents) {
72  const float dR = jet::JetDistances::deltaR(jetEta, jetPhi, constituent->eta(), constituent->phi() );
73  const float dEta = fabs(jet::JetDistances::deltaEta(jetEta, constituent->eta() ));
74  const float dPhi = fabs(jet::JetDistances::deltaPhi(jetPhi, constituent->phi() ));
75  const float pt = constituent->pt();
76 
77  weightedWidth += dR * pt;
78  weightedWidthEta += dEta * pt;
79  weightedWidthPhi += dPhi * pt;
80 
81  ptSum += pt;
82  }
83 
84  widthEta = ptSum > 0 ? weightedWidthEta/ptSum : -1;
85  widthPhi = ptSum > 0 ? weightedWidthPhi/ptSum : -1;
86 
87  return ptSum > 0 ? weightedWidth/ptSum : -1;
88 }
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
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
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
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:530
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
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:525
JetDistances.h