ATLAS Offline Software
Loading...
Searching...
No Matches
xAOD::PVHelpers Namespace Reference

Functions

std::pair< float, floatgetZCommonAndError (const xAOD::EventInfo *eventInfo, const xAOD::EgammaContainer *egammas, float convPtCut=2e3)
 Return zCommon and zCommonError.
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)
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)
const xAOD::VertexgetHardestVertex (const xAOD::VertexContainer *vertices)
 Return vertex with highest sum pT^2.
TLorentzVector getTrackAtFirstMeasurement (const xAOD::TrackParticle *tp)
 Return track at first measurment, useful as proxy to conversion vertex pT.
bool passConvSelection (const xAOD::Photon *photon, float convPtCut=2e3)
 Check if photon is converted, and tracks have Si hits and pass selection.
bool passConvSelection (const xAOD::Vertex &conversionVertex, size_t i, float convPtCut)
 Check if track i of conversion vertex pass selection (Si hits and pt)

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}
@ PriVtx
Primary vertex.

◆ 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}
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
@ FirstMeasurement
Parameter defined at the position of the 1st measurement.

◆ 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}
Scalar eta() const
pseudorapidity method
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
setRcore setEtHad setFside pt
TrackParticle_v1 TrackParticle
Reference the current persistent version:

◆ 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}
constexpr int pow(int base, int exp) noexcept
Helper class to provide constant type-safe access to aux data.
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.

◆ 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}
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
elec/gamma data class.
Definition egamma.h:58
float beamPosZ() const
Z coordinate of the beam spot position.
float beamPosSigmaZ() const
The length of the beam spot in the Z direction.
@ zvertex
pointing z at vertex reconstructed from the cluster
@ errz
associated error on zvertex
@ Photon
The object is a photon.
Definition ObjectType.h:47
bool passConvSelection(const xAOD::Photon *photon, float convPtCut=2e3)
Check if photon is converted, and tracks have Si hits and pass selection.
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
Photon_v1 Photon
Definition of the current "egamma version".
#define CXXUTILS_TRAPPING_FP
Definition trapping_fp.h:24

◆ 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}
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Vertex_v1 Vertex
Define the latest version of the vertex class.

◆ 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}
const TrackParticle * trackParticle(size_t i) const
Get the pointer to a given track that was used in vertex reco.
Amg::Vector3D momentumAtVertex(const xAOD::Photon *, bool debug=false)
return the momentum at the vertex (which can be 0)
std::size_t numberOfSiHits(const xAOD::TrackParticle *tp)
return the number of Si hits in the track particle