FairShip
Loading...
Searching...
No Matches
shipDet_conf Namespace Reference

Functions

None configure_snd_old (str yaml_file, emulsion_target_z_end, cave_floorHeightMuonShield)
None configure_snd_mtc (str yaml_file, ship_geo)
None configure_snd_siliconTarget (str yaml_file, ship_geo)
None configure_veto (str yaml_file, z0)
None configure_strawtubes (str yaml_file, ship_geo)
None check_upstream_tagger_map (ubt_map, ubt_geo)
list[tuple[float, float]] _axis_cells (float low, float high, float size)
list[tuple[float, float, float, float]] _small_tile_areas (rule)
dict[str, Any] generate_upstream_tagger_map (rule, ubt_geo)
None configure_upstream_tagger (str yaml_file, upstream_tagger, ship_geo)
float _ubt_front_face (ubt_geo)
 configure (run, ship_geo, str|None geofile=None)

Variables

list detectorList = []

Function Documentation

◆ _axis_cells()

list[tuple[float, float]] shipDet_conf._axis_cells ( float low,
float high,
float size )
protected
(centre, size) of the cells of ``size`` centred on the beam axis, cut at [low, high].

Definition at line 328 of file shipDet_conf.py.

328def _axis_cells(low: float, high: float, size: float) -> list[tuple[float, float]]:
329 """(centre, size) of the cells of ``size`` centred on the beam axis, cut at [low, high]."""
330 first = math.floor((low + size / 2.0) / size + 1.0e-9)
331 last = math.ceil((high - size / 2.0) / size - 1.0e-9)
332 cells = []
333 for k in range(first, last + 1):
334 cell_low, cell_high = max(k * size - size / 2.0, low), min(k * size + size / 2.0, high)
335 if cell_high - cell_low > 1.0e-9:
336 cells.append(((cell_low + cell_high) / 2.0, cell_high - cell_low))
337 return cells
338
339

◆ _small_tile_areas()

list[tuple[float, float, float, float]] shipDet_conf._small_tile_areas ( rule)
protected
The areas of small tiles of the UBT rule, as (x low, x high, y low, y high) in cm.

Definition at line 340 of file shipDet_conf.py.

340def _small_tile_areas(rule) -> list[tuple[float, float, float, float]]:
341 """The areas of small tiles of the UBT rule, as (x low, x high, y low, y high) in cm."""
342 areas = []
343 for area in rule.get("small_tile_areas", []):
344 (x_low, x_high), (y_low, y_high) = (float(v) for v in area["x"]), (float(v) for v in area["y"])
345 if not (x_low < x_high and y_low < y_high):
346 raise ValueError(f"The UBT small-tile area {area} must have x and y ranges [low, high] with low < high")
347 areas.append((x_low, x_high, y_low, y_high))
348 return areas
349
350

◆ _ubt_front_face()

float shipDet_conf._ubt_front_face ( ubt_geo)
protected
z of the front face of the UBT envelope, from which the old SND design is placed.

A UBT from before the scintillator tiles gives its centre as Z_Position,
and the old SND design was then placed 8 cm upstream of it whatever BoxZ
was, so that is reproduced here.

Definition at line 488 of file shipDet_conf.py.

488def _ubt_front_face(ubt_geo) -> float:
489 """z of the front face of the UBT envelope, from which the old SND design is placed.
490
491 A UBT from before the scintillator tiles gives its centre as Z_Position,
492 and the old SND design was then placed 8 cm upstream of it whatever BoxZ
493 was, so that is reproduced here.
494 """
495 if hasattr(ubt_geo, "z0"):
496 return ubt_geo.z0
497 return ubt_geo.Z_Position - 8.0 * u.cm
498
499

◆ check_upstream_tagger_map()

None shipDet_conf.check_upstream_tagger_map ( ubt_map,
ubt_geo )
Check that the UBT map covers exactly the UBT box of the geometry configuration.

A generated map does by construction, so this is only run on a map stored
with a geometry that the rule of the checkout does not reproduce, against
the box stored with it. A box larger than the map would
leave a strip without tiles, a smaller one would stop ConstructGeometry.

Definition at line 277 of file shipDet_conf.py.

277def check_upstream_tagger_map(ubt_map, ubt_geo) -> None:
278 """Check that the UBT map covers exactly the UBT box of the geometry configuration.
279
280 A generated map does by construction, so this is only run on a map stored
281 with a geometry that the rule of the checkout does not reproduce, against
282 the box stored with it. A box larger than the map would
283 leave a strip without tiles, a smaller one would stop ConstructGeometry.
284 """
285 tolerance = 1.0e-6 # cm
286 box = {
287 "x": (ubt_geo.BoxCenterX - ubt_geo.BoxX / 2.0, ubt_geo.BoxCenterX + ubt_geo.BoxX / 2.0),
288 "y": (ubt_geo.BoxCenterY - ubt_geo.BoxY / 2.0, ubt_geo.BoxCenterY + ubt_geo.BoxY / 2.0),
289 }
290 bounds = {axis: tuple(bound * u.cm for bound in ubt_map["bounds"][axis]) for axis in ("x", "y")}
291 for axis in ("x", "y"):
292 if any(abs(b - e) > tolerance * u.cm for b, e in zip(bounds[axis], box[axis])):
293 raise ValueError(
294 f"The UBT map bounds in {axis}, {bounds[axis]} cm, differ from the UBT box of the geometry"
295 f" configuration, {box[axis]} cm"
296 )
297
298 # The regions must tile the bounds: each inside them, no two overlapping,
299 # and together as large as them.
300 rectangles = []
301 for region in ubt_map["regions"]:
302 half_x, half_y = region["size_x"] * u.cm / 2.0, region["size_y"] * u.cm / 2.0
303 x, y = region["x"] * u.cm, region["y"] * u.cm
304 rectangle = (x - half_x, x + half_x, y - half_y, y + half_y)
305 if (
306 rectangle[0] < bounds["x"][0] - tolerance
307 or rectangle[1] > bounds["x"][1] + tolerance
308 or rectangle[2] < bounds["y"][0] - tolerance
309 or rectangle[3] > bounds["y"][1] + tolerance
310 ):
311 raise ValueError(f"UBT region {region['id']} extends outside the map bounds")
312 rectangles.append((region["id"], rectangle))
313 for i, (id_a, a) in enumerate(rectangles):
314 for id_b, b in rectangles[i + 1 :]:
315 if (
316 a[0] < b[1] - tolerance
317 and b[0] < a[1] - tolerance
318 and a[2] < b[3] - tolerance
319 and b[2] < a[3] - tolerance
320 ):
321 raise ValueError(f"UBT regions {id_a} and {id_b} overlap")
322 covered = sum((r[1] - r[0]) * (r[3] - r[2]) for _, r in rectangles)
323 area = (bounds["x"][1] - bounds["x"][0]) * (bounds["y"][1] - bounds["y"][0])
324 if abs(covered - area) > tolerance * area:
325 raise ValueError(f"The UBT regions cover {covered} cm2 of the {area} cm2 map: some of it has no tiles")
326
327

