forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayerCreator.cpp
More file actions
444 lines (388 loc) · 17.6 KB
/
LayerCreator.cpp
File metadata and controls
444 lines (388 loc) · 17.6 KB
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
// This file is part of the ACTS project.
//
// Copyright (C) 2016 CERN for the benefit of the ACTS project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
#include "Acts/Geometry/LayerCreator.hpp"
#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Geometry/CylinderLayer.hpp"
#include "Acts/Geometry/DiscLayer.hpp"
#include "Acts/Geometry/Extent.hpp"
#include "Acts/Geometry/Layer.hpp"
#include "Acts/Geometry/PlaneLayer.hpp"
#include "Acts/Geometry/ProtoLayer.hpp"
#include "Acts/Geometry/SurfaceArrayCreator.hpp"
#include "Acts/Surfaces/CylinderBounds.hpp"
#include "Acts/Surfaces/RadialBounds.hpp"
#include "Acts/Surfaces/RectangleBounds.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/Diagnostics.hpp"
#include <algorithm>
#include <iterator>
#include <ostream>
#include <set>
#include <utility>
namespace Acts {
using VectorHelpers::perp;
using VectorHelpers::phi;
LayerCreator::LayerCreator(const LayerCreator::Config& lcConfig,
std::unique_ptr<const Logger> logger)
: m_cfg(lcConfig), m_logger(std::move(logger)) {}
void LayerCreator::setConfiguration(const LayerCreator::Config& lcConfig) {
// @todo check consistency
// copy the configuration
m_cfg = lcConfig;
}
void LayerCreator::setLogger(std::unique_ptr<const Logger> newLogger) {
m_logger = std::move(newLogger);
}
MutableLayerPtr LayerCreator::cylinderLayer(
const GeometryContext& gctx,
std::vector<std::shared_ptr<const Surface>> surfaces, std::size_t binsPhi,
std::size_t binsZ, std::optional<ProtoLayer> _protoLayer,
const Transform3& transform, std::unique_ptr<ApproachDescriptor> ad,
std::uint8_t maxNeighborDistance) const {
ProtoLayer protoLayer =
_protoLayer ? *_protoLayer : ProtoLayer(gctx, surfaces);
if (!_protoLayer) {
protoLayer.envelope[AxisDirection::AxisR] = m_cfg.defaultEnvelopeR;
protoLayer.envelope[AxisDirection::AxisZ] = m_cfg.defaultEnvelopeZ;
}
// Remaining layer parameters - they include the envelopes
double layerR = protoLayer.medium(AxisDirection::AxisR);
double layerZ = protoLayer.medium(AxisDirection::AxisZ);
double layerHalfZ = 0.5 * protoLayer.range(AxisDirection::AxisZ);
double layerThickness = protoLayer.range(AxisDirection::AxisR);
ACTS_VERBOSE("Creating a cylindrical Layer:");
ACTS_VERBOSE(" - with layer R = " << layerR);
ACTS_VERBOSE(" - from R min/max = "
<< protoLayer.min(AxisDirection::AxisR, false) << " / "
<< protoLayer.max(AxisDirection::AxisR, false));
ACTS_VERBOSE(" - with R thickness = " << layerThickness);
ACTS_VERBOSE(" - incl envelope = "
<< protoLayer.envelope[AxisDirection::AxisR][0u] << " / "
<< protoLayer.envelope[AxisDirection::AxisR][1u]);
ACTS_VERBOSE(" - with z min/max = "
<< protoLayer.min(AxisDirection::AxisZ, false) << " (-"
<< protoLayer.envelope[AxisDirection::AxisZ][0u] << ") / "
<< protoLayer.max(AxisDirection::AxisZ, false) << " (+"
<< protoLayer.envelope[AxisDirection::AxisZ][1u] << ")");
ACTS_VERBOSE(" - z center = " << layerZ);
ACTS_VERBOSE(" - halflength z = " << layerHalfZ);
// create the layer transforms if not given
// we need to transform in case layerZ != 0, so that the layer will be
// correctly defined using the halflength
Transform3 fullTransform = transform;
if (fullTransform.isApprox(Transform3::Identity())) {
fullTransform = Translation3(0, 0, layerZ) * fullTransform;
ACTS_VERBOSE(" - layer z shift = " << -layerZ);
}
ACTS_VERBOSE(" - with phi min/max = "
<< protoLayer.min(AxisDirection::AxisPhi, false) << " / "
<< protoLayer.max(AxisDirection::AxisPhi, false));
ACTS_VERBOSE(" - # of modules = " << surfaces.size() << " ordered in ( "
<< binsPhi << " x " << binsZ << ")");
std::unique_ptr<SurfaceArray> sArray;
if (!surfaces.empty()) {
sArray = m_cfg.surfaceArrayCreator->surfaceArrayOnCylinder(
gctx, std::move(surfaces), binsPhi, binsZ, protoLayer, fullTransform,
maxNeighborDistance);
}
// create the layer and push it back
std::shared_ptr<const CylinderBounds> cBounds(
new CylinderBounds(layerR, layerHalfZ));
// create the layer
MutableLayerPtr cLayer =
CylinderLayer::create(fullTransform, cBounds, std::move(sArray),
layerThickness, std::move(ad), active);
if (!cLayer) {
ACTS_ERROR("Creation of cylinder layer did not succeed!");
}
associateSurfacesToLayer(*cLayer);
// now return
return cLayer;
}
MutableLayerPtr LayerCreator::cylinderLayer(
const GeometryContext& gctx,
std::vector<std::shared_ptr<const Surface>> surfaces, BinningType bTypePhi,
BinningType bTypeZ, std::optional<ProtoLayer> _protoLayer,
const Transform3& transform, std::unique_ptr<ApproachDescriptor> ad,
std::uint8_t maxNeighborDistance) const {
ProtoLayer protoLayer =
_protoLayer ? *_protoLayer : ProtoLayer(gctx, surfaces);
if (!_protoLayer) {
protoLayer.envelope[AxisDirection::AxisR] = m_cfg.defaultEnvelopeR;
protoLayer.envelope[AxisDirection::AxisZ] = m_cfg.defaultEnvelopeZ;
}
// remaining layer parameters
double layerR = protoLayer.medium(AxisDirection::AxisR);
double layerZ = protoLayer.medium(AxisDirection::AxisZ);
double layerHalfZ = 0.5 * protoLayer.range(AxisDirection::AxisZ);
double layerThickness = protoLayer.range(AxisDirection::AxisR);
// adjust the layer radius
ACTS_VERBOSE("Creating a cylindrical Layer:");
ACTS_VERBOSE(" - with layer R = " << layerR);
ACTS_VERBOSE(" - from R min/max = "
<< protoLayer.min(AxisDirection::AxisR, false) << " / "
<< protoLayer.max(AxisDirection::AxisR, false));
ACTS_VERBOSE(" - with R thickness = " << layerThickness);
ACTS_VERBOSE(" - incl envelope = "
<< protoLayer.envelope[AxisDirection::AxisR][0u] << " / "
<< protoLayer.envelope[AxisDirection::AxisR][1u]);
ACTS_VERBOSE(" - with z min/max = "
<< protoLayer.min(AxisDirection::AxisZ, false) << " (-"
<< protoLayer.envelope[AxisDirection::AxisZ][0u] << ") / "
<< protoLayer.max(AxisDirection::AxisZ, false) << " (+"
<< protoLayer.envelope[AxisDirection::AxisZ][1u] << ")");
ACTS_VERBOSE(" - z center = " << layerZ);
ACTS_VERBOSE(" - halflength z = " << layerHalfZ);
// create the layer transforms if not given
// we need to transform in case layerZ != 0, so that the layer will be
// correctly defined using the halflength
// create the layer transforms if not given
Transform3 fullTransform = transform;
if (fullTransform.isApprox(Transform3::Identity()) && bTypeZ == equidistant) {
fullTransform = Translation3(0, 0, layerZ) * fullTransform;
ACTS_VERBOSE(" - layer z shift = " << -layerZ);
}
ACTS_VERBOSE(" - with phi min/max = "
<< protoLayer.min(AxisDirection::AxisPhi, false) << " / "
<< protoLayer.max(AxisDirection::AxisPhi, false));
ACTS_VERBOSE(" - # of modules = " << surfaces.size() << "");
// create the surface array
std::unique_ptr<SurfaceArray> sArray;
if (!surfaces.empty()) {
sArray = m_cfg.surfaceArrayCreator->surfaceArrayOnCylinder(
gctx, std::move(surfaces), bTypePhi, bTypeZ, protoLayer, fullTransform,
maxNeighborDistance);
}
// create the layer and push it back
std::shared_ptr<const CylinderBounds> cBounds(
new CylinderBounds(layerR, layerHalfZ));
// create the layer
MutableLayerPtr cLayer =
CylinderLayer::create(fullTransform, cBounds, std::move(sArray),
layerThickness, std::move(ad), active);
if (!cLayer) {
ACTS_ERROR("Creation of cylinder layer did not succeed!");
}
associateSurfacesToLayer(*cLayer);
// now return
return cLayer;
}
MutableLayerPtr LayerCreator::discLayer(
const GeometryContext& gctx,
std::vector<std::shared_ptr<const Surface>> surfaces, std::size_t binsR,
std::size_t binsPhi, std::optional<ProtoLayer> _protoLayer,
const Transform3& transform, std::unique_ptr<ApproachDescriptor> ad,
std::uint8_t maxNeighborDistance) const {
ProtoLayer protoLayer =
_protoLayer ? *_protoLayer : ProtoLayer(gctx, surfaces);
if (!_protoLayer) {
protoLayer.envelope[AxisDirection::AxisR] = m_cfg.defaultEnvelopeR;
protoLayer.envelope[AxisDirection::AxisZ] = m_cfg.defaultEnvelopeZ;
}
double layerZ = protoLayer.medium(AxisDirection::AxisZ);
double layerThickness = protoLayer.range(AxisDirection::AxisZ);
// adjust the layer radius
ACTS_VERBOSE("Creating a disk Layer:");
ACTS_VERBOSE(" - at Z position = " << layerZ);
ACTS_VERBOSE(" - from Z min/max = "
<< protoLayer.min(AxisDirection::AxisZ, false) << " / "
<< protoLayer.max(AxisDirection::AxisZ, false));
ACTS_VERBOSE(" - with Z thickness = " << layerThickness);
ACTS_VERBOSE(" - incl envelope = "
<< protoLayer.envelope[AxisDirection::AxisZ][0u] << " / "
<< protoLayer.envelope[AxisDirection::AxisZ][1u]);
ACTS_VERBOSE(" - with R min/max = "
<< protoLayer.min(AxisDirection::AxisR, false) << " (-"
<< protoLayer.envelope[AxisDirection::AxisR][0u] << ") / "
<< protoLayer.max(AxisDirection::AxisR, false) << " (+"
<< protoLayer.envelope[AxisDirection::AxisR][1u] << ")");
ACTS_VERBOSE(" - with phi min/max = "
<< protoLayer.min(AxisDirection::AxisPhi, false) << " / "
<< protoLayer.max(AxisDirection::AxisPhi, false));
ACTS_VERBOSE(" - # of modules = " << surfaces.size() << " ordered in ( "
<< binsR << " x " << binsPhi << ")");
// create the layer transforms if not given
Transform3 fullTransform = transform;
if (fullTransform.isApprox(Transform3::Identity())) {
fullTransform = Translation3(0, 0, layerZ) * fullTransform;
}
// create the surface array
std::unique_ptr<SurfaceArray> sArray;
if (!surfaces.empty()) {
sArray = m_cfg.surfaceArrayCreator->surfaceArrayOnDisc(
gctx, std::move(surfaces), binsR, binsPhi, protoLayer, fullTransform,
maxNeighborDistance);
}
// create the share disc bounds
auto dBounds = std::make_shared<const RadialBounds>(
protoLayer.min(AxisDirection::AxisR),
protoLayer.max(AxisDirection::AxisR));
// create the layers
// we use the same transform here as for the layer itself
// for disk this is fine since we don't bin in Z, so does not matter
MutableLayerPtr dLayer =
DiscLayer::create(fullTransform, dBounds, std::move(sArray),
layerThickness, std::move(ad), active);
if (!dLayer) {
ACTS_ERROR("Creation of disc layer did not succeed!");
}
associateSurfacesToLayer(*dLayer);
// return the layer
return dLayer;
}
MutableLayerPtr LayerCreator::discLayer(
const GeometryContext& gctx,
std::vector<std::shared_ptr<const Surface>> surfaces, BinningType bTypeR,
BinningType bTypePhi, std::optional<ProtoLayer> _protoLayer,
const Transform3& transform, std::unique_ptr<ApproachDescriptor> ad,
std::uint8_t maxNeighborDistance) const {
ProtoLayer protoLayer =
_protoLayer ? *_protoLayer : ProtoLayer(gctx, surfaces);
if (!_protoLayer) {
protoLayer.envelope[AxisDirection::AxisR] = m_cfg.defaultEnvelopeR;
protoLayer.envelope[AxisDirection::AxisZ] = m_cfg.defaultEnvelopeZ;
}
const double layerZ = protoLayer.medium(AxisDirection::AxisZ);
const double layerThickness = protoLayer.range(AxisDirection::AxisZ);
// adjust the layer radius
ACTS_VERBOSE("Creating a disk Layer:");
ACTS_VERBOSE(" - at Z position = " << layerZ);
ACTS_VERBOSE(" - from Z min/max = "
<< protoLayer.min(AxisDirection::AxisZ, false) << " / "
<< protoLayer.max(AxisDirection::AxisZ, false));
ACTS_VERBOSE(" - with Z thickness = " << layerThickness);
ACTS_VERBOSE(" - incl envelope = "
<< protoLayer.envelope[AxisDirection::AxisZ][0u] << " / "
<< protoLayer.envelope[AxisDirection::AxisZ][1u]);
ACTS_VERBOSE(" - with R min/max = "
<< protoLayer.min(AxisDirection::AxisR, false) << " (-"
<< protoLayer.envelope[AxisDirection::AxisR][0u] << ") / "
<< protoLayer.max(AxisDirection::AxisR, false) << " (+"
<< protoLayer.envelope[AxisDirection::AxisR][1u] << ")");
ACTS_VERBOSE(" - with phi min/max = "
<< protoLayer.min(AxisDirection::AxisPhi, false) << " / "
<< protoLayer.max(AxisDirection::AxisPhi, false));
ACTS_VERBOSE(" - # of modules = " << surfaces.size());
// create the layer transforms if not given
Transform3 fullTransform = transform;
if (fullTransform.isApprox(Transform3::Identity())) {
fullTransform = Translation3(0, 0, layerZ) * fullTransform;
}
// create the surface array
std::unique_ptr<SurfaceArray> sArray;
if (!surfaces.empty()) {
sArray = m_cfg.surfaceArrayCreator->surfaceArrayOnDisc(
gctx, std::move(surfaces), bTypeR, bTypePhi, protoLayer, fullTransform,
maxNeighborDistance);
}
// create the shared disc bounds
auto dBounds = std::make_shared<const RadialBounds>(
protoLayer.min(AxisDirection::AxisR),
protoLayer.max(AxisDirection::AxisR));
// create the layers
MutableLayerPtr dLayer =
DiscLayer::create(fullTransform, dBounds, std::move(sArray),
layerThickness, std::move(ad), active);
if (!dLayer) {
ACTS_ERROR("Creation of disc layer did not succeed!");
}
associateSurfacesToLayer(*dLayer);
// return the layer
return dLayer;
}
MutableLayerPtr LayerCreator::planeLayer(
const GeometryContext& gctx,
std::vector<std::shared_ptr<const Surface>> surfaces, std::size_t bins1,
std::size_t bins2, AxisDirection aDir,
std::optional<ProtoLayer> _protoLayer, const Transform3& transform,
std::unique_ptr<ApproachDescriptor> ad,
std::uint8_t maxNeighborDistance) const {
ProtoLayer protoLayer =
_protoLayer ? *_protoLayer : ProtoLayer(gctx, surfaces);
if (!_protoLayer) {
protoLayer.envelope[AxisDirection::AxisR] = m_cfg.defaultEnvelopeR;
protoLayer.envelope[AxisDirection::AxisZ] = m_cfg.defaultEnvelopeZ;
}
// remaining layer parameters
double layerHalf1 = 0, layerHalf2 = 0, layerThickness = 0;
switch (aDir) {
case AxisDirection::AxisX: {
layerHalf1 = 0.5 * protoLayer.range(AxisDirection::AxisY);
layerHalf2 = 0.5 * protoLayer.range(AxisDirection::AxisZ);
layerThickness = protoLayer.range(AxisDirection::AxisX);
break;
}
case AxisDirection::AxisY: {
layerHalf1 = 0.5 * protoLayer.range(AxisDirection::AxisX);
layerHalf2 = 0.5 * protoLayer.range(AxisDirection::AxisZ);
layerThickness = protoLayer.range(AxisDirection::AxisY);
break;
}
case AxisDirection::AxisZ: {
layerHalf1 = 0.5 * protoLayer.range(AxisDirection::AxisX);
layerHalf2 = 0.5 * protoLayer.range(AxisDirection::AxisY);
layerThickness = protoLayer.range(AxisDirection::AxisZ);
break;
}
default:
throw std::invalid_argument("Invalid binning value");
}
const double centerX = protoLayer.medium(AxisDirection::AxisX);
const double centerY = protoLayer.medium(AxisDirection::AxisY);
const double centerZ = protoLayer.medium(AxisDirection::AxisZ);
ACTS_VERBOSE("Creating a plane Layer:");
ACTS_VERBOSE(" - with layer center = "
<< "(" << centerX << ", " << centerY << ", " << centerZ << ")");
ACTS_VERBOSE(" - from X min/max = "
<< protoLayer.min(AxisDirection::AxisX) << " / "
<< protoLayer.max(AxisDirection::AxisX));
ACTS_VERBOSE(" - from Y min/max = "
<< protoLayer.min(AxisDirection::AxisY) << " / "
<< protoLayer.max(AxisDirection::AxisY));
ACTS_VERBOSE(" - with Z thickness = " << layerThickness);
ACTS_VERBOSE(" - incl envelope = " << protoLayer.envelope[aDir][0u]
<< " / "
<< protoLayer.envelope[aDir][1u]);
// create the layer transforms if not given
// we need to transform in case centerX/centerY/centerZ != 0, so that the
// layer will be correctly defined
Transform3 fullTransform = transform;
if (fullTransform.isApprox(Transform3::Identity())) {
fullTransform = Translation3(centerX, centerY, centerZ) * fullTransform;
ACTS_VERBOSE(" - layer shift = " << "(" << centerX << ", " << centerY
<< ", " << centerZ << ")");
}
std::unique_ptr<SurfaceArray> sArray;
if (!surfaces.empty()) {
sArray = m_cfg.surfaceArrayCreator->surfaceArrayOnPlane(
gctx, std::move(surfaces), bins1, bins2, aDir, protoLayer,
fullTransform, maxNeighborDistance);
}
// create the layer and push it back
auto pBounds = std::make_shared<RectangleBounds>(layerHalf1, layerHalf2);
// create the layer
MutableLayerPtr pLayer =
PlaneLayer::create(fullTransform, pBounds, std::move(sArray),
layerThickness, std::move(ad), active);
if (!pLayer) {
ACTS_ERROR("Creation of plane layer did not succeed!");
}
associateSurfacesToLayer(*pLayer);
// now return
return pLayer;
}
void LayerCreator::associateSurfacesToLayer(Layer& layer) const {
if (layer.surfaceArray() != nullptr) {
auto surfaces = layer.surfaceArray()->surfaces();
for (auto& surface : surfaces) {
auto mutableSurface = const_cast<Surface*>(surface);
mutableSurface->associateLayer(layer);
}
}
}
} // namespace Acts