ATLAS Offline Software
Loading...
Searching...
No Matches
GenData.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "GaudiKernel/ServiceHandle.h"
7#include "GaudiKernel/IPartPropSvc.h"
8#include "HepPDT/ParticleData.hh"
9#include "HepPDT/ParticleDataTable.hh"
10#include <atomic>
11#include <iostream>
12#include <cmath>
13#include <cstdlib>
14#include <mutex>
15GenData::GenData(): m_service_name("PartPropSvc"), m_name("GenData"), m_ppSvc("PartPropSvc", "GenData") {}
16
17GenData::GenData(const std::string& sname, const std::string& name): m_service_name(sname), m_name(name), m_ppSvc(sname, name) {}
18
20
21 if (!m_initialized) {
22 if (m_ppSvc.retrieve().isFailure()) {
23 std::cerr << "GenData: failed to retrieve IPartPropSvc(" << m_service_name << ", " << m_name << ")\n";
24 std::abort();
25 }
26 m_initialized = true;
27 }
28
29 ParticleInfo info;
30 if (const HepPDT::ParticleData* particle = m_ppSvc->PDT()->particle(HepPDT::ParticleID(absPid))) {
31 info.mass = particle->mass().value();
32 info.lifetime = particle->lifetime();
33 info.name = particle->name();
34 }
35 return info;
36}
37
38std::optional<double> GenData::particleMass(int pdgId) const {
39 return particleInfo(std::abs(pdgId)).mass;
40}
41
42std::optional<double> GenData::particleLifetime(int pdgId) const {
43 return particleInfo(std::abs(pdgId)).lifetime;
44}
45
46std::optional<std::string> GenData::particleName(int pdgId) const {
47 return particleInfo(std::abs(pdgId)).name;
48}
std::string m_name
Definition GenData.h:47
ParticleInfo particleInfo(int absPid) const
Definition GenData.cxx:19
std::optional< std::string > particleName(int pdgId) const
Get the name of a particle by PDG ID.
Definition GenData.cxx:46
GenData()
Definition GenData.cxx:15
std::optional< double > particleMass(int pdgId) const
Get the mass of a particle by PDG ID.
Definition GenData.cxx:38
ServiceHandle< IPartPropSvc > m_ppSvc
Definition GenData.h:48
std::optional< double > particleLifetime(int pdgId) const
Get the lifetime of a particle by PDG ID.
Definition GenData.cxx:42
std::string m_service_name
Handle on the particle property service.
Definition GenData.h:46
std::atomic< bool > m_initialized
Definition GenData.h:49
std::optional< double > lifetime
Definition GenData.h:40
std::optional< double > mass
Definition GenData.h:39
std::optional< std::string > name
Definition GenData.h:41