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: Introduce DD4hep GeometryContext #3854

Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
22 changes: 22 additions & 0 deletions Core/include/Acts/Utilities/detail/ContextType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ class ContextType {
return std::any_cast<const std::decay_t<T>&>(m_data);
}

/// Retrieve a pointer to the contained type
///
/// @note Returns `nullptr` if @p is not the contained type.
///
/// @tparam T The type to attempt to retrieve the value as
/// @return Pointer to the contained value, may be null
template <typename T>
std::decay_t<T>* maybeGet() {
return std::any_cast<std::decay_t<T>>(&m_data);
}
asalzburger marked this conversation as resolved.
Show resolved Hide resolved

/// Retrieve a pointer to the contained type
///
/// @note Returns `nullptr` if @p is not the contained type.
///
/// @tparam T The type to attempt to retrieve the value as
/// @return Pointer to the contained value, may be null
template <typename T>
const std::decay_t<T>* maybeGet() const {
return std::any_cast<const std::decay_t<T>>(&m_data);
}
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
asalzburger marked this conversation as resolved.
Show resolved Hide resolved

/// Check if the contained type is initialized.
/// @return Boolean indicating whether a type is present
bool hasValue() const { return m_data.has_value(); }
Expand Down
1 change: 1 addition & 0 deletions Plugins/DD4hep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_library(
src/DD4hepBlueprintFactory.cpp
src/DD4hepBinningHelpers.cpp
src/DD4hepDetectorStructure.cpp
src/DD4hepGeometryContext.cpp
src/DD4hepMaterialHelpers.cpp
src/DD4hepDetectorElement.cpp
src/DD4hepDetectorSurfaceFactory.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ class DD4hepDetectorElement : public TGeoDetectorElement {
// Give access to the DD4hep detector element
const dd4hep::DetElement& sourceElement() const { return m_detElement; }

/// Return the transform for the Element proxy mechanism
///
/// @param gctx The current geometry context object, e.g. alignment
/// @return The contextual transform matrix that may include misalignment
/// @note This method enables dynamic geometry updates through the context
const Transform3& transform(const GeometryContext& gctx) const final;
asalzburger marked this conversation as resolved.
Show resolved Hide resolved

private:
/// DD4hep detector element
dd4hep::DetElement m_detElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.

#pragma once

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Geometry/GeometryContext.hpp"

namespace Acts {

class DD4hepDetectorElement;

/// @class GeometryContext
///
/// @brief DD4hep specific geometry context for alignment handling
///
/// Extends the base GeometryContext to provide DD4hep-specific alignment
/// capabilities. The context can be active or inactive, controlling whether
/// alignment corrections should be applied.
///
/// @note This context is specifically designed to work with DD4hepDetectorElement
/// and provides contextual transformations for alignment purposes.
///
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
class DD4hepGeometryContext : public GeometryContext{
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
public:
/// Explicit inactive constructor
/// Creates an inactive geometry context that skips alignment corrections
/// @return DD4hepGeometryContext instance with inactive state
static DD4hepGeometryContext inactive() { return DD4hepGeometryContext(false); }
asalzburger marked this conversation as resolved.
Show resolved Hide resolved

/// The transform of this detector element within the given context
///
/// @param dElement The detector element
///
/// @return The transform of the detector element
const Transform3& contextualTransform( const DD4hepDetectorElement& dElement) const;
asalzburger marked this conversation as resolved.
Show resolved Hide resolved

/// @brief Return the active status of the context
/// @return boolean that indicates if the context is active
bool isActive() const { return m_active; }

private :
/// Constructor
explicit DD4hepGeometryContext(bool isContextActive) : m_active(isContextActive) {}

const bool m_active = true;

};
asalzburger marked this conversation as resolved.
Show resolved Hide resolved


} // namespace Acts


12 changes: 12 additions & 0 deletions Plugins/DD4hep/src/DD4hepDetectorElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "Acts/Plugins/DD4hep/DD4hepDetectorElement.hpp"

#include "Acts/Plugins/DD4hep/DD4hepGeometryContext.hpp"

#include <utility>

#include <DD4hep/Alignments.h>
Expand All @@ -23,3 +25,13 @@ Acts::DD4hepDetectorElement::DD4hepDetectorElement(
detElement.nominal().worldTransformation(), axes, scalor,
std::move(material)),
m_detElement(detElement) {}

const Acts::Transform3& Acts::DD4hepDetectorElement::transform(
const GeometryContext& gctx) const {
const Acts::DD4hepGeometryContext* dd4hepGtx =
gctx.maybeGet<DD4hepGeometryContext>();
if (dd4hepGtx != nullptr && dd4hepGtx->isActive()) {
return dd4hepGtx->contextualTransform(*this);
}
return TGeoDetectorElement::m_transform;
}
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions Plugins/DD4hep/src/DD4hepGeometryContext.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/DD4hep/DD4hepDetectorElement.hpp"
#include "Acts/Plugins/DD4hep/DD4hepGeometryContext.hpp"

const Acts::Transform3& Acts::DD4hepGeometryContext::contextualTransform(
const Acts::DD4hepDetectorElement& dElement) const {
// Use inactive context as the base transformation state
return dElement.transform(DD4hepGeometryContext::inactive());
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class TGeoDetectorElement : public Acts::DetectorElementBase {
/// Return the TGeoNode for back navigation
const TGeoNode& tgeoNode() const { return *m_detElement; }

private:
protected:
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
/// Pointer to TGeoNode (not owned)
const TGeoNode* m_detElement{nullptr};
/// Transformation of the detector element
Expand Down
Loading