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"])
30 nuTauTT_geo.n_hor_planes * nuTauTT_geo.scifimat_width + 2.9 * u.cm
33 nuTauTT_geo.n_vert_planes * nuTauTT_geo.scifimat_width + 2.9 * u.cm
36 snd_nuTauTT_TTZ = 2 * nuTauTT_geo.support_z + 2 * nuTauTT_geo.scifimat_z + nuTauTT_geo.honeycomb_z
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
44 snd_nuTarget_BrX = nuTarget_geo.BrPackX + nuTarget_geo.EmX
45 snd_nuTarget_BrY = nuTarget_geo.BrPackY + nuTarget_geo.EmY
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
51 snd_nuTarget_zC = emulsion_target_z_end - snd_nuTarget_zdim / 2.0
53 snd_nuTarget_PillarY = (
54 10 * u.m - snd_nuTarget_ydim / 2 - nuTarget_geo.BaseY - 0.1 * u.mm - cave_floorHeightMuonShield
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(
66 NuTauTarget.SetDetectorDimension(
71 NuTauTarget.SetTargetWallDimension(
72 nuTarget_geo.col * snd_nuTarget_BrX,
73 nuTarget_geo.row * snd_nuTarget_BrY + (nuTarget_geo.row - 1) * nuTarget_geo.Ydist,
76 NuTauTarget.SetEmulsionParam(
81 2 * nuTarget_geo.EmTh + nuTarget_geo.PBTh,
83 nuTarget_geo.LeadTh + 2 * nuTarget_geo.EmTh + nuTarget_geo.PBTh,
85 NuTauTarget.SetBrickParam(
92 nuTarget_geo.n_plates,
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)
98 NuTauTT = ROOT.TargetTracker(
105 NuTauTT.SetDesign(nuTauTT_geo.design)
106 NuTauTT.SetSciFiParam(
107 nuTauTT_geo.scifimat_width,
110 nuTauTT_geo.scifimat_z,
111 nuTauTT_geo.support_z,
112 nuTauTT_geo.honeycomb_z,
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)
120 NuTauTarget.SetTTzdimension(snd_nuTauTT_TTZ)
122 detectorList.append(NuTauTarget)
123 detectorList.append(NuTauTT)
127 with open(yaml_file)
as file:
128 config = yaml.safe_load(file)
130 ship_geo.mtc_geo =
AttrDict(config[
"MTC"])
132 if ship_geo.mtc_geo.zPosition ==
"auto":
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,
154 detectorList.append(mtc)
158 with open(yaml_file)
as file:
159 config = yaml.safe_load(file)
161 ship_geo.SiliconTarget_geo =
AttrDict(config[
"SiliconTarget"])
163 if ship_geo.SiliconTarget_geo.zPosition ==
"auto":
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
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,
186 detectorList.append(SiliconTarget)
224 with open(yaml_file)
as file:
225 config = yaml.safe_load(file)
227 ship_geo.strawtubes_geo =
AttrDict(config[
"SST"])
230 ship_geo.strawtubes_geo.medium =
"vacuums" if ship_geo.DecayVolumeMedium ==
"vacuums" else "air"
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"
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,
246 ship_geo.strawtubes_geo.width,
247 ship_geo.strawtubes_geo.height,
250 ship_geo.strawtubes_geo.outer_straw_diameter,
251 ship_geo.strawtubes_geo.wall_thickness,
254 ship_geo.strawtubes_geo.straw_pitch,
255 ship_geo.strawtubes_geo.y_layer_offset,
263 ship_geo.strawtubes_geo.station_width,
264 ship_geo.strawtubes_geo.station_height,
265 ship_geo.strawtubes_geo.station_length,
270 ship_geo.strawtubesDigi.v_drift,
271 ship_geo.strawtubesDigi.sigma_spatial,
274 detectorList.append(strawtubes)
352 """Generate the UBT regions on the UBT box of the geometry configuration.
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.
358 if rule[
"kind"] !=
"simulation" or rule[
"units"] !=
"cm":
359 raise ValueError(
"The UBT map must be a simulation map expressed in cm")
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],
364 size = rule[
"region_size"]
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):
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
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:
379 if overlap_x < size_x - tolerance
or overlap_y < size_y - tolerance:
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"
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:
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"
401 "constituent_tile_size": tile,
404 return {
"kind": rule[
"kind"],
"units": rule[
"units"],
"bounds": bounds,
"regions": regions}
408 """Configure the UBT regions and their digitization parameters.
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.
417 with open(yaml_file)
as file:
418 rule = yaml.safe_load(file)
420 stored_map = ship_geo.get(
"UpstreamTagger_geo")
421 if stored_map
is None:
423 ship_geo.UpstreamTagger_geo =
AttrDict(ubt_map)
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."
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")
448 ship_geo.UpstreamTagger.RegionTileSize = {
449 region[
"id"]: region[
"constituent_tile_size"] * u.cm
for region
in regions
451 ship_geo.UpstreamTagger.TileGridOriginX, ship_geo.UpstreamTagger.TileGridEndX = (
452 bound * u.cm
for bound
in ubt_map[
"bounds"][
"x"]
454 ship_geo.UpstreamTagger.TileGridOriginY, ship_geo.UpstreamTagger.TileGridEndY = (
455 bound * u.cm
for bound
in ubt_map[
"bounds"][
"y"]
459 ship_geo.UpstreamTagger.ADCResponseMapFile = os.path.join(
460 os.environ[
"FAIRSHIP"],
"geometry",
"UpstreamTagger_adc_response.root"
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:
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)"
477 upstream_tagger.AddRegion(
481 region[
"size_x"] * u.cm,
482 region[
"size_y"] * u.cm,
483 region[
"constituent_tile_size"],
500def configure(run, ship_geo, geofile: str |
None =
None):
501 """Configure the modules of the run and add them to it.
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.
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"):
526 if not hasattr(ship_geo.cave,
"ECN3FloorY"):
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):
541 old_ubt =
"the UBT of before the scintillator tiles (a vacuum box), which the current code cannot build"
543 left_out[
"UpstreamTagger"] = old_ubt
544 if not has_scoring_planes:
545 left_out[
"UpstreamTaggerScoringPlane"] = (
548 else "no configuration of the UBT scoring planes (UpstreamTaggerScoringPlane)"
558 run.SetMaterials(
"media.geo")
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,
571 cave.SetSpectrometerZ(ship_geo.z)
572 detectorList.append(cave)
574 TargetStation = ROOT.ShipTargetStation(
576 ship_geo.target.length,
582 TargetStation.SetLayerPosMat(
583 ship_geo.target.xy, ship_geo.target.slices_length, ship_geo.target.slices_gap, ship_geo.target.slices_material
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)
594 for design
in ship_geo.SND_design:
597 configure_snd_mtc(os.path.join(os.environ[
"FAIRSHIP"],
"geometry",
"MTC_config.yaml"), ship_geo)
599 os.path.join(os.environ[
"FAIRSHIP"],
"geometry",
"SiliconTarget_config.yaml"), ship_geo
602 if getattr(ship_geo,
"UpstreamTagger",
None)
is None:
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"
609 os.path.join(os.environ[
"FAIRSHIP"],
"geometry",
"snd_config_old.yaml"),
611 ship_geo.cave.floorHeightMuonShield,
614 print(f
"Warning: SND design {design} is not recognized.")
616 in_params = list(ship_geo.muShield.params)
618 MuonShield = ROOT.ShipMuonShield(in_params, ship_geo.muShield.nMagnets, ship_geo.muShield.z)
622 if 2
in getattr(ship_geo,
"SND_design", []):
625 n_magnets = ship_geo.muShield.nMagnets
626 MuonShield.SetSNDSpace(
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,
633 detectorList.append(MuonShield)
635 if not hasattr(ship_geo,
"magnetDesign"):
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:
644 magnet = ROOT.ShipMagnet(
648 ship_geo.magnetDesign,
651 ship_geo.cave.floorHeightTankB,
658 magnet = ROOT.ShipMagnet(
662 ship_geo.magnetDesign,
665 ship_geo.cave.floorHeightTankB,
668 magnet = ROOT.ShipMagnet(
"Magnet",
"SHiP Magnet", ship_geo.Bfield.z)
669 detectorList.append(magnet)
671 fairship = os.environ[
"FAIRSHIP"]
674 os.path.join(fairship, f
"geometry/veto_config_{ship_geo.DecayVolumeMedium}.yaml"),
675 ship_geo.decayVolume.z0,
679 os.path.join(os.environ[
"FAIRSHIP"],
"geometry",
"strawtubes_config.yaml"),
683 if hasattr(ship_geo,
"CaloScoringPlane"):
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
689 detectorList.append(caloScoringPlane)
691 print(
"Warning: no CaloScoringPlane in this geometry configuration; not building it.")
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
699 upstreamTagger.SetBoxCenter(ship_geo.UpstreamTagger.BoxCenterX, ship_geo.UpstreamTagger.BoxCenterY)
701 os.path.join(os.environ[
"FAIRSHIP"],
"geometry",
"UpstreamTagger_config.yaml"),
705 detectorList.append(upstreamTagger)
707 if "UpstreamTaggerScoringPlane" not in left_out:
708 sp = ship_geo.UpstreamTaggerScoringPlane
709 ubt_scoring_plane = ROOT.UpstreamTaggerScoringPlane(
"UpstreamTaggerScoringPlane", ROOT.kTRUE)
711 for number, plane
in enumerate((sp.DecayVessel, sp.MuonShield), start=1):
712 ubt_scoring_plane.AddPlane(
713 f
"UpstreamTaggerScoringPlane{number}",
720 [13]
if plane.MuonsOnly
else [],
721 plane.get(
"KeepTracks",
True),
723 detectorList.append(ubt_scoring_plane)
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)
734 if not hasattr(ship_geo.Bfield,
"fieldMap"):
735 if ship_geo.strawDesign == 4
or ship_geo.strawDesign == 10:
736 fMagField = ROOT.ShipBellField(
741 ship_geo.Yheight / 2.0 * u.m,
744 fMagField = ROOT.ShipBellField(
749 ship_geo.Yheight / 2.0 * u.m,
751 run.SetField(fMagField)
752 ROOT.SetOwnership(fMagField,
False)
754 exclusionList: list[str] = []
761 detElements: dict[str, Any] = {}
765 for x
in detectorList:
766 if x.GetName()
in exclusionList:
769 ROOT.SetOwnership(x,
False)
770 detElements[x.GetName()] = x
777 ROOT.SetOwnership(swap,
False)
778 detElements[geometry_from_file.SWAP_NAME] = swap