File indexing completed on 2025-01-18 09:27:42
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Utilities/BinningType.hpp"
0012 #include "Acts/Utilities/Delegate.hpp"
0013
0014 #include <array>
0015 #include <string>
0016 #include <vector>
0017
0018 #include "G4VPhysicalVolume.hh"
0019
0020 namespace Acts {
0021
0022
0023
0024
0025 EAxis binToGeant4Axis(const Acts::BinningValue& bv) {
0026 switch (bv) {
0027 case Acts::BinningValue::binX:
0028 return EAxis::kXAxis;
0029 case Acts::BinningValue::binY:
0030 return EAxis::kYAxis;
0031 case Acts::BinningValue::binZ:
0032 return EAxis::kZAxis;
0033 case Acts::BinningValue::binR:
0034 return EAxis::kRho;
0035 case Acts::BinningValue::binPhi:
0036 return EAxis::kPhi;
0037 default:
0038 throw std::invalid_argument(
0039 "No Geant4 axis conversion for this binning value");
0040 }
0041 }
0042
0043
0044 class IGeant4PhysicalVolumeSelector {
0045 public:
0046 virtual ~IGeant4PhysicalVolumeSelector() = default;
0047
0048
0049
0050 virtual bool select(const G4VPhysicalVolume& g4Phys) const = 0;
0051 };
0052
0053 namespace Geant4PhysicalVolumeSelectors {
0054
0055
0056 struct AllSelector : public IGeant4PhysicalVolumeSelector {
0057 bool select(const G4VPhysicalVolume& ) const final { return true; }
0058 };
0059
0060
0061
0062 struct NameSelector : public IGeant4PhysicalVolumeSelector {
0063 std::vector<std::string> names = {};
0064 bool exact = false;
0065
0066
0067
0068
0069 NameSelector(const std::vector<std::string>& ns, bool e = false)
0070 : names(ns), exact(e) {}
0071
0072
0073
0074
0075 bool select(const G4VPhysicalVolume& g4PhysVol) const final {
0076 std::string volumeName = g4PhysVol.GetName();
0077 bool matched = false;
0078 for (const auto& name : names) {
0079 matched = exact ? (volumeName == name)
0080 : volumeName.find(name) != std::string::npos;
0081 if (matched) {
0082 break;
0083 }
0084 }
0085 return matched;
0086 }
0087 };
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099 struct PositionSelector : public IGeant4PhysicalVolumeSelector {
0100 std::map<unsigned int, std::tuple<double, double>> m_ranges;
0101
0102
0103
0104 PositionSelector(
0105 const std::map<unsigned int, std::tuple<double, double>>& ranges)
0106 : m_ranges(ranges) {}
0107
0108
0109
0110
0111 bool select(const G4VPhysicalVolume& g4PhysVol) const final {
0112 bool matched = false;
0113 G4ThreeVector pos = g4PhysVol.GetTranslation();
0114 for (auto range : m_ranges) {
0115 auto& [min, max] = range.second;
0116 EAxis axis = static_cast<EAxis>(range.first);
0117 matched = (pos[axis] >= min) && (pos[axis] <= max);
0118 if (!matched) {
0119 break;
0120 }
0121 }
0122 return matched;
0123 }
0124 };
0125
0126 }
0127 }