Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_particleInfo.cc
Go to the documentation of this file.
1/*
2# <<BEGIN-copyright>>
3# Copyright 2019, Lawrence Livermore National Security, LLC.
4# This file is part of the gidiplus package (https://github.com/LLNL/gidiplus).
5# gidiplus is licensed under the MIT license (see https://opensource.org/licenses/MIT).
6# SPDX-License-Identifier: MIT
7# <<END-copyright>>
8*/
9
10#include "GIDI.hpp"
11
12namespace GIDI {
13
14/*! \class ParticleInfo
15 * This class stores an abridged set of particle information from PoPI::Database as needed by GIDI.
16 *
17 * Note, the stored mass does not include the mass associated with nuclear excitation energy. This addition mass is
18 * store in m_excitationEnergy.
19 */
20
21/* *********************************************************************************************************//**
22 * @param a_ID [in] The particle's PoPs ID.
23 * @param a_pid [in] The same as *a_id* unless particle is an alias, then the final particle's id.
24 * @param a_mass [in] The particle's groud state mass. For nuclide and nucleus, this is the
25 * @param a_excitationEnergy [in] The particle's nuclear excitation energy.
26 ***********************************************************************************************************/
27
28ParticleInfo::ParticleInfo( std::string const &a_ID, std::string const &a_pid, double a_mass, double a_excitationEnergy ) :
29 m_id( ParticleInfo::IDPortion( a_ID ) ),
30 m_qualifier( ParticleInfo::qualifierPortion( a_ID ) ),
31 m_pid( a_pid ),
32 m_mass( a_mass, "amu" ),
33 m_excitationEnergy( a_excitationEnergy, "MeV" ) {
34
35}
36
37/* *********************************************************************************************************//**
38 * @param a_ID [in] The particle's PoPs ID.
39 * @param a_pops [in] A PoPI::Database instance used to get particle indices and possibly other particle information.
40 * @param a_internalPoPs [in] The internal PoPI::Database instance used to get particle indices and possibly other particle information.
41 * This is the <**PoPs**> node under the <**reactionSuite**> node.
42 * @param a_requiredInGlobalPoPs [in] If *true*, the ID must be in *a_pops*.
43 ***********************************************************************************************************/
44
45ParticleInfo::ParticleInfo( std::string const &a_ID, PoPI::Database const &a_pops, PoPI::Database const &a_internalPoPs, bool a_requiredInGlobalPoPs ) :
46 m_id( ParticleInfo::IDPortion( a_ID ) ),
47 m_qualifier( ParticleInfo::qualifierPortion( a_ID ) ),
48 m_pid( "" ),
49 m_mass( -1, "amu" ),
50 m_excitationEnergy( 0, "MeV" ) {
51
52 PoPI::Base const *particleOrAlias = nullptr; // Need to get the mass and nuclear excitation energy. Favor from internal PoPs if present.
53 std::string energyUnit( "MeV" );
54
55 if( a_pops.exists( m_id ) ) {
56 particleOrAlias = &a_pops.get<PoPI::Base>( m_id );
57 if( particleOrAlias->isAlias( ) ) {
58 PoPI::Alias const *alias = static_cast<PoPI::Alias const *>( particleOrAlias );
59 particleOrAlias = &a_pops.get<PoPI::Base>( alias->pid( ) );
60 }
61 m_pid = particleOrAlias->ID( ); }
62 else {
63 if( a_requiredInGlobalPoPs ) throw Exception( "ParticleInfo::ParticleInfo: required particle ID not in global PoPs: " + m_id );
64 }
65
66 if( a_internalPoPs.exists( m_id ) ) {
67 particleOrAlias = &a_internalPoPs.get<PoPI::Base>( m_id );
68 if( particleOrAlias->isAlias( ) ) {
69 PoPI::Alias const *alias = static_cast<PoPI::Alias const *>( particleOrAlias );
70 particleOrAlias = &a_pops.get<PoPI::Base>( alias->pidIndex( ) );
71 }
72 }
73
74 if( particleOrAlias == nullptr ) throw Exception( "ParticleInfo::ParticleInfo: particle ID not in global PoPs: " + m_id );
75
76 if( particleOrAlias->isParticle( ) ) {
77 PoPI::Particle const &particle = static_cast<PoPI::Particle const &>( *particleOrAlias );
78
79 try {
80 m_mass = PhysicalQuantity( particle.massValue( "amu" ), "amu" ); }
81 catch (...) {
82 m_mass = PhysicalQuantity( -1, "amu" );
83 }
84
85 if( particle.isNuclide( ) ) {
86 PoPI::Nuclide const &nuclide = static_cast<PoPI::Nuclide const &>( particle );
87
88 m_excitationEnergy = PhysicalQuantity( nuclide.levelEnergy( energyUnit ), energyUnit );
89 }
90 }
91}
92
93/* *********************************************************************************************************//**
94 * Copy constructor for ParticleInfo.
95 *
96 * @param a_particleInfo [in] ParticleInfo instance to copy.
97 ***********************************************************************************************************/
98
99ParticleInfo::ParticleInfo( ParticleInfo const &a_particleInfo ) :
100 m_id( a_particleInfo.ID( ) ),
101 m_qualifier( a_particleInfo.qualifier( ) ),
102 m_pid( a_particleInfo.pid( ) ),
103 m_mass( a_particleInfo.mass( ) ),
104 m_excitationEnergy( a_particleInfo.excitationEnergy( ) ) {
105
106}
107
108/* *********************************************************************************************************//**
109 * The assignment operator. This method sets the members of *this* to those of *a_rhs* except for those
110 * not set by base classes.
111 *
112 * @param a_rhs [in] Instance whose member are used to set the members of *this*.
113 ***********************************************************************************************************/
114
116
117 if( this != &a_rhs ) {
118 m_id = a_rhs.ID( );
119 m_qualifier = a_rhs.qualifier( );
120 m_pid = a_rhs.pid( );
121 m_mass = a_rhs.mass( );
122 m_excitationEnergy = a_rhs.excitationEnergy( );
123 }
124
125 return( *this );
126}
127
128/* *********************************************************************************************************//**
129 * Returns the particle's actual mass (i.e., its *m_mass* plus *m_excitationEnergy*) in unit of *a_unit*.
130 *
131 * @param a_unit [in] The requested unit for the returned mass.
132 *
133 * @return The mass in unit of *a_unit*.
134 ***********************************************************************************************************/
135
136double ParticleInfo::mass( LUPI_maybeUnused std::string const &a_unit ) const {
137
138 return( PoPI_AMU2MeV_c2 * m_mass.value( ) );
139}
140
141/* *********************************************************************************************************//**
142 * This static method returns the non-qualifier portion of a particle's id. For example, for the id "Th232{1s1/2}",
143 * the string "Th232" is returned.
144 *
145 * @param a_ID [in] The id's whose non-qualifier portion is to be returned.
146 *
147 * @return The non-qualifier portion of the particle's id.
148 ***********************************************************************************************************/
149
150std::string const ParticleInfo::IDPortion( std::string const &a_ID ) {
151
152 std::string::size_type index1 = a_ID.find( "{" );
153
154 std::string ID( a_ID, 0, index1 );
155 return( ID );
156}
157/* *********************************************************************************************************//**
158 * This static method returns the qualifier portion of a particle's id. For example, for the id "Th232{1s1/2}",
159 * the string "1s1/2" is returned.
160 *
161 * @param a_ID [in] The id's whose qualifier portion is to be returned.
162 *
163 * @return The non-qualifier portion of the particle's id.
164 ***********************************************************************************************************/
165
166std::string const ParticleInfo::qualifierPortion( std::string const &a_ID ) {
167
168 std::string::size_type index1 = a_ID.find( "{" );
169
170 std::string qualifier( "" );
171 if( index1 == std::string::npos ) return( qualifier );
172
173 std::string::size_type index2 = a_ID.find( "}" );
174 qualifier = std::string( a_ID, index1 + 1, index2 - index1 - 1 );
175
176 return( qualifier );
177}
178
179} // End of namespace GIDI.
#define LUPI_maybeUnused
#define PoPI_AMU2MeV_c2
Definition PoPI.hpp:30
PhysicalQuantity const & mass() const
Definition GIDI.hpp:765
std::string const & pid() const
Definition GIDI.hpp:762
PhysicalQuantity const & excitationEnergy() const
Definition GIDI.hpp:766
std::string const & qualifier() const
Definition GIDI.hpp:761
ParticleInfo & operator=(ParticleInfo const &a_rhs)
std::string const & ID() const
Definition GIDI.hpp:760
static std::string const qualifierPortion(std::string const &a_id)
static std::string const IDPortion(std::string const &a_id)
ParticleInfo(std::string const &a_id, std::string const &a_pid, double a_mass, double a_excitationEnergy=0.0)
double value() const
Definition GIDI.hpp:728
bool isAlias(void) const
Definition PoPI.hpp:658
bool isNuclide() const
Definition PoPI.hpp:668
virtual bool isParticle() const
Definition PoPI.hpp:657
std::string const & ID(void) const
Definition PoPI.hpp:652
T const & get(std::string const &a_id) const
bool exists(std::string const &a_id) const
virtual double massValue(char const *a_unit) const
Definition GIDI.hpp:32