Back to home page

EIC code displayed by LXR

 
 

    


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

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/Surfaces/Surface.hpp"
0013 #include "ActsPlugins/Geant4/Geant4DetectorElement.hpp"
0014 #include "ActsPlugins/Geant4/Geant4PhysicalVolumeSelectors.hpp"
0015 
0016 #include <cstddef>
0017 #include <memory>
0018 #include <tuple>
0019 #include <vector>
0020 
0021 namespace HepGeom {
0022 class Transform3D;
0023 }
0024 
0025 class G4VPhysicalVolume;
0026 using G4Transform3D = HepGeom::Transform3D;
0027 
0028 namespace ActsPlugins {
0029 
0030 class Geant4DetectorElement;
0031 class IGeant4PhysicalVolumeSelector;
0032 
0033 /// A factory to convert Geant4 physical volumes
0034 /// into Geant4 detector elements
0035 ///
0036 class Geant4DetectorSurfaceFactory {
0037  public:
0038   /// Type alias for detector element factory function
0039   using ElementFactory = std::function<std::shared_ptr<Geant4DetectorElement>(
0040       std::shared_ptr<Acts::Surface>, const G4VPhysicalVolume&,
0041       const Acts::Transform3&, double)>;
0042 
0043   /// Nested configuration struct that holds
0044   /// global lifetime configuration
0045   struct Config {
0046     /// @cond
0047     /// The detector element factory with default implementation
0048     ElementFactory detectorElementFactory =
0049         [](std::shared_ptr<Acts::Surface> surface,
0050            const G4VPhysicalVolume& g4physVol, const Acts::Transform3& toGlobal,
0051            double thickness) {
0052           return std::make_shared<Geant4DetectorElement>(
0053               std::move(surface), g4physVol, toGlobal, thickness);
0054         };
0055     /// @endcond
0056   };
0057 
0058   /// Type alias for sensitive surface with detector element
0059   using Geant4SensitiveSurface =
0060       std::tuple<std::shared_ptr<Geant4DetectorElement>,
0061                  std::shared_ptr<Acts::Surface>>;
0062 
0063   using Geant4PassiveSurface = std::shared_ptr<Acts::Surface>;
0064   /// Type alias for passive surface
0065 
0066   /// Nested cache that records the conversion status
0067   struct Cache {
0068     /// The created detector elements - for the detector store
0069     std::vector<Geant4SensitiveSurface> sensitiveSurfaces;
0070     /// The created non-const surfaces - for further processing,
0071     std::vector<Geant4PassiveSurface> passiveSurfaces;
0072     /// matching and conversion statistics: volumes
0073     std::size_t matchedG4Volumes = 0;
0074     /// matching and conversion statistics: surfaces
0075     std::size_t convertedSurfaces = 0;
0076     /// matching and conversion statistics: materials
0077     std::size_t convertedMaterials = 0;
0078   };
0079 
0080   /// Nested option struct that allows per call changeable configuration
0081   struct Options {
0082     /// Convert the length scale
0083     double scaleConversion = 1.;
0084     /// Convert the material
0085     bool convertMaterial = false;
0086     /// Converted material thickness (< 0 indicates keeping original thickness)
0087     double convertedMaterialThickness = -1;
0088     /// A selector for sensitive surfaces
0089     std::shared_ptr<IGeant4PhysicalVolumeSelector> sensitiveSurfaceSelector =
0090         nullptr;
0091     /// A selector for passive surfaces
0092     std::shared_ptr<IGeant4PhysicalVolumeSelector> passiveSurfaceSelector =
0093         nullptr;
0094   };
0095 
0096   /// The Geant4 detector element factory
0097   Geant4DetectorSurfaceFactory() = delete;
0098 
0099   /// The Geant4 detector element factory with a configuration
0100   ///
0101   /// @param config the configuration of the factory
0102   /// @param mlogger a screen output logger
0103   explicit Geant4DetectorSurfaceFactory(
0104       const Config& config,
0105       std::unique_ptr<const Acts::Logger> mlogger = Acts::getDefaultLogger(
0106           "Geant4DetectorSurfaceFactory", Acts::Logging::INFO))
0107       : m_config(config), m_logger(std::move(mlogger)) {}
0108 
0109   /// Construction method of the detector elements
0110   ///
0111   /// @param cache [in,out] into which the Elements are filled
0112   /// @param g4ToGlobal the transformation to global
0113   /// @param g4PhysVol the current physical volume
0114   /// @param option the factory creation option
0115   ///
0116   void construct(Cache& cache, const G4Transform3D& g4ToGlobal,
0117                  const G4VPhysicalVolume& g4PhysVol, const Options& option);
0118 
0119  private:
0120   /// The configuration of the factory
0121   Config m_config = Config{};
0122 
0123   /// Logging instance
0124   std::unique_ptr<const Acts::Logger> m_logger;
0125 
0126   /// Private access to the logger
0127   const Acts::Logger& logger() const { return *m_logger; }
0128 };
0129 
0130 }  // namespace ActsPlugins