SHiP Geometry
SHiP experiment geometry implementation using GeoModel.
Loading...
Searching...
No Matches
MagnetFactory.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// Copyright (C) CERN for the benefit of the SHiP Collaboration
3
4#pragma once
5
9
10#include <string>
11
12class GeoPhysVol;
13
14namespace SHiP::geometry {
15
16class Materials;
17
27 public:
28 explicit MagnetFactory(Materials& materials);
29 ~MagnetFactory() = default;
30
36 static constexpr SubsystemDescriptor descriptor() {
37 using units::gm;
38 using units::m;
39 return {.name = "Magnet",
40 .node = "/SHiP/magnet",
41 .id = 6,
42 .x_mm = 0.0,
43 .y_mm = 0.0,
44 .z_mm = gm(89.57 * m),
45 .isWorld = false};
46 }
47
51 [[nodiscard]] GeoPhysVol* build();
52
53 // Container sized to enclose the yoke, coils, and connectors: HalfX and
54 // HalfZ exceed the yoke outer dimensions, while HalfY matches it.
55 static constexpr auto s_containerHalfX = 3250.0 * units::mm;
56 static constexpr auto s_containerHalfY = 4300.0 * units::mm;
57 static constexpr auto s_containerHalfZ = 2500.0 * units::mm;
58
59 private:
60 Materials& m_materials;
61
62 GeoPhysVol* createYoke();
63 GeoPhysVol* createCoil(const std::string& name);
64 GeoPhysVol* createVerticalConnector(const std::string& name);
65
66 // Yoke dimensions from GDML (half-sizes)
67 // GDML: outer 600×860×280 cm, inner 440×700×282 cm
68 static constexpr auto s_yokeOuterHalfX = 3000.0 * units::mm;
69 static constexpr auto s_yokeOuterHalfY = 4300.0 * units::mm;
70 static constexpr auto s_yokeOuterHalfZ = 1400.0 * units::mm;
71 static constexpr auto s_yokeInnerHalfX = 2200.0 * units::mm;
72 static constexpr auto s_yokeInnerHalfY = 3500.0 * units::mm;
73 static constexpr auto s_yokeInnerHalfZ = 1410.0 * units::mm;
74
75 // Coil dimensions (simplified as boxes)
76 static constexpr auto s_coilHalfX = 800.0 * units::mm;
77 static constexpr auto s_coilHalfY = 400.0 * units::mm;
78 static constexpr auto s_coilHalfZ = 1660.0 * units::mm;
79 static constexpr auto s_coilXOffset = 2200.0 * units::mm;
80 static constexpr auto s_coilYOffset = 3250.0 * units::mm;
81
82 // Vertical connector dimensions from GDML: 80×650×25 cm
83 static constexpr auto s_connectorHalfX = 400.0 * units::mm;
84 static constexpr auto s_connectorHalfY = 3250.0 * units::mm;
85 static constexpr auto s_connectorHalfZ = 125.0 * units::mm;
86 static constexpr auto s_connectorXOffset = 2600.0 * units::mm;
87 static constexpr auto s_connectorZOffset = 1525.0 * units::mm; // From GDML positions
88
89 // ── Compile-time validation ─────────────────────────────────────────
90 // Coils sit at (±s_coilXOffset, ±s_coilYOffset, 0) and connectors at
91 // (±s_connectorXOffset, 0, ±s_connectorZOffset); checking the +x/+y/+z
92 // copy covers all four by symmetry.
93 static constexpr auto s_zero = 0.0 * units::mm;
94 static constexpr checks::Box s_containerBox =
96 static constexpr checks::Box s_coilBox =
97 checks::box(s_coilXOffset, s_coilYOffset, s_zero, s_coilHalfX, s_coilHalfY, s_coilHalfZ);
98 static constexpr checks::Box s_connectorBox =
99 checks::box(s_connectorXOffset, s_zero, s_connectorZOffset, s_connectorHalfX,
100 s_connectorHalfY, s_connectorHalfZ);
102 static constexpr checks::Box s_yokeSideBox = checks::box(
103 0.5 * (s_yokeInnerHalfX + s_yokeOuterHalfX), s_zero, s_zero,
104 0.5 * (s_yokeOuterHalfX - s_yokeInnerHalfX), s_yokeOuterHalfY, s_yokeOuterHalfZ);
105
106 static_assert(s_yokeInnerHalfX < s_yokeOuterHalfX && s_yokeInnerHalfY < s_yokeOuterHalfY &&
107 s_yokeInnerHalfZ >= s_yokeOuterHalfZ,
108 "the yoke inner cut-out must leave a frame open along the beam");
109 static_assert(checks::contains(s_containerBox, checks::box(s_yokeOuterHalfX, s_yokeOuterHalfY,
110 s_yokeOuterHalfZ)) &&
111 checks::contains(s_containerBox, s_coilBox) &&
112 checks::contains(s_containerBox, s_connectorBox),
113 "a magnet part sticks out of the container");
114 static_assert(!checks::overlaps(s_connectorBox, s_yokeSideBox),
115 "the connectors must sit clear of the yoke");
116 // Known deviations (#119): the box coils approximate GDML half-tubes and
117 // overlap both the yoke sides and the connectors. Each overlap must stay
118 // within its current region (magnet frame, mm), so the build fails both
119 // when it is fixed and when it grows.
120 static_assert(checks::overlapsWithin(s_coilBox, s_yokeSideBox,
121 checks::bounds(2200, 3000, 2850, 3650, -1400, 1400)),
122 "the coil/yoke overlap is gone (assert !overlaps) or has grown");
123 static_assert(checks::overlapsWithin(s_coilBox, s_connectorBox,
124 checks::bounds(2200, 3000, 2850, 3250, 1400, 1650)),
125 "the coil/connector overlap is gone (assert !overlaps) or has grown");
126};
127
128} // namespace SHiP::geometry
GeoPhysVol * build()
Build the Magnet geometry.
Definition MagnetFactory.cpp:24
static constexpr auto s_containerHalfY
Definition MagnetFactory.h:56
static constexpr auto s_containerHalfZ
Definition MagnetFactory.h:57
static constexpr auto s_containerHalfX
Definition MagnetFactory.h:55
static constexpr SubsystemDescriptor descriptor()
This subsystem's self-description (name, node, id, placement).
Definition MagnetFactory.h:36
MagnetFactory(Materials &materials)
Definition MagnetFactory.cpp:22
Central material manager for the SHiP detector.
Definition Materials.h:22
constexpr bool overlaps(Span a, Span b)
The intervals share more than a boundary. Touching ends do not overlap.
Definition StaticChecks.h:45
constexpr bool contains(Span outer, Span inner, LengthMm tol=0.0 *units::mm)
inner lies within outer, allowing tol of slack at either end.
Definition StaticChecks.h:40
constexpr Box bounds(double x0, double x1, double y0, double y1, double z0, double z1)
Box from its bounds in mm, for writing a known region down literally.
Definition StaticChecks.h:80
constexpr bool overlapsWithin(const Box &a, const Box &b, const Box &region, LengthMm tol=1e-6 *units::mm)
The boxes overlap, and only within region.
Definition StaticChecks.h:97
constexpr Box box(LengthMm cx, LengthMm cy, LengthMm cz, LengthMm hx, LengthMm hy, LengthMm hz)
Box with centre (cx, cy, cz) and the given half-lengths.
Definition StaticChecks.h:57
constexpr auto m
Definition Units.h:29
constexpr double gm(mp_units::quantity< U, Rep > q)
Length quantity -> GeoModel raw double (GeoModel native unit: mm).
Definition Units.h:47
constexpr auto mm
Definition Units.h:27
Definition DetectorBuilder.h:8
constexpr double gm(mp_units::quantity< U, Rep > q)
Length quantity -> GeoModel raw double (GeoModel native unit: mm).
Definition Units.h:47
A subsystem's self-description: everything the assembler needs.
Definition SubsystemDescriptor.h:20
Axis-aligned box.
Definition StaticChecks.h:50