forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Geometry.test.cc
342 lines (301 loc) · 13 KB
/
Geometry.test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
//----------------------------------*-C++-*----------------------------------//
// Copyright 2022-2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celeritas/geo/Geometry.test.cc
//---------------------------------------------------------------------------//
#include "celeritas_config.h"
#include "geocel/GeoParamsOutput.hh"
#include "celeritas/geo/GeoParams.hh"
#include "HeuristicGeoTestBase.hh"
#include "celeritas_test.hh"
namespace celeritas
{
namespace test
{
constexpr bool not_orange_geo
= (CELERITAS_CORE_GEO != CELERITAS_CORE_GEO_ORANGE);
//---------------------------------------------------------------------------//
class TestEm3Test : public HeuristicGeoTestBase
{
protected:
std::string_view geometry_basename() const override
{
return "testem3-flat"sv;
}
HeuristicGeoScalars build_scalars() const final
{
HeuristicGeoScalars result;
result.lower = {-19.77, -20, -20};
result.upper = {19.43, 20, 20};
result.world_volume = this->geometry()->find_volume("world");
return result;
}
size_type num_steps() const final { return 1024; }
SpanConstStr reference_volumes() const final;
SpanConstReal reference_avg_path() const final;
};
auto TestEm3Test::reference_volumes() const -> SpanConstStr
{
static std::string const vols[]
= {"world", "gap_0", "absorber_0", "gap_1",
"absorber_1", "gap_2", "absorber_2", "gap_3",
"absorber_3", "gap_4", "absorber_4", "gap_5",
"absorber_5", "gap_6", "absorber_6", "gap_7",
"absorber_7", "gap_8", "absorber_8", "gap_9",
"absorber_9", "gap_10", "absorber_10", "gap_11",
"absorber_11", "gap_12", "absorber_12", "gap_13",
"absorber_13", "gap_14", "absorber_14", "gap_15",
"absorber_15", "gap_16", "absorber_16", "gap_17",
"absorber_17", "gap_18", "absorber_18", "gap_19",
"absorber_19", "gap_20", "absorber_20", "gap_21",
"absorber_21", "gap_22", "absorber_22", "gap_23",
"absorber_23", "gap_24", "absorber_24", "gap_25",
"absorber_25", "gap_26", "absorber_26", "gap_27",
"absorber_27", "gap_28", "absorber_28", "gap_29",
"absorber_29", "gap_30", "absorber_30", "gap_31",
"absorber_31", "gap_32", "absorber_32", "gap_33",
"absorber_33", "gap_34", "absorber_34", "gap_35",
"absorber_35", "gap_36", "absorber_36", "gap_37",
"absorber_37", "gap_38", "absorber_38", "gap_39",
"absorber_39", "gap_40", "absorber_40", "gap_41",
"absorber_41", "gap_42", "absorber_42", "gap_43",
"absorber_43", "gap_44", "absorber_44", "gap_45",
"absorber_45", "gap_46", "absorber_46", "gap_47",
"absorber_47", "gap_48", "absorber_48", "gap_49",
"absorber_49"};
return make_span(vols);
}
auto TestEm3Test::reference_avg_path() const -> SpanConstReal
{
static real_type const orange_paths[]
= {7.504, 0.07378, 0.2057, 0.102, 0.2408, 0.1006, 0.3019, 0.1153,
0.2812, 0.1774, 0.4032, 0.1354, 0.3163, 0.1673, 0.3465, 0.1786,
0.4494, 0.2237, 0.5863, 0.192, 0.4027, 0.1905, 0.5949, 0.3056,
0.5217, 0.2179, 0.5365, 0.2123, 0.5484, 0.2938, 0.634, 0.3144,
0.6364, 0.2207, 0.5688, 0.2685, 0.6717, 0.2697, 0.6468, 0.2824,
0.7424, 0.3395, 0.6919, 0.3018, 0.7078, 0.3441, 0.9093, 0.4125,
0.7614, 0.334, 0.8102, 0.3901, 0.8114, 0.3377, 0.8856, 0.39,
0.7765, 0.3847, 0.785, 0.3017, 0.6694, 0.3026, 0.7018, 0.2482,
0.6192, 0.2405, 0.6014, 0.2733, 0.6454, 0.2804, 0.6941, 0.2608,
0.5855, 0.2318, 0.5043, 0.1906, 0.6139, 0.3125, 0.6684, 0.3002,
0.7295, 0.2874, 0.6328, 0.2524, 0.532, 0.2354, 0.5435, 0.2612,
0.5484, 0.2294, 0.5671, 0.246, 0.5157, 0.1953, 0.3996, 0.1301,
0.3726, 0.1642, 0.3317, 0.1375, 0.1909};
return make_span(orange_paths);
}
//---------------------------------------------------------------------------//
class SimpleCmsTest : public HeuristicGeoTestBase
{
protected:
std::string_view geometry_basename() const override
{
return "simple-cms"sv;
}
HeuristicGeoScalars build_scalars() const final
{
HeuristicGeoScalars result;
result.lower = {-30, -30, -700};
result.upper = {30, 30, 700};
result.log_min_step = std::log(1e-4);
result.log_max_step = std::log(1e2);
result.world_volume = this->geometry()->find_volume("world");
return result;
}
size_type num_steps() const final { return 1024; }
SpanConstStr reference_volumes() const final;
SpanConstReal reference_avg_path() const final;
};
auto SimpleCmsTest::reference_volumes() const -> SpanConstStr
{
static std::string const vols[] = {"vacuum_tube",
"si_tracker",
"em_calorimeter",
"had_calorimeter",
"sc_solenoid",
"fe_muon_chambers",
"world"};
return make_span(vols);
}
auto SimpleCmsTest::reference_avg_path() const -> SpanConstReal
{
static real_type const paths[]
= {56.38, 403, 261.3, 507.5, 467.1, 1142, 1851};
return make_span(paths);
}
//---------------------------------------------------------------------------//
class ThreeSpheresTest : public HeuristicGeoTestBase
{
protected:
std::string_view geometry_basename() const override
{
return "three-spheres"sv;
}
HeuristicGeoScalars build_scalars() const final
{
HeuristicGeoScalars result;
result.lower = {-2.1, -2.1, -2.1};
result.upper = {2.1, 2.1, 2.1};
return result;
}
size_type num_steps() const final { return 1024; }
SpanConstStr reference_volumes() const final;
SpanConstReal reference_avg_path() const final;
};
auto ThreeSpheresTest::reference_volumes() const -> SpanConstStr
{
static std::string const vols[] = {"inner", "middle", "outer", "world"};
return make_span(vols);
}
auto ThreeSpheresTest::reference_avg_path() const -> SpanConstReal
{
static real_type const paths[] = {0.2013, 3.346, 6.696, 375.5};
return make_span(paths);
}
//---------------------------------------------------------------------------//
#if CELERITAS_CORE_GEO == CELERITAS_CORE_GEO_ORANGE
# define CmseTest DISABLED_CmseTest
#endif
class CmseTest : public HeuristicGeoTestBase
{
protected:
std::string_view geometry_basename() const override { return "cmse"sv; }
HeuristicGeoScalars build_scalars() const final
{
HeuristicGeoScalars result;
result.lower = {-80, -80, -4500};
result.upper = {80, 80, 4500};
result.log_min_step = std::log(1e-4);
result.log_max_step = std::log(1e3);
return result;
}
size_type num_steps() const final { return 1024; }
SpanConstStr reference_volumes() const final;
SpanConstReal reference_avg_path() const final;
};
auto CmseTest::reference_volumes() const -> SpanConstStr
{
// clang-format off
static std::string const vols[] = {"CMStoZDC", "Tracker", "CALO", "MUON",
"BEAM", "BEAM1", "BEAM2", "BEAM3", "TrackerPixelNose", "VCAL",
"TotemT1", "TotemT2", "CastorF", "CastorB", "OQUA", "BSC2", "CMSE",
"OCMS"};
// clang-format on
return make_span(vols);
}
auto CmseTest::reference_avg_path() const -> SpanConstReal
{
// clang-format off
static real_type const paths[] = {74.17136, 13.25306, 76.67924, 449.5464,
0.09551618, 0.3231404, 0.310899, 0.3844357, 0.01179415, 11.09485,
9.101073, 0.0004083249, 0.3033329, 0.4292332, 228.7892, 0.03947559,
563.0746, 2858.592};
// clang-format on
return make_span(paths);
}
//---------------------------------------------------------------------------//
// TESTEM3
//---------------------------------------------------------------------------//
TEST_F(TestEm3Test, host)
{
if (CELERITAS_USE_GEANT4 || CELERITAS_CORE_GEO != CELERITAS_CORE_GEO_ORANGE)
{
EXPECT_TRUE(this->geometry()->supports_safety());
}
else
{
// ORANGE from JSON file doesn't support safety
EXPECT_FALSE(this->geometry()->supports_safety());
}
real_type tol = not_orange_geo ? 0.35 : 1e-3;
this->run_host(512, tol);
}
TEST_F(TestEm3Test, TEST_IF_CELER_DEVICE(device))
{
real_type tol = not_orange_geo ? 0.25 : 1e-3;
this->run_device(512, tol);
}
//---------------------------------------------------------------------------//
// SIMPLECMS
//---------------------------------------------------------------------------//
TEST_F(SimpleCmsTest, host)
{
// Results were generated with ORANGE
real_type tol = not_orange_geo ? 0.05 : 1e-3;
this->run_host(512, tol);
}
TEST_F(SimpleCmsTest, TEST_IF_CELER_DEVICE(device))
{
// Results were generated with ORANGE
real_type tol = not_orange_geo ? 0.025 : 1e-3;
this->run_device(512, tol);
}
TEST_F(SimpleCmsTest, output)
{
GeoParamsOutput out(this->geometry());
EXPECT_EQ("geometry", out.label());
if (!CELERITAS_USE_JSON)
{
EXPECT_EQ(R"json("output unavailable")json", to_string(out));
}
else if (CELERITAS_CORE_GEO == CELERITAS_CORE_GEO_VECGEOM)
{
EXPECT_JSON_EQ(
R"json({"bbox":[[-1000.001,-1000.001,-2000.001],[1000.001,1000.001,2000.001]],"supports_safety":true,"volumes":{"label":["vacuum_tube","si_tracker","em_calorimeter","had_calorimeter","sc_solenoid","fe_muon_chambers","world"]}})json",
to_string(out));
}
else if (CELERITAS_CORE_GEO == CELERITAS_CORE_GEO_ORANGE
&& CELERITAS_USE_GEANT4)
{
EXPECT_JSON_EQ(
R"json({"bbox":[[-1000.0,-1000.0,-2000.0],[1000.0,1000.0,2000.0]],"supports_safety":false,"surfaces":{"label":["world_box@mx","world_box@px","world_box@my","world_box@py","world_box@mz","world_box@pz","crystal_em_calorimeter@excluded.mz","crystal_em_calorimeter@excluded.pz","lhc_vacuum_tube@cz","crystal_em_calorimeter@excluded.cz","crystal_em_calorimeter@interior.cz","hadron_calorimeter@interior.cz","iron_muon_chambers@excluded.cz","iron_muon_chambers@interior.cz"]},"volumes":{"label":["[EXTERIOR]@world0x0","vacuum_tube@0x0","si_tracker@0x0","em_calorimeter@0x0","had_calorimeter@0x0","sc_solenoid@0x0","fe_muon_chambers@0x0","world@0x0"]}})json",
this->genericize_pointers(to_string(out)));
}
else if (CELERITAS_CORE_GEO == CELERITAS_CORE_GEO_ORANGE)
{
EXPECT_JSON_EQ(
R"json({"bbox":[[-1000.0,-1000.0,-2000.0],[1000.0,1000.0,2000.0]],"supports_safety":false,"surfaces":{"label":["world_box.mx@global","world_box.px@global","world_box.my@global","world_box.py@global","world_box.mz@global","world_box.pz@global","guide_tube.coz@global","crystal_em_calorimeter_outer.mz@global","crystal_em_calorimeter_outer.pz@global","silicon_tracker_outer.coz@global","crystal_em_calorimeter_outer.coz@global","hadron_calorimeter_outer.coz@global","superconducting_solenoid_outer.coz@global","iron_muon_chambers_outer.coz@global"]},"volumes":{"label":["[EXTERIOR]@global","vacuum_tube@global","si_tracker@global","em_calorimeter@global","had_calorimeter@global","sc_solenoid@global","fe_muon_chambers@global","world@global"]}})json",
this->genericize_pointers(to_string(out)));
}
}
//---------------------------------------------------------------------------//
// THREE_SPHERES
//---------------------------------------------------------------------------//
TEST_F(ThreeSpheresTest, host)
{
// Results were generated with ORANGE
real_type tol = not_orange_geo ? 0.05 : 1e-3;
EXPECT_TRUE(this->geometry()->supports_safety());
this->run_host(512, tol);
}
TEST_F(ThreeSpheresTest, TEST_IF_CELER_DEVICE(device))
{
// Results were generated with ORANGE
real_type tol = not_orange_geo ? 0.025 : 1e-3;
this->run_device(512, tol);
}
//---------------------------------------------------------------------------//
// CMSE
//---------------------------------------------------------------------------//
TEST_F(CmseTest, host)
{
auto const& bbox = this->geometry()->bbox();
real_type const geo_eps
= CELERITAS_CORE_GEO == CELERITAS_CORE_GEO_VECGEOM ? 0.001 : 0;
EXPECT_VEC_SOFT_EQ(
(Real3{-1750 - geo_eps, -1750 - geo_eps, -45000 - geo_eps}),
bbox.lower());
EXPECT_VEC_SOFT_EQ((Real3{1750 + geo_eps, 1750 + geo_eps, 45000 + geo_eps}),
bbox.upper());
real_type tol = CELERITAS_CORE_GEO == CELERITAS_CORE_GEO_VECGEOM ? 0.005
: 0.35;
this->run_host(512, tol);
}
TEST_F(CmseTest, TEST_IF_CELER_DEVICE(device))
{
this->run_device(512, 0.005);
}
//---------------------------------------------------------------------------//
} // namespace test
} // namespace celeritas