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
CachedOpticalModel.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/CachedOpticalModel.hh"
18#include "marley/LinearInterpolatingFunction.hh"
19
20// Default to using the cache unless it is explicitly disabled
22
24 double total_KE_CM, int fragment_pdg, int two_j, int l, int two_s,
25 int target_charge )
26{
27 // If we're in the region of kinetic energies where we use the cache, then
28 // check whether we've encountered this combination of quantum numbers before
29 if ( USE_CACHE && total_KE_CM >= MIN_TOTAL_KE_CM
30 && total_KE_CM <= MAX_TOTAL_KE_CM )
31 {
32 TCKey temp_key( fragment_pdg, two_j, l, two_s, target_charge );
33 const auto cache_iter = tc_cache_.find( temp_key );
34
35 // If we can find a match in the cache, evaluate the transmission
36 // coefficient value using the stored interpolating function
37 if ( cache_iter != tc_cache_.cend() ) {
38 return cache_iter->second->evaluate( total_KE_CM );
39 }
40
41 // Otherwise, create an interpolating function object over the caching
42 // kinetic energy range
43 std::function< double(double) > t_coeff = [ this, fragment_pdg, two_j,
44 l, two_s, target_charge ]( double tot_KE_CM ) -> double
45 {
46 return this->compute_transmission_coefficient( tot_KE_CM, fragment_pdg,
47 two_j, l, two_s, target_charge );
48 };
49
50 auto t_coeff_interp = std::make_shared<
52 MAX_TOTAL_KE_CM, marley::DEFAULT_N_LINEAR );
53
54 // Compute the interpolated transmission coefficient for the current
55 // call to this function
56 double tc_result = t_coeff_interp->evaluate( total_KE_CM );
57
58 // Add the completed interpolating function to the cache before returning
59 // the current result
60 tc_cache_[ temp_key ] = std::move( t_coeff_interp );
61 return tc_result;
62 }
63
64 // If we're outside the caching energy range, just compute the transmission
65 // coefficient without relying on the cache at all
66 return this->compute_transmission_coefficient( total_KE_CM, fragment_pdg,
67 two_j, l, two_s, target_charge );
68}
static bool USE_CACHE
Boolean switch that allows global enabling/disabling of the cache, which is used by default.
static constexpr double MIN_TOTAL_KE_CM
Minimum kinetic energy to use when interacting with the cache.
static constexpr double MAX_TOTAL_KE_CM
Maximum kinetic energy to use when interacting with the cache.
std::map< TCKey, std::shared_ptr< InterpolatingFunction > > tc_cache_
Saved InterpolatingFunction objects corresponding to previously-encountered transmission coefficient ...
virtual double compute_transmission_coefficient(double total_KE_CM, int fragment_pdg, int two_j, int l, int two_s, int target_charge=0)=0
Do the actual calculation of the transmission coefficient.
virtual double transmission_coefficient(double total_KE_CM, int fragment_pdg, int two_j, int l, int two_s, int target_charge=0) override
Calculate the transmission coefficient for a nuclear fragment.
Approximates a 1D function using linear interpolation on a grid of regularly-spaced points.
double evaluate(double x) const override
Returns an approximate value of the represented function.