Skip to content

Commit

Permalink
feat: generalized conversion of FullPhysicalVolume (acts-project#3585)
Browse files Browse the repository at this point in the history
This PR generalizes the `GeoModelDetectorObjectFactory` by enabling the conversion of `GeoFullPhysicalVolume` to `DetectorVolume` in the case where they don't have any subvolumes. This feature is not required for ATLAS application as far as I know, but is still nice to have for generality's sake and makes the testing an prototyping of geometries more intuitive.
  • Loading branch information
Berggren-Jonas authored Sep 16, 2024
1 parent e590140 commit 5a420db
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 55 deletions.
53 changes: 26 additions & 27 deletions Plugins/GeoModel/src/GeoModelDetectorObjectFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,38 +155,37 @@ void Acts::GeoModelDetectorObjectFactory::convertFpv(
// get children
std::vector<GeoChildNodeWithTrf> subvolumes =
getChildrenWithRef(physVol, false);
if (!subvolumes.empty()) {
// vector containing all subvolumes to be converted to surfaces
std::vector<GeoChildNodeWithTrf> surfaces = findAllSubVolumes(physVol);
std::vector<GeoModelSensitiveSurface> sensitives;

for (const auto &surface : surfaces) {
const Transform3 &transform =
fpv->getAbsoluteTransform() * surface.transform;
convertSensitive(surface.volume, transform, sensitives);
}
cache.sensitiveSurfaces.insert(cache.sensitiveSurfaces.end(),
sensitives.begin(), sensitives.end());
// TODO maybe put that down after an surface conversions
if (convertBox(name)) {
const GeoLogVol *logVol =
physVol->getLogVol(); // get logVol for the shape of the volume
const GeoShape *shape = logVol->getShape(); // get shape
const Acts::Transform3 &fpvtransform = fpv->getAbsoluteTransform(nullptr);

// convert bounding boxes with surfaces inside
std::shared_ptr<Experimental::DetectorVolume> box =
Acts::GeoModel::convertDetectorVolume(gctx, *shape, name,
fpvtransform, sensitives);
cache.boundingBoxes.push_back(box);
}
} else {
// vector containing all subvolumes to be converted to surfaces
std::vector<GeoChildNodeWithTrf> surfaces = findAllSubVolumes(physVol);
std::vector<GeoModelSensitiveSurface> sensitives;

for (const auto &surface : surfaces) {
const Transform3 &transform =
fpv->getAbsoluteTransform() * surface.transform;
convertSensitive(surface.volume, transform, sensitives);
}
cache.sensitiveSurfaces.insert(cache.sensitiveSurfaces.end(),
sensitives.begin(), sensitives.end());
if (convertBox(name)) {
const GeoLogVol *logVol =
physVol->getLogVol(); // get logVol for the shape of the volume
const GeoShape *shape = logVol->getShape(); // get shape
const Acts::Transform3 &fpvtransform = fpv->getAbsoluteTransform(nullptr);

// convert bounding boxes with surfaces inside
std::shared_ptr<Experimental::DetectorVolume> box =
Acts::GeoModel::convertDetectorVolume(gctx, *shape, name, fpvtransform,
sensitives);
cache.boundingBoxes.push_back(box);
}
// If fpv has no subs and should not be converted to volume convert to surface
else if (subvolumes.empty()) {
// convert fpvs to surfaces
const Transform3 &transform = fpv->getAbsoluteTransform();
convertSensitive(fpv, transform, cache.sensitiveSurfaces);
}
}
// lambda to determine if object fits query
// function to determine if object fits query
bool Acts::GeoModelDetectorObjectFactory::matches(const std::string &name,
const PVConstLink &physvol) {
if (m_cfg.nameList.empty() && m_cfg.materialList.empty()) {
Expand Down
7 changes: 0 additions & 7 deletions Tests/UnitTests/Plugins/GeoModel/GeoBoxToVolumeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ BOOST_AUTO_TEST_CASE(GeoBoxToSensitiveConversion) {
auto logBox = new GeoLogVol("Box", box, material);
auto physBox = make_intrusive<GeoFullPhysVol>(logBox);

// add subvolume since converter needs that to convert fpv to volume
auto sBox = new GeoBox(50, 20, 10);
auto slogBox = new GeoLogVol("Box", sBox, material);
auto sphysBox = make_intrusive<GeoFullPhysVol>(slogBox);

physBox->add(sphysBox);

// create pars for conversion
Acts::GeoModelDetectorObjectFactory::Config gmConfig;
gmConfig.convertBox = {"Box"};
Expand Down
2 changes: 0 additions & 2 deletions Tests/UnitTests/Plugins/GeoModel/GeoDetectorObjectTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ struct GeoDims {
std::vector<std::vector<double>> trapVerts;
std::vector<double> trapHls;
std::vector<std::vector<double>> polyVerts;
// double poly_z;
};
void test(const Acts::GeoModelDetectorObjectFactory::Cache& cache,
GeoModelDetObj::GeoDims geoDims) {
Expand Down Expand Up @@ -101,7 +100,6 @@ GeoGeometry constructGeoModel() {
geoDims.polyVerts = {{-60, -50}, {60, -50}, {153, 0},
{123, 50}, {-123, 50}, {-153, 0}};
geoDims.tube = {5, 6, 100};
// geoDims.poly_z = 2;
geoDims.trapHls = {
fabs(geoDims.trapVerts[0][0] - geoDims.trapVerts[1][0]) / 2,
fabs(geoDims.trapVerts[2][0] - geoDims.trapVerts[3][0]) / 2,
Expand Down
8 changes: 0 additions & 8 deletions Tests/UnitTests/Plugins/GeoModel/GeoTrdToVolumeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,11 @@ BOOST_AUTO_TEST_CASE(GeoTrdToVolumeConversion) {
auto logTrd = new GeoLogVol("Trd", trd, material);
auto physTrd = make_intrusive<GeoFullPhysVol>(logTrd);

// add subvolume since converter needs that to convert fpv to volume
auto strd = new GeoTrd(1, 1, 25, 40, 30);
auto slogTrd = new GeoLogVol("Trd", strd, material);
auto sphysTrd = make_intrusive<GeoFullPhysVol>(slogTrd);

// this should produce an error while converting
auto errTrd = new GeoTrd(2, 3, 25, 40, 30);
auto errLogTrd = new GeoLogVol("Trd", errTrd, material);
auto errPhysTrd = make_intrusive<GeoFullPhysVol>(errLogTrd);

physTrd->add(sphysTrd);
errPhysTrd->add(sphysTrd);

// create pars for conversion
Acts::GeoModelDetectorObjectFactory::Config gmConfig;
gmConfig.convertBox = {"Trd"};
Expand Down
15 changes: 4 additions & 11 deletions Tests/UnitTests/Plugins/GeoModel/GeoTubeToVolumeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

#include <boost/test/unit_test.hpp>

// switching format off to avoid conflicting declaration in GeoModel
// needed until Acts GeoModel bumps to 6.5
//clang-format off
// In order to avoid conflicts with declarations in Geomodel that is fixed in
// v3.5
// clang-formal off
#include "Acts/Plugins/GeoModel/GeoModelDetectorObjectFactory.hpp"
//clang-format on
// clang-formal on
#include "Acts/Geometry/CylinderVolumeBounds.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Plugins/GeoModel/GeoModelConverters.hpp"
Expand Down Expand Up @@ -41,13 +41,6 @@ BOOST_AUTO_TEST_CASE(GeoBoxToSensitiveConversion) {
auto logTube = new GeoLogVol("Tube", tube, material);
auto physTube = make_intrusive<GeoFullPhysVol>(logTube);

// add subvolume since converter needs that to convert fpv to volume
auto sTube = new GeoTube(50, 20, 10);
auto slogTube = new GeoLogVol("Tube", sTube, material);
auto sphysTube = make_intrusive<GeoFullPhysVol>(slogTube);

physTube->add(sphysTube);

// create pars for conversion
Acts::GeoModelDetectorObjectFactory::Config gmConfig;
gmConfig.convertBox = {"Tube"};
Expand Down

0 comments on commit 5a420db

Please sign in to comment.