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"
14
15#include "HepPDT/ParticleData.hh"
16#include "HepPDT/ParticleDataTable.hh"
17
18#include <atomic>
19#include <string>
20#include <vector>
21#include <map>
22#include <cmath> //for std::abs
23#include <stdexcept>
24#include <stdlib.h>
25#include <cstdio>
26#include <iostream>
27
29
30class GenData {
31public:
32
33 GenData() { };
34
35 virtual ~GenData() { }
36
37private:
39 const HepPDT::ParticleData* particleData(int pid) const {
40 if (!m_initialized) {
41 if (m_ppSvc.retrieve().isFailure()) {
42 std::cerr<< "GenData: failed to retrieve PartPropSvc\n";
43 std::abort();
44 }
45 m_initialized = true;
46 }
47 const int absPid = std::abs(pid);
48 return m_ppSvc->PDT()->particle(HepPDT::ParticleID(absPid));
49 }
50public:
51
52 std::optional<double> particleMass(int pdgId) const {
53 const HepPDT::ParticleData* particle = particleData(std::abs(pdgId));
54 return particle ? std::optional<double>{particle->mass().value()} : std::nullopt;
55 }
56
57 std::optional<double> particleLifetime(int pdgId) const {
58 const HepPDT::ParticleData* particle = particleData(std::abs(pdgId));
59 return particle ? std::optional<double>{particle->lifetime()} : std::nullopt;
60 }
61
62 std::optional<std::string> particleName(int pdgId) const {
63 const HepPDT::ParticleData* particle = particleData(std::abs(pdgId));
64 return particle ? std::optional<std::string>{particle->name()} : std::nullopt;
65 }
66
67private:
68
70 ServiceHandle<IPartPropSvc> m_ppSvc{"PartPropSvc", "GenData"};
71 mutable std::atomic<bool> m_initialized{false};
72
73};
74
75
76#endif
Helpers for checking error return status codes and reporting errors.
Property holding a SG store/key/clid from which a ReadHandle is made.
std::optional< std::string > particleName(int pdgId) const
Definition GenData.h:62
GenData()
Definition GenData.h:33
std::optional< double > particleMass(int pdgId) const
Definition GenData.h:52
virtual ~GenData()
Definition GenData.h:35
ServiceHandle< IPartPropSvc > m_ppSvc
Handle on the particle property service.
Definition GenData.h:70
const HepPDT::ParticleData * particleData(int pid) const
Access an element in the particle data table.
Definition GenData.h:39
std::optional< double > particleLifetime(int pdgId) const
Definition GenData.h:57
std::atomic< bool > m_initialized
Definition GenData.h:71