ATLAS Offline Software
Loading...
Searching...
No Matches
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
15JetWidthTool::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
40StatusCode JetWidthTool::decorate(const xAOD::JetContainer& jets) const {
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
55float 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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
Handle class for adding a decoration to an object.
This file defines helper classes to deal with jet constituents.
const double width
virtual StatusCode decorate(const xAOD::JetContainer &jets) const override
Decorate a jet collection without otherwise modifying it.
SG::WriteDecorHandleKey< xAOD::JetContainer > m_widthPhiKey
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
float width(const xAOD::Jet &jet, float &widthEta, float &widthPhi) const
JetWidthTool(const std::string &myname)
Gaudi::Property< std::string > m_jetContainerName
SG::WriteDecorHandleKey< xAOD::JetContainer > m_widthKey
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
A vector of jet constituents at the scale used during jet finding.
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi
Jet_v1 Jet
Definition of the current "jet version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".