ATLAS Offline Software
JetBalancePFlowJvtTool.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // JetBalancePFlowJvtTool.cxx
8 // Implementation file for class JetBalancePFlowJvtTool
9 // Author: Eimear Conroy <eimear.isobel.conroy@cern.ch>
10 // Inherits from JetForwardPFlowJvtTool - Author: Anastasia Kotsokechagia <anastasia.kotsokechagia@cern.ch>
12 
13 // JetBalancePFlowJvtTool includes
15 
16 // Jet EDM
17 #include "xAODJet/JetAttributes.h"
18 
19 // FastJet
20 #include "fastjet/ClusterSequence.hh"
21 #include "fastjet/ClusterSequenceArea.hh"
22 #include <fastjet/AreaDefinition.hh>
23 
24 // Jet
26 
28  // Public methods:
30 
31  // Constructors
35  m_bjvtThresh = 0;
36  }
37 
38  // Destructor
41  = default;
42 
43  // Athena algtool's Hooks
46  {
47  ATH_MSG_INFO ("Initializing " << name() << "...");
48  //WPs have not been calculated yet. Using holdover fJVT values here for now
49  if (m_tightOP) m_fjvtThresh = 0.53; //Closer to 1 ==> more likely to be PU
50  else m_fjvtThresh = 0.72;
51 
53 
54  if(m_jetContainerName.empty()){
55  ATH_MSG_ERROR("JetBalancePFlowJvtTool needs to have its input jet container configured!");
56  return StatusCode::FAILURE;
57  }
58 
59  if(!m_FEKey.empty()){
60  if(!m_orFEKey.key().empty()){
61  m_orFEKey = m_jetContainerName + "." + m_orFEKey.key();
62  }
63  }
64  else{
65  ATH_MSG_ERROR("Flow Element container is empty");
66  }
67 
68  ATH_CHECK(m_FEKey.initialize( !m_FEKey.empty() ));
69  ATH_CHECK(m_orFEKey.initialize( !m_FEKey.empty() && !m_orFEKey.key().empty() ));
70 
71  m_bjvtKey = m_jetContainerName + "." + m_bjvtKey.key();
73  m_isHSKey = m_jetContainerName + "." + m_isHSKey.key();
77 
78  ATH_CHECK(m_bjvtKey.initialize());
79  ATH_CHECK(m_bjvtRawKey.initialize());
80  ATH_CHECK(m_isHSKey.initialize());
81  ATH_CHECK(m_isQCDPUKey.initialize());
82  ATH_CHECK(m_isStochPUKey.initialize());
83  ATH_CHECK(m_passJvtKey.initialize());
84 
85  ATH_CHECK(m_vxContKey.initialize());
86 
87  //These keys do nothing in this tool, but need to be initialised because of inheritance from JetForwardPFlowJvtTool
88  //This is probably a very hacky way of getting around the issue
89  m_orKey = m_jetContainerName + "." + m_orKey.key();;
90  m_PFOKey = m_jetContainerName + "." + m_PFOKey.key();
91  m_fjvtKey = m_jetContainerName + "." + m_fjvtKey.key();
93  m_isPUKey = m_jetContainerName + "." + m_isPUKey.key();
94 
95  ATH_CHECK(m_orKey.initialize());
96  ATH_CHECK(m_PFOKey.initialize());
97  ATH_CHECK(m_fjvtKey.initialize());
98  ATH_CHECK(m_fjvtRawKey.initialize());
99  ATH_CHECK(m_isPUKey.initialize());
100 
101  return StatusCode::SUCCESS;
102  }
103 
105  std::vector<TVector2> pileupMomenta;
106  pileupMomenta=calculateVertexMomenta(&jetCont,m_pvind, m_vertices);
109  if(pileupMomenta.empty()) {
110  ATH_MSG_DEBUG( "pileupMomenta is empty, this can happen for events with no PU vertices."
111  <<" bJVT won't be computed for this event and will be set to 0 instead." );
112  for(const xAOD::Jet* jetC : jetCont) {
113  bjvtHandle(*jetC) = 1;
114  bjvtRawHandle(*jetC) = 0;
115  }
116  return StatusCode::SUCCESS;
117  }
118 
119  for(const xAOD::Jet* jetC : jetCont) {
120  bjvtHandle(*jetC) = 1;
121  bjvtRawHandle(*jetC) = 0;
122 
123  if (isCentralJet(jetC)){
124  double bjvt = getFJVT(jetC,pileupMomenta); //Same projection function as fJVT
125  if (bjvt>m_bjvtThresh) bjvtHandle(*jetC) = 0;
126  bjvtRawHandle(*jetC) = bjvt;
127  }
128  }
129  return StatusCode::SUCCESS;
130  }
131 
132  //Redefined here: Using isQCDPUJet()
134  int pvind, int vertices) const {
135  std::vector<TVector2> pileupMomenta;
136  // -- Retrieve PV index if not provided by user
137  const std::size_t pv_index = (pvind==-1) ? getPV() : std::size_t(pvind);
138 
140 
141  for(const xAOD::Vertex* vx: *vxContHandle) {
142  if(vx->vertexType()!=xAOD::VxType::PriVtx && vx->vertexType()!=xAOD::VxType::PileUp) continue;
143  if(vx->index()==(size_t)pv_index) continue;
144 
145  TString jname = m_jetsName.value();
146  jname += vx->index();
147 
148  pflow::puJets vertjets = buildPFlowPUjets(*vx);
149  if( !vertjets.jetCont || !vertjets.jetAuxCont ){
150  ATH_MSG_WARNING(" Some issue appeared while building the pflow pileup jets for vertex "
151  << vx->index() << " (vxType = " << vx->vertexType()<<" )!" );
152  return pileupMomenta;
153  }
154 
155  TVector2 vertex_met;
156  for( const xAOD::Jet *jet : *(vertjets.jetCont) ) {
157 
158  // Remove jets which are close to hs
159  if (!m_includePV && hasCloseByHSjet(jet,pjets)) continue;
160 
161  // Calculate vertex missing momentum
162  if (isQCDPUJet(jet) && getRpt(jet)> m_rptCut)
163  {
164  vertex_met += TVector2(jet->pt()*cos(jet->phi()),jet->pt()*sin(jet->phi()) ) ;
165  }
166  else{
167  vertex_met += TVector2(jet->jetP4(m_jetchargedp4).Pt()*cos(jet->jetP4(m_jetchargedp4).Phi()),
168  jet->jetP4(m_jetchargedp4).Pt()*sin(jet->jetP4(m_jetchargedp4).Phi()) );
169  }
170  }
171 
172  pileupMomenta.push_back(vertex_met);
173  if(vertices!=-1 && int(vx->index())==vertices) break;
174  }
175  return pileupMomenta;
176  }
177 
179  if (std::abs(jet->eta())>m_etaThresh) return false; //Must be central
180  if (jet->pt()<m_QCDPUMinPt || (m_QCDPUMaxPt>0 && jet->pt()>m_QCDPUMaxPt) ) return false;
181  //Other selections? EMPTopo studies included cuts on JVT and JVF
182  return true;
183  }
184 
185  //Redefined here: Separately label QCD and stochastic PU
187  const xAOD::JetContainer *itpujets,const xAOD::JetContainer *ootpujets) {
188  //truthJets container taken to be truth HS - @to-Do double check this
189  //In-time and out-of-time PU truth jets given in AODs as separate containers
193 
194  for(const xAOD::Jet *jet : *jets) {
195  bool ishs = false;
196  bool ispu = true;
197 
198  bool isqcdpu = false;
199  bool isstochpu = true; //Default value to make logic work - changed below
200 
201  for(const xAOD::Jet *tjet : *truthJets) {
202  if (tjet->p4().DeltaR(jet->p4())<0.3 && tjet->pt()>10e3) ishs = true;
203  if (tjet->p4().DeltaR(jet->p4())<0.6 && tjet->pt()>4e3) ispu = false;
204  }
205 
206  if (ispu){
207  //Need to check both containers
208  for(const xAOD::Jet *itpujet : *itpujets){
209  if (itpujet->p4().DeltaR(jet->p4())<0.3 && itpujet->pt()>10e3) isqcdpu = true;
210  if (itpujet->p4().DeltaR(jet->p4())<0.6 && itpujet->pt()>10e3) isstochpu = false;
211  }
212  for(const xAOD::Jet *ootpujet : *ootpujets){
213  if (ootpujet->p4().DeltaR(jet->p4())<0.3 && ootpujet->pt()>10e3) isqcdpu = true;
214  if (ootpujet->p4().DeltaR(jet->p4())<0.6 && ootpujet->pt()>10e3) isstochpu = false;
215  }
216  }
217 
218  else {
219  isstochpu = false; //Can't be labelled stochastic PU if jet is not determined to be PU
220  }
221 
222  isHSHandle(*jet)=ishs;
223  isQCDPUHandle(*jet)=isqcdpu;
224  isStochPUHandle(*jet)=isstochpu;
225  }
226 
227  return StatusCode::SUCCESS;
228  }
JetBalancePFlowJvtTool::JetBalancePFlowJvtTool
JetBalancePFlowJvtTool(const std::string &name)
Constructor with parameters:
Definition: JetBalancePFlowJvtTool.cxx:33
pflow::puJets::jetAuxCont
std::shared_ptr< xAOD::JetAuxContainer > jetAuxCont
Definition: JetForwardPFlowJvtTool.h:85
JetBalancePFlowJvtTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: JetBalancePFlowJvtTool.cxx:45
JetBalancePFlowJvtTool::m_isStochPUKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_isStochPUKey
Definition: JetBalancePFlowJvtTool.h:129
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
JetForwardPFlowJvtTool::hasCloseByHSjet
bool hasCloseByHSjet(const xAOD::Jet *jet, const xAOD::JetContainer *pjets) const
Definition: JetForwardPFlowJvtTool.cxx:178
JetForwardPFlowJvtTool::m_jetContainerName
Gaudi::Property< std::string > m_jetContainerName
Definition: JetForwardPFlowJvtTool.h:126
JetForwardPFlowJvtTool::m_pvind
Gaudi::Property< int > m_pvind
Definition: JetForwardPFlowJvtTool.h:131
JetAttributes.h
JetBalancePFlowJvtTool::m_QCDPUMinPt
Gaudi::Property< float > m_QCDPUMinPt
Definition: JetBalancePFlowJvtTool.h:122
JetForwardPFlowJvtTool::m_tvaKey
SG::ReadHandleKey< jet::TrackVertexAssociation > m_tvaKey
Definition: JetForwardPFlowJvtTool.h:125
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
JetForwardPFlowJvtTool::m_includePV
Gaudi::Property< bool > m_includePV
Definition: JetForwardPFlowJvtTool.h:133
JetForwardPFlowJvtTool
Definition: JetForwardPFlowJvtTool.h:91
JetForwardPFlowJvtTool::m_vertices
Gaudi::Property< int > m_vertices
Definition: JetForwardPFlowJvtTool.h:132
JetBalancePFlowJvtTool::tagTruth
StatusCode tagTruth(const xAOD::JetContainer *jets, const xAOD::JetContainer *truthJets, const xAOD::JetContainer *itpujets, const xAOD::JetContainer *ootpujets)
Definition: JetBalancePFlowJvtTool.cxx:186
JetForwardPFlowJvtTool::m_isPUKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_isPUKey
Definition: JetForwardPFlowJvtTool.h:164
JetForwardPFlowJvtTool::m_jetchargedp4
Gaudi::Property< std::string > m_jetchargedp4
Definition: JetForwardPFlowJvtTool.h:128
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
pflow::puJets::jetCont
std::shared_ptr< xAOD::JetContainer > jetCont
Definition: JetForwardPFlowJvtTool.h:84
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
JetBalancePFlowJvtTool.h
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
JetBalancePFlowJvtTool::~JetBalancePFlowJvtTool
virtual ~JetBalancePFlowJvtTool()
Destructor:
JetBalancePFlowJvtTool::decorate
virtual StatusCode decorate(const xAOD::JetContainer &jetCont) const override
Decorate a jet collection without otherwise modifying it.
Definition: JetBalancePFlowJvtTool.cxx:104
JetForwardPFlowJvtTool::getPV
std::size_t getPV() const
Definition: JetForwardPFlowJvtTool.cxx:377
JetForwardPFlowJvtTool::m_passJvtKey
SG::ReadDecorHandleKey< xAOD::JetContainer > m_passJvtKey
Definition: JetForwardPFlowJvtTool.h:157
JetForwardPFlowJvtTool::m_jetsName
Gaudi::Property< std::string > m_jetsName
Definition: JetForwardPFlowJvtTool.h:127
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
JetForwardPFlowJvtTool::m_fjvtRawKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_fjvtRawKey
Definition: JetForwardPFlowJvtTool.h:162
JetForwardPFlowJvtTool::m_fjvtKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_fjvtKey
Definition: JetForwardPFlowJvtTool.h:161
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
JetBalancePFlowJvtTool::m_bjvtRawKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_bjvtRawKey
Definition: JetBalancePFlowJvtTool.h:127
JetForwardPFlowJvtTool::m_vxContKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vxContKey
Definition: JetForwardPFlowJvtTool.h:152
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
JetBalancePFlowJvtTool::m_isQCDPUKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_isQCDPUKey
Definition: JetBalancePFlowJvtTool.h:128
JetBalancePFlowJvtTool::isQCDPUJet
bool isQCDPUJet(const xAOD::Jet *jet) const
Definition: JetBalancePFlowJvtTool.cxx:178
JetForwardPFlowJvtTool::m_rptCut
Gaudi::Property< double > m_rptCut
Definition: JetForwardPFlowJvtTool.h:140
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
JetForwardPFlowJvtTool::isCentralJet
bool isCentralJet(const xAOD::Jet *jet) const
Definition: JetForwardPFlowJvtTool.cxx:365
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
JetBalancePFlowJvtTool::m_bjvtThresh
float m_bjvtThresh
Definition: JetBalancePFlowJvtTool.h:131
JetForwardPFlowJvtTool::m_FEKey
SG::ReadHandleKey< xAOD::FlowElementContainer > m_FEKey
Definition: JetForwardPFlowJvtTool.h:154
xAOD::VxType::PileUp
@ PileUp
Pile-up vertex.
Definition: TrackingPrimitives.h:573
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
JetForwardPFlowJvtTool::m_tightOP
Gaudi::Property< bool > m_tightOP
Definition: JetForwardPFlowJvtTool.h:146
JetBalancePFlowJvtTool::m_bjvtKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_bjvtKey
Definition: JetBalancePFlowJvtTool.h:126
JetForwardPFlowJvtTool::m_orFEKey
SG::ReadDecorHandleKey< xAOD::FlowElement > m_orFEKey
Definition: JetForwardPFlowJvtTool.h:159
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
JetForwardPFlowJvtTool::m_fjvtThresh
Gaudi::Property< double > m_fjvtThresh
Definition: JetForwardPFlowJvtTool.h:139
pflow::puJets
Definition: JetForwardPFlowJvtTool.h:83
JetForwardPFlowJvtTool::getRpt
double getRpt(const xAOD::Jet *jet) const
Definition: JetForwardPFlowJvtTool.cxx:371
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
JetForwardPFlowJvtTool::m_isHSKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_isHSKey
Definition: JetForwardPFlowJvtTool.h:163
JetForwardPFlowJvtTool::m_PFOKey
SG::ReadHandleKey< xAOD::PFOContainer > m_PFOKey
Definition: JetForwardPFlowJvtTool.h:153
JetForwardPFlowJvtTool::m_etaThresh
Gaudi::Property< double > m_etaThresh
Definition: JetForwardPFlowJvtTool.h:134
JetBalancePFlowJvtTool::m_QCDPUMaxPt
Gaudi::Property< float > m_QCDPUMaxPt
Definition: JetBalancePFlowJvtTool.h:123
JetBalancePFlowJvtTool::calculateVertexMomenta
virtual std::vector< TVector2 > calculateVertexMomenta(const xAOD::JetContainer *jets, int pvind, int vertices) const override
Definition: JetBalancePFlowJvtTool.cxx:133
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
JetFromPseudojet.h
JetForwardPFlowJvtTool::buildPFlowPUjets
pflow::puJets buildPFlowPUjets(const xAOD::Vertex &vx) const
Definition: JetForwardPFlowJvtTool.cxx:188
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
JetForwardPFlowJvtTool::getFJVT
float getFJVT(const xAOD::Jet *jet, const std::vector< TVector2 > &pileupMomenta) const
Definition: JetForwardPFlowJvtTool.cxx:123
JetForwardPFlowJvtTool::m_orKey
SG::ReadDecorHandleKey< xAOD::PFO > m_orKey
Definition: JetForwardPFlowJvtTool.h:158