Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: GeoShapes to DetectorVolumes and GeoMaterial Converters #3268

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5c69706
Changes to fix finding geomodel on system and first round of converter
Jun 3, 2024
daaf5b8
format changes
Jun 7, 2024
0700fc7
Changes to fix finding geomodel on system and first round of converter
Jun 3, 2024
891280f
format changes
Jun 7, 2024
15612c9
fix
Jun 7, 2024
b8712b4
small changes
Jun 7, 2024
fa55d0e
Final changes for using system geomodel
Jun 7, 2024
656c771
oops
Jun 7, 2024
b0c1a09
Merge branch 'main' into geoShapeToDetVol
Matthewharri Jun 12, 2024
1660a53
Use forward declare and move around some includes
Jun 13, 2024
a7fb341
Change to GeoModel namespace
Jun 13, 2024
53334ab
fix format
Jun 13, 2024
6b016ca
change from dynamic_cast to static_cast
Jun 17, 2024
cd12571
Address Johannes comments
Jun 28, 2024
47547d9
bump GeoModel to 6.0.0 and add GeoMaterial converter
Jul 4, 2024
c418f5b
Changes to DetVol converter
Jul 4, 2024
e6c8ac0
format fix
Jul 4, 2024
2792e65
last format fix i hope
Jul 4, 2024
fe54079
fix
Jul 4, 2024
e892533
Apply suggestions from code review
Matthewharri Jul 4, 2024
140cd91
fix GeoModelTree.hpp
Jul 4, 2024
b021387
switch from class to namespace definition for mat conv
Jul 4, 2024
b7463da
parse shape by pointer
Jul 4, 2024
35fbd02
simplify transforms
Jul 4, 2024
7c7c3c3
format yet again
Jul 4, 2024
8761e4a
move to 6.3.0 and change to returning a volume instead of vector
Jul 11, 2024
6fdc26b
Merge branch 'main' into geoShapeToDetVol
Matthewharri Jul 11, 2024
47b7235
Merge branch 'main' into geoShapeToDetVol
Matthewharri Jul 19, 2024
a052cfc
Merge branch 'main' into geoShapeToDetVol
Matthewharri Jul 30, 2024
1a5afbb
fix build issue + renaming
Aug 2, 2024
68d51a0
fix format
Aug 2, 2024
247f90c
change the version to fetch from gitlab
Aug 2, 2024
787daf5
Merge branch 'geoShapeToDetVol' of github.com:Matthewharri/acts into …
Aug 2, 2024
4a140af
Merge branch 'main' into geoShapeToDetVol
Matthewharri Aug 19, 2024
f457684
Apply suggestions from code review
Matthewharri Aug 19, 2024
d5b763a
move converison constant into function
Matthewharri Aug 19, 2024
7608689
Merge branch 'main' into geoShapeToDetVol
Matthewharri Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ 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)
Matthewharri marked this conversation as resolved.
Show resolved Hide resolved
set(_acts_podio_version 0.16)
set(_acts_doxygen_version 1.9.4)
set(_acts_hepmc3_version 3.2.1)
Expand Down Expand Up @@ -348,7 +348,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(GeoModelIO ${_acts_geomodel_version} COMPONENTS GeoModelDBManager GeoModelRead REQUIRED CONFIG)
else()
add_subdirectory(thirdparty/GeoModel)
endif()
Expand Down
3 changes: 2 additions & 1 deletion Plugins/GeoModel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include(FetchContent)
add_library(
ActsPluginGeoModel SHARED
src/GeoModelConversionError.cpp
src/GeoModelToDetVol.cpp
src/GeoModelReader.cpp
src/GeoModelDetectorElement.cpp
src/GeoModelDetectorSurfaceFactory.cpp
Expand All @@ -19,7 +20,7 @@ target_include_directories(
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_link_libraries(
ActsPluginGeoModel
PUBLIC ActsCore GeoModelKernel GeoModelIO::GeoModelDBManager GeoModelIO::GeoModelRead)
PUBLIC ActsCore GeoModelCore::GeoModelKernel GeoModelIO::GeoModelDBManager GeoModelIO::GeoModelRead)

install(
TARGETS ActsPluginGeoModel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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/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"

namespace Acts {
namespace GeoModelToDetVol {
Matthewharri marked this conversation as resolved.
Show resolved Hide resolved
/// @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<Experimental::DetectorVolume> convert(
const GeometryContext& context, const GeoShape& shape,
Matthewharri marked this conversation as resolved.
Show resolved Hide resolved
const std::string& name, const Transform3& transform);
Matthewharri marked this conversation as resolved.
Show resolved Hide resolved
} // namespace GeoModelToDetVol
} // namespace Acts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Acts {

struct GeoModelTree {
std::shared_ptr<GeoModelIO::ReadGeoModel> geoReader = nullptr;
GeoVPhysVol* worldVolume = nullptr;
const GeoVPhysVol* worldVolume = nullptr;
Matthewharri marked this conversation as resolved.
Show resolved Hide resolved
Matthewharri marked this conversation as resolved.
Show resolved Hide resolved
std::string worldVolumeName = "World";
};
} // namespace Acts
191 changes: 191 additions & 0 deletions Plugins/GeoModel/src/GeoModelToDetVol.cpp
Matthewharri marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
// 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/InternalNavigation.hpp"

#include <GeoModelKernel/GeoBox.h>
#include <GeoModelKernel/GeoPcon.h>
#include <GeoModelKernel/GeoShapeShift.h>
#include <GeoModelKernel/GeoShapeSubtraction.h>
#include <GeoModelKernel/GeoShapeUnion.h>
#include <GeoModelKernel/GeoSimplePolygonBrep.h>
#include <GeoModelKernel/GeoTrd.h>
#include <GeoModelKernel/GeoTube.h>
#include <GeoModelKernel/GeoTubs.h>

namespace Acts {
namespace GeoModelToDetVol {
std::shared_ptr<Experimental::DetectorVolume> 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<const GeoTube&>(shape);
Matthewharri marked this conversation as resolved.
Show resolved Hide resolved
std::shared_ptr<CylinderVolumeBounds> bounds =
std::make_shared<CylinderVolumeBounds>(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<const GeoTubs&>(shape);
std::shared_ptr<CylinderVolumeBounds> bounds =
std::make_shared<CylinderVolumeBounds>(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<const GeoBox&>(shape);
std::shared_ptr<CuboidVolumeBounds> bounds =
std::make_shared<CuboidVolumeBounds>(
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 =
Matthewharri marked this conversation as resolved.
Show resolved Hide resolved
dynamic_cast<const GeoSimplePolygonBrep&>(shape);
brep.extent(xmin, ymin, zmin, xmax, ymax, zmax);
std::shared_ptr<CuboidVolumeBounds> bounds =
std::make_shared<CuboidVolumeBounds>(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<const GeoTrd&>(shape);
float x1 = trd.getXHalfLength1();
float x2 = trd.getXHalfLength2();
float y1 = trd.getYHalfLength1();
float y2 = trd.getYHalfLength2();
float z = trd.getZHalfLength();
Matthewharri marked this conversation as resolved.
Show resolved Hide resolved
if (y1 == y2) {
if (x1 <= x2) {
// y axis in ACTS is z axis in geomodel
std::shared_ptr<TrapezoidVolumeBounds> bounds =
std::make_shared<TrapezoidVolumeBounds>(x1, x2, z, y1);
auto rotationAngle = M_PI / 2;
Matthewharri marked this conversation as resolved.
Show resolved Hide resolved
Acts::Transform3 newTransform = Acts::Transform3::Identity();
Matthewharri marked this conversation as resolved.
Show resolved Hide resolved
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<TrapezoidVolumeBounds> bounds =
std::make_shared<TrapezoidVolumeBounds>(x2, x1, z, y1);
auto rotationAngle = M_PI;
Matthewharri marked this conversation as resolved.
Show resolved Hide resolved
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<TrapezoidVolumeBounds> bounds =
std::make_shared<TrapezoidVolumeBounds>(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<TrapezoidVolumeBounds> bounds =
std::make_shared<TrapezoidVolumeBounds>(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()) {
// 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<const GeoShapeUnion&>(shape);
unionShape.extent(xmin, ymin, zmin, xmax, ymax, zmax);
std::shared_ptr<CuboidVolumeBounds> bounds =
std::make_shared<CuboidVolumeBounds>(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<const GeoShapeSubtraction&>(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<const GeoPcon&>(shape);
pcon.extent(xmin, ymin, zmin, xmax, ymax, zmax);
std::shared_ptr<CuboidVolumeBounds> bounds =
std::make_shared<CuboidVolumeBounds>(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<const GeoShapeShift&>(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
3 changes: 3 additions & 0 deletions cmake/ActsConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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(GeoModelIO @GeoModelIO_VERSION@ CONFIG EXACT)
endif()
if(PluginActSVG IN_LIST Acts_COMPONENTS)
find_dependency(actsvg @actsvg_VERSION@ CONFIG EXACT)
endif()
Expand Down
Loading