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 all 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
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 @@ -9,6 +9,7 @@
#pragma once

#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Plugins/DD4hep/DD4hepGeometryContext.hpp"
#include "Acts/Plugins/TGeo/TGeoDetectorElement.hpp"
#include "Acts/Utilities/ThrowAssert.hpp"

Expand Down Expand Up @@ -42,7 +43,7 @@ class DD4hepDetectorElement : public TGeoDetectorElement {
using DD4hepVolumeID = dd4hep::DDSegmentation::VolumeID;

/// Broadcast the context type
using ContextType = GeometryContext;
using ContextType = DD4hepGeometryContext;

/// Define a string based story
using Store = std::map<std::string,
Expand Down Expand Up @@ -87,6 +88,18 @@ 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

/// Return the nominal transform
///
/// @note This method returns the nominal transform without any alignment
const Transform3& nominalTransform() const;

private:
/// DD4hep detector element
dd4hep::DetElement m_detElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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"

namespace Acts {

class DD4hepDetectorElement;

/// @class DD4hepGeometryContext
///
/// @brief DD4hep specific geometry context for alignment handling
///
/// @note This context is specifically designed to work with DD4hepDetectorElement
/// and provides contextual transformations for alignment purposes.
///
class DD4hepGeometryContext {
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);
}

/// 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) {}
asalzburger marked this conversation as resolved.
Show resolved Hide resolved

const bool m_active = true;
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace Acts
18 changes: 18 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,19 @@ Acts::DD4hepDetectorElement::DD4hepDetectorElement(
detElement.nominal().worldTransformation(), axes, scalor,
std::move(material)),
m_detElement(detElement) {}

const Acts::Transform3& Acts::DD4hepDetectorElement::transform(
const GeometryContext& gctx) const {
if (gctx.hasValue()) {
const DD4hepGeometryContext* dd4hepContext =
gctx.maybeGet<DD4hepGeometryContext>();
if (dd4hepContext != nullptr && dd4hepContext->isActive()) {
return dd4hepContext->contextualTransform(*this);
}
}
return nominalTransform();
}

const Acts::Transform3& Acts::DD4hepDetectorElement::nominalTransform() const {
return TGeoDetectorElement::m_transform;
};
17 changes: 17 additions & 0 deletions Plugins/DD4hep/src/DD4hepGeometryContext.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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/DD4hepGeometryContext.hpp"

#include "Acts/Plugins/DD4hep/DD4hepDetectorElement.hpp"
asalzburger marked this conversation as resolved.
Show resolved Hide resolved

const Acts::Transform3& Acts::DD4hepGeometryContext::contextualTransform(
const Acts::DD4hepDetectorElement& dElement) const {
// Use inactive context as the base transformation state
return dElement.nominalTransform();
}
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