FairShip
Loading...
Searching...
No Matches
ShipMuonShield.cxx
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
3// Collaboration
4
5#include "ShipMuonShield.h"
6
7#include <algorithm> // for std::ranges::copy
8#include <iterator> // for std::back_inserter
9
10#include "FairLogger.h"
11#include "ShipCavernLayout.h"
12#include "ShipGeoUtil.h"
13#include "ShipUnit.h"
14#include "TGeoBBox.h"
15#include "TGeoCompositeShape.h"
16#include "TGeoManager.h"
17#include "TGeoMatrix.h"
18#include "TString.h" // for TString
19
20using ShipUnit::m;
21
23ShipMuonShield::ShipMuonShield() : FairModule("ShipMuonShield", "") {}
24
25ShipMuonShield::ShipMuonShield(std::vector<double> in_params, size_t n_magnets,
26 Double_t z)
27 : FairModule("MuonShield", "ShipMuonShield") {
28 LOG(debug) << " Function ShipMuonShield MS ";
29 std::ranges::copy(in_params, std::back_inserter(shield_params));
30 nMagnets = n_magnets;
31
33}
34
35void ShipMuonShield::SetSNDSpace(Bool_t hole, Double_t hole_dx,
36 Double_t hole_dy, Int_t first_magnet,
37 Int_t last_magnet) {
38 snd_hole = hole;
39 snd_first_magnet = first_magnet;
40 snd_last_magnet = last_magnet;
41 snd_hole_dx = hole_dx;
42 snd_hole_dy = hole_dy;
43}
44
45void ShipMuonShield::CreateMagnet(const TString& magnetName, TGeoMedium* medium,
46 TGeoVolume* tShield, Double_t dX, Double_t dY,
47 Double_t dZ, Double_t Z, Bool_t withSNDHole) {
48 LOG(debug) << " Create a magnet of the MS ";
49 TGeoVolume* magVol = nullptr;
50
51 if (withSNDHole) {
52 // Solid box minus a void box along the beam axis
53 TString shapeName = magnetName + "_shape";
54 new TGeoBBox(shapeName, dX, dY, dZ);
55
56 // Void 0.1 mm smaller than the hole transversally (anti-overlap with the
57 // SND) and longer than the magnet, so that no faces coincide
58 constexpr double eps = 0.01;
59 TString voidName = magnetName + "_void";
60 new TGeoBBox(voidName, snd_hole_dx - eps, snd_hole_dy - eps, dZ + eps);
61
62 auto* compShape = new TGeoCompositeShape(magnetName + "_comp",
63 shapeName + " - " + voidName);
64 magVol = new TGeoVolume(magnetName, compShape, medium);
65 } else {
66 magVol = gGeoManager->MakeBox(magnetName, medium, dX, dY, dZ);
67 }
68
69 magVol->SetLineColor(45);
70 tShield->AddNode(magVol, 1, new TGeoTranslation(0, 0, Z));
71}
72
74 LOG(debug) << " Construct Geometry of the MS ";
75 // A list in the old 15-value format also divides evenly by nParams, so
76 // check the size against the expected number of magnets. At least one
77 // magnet is needed, since the absorber is sized from the first one.
78 if (nMagnets == 0 || shield_params.size() != nMagnets * nParams) {
79 LOG(fatal) << "ShipMuonShield: expected " << nMagnets << " magnets x "
80 << nParams << " parameters, got " << shield_params.size()
81 << " values. Is the geometry from an older version?";
82 }
83 TGeoVolume* top = gGeoManager->GetTopVolume();
84 TGeoVolume* tShield = new TGeoVolumeAssembly("MuonShieldArea");
85 ShipGeo::InitMedium("iron");
86 TGeoMedium* iron = gGeoManager->GetMedium("iron");
87
88 bool absorber_magnet = false;
90 for (size_t nM = 0; nM < nMagnets; ++nM) {
91 const Double_t Zgap = shield_params[nM * nParams + 0];
92 const Double_t dZ = shield_params[nM * nParams + 1];
93 const Double_t dX = shield_params[nM * nParams + 2];
94 const Double_t dY = shield_params[nM * nParams + 3];
95 // Subsequent magnets are placed relative to the previous one
96 if (nM > 0) {
97 Z += shield_params[(nM - 1) * nParams + 1];
98 }
99 Z += Zgap + dZ;
100
101 TString name = nM == 0 ? TString("MagnAbsorb") : Form("Magn%zu", nM);
102 LOG(debug) << "Magnet " << name << ": Zgap=" << Zgap << ", dZ=" << dZ
103 << ", dX=" << dX << ", dY=" << dY << ", Z=" << Z;
104 if (dZ < 1e-5 || dX == 0) {
105 continue;
106 }
107 const auto i = static_cast<Int_t>(nM);
108 CreateMagnet(name, iron, tShield, dX, dY, dZ, Z,
110 absorber_magnet |= nM == 0;
111 }
112
113 // Place in origin of SHiP coordinate system as subnodes placed correctly
114 top->AddNode(tShield, 1);
115
116 Double_t absorber_offset = shield_params[0];
117 Double_t absorber_half_length = shield_params[1];
118
119 // Absorber: iron filling the TCC8 cross-section around the hadron stopper
120
125 TGeoShape* absorberShape = new TGeoBBox(
126 "absorber", (kTCC8RightX - kTCC8LeftX) / 2. - 0.002 * m,
127 (kTCC8CeilingY - kTCC8FloorY) / 2., absorber_half_length - 0.002 * m);
128 Double_t shift_x = (kTCC8RightX + kTCC8LeftX) / 2.;
129 Double_t shift_y = (kTCC8CeilingY + kTCC8FloorY) / 2.;
130
131 if (absorber_magnet) {
132 // Leave room for the magnet of the hadron absorber
133 auto* absorber_shift =
134 new TGeoTranslation("absorber_shift", shift_x, shift_y, 0);
135 absorber_shift->RegisterYourself();
136 absorberShape = new TGeoCompositeShape(
137 "Absorber", "absorber:absorber_shift - MagnAbsorb");
138 shift_x = shift_y = 0;
139 }
140
141 TGeoVolume* absorber = new TGeoVolume("AbsorberVol", absorberShape, iron);
142 absorber->SetLineColor(42); // brown / light red
143 tShield->AddNode(
144 absorber, 1,
145 new TGeoTranslation(shift_x, shift_y,
146 z_end_of_proximity_shielding + absorber_half_length +
147 absorber_offset)); // - Passive?
148}
const Int_t debug
constexpr Double_t m
void ConstructGeometry() override
Double_t z_end_of_proximity_shielding
Double_t snd_hole_dy
std::vector< Double_t > shield_params
~ShipMuonShield() override
static constexpr size_t nParams
void SetSNDSpace(Bool_t hole, Double_t hole_dx, Double_t hole_dy, Int_t first_magnet, Int_t last_magnet)
void CreateMagnet(const TString &magnetName, TGeoMedium *medium, TGeoVolume *tShield, Double_t dX, Double_t dY, Double_t dZ, Double_t Z, Bool_t withSNDHole)
Double_t snd_hole_dx
const Double_t kTCC8RightX
const Double_t kTCC8LeftX
const Double_t kTCC8CeilingY
const Double_t kTCC8FloorY
Int_t InitMedium(const char *name)
Definition ShipGeoUtil.h:22
constexpr double m
Definition ShipUnit.h:24