ATLAS Offline Software
Loading...
Searching...
No Matches
PhotonxAODHelpers.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include "xAODEgamma/Photon.h"
10
11
12#include<cmath>
13
14// ==================================================================
15
16bool xAOD::EgammaHelpers::isConvertedPhoton(const xAOD::Photon *ph, bool excludeTRT) {
17 if (!ph) return false;
18 return EgammaDetails::isConvertedPhoton(excludeTRT, ph->eta(), ph->nVertices(), conversionType(ph));
19}
20
25
28
29 const TrackParticle *trk1 = ( vx->nTrackParticles() ? vx->trackParticle(0) : nullptr );
30 const TrackParticle *trk2 = ( vx->nTrackParticles() > 1 ? vx->trackParticle(1) : nullptr );
31 uint8_t nSiHits1 = numberOfSiHits(trk1);
32 uint8_t nSiHits2 = numberOfSiHits(trk2);
33
34 return EgammaDetails::conversionType (trk1 != nullptr, trk2 != nullptr, nSiHits1, nSiHits2);
35}
36
37// ==================================================================
38
40 if (!ph || !ph->vertex()) {return 0;}
41 return numberOfSiTracks(ph->vertex());
42}
43
45 if (!vx) return 0;
47}
48
50 if (convType == xAOD::EgammaParameters::doubleSi) {return 2;}
51 if (convType == xAOD::EgammaParameters::singleSi ||
52 convType == xAOD::EgammaParameters::doubleSiTRT) {return 1;}
53 return 0;
54}
55
56// ==================================================================
57
59 if (!vx) return 9999.;
60 return sqrt( vx->x()*vx->x() + vx->y()*vx->y() );
61}
62
64 if (!ph || !ph->vertex()) return 9999.;
65 return conversionRadius(ph->vertex());
66}
67
68// ==================================================================
69
71 if (!photon || !photon->vertex()) return Amg::Vector3D(0., 0., 0.);
72 return momentumAtVertex(*photon->vertex(), debug);
73}
74
75
77
78 static const SG::AuxElement::Accessor<float> accPx("px");
79 static const SG::AuxElement::Accessor<float> accPy("py");
80 static const SG::AuxElement::Accessor<float> accPz("pz");
81
82 if (accPx.isAvailable(vertex) &&
83 accPy.isAvailable(vertex) &&
84 accPz.isAvailable(vertex))
85 {
86 return Amg::Vector3D(accPx(vertex),
87 accPy(vertex),
88 accPz(vertex));
89 }
90 if (debug){
91 std::cout << "Vertex not decorated with momentum" << std::endl;
92 }
93 return Amg::Vector3D(0., 0., 0.);
94}
95
96// ==================================================================
97std::set<const xAOD::TrackParticle*> xAOD::EgammaHelpers::getTrackParticles(const xAOD::Photon* ph,
98 bool useBremAssoc /* = true */){
99
100 std::set<const xAOD::TrackParticle*> tps;
101 if (!ph) return tps;
102 for (unsigned int ivx = 0; ivx < ph->nVertices(); ++ivx)
103 {
104 const xAOD::Vertex* vx = ph->vertex(ivx);
105 for (unsigned int i=0; vx && i < vx->nTrackParticles(); ++i){
106 const xAOD::TrackParticle *tp = vx->trackParticle(i);
107 tps.insert( useBremAssoc ? xAOD::EgammaHelpers::getOriginalTrackParticleFromGSF(tp) : tp );
108 }
109 }
110 return tps;
111}
112// ==================================================================
113std::vector<const xAOD::TrackParticle*> xAOD::EgammaHelpers::getTrackParticlesVec(const xAOD::Photon* ph,
114 bool useBremAssoc /* = true */){
115 std::vector<const xAOD::TrackParticle*> tps;
116 if (!ph) return tps;
117 for (unsigned int ivx = 0; ivx < ph->nVertices(); ++ivx)
118 {
119 const xAOD::Vertex* vx = ph->vertex(ivx);
120 for (unsigned int i=0; vx && i < vx->nTrackParticles(); ++i){
121 const xAOD::TrackParticle *tp = vx->trackParticle(i);
122 tps.push_back( useBremAssoc ? xAOD::EgammaHelpers::getOriginalTrackParticleFromGSF(tp) : tp );
123 }
124 }
125 return tps;
126}
Helper functions for EgammaDetails accessors.
const bool debug
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition Egamma_v1.cxx:71
size_t nVertices() const
Return the number xAOD::Vertex/vertices that match the photon candidate.
const xAOD::Vertex * vertex(size_t index=0) const
Pointer to the xAOD::Vertex/es that match the photon candidate.
Definition Photon_v1.cxx:61
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
const TrackParticle * trackParticle(size_t i) const
Get the pointer to a given track that was used in vertex reco.
float y() const
Returns the y position.
float x() const
Returns the x position.
Eigen::Matrix< double, 3, 1 > Vector3D
ConversionType conversionType(const bool hasTrk1, const bool hasTrk2, const std::uint8_t nSiHits1, const std::uint8_t nSiHits2)
return the photon conversion type (see EgammaEnums)
bool isConvertedPhoton(const bool excludeTRT, const float eta, const std::size_t nVertices, const ConversionType conversionType)
is the object a converted photon
std::size_t numberOfSiTracks(const xAOD::Photon *eg)
return the number of Si tracks in the conversion
std::vector< const xAOD::TrackParticle * > getTrackParticlesVec(const xAOD::Egamma *eg, bool useBremAssoc=true, bool allParticles=true)
Return a list of all or only the best TrackParticle associated to the object.
std::set< const xAOD::TrackParticle * > getTrackParticles(const xAOD::Egamma *eg, bool useBremAssoc=true, bool allParticles=true)
Return a list of all or only the best TrackParticle associated to the object.
bool isConvertedPhoton(const xAOD::Egamma *eg, bool excludeTRT=false)
is the object a converted photon
Amg::Vector3D momentumAtVertex(const xAOD::Photon *, bool debug=false)
return the momentum at the vertex (which can be 0)
xAOD::EgammaParameters::ConversionType conversionType(const xAOD::Photon *ph)
return the photon conversion type (see EgammaEnums)
const xAOD::TrackParticle * getOriginalTrackParticleFromGSF(const xAOD::TrackParticle *trkPar)
Helper function for getting the "Original" Track Particle (i.e before GSF) via the GSF Track Particle...
std::size_t numberOfSiHits(const xAOD::TrackParticle *tp)
return the number of Si hits in the track particle
float conversionRadius(const xAOD::Vertex *vx)
return the conversion radius or 9999.
@ singleSi
one track only, with Si hits
@ NumberOfVertexConversionTypes
maximum number of types
@ unconverted
unconverted photon
@ doubleSi
two tracks, both with Si hits
@ doubleSiTRT
two tracks, only one with Si hits
static const SG::AuxElement::Accessor< float > accPx("px")
static const SG::AuxElement::Accessor< float > accPy("py")
static const SG::AuxElement::Accessor< float > accPz("pz")
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.
Photon_v1 Photon
Definition of the current "egamma version".