File indexing completed on 2025-01-18 09:11:36
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Geant4/RegionCreator.hpp"
0010
0011 #include "Acts/Utilities/Logger.hpp"
0012
0013 #include <G4LogicalVolume.hh>
0014 #include <G4LogicalVolumeStore.hh>
0015 #include <G4ProductionCuts.hh>
0016 #include <G4Region.hh>
0017
0018 namespace ActsExamples::Geant4 {
0019
0020 RegionCreator::RegionCreator(const Config& cfg) : m_cfg(cfg) {}
0021
0022 G4Region* RegionCreator::buildRegion(const Acts::Logger& logger) const {
0023
0024 G4Region* region = new G4Region(m_cfg.name);
0025
0026
0027 std::size_t nVolumes{0};
0028 G4LogicalVolumeStore* logStore = G4LogicalVolumeStore::GetInstance();
0029 for (const std::string& volumeName : m_cfg.volumes) {
0030 std::size_t nVolumesCurrent{0};
0031 for (auto* it : *logStore) {
0032 ACTS_DEBUG("Checking volume " << it->GetName() << " against "
0033 << volumeName);
0034 if (volumeName == static_cast<const std::string&>(it->GetName())) {
0035 nVolumesCurrent++;
0036 it->SetRegion(region);
0037 region->AddRootLogicalVolume(it);
0038 ACTS_DEBUG("Volume " << it->GetName() << " added to region");
0039 }
0040 }
0041 if (nVolumesCurrent == 0) {
0042 ACTS_WARNING("No volumes matching \""
0043 << volumeName << "\" found in G4 LogicalVolumeStore. "
0044 << m_cfg.name
0045 << " G4PhysicsRegion may not behave as intended.");
0046 }
0047 nVolumes += nVolumesCurrent;
0048 }
0049
0050 ACTS_INFO("Created region " << m_cfg.name);
0051 ACTS_INFO("A total of " << nVolumes << " volumes were assigned");
0052
0053
0054 G4ProductionCuts* cuts = new G4ProductionCuts();
0055 cuts->SetProductionCut(m_cfg.gammaCut, "gamma");
0056 cuts->SetProductionCut(m_cfg.electronCut, "e-");
0057 cuts->SetProductionCut(m_cfg.positronCut, "e+");
0058 cuts->SetProductionCut(m_cfg.protonCut, "proton");
0059
0060 ACTS_INFO("Setting production cuts to");
0061 ACTS_INFO(" gamma: " << m_cfg.gammaCut);
0062 ACTS_INFO(" e-: " << m_cfg.electronCut);
0063 ACTS_INFO(" e+: " << m_cfg.positronCut);
0064 ACTS_INFO(" proton: " << m_cfg.protonCut);
0065
0066
0067 region->SetProductionCuts(cuts);
0068
0069 return region;
0070 }
0071
0072 }