Skip to content

Commit

Permalink
feat: dd4hep allow proto material (#2889)
Browse files Browse the repository at this point in the history
This PR sits on top of #2879 and uses the new `ProtoBinning`, `ProtoMaterial` and `ProtoSupport` schema within the DD4hep context.

It allows to assign `ProtoBinning` to translated support surfaces, but also to define support via DD4hep.

This is the first part of this, a dedicated filling of `acts_proto_support` will follow in a second PR.
  • Loading branch information
asalzburger authored Jan 29, 2024
1 parent 5166de1 commit fb92e4c
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Examples/Scripts/Python/detector_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
detector,
"odd",
[[ivol, volumeOptions] for ivol in range(detector.number_volumes())],
[["xy", ["sensitives"], xyRange], ["zr", ["sensitives"], zrRange]],
[["xy", ["sensitives"], xyRange], ["zr", ["materials"], zrRange]],
"detector",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class DD4hepBlueprintFactory {
struct Config {
std::shared_ptr<Experimental::DD4hepLayerStructure> layerStructure =
nullptr;

/// The maximum number of portals to be checked for protal material
unsigned int maxPortals = 8u;
};

/// @brief Nested cache object for the detector store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ class DD4hepDetectorSurfaceFactory {
/// Convert passive surfaces
bool convertPassive = true;
/// Convert material directly
bool convertMaterial = true;
/// Convert proxy material - overrides convertMaterial if present
bool convertProxyMaterial = true;
bool convertMaterial = false;
/// New reference material thickness for surfaces
ActsScalar surfaceMaterialThickness = 1_mm;
};
Expand Down Expand Up @@ -161,6 +159,8 @@ class DD4hepDetectorSurfaceFactory {

/// Attach surface material if present
///
/// @param gctx the geometry context
/// @param prefix the acts prefix for the variant parameter string
/// @param dd4hepElement the detector element
/// @param surface the surface to attach the material to
/// @param thickness the thickness of the condensed component
Expand All @@ -170,7 +170,9 @@ class DD4hepDetectorSurfaceFactory {
/// extent of the sensitive surface and register it
///
/// @note void function that also checks the options if the attachment should be applied
void attachSurfaceMaterial(const dd4hep::DetElement& dd4hepElement,
void attachSurfaceMaterial(const GeometryContext& gctx,
const std::string& prefix,
const dd4hep::DetElement& dd4hepElement,
Acts::Surface& surface, ActsScalar thickness,
const Options& options) const;
};
Expand Down
7 changes: 4 additions & 3 deletions Plugins/DD4hep/src/DD4hepBinningHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ Acts::DD4hepBinningHelpers::convertBinning(
Experimental::ProtoBinning(bVal, bType, nBins, nExpansion));
} else {
// Equidistant binning
ActsScalar minDefault = bVal == binPhi ? -M_PI : 0.;
ActsScalar maxDefault = bVal == binPhi ? M_PI : 0.;
auto min = getParamOr<ActsScalar>(bname + "_" + ab + "_min",
dd4hepElement, 0.);
dd4hepElement, minDefault);
auto max = getParamOr<ActsScalar>(bname + "_" + ab + "_max",
dd4hepElement, 0.);

dd4hepElement, maxDefault);
// Check for closed phi binning
if (bVal == binPhi && (max - min) > 1.9 * M_PI) {
bType = Acts::detail::AxisBoundaryType::Closed;
Expand Down
22 changes: 22 additions & 0 deletions Plugins/DD4hep/src/DD4hepBlueprintFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ void Acts::Experimental::DD4hepBlueprintFactory::recursiveParse(
current->rootVolumeFinderBuilder = rootsFinderBuilder;
}

// Check for proto material for the portals, max portal number
// can be changed in configuration
for (unsigned int p = 0u; p < m_cfg.maxPortals; ++p) {
std::string pmName = "acts_portal_proto_material_" + std::to_string(p);
auto protoMaterial = getParamOr<bool>(pmName, dd4hepElement, false);
if (protoMaterial) {
ACTS_VERBOSE(ofs << " - proto material binning for portal " << p
<< " found");
auto pmProtoBinnings = DD4hepBinningHelpers::convertBinning(
dd4hepElement, pmName + "_binning");
current->portalMaterialBinning[p] =
BinningDescription{pmProtoBinnings};
ACTS_VERBOSE(ofs << " - binning description is "
<< current->portalMaterialBinning[p].toString());
}
}

// Adding geo Id generator - if present
if (geoIdGenerator != nullptr) {
ACTS_VERBOSE(ofs << " - " << auxInt[2u]);
Expand Down Expand Up @@ -225,6 +242,11 @@ Acts::Experimental::DD4hepBlueprintFactory::extractInternals(
// Create a new layer builder
DD4hepLayerStructure::Options lOptions;
lOptions.name = dd4hepElement.name();
// Check whether internal/sensitive surfaces should have directly
// translated material
auto convertMaterial = Acts::getParamOr<bool>(
"acts_surface_material_conversion", dd4hepElement, false);
lOptions.conversionOptions.convertMaterial = convertMaterial;
// Check if the extent should be measured
auto interenalsMeasure = Acts::getParamOr<std::string>(
baseName + "_internals_measure", dd4hepElement, "");
Expand Down
23 changes: 20 additions & 3 deletions Plugins/DD4hep/src/DD4hepDetectorSurfaceFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Acts/Plugins/DD4hep/DD4hepDetectorSurfaceFactory.hpp"

#include "Acts/Definitions/Units.hpp"
#include "Acts/Detector/detail/ProtoMaterialHelper.hpp"
#include "Acts/Material/HomogeneousSurfaceMaterial.hpp"
#include "Acts/Plugins/DD4hep/DD4hepBinningHelpers.hpp"
#include "Acts/Plugins/DD4hep/DD4hepConversionHelpers.hpp"
Expand Down Expand Up @@ -112,7 +113,8 @@ Acts::DD4hepDetectorSurfaceFactory::constructSensitiveComponents(
cache.sExtent.value().extend(sExtent, cache.extentConstraints);
}

attachSurfaceMaterial(dd4hepElement, *sSurface.get(),
// Attach surface material if present
attachSurfaceMaterial(gctx, "acts_surface_", dd4hepElement, *sSurface.get(),
dd4hepDetElement->thickness(), options);
// return the surface
return {dd4hepDetElement, sSurface};
Expand All @@ -139,15 +141,30 @@ Acts::DD4hepDetectorSurfaceFactory::constructPassiveComponents(
.extent();
cache.pExtent.value().extend(sExtent, cache.extentConstraints);
}
attachSurfaceMaterial(dd4hepElement, *pSurface.get(), thickness, options);
attachSurfaceMaterial(gctx, "acts_passive_surface", dd4hepElement,
*pSurface.get(), thickness, options);
// Return a passive surface
return {pSurface, assignToAll};
}

void Acts::DD4hepDetectorSurfaceFactory::attachSurfaceMaterial(
const GeometryContext& gctx, const std::string& prefix,
const dd4hep::DetElement& dd4hepElement, Acts::Surface& surface,
ActsScalar thickness, const Options& options) const {
if (options.convertMaterial) {
// Bool proto material overrules converted material
bool protoMaterial =
getParamOr<bool>(prefix + "_proto_material", dd4hepElement, false);
if (protoMaterial) {
ACTS_VERBOSE(" - proto material binning for passive surface found.");
Experimental::BinningDescription pmBinning{
DD4hepBinningHelpers::convertBinning(
dd4hepElement, prefix + "_proto_material_binning")};
ACTS_VERBOSE(" - converted binning is " << pmBinning.toString());
Experimental::detail::ProtoMaterialHelper::attachProtoMaterial(
gctx, surface, pmBinning);

} else if (options.convertMaterial) {
ACTS_VERBOSE(" - direct conversion of DD4hep material triggered.");
// Extract the material
const auto& tgeoNode = *(dd4hepElement.placement().ptr());
auto tgeoMaterial = tgeoNode.GetMedium()->GetMaterial();
Expand Down
21 changes: 21 additions & 0 deletions Tests/UnitTests/Core/Geometry/ExtentTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,27 @@ BOOST_AUTO_TEST_CASE(ExtentTest) {
BOOST_CHECK(!gExtVertexCheck.contains(Vector3(6., 0., 0.)));
}

// Test that the constrains() check advances when the extend() method
// is used with a new binning type
BOOST_AUTO_TEST_CASE(ProtoSupportCaseTests) {
std::vector<Vector3> vertices = {
Vector3(15_mm, -3_mm, -10_mm), Vector3(18_mm, 0_mm, -10_mm),
Vector3(15_mm, 3_mm, -10_mm), Vector3(15_mm, -3_mm, 10_mm),
Vector3(18_mm, 0_mm, 10_mm), Vector3(15_mm, 3_mm, 10_mm)};

Extent volumeExtent;
volumeExtent.set(binZ, -300_mm, 300_mm);

BOOST_CHECK(volumeExtent.constrains(binZ));
BOOST_CHECK(!volumeExtent.constrains(binR));

for (const auto& v : vertices) {
volumeExtent.extend(v, {binR});
}

BOOST_CHECK(volumeExtent.constrains(binR));
}

BOOST_AUTO_TEST_SUITE_END()

} // namespace Test
Expand Down

0 comments on commit fb92e4c

Please sign in to comment.