18#include "marley/Error.hh"
19#include "marley/FileManager.hh"
20#include "marley/JSON.hh"
21#include "marley/JSONConfig.hh"
22#include "marley/NuclearFormFactor.hh"
27 static bool need_to_log_nuc_ff_info =
true;
33 auto tnff = std::make_shared< marley::TrivialNuclearFormFactor >( Z, A );
34 need_to_log_nuc_ff_info =
false;
38 if ( !ff_config.has_key(
"nuclear_model") ) {
39 throw marley::Error(
"Missing nuclear form factor model configuration" );
41 const auto& nucl_json = ff_config.at(
"nuclear_model" );
42 if ( !nucl_json.is_string() ) {
44 + nucl_json.dump_string() );
46 std::string nucl_ff_model = nucl_json.to_string();
48 std::shared_ptr< marley::NuclearFormFactor > nuclear_ff;
51 if ( nucl_ff_model ==
"trivial" ) {
52 nuclear_ff = std::make_shared< marley::TrivialNuclearFormFactor >( Z, A );
53 if ( need_to_log_nuc_ff_info ) {
54 MARLEY_LOG( INFO,
"physics.formfactor" ) <<
"Using trivial nuclear form factor";
57 else if ( nucl_ff_model ==
"helm" ) {
58 nuclear_ff = std::make_shared< marley::HelmNuclearFormFactor >( Z, A );
59 if ( need_to_log_nuc_ff_info ) {
60 MARLEY_LOG( INFO,
"physics.formfactor" ) <<
"Using Helm nuclear form factor";
63 else if ( nucl_ff_model ==
"klein" ) {
67 marley::JSON nucl_opt = assign_from_json< marley::JSON >(
68 "nucl_options", ff_config, ok, marley::JSON::object() );
71 bool adapted = assign_from_json< bool >(
"adapted", nucl_opt, ok,
true );
73 nuclear_ff = std::make_shared< marley
74 ::KleinNystrandNuclearFormFactor >( Z, A, adapted );
76 if ( need_to_log_nuc_ff_info ) {
78 if ( adapted ) kn_name +=
"adapted ";
79 kn_name +=
"Klein-Nystrand";
80 MARLEY_LOG( INFO,
"physics.formfactor" ) <<
"Using " << kn_name <<
" nuclear form factor";
83 else throw marley::Error(
"Unrecognized nuclear form factor model name \""
84 + nucl_ff_model +
"\" in marley::NuclearFormFactor::create()" );
86 need_to_log_nuc_ff_info =
false;
91 if ( kappa == 0. )
return 1.;
92 double kappa_in_inverse_fm = kappa / marley_utils::hbar_c;
93 double x = kappa_in_inverse_fm *
R_;
94 double j1 = ( std::sin( x ) / x - std::cos( x ) ) / x;
95 double F = 3. * j1 / x * std::exp( -kappa_in_inverse_fm
96 * kappa_in_inverse_fm *
s_ *
s_ / 2. );
101 if ( kappa == 0. )
return 1.;
102 double kappa_in_inverse_fm = kappa / marley_utils::hbar_c;
103 double x = kappa_in_inverse_fm *
R_;
104 double j1 = ( std::sin( x ) / x - std::cos( x ) ) / x;
105 double F = 3. * j1 / x * ( 1. / ( 1.
106 + kappa_in_inverse_fm*kappa_in_inverse_fm*
a_*
a_ ) );
110void marley::KleinNystrandNuclearFormFactor::initialize_r0_table() {
115 std::string full_r0_file_name = fm.find_file( r0_data_file_name_ );
117 if ( full_r0_file_name.empty() ) {
118 throw marley::Error(
"Could not find the MARLEY nuclear rms charge radii"
119 " data file " + r0_data_file_name_ +
". Please ensure that"
120 " the folder containing it is on the MARLEY search path."
121 " If needed, the folder can be appended to the MARLEY_SEARCH_PATH"
122 " environment variable." );
125 MARLEY_LOG( INFO,
"init.structure" ) <<
"Loading ground-state nuclear rms charge radii from "
126 << full_r0_file_name;
128 marley::JSON r0_json_obj = marley::JSON::load_file( full_r0_file_name );
129 if ( !r0_json_obj.has_key(
"nuclear_charge_radii") ) {
130 throw marley::Error(
"Missing \"nuclear_charge_radii\" key in "
131 + full_r0_file_name );
133 const marley::JSON& r0_json_array = r0_json_obj.at(
"nuclear_charge_radii" );
134 if ( !r0_json_array.is_array() ) {
135 throw marley::Error(
"Invalid \"nuclear_charge_radii\" array in "
136 + full_r0_file_name );
139 r0_table_ = std::make_unique< std::map< int, double > >();
142 for (
const auto& r0_js : r0_json_array.array_range() ) {
143 int Z = assign_from_json< int >(
"Z", r0_js, ok );
144 int A = assign_from_json< int >(
"A", r0_js, ok );
145 double R = assign_from_json< double >(
"R", r0_js, ok );
151 int pdg = marley_utils::get_nucleus_pid( Z, A );
152 r0_table_->operator[]( pdg ) = R;
154 MARLEY_LOG( TRACE,
"init.structure.masstable" ) <<
"Nucleus with PDG code "
155 << pdg <<
" has rms charge radius " << R <<
" fm";
Base class for all exceptions thrown by MARLEY functions.
static const FileManager & Instance()
Get a const reference to the singleton instance of the FileManager.
static bool check_for_allowed_approximation(const marley::JSON &ff_config)