forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: geo model detector elements, converters (acts-project#3256)
Add converters for various shape types to the GeoModel plugin, as well as a factory to read surfaces from a database. Surfaces can be written via a python script to *.obj files for visualization. Built on top of acts-project#3213, add some missing things and restructures the code a bit. Co-authored-by: Andreas Salzburger <[email protected]>
- Loading branch information
1 parent
6b2e205
commit 02de894
Showing
36 changed files
with
2,154 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// 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/Definitions/Algebra.hpp" | ||
|
||
#include <memory> | ||
#include <tuple> | ||
#include <vector> | ||
|
||
namespace Acts { | ||
|
||
class AnnulusBounds; | ||
|
||
namespace detail::AnnulusBoundsHelper { | ||
|
||
/// @brief The factory function to create an annulus bounds | ||
/// | ||
/// @param transform the transform of final surface object | ||
/// @param rMin minimal radius in disc frame | ||
/// @param rMax maximal radius in disc frame | ||
/// @param vertices the vertices of the cutout trapezoid | ||
/// | ||
/// @note - for the time being, the vertices follow ROOT::TGeo convention | ||
/// i.e. [0 - 3] vertices defince clockwise (sic!) the plane at -z | ||
/// and [4 - 7] vertices define clockwise (sic!) the plane at +z | ||
/// | ||
/// @return AnnulusBounds | ||
std::tuple<std::shared_ptr<AnnulusBounds>, Transform3> create( | ||
const Transform3& transform, ActsScalar rMin, ActsScalar rMax, | ||
std::vector<Vector2> vertices); | ||
|
||
} // namespace detail::AnnulusBoundsHelper | ||
} // namespace Acts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 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/Surfaces/detail/AnnulusBoundsHelper.hpp" | ||
|
||
#include "Acts/Surfaces/AnnulusBounds.hpp" | ||
#include "Acts/Utilities/VectorHelpers.hpp" | ||
|
||
#include <iostream> | ||
|
||
std::tuple<std::shared_ptr<Acts::AnnulusBounds>, Acts::Transform3> | ||
Acts::detail::AnnulusBoundsHelper::create(const Transform3& transform, | ||
ActsScalar rMin, ActsScalar rMax, | ||
std::vector<Vector2> vertices) { | ||
using Line2D = Eigen::Hyperplane<double, 2>; | ||
|
||
// Construct the bound lines | ||
std::vector<std::pair<Vector2, Vector2>> boundLines; | ||
for (std::size_t i = 0; i < vertices.size(); ++i) { | ||
Vector2 a = vertices.at(i); | ||
Vector2 b = vertices.at((i + 1) % vertices.size()); | ||
Vector2 ab = b - a; | ||
double phi = VectorHelpers::phi(ab); | ||
|
||
if (std::abs(phi) > 3 * M_PI / 4. || std::abs(phi) < M_PI / 4.) { | ||
if (a.norm() < b.norm()) { | ||
boundLines.push_back(std::make_pair(a, b)); | ||
} else { | ||
boundLines.push_back(std::make_pair(b, a)); | ||
} | ||
} | ||
} | ||
|
||
if (boundLines.size() != 2) { | ||
throw std::logic_error( | ||
"Input DiscPoly bounds type does not have sensible edges."); | ||
} | ||
|
||
Line2D lA = Line2D::Through(boundLines[0].first, boundLines[0].second); | ||
Line2D lB = Line2D::Through(boundLines[1].first, boundLines[1].second); | ||
Vector2 ix = lA.intersection(lB); | ||
|
||
const Eigen::Translation3d originTranslation(ix.x(), ix.y(), 0.); | ||
const Vector2 originShift = -ix; | ||
|
||
// Update transform by prepending the origin shift translation | ||
Transform3 boundsTransform = transform * originTranslation; | ||
// Transform phi line point to new origin and get phi | ||
double phi1 = VectorHelpers::phi(boundLines[0].second - boundLines[0].first); | ||
double phi2 = VectorHelpers::phi(boundLines[1].second - boundLines[1].first); | ||
double phiMax = std::max(phi1, phi2); | ||
double phiMin = std::min(phi1, phi2); | ||
double phiShift = 0.; | ||
|
||
// Create the bounds | ||
auto annulusBounds = std::make_shared<AnnulusBounds>( | ||
rMin, rMax, phiMin, phiMax, originShift, phiShift); | ||
|
||
return std::make_tuple(annulusBounds, boundsTransform); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import acts | ||
import argparse | ||
from acts import logging, GeometryContext | ||
from acts import geomodel as gm | ||
from acts import examples | ||
|
||
|
||
def main(): | ||
p = argparse.ArgumentParser() | ||
|
||
p.add_argument("-i", "--input", type=str, default="", help="Input SQL file") | ||
|
||
p.add_argument( | ||
"-q", | ||
"--queries", | ||
type=str, | ||
nargs="+", | ||
default="GeoModelXML", | ||
help="List of Queries for Published full phys volumes", | ||
) | ||
|
||
p.add_argument( | ||
"--output-obj", | ||
help="Write the surfaces to OBJ files", | ||
action="store_true", | ||
default=False, | ||
) | ||
|
||
args = p.parse_args() | ||
|
||
gContext = acts.GeometryContext() | ||
|
||
# Read the geometry model from the database | ||
gmTree = acts.geomodel.readFromDb(args.input) | ||
|
||
gmFactoryConfig = gm.GeoModelDetectorSurfaceFactory.Config() | ||
gmFactoryConfig.shapeConverters = [ | ||
gm.GeoBoxConverter(), | ||
gm.GeoTrdConverter(), | ||
gm.GeoIntersectionAnnulusConverter(), | ||
gm.GeoShiftConverter(), | ||
gm.GeoUnionDoubleTrdConverter(), | ||
] | ||
gmFactoryConfig.nameList = [] | ||
gmFactoryConfig.materialList = [ | ||
"std::Silicon", | ||
] | ||
|
||
gmFactory = gm.GeoModelDetectorSurfaceFactory(gmFactoryConfig, logging.VERBOSE) | ||
# The options | ||
gmFactoryOptions = gm.GeoModelDetectorSurfaceFactory.Options() | ||
gmFactoryOptions.queries = args.queries | ||
# The Cache & construct call | ||
gmFactoryCache = gm.GeoModelDetectorSurfaceFactory.Cache() | ||
gmFactory.construct(gmFactoryCache, gContext, gmTree, gmFactoryOptions) | ||
|
||
# Output the surface to an OBJ file | ||
segments = 720 | ||
if args.output_obj: | ||
ssurfaces = [ss[1] for ss in gmFactoryCache.sensitiveSurfaces] | ||
acts.examples.writeSurfacesObj( | ||
ssurfaces, gContext, [75, 220, 100], segments, "geomodel.obj" | ||
) | ||
|
||
return | ||
|
||
|
||
if "__main__" == __name__: | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelConversionError.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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 <system_error> | ||
#include <type_traits> | ||
|
||
class GeoFullPhysVol; | ||
|
||
namespace Acts { | ||
|
||
enum class GeoModelConversionError { | ||
// ensure all values are non-zero | ||
WrongShapeForConverter = 1, | ||
InvalidShapeParameters, | ||
UnkownShape, | ||
MissingLogicalVolume | ||
}; | ||
|
||
std::error_code make_error_code(Acts::GeoModelConversionError e); | ||
|
||
} // namespace Acts | ||
|
||
namespace std { | ||
// register with STL | ||
template <> | ||
struct is_error_code_enum<Acts::GeoModelConversionError> : std::true_type {}; | ||
} // namespace std |
Oops, something went wrong.