ATLAS Offline Software
JetForwardJvtTool.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2023 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
28  AsgTool(name) {
29  }
30 
31  // Destructor
34  = default;
35 
36  // Athena algtool's Hooks
39  {
40  ATH_MSG_INFO ("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()) {
48  if (m_renounceOutputs) {
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();
58  m_isHSKey = m_jetContainerName + "." + m_isHSKey.key();
59  m_isPUKey = m_jetContainerName + "." + m_isPUKey.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
75  if (m_renounceOutputs) {
76  renounce (m_orKey);
84  }
85 #endif
86 
87  return StatusCode::SUCCESS;
88  }
89 
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 {
111  if(!m_recalculateFjvt){
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  CWidth /= ptsum;
173  return (CWidth + Width);
174  }
175 
177  if (fabs(jet->eta())<m_etaThresh) return false;
178  if (jet->pt()<m_forwardMinPt || jet->pt()>m_forwardMaxPt) return false;
179  return true;
180  }
181 
183  if (fabs(jet->eta())>m_etaThresh) return false;
184  if (jet->pt()<m_centerMinPt || (m_centerMaxPt>0 && jet->pt()>m_centerMaxPt)) return false;
185  if(!m_orKey.key().empty()){
187  if(!orHandle(*jet)) return false;
188  }
189  float jvt = 0;
191  jvt = jvtMomentHandle(*jet);
192  if (jvt>m_centerJvtThresh) return false;
193  if (jet->pt()<m_maxStochPt && getDrpt(jet)<m_centerDrptThresh) return false;
194  return true;
195  }
196 
198  std::vector<float> sumpts;
200  sumpts = sumPtsHandle(*jet);
201  double firstVal = 0;
202  int bestMatch = -1;
203  for (size_t i = 0; i < sumpts.size(); i++) {
204  if (sumpts[i]>firstVal) {
205  bestMatch = i;
206  firstVal = sumpts[i];
207  }
208  }
209  return bestMatch;
210  }
211 
213  std::vector<float> sumpts;
215  sumpts = sumPtsHandle(*jet);
216  if (sumpts.size()<2) return 0;
217 
218  std::nth_element(sumpts.begin(),sumpts.begin()+sumpts.size()/2,sumpts.end(),std::greater<int>());
219  double median = sumpts[sumpts.size()/2];
220  std::nth_element(sumpts.begin(),sumpts.begin(),sumpts.end(),std::greater<int>());
221  double max = sumpts[0];
222  return (max-median)/jet->pt();
223  }
224 
225  std::size_t JetForwardJvtTool::getPV() const {
226 
227  std::size_t pvind = 0;
228  auto vertexContainer = SG::makeHandle (m_vertexContainerName);
229  if (!vertexContainer.isValid()){
230  ATH_MSG_WARNING("Invalid xAOD::VertexContainer datahandle");
231  return pvind;
232  }
233  const auto *vxCont = vertexContainer.cptr();
234 
235  if(vxCont->empty()) {
236  ATH_MSG_WARNING("Event has no primary vertices!");
237  } else {
238  ATH_MSG_DEBUG("Successfully retrieved primary vertex container");
239  for(const auto *const vx : *vxCont) {
240  if(vx->vertexType()==xAOD::VxType::PriVtx)
241  {pvind = vx->index(); break;}
242  }
243  }
244  return pvind;
245  }
246 
250  for(const auto *const jet : *jets) {
251  bool ishs = false;
252  bool ispu = true;
253  for(const auto *const tjet : *truthJets) {
254  if (tjet->p4().DeltaR(jet->p4())<0.3 && tjet->pt()>10e3) ishs = true;
255  if (tjet->p4().DeltaR(jet->p4())<0.6) ispu = false;
256  }
257  isHSHandle(*jet)=ishs;
258  isPUHandle(*jet)=ispu;
259  }
260  return StatusCode::SUCCESS;
261  }
262 
JetForwardJvtTool::m_etaThresh
Gaudi::Property< double > m_etaThresh
Definition: JetForwardJvtTool.h:73
JetForwardJvtTool::tagTruth
StatusCode tagTruth(const xAOD::JetContainer *jets, const xAOD::JetContainer *truthJets)
Definition: JetForwardJvtTool.cxx:247
JetForwardJvtTool::JetForwardJvtTool
JetForwardJvtTool()
Default constructor:
JetForwardJvtTool::m_centerMinPt
Gaudi::Property< double > m_centerMinPt
Definition: JetForwardJvtTool.h:76
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
JetForwardJvtTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: JetForwardJvtTool.cxx:38
JetForwardJvtTool::getPV
std::size_t getPV() const
Definition: JetForwardJvtTool.cxx:225
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
JetForwardJvtTool::centralJet
bool centralJet(const xAOD::Jet *jet) const
Definition: JetForwardJvtTool.cxx:182
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
xAOD::JetConstituentVector::end
iterator end() const
iterator after the last constituent
Definition: JetConstituentVector.cxx:104
JetForwardJvtTool::m_forwardMaxPt
Gaudi::Property< double > m_forwardMaxPt
Definition: JetForwardJvtTool.h:75
AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce
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)
Definition: AthCommonDataStore.h:380
skel.it
it
Definition: skel.GENtoEVGEN.py:396
JetForwardJvtTool::m_tightOP
Gaudi::Property< bool > m_tightOP
Definition: JetForwardJvtTool.h:83
JetForwardJvtTool::getCombinedWidth
float getCombinedWidth(const xAOD::Jet *jet) const
Definition: JetForwardJvtTool.cxx:158
JetForwardJvtTool::calculateVertexMomenta
std::vector< TVector2 > calculateVertexMomenta(const xAOD::JetContainer *jets, std::size_t pvind) const
Definition: JetForwardJvtTool.cxx:127
InDet::median
float median(std::vector< float > &Vec)
Definition: BTagVrtSec.cxx:35
JetForwardJvtTool::getDrpt
float getDrpt(const xAOD::Jet *jet) const
Definition: JetForwardJvtTool.cxx:212
JetForwardJvtTool::m_outKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_outKey
Definition: JetForwardJvtTool.h:93
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
JetForwardJvtTool::m_centerJvtThresh
Gaudi::Property< double > m_centerJvtThresh
Definition: JetForwardJvtTool.h:78
JetForwardJvtTool::getFJVT
float getFJVT(const xAOD::Jet *jet, const std::vector< TVector2 > &pileupMomenta, std::size_t pvind) const
Definition: JetForwardJvtTool.cxx:110
JetForwardJvtTool.h
JetForwardJvtTool::m_centerDrptThresh
Gaudi::Property< double > m_centerDrptThresh
Definition: JetForwardJvtTool.h:79
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
JetForwardJvtTool::m_maxStochPt
Gaudi::Property< double > m_maxStochPt
Definition: JetForwardJvtTool.h:80
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
xAOD::JetConstituentVector::begin
iterator begin() const
iterator on the first constituent
Definition: JetConstituentVector.cxx:103
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
lumiFormat.i
int i
Definition: lumiFormat.py:85
JetForwardJvtTool::m_sumPtsKey
SG::ReadDecorHandleKey< xAOD::JetContainer > m_sumPtsKey
Definition: JetForwardJvtTool.h:103
JetForwardJvtTool::m_trkMETName
SG::ReadHandleKey< xAOD::MissingETContainer > m_trkMETName
Definition: JetForwardJvtTool.h:99
JetForwardJvtTool::m_jetContainerName
Gaudi::Property< std::string > m_jetContainerName
Definition: JetForwardJvtTool.h:91
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:100
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
JetForwardJvtTool::m_jetScaleFactor
Gaudi::Property< double > m_jetScaleFactor
Definition: JetForwardJvtTool.h:81
JetForwardJvtTool::m_forwardMinPt
Gaudi::Property< double > m_forwardMinPt
Definition: JetForwardJvtTool.h:74
JetForwardJvtTool::m_centerMaxPt
Gaudi::Property< double > m_centerMaxPt
Definition: JetForwardJvtTool.h:77
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.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::VxType::PileUp
@ PileUp
Pile-up vertex.
Definition: TrackingPrimitives.h:573
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
JetForwardJvtTool::decorate
virtual StatusCode decorate(const xAOD::JetContainer &jetCont) const override
Decorate a jet collection without otherwise modifying it.
Definition: JetForwardJvtTool.cxx:90
TauGNNUtils::Variables::Cluster::SECOND_R
bool SECOND_R(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
Definition: TauGNNUtils.cxx:830
TauGNNUtils::Variables::Cluster::CENTER_MAG
bool CENTER_MAG(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
Definition: TauGNNUtils.cxx:916
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
JetForwardJvtTool::getJetVertex
int getJetVertex(const xAOD::Jet *jet) const
Definition: JetForwardJvtTool.cxx:197
JetForwardJvtTool::m_fjvtDecKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_fjvtDecKey
Definition: JetForwardJvtTool.h:96
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
JetForwardJvtTool::m_jvtMomentKey
SG::ReadDecorHandleKey< xAOD::JetContainer > m_jvtMomentKey
Definition: JetForwardJvtTool.h:102
ReadDecorHandle.h
Handle class for reading a decoration on an object.
JetForwardJvtTool::forwardJet
bool forwardJet(const xAOD::Jet *jet) const
Definition: JetForwardJvtTool.cxx:176
JetForwardJvtTool::m_fjvtThresh
Gaudi::Property< double > m_fjvtThresh
Definition: JetForwardJvtTool.h:82
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
xAOD::JetConstituentVector::iterator
Definition: JetConstituentVector.h:121
JetForwardJvtTool::m_isPUKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_isPUKey
Definition: JetForwardJvtTool.h:95
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
JetForwardJvtTool::m_renounceOutputs
Gaudi::Property< bool > m_renounceOutputs
Definition: JetForwardJvtTool.h:90
JetForwardJvtTool::m_orKey
SG::ReadDecorHandleKey< xAOD::JetContainer > m_orKey
Definition: JetForwardJvtTool.h:92
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
JetForwardJvtTool::m_recalculateFjvt
Gaudi::Property< bool > m_recalculateFjvt
Definition: JetForwardJvtTool.h:84
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
JetForwardJvtTool::m_widthKey
SG::ReadDecorHandleKey< xAOD::JetContainer > m_widthKey
Definition: JetForwardJvtTool.h:101
JetForwardJvtTool::m_isHSKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_isHSKey
Definition: JetForwardJvtTool.h:94
JetForwardJvtTool::m_vertexContainerName
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerName
Definition: JetForwardJvtTool.h:98
JetForwardJvtTool::~JetForwardJvtTool
virtual ~JetForwardJvtTool()
Destructor: