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 24 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
19 changes: 18 additions & 1 deletion Examples/Python/src/GeoModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
#include "Acts/Plugins/GeoModel/GeoModelBlueprintCreater.hpp"
#include "Acts/Plugins/GeoModel/GeoModelConverters.hpp"
#include "Acts/Plugins/GeoModel/GeoModelDetectorElement.hpp"
#include "Acts/Plugins/GeoModel/GeoModelDetectorElementITk.hpp"
#include "Acts/Plugins/GeoModel/GeoModelDetectorSurfaceFactory.hpp"
#include "Acts/Plugins/GeoModel/GeoModelReader.hpp"
#include "Acts/Plugins/GeoModel/GeoModelTree.hpp"
#include "Acts/Plugins/GeoModel/IGeoShapeConverter.hpp"
#include "Acts/Plugins/GeoModel/SplitModulesByRadius.hpp"
#include "Acts/Plugins/Python/Utilities.hpp"
#include "Acts/Surfaces/Surface.hpp"

Expand All @@ -46,7 +48,10 @@ void addGeoModel(Context& ctx) {

py::class_<Acts::GeoModelDetectorElement,
std::shared_ptr<Acts::GeoModelDetectorElement>>(
gm, "GeoModelDetectorElement");
gm, "GeoModelDetectorElement")
.def("logVolName", &Acts::GeoModelDetectorElement::logVolName)
.def("databaseEntryName",
&Acts::GeoModelDetectorElement::databaseEntryName);

// Shape converters
{
Expand Down Expand Up @@ -179,5 +184,17 @@ void addGeoModel(Context& ctx) {
.def_readwrite("table",
&Acts::GeoModelBlueprintCreater::Options::table);
}

py::class_<Acts::ModuleByRadiusSplitter>(gm, "ModuleByRadiusSplitter")
.def(py::init<std::map<std::string, std::vector<double>>, double,
Acts::Logging::Level>(),
"designs"_a, "tolerance"_a = 1.e-3, "level"_a = Acts::Logging::INFO)
.def("split", &Acts::ModuleByRadiusSplitter::split, "surface"_a,
"detElement"_a, "gctx"_a);

py::class_<Acts::GeoModelDetectorElementITk,
std::shared_ptr<Acts::GeoModelDetectorElementITk>>(
gm, "GeoModelDetectorElementITk");
gm.def("convertToItk", &GeoModelDetectorElementITk::convertFromGeomodel);
}
} // namespace Acts::Python
2 changes: 2 additions & 0 deletions Plugins/GeoModel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ add_library(
src/detail/GeoModelBinningHelper.cpp
src/detail/GeoModelExtentHelper.cpp
src/detail/GeoUnionDoubleTrdConverter.cpp
src/SplitModulesByRadius.cpp
src/GeoModelDetectorElementITk.cpp
)
target_include_directories(
ActsPluginGeoModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,28 @@ class GeoModelDetectorElement : public DetectorElementBase {
/// @return to the Geant4 physical volume
const GeoFullPhysVol& physicalVolume() const;

private:
/// Get the name of the logical volume
const std::string& logVolName() const;

/// Get the string identifier of the corresponding database entry
/// Note: This is not by defnitition a unique identifier, there can be
/// several detector elements created from a single database entry.
const std::string& databaseEntryName() const { return m_entryName; };

/// Set the corresponding database entry string
void setDatabaseEntryName(const std::string& n) { m_entryName = n; };

protected:
/// Attach a surface
///
/// @param surface The surface to attach
void attachSurface(std::shared_ptr<Surface> surface) {
m_surface = std::move(surface);
}

private:
std::string m_entryName;

/// The GeoModel full physical volume
const GeoFullPhysVol* m_geoPhysVol{nullptr};
/// The surface
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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/Plugins/GeoModel/GeoModelDetectorElement.hpp"

namespace Acts {

/// Specialization of the GeoModelDetectorElement for the ITk. This allows
/// mapping of Acts::GeometryIdentifiers to ITk modules in a straight-forward
/// way.
class GeoModelDetectorElementITk : public GeoModelDetectorElement {
int m_hardware;
int m_barrelEndcap;
int m_layerWheel;
int m_etaModule;
int m_phiModule;
int m_side;
benjaminhuth marked this conversation as resolved.
Show resolved Hide resolved

public:
GeoModelDetectorElementITk(const GeoFullPhysVol& geoPhysVol,
std::shared_ptr<Surface> surface,
const Transform3& sfTransform,
ActsScalar thickness, int hardware,
int barrelEndcap, int layerWheel, int etaModule,
int phiModule, int side)
: GeoModelDetectorElement(geoPhysVol, surface, sfTransform, thickness),
m_hardware(hardware),
m_barrelEndcap(barrelEndcap),
m_layerWheel(layerWheel),
m_etaModule(etaModule),
m_phiModule(phiModule),
m_side(side) {}

int hardware() const { return m_hardware; }
int barrelEndcap() const { return m_barrelEndcap; }
int layerWheel() const { return m_layerWheel; }
int phiModule() const { return m_phiModule; }
int etaModule() const { return m_etaModule; }
int side() const { return m_side; }

static std::tuple<std::shared_ptr<GeoModelDetectorElementITk>,
std::shared_ptr<Surface>>
convertFromGeomodel(std::shared_ptr<GeoModelDetectorElement> detEl,
std::shared_ptr<Surface> srf, const GeometryContext& gctx,
int hardware, int barrelEndcap, int layerWheel,
int etaModule, int phiModule, int side);
};

} // namespace Acts
benjaminhuth marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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/Plugins/GeoModel/GeoModelDetectorElement.hpp"
#include "Acts/Utilities/Logger.hpp"

#include <map>
#include <string>
#include <vector>

namespace Acts {

class ModuleByRadiusSplitter {
benjaminhuth marked this conversation as resolved.
Show resolved Hide resolved
public:
/// Construct with a map { design-name: list of radii }
ModuleByRadiusSplitter(
const std::map<std::string, std::vector<double>> &designs,
double tolerance = 1.e-3,
Acts::Logging::Level level = Acts::Logging::INFO)
: m_designs(designs),
m_tolerance(tolerance),
m_logger(getDefaultLogger("ModuleByRadiusSplitter", level)) {}

std::optional<std::vector<std::pair<
std::shared_ptr<Surface>, std::shared_ptr<GeoModelDetectorElement>>>>
benjaminhuth marked this conversation as resolved.
Show resolved Hide resolved
split(std::shared_ptr<Surface> surface,
std::shared_ptr<GeoModelDetectorElement> detElement,
const GeometryContext &gctx) const;

private:
std::map<std::string, std::vector<double>> m_designs;
double m_tolerance;
std::unique_ptr<const Acts::Logger> m_logger;
};

} // namespace Acts
6 changes: 6 additions & 0 deletions Plugins/GeoModel/src/GeoModelDetectorElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include <utility>

#include <GeoModelKernel/GeoFullPhysVol.h>

Acts::GeoModelDetectorElement::GeoModelDetectorElement(
const GeoFullPhysVol& geoPhysVol, std::shared_ptr<Surface> surface,
const Transform3& sfTransform, ActsScalar thickness)
Expand Down Expand Up @@ -40,3 +42,7 @@ Acts::ActsScalar Acts::GeoModelDetectorElement::thickness() const {
const GeoFullPhysVol& Acts::GeoModelDetectorElement::physicalVolume() const {
return *m_geoPhysVol;
}

const std::string& Acts::GeoModelDetectorElement::logVolName() const {
return m_geoPhysVol->getLogVol()->getName();
}
51 changes: 51 additions & 0 deletions Plugins/GeoModel/src/GeoModelDetectorElementITk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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/GeoModelDetectorElementITk.hpp"

#include "Acts/Surfaces/AnnulusBounds.hpp"
#include "Acts/Surfaces/DiscSurface.hpp"
#include "Acts/Surfaces/PlaneSurface.hpp"
#include "Acts/Surfaces/RectangleBounds.hpp"

namespace Acts {

std::tuple<std::shared_ptr<Acts::GeoModelDetectorElementITk>,
std::shared_ptr<Acts::Surface>>
Acts::GeoModelDetectorElementITk::convertFromGeomodel(
paulgessinger marked this conversation as resolved.
Show resolved Hide resolved
std::shared_ptr<GeoModelDetectorElement> detEl,
std::shared_ptr<Surface> srf, const GeometryContext &gctx, int hardware,
int barrelEndcap, int layerWheel, int etaModule, int phiModule, int side) {
auto helper = [&]<typename surface_t, typename bounds_t>() {
auto bounds = std::make_shared<bounds_t>(
dynamic_cast<const bounds_t &>(srf->bounds()));

auto itkEl = std::make_shared<GeoModelDetectorElementITk>(
detEl->physicalVolume(), nullptr, detEl->transform(gctx),
detEl->thickness(), hardware, barrelEndcap, layerWheel, etaModule,
phiModule, side);
benjaminhuth marked this conversation as resolved.
Show resolved Hide resolved
auto surface = Surface::makeShared<surface_t>(bounds, *itkEl.get());
itkEl->attachSurface(surface);
itkEl->setDatabaseEntryName(detEl->databaseEntryName());
benjaminhuth marked this conversation as resolved.
Show resolved Hide resolved
benjaminhuth marked this conversation as resolved.
Show resolved Hide resolved
return std::make_pair(itkEl, surface);
benjaminhuth marked this conversation as resolved.
Show resolved Hide resolved
};

if (srf->type() == Acts::Surface::Plane &&
srf->bounds().type() == Acts::SurfaceBounds::eRectangle) {
return helper.operator()<Acts::PlaneSurface, Acts::RectangleBounds>();
}
if (srf->type() == Acts::Surface::Disc &&
srf->bounds().type() == Acts::SurfaceBounds::eAnnulus) {
return helper.operator()<Acts::DiscSurface, Acts::AnnulusBounds>();
}

throw std::runtime_error(
"Only Plane+Rectangle and Disc+Annulus are converted for the ITk");
}

} // namespace Acts
5 changes: 4 additions & 1 deletion Plugins/GeoModel/src/GeoModelDetectorSurfaceFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ void Acts::GeoModelDetectorSurfaceFactory::construct(
if (converted.ok()) {
// Add the element and surface to the cache
cache.sensitiveSurfaces.push_back(converted.value());
const auto &[el, sf] = converted.value();
auto &[el, sf] = converted.value();

// Set the name to the element
el->setDatabaseEntryName(name);
success = true;
ACTS_VERBOSE("successfully converted "
<< name << " (" << vname << " / " << recType(shape)
Expand Down
84 changes: 84 additions & 0 deletions Plugins/GeoModel/src/SplitModulesByRadius.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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/SplitModulesByRadius.hpp"

#include "Acts/Surfaces/AnnulusBounds.hpp"
#include "Acts/Surfaces/DiscSurface.hpp"
#include "Acts/Utilities/Logger.hpp"

#include <iostream>

namespace Acts {

std::optional<std::vector<std::pair<std::shared_ptr<Surface>,
std::shared_ptr<GeoModelDetectorElement>>>>
ModuleByRadiusSplitter::split(
benjaminhuth marked this conversation as resolved.
Show resolved Hide resolved
std::shared_ptr<Surface> surface,
std::shared_ptr<GeoModelDetectorElement> detElement,
const Acts::GeometryContext &gctx) const {
const auto &logger = *m_logger;

auto annulusBounds = dynamic_cast<const AnnulusBounds *>(&surface->bounds());

if (annulusBounds == nullptr) {
ACTS_DEBUG("Not annulus bounds");
return std::nullopt;
}

std::optional<std::vector<std::pair<
std::shared_ptr<Surface>, std::shared_ptr<GeoModelDetectorElement>>>>
result;

for (auto [design, radii] : m_designs) {
if ((std::abs(radii.front() - annulusBounds->rMin()) > m_tolerance) ||
(std::abs(radii.back() - annulusBounds->rMax()) > m_tolerance)) {
ACTS_VERBOSE("Skip design '" << design << "' for element '"
<< detElement->databaseEntryName());
continue;
}

radii.front() = annulusBounds->rMin();
radii.back() = annulusBounds->rMax();

ACTS_DEBUG("Accept design '" << design << "' for element '"
<< detElement->databaseEntryName());

result.emplace();
const auto origValues = annulusBounds->values();

for (auto i = 0ul; i < radii.size() - 1; ++i) {
std::array<double, AnnulusBounds::eSize> values;
std::copy(origValues.begin(), origValues.end(), values.begin());
values[AnnulusBounds::eMinR] = radii[i];
values[AnnulusBounds::eMaxR] = radii[i + 1];

auto bounds = std::make_shared<AnnulusBounds>(values);

auto newDetElement =
GeoModelDetectorElement::createDetectorElement<DiscSurface>(
detElement->physicalVolume(), bounds, detElement->transform(gctx),
detElement->thickness());
auto newSurface = newDetElement->surface().getSharedPtr();

newDetElement->setDatabaseEntryName(detElement->databaseEntryName());

result->emplace_back(newSurface, newDetElement);
}

return result;
}

ACTS_WARNING("Could not split '" << detElement->databaseEntryName()
<< "' (rmin: " << annulusBounds->rMin()
<< ", rmax: " << annulusBounds->rMax()
<< ")");
benjaminhuth marked this conversation as resolved.
Show resolved Hide resolved
return result;
}

} // namespace Acts
Loading