From 5c6970641e81c7cfb9c092b6989cfe29a346b930 Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Mon, 3 Jun 2024 08:14:13 -0500 Subject: [PATCH 01/29] Changes to fix finding geomodel on system and first round of converter --- CMakeLists.txt | 4 +- Plugins/CMakeLists.txt | 1 + Plugins/GeoModel/CMakeLists.txt | 22 ++++ .../Plugins/GeoModel/GeoModelToDetVol.hpp | 21 +++ Plugins/GeoModel/src/GeoModelToDetVol.cpp | 122 ++++++++++++++++++ cmake/ActsConfig.cmake.in | 3 + 6 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 Plugins/GeoModel/CMakeLists.txt create mode 100644 Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp create mode 100644 Plugins/GeoModel/src/GeoModelToDetVol.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index df1545f8e77..3781ba4cea0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,7 +188,7 @@ set(_acts_autodiff_version 0.6) set(_acts_boost_version 1.71.0) set(_acts_dd4hep_version 1.21) set(_acts_edm4hep_version 0.7) -set(_acts_geomodel_version 4.6.0) +set(_acts_geomodel_version 5.6.0) set(_acts_podio_version 0.16) set(_acts_doxygen_version 1.9.4) set(_acts_eigen3_version 3.3.7) @@ -301,7 +301,7 @@ endif() if(ACTS_BUILD_PLUGIN_GEOMODEL) if(ACTS_USE_SYSTEM_GEOMODEL) message(STATUS "Using system installation of GeoModel") - find_package(GeoModel ${_acts_geomodel_version} REQUIRED CONFIG) + find_package(GeoModelCore ${_acts_geomodel_version} COMPONENTS GeoModelKernel REQUIRED CONFIG) else() add_subdirectory(thirdparty/GeoModel) endif() diff --git a/Plugins/CMakeLists.txt b/Plugins/CMakeLists.txt index 6bae783f9d5..495eb416160 100644 --- a/Plugins/CMakeLists.txt +++ b/Plugins/CMakeLists.txt @@ -6,6 +6,7 @@ add_component_if(Cuda PluginCuda ACTS_BUILD_PLUGIN_CUDA) add_component_if(FpeMonitoring PluginFpeMonitoring ACTS_BUILD_PLUGIN_FPEMON) add_component_if(Geant4 PluginGeant4 ACTS_BUILD_PLUGIN_GEANT4) add_component_if(Identification PluginIdentification ACTS_BUILD_PLUGIN_IDENTIFICATION) +add_component_if(GeoModel PluginGeoModel ACTS_BUILD_PLUGIN_GEOMODEL) add_component_if(Json PluginJson ACTS_BUILD_PLUGIN_JSON) add_component_if(Legacy PluginLegacy ACTS_BUILD_PLUGIN_LEGACY) add_component_if(Onnx PluginOnnx ACTS_BUILD_PLUGIN_ONNX) diff --git a/Plugins/GeoModel/CMakeLists.txt b/Plugins/GeoModel/CMakeLists.txt new file mode 100644 index 00000000000..2c6c9b4bc6e --- /dev/null +++ b/Plugins/GeoModel/CMakeLists.txt @@ -0,0 +1,22 @@ +include(FetchContent) +add_library( + ActsPluginGeoModel SHARED + src/GeoModelToDetVol.cpp) +target_include_directories( + ActsPluginGeoModel + PUBLIC + $ + $) +target_include_directories( + ActsPluginGeoModel + SYSTEM PUBLIC) +target_link_libraries( + ActsPluginGeoModel + PUBLIC ActsCore GeoModelCore::GeoModelKernel) +install( + TARGETS ActsPluginGeoModel + EXPORT ActsPluginGeoModelTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install( + DIRECTORY include/Acts + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) \ No newline at end of file diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp new file mode 100644 index 00000000000..5cb1c9fd164 --- /dev/null +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp @@ -0,0 +1,21 @@ +#include "Acts/Geometry/CylinderVolumeBounds.hpp" +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "Acts/Detector/GeometryIdGenerator.hpp" +#include "Acts/Geometry/TrapezoidVolumeBounds.hpp" +#include "Acts/Geometry/CutoutCylinderVolumeBounds.hpp" +#include "Acts/Geometry/GeometryContext.hpp" +#include "Acts/Geometry/CuboidVolumeBounds.hpp" +#include "Acts/Detector/DetectorVolume.hpp" + +#include "GeoModelKernel/GeoShape.h" + +namespace Acts { + namespace GeoModelToDetVol { + /// @brief Convert a GeoModel shape to a DetectorVolume + /// + /// @param shape the GeoModel shape + /// @param transform the transform to be applied + /// @return the DetectorVolume + std::shared_ptr convert(const GeometryContext& context, const GeoShape& shape, const std::string& name, const Transform3& transform); + } +} \ No newline at end of file diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp new file mode 100644 index 00000000000..86326856663 --- /dev/null +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -0,0 +1,122 @@ +#include "Acts/Detector/PortalGenerators.hpp" +#include "Acts/Navigation/SurfaceCandidatesUpdaters.hpp" +#include "Acts/Plugins/GeoModel/GeoModelToDetVol.hpp" + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Acts { + namespace GeoModelToDetVol { + std::shared_ptr convert(const GeometryContext& context, const GeoShape& shape, const std::string& name, const Transform3& transform) { + auto portalGenerator = Experimental::defaultPortalGenerator(); + if (shape.typeID() == GeoTube::getClassTypeID()) { + const GeoTube& tube = dynamic_cast(shape); + std::shared_ptr bounds = std::make_shared(tube.getRMin(), tube.getRMax(), tube.getZHalfLength()); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoTubs::getClassTypeID()) { + const GeoTubs& tubs = dynamic_cast(shape); + std::shared_ptr bounds = std::make_shared(tubs.getRMin(), tubs.getRMax(), tubs.getZHalfLength(), tubs.getDPhi()/ 2); + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(Eigen::AngleAxisd(tubs.getSPhi() + 0.5 * tubs.getDPhi(), Acts::Vector3::UnitZ())); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoBox::getClassTypeID()) { + const GeoBox& box = dynamic_cast(shape); + std::shared_ptr bounds = std::make_shared(box.getXHalfLength(), box.getYHalfLength(), box.getZHalfLength()); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoSimplePolygonBrep::getClassTypeID()) { + double xmin{0}; + double xmax{0}; + double ymin{0}; + double ymax{0}; + double zmin{0}; + double zmax{0}; + const GeoSimplePolygonBrep& brep = dynamic_cast(shape); + brep.extent(xmin, ymin, zmin, xmax, ymax, zmax); + std::shared_ptr bounds = std::make_shared(xmax-xmin, ymax-ymin, zmax-zmin); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoTrd::getClassTypeID()){ + const GeoTrd& trd = dynamic_cast(shape); + float x1 = trd.getXHalfLength1(); + float x2 = trd.getXHalfLength2(); + float y1 = trd.getYHalfLength1(); + float y2 = trd.getYHalfLength2(); + float z = trd.getZHalfLength(); + if (y1 == y2){ + if (x1 <= x2){ + //y axis in ACTS is z axis in geomodel + std::shared_ptr bounds = std::make_shared(x1,x2,z,y1); + auto rotationAngle = M_PI/2; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); + } else { + std::shared_ptr bounds = std::make_shared(x2,x1,z,y1); + auto rotationAngle = M_PI; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitY()) * Eigen::AngleAxisd(rotationAngle ,Acts::Vector3::UnitZ())); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); + } + } else if(x1 == x2){ + if(y1 < y2) { + std::shared_ptr bounds = std::make_shared(y1,y2,z,x1); + auto rotationAngle = M_PI/2; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ()) * Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); + } else { + std::shared_ptr bounds = std::make_shared(y2,y1,z,x1); + auto rotationAngle = M_PI; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX()) * Eigen::AngleAxisd(rotationAngle/2, Acts::Vector3::UnitZ()) * Eigen::AngleAxisd(rotationAngle/2, Acts::Vector3::UnitX())); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); + } + } else{ + throw std::runtime_error("FATAL: Translating GeoTrd to ACTS failed"); + } + } else if (shape.typeID() == GeoShapeUnion::getClassTypeID()){ + double xmin{0}; + double xmax{0}; + double ymin{0}; + double ymax{0}; + double zmin{0}; + double zmax{0}; + const GeoShapeUnion& unionShape = dynamic_cast(shape); + unionShape.extent(xmin, ymin, zmin, xmax, ymax, zmax); + std::shared_ptr bounds = std::make_shared(xmax-xmin, ymax-ymin, zmax-zmin); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoShapeSubtraction::getClassTypeID()) { + //Go down the left side (opA) of the subtraction until we reach a normal shape + const GeoShapeSubtraction& subtractionShape = dynamic_cast(shape); + const GeoShape* shapeA = subtractionShape.getOpA(); + return convert(context, *shapeA, name, transform); + } else if (shape.typeID() == GeoPcon::getClassTypeID()) { + //nothing + std::shared_ptr bounds = std::make_shared(1,1,1); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); + } + if (shape.typeID() == GeoShapeShift::getClassTypeID()) { + const GeoShapeShift& shiftShape = dynamic_cast(shape); + const GeoShape* shapeOp = shiftShape.getOp(); + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(transform.rotation()); + newTransform.translate(shiftShape.getX().translation()); + return convert(context, *shapeOp, name, newTransform); + } + throw std::runtime_error("Unknown shape type: " + shape.type()); + } + } +} \ No newline at end of file diff --git a/cmake/ActsConfig.cmake.in b/cmake/ActsConfig.cmake.in index b82fd8bf7a7..bc27ffb022f 100644 --- a/cmake/ActsConfig.cmake.in +++ b/cmake/ActsConfig.cmake.in @@ -67,6 +67,9 @@ endif() if(PluginTGeo IN_LIST Acts_COMPONENTS) find_dependency(ROOT @ROOT_VERSION@ CONFIG EXACT) endif() +if(PluginGeoModel IN_LIST Acts_COMPONENTS) + find_dependency(GeoModelCore @GeoModelCore_VERSION@ CONFIG EXACT) +endif() if(PluginActSVG IN_LIST Acts_COMPONENTS) find_dependency(actsvg @actsvg_VERSION@ CONFIG EXACT) endif() From daaf5b8ace331149576c981c4f9c9933f4ecf6b9 Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Fri, 7 Jun 2024 09:18:21 -0500 Subject: [PATCH 02/29] format changes --- .../Plugins/GeoModel/GeoModelToDetVol.hpp | 39 ++- Plugins/GeoModel/src/GeoModelToDetVol.cpp | 295 +++++++++++------- 2 files changed, 207 insertions(+), 127 deletions(-) diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp index 5cb1c9fd164..08a12d8bf97 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp @@ -1,21 +1,32 @@ -#include "Acts/Geometry/CylinderVolumeBounds.hpp" -#include "Acts/Geometry/GeometryIdentifier.hpp" +// This file is part of the Acts project. +// +// Copyright (C) 2024 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +#pragma once + +#include "Acts/Detector/DetectorVolume.hpp" #include "Acts/Detector/GeometryIdGenerator.hpp" -#include "Acts/Geometry/TrapezoidVolumeBounds.hpp" +#include "Acts/Geometry/CuboidVolumeBounds.hpp" #include "Acts/Geometry/CutoutCylinderVolumeBounds.hpp" +#include "Acts/Geometry/CylinderVolumeBounds.hpp" #include "Acts/Geometry/GeometryContext.hpp" -#include "Acts/Geometry/CuboidVolumeBounds.hpp" -#include "Acts/Detector/DetectorVolume.hpp" +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "Acts/Geometry/TrapezoidVolumeBounds.hpp" #include "GeoModelKernel/GeoShape.h" namespace Acts { - namespace GeoModelToDetVol { - /// @brief Convert a GeoModel shape to a DetectorVolume - /// - /// @param shape the GeoModel shape - /// @param transform the transform to be applied - /// @return the DetectorVolume - std::shared_ptr convert(const GeometryContext& context, const GeoShape& shape, const std::string& name, const Transform3& transform); - } -} \ No newline at end of file +namespace GeoModelToDetVol { +/// @brief Convert a GeoModel shape to a DetectorVolume +/// +/// @param shape the GeoModel shape +/// @param transform the transform to be applied +/// @return the DetectorVolume +std::shared_ptr convert( + const GeometryContext& context, const GeoShape& shape, + const std::string& name, const Transform3& transform); +} // namespace GeoModelToDetVol +} // namespace Acts diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp index 86326856663..1e772515166 100644 --- a/Plugins/GeoModel/src/GeoModelToDetVol.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -1,122 +1,191 @@ -#include "Acts/Detector/PortalGenerators.hpp" -#include "Acts/Navigation/SurfaceCandidatesUpdaters.hpp" +// This file is part of the Acts project. +// +// Copyright (C) 2024 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + #include "Acts/Plugins/GeoModel/GeoModelToDetVol.hpp" +#include "Acts/Detector/PortalGenerators.hpp" +#include "Acts/Navigation/SurfaceCandidatesUpdaters.hpp" -#include -#include -#include #include -#include -#include +#include #include #include -#include +#include +#include +#include +#include +#include namespace Acts { - namespace GeoModelToDetVol { - std::shared_ptr convert(const GeometryContext& context, const GeoShape& shape, const std::string& name, const Transform3& transform) { - auto portalGenerator = Experimental::defaultPortalGenerator(); - if (shape.typeID() == GeoTube::getClassTypeID()) { - const GeoTube& tube = dynamic_cast(shape); - std::shared_ptr bounds = std::make_shared(tube.getRMin(), tube.getRMax(), tube.getZHalfLength()); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); - } else if (shape.typeID() == GeoTubs::getClassTypeID()) { - const GeoTubs& tubs = dynamic_cast(shape); - std::shared_ptr bounds = std::make_shared(tubs.getRMin(), tubs.getRMax(), tubs.getZHalfLength(), tubs.getDPhi()/ 2); - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(Eigen::AngleAxisd(tubs.getSPhi() + 0.5 * tubs.getDPhi(), Acts::Vector3::UnitZ())); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); - } else if (shape.typeID() == GeoBox::getClassTypeID()) { - const GeoBox& box = dynamic_cast(shape); - std::shared_ptr bounds = std::make_shared(box.getXHalfLength(), box.getYHalfLength(), box.getZHalfLength()); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); - } else if (shape.typeID() == GeoSimplePolygonBrep::getClassTypeID()) { - double xmin{0}; - double xmax{0}; - double ymin{0}; - double ymax{0}; - double zmin{0}; - double zmax{0}; - const GeoSimplePolygonBrep& brep = dynamic_cast(shape); - brep.extent(xmin, ymin, zmin, xmax, ymax, zmax); - std::shared_ptr bounds = std::make_shared(xmax-xmin, ymax-ymin, zmax-zmin); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); - } else if (shape.typeID() == GeoTrd::getClassTypeID()){ - const GeoTrd& trd = dynamic_cast(shape); - float x1 = trd.getXHalfLength1(); - float x2 = trd.getXHalfLength2(); - float y1 = trd.getYHalfLength1(); - float y2 = trd.getYHalfLength2(); - float z = trd.getZHalfLength(); - if (y1 == y2){ - if (x1 <= x2){ - //y axis in ACTS is z axis in geomodel - std::shared_ptr bounds = std::make_shared(x1,x2,z,y1); - auto rotationAngle = M_PI/2; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); - } else { - std::shared_ptr bounds = std::make_shared(x2,x1,z,y1); - auto rotationAngle = M_PI; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitY()) * Eigen::AngleAxisd(rotationAngle ,Acts::Vector3::UnitZ())); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); - } - } else if(x1 == x2){ - if(y1 < y2) { - std::shared_ptr bounds = std::make_shared(y1,y2,z,x1); - auto rotationAngle = M_PI/2; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ()) * Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); - } else { - std::shared_ptr bounds = std::make_shared(y2,y1,z,x1); - auto rotationAngle = M_PI; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX()) * Eigen::AngleAxisd(rotationAngle/2, Acts::Vector3::UnitZ()) * Eigen::AngleAxisd(rotationAngle/2, Acts::Vector3::UnitX())); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); - } - } else{ - throw std::runtime_error("FATAL: Translating GeoTrd to ACTS failed"); - } - } else if (shape.typeID() == GeoShapeUnion::getClassTypeID()){ - double xmin{0}; - double xmax{0}; - double ymin{0}; - double ymax{0}; - double zmin{0}; - double zmax{0}; - const GeoShapeUnion& unionShape = dynamic_cast(shape); - unionShape.extent(xmin, ymin, zmin, xmax, ymax, zmax); - std::shared_ptr bounds = std::make_shared(xmax-xmin, ymax-ymin, zmax-zmin); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); - } else if (shape.typeID() == GeoShapeSubtraction::getClassTypeID()) { - //Go down the left side (opA) of the subtraction until we reach a normal shape - const GeoShapeSubtraction& subtractionShape = dynamic_cast(shape); - const GeoShape* shapeA = subtractionShape.getOpA(); - return convert(context, *shapeA, name, transform); - } else if (shape.typeID() == GeoPcon::getClassTypeID()) { - //nothing - std::shared_ptr bounds = std::make_shared(1,1,1); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); - } - if (shape.typeID() == GeoShapeShift::getClassTypeID()) { - const GeoShapeShift& shiftShape = dynamic_cast(shape); - const GeoShape* shapeOp = shiftShape.getOp(); - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation()); - newTransform.translate(shiftShape.getX().translation()); - return convert(context, *shapeOp, name, newTransform); - } - throw std::runtime_error("Unknown shape type: " + shape.type()); - } +namespace GeoModelToDetVol { +std::shared_ptr convert( + const GeometryContext& context, const GeoShape& shape, + const std::string& name, const Transform3& transform) { + auto portalGenerator = Experimental::defaultPortalAndSubPortalGenerator(); + if (shape.typeID() == GeoTube::getClassTypeID()) { + const GeoTube& tube = dynamic_cast(shape); + std::shared_ptr bounds = + std::make_shared(tube.getRMin(), tube.getRMax(), + tube.getZHalfLength()); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoTubs::getClassTypeID()) { + const GeoTubs& tubs = dynamic_cast(shape); + std::shared_ptr bounds = + std::make_shared(tubs.getRMin(), tubs.getRMax(), + tubs.getZHalfLength(), + tubs.getDPhi() / 2); + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(Eigen::AngleAxisd(tubs.getSPhi() + 0.5 * tubs.getDPhi(), + Acts::Vector3::UnitZ())); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoBox::getClassTypeID()) { + const GeoBox& box = dynamic_cast(shape); + std::shared_ptr bounds = + std::make_shared( + box.getXHalfLength(), box.getYHalfLength(), box.getZHalfLength()); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoSimplePolygonBrep::getClassTypeID()) { + // Will change this in the future + double xmin{0}; + double xmax{0}; + double ymin{0}; + double ymax{0}; + double zmin{0}; + double zmax{0}; + const GeoSimplePolygonBrep& brep = + dynamic_cast(shape); + brep.extent(xmin, ymin, zmin, xmax, ymax, zmax); + std::shared_ptr bounds = + std::make_shared(xmax - xmin, ymax - ymin, + zmax - zmin); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoTrd::getClassTypeID()) { + const GeoTrd& trd = dynamic_cast(shape); + float x1 = trd.getXHalfLength1(); + float x2 = trd.getXHalfLength2(); + float y1 = trd.getYHalfLength1(); + float y2 = trd.getYHalfLength2(); + float z = trd.getZHalfLength(); + if (y1 == y2) { + if (x1 <= x2) { + // y axis in ACTS is z axis in geomodel + std::shared_ptr bounds = + std::make_shared(x1, x2, z, y1); + auto rotationAngle = M_PI / 2; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate( + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortals()); + } else { + std::shared_ptr bounds = + std::make_shared(x2, x1, z, y1); + auto rotationAngle = M_PI; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate( + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitY()) * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ())); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortals()); + } + } else if (x1 == x2) { + if (y1 < y2) { + std::shared_ptr bounds = + std::make_shared(y1, y2, z, x1); + auto rotationAngle = M_PI / 2; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate( + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ()) * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortals()); + } else { + std::shared_ptr bounds = + std::make_shared(y2, y1, z, x1); + auto rotationAngle = M_PI; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate( + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX()) * + Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitZ()) * + Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitX())); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortals()); + } + } else { + throw std::runtime_error("FATAL: Translating GeoTrd to ACTS failed"); } -} \ No newline at end of file + } else if (shape.typeID() == GeoShapeUnion::getClassTypeID()) { + // Get the bounding box of the union + double xmin{0}; + double xmax{0}; + double ymin{0}; + double ymax{0}; + double zmin{0}; + double zmax{0}; + const GeoShapeUnion& unionShape = dynamic_cast(shape); + unionShape.extent(xmin, ymin, zmin, xmax, ymax, zmax); + std::shared_ptr bounds = + std::make_shared(xmax - xmin, ymax - ymin, + zmax - zmin); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoShapeSubtraction::getClassTypeID()) { + // Go down the left side (opA) of the subtraction until we reach a normal + // shape + const GeoShapeSubtraction& subtractionShape = + dynamic_cast(shape); + const GeoShape* shapeA = subtractionShape.getOpA(); + return convert(context, *shapeA, name, transform); + } else if (shape.typeID() == GeoPcon::getClassTypeID()) { + // Will change in future, get bounding box for now + double xmin{0}; + double xmax{0}; + double ymin{0}; + double ymax{0}; + double zmin{0}; + double zmax{0}; + const GeoPcon& pcon = dynamic_cast(shape); + pcon.extent(xmin, ymin, zmin, xmax, ymax, zmax); + std::shared_ptr bounds = + std::make_shared(xmax - xmin, ymax - ymin, + zmax - zmin); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortals()); + } + if (shape.typeID() == GeoShapeShift::getClassTypeID()) { + const GeoShapeShift& shiftShape = dynamic_cast(shape); + const GeoShape* shapeOp = shiftShape.getOp(); + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(transform.rotation()); + newTransform.translate(shiftShape.getX().translation()); + return convert(context, *shapeOp, name, newTransform); + } + throw std::runtime_error("Unknown shape type: " + shape.type()); +} +} // namespace GeoModelToDetVol +} // namespace Acts From 0700fc7803554bd3425659e617b4e022a34e8eb9 Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Mon, 3 Jun 2024 08:14:13 -0500 Subject: [PATCH 03/29] Changes to fix finding geomodel on system and first round of converter --- CMakeLists.txt | 6 +- Plugins/GeoModel/CMakeLists.txt | 5 +- .../Plugins/GeoModel/GeoModelToDetVol.hpp | 21 +++ Plugins/GeoModel/src/GeoModelToDetVol.cpp | 122 ++++++++++++++++++ cmake/ActsConfig.cmake.in | 3 + 5 files changed, 152 insertions(+), 5 deletions(-) create mode 100644 Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp create mode 100644 Plugins/GeoModel/src/GeoModelToDetVol.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f1ae068d049..831e6e87650 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -196,8 +196,7 @@ set(_acts_autodiff_version 0.6) set(_acts_boost_version 1.71.0) set(_acts_dd4hep_version 1.21) set(_acts_edm4hep_version 0.7) -set(_acts_geomodel_version 4.6.0) -set(_acts_eigen3_version 3.3.7) +set(_acts_geomodel_version 5.6.0) set(_acts_podio_version 0.16) set(_acts_doxygen_version 1.9.4) set(_acts_hepmc3_version 3.2.1) @@ -348,7 +347,8 @@ if(ACTS_BUILD_PLUGIN_JSON) endif() if(ACTS_BUILD_PLUGIN_GEOMODEL) if(ACTS_USE_SYSTEM_GEOMODEL) - find_package(GeoModel ${_acts_geomodel_version} REQUIRED CONFIG) + message(STATUS "Using system installation of GeoModel") + find_package(GeoModelCore ${_acts_geomodel_version} COMPONENTS GeoModelKernel REQUIRED CONFIG) else() add_subdirectory(thirdparty/GeoModel) endif() diff --git a/Plugins/GeoModel/CMakeLists.txt b/Plugins/GeoModel/CMakeLists.txt index a7fc08498f7..c7ddfcad70b 100644 --- a/Plugins/GeoModel/CMakeLists.txt +++ b/Plugins/GeoModel/CMakeLists.txt @@ -2,7 +2,8 @@ include(FetchContent) add_library( ActsPluginGeoModel SHARED - src/GeoModelReader.cpp) + src/GeoModelReader.cpp + src/GeoModelToDetVol.cpp) target_include_directories( ActsPluginGeoModel PUBLIC @@ -10,7 +11,7 @@ target_include_directories( $) target_link_libraries( ActsPluginGeoModel - PUBLIC ActsCore GeoModelKernel GeoModelIO::GeoModelDBManager GeoModelIO::GeoModelRead) + PUBLIC ActsCore GeoModelCore::GeoModelKernel GeoModelIO::GeoModelDBManager GeoModelIO::GeoModelRead) install( TARGETS ActsPluginGeoModel diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp new file mode 100644 index 00000000000..5cb1c9fd164 --- /dev/null +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp @@ -0,0 +1,21 @@ +#include "Acts/Geometry/CylinderVolumeBounds.hpp" +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "Acts/Detector/GeometryIdGenerator.hpp" +#include "Acts/Geometry/TrapezoidVolumeBounds.hpp" +#include "Acts/Geometry/CutoutCylinderVolumeBounds.hpp" +#include "Acts/Geometry/GeometryContext.hpp" +#include "Acts/Geometry/CuboidVolumeBounds.hpp" +#include "Acts/Detector/DetectorVolume.hpp" + +#include "GeoModelKernel/GeoShape.h" + +namespace Acts { + namespace GeoModelToDetVol { + /// @brief Convert a GeoModel shape to a DetectorVolume + /// + /// @param shape the GeoModel shape + /// @param transform the transform to be applied + /// @return the DetectorVolume + std::shared_ptr convert(const GeometryContext& context, const GeoShape& shape, const std::string& name, const Transform3& transform); + } +} \ No newline at end of file diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp new file mode 100644 index 00000000000..86326856663 --- /dev/null +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -0,0 +1,122 @@ +#include "Acts/Detector/PortalGenerators.hpp" +#include "Acts/Navigation/SurfaceCandidatesUpdaters.hpp" +#include "Acts/Plugins/GeoModel/GeoModelToDetVol.hpp" + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Acts { + namespace GeoModelToDetVol { + std::shared_ptr convert(const GeometryContext& context, const GeoShape& shape, const std::string& name, const Transform3& transform) { + auto portalGenerator = Experimental::defaultPortalGenerator(); + if (shape.typeID() == GeoTube::getClassTypeID()) { + const GeoTube& tube = dynamic_cast(shape); + std::shared_ptr bounds = std::make_shared(tube.getRMin(), tube.getRMax(), tube.getZHalfLength()); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoTubs::getClassTypeID()) { + const GeoTubs& tubs = dynamic_cast(shape); + std::shared_ptr bounds = std::make_shared(tubs.getRMin(), tubs.getRMax(), tubs.getZHalfLength(), tubs.getDPhi()/ 2); + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(Eigen::AngleAxisd(tubs.getSPhi() + 0.5 * tubs.getDPhi(), Acts::Vector3::UnitZ())); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoBox::getClassTypeID()) { + const GeoBox& box = dynamic_cast(shape); + std::shared_ptr bounds = std::make_shared(box.getXHalfLength(), box.getYHalfLength(), box.getZHalfLength()); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoSimplePolygonBrep::getClassTypeID()) { + double xmin{0}; + double xmax{0}; + double ymin{0}; + double ymax{0}; + double zmin{0}; + double zmax{0}; + const GeoSimplePolygonBrep& brep = dynamic_cast(shape); + brep.extent(xmin, ymin, zmin, xmax, ymax, zmax); + std::shared_ptr bounds = std::make_shared(xmax-xmin, ymax-ymin, zmax-zmin); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoTrd::getClassTypeID()){ + const GeoTrd& trd = dynamic_cast(shape); + float x1 = trd.getXHalfLength1(); + float x2 = trd.getXHalfLength2(); + float y1 = trd.getYHalfLength1(); + float y2 = trd.getYHalfLength2(); + float z = trd.getZHalfLength(); + if (y1 == y2){ + if (x1 <= x2){ + //y axis in ACTS is z axis in geomodel + std::shared_ptr bounds = std::make_shared(x1,x2,z,y1); + auto rotationAngle = M_PI/2; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); + } else { + std::shared_ptr bounds = std::make_shared(x2,x1,z,y1); + auto rotationAngle = M_PI; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitY()) * Eigen::AngleAxisd(rotationAngle ,Acts::Vector3::UnitZ())); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); + } + } else if(x1 == x2){ + if(y1 < y2) { + std::shared_ptr bounds = std::make_shared(y1,y2,z,x1); + auto rotationAngle = M_PI/2; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ()) * Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); + } else { + std::shared_ptr bounds = std::make_shared(y2,y1,z,x1); + auto rotationAngle = M_PI; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX()) * Eigen::AngleAxisd(rotationAngle/2, Acts::Vector3::UnitZ()) * Eigen::AngleAxisd(rotationAngle/2, Acts::Vector3::UnitX())); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); + } + } else{ + throw std::runtime_error("FATAL: Translating GeoTrd to ACTS failed"); + } + } else if (shape.typeID() == GeoShapeUnion::getClassTypeID()){ + double xmin{0}; + double xmax{0}; + double ymin{0}; + double ymax{0}; + double zmin{0}; + double zmax{0}; + const GeoShapeUnion& unionShape = dynamic_cast(shape); + unionShape.extent(xmin, ymin, zmin, xmax, ymax, zmax); + std::shared_ptr bounds = std::make_shared(xmax-xmin, ymax-ymin, zmax-zmin); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoShapeSubtraction::getClassTypeID()) { + //Go down the left side (opA) of the subtraction until we reach a normal shape + const GeoShapeSubtraction& subtractionShape = dynamic_cast(shape); + const GeoShape* shapeA = subtractionShape.getOpA(); + return convert(context, *shapeA, name, transform); + } else if (shape.typeID() == GeoPcon::getClassTypeID()) { + //nothing + std::shared_ptr bounds = std::make_shared(1,1,1); + return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); + } + if (shape.typeID() == GeoShapeShift::getClassTypeID()) { + const GeoShapeShift& shiftShape = dynamic_cast(shape); + const GeoShape* shapeOp = shiftShape.getOp(); + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(transform.rotation()); + newTransform.translate(shiftShape.getX().translation()); + return convert(context, *shapeOp, name, newTransform); + } + throw std::runtime_error("Unknown shape type: " + shape.type()); + } + } +} \ No newline at end of file diff --git a/cmake/ActsConfig.cmake.in b/cmake/ActsConfig.cmake.in index 0233e09c74a..1d8136e9c10 100644 --- a/cmake/ActsConfig.cmake.in +++ b/cmake/ActsConfig.cmake.in @@ -67,6 +67,9 @@ endif() if(PluginTGeo IN_LIST Acts_COMPONENTS) find_dependency(ROOT @ROOT_VERSION@ CONFIG EXACT) endif() +if(PluginGeoModel IN_LIST Acts_COMPONENTS) + find_dependency(GeoModelCore @GeoModelCore_VERSION@ CONFIG EXACT) +endif() if(PluginActSVG IN_LIST Acts_COMPONENTS) find_dependency(actsvg @actsvg_VERSION@ CONFIG EXACT) endif() From 891280f583459b89986983119c5a29e9245f9651 Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Fri, 7 Jun 2024 09:18:21 -0500 Subject: [PATCH 04/29] format changes --- .../Plugins/GeoModel/GeoModelToDetVol.hpp | 39 ++- Plugins/GeoModel/src/GeoModelToDetVol.cpp | 295 +++++++++++------- 2 files changed, 207 insertions(+), 127 deletions(-) diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp index 5cb1c9fd164..08a12d8bf97 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp @@ -1,21 +1,32 @@ -#include "Acts/Geometry/CylinderVolumeBounds.hpp" -#include "Acts/Geometry/GeometryIdentifier.hpp" +// This file is part of the Acts project. +// +// Copyright (C) 2024 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +#pragma once + +#include "Acts/Detector/DetectorVolume.hpp" #include "Acts/Detector/GeometryIdGenerator.hpp" -#include "Acts/Geometry/TrapezoidVolumeBounds.hpp" +#include "Acts/Geometry/CuboidVolumeBounds.hpp" #include "Acts/Geometry/CutoutCylinderVolumeBounds.hpp" +#include "Acts/Geometry/CylinderVolumeBounds.hpp" #include "Acts/Geometry/GeometryContext.hpp" -#include "Acts/Geometry/CuboidVolumeBounds.hpp" -#include "Acts/Detector/DetectorVolume.hpp" +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "Acts/Geometry/TrapezoidVolumeBounds.hpp" #include "GeoModelKernel/GeoShape.h" namespace Acts { - namespace GeoModelToDetVol { - /// @brief Convert a GeoModel shape to a DetectorVolume - /// - /// @param shape the GeoModel shape - /// @param transform the transform to be applied - /// @return the DetectorVolume - std::shared_ptr convert(const GeometryContext& context, const GeoShape& shape, const std::string& name, const Transform3& transform); - } -} \ No newline at end of file +namespace GeoModelToDetVol { +/// @brief Convert a GeoModel shape to a DetectorVolume +/// +/// @param shape the GeoModel shape +/// @param transform the transform to be applied +/// @return the DetectorVolume +std::shared_ptr convert( + const GeometryContext& context, const GeoShape& shape, + const std::string& name, const Transform3& transform); +} // namespace GeoModelToDetVol +} // namespace Acts diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp index 86326856663..1e772515166 100644 --- a/Plugins/GeoModel/src/GeoModelToDetVol.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -1,122 +1,191 @@ -#include "Acts/Detector/PortalGenerators.hpp" -#include "Acts/Navigation/SurfaceCandidatesUpdaters.hpp" +// This file is part of the Acts project. +// +// Copyright (C) 2024 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + #include "Acts/Plugins/GeoModel/GeoModelToDetVol.hpp" +#include "Acts/Detector/PortalGenerators.hpp" +#include "Acts/Navigation/SurfaceCandidatesUpdaters.hpp" -#include -#include -#include #include -#include -#include +#include #include #include -#include +#include +#include +#include +#include +#include namespace Acts { - namespace GeoModelToDetVol { - std::shared_ptr convert(const GeometryContext& context, const GeoShape& shape, const std::string& name, const Transform3& transform) { - auto portalGenerator = Experimental::defaultPortalGenerator(); - if (shape.typeID() == GeoTube::getClassTypeID()) { - const GeoTube& tube = dynamic_cast(shape); - std::shared_ptr bounds = std::make_shared(tube.getRMin(), tube.getRMax(), tube.getZHalfLength()); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); - } else if (shape.typeID() == GeoTubs::getClassTypeID()) { - const GeoTubs& tubs = dynamic_cast(shape); - std::shared_ptr bounds = std::make_shared(tubs.getRMin(), tubs.getRMax(), tubs.getZHalfLength(), tubs.getDPhi()/ 2); - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(Eigen::AngleAxisd(tubs.getSPhi() + 0.5 * tubs.getDPhi(), Acts::Vector3::UnitZ())); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); - } else if (shape.typeID() == GeoBox::getClassTypeID()) { - const GeoBox& box = dynamic_cast(shape); - std::shared_ptr bounds = std::make_shared(box.getXHalfLength(), box.getYHalfLength(), box.getZHalfLength()); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); - } else if (shape.typeID() == GeoSimplePolygonBrep::getClassTypeID()) { - double xmin{0}; - double xmax{0}; - double ymin{0}; - double ymax{0}; - double zmin{0}; - double zmax{0}; - const GeoSimplePolygonBrep& brep = dynamic_cast(shape); - brep.extent(xmin, ymin, zmin, xmax, ymax, zmax); - std::shared_ptr bounds = std::make_shared(xmax-xmin, ymax-ymin, zmax-zmin); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); - } else if (shape.typeID() == GeoTrd::getClassTypeID()){ - const GeoTrd& trd = dynamic_cast(shape); - float x1 = trd.getXHalfLength1(); - float x2 = trd.getXHalfLength2(); - float y1 = trd.getYHalfLength1(); - float y2 = trd.getYHalfLength2(); - float z = trd.getZHalfLength(); - if (y1 == y2){ - if (x1 <= x2){ - //y axis in ACTS is z axis in geomodel - std::shared_ptr bounds = std::make_shared(x1,x2,z,y1); - auto rotationAngle = M_PI/2; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); - } else { - std::shared_ptr bounds = std::make_shared(x2,x1,z,y1); - auto rotationAngle = M_PI; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitY()) * Eigen::AngleAxisd(rotationAngle ,Acts::Vector3::UnitZ())); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); - } - } else if(x1 == x2){ - if(y1 < y2) { - std::shared_ptr bounds = std::make_shared(y1,y2,z,x1); - auto rotationAngle = M_PI/2; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ()) * Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); - } else { - std::shared_ptr bounds = std::make_shared(y2,y1,z,x1); - auto rotationAngle = M_PI; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX()) * Eigen::AngleAxisd(rotationAngle/2, Acts::Vector3::UnitZ()) * Eigen::AngleAxisd(rotationAngle/2, Acts::Vector3::UnitX())); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortals()); - } - } else{ - throw std::runtime_error("FATAL: Translating GeoTrd to ACTS failed"); - } - } else if (shape.typeID() == GeoShapeUnion::getClassTypeID()){ - double xmin{0}; - double xmax{0}; - double ymin{0}; - double ymax{0}; - double zmin{0}; - double zmax{0}; - const GeoShapeUnion& unionShape = dynamic_cast(shape); - unionShape.extent(xmin, ymin, zmin, xmax, ymax, zmax); - std::shared_ptr bounds = std::make_shared(xmax-xmin, ymax-ymin, zmax-zmin); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); - } else if (shape.typeID() == GeoShapeSubtraction::getClassTypeID()) { - //Go down the left side (opA) of the subtraction until we reach a normal shape - const GeoShapeSubtraction& subtractionShape = dynamic_cast(shape); - const GeoShape* shapeA = subtractionShape.getOpA(); - return convert(context, *shapeA, name, transform); - } else if (shape.typeID() == GeoPcon::getClassTypeID()) { - //nothing - std::shared_ptr bounds = std::make_shared(1,1,1); - return Experimental::DetectorVolumeFactory::construct(portalGenerator, context, name, transform, bounds, Experimental::tryAllPortals()); - } - if (shape.typeID() == GeoShapeShift::getClassTypeID()) { - const GeoShapeShift& shiftShape = dynamic_cast(shape); - const GeoShape* shapeOp = shiftShape.getOp(); - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation()); - newTransform.translate(shiftShape.getX().translation()); - return convert(context, *shapeOp, name, newTransform); - } - throw std::runtime_error("Unknown shape type: " + shape.type()); - } +namespace GeoModelToDetVol { +std::shared_ptr convert( + const GeometryContext& context, const GeoShape& shape, + const std::string& name, const Transform3& transform) { + auto portalGenerator = Experimental::defaultPortalAndSubPortalGenerator(); + if (shape.typeID() == GeoTube::getClassTypeID()) { + const GeoTube& tube = dynamic_cast(shape); + std::shared_ptr bounds = + std::make_shared(tube.getRMin(), tube.getRMax(), + tube.getZHalfLength()); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoTubs::getClassTypeID()) { + const GeoTubs& tubs = dynamic_cast(shape); + std::shared_ptr bounds = + std::make_shared(tubs.getRMin(), tubs.getRMax(), + tubs.getZHalfLength(), + tubs.getDPhi() / 2); + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(Eigen::AngleAxisd(tubs.getSPhi() + 0.5 * tubs.getDPhi(), + Acts::Vector3::UnitZ())); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoBox::getClassTypeID()) { + const GeoBox& box = dynamic_cast(shape); + std::shared_ptr bounds = + std::make_shared( + box.getXHalfLength(), box.getYHalfLength(), box.getZHalfLength()); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoSimplePolygonBrep::getClassTypeID()) { + // Will change this in the future + double xmin{0}; + double xmax{0}; + double ymin{0}; + double ymax{0}; + double zmin{0}; + double zmax{0}; + const GeoSimplePolygonBrep& brep = + dynamic_cast(shape); + brep.extent(xmin, ymin, zmin, xmax, ymax, zmax); + std::shared_ptr bounds = + std::make_shared(xmax - xmin, ymax - ymin, + zmax - zmin); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoTrd::getClassTypeID()) { + const GeoTrd& trd = dynamic_cast(shape); + float x1 = trd.getXHalfLength1(); + float x2 = trd.getXHalfLength2(); + float y1 = trd.getYHalfLength1(); + float y2 = trd.getYHalfLength2(); + float z = trd.getZHalfLength(); + if (y1 == y2) { + if (x1 <= x2) { + // y axis in ACTS is z axis in geomodel + std::shared_ptr bounds = + std::make_shared(x1, x2, z, y1); + auto rotationAngle = M_PI / 2; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate( + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortals()); + } else { + std::shared_ptr bounds = + std::make_shared(x2, x1, z, y1); + auto rotationAngle = M_PI; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate( + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitY()) * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ())); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortals()); + } + } else if (x1 == x2) { + if (y1 < y2) { + std::shared_ptr bounds = + std::make_shared(y1, y2, z, x1); + auto rotationAngle = M_PI / 2; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate( + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ()) * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortals()); + } else { + std::shared_ptr bounds = + std::make_shared(y2, y1, z, x1); + auto rotationAngle = M_PI; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate( + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX()) * + Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitZ()) * + Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitX())); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortals()); + } + } else { + throw std::runtime_error("FATAL: Translating GeoTrd to ACTS failed"); } -} \ No newline at end of file + } else if (shape.typeID() == GeoShapeUnion::getClassTypeID()) { + // Get the bounding box of the union + double xmin{0}; + double xmax{0}; + double ymin{0}; + double ymax{0}; + double zmin{0}; + double zmax{0}; + const GeoShapeUnion& unionShape = dynamic_cast(shape); + unionShape.extent(xmin, ymin, zmin, xmax, ymax, zmax); + std::shared_ptr bounds = + std::make_shared(xmax - xmin, ymax - ymin, + zmax - zmin); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortals()); + } else if (shape.typeID() == GeoShapeSubtraction::getClassTypeID()) { + // Go down the left side (opA) of the subtraction until we reach a normal + // shape + const GeoShapeSubtraction& subtractionShape = + dynamic_cast(shape); + const GeoShape* shapeA = subtractionShape.getOpA(); + return convert(context, *shapeA, name, transform); + } else if (shape.typeID() == GeoPcon::getClassTypeID()) { + // Will change in future, get bounding box for now + double xmin{0}; + double xmax{0}; + double ymin{0}; + double ymax{0}; + double zmin{0}; + double zmax{0}; + const GeoPcon& pcon = dynamic_cast(shape); + pcon.extent(xmin, ymin, zmin, xmax, ymax, zmax); + std::shared_ptr bounds = + std::make_shared(xmax - xmin, ymax - ymin, + zmax - zmin); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortals()); + } + if (shape.typeID() == GeoShapeShift::getClassTypeID()) { + const GeoShapeShift& shiftShape = dynamic_cast(shape); + const GeoShape* shapeOp = shiftShape.getOp(); + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(transform.rotation()); + newTransform.translate(shiftShape.getX().translation()); + return convert(context, *shapeOp, name, newTransform); + } + throw std::runtime_error("Unknown shape type: " + shape.type()); +} +} // namespace GeoModelToDetVol +} // namespace Acts From b8712b431f0f147dd3c6826144098c3d5f8c66c8 Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Fri, 7 Jun 2024 10:13:20 -0500 Subject: [PATCH 05/29] small changes --- CMakeLists.txt | 1 + Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelTree.hpp | 2 +- Plugins/GeoModel/src/GeoModelToDetVol.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 831e6e87650..3ed3d57562f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -348,6 +348,7 @@ endif() if(ACTS_BUILD_PLUGIN_GEOMODEL) if(ACTS_USE_SYSTEM_GEOMODEL) message(STATUS "Using system installation of GeoModel") + find_package(GeoModelIO ${_acts_geomodel_version} COMPONENTS GeoModelDBManager GeoModelRead REQUIRED CONFIG) find_package(GeoModelCore ${_acts_geomodel_version} COMPONENTS GeoModelKernel REQUIRED CONFIG) else() add_subdirectory(thirdparty/GeoModel) diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelTree.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelTree.hpp index 224e0f786ed..1d3ba02e43f 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelTree.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelTree.hpp @@ -18,7 +18,7 @@ namespace Acts { struct GeoModelTree { std::shared_ptr geoReader = nullptr; - GeoVPhysVol* worldVolume = nullptr; + const GeoVPhysVol* worldVolume = nullptr; std::string worldVolumeName = "World"; }; } // namespace Acts diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp index 1e772515166..daa6b8416e1 100644 --- a/Plugins/GeoModel/src/GeoModelToDetVol.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -9,7 +9,7 @@ #include "Acts/Plugins/GeoModel/GeoModelToDetVol.hpp" #include "Acts/Detector/PortalGenerators.hpp" -#include "Acts/Navigation/SurfaceCandidatesUpdaters.hpp" +#include "Acts/Navigation/InternalNavigation.hpp" #include #include From fa55d0ece9ef88fea3e1ce846ec0984a7a6dfd3b Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Fri, 7 Jun 2024 11:39:59 -0500 Subject: [PATCH 06/29] Final changes for using system geomodel --- CMakeLists.txt | 1 - cmake/ActsConfig.cmake.in | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ed3d57562f..8a03fc82e94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -349,7 +349,6 @@ if(ACTS_BUILD_PLUGIN_GEOMODEL) if(ACTS_USE_SYSTEM_GEOMODEL) message(STATUS "Using system installation of GeoModel") find_package(GeoModelIO ${_acts_geomodel_version} COMPONENTS GeoModelDBManager GeoModelRead REQUIRED CONFIG) - find_package(GeoModelCore ${_acts_geomodel_version} COMPONENTS GeoModelKernel REQUIRED CONFIG) else() add_subdirectory(thirdparty/GeoModel) endif() diff --git a/cmake/ActsConfig.cmake.in b/cmake/ActsConfig.cmake.in index 1d8136e9c10..fbe223bf558 100644 --- a/cmake/ActsConfig.cmake.in +++ b/cmake/ActsConfig.cmake.in @@ -68,7 +68,7 @@ if(PluginTGeo IN_LIST Acts_COMPONENTS) find_dependency(ROOT @ROOT_VERSION@ CONFIG EXACT) endif() if(PluginGeoModel IN_LIST Acts_COMPONENTS) - find_dependency(GeoModelCore @GeoModelCore_VERSION@ CONFIG EXACT) + find_dependency(GeoModelIO @GeoModelIO_VERSION@ CONFIG EXACT) endif() if(PluginActSVG IN_LIST Acts_COMPONENTS) find_dependency(actsvg @actsvg_VERSION@ CONFIG EXACT) From 656c771f521800a8666964aabb3e8c6ea09e680c Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Fri, 7 Jun 2024 11:49:03 -0500 Subject: [PATCH 07/29] oops --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a03fc82e94..4676c6c2f46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -196,6 +196,7 @@ set(_acts_autodiff_version 0.6) set(_acts_boost_version 1.71.0) set(_acts_dd4hep_version 1.21) set(_acts_edm4hep_version 0.7) +set(_acts_eigen3_version 3.3.7) set(_acts_geomodel_version 5.6.0) set(_acts_podio_version 0.16) set(_acts_doxygen_version 1.9.4) From 1660a53e83053f234bd8bcc275f2dc86960a6297 Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Thu, 13 Jun 2024 13:18:07 -0500 Subject: [PATCH 08/29] Use forward declare and move around some includes --- .../include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp | 10 ++-------- Plugins/GeoModel/src/GeoModelToDetVol.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp index 08a12d8bf97..042151dda59 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp @@ -8,17 +8,11 @@ #pragma once #include "Acts/Detector/DetectorVolume.hpp" -#include "Acts/Detector/GeometryIdGenerator.hpp" -#include "Acts/Geometry/CuboidVolumeBounds.hpp" -#include "Acts/Geometry/CutoutCylinderVolumeBounds.hpp" -#include "Acts/Geometry/CylinderVolumeBounds.hpp" -#include "Acts/Geometry/GeometryContext.hpp" -#include "Acts/Geometry/GeometryIdentifier.hpp" -#include "Acts/Geometry/TrapezoidVolumeBounds.hpp" -#include "GeoModelKernel/GeoShape.h" +class GeoShape; namespace Acts { + namespace GeoModelToDetVol { /// @brief Convert a GeoModel shape to a DetectorVolume /// diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp index daa6b8416e1..36b8ca23e49 100644 --- a/Plugins/GeoModel/src/GeoModelToDetVol.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -8,7 +8,13 @@ #include "Acts/Plugins/GeoModel/GeoModelToDetVol.hpp" +#include "Acts/Detector/GeometryIdGenerator.hpp" #include "Acts/Detector/PortalGenerators.hpp" +#include "Acts/Geometry/CuboidVolumeBounds.hpp" +#include "Acts/Geometry/CutoutCylinderVolumeBounds.hpp" +#include "Acts/Geometry/CylinderVolumeBounds.hpp" +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "Acts/Geometry/TrapezoidVolumeBounds.hpp" #include "Acts/Navigation/InternalNavigation.hpp" #include From a7fb341cf9af4261e57d721b01fc2d2297b8f6b6 Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Thu, 13 Jun 2024 13:41:24 -0500 Subject: [PATCH 09/29] Change to GeoModel namespace --- .../Plugins/GeoModel/GeoModelToDetVol.hpp | 4 +-- Plugins/GeoModel/src/GeoModelToDetVol.cpp | 30 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp index 042151dda59..85be681acdb 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp @@ -13,13 +13,13 @@ class GeoShape; namespace Acts { -namespace GeoModelToDetVol { +namespace GeoModel { /// @brief Convert a GeoModel shape to a DetectorVolume /// /// @param shape the GeoModel shape /// @param transform the transform to be applied /// @return the DetectorVolume -std::shared_ptr convert( +std::shared_ptr convertVolume( const GeometryContext& context, const GeoShape& shape, const std::string& name, const Transform3& transform); } // namespace GeoModelToDetVol diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp index 36b8ca23e49..12f5ceda401 100644 --- a/Plugins/GeoModel/src/GeoModelToDetVol.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -28,8 +28,8 @@ #include namespace Acts { -namespace GeoModelToDetVol { -std::shared_ptr convert( +namespace GeoModel { +std::shared_ptr convertVolume( const GeometryContext& context, const GeoShape& shape, const std::string& name, const Transform3& transform) { auto portalGenerator = Experimental::defaultPortalAndSubPortalGenerator(); @@ -40,7 +40,7 @@ std::shared_ptr convert( tube.getZHalfLength()); return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortals()); + Experimental::tryAllPortalsAndSurfaces()); } else if (shape.typeID() == GeoTubs::getClassTypeID()) { const GeoTubs& tubs = dynamic_cast(shape); std::shared_ptr bounds = @@ -53,7 +53,7 @@ std::shared_ptr convert( Acts::Vector3::UnitZ())); return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortals()); + Experimental::tryAllPortalsAndSurfaces()); } else if (shape.typeID() == GeoBox::getClassTypeID()) { const GeoBox& box = dynamic_cast(shape); std::shared_ptr bounds = @@ -61,7 +61,7 @@ std::shared_ptr convert( box.getXHalfLength(), box.getYHalfLength(), box.getZHalfLength()); return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortals()); + Experimental::tryAllPortalsAndSurfaces()); } else if (shape.typeID() == GeoSimplePolygonBrep::getClassTypeID()) { // Will change this in the future double xmin{0}; @@ -78,7 +78,7 @@ std::shared_ptr convert( zmax - zmin); return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortals()); + Experimental::tryAllPortalsAndSurfaces()); } else if (shape.typeID() == GeoTrd::getClassTypeID()) { const GeoTrd& trd = dynamic_cast(shape); float x1 = trd.getXHalfLength1(); @@ -98,7 +98,7 @@ std::shared_ptr convert( Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortals()); + Experimental::tryAllPortalsAndSurfaces()); } else { std::shared_ptr bounds = std::make_shared(x2, x1, z, y1); @@ -110,7 +110,7 @@ std::shared_ptr convert( Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ())); return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortals()); + Experimental::tryAllPortalsAndSurfaces()); } } else if (x1 == x2) { if (y1 < y2) { @@ -124,7 +124,7 @@ std::shared_ptr convert( Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortals()); + Experimental::tryAllPortalsAndSurfaces()); } else { std::shared_ptr bounds = std::make_shared(y2, y1, z, x1); @@ -137,7 +137,7 @@ std::shared_ptr convert( Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitX())); return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortals()); + Experimental::tryAllPortalsAndSurfaces()); } } else { throw std::runtime_error("FATAL: Translating GeoTrd to ACTS failed"); @@ -157,14 +157,14 @@ std::shared_ptr convert( zmax - zmin); return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortals()); + Experimental::tryAllPortalsAndSurfaces()); } else if (shape.typeID() == GeoShapeSubtraction::getClassTypeID()) { // Go down the left side (opA) of the subtraction until we reach a normal // shape const GeoShapeSubtraction& subtractionShape = dynamic_cast(shape); const GeoShape* shapeA = subtractionShape.getOpA(); - return convert(context, *shapeA, name, transform); + return convertVolume(context, *shapeA, name, transform); } else if (shape.typeID() == GeoPcon::getClassTypeID()) { // Will change in future, get bounding box for now double xmin{0}; @@ -180,7 +180,7 @@ std::shared_ptr convert( zmax - zmin); return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortals()); + Experimental::tryAllPortalsAndSurfaces()); } if (shape.typeID() == GeoShapeShift::getClassTypeID()) { const GeoShapeShift& shiftShape = dynamic_cast(shape); @@ -189,9 +189,9 @@ std::shared_ptr convert( newTransform.translate(transform.translation()); newTransform.rotate(transform.rotation()); newTransform.translate(shiftShape.getX().translation()); - return convert(context, *shapeOp, name, newTransform); + return convertVolume(context, *shapeOp, name, newTransform); } throw std::runtime_error("Unknown shape type: " + shape.type()); } -} // namespace GeoModelToDetVol +} // namespace GeoModel } // namespace Acts From 53334abac6492c725709b30ad99910069691af56 Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Thu, 13 Jun 2024 13:53:38 -0500 Subject: [PATCH 10/29] fix format --- .../GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp index 85be681acdb..147ecfa7f94 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp @@ -22,5 +22,5 @@ namespace GeoModel { std::shared_ptr convertVolume( const GeometryContext& context, const GeoShape& shape, const std::string& name, const Transform3& transform); -} // namespace GeoModelToDetVol +} // namespace GeoModel } // namespace Acts From 6b016cafc310815d6a98b98761e0112eeb626d91 Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Mon, 17 Jun 2024 03:25:37 -0500 Subject: [PATCH 11/29] change from dynamic_cast to static_cast --- Plugins/GeoModel/src/GeoModelToDetVol.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp index 12f5ceda401..da8274d8e67 100644 --- a/Plugins/GeoModel/src/GeoModelToDetVol.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -34,7 +34,7 @@ std::shared_ptr convertVolume( const std::string& name, const Transform3& transform) { auto portalGenerator = Experimental::defaultPortalAndSubPortalGenerator(); if (shape.typeID() == GeoTube::getClassTypeID()) { - const GeoTube& tube = dynamic_cast(shape); + const GeoTube& tube = static_cast(shape); std::shared_ptr bounds = std::make_shared(tube.getRMin(), tube.getRMax(), tube.getZHalfLength()); @@ -42,7 +42,7 @@ std::shared_ptr convertVolume( portalGenerator, context, name, transform, bounds, Experimental::tryAllPortalsAndSurfaces()); } else if (shape.typeID() == GeoTubs::getClassTypeID()) { - const GeoTubs& tubs = dynamic_cast(shape); + const GeoTubs& tubs = static_cast(shape); std::shared_ptr bounds = std::make_shared(tubs.getRMin(), tubs.getRMax(), tubs.getZHalfLength(), @@ -55,7 +55,7 @@ std::shared_ptr convertVolume( portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortalsAndSurfaces()); } else if (shape.typeID() == GeoBox::getClassTypeID()) { - const GeoBox& box = dynamic_cast(shape); + const GeoBox& box = static_cast(shape); std::shared_ptr bounds = std::make_shared( box.getXHalfLength(), box.getYHalfLength(), box.getZHalfLength()); @@ -71,7 +71,7 @@ std::shared_ptr convertVolume( double zmin{0}; double zmax{0}; const GeoSimplePolygonBrep& brep = - dynamic_cast(shape); + static_cast(shape); brep.extent(xmin, ymin, zmin, xmax, ymax, zmax); std::shared_ptr bounds = std::make_shared(xmax - xmin, ymax - ymin, @@ -80,7 +80,7 @@ std::shared_ptr convertVolume( portalGenerator, context, name, transform, bounds, Experimental::tryAllPortalsAndSurfaces()); } else if (shape.typeID() == GeoTrd::getClassTypeID()) { - const GeoTrd& trd = dynamic_cast(shape); + const GeoTrd& trd = static_cast(shape); float x1 = trd.getXHalfLength1(); float x2 = trd.getXHalfLength2(); float y1 = trd.getYHalfLength1(); @@ -150,7 +150,7 @@ std::shared_ptr convertVolume( double ymax{0}; double zmin{0}; double zmax{0}; - const GeoShapeUnion& unionShape = dynamic_cast(shape); + const GeoShapeUnion& unionShape = static_cast(shape); unionShape.extent(xmin, ymin, zmin, xmax, ymax, zmax); std::shared_ptr bounds = std::make_shared(xmax - xmin, ymax - ymin, @@ -162,7 +162,7 @@ std::shared_ptr convertVolume( // Go down the left side (opA) of the subtraction until we reach a normal // shape const GeoShapeSubtraction& subtractionShape = - dynamic_cast(shape); + static_cast(shape); const GeoShape* shapeA = subtractionShape.getOpA(); return convertVolume(context, *shapeA, name, transform); } else if (shape.typeID() == GeoPcon::getClassTypeID()) { @@ -173,7 +173,7 @@ std::shared_ptr convertVolume( double ymax{0}; double zmin{0}; double zmax{0}; - const GeoPcon& pcon = dynamic_cast(shape); + const GeoPcon& pcon = static_cast(shape); pcon.extent(xmin, ymin, zmin, xmax, ymax, zmax); std::shared_ptr bounds = std::make_shared(xmax - xmin, ymax - ymin, @@ -183,7 +183,7 @@ std::shared_ptr convertVolume( Experimental::tryAllPortalsAndSurfaces()); } if (shape.typeID() == GeoShapeShift::getClassTypeID()) { - const GeoShapeShift& shiftShape = dynamic_cast(shape); + const GeoShapeShift& shiftShape = static_cast(shape); const GeoShape* shapeOp = shiftShape.getOp(); Acts::Transform3 newTransform = Acts::Transform3::Identity(); newTransform.translate(transform.translation()); From cd12571d07934b3cecdb0ab53dc2d200af126f76 Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Fri, 28 Jun 2024 03:43:12 -0500 Subject: [PATCH 12/29] Address Johannes comments --- Plugins/GeoModel/src/GeoModelToDetVol.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp index da8274d8e67..b19a618b159 100644 --- a/Plugins/GeoModel/src/GeoModelToDetVol.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -49,7 +49,8 @@ std::shared_ptr convertVolume( tubs.getDPhi() / 2); Acts::Transform3 newTransform = Acts::Transform3::Identity(); newTransform.translate(transform.translation()); - newTransform.rotate(Eigen::AngleAxisd(tubs.getSPhi() + 0.5 * tubs.getDPhi(), + newTransform.rotate(transform.rotation() * + Eigen::AngleAxisd(tubs.getSPhi() + 0.5 * tubs.getDPhi(), Acts::Vector3::UnitZ())); return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, @@ -81,11 +82,11 @@ std::shared_ptr convertVolume( Experimental::tryAllPortalsAndSurfaces()); } else if (shape.typeID() == GeoTrd::getClassTypeID()) { const GeoTrd& trd = static_cast(shape); - float x1 = trd.getXHalfLength1(); - float x2 = trd.getXHalfLength2(); - float y1 = trd.getYHalfLength1(); - float y2 = trd.getYHalfLength2(); - float z = trd.getZHalfLength(); + double x1 = trd.getXHalfLength1(); + double x2 = trd.getXHalfLength2(); + double y1 = trd.getYHalfLength1(); + double y2 = trd.getYHalfLength2(); + double z = trd.getZHalfLength(); if (y1 == y2) { if (x1 <= x2) { // y axis in ACTS is z axis in geomodel @@ -94,7 +95,7 @@ std::shared_ptr convertVolume( auto rotationAngle = M_PI / 2; Acts::Transform3 newTransform = Acts::Transform3::Identity(); newTransform.translate(transform.translation()); - newTransform.rotate( + newTransform.rotate(transform.rotation() * Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, @@ -105,7 +106,7 @@ std::shared_ptr convertVolume( auto rotationAngle = M_PI; Acts::Transform3 newTransform = Acts::Transform3::Identity(); newTransform.translate(transform.translation()); - newTransform.rotate( + newTransform.rotate(transform.rotation() * Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitY()) * Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ())); return Experimental::DetectorVolumeFactory::construct( @@ -119,7 +120,7 @@ std::shared_ptr convertVolume( auto rotationAngle = M_PI / 2; Acts::Transform3 newTransform = Acts::Transform3::Identity(); newTransform.translate(transform.translation()); - newTransform.rotate( + newTransform.rotate(transform.rotation() * Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ()) * Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); return Experimental::DetectorVolumeFactory::construct( @@ -131,7 +132,7 @@ std::shared_ptr convertVolume( auto rotationAngle = M_PI; Acts::Transform3 newTransform = Acts::Transform3::Identity(); newTransform.translate(transform.translation()); - newTransform.rotate( + newTransform.rotate(transform.rotation() * Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX()) * Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitZ()) * Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitX())); From 47547d98e60637b1398dbd532f0a7b386188af8c Mon Sep 17 00:00:00 2001 From: Matthew Leary Harris Date: Thu, 4 Jul 2024 11:19:50 +0200 Subject: [PATCH 13/29] bump GeoModel to 6.0.0 and add GeoMaterial converter --- CMakeLists.txt | 2 +- Plugins/GeoModel/CMakeLists.txt | 3 +- .../GeoModel/GeoModelMaterialConverter.hpp | 33 ++++++++++++++++ .../src/GeoModelMaterialConverter.cpp | 38 +++++++++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp create mode 100644 Plugins/GeoModel/src/GeoModelMaterialConverter.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 4676c6c2f46..7563f77e2c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,7 +197,7 @@ set(_acts_boost_version 1.71.0) set(_acts_dd4hep_version 1.21) set(_acts_edm4hep_version 0.7) set(_acts_eigen3_version 3.3.7) -set(_acts_geomodel_version 5.6.0) +set(_acts_geomodel_version 6.0.0) set(_acts_podio_version 0.16) set(_acts_doxygen_version 1.9.4) set(_acts_hepmc3_version 3.2.1) diff --git a/Plugins/GeoModel/CMakeLists.txt b/Plugins/GeoModel/CMakeLists.txt index c3cf22473eb..05b0190f4b7 100644 --- a/Plugins/GeoModel/CMakeLists.txt +++ b/Plugins/GeoModel/CMakeLists.txt @@ -7,6 +7,7 @@ add_library( src/GeoModelReader.cpp src/GeoModelDetectorElement.cpp src/GeoModelDetectorSurfaceFactory.cpp + src/GeoModelMaterialConverter.cpp src/detail/GeoBoxConverter.cpp src/detail/GeoTrdConverter.cpp src/detail/GeoTubeConverter.cpp @@ -20,7 +21,7 @@ target_include_directories( $) target_link_libraries( ActsPluginGeoModel - PUBLIC ActsCore GeoModelCore::GeoModelKernel GeoModelIO::GeoModelDBManager GeoModelIO::GeoModelRead) + PUBLIC ActsCore GeoModelCore::GeoModelKernel GeoModelCore::GeoModelHelpers GeoModelIO::GeoModelDBManager GeoModelIO::GeoModelRead) install( TARGETS ActsPluginGeoModel diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp new file mode 100644 index 00000000000..e990e758a90 --- /dev/null +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp @@ -0,0 +1,33 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2024 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +#pragma once + +#include "Acts/Material/Material.hpp" + +class GeoMaterial; + +namespace Acts{ + +namespace GeoModel { + +class GeoMaterialConverter { + public: + // Remove default constructor + GeoMaterialConverter() = delete; + + ~GeoMaterialConverter() = default; + + /// @brief Convert GeoMaterial to Acts::Material + /// + /// @param gm The GeoMaterial to be converted + /// @return the Acts::Material + static Material convert(const GeoMaterial* gm, bool molarDensity = true); + +}; // class GeoMaterialConverter +} // namespace GeoModel +} // namespace Acts \ No newline at end of file diff --git a/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp b/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp new file mode 100644 index 00000000000..59b970704ab --- /dev/null +++ b/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp @@ -0,0 +1,38 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2024 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp" + +#include "Acts/Material/Material.hpp" + +#include "GeoModelKernel/GeoMaterial.h" +#include "GeoModelKernel/Units.h" +namespace { + constexpr double s_densityCnvFactor = 1./ GeoModelKernelUnits::gram; +} +Acts::Material Acts::GeoModel::GeoMaterialConverter::convert(const GeoMaterial* gm, bool molarDensity) { + double x0 = gm->getRadLength(); + double l0 = gm->getIntLength(); + double density = gm->getDensity() * s_densityCnvFactor; + double A = 0.; + double Z = 0.; + //Get number elements + int numberOfElements = gm->getNumElements(); + //Loop + for(int iEl = 0; iEl < numberOfElements; ++iEl) { + const GeoElement* geoEl = gm->getElement(iEl); + double fraction = gm->getFraction(iEl); + A += fraction * (geoEl->getA() / GeoModelKernelUnits::gram); + Z += fraction * geoEl->getZ(); + } + if(molarDensity) { + return Material::fromMolarDensity(x0, l0, A, Z, density); + } else{ + return Material::fromMassDensity(x0, l0, A, Z, density); + } +} From c418f5bcd7d792172753e41b995040c4444df838 Mon Sep 17 00:00:00 2001 From: Matthew Leary Harris Date: Thu, 4 Jul 2024 11:29:39 +0200 Subject: [PATCH 14/29] Changes to DetVol converter --- .../GeoModel/GeoModelMaterialConverter.hpp | 4 +- .../Plugins/GeoModel/GeoModelToDetVol.hpp | 5 +- .../src/GeoModelMaterialConverter.cpp | 2 +- Plugins/GeoModel/src/GeoModelToDetVol.cpp | 285 ++++++++---------- 4 files changed, 138 insertions(+), 158 deletions(-) diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp index e990e758a90..be8e52ad743 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp @@ -26,8 +26,8 @@ class GeoMaterialConverter { /// /// @param gm The GeoMaterial to be converted /// @return the Acts::Material - static Material convert(const GeoMaterial* gm, bool molarDensity = true); + static Material convert(const GeoMaterial* gm, bool useMolarDensity = true); }; // class GeoMaterialConverter } // namespace GeoModel -} // namespace Acts \ No newline at end of file +} // namespace Acts diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp index 147ecfa7f94..1be9c641f04 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp @@ -19,8 +19,9 @@ namespace GeoModel { /// @param shape the GeoModel shape /// @param transform the transform to be applied /// @return the DetectorVolume -std::shared_ptr convertVolume( +void convertVolume( const GeometryContext& context, const GeoShape& shape, - const std::string& name, const Transform3& transform); + const std::string& name, const Transform3& transform, + std::vector>& volumes); } // namespace GeoModel } // namespace Acts diff --git a/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp b/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp index 59b970704ab..88f3fe6f1cb 100644 --- a/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp +++ b/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp @@ -15,7 +15,7 @@ namespace { constexpr double s_densityCnvFactor = 1./ GeoModelKernelUnits::gram; } -Acts::Material Acts::GeoModel::GeoMaterialConverter::convert(const GeoMaterial* gm, bool molarDensity) { +Acts::Material Acts::GeoModel::GeoMaterialConverter::convert(const GeoMaterial* gm, bool useMolarDensity) { double x0 = gm->getRadLength(); double l0 = gm->getIntLength(); double density = gm->getDensity() * s_densityCnvFactor; diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp index b19a618b159..6c8eb9309d4 100644 --- a/Plugins/GeoModel/src/GeoModelToDetVol.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -29,170 +29,149 @@ namespace Acts { namespace GeoModel { -std::shared_ptr convertVolume( - const GeometryContext& context, const GeoShape& shape, - const std::string& name, const Transform3& transform) { +void convertVolume( + const GeometryContext& context, const GeoShape& shape, + const std::string& name, const Transform3& transform, + std::vector>& volumes) { auto portalGenerator = Experimental::defaultPortalAndSubPortalGenerator(); if (shape.typeID() == GeoTube::getClassTypeID()) { - const GeoTube& tube = static_cast(shape); - std::shared_ptr bounds = - std::make_shared(tube.getRMin(), tube.getRMax(), - tube.getZHalfLength()); - return Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortalsAndSurfaces()); + const GeoTube& tube = static_cast(shape); + std::shared_ptr bounds = + std::make_shared(tube.getRMin(), tube.getRMax(), + tube.getZHalfLength()); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortalsAndSurfaces())); } else if (shape.typeID() == GeoTubs::getClassTypeID()) { - const GeoTubs& tubs = static_cast(shape); - std::shared_ptr bounds = - std::make_shared(tubs.getRMin(), tubs.getRMax(), - tubs.getZHalfLength(), - tubs.getDPhi() / 2); - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation() * - Eigen::AngleAxisd(tubs.getSPhi() + 0.5 * tubs.getDPhi(), - Acts::Vector3::UnitZ())); - return Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortalsAndSurfaces()); + const GeoTubs& tubs = static_cast(shape); + std::shared_ptr bounds = + std::make_shared(tubs.getRMin(), tubs.getRMax(), + tubs.getZHalfLength(), + tubs.getDPhi() / 2); + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(transform.rotation() * + Eigen::AngleAxisd(tubs.getSPhi() + 0.5 * tubs.getDPhi(), + Acts::Vector3::UnitZ())); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortalsAndSurfaces())); } else if (shape.typeID() == GeoBox::getClassTypeID()) { - const GeoBox& box = static_cast(shape); - std::shared_ptr bounds = - std::make_shared( - box.getXHalfLength(), box.getYHalfLength(), box.getZHalfLength()); - return Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortalsAndSurfaces()); + const GeoBox& box = static_cast(shape); + std::shared_ptr bounds = + std::make_shared( + box.getXHalfLength(), box.getYHalfLength(), box.getZHalfLength()); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortalsAndSurfaces())); } else if (shape.typeID() == GeoSimplePolygonBrep::getClassTypeID()) { - // Will change this in the future - double xmin{0}; - double xmax{0}; - double ymin{0}; - double ymax{0}; - double zmin{0}; - double zmax{0}; - const GeoSimplePolygonBrep& brep = - static_cast(shape); - brep.extent(xmin, ymin, zmin, xmax, ymax, zmax); - std::shared_ptr bounds = - std::make_shared(xmax - xmin, ymax - ymin, - zmax - zmin); - return Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortalsAndSurfaces()); + const GeoSimplePolygonBrep& brep = static_cast(shape); + double xmin{0}, xmax{0}, ymin{0}, ymax{0}, zmin{0}, zmax{0}; + brep.extent(xmin, ymin, zmin, xmax, ymax, zmax); + std::shared_ptr bounds = + std::make_shared((xmax - xmin)/2, (ymax - ymin)/2, + (zmax - zmin)/2); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortalsAndSurfaces())); } else if (shape.typeID() == GeoTrd::getClassTypeID()) { - const GeoTrd& trd = static_cast(shape); - double x1 = trd.getXHalfLength1(); - double x2 = trd.getXHalfLength2(); - double y1 = trd.getYHalfLength1(); - double y2 = trd.getYHalfLength2(); - double z = trd.getZHalfLength(); - if (y1 == y2) { - if (x1 <= x2) { - // y axis in ACTS is z axis in geomodel - std::shared_ptr bounds = - std::make_shared(x1, x2, z, y1); - auto rotationAngle = M_PI / 2; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation() * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); - return Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortalsAndSurfaces()); - } else { - std::shared_ptr bounds = - std::make_shared(x2, x1, z, y1); - auto rotationAngle = M_PI; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation() * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitY()) * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ())); - return Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortalsAndSurfaces()); - } - } else if (x1 == x2) { - if (y1 < y2) { - std::shared_ptr bounds = - std::make_shared(y1, y2, z, x1); - auto rotationAngle = M_PI / 2; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation() * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ()) * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); - return Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortalsAndSurfaces()); - } else { - std::shared_ptr bounds = - std::make_shared(y2, y1, z, x1); - auto rotationAngle = M_PI; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation() * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX()) * - Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitZ()) * - Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitX())); - return Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortalsAndSurfaces()); - } - } else { - throw std::runtime_error("FATAL: Translating GeoTrd to ACTS failed"); - } + const GeoTrd& trd = static_cast(shape); + double x1 = trd.getXHalfLength1(); + double x2 = trd.getXHalfLength2(); + double y1 = trd.getYHalfLength1(); + double y2 = trd.getYHalfLength2(); + double z = trd.getZHalfLength(); + if (y1 == y2) { + if (x1 <= x2) { + // y axis in ACTS is z axis in geomodel + std::shared_ptr bounds = + std::make_shared(x1, x2, z, y1); + auto rotationAngle = M_PI / 2; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(transform.rotation() * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortalsAndSurfaces())); + } else { + std::shared_ptr bounds = + std::make_shared(x2, x1, z, y1); + auto rotationAngle = M_PI; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(transform.rotation() * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitY()) * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ())); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortalsAndSurfaces())); + } + } else if (x1 == x2) { + if (y1 < y2) { + std::shared_ptr bounds = + std::make_shared(y1, y2, z, x1); + auto rotationAngle = M_PI / 2; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(transform.rotation() * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ()) * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortalsAndSurfaces())); + } else { + std::shared_ptr bounds = + std::make_shared(y2, y1, z, x1); + auto rotationAngle = M_PI; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(transform.rotation() * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX()) * + Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitZ()) * + Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitX())); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortalsAndSurfaces())); + } + } else { + throw std::runtime_error("FATAL: Translating GeoTrd to ACTS failed"); + } } else if (shape.typeID() == GeoShapeUnion::getClassTypeID()) { - // Get the bounding box of the union - double xmin{0}; - double xmax{0}; - double ymin{0}; - double ymax{0}; - double zmin{0}; - double zmax{0}; - const GeoShapeUnion& unionShape = static_cast(shape); - unionShape.extent(xmin, ymin, zmin, xmax, ymax, zmax); - std::shared_ptr bounds = - std::make_shared(xmax - xmin, ymax - ymin, - zmax - zmin); - return Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortalsAndSurfaces()); - } else if (shape.typeID() == GeoShapeSubtraction::getClassTypeID()) { - // Go down the left side (opA) of the subtraction until we reach a normal - // shape - const GeoShapeSubtraction& subtractionShape = - static_cast(shape); - const GeoShape* shapeA = subtractionShape.getOpA(); - return convertVolume(context, *shapeA, name, transform); + const GeoShapeUnion& unionShape = static_cast(shape); + const GeoShape* shapeA = unionShape.getOpA(); + const GeoShape* shapeB = unionShape.getOpB(); + convertVolume(context, *shapeA, name+"A", transform, volumes); + convertVolume(context, *shapeB, name+"B", transform, volumes); + } else if (shape.typeID() == GeoShapeSubtraction::getClassTypeID()) { + // Go down the left side (opA) of the subtraction until we reach a normal + // shape + const GeoShapeSubtraction& subtractionShape = + static_cast(shape); + const GeoShape* shapeA = subtractionShape.getOpA(); + convertVolume(context, *shapeA, name, transform, volumes); } else if (shape.typeID() == GeoPcon::getClassTypeID()) { - // Will change in future, get bounding box for now - double xmin{0}; - double xmax{0}; - double ymin{0}; - double ymax{0}; - double zmin{0}; - double zmax{0}; - const GeoPcon& pcon = static_cast(shape); - pcon.extent(xmin, ymin, zmin, xmax, ymax, zmax); - std::shared_ptr bounds = - std::make_shared(xmax - xmin, ymax - ymin, - zmax - zmin); - return Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortalsAndSurfaces()); + // Will change in future, get bounding box for now + double xmin{0}, xmax{0}, ymin{0}, ymax{0}, zmin{0}, zmax{0}; + const GeoPcon& pcon = static_cast(shape); + pcon.extent(xmin, ymin, zmin, xmax, ymax, zmax); + std::shared_ptr bounds = + std::make_shared((xmax - xmin)/2, (ymax - ymin)/2, + (zmax - zmin)/2); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortalsAndSurfaces())); } if (shape.typeID() == GeoShapeShift::getClassTypeID()) { - const GeoShapeShift& shiftShape = static_cast(shape); - const GeoShape* shapeOp = shiftShape.getOp(); - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation()); - newTransform.translate(shiftShape.getX().translation()); - return convertVolume(context, *shapeOp, name, newTransform); + const GeoShapeShift& shiftShape = static_cast(shape); + const GeoShape* shapeOp = shiftShape.getOp(); + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(transform.rotation()); + newTransform.translate(shiftShape.getX().translation()); + newTransform.rotate(shiftShape.getX().rotation()); + convertVolume(context, *shapeOp, name, newTransform, volumes); } - throw std::runtime_error("Unknown shape type: " + shape.type()); } } // namespace GeoModel } // namespace Acts From e6c8ac0c0973be7e63b1d4a10760ca36e91e99ff Mon Sep 17 00:00:00 2001 From: Matt Harris Date: Thu, 4 Jul 2024 11:34:17 +0200 Subject: [PATCH 15/29] format fix --- .../src/GeoModelMaterialConverter.cpp | 43 +-- Plugins/GeoModel/src/GeoModelToDetVol.cpp | 267 +++++++++--------- 2 files changed, 158 insertions(+), 152 deletions(-) diff --git a/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp b/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp index 88f3fe6f1cb..a5106625c78 100644 --- a/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp +++ b/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp @@ -13,26 +13,27 @@ #include "GeoModelKernel/GeoMaterial.h" #include "GeoModelKernel/Units.h" namespace { - constexpr double s_densityCnvFactor = 1./ GeoModelKernelUnits::gram; +constexpr double s_densityCnvFactor = 1. / GeoModelKernelUnits::gram; } -Acts::Material Acts::GeoModel::GeoMaterialConverter::convert(const GeoMaterial* gm, bool useMolarDensity) { - double x0 = gm->getRadLength(); - double l0 = gm->getIntLength(); - double density = gm->getDensity() * s_densityCnvFactor; - double A = 0.; - double Z = 0.; - //Get number elements - int numberOfElements = gm->getNumElements(); - //Loop - for(int iEl = 0; iEl < numberOfElements; ++iEl) { - const GeoElement* geoEl = gm->getElement(iEl); - double fraction = gm->getFraction(iEl); - A += fraction * (geoEl->getA() / GeoModelKernelUnits::gram); - Z += fraction * geoEl->getZ(); - } - if(molarDensity) { - return Material::fromMolarDensity(x0, l0, A, Z, density); - } else{ - return Material::fromMassDensity(x0, l0, A, Z, density); - } +Acts::Material Acts::GeoModel::GeoMaterialConverter::convert( + const GeoMaterial* gm, bool useMolarDensity) { + double x0 = gm->getRadLength(); + double l0 = gm->getIntLength(); + double density = gm->getDensity() * s_densityCnvFactor; + double A = 0.; + double Z = 0.; + // Get number elements + int numberOfElements = gm->getNumElements(); + // Loop + for (int iEl = 0; iEl < numberOfElements; ++iEl) { + const GeoElement* geoEl = gm->getElement(iEl); + double fraction = gm->getFraction(iEl); + A += fraction * (geoEl->getA() / GeoModelKernelUnits::gram); + Z += fraction * geoEl->getZ(); + } + if (molarDensity) { + return Material::fromMolarDensity(x0, l0, A, Z, density); + } else { + return Material::fromMassDensity(x0, l0, A, Z, density); + } } diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp index 6c8eb9309d4..4aea23020db 100644 --- a/Plugins/GeoModel/src/GeoModelToDetVol.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -30,147 +30,152 @@ namespace Acts { namespace GeoModel { void convertVolume( - const GeometryContext& context, const GeoShape& shape, - const std::string& name, const Transform3& transform, - std::vector>& volumes) { + const GeometryContext& context, const GeoShape& shape, + const std::string& name, const Transform3& transform, + std::vector>& volumes) { auto portalGenerator = Experimental::defaultPortalAndSubPortalGenerator(); if (shape.typeID() == GeoTube::getClassTypeID()) { - const GeoTube& tube = static_cast(shape); - std::shared_ptr bounds = - std::make_shared(tube.getRMin(), tube.getRMax(), - tube.getZHalfLength()); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortalsAndSurfaces())); + const GeoTube& tube = static_cast(shape); + std::shared_ptr bounds = + std::make_shared(tube.getRMin(), tube.getRMax(), + tube.getZHalfLength()); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortalsAndSurfaces())); } else if (shape.typeID() == GeoTubs::getClassTypeID()) { - const GeoTubs& tubs = static_cast(shape); - std::shared_ptr bounds = - std::make_shared(tubs.getRMin(), tubs.getRMax(), - tubs.getZHalfLength(), - tubs.getDPhi() / 2); - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation() * - Eigen::AngleAxisd(tubs.getSPhi() + 0.5 * tubs.getDPhi(), - Acts::Vector3::UnitZ())); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortalsAndSurfaces())); + const GeoTubs& tubs = static_cast(shape); + std::shared_ptr bounds = + std::make_shared(tubs.getRMin(), tubs.getRMax(), + tubs.getZHalfLength(), + tubs.getDPhi() / 2); + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(transform.rotation() * + Eigen::AngleAxisd(tubs.getSPhi() + 0.5 * tubs.getDPhi(), + Acts::Vector3::UnitZ())); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortalsAndSurfaces())); } else if (shape.typeID() == GeoBox::getClassTypeID()) { - const GeoBox& box = static_cast(shape); - std::shared_ptr bounds = - std::make_shared( - box.getXHalfLength(), box.getYHalfLength(), box.getZHalfLength()); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortalsAndSurfaces())); + const GeoBox& box = static_cast(shape); + std::shared_ptr bounds = + std::make_shared( + box.getXHalfLength(), box.getYHalfLength(), box.getZHalfLength()); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortalsAndSurfaces())); } else if (shape.typeID() == GeoSimplePolygonBrep::getClassTypeID()) { - const GeoSimplePolygonBrep& brep = static_cast(shape); - double xmin{0}, xmax{0}, ymin{0}, ymax{0}, zmin{0}, zmax{0}; - brep.extent(xmin, ymin, zmin, xmax, ymax, zmax); - std::shared_ptr bounds = - std::make_shared((xmax - xmin)/2, (ymax - ymin)/2, - (zmax - zmin)/2); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortalsAndSurfaces())); + const GeoSimplePolygonBrep& brep = + static_cast(shape); + double xmin{0}, xmax{0}, ymin{0}, ymax{0}, zmin{0}, zmax{0}; + brep.extent(xmin, ymin, zmin, xmax, ymax, zmax); + std::shared_ptr bounds = + std::make_shared( + (xmax - xmin) / 2, (ymax - ymin) / 2, (zmax - zmin) / 2); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortalsAndSurfaces())); } else if (shape.typeID() == GeoTrd::getClassTypeID()) { - const GeoTrd& trd = static_cast(shape); - double x1 = trd.getXHalfLength1(); - double x2 = trd.getXHalfLength2(); - double y1 = trd.getYHalfLength1(); - double y2 = trd.getYHalfLength2(); - double z = trd.getZHalfLength(); - if (y1 == y2) { - if (x1 <= x2) { - // y axis in ACTS is z axis in geomodel - std::shared_ptr bounds = - std::make_shared(x1, x2, z, y1); - auto rotationAngle = M_PI / 2; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation() * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortalsAndSurfaces())); - } else { - std::shared_ptr bounds = - std::make_shared(x2, x1, z, y1); - auto rotationAngle = M_PI; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation() * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitY()) * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ())); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortalsAndSurfaces())); - } - } else if (x1 == x2) { - if (y1 < y2) { - std::shared_ptr bounds = - std::make_shared(y1, y2, z, x1); - auto rotationAngle = M_PI / 2; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation() * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ()) * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortalsAndSurfaces())); - } else { - std::shared_ptr bounds = - std::make_shared(y2, y1, z, x1); - auto rotationAngle = M_PI; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation() * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX()) * - Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitZ()) * - Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitX())); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortalsAndSurfaces())); - } - } else { - throw std::runtime_error("FATAL: Translating GeoTrd to ACTS failed"); - } + const GeoTrd& trd = static_cast(shape); + double x1 = trd.getXHalfLength1(); + double x2 = trd.getXHalfLength2(); + double y1 = trd.getYHalfLength1(); + double y2 = trd.getYHalfLength2(); + double z = trd.getZHalfLength(); + if (y1 == y2) { + if (x1 <= x2) { + // y axis in ACTS is z axis in geomodel + std::shared_ptr bounds = + std::make_shared(x1, x2, z, y1); + auto rotationAngle = M_PI / 2; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate( + transform.rotation() * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortalsAndSurfaces())); + } else { + std::shared_ptr bounds = + std::make_shared(x2, x1, z, y1); + auto rotationAngle = M_PI; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate( + transform.rotation() * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitY()) * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ())); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortalsAndSurfaces())); + } + } else if (x1 == x2) { + if (y1 < y2) { + std::shared_ptr bounds = + std::make_shared(y1, y2, z, x1); + auto rotationAngle = M_PI / 2; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate( + transform.rotation() * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ()) * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortalsAndSurfaces())); + } else { + std::shared_ptr bounds = + std::make_shared(y2, y1, z, x1); + auto rotationAngle = M_PI; + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate( + transform.rotation() * + Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX()) * + Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitZ()) * + Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitX())); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, newTransform, bounds, + Experimental::tryAllPortalsAndSurfaces())); + } + } else { + throw std::runtime_error("FATAL: Translating GeoTrd to ACTS failed"); + } } else if (shape.typeID() == GeoShapeUnion::getClassTypeID()) { - const GeoShapeUnion& unionShape = static_cast(shape); - const GeoShape* shapeA = unionShape.getOpA(); - const GeoShape* shapeB = unionShape.getOpB(); - convertVolume(context, *shapeA, name+"A", transform, volumes); - convertVolume(context, *shapeB, name+"B", transform, volumes); - } else if (shape.typeID() == GeoShapeSubtraction::getClassTypeID()) { - // Go down the left side (opA) of the subtraction until we reach a normal - // shape - const GeoShapeSubtraction& subtractionShape = - static_cast(shape); - const GeoShape* shapeA = subtractionShape.getOpA(); - convertVolume(context, *shapeA, name, transform, volumes); + const GeoShapeUnion& unionShape = static_cast(shape); + const GeoShape* shapeA = unionShape.getOpA(); + const GeoShape* shapeB = unionShape.getOpB(); + convertVolume(context, *shapeA, name + "A", transform, volumes); + convertVolume(context, *shapeB, name + "B", transform, volumes); + } else if (shape.typeID() == GeoShapeSubtraction::getClassTypeID()) { + // Go down the left side (opA) of the subtraction until we reach a normal + // shape + const GeoShapeSubtraction& subtractionShape = + static_cast(shape); + const GeoShape* shapeA = subtractionShape.getOpA(); + convertVolume(context, *shapeA, name, transform, volumes); } else if (shape.typeID() == GeoPcon::getClassTypeID()) { - // Will change in future, get bounding box for now - double xmin{0}, xmax{0}, ymin{0}, ymax{0}, zmin{0}, zmax{0}; - const GeoPcon& pcon = static_cast(shape); - pcon.extent(xmin, ymin, zmin, xmax, ymax, zmax); - std::shared_ptr bounds = - std::make_shared((xmax - xmin)/2, (ymax - ymin)/2, - (zmax - zmin)/2); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( - portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortalsAndSurfaces())); + // Will change in future, get bounding box for now + double xmin{0}, xmax{0}, ymin{0}, ymax{0}, zmin{0}, zmax{0}; + const GeoPcon& pcon = static_cast(shape); + pcon.extent(xmin, ymin, zmin, xmax, ymax, zmax); + std::shared_ptr bounds = + std::make_shared( + (xmax - xmin) / 2, (ymax - ymin) / 2, (zmax - zmin) / 2); + volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortalsAndSurfaces())); } if (shape.typeID() == GeoShapeShift::getClassTypeID()) { - const GeoShapeShift& shiftShape = static_cast(shape); - const GeoShape* shapeOp = shiftShape.getOp(); - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation()); - newTransform.translate(shiftShape.getX().translation()); - newTransform.rotate(shiftShape.getX().rotation()); - convertVolume(context, *shapeOp, name, newTransform, volumes); + const GeoShapeShift& shiftShape = static_cast(shape); + const GeoShape* shapeOp = shiftShape.getOp(); + Acts::Transform3 newTransform = Acts::Transform3::Identity(); + newTransform.translate(transform.translation()); + newTransform.rotate(transform.rotation()); + newTransform.translate(shiftShape.getX().translation()); + newTransform.rotate(shiftShape.getX().rotation()); + convertVolume(context, *shapeOp, name, newTransform, volumes); } } } // namespace GeoModel From 2792e65fa427094864df947374caa11df200a54c Mon Sep 17 00:00:00 2001 From: Matt Harris Date: Thu, 4 Jul 2024 11:39:06 +0200 Subject: [PATCH 16/29] last format fix i hope --- .../GeoModel/GeoModelMaterialConverter.hpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp index be8e52ad743..a39c44b0025 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp @@ -11,23 +11,23 @@ class GeoMaterial; -namespace Acts{ +namespace Acts { namespace GeoModel { class GeoMaterialConverter { - public: - // Remove default constructor - GeoMaterialConverter() = delete; + public: + // Remove default constructor + GeoMaterialConverter() = delete; - ~GeoMaterialConverter() = default; + ~GeoMaterialConverter() = default; - /// @brief Convert GeoMaterial to Acts::Material - /// - /// @param gm The GeoMaterial to be converted - /// @return the Acts::Material - static Material convert(const GeoMaterial* gm, bool useMolarDensity = true); + /// @brief Convert GeoMaterial to Acts::Material + /// + /// @param gm The GeoMaterial to be converted + /// @return the Acts::Material + static Material convert(const GeoMaterial* gm, bool useMolarDensity = true); -}; // class GeoMaterialConverter -} // namespace GeoModel -} // namespace Acts +}; // class GeoMaterialConverter +} // namespace GeoModel +} // namespace Acts From fe5407916e5ce7099bf699ab52eb1354f016aaa9 Mon Sep 17 00:00:00 2001 From: Matthew Leary Harris Date: Thu, 4 Jul 2024 11:48:31 +0200 Subject: [PATCH 17/29] fix --- Plugins/GeoModel/src/GeoModelMaterialConverter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp b/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp index a5106625c78..d7b7907d01c 100644 --- a/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp +++ b/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp @@ -31,7 +31,7 @@ Acts::Material Acts::GeoModel::GeoMaterialConverter::convert( A += fraction * (geoEl->getA() / GeoModelKernelUnits::gram); Z += fraction * geoEl->getZ(); } - if (molarDensity) { + if (useMolarDensity) { return Material::fromMolarDensity(x0, l0, A, Z, density); } else { return Material::fromMassDensity(x0, l0, A, Z, density); From e89253371e83e37e01446168ecd48552b34acb4d Mon Sep 17 00:00:00 2001 From: Matthew Harris <44590310+Matthewharri@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:03:51 +0200 Subject: [PATCH 18/29] Apply suggestions from code review Co-authored-by: junggjo9 --- Plugins/GeoModel/src/GeoModelToDetVol.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp index 4aea23020db..464830ecf74 100644 --- a/Plugins/GeoModel/src/GeoModelToDetVol.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -87,7 +87,7 @@ void convertVolume( // y axis in ACTS is z axis in geomodel std::shared_ptr bounds = std::make_shared(x1, x2, z, y1); - auto rotationAngle = M_PI / 2; + constexpr double rotationAngle = M_PI / 2; Acts::Transform3 newTransform = Acts::Transform3::Identity(); newTransform.translate(transform.translation()); newTransform.rotate( @@ -99,7 +99,7 @@ void convertVolume( } else { std::shared_ptr bounds = std::make_shared(x2, x1, z, y1); - auto rotationAngle = M_PI; + constexpr double rotationAngle = M_PI; Acts::Transform3 newTransform = Acts::Transform3::Identity(); newTransform.translate(transform.translation()); newTransform.rotate( From 140cd9155c9d4d86e3995ee080312ece5fdc2083 Mon Sep 17 00:00:00 2001 From: Matthew Leary Harris Date: Thu, 4 Jul 2024 12:07:13 +0200 Subject: [PATCH 19/29] fix GeoModelTree.hpp --- Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelTree.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelTree.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelTree.hpp index 1d3ba02e43f..7d1df1b9f3d 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelTree.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelTree.hpp @@ -18,7 +18,7 @@ namespace Acts { struct GeoModelTree { std::shared_ptr geoReader = nullptr; - const GeoVPhysVol* worldVolume = nullptr; + PVConstLink worldVolume{nullptr}; std::string worldVolumeName = "World"; }; } // namespace Acts From b02138730534e3598be7aff527be6b4bf68fc4cd Mon Sep 17 00:00:00 2001 From: Matthew Leary Harris Date: Thu, 4 Jul 2024 12:16:30 +0200 Subject: [PATCH 20/29] switch from class to namespace definition for mat conv --- CMakeLists.txt | 2 +- .../Plugins/GeoModel/GeoModelMaterialConverter.hpp | 11 +---------- Plugins/GeoModel/src/GeoModelMaterialConverter.cpp | 2 +- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7563f77e2c4..ed9dd8fb7de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,7 +197,7 @@ set(_acts_boost_version 1.71.0) set(_acts_dd4hep_version 1.21) set(_acts_edm4hep_version 0.7) set(_acts_eigen3_version 3.3.7) -set(_acts_geomodel_version 6.0.0) +set(_acts_geomodel_version 6.2.0) set(_acts_podio_version 0.16) set(_acts_doxygen_version 1.9.4) set(_acts_hepmc3_version 3.2.1) diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp index a39c44b0025..8ab93528acb 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp @@ -14,20 +14,11 @@ class GeoMaterial; namespace Acts { namespace GeoModel { - -class GeoMaterialConverter { - public: - // Remove default constructor - GeoMaterialConverter() = delete; - - ~GeoMaterialConverter() = default; - /// @brief Convert GeoMaterial to Acts::Material /// /// @param gm The GeoMaterial to be converted /// @return the Acts::Material - static Material convert(const GeoMaterial* gm, bool useMolarDensity = true); + Material geoMaterialConverter(const GeoMaterial* gm, bool useMolarDensity = true); -}; // class GeoMaterialConverter } // namespace GeoModel } // namespace Acts diff --git a/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp b/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp index d7b7907d01c..cf1c38f25d3 100644 --- a/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp +++ b/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp @@ -15,7 +15,7 @@ namespace { constexpr double s_densityCnvFactor = 1. / GeoModelKernelUnits::gram; } -Acts::Material Acts::GeoModel::GeoMaterialConverter::convert( +Acts::Material Acts::GeoModel::geoMaterialConverter( const GeoMaterial* gm, bool useMolarDensity) { double x0 = gm->getRadLength(); double l0 = gm->getIntLength(); From b7463dac4f7ccdcd4e61047c67113cb67408f628 Mon Sep 17 00:00:00 2001 From: Matthew Leary Harris Date: Thu, 4 Jul 2024 12:26:39 +0200 Subject: [PATCH 21/29] parse shape by pointer --- .../Plugins/GeoModel/GeoModelToDetVol.hpp | 2 +- Plugins/GeoModel/src/GeoModelToDetVol.cpp | 90 +++++++++---------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp index 1be9c641f04..e34ec124da5 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp @@ -20,7 +20,7 @@ namespace GeoModel { /// @param transform the transform to be applied /// @return the DetectorVolume void convertVolume( - const GeometryContext& context, const GeoShape& shape, + const GeometryContext& context, const GeoShape* shape, const std::string& name, const Transform3& transform, std::vector>& volumes); } // namespace GeoModel diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp index 464830ecf74..3b8da05fb47 100644 --- a/Plugins/GeoModel/src/GeoModelToDetVol.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -30,58 +30,58 @@ namespace Acts { namespace GeoModel { void convertVolume( - const GeometryContext& context, const GeoShape& shape, + const GeometryContext& context, const GeoShape* shape, const std::string& name, const Transform3& transform, std::vector>& volumes) { auto portalGenerator = Experimental::defaultPortalAndSubPortalGenerator(); - if (shape.typeID() == GeoTube::getClassTypeID()) { - const GeoTube& tube = static_cast(shape); + if (shape->typeID() == GeoTube::getClassTypeID()) { + const GeoTube* tube = static_cast(shape); std::shared_ptr bounds = - std::make_shared(tube.getRMin(), tube.getRMax(), - tube.getZHalfLength()); + std::make_shared(tube->getRMin(), tube->getRMax(), + tube->getZHalfLength()); volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, transform, bounds, Experimental::tryAllPortalsAndSurfaces())); - } else if (shape.typeID() == GeoTubs::getClassTypeID()) { - const GeoTubs& tubs = static_cast(shape); + } else if (shape->typeID() == GeoTubs::getClassTypeID()) { + const GeoTubs* tubs = static_cast(shape); std::shared_ptr bounds = - std::make_shared(tubs.getRMin(), tubs.getRMax(), - tubs.getZHalfLength(), - tubs.getDPhi() / 2); + std::make_shared(tubs->getRMin(), tubs->getRMax(), + tubs->getZHalfLength(), + tubs->getDPhi() / 2); Acts::Transform3 newTransform = Acts::Transform3::Identity(); newTransform.translate(transform.translation()); newTransform.rotate(transform.rotation() * - Eigen::AngleAxisd(tubs.getSPhi() + 0.5 * tubs.getDPhi(), + Eigen::AngleAxisd(tubs->getSPhi() + 0.5 * tubs->getDPhi(), Acts::Vector3::UnitZ())); volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortalsAndSurfaces())); - } else if (shape.typeID() == GeoBox::getClassTypeID()) { - const GeoBox& box = static_cast(shape); + } else if (shape->typeID() == GeoBox::getClassTypeID()) { + const GeoBox* box = static_cast(shape); std::shared_ptr bounds = std::make_shared( - box.getXHalfLength(), box.getYHalfLength(), box.getZHalfLength()); + box->getXHalfLength(), box->getYHalfLength(), box->getZHalfLength()); volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, transform, bounds, Experimental::tryAllPortalsAndSurfaces())); - } else if (shape.typeID() == GeoSimplePolygonBrep::getClassTypeID()) { - const GeoSimplePolygonBrep& brep = - static_cast(shape); + } else if (shape->typeID() == GeoSimplePolygonBrep::getClassTypeID()) { + const GeoSimplePolygonBrep* brep = + static_cast(shape); double xmin{0}, xmax{0}, ymin{0}, ymax{0}, zmin{0}, zmax{0}; - brep.extent(xmin, ymin, zmin, xmax, ymax, zmax); + brep->extent(xmin, ymin, zmin, xmax, ymax, zmax); std::shared_ptr bounds = std::make_shared( (xmax - xmin) / 2, (ymax - ymin) / 2, (zmax - zmin) / 2); volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, transform, bounds, Experimental::tryAllPortalsAndSurfaces())); - } else if (shape.typeID() == GeoTrd::getClassTypeID()) { - const GeoTrd& trd = static_cast(shape); - double x1 = trd.getXHalfLength1(); - double x2 = trd.getXHalfLength2(); - double y1 = trd.getYHalfLength1(); - double y2 = trd.getYHalfLength2(); - double z = trd.getZHalfLength(); + } else if (shape->typeID() == GeoTrd::getClassTypeID()) { + const GeoTrd* trd = static_cast(shape); + double x1 = trd->getXHalfLength1(); + double x2 = trd->getXHalfLength2(); + double y1 = trd->getYHalfLength1(); + double y2 = trd->getYHalfLength2(); + double z = trd->getZHalfLength(); if (y1 == y2) { if (x1 <= x2) { // y axis in ACTS is z axis in geomodel @@ -142,24 +142,24 @@ void convertVolume( } else { throw std::runtime_error("FATAL: Translating GeoTrd to ACTS failed"); } - } else if (shape.typeID() == GeoShapeUnion::getClassTypeID()) { - const GeoShapeUnion& unionShape = static_cast(shape); - const GeoShape* shapeA = unionShape.getOpA(); - const GeoShape* shapeB = unionShape.getOpB(); - convertVolume(context, *shapeA, name + "A", transform, volumes); - convertVolume(context, *shapeB, name + "B", transform, volumes); - } else if (shape.typeID() == GeoShapeSubtraction::getClassTypeID()) { + } else if (shape->typeID() == GeoShapeUnion::getClassTypeID()) { + const GeoShapeUnion* unionShape = static_cast(shape); + const GeoShape* shapeA = unionShape->getOpA(); + const GeoShape* shapeB = unionShape->getOpB(); + convertVolume(context, shapeA, name + "A", transform, volumes); + convertVolume(context, shapeB, name + "B", transform, volumes); + } else if (shape->typeID() == GeoShapeSubtraction::getClassTypeID()) { // Go down the left side (opA) of the subtraction until we reach a normal // shape - const GeoShapeSubtraction& subtractionShape = - static_cast(shape); - const GeoShape* shapeA = subtractionShape.getOpA(); - convertVolume(context, *shapeA, name, transform, volumes); - } else if (shape.typeID() == GeoPcon::getClassTypeID()) { + const GeoShapeSubtraction* subtractionShape = + static_cast(shape); + const GeoShape* shapeA = subtractionShape->getOpA(); + convertVolume(context, shapeA, name, transform, volumes); + } else if (shape->typeID() == GeoPcon::getClassTypeID()) { // Will change in future, get bounding box for now double xmin{0}, xmax{0}, ymin{0}, ymax{0}, zmin{0}, zmax{0}; - const GeoPcon& pcon = static_cast(shape); - pcon.extent(xmin, ymin, zmin, xmax, ymax, zmax); + const GeoPcon* pcon = static_cast(shape); + pcon->extent(xmin, ymin, zmin, xmax, ymax, zmax); std::shared_ptr bounds = std::make_shared( (xmax - xmin) / 2, (ymax - ymin) / 2, (zmax - zmin) / 2); @@ -167,15 +167,15 @@ void convertVolume( portalGenerator, context, name, transform, bounds, Experimental::tryAllPortalsAndSurfaces())); } - if (shape.typeID() == GeoShapeShift::getClassTypeID()) { - const GeoShapeShift& shiftShape = static_cast(shape); - const GeoShape* shapeOp = shiftShape.getOp(); + if (shape->typeID() == GeoShapeShift::getClassTypeID()) { + const GeoShapeShift* shiftShape = static_cast(shape); + const GeoShape* shapeOp = shiftShape->getOp(); Acts::Transform3 newTransform = Acts::Transform3::Identity(); newTransform.translate(transform.translation()); newTransform.rotate(transform.rotation()); - newTransform.translate(shiftShape.getX().translation()); - newTransform.rotate(shiftShape.getX().rotation()); - convertVolume(context, *shapeOp, name, newTransform, volumes); + newTransform.translate(shiftShape->getX().translation()); + newTransform.rotate(shiftShape->getX().rotation()); + convertVolume(context, shapeOp, name, newTransform, volumes); } } } // namespace GeoModel From 35fbd028268c0364b6a2ad06650cff79983327bf Mon Sep 17 00:00:00 2001 From: Matthew Leary Harris Date: Thu, 4 Jul 2024 13:03:23 +0200 Subject: [PATCH 22/29] simplify transforms --- .../Plugins/GeoModel/GeoModelToDetVol.hpp | 4 +- Plugins/GeoModel/src/GeoModelToDetVol.cpp | 42 ++++--------------- 2 files changed, 10 insertions(+), 36 deletions(-) diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp index e34ec124da5..b97bd1b8b2d 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp @@ -9,6 +9,8 @@ #include "Acts/Detector/DetectorVolume.hpp" +#include "GeoModelKernel/GeoDefinitions.h" + class GeoShape; namespace Acts { @@ -21,7 +23,7 @@ namespace GeoModel { /// @return the DetectorVolume void convertVolume( const GeometryContext& context, const GeoShape* shape, - const std::string& name, const Transform3& transform, + const std::string& name, const GeoTrf::Transform3D transform, std::vector>& volumes); } // namespace GeoModel } // namespace Acts diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp index 3b8da05fb47..875c2894e98 100644 --- a/Plugins/GeoModel/src/GeoModelToDetVol.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -31,7 +31,7 @@ namespace Acts { namespace GeoModel { void convertVolume( const GeometryContext& context, const GeoShape* shape, - const std::string& name, const Transform3& transform, + const std::string& name, const GeoTrf::Transform3D transform, std::vector>& volumes) { auto portalGenerator = Experimental::defaultPortalAndSubPortalGenerator(); if (shape->typeID() == GeoTube::getClassTypeID()) { @@ -48,11 +48,7 @@ void convertVolume( std::make_shared(tubs->getRMin(), tubs->getRMax(), tubs->getZHalfLength(), tubs->getDPhi() / 2); - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation() * - Eigen::AngleAxisd(tubs->getSPhi() + 0.5 * tubs->getDPhi(), - Acts::Vector3::UnitZ())); + GeoTrf::Transform3D newTransform = transform * GeoTrf::RotateZ3D(tubs->getSPhi() + 0.5 * tubs->getDPhi()); volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortalsAndSurfaces())); @@ -88,11 +84,7 @@ void convertVolume( std::shared_ptr bounds = std::make_shared(x1, x2, z, y1); constexpr double rotationAngle = M_PI / 2; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate( - transform.rotation() * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); + GeoTrf::Transform3D newTransform = transform * GeoTrf::RotateX3D(rotationAngle); volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortalsAndSurfaces())); @@ -100,12 +92,7 @@ void convertVolume( std::shared_ptr bounds = std::make_shared(x2, x1, z, y1); constexpr double rotationAngle = M_PI; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate( - transform.rotation() * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitY()) * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ())); + GeoTrf::Transform3D newTransform = transform * GeoTrf::RotateY3D(rotationAngle) * GeoTrf::RotateZ3D(rotationAngle); volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortalsAndSurfaces())); @@ -115,12 +102,7 @@ void convertVolume( std::shared_ptr bounds = std::make_shared(y1, y2, z, x1); auto rotationAngle = M_PI / 2; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate( - transform.rotation() * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitZ()) * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX())); + GeoTrf::Transform3D newTransform = transform * GeoTrf::RotateZ3D(rotationAngle) * GeoTrf::RotateX3D(rotationAngle); volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortalsAndSurfaces())); @@ -128,13 +110,7 @@ void convertVolume( std::shared_ptr bounds = std::make_shared(y2, y1, z, x1); auto rotationAngle = M_PI; - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate( - transform.rotation() * - Eigen::AngleAxisd(rotationAngle, Acts::Vector3::UnitX()) * - Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitZ()) * - Eigen::AngleAxisd(rotationAngle / 2, Acts::Vector3::UnitX())); + GeoTrf::Transform3D newTransform = transform * GeoTrf::RotateX3D(rotationAngle) * GeoTrf::RotateZ3D(rotationAngle / 2) * GeoTrf::RotateX3D(rotationAngle / 2); volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortalsAndSurfaces())); @@ -170,11 +146,7 @@ void convertVolume( if (shape->typeID() == GeoShapeShift::getClassTypeID()) { const GeoShapeShift* shiftShape = static_cast(shape); const GeoShape* shapeOp = shiftShape->getOp(); - Acts::Transform3 newTransform = Acts::Transform3::Identity(); - newTransform.translate(transform.translation()); - newTransform.rotate(transform.rotation()); - newTransform.translate(shiftShape->getX().translation()); - newTransform.rotate(shiftShape->getX().rotation()); + GeoTrf::Transform3D newTransform = transform * shiftShape->getX(); convertVolume(context, shapeOp, name, newTransform, volumes); } } From 7c7c3c337fe5c5d4c369b9ed1a26742134da8cdf Mon Sep 17 00:00:00 2001 From: Matt Harris Date: Thu, 4 Jul 2024 13:05:52 +0200 Subject: [PATCH 23/29] format yet again --- .../GeoModel/GeoModelMaterialConverter.hpp | 11 ++++---- .../src/GeoModelMaterialConverter.cpp | 4 +-- Plugins/GeoModel/src/GeoModelToDetVol.cpp | 26 +++++++++++++------ 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp index 8ab93528acb..3e19df13c94 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp @@ -14,11 +14,12 @@ class GeoMaterial; namespace Acts { namespace GeoModel { - /// @brief Convert GeoMaterial to Acts::Material - /// - /// @param gm The GeoMaterial to be converted - /// @return the Acts::Material - Material geoMaterialConverter(const GeoMaterial* gm, bool useMolarDensity = true); +/// @brief Convert GeoMaterial to Acts::Material +/// +/// @param gm The GeoMaterial to be converted +/// @return the Acts::Material +Material geoMaterialConverter(const GeoMaterial* gm, + bool useMolarDensity = true); } // namespace GeoModel } // namespace Acts diff --git a/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp b/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp index cf1c38f25d3..6df13079a72 100644 --- a/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp +++ b/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp @@ -15,8 +15,8 @@ namespace { constexpr double s_densityCnvFactor = 1. / GeoModelKernelUnits::gram; } -Acts::Material Acts::GeoModel::geoMaterialConverter( - const GeoMaterial* gm, bool useMolarDensity) { +Acts::Material Acts::GeoModel::geoMaterialConverter(const GeoMaterial* gm, + bool useMolarDensity) { double x0 = gm->getRadLength(); double l0 = gm->getIntLength(); double density = gm->getDensity() * s_densityCnvFactor; diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp index 875c2894e98..4519ab803bf 100644 --- a/Plugins/GeoModel/src/GeoModelToDetVol.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -48,15 +48,17 @@ void convertVolume( std::make_shared(tubs->getRMin(), tubs->getRMax(), tubs->getZHalfLength(), tubs->getDPhi() / 2); - GeoTrf::Transform3D newTransform = transform * GeoTrf::RotateZ3D(tubs->getSPhi() + 0.5 * tubs->getDPhi()); + GeoTrf::Transform3D newTransform = + transform * GeoTrf::RotateZ3D(tubs->getSPhi() + 0.5 * tubs->getDPhi()); volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortalsAndSurfaces())); } else if (shape->typeID() == GeoBox::getClassTypeID()) { const GeoBox* box = static_cast(shape); std::shared_ptr bounds = - std::make_shared( - box->getXHalfLength(), box->getYHalfLength(), box->getZHalfLength()); + std::make_shared(box->getXHalfLength(), + box->getYHalfLength(), + box->getZHalfLength()); volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, transform, bounds, Experimental::tryAllPortalsAndSurfaces())); @@ -84,7 +86,8 @@ void convertVolume( std::shared_ptr bounds = std::make_shared(x1, x2, z, y1); constexpr double rotationAngle = M_PI / 2; - GeoTrf::Transform3D newTransform = transform * GeoTrf::RotateX3D(rotationAngle); + GeoTrf::Transform3D newTransform = + transform * GeoTrf::RotateX3D(rotationAngle); volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortalsAndSurfaces())); @@ -92,7 +95,9 @@ void convertVolume( std::shared_ptr bounds = std::make_shared(x2, x1, z, y1); constexpr double rotationAngle = M_PI; - GeoTrf::Transform3D newTransform = transform * GeoTrf::RotateY3D(rotationAngle) * GeoTrf::RotateZ3D(rotationAngle); + GeoTrf::Transform3D newTransform = transform * + GeoTrf::RotateY3D(rotationAngle) * + GeoTrf::RotateZ3D(rotationAngle); volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortalsAndSurfaces())); @@ -102,7 +107,9 @@ void convertVolume( std::shared_ptr bounds = std::make_shared(y1, y2, z, x1); auto rotationAngle = M_PI / 2; - GeoTrf::Transform3D newTransform = transform * GeoTrf::RotateZ3D(rotationAngle) * GeoTrf::RotateX3D(rotationAngle); + GeoTrf::Transform3D newTransform = transform * + GeoTrf::RotateZ3D(rotationAngle) * + GeoTrf::RotateX3D(rotationAngle); volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortalsAndSurfaces())); @@ -110,7 +117,10 @@ void convertVolume( std::shared_ptr bounds = std::make_shared(y2, y1, z, x1); auto rotationAngle = M_PI; - GeoTrf::Transform3D newTransform = transform * GeoTrf::RotateX3D(rotationAngle) * GeoTrf::RotateZ3D(rotationAngle / 2) * GeoTrf::RotateX3D(rotationAngle / 2); + GeoTrf::Transform3D newTransform = + transform * GeoTrf::RotateX3D(rotationAngle) * + GeoTrf::RotateZ3D(rotationAngle / 2) * + GeoTrf::RotateX3D(rotationAngle / 2); volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, Experimental::tryAllPortalsAndSurfaces())); @@ -146,7 +156,7 @@ void convertVolume( if (shape->typeID() == GeoShapeShift::getClassTypeID()) { const GeoShapeShift* shiftShape = static_cast(shape); const GeoShape* shapeOp = shiftShape->getOp(); - GeoTrf::Transform3D newTransform = transform * shiftShape->getX(); + GeoTrf::Transform3D newTransform = transform * shiftShape->getX(); convertVolume(context, shapeOp, name, newTransform, volumes); } } From 8761e4a558b9d9b992eeefd7ee234721cebc1c9f Mon Sep 17 00:00:00 2001 From: Matthew Leary Harris Date: Thu, 11 Jul 2024 09:38:07 +0200 Subject: [PATCH 24/29] move to 6.3.0 and change to returning a volume instead of vector --- CMakeLists.txt | 2 +- .../Plugins/GeoModel/GeoModelToDetVol.hpp | 5 +- Plugins/GeoModel/src/GeoModelToDetVol.cpp | 58 ++++++++++--------- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed9dd8fb7de..1d613601fd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,7 +197,7 @@ set(_acts_boost_version 1.71.0) set(_acts_dd4hep_version 1.21) set(_acts_edm4hep_version 0.7) set(_acts_eigen3_version 3.3.7) -set(_acts_geomodel_version 6.2.0) +set(_acts_geomodel_version 6.3.0) set(_acts_podio_version 0.16) set(_acts_doxygen_version 1.9.4) set(_acts_hepmc3_version 3.2.1) diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp index b97bd1b8b2d..118bbc4749b 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp @@ -21,9 +21,8 @@ namespace GeoModel { /// @param shape the GeoModel shape /// @param transform the transform to be applied /// @return the DetectorVolume -void convertVolume( +std::shared_ptr convertVolume( const GeometryContext& context, const GeoShape* shape, - const std::string& name, const GeoTrf::Transform3D transform, - std::vector>& volumes); + const std::string& name, const GeoTrf::Transform3D transform); } // namespace GeoModel } // namespace Acts diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetVol.cpp index 4519ab803bf..051c5ab2354 100644 --- a/Plugins/GeoModel/src/GeoModelToDetVol.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetVol.cpp @@ -29,19 +29,18 @@ namespace Acts { namespace GeoModel { -void convertVolume( +std::shared_ptr convertVolume( const GeometryContext& context, const GeoShape* shape, - const std::string& name, const GeoTrf::Transform3D transform, - std::vector>& volumes) { + const std::string& name, const GeoTrf::Transform3D transform) { auto portalGenerator = Experimental::defaultPortalAndSubPortalGenerator(); if (shape->typeID() == GeoTube::getClassTypeID()) { const GeoTube* tube = static_cast(shape); std::shared_ptr bounds = std::make_shared(tube->getRMin(), tube->getRMax(), tube->getZHalfLength()); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortalsAndSurfaces())); + Experimental::tryAllPortalsAndSurfaces()); } else if (shape->typeID() == GeoTubs::getClassTypeID()) { const GeoTubs* tubs = static_cast(shape); std::shared_ptr bounds = @@ -50,18 +49,18 @@ void convertVolume( tubs->getDPhi() / 2); GeoTrf::Transform3D newTransform = transform * GeoTrf::RotateZ3D(tubs->getSPhi() + 0.5 * tubs->getDPhi()); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortalsAndSurfaces())); + Experimental::tryAllPortalsAndSurfaces()); } else if (shape->typeID() == GeoBox::getClassTypeID()) { const GeoBox* box = static_cast(shape); std::shared_ptr bounds = std::make_shared(box->getXHalfLength(), box->getYHalfLength(), box->getZHalfLength()); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortalsAndSurfaces())); + Experimental::tryAllPortalsAndSurfaces()); } else if (shape->typeID() == GeoSimplePolygonBrep::getClassTypeID()) { const GeoSimplePolygonBrep* brep = static_cast(shape); @@ -70,9 +69,9 @@ void convertVolume( std::shared_ptr bounds = std::make_shared( (xmax - xmin) / 2, (ymax - ymin) / 2, (zmax - zmin) / 2); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortalsAndSurfaces())); + Experimental::tryAllPortalsAndSurfaces()); } else if (shape->typeID() == GeoTrd::getClassTypeID()) { const GeoTrd* trd = static_cast(shape); double x1 = trd->getXHalfLength1(); @@ -88,9 +87,9 @@ void convertVolume( constexpr double rotationAngle = M_PI / 2; GeoTrf::Transform3D newTransform = transform * GeoTrf::RotateX3D(rotationAngle); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortalsAndSurfaces())); + Experimental::tryAllPortalsAndSurfaces()); } else { std::shared_ptr bounds = std::make_shared(x2, x1, z, y1); @@ -98,9 +97,9 @@ void convertVolume( GeoTrf::Transform3D newTransform = transform * GeoTrf::RotateY3D(rotationAngle) * GeoTrf::RotateZ3D(rotationAngle); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortalsAndSurfaces())); + Experimental::tryAllPortalsAndSurfaces()); } } else if (x1 == x2) { if (y1 < y2) { @@ -110,9 +109,9 @@ void convertVolume( GeoTrf::Transform3D newTransform = transform * GeoTrf::RotateZ3D(rotationAngle) * GeoTrf::RotateX3D(rotationAngle); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortalsAndSurfaces())); + Experimental::tryAllPortalsAndSurfaces()); } else { std::shared_ptr bounds = std::make_shared(y2, y1, z, x1); @@ -121,26 +120,30 @@ void convertVolume( transform * GeoTrf::RotateX3D(rotationAngle) * GeoTrf::RotateZ3D(rotationAngle / 2) * GeoTrf::RotateX3D(rotationAngle / 2); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, newTransform, bounds, - Experimental::tryAllPortalsAndSurfaces())); + Experimental::tryAllPortalsAndSurfaces()); } } else { throw std::runtime_error("FATAL: Translating GeoTrd to ACTS failed"); } } else if (shape->typeID() == GeoShapeUnion::getClassTypeID()) { const GeoShapeUnion* unionShape = static_cast(shape); - const GeoShape* shapeA = unionShape->getOpA(); - const GeoShape* shapeB = unionShape->getOpB(); - convertVolume(context, shapeA, name + "A", transform, volumes); - convertVolume(context, shapeB, name + "B", transform, volumes); + double xmin{0}, xmax{0}, ymin{0}, ymax{0}, zmin{0}, zmax{0}; + unionShape->extent(xmin, ymin, zmin, xmax, ymax, zmax); + std::shared_ptr bounds = + std::make_shared( + (xmax - xmin) / 2, (ymax - ymin) / 2, (zmax - zmin) / 2); + return Experimental::DetectorVolumeFactory::construct( + portalGenerator, context, name, transform, bounds, + Experimental::tryAllPortalsAndSurfaces()); } else if (shape->typeID() == GeoShapeSubtraction::getClassTypeID()) { // Go down the left side (opA) of the subtraction until we reach a normal // shape const GeoShapeSubtraction* subtractionShape = static_cast(shape); const GeoShape* shapeA = subtractionShape->getOpA(); - convertVolume(context, shapeA, name, transform, volumes); + return convertVolume(context, shapeA, name, transform); } else if (shape->typeID() == GeoPcon::getClassTypeID()) { // Will change in future, get bounding box for now double xmin{0}, xmax{0}, ymin{0}, ymax{0}, zmin{0}, zmax{0}; @@ -149,16 +152,17 @@ void convertVolume( std::shared_ptr bounds = std::make_shared( (xmax - xmin) / 2, (ymax - ymin) / 2, (zmax - zmin) / 2); - volumes.emplace_back(Experimental::DetectorVolumeFactory::construct( + return Experimental::DetectorVolumeFactory::construct( portalGenerator, context, name, transform, bounds, - Experimental::tryAllPortalsAndSurfaces())); + Experimental::tryAllPortalsAndSurfaces()); } if (shape->typeID() == GeoShapeShift::getClassTypeID()) { const GeoShapeShift* shiftShape = static_cast(shape); const GeoShape* shapeOp = shiftShape->getOp(); GeoTrf::Transform3D newTransform = transform * shiftShape->getX(); - convertVolume(context, shapeOp, name, newTransform, volumes); + return convertVolume(context, shapeOp, name, newTransform); } + throw std::runtime_error("FATAL: Unsupported GeoModel shape"); } } // namespace GeoModel } // namespace Acts From 1a5afbbaa3f4c7bbbd32914b54e815f61997e72d Mon Sep 17 00:00:00 2001 From: Matthew Leary Harris Date: Fri, 2 Aug 2024 10:27:39 +0200 Subject: [PATCH 25/29] fix build issue + renaming --- Plugins/GeoModel/CMakeLists.txt | 4 ++-- .../{GeoModelToDetVol.hpp => GeoModelToDetectorVolume.hpp} | 0 Plugins/GeoModel/src/GeoModelBlueprintCreater.cpp | 2 +- .../{GeoModelToDetVol.cpp => GeoModelToDetectorVolume.cpp} | 2 +- cmake/ActsConfig.cmake.in | 3 --- 5 files changed, 4 insertions(+), 7 deletions(-) rename Plugins/GeoModel/include/Acts/Plugins/GeoModel/{GeoModelToDetVol.hpp => GeoModelToDetectorVolume.hpp} (100%) rename Plugins/GeoModel/src/{GeoModelToDetVol.cpp => GeoModelToDetectorVolume.cpp} (99%) diff --git a/Plugins/GeoModel/CMakeLists.txt b/Plugins/GeoModel/CMakeLists.txt index 933fb8a19d3..314df1a2b61 100644 --- a/Plugins/GeoModel/CMakeLists.txt +++ b/Plugins/GeoModel/CMakeLists.txt @@ -4,7 +4,7 @@ add_library( ActsPluginGeoModel SHARED src/GeoModelBlueprintCreater.cpp src/GeoModelConversionError.cpp - src/GeoModelToDetVol.cpp + src/GeoModelToDetectorVolume.cpp src/GeoModelReader.cpp src/GeoModelDetectorElement.cpp src/GeoModelDetectorSurfaceFactory.cpp @@ -24,7 +24,7 @@ target_include_directories( $) target_link_libraries( ActsPluginGeoModel - PUBLIC ActsCore GeoModelCore::GeoModelKernel GeoModelCore::GeoModelHelpers GeoModelIO::GeoModelDBManager GeoModelIO::GeoModelRead) + PUBLIC ActsCore GeoModelCore::GeoModelKernel GeoModelIO::GeoModelDBManager GeoModelIO::GeoModelRead) install( TARGETS ActsPluginGeoModel diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetectorVolume.hpp similarity index 100% rename from Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetVol.hpp rename to Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetectorVolume.hpp diff --git a/Plugins/GeoModel/src/GeoModelBlueprintCreater.cpp b/Plugins/GeoModel/src/GeoModelBlueprintCreater.cpp index 3f12c01037d..d94b63e687b 100644 --- a/Plugins/GeoModel/src/GeoModelBlueprintCreater.cpp +++ b/Plugins/GeoModel/src/GeoModelBlueprintCreater.cpp @@ -40,7 +40,7 @@ Acts::GeoModelBlueprintCreater::create(const GeometryContext& gctx, "GeoModelBlueprintCreater: GeoModelTree has no GeoModelReader"); } - auto blueprintTable = gmTree.geoReader->getTableFromTableName(options.table); + auto blueprintTable = gmTree.geoReader->getTableFromTableName_String(options.table); // Prepare the map std::map blueprintTableMap; diff --git a/Plugins/GeoModel/src/GeoModelToDetVol.cpp b/Plugins/GeoModel/src/GeoModelToDetectorVolume.cpp similarity index 99% rename from Plugins/GeoModel/src/GeoModelToDetVol.cpp rename to Plugins/GeoModel/src/GeoModelToDetectorVolume.cpp index 051c5ab2354..74059936230 100644 --- a/Plugins/GeoModel/src/GeoModelToDetVol.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetectorVolume.cpp @@ -6,7 +6,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -#include "Acts/Plugins/GeoModel/GeoModelToDetVol.hpp" +#include "Acts/Plugins/GeoModel/GeoModelToDetectorVolume.hpp" #include "Acts/Detector/GeometryIdGenerator.hpp" #include "Acts/Detector/PortalGenerators.hpp" diff --git a/cmake/ActsConfig.cmake.in b/cmake/ActsConfig.cmake.in index fab76b8a734..362f293ce19 100644 --- a/cmake/ActsConfig.cmake.in +++ b/cmake/ActsConfig.cmake.in @@ -67,9 +67,6 @@ endif() if(PluginTGeo IN_LIST Acts_COMPONENTS) find_dependency(ROOT @ROOT_VERSION@ CONFIG EXACT) endif() -if(PluginGeoModel IN_LIST Acts_COMPONENTS) - find_dependency(GeoModelIO @GeoModelIO_VERSION@ CONFIG EXACT) -endif() if(PluginActSVG IN_LIST Acts_COMPONENTS) find_dependency(actsvg @actsvg_VERSION@ CONFIG EXACT) endif() From 68d51a094ca4fc3beff41d3ac44ce9c66f27e148 Mon Sep 17 00:00:00 2001 From: Matt Harris Date: Fri, 2 Aug 2024 10:32:04 +0200 Subject: [PATCH 26/29] fix format --- Plugins/GeoModel/src/GeoModelBlueprintCreater.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Plugins/GeoModel/src/GeoModelBlueprintCreater.cpp b/Plugins/GeoModel/src/GeoModelBlueprintCreater.cpp index d94b63e687b..7495f8cca39 100644 --- a/Plugins/GeoModel/src/GeoModelBlueprintCreater.cpp +++ b/Plugins/GeoModel/src/GeoModelBlueprintCreater.cpp @@ -40,7 +40,8 @@ Acts::GeoModelBlueprintCreater::create(const GeometryContext& gctx, "GeoModelBlueprintCreater: GeoModelTree has no GeoModelReader"); } - auto blueprintTable = gmTree.geoReader->getTableFromTableName_String(options.table); + auto blueprintTable = + gmTree.geoReader->getTableFromTableName_String(options.table); // Prepare the map std::map blueprintTableMap; From 247f90cecc7ffaf50502e8d32a473e2cf40301a1 Mon Sep 17 00:00:00 2001 From: Matthew Leary Harris Date: Fri, 2 Aug 2024 11:04:53 +0200 Subject: [PATCH 27/29] change the version to fetch from gitlab --- cmake/ActsExternSources.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/ActsExternSources.cmake b/cmake/ActsExternSources.cmake index 95559701a04..86951dddfd1 100644 --- a/cmake/ActsExternSources.cmake +++ b/cmake/ActsExternSources.cmake @@ -31,7 +31,7 @@ set( ACTS_FRNN_SOURCE mark_as_advanced( ACTS_FRNN_SOURCE ) set( ACTS_GEOMODEL_SOURCE - "GIT_REPOSITORY;https://gitlab.cern.ch/GeoModelDev/GeoModel;GIT_TAG;4.6.0;" CACHE STRING "Source to take GeoModel from") + "GIT_REPOSITORY;https://gitlab.cern.ch/GeoModelDev/GeoModel;GIT_TAG;6.3.0;" CACHE STRING "Source to take GeoModel from") mark_as_advanced( ACTS_GEOMODEL_SOURCE ) set( ACTS_NLOHMANNJSON_SOURCE From f457684c8fdf0606a79694653460976e293453cf Mon Sep 17 00:00:00 2001 From: Matthew Leary Harris <44590310+Matthewharri@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:16:04 +0200 Subject: [PATCH 28/29] Apply suggestions from code review Co-authored-by: Andreas Stefl --- .../Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp | 7 +++---- .../Acts/Plugins/GeoModel/GeoModelToDetectorVolume.hpp | 8 ++++---- Plugins/GeoModel/src/GeoModelToDetectorVolume.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp index 3e19df13c94..bde01e92f60 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp @@ -5,15 +5,15 @@ // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "Acts/Material/Material.hpp" class GeoMaterial; -namespace Acts { +namespace Acts::GeoModel { -namespace GeoModel { /// @brief Convert GeoMaterial to Acts::Material /// /// @param gm The GeoMaterial to be converted @@ -21,5 +21,4 @@ namespace GeoModel { Material geoMaterialConverter(const GeoMaterial* gm, bool useMolarDensity = true); -} // namespace GeoModel -} // namespace Acts +} // namespace Acts::GeoModel diff --git a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetectorVolume.hpp b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetectorVolume.hpp index 118bbc4749b..e71863a49b6 100644 --- a/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetectorVolume.hpp +++ b/Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetectorVolume.hpp @@ -5,6 +5,7 @@ // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "Acts/Detector/DetectorVolume.hpp" @@ -13,9 +14,8 @@ class GeoShape; -namespace Acts { +namespace Acts::GeoModel { -namespace GeoModel { /// @brief Convert a GeoModel shape to a DetectorVolume /// /// @param shape the GeoModel shape @@ -24,5 +24,5 @@ namespace GeoModel { std::shared_ptr convertVolume( const GeometryContext& context, const GeoShape* shape, const std::string& name, const GeoTrf::Transform3D transform); -} // namespace GeoModel -} // namespace Acts + +} // namespace Acts::GeoModel diff --git a/Plugins/GeoModel/src/GeoModelToDetectorVolume.cpp b/Plugins/GeoModel/src/GeoModelToDetectorVolume.cpp index 74059936230..2b567337f2e 100644 --- a/Plugins/GeoModel/src/GeoModelToDetectorVolume.cpp +++ b/Plugins/GeoModel/src/GeoModelToDetectorVolume.cpp @@ -27,8 +27,8 @@ #include #include -namespace Acts { -namespace GeoModel { +namespace Acts::GeoModel { + std::shared_ptr convertVolume( const GeometryContext& context, const GeoShape* shape, const std::string& name, const GeoTrf::Transform3D transform) { @@ -164,5 +164,5 @@ std::shared_ptr convertVolume( } throw std::runtime_error("FATAL: Unsupported GeoModel shape"); } -} // namespace GeoModel -} // namespace Acts + +} // namespace Acts::GeoModel From d5b763af275d279add283fd90f57d359e08a5466 Mon Sep 17 00:00:00 2001 From: Matthew Leary Harris <44590310+Matthewharri@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:21:51 +0200 Subject: [PATCH 29/29] move converison constant into function --- Plugins/GeoModel/src/GeoModelMaterialConverter.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp b/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp index 6df13079a72..e60dbca87ed 100644 --- a/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp +++ b/Plugins/GeoModel/src/GeoModelMaterialConverter.cpp @@ -12,14 +12,13 @@ #include "GeoModelKernel/GeoMaterial.h" #include "GeoModelKernel/Units.h" -namespace { -constexpr double s_densityCnvFactor = 1. / GeoModelKernelUnits::gram; -} + Acts::Material Acts::GeoModel::geoMaterialConverter(const GeoMaterial* gm, bool useMolarDensity) { + constexpr double densityCnvFactor = 1. / GeoModelKernelUnits::gram; double x0 = gm->getRadLength(); double l0 = gm->getIntLength(); - double density = gm->getDensity() * s_densityCnvFactor; + double density = gm->getDensity() * densityCnvFactor; double A = 0.; double Z = 0.; // Get number elements