◆ configure()

shipDet_conf.configure ( run,
ship_geo,
str | None geofile = None )
Configure the modules of the run and add them to it.

With ``geofile``, particles are transported through the geometry stored in
that geometry file: the modules build their geometry as usual, and a last
module replaces it by the stored one (see geometry_from_file). ``ship_geo``
must then be the configuration stored in the same file. A detector that
the current code cannot build from that configuration, such as the UBT of
a file from before the scintillator tiles, is left out of the run with a
warning: it records no hits, and its volumes in the stored geometry are
passive. Its stored configuration is kept, so that the geometry file this
run writes can be used with -g in the same way.

Definition at line 500 of file shipDet_conf.py.

500def configure(run, ship_geo, geofile: str | None = None):
501 """Configure the modules of the run and add them to it.
502
503 With ``geofile``, particles are transported through the geometry stored in
504 that geometry file: the modules build their geometry as usual, and a last
505 module replaces it by the stored one (see geometry_from_file). ``ship_geo``
506 must then be the configuration stored in the same file. A detector that
507 the current code cannot build from that configuration, such as the UBT of
508 a file from before the scintillator tiles, is left out of the run with a
509 warning: it records no hits, and its volumes in the stored geometry are
510 passive. Its stored configuration is kept, so that the geometry file this
511 run writes can be used with -g in the same way.
512 """
513 stored_yaml_configs = geometry_from_file.stored_yaml_configs(ship_geo) if geofile else {}
514 # ---- for backward compatibility ----
515 if not hasattr(ship_geo, "DecayVolumeMedium"):
516 raise ValueError("DecayVolumeMedium is not defined, possibly old (incompatible) geometry!")
517 if not hasattr(ship_geo.Bfield, "x"):
518 ship_geo.Bfield.x = 3.0 * u.m
519 if not hasattr(ship_geo, "cave"):
520 ship_geo.cave = AttrDict(z=0 * u.cm)
521 ship_geo.cave.floorHeightMuonShield = 5 * u.m
522 ship_geo.cave.floorHeightTankA = 4.5 * u.m
523 ship_geo.cave.floorHeightTankB = 2.0 * u.m
524 if not hasattr(ship_geo, "SND"):
525 ship_geo.SND = True
526 if not hasattr(ship_geo.cave, "ECN3FloorY"):
527 # Placing the UBT needs the ECN3 floor and side walls: use those of the
528 # cavern that ShipCave builds.
530 # With -g, the modules that the current code cannot build from the stored
531 # configuration, and why; they are left out of the run.
532 left_out: dict[str, str] = {}
533 ubt_geo = getattr(ship_geo, "UpstreamTagger", None)
534 has_tiles = hasattr(ubt_geo, "TileThickness") or hasattr(ubt_geo, "SmallTileZ")
535 has_scoring_planes = hasattr(ship_geo, "UpstreamTaggerScoringPlane")
536 if not (has_tiles and has_scoring_planes):
537 # A geometry from before the scintillator UBT: its UBT was a vacuum box,
538 # which can no longer be built, and it has no UBT scoring planes.
539 if geofile:
540 # Each module is left out only if its own configuration is missing.
541 old_ubt = "the UBT of before the scintillator tiles (a vacuum box), which the current code cannot build"
542 if not has_tiles:
543 left_out["UpstreamTagger"] = old_ubt
544 if not has_scoring_planes:
545 left_out["UpstreamTaggerScoringPlane"] = (
546 old_ubt
547 if not has_tiles
548 else "no configuration of the UBT scoring planes (UpstreamTaggerScoringPlane)"
549 )
550 else:
551 # Use the current UBT and scoring planes, placed from this geometry's
552 # decay vessel and muon shield, so that the other detectors can be
553 # used; the UBT points of such a file are not digitized (see
554 # UpstreamTaggerDetector.validate_stored_geometry).
556
557 # -----Create media-------------------------------------------------
558 run.SetMaterials("media.geo") # Materials
559 # ------------------------------------------------------------------------
560
561 # -----Create geometry----------------------------------------------
562 cave = ROOT.ShipCave("Cave", "ShipCave")
563 cave.SetGeometryFileName("caveWithAir.geo")
564 if hasattr(ship_geo.cave, "ECN3_length"):
565 cave.SetCavernDimensions(
566 ship_geo.cave.TCC8_length,
567 ship_geo.cave.ECN3_length,
568 ship_geo.cave.stair_step_length,
569 ship_geo.cave.z_transition,
570 )
571 cave.SetSpectrometerZ(ship_geo.z)
572 detectorList.append(cave)
573
574 TargetStation = ROOT.ShipTargetStation(
575 "TargetStation",
576 ship_geo.target.length,
577 ship_geo.target.z,
578 ship_geo.target.nS,
579 ship_geo.target.HeT,
580 )
581
582 TargetStation.SetLayerPosMat(
583 ship_geo.target.xy, ship_geo.target.slices_length, ship_geo.target.slices_gap, ship_geo.target.slices_material
584 )
585 target_version = getattr(ship_geo.target, "version", 1)
586 TargetStation.SetDesign(target_version)
587 if target_version >= 2:
588 TargetStation.SetLastDiskDiameter(ship_geo.target.xy2)
589 TargetStation.SetShieldingReferenceLength(ship_geo.target.length_fixed)
590 detectorList.append(TargetStation)
591
592 # For SND: support multiple designs
593 if ship_geo.SND:
594 for design in ship_geo.SND_design:
595 if design == 2:
596 # SND design 2 -- MTC/SiliconTarget
597 configure_snd_mtc(os.path.join(os.environ["FAIRSHIP"], "geometry", "MTC_config.yaml"), ship_geo)
598 configure_snd_siliconTarget(
599 os.path.join(os.environ["FAIRSHIP"], "geometry", "SiliconTarget_config.yaml"), ship_geo
600 )
601 elif design == 1:
602 if getattr(ship_geo, "UpstreamTagger", None) is None:
603 # Only possible with -g: otherwise set_upstream_tagger made one above.
604 raise ValueError(
605 f"{geofile} has SND design 1 but no UBT configuration (UpstreamTagger), from which that SND"
606 " design is placed, so it cannot be used with -g"
607 )
608 configure_snd_old(
609 os.path.join(os.environ["FAIRSHIP"], "geometry", "snd_config_old.yaml"),
610 _ubt_front_face(ship_geo.UpstreamTagger) - 5 * u.cm,
611 ship_geo.cave.floorHeightMuonShield,
612 )
613 else:
614 print(f"Warning: SND design {design} is not recognized.")
615
616 in_params = list(ship_geo.muShield.params)
617
618 MuonShield = ROOT.ShipMuonShield(in_params, ship_geo.muShield.nMagnets, ship_geo.muShield.z)
619
620 if ship_geo.SND:
621 # If any SND design is 2 (MTC), set SNDSpace for MuonShield
622 if 2 in getattr(ship_geo, "SND_design", []):
623 # The SND sits in the third-to-last and second-to-last magnets
624 # (S5 and M6 in the 2026 layout), see configure_snd_mtc.
625 n_magnets = ship_geo.muShield.nMagnets
626 MuonShield.SetSNDSpace(
627 hole=True,
628 hole_dx=(ship_geo.mtc_geo.width + 5.0 * u.cm) / 2.0,
629 hole_dy=(ship_geo.mtc_geo.height + 5.0 * u.cm) / 2.0,
630 first_magnet=n_magnets - 3,
631 last_magnet=n_magnets - 2,
632 )
633 detectorList.append(MuonShield)
634
635 if not hasattr(ship_geo, "magnetDesign"):
636 # backward compatibility
637 ship_geo.magnetDesign = 4
638 ship_geo.Bfield.YokeWidth = 200.0 * u.cm
639 ship_geo.Bfield.YokeDepth = 200.0 * u.cm
640 ship_geo.Bfield.CoilThick = 25.0 * u.cm
641 if ship_geo.strawDesign > 1:
642 if ship_geo.magnetDesign > 3:
643 B = ship_geo.Bfield
644 magnet = ROOT.ShipMagnet(
645 "Magnet",
646 "SHiP Magnet",
647 B.z,
648 ship_geo.magnetDesign,
649 B.x,
650 B.y,
651 ship_geo.cave.floorHeightTankB,
652 B.YokeWidth,
653 B.YokeDepth,
654 B.CoilThick,
655 )
656 # xaperture, yaperture
657 else:
658 magnet = ROOT.ShipMagnet(
659 "Magnet",
660 "SHiP Magnet",
661 ship_geo.Bfield.z,
662 ship_geo.magnetDesign,
663 ship_geo.Bfield.x,
664 ship_geo.Bfield.y,
665 ship_geo.cave.floorHeightTankB,
666 )
667 else:
668 magnet = ROOT.ShipMagnet("Magnet", "SHiP Magnet", ship_geo.Bfield.z)
669 detectorList.append(magnet)
670
671 fairship = os.environ["FAIRSHIP"]
672
673 configure_veto(
674 os.path.join(fairship, f"geometry/veto_config_{ship_geo.DecayVolumeMedium}.yaml"),
675 ship_geo.decayVolume.z0,
676 )
677
678 configure_strawtubes(
679 os.path.join(os.environ["FAIRSHIP"], "geometry", "strawtubes_config.yaml"),
680 ship_geo,
681 )
682
683 if hasattr(ship_geo, "CaloScoringPlane"): # absent in geometry files made before SplitCal removal
684 caloScoringPlane = ROOT.CaloScoringPlane("CaloScoringPlane", ROOT.kTRUE)
685 caloScoringPlane.SetZposition(ship_geo.CaloScoringPlane.z)
686 caloScoringPlane.SetBoxDimensions(
687 ship_geo.CaloScoringPlane.DX, ship_geo.CaloScoringPlane.DY, ship_geo.CaloScoringPlane.DZ
688 )
689 detectorList.append(caloScoringPlane)
690 else:
691 print("Warning: no CaloScoringPlane in this geometry configuration; not building it.")
692
693 if "UpstreamTagger" not in left_out:
694 upstreamTagger = ROOT.UpstreamTagger("UpstreamTagger", ROOT.kTRUE)
695 upstreamTagger.SetZposition(ship_geo.UpstreamTagger.z)
696 upstreamTagger.SetBoxDimensions(
697 ship_geo.UpstreamTagger.BoxX, ship_geo.UpstreamTagger.BoxY, ship_geo.UpstreamTagger.BoxZ
698 )
699 upstreamTagger.SetBoxCenter(ship_geo.UpstreamTagger.BoxCenterX, ship_geo.UpstreamTagger.BoxCenterY)
700 configure_upstream_tagger(
701 os.path.join(os.environ["FAIRSHIP"], "geometry", "UpstreamTagger_config.yaml"),
702 upstreamTagger,
703 ship_geo,
704 )
705 detectorList.append(upstreamTagger)
706
707 if "UpstreamTaggerScoringPlane" not in left_out:
708 sp = ship_geo.UpstreamTaggerScoringPlane
709 ubt_scoring_plane = ROOT.UpstreamTaggerScoringPlane("UpstreamTaggerScoringPlane", ROOT.kTRUE)
710 # Planes 1 and 2, in this order: the plane number is the point detector ID.
711 for number, plane in enumerate((sp.DecayVessel, sp.MuonShield), start=1):
712 ubt_scoring_plane.AddPlane(
713 f"UpstreamTaggerScoringPlane{number}",
714 plane.CenterX,
715 plane.CenterY,
716 plane.z,
717 plane.X,
718 plane.Y,
719 sp.Z,
720 [13] if plane.MuonsOnly else [],
721 plane.get("KeepTracks", True), # absent in geometry files written before it
722 )
723 detectorList.append(ubt_scoring_plane)
724
725 timeDet = ROOT.TimeDet("TimeDet", ROOT.kTRUE)
726 timeDet.SetZposition(ship_geo.TimeDet.z)
727 timeDet.SetBarZspacing(ship_geo.TimeDet.dzBarRow, ship_geo.TimeDet.dzBarCol)
728 timeDet.SetBarZ(ship_geo.TimeDet.zBar)
729 timeDet.SetSizeX(2 * ship_geo.TimeDet.DX)
730 timeDet.SetSizeY(2 * ship_geo.TimeDet.DY)
731 detectorList.append(timeDet)
732
733 # ----- Magnetic field -------------------------------------------
734 if not hasattr(ship_geo.Bfield, "fieldMap"):
735 if ship_geo.strawDesign == 4 or ship_geo.strawDesign == 10:
736 fMagField = ROOT.ShipBellField(
737 "wilfried",
738 ship_geo.Bfield.max,
739 ship_geo.Bfield.z,
740 2,
741 ship_geo.Yheight / 2.0 * u.m,
742 )
743 else:
744 fMagField = ROOT.ShipBellField(
745 "wilfried",
746 ship_geo.Bfield.max,
747 ship_geo.Bfield.z,
748 1,
749 ship_geo.Yheight / 2.0 * u.m,
750 )
751 run.SetField(fMagField)
752 ROOT.SetOwnership(fMagField, False) # C++ FairRunSim takes ownership
753
754 exclusionList: list[str] = []
755 # exclusionList = ["strawtubes","TargetTrackers","NuTauTarget",\
756 # "SiliconTarget","Veto","Magnet","MuonShield","TargetStation", "TimeDet", "UpstreamTagger"]
757
758 # Heterogeneous module dict: keys are GetName() strings, values are
759 # FairModule subclasses (Target/MTC/strawtubes/...). Annotate as Any to
760 # match the heterogeneous detectorList type.
761 detElements: dict[str, Any] = {}
762 if geofile:
763 geometry_from_file.check_yaml_configs(stored_yaml_configs, ship_geo)
764 geometry_from_file.warn_left_out(geofile, left_out)
765 for x in detectorList:
766 if x.GetName() in exclusionList:
767 continue
768 run.AddModule(x)
769 ROOT.SetOwnership(x, False) # C++ FairRunSim takes ownership
770 detElements[x.GetName()] = x
771 if geofile:
772 # Last, so that every module has built its geometry, registered its
773 # sensitive volumes and attached its fields before the swap. The
774 # caller must keep the returned dict: C++ calls back into this object.
775 swap = geometry_from_file.make_swap(geofile)
776 run.AddModule(swap)
777 ROOT.SetOwnership(swap, False) # C++ FairRunSim takes ownership
778 detElements[geometry_from_file.SWAP_NAME] = swap
779 return detElements
None set_upstream_tagger(c)
dict[str, Any] stored_yaml_configs(Any ship_geo)
None warn_left_out(str geofile, dict[str, str] left_out)
Any make_swap(str geofile)
None check_yaml_configs(dict[str, Any] stored, Any ship_geo)

