ATLAS Offline Software
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 
9 
12 
13 #include "TauVertexVariables.h"
14 #include <memory>
15 
16 //-----------------------------------------------------------------------------
17 // Constructor
18 //-----------------------------------------------------------------------------
19 
22 }
23 
24 //-----------------------------------------------------------------------------
25 // Destructor
26 //-----------------------------------------------------------------------------
27 
29 }
30 
31 
32 //-----------------------------------------------------------------------------
33 // Initializer
34 //-----------------------------------------------------------------------------
35 
37 
38  ATH_CHECK( m_fitTool.retrieve() );
39  ATH_CHECK( m_SeedFinder.retrieve() );
40 
41  return StatusCode::SUCCESS;
42 }
43 
44 //-----------------------------------------------------------------------------
45 // Execution
46 //-----------------------------------------------------------------------------
48 
52 
53  // try to find secondary vertex if more than 1 track and the tau vertex is available
54  if ( pTau.nTracks() < 2 || pTau.vertex()==nullptr ) {
55  return StatusCode::SUCCESS;
56  }
57 
58  // xAOD TrackParticles
59  std::vector<const xAOD::TrackParticle*> xaodTracks;
60  // standard reconstruction uses Trk::Tracks in SeedFinder
61  std::vector<const Trk::Track*> origTracks;
62  // reconstruction from xAOD uses Trk::TrackParameters (Trk::Track not available)
63  std::vector<const Trk::TrackParameters*> origTrackParameters;
64 
65  for (const xAOD::TauTrack* track : pTau.tracks()) {
66  xaodTracks.push_back(track->track());
67 
68  if(track->track()->track()) {
69  origTracks.push_back(track->track()->track());
70  }
71  else {
72  const Trk::Perigee& perigee = track->track()->perigeeParameters();
73  origTrackParameters.push_back(static_cast<const Trk::TrackParameters*>(&perigee));
74  }
75  }
76 
77  // origTrackParameters should be empty in standard reconstruction, origTracks should be empty when re-running from xAOD
78  // cppcheck-suppress invalidLifetime
79  if(!origTracks.empty() && !origTrackParameters.empty()) {
80  ATH_MSG_ERROR("Inconsistent mix of Trk::Track and Trk::TrackParameter");
81  return StatusCode::FAILURE;
82  }
83 
84  xAOD::Vertex* xAODvertex = nullptr;
85 
86  if(!origTracks.empty()) {
87  // get the starting point for the fit using Trk::Tracks
88  const Amg::Vector3D& seedPoint = m_SeedFinder->findSeed(origTracks);
89  // fitting the vertex
90  xAODvertex = m_fitTool->fit(xaodTracks, seedPoint);
91  }
92  else if (!origTrackParameters.empty()) {
93  // get the starting point for the fit using Trk::TrackParameters
94  const Amg::Vector3D& seedPoint = m_SeedFinder->findSeed(origTrackParameters);
95  // fitting the vertex
96  xAODvertex = m_fitTool->fit(xaodTracks, seedPoint);
97  }
98 
99  if (!xAODvertex) {
100  ATH_MSG_WARNING("no secondary vertex found!");
101  return StatusCode::SUCCESS;
102  }
103 
104  // get the transverse flight path significance
105  double trFlightPS = trFlightPathSig(pTau, *xAODvertex);
106  pTau.setDetail(xAOD::TauJetParameters::trFlightPathSig, (float)(trFlightPS));
107  ATH_MSG_VERBOSE("transverse flight path significance="<<trFlightPS);
108 
109  // Note, we only attach the 2nd vertex if at offline, otherwise, break the trigger persistency
110  if (!inTrigger()) {
111  ATH_MSG_VERBOSE("secondary vertex recorded! x="<<xAODvertex->position().x()<< ", y="<<xAODvertex->position().y()<<", perp="<<xAODvertex->position().perp());
112  pSecVtxContainer.push_back(xAODvertex);
114  pTau.setSecondaryVertex(&pSecVtxContainer, xAODvertex);
115  }
116  else {
117  delete xAODvertex; // delete the vertex when in trigger mode, because we can not save it
118  }
119 
120  return StatusCode::SUCCESS;
121 }
122 
123 //-------------------------------------------------------------------------
124 // calculate the transverse flight path significance
125 //-------------------------------------------------------------------------
126 double TauVertexVariables::trFlightPathSig(const xAOD::TauJet& pTau, const xAOD::Vertex& secVertex) const {
127 
128  const xAOD::Vertex* pVertex = pTau.vertex();
129  if (pVertex==nullptr) {
130  ATH_MSG_WARNING("No primary vertex information for calculation of transverse flight path significance");
131  return -11111.;
132  }
133 
134  double fpt = (secVertex.position() - pVertex->position()).perp();
135 
136  if (fpt == 0.) {
137  ATH_MSG_WARNING("delta pt of (secVtx - priVtx) is 0!");
138  return -11111.;
139  }
140 
141  double fpx = secVertex.position().x() - pVertex->position().x();
142  double fpy = secVertex.position().y() - pVertex->position().y();
143 
144  double sigma_fpt2 = (fpx * fpx * secVertex.covariancePosition()(Trk::x, Trk::x) +
145  fpx * fpy * secVertex.covariancePosition()(Trk::x, Trk::y) +
146  fpy * fpx * secVertex.covariancePosition()(Trk::y, Trk::x) +
147  fpy * fpy * secVertex.covariancePosition()(Trk::y, Trk::y)) / (fpt * fpt);
148 
149  if (sigma_fpt2 <= 0.) {
150  ATH_MSG_WARNING("sigma delta pt of (secVtx - priVtx) is 0!");
151  return -11111.;
152  }
153 
154  double sign = (fpx * pTau.p4().Px() + fpy * pTau.p4().Py() > 0.) ? 1. : -1.;
155 
156  return sign * fpt / std::sqrt(sigma_fpt2);
157 }
158 
159 #endif
Trk::y
@ y
Definition: ParamDefs.h:56
TauVertexVariables::trFlightPathSig
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...
Definition: TauVertexVariables.cxx:126
TauVertexVariables::TauVertexVariables
TauVertexVariables(const std::string &name)
Definition: TauVertexVariables.cxx:20
xAOD::TauJetParameters::trFlightPathSig
@ trFlightPathSig
Definition: TauDefs.h:163
TauVertexVariables::initialize
virtual StatusCode initialize() override
Tool initializer.
Definition: TauVertexVariables.cxx:36
perp
Scalar perp() const
perp method - perpenticular length
Definition: AmgMatrixBasePlugin.h:44
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
xAOD::TauJet_v3::nTracks
size_t nTracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
Definition: TauJet_v3.cxx:526
TauRecToolBase
The base class for all tau tools.
Definition: TauRecToolBase.h:21
xAOD::Vertex_v1::position
const Amg::Vector3D & position() const
Returns the 3-pos.
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TauRecToolBase::inTrigger
bool inTrigger() const
Definition: TauRecToolBase.h:87
empty
bool empty(TH1 *h)
Definition: computils.cxx:295
xAOD::Vertex_v1::setVertexType
void setVertexType(VxType::VertexType vType)
Set the type of the vertex.
TauVertexVariables::m_SeedFinder
ToolHandle< Trk::IVertexSeedFinder > m_SeedFinder
Definition: TauVertexVariables.h:43
TauVertexVariables::~TauVertexVariables
~TauVertexVariables()
Definition: TauVertexVariables.cxx:28
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LinkToXAODTrackParticle.h
xAOD::TauJet_v3::setSecondaryVertex
void setSecondaryVertex(const xAOD::VertexContainer *cont, const xAOD::Vertex *vertex)
Definition: TauJet_v3.cxx:735
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TauJet_v3::setSecondaryVertexLink
void setSecondaryVertexLink(const VertexLink_t &vertexLink)
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
sign
int sign(int a)
Definition: TRT_StrawNeighbourSvc.h:107
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::ParametersBase
Definition: ParametersBase.h:55
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
TauVertexVariables.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
TauVertexVariables::m_fitTool
ToolHandle< Trk::IVertexFitter > m_fitTool
Definition: TauVertexVariables.h:42
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
xAOD::TauJet_v3::vertex
const Vertex * vertex() const
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::TauTrack_v1
Definition: TauTrack_v1.h:27
xAOD::TauJet_v3::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: TauJet_v3.cxx:97
xAOD::TauJet_v3::setDetail
void setDetail(TauJetParameters::Detail detail, int value)
Definition: TauJet_v3.cxx:337
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
Trk::x
@ x
Definition: ParamDefs.h:55
AdaptiveVertexFitter.h
xAOD::VxType::NotSpecified
@ NotSpecified
Default value, no explicit type set.
Definition: TrackingPrimitives.h:577
xAOD::TauJet_v3::tracks
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.
Definition: TauJet_v3.cxx:493
TrackParticleContainer.h
TauVertexVariables::executeVertexVariables
virtual StatusCode executeVertexVariables(xAOD::TauJet &pTau, xAOD::VertexContainer &pVertexContainer) const override
Definition: TauVertexVariables.cxx:47
TrackParticleContainer.h