ATLAS Offline Software
VertexFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
10 #include "xAODTracking/Vertex.h"
11 #include "StoreGate/ReadHandle.h"
12 
13 
14 VertexFinder::VertexFinder(const std::string& type,
15  const std::string& name,
16  const IInterface * parent) :
18  m_assocTracksName("GhostTrack")
19 {
20  declareInterface<DiTauToolBase > (this);
21  declareProperty("AssociatedTracks", m_assocTracksName);
22 }
23 
24 
25 VertexFinder::~VertexFinder() = default;
26 
27 
29 
30  ATH_CHECK( m_primVtxContainerName.initialize() );
32 
33  return StatusCode::SUCCESS;
34 }
35 
36 
38  const EventContext& ctx) const {
39 
40  ATH_MSG_DEBUG("execute VertexFinder...");
41 
42  xAOD::DiTauJet *pDiTau = data->xAODDiTau;
43 
44  // get the primary vertex container from StoreGate
45  //do it here because of tau trigger
46  const xAOD::Vertex* vxPrimary = nullptr;
47 
49 
50  // find default PrimaryVertex
51  // see https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/VertexReselectionOnAOD
52  // and https://svnweb.cern.ch/trac/atlasoff/browser/Tracking/TrkEvent/VxVertex/trunk/VxVertex/PrimaryVertexSelector.h
53  for (const auto *const vtx : *vxContainer) {
54  // the first and only primary vertex candidate is picked
55  if ( vtx->vertexType() == xAOD::VxType::PriVtx) {
56  vxPrimary = vtx;
57  break;
58  }
59  }
60 
61  if (vxPrimary == nullptr) {
62  ATH_MSG_WARNING("Unable to find primary Vertex in VertexContainer." <<
63  " Continue without Tau Vertex Association.");
64  return StatusCode::SUCCESS;
65  }
66 
67  // associate vertex to tau
68  pDiTau->setVertex(vxContainer.get(), vxPrimary);
69 
70 
71  // try to find new PV with TJVA
72  ATH_MSG_DEBUG("TJVA enabled -> try to find new PV for the tau candidate");
73 
74  float maxJVF = -100.;
75  ElementLink<xAOD::VertexContainer> newPrimaryVertexLink = getPV_TJVA(pDiTau, vxContainer.get(), maxJVF, ctx);
76  if (newPrimaryVertexLink.isValid()) {
77  // set new primary vertex
78  // will overwrite default one which was set above
79  pDiTau->setVertexLink(newPrimaryVertexLink);
80  // save highest JVF value
81  pDiTau->setDetail(xAOD::DiTauJetParameters::TauJetVtxFraction,static_cast<float>(maxJVF));
82  ATH_MSG_DEBUG("TJVA vertex found and set");
83  }
84  else {
85  ATH_MSG_DEBUG("couldn't find new PV for TJVA");
86  }
87 
88  return StatusCode::SUCCESS;
89 }
90 
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
93  float& maxJVF,
94  const EventContext& ctx) const
95 {
96  const xAOD::Jet* pJetSeed = (*pDiTau->jetLink());
97 
98  // 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
99 
100  // Get the tracks associated to the jet
101  std::vector<const xAOD::TrackParticle*> assocTracks;
102  if (! pJetSeed->getAssociatedObjects(m_assocTracksName, assocTracks)) {
103  ATH_MSG_ERROR("Could not retrieve the AssociatedObjects named \""<< m_assocTracksName <<"\" from jet");
104  return {};
105  }
106 
107  // Get the TVA object
109 
110  // Calculate Jet Vertex Fraction
111  std::vector<float> jvf;
112  jvf.resize(vertices->size());
113  for (size_t iVertex = 0; iVertex < vertices->size(); ++iVertex) {
114  jvf.at(iVertex) = getJetVertexFraction(vertices->at(iVertex),assocTracks,tva.get());
115  }
116 
117  // Get the highest JVF vertex and store maxJVF for later use
118  // Note: the official JetMomentTools/JetVertexFractionTool doesn't provide any possibility to access the JVF value, but just the vertex.
119  maxJVF=-100.;
120  size_t maxIndex = 0;
121  for (size_t iVertex = 0; iVertex < jvf.size(); ++iVertex) {
122  if (jvf.at(iVertex) > maxJVF) {
123  maxJVF = jvf.at(iVertex);
124  maxIndex = iVertex;
125  }
126  }
127 
128  // Set the highest JVF vertex
129  ElementLink<xAOD::VertexContainer> vtxlink = ElementLink<xAOD::VertexContainer>(*vertices,vertices->at(maxIndex)->index());
130 
131  return vtxlink;
132 }
133 
134 // reimplementation of JetVertexFractionTool::getJetVertexFraction(const xAOD::Vertex* vertex, const std::vector<const xAOD::TrackParticle*>& tracks, const jet::TrackVertexAssociation* tva) const
135 // avoid to call this specific tool only for this easy purpose
136 // see https://svnweb.cern.ch/trac/atlasoff/browser/Reconstruction/Jet/JetMomentTools/trunk/Root/JetVertexFractionTool.cxx
137 float VertexFinder::getJetVertexFraction(const xAOD::Vertex* vertex, const std::vector<const xAOD::TrackParticle*>& tracks, const jet::TrackVertexAssociation* tva)
138 {
139  float sumTrackPV = 0.;
140  float sumTrackAll = 0.;
141  for (size_t iTrack = 0; iTrack < tracks.size(); ++iTrack)
142  {
143  const xAOD::TrackParticle* track = tracks.at(iTrack);
144  const xAOD::Vertex* ptvtx = tva->associatedVertex(track);
145  if (ptvtx != nullptr) {
146  if (ptvtx->index() == vertex->index()) sumTrackPV += track->pt();
147  }
148 
149  sumTrackAll += track->pt();
150  }
151 
152  return sumTrackAll!=0. ? sumTrackPV/sumTrackAll : 0.;
153 }
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
DiTauToolBase.h
VertexFinder::initialize
virtual StatusCode initialize() override
Tool initializer.
Definition: VertexFinder.cxx:28
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
DiTauCandidateData.h
VertexFinder::VertexFinder
VertexFinder(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
Definition: VertexFinder.cxx:14
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:137
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:92
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:581
Vertex.h
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:221
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
VertexContainer.h
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:37
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.
ReadHandle.h
Handle class for reading from StoreGate.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
VertexFinder::~VertexFinder
virtual ~VertexFinder()
Destructor.