Back to home page

EIC code displayed by LXR

 
 

    


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

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/Definitions/Algebra.hpp"
0012 #include "Acts/Geometry/DetectorElementBase.hpp"
0013 #include "Acts/Geometry/GeometryContext.hpp"
0014 
0015 #include <iostream>
0016 #include <memory>
0017 #include <string>
0018 
0019 #include "TGeoManager.h"
0020 
0021 namespace Acts {
0022 class ISurfaceMaterial;
0023 class SurfaceBounds;
0024 class PlanarBounds;
0025 class DiscBounds;
0026 class DigitizationModule;
0027 class Surface;
0028 }  // namespace Acts
0029 
0030 namespace ActsPlugins {
0031 
0032 /// @class TGeoDetectorElement
0033 ///
0034 /// DetectorElement plugin for ROOT TGeo shapes. Added possibility to hand over
0035 /// transformation matrix.
0036 ///
0037 /// @todo what if shape conversion fails? add implementation of more than one
0038 /// surface per module, implementing also for other shapes->Cone,ConeSeg,Tube?
0039 /// what if not used with DD4hep?
0040 ///
0041 class TGeoDetectorElement : public Acts::DetectorElementBase {
0042  public:
0043   using identifier_type = unsigned long long;
0044   using identifier_diff = long long;
0045   using Identifier = identifier_type;
0046 
0047   /// Broadcast the context type
0048   using ContextType = Acts::GeometryContext;
0049 
0050   /// Constructor
0051   ///
0052   /// @note this constructor used auto-translation
0053   ///
0054   /// @param identifier is the detector identifier
0055   /// @param tGeoNode is the TGeoNode which should be represented
0056   /// @param tGeoMatrix The Matrix to global (i.e. ACTS transform)
0057   /// @param axes is the axis orientation with respect to the tracking frame
0058   ///        it is a string of the three characters x, y and z (standing for the
0059   ///        three axes)
0060   ///        there is a distinction between capital and lower case characters :
0061   ///        - capital      -> positive orientation of the axis
0062   ///        - lower case   -> negative orientation of the axis
0063   ///        example options are "XYZ" -> identical frame definition (default
0064   ///        value)
0065   ///                            "YZX" -> node y axis is tracking x axis, etc.
0066   ///                            "XzY" -> negative node z axis is tracking y
0067   ///                            axis, etc.
0068   /// @note This parameter only needs to be set for plane modules
0069   /// @param scalor is the scale factor for unit conversion if needed
0070   /// @note In the translation from a 3D geometry (TGeo) which only knows tubes
0071   ///       to a 2D geometry (Tracking geometry) a distinction if the module
0072   ///       should be described as a cylinder or a disc surface needs to be
0073   ///       done. Since this information can not be taken just from the geometry
0074   ///       description (both can be described as TGeoTubeSeg), one needs to
0075   ///       set the flag 'isDisc' in case a volume with shape \c TGeoTubeSeg
0076   ///       should be translated to a disc surface. Per default it will be
0077   ///       translated into a cylindrical surface.
0078   /// @param material Possible material of detector element
0079   TGeoDetectorElement(
0080       const Identifier& identifier, const TGeoNode& tGeoNode,
0081       const TGeoMatrix& tGeoMatrix = TGeoIdentity(),
0082       const std::string& axes = "XYZ", double scalor = 10.,
0083       std::shared_ptr<const Acts::ISurfaceMaterial> material = nullptr);
0084 
0085   /// Constructor with pre-computed surface
0086   ///
0087   /// @note this detector element constructor needs everything
0088   /// pre-computed.
0089   ///
0090   /// @param identifier is the detector identifier
0091   /// @param tGeoNode is the TGeoNode which should be represented
0092   /// @param tgTransform the transform of this detector element
0093   /// @param tgBounds the bounds of this surface
0094   /// @param tgThickness the thickness of this detector element
0095   TGeoDetectorElement(const Identifier& identifier, const TGeoNode& tGeoNode,
0096                       const Acts::Transform3& tgTransform,
0097                       const std::shared_ptr<const Acts::PlanarBounds>& tgBounds,
0098                       double tgThickness = 0.);
0099 
0100   /// Constructor with pre-computed disk surface.
0101   ///
0102   /// @note this detector element constructor needs everything
0103   /// pre-computed.
0104   ///
0105   /// @param identifier is the detector identifier
0106   /// @param tGeoNode is the TGeoNode which should be represented
0107   /// @param tgTransform the transform of this detector element
0108   /// @param tgBounds the bounds of this surface
0109   /// @param tgThickness the thickness of this detector element
0110   TGeoDetectorElement(const Identifier& identifier, const TGeoNode& tGeoNode,
0111                       const Acts::Transform3& tgTransform,
0112                       const std::shared_ptr<const Acts::DiscBounds>& tgBounds,
0113                       double tgThickness = 0.);
0114 
0115   ~TGeoDetectorElement() override;
0116 
0117   /// Get the detector element identifier
0118   /// @return The unique identifier for this detector element
0119   Identifier identifier() const;
0120 
0121   /// Return local to global transform associated with this identifier
0122   ///
0123   /// @param gctx The current geometry context object, e.g. alignment
0124   const Acts::Transform3& transform(
0125       const Acts::GeometryContext& gctx) const override;
0126   /// @return Reference to the transformation matrix from local to global coordinates
0127 
0128   /// Return the nominal - non-contextual transform
0129   const Acts::Transform3& nominalTransform() const;
0130   /// @return Reference to the nominal transformation matrix
0131 
0132   /// Return surface associated with this detector element
0133   const Acts::Surface& surface() const override;
0134   /// @return Const reference to the surface
0135 
0136   /// Return surface associated with this detector element
0137   ///
0138   /// @note this is the non-const access
0139   Acts::Surface& surface() override;
0140   /// @return Mutable reference to the surface
0141 
0142   /// Returns the thickness of the module
0143   /// @return Thickness of the detector element in units of length
0144   double thickness() const override;
0145 
0146   /// Return the TGeoNode for back navigation
0147   /// @return Reference to the underlying TGeoNode
0148   const TGeoNode& tgeoNode() const { return *m_detElement; }
0149 
0150  private:
0151   /// Pointer to TGeoNode (not owned)
0152   const TGeoNode* m_detElement{nullptr};
0153   /// Transformation of the detector element
0154   Acts::Transform3 m_transform = Acts::Transform3::Identity();
0155   /// Identifier of the detector element
0156   Identifier m_identifier;
0157   /// Boundaries of the detector element
0158   std::shared_ptr<const Acts::SurfaceBounds> m_bounds{nullptr};
0159   ///  Thickness of this detector element
0160   double m_thickness{0.};
0161   /// Corresponding Surface
0162   std::shared_ptr<Acts::Surface> m_surface{nullptr};
0163 };
0164 
0165 inline TGeoDetectorElement::Identifier TGeoDetectorElement::identifier() const {
0166   return m_identifier;
0167 }
0168 
0169 inline const Acts::Transform3& TGeoDetectorElement::transform(
0170     const Acts::GeometryContext& /*gctx*/) const {
0171   return m_transform;
0172 }
0173 
0174 inline const Acts::Surface& TGeoDetectorElement::surface() const {
0175   return (*m_surface);
0176 }
0177 
0178 inline Acts::Surface& TGeoDetectorElement::surface() {
0179   return (*m_surface);
0180 }
0181 
0182 inline double TGeoDetectorElement::thickness() const {
0183   return m_thickness;
0184 }
0185 
0186 }  // namespace ActsPlugins