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 """
514
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
528
530
531
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
538
539 if geofile:
540
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
552
553
554
556
557
558 run.SetMaterials("media.geo")
559
560
561
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
593 if ship_geo.SND:
594 for design in ship_geo.SND_design:
595 if design == 2:
596
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
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
622 if 2 in getattr(ship_geo, "SND_design", []):
623
624
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
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
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"):
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
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),
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
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)
753
754 exclusionList: list[str] = []
755
756
757
758
759
760
761 detElements: dict[str, Any] = {}
762 if geofile:
765 for x in detectorList:
766 if x.GetName() in exclusionList:
767 continue
768 run.AddModule(x)
769 ROOT.SetOwnership(x, False)
770 detElements[x.GetName()] = x
771 if geofile:
772
773
774
776 run.AddModule(swap)
777 ROOT.SetOwnership(swap, False)
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)