ATLAS Offline Software
Loading...
Searching...
No Matches
JetForwardJvtTool.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
7// JetForwardJvtTool.cxx
8// Implementation file for class JetForwardJvtTool
9// Author: Matt Klein<matthew.henry.klein@cern.ch>
11
12// JetForwardJvtTool includes
16
17#include <TString.h>
18
19// Jet EDM
20
22 // Public methods:
24
25 // Constructors
27 JetForwardJvtTool::JetForwardJvtTool(const std::string& name) :
28 AsgTool(name) {
29 }
30
31 // Destructor
34 = default;
35
36 // Athena algtool's Hooks
39 {
40 ATH_MSG_DEBUG ("Initializing " << name() << "...");
41 if (m_tightOP) m_fjvtThresh = 0.4;
42 else m_fjvtThresh = 0.5;
43
44 ATH_CHECK(m_vertexContainerName.initialize());
45 ATH_CHECK(m_trkMETName.initialize());
46
47 if(m_jetContainerName.empty()) {
49 m_jetContainerName = "_dummy";
50 }
51 else {
52 ATH_MSG_ERROR("JetForwardJvtTool needs to have its input jet container configured!");
53 return StatusCode::FAILURE;
54 }
55 }
56 if(!m_orKey.key().empty()) m_orKey = m_jetContainerName + "." + m_orKey.key();
57 m_outKey = m_jetContainerName + "." + m_outKey.key();
64
65 ATH_CHECK(m_orKey.initialize(!m_orKey.key().empty()));
66 ATH_CHECK(m_outKey.initialize());
67 ATH_CHECK(m_isHSKey.initialize());
68 ATH_CHECK(m_isPUKey.initialize());
69 ATH_CHECK(m_fjvtDecKey.initialize());
70 ATH_CHECK(m_widthKey.initialize());
71 ATH_CHECK(m_jvtMomentKey.initialize());
72 ATH_CHECK(m_sumPtsKey.initialize());
73
74#ifndef XAOD_STANDALONE
84 }
85#endif
86
87 return StatusCode::SUCCESS;
88 }
89
90 StatusCode JetForwardJvtTool::decorate(const xAOD::JetContainer& jetCont) const {
93
94 std::vector<TVector2> pileupMomenta;
95 const std::size_t pvind = getPV();
96 if (m_recalculateFjvt && !jetCont.empty()) {
97 pileupMomenta = calculateVertexMomenta(&jetCont, pvind);
98 }
99 for(const auto *const jetF : jetCont) {
100 outHandle(*jetF) = 1;
101 if(m_recalculateFjvt) fjvtDecHandle(*jetF) = 0;
102 if (!forwardJet(jetF)) continue;
103 double fjvt = getFJVT(jetF, pileupMomenta, pvind)/jetF->pt();
104 if (fjvt>m_fjvtThresh) outHandle(*jetF) = 0;
105 fjvtDecHandle(*jetF) = fjvt;
106 }
107 return StatusCode::SUCCESS;
108 }
109
110 float JetForwardJvtTool::getFJVT(const xAOD::Jet *jet, const std::vector<TVector2>& pileupMomenta, std::size_t pvind) const {
113 return fjvtDecHandle(*jet);
114 }
115
116 TVector2 fjet(-jet->pt()*cos(jet->phi()),-jet->pt()*sin(jet->phi()));
117 double fjvt = 0;
118 for (size_t pui = 0; pui < pileupMomenta.size(); pui++) {
119 if (pui==pvind) continue;
120 double projection = pileupMomenta[pui]*fjet/fjet.Mod();
121 if (projection>fjvt) fjvt = projection;
122 }
123 //fjvt += getCombinedWidth(jet);
124 return fjvt;
125 }
126
127 std::vector<TVector2> JetForwardJvtTool::calculateVertexMomenta(const xAOD::JetContainer *jets, std::size_t pvind) const {
128
131 if( !trkMetHandle.isValid() ) {
132 ATH_MSG_WARNING("xAOD::MissingETContainer " << m_trkMETName.key() << " is invalid");
133 return {};
134 }
135 if( !vertexContainerHandle.isValid() ) {
136 ATH_MSG_WARNING("xAOD::VertexContainer " << m_vertexContainerName.key() << " is invalid");
137 return {};
138 }
139
140 std::vector<TVector2> pileupMomenta;
141 for(const auto *const vx : *vertexContainerHandle) {
142 if(vx->vertexType()!=xAOD::VxType::PriVtx && vx->vertexType()!=xAOD::VxType::PileUp) continue;
143 TString vname = "PVTrack_vx";
144 vname += vx->index();
145 pileupMomenta.push_back((vx->index()==pvind ? 0 : -(1./m_jetScaleFactor)) *
146 TVector2(0.5*(*trkMetHandle)[vname.Data()]->mpx(),
147 0.5*(*trkMetHandle)[vname.Data()]->mpy()));
148 }
149
150 for (const auto *const jet : *jets) {
151 if (!centralJet(jet)) continue;
152 int jetvert = getJetVertex(jet);
153 if (jetvert>=0) pileupMomenta[jetvert] += TVector2(0.5*jet->pt()*cos(jet->phi()),0.5*jet->pt()*sin(jet->phi()));
154 }
155 return pileupMomenta;
156 }
157
159 float Width = 0;
160 float CWidth = 0;
161 float ptsum = 0;
163 Width = widthHandle(*jet);
164 xAOD::JetConstituentVector constvec = jet->getConstituents();
165 for (xAOD::JetConstituentVector::iterator it = constvec.begin(); it != constvec.end(); ++it) {
166 const xAOD::CaloCluster *cl = static_cast<const xAOD::CaloCluster*>((*it)->rawConstituent());
167 float secondR = cl->getMomentValue(xAOD::CaloCluster::MomentType::SECOND_R);
168 float centermag = cl->getMomentValue(xAOD::CaloCluster::MomentType::CENTER_MAG);
169 CWidth+=fabs(cl->pt()*atan(sqrt(secondR)/centermag)*cosh(cl->eta()));
170 ptsum += cl->pt();
171 }
172 if (ptsum != 0.)[[likely]]{
173 CWidth /= ptsum;
174 }
175 return (CWidth + Width);
176 }
177
179 if (fabs(jet->eta())<m_etaThresh) return false;
180 if (jet->pt()<m_forwardMinPt || jet->pt()>m_forwardMaxPt) return false;
181 return true;
182 }
183
185 if (fabs(jet->eta())>m_etaThresh) return false;
186 if (jet->pt()<m_centerMinPt || (m_centerMaxPt>0 && jet->pt()>m_centerMaxPt)) return false;
187 if(!m_orKey.key().empty()){
189 if(!orHandle(*jet)) return false;
190 }
191 float jvt = 0;
193 jvt = jvtMomentHandle(*jet);
194 if (jvt>m_centerJvtThresh) return false;
195 if (jet->pt()<m_maxStochPt && getDrpt(jet)<m_centerDrptThresh) return false;
196 return true;
197 }
198
200 std::vector<float> sumpts;
202 sumpts = sumPtsHandle(*jet);
203 double firstVal = 0;
204 int bestMatch = -1;
205 for (size_t i = 0; i < sumpts.size(); i++) {
206 if (sumpts[i]>firstVal) {
207 bestMatch = i;
208 firstVal = sumpts[i];
209 }
210 }
211 return bestMatch;
212 }
213
215 std::vector<float> sumpts;
217 sumpts = sumPtsHandle(*jet);
218 if (sumpts.size()<2) return 0;
219
220 std::nth_element(sumpts.begin(),sumpts.begin()+sumpts.size()/2,sumpts.end(),std::greater<int>());
221 double median = sumpts[sumpts.size()/2];
222 std::nth_element(sumpts.begin(),sumpts.begin(),sumpts.end(),std::greater<int>());
223 double max = sumpts[0];
224 return (max-median)/jet->pt();
225 }
226
227 std::size_t JetForwardJvtTool::getPV() const {
228
229 std::size_t pvind = 0;
230 auto vertexContainer = SG::makeHandle (m_vertexContainerName);
231 if (!vertexContainer.isValid()){
232 ATH_MSG_WARNING("Invalid xAOD::VertexContainer datahandle");
233 return pvind;
234 }
235 const auto *vxCont = vertexContainer.cptr();
236
237 if(vxCont->empty()) {
238 ATH_MSG_WARNING("Event has no primary vertices!");
239 } else {
240 ATH_MSG_DEBUG("Successfully retrieved primary vertex container");
241 for(const auto *const vx : *vxCont) {
242 if(vx->vertexType()==xAOD::VxType::PriVtx)
243 {pvind = vx->index(); break;}
244 }
245 }
246 return pvind;
247 }
248
249 StatusCode JetForwardJvtTool::tagTruth(const xAOD::JetContainer *jets,const xAOD::JetContainer *truthJets) {
252 for(const auto *const jet : *jets) {
253 bool ishs = false;
254 bool ispu = true;
255 for(const auto *const tjet : *truthJets) {
256 if (tjet->p4().DeltaR(jet->p4())<0.3 && tjet->pt()>10e3) ishs = true;
257 if (tjet->p4().DeltaR(jet->p4())<0.6) ispu = false;
258 }
259 isHSHandle(*jet)=ishs;
260 isPUHandle(*jet)=ispu;
261 }
262 return StatusCode::SUCCESS;
263 }
264
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
Handle class for adding a decoration to an object.
#define max(a, b)
Definition cfImp.cxx:41
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
bool empty() const noexcept
Returns true if the collection is empty.
Gaudi::Property< bool > m_recalculateFjvt
Gaudi::Property< double > m_maxStochPt
Gaudi::Property< double > m_centerJvtThresh
virtual ~JetForwardJvtTool()
Destructor:
SG::ReadDecorHandleKey< xAOD::JetContainer > m_orKey
SG::ReadDecorHandleKey< xAOD::JetContainer > m_widthKey
SG::ReadDecorHandleKey< xAOD::JetContainer > m_jvtMomentKey
Gaudi::Property< double > m_etaThresh
SG::ReadHandleKey< xAOD::MissingETContainer > m_trkMETName
JetForwardJvtTool()
Default constructor:
float getCombinedWidth(const xAOD::Jet *jet) const
Gaudi::Property< bool > m_renounceOutputs
Gaudi::Property< bool > m_tightOP
StatusCode tagTruth(const xAOD::JetContainer *jets, const xAOD::JetContainer *truthJets)
Gaudi::Property< double > m_fjvtThresh
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Gaudi::Property< double > m_centerMinPt
SG::WriteDecorHandleKey< xAOD::JetContainer > m_isPUKey
bool forwardJet(const xAOD::Jet *jet) const
bool centralJet(const xAOD::Jet *jet) const
Gaudi::Property< double > m_centerDrptThresh
SG::WriteDecorHandleKey< xAOD::JetContainer > m_fjvtDecKey
Gaudi::Property< double > m_forwardMaxPt
std::vector< TVector2 > calculateVertexMomenta(const xAOD::JetContainer *jets, std::size_t pvind) const
SG::WriteDecorHandleKey< xAOD::JetContainer > m_outKey
SG::ReadDecorHandleKey< xAOD::JetContainer > m_sumPtsKey
virtual StatusCode decorate(const xAOD::JetContainer &jetCont) const override
Decorate a jet collection without otherwise modifying it.
int getJetVertex(const xAOD::Jet *jet) const
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerName
Gaudi::Property< double > m_jetScaleFactor
Gaudi::Property< double > m_forwardMinPt
float getDrpt(const xAOD::Jet *jet) const
float getFJVT(const xAOD::Jet *jet, const std::vector< TVector2 > &pileupMomenta, std::size_t pvind) const
Gaudi::Property< std::string > m_jetContainerName
std::size_t getPV() const
Gaudi::Property< double > m_centerMaxPt
SG::WriteDecorHandleKey< xAOD::JetContainer > m_isHSKey
Handle class for reading a decoration on an object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
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
@ SECOND_R
Second Moment in .
@ CENTER_MAG
Cluster Centroid ( ).
A vector of jet constituents at the scale used during jet finding.
iterator begin() const
iterator on the first constituent
iterator end() const
iterator after the last constituent
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
@ PileUp
Pile-up vertex.
@ PriVtx
Primary vertex.
Jet_v1 Jet
Definition of the current "jet version".
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
#define likely(x)