ATLAS Offline Software
JetTrackSumMomentsTool.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 // JetTrackSumMomentsTool.cxx
8 // Implementation file for class JetTrackSumMomentsTool
9 // Author: James Frost <james.frost@cern.ch>
11 
13 
16 
17 using xAOD::JetFourMom_t;
18 //using AODTracking::FourMom_t;
19 //using xAOD::TrackParticle::FourMom_t;
20 
22  : asg::AsgTool(name) {
23 }
24 
25 //**********************************************************************
26 
28  ATH_MSG_INFO("Initializing JetTrackSumMomentsTool " << name());
29  if ( m_htsel.empty() ) {
30  ATH_MSG_INFO(" No track selector.");
31  } else {
32  ATH_MSG_INFO(" Track selector: " << m_htsel->name());
33  }
34 
35  ATH_CHECK(m_vertexContainer_key.initialize());
37 
38  if(m_jetContainerName.empty()) {
39  ATH_MSG_ERROR("JetTrackSumMomentsTool needs to have its input jet container configured!");
40  return StatusCode::FAILURE;
41  }
44 
45  ATH_CHECK(m_trackSumPtKey.initialize());
46  ATH_CHECK(m_trackSumMassKey.initialize());
47 
48  return StatusCode::SUCCESS;
49 }
50 
51 //**********************************************************************
52 
54  // Get input vertex collection
55 
56  auto handle_v = SG::makeHandle(m_vertexContainer_key);
57  if (!handle_v.isValid()){
58  ATH_MSG_ERROR("Could not retrieve the VertexContainer: "
59  << m_vertexContainer_key.key());
60  return StatusCode::FAILURE;
61  }
62 
63  const auto *vertexContainer = handle_v.cptr();
64 
65  // Get the track-vertex association
66  auto handle_tva = SG::makeHandle(m_tva_key);
67  if (!handle_tva.isValid()){
68  ATH_MSG_ERROR("Could not retrieve the TrackVertexAssociation: "
69  << m_tva_key.key());
70  return StatusCode::FAILURE;
71  }
72 
73  const auto *tva = handle_tva.cptr();
74 
77 
78  // Get the tracks associated to the jet
79  // Note that there may be no tracks - this is both normal and an error case
80  std::vector<const xAOD::TrackParticle*> tracks;
81  for(const xAOD::Jet* jet : jets) {
82  if ( ! jet->getAssociatedObjects(m_assocTracksName, tracks) ) {
83  ATH_MSG_DEBUG("Associated tracks not found.");
84  }
85 
86  if (vertexContainer->empty() ) {
87  ATH_MSG_WARNING("There are no vertices in the container. Exiting");
88  return StatusCode::FAILURE;
89  }
90 
91  const xAOD::Vertex* HSvertex = nullptr;
92  if (!m_useOriginVertex)
93  HSvertex = findHSVertex(vertexContainer);
94  else
95  {
96  HSvertex = jet->getAssociatedObject<xAOD::Vertex>("OriginVertex");
97  if (!HSvertex) // nullptr if the attribute doesn't exist
98  {
99  ATH_MSG_ERROR("OriginVertex was requested, but the jet does not contain an OriginVertex");
100  return StatusCode::FAILURE;
101  }
102  else
103  ATH_MSG_VERBOSE("JetTrackSumMomentsTool " << name() << " is using OriginVertex at index: " << HSvertex->index());
104  }
105  const std::pair<float,float> tracksums = getJetTrackSums(HSvertex, tracks, tva);
106 
107  trackSumPtHandle(*jet) = tracksums.first;
108  trackSumMassHandle(*jet) = tracksums.second;
109 
110  ATH_MSG_VERBOSE("JetTrackSumMomentsTool " << name()
111  << ": TrackSumPt=" << tracksums.first
112  << ", TrackSumMass=" << tracksums.second );
113  }
114  return StatusCode::SUCCESS;
115 }
116 
117 //**********************************************************************
118 
120 {
121  for ( size_t iVertex = 0; iVertex < vertices->size(); ++iVertex ) {
122  if(vertices->at(iVertex)->vertexType() == xAOD::VxType::PriVtx) {
123 
124  ATH_MSG_VERBOSE("JetVertexTaggerTool " << name() << " Found HS vertex at index: "<< iVertex);
125  return vertices->at(iVertex);
126  }
127  }
128  ATH_MSG_VERBOSE("There is no vertex of type PriVx. Taking default vertex.");
129  return vertices->at(0);
130 }
131 
132 //**********************************************************************
133 
135  const std::vector<const xAOD::TrackParticle*>& tracks,
136  const jet::TrackVertexAssociation* tva) const {
137 
138  bool notsel = m_htsel.empty();
139  unsigned int nkeep = 0;
140  unsigned int nskip = 0;
141  xAOD::TrackParticle::FourMom_t tracksum(0,0,0,0);
142  for (size_t iTrack = 0; iTrack < tracks.size(); ++iTrack) {
143  const xAOD::TrackParticle* track = tracks.at(iTrack);
144  if ( notsel || m_htsel->accept(*track) ) {
145  const xAOD::Vertex* ptvtx = tva->associatedVertex(track);
146  if (!m_requireTrackPV || ptvtx != nullptr ) { // Track has vertex assigned
147  // Add to sums
148  if (!m_requireTrackPV || ptvtx->index() == vertex->index() ) { tracksum += track->p4(); }
149  }
150  ++nkeep;
151  }
152  else { ++nskip; }
153  }
154 
155  ATH_MSG_VERBOSE("JetTrackSumMomentsTool " << name()
156  << ": nsel=" << nkeep
157  << ", nrej=" << nskip );
158 
159  return std::make_pair(tracksum.Pt(),tracksum.M());
160 
161 }
162 
163 //**********************************************************************
JetTrackSumMomentsTool::findHSVertex
const xAOD::Vertex * findHSVertex(const xAOD::VertexContainer *&) const
Definition: JetTrackSumMomentsTool.cxx:119
JetTrackSumMomentsTool::m_tva_key
SG::ReadHandleKey< jet::TrackVertexAssociation > m_tva_key
Definition: JetTrackSumMomentsTool.h:76
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
JetTrackSumMomentsTool::getJetTrackSums
std::pair< float, float > getJetTrackSums(const xAOD::Vertex *, const std::vector< const xAOD::TrackParticle * > &, const jet::TrackVertexAssociation *) const
Definition: JetTrackSumMomentsTool.cxx:134
xAOD::TrackParticle_v1::FourMom_t
IParticle::FourMom_t FourMom_t
Definition of the 4-momentum type.
Definition: TrackParticle_v1.h:72
asg
Definition: DataHandleTestTool.h:28
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
JetTrackSumMomentsTool::m_trackSumPtKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_trackSumPtKey
Definition: JetTrackSumMomentsTool.h:78
JetTrackSumMomentsTool::m_jetContainerName
Gaudi::Property< std::string > m_jetContainerName
Definition: JetTrackSumMomentsTool.h:71
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
JetTrackSumMomentsTool::m_htsel
ToolHandle< InDet::IInDetTrackSelectionTool > m_htsel
Definition: JetTrackSumMomentsTool.h:72
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
JetTrackSumMomentsTool.h
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
jet::TrackVertexAssociation
Class to hold N-to-one aassociations between tracks and vertices.
Definition: TrackVertexAssociation.h:23
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
JetTrackSumMomentsTool::decorate
virtual StatusCode decorate(const xAOD::JetContainer &jets) const override
Decorate a jet collection without otherwise modifying it.
Definition: JetTrackSumMomentsTool.cxx:53
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
JetTrackSumMomentsTool::m_assocTracksName
Gaudi::Property< std::string > m_assocTracksName
Definition: JetTrackSumMomentsTool.h:69
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
WriteDecorHandle.h
Handle class for adding a decoration to an object.
jet::TrackVertexAssociation::associatedVertex
const xAOD::Vertex * associatedVertex(const xAOD::TrackParticle *trk) const
Definition: TrackVertexAssociation.cxx:23
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ReadHandle.h
Handle class for reading from StoreGate.
mc.nskip
nskip
Definition: mc.PhPy8EG_Hto4l_NNLOPS_nnlo_30_ggH125_ZZ4l.py:41
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
JetTrackSumMomentsTool::m_useOriginVertex
Gaudi::Property< bool > m_useOriginVertex
Definition: JetTrackSumMomentsTool.h:73
JetTrackSumMomentsTool::m_trackSumMassKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_trackSumMassKey
Definition: JetTrackSumMomentsTool.h:79
JetTrackSumMomentsTool::m_requireTrackPV
Gaudi::Property< bool > m_requireTrackPV
Definition: JetTrackSumMomentsTool.h:70
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
JetTrackSumMomentsTool::m_vertexContainer_key
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainer_key
Definition: JetTrackSumMomentsTool.h:75
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
JetTrackSumMomentsTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: JetTrackSumMomentsTool.cxx:27
JetTrackSumMomentsTool::JetTrackSumMomentsTool
JetTrackSumMomentsTool(const std::string &name)
Definition: JetTrackSumMomentsTool.cxx:21