Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-11 09:40:21

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Detector/GeometryIdMapper.hpp"
0012 #include "Acts/Surfaces/Surface.hpp"
0013 #include "ActsPlugins/DD4hep/DD4hepDetectorElement.hpp"
0014 
0015 #include <climits>
0016 
0017 namespace ActsPlugins {
0018 
0019 /// @brief Type alias for DD4hep identifier type
0020 /// @details Used to represent unique identifiers in the DD4hep geometry description framework
0021 using DD4hepIdentifier = DD4hepDetectorElement::DD4hepVolumeID;
0022 
0023 /// @brief This struct helps to capture the DD4hep identifier
0024 /// from the DD4hepDetectorElement from a Acts::Surface
0025 ///
0026 /// It can be used for mapping/assigning geometry ids to surfaces
0027 struct DD4hepIdentifierCapture {
0028   /// @brief Return an invalid identifier for volumes as they are not directly translated
0029   /// @return maximum value
0030   DD4hepIdentifier operator()(
0031       const Acts::Experimental::DetectorVolume& /*volume*/) const {
0032     return std::numeric_limits<DD4hepIdentifier>::max();
0033   }
0034 
0035   /// @brief Return an invalid identifier for portal objects as they are not directly translated
0036   /// @return maximum value
0037   DD4hepIdentifier operator()(
0038       const Acts::Experimental::Portal& /*portal*/) const {
0039     return std::numeric_limits<DD4hepIdentifier>::max();
0040   }
0041 
0042   /// @brief Return the DD4hep identifier from the DD4hepDetectorElement associated to the surface
0043   /// @param surface the Acts::Surface object
0044   /// @return the DD4hep identifier (or maximum value if now DD4hepDetectorElement is associated)
0045   DD4hepIdentifier operator()(const Acts::Surface& surface) const {
0046     // Get the DD4hepDetectorElement
0047     const auto* dde = surface.associatedDetectorElement();
0048     const auto* dd4hepDetElement =
0049         dynamic_cast<const ActsPlugins::DD4hepDetectorElement*>(dde);
0050     // Check if it is valid
0051     if (dd4hepDetElement) {
0052       return dd4hepDetElement->sourceElement().volumeID();
0053     }  // Return the maximum value
0054     return std::numeric_limits<DD4hepIdentifier>::max();
0055   }
0056 };
0057 
0058 /// @brief Type alias for mapping between DD4hep and Acts identifiers
0059 /// @details Function type that converts DD4hep identifiers to Acts geometry identifiers
0060 using DD4hepIdentifierMapper =
0061     Acts::Experimental::GeometryIdMapper<DD4hepIdentifier,
0062                                          DD4hepIdentifierCapture>;
0063 
0064 }  // namespace ActsPlugins