ATLAS Offline Software
Loading...
Searching...
No Matches
TauVertexVariables.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef XAOD_ANALYSIS
6
9
10//-----------------------------------------------------------------------------
11// Constructor
12//-----------------------------------------------------------------------------
13
15 TauRecToolBase(name) {}
16
17//-----------------------------------------------------------------------------
18// Destructor
19//-----------------------------------------------------------------------------
20
22
23
24//-----------------------------------------------------------------------------
25// Initializer
26//-----------------------------------------------------------------------------
27
29
30 ATH_CHECK( m_fitTool.retrieve() );
31 ATH_CHECK( m_SeedFinder.retrieve() );
32
33 return StatusCode::SUCCESS;
34}
35
36//-----------------------------------------------------------------------------
37// Execution
38//-----------------------------------------------------------------------------
40 const EventContext& ctx = Gaudi::Hive::currentContext();
41
45
46 // try to find secondary vertex if more than 1 track and the tau vertex is available
47 if ( pTau.nTracks() < 2 || pTau.vertex()==nullptr ) {
48 return StatusCode::SUCCESS;
49 }
50
51 // xAOD TrackParticles
52 std::vector<const xAOD::TrackParticle*> xaodTracks;
53 // standard reconstruction uses Trk::Tracks in SeedFinder
54 std::vector<const Trk::Track*> origTracks;
55 // reconstruction from xAOD uses Trk::TrackParameters (Trk::Track not available)
56 std::vector<const Trk::TrackParameters*> origTrackParameters;
57
58 for (const xAOD::TauTrack* track : pTau.tracks()) {
59 xaodTracks.push_back(track->track());
60
61 if(track->track()->track()) {
62 origTracks.push_back(track->track()->track());
63 }
64 else {
65 const Trk::Perigee& perigee = track->track()->perigeeParameters();
66 origTrackParameters.push_back(static_cast<const Trk::TrackParameters*>(&perigee));
67 }
68 }
69
70 // origTrackParameters should be empty in standard reconstruction, origTracks should be empty when re-running from xAOD
71 // cppcheck-suppress invalidLifetime
72 if(!origTracks.empty() && !origTrackParameters.empty()) {
73 ATH_MSG_ERROR("Inconsistent mix of Trk::Track and Trk::TrackParameter");
74 return StatusCode::FAILURE;
75 }
76
77 std::unique_ptr<xAOD::Vertex> xAODvertex;
78
79 if(!origTracks.empty()) {
80 // get the starting point for the fit using Trk::Tracks
81 const Amg::Vector3D& seedPoint = m_SeedFinder->findSeed(origTracks);
82 // fitting the vertex
83 xAODvertex = m_fitTool->fit(ctx, xaodTracks, seedPoint);
84 }
85 else if (!origTrackParameters.empty()) {
86 // get the starting point for the fit using Trk::TrackParameters
87 const Amg::Vector3D& seedPoint = m_SeedFinder->findSeed(origTrackParameters);
88 // fitting the vertex
89 xAODvertex = m_fitTool->fit(ctx, xaodTracks, seedPoint);
90 }
91
92 if (!xAODvertex) {
93 ATH_MSG_WARNING("no secondary vertex found!");
94 return StatusCode::SUCCESS;
95 }
96
97 // get the transverse flight path significance
98 double trFlightPS = trFlightPathSig(pTau, *xAODvertex);
99 pTau.setDetail(xAOD::TauJetParameters::trFlightPathSig, static_cast<float>(trFlightPS));
100 ATH_MSG_VERBOSE("transverse flight path significance="<<trFlightPS);
101
102 // Note, we only attach the 2nd vertex if at offline, otherwise, break the trigger persistency
103 if (!inTrigger()) {
104 ATH_MSG_VERBOSE("secondary vertex recorded! x="<<xAODvertex->position().x()<< ", y="<<xAODvertex->position().y()<<", perp="<<xAODvertex->position().perp());
105 xAODvertex->setVertexType(xAOD::VxType::NotSpecified);
106 pSecVtxContainer.push_back(std::move(xAODvertex));
107 pTau.setSecondaryVertex(&pSecVtxContainer, pSecVtxContainer.back());
108 }
109
110 return StatusCode::SUCCESS;
111}
112
113//-------------------------------------------------------------------------
114// calculate the transverse flight path significance
115//-------------------------------------------------------------------------
116double TauVertexVariables::trFlightPathSig(const xAOD::TauJet& pTau, const xAOD::Vertex& secVertex) const {
117
118 const xAOD::Vertex* pVertex = pTau.vertex();
119 if (pVertex==nullptr) {
120 ATH_MSG_WARNING("No primary vertex information for calculation of transverse flight path significance");
121 return -11111.;
122 }
123
124 double fpt = (secVertex.position() - pVertex->position()).perp();
125
126 if (fpt == 0.) {
127 ATH_MSG_WARNING("delta pt of (secVtx - priVtx) is 0!");
128 return -11111.;
129 }
130
131 double fpx = secVertex.position().x() - pVertex->position().x();
132 double fpy = secVertex.position().y() - pVertex->position().y();
133
134 double sigma_fpt2 = (fpx * fpx * secVertex.covariancePosition()(Trk::x, Trk::x) +
135 fpx * fpy * secVertex.covariancePosition()(Trk::x, Trk::y) +
136 fpy * fpx * secVertex.covariancePosition()(Trk::y, Trk::x) +
137 fpy * fpy * secVertex.covariancePosition()(Trk::y, Trk::y)) / (fpt * fpt);
138
139 if (sigma_fpt2 <= 0.) {
140 ATH_MSG_WARNING("sigma delta pt of (secVtx - priVtx) is 0!");
141 return -11111.;
142 }
143
144 double sign = (fpx * pTau.p4().Px() + fpy * pTau.p4().Py() > 0.) ? 1. : -1.;
145
146 return sign * fpt / std::sqrt(sigma_fpt2);
147}
148
149#endif
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
int sign(int a)
static const Attributes_t empty
const T * back() const
Access the last element in the collection as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
TauRecToolBase(const std::string &name)
bool inTrigger() const
virtual StatusCode executeVertexVariables(xAOD::TauJet &pTau, xAOD::VertexContainer &pVertexContainer) const override
double trFlightPathSig(const xAOD::TauJet &pTau, const xAOD::Vertex &secVertex) const
determines the transverse flight path significance from the primary vertex and the secondary vertex o...
ToolHandle< Trk::IVertexFitter > m_fitTool
TauVertexVariables(const std::string &name)
ToolHandle< Trk::IVertexSeedFinder > m_SeedFinder
virtual StatusCode initialize() override
Tool initializer.
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition TauJet_v3.cxx:96
void setSecondaryVertexLink(const VertexLink_t &vertexLink)
void setDetail(TauJetParameters::Detail detail, int value)
const Vertex * vertex() const
void setSecondaryVertex(const xAOD::VertexContainer *cont, const xAOD::Vertex *vertex)
size_t nTracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
std::vector< const TauTrack * > tracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
Get the v<const pointer> to a given tauTrack collection associated with this tau.
const Amg::Vector3D & position() const
Returns the 3-pos.
Eigen::Matrix< double, 3, 1 > Vector3D
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ x
Definition ParamDefs.h:55
@ y
Definition ParamDefs.h:56
ParametersBase< TrackParametersDim, Charged > TrackParameters
@ NotSpecified
Default value, no explicit type set.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
TauTrack_v1 TauTrack
Definition of the current version.
Definition TauTrack.h:16
TauJet_v3 TauJet
Definition of the current "tau version".