Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:20

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 #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   // Get Rotation and translation
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   // Get the logical volume
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   // Check if the volume is accepted by a sensitive or passive selector
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     // Conversion and selection code
0054     ++cache.matchedG4Volumes;
0055 
0056     // Attempt the conversion
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       // Count the material conversion
0064       if (surface->surfaceMaterial() != nullptr) {
0065         ++cache.convertedMaterials;
0066       }
0067 
0068       if (sensitive) {
0069         // empty geometry context is fine as the transform was just passed down
0070         // without context before
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 }