Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 28 of file PhotonVertexHelpers.cxx.

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

◆ getTrackAtFirstMeasurement()

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

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

Definition at line 149 of file PhotonVertexHelpers.cxx.

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

◆ 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 174 of file PhotonVertexHelpers.cxx.

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

◆ 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 214 of file PhotonVertexHelpers.cxx.

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

◆ 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 43 of file PhotonVertexHelpers.cxx.

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

◆ 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 132 of file PhotonVertexHelpers.cxx.

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

◆ 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 112 of file PhotonVertexHelpers.cxx.

115 {
116  const xAOD::TrackParticle* tp = conversionVertex.trackParticle(i);
117 
119  return false;
120  // pt1,pt2 is only set for 2-track vertices
121  if (conversionVertex.nTrackParticles() == 1)
122  return xAOD::EgammaHelpers::momentumAtVertex(conversionVertex).perp() >
123  convPtCut;
124 
125  std::string s = Form("pt%lu", i + 1);
127  return (acc.withDefault(conversionVertex, 0) > convPtCut);
128 }
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:67
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
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:55
egamma
Definition: egamma.h:58
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
lumiFormat.i
int i
Definition: lumiFormat.py:85
xAOD::FirstMeasurement
@ FirstMeasurement
Parameter defined at the position of the 1st measurement.
Definition: TrackingPrimitives.h:214
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:292
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:572
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:89
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::EgammaHelpers::numberOfSiHits
std::size_t numberOfSiHits(const xAOD::TrackParticle *tp)
return the number of Si hits in the track particle
Definition: ElectronxAODHelpers.cxx:66
columnar::ContainerId::eventInfo
@ eventInfo
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:154
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::photon
@ photon
Definition: TrackingPrimitives.h:200
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:132
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15