FairShip
Loading...
Searching...
No Matches
geometry_config.py
Go to the documentation of this file.
1# SPDX-License-Identifier: LGPL-3.0-or-later
2# SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP Collaboration
3
4import os
5
6import shipunit as u
7import yaml
8from ShipGeoConfig import AttrDict, Config
9
10# Parameters for geometry configuration are passed to create_config() function
11# nuTargetPassive = 1 #0 = with active layers, 1 = only passive
12
13# targetOpt = 5 # 0=solid >0 sliced, 5: 5 pieces of tungsten, 4 air slits, 17: molybdenum tungsten interleaved with H20
14# strawOpt = 0 # 4=Aluminium frame 10=steel frame (default)
15
16# Here you can select the MS geometry.
17# Each magnet is a solid iron box; its field comes from the map files/<shieldName>.root.
18# One row per magnet, in cm: [Zgap, dZ, dX, dY]
19# Zgap: gap upstream of the magnet, dZ: half length, dX/dY: outer half width and half height.
20# The first row is the magnetised hadron absorber.
21shield_db = {
22 "TRY_2026": {
23 "params": [
24 [0.0, 115.0, 163.5, 169.0],
25 [15, 150, 136, 80],
26 # 0.3 m gap between the M1 and M2 yokes (integration layout 2026-0.1)
27 [30, 225, 149, 89],
28 [16, 225, 155.2, 85],
29 [15, 225, 159.2, 60],
30 [16, 131, 134, 52],
31 [15, 168, 150, 63],
32 [19, 200, 171, 127],
33 ],
34 },
35}
36
37
38def set_ecn3_cavern(c) -> None:
39 """Set in c.cave the ECN3 hall cross-section used to place the UBT and its scoring planes."""
40 # ECN3 hall cross-section, used to place the UBT and its scoring planes:
41 # the inner concrete surfaces of the CAD model, as in
42 # passive/ShipCavernLayout.h. They are copied so that geometry_config does
43 # not need ROOT; tests/test_cavern_layout.py compares them with the
44 # compiled constants. Beam axis at x = y = 0.
45 c.cave.ECN3LeftX = -4.566 * u.m
46 c.cave.ECN3RightX = 11.434 * u.m
47 c.cave.ECN3FloorY = -3.364 * u.m
48 # Side wall closest to the beam axis: the -x wall at x = -4.566 m
49 c.cave.ECN3WallDistance = min(-c.cave.ECN3LeftX, c.cave.ECN3RightX)
50
51
52def set_upstream_tagger(c) -> None:
53 """Set the UBT (c.UpstreamTagger) and its scoring planes (c.UpstreamTaggerScoringPlane).
54
55 Needs c.cave (with the ECN3 cavern), c.decayVolume.z0, c.muShield.z and c.muShield.length.
56 """
57 # Upstream Tagger: polystyrene scintillator plane, split into regions
58 # generated on the box below from the rule in
59 # geometry/UpstreamTagger_config.yaml. BoxZ is the space reserved by the
60 # integration layout; the active thickness depends on the tile size.
61 c.UpstreamTagger = AttrDict()
62 # The plane spans x in [-1.7, 1.7] m and y from FloorMargin above the ECN3
63 # floor up to Top, covering the decay vessel entrance. Its edges must lie
64 # on the edges of the 40 mm tiles (x, y = 2 + 4k cm).
65 c.UpstreamTagger.Top = 1.7 * u.m
66 # 2.4 cm above the ECN3 floor at -336.4 cm, so that the plane ends on a
67 # 40 mm tile edge (y = 2 + 4k cm), at -334 cm
68 c.UpstreamTagger.FloorMargin = 2.4 * u.cm
69 c.UpstreamTagger.BoxX = 3.4 * u.m # X extent of detector map
70 c.UpstreamTagger.BoxY = c.UpstreamTagger.Top - c.cave.ECN3FloorY - c.UpstreamTagger.FloorMargin # 5.04 m
71 c.UpstreamTagger.BoxCenterX = 0.0 * u.m
72 c.UpstreamTagger.BoxCenterY = (
73 c.UpstreamTagger.Top + c.cave.ECN3FloorY + c.UpstreamTagger.FloorMargin
74 ) / 2.0 # -0.82 m
75 c.UpstreamTagger.BoxZ = 16.0 * u.cm # Z dimension (thickness)
76 # Tile thickness for each tile side (cm) of UpstreamTagger_config.yaml:
77 # 20 x 20 mm2 tiles are 5 mm thick, 40 x 40 mm2 tiles 10 mm. These are the
78 # only tile sizes of the UBT: if small_tile_size or large_tile_size in the
79 # YAML is changed to anything other than 2 or 4 cm, the thickness of the
80 # new size has to be added here.
81 c.UpstreamTagger.TileThickness = {2: 0.5 * u.cm, 4: 1.0 * u.cm}
82 # Gap between the back of the UBT envelope and the decay vessel entrance
83 c.UpstreamTagger.DecayVesselGap = 32.0 * u.cm
84 # Centre (z) and front face (z0) of the UBT envelope
85 c.UpstreamTagger.z = c.decayVolume.z0 - c.UpstreamTagger.DecayVesselGap - c.UpstreamTagger.BoxZ / 2.0
86 c.UpstreamTagger.z0 = c.UpstreamTagger.z - c.UpstreamTagger.BoxZ / 2.0
87 c.UpstreamTagger.TimeResolution = 0.3 # Time resolution in ns
88 c.UpstreamTagger.ADCTriggerThreshold = 100
89
90 # Thin vacuum scoring planes. They record every track entering them,
91 # without energy deposit; the point detID is the plane number.
92 c.UpstreamTaggerScoringPlane = AttrDict()
93 c.UpstreamTaggerScoringPlane.Z = 1.0 * u.mm # thickness
94 # Plane 1, all particles: on the decay vessel entrance, centred on the
95 # beam axis, with y from the ECN3 floor to its mirror image.
96 dv = c.UpstreamTaggerScoringPlane.DecayVessel = AttrDict()
97 dv.X = 4.4 * u.m
98 dv.Y = -2.0 * c.cave.ECN3FloorY # 6.728 m
99 dv.CenterX = 0.0 * u.m
100 dv.CenterY = 0.0 * u.m
101 dv.z = c.decayVolume.z0 - c.UpstreamTaggerScoringPlane.Z / 2.0
102 dv.MuonsOnly = False
103 # Its points do not keep their tracks in MCTrack (with MCTracksWithHitsOnly,
104 # as in --MuonBack): it sees every soft photon and electron from the
105 # shield and the cavern, which would otherwise all be kept, about 26 % more
106 # MCTracks in a muon-background sample. Points of tracks not kept for
107 # another reason get track ID -2.
108 dv.KeepTracks = False
109 # Plane 2, muons only: ShieldGap downstream of the muon shield. It spans x
110 # between the closest ECN3 side wall and its mirror image, and y from the
111 # ECN3 floor up to Top.
112 ms = c.UpstreamTaggerScoringPlane.MuonShield = AttrDict()
113 ms.Top = 5.2 * u.m
114 ms.ShieldGap = 10.0 * u.cm
115 ms.X = 2.0 * c.cave.ECN3WallDistance # 9.132 m
116 ms.Y = ms.Top - c.cave.ECN3FloorY # 8.564 m
117 ms.CenterX = 0.0 * u.m
118 ms.CenterY = (ms.Top + c.cave.ECN3FloorY) / 2.0 # 0.918 m
119 ms.z = c.muShield.z + c.muShield.length + ms.ShieldGap
120 ms.MuonsOnly = True
121 ms.KeepTracks = True # muons only: their points keep their tracks
122
123
125 DecayVolumeMedium: str = "helium",
126 Yheight: float = 6.0,
127 strawDesign: int = 10,
128 shieldName: str = "TRY_2026",
129 nuTargetPassive: int = 1,
130 SND: bool = True,
131 SND_design=None,
132 TARGET_YAML=None,
133):
134 """
135 Create geometry configuration with specified parameters.
136
137 Args:
138 DecayVolumeMedium: Medium in decay volume ("helium" or "vacuums"), default: "helium"
139 Yheight: Height of vacuum tank in meters, default: 6.0
140 strawDesign: Straw tube design (4=Aluminium frame, 10=steel frame), default: 10
141 shieldName: Name of shield configuration, default: "TRY_2026"
142 nuTargetPassive: Target type (0=with active layers, 1=only passive), default: 1
143 SND: Enable SND detector, default: True
144 SND_design: SND design options (list of design numbers), default: [2]
145 TARGET_YAML: Path to target YAML configuration file, default: "$FAIRSHIP/geometry/target_config.yaml"
146
147 Returns:
148 Config: Geometry configuration object
149 """
150 # Set defaults for mutable parameters
151 if SND_design is None:
152 SND_design = [2]
153 if TARGET_YAML is None:
154 TARGET_YAML = os.path.expandvars("$FAIRSHIP/geometry/target_config.yaml")
155
156 # Create configuration object
157 c = Config()
158 c.DecayVolumeMedium = DecayVolumeMedium
159 c.SND = SND
160 # Ensure SND_design is always a list
161 if not isinstance(SND_design, list):
162 SND_design = [SND_design]
163 c.SND_design = SND_design
164 c.target_yaml = TARGET_YAML
165 print("Info: Target using configuration:", c.target_yaml)
166
167 if not shieldName:
168 raise ValueError("shieldName must not be empty!")
169
170 c.shieldName = shieldName
171
172 # global strawDesign, Yheight
173 c.Yheight = Yheight * u.m
174 extraVesselLength = 10 * u.m
175 windowBulge = 25 * u.cm
176 c.strawDesign = strawDesign
177 c.magnetDesign = 4
178 # cave parameters
179 c.cave = AttrDict()
180 c.cave.floorHeightMuonShield = 5 * u.m
181 c.cave.floorHeightTankA = 4.2 * u.m
182 if strawDesign == 10:
183 c.cave.floorHeightMuonShield = c.cave.floorHeightTankA # avoid the gap, for 2018 geometry
184 c.cave.floorHeightTankB = 2 * u.m
185 # ECN3 cavern, see passive/ShipCave.cxx
186 c.cave.TCC8_length = 170 * u.m
187 c.cave.ECN3_length = 100.81 * u.m # step and hall, up to the end wall at 122.18 m
188 c.cave.stair_step_length = 0.82 * u.m
189 # End of the TCC8 floor (integration layout 2026-0.1); the stair step that follows is
190 # centred on the gap between M4 and S5
191 c.cave.z_transition = 21.37 * u.m
192 c.cave.zEnd = c.cave.z_transition + c.cave.ECN3_length # downstream ECN3 wall
194
195 with open(c.target_yaml) as file:
196 targetconfig = yaml.safe_load(file)
197 c.target = AttrDict(targetconfig["target"])
198 if "version" not in c.target:
199 c.target.version = 1 # legacy design
200
201 c.target.slices_length = []
202 c.target.slices_gap = []
203 c.target.slices_material = []
204
205 for i in range(c.target.Nplates):
206 for j in range(c.target.N[i]):
207 if len(c.target.L) == 1:
208 c.target.slices_length.append(c.target.L[0])
209 else:
210 c.target.slices_length.append(c.target.L[i])
211 if len(c.target.G) == 1:
212 c.target.slices_gap.append(c.target.G[0])
213 else:
214 c.target.slices_gap.append(c.target.G[i])
215 if len(c.target.M) == 1:
216 c.target.slices_material.append(c.target.M[0])
217 else:
218 c.target.slices_material.append(c.target.M[i])
219 # Last gap should be 0...
220 c.target.slices_gap[c.target.nS - 1] = 0
221 print(c.target.slices_material, c.target.slices_length, c.target.slices_gap)
222
223 target_length = 0
224 for width, gap in zip(c.target.slices_length, c.target.slices_gap):
225 target_length += width + gap
226 c.target.length = target_length
227 # interaction point, start of target
228
229 c.target.z0 = 0 # Origin of SHiP coordinate system
230 c.target.z = c.target.z0 + c.target.length / 2.0
231
232 c.hadronAbsorber = AttrDict()
233
234 # Downstream elements are positioned using the nominal length of the
235 # legacy target so that they stay put when a different (e.g. shorter)
236 # target design is selected. This is the single authoritative value for the
237 # fixed length; it is passed to ShipTargetStation (SetShieldingReferenceLength)
238 # so the proximity shielding stays independent of the actual target length.
239 c.target.length_fixed = 158.64 * u.cm
240
241 c.hadronAbsorber.z = (
242 c.target.z0
243 + c.target.length_fixed
244 + 96.1 * u.mm # Distance between target and proximity shielding
245 + 250 * u.mm # Thickness of proximity shielding
246 + 207.5 * u.mm # Distance between hadron absorber and proximity shielding
247 ) # front face of the magnetised hadron stopper at 2.14 m (integration layout 2026-0.1)
248
249 # DEFINITION OF THE MUON SHIELD
250 c.muShield = AttrDict()
251
252 c.muShield.z = c.hadronAbsorber.z
253
254 params = shield_db[shieldName]["params"]
255 c.muShield.params = params
256
257 # MS length
258 c.muShield.length = sum(line[0] + line[1] * 2 for line in params)
259 c.muShield.nMagnets = len(params)
260
261 c.muShield.Zgap = []
262 c.muShield.half_length = []
263 c.muShield.Entrance = []
264
265 for line in params:
266 c.muShield.Zgap.append(line[0])
267 c.muShield.half_length.append(line[1])
268
269 # Compute Z position for each magnet
270 for i in range(len(c.muShield.Zgap)):
271 if i == 0:
272 # First magnet uses the initial offset
273 c.muShield.Entrance.append(c.muShield.z + c.muShield.Zgap[i])
274 else:
275 # Subsequent magnets are placed relative to the previous one
276 c.muShield.Entrance.append(
277 c.muShield.Entrance[i - 1] + c.muShield.half_length[i - 1] * 2 + c.muShield.Zgap[i]
278 )
279 # Flatten the params list
280 c.muShield.params = [item for sublist in params for item in sublist]
281
282 c.decayVolume = AttrDict()
283
284 # target absorber muon shield setup, decayVolume.length = nominal EOI length, only kept to define z=0
285 c.decayVolume.length = 50 * u.m
286
287 # make z coordinates for the decay volume and tracking stations relative to T4z
288 # eventually, the only parameter which needs to be changed when the active shielding length changes.
289 c.z = 89.72 * u.m # mid-plane of the spectrometer magnet (integration layout 2026-0.1)
290 c.decayVolume.z = c.z - 31.450 * u.m # Relative position of decay vessel centre to spectrometer magnet
291 c.decayVolume.z0 = c.decayVolume.z - c.decayVolume.length / 2.0
292 veto_yaml = os.path.expandvars(f"$FAIRSHIP/geometry/veto_config_{DecayVolumeMedium}.yaml")
293 with open(veto_yaml) as f:
294 veto_config = yaml.safe_load(f)
295 c.decayVolume.xEndInner = veto_config["xendInner"] * u.cm
296 c.decayVolume.yEndInner = veto_config["yendInner"] * u.cm
297
298 c.chambers = AttrDict()
299 magnetIncrease = 100.0 * u.cm
300
301 if strawDesign != 4 and strawDesign != 10:
302 raise ValueError(f"straw design {strawDesign} is not supported, use strawDesign = 4 or 10")
303 else:
304 c.chambers.Tub1length = 2.5 * u.m
305 c.chambers.Tub2length = 17.68 * u.m + extraVesselLength / 2.0
306 c.chambers.Tub3length = 0.8 * u.m
307 c.chambers.Tub4length = 2.0 * u.m + magnetIncrease / 2.0
308 c.chambers.Tub5length = 0.8 * u.m
309 c.chambers.Tub6length = 0.1 * u.m + windowBulge / 2.0
310 c.chambers.Rmin = 245.0 * u.cm
311 c.chambers.Rmax = 250.0 * u.cm
312
313 c.xMax = 2 * u.m # max horizontal width at T4
314 TrGap = 2 * u.m # Distance between Tr1/2 and Tr3/4
315 TrMagGap = 3.5 * u.m # Distance from spectrometer magnet centre to the next tracking stations
316 #
317 z4 = c.z + TrMagGap + TrGap
318 c.TrackStation4 = AttrDict(z=z4)
319 z3 = c.z + TrMagGap
320 c.TrackStation3 = AttrDict(z=z3)
321 z2 = c.z - TrMagGap
322 c.TrackStation2 = AttrDict(z=z2)
323 z1 = c.z - TrMagGap - TrGap
324 c.TrackStation1 = AttrDict(z=z1)
325
326 # positions and lengths of vacuum tube segments (for backward compatibility)
327 # Chamber1.z is the downstream end of Tub1, so consumers can take z - Tub1length to get the decay-vessel entrance.
328 c.Chamber1 = AttrDict(z=c.decayVolume.z0 + c.chambers.Tub1length)
329 c.Chamber6 = AttrDict(z=z4 + 30.0 * u.cm + windowBulge / 2.0)
330
331 c.Bfield = AttrDict()
332 c.Bfield.z = c.z
333 c.Bfield.max = 0 # 1.4361*u.kilogauss # was 1.15 in EOI
334 c.Bfield.y = c.Yheight
335 c.Bfield.x = 2.4 * u.m
336 c.Bfield.fieldMap = "files/2026_07_02_MainSpectrometerField_V21_2455.root"
337 if c.magnetDesign > 3: # MISIS design
338 c.Bfield.YokeWidth = 0.8 * u.m # full width 200.*cm
339 c.Bfield.YokeDepth = 1.4 * u.m # half length 200 *cm;
340 c.Bfield.CoilThick = 25.0 * u.cm # thickness
341 c.Bfield.x = 2.2 * u.m # half apertures
342 c.Bfield.y = 3.5 * u.m
343
344 # TimeDet
345 c.TimeDet = AttrDict()
346 c.TimeDet.dzBarRow = 1.2 * u.cm
347 c.TimeDet.dzBarCol = 9.0 * u.cm
348 c.TimeDet.zBar = 1 * u.cm
349 c.TimeDet.DZ = (c.TimeDet.dzBarRow + c.TimeDet.dzBarCol + c.TimeDet.zBar) / 2
350 c.TimeDet.DX = 275 * u.cm
351 c.TimeDet.DY = 325 * u.cm
352 # First bar row, placed so that the front face of the timing detector is 37.87 m
353 # downstream of the decay vessel centre, i.e. at 96.14 m (integration layout 2026-0.1)
354 c.TimeDet.z = 37.870 * u.m + c.decayVolume.z + c.TimeDet.zBar / 2
355
356 # CaloScoringPlane: ideal (vacuum) plane where the calorimeter entrance window sits.
357 # Every track entering it is scored.
358 c.CaloScoringPlane = AttrDict()
359 c.CaloScoringPlane.DX = 4 * u.m # full width (former SplitCal 2*XMax)
360 c.CaloScoringPlane.DY = 6 * u.m # full height (former SplitCal 2*YMax)
361 c.CaloScoringPlane.DZ = 1 * u.mm # full thickness
362 # Digitisation (python/detectors/CaloScoringPlaneDetector.py). Particle identification is
363 # configured at reconstruction time: ShipReco.py --caloScoringPlanePID file.yaml
364 c.CaloScoringPlane.PositionResolution = 0.0 * u.cm # Gaussian x/y smearing, 0 = none
365 c.CaloScoringPlane.TimeResolution = 0.0 # Gaussian time smearing in ns, 0 = none
366 c.CaloScoringPlane.ForwardOnly = True # digitise only crossings with pz > 0
367 c.CaloScoringPlane.IgnoredPdg = [12, 14, 16] # never produce a hit (neutrinos)
368 # Centre of the plane; its upstream face is the ECAL front face, 38.90 m downstream of the
369 # decay vessel centre, i.e. at 97.17 m (integration layout 2026-0.1)
370 c.CaloScoringPlane.z = 38.900 * u.m + c.decayVolume.z + c.CaloScoringPlane.DZ / 2
371 if c.CaloScoringPlane.z + c.CaloScoringPlane.DZ / 2 >= c.cave.zEnd:
372 raise ValueError(
373 f"CaloScoringPlane ends at z = {c.CaloScoringPlane.z + c.CaloScoringPlane.DZ / 2} cm, "
374 f"beyond the downstream ECN3 wall at {c.cave.zEnd} cm"
375 )
376
377 # for the digitizing step
378 c.strawtubesDigi = AttrDict()
379 c.strawtubesDigi.v_drift = 1.0 / (30 * u.ns / u.mm) # for baseline NA62 5mm radius straws)
380 c.strawtubesDigi.sigma_spatial = 0.012 * u.cm # according to Massi's TP section
381
382 # CAMM - For Nu tau detector, keep only these parameters which are used by others...
383 c.tauMudet = AttrDict()
384 c.tauMudet.Ztot = 3 * u.m # space allocated to Muon spectrometer
385 c.tauMudet.zMudetC = c.muShield.z + c.muShield.length / 2.0 - c.tauMudet.Ztot / 2.0 - 70 * u.cm
386
388
389 # Store parameters that might be needed for reference
390 c.nuTargetPassive = nuTargetPassive
391
392 return c
None set_upstream_tagger(c)
create_config(str DecayVolumeMedium="helium", float Yheight=6.0, int strawDesign=10, str shieldName="TRY_2026", int nuTargetPassive=1, bool SND=True, SND_design=None, TARGET_YAML=None)