ATLAS Offline Software
Functions
xAOD::PVHelpers Namespace Reference

Functions

std::pair< float, floatgetZCommonAndError (const xAOD::EventInfo *eventInfo, const xAOD::EgammaContainer *egammas, float convPtCut=2e3)
 Return zCommon and zCommonError. More...
 
float getVertexSumPt (const xAOD::Vertex *vertex, int power=1, bool useAux=true)
 Loop over track particles associated with vertex and return scalar sum of pT^power in GeV (from auxdata if available and useAux = true) More...
 
TLorentzVector getVertexMomentum (const xAOD::Vertex *vertex, bool useAux=true, const std::string &derivationPrefix="")
 Return vector sum of tracks associated with vertex (from auxdata if available and useAux = true) More...
 
const xAOD::VertexgetHardestVertex (const xAOD::VertexContainer *vertices)
 Return vertex with highest sum pT^2. More...
 
TLorentzVector getTrackAtFirstMeasurement (const xAOD::TrackParticle *tp)
 Return track at first measurment, useful as proxy to conversion vertex pT. More...
 
bool passConvSelection (const xAOD::Photon *photon, float convPtCut=2e3)
 Check if photon is converted, and tracks have Si hits and pass selection. More...
 
bool passConvSelection (const xAOD::Vertex &conversionVertex, size_t i, float convPtCut)
 Check if track i of conversion vertex pass selection (Si hits and pt) More...
 

Function Documentation

◆ getHardestVertex()

const xAOD::Vertex * xAOD::PVHelpers::getHardestVertex ( const xAOD::VertexContainer vertices)

Return vertex with highest sum pT^2.

Definition at line 29 of file PhotonVertexHelpers.cxx.

30 {
31  // Check PV collection
32 
33  // Check for primary vertex in collection
34  for (const auto* vertex : *vertices) {
35  if (vertex->vertexType() == xAOD::VxType::VertexType::PriVtx)
36  return vertex;
37  }
38 
39  return nullptr;
40 }

◆ getTrackAtFirstMeasurement()

TLorentzVector xAOD::PVHelpers::getTrackAtFirstMeasurement ( const xAOD::TrackParticle tp)

Return track at first measurment, useful as proxy to conversion vertex pT.

Definition at line 150 of file PhotonVertexHelpers.cxx.

151 {
152 
153  static const SG::AuxElement::ConstAccessor<std::vector<float>> accParameterPX(
154  "parameterPX");
155  static const SG::AuxElement::ConstAccessor<std::vector<float>> accParameterPY(
156  "parameterPY");
157 
158  TLorentzVector v;
159  v.SetPtEtaPhiM(tp->pt(), tp->eta(), tp->phi(), 0.);
160  if (!accParameterPX.isAvailable(*tp) || !accParameterPY.isAvailable(*tp)) {
161  return v;
162  }
163 
164  for (unsigned int i = 0; i < accParameterPX(*tp).size(); ++i) {
165  if (tp->parameterPosition(i) == xAOD::FirstMeasurement) {
166  v.SetPxPyPzE(accParameterPX(*tp)[i], accParameterPY(*tp)[i], 0, 0);
167  return v;
168  }
169  }
170  return v;
171 }

◆ getVertexMomentum()

TLorentzVector xAOD::PVHelpers::getVertexMomentum ( const xAOD::Vertex vertex,
bool  useAux = true,
const std::string &  derivationPrefix = "" 
)

Return vector sum of tracks associated with vertex (from auxdata if available and useAux = true)

Definition at line 175 of file PhotonVertexHelpers.cxx.

