File indexing completed on 2025-01-18 09:12:20
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Plugins/Geant4/Geant4DetectorSurfaceFactory.hpp"
0010
0011 #include "Acts/Plugins/Geant4/Geant4Converters.hpp"
0012 #include "Acts/Plugins/Geant4/Geant4DetectorElement.hpp"
0013 #include "Acts/Plugins/Geant4/Geant4PhysicalVolumeSelectors.hpp"
0014 #include "Acts/Surfaces/Surface.hpp"
0015 #include "Acts/Utilities/StringHelpers.hpp"
0016
0017 #include <utility>
0018
0019 #include "G4LogicalVolume.hh"
0020 #include "G4Transform3D.hh"
0021 #include "G4VPhysicalVolume.hh"
0022
0023 void Acts::Geant4DetectorSurfaceFactory::construct(
0024 Cache& cache, const G4Transform3D& g4ToGlobal,
0025 const G4VPhysicalVolume& g4PhysVol, const Options& option) {
0026
0027 auto g4Translation = g4PhysVol.GetTranslation();
0028 auto g4Rotation = g4PhysVol.GetRotation();
0029
0030 auto newTranslation =
0031 g4ToGlobal.getTranslation() + g4ToGlobal.getRotation() * g4Translation;
0032 auto newRotation = (g4Rotation == nullptr)
0033 ? g4ToGlobal.getRotation() * CLHEP::HepRotation()
0034 : g4ToGlobal.getRotation() * g4Rotation->inverse();
0035
0036 G4Transform3D newToGlobal(newRotation, newTranslation);
0037
0038
0039 auto g4LogicalVolume = g4PhysVol.GetLogicalVolume();
0040 std::size_t nDaughters = g4LogicalVolume->GetNoDaughters();
0041 for (std::size_t d = 0; d < nDaughters; ++d) {
0042 auto daughter = g4LogicalVolume->GetDaughter(d);
0043 construct(cache, newToGlobal, *daughter, option);
0044 }
0045
0046
0047 bool sensitive = option.sensitiveSurfaceSelector != nullptr &&
0048 option.sensitiveSurfaceSelector->select(g4PhysVol);
0049 bool passive = option.passiveSurfaceSelector != nullptr &&
0050 option.passiveSurfaceSelector->select(g4PhysVol);
0051
0052 if (sensitive || passive) {
0053
0054 ++cache.matchedG4Volumes;
0055
0056
0057 auto surface = Acts::Geant4PhysicalVolumeConverter{}.surface(
0058 g4PhysVol, Geant4AlgebraConverter{}.transform(newToGlobal),
0059 option.convertMaterial, option.convertedMaterialThickness);
0060
0061 if (surface != nullptr) {
0062 ++cache.convertedSurfaces;
0063
0064 if (surface->surfaceMaterial() != nullptr) {
0065 ++cache.convertedMaterials;
0066 }
0067
0068 if (sensitive) {
0069
0070
0071 auto detectorElement = std::make_shared<Acts::Geant4DetectorElement>(
0072 surface, g4PhysVol, surface->transform({}), 0.1);
0073 surface->assignDetectorElement(*detectorElement);
0074
0075 cache.sensitiveSurfaces.push_back(
0076 {std::move(detectorElement), std::move(surface)});
0077 } else {
0078 cache.passiveSurfaces.push_back(std::move(surface));
0079 }
0080 }
0081 }
0082 }