ATLAS Offline Software
VertexFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 //#include "StoreGate/ReadHandle.h"
7 
8 
9 VertexFinder::VertexFinder(const std::string& type,
10  const std::string& name,
11  const IInterface * parent) :
13  m_assocTracksName("GhostTrack")
14 {
15  declareInterface<DiTauToolBase > (this);
16  declareProperty("AssociatedTracks", m_assocTracksName);
17 }
18 
19 
20 VertexFinder::~VertexFinder() = default;
21 
22 
24 
25  ATH_CHECK( m_primVtxContainerName.initialize() );
27 
28  return StatusCode::SUCCESS;
29 }
30 
31 
33  const EventContext& ctx) const {
34 
35  ATH_MSG_DEBUG("execute VertexFinder...");
36 
37  xAOD::DiTauJet *pDiTau = data->xAODDiTau;
38 
39  // get the primary vertex container from StoreGate
40  //do it here because of tau trigger
41  const xAOD::Vertex* vxPrimary = nullptr;
42 
44 
45  // find default PrimaryVertex
46  // see https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/VertexReselectionOnAOD
47  // and https://svnweb.cern.ch/trac/atlasoff/browser/Tracking/TrkEvent/VxVertex/trunk/VxVertex/PrimaryVertexSelector.h
48  for (const auto *const vtx : *vxContainer) {
49  // the first and only primary vertex candidate is picked
50  if ( vtx->vertexType() == xAOD::VxType::PriVtx) {
51  vxPrimary = vtx;
52  break;
53  }
54  }
55 
56  if (vxPrimary == nullptr) {
57  ATH_MSG_WARNING("Unable to find primary Vertex in VertexContainer." <<
58  " Continue without Tau Vertex Association.");
59  return StatusCode::SUCCESS;
60  }
61 
62  // associate vertex to tau
63  pDiTau->setVertex(vxContainer.get(), vxPrimary);
64 
65 
66  // try to find new PV with TJVA
67  ATH_MSG_DEBUG("TJVA enabled -> try to find new PV for the tau candidate");
68 
69  float maxJVF = -100.;
70  ElementLink<xAOD::VertexContainer> newPrimaryVertexLink = getPV_TJVA(pDiTau, vxContainer.get(), maxJVF, ctx);
71  if (newPrimaryVertexLink.isValid()) {
72  // set new primary vertex
73  // will overwrite default one which was set above
74  pDiTau->setVertexLink(newPrimaryVertexLink);
75  // save highest JVF value
76  pDiTau->setDetail(xAOD::DiTauJetParameters::TauJetVtxFraction,static_cast<float>(maxJVF));
77  ATH_MSG_DEBUG("TJVA vertex found and set");
78  }
79  else {
80  ATH_MSG_DEBUG("couldn't find new PV for TJVA");
81  }
82 
83  return StatusCode::SUCCESS;
84 }
85 
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
88  float& maxJVF,
89  const EventContext& ctx) const
90 {
91  const xAOD::Jet* pJetSeed = (*pDiTau->jetLink());
92 
93  // the implementation follows closely the example given in modifyJet(...) in https://svnweb.cern.ch/trac/atlasoff/browser/Reconstruction/Jet/JetMomentTools/trunk/Root/JetVertexFractionTool.cxx#15
94 
95  // Get the tracks associated to the jet
96  std::vector<const xAOD::TrackParticle*> assocTracks;
97  if (! pJetSeed->getAssociatedObjects(m_assocTracksName, assocTracks)) {
98  ATH_MSG_ERROR("Could not retrieve the AssociatedObjects named \""<< m_assocTracksName <<"\" from jet");
99  return {};
100  }
101 
102  // Get the TVA object
104 
105  // Calculate Jet Vertex Fraction
106  std::vector<float> jvf;
107  jvf.resize(vertices->size());
108  for (size_t iVertex = 0; iVertex < vertices->size(); ++iVertex) {
109  jvf.at(iVertex) = getJetVertexFraction(vertices->at(iVertex),assocTracks,tva.get());
110  }
111 
112  // Get the highest JVF vertex and store maxJVF for later use
113  // Note: the official JetMomentTools/JetVertexFractionTool doesn't provide any possibility to access the JVF value, but just the vertex.
114  maxJVF=-100.;
115  size_t maxIndex = 0;
116  for (size_t iVertex = 0; iVertex < jvf.size(); ++iVertex) {
117  if (jvf.at(iVertex) > maxJVF) {
118  maxJVF = jvf.at(iVertex);
119  maxIndex = iVertex;
120  }
121  }
122 
123  // Set the highest JVF vertex
124  ElementLink<xAOD::VertexContainer> vtxlink = ElementLink<xAOD::VertexContainer>(*vertices,vertices->at(maxIndex)->index());
125 
126  return vtxlink;
127 }
128 
129 // reimplementation of JetVertexFractionTool::getJetVertexFraction(const xAOD::Vertex* vertex, const std::vector<const xAOD::TrackParticle*>& tracks, const jet::TrackVertexAssociation* tva) const
130 // avoid to call this specific tool only for this easy purpose
131 // see https://svnweb.cern.ch/trac/atlasoff/browser/Reconstruction/Jet/JetMomentTools/trunk/Root/JetVertexFractionTool.cxx
132 float VertexFinder::getJetVertexFraction(const xAOD::Vertex* vertex, const std::vector<const xAOD::TrackParticle*>& tracks, const jet::TrackVertexAssociation* tva)
133 {
134  float sumTrackPV = 0.;
135  float sumTrackAll = 0.;
136  for (size_t iTrack = 0; iTrack < tracks.size(); ++iTrack)
137  {
138  const xAOD::TrackParticle* track = tracks.at(iTrack);
139  const xAOD::Vertex* ptvtx = tva->associatedVertex(track);
140  if (ptvtx != nullptr) {
141  if (ptvtx->index() == vertex->index()) sumTrackPV += track->pt();
142  }
143 
144  sumTrackAll += track->pt();
145  }
146 
147  return sumTrackAll!=0. ? sumTrackPV/sumTrackAll : 0.;
148 }
xAOD::DiTauJetParameters::TauJetVtxFraction
@ TauJetVtxFraction
Definition: DiTauDefs.h:39
xAOD::DiTauJet_v1::setVertex
void setVertex(const xAOD::VertexContainer *cont, const xAOD::Vertex *vertex)
Definition: DiTauJet_v1.cxx:204
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
VertexFinder::initialize
virtual StatusCode initialize() override
Tool initializer.
Definition: VertexFinder.cxx:23
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::DiTauJet_v1::setDetail
void setDetail(DiTauJetParameters::Detail detail, int value)
Definition: DiTauJet_v1.cxx:373
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
VertexFinder::VertexFinder
VertexFinder(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
Definition: VertexFinder.cxx:9
VertexFinder::m_primVtxContainerName
SG::ReadHandleKey< xAOD::VertexContainer > m_primVtxContainerName
Definition: VertexFinder.h:43
VertexFinder::getJetVertexFraction
static float getJetVertexFraction(const xAOD::Vertex *, const std::vector< const xAOD::TrackParticle * > &, const jet::TrackVertexAssociation *)
Definition: VertexFinder.cxx:132
xAOD::Jet_v1::getAssociatedObjects
std::vector< const T * > getAssociatedObjects(const std::string &name) const
get associated objects as a vector<object> this compact form throws an exception if the object is not...
VertexFinder::getPV_TJVA
ElementLink< xAOD::VertexContainer > getPV_TJVA(const xAOD::DiTauJet *, const xAOD::VertexContainer *, float &maxJVF, const EventContext &ctx) const
Definition: VertexFinder.cxx:87
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
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
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
VertexFinder::m_trackVertexAssocName
SG::ReadHandleKey< jet::TrackVertexAssociation > m_trackVertexAssocName
Definition: VertexFinder.h:46
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
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
jet::TrackVertexAssociation::associatedVertex
const xAOD::Vertex * associatedVertex(const xAOD::TrackParticle *trk) const
Definition: TrackVertexAssociation.cxx:23
xAOD::DiTauJet_v1::setVertexLink
void setVertexLink(const VertexLink_t &vertexLink)
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
DiTauToolBase
The base class for all tau tools.
Definition: DiTauToolBase.h:20
xAOD::DiTauJet_v1::jetLink
const JetLink_t & jetLink() const
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
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
VertexFinder.h
xAOD::DiTauJet_v1
Definition: DiTauJet_v1.h:31
VertexFinder::execute
virtual StatusCode execute(DiTauCandidateData *data, const EventContext &ctx) const override
Execute - called for each Ditau candidate.
Definition: VertexFinder.cxx:32
VertexFinder::m_assocTracksName
std::string m_assocTracksName
Definition: VertexFinder.h:44
DiTauCandidateData
Definition: DiTauCandidateData.h:15
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.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
VertexFinder::~VertexFinder
virtual ~VertexFinder()
Destructor.