ATLAS Offline Software
Loading...
Searching...
No Matches
VertexFinder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6//#include "StoreGate/ReadHandle.h"
7
8
10 const std::string& name,
11 const IInterface * parent) :
12 DiTauToolBase(type, name, parent)
13{
14 declareInterface<DiTauToolBase > (this);
15}
16
17
19
20
22
23 ATH_CHECK( m_primVtxContainerName.initialize() );
24 ATH_CHECK( m_trackVertexAssocName.initialize() );
25
26 return StatusCode::SUCCESS;
27}
28
29
31 const EventContext& ctx) const {
32
33 ATH_MSG_DEBUG("execute VertexFinder...");
34
35 xAOD::DiTauJet *pDiTau = data->xAODDiTau;
36
37 // get the primary vertex container from StoreGate
38 //do it here because of tau trigger
39 const xAOD::Vertex* vxPrimary = nullptr;
40
42
43 // find default PrimaryVertex
44 // see https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/VertexReselectionOnAOD
45 // and https://svnweb.cern.ch/trac/atlasoff/browser/Tracking/TrkEvent/VxVertex/trunk/VxVertex/PrimaryVertexSelector.h
46 for (const auto *const vtx : *vxContainer) {
47 // the first and only primary vertex candidate is picked
48 if ( vtx->vertexType() == xAOD::VxType::PriVtx) {
49 vxPrimary = vtx;
50 break;
51 }
52 }
53
54 if (vxPrimary == nullptr) {
55 ATH_MSG_WARNING("Unable to find primary Vertex in VertexContainer." <<
56 " Continue without Tau Vertex Association.");
57 return StatusCode::SUCCESS;
58 }
59
60 // associate vertex to tau
61 pDiTau->setVertex(vxContainer.get(), vxPrimary);
62
63
64 if(m_useTJVA){
65 // try to find new PV with TJVA
66 ATH_MSG_DEBUG("TJVA enabled -> try to find new PV for the tau candidate");
67
68 float maxJVF = -100.;
69 ElementLink<xAOD::VertexContainer> newPrimaryVertexLink = getPV_TJVA(pDiTau, vxContainer.get(), maxJVF, ctx);
70 if (newPrimaryVertexLink.isValid()) {
71 // set new primary vertex
72 // will overwrite default one which was set above
73 pDiTau->setVertexLink(newPrimaryVertexLink);
74 // save highest JVF value
75 pDiTau->setDetail(xAOD::DiTauJetParameters::TauJetVtxFraction,static_cast<float>(maxJVF));
76 ATH_MSG_DEBUG("TJVA vertex found and set");
77 }
78 else {
79 ATH_MSG_DEBUG("couldn't find new PV for TJVA");
80 }
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
132float 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}
#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)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
DiTauToolBase(const std::string &type, const std::string &name, const IInterface *parent)
size_t index() const
Return the index of this element within its container.
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
virtual StatusCode execute(DiTauCandidateData *data, const EventContext &ctx) const override
Execute - called for each Ditau candidate.
virtual ~VertexFinder()
Destructor.
SG::ReadHandleKey< jet::TrackVertexAssociation > m_trackVertexAssocName
Gaudi::Property< std::string > m_assocTracksName
Gaudi::Property< bool > m_useTJVA
ElementLink< xAOD::VertexContainer > getPV_TJVA(const xAOD::DiTauJet *, const xAOD::VertexContainer *, float &maxJVF, const EventContext &ctx) const
VertexFinder(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
static float getJetVertexFraction(const xAOD::Vertex *, const std::vector< const xAOD::TrackParticle * > &, const jet::TrackVertexAssociation *)
SG::ReadHandleKey< xAOD::VertexContainer > m_primVtxContainerName
virtual StatusCode initialize() override
Tool initializer.
Class to hold N-to-one aassociations between tracks and vertices.
const xAOD::Vertex * associatedVertex(const xAOD::TrackParticle *trk) const
const JetLink_t & jetLink() const
void setDetail(DiTauJetParameters::Detail detail, int value)
void setVertexLink(const VertexLink_t &vertexLink)
void setVertex(const xAOD::VertexContainer *cont, const xAOD::Vertex *vertex)
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...
@ PriVtx
Primary vertex.
Jet_v1 Jet
Definition of the current "jet version".
TrackParticle_v1 TrackParticle
Reference the current persistent version:
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
DiTauJet_v1 DiTauJet
Definition of the current version.
Definition DiTauJet.h:17