178 {
179  TLorentzVector v;
180 
181  SG::AuxElement::ConstAccessor<float> pt(derivationPrefix + "pt");
182  SG::AuxElement::ConstAccessor<float> eta(derivationPrefix + "eta");
183  SG::AuxElement::ConstAccessor<float> phi(derivationPrefix + "phi");
184 
185  if (useAux and pt.isAvailable(*vertex) and eta.isAvailable(*vertex) and phi.isAvailable(*vertex)) {
186  // protect against decoreated nan values (from Rel24 on?)
187  if(!std::isnan(pt(*vertex)) and !std::isnan(eta(*vertex)) and !std::isnan(phi(*vertex))){
188  v.SetPtEtaPhiM(pt(*vertex), eta(*vertex), phi(*vertex), 0.0);
189  return v;
190  }
191  else{
192  using namespace asg::msgUserCode;
193  ANA_MSG_WARNING("PhotonVertexHelpers::getVertexMomentum : "
194  << "NaN detected in Vertex decorations (pt, eta, phi) = "
195  << " (" << pt(*vertex) << ", " << eta(*vertex) << ", " << phi(*vertex) << ")");
196  ANA_MSG_WARNING("PhotonVertexHelpers::getVertexMomentum : "
197  << "Recompute sum tracks 4-momenta from associated TrackParticles");
198  }
199  }
200 
201  // Sum the 4-momenta of all track particles at the vertex
202  const xAOD::TrackParticle* tp = nullptr;
203  for (size_t i = 0; i < vertex->nTrackParticles(); ++i) {
204  tp = vertex->trackParticle(i);
205  if (tp == nullptr) {
206  continue; // protect against thinned tracks
207  }
208  v += tp->p4();
209  }
210  return v;
211 }

◆ getVertexSumPt()

float xAOD::PVHelpers::getVertexSumPt ( const xAOD::Vertex vertex,
int  power = 1,
bool  useAux = true 
)

Loop over track particles associated with vertex and return scalar sum of pT^power in GeV (from auxdata if available and useAux = true)

Definition at line 215 of file PhotonVertexHelpers.cxx.

216 {
217 
218  std::string pw = (power == 1) ? "sumPt" : Form("sumPt%d", power);
220  if (useAux and acc.isAvailable(*vertex))
221  return acc(*vertex);
222 
223  // Loop over all track particles, sum up their pt
224  float pt = 0.0;
225  const xAOD::TrackParticle* tp = nullptr;
226  for (size_t i = 0; i < vertex->nTrackParticles(); ++i) {
227  tp = vertex->trackParticle(i);
228  if (tp == nullptr)
229  continue; // protect against slimmed tracks
230 
231  pt += pow(tp->pt() / 1e3, power);
232  }
233  return pt;
234 }

◆ getZCommonAndError()

std::pair< float, float > xAOD::PVHelpers::getZCommonAndError ( const xAOD::EventInfo eventInfo,
const xAOD::EgammaContainer egammas,
float  convPtCut = 2e3 
)

Return zCommon and zCommonError.

Definition at line 44 of file PhotonVertexHelpers.cxx.

47 {
48  // Static accessors
49  static const SG::AuxElement::Accessor<float> zvertex("zvertex");
50  static const SG::AuxElement::Accessor<float> errz("errz");
51  static const SG::AuxElement::Accessor<float> HPV_zvertex("HPV_zvertex");
52  static const SG::AuxElement::Accessor<float> HPV_errz("HPV_errz");
53 
54  // Clear values
55  float zCommon = 0.0, zCommonError = 0.0;
56 
57  // Beam position is the base for zCommon weighted average
58  double beamPosZ = eventInfo->beamPosZ();
59  double beamPosSigmaZ = eventInfo->beamPosSigmaZ();
60 
61  if( beamPosSigmaZ == 0 )
62  beamPosSigmaZ = 10;
63 
64  zCommon = beamPosZ / beamPosSigmaZ / beamPosSigmaZ;
65  zCommonError = 1.0 / beamPosSigmaZ / beamPosSigmaZ;
66 
67  // Include z-position pointed at by egammas
68  for (const xAOD::Egamma* egamma : *egammas) {
69  if (egamma == nullptr) {
70  continue;
71  }
72 
73  const xAOD::Photon* photon = nullptr;
74  if (egamma->type() == xAOD::Type::Photon)
75  photon = dynamic_cast<const xAOD::Photon*>(egamma);
76 
77  if (photon && passConvSelection(photon, convPtCut)) {
78  if (!HPV_zvertex.isAvailable(*photon) || !HPV_errz.isAvailable(*photon)) {
79  continue;
80  }
81  if (HPV_errz(*photon) == 0.0) {
82  continue;
83  }
84  zCommon += HPV_zvertex(*photon) / HPV_errz(*photon) / HPV_errz(*photon);
85  zCommonError += 1.0 / HPV_errz(*photon) / HPV_errz(*photon);
86  } else {
87  if (!zvertex.isAvailable(*egamma) || !errz.isAvailable(*egamma)) {
88  continue;
89  }
90  if (errz(*egamma) == 0.0) {
91  continue;
92  }
93  zCommon += zvertex(*egamma) / errz(*egamma) / errz(*egamma);
94  zCommonError += 1.0 / errz(*egamma) / errz(*egamma);
95  }
96  }
97 
98  // Normalize by error (weighted average)
99  {
100  // Tell clang to optimize assuming that FP exceptions can trap.
101  // Otherwise, it can vectorize these divisions, which can lead to
102  // spurious division-by-zero traps from unused vector lanes.
104  zCommon /= zCommonError;
105  zCommonError = 1.0 / sqrt(zCommonError);
106  }
107 
108  return std::make_pair(zCommon, zCommonError);
109 }

◆ passConvSelection() [1/2]

bool xAOD::PVHelpers::passConvSelection ( const xAOD::Photon photon,
float  convPtCut = 2e3 
)

Check if photon is converted, and tracks have Si hits and pass selection.

Definition at line 133 of file PhotonVertexHelpers.cxx.

134 {
135  const xAOD::Vertex* conversionVertex = photon->vertex();
136  if (conversionVertex == nullptr)
137  return false;
138 
139  size_t NumberOfTracks = conversionVertex->nTrackParticles();
140  for (size_t i = 0; i < NumberOfTracks; ++i) {
141  if (passConvSelection(*conversionVertex, i, convPtCut))
142  return true;
143  }
144 
145  return false;
146 }

◆ passConvSelection() [2/2]

bool xAOD::PVHelpers::passConvSelection ( const xAOD::Vertex conversionVertex,
size_t  i,
float  convPtCut 
)

Check if track i of conversion vertex pass selection (Si hits and pt)

Definition at line 113 of file PhotonVertexHelpers.cxx.

116 {
117  const xAOD::TrackParticle* tp = conversionVertex.trackParticle(i);
118 
120  return false;
121  // pt1,pt2 is only set for 2-track vertices
122  if (conversionVertex.nTrackParticles() == 1)
123  return xAOD::EgammaHelpers::momentumAtVertex(conversionVertex).perp() >
124  convPtCut;
125 
126  std::string s = Form("pt%lu", i + 1);
128  return (acc.withDefault(conversionVertex, 0) > convPtCut);
129 }
CXXUTILS_TRAPPING_FP
#define CXXUTILS_TRAPPING_FP
Definition: trapping_fp.h:24
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
xAOD::Vertex_v1::nTrackParticles
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Definition: Vertex_v1.cxx:270
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
egammaParameters::zvertex
@ zvertex
pointing z at vertex reconstructed from the cluster
Definition: egammaParamDefs.h:270
test_pyathena.pt
pt
Definition: test_pyathena.py:11
ParticleTest.tp
tp
Definition: ParticleTest.py:25
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
egamma
Definition: egamma.h:58
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
lumiFormat.i
int i
Definition: lumiFormat.py:92
xAOD::FirstMeasurement
@ FirstMeasurement
Parameter defined at the position of the 1st measurement.
Definition: TrackingPrimitives.h:213
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:292
xAOD::EventInfo_v1::beamPosSigmaZ
float beamPosSigmaZ() const
The length of the beam spot in the Z direction.
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
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:81
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
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
xAOD::EventInfo_v1::beamPosZ
float beamPosZ() const
Z coordinate of the beam spot position.
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
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
python.PyAthena.v
v
Definition: PyAthena.py:157
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
egammaParameters::errz
@ errz
associated error on zvertex
Definition: egammaParamDefs.h:272
xAOD::PVHelpers::passConvSelection
bool passConvSelection(const xAOD::Photon *photon, float convPtCut=2e3)
Check if photon is converted, and tracks have Si hits and pass selection.
Definition: PhotonVertexHelpers.cxx:133
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43