19#include "marley/Error.hh"
20#include "marley/Logger.hh"
21#include "marley/Target.hh"
22#include "marley/marley_utils.hh"
30 int pdg = marley_utils::get_nucleus_pid( Z, A );
39 std::vector<double> atom_fracs = { 1. };
40 std::vector<marley::TargetAtom> atoms;
41 atoms.emplace_back( pdg );
48 const std::vector<double>& atom_fracs )
54 const std::vector<double>& atom_fracs )
57 if ( nuclides.size() != atom_fracs.size() ) {
58 throw marley::Error(
"Different numbers of target atoms and atom fractions"
59 " encountered in the constructor of marley::Target");
64 if ( nuclides.size() == 0u )
throw marley::Error(
"No target atoms"
65 " specified when constructing a marley::Target object" );
69 for (
size_t j = 0u; j < atom_fracs.size(); ++j ) {
70 double af = atom_fracs.at( j );
71 const auto& nuc = nuclides.at( j );
73 + std::to_string(af) +
" encountered for a "
74 + nuc.to_string() +
" target atom");
75 else if ( af == 0. ) MARLEY_LOG( WARN,
"init.config.target" )
76 <<
"Atom fraction of zero encountered for a " << nuc <<
" target atom";
81 if ( sum <= 0. )
throw marley::Error(
"Sum of atom fractions = "
82 + std::to_string(sum) +
" in the constructor of marley::Target" );
84 std::vector<double> renorm_fracs;
85 for (
const auto& af : atom_fracs ) renorm_fracs.push_back( af / sum );
88 for (
size_t j = 0u; j < nuclides.size(); ++j ) {
89 const auto& nuc = nuclides.at( j );
90 const auto& frac = renorm_fracs.at( j );
93 " fractions specified for the target atom " + nuc.to_string() +
" in"
94 " the constructor of marley::Target");
116 const auto& nuc = pair.first;
117 const auto& frac = pair.second;
118 std::string A_str = std::to_string( nuc.A() );
119 marley_utils::pad_left_inplace( A_str, 3 );
121 auto it = marley_utils::element_symbols.find( nuc.Z() );
122 std::string symb =
"??";
123 if ( it != marley_utils::element_symbols.end() ) symb = it->second;
124 marley_utils::pad_right_inplace( symb, 2 );
126 out << A_str << symb <<
" = " << frac;
128 if ( count < num_atom_types ) out <<
'\n';
Base class for all exceptions thrown by MARLEY functions.
An atomic target for a lepton scattering reaction.
std::map< marley::TargetAtom, double > atom_fractions_
Map storing the atom fraction for each nuclide in the target material.
Target(int pdg)
Create a Target composed of a single nuclide.
void initialize_single_nuclide(int pdg)
Helper function for the constructors that use a single nuclide.
bool contains(const marley::TargetAtom &atom) const
Return true if the target contains the requested atom, or false otherwise.
void initialize(const std::vector< TargetAtom > &nuclides, const std::vector< double > &atom_fracs)
General helper function for the constructors.
void print(std::ostream &out) const
Print a textual representation of the Target to a std::ostream.
double atom_fraction(const marley::TargetAtom &atom) const
Returns the atom fraction for the requested nuclide.