Execute method.
105 {
106 SG::ReadHandle<xAOD::VertexContainer> vertices(
m_vertexInKey, ctx);
108
109 SG::ReadHandle<xAOD::PhotonContainer> photonsIn(
m_photonsInKey, ctx);
111
114 SG::ReadHandle<xAOD::MuonContainer> muonsIn(
m_muonsInKey, ctx);
116 SG::ReadHandle<xAOD::JetContainer> jetsIn(
m_jetsInKey, ctx);
118 SG::ReadHandle<xAOD::EventInfo> eventInfo(
m_eventInKey,ctx);
120
121 SG::WriteDecorHandle<xAOD::VertexContainer, std::vector<ElementLink<xAOD::PhotonContainer>>> dec_photonLinks(
m_photonLinksKey, ctx);
122 SG::WriteDecorHandle<xAOD::VertexContainer, std::vector<ElementLink<xAOD::JetContainer>>> dec_jetLinks(
m_jetLinksKey, ctx);
123 SG::WriteDecorHandle<xAOD::VertexContainer, std::vector<ElementLink<xAOD::ElectronContainer>>> dec_electronLinks(
m_electronLinksKey, ctx);
124 SG::WriteDecorHandle<xAOD::VertexContainer, std::vector<ElementLink<xAOD::MuonContainer>>> dec_muonLinks(
m_muonLinksKey, ctx);
125 SG::WriteDecorHandle<xAOD::VertexContainer, std::vector<ElementLink<xAOD::CompositeParticleContainer>>> dec_multiPhotonLinks(
m_multiPhotonLinksKey, ctx);
126
127 SG::ReadDecorHandle<xAOD::VertexContainer, float> acc_deltaZ(
m_deltaZKey, ctx);
128 SG::ReadDecorHandle<xAOD::VertexContainer, float> acc_deltaPhi(
m_deltaPhiKey, ctx);
129 SG::ReadDecorHandle<xAOD::PhotonContainer, float> acc_caloPointingZ(
m_caloPointingZKey, ctx);
130 SG::ReadDecorHandle<xAOD::PhotonContainer, float> acc_zCommon(
m_zCommonKey, ctx);
131 SG::ReadDecorHandle<xAOD::PhotonContainer, float> acc_zCommonError(
m_zCommonErrorKey, ctx);
132
133 SG::WriteDecorHandle<xAOD::VertexContainer, float> dec_gnnScore(
m_mDecor_gnnScore,ctx);
134
135
136 SG::WriteDecorHandle<xAOD::VertexContainer, int> dec_ntrk(
m_mDecor_ntrk, ctx);
137 SG::WriteDecorHandle<xAOD::VertexContainer, float> dec_sumPt(
m_mDecor_sumPt,ctx);
139 SG::WriteDecorHandle<xAOD::VertexContainer, float> dec_z_asym(
m_mDecor_z_asym,ctx);
142 SG::WriteDecorHandle<xAOD::VertexContainer, float> dec_z_skew(
m_mDecor_z_skew,ctx);
147 SG::WriteDecorHandle<xAOD::VertexContainer, int> dec_nMuons(
m_mDecor_nMuons,ctx);
148 SG::WriteDecorHandle<xAOD::VertexContainer, int> dec_nJets(
m_mDecor_nJets,ctx);
149 SG::WriteDecorHandle<xAOD::VertexContainer, int> dec_nPhotons(
m_mDecor_nPhotons,ctx);
151
152 auto mpCont = std::make_unique<xAOD::CompositeParticleContainer>();
153 auto mpAux = std::make_unique<xAOD::CompositeParticleAuxContainer>();
154 mpCont->setStore(mpAux.get());
155
158 bool haveMP = false;
159
160
161 const bool haveZCommonDecor = acc_zCommon.isAvailable() && acc_zCommonError.isAvailable();
162 const bool haveCaloPointingDecor = acc_caloPointingZ.isAvailable();
163
164 if (photonsIn->size() > 1 && (!haveZCommonDecor || !haveCaloPointingDecor))
165 {
166 ATH_MSG_ERROR(
"photonsIn has size > 1 but required decorations are missing: "
169 return StatusCode::FAILURE;
170 }
171
172 if (photonsIn->size() > 1)
173 {
174
175 double sumW = 0.0;
176 double sumWZ = 0.0;
177
178 TLorentzVector p4sum;
179 int nUsed = 0;
181 {
182 const float zCommon = acc_zCommon(*ph);
183 const float zCaloPointing = acc_caloPointingZ(*ph);
184
185 const bool useZCommonValue = std::isfinite(zCommon);
186 const float z = useZCommonValue ? zCommon : zCaloPointing;
187 if (!std::isfinite(
z)) {
188 ATH_MSG_ERROR(
"Non-finite photon pointing values found in both "
190 return StatusCode::FAILURE;
191 }
192
193
194
196 if (useZCommonValue) {
197 const float s = acc_zCommonError(*ph);
198 if (std::isfinite(s) && s > 0.0f)
w = 1.0 / (
double(s) *
double(s));
199 }
200
203 p4sum += ph->p4();
204 ++nUsed;
205 }
206
207 if (nUsed > 1 && sumW > 0.0)
208 {
209 const float zPoint = sumWZ / sumW;
210
211
212 float bestAbsDZ = 1e30;
214 {
216
217 const float dz = zPoint - vtx->z();
218 const float adz = std::abs(dz);
219 if (adz < bestAbsDZ)
220 {
221 bestAbsDZ = adz;
222 bestVtxForMP = vtx;
223 }
224 }
225
226 if (bestVtxForMP)
227 {
228
230 mpCont->push_back(mp);
231
232 mp->setP4(p4sum);
233
234 SG::AuxElement::Decorator<float> dec_mp_deltaZ("deltaZ");
235 SG::AuxElement::Decorator<float> dec_mp_deltaPhi("deltaPhi");
236 SG::AuxElement::Decorator<int> dec_mp_nPhotons("nPhotons");
237 SG::AuxElement::Decorator<float> dec_mp_zPointing("zPointing");
238
239 const float deltaZ = zPoint - bestVtxForMP->
z();
240 dec_mp_deltaZ(*mp) =
deltaZ;
241 dec_mp_zPointing(*mp) = zPoint;
242 dec_mp_nPhotons(*mp) = static_cast<int>(photonsIn->size());
243
244 float dphi = 0.0f;
245 if (acc_deltaPhi.isAvailable())
246 {
247 dphi = acc_deltaPhi(*bestVtxForMP);
248 if (!std::isfinite(dphi)) dphi = 0.0f;
249 }
250 dec_mp_deltaPhi(*mp) = dphi;
253
254 haveMP = true;
255 }
256 }
257 }
258
259
260 ATH_CHECK(mpHandle.record(std::move(mpCont), std::move(mpAux)));
261
262 std::map< const xAOD::Vertex*, std::vector<ElementLink<xAOD::JetContainer>> > jetsInVertex;
263 std::map< const xAOD::Jet*, std::map< const xAOD::Vertex*, int> > jetVertexPt;
264
265
267 jetsInVertex[
vertex] = {};
269 jetVertexPt[jet][
vertex] = 0;
270 }
271 }
272
273
275
276
279 if( !jtrk ) continue;
281 if(jetTrackVertex) jetVertexPt[jet][*jetTrackVertex] += jtrk->pt();
282 }
283
284
285 float maxPtFrac = -1;
289 if(jetVertexPt[jet][vertex] > maxPtFrac){
290 maxPtFrac = jetVertexPt[jet][
vertex];
291 uniqueVertexAddress =
vertex;
292 }
293 }
294
295
296 ElementLink<xAOD::JetContainer> jetLink;
299 jetsInVertex[uniqueVertexAddress].push_back(jetLink);
300 }
301
303 {
305 continue;
306
307 if (
vertex->nTrackParticles() < 2)
308 continue;
309
310 dec_actualInterPerXing(*vertex) = eventInfo->actualInteractionsPerCrossing();
311
312
313 float z_asym = 0;
314 float sumDZ = 0;
316 float modsumDZ = 0;
317 float weighted_sumDZ = 0;
318 float weighted_deltaZ = 0;
319 float weighted_modsumDZ = 0;
320 float weighted_z_asym = 0;
321
322
323 std::vector<float> track_deltaZ;
324
325 for (
size_t i = 0;
i <
vertex->nTrackParticles();
i++) {
326
328
329 if(!trackTmp) continue;
330
332 track_deltaZ.push_back(deltaZ);
333
334 float trk_weight =
vertex->trackWeight(i);
335 weighted_deltaZ =
deltaZ * trk_weight;
336
338 modsumDZ += std::abs(deltaZ);
339 weighted_sumDZ += weighted_deltaZ;
340 weighted_modsumDZ += std::abs(weighted_deltaZ);
341 }
342
343 if (modsumDZ > 0) {
344 z_asym = sumDZ / modsumDZ;
345 }
346 if (weighted_modsumDZ > 0) {
347 weighted_z_asym = weighted_sumDZ / weighted_modsumDZ;
348 }
349
350 const float number_tracks = track_deltaZ.size();
351 const float mean_Dz =
352 number_tracks > 0 ? sumDZ / number_tracks : 0.F;
353
354 float z_skew = 0;
355 float z_kurt = 0;
356 float z_var = 0;
357
358 for (auto i : track_deltaZ)
359 {
360 float z_zbar = (
i - mean_Dz);
361 z_var += std::pow(z_zbar, 2);
362 z_skew += std::pow(z_zbar, 3);
363 z_kurt += std::pow(z_zbar, 4);
364 }
365 if (number_tracks > 1 && z_var > 0) {
366 z_var /= (number_tracks - 1);
367 float z_sd = std::sqrt(z_var);
368 const float skew_denom = (number_tracks - 1) * std::pow(z_sd, 3);
369 const float kurt_denom = (number_tracks - 1) * std::pow(z_sd, 4);
370 if (std::isfinite(skew_denom) && skew_denom != 0.F) {
371 z_skew /= skew_denom;
372 } else {
373 z_skew = 0.F;
374 }
375 if (std::isfinite(kurt_denom) && kurt_denom != 0.F) {
376 z_kurt /= kurt_denom;
377 } else {
378 z_kurt = 0.F;
379 }
380 }
381 else
382 {
384 z_skew = 0.;
385 z_kurt = 0.;
386 }
387
388 dec_ntrk(*vertex) = number_tracks;
389
390 if(!dec_sumPt.isAvailable()){
392 }
393 const float numberDoF =
vertex->numberDoF();
394 dec_chi2Over_ndf(*vertex) =
395 numberDoF > 0.F ?
vertex->chiSquared() / numberDoF : 0.F;
396 dec_z_asym(*vertex) = z_asym;
397 dec_weighted_z_asym(*vertex) = weighted_z_asym;
398 dec_z_kurt(*vertex) = z_kurt;
399 dec_z_skew(*vertex) = z_skew;
400
401 if (acc_deltaZ.isAvailable() && photonsIn->size() > 0 ) {
402
403 if (!std::isfinite(acc_deltaZ(*vertex))) {
405 dec_photon_deltaz(*vertex) = -1;
406 }
407 else{
408 dec_photon_deltaz(*vertex) = acc_deltaZ(*vertex);
409 }
410 }
411 else{
412 dec_photon_deltaz(*vertex) = -1;
413 }
414 if (acc_deltaPhi.isAvailable() && photonsIn->size() > 0) {
415
416 if (!std::isfinite(acc_deltaPhi(*vertex))) {
418 dec_photon_deltaPhi(*vertex) = -1;
419 }
420 else{
421 dec_photon_deltaPhi(*vertex) = acc_deltaPhi(*vertex);
422 }
423 }
424 else{
425 dec_photon_deltaPhi(*vertex) = -1;
426 }
427
428
429 auto countValid = [](
const auto&
links) ->
int {
431 for (
const auto& l : links)
if (
l.isValid()) ++
n;
433 };
434
435 std::vector<ElementLink<xAOD::ElectronContainer>> electronLinks;
438 if(!id_trk) continue;
440 if(!eleVertex) continue;
441 ElementLink<xAOD::ElectronContainer> elLink;
442 if(*eleVertex == vertex){
445 electronLinks.push_back(elLink);
446 }
447 }
448 dec_electronLinks(*vertex) = electronLinks;
449 dec_nElectrons(*vertex) = countValid(electronLinks);
450
451 std::vector<ElementLink<xAOD::PhotonContainer>> photonLinks;
453 ElementLink<xAOD::PhotonContainer> phLink;
456 photonLinks.push_back(phLink);
457 }
458 dec_photonLinks(*vertex) = photonLinks;
459 dec_nPhotons(*vertex) = countValid(photonLinks);
460
461
462 std::vector<ElementLink<xAOD::CompositeParticleContainer>> mpLinks;
463 if (haveMP && vertex == bestVtxForMP)
464 {
465 mpLinks.push_back(mpLink);
466 }
467 dec_multiPhotonLinks(*vertex) = mpLinks;
468
469
470 dec_jetLinks(*vertex) = jetsInVertex[
vertex];
471 dec_nJets(*vertex) = countValid(jetsInVertex[vertex]);
472
473 std::vector<ElementLink<xAOD::MuonContainer>> muonLinks;
475 const auto *tp =
muon->trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
476 if(!tp) continue;
477 try{
479 if(!muonVertex) continue;
480 ElementLink<xAOD::MuonContainer> muonLink;
481 if(*muonVertex == vertex){
484 muonLinks.push_back(muonLink);
485 }
486 }catch(...) {
487 ATH_MSG_DEBUG(
"Skipping muon as the track is not associated to any PV ");
489 }
490
491 }
492 dec_muonLinks(*vertex) = muonLinks;
493 dec_nMuons(*vertex) = countValid(muonLinks);
494
495
496 float score_phsvertex =
m_gnnTool->decorate(*vertex);
497
498 dec_gnnScore(*vertex) = score_phsvertex;
499 }
500
501 return StatusCode::SUCCESS;
502 }
#define ATH_CHECK
Evaluate an expression and check for errors.
ElementLink()
Default constructor.
#define ATH_MSG_WARNING(x)
bool setElement(ElementType element)
Set link to point to an Element (slowest).
bool setStorableObject(BaseConstReference data, bool replace=false)
Set link storable to data object pointed by data (slower).
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_mDecor_gnnScore
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_mDecor_photon_deltaPhi
ToolHandle< GNNTool > m_gnnTool
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_mDecor_z_skew
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_muonLinksKey
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_mDecor_sumPt
SG::WriteHandleKey< xAOD::CompositeParticleContainer > m_multiPhotonsOutKey
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_mDecor_nJets
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_mDecor_chi2Over_ndf
SG::ReadDecorHandleKey< xAOD::VertexContainer > m_deltaZKey
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_photonLinksKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muonsInKey
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_mDecor_weighted_z_asym
SG::ReadDecorHandleKey< xAOD::PhotonContainer > m_zCommonKey
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_electronLinksKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInKey
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_mDecor_ntrk
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_mDecor_nElectrons
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_mDecor_actualInterPerXing
ToolHandle< CP::TrackVertexAssociationTool > m_trkVtxAssociationTool
SG::ReadDecorHandleKey< xAOD::VertexContainer > m_deltaPhiKey
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_mDecor_weighted_z_kurt
SG::ReadDecorHandleKey< xAOD::PhotonContainer > m_zCommonErrorKey
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_mDecor_photon_deltaz
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_mDecor_nPhotons
SG::ReadDecorHandleKey< xAOD::PhotonContainer > m_caloPointingZKey
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_multiPhotonLinksKey
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_mDecor_z_asym
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_mDecor_nMuons
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexInKey
SG::ReadHandleKey< xAOD::PhotonContainer > m_photonsInKey
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_jetLinksKey
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronsInKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetsInKey
float z0() const
Returns the parameter.
float vz() const
The z origin for the parameters.
float z() const
Returns the z position.
l
Printing final latex table to .tex output file.
const xAOD::TrackParticle * getOriginalTrackParticle(const xAOD::Electron *el)
Helper function for getting the "Original" Track Particle (i.e before GSF) via the electron.
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...
@ NoVtx
Dummy vertex. TrackParticle was not used in vertex fit.
Jet_v1 Jet
Definition of the current "jet version".
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.
CompositeParticle_v1 CompositeParticle
Define the latest version of the composite particle class.
Muon_v1 Muon
Reference the current persistent version:
Photon_v1 Photon
Definition of the current "egamma version".
Electron_v1 Electron
Definition of the current "egamma version".