ATLAS Offline Software
Loading...
Searching...
No Matches
TauVertexVariables.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef XAOD_ANALYSIS
6
8
9//-----------------------------------------------------------------------------
10// Constructor
11//-----------------------------------------------------------------------------
12
14 TauRecToolBase(name) {}
15
16//-----------------------------------------------------------------------------
17// Destructor
18//-----------------------------------------------------------------------------
19
21
22
23//-----------------------------------------------------------------------------
24// Initializer
25//-----------------------------------------------------------------------------
26
28
29 ATH_CHECK( m_fitTool.retrieve() );
30 ATH_CHECK( m_SeedFinder.retrieve() );
31
32 return StatusCode::SUCCESS;
33}
34
35//-----------------------------------------------------------------------------
36// Execution
37//-----------------------------------------------------------------------------
39
43
44 // try to find secondary vertex if more than 1 track and the tau vertex is available
45 if ( pTau.nTracks() < 2 || pTau.vertex()==nullptr ) {
46 return StatusCode::SUCCESS;
47 }
48
49 // xAOD TrackParticles
50 std::vector<const xAOD::TrackParticle*> xaodTracks;
51 // standard reconstruction uses Trk::Tracks in SeedFinder
52 std::vector<const Trk::Track*> origTracks;
53 // reconstruction from xAOD uses Trk::TrackParameters (Trk::Track not available)
54 std::vector<const Trk::TrackParameters*> origTrackParameters;
55
56 for (const xAOD::TauTrack* track : pTau.tracks()) {
57 xaodTracks.push_back(track->track());
58
59 if(track->track()->track()) {
60 origTracks.push_back(track->track()->track());
61 }
62 else {
63 const Trk::Perigee& perigee = track->track()->perigeeParameters();
64 origTrackParameters.push_back(static_cast<const Trk::TrackParameters*>(&perigee));
65 }
66 }
67
68 // origTrackParameters should be empty in standard reconstruction, origTracks should be empty when re-running from xAOD
69 // cppcheck-suppress invalidLifetime
70 if(!origTracks.empty() && !origTrackParameters.empty()) {
71 ATH_MSG_ERROR("Inconsistent mix of Trk::Track and Trk::TrackParameter");
72 return StatusCode::FAILURE;
73 }
74
75 xAOD::Vertex* xAODvertex = nullptr;
76
77 if(!origTracks.empty()) {
78 // get the starting point for the fit using Trk::Tracks
79 const Amg::Vector3D& seedPoint = m_SeedFinder->findSeed(origTracks);
80 // fitting the vertex
81 xAODvertex = m_fitTool->fit(xaodTracks, seedPoint);
82 }
83 else if (!origTrackParameters.empty()) {
84 // get the starting point for the fit using Trk::TrackParameters
85 const Amg::Vector3D& seedPoint = m_SeedFinder->findSeed(origTrackParameters);
86 // fitting the vertex
87 xAODvertex = m_fitTool->fit(xaodTracks, seedPoint);
88 }
89
90 if (!xAODvertex) {
91 ATH_MSG_WARNING("no secondary vertex found!");
92 return StatusCode::SUCCESS;
93 }
94
95 // get the transverse flight path significance
96 double trFlightPS = trFlightPathSig(pTau, *xAODvertex);
97 pTau.setDetail(xAOD::TauJetParameters::trFlightPathSig, static_cast<float>(trFlightPS));
98 ATH_MSG_VERBOSE("transverse flight path significance="<<trFlightPS);
99
100 // Note, we only attach the 2nd vertex if at offline, otherwise, break the trigger persistency
101 if (!inTrigger()) {
102 ATH_MSG_VERBOSE("secondary vertex recorded! x="<<xAODvertex->position().x()<< ", y="<<xAODvertex->position().y()<<", perp="<<xAODvertex->position().perp());
103 pSecVtxContainer.push_back(xAODvertex);
105 pTau.setSecondaryVertex(&pSecVtxContainer, xAODvertex);
106 }
107 else {
108 delete xAODvertex; // delete the vertex when in trigger mode, because we can not save it
109 }
110
111 return StatusCode::SUCCESS;
112}
113
114//-------------------------------------------------------------------------
115// calculate the transverse flight path significance
116//-------------------------------------------------------------------------
117double TauVertexVariables::trFlightPathSig(const xAOD::TauJet& pTau, const xAOD::Vertex& secVertex) const {
118
119 const xAOD::Vertex* pVertex = pTau.vertex();
120 if (pVertex==nullptr) {
121 ATH_MSG_WARNING("No primary vertex information for calculation of transverse flight path significance");
122 return -11111.;
123 }
124
125 double fpt = (secVertex.position() - pVertex->position()).perp();
126
127 if (fpt == 0.) {
128 ATH_MSG_WARNING("delta pt of (secVtx - priVtx) is 0!");
129 return -11111.;
130 }
131
132 double fpx = secVertex.position().x() - pVertex->position().x();
133 double fpy = secVertex.position().y() - pVertex->position().y();
134
135 double sigma_fpt2 = (fpx * fpx * secVertex.covariancePosition()(Trk::x, Trk::x) +
136 fpx * fpy * secVertex.covariancePosition()(Trk::x, Trk::y) +
137 fpy * fpx * secVertex.covariancePosition()(Trk::y, Trk::x) +
138 fpy * fpy * secVertex.covariancePosition()(Trk::y, Trk::y)) / (fpt * fpt);
139
140 if (sigma_fpt2 <= 0.) {
141 ATH_MSG_WARNING("sigma delta pt of (secVtx - priVtx) is 0!");
142 return -11111.;
143 }
144
145 double sign = (fpx * pTau.p4().Px() + fpy * pTau.p4().Py() > 0.) ? 1. : -1.;
146
147 return sign * fpt / std::sqrt(sigma_fpt2);
148}
149
150#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
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.
void setVertexType(VxType::VertexType vType)
Set the type of the vertex.
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".