◆ configure_snd_mtc()

None shipDet_conf.configure_snd_mtc ( str yaml_file,
ship_geo )

Definition at line 126 of file shipDet_conf.py.

126def configure_snd_mtc(yaml_file: str, ship_geo) -> None:
127 with open(yaml_file) as file:
128 config = yaml.safe_load(file)
129
130 ship_geo.mtc_geo = AttrDict(config["MTC"])
131 # Initialize detector
132 if ship_geo.mtc_geo.zPosition == "auto":
133 # Centre of the second-to-last magnet (M6 in the 2026 layout), see configure_snd_siliconTarget
134 mtc_total_length = (
135 ship_geo.mtc_geo.ironThick + ship_geo.mtc_geo.sciFiThick + ship_geo.mtc_geo.scintThick
136 ) * ship_geo.mtc_geo.nLayers
137 ship_geo.mtc_geo.zPosition = ship_geo.muShield.Entrance[-2] + ship_geo.muShield.half_length[-2]
138 if mtc_total_length > 2 * ship_geo.muShield.half_length[-2]:
139 print("Warning: MTC is longer than the magnet it is placed in")
140 mtc = ROOT.MTCDetector("MTC", ROOT.kTRUE)
141 mtc.SetMTCParameters(
142 ship_geo.mtc_geo.width,
143 ship_geo.mtc_geo.height,
144 ship_geo.mtc_geo.angle,
145 ship_geo.mtc_geo.ironThick,
146 ship_geo.mtc_geo.sciFiThick,
147 ship_geo.mtc_geo.num_of_agg_channels,
148 ship_geo.mtc_geo.scint_cell_size,
149 ship_geo.mtc_geo.scintThick,
150 ship_geo.mtc_geo.nLayers,
151 ship_geo.mtc_geo.zPosition,
152 ship_geo.mtc_geo.fieldY,
153 )
154 detectorList.append(mtc)
155
156

◆ configure_snd_old()

None shipDet_conf.configure_snd_old ( str yaml_file,
emulsion_target_z_end,
cave_floorHeightMuonShield )

Definition at line 21 of file shipDet_conf.py.

21def configure_snd_old(yaml_file: str, emulsion_target_z_end, cave_floorHeightMuonShield) -> None:
22 with open(yaml_file) as file:
23 config = yaml.safe_load(file)
24 nuTarget_geo = AttrDict(config["nuTarget"])
25 nuTauTT_geo = AttrDict(config["nuTauTT"])
26
27 # specific parameters
28 # nu Target Tracker
29 snd_nuTauTT_TTX = (
30 nuTauTT_geo.n_hor_planes * nuTauTT_geo.scifimat_width + 2.9 * u.cm
31 ) # endpieces (~2.9cm from previous geom)
32 snd_nuTauTT_TTY = (
33 nuTauTT_geo.n_vert_planes * nuTauTT_geo.scifimat_width + 2.9 * u.cm
34 ) # endpieces (~2.9cm from previous geom)
35
36 snd_nuTauTT_TTZ = 2 * nuTauTT_geo.support_z + 2 * nuTauTT_geo.scifimat_z + nuTauTT_geo.honeycomb_z
37
38 # nuTau target
39 snd_nuTarget_BrZ = (
40 nuTarget_geo.n_plates * nuTarget_geo.LeadTh
41 + (nuTarget_geo.n_plates + 1) * (2 * nuTarget_geo.EmTh + nuTarget_geo.PBTh)
42 + nuTarget_geo.BrPackZ
43 )
44 snd_nuTarget_BrX = nuTarget_geo.BrPackX + nuTarget_geo.EmX
45 snd_nuTarget_BrY = nuTarget_geo.BrPackY + nuTarget_geo.EmY
46
47 snd_nuTarget_zdim = nuTarget_geo.wall * snd_nuTarget_BrZ + (nuTarget_geo.wall + 1) * snd_nuTauTT_TTZ
48 snd_nuTarget_xdim = snd_nuTauTT_TTX
49 snd_nuTarget_ydim = snd_nuTauTT_TTY
50
51 snd_nuTarget_zC = emulsion_target_z_end - snd_nuTarget_zdim / 2.0
52
53 snd_nuTarget_PillarY = (
54 10 * u.m - snd_nuTarget_ydim / 2 - nuTarget_geo.BaseY - 0.1 * u.mm - cave_floorHeightMuonShield
55 )
56 NuTauTarget = ROOT.Target("NuTauTarget", nuTarget_geo.Ydist, ROOT.kTRUE)
57 NuTauTarget.MakeNuTargetPassive(nuTarget_geo.nuTargetPassive)
58 NuTauTarget.MergeTopBot(nuTarget_geo.SingleEmFilm)
59 NuTauTarget.SetDetectorDesign(nuTarget_geo.Design)
60 NuTauTarget.SetCenterZ(snd_nuTarget_zC)
61 NuTauTarget.SetNumberBricks(
62 nuTarget_geo.col,
63 nuTarget_geo.row,
64 nuTarget_geo.wall,
65 )
66 NuTauTarget.SetDetectorDimension(
67 snd_nuTarget_xdim,
68 snd_nuTarget_ydim,
69 snd_nuTarget_zdim,
70 )
71 NuTauTarget.SetTargetWallDimension(
72 nuTarget_geo.col * snd_nuTarget_BrX,
73 nuTarget_geo.row * snd_nuTarget_BrY + (nuTarget_geo.row - 1) * nuTarget_geo.Ydist,
74 snd_nuTarget_BrZ,
75 )
76 NuTauTarget.SetEmulsionParam(
77 nuTarget_geo.EmTh,
78 nuTarget_geo.EmX,
79 nuTarget_geo.EmY,
80 nuTarget_geo.PBTh,
81 2 * nuTarget_geo.EmTh + nuTarget_geo.PBTh,
82 nuTarget_geo.LeadTh,
83 nuTarget_geo.LeadTh + 2 * nuTarget_geo.EmTh + nuTarget_geo.PBTh,
84 )
85 NuTauTarget.SetBrickParam(
86 snd_nuTarget_BrX,
87 snd_nuTarget_BrY,
88 snd_nuTarget_BrZ,
89 nuTarget_geo.BrPackX,
90 nuTarget_geo.BrPackY,
91 nuTarget_geo.BrPackZ,
92 nuTarget_geo.n_plates,
93 )
94 NuTauTarget.SetCellParam(snd_nuTarget_BrZ)
95 NuTauTarget.SetPillarDimension(nuTarget_geo.PillarX, snd_nuTarget_PillarY, nuTarget_geo.PillarZ)
96 NuTauTarget.SetBaseDimension(snd_nuTarget_xdim + 20, nuTarget_geo.BaseY, snd_nuTarget_zdim + 10)
97 # Target Tracker
98 NuTauTT = ROOT.TargetTracker(
99 "TargetTrackers",
100 snd_nuTauTT_TTX,
101 snd_nuTauTT_TTY,
102 snd_nuTauTT_TTZ,
103 ROOT.kTRUE,
104 )
105 NuTauTT.SetDesign(nuTauTT_geo.design)
106 NuTauTT.SetSciFiParam(
107 nuTauTT_geo.scifimat_width,
108 snd_nuTauTT_TTX,
109 snd_nuTauTT_TTY,
110 nuTauTT_geo.scifimat_z,
111 nuTauTT_geo.support_z,
112 nuTauTT_geo.honeycomb_z,
113 )
114 NuTauTT.SetNumberSciFi(nuTauTT_geo.n_hor_planes, nuTauTT_geo.n_vert_planes)
115 NuTauTT.SetTargetTrackerParam(snd_nuTauTT_TTX, snd_nuTauTT_TTY, snd_nuTauTT_TTZ)
116 NuTauTT.SetBrickParam(snd_nuTarget_BrZ)
117 NuTauTT.SetTotZDimension(snd_nuTarget_zdim)
118 NuTauTT.SetNumberTT(nuTarget_geo.wall + 1)
119 # method of nutau target that must be called after TT parameter definition
120 NuTauTarget.SetTTzdimension(snd_nuTauTT_TTZ)
121
122 detectorList.append(NuTauTarget)
123 detectorList.append(NuTauTT)
124
125

◆ configure_snd_siliconTarget()

None shipDet_conf.configure_snd_siliconTarget ( str yaml_file,
ship_geo )

Definition at line 157 of file shipDet_conf.py.

157def configure_snd_siliconTarget(yaml_file: str, ship_geo) -> None:
158 with open(yaml_file) as file:
159 config = yaml.safe_load(file)
160
161 ship_geo.SiliconTarget_geo = AttrDict(config["SiliconTarget"])
162 # Initialize detector
163 if ship_geo.SiliconTarget_geo.zPosition == "auto":
164 # auto: the last layer ends at the downstream face of the third-to-last
165 # magnet (S5 in the 2026 layout), one magnet Z-gap upstream of the
166 # magnet that holds the MTC. This follows the integration layout
167 # 2026-0.1, where the scattering detector occupies the end of S5 and
168 # the whole of M6.
169 SiliconTarget_total_length = ship_geo.SiliconTarget_geo.targetSpacing * ship_geo.SiliconTarget_geo.nLayers
170 ship_geo.SiliconTarget_geo.zPosition = (
171 ship_geo.muShield.Entrance[-2] - ship_geo.muShield.Zgap[-2] - SiliconTarget_total_length / 2
172 )
173 print("SiliconTarget zPosition set to ", ship_geo.SiliconTarget_geo.zPosition)
174 SiliconTarget = ROOT.SiliconTarget("SiliconTarget", ROOT.kTRUE)
176 ship_geo.SiliconTarget_geo.targetWidth,
177 ship_geo.SiliconTarget_geo.targetHeight,
178 ship_geo.SiliconTarget_geo.sensorWidth,
179 ship_geo.SiliconTarget_geo.sensorLength,
180 ship_geo.SiliconTarget_geo.nLayers,
181 ship_geo.SiliconTarget_geo.zPosition,
182 ship_geo.SiliconTarget_geo.targetThickness,
183 ship_geo.SiliconTarget_geo.targetSpacing,
184 ship_geo.SiliconTarget_geo.moduleOffset,
185 )
186 detectorList.append(SiliconTarget)
187
188
void SetSiliconTargetParameters(Double_t targetWidth, Double_t targetHeight, Double_t sensorWidth, Double_t sensorLength, Int_t nLayers, Double_t zPosition, Double_t targetThickness, Double_t targetSpacing, Double_t moduleOffset)

◆ configure_strawtubes()

None shipDet_conf.configure_strawtubes ( str yaml_file,
ship_geo )

Definition at line 223 of file shipDet_conf.py.

223def configure_strawtubes(yaml_file: str, ship_geo) -> None:
224 with open(yaml_file) as file:
225 config = yaml.safe_load(file)
226
227 ship_geo.strawtubes_geo = AttrDict(config["SST"])
228
229 # Straw tubes in decay vessel if vacuum, otherwise outside in air
230 ship_geo.strawtubes_geo.medium = "vacuums" if ship_geo.DecayVolumeMedium == "vacuums" else "air"
231
232 # Choose frame material
233 if ship_geo.strawDesign == 4:
234 ship_geo.strawtubes_geo.frame_material = "Aluminium"
235 elif ship_geo.strawDesign == 10:
236 ship_geo.strawtubes_geo.frame_material = "steel"
237
238 strawtubes = ROOT.strawtubes(ship_geo.strawtubes_geo.medium)
240 ship_geo.TrackStation1.z,
241 ship_geo.TrackStation2.z,
242 ship_geo.TrackStation3.z,
243 ship_geo.TrackStation4.z,
244 )
246 ship_geo.strawtubes_geo.width,
247 ship_geo.strawtubes_geo.height,
248 )
250 ship_geo.strawtubes_geo.outer_straw_diameter,
251 ship_geo.strawtubes_geo.wall_thickness,
252 )
254 ship_geo.strawtubes_geo.straw_pitch,
255 ship_geo.strawtubes_geo.y_layer_offset,
256 )
257 strawtubes.SetDeltazLayer(ship_geo.strawtubes_geo.delta_z_layer)
258 strawtubes.SetStereoAngle(ship_geo.strawtubes_geo.view_angle)
259 strawtubes.SetWireThickness(ship_geo.strawtubes_geo.wire_thickness)
260 strawtubes.SetDeltazView(ship_geo.strawtubes_geo.delta_z_view)
261 strawtubes.SetFrameMaterial(ship_geo.strawtubes_geo.frame_material)
263 ship_geo.strawtubes_geo.station_width,
264 ship_geo.strawtubes_geo.station_height,
265 ship_geo.strawtubes_geo.station_length,
266 )
267
268 # For digitization
270 ship_geo.strawtubesDigi.v_drift,
271 ship_geo.strawtubesDigi.sigma_spatial,
272 )
273
274 detectorList.append(strawtubes)
275
276
void SetDeltazView(Double_t delta_z_view)
void SetStrawResolution(Double_t a, Double_t b)
Definition strawtubes.h:50
void SetDeltazLayer(Double_t delta_z_layer)
void SetStrawDiameter(Double_t outer_straw_diameter, Double_t wall_thickness)
void SetzPositions(Double_t z1, Double_t z2, Double_t z3, Double_t z4)
void SetStrawPitch(Double_t straw_pitch, Double_t layer_offset)
void SetFrameMaterial(TString frame_material)
void SetStereoAngle(Double_t stereo_angle)
void SetWireThickness(Double_t wire_thickness)
void SetApertureArea(Double_t width, Double_t height)
void SetStationEnvelope(Double_t x, Double_t y, Double_t z)

◆ configure_upstream_tagger()

None shipDet_conf.configure_upstream_tagger ( str yaml_file,
upstream_tagger,
ship_geo )
Configure the UBT regions and their digitization parameters.

The regions are generated from the rule in ``yaml_file`` on the UBT box of
``ship_geo``, and the resulting map is kept in ``ship_geo.UpstreamTagger_geo``,
so that it is saved with the geometry. A configuration read back from a
geometry file (reconstruction, analysis, ``-g``) already has it: then the
stored map is used, so that the regions and tile IDs are those of the
simulation, whatever the rule in the checkout says.

Definition at line 407 of file shipDet_conf.py.

407def configure_upstream_tagger(yaml_file: str, upstream_tagger, ship_geo) -> None:
408 """Configure the UBT regions and their digitization parameters.
409
410 The regions are generated from the rule in ``yaml_file`` on the UBT box of
411 ``ship_geo``, and the resulting map is kept in ``ship_geo.UpstreamTagger_geo``,
412 so that it is saved with the geometry. A configuration read back from a
413 geometry file (reconstruction, analysis, ``-g``) already has it: then the
414 stored map is used, so that the regions and tile IDs are those of the
415 simulation, whatever the rule in the checkout says.
416 """
417 with open(yaml_file) as file:
418 rule = yaml.safe_load(file)
419
420 stored_map = ship_geo.get("UpstreamTagger_geo")
421 if stored_map is None:
422 ubt_map = generate_upstream_tagger_map(rule, ship_geo.UpstreamTagger)
423 ship_geo.UpstreamTagger_geo = AttrDict(ubt_map)
424 else:
425 # The rule of the checkout is only compared with the stored map: it may
426 # have changed since the simulation and no longer fit the stored box.
427 try:
428 differs = dict(stored_map) != generate_upstream_tagger_map(rule, ship_geo.UpstreamTagger)
429 except ValueError:
430 differs = True
431 ubt_map = stored_map
432 if differs:
433 print(
434 f"Warning: the UBT map generated from {yaml_file} differs from the one stored with the"
435 " geometry; the stored map, used in the simulation, is used."
436 )
437 # A generated map tiles its box by construction, so only a stored
438 # map that the rule does not reproduce needs checking.
439 check_upstream_tagger_map(ubt_map, ship_geo.UpstreamTagger)
440
441 regions = ubt_map["regions"]
442 region_ids = [region["id"] for region in regions]
443 if len(region_ids) != len(set(region_ids)):
444 raise ValueError("The UBT detector map contains duplicate region IDs")
445
446 # Kept in ShipGeo for digitization: detector ID -> constituent tile side
447 # in FairShip internal length units. This distinguishes 2x2 and 4x4 cm2.
448 ship_geo.UpstreamTagger.RegionTileSize = {
449 region["id"]: region["constituent_tile_size"] * u.cm for region in regions
450 }
451 ship_geo.UpstreamTagger.TileGridOriginX, ship_geo.UpstreamTagger.TileGridEndX = (
452 bound * u.cm for bound in ubt_map["bounds"]["x"]
453 )
454 ship_geo.UpstreamTagger.TileGridOriginY, ship_geo.UpstreamTagger.TileGridEndY = (
455 bound * u.cm for bound in ubt_map["bounds"]["y"]
456 )
457 # TH2D maps of ADC counts per MeV vs local hit position (mm) in a tile,
458 # named adc_per_mev_<tile side in mm>mm.
459 ship_geo.UpstreamTagger.ADCResponseMapFile = os.path.join(
460 os.environ["FAIRSHIP"], "geometry", "UpstreamTagger_adc_response.root"
461 )
462
463 # Tile side (cm) -> thickness. A configuration read back from a file has
464 # the keys as strings, and one written before TileThickness has the
465 # thicknesses of the 20 and 40 mm tiles in SmallTileZ and LargeTileZ.
466 ubt_geo = ship_geo.UpstreamTagger
467 if "TileThickness" not in ubt_geo:
468 ubt_geo.TileThickness = {2: ubt_geo.SmallTileZ, 4: ubt_geo.LargeTileZ}
469 thicknesses = {float(size): thickness for size, thickness in ubt_geo.TileThickness.items()}
470 for region in regions:
471 thickness = thicknesses.get(float(region["constituent_tile_size"]))
472 if thickness is None:
473 raise ValueError(
474 f"UBT region {region['id']} has {region['constituent_tile_size']} cm tiles, which have no thickness in"
475 f" UpstreamTagger.TileThickness (tile sides {sorted(thicknesses)} cm)"
476 )
477 upstream_tagger.AddRegion(
478 region["id"],
479 region["x"] * u.cm,
480 region["y"] * u.cm,
481 region["size_x"] * u.cm,
482 region["size_y"] * u.cm,
483 region["constituent_tile_size"],
484 thickness,
485 )
486
487

◆ configure_veto()

None shipDet_conf.configure_veto ( str yaml_file,
z0 )

Definition at line 189 of file shipDet_conf.py.

189def configure_veto(yaml_file: str, z0) -> None:
190 with open(yaml_file) as file:
191 config = yaml.safe_load(file)
192
193 veto_geo = AttrDict(config)
194
195 Veto = ROOT.veto()
196 Veto.SetVesselDimensions(
197 veto_geo.xstartInner,
198 veto_geo.xendInner,
199 veto_geo.ystartInner,
200 veto_geo.yendInner,
201 z0,
202 )
203
204 Veto.SetLiquidVeto(1)
205
206 Veto.SetVesselStructure(
207 veto_geo.innerSupport,
208 veto_geo.sensitiveThickness,
209 veto_geo.outerSupport,
210 veto_geo.innerSupportMed,
211 veto_geo.lidThickness,
212 veto_geo.sensitiveMed,
213 veto_geo.outerSupportMed,
214 veto_geo.decayMed,
215 veto_geo.rib,
216 veto_geo.he_balloon_thickness,
217 veto_geo.he_balloon_med,
218 )
219
220 detectorList.append(Veto)
221
222

◆ generate_upstream_tagger_map()

dict[str, Any] shipDet_conf.generate_upstream_tagger_map ( rule,
ubt_geo )
Generate the UBT regions on the UBT box of the geometry configuration.

See the note in geometry/UpstreamTagger_config.yaml for the rule. The map
has the same form as the one stored with the geometry: kind, units, the
bounds of the box and the regions, all in cm.

Definition at line 351 of file shipDet_conf.py.

351def generate_upstream_tagger_map(rule, ubt_geo) -> dict[str, Any]:
352 """Generate the UBT regions on the UBT box of the geometry configuration.
353
354 See the note in geometry/UpstreamTagger_config.yaml for the rule. The map
355 has the same form as the one stored with the geometry: kind, units, the
356 bounds of the box and the regions, all in cm.
357 """
358 if rule["kind"] != "simulation" or rule["units"] != "cm":
359 raise ValueError("The UBT map must be a simulation map expressed in cm")
360 bounds = {
361 "x": [(ubt_geo.BoxCenterX - ubt_geo.BoxX / 2.0) / u.cm, (ubt_geo.BoxCenterX + ubt_geo.BoxX / 2.0) / u.cm],
362 "y": [(ubt_geo.BoxCenterY - ubt_geo.BoxY / 2.0) / u.cm, (ubt_geo.BoxCenterY + ubt_geo.BoxY / 2.0) / u.cm],
363 }
364 size = rule["region_size"]
365 areas = _small_tile_areas(rule)
366 tolerance = 1.0e-9 # cm
367 regions = []
368 for y, size_y in _axis_cells(bounds["y"][0], bounds["y"][1], size):
369 for x, size_x in _axis_cells(bounds["x"][0], bounds["x"][1], size):
370 # A region lying inside a small-tile area has small tiles; an area
371 # covering only part of a region would cut it in two.
372 low_x, high_x, low_y, high_y = x - size_x / 2.0, x + size_x / 2.0, y - size_y / 2.0, y + size_y / 2.0
373 in_area = False
374 for area in areas:
375 overlap_x = min(high_x, area[1]) - max(low_x, area[0])
376 overlap_y = min(high_y, area[3]) - max(low_y, area[2])
377 if overlap_x <= tolerance or overlap_y <= tolerance:
378 continue
379 if overlap_x < size_x - tolerance or overlap_y < size_y - tolerance:
380 raise ValueError(
381 f"The UBT small-tile area x {list(area[:2])}, y {list(area[2:])} cm covers only part of the"
382 f" region at ({x}, {y}) cm: its edges must lie on region edges"
383 )
384 in_area = True
385 tile = rule["small_tile_size"] if in_area else rule["large_tile_size"]
386 for centre, extent, axis in ((x, size_x, "x"), (y, size_y, "y")):
387 for edge in (centre - extent / 2.0, centre + extent / 2.0):
388 tiles = (edge - rule["tile_edge_offset"]) / tile
389 if abs(tiles - round(tiles)) > 1.0e-6:
390 raise ValueError(
391 f"The UBT region at ({x}, {y}) cm has an edge at {axis} = {edge} cm, off the grid of its"
392 f" {tile} cm tiles: the UBT box, {bounds} cm, must end on a tile edge"
393 )
394 regions.append(
395 {
396 "id": len(regions),
397 "x": x,
398 "y": y,
399 "size_x": size_x,
400 "size_y": size_y,
401 "constituent_tile_size": tile,
402 }
403 )
404 return {"kind": rule["kind"], "units": rule["units"], "bounds": bounds, "regions": regions}
405
406

Variable Documentation

◆ detectorList

list shipDet_conf.detectorList = []

Definition at line 18 of file shipDet_conf.py.