ATLAS Offline Software
PhotonxAODHelpers.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "xAODEgamma/Photon.h"
8 #include "xAODTracking/Vertex.h"
9 
10 
11 #include<cmath>
12 
13 // ==================================================================
14 
15 bool xAOD::EgammaHelpers::isConvertedPhoton(const xAOD::Photon *ph, bool excludeTRT){
16 
17  bool isConv = ph && (ph->nVertices()>0);
18  if(excludeTRT) {
20  bool isNewConv = isConv && (std::abs(ph->eta()) > 0.8 || !isTRTConv);
21  return isNewConv;
22  }
23  return isConv;
24 }
25 
28  return conversionType(ph->vertex());
29 }
30 
33 
34  const TrackParticle *trk1 = ( vx->nTrackParticles() ? vx->trackParticle(0) : nullptr );
35  const TrackParticle *trk2 = ( vx->nTrackParticles() > 1 ? vx->trackParticle(1) : nullptr );
36  uint8_t nSiHits1 = numberOfSiHits(trk1);
37  uint8_t nSiHits2 = numberOfSiHits(trk2);
38 
39  if (!trk1) {return xAOD::EgammaParameters::unconverted;}
40 
41  if (!trk2)
43 
44  if (nSiHits1 && nSiHits2){
46  }
47  if (nSiHits1 || nSiHits2){
49  }
50  else{
52  }
53 }
54 
55 // ==================================================================
56 
58  if (!ph || !ph->vertex()) {return 0;}
59  return numberOfSiTracks(ph->vertex());
60 }
61 
63  if (!vx) return 0;
64  return numberOfSiTracks(conversionType(vx));
65 }
66 
68  if (convType == xAOD::EgammaParameters::doubleSi) {return 2;}
69  if (convType == xAOD::EgammaParameters::singleSi ||
70  convType == xAOD::EgammaParameters::doubleSiTRT) {return 1;}
71  return 0;
72 }
73 
74 // ==================================================================
75 
77  if (!vx) return 9999.;
78  return sqrt( vx->x()*vx->x() + vx->y()*vx->y() );
79 }
80 
82  if (!ph || !ph->vertex()) return 9999.;
83  return conversionRadius(ph->vertex());
84 }
85 
86 // ==================================================================
87 
89  if (!photon || !photon->vertex()) return Amg::Vector3D(0., 0., 0.);
90  return momentumAtVertex(*photon->vertex(), debug);
91 }
92 
93 
95 
96  static const SG::AuxElement::Accessor<float> accPx("px");
97  static const SG::AuxElement::Accessor<float> accPy("py");
98  static const SG::AuxElement::Accessor<float> accPz("pz");
99 
100  if (accPx.isAvailable(vertex) &&
101  accPy.isAvailable(vertex) &&
102  accPz.isAvailable(vertex))
103  {
104  return Amg::Vector3D(accPx(vertex),
105  accPy(vertex),
106  accPz(vertex));
107  }
108  if (debug){
109  std::cout << "Vertex not decorated with momentum" << std::endl;
110  }
111  return Amg::Vector3D(0., 0., 0.);
112 }
113 
114 // ==================================================================
115 std::set<const xAOD::TrackParticle*> xAOD::EgammaHelpers::getTrackParticles(const xAOD::Photon* ph,
116  bool useBremAssoc /* = true */){
117 
118  std::set<const xAOD::TrackParticle*> tps;
119  if (!ph) return tps;
120  for (unsigned int ivx = 0; ivx < ph->nVertices(); ++ivx)
121  {
122  const xAOD::Vertex* vx = ph->vertex(ivx);
123  for (unsigned int i=0; vx && i < vx->nTrackParticles(); ++i){
124  const xAOD::TrackParticle *tp = vx->trackParticle(i);
125  tps.insert( useBremAssoc ? xAOD::EgammaHelpers::getOriginalTrackParticleFromGSF(tp) : tp );
126  }
127  }
128  return tps;
129 }
130 // ==================================================================
131 std::vector<const xAOD::TrackParticle*> xAOD::EgammaHelpers::getTrackParticlesVec(const xAOD::Photon* ph,
132  bool useBremAssoc /* = true */){
133  std::vector<const xAOD::TrackParticle*> tps;
134  if (!ph) return tps;
135  for (unsigned int ivx = 0; ivx < ph->nVertices(); ++ivx)
136  {
137  const xAOD::Vertex* vx = ph->vertex(ivx);
138  for (unsigned int i=0; vx && i < vx->nTrackParticles(); ++i){
139  const xAOD::TrackParticle *tp = vx->trackParticle(i);
140  tps.push_back( useBremAssoc ? xAOD::EgammaHelpers::getOriginalTrackParticleFromGSF(tp) : tp );
141  }
142  }
143  return tps;
144 }
xAOD::EgammaParameters::unconverted
@ unconverted
unconverted photon
Definition: EgammaEnums.h:270
xAOD::Photon_v1::nVertices
size_t nVertices() const
Return the number xAOD::Vertex/vertices that match the photon candidate.
xAOD::Vertex_v1::x
float x() const
Returns the x position.
xAOD::Vertex_v1::nTrackParticles
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Definition: Vertex_v1.cxx:270
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
ElectronxAODHelpers.h
ParticleTest.tp
tp
Definition: ParticleTest.py:25
xAOD::EgammaHelpers::getTrackParticles
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.
Definition: EgammaxAODHelpers.cxx:120
xAOD::EgammaParameters::ConversionType
ConversionType
Definition: EgammaEnums.h:268
xAOD::EgammaHelpers::getTrackParticlesVec
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.
Definition: EgammaxAODHelpers.cxx:141
xAOD::EgammaHelpers::numberOfSiTracks
std::size_t numberOfSiTracks(const xAOD::Photon *eg)
return the number of Si tracks in the conversion
Definition: PhotonxAODHelpers.cxx:57
xAOD::EgammaHelpers::isConvertedPhoton
bool isConvertedPhoton(const xAOD::Egamma *eg, bool excludeTRT=false)
is the object a converted photon
Definition: EgammaxAODHelpers.cxx:25
lumiFormat.i
int i
Definition: lumiFormat.py:85
Photon.h
xAOD::EgammaHelpers::momentumAtVertex
Amg::Vector3D momentumAtVertex(const xAOD::Photon *, bool debug=false)
return the momentum at the vertex (which can be 0)
Definition: PhotonxAODHelpers.cxx:88
xAOD::EgammaParameters::doubleSi
@ doubleSi
two tracks, both with Si hits
Definition: EgammaEnums.h:279
PhotonxAODHelpers.h
xAOD::Vertex_v1::trackParticle
const TrackParticle * trackParticle(size_t i) const
Get the pointer to a given track that was used in vertex reco.
Definition: Vertex_v1.cxx:249
Vertex.h
xAOD::EgammaParameters::doubleSiTRT
@ doubleSiTRT
two tracks, only one with Si hits
Definition: EgammaEnums.h:285
xAOD::EgammaParameters::singleTRT
@ singleTRT
one track only, no Si hits (TRT only)
Definition: EgammaEnums.h:276
xAOD::EgammaParameters::singleSi
@ singleSi
one track only, with Si hits
Definition: EgammaEnums.h:273
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
xAOD::EgammaHelpers::conversionRadius
float conversionRadius(const xAOD::Vertex *vx)
return the conversion radius or 9999.
Definition: PhotonxAODHelpers.cxx:76
xAOD::EgammaHelpers::getOriginalTrackParticleFromGSF
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...
Definition: ElectronxAODHelpers.cxx:22
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
xAOD::EgammaHelpers::numberOfSiHits
std::size_t numberOfSiHits(const xAOD::TrackParticle *tp)
return the number of Si hits in the track particle
Definition: ElectronxAODHelpers.cxx:66
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::photon
@ photon
Definition: TrackingPrimitives.h:199
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
xAOD::Photon_v1
Definition: Photon_v1.h:37
xAOD::Vertex_v1::y
float y() const
Returns the y position.
xAOD::EgammaHelpers::conversionType
xAOD::EgammaParameters::ConversionType conversionType(const xAOD::Photon *ph)
return the photon conversion type (see EgammaEnums)
Definition: PhotonxAODHelpers.cxx:26
SG::ConstAccessor< T, AuxAllocator_t< T > >::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
xAOD::Egamma_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: Egamma_v1.cxx:70
xAOD::EgammaParameters::doubleTRT
@ doubleTRT
two tracks, none with Si hits (TRT only)
Definition: EgammaEnums.h:282
xAOD::EgammaParameters::NumberOfVertexConversionTypes
@ NumberOfVertexConversionTypes
maximum number of types
Definition: EgammaEnums.h:288
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
xAOD::Photon_v1::vertex
const xAOD::Vertex * vertex(size_t index=0) const
Pointer to the xAOD::Vertex/es that match the photon candidate.
Definition: Photon_v1.cxx:46