Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-18 08:22:07

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/Definitions/Common.hpp"
0013 #include "Acts/Surfaces/Surface.hpp"
0014 
0015 #include <array>
0016 #include <memory>
0017 #include <tuple>
0018 
0019 namespace CLHEP {
0020 class Hep3Vector;
0021 class HepRotation;
0022 }  // namespace CLHEP
0023 
0024 namespace HepGeom {
0025 class Transform3D;
0026 }  // namespace HepGeom
0027 
0028 namespace Acts {
0029 class AnnulusBounds;
0030 class CylinderBounds;
0031 class RadialBounds;
0032 class RectangleBounds;
0033 class TrapezoidBounds;
0034 class PlanarBounds;
0035 class LineBounds;
0036 class Material;
0037 class HomogeneousSurfaceMaterial;
0038 class HomogeneousVolumeMaterial;
0039 class CylinderVolumeBounds;
0040 
0041 }  // namespace Acts
0042 
0043 class G4Box;
0044 class G4Material;
0045 class G4Trd;
0046 class G4Trap;
0047 class G4Tubs;
0048 class G4VSolid;
0049 class G4VPhysicalVolume;
0050 using G4ThreeVector = CLHEP::Hep3Vector;
0051 using G4RotationMatrix = CLHEP::HepRotation;
0052 using G4Transform3D = HepGeom::Transform3D;
0053 
0054 namespace ActsPlugins {
0055 
0056 struct Geant4AlgebraConverter {
0057   // A potential scalar between Geant4 and ACTS
0058   double scale = 1.;
0059 
0060   /// @brief Translate a geometry transform: translation only
0061   ///
0062   /// @param g4Trans the translation of the Geant4 object
0063   ///
0064   /// @return a Acts transform
0065   Acts::Transform3 transform(const G4ThreeVector& g4Trans);
0066 
0067   /// @brief Translate a geometry transform
0068   ///
0069   /// @param g4Rot the rotation of the Geant4 object
0070   /// @param g4Trans the translation of the Geant4 object
0071   ///
0072   /// @return a Acts transform
0073   Acts::Transform3 transform(const G4RotationMatrix& g4Rot,
0074                              const G4ThreeVector& g4Trans);
0075 
0076   /// @brief Translate a geometry transform
0077   ///
0078   /// @param g4Trf the Geant4 transform object
0079   ///
0080   /// @return a Acts transform
0081   Acts::Transform3 transform(const G4Transform3D& g4Trf);
0082 
0083   /// @brief Translate a geometry transform from a G4 physical volume
0084   ///
0085   /// @param g4PhysVol the Geant4 physical volume
0086   ///
0087   /// @return a Acts transform
0088   Acts::Transform3 transform(const G4VPhysicalVolume& g4PhysVol);
0089 };
0090 
0091 // The following set of converters convert a Geant4 volume shape
0092 // to an ACTS surface bounds object, this is for converting the volume
0093 // based geometry into a surfaced based one.
0094 //
0095 // The obviously smallest expansion/extrusion is condensed to the epsilon
0096 // thin surface.
0097 struct Geant4ShapeConverter {
0098   /// A scale between Geant4 and ACTS
0099   double scale = 1.;
0100   /// A description to keep the axis order, if it is set to false
0101   /// cyclic re-ordering will happen, otherwise axis flip if needed in
0102   /// order to keep the system right-handed
0103   bool keepAxisOrder = false;
0104 
0105   /// @brief Convert to cylinder bounds
0106   ///
0107   /// @param g4Tubs a Geant4 tube shape
0108   ///
0109   /// @return an Acts Cylinder bounds object, and thickness
0110   std::tuple<std::shared_ptr<Acts::CylinderBounds>, double> cylinderBounds(
0111       const G4Tubs& g4Tubs);
0112 
0113   /// @brief Convert to radial bounds
0114   ///
0115   /// @param g4Tubs a Geant4 tube shape
0116   ///
0117   /// @return an Acts Radial bounds object and thickness
0118   std::tuple<std::shared_ptr<Acts::RadialBounds>, double> radialBounds(
0119       const G4Tubs& g4Tubs);
0120 
0121   /// @brief Convert to line/straw bounds
0122   ///
0123   /// @param g4Tubs a Geant4 tube shape
0124   ///
0125   /// @return an Acts line bounds object and thickness
0126   std::shared_ptr<Acts::LineBounds> lineBounds(const G4Tubs& g4Tubs);
0127 
0128   /// @brief Convert to rectangle bounds
0129   ///
0130   /// @param g4Box a Geant4 box shape
0131   ///
0132   /// @return an ACTS Rectangle bounds shape,  axis orientation, and thickness
0133   std::tuple<std::shared_ptr<Acts::RectangleBounds>, std::array<int, 2u>,
0134              double>
0135   rectangleBounds(const G4Box& g4Box);
0136 
0137   /// @brief Convert to trapezoid bounds - from Trd
0138   ///
0139   /// @param g4Trd a Geant4 trapezoid shape
0140   ///
0141   /// @return an ACTS Trapezoid bounds object, axis orientation, and thickness
0142   std::tuple<std::shared_ptr<Acts::TrapezoidBounds>, std::array<int, 2u>,
0143              double>
0144   trapezoidBounds(const G4Trd& g4Trd);
0145 
0146   /// @brief Convert to trapezoid bounds - from Trap
0147   ///
0148   /// @param g4Trap a Geant4 trapezoid shape
0149   ///
0150   /// @return an ACTS Trapezoid bounds object, axis orientation, and thickness
0151   std::tuple<std::shared_ptr<Acts::TrapezoidBounds>, std::array<int, 2u>,
0152              double>
0153   trapezoidBounds(const G4Trap& g4Trap);
0154 
0155   /// @brief Convert to general solid into a planar shape
0156   ///
0157   /// @param g4Solid a Geant4 solid shape
0158   ///
0159   /// @return an ACTS Planar bounds object,
0160   /// the axes, and the thickness of the compressed dimension
0161   std::tuple<std::shared_ptr<Acts::PlanarBounds>, std::array<int, 2u>, double>
0162   planarBounds(const G4VSolid& g4Solid);
0163 };
0164 
0165 struct Geant4PhysicalVolumeConverter {
0166   /// Optionally allow to foce a type, throws exception if not possible
0167   Acts::Surface::SurfaceType forcedType = Acts::Surface::SurfaceType::Other;
0168 
0169   /// @brief Convert a Geant4 phsyical volume to a surface
0170   ///
0171   /// @param g4PhysVol the physical volume to be constructed
0172   /// @param toGlobal the global transformation before the volume
0173   /// @param convertMaterial a material conversion flag
0174   /// @param compressed the compressed thickness of the converted material
0175   ///
0176   /// @return a shared surface object
0177   std::shared_ptr<Acts::Surface> surface(const G4VPhysicalVolume& g4PhysVol,
0178                                          const Acts::Transform3& toGlobal,
0179                                          bool convertMaterial = false,
0180                                          double compressed = 0.);
0181 };
0182 
0183 struct Geant4MaterialConverter {
0184   Acts::Material material(const G4Material& g4Material, double compression = 1);
0185 
0186   /// @brief Convert a Geant4 material to a surface material description
0187   ///
0188   /// @param g4Material the geant4 material description
0189   /// @param original the original thickness
0190   /// @param compressed the compressed thickness
0191   ///
0192   std::shared_ptr<Acts::HomogeneousSurfaceMaterial> surfaceMaterial(
0193       const G4Material& g4Material, double original, double compressed);
0194 };
0195 
0196 struct Geant4VolumeConverter {
0197   /// @brief Convert to cylinder bounds
0198   ///
0199   /// @param g4Tubs a Geant4 tube shape
0200   ///
0201   /// @return an Acts Cylinder bounds object
0202   std::shared_ptr<Acts::CylinderVolumeBounds> cylinderBounds(
0203       const G4Tubs& g4Tubs);
0204 };
0205 
0206 }  // namespace ActsPlugins