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
Level.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 <string>
18#include <vector>
19#include <regex>
20
21#include "marley/marley_utils.hh"
22#include "marley/Generator.hh"
23#include "marley/Level.hh"
24#include "marley/Parity.hh"
25
27 : energy_( E ), twoJ_( twoJ ), parity_( pi ), half_life_( half_life )
28{}
29
31 double* prob_ptr )
32{
33 // Initialize the probability of sampling the gamma to zero
34 if ( prob_ptr ) *prob_ptr = 0.;
35
36 if ( gammas_.empty() ) return nullptr;
37 else {
38 // Get the index of the gamma to return by randomly sampling from the
39 // discrete distribution gamma_dist using the standard marley_utils random
40 // number generator.
41 size_t g_index = gen.sample_from_distribution( gamma_dist_ );
42
43 // If we have a non-null double* to use to store the probability of
44 // sampling this particular gamma, then do the storage here
45 if ( prob_ptr ) {
46 std::vector< double > probs = gamma_dist_.probabilities();
47 *prob_ptr = probs.at( g_index );
48 }
49
50 // Return a pointer to the corresponding gamma
51 return &( gammas_[ g_index ] );
52 }
53}
54
56 // Update the vector of gamma objects
57 gammas_.push_back( gamma );
58
59 // Update the distribution for sampling gammas
60 update_gamma_distribution();
61
62 // Return a reference to the newly added gamma
63 return gammas_.back();
64}
65
67 double branching_ratio, marley::Level* end_lev )
68{
69 // Update the vector of gamma objects
70 gammas_.emplace_back( energy, branching_ratio, this, end_lev );
71
72 // Update the distribution for sampling gammas
73 update_gamma_distribution();
74
75 // Return a reference to the newly added gamma
76 return gammas_.back();
77}
78
80 gammas_.clear();
81
82 // The discrete distribution will be cleared by this command because the
83 // vector of gammas is now empty.
84 update_gamma_distribution();
85}
86
88 std::string str = std::to_string( twoJ_ / 2 );
89 // If 2*J is odd, then the level has half-integer spin
90 if ( twoJ_ % 2 ) str += "/2";
91 return str + parity_.to_char();
92}
93
94void marley::Level::update_gamma_distribution() {
95 // Get iterators to the relative intensities of the gammas owned by this
96 // level.
97 auto ri_begin = marley::Gamma::make_intensity_iterator( gammas_.begin() );
98 auto ri_end = marley::Gamma::make_intensity_iterator( gammas_.end() );
99
100 // Update the discrete distribution used to sample gammas
101 std::discrete_distribution< size_t >::param_type params( ri_begin, ri_end );
102 gamma_dist_.param( params );
103}
A gamma-ray transition between two nuclear levels.
Definition Gamma.hh:25
static marley::IteratorToMember< It, double > make_intensity_iterator(It it)
Convert an iterator that points to a Gamma object into an iterator that points to the Gamma's relativ...
Definition Gamma.hh:89
The MARLEY Event generator.
Definition Generator.hh:54
auto sample_from_distribution(RandomNumberDistribution &rnd) -> decltype(std::declval< RandomNumberDistribution & >().operator()(std::declval< std::mt19937_64 & >()))
Sample from an arbitrary probability distribution (defined here as any object that implements an oper...
Definition Generator.hh:193
A discrete nuclear energy level.
Definition Level.hh:29
double half_life() const
Get the level half-life (s)
Definition Level.hh:144
marley::Gamma & add_gamma(const marley::Gamma &gamma)
Add a new gamma-ray transition to this level.
Definition Level.cc:55
Level(double E, int twoJ, marley::Parity pi, double half_life)
Definition Level.cc:26
const marley::Gamma * sample_gamma(marley::Generator &gen, double *prob_ptr=nullptr)
Choose a gamma owned by this level randomly based on the relative intensities of all of the gammas.
Definition Level.cc:30
int twoJ() const
Get two times the level spin.
Definition Level.hh:138
void clear_gammas()
Remove all gamma ray information from this level.
Definition Level.cc:79
std::string spin_parity_string() const
Returns the level spin-parity as a string.
Definition Level.cc:87
double energy() const
Get the excitation energy of this level (MeV)
Definition Level.hh:135
Type-safe representation of a parity value (either +1 or -1)
Definition Parity.hh:25