ATLAS Offline Software
Loading...
Searching...
No Matches
TauAxisSetter.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
7#include "TauAxisSetter.h"
9
10TauAxisSetter::TauAxisSetter(const std::string& name) :
11TauRecToolBase(name) {}
12
14 const EventContext& /*ctx*/) const {
15
16 if (tau.jet() == nullptr) {
17 ATH_MSG_ERROR("Tau jet link is invalid.");
18 return StatusCode::FAILURE;
19 }
20
21 const xAOD::Jet* jetSeed = tau.jet();
22
23 // store all jet constituents p4 in a vector
24 std::vector<TLorentzVector> jet_const_vec;
25 // Barycenter is the sum of cluster p4 in the seed jet
26 TLorentzVector baryCenter;
27
28 xAOD::JetConstituentVector constituents = jetSeed->getConstituents();
29 for (TLorentzVector const_p4; const xAOD::JetConstituent* constituent : constituents) {
30 const_p4 = tauRecTools::GetConstituentP4(*constituent);
31 baryCenter += const_p4;
32 jet_const_vec.push_back(const_p4);
33 }
34
35 ATH_MSG_DEBUG("barycenter (eta, phi): " << baryCenter.Eta() << " " << baryCenter.Phi());
36
37 // Detector axis is the total p4 of clusters within m_clusterCone core of the barycenter
38 TLorentzVector tauDetectorAxis;
39
40 for (const auto& constituentP4 : jet_const_vec) {
41 if (baryCenter.DeltaR(constituentP4) > m_clusterCone) continue;
42 tauDetectorAxis += constituentP4;
43 }
44
45 if (tauDetectorAxis.Pt() == 0. && !m_doVertexCorrection) {
46 ATH_MSG_DEBUG("this tau candidate does not have any constituent clusters!");
47 return StatusCode::FAILURE;
48 }
49
50 ATH_MSG_DEBUG("detector axis:" << tauDetectorAxis.Pt()<< " " << tauDetectorAxis.Eta() << " " << tauDetectorAxis.Phi() << " " << tauDetectorAxis.E());
51 tau.setP4(tauDetectorAxis.Pt(), tauDetectorAxis.Eta(), tauDetectorAxis.Phi(), tau.m());
52 tau.setP4(xAOD::TauJetParameters::DetectorAxis, tauDetectorAxis.Pt(), tauDetectorAxis.Eta(), tauDetectorAxis.Phi(), tauDetectorAxis.M());
53
54
56 // Tau intermediate axis (corrected for tau vertex)
57 TLorentzVector tauInterAxis;
58
59 const xAOD::Vertex* jetVertex = tauRecTools::getJetVertex(*jetSeed);
60
61 // Redo the vertex correction when tau vertex is different from jet vertex
62 if (jetVertex != tau.vertex()) {
63
64 // If seed jet has a vertex, then tau must have one
65 if (tau.vertex() == nullptr) {
66 ATH_MSG_WARNING("The seed jet has a vertex, while the tau candidate does not. It should not happen.");
67 return StatusCode::FAILURE;
68 }
69
70 const xAOD::Vertex* tauVertex = tau.vertex();
71
72 // Relative position of the tau vertex and jet vertex
73 Amg::Vector3D position = tauVertex->position();
74 if (jetVertex != nullptr) {
75 position -= jetVertex->position();
76 }
77
78 // store all jet constituents p4 in a vector to avoid doing vertex correction twice
79 std::vector<TLorentzVector> jet_const_vec_vtxcorr;
80 // Barycenter at the tau vertex
81 TLorentzVector baryCenterTauVertex;
82
83 // Loop over the jet constituents, and calculate the barycenter using the four momentum
84 // corrected to point at tau vertex
85 for (TLorentzVector const_vtxcorr_p4; const xAOD::JetConstituent* constituent : constituents) {
86 const_vtxcorr_p4 = getVertexCorrectedP4(*constituent, position);
87 baryCenterTauVertex += const_vtxcorr_p4;
88 jet_const_vec_vtxcorr.push_back(const_vtxcorr_p4);
89 }
90 ATH_MSG_DEBUG("barycenter (eta, phi) at tau vertex: " << baryCenterTauVertex.Eta() << " " << baryCenterTauVertex.Phi());
91
92 // Tau intermediate axis is the four momentum (corrected to point at tau vertex) of clusters
93 // within m_clusterCone of the barycenter
94 for (const auto& constituent_vtxcorr_P4 : jet_const_vec_vtxcorr) {
95 if (baryCenterTauVertex.DeltaR(constituent_vtxcorr_P4) > m_clusterCone) continue;
96 tauInterAxis += constituent_vtxcorr_P4;
97 }
98 }
99 else {
100 tauInterAxis = tauDetectorAxis;
101 }
102
103 if (tauInterAxis.Pt() == 0.) {
104 ATH_MSG_DEBUG("this tau candidate does not have any constituent clusters!");
105 return StatusCode::FAILURE;
106 }
107
108 ATH_MSG_DEBUG("tau axis:" << tauInterAxis.Pt()<< " " << tauInterAxis.Eta() << " " << tauInterAxis.Phi() << " " << tauInterAxis.E() );
109 tau.setP4(tauInterAxis.Pt(), tauInterAxis.Eta(), tauInterAxis.Phi(), tau.m());
110 tau.setP4(xAOD::TauJetParameters::IntermediateAxis, tauInterAxis.Pt(), tauInterAxis.Eta(), tauInterAxis.Phi(), tauInterAxis.M());
111 } // End of m_doVertexCorrection
112
113 return StatusCode::SUCCESS;
114}
115
116
117
119 const Amg::Vector3D& position) const {
120 TLorentzVector vertexCorrectedP4;
121
122 if (constituent.type() == xAOD::Type::CaloCluster) {
123 const xAOD::CaloCluster* cluster = static_cast<const xAOD::CaloCluster*>(constituent.rawConstituent());
124 vertexCorrectedP4 = xAOD::CaloVertexedTopoCluster(*cluster, position).p4();;
125 }
126 else if ( constituent->type() == xAOD::Type::FlowElement ) {
127 const xAOD::FlowElement* fe = static_cast<const xAOD::FlowElement*>( constituent->rawConstituent() );
128 vertexCorrectedP4 = getVertexCorrectedP4(*fe, position);
129 }
130 else {
131 ATH_MSG_WARNING("Seed jet constituent type not supported, will not do vertex correction !");
132 vertexCorrectedP4 = tauRecTools::GetConstituentP4(constituent);
133 }
134
135 return vertexCorrectedP4;
136}
137
139 const Amg::Vector3D& position) const {
140
141 TLorentzVector vertexCorrectedP4;
142 // Only perfrom vertex corretion for neutral FlowElement
143 if (!fe.isCharged()) {
144 TVector3 pos(position.x(), position.y(), position.z());
145 vertexCorrectedP4 = FEHelpers::getVertexCorrectedFourVec(fe,pos);
146 }
147 else {
148 vertexCorrectedP4 = fe.p4();
149 }
150
151 ATH_MSG_DEBUG("Original fe four momentum, pt: " << fe.pt() <<
152 " eta: " << fe.eta() << " phi: " << fe.phi() << " e: " << fe.e());
153 ATH_MSG_DEBUG("Vertex corrected four momentum, pt: " << vertexCorrectedP4.Pt() <<
154 " eta: " << vertexCorrectedP4.Eta() << " phi: " << vertexCorrectedP4.Phi() << " e: " << vertexCorrectedP4.E());
155
156 return vertexCorrectedP4;
157
158}
159
160#endif
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
TLorentzVector getVertexCorrectedP4(const xAOD::JetConstituent &constituent, const Amg::Vector3D &position) const
Get the vertex corrected four momentum.
Gaudi::Property< bool > m_doVertexCorrection
virtual StatusCode executeTool(xAOD::TauJet &tau, const EventContext &ctx) const override
Execute - called for each tau candidate.
TauAxisSetter(const std::string &name)
Constructor.
Gaudi::Property< double > m_clusterCone
TauRecToolBase(const std::string &name)
virtual FourMom_t p4() const final
The full 4-momentum of the particle.
Evaluate cluster kinematics with a different vertex / signal state.
virtual double pt() const override
virtual double phi() const override
The azimuthal angle ( ) of the particle.
virtual double eta() const override
The pseudorapidity ( ) of the particle.
virtual double e() const override
The total energy of the particle.
virtual FourMom_t p4() const override
The full 4-momentum of the particle.
A vector of jet constituents at the scale used during jet finding.
4-vector of jet constituent at the scale used during jet finding.
Type::ObjectType type() const
The full 4-momentum of the particle.
const IParticle * rawConstituent() const
Access the real underlying IParticle.
JetConstituentVector getConstituents() const
Return a vector of consituents. The object behaves like vector<const IParticle*>. See JetConstituentV...
Definition Jet_v1.cxx:149
const Amg::Vector3D & position() const
Returns the 3-pos.
Eigen::Matrix< double, 3, 1 > Vector3D
TLorentzVector getVertexCorrectedFourVec(const xAOD::FlowElement &fe, const xAOD::Vertex &vertexToCorrectTo)
Definition FEHelpers.cxx:13
const xAOD::Vertex * getJetVertex(const xAOD::Jet &jet)
Return the vertex of jet candidate.
TLorentzVector GetConstituentP4(const xAOD::JetConstituent &constituent)
@ FlowElement
The object is a track-calo-cluster.
Definition ObjectType.h:52
@ CaloCluster
The object is a calorimeter cluster.
Definition ObjectType.h:39
Jet_v1 Jet
Definition of the current "jet version".
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition FlowElement.h:16
Vertex_v1 Vertex
Define the latest version of the vertex class.
TauJet_v3 TauJet
Definition of the current "tau version".
Definition TauJet.h:17