53 std::shared_ptr<Acts::Experimental::DetectorVolume>
56 if (g4World ==
nullptr) {
57 throw std::invalid_argument(
"MockupSector: No g4World initialized");
65 g4WorldConfig.name =
"Chamber";
66 g4WorldConfig.g4World = g4World;
70 std::make_shared<Acts::Geant4PhysicalVolumeSelectors::NameSelector>(
73 std::make_shared<Acts::Geant4PhysicalVolumeSelectors::NameSelector>(
77 g4SurfaceOptions.sensitiveSurfaceSelector = g4Sensitive;
78 g4SurfaceOptions.passiveSurfaceSelector = g4Passive;
79 g4WorldConfig.g4SurfaceOptions = g4SurfaceOptions;
83 auto [
detector, surfaces, detectorElements] =
87 std::vector<std::shared_ptr<Acts::Surface>> strawSurfaces = {};
89 std::array<std::pair<float, float>, 3>
min_max;
90 std::fill(min_max.begin(), min_max.end(),
91 std::make_pair<float, float>(std::numeric_limits<float>::max(),
92 -std::numeric_limits<float>::max()));
95 for (
auto& detectorElement : detectorElements) {
99 g4conv.forcedType = Acts::Surface::SurfaceType::Straw;
100 auto g4ConvSurf = g4conv.Geant4PhysicalVolumeConverter::surface(
101 detectorElement->g4PhysicalVolume(),
102 detectorElement->transform(context));
104 strawSurfaces.push_back(g4ConvSurf);
107 std::min(min_max[0].first, (
float)g4ConvSurf->center(context).x());
109 std::max(min_max[0].second, (
float)g4ConvSurf->center(context).x());
112 std::min(min_max[1].first, (
float)g4ConvSurf->center(context).y());
114 std::max(min_max[1].second, (
float)g4ConvSurf->center(context).y());
117 std::min(min_max[2].first, (
float)g4ConvSurf->center(context).z());
119 std::max(min_max[2].second, (
float)g4ConvSurf->center(context).z());
123 float radius = strawSurfaces.front()->bounds().values()[0];
125 Acts::Vector3 minValues = {min_max[0].first, min_max[1].first,
127 Acts::Vector3 maxValues = {min_max[0].second, min_max[1].second,
131 strawSurfaces.front()->bounds().values()[1] + mCfg.toleranceOverlap;
133 0.5 * ((maxValues.y() + radius) - (minValues.y() - radius)) +
134 mCfg.toleranceOverlap;
136 0.5 * ((maxValues.z() + radius) - (minValues.z() - radius)) +
137 mCfg.toleranceOverlap;
139 auto detectorVolumeBounds =
140 std::make_shared<Acts::CuboidVolumeBounds>(
hx,
hy,
hz);
142 Acts::Vector3 chamber_position = {(maxValues.x() + minValues.x()) / 2,
143 (maxValues.y() + minValues.y()) / 2,
144 (maxValues.z() + minValues.z()) / 2};
151 std::move(detectorVolumeBounds), strawSurfaces,
152 std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>>{},
156 return detectorVolume;
159 std::shared_ptr<Acts::Experimental::DetectorVolume>
161 std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>>
163 if (mCfg.NumberOfSectors > maxNumberOfSectors) {
164 throw std::invalid_argument(
"MockupSector:Number of max sectors exceeded");
172 std::sort(detVolumes.begin(), detVolumes.end(),
173 [](
const auto& detVol1,
const auto& detVol2) {
174 return detVol1->center().y() < detVol2->center().y();
177 auto xA = detVolumes.back()->center().x() +
178 detVolumes.back()->volumeBounds().values()[0];
179 auto yA = detVolumes.back()->center().y() -
180 detVolumes.back()->volumeBounds().values()[1];
181 auto zA = detVolumes.back()->center().z();
183 auto xB = detVolumes.back()->center().x() -
184 detVolumes.back()->volumeBounds().values()[0];
185 auto yB = detVolumes.back()->center().y() -
186 detVolumes.back()->volumeBounds().values()[1];
187 auto zB = detVolumes.back()->center().z();
195 auto sectorAngle = M_PI;
197 auto halfPhi = M_PI / mCfg.NumberOfSectors;
199 if (mCfg.NumberOfSectors == 1) {
200 halfPhi = (phiB - phiA) / 2;
201 sectorAngle = halfPhi;
204 const int detVolumesSize = detVolumes.size();
206 std::vector<float> rmins(detVolumesSize);
207 std::vector<float> rmaxs(detVolumesSize);
208 std::vector<float> halfZ(detVolumesSize);
209 std::vector<std::shared_ptr<Acts::CylinderVolumeBounds>>
210 cylinderVolumesBounds(detVolumesSize);
212 for (
int i = 0;
i < detVolumesSize;
i++) {
213 const auto& detVol = detVolumes[
i];
214 rmins[
i] = detVol->center().y() - detVol->volumeBounds().values()[1] -
215 mCfg.toleranceOverlap;
216 rmaxs[
i] = std::sqrt(std::pow(detVol->volumeBounds().values()[0], 2) +
217 std::pow(detVol->center().y() +
218 detVol->volumeBounds().values()[1],
220 mCfg.toleranceOverlap;
221 halfZ[
i] = detVol->volumeBounds().values()[2];
223 cylinderVolumesBounds[
i] = std::make_shared<Acts::CylinderVolumeBounds>(
224 rmins[
i], rmaxs[
i], halfZ[
i], sectorAngle);
235 std::vector<std::shared_ptr<Acts::Surface>> shiftedSurfaces = {};
238 std::vector<std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>>>
239 chambersOfSectors(detVolumesSize);
241 std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>>
242 detectorCylinderVolumesOfSector = {};
244 for (
int i = 0;
i < mCfg.NumberOfSectors;
i++) {
247 for (
int itr = 0; itr < detVolumesSize; itr++) {
248 const auto& detVol = detVolumes[itr];
253 for (
auto& detSurf : detVol->surfaces()) {
254 auto shift_surf = Acts::Transform3::Identity() * rotation;
257 auto strawSurfaceObject = Acts::Surface::makeShared<Acts::StrawSurface>(
259 detSurf->bounds().values()[0], detSurf->bounds().values()[1]);
261 auto copiedTransformStrawSurface =
262 Acts::Surface::makeShared<Acts::StrawSurface>(
265 shiftedSurfaces.push_back(copiedTransformStrawSurface);
269 auto bounds = std::make_unique<Acts::CuboidVolumeBounds>(
270 detVol->volumeBounds().values()[0],
271 detVol->volumeBounds().values()[1],
272 detVol->volumeBounds().values()[2]);
274 auto detectorVolumeSec =
280 std::shared_ptr<Acts::Experimental::DetectorVolume>>{},
284 chambersOfSectors[itr].push_back(detectorVolumeSec);
286 shiftedSurfaces.clear();
292 for (std::size_t
i = 0;
i < cylinderVolumesBounds.size(); ++
i) {
293 detectorCylinderVolumesOfSector.push_back(
298 std::vector<std::shared_ptr<Acts::Surface>>{}, chambersOfSectors[
i],
304 auto cylinderVolumesBoundsOfMother =
305 std::make_shared<Acts::CylinderVolumeBounds>(
306 rmins.front(), rmaxs.back(),
307 *std::max_element(halfZ.begin(), halfZ.end()), sectorAngle);
313 std::move(cylinderVolumesBoundsOfMother),
314 std::vector<std::shared_ptr<Acts::Surface>>{},
318 return detectorVolume;
322 const std::shared_ptr<Acts::Experimental::DetectorVolume>&
331 Acts::Transform3::Identity(), sConfig);
333 objSector.
write(nameObjFile);