ATLAS Offline Software
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 
9 VertexFinder::VertexFinder(const std::string& type,
10  const std::string& name,
11  const IInterface * parent) :
13 {
14  declareInterface<DiTauToolBase > (this);
15 }
16 
17 
18 VertexFinder::~VertexFinder() = default;
19 
20 
22 
23  ATH_CHECK( m_primVtxContainerName.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
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:203
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
VertexFinder::initialize
virtual StatusCode initialize() override
Tool initializer.
Definition: VertexFinder.cxx:21
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
xAOD::DiTauJet_v1::setDetail
void setDetail(DiTauJetParameters::Detail detail, int value)
Definition: DiTauJet_v1.cxx:339
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:44
VertexFinder::getJetVertexFraction
static float getJetVertexFraction(const xAOD::Vertex *, const std::vector< const xAOD::TrackParticle * > &, const jet::TrackVertexAssociation *)
Definition: VertexFinder.cxx:132
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
VertexFinder::m_assocTracksName
Gaudi::Property< std::string > m_assocTracksName
Definition: VertexFinder.h:48
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:572
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:240
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
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:30
VertexFinder::m_useTJVA
Gaudi::Property< bool > m_useTJVA
Definition: VertexFinder.h:49
DiTauCandidateData
Definition: DiTauCandidateData.h:15
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
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.