ATLAS Offline Software
Loading...
Searching...
No Matches
PhotonVertexHelpers.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Local includes
7
8// EDM includes
16
17// Asg tools
19
20// ROOT include(s).
21#include <TString.h>
22
23namespace xAOD {
24namespace PVHelpers {
25
26//__________________________________________________________________________
27const xAOD::Vertex*
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}
40
41//__________________________________________________________________________
42std::pair<float, float>
44 const xAOD::EgammaContainer* egammas,
45 float convPtCut)
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}
109
110//____________________________________________________________________________
111bool
112passConvSelection(const xAOD::Vertex& conversionVertex,
113 size_t i,
114 float convPtCut)
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}
129
130//____________________________________________________________________________
131bool
132passConvSelection(const xAOD::Photon* photon, float convPtCut)
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}
146
147//__________________________________________________________________________
148TLorentzVector
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}
171
172//__________________________________________________________________________
173TLorentzVector
175 bool useAux /* true */,
176 const std::string& derivationPrefix /* "" */)
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}
211
212//__________________________________________________________________________
213float
214getVertexSumPt(const xAOD::Vertex* vertex, int power, bool useAux /* = true */)
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}
234
235} // namespace PVHelpers
236} // namespace xAOD
Scalar eta() const
pseudorapidity method
Helper class to provide constant type-safe access to aux data.
macros for messaging and checking status codes
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
constexpr int pow(int base, int exp) noexcept
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
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.
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.
@ Photon
The object is a photon.
Definition ObjectType.h:47
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
TLorentzVector getTrackAtFirstMeasurement(const xAOD::TrackParticle *tp)
Return track at first measurment, useful as proxy to conversion vertex pT.
const xAOD::Vertex * getHardestVertex(const xAOD::VertexContainer *vertices)
Return vertex with highest sum pT^2.
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 auxda...
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)
bool passConvSelection(const xAOD::Photon *photon, float convPtCut=2e3)
Check if photon is converted, and tracks have Si hits and pass selection.
std::pair< float, float > getZCommonAndError(const xAOD::EventInfo *eventInfo, const xAOD::EgammaContainer *egammas, float convPtCut=2e3)
Return zCommon and zCommonError.
@ PriVtx
Primary vertex.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
setRcore setEtHad setFside pt
EventInfo_v1 EventInfo
Definition of the latest event info version.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
Photon_v1 Photon
Definition of the current "egamma version".
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.
EgammaContainer_v1 EgammaContainer
Definition of the current "egamma container version".
@ FirstMeasurement
Parameter defined at the position of the 1st measurement.
Tell the compiler to optimize assuming that FP may trap.
#define CXXUTILS_TRAPPING_FP
Definition trapping_fp.h:24