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: GeoModel plugin changes for ITk building. #3519

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
025527c
it works!
Jul 26, 2024
7dbcc0d
clang-format
Jul 26, 2024
d5efd30
remove some unused stuff
Jul 26, 2024
7bdebc3
update outer pixel
Jul 26, 2024
aaea283
black format
Jul 26, 2024
74e8c7b
remove dead code
Jul 26, 2024
eb25f13
Merge branch 'main' into feature/gen1-itk
Jul 29, 2024
e1b72b6
remove build script / undo unrelated stuff
Jul 29, 2024
d0f914b
remove remaining leftovers
Jul 29, 2024
7e962ff
some changes
Jul 30, 2024
3738431
avoid segfaults in bin adjustments
Aug 2, 2024
83ed5a1
change to dynamic cast only
Aug 2, 2024
1f333f9
format
Aug 2, 2024
18da1de
some python updates
Aug 2, 2024
7b31c7a
refactor bin adjustement again
Aug 2, 2024
aa2fdd9
Merge branch 'main' into feature/gen1-itk-material
Aug 15, 2024
d187a9e
add vertex writing of annulus bounds to CsvTrackingGeometryWriter
Aug 15, 2024
6081497
some hacky changes to get more data
Aug 16, 2024
6acb330
Make some ITk specific stuff work
Aug 19, 2024
250db14
smaller cleanups
Aug 20, 2024
a28cb57
a bit more cleanup
Aug 20, 2024
434d68c
Merge branch 'main' into feature/gen1-itk-material
Aug 20, 2024
7aa89a6
revert changes not related to geomodel
Aug 20, 2024
0e0b7cf
improve doc
Aug 20, 2024
cd509e6
Merge branch 'main' into feature/gen1-itk-geomodel-changes
Aug 21, 2024
478aa87
some renaming, add test
Aug 21, 2024
769f910
update
Aug 21, 2024
615a3e3
fix cmake
Aug 21, 2024
2cadcbb
Merge branch 'main' into feature/gen1-itk-geomodel-changes
Aug 27, 2024
7495699
review
Aug 27, 2024
233486c
update
Aug 27, 2024
a4e32fa
fix
Aug 27, 2024
f336c8f
fix
Aug 27, 2024
ad8b843
fix unittest
Aug 27, 2024
dbdf19c
apply review
Aug 28, 2024
cdcac20
Apply suggestions from code review
benjaminhuth Aug 28, 2024
422840a
revert thing
Aug 28, 2024
93a803a
fix
Aug 28, 2024
038e27d
update
Aug 29, 2024
9614e6b
spelling
Aug 29, 2024
6728429
add test
Aug 29, 2024
5e6e1cb
fix test
Aug 29, 2024
592399a
update
Aug 29, 2024
ffe3ada
Merge branch 'main' into feature/gen1-itk-geomodel-changes
AJPfleger Aug 29, 2024
a64a2a5
Merge branch 'main' into feature/gen1-itk-geomodel-changes
AJPfleger Aug 29, 2024
e16a725
make clang-tidy happy
Aug 29, 2024
1764173
Merge branch 'main' into feature/gen1-itk-geomodel-changes
kodiakhq[bot] Aug 30, 2024
60b5903
change module splitter to be unified with ITk module splitter
Sep 2, 2024
159d4a5
fix
Sep 2, 2024
f44faa3
fix
Sep 3, 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
1 change: 1 addition & 0 deletions Examples/Detectors/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ add_subdirectory(GenericDetector)
add_subdirectory_if(Geant4Detector ACTS_BUILD_EXAMPLES_GEANT4)
add_subdirectory(MagneticField)
add_subdirectory(TGeoDetector)
add_subdirectory(ITkModuleSplitting)
add_subdirectory(TelescopeDetector)
add_subdirectory_if(MuonSpectrometerMockupDetector ACTS_BUILD_EXAMPLES_GEANT4)
7 changes: 7 additions & 0 deletions Examples/Detectors/ITkModuleSplitting/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_library(ActsExamplesITkModuleSplitting INTERFACE)
target_include_directories(
ActsExamplesITkModuleSplitting
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

install(DIRECTORY include/ActsExamples DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// 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 "Acts/Surfaces/AnnulusBounds.hpp"
#include "Acts/Surfaces/RectangleBounds.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Surfaces/SurfaceBounds.hpp"

#include <algorithm>
#include <array>
#include <cstddef>
#include <sstream>

namespace ActsExamples::ITk {

template <typename detector_element_t, typename element_factory_t>
inline std::vector<std::shared_ptr<const detector_element_t>> splitBarrelModule(
const Acts::GeometryContext& gctx,
const std::shared_ptr<const detector_element_t>& detElement,
unsigned int nSegments, const element_factory_t& factory,
const std::string& name,
const Acts::Logger& logger = Acts::getDummyLogger()) {
// Retrieve the surface
const Acts::Surface& surface = detElement->surface();
const Acts::SurfaceBounds& bounds = surface.bounds();
if (bounds.type() != Acts::SurfaceBounds::eRectangle || nSegments <= 1u) {
ACTS_WARNING("Invalid splitting config for barrel node: "
<< name << "! Node will not be slpit.");
return {detElement};
}

// Output container for the submodules
std::vector<std::shared_ptr<const detector_element_t>> detElements = {};
detElements.reserve(nSegments);

// Get the geometric information
const Acts::Transform3& transform = surface.transform(gctx);
// Determine the new bounds
const std::vector<double> boundsValues = bounds.values();

double lengthX = (boundsValues[Acts::RectangleBounds::eMaxX] -
boundsValues[Acts::RectangleBounds::eMinX]) /
nSegments;
double lengthY = boundsValues[Acts::RectangleBounds::eMaxY] -
boundsValues[Acts::RectangleBounds::eMinY];
auto rectBounds =
std::make_shared<Acts::RectangleBounds>(0.5 * lengthX, 0.5 * lengthY);
// Translation for every subelement
auto localTranslation = Acts::Vector2(-0.5 * lengthX * (nSegments - 1), 0.);
const auto step = Acts::Vector2(lengthX, 0.);
ACTS_DEBUG("Rectangle bounds for new node (half length): " +
std::to_string(rectBounds->halfLengthX()) + ", " +
std::to_string(rectBounds->halfLengthY()));

for (std::size_t i = 0; i < nSegments; i++) {
Acts::Vector3 globalTranslation =
surface.localToGlobal(gctx, localTranslation, {}) -
transform.translation();
auto elemTransform =
Acts::Transform3(transform).pretranslate(globalTranslation);
detElements.emplace_back(factory(elemTransform, rectBounds));

localTranslation += step;
}
return detElements;
}

template <typename detector_element_t, typename element_factory_t>
inline std::vector<std::shared_ptr<detector_element_t>> splitDiscModule(
const Acts::GeometryContext& gctx,
const std::shared_ptr<detector_element_t>& detElement,
const std::vector<std::pair<double, double>>& splitRanges,
const element_factory_t& factory, const std::string& name,
const Acts::Logger& logger = Acts::getDummyLogger()) {
// Retrieve the surface
const Acts::Surface& surface = detElement->surface();
const Acts::SurfaceBounds& bounds = surface.bounds();

// Check annulus bounds origin
auto printOrigin = [&](const Acts::Surface& sf) {
Acts::Vector3 discOrigin =
sf.localToGlobal(gctx, Acts::Vector2(0., 0.), Acts::Vector3::Zero());
std::string out =
"Disc surface origin at: " + std::to_string(discOrigin[0]) + ", " +
std::to_string(discOrigin[1]) + ", " + std::to_string(discOrigin[2]);
return out;
};
ACTS_DEBUG(printOrigin(surface));

if (bounds.type() != Acts::SurfaceBounds::eAnnulus || splitRanges.empty()) {
ACTS_WARNING("Invalid splitting config for disk node: "
<< name << "! Node will not be slpit.");
return {detElement};
}

auto nSegments = splitRanges.size();

// Output container for the submodules
std::vector<std::shared_ptr<const detector_element_t>> detElements = {};
detElements.reserve(nSegments);

// Get the geometric information
const Acts::Transform3& transform = surface.transform(gctx);
const std::vector<double> boundsValues = bounds.values();
std::array<double, Acts::AnnulusBounds::eSize> values{};

std::copy_n(boundsValues.begin(), Acts::AnnulusBounds::eSize, values.begin());

for (std::size_t i = 0; i < nSegments; i++) {
if (boundsValues[Acts::AnnulusBounds::eMinR] > splitRanges[i].first ||
boundsValues[Acts::AnnulusBounds::eMaxR] < splitRanges[i].second) {
ACTS_WARNING(
"Radius pattern not within the original bounds, node will not be "
"split!");
return {detElement};
}

values[Acts::AnnulusBounds::eMinR] = splitRanges[i].first;
values[Acts::AnnulusBounds::eMaxR] = splitRanges[i].second;
auto annulusBounds = std::make_shared<Acts::AnnulusBounds>(values);
ACTS_DEBUG(
"New r bounds for node: " + std::to_string(annulusBounds->rMin()) +
", " + std::to_string(annulusBounds->rMax()));

auto element = factory(transform, annulusBounds);
detElements.push_back(std::move(element));
}
return detElements;
}

} // namespace ActsExamples::ITk
1 change: 1 addition & 0 deletions Examples/Detectors/TGeoDetector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ target_link_libraries(
ActsPluginJson
ActsExamplesFramework
ActsExamplesDetectorGeneric
ActsExamplesITkModuleSplitting
)

install(
Expand Down
113 changes: 18 additions & 95 deletions Examples/Detectors/TGeoDetector/src/TGeoITkModuleSplitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
#include "Acts/Surfaces/RectangleBounds.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Surfaces/SurfaceBounds.hpp"
#include "ActsExamples/ITkModuleSplitting/ITkModuleSplitting.hpp"

#include <algorithm>
#include <array>
#include <cstddef>
#include <sstream>

namespace {}

ActsExamples::TGeoITkModuleSplitter::TGeoITkModuleSplitter(
const ActsExamples::TGeoITkModuleSplitter::Config& cfg,
std::unique_ptr<const Acts::Logger> logger)
Expand Down Expand Up @@ -88,55 +91,16 @@ ActsExamples::TGeoITkModuleSplitter::splitBarrelModule(
const Acts::GeometryContext& gctx,
const std::shared_ptr<const Acts::TGeoDetectorElement>& detElement,
unsigned int nSegments) const {
// Retrieve the surface
auto identifier = detElement->identifier();
const Acts::Surface& surface = detElement->surface();
const Acts::SurfaceBounds& bounds = surface.bounds();
if (bounds.type() != Acts::SurfaceBounds::eRectangle || nSegments <= 1u) {
ACTS_WARNING("Invalid splitting config for barrel node: " +
std::string(detElement->tgeoNode().GetName()) +
"! Node will not be slpit.");
return {detElement};
}

// Output container for the submodules
std::vector<std::shared_ptr<const Acts::TGeoDetectorElement>> detElements =
{};
detElements.reserve(nSegments);

// Get the geometric information
double thickness = detElement->thickness();
const Acts::Transform3& transform = surface.transform(gctx);
// Determine the new bounds
const std::vector<double> boundsValues = bounds.values();
double lengthX = (boundsValues[Acts::RectangleBounds::eMaxX] -
boundsValues[Acts::RectangleBounds::eMinX]) /
nSegments;
double lengthY = boundsValues[Acts::RectangleBounds::eMaxY] -
boundsValues[Acts::RectangleBounds::eMinY];
auto rectBounds =
std::make_shared<Acts::RectangleBounds>(0.5 * lengthX, 0.5 * lengthY);
// Translation for every subelement
auto localTranslation = Acts::Vector2(-0.5 * lengthX * (nSegments - 1), 0.);
const auto step = Acts::Vector2(lengthX, 0.);
ACTS_DEBUG("Rectangle bounds for new node (half length): " +
std::to_string(rectBounds->halfLengthX()) + ", " +
std::to_string(rectBounds->halfLengthY()));
auto name = detElement->tgeoNode().GetName();

for (std::size_t i = 0; i < nSegments; i++) {
Acts::Vector3 globalTranslation =
surface.localToGlobal(gctx, localTranslation, {}) -
transform.translation();
auto elemTransform =
Acts::Transform3(transform).pretranslate(globalTranslation);
auto element = std::make_shared<const Acts::TGeoDetectorElement>(
identifier, detElement->tgeoNode(), elemTransform, rectBounds,
thickness);
detElements.push_back(std::move(element));
auto factory = [&](const auto& trafo, const auto& bounds) {
return std::make_shared<const Acts::TGeoDetectorElement>(
detElement->identifier(), detElement->tgeoNode(), trafo, bounds,
detElement->thickness());
};

localTranslation += step;
}
return detElements;
return ITk::splitBarrelModule(gctx, detElement, nSegments, factory, name,
logger());
}

/// If applicable, returns a split detector element
Expand All @@ -146,55 +110,14 @@ ActsExamples::TGeoITkModuleSplitter::splitDiscModule(
const std::shared_ptr<const Acts::TGeoDetectorElement>& detElement,
const std::vector<ActsExamples::TGeoITkModuleSplitter::SplitRange>&
splitRanges) const {
// Retrieve the surface
auto identifier = detElement->identifier();
const Acts::Surface& surface = detElement->surface();
const Acts::SurfaceBounds& bounds = surface.bounds();
auto name = detElement->tgeoNode().GetName();

// Check annulus bounds origin
auto printOrigin = [&](const Acts::Surface& sf) {
Acts::Vector3 discOrigin =
sf.localToGlobal(gctx, Acts::Vector2(0., 0.), Acts::Vector3::Zero());
std::string out =
"Disc surface origin at: " + std::to_string(discOrigin[0]) + ", " +
std::to_string(discOrigin[1]) + ", " + std::to_string(discOrigin[2]);
return out;
auto factory = [&](const auto& trafo, const auto& bounds) {
return std::make_shared<const Acts::TGeoDetectorElement>(
detElement->identifier(), detElement->tgeoNode(), trafo, bounds,
detElement->thickness());
};
ACTS_DEBUG(printOrigin(surface));

if (bounds.type() != Acts::SurfaceBounds::eAnnulus || splitRanges.empty()) {
ACTS_WARNING("Invalid splitting config for disk node: " +
std::string(detElement->tgeoNode().GetName()) +
"! Node will not be slpit.");
return {detElement};
}

auto nSegments = splitRanges.size();

// Output container for the submodules
std::vector<std::shared_ptr<const Acts::TGeoDetectorElement>> detElements =
{};
detElements.reserve(nSegments);

// Get the geometric information
double thickness = detElement->thickness();
const Acts::Transform3& transform = surface.transform(gctx);
const std::vector<double> boundsValues = bounds.values();
std::array<double, Acts::AnnulusBounds::eSize> values{};
std::copy_n(boundsValues.begin(), Acts::AnnulusBounds::eSize, values.begin());

for (std::size_t i = 0; i < nSegments; i++) {
values[Acts::AnnulusBounds::eMinR] = splitRanges[i].first;
values[Acts::AnnulusBounds::eMaxR] = splitRanges[i].second;
auto annulusBounds = std::make_shared<Acts::AnnulusBounds>(values);
ACTS_DEBUG(
"New r bounds for node: " + std::to_string(annulusBounds->rMin()) +
", " + std::to_string(annulusBounds->rMax()));

auto element = std::make_shared<const Acts::TGeoDetectorElement>(
identifier, detElement->tgeoNode(), transform, annulusBounds,
thickness);
detElements.push_back(std::move(element));
}
return detElements;
return ITk::splitDiscModule(gctx, detElement, splitRanges, factory, name,
logger());
}
5 changes: 4 additions & 1 deletion Examples/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ else()
endif()

if(ACTS_BUILD_PLUGIN_GEOMODEL)
target_link_libraries(ActsPythonBindings PUBLIC ActsPluginGeoModel)
target_link_libraries(
ActsPythonBindings
PUBLIC ActsPluginGeoModel ActsExamplesITkModuleSplitting
)
target_sources(ActsPythonBindings PRIVATE src/GeoModel.cpp)
else()
target_sources(ActsPythonBindings PRIVATE src/GeoModelStub.cpp)
Expand Down
Loading
Loading