8#include <ecl/geometry/BelleCrystal.h>
9#include <ecl/geometry/BelleLathe.h>
10#include <gtest/gtest.h>
11#include "ecl/geometry/shapes.h"
20 class BelleCrystalTest :
public ::testing::Test {};
23 class BelleLatheTest :
public ::testing::Test {
25 double absolute_tolerance = 0.00001;
28 TEST_F(BelleCrystalTest, BoundingBoxFourSides)
31 G4ThreeVector vertices[] = {G4ThreeVector(-1, -1, -1), G4ThreeVector(1, -1, -1), G4ThreeVector(1, 1, -1), G4ThreeVector(-1, 1, -1),
32 G4ThreeVector(-1, -1, 1), G4ThreeVector(1, -1, 1), G4ThreeVector(1, 1, 1), G4ThreeVector(-1, 1, 1)
37 G4ThreeVector pMin; G4ThreeVector pMax;
41 G4ThreeVector pMin_real(-1, -1, -1); G4ThreeVector pMax_real(1, 1, 1);
43 EXPECT_DOUBLE_EQ(pMin_real.x(), pMin.x());
44 EXPECT_DOUBLE_EQ(pMin_real.y(), pMin.y());
45 EXPECT_DOUBLE_EQ(pMin_real.z(), pMin.z());
47 EXPECT_DOUBLE_EQ(pMax_real.x(), pMax.x());
48 EXPECT_DOUBLE_EQ(pMax_real.y(), pMax.y());
49 EXPECT_DOUBLE_EQ(pMax_real.z(), pMax.z());
52 TEST_F(BelleCrystalTest, BoundingBoxFiveSides)
56 double c1 = 0.25 * (
sqrt(5) - 1), c2 = 0.25 * (
sqrt(5) + 1);
57 double s1 = 0.25 *
sqrt(10 + 2 *
sqrt(5)), s2 = 0.25 *
sqrt(10 - 2 *
sqrt(5));
58 G4ThreeVector vertices[] = {G4ThreeVector(0, 1, -z), G4ThreeVector(-s1, c1, -z), G4ThreeVector(-s2, -c2, -z), G4ThreeVector(s2, -c2, -z), G4ThreeVector(s1, c1, -z),
59 G4ThreeVector(0, 1, z), G4ThreeVector(-s1, c1, z), G4ThreeVector(-s2, -c2, z), G4ThreeVector(s2, -c2, z), G4ThreeVector(s1, c1, z)
64 G4ThreeVector pMin; G4ThreeVector pMax;
68 G4ThreeVector pMin_real(-s1, -c2, -z); G4ThreeVector pMax_real(s1, 1, z);
70 EXPECT_DOUBLE_EQ(pMin_real.x(), pMin.x());
71 EXPECT_DOUBLE_EQ(pMin_real.y(), pMin.y());
72 EXPECT_DOUBLE_EQ(pMin_real.z(), pMin.z());
74 EXPECT_DOUBLE_EQ(pMax_real.x(), pMax.x());
75 EXPECT_DOUBLE_EQ(pMax_real.y(), pMax.y());
76 EXPECT_DOUBLE_EQ(pMax_real.z(), pMax.z());
79 TEST_F(BelleCrystalTest, PentagonSurface)
83 double c1 = 0.25 * (
sqrt(5) - 1), c2 = 0.25 * (
sqrt(5) + 1);
84 double s1 = 0.25 *
sqrt(10 + 2 *
sqrt(5)), s2 = 0.25 *
sqrt(10 - 2 *
sqrt(5));
85 G4ThreeVector p0m(0, 1, -z), p1m(-s1, c1, -z), p2m(-s2, -c2, -z), p3m(s2, -c2, -z), p4m(s1, c1, -z);
86 G4ThreeVector p0p(0, 1, z), p1p(-s1, c1, z), p2p(-s2, -c2, z), p3p(s2, -c2, z), p4p(s1, c1, z);
87 G4ThreeVector vertices[] = {p0m, p1m, p2m, p3m, p4m, p0p, p1p, p2p, p3p, p4p};
90 for (
int i = 0; i < 1000 * 100; i++) {
91 G4ThreeVector p = c->GetPointOnSurface();
92 EXPECT_EQ(c->Inside(p), kSurface);
97 TEST_F(BelleCrystalTest, BarrelSurfaces)
99 vector<shape_t*> cryst = load_shapes(
"/ecl/data/crystal_shape_barrel.dat");
100 double wrapthickness = 0.17;
101 for (
auto it = cryst.begin(); it != cryst.end(); it++) {
103 std::string prefix(
"sv_"); prefix +=
"barrel"; prefix +=
"_wrap";
105 G4VSolid* c = s->get_solid(prefix, wrapthickness, tw);
106 for (
int i = 0; i < 1000 * 100; i++) {
107 G4ThreeVector p = c->GetPointOnSurface();
108 EInside I = c->Inside(p);
109 EXPECT_EQ(I, kSurface);
113 for (
auto it = cryst.begin(); it != cryst.end(); it++)
delete *it;
116 TEST_F(BelleCrystalTest, ForwardSurfaces)
118 vector<shape_t*> cryst = load_shapes(
"/ecl/data/crystal_shape_forward.dat");
119 double wrapthickness = 0.17;
120 for (
auto it = cryst.begin(); it != cryst.end(); it++) {
122 std::string prefix(
"sv_"); prefix +=
"barrel"; prefix +=
"_wrap";
124 G4VSolid* c = s->get_solid(prefix, wrapthickness, tw);
125 for (
int i = 0; i < 1000 * 100; i++) {
126 G4ThreeVector p = c->GetPointOnSurface();
127 EInside I = c->Inside(p);
128 EXPECT_EQ(I, kSurface);
132 for (
auto it = cryst.begin(); it != cryst.end(); it++)
delete *it;
135 TEST_F(BelleCrystalTest, BackwardSurfaces)
137 vector<shape_t*> cryst = load_shapes(
"/ecl/data/crystal_shape_backward.dat");
138 double wrapthickness = 0.17;
139 for (
auto it = cryst.begin(); it != cryst.end(); it++) {
141 std::string prefix(
"sv_"); prefix +=
"barrel"; prefix +=
"_wrap";
143 G4VSolid* c = s->get_solid(prefix, wrapthickness, tw);
144 for (
int i = 0; i < 1000 * 100; i++) {
145 G4ThreeVector p = c->GetPointOnSurface();
146 EInside I = c->Inside(p);
147 EXPECT_EQ(I, kSurface);
151 for (
auto it = cryst.begin(); it != cryst.end(); it++)
delete *it;
155 TEST_F(BelleLatheTest, BoundingBoxSect0)
158 zr_t bint[] = {{ -1, 0}, {1, 0}, {1, 1}, { -1, 1}};
159 std::vector<zr_t> contourb(bint, bint +
sizeof(bint) /
sizeof(
zr_t));
163 G4ThreeVector pMin; G4ThreeVector pMax;
167 G4ThreeVector pMin_real(-1, -1, -1);
168 G4ThreeVector pMax_real(0, 1, 1);
170 EXPECT_NEAR(pMin_real.x(), pMin.x(), absolute_tolerance);
171 EXPECT_NEAR(pMin_real.y(), pMin.y(), absolute_tolerance);
172 EXPECT_NEAR(pMin_real.z(), pMin.z(), absolute_tolerance);
174 EXPECT_NEAR(pMax_real.x(), pMax.x(), absolute_tolerance);
175 EXPECT_NEAR(pMax_real.y(), pMax.y(), absolute_tolerance);
176 EXPECT_NEAR(pMax_real.z(), pMax.z(), absolute_tolerance);
180 TEST_F(BelleLatheTest, BoundingBoxSect1)
183 zr_t bint[] = {{ -1, 0}, {1, 0}, {1, 1}, { -1, 1}};
184 std::vector<zr_t> contourb(bint, bint +
sizeof(bint) /
sizeof(
zr_t));
188 G4ThreeVector pMin; G4ThreeVector pMax;
192 G4ThreeVector pMin_real(0, -1, -1);
193 G4ThreeVector pMax_real(1, 1, 1);
195 EXPECT_NEAR(pMin_real.x(), pMin.x(), absolute_tolerance);
196 EXPECT_NEAR(pMin_real.y(), pMin.y(), absolute_tolerance);
197 EXPECT_NEAR(pMin_real.z(), pMin.z(), absolute_tolerance);
199 EXPECT_NEAR(pMax_real.x(), pMax.x(), absolute_tolerance);
200 EXPECT_NEAR(pMax_real.y(), pMax.y(), absolute_tolerance);
201 EXPECT_NEAR(pMax_real.z(), pMax.z(), absolute_tolerance);
205 TEST_F(BelleLatheTest, BoundingBoxSect2)
208 zr_t bint[] = {{ -1, 0}, {1, 0}, {1, 1}, { -1, 1}};
209 std::vector<zr_t> contourb(bint, bint +
sizeof(bint) /
sizeof(
zr_t));
213 G4ThreeVector pMin; G4ThreeVector pMax;
217 G4ThreeVector pMin_real(-1, -1, -1);
218 G4ThreeVector pMax_real(0, 0, 1);
220 EXPECT_NEAR(pMin_real.x(), pMin.x(), absolute_tolerance);
221 EXPECT_NEAR(pMin_real.y(), pMin.y(), absolute_tolerance);
222 EXPECT_NEAR(pMin_real.z(), pMin.z(), absolute_tolerance);
224 EXPECT_NEAR(pMax_real.x(), pMax.x(), absolute_tolerance);
225 EXPECT_NEAR(pMax_real.y(), pMax.y(), absolute_tolerance);
226 EXPECT_NEAR(pMax_real.z(), pMax.z(), absolute_tolerance);
230 TEST_F(BelleLatheTest, BoundingBoxSect3)
233 zr_t bint[] = {{ -1, 0}, {1, 0}, {1, 1}, { -1, 1}};
234 std::vector<zr_t> contourb(bint, bint +
sizeof(bint) /
sizeof(
zr_t));
238 G4ThreeVector pMin; G4ThreeVector pMax;
242 G4ThreeVector pMin_real(-1, -1, -1);
243 G4ThreeVector pMax_real(1, 1, 1);
245 EXPECT_NEAR(pMin_real.x(), pMin.x(), absolute_tolerance);
246 EXPECT_NEAR(pMin_real.y(), pMin.y(), absolute_tolerance);
247 EXPECT_NEAR(pMin_real.z(), pMin.z(), absolute_tolerance);
249 EXPECT_NEAR(pMax_real.x(), pMax.x(), absolute_tolerance);
250 EXPECT_NEAR(pMax_real.y(), pMax.y(), absolute_tolerance);
251 EXPECT_NEAR(pMax_real.z(), pMax.z(), absolute_tolerance);
255 TEST_F(BelleLatheTest, BoundingBoxSect4)
258 zr_t bint[] = {{ -1, 0.5}, {1, 0.5}, {1, 1}, { -1, 1}};
259 std::vector<zr_t> contourb(bint, bint +
sizeof(bint) /
sizeof(
zr_t));
263 G4ThreeVector pMin; G4ThreeVector pMax;
267 G4ThreeVector pMin_real(cos(3 * M_PI / 4), 0.5 * sin(M_PI / 4), -1);
268 G4ThreeVector pMax_real(cos(M_PI / 4), 1, 1);
270 EXPECT_NEAR(pMin_real.x(), pMin.x(), absolute_tolerance);
271 EXPECT_NEAR(pMin_real.y(), pMin.y(), absolute_tolerance);
272 EXPECT_NEAR(pMin_real.z(), pMin.z(), absolute_tolerance);
274 EXPECT_NEAR(pMax_real.x(), pMax.x(), absolute_tolerance);
275 EXPECT_NEAR(pMax_real.y(), pMax.y(), absolute_tolerance);
276 EXPECT_NEAR(pMax_real.z(), pMax.z(), absolute_tolerance);
a Belle crystal in Geant4
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
Two vectors define an axis-parallel bounding box for the shape.
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
Two vectors define an axis-parallel bounding box for the shape.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.
simple struct with z and r coordinates