ATLAS Offline Software
Loading...
Searching...
No Matches
GenData.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef GENERATORMODULES_GENDATA_H
6#define GENERATORMODULES_GENDATA_H
7
9#include "GaudiKernel/ServiceHandle.h"
10#include "GaudiKernel/IPartPropSvc.h"
11#include "GaudiKernel/IIncidentSvc.h"
16
17#include "AtlasHepMC/GenEvent.h"
20
21#include "HepPDT/ParticleData.hh"
22#include "HepPDT/ParticleDataTable.hh"
23
24
25#include <atomic>
26#include <string>
27#include <vector>
28#include <map>
29#include <cmath> //for std::abs
30#include <stdexcept>
31#include <stdlib.h>
32#include <cstdio>
33#include <iostream>
36
37class GenData {
38public:
39
41
42
44 GenData() { };
45
47 virtual ~GenData() { }
48
50
52
53
56 return m_ppSvc;
57 }
58
60 const HepPDT::ParticleDataTable& particleTable() const {
61 if (!m_initialized) {
62 if (m_ppSvc.retrieve().isFailure()) {
63 std::cerr<< "GenData: failed to retrieve PartPropSvc\n";
64 std::abort();
65 }
66 m_initialized = true;
67 }
68 return *(m_ppSvc->PDT());
69 }
70
72 const HepPDT::ParticleDataTable& pdt() const { return particleTable(); }
73
75 const HepPDT::ParticleData* particleData(int pid) const {
76 return pdt().particle(HepPDT::ParticleID(std::abs(pid)));
77 }
78
79 std::optional<double> particleMass(int pdgId) const {
80 const HepPDT::ParticleData* particle = particleData(std::abs(pdgId));
81 if (!particle) {
82 return std::nullopt;
83 }
84 return particle->mass().value();
85 }
86
87 std::optional<double> particleLifetime(int pdgId) const {
88 const HepPDT::ParticleData* particle = particleData(std::abs(pdgId));
89 if (!particle) {
90 return std::nullopt;
91 }
92 return particle->lifetime();
93 }
94 std::optional<std::string> particleName(int pdgId) const {
95 const HepPDT::ParticleData* particle = particleData(std::abs(pdgId));
96 if (!particle) {
97 return std::nullopt;
98 }
99 return particle->name();
100 }
101
103
104
105
106private:
107
109 ServiceHandle<IPartPropSvc> m_ppSvc{"PartPropSvc", "GenData"};
110 mutable std::atomic<bool> m_initialized{false};
111
112};
113
114
115#endif
Helpers for checking error return status codes and reporting errors.
Property holding a SG store/key/clid from which a ReadHandle is made.
Define macros for attributes used to control the static checker.
const HepPDT::ParticleDataTable & particleTable() const
Get a particle data table.
Definition GenData.h:60
const ServiceHandle< IPartPropSvc > partPropSvc() const
Access the particle property service.
Definition GenData.h:55
std::optional< std::string > particleName(int pdgId) const
Definition GenData.h:94
GenData()
Constructor.
Definition GenData.h:44
std::optional< double > particleMass(int pdgId) const
Definition GenData.h:79
virtual ~GenData()
Virtual destructor.
Definition GenData.h:47
ServiceHandle< IPartPropSvc > m_ppSvc
Handle on the particle property service.
Definition GenData.h:109
const HepPDT::ParticleData * particleData(int pid) const
Access an element in the particle data table.
Definition GenData.h:75
std::optional< double > particleLifetime(int pdgId) const
Definition GenData.h:87
std::atomic< bool > m_initialized
Definition GenData.h:110
const HepPDT::ParticleDataTable & pdt() const
Shorter alias to get a particle data table.
Definition GenData.h:72