From dc7f3923edb3a5f26e4396032bfd9394c148fcee Mon Sep 17 00:00:00 2001 From: Gordon McCann Date: Sat, 13 Feb 2021 17:35:29 -0500 Subject: [PATCH] Fixed bug in target thickness calc, where angle through target was incorrectly used for energy loss --- src/Target.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Target.cpp b/src/Target.cpp index fffd480..b3757df 100644 --- a/src/Target.cpp +++ b/src/Target.cpp @@ -40,25 +40,29 @@ bool Target::ContainsElement(int z, int a) { /*Calculates energy loss for travelling all the way through the target*/ double Target::getEnergyLossTotal(int zp, int ap, double startEnergy, double theta) { if(theta == PI/2.) return startEnergy; - else return eloss.GetEnergyLoss(zp, ap, startEnergy, thickness/fabs(cos(theta))); + else if (theta > PI/2.) theta = PI - theta; + return eloss.GetEnergyLoss(zp, ap, startEnergy, thickness/fabs(cos(theta))); } /*Calculates energy loss for travelling halfway through the target*/ double Target::getEnergyLossHalf(int zp, int ap, double startEnergy, double theta) { if(theta == PI/2.) return startEnergy; - else return eloss.GetEnergyLoss(zp, ap, startEnergy, thickness/(2.0*fabs(cos(theta)))); + else if (theta > PI/2.) theta = PI - theta; + return eloss.GetEnergyLoss(zp, ap, startEnergy, thickness/(2.0*fabs(cos(theta)))); } /*Calculates reverse energy loss for travelling all the way through the target*/ double Target::getReverseEnergyLossTotal(int zp, int ap, double finalEnergy, double theta) { if(theta == PI/2.) return finalEnergy; - else return eloss.GetReverseEnergyLoss(zp, ap, finalEnergy, thickness/fabs(cos(theta))); + else if (theta > PI/2.) theta = PI - theta; + return eloss.GetReverseEnergyLoss(zp, ap, finalEnergy, thickness/fabs(cos(theta))); } /*Calculates reverse energy loss for travelling half way through the target*/ double Target::getReverseEnergyLossHalf(int zp, int ap, double finalEnergy, double theta) { if(theta == PI/2.) return finalEnergy; - else return eloss.GetReverseEnergyLoss(zp, ap, finalEnergy, thickness/(2.0*fabs(cos(theta)))); + else if (theta > PI/2.) theta = PI - theta; + return eloss.GetReverseEnergyLoss(zp, ap, finalEnergy, thickness/(2.0*fabs(cos(theta)))); } /*Getter functions*/