From 671cda3c0f13f2eb38988ff0bfd5f5e9579b5fec Mon Sep 17 00:00:00 2001 From: gwm17 Date: Thu, 1 Dec 2022 09:39:02 -0500 Subject: [PATCH] Fix bug in integrator where occasionally step past 0 energy when stopping in material --- catima/gwm_integrators.cpp | 9 +++++++++ catima/gwm_integrators.h | 7 ++++++- gwm_test/gwm_test.cpp | 7 ++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/catima/gwm_integrators.cpp b/catima/gwm_integrators.cpp index 52963b6..34f4bcd 100644 --- a/catima/gwm_integrators.cpp +++ b/catima/gwm_integrators.cpp @@ -1,3 +1,8 @@ +/* + * Simple energy loss integrators for forward and reverse cases. + * + * Dec 2022, Gordon McCann + */ #include "catima/gwm_integrators.h" namespace catima { @@ -34,6 +39,10 @@ namespace catima { { return e_in*proj.A; } + else if (e_final > 0.0) + { + return e_in * proj.A; //In case an integration step takes us below 0 + } else { e_step = dedx(proj, mat, c)*x_step*A_recip; diff --git a/catima/gwm_integrators.h b/catima/gwm_integrators.h index 6ccf939..a4d4592 100644 --- a/catima/gwm_integrators.h +++ b/catima/gwm_integrators.h @@ -1,3 +1,8 @@ +/* + * Simple energy loss integrators for forward and reverse cases. + * + * Dec 2022, Gordon McCann + */ #ifndef GWM_INTEGRATORS_H #define GWM_INTEGRATORS_H @@ -10,4 +15,4 @@ namespace catima { double reverse_integrate_energyloss(Projectile& proj, const Material& mat, const Config& c=default_config); } -#endif \ No newline at end of file +#endif diff --git a/gwm_test/gwm_test.cpp b/gwm_test/gwm_test.cpp index 29e78eb..d90c965 100644 --- a/gwm_test/gwm_test.cpp +++ b/gwm_test/gwm_test.cpp @@ -1,3 +1,8 @@ +/* + * Testing for gwm_integrators + * + * Dec 2022, Gordon McCann + */ #include "catima/gwm_integrators.h" #include "catima/nucdata.h" #include @@ -14,4 +19,4 @@ int main() result = catima::reverse_integrate_energyloss(p1, mat1); std::cout<<"Reverse Energy loss (MeV): "<