92 {
93 TGeoVolume*
top = gGeoManager->GetTopVolume();
94
96 TGeoMedium* scintillator = gGeoManager->GetMedium("Scintillator");
97 if (!scintillator) {
98 Fatal("ConstructGeometry", "Medium 'Scintillator' not found.");
99 }
101 Fatal("ConstructGeometry", "No regions loaded from the UBT detector map.");
102 }
104 Fatal("ConstructGeometry", "UBT box dimensions not set.");
105 }
106
107 fDetector =
new TGeoVolumeAssembly(
"Upstream_Tagger");
108
109 std::map<Double_t, Int_t> regionsPerTileSize;
110
111
112
113
114 using ShapeKey = std::tuple<Long64_t, Long64_t, Long64_t, Long64_t>;
115 const auto um = [](Double_t length) {
return std::llround(length * 1.0e4); };
116 std::map<ShapeKey, TGeoVolume*> volumes;
118 if (region.sizeX <= 0. || region.sizeY <= 0.) {
119 Fatal("ConstructGeometry", "UBT region %d has a non-positive size.",
120 region.id);
121 }
122 if (region.thickness <= 0. || region.thickness >
fEnvelopeZ) {
123 Fatal("ConstructGeometry",
124 "UBT region %d: the thickness %g cm of its %g cm tiles is not in "
125 "(0, %g] cm, the space reserved for the UBT.",
126 region.id, region.thickness, region.constituentTileSize,
128 }
129 if (std::abs(region.x -
fCenterX) + region.sizeX / 2. >
fSizeX / 2. ||
130 std::abs(region.y -
fCenterY) + region.sizeY / 2. >
fSizeY / 2.) {
131 Fatal("ConstructGeometry", "UBT region %d lies outside the UBT box.",
132 region.id);
133 }
134 const ShapeKey shape{
um(region.sizeX),
um(region.sizeY),
135 um(region.thickness),
um(region.constituentTileSize)};
136 TGeoVolume*& regionVolume = volumes[shape];
137 if (!regionVolume) {
138
139
140 const TString volumeName = TString::Format(
141 "UpstreamTaggerRegion_%dcm_%zu",
142 static_cast<Int_t>(region.constituentTileSize), volumes.size() - 1);
143 regionVolume =
144 gGeoManager->MakeBox(volumeName, scintillator, region.sizeX / 2.,
145 region.sizeY / 2., region.thickness / 2.);
146
147 regionVolume->SetLineColor(
148 kBlue - static_cast<Int_t>(region.constituentTileSize));
149 AddSensitiveVolume(regionVolume);
150 }
151 fDetector->AddNode(regionVolume, region.id,
152 new TGeoTranslation(region.x, region.y, 0.));
153 ++regionsPerTileSize[region.constituentTileSize];
154 }
155
157 cout <<
" Z Position (Upstream Tagger) " <<
det_zPos <<
", "
158 <<
fRegions.size() <<
" mapped regions (";
159 for (auto it = regionsPerTileSize.begin(); it != regionsPerTileSize.end();
160 ++it) {
161 cout << (it == regionsPerTileSize.begin() ? "" : ", ") << it->second
162 << " with " << it->first << " cm tiles";
163 }
164 cout << ") in " << volumes.size() << " region shapes" << endl;
165}
Double_t fSizeX
coarse regions loaded from detector map
Double_t fCenterY
detector centre x
Double_t fCenterX
detector height
Double_t fSizeY
detector width
Double_t fEnvelopeZ
detector centre y
Int_t InitMedium(const char *name)
z-position of the active tile plane