MARLEY (Model of Argon Reaction Low Energy Yields) v2.0.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Loading...
Searching...
No Matches
coulomb_wavefunctions.cc
1
4//
5// This file is part of MARLEY (Model of Argon Reaction Low Energy Yields)
6//
7// MARLEY is free software: you can redistribute it and/or modify it under the
8// terms of version 3 of the GNU General Public License as published by the
9// Free Software Foundation.
10//
11// For the full text of the license please see COPYING or
12// visit http://opensource.org/licenses/GPL-3.0
13//
14// Please respect the MCnet academic usage guidelines. See GUIDELINES
15// or visit https://www.montecarlonet.org/GUIDELINES for details.
16
17#include "marley/coulomb_wavefunctions.hh"
18#include "builtin/marley_gsl.hh"
19#include "marley/Logger.hh"
20
21std::complex< double > coulomb_H_plus( int l, double eta, double rho ) {
22
23 // Temporarily use the MARLEY gsl error handler (designed to ignore overflows
24 // signaled by GSL_EOVRFLW, which are sometimes expected when computing the
25 // Coulomb wavefunctions). Keep a pointer to the previous error handler to
26 // restore it later in this function.
27 auto* previous_handler = gsl_set_error_handler( &marley_gsl_error_handler );
28
29 // H+ = G + i F
30 gsl_sf_result F, Fp, G, Gp;
31 double exp_F, exp_G;
32 int code = gsl_sf_coulomb_wave_FG_e( eta, rho, static_cast<double>(l), 0,
33 &F, &Fp, &G, &Gp, &exp_F, &exp_G );
34
35 // Compute the value of H+, correcting for an overflow condition if one was
36 // signaled by GSL
37 std::complex< double > result;
38
39 if ( code == GSL_EOVRFLW ) {
40 double Fl = F.val * std::exp( exp_F );
41 double Gl = G.val * std::exp( exp_G );
42 result = std::complex<double>( Gl, Fl );
43 }
44 else {
45 result = std::complex<double>( G.val, F.val );
46 }
47
48 // Restore the old GSL error handler to play nicely with other packages that
49 // may manipulate it
50 gsl_set_error_handler( previous_handler );
51
52 return result;
53}
54
57void marley_gsl_error_handler( const char* reason, const char* file, int line,
58 int gsl_errno )
59{
60 // Overflows are expected sometimes, and they are handled explicitly by
61 // coulomb_H_plus()
62 if ( gsl_errno == GSL_EOVRFLW ) return;
63
64 MARLEY_LOG( ERROR, "physics.formfactor" ) << "GSL error: " << reason
65 << " in file " << file
66 << " at line " << line << " with error code " << gsl_errno;
67}