Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trapezoid construction for negative phi and older Geant4 #1227

Merged
merged 5 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/celer-sim/simple-driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ def strtobool(text):
time = run_output['time'].copy()
steps = time.pop('steps')
if use_device:
assert(len(steps) == run_output['num_step_iterations'][0])
assert steps
assert len(steps[0]) == run_output['num_step_iterations'][0]
else:
# Step times disabled on CPU from input
assert(steps is None)
assert steps is None
print(json.dumps(time, indent=1))
5 changes: 2 additions & 3 deletions src/orange/g4org/SolidConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ SolidEnclosedAngle get_polar_wedge(S const& solid)
CELER_EXPECT(
is_soft_unit_vector(Array<double, 3>{axis.x(), axis.y(), axis.z()}));

double const theta = 1 / std::cos(axis.z());
double const phi = std::atan2(axis.x() / axis.z(), axis.y() / axis.z());

double const theta = std::acos(axis.z());
double const phi = std::atan2(axis.y(), axis.x());
return {native_value_to<Turn>(theta), native_value_to<Turn>(phi)};
}

Expand Down
4 changes: 0 additions & 4 deletions src/orange/orangeinp/ConvexRegion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ namespace orangeinp
{
namespace
{
using Real2 = Array<real_type, 2>;
//---------------------------------------------------------------------------//
/*!
* Create a z-aligned bounding box infinite along z and symmetric in r.
Expand Down Expand Up @@ -356,9 +355,6 @@ GenTrap GenTrap::from_trap(
CELER_VALIDATE(theta >= zero_quantity() && theta < Turn{0.25},
<< "invalid angle " << theta.value()
<< " [turns]: must be in the range [0, 0.25)");
CELER_VALIDATE(phi >= zero_quantity() && phi < Turn{1.},
<< "invalid angle " << phi.value()
<< " [turns]: must be in the range [0, 1)");

// Calculate offset of faces from z axis
auto [dxdz_hz, dydz_hz] = [&]() -> std::pair<real_type, real_type> {
Expand Down
19 changes: 19 additions & 0 deletions test/orange/g4org/SolidConverter.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,25 @@ TEST_F(SolidConverterTest, trap)
{1.20, 1.94, -4.01},
{-0.81, 1.9, -4.01},
{-1.96, -2.94, 4.01}});
tan_alpha = std::tan(30 * degree);
this->build_and_test(
G4Trap("trap",
10,
10 * degree,
-15 * degree,
20,
10,
10,
tan_alpha,
30,
15,
15,
tan_alpha),
R"json({"_type":"shape","interior":{"_type":"gentrap","halfheight":1.0,"lower":[[-2.325019322917132,-1.9543632192272244],[-0.32501932291713187,-1.9543632192272244],[1.9843817538413706,2.0456367807727753],[-0.01561824615862939,2.0456367807727753]],"upper":[[-3.061732023030996,-3.0456367807727753],[-0.06173202303099612,-3.0456367807727753],[3.4023695921067576,2.9543632192272247],[0.4023695921067574,2.9543632192272247]]},"label":"trap"})json",
{{-2.33, -1.96, -1.01},
{-2.32, -1.95, -0.99},
{3.41, 2.96, 1.01},
{3.40, 2.95, 0.99}});
}

TEST_F(SolidConverterTest, trd_box)
Expand Down
Loading