Skip to content

Commit

Permalink
fix: SimulationActor produces negative MaterialSlab thickness (#1288)
Browse files Browse the repository at this point in the history
fix #1284

SimulationActor produces negative MaterialSlab thickness if `normal` and `before` produce an angle > 90°

apply `abs` to avoid negative scaling factors
  • Loading branch information
andiwand authored Jun 22, 2022
1 parent c586094 commit 75f0835
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Core/src/Material/MaterialSlab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <limits>
#include <ostream>
#include <stdexcept>

static constexpr auto eps = 2 * std::numeric_limits<float>::epsilon();

Expand All @@ -22,6 +23,9 @@ Acts::MaterialSlab::MaterialSlab(const Material& material, float thickness)
m_thickness(thickness),
m_thicknessInX0((eps < material.X0()) ? (thickness / material.X0()) : 0),
m_thicknessInL0((eps < material.L0()) ? (thickness / material.L0()) : 0) {
if (thickness < 0) {
throw std::runtime_error("thickness < 0");
}
}

Acts::MaterialSlab::MaterialSlab(const std::vector<MaterialSlab>& layers)
Expand All @@ -40,6 +44,10 @@ Acts::MaterialSlab::MaterialSlab(const std::vector<MaterialSlab>& layers)
}

void Acts::MaterialSlab::scaleThickness(float scale) {
if (scale < 0) {
throw std::runtime_error("scale < 0");
}

m_thickness *= scale;
m_thicknessInX0 *= scale;
m_thicknessInL0 *= scale;
Expand Down
3 changes: 2 additions & 1 deletion Fatras/include/ActsFatras/Kernel/detail/SimulationActor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ struct SimulationActor {
// particle direction is normalized, not sure about surface normal
auto cosIncidenceInv =
normal.norm() / normal.dot(before.unitDirection());
slab.scaleThickness(cosIncidenceInv);
// apply abs in case `normal` and `before` produce an angle > 90°
slab.scaleThickness(std::abs(cosIncidenceInv));
// run the interaction simulation
interact(slab, result);
}
Expand Down

0 comments on commit 75f0835

Please sign in to comment.