@@ -36,6 +36,11 @@ namespace detray {
36
36
// / @tparam serialzier_t type of the serializer to the storage represenations
37
37
// / @tparam algebra_t the matrix/vector/point types to use
38
38
// / @tparam container_t the container types to use
39
+ // /
40
+ // / throughout:
41
+ // / @note that bin_edges is only used for variable binning
42
+ // / @note that if non-zero axis_spans are provided the values of the
43
+ // / mask is overwritten
39
44
template <typename bin_t , template <std::size_t > class serializer_t ,
40
45
typename algebra_t = ALGEBRA_PLUGIN<detray::scalar>>
41
46
class grid_factory {
@@ -76,12 +81,14 @@ class grid_factory {
76
81
typename phi_binning = axis::regular<host_container_types, scalar_type>,
77
82
std::enable_if_t <std::is_enum_v<decltype(r_bounds::label)>, bool > =
78
83
true >
79
- auto new_grid (const mask<annulus2D> &grid_bounds,
80
- const std::array<std::size_t , 2UL > n_bins,
81
- const std::vector<std::pair<loc_bin_index<annulus2D>, dindex>>
82
- &bin_capacities = {},
83
- const std::array<std::vector<scalar_type>, 2UL > &bin_edges = {
84
- {}}) const {
84
+ auto new_grid (
85
+ const mask<annulus2D> &grid_bounds,
86
+ const std::array<std::size_t , 2UL > n_bins,
87
+ const std::vector<std::pair<loc_bin_index<annulus2D>, dindex>>
88
+ &bin_capacities = {},
89
+ const std::array<std::vector<scalar_type>, 2UL > &bin_edges = {{}},
90
+ const std::array<std::vector<scalar_type>, 2UL > &axis_spans = {
91
+ {}}) const {
85
92
86
93
static_assert (
87
94
std::is_same_v<phi_bounds, axis::circular<>>,
@@ -96,13 +103,25 @@ class grid_factory {
96
103
constexpr auto e_phi_axis = static_cast <dindex>(axes_t ::label1);
97
104
98
105
auto b_values = grid_bounds.values ();
106
+ // Overwrite the mask values if axis spans are provided
107
+ if (!axis_spans[0UL ].empty ()) {
108
+ assert (axis_spans[0UL ].size () == 2UL );
109
+ b_values[boundary::e_min_r] = axis_spans[0UL ].at (0UL );
110
+ b_values[boundary::e_max_r] = axis_spans[0UL ].at (1UL );
111
+ }
112
+ scalar_type min_phi = b_values[boundary::e_average_phi] -
113
+ b_values[boundary::e_min_phi_rel];
114
+ scalar_type max_phi = b_values[boundary::e_average_phi] +
115
+ b_values[boundary::e_max_phi_rel];
116
+ if (!axis_spans[1UL ].empty ()) {
117
+ assert (axis_spans[1UL ].size () == 2UL );
118
+ min_phi = axis_spans[1UL ].at (0UL );
119
+ max_phi = axis_spans[1UL ].at (1UL );
120
+ }
99
121
100
122
return new_grid<local_frame>(
101
- {b_values[boundary::e_min_r], b_values[boundary::e_max_r],
102
- b_values[boundary::e_average_phi] -
103
- b_values[boundary::e_min_phi_rel],
104
- b_values[boundary::e_average_phi] +
105
- b_values[boundary::e_max_phi_rel]},
123
+ {b_values[boundary::e_min_r], b_values[boundary::e_max_r], min_phi,
124
+ max_phi},
106
125
{n_bins[e_r_axis], n_bins[e_phi_axis]}, bin_capacities,
107
126
{bin_edges[e_r_axis], bin_edges[e_phi_axis]},
108
127
types::list<r_bounds, phi_bounds>{},
@@ -121,12 +140,14 @@ class grid_factory {
121
140
typename z_binning = axis::regular<host_container_types, scalar_type>,
122
141
std::enable_if_t <std::is_enum_v<decltype(x_bounds::label)>, bool > =
123
142
true >
124
- auto new_grid (const mask<cuboid3D> &grid_bounds,
125
- const std::array<std::size_t , 3UL > n_bins,
126
- const std::vector<std::pair<loc_bin_index<cuboid3D>, dindex>>
127
- &bin_capacities = {},
128
- const std::array<std::vector<scalar_type>, 3UL > &bin_edges = {
129
- {}}) const {
143
+ auto new_grid (
144
+ const mask<cuboid3D> &grid_bounds,
145
+ const std::array<std::size_t , 3UL > n_bins,
146
+ const std::vector<std::pair<loc_bin_index<cuboid3D>, dindex>>
147
+ &bin_capacities = {},
148
+ const std::array<std::vector<scalar_type>, 3UL > &bin_edges = {{}},
149
+ const std::array<std::vector<scalar_type>, 3UL > &axis_spans = {
150
+ {}}) const {
130
151
// Axes boundaries and local indices
131
152
using boundary = cuboid3D::boundaries;
132
153
using axes_t = axes<cuboid3D>::template type<algebra_t >;
@@ -136,7 +157,23 @@ class grid_factory {
136
157
constexpr auto e_y_axis = static_cast <dindex>(axes_t ::label1);
137
158
constexpr auto e_z_axis = static_cast <dindex>(axes_t ::label2);
138
159
160
+ // Overwrite the mask values if axis spans are provided
139
161
auto b_values = grid_bounds.values ();
162
+ if (!axis_spans[0UL ].empty ()) {
163
+ assert (axis_spans[0UL ].size () == 2UL );
164
+ b_values[boundary::e_min_x] = axis_spans[0UL ].at (0UL );
165
+ b_values[boundary::e_max_x] = axis_spans[0UL ].at (1UL );
166
+ }
167
+ if (!axis_spans[1UL ].empty ()) {
168
+ assert (axis_spans[1UL ].size () == 2UL );
169
+ b_values[boundary::e_min_y] = axis_spans[1UL ].at (0UL );
170
+ b_values[boundary::e_max_y] = axis_spans[1UL ].at (1UL );
171
+ }
172
+ if (!axis_spans[2UL ].empty ()) {
173
+ assert (axis_spans[2UL ].size () == 2UL );
174
+ b_values[boundary::e_min_z] = axis_spans[2UL ].at (0UL );
175
+ b_values[boundary::e_max_z] = axis_spans[2UL ].at (1UL );
176
+ }
140
177
141
178
return new_grid<local_frame>(
142
179
{b_values[boundary::e_min_x], b_values[boundary::e_max_x],
@@ -165,7 +202,8 @@ class grid_factory {
165
202
const std::array<std::size_t , 2UL > n_bins,
166
203
const std::vector<std::pair<loc_bin_index<cylinder2D>, dindex>>
167
204
&bin_capacities = {},
168
- const std::array<std::vector<scalar_type>, 2UL > &bin_edges = {
205
+ const std::array<std::vector<scalar_type>, 2UL > &bin_edges = {{}},
206
+ const std::array<std::vector<scalar_type>, 2UL > &axis_spans = {
169
207
{}}) const {
170
208
171
209
static_assert (
@@ -181,7 +219,11 @@ class grid_factory {
181
219
constexpr auto e_z_axis = static_cast <dindex>(axes_t ::label1);
182
220
183
221
auto b_values = grid_bounds.values ();
184
-
222
+ if (!axis_spans[1UL ].empty ()) {
223
+ assert (axis_spans[1UL ].size () == 2UL );
224
+ b_values[boundary::e_lower_z] = axis_spans[1UL ].at (0UL );
225
+ b_values[boundary::e_upper_z] = axis_spans[1UL ].at (1UL );
226
+ }
185
227
return new_grid<local_frame>(
186
228
{-constant<scalar_type>::pi , constant<scalar_type>::pi ,
187
229
b_values[boundary::e_lower_z], b_values[boundary::e_upper_z]},
@@ -202,13 +244,14 @@ class grid_factory {
202
244
typename z_binning = axis::regular<host_container_types, scalar_type>,
203
245
std::enable_if_t <std::is_enum_v<decltype(rphi_bounds::label)>, bool > =
204
246
true >
205
- auto new_grid (const mask<concentric_cylinder2D> &grid_bounds,
206
- const std::array<std::size_t , 2UL > n_bins,
207
- const std::vector<
208
- std::pair<loc_bin_index<concentric_cylinder2D>, dindex>>
209
- &bin_capacities = {},
210
- const std::array<std::vector<scalar_type>, 2UL > &bin_edges = {
211
- {}}) const {
247
+ auto new_grid (
248
+ const mask<concentric_cylinder2D> &grid_bounds,
249
+ const std::array<std::size_t , 2UL > n_bins,
250
+ const std::vector<std::pair<loc_bin_index<concentric_cylinder2D>,
251
+ dindex>> &bin_capacities = {},
252
+ const std::array<std::vector<scalar_type>, 2UL > &bin_edges = {{}},
253
+ const std::array<std::vector<scalar_type>, 2UL > &axis_spans = {
254
+ {}}) const {
212
255
213
256
static_assert (
214
257
std::is_same_v<rphi_bounds, axis::circular<axis::label::e_rphi>>,
@@ -223,6 +266,11 @@ class grid_factory {
223
266
constexpr auto e_z_axis = static_cast <dindex>(axes_t ::label1);
224
267
225
268
auto b_values = grid_bounds.values ();
269
+ if (!axis_spans[1UL ].empty ()) {
270
+ assert (axis_spans[1UL ].size () == 2UL );
271
+ b_values[boundary::e_lower_z] = axis_spans[1UL ].at (0UL );
272
+ b_values[boundary::e_upper_z] = axis_spans[1UL ].at (1UL );
273
+ }
226
274
227
275
return new_grid<local_frame>(
228
276
{-constant<scalar_type>::pi , constant<scalar_type>::pi ,
@@ -250,7 +298,8 @@ class grid_factory {
250
298
const std::array<std::size_t , 3UL > n_bins,
251
299
const std::vector<std::pair<loc_bin_index<cylinder3D>, dindex>>
252
300
&bin_capacities = {},
253
- const std::array<std::vector<scalar_type>, 3UL > &bin_edges = {
301
+ const std::array<std::vector<scalar_type>, 3UL > &bin_edges = {{}},
302
+ const std::array<std::vector<scalar_type>, 3UL > &axis_spans = {
254
303
{}}) const {
255
304
256
305
static_assert (
@@ -267,11 +316,29 @@ class grid_factory {
267
316
constexpr auto e_z_axis = static_cast <dindex>(axes_t ::label2);
268
317
269
318
auto b_values = grid_bounds.values ();
319
+ // Overwrite the mask values if axis spans are provided
320
+ if (!axis_spans[0UL ].empty ()) {
321
+ assert (axis_spans[0UL ].size () == 2UL );
322
+ b_values[boundary::e_min_r] = axis_spans[0UL ].at (0UL );
323
+ b_values[boundary::e_max_r] = axis_spans[0UL ].at (1UL );
324
+ }
325
+ scalar_type min_phi = -constant<scalar_type>::pi ;
326
+ scalar_type max_phi = constant<scalar_type>::pi ;
327
+ if (!axis_spans[1UL ].empty ()) {
328
+ assert (axis_spans[1UL ].size () == 2UL );
329
+ min_phi = axis_spans[1UL ].at (0UL );
330
+ max_phi = axis_spans[1UL ].at (1UL );
331
+ }
332
+ if (!axis_spans[2UL ].empty ()) {
333
+ assert (axis_spans[2UL ].size () == 2UL );
334
+ b_values[boundary::e_min_z] = axis_spans[2UL ].at (0UL );
335
+ b_values[boundary::e_max_z] = axis_spans[2UL ].at (1UL );
336
+ }
270
337
271
338
return new_grid<local_frame>(
272
- {b_values[boundary::e_min_r], b_values[boundary::e_max_r],
273
- b_values[boundary::e_min_phi], b_values[boundary::e_max_phi ],
274
- -b_values[boundary::e_min_z], b_values[boundary::e_max_z]},
339
+ {b_values[boundary::e_min_r], b_values[boundary::e_max_r], min_phi,
340
+ max_phi, - b_values[boundary::e_min_z ],
341
+ b_values[boundary::e_max_z]},
275
342
{n_bins[e_r_axis], n_bins[e_phi_axis], n_bins[e_z_axis]},
276
343
bin_capacities,
277
344
{bin_edges[e_r_axis], bin_edges[e_phi_axis], bin_edges[e_z_axis]},
@@ -289,12 +356,14 @@ class grid_factory {
289
356
typename phi_binning = axis::regular<host_container_types, scalar_type>,
290
357
std::enable_if_t <std::is_enum_v<decltype(r_bounds::label)>, bool > =
291
358
true >
292
- auto new_grid (const mask<ring2D> &grid_bounds,
293
- const std::array<std::size_t , 2UL > n_bins,
294
- const std::vector<std::pair<loc_bin_index<ring2D>, dindex>>
295
- &bin_capacities = {},
296
- const std::array<std::vector<scalar_type>, 2UL > &bin_edges = {
297
- {}}) const {
359
+ auto new_grid (
360
+ const mask<ring2D> &grid_bounds,
361
+ const std::array<std::size_t , 2UL > n_bins,
362
+ const std::vector<std::pair<loc_bin_index<ring2D>, dindex>>
363
+ &bin_capacities = {},
364
+ const std::array<std::vector<scalar_type>, 2UL > &bin_edges = {{}},
365
+ const std::array<std::vector<scalar_type>, 2UL > &axis_spans = {
366
+ {}}) const {
298
367
299
368
static_assert (std::is_same_v<phi_bounds, axis::circular<>>,
300
369
" Phi axis bounds need to be circular for ring shape" );
@@ -308,6 +377,12 @@ class grid_factory {
308
377
constexpr auto e_phi_axis = static_cast <dindex>(axes_t ::label1);
309
378
310
379
auto b_values = grid_bounds.values ();
380
+ // Overwrite the mask values if axis spans are provided
381
+ if (!axis_spans[0UL ].empty ()) {
382
+ assert (axis_spans[0UL ].size () == 2UL );
383
+ b_values[boundary::e_inner_r] = axis_spans[0UL ].at (0UL );
384
+ b_values[boundary::e_outer_r] = axis_spans[0UL ].at (1UL );
385
+ }
311
386
312
387
return new_grid<local_frame>(
313
388
{b_values[boundary::e_inner_r], b_values[boundary::e_outer_r],
@@ -333,7 +408,8 @@ class grid_factory {
333
408
const std::array<std::size_t , 2UL > n_bins,
334
409
const std::vector<std::pair<loc_bin_index<rectangle2D>, dindex>>
335
410
&bin_capacities = {},
336
- const std::array<std::vector<scalar_type>, 2UL > &bin_edges = {
411
+ const std::array<std::vector<scalar_type>, 2UL > &bin_edges = {{}},
412
+ const std::array<std::vector<scalar_type>, 2UL > &axis_spans = {
337
413
{}}) const {
338
414
// Axes boundaries and local indices
339
415
using boundary = rectangle2D::boundaries;
@@ -344,6 +420,15 @@ class grid_factory {
344
420
constexpr auto e_y_axis = static_cast <dindex>(axes_t ::label1);
345
421
346
422
auto b_values = grid_bounds.values ();
423
+ // Overwrite the mask values if axis spans are provided
424
+ if (!axis_spans[0UL ].empty ()) {
425
+ assert (axis_spans[0UL ].size () == 2UL );
426
+ b_values[boundary::e_half_x] = axis_spans[0UL ].at (1UL );
427
+ }
428
+ if (!axis_spans[1UL ].empty ()) {
429
+ assert (axis_spans[1UL ].size () == 2UL );
430
+ b_values[boundary::e_half_y] = axis_spans[1UL ].at (1UL );
431
+ }
347
432
348
433
return new_grid<local_frame>(
349
434
{-b_values[boundary::e_half_x], b_values[boundary::e_half_x],
@@ -369,7 +454,8 @@ class grid_factory {
369
454
const std::array<std::size_t , 2UL > n_bins,
370
455
const std::vector<std::pair<loc_bin_index<trapezoid2D>, dindex>>
371
456
&bin_capacities = {},
372
- const std::array<std::vector<scalar_type>, 2UL > &bin_edges = {
457
+ const std::array<std::vector<scalar_type>, 2UL > &bin_edges = {{}},
458
+ const std::array<std::vector<scalar_type>, 2UL > &axis_spans = {
373
459
{}}) const {
374
460
// Axes boundaries and local indices
375
461
using boundary = trapezoid2D::boundaries;
@@ -380,6 +466,15 @@ class grid_factory {
380
466
constexpr auto e_y_axis = static_cast <dindex>(axes_t ::label1);
381
467
382
468
auto b_values = grid_bounds.values ();
469
+ // Overwrite the mask values if axis spans are provided
470
+ if (!axis_spans[0UL ].empty ()) {
471
+ assert (axis_spans[0UL ].size () == 2UL );
472
+ b_values[boundary::e_half_length_1] = axis_spans[0UL ].at (1UL );
473
+ }
474
+ if (!axis_spans[1UL ].empty ()) {
475
+ assert (axis_spans[1UL ].size () == 2UL );
476
+ b_values[boundary::e_half_length_2] = axis_spans[1UL ].at (1UL );
477
+ }
383
478
384
479
return new_grid<local_frame>({-b_values[boundary::e_half_length_1],
385
480
b_values[boundary::e_half_length_1],
0 commit comments