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/Geometry/GeometryContext.hpp"
0012 #include "Acts/Utilities/ThrowAssert.hpp"
0013 #include "ActsPlugins/Root/TGeoDetectorElement.hpp"
0014 
0015 #include <map>
0016 #include <memory>
0017 #include <string>
0018 
0019 #include "DD4hep/DetElement.h"
0020 #include "DD4hep/Segmentations.h"
0021 
0022 namespace Acts {
0023 
0024 /// Forward declaration of Digitization module is enough
0025 class ISurfaceMaterial;
0026 
0027 }  // namespace Acts
0028 
0029 namespace ActsPlugins {
0030 /// @class DD4hepDetectorElement
0031 ///
0032 /// @brief DetectorElement class implementation for DD4hep geometry
0033 ///
0034 /// DetectorElement plugin for DD4hep detector elements. DD4hep is based on
0035 /// TGeo shapes, therefore the DD4hepDetectorElement inherits from
0036 /// TGeoDetectorElement in order to perform the conversion.
0037 ///
0038 /// The full geometrical information is provided by the TGeoDetectorElement.
0039 /// The DD4hepDetectorElement extends the TGeoDetectorElement by containing a
0040 /// segmentation for the readout.
0041 ///
0042 class DD4hepDetectorElement : public TGeoDetectorElement {
0043  public:
0044   /// Type alias for DD4hep volume identifier used in segmentation
0045   using DD4hepVolumeID = dd4hep::DDSegmentation::VolumeID;
0046 
0047   /// Broadcast the context type
0048   using ContextType = Acts::GeometryContext;
0049 
0050   /// Define a string based store
0051   using Store = std::map<std::string,
0052                          std::vector<std::shared_ptr<DD4hepDetectorElement>>>;
0053 
0054   /// Constructor
0055   /// @param detElement The DD4hep DetElement which should be associated to
0056   /// an ACTS surface
0057   ///
0058   /// @param axes is the axis orientation with respect to the tracking frame
0059   ///        it is a string of the three characters x, y and z (standing for
0060   ///        the three axes) There is a distinction between
0061   /// capital and lower case
0062   /// characters :
0063   ///   - capital      -> positive orientation of the axis
0064   ///       - lower case   -> negative orientation of the axis
0065   ///
0066   ///
0067   /// Example options are:
0068   ///   - "XYZ" -> identical frame definition (default value)
0069   ///   - "YZX" -> node y axis is tracking x axis, etc.
0070   ///       - "XzY" -> negative node z axis is tracking y axis, etc.
0071   /// @param scalor is the scale factor for unit conversion if needed
0072   /// @param isDisc in case the sensitive detector module should be translated
0073   ///        as disc (e.g. for endcaps) this flag should be set to true
0074   /// @note In the translation from a 3D geometry (TGeo) which only knows
0075   ///       tubes to a 2D geometry (Tracking geometry) a distinction if the
0076   ///       module should be described as a cylinder or a disc surface needs to
0077   ///       be done. Since this information can not be taken just from the
0078   ///       geometry description (both can be described as TGeoTubeSeg), one
0079   ///       needs to set the flag 'isDisc' in case a volume with shape \c
0080   ///       TGeoTubeSeg should be translated to a disc surface. Per default it
0081   ///       will be translated into a cylindrical surface.
0082   /// @param material Optional material of detector element
0083   explicit DD4hepDetectorElement(
0084       const dd4hep::DetElement detElement, const std::string& axes = "XYZ",
0085       double scalor = 1., bool isDisc = false,
0086       std::shared_ptr<const Acts::ISurfaceMaterial> material = nullptr);
0087 
0088   ~DD4hepDetectorElement() override = default;
0089 
0090   /// Give access to the DD4hep detector element
0091   /// @return Reference to the underlying DD4hep detector element
0092   const dd4hep::DetElement& sourceElement() const { return m_detElement; }
0093 
0094  private:
0095   /// DD4hep detector element
0096   dd4hep::DetElement m_detElement;
0097 };
0098 
0099 /// This extension holds an ACTS detector element belonging to a DD4hep detector
0100 /// element, and synchronizes ownership
0101 struct DD4hepDetectorElementExtension {
0102   /// Constructor from shared pointer to DD4hep detector element
0103   /// @param de The DD4hep detector element to wrap (must not be nullptr)
0104   explicit DD4hepDetectorElementExtension(
0105       std::shared_ptr<DD4hepDetectorElement> de)
0106       : detectorElement(std::move(de)) {
0107     throw_assert(detectorElement != nullptr,
0108                  "DD4hepDetectorElement is nullptr");
0109   }
0110 
0111  private:
0112   std::shared_ptr<DD4hepDetectorElement> detectorElement;
0113 };
0114 
0115 }  // namespace ActsPlugins