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
NuclearResponses.hh
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#pragma once
18
19// Standard library includes
20#include <fstream>
21#include <functional>
22
23namespace marley {
24
25 class NuclearResponses {
26
27 public:
28
29 NuclearResponses() : rCC_( 0. ), rLL_( 0. ), rCL_( 0. ), rTvv_( 0. ),
30 rTaa_( 0. ), rTprime_( 0. ) {}
31
32 NuclearResponses( double rCC, double rLL, double rCL, double rTvv,
33 double rTaa, double rTprime ) : rCC_( rCC ), rLL_( rLL ),
34 rCL_( rCL ), rTvv_( rTvv ), rTaa_( rTaa ), rTprime_( rTprime ) {}
35
36 inline double RCC() const { return rCC_; }
37 inline double RLL() const { return rLL_; }
38 inline double RCL() const { return rCL_; }
39 inline double RT() const { return rTvv_ + rTaa_; }
40 inline double RTvv() const { return rTvv_; }
41 inline double RTaa() const { return rTaa_; }
42 inline double RTprime() const { return rTprime_; }
43
44 inline void set_RCC(double val) { rCC_ = val; }
45 inline void set_RLL(double val) { rLL_ = val; }
46 inline void set_RCL(double val) { rCL_ = val; }
47 inline void set_RTvv(double val) { rTvv_ = val; }
48 inline void set_RTaa(double val) { rTaa_ = val; }
49 inline void set_RTprime(double val) { rTprime_ = val; }
50
51 // Scalar operations
52 NuclearResponses operator*(double d) const
53 { return apply_to_members(d, [](double a, double b)
54 -> double { return a * b; }); }
55
56 NuclearResponses operator/(double d) const
57 { return apply_to_members(d, [](double a, double b)
58 -> double { return a / b; }); }
59
60 // NuclearResponses operations
61 NuclearResponses operator+(const NuclearResponses& other) const
62 { return apply_to_members(other, [](double a, double b)
63 -> double { return a + b; }); }
64
65 NuclearResponses operator-(const NuclearResponses& other) const
66 { return apply_to_members(other, [](double a, double b)
67 -> double { return a - b; }); }
68
69 NuclearResponses operator*(const NuclearResponses& other) const
70 { return apply_to_members(other, [](double a, double b)
71 -> double { return a * b; }); }
72
73 NuclearResponses operator/(const NuclearResponses& other) const
74 { return apply_to_members(other, [](double a, double b)
75 -> double { return a / b; }); }
76
77 bool operator==(const NuclearResponses& other) const {
78 bool are_equal = this->rCC_ == other.rCC_;
79 if ( are_equal ) are_equal = this->rLL_ == other.rLL_;
80 if ( are_equal ) are_equal = this->rCL_ == other.rCL_;
81 if ( are_equal ) are_equal = this->rTvv_ == other.rTvv_;
82 if ( are_equal ) are_equal = this->rTaa_ == other.rTaa_;
83 if ( are_equal ) are_equal = this->rTprime_ == other.rTprime_;
84 return are_equal;
85 }
86
87 bool operator!=(const NuclearResponses& other) const {
88 return !operator==( other );
89 }
90
91 inline void print(std::ostream& out) const {
92 out << rCC_ << ' ' << rLL_ << ' ' << rCL_ << ' '
93 << rTvv_ << ' ' << rTaa_ << ' ' << rTprime_;
94 }
95
96 protected:
97
98 NuclearResponses apply_to_members( double d,
99 const std::function<double(double,double)>& my_function ) const
100 {
101 // Create a new NuclearResponses object by applying the function to
102 // each pair of elements
103 NuclearResponses result;
104
105 result.rCC_ = my_function( this->rCC_, d );
106 result.rLL_ = my_function( this->rLL_, d );
107 result.rCL_ = my_function( this->rCL_, d );
108 result.rTvv_ = my_function( this->rTvv_, d );
109 result.rTaa_ = my_function( this->rTaa_, d );
110 result.rTprime_ = my_function( this->rTprime_, d );
111
112 return result;
113 }
114
115 NuclearResponses apply_to_members( const NuclearResponses& other,
116 const std::function<double(double,double)>& my_function ) const
117 {
118 // Create a new NuclearResponses object by applying the function to
119 // each pair of elements
120 NuclearResponses result;
121
122 result.rCC_ = my_function( this->rCC_, other.rCC_ );
123 result.rLL_ = my_function( this->rLL_, other.rLL_ );
124 result.rCL_ = my_function( this->rCL_, other.rCL_ );
125 result.rTvv_ = my_function( this->rTvv_, other.rTvv_ );
126 result.rTaa_ = my_function( this->rTaa_, other.rTaa_ );
127 result.rTprime_ = my_function( this->rTprime_, other.rTprime_ );
128
129 return result;
130 }
131
132 double rCC_;
133 double rLL_;
134 double rCL_;
135 double rTvv_;
136 double rTaa_;
137 double rTprime_;
138
139 };
140
141}
142
143inline std::ostream& operator<<( std::ostream& out,
144 const marley::NuclearResponses& np )
145{
146 np.print( out );
147 return out;
148}