From 1a100005560100df8609350f3bb6c479d8759358 Mon Sep 17 00:00:00 2001 From: Gordon McCann Date: Fri, 8 Oct 2021 15:41:23 -0400 Subject: [PATCH] Modified reading in of layered target data to be more intuitive, which lead to finding and fixing a bug in the logic for handling zero thickness or zero energy EnergyLoss::GetEnergyLoss calls --- include/KinematicsExceptions.h | 6 ++---- input.txt | 17 ++++++++--------- src/EnergyLoss.cpp | 9 ++++----- src/MaskApp.cpp | 16 ++++++++++------ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/KinematicsExceptions.h b/include/KinematicsExceptions.h index 76ed6f1..3153a18 100644 --- a/include/KinematicsExceptions.h +++ b/include/KinematicsExceptions.h @@ -14,15 +14,13 @@ */ struct ELossException : public std::exception { ELossException(const std::string& error) { - m_error = error; + m_error = "Failure to calculate particle energy loss. Reason: " + error + " See KinematicsExceptions.h for documentation."; } std::string m_error; const char* what() const noexcept { - std::string err_str = "Failure to calculate particle energy loss. Reason: "; - err_str += m_error + " See KinematicsExceptions.h for documentation."; - return err_str.c_str(); + return m_error.c_str(); }; }; diff --git a/input.txt b/input.txt index 9022e7a..9c11870 100644 --- a/input.txt +++ b/input.txt @@ -8,15 +8,14 @@ Z A (order is target, projectile, ejectile, break1, break3(if pure decay is targ 1 1 2 4 ----------Target Information---------- -Name: test_targ -Layers: 1 -~Layer1 -Thickness(ug/cm^2): 50 -Z A Stoich -1 2 2 -6 12 1 -0 -~ +NumberOfLayers: 2 +begin_layer + Thickness(ug/cm^2): 50 + begin_elements (Z, A, Stoich.) + element 1 2 2 + element 6 12 1 + end_elements +end_layer ----------Sampling Information---------- NumberOfSamples: 100000 BeamMeanEnergy(MeV): 0.87 BeamEnergySigma(MeV): 0.0 diff --git a/src/EnergyLoss.cpp b/src/EnergyLoss.cpp index 7130849..236bb41 100644 --- a/src/EnergyLoss.cpp +++ b/src/EnergyLoss.cpp @@ -49,6 +49,9 @@ namespace Mask { AP = ap; MP = MassLookup::GetInstance().FindMass(ZP, AP)*MEV2U; } + + if(thickness == 0.0 || e_initial == 0.0) + return 0; double e_final = e_initial; double x_traversed = 0; @@ -58,10 +61,6 @@ namespace Mask { int depth=0; - - if(thickness == 0.0 || e_initial == 0.0) - return 0; - bool go = true; while(go) { //If intial guess of step size is too large, shrink until in range @@ -99,7 +98,7 @@ namespace Mask { MP = MassLookup::GetInstance().FindMass(ZP, AP)*MEV2U; } - + double e_initial = e_final; double x_traversed = 0.0; double x_step = 0.25*thickness; //initial step in x diff --git a/src/MaskApp.cpp b/src/MaskApp.cpp index d75f78e..261439f 100644 --- a/src/MaskApp.cpp +++ b/src/MaskApp.cpp @@ -93,17 +93,21 @@ namespace Mask { double thickness; getline(input, junk); getline(input, junk); - input>>junk>>junk; input>>junk>>nlayers; for(int i=0; i>junk>>junk>>thickness; - getline(input, junk); - getline(input, junk); avec.clear(); zvec.clear(); svec.clear(); - while(input>>z) { - if(z == 0) break; - input>>a>>s; + while(input>>junk) + { + if(junk == "begin_elements") + { + input>>junk>>junk>>junk; + continue; + } + else if (junk == "end_elements") + break; + input>>z>>a>>s; zvec.push_back(z); avec.push_back(a); svec.push_back(s); } sys->AddTargetLayer(zvec, avec, svec, thickness);