Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
PoPI_decayData.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 "PoPI.hpp"
11
12namespace PoPI {
13
14#define PoPI_decayModesChars "decayModes"
15#define PoPI_decayModeChars "decayMode"
16#define PoPI_decayPathChars "decayPath"
17#define PoPI_decayChars "decay"
18#define PoPI_productsChars "products"
19#define PoPI_photonEmissionProbabilitiesChars "photonEmissionProbabilities"
20
21#define PoPI_typeChars "type"
22#define PoPI_modeChars "mode"
23#define PoPI_completeChars "complete"
24#define PoPI_probabilityChars "probability"
25
26/*
27============================================================
28======================== DecayData =========================
29============================================================
30*/
32 m_decayModes( PoPI_decayModesChars ) {
33
34 m_decayModes.appendFromParentNode2( a_node.child( PoPI_decayModesChars ), this );
35}
36/*
37=========================================================
38*/
42/*
43=========================================================
44*/
45void DecayData::calculateNuclideGammaBranchStateInfo( PoPI::Database const &a_pops, NuclideGammaBranchStateInfo &a_nuclideGammaBranchStateInfo ) const {
46
47 for( std::size_t i1 = 0; i1 < m_decayModes.size( ); ++i1 ) {
48 DecayMode const &decayMode = m_decayModes[i1];
49
50 decayMode.calculateNuclideGammaBranchStateInfo( a_pops, a_nuclideGammaBranchStateInfo );
51 }
52}
53
54/* *********************************************************************************************************//**
55 * Adds the contents of *this* to *a_XMLList* where each item in *a_XMLList* is one line (without linefeeds) to output as an XML representation of *this*.
56 *
57 * @param a_XMLList [in] The list to add an XML output representation of *this* to.
58 * @param a_indent1 [in] The amount of indentation to added to each line added to *a_XMLList*.
59 ***********************************************************************************************************/
60
61void DecayData::toXMLList( std::vector<std::string> &a_XMLList, std::string const &a_indent1 ) const {
62
63 std::string::size_type size = m_decayModes.size( );
64
65 if( size == 0 ) return;
66
67 std::string header = a_indent1 + "<" + PoPI_decayDataChars + ">";
68 a_XMLList.push_back( std::move( header ) );
69
70 if( size > 0 ) {
71 std::string indent2 = a_indent1 + " ";
72 m_decayModes.toXMLList( a_XMLList, indent2 );
73 }
74
76}
77
78/*
79============================================================
80======================== DecayMode =========================
81============================================================
82*/
83DecayMode::DecayMode( HAPI::Node const &a_node, LUPI_maybeUnused DecayData const *a_decayData ) :
84 m_label( a_node.attribute( PoPI_labelChars ).value( ) ),
85 m_mode( a_node.attribute( PoPI_modeChars ).value( ) ),
86 m_probability( a_node.child( PoPI_probabilityChars ) ),
87 m_photonEmissionProbabilities( a_node.child( PoPI_photonEmissionProbabilitiesChars ) ),
88 m_decayPath( PoPI_decayPathChars ) {
89
90 m_decayPath.appendFromParentNode2( a_node.child( PoPI_decayPathChars ), this );
91}
92/*
93============================================================
94*/
98
99/*
100============================================================
101*/
102void DecayMode::calculateNuclideGammaBranchStateInfo( PoPI::Database const &a_pops, NuclideGammaBranchStateInfo &a_nuclideGammaBranchStateInfo ) const {
103
104 if( m_mode == PoPI_decayModeElectroMagnetic ) {
105 double _probability = getPhysicalQuantityOfSuiteAsDouble( probability( ) );
106 double _photonEmissionProbabilities = getPhysicalQuantityOfSuiteAsDouble( photonEmissionProbabilities( ), true, 1.0 );
107
108 std::string residualState( "" );
109 Decay const &decay = m_decayPath[0];
110 Suite<Product, Decay> const &products = decay.products( );
111 for( std::size_t i1 = 0; i1 < products.size( ); ++i1 ) {
112 Product const &product = products[i1];
113
114 if( product.pid( ) != IDs::photon ) residualState = product.pid( );
115 }
116
117 Particle const &initialState = a_pops.get<Particle>( a_nuclideGammaBranchStateInfo.state( ) );
118 Particle const &finalState = a_pops.get<Particle>( residualState );
119 double gammaEnergy = PoPI_AMU2MeV_c2 * ( initialState.massValue( "amu" ) - finalState.massValue( "amu" ) );
120
121 NuclideGammaBranchInfo nuclideGammaBranchInfo( _probability, _photonEmissionProbabilities, gammaEnergy, residualState );
122 a_nuclideGammaBranchStateInfo.add( nuclideGammaBranchInfo );
123 }
124}
125
126/* *********************************************************************************************************//**
127 * Adds the contents of *this* to *a_XMLList* where each item in *a_XMLList* is one line (without linefeeds) to output as an XML representation of *this*.
128 *
129 * @param a_XMLList [in] The list to add an XML output representation of *this* to.
130 * @param a_indent1 [in] The amount of indentation to added to each line added to *a_XMLList*.
131 ***********************************************************************************************************/
132
133void DecayMode::toXMLList( std::vector<std::string> &a_XMLList, std::string const &a_indent1 ) const {
134
135 std::string header = a_indent1 + "<decayMode label=\"" + m_label + "\" mode=\"" + m_mode + "\">";
136 a_XMLList.push_back( std::move( header ) );
137
138 std::string indent2 = a_indent1 + " ";
139 m_probability.toXMLList( a_XMLList, indent2 );
140 m_decayPath.toXMLList( a_XMLList, indent2 );
141
142 appendXMLEnd( a_XMLList, PoPI_decayModeChars );
143}
144
145/*
146============================================================
147========================== Decay ===========================
148============================================================
149*/
150
151Decay::Decay( HAPI::Node const &a_node, LUPI_maybeUnused DecayMode const *a_decayMode ) :
152 m_index( a_node.attribute( PoPI_indexChars ).as_int( ) ),
153 m_mode( a_node.attribute( PoPI_modeChars ).value( ) ),
154 m_complete( a_node.attribute( PoPI_completeChars ).value( ) == "true" ),
155 m_products( PoPI_productsChars ) {
156
157 if( a_node.attribute( PoPI_typeChars ).value( ) != "" ) m_mode = a_node.attribute( PoPI_typeChars ).value( );
158
159 m_products.appendFromParentNode2( a_node.child( PoPI_productsChars ), this );
160}
161
162/* *********************************************************************************************************//**
163 ***********************************************************************************************************/
164
166
167}
168
169/* *********************************************************************************************************//**
170 * Adds the contents of *this* to *a_XMLList* where each item in *a_XMLList* is one line (without linefeeds) to output as an XML representation of *this*.
171 *
172 * @param a_XMLList [in] The list to add an XML output representation of *this* to.
173 * @param a_indent1 [in] The amount of indentation to added to each line added to *a_XMLList*.
174 ***********************************************************************************************************/
175
176void Decay::toXMLList( std::vector<std::string> &a_XMLList, std::string const &a_indent1 ) const {
177
178 std::string indexString( std::to_string( m_index ) );
179
180 std::string header = a_indent1 + "<decay index=\"" + indexString + "\"";
181 if( m_mode != "" ) header += " mode=\"" + m_mode + "\"";
182 if( m_complete ) header += " mode=\"true\"";
183 header += ">";
184 a_XMLList.push_back( std::move( header ) );
185
186 std::string indent2 = a_indent1 + " ";
187 m_products.toXMLList( a_XMLList, indent2 );
188
189 appendXMLEnd( a_XMLList, PoPI_decayChars );
190}
191
192/*
193============================================================
194========================= Product ==========================
195============================================================
196*/
197Product::Product( HAPI::Node const &a_node, LUPI_maybeUnused Decay *a_DB ) :
198 m_id( -1 ),
199 m_pid( a_node.attribute( PoPI_pidChars ).value( ) ),
200 m_label( a_node.attribute( PoPI_labelChars ).value( ) ) {
201
202}
203
204/*
205============================================================
206*/
208
209}
210
211/* *********************************************************************************************************//**
212 * Adds the contents of *this* to *a_XMLList* where each item in *a_XMLList* is one line (without linefeeds) to output as an XML representation of *this*.
213 *
214 * @param a_XMLList [in] The list to add an XML output representation of *this* to.
215 * @param a_indent1 [in] The amount of indentation to added to each line added to *a_XMLList*.
216 ***********************************************************************************************************/
217
218void Product::toXMLList( std::vector<std::string> &a_XMLList, std::string const &a_indent1 ) const {
219
220 std::string header = a_indent1 + "<product label=\"" + m_label + "\" pid=\"" + m_pid + "\"/>";
221 a_XMLList.push_back( std::move( header ) );
222}
223
224/*! \class GammaDecayData
225 * This class stores, in a crude way, the GRIN, non-GNDS 2.0 compliant, nuclide gamma decay data.
226 */
227
228/* *********************************************************************************************************//**
229 * @param a_node [in] The HAPI node to parse.
230 ***********************************************************************************************************/
231
233 m_kind( a_node.attribute_as_string( "kind" ) ),
234 m_rows( 0 ),
235 m_columns( 0 ) {
236
237 if( m_kind == "" ) m_kind = PoPI_discreteChars;
238
239 if( !a_node.empty( ) ) {
240 HAPI::Node table = a_node.child( "table" );
241 m_rows = table.attribute_as_int( "rows" );
242 m_columns = table.attribute_as_int( "columns" );
243
244 HAPI::Node data = table.child( "data" );
245
246 std::string text = LUPI::Misc::stripString( data.text( ).get( ) );
247 auto cells = LUPI::Misc::splitString( text, ' ', true );
248
249 m_ids.reserve( static_cast<std::size_t>( m_rows ) );
250 m_probabilities.reserve( static_cast<std::size_t>( m_rows ) );
251 m_photonEmissionProbabilities.reserve( static_cast<std::size_t>( m_rows ) );
252 for( std::size_t cellIndex = 0; cellIndex < cells.size( ); cellIndex += 3 ) {
253 m_ids.push_back( cells[cellIndex] );
254 m_probabilities.push_back( std::stod( cells[cellIndex+1] ) );
255 m_photonEmissionProbabilities.push_back( std::stod( cells[cellIndex+2] ) );
256 }
257 }
258}
259
260/* *********************************************************************************************************//**
261 ***********************************************************************************************************/
262
266
267/*
268============================================================
269*/
271
272 Particle const &initialState = a_pops.get<Particle>( a_nuclideGammaBranchStateInfo.state( ) );
273 double initialStateMass = initialState.massValue( "amu" );
274
275 for( std::size_t index = 0; index < static_cast<std::size_t>( m_rows ); ++index ) {
276 std::string residualState( m_ids[index] );
277 double _probability = m_probabilities[index];
278 double _photonEmissionProbabilities = m_photonEmissionProbabilities[index];
279
280 Particle const &finalState = a_pops.get<Particle>( residualState );
281 double gammaEnergy = PoPI_AMU2MeV_c2 * ( initialStateMass - finalState.massValue( "amu" ) );
282
283 NuclideGammaBranchInfo nuclideGammaBranchInfo( _probability, _photonEmissionProbabilities, gammaEnergy, residualState );
284 a_nuclideGammaBranchStateInfo.add( nuclideGammaBranchInfo );
285 }
286}
287
288}
#define LUPI_maybeUnused
#define PoPI_AMU2MeV_c2
Definition PoPI.hpp:30
#define PoPI_pidChars
Definition PoPI.hpp:92
#define PoPI_discreteChars
Definition PoPI.hpp:98
#define PoPI_labelChars
Definition PoPI.hpp:90
#define PoPI_indexChars
Definition PoPI.hpp:91
#define PoPI_decayModeElectroMagnetic
Definition PoPI.hpp:87
#define PoPI_decayDataChars
Definition PoPI.hpp:84
#define PoPI_modeChars
#define PoPI_completeChars
#define PoPI_probabilityChars
#define PoPI_decayModesChars
#define PoPI_decayModeChars
#define PoPI_productsChars
#define PoPI_typeChars
#define PoPI_photonEmissionProbabilitiesChars
#define PoPI_decayPathChars
#define PoPI_decayChars
std::string const value() const
Definition HAPI.hpp:137
bool empty() const
Definition HAPI_Node.cc:150
Node child(const char *name) const
Definition HAPI_Node.cc:72
Attribute attribute(const char *a_name) const
Definition HAPI.hpp:176
T const & get(std::string const &a_id) const
DecayData(HAPI::Node const &a_node)
void calculateNuclideGammaBranchStateInfo(PoPI::Database const &a_pops, NuclideGammaBranchStateInfo &a_nuclideGammaBranchStateInfo) const
void toXMLList(std::vector< std::string > &a_XMLList, std::string const &a_indent1) const
void calculateNuclideGammaBranchStateInfo(PoPI::Database const &a_pops, NuclideGammaBranchStateInfo &a_nuclideGammaBranchStateInfo) const
DecayMode(HAPI::Node const &a_node, DecayData const *a_decayData)
void toXMLList(std::vector< std::string > &a_XMLList, std::string const &a_indent1) const
PQ_suite const & photonEmissionProbabilities() const
Definition PoPI.hpp:789
PQ_suite const & probability() const
Definition PoPI.hpp:788
void toXMLList(std::vector< std::string > &a_XMLList, std::string const &a_indent1) const
Decay(HAPI::Node const &a_node, DecayMode const *a_decayMode)
void calculateNuclideGammaBranchStateInfo(PoPI::Database const &a_pops, NuclideGammaBranchStateInfo &nuclideGammaBranchStateInfo) const
GammaDecayData(HAPI::Node const &a_node)
std::string const & state() const
Definition PoPI.hpp:589
void add(NuclideGammaBranchInfo const &a_nuclideGammaBranchInfo)
virtual double massValue(char const *a_unit) const
void toXMLList(std::vector< std::string > &a_XMLList, std::string const &a_indent1) const
Product(HAPI::Node const &a_node, Decay *a_DB)
std::string::size_type size(void) const
Definition PoPI.hpp:321
Definition PoPI.hpp:28
double getPhysicalQuantityOfSuiteAsDouble(PQ_suite const &a_suite, bool a_allowEmpty=false, double a_emptyValue=0.0)
Definition PoPI_misc.cc:435
void appendXMLEnd(std::vector< std::string > &a_XMLList, std::string const &a_label)
Definition PoPI_misc.cc:53
std::string to_string(G4FermiAtomicMass mass)
static std::string const photon
Definition PoPI.hpp:162