Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
PoPI_nucleus.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 <stdlib.h>
11#include <stdexcept>
12
13#include "PoPI.hpp"
14
15namespace PoPI {
16
17#define PoPI_energyChars "energy"
18
19/*! \class Nucleus
20 * This class represents **PoPs** nucleus instance.
21 */
22
23/* *********************************************************************************************************//**
24 * Constructor that parses an **HAPI** instance to create a **PoPs** nucleus node.
25 *
26 * @param a_node [in] The **HAPI::Node** to be parsed.
27 * @param a_DB [in] The **PoPI::Database:: instance to add the constructed **Nucleus** to.
28 * @param a_nuclide [in] This nuclide instance that will contain *this*.
29 ***********************************************************************************************************/
30
31Nucleus::Nucleus( HAPI::Node const &a_node, Database *a_DB, Nuclide *a_nuclide ) :
33 m_nuclide( a_nuclide ),
34 m_Z( a_nuclide->Z( ) ),
35 m_A( a_nuclide->A( ) ),
36 m_levelName( a_node.attribute( PoPI_indexChars ).value( ) ), // The string version of m_levelIndex.
37 m_levelIndex( a_node.attribute( PoPI_indexChars ).as_int( ) ), // The int version of m_levelName.
38 m_energy( a_node.child( PoPI_energyChars ) ) {
39
40 if( a_node.empty( ) ) throw Exception( "nuclide is missing nucleus" );
41
42 int sign = ( isAnti( ) ? -1 : 1 );
43 setIntid( sign * ( 1000 * ( 1000 * (levelIndex( ) + 500) + Z( ) ) + A( ) ) );
44
45 addToDatabase( a_DB );
46}
47
48/* *********************************************************************************************************//**
49 ***********************************************************************************************************/
50
54
55/* *********************************************************************************************************//**
56 * Returns the atomic ID of the parent nuclide.
57 *
58 * @return The atomic ID of the parent nuclide.
59 ***********************************************************************************************************/
60
61std::string const &Nucleus::atomsID( void ) const {
62
63 return( m_nuclide->atomsID( ) );
64}
65
66/* *********************************************************************************************************//**
67 * Returns the mass of the nucleus in units of *a_unit*. Currently not fully implement and does not support *a_unit*.
68 *
69 * @param a_unit [in] The unit to return the mass in.
70 *
71 * @return The mass in unit of *a_unit*.
72 ***********************************************************************************************************/
73
74double Nucleus::massValue( char const *a_unit ) const {
75
76 if( mass( ).size( ) > 0 ) {
77 PQ_double const *pq_mass = dynamic_cast<PQ_double const *>( mass( )[0] );
78
79 if( pq_mass == nullptr ) throw Exception( "Particle does not have a PoPI::PQ_double mass." );
80 return( pq_mass->value( a_unit ) );
81 }
82
83// FIXME: still need to correct for electron masses and binding energy. Currently, an approximation is done.
84 double bindingEnergy = 0.0;
85 if( m_Z == 1 ) {
86 bindingEnergy = 13.5981e-6; }
87 else if( m_Z == 2 ) {
88 bindingEnergy = 79.005e-6;
89 }
90
91 return( m_nuclide->massValue( a_unit ) - ( m_Z * PoPI_electronMass_MeV_c2 - bindingEnergy ) / PoPI_AMU2MeV_c2 );
92}
93
94/* *********************************************************************************************************//**
95 * Returns the excitation energy of the nucleus in units of *a_unit*. Currently not fully implement and does not support *a_unit*.
96 *
97 * @param a_unit [in] The unit to return the mass in.
98 *
99 * @return The mass in unit of *a_unit*.
100 ***********************************************************************************************************/
101
102double Nucleus::energy( std::string const &a_unit ) const {
103
104 if( m_energy.size( ) == 0 ) {
105 if( m_levelIndex != 0 )
106 std::cerr << std::endl << "Particle " << ID( ) << " missing energy node, please report to PoPs maintainer. Using 0.0 and continuing." << std::endl;
107 return( 0.0 );
108 }
109 PQ_double *pq = static_cast<PQ_double *>( m_energy[0] );
110 if( pq->unit( ) == "eV" ) return( pq->value( ) * 1e-6 ); // Kludge until units are functional.
111 return( pq->value( a_unit ) );
112}
113
114/* *********************************************************************************************************//**
115 * Returns the index attribute.
116 ***********************************************************************************************************/
117
118std::string Nucleus::toXMLListExtraAttributes( void ) const {
119
120 return( std::string( " index=\"" + m_levelName + "\"" ) );
121}
122
123/* *********************************************************************************************************//**
124 * Added the *m_energy* stuff to *a_XMLList*.
125 *
126 * @param a_XMLList [in] The list to add an XML output representation of *this* to.
127 * @param a_indent1 [in] The amount of indentation to added to each line added to *a_XMLList*.
128 ***********************************************************************************************************/
129
130void Nucleus::toXMLListExtraElements( std::vector<std::string> &a_XMLList, std::string const &a_indent1 ) const {
131
132 m_energy.toXMLList( a_XMLList, a_indent1 );
133}
134
135}
#define PoPI_AMU2MeV_c2
Definition PoPI.hpp:30
#define PoPI_electronMass_MeV_c2
Definition PoPI.hpp:31
#define PoPI_nucleusChars
Definition PoPI.hpp:50
#define PoPI_indexChars
Definition PoPI.hpp:91
#define PoPI_energyChars
bool empty() const
Definition HAPI_Node.cc:150
friend Nucleus
Definition PoPI.hpp:678
std::string const & ID(void) const
Definition PoPI.hpp:652
std::size_t addToDatabase(Database *a_DB)
Definition PoPI_base.cc:95
std::string const & atomsID(void) const
int levelIndex(void) const
Definition PoPI.hpp:978
int A(void) const
Definition PoPI.hpp:976
int Z(void) const
Definition PoPI.hpp:975
virtual ~Nucleus()
virtual void toXMLListExtraElements(std::vector< std::string > &a_XMLList, std::string const &a_indent1) const
PQ_suite const & energy(void) const
Definition PoPI.hpp:982
double massValue(char const *a_unit) const
virtual std::string toXMLListExtraAttributes(void) const
double value(void) const
Definition PoPI.hpp:443
Particle(HAPI::Node const &a_node, Particle_class a_class, std::string const &a_family, int a_hasNucleus=0)
virtual PQ_suite const & mass(void) const
Definition PoPI.hpp:878
bool isAnti() const
Definition PoPI.hpp:875
std::string const & unit(void) const
Definition PoPI.hpp:420
Definition PoPI.hpp:28
Particle_class
Definition PoPI.hpp:58