Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:41

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2023 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Detector/GeometryIdMapper.hpp"
0012 #include "Acts/Plugins/DD4hep/DD4hepDetectorElement.hpp"
0013 #include "Acts/Surfaces/Surface.hpp"
0014 
0015 #include <climits>
0016 
0017 namespace Acts {
0018 
0019 using DD4hepIdentifier = DD4hepDetectorElement::DD4hepVolumeID;
0020 
0021 /// @brief This struct helps to capture the DD4hep identifier
0022 /// from the DD4hepDetectorElement from a Acts::Surface
0023 ///
0024 /// It can be used for mapping/assigning geometry ids to surfaces
0025 struct DD4hepIdentifierCapture {
0026   /// @brief Return an invalid identifier for volumes as they are not directly translated
0027   /// @return maximum value
0028   DD4hepIdentifier operator()(
0029       const Acts::Experimental::DetectorVolume& /*volume*/) const {
0030     return std::numeric_limits<DD4hepIdentifier>::max();
0031   }
0032 
0033   /// @brief Return an invalid identifier for portal objects as they are not directly translated
0034   /// @return maximum value
0035   DD4hepIdentifier operator()(
0036       const Acts::Experimental::Portal& /*portal*/) const {
0037     return std::numeric_limits<DD4hepIdentifier>::max();
0038   }
0039 
0040   /// @brief Return the DD4hep identifier from the DD4hepDetectorElement associated to the surface
0041   /// @param surface the Acts::Surface object
0042   /// @return the DD4hep identifier (or maximum value if now DD4hepDetectorElement is associated)
0043   DD4hepIdentifier operator()(const Acts::Surface& surface) const {
0044     // Get the DD4hepDetectorElement
0045     const auto* dde = surface.associatedDetectorElement();
0046     const auto* dd4hepDetElement =
0047         dynamic_cast<const Acts::DD4hepDetectorElement*>(dde);
0048     // Check if it is valid
0049     if (dd4hepDetElement) {
0050       return dd4hepDetElement->sourceElement().volumeID();
0051     }  // Return the maximum value
0052     return std::numeric_limits<DD4hepIdentifier>::max();
0053   }
0054 };
0055 
0056 using DD4hepIdentifierMapper =
0057     Experimental::GeometryIdMapper<DD4hepIdentifier, DD4hepIdentifierCapture>;
0058 
0059 }  // namespace Acts