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/Utilities/BinningType.hpp"
0012 #include "Acts/Utilities/Delegate.hpp"
0013 
0014 #include <array>
0015 #include <map>
0016 #include <string>
0017 #include <vector>
0018 
0019 class G4VPhysicalVolume;
0020 
0021 namespace ActsPlugins {
0022 
0023 /// Interface class for selectors from physical volumes
0024 class IGeant4PhysicalVolumeSelector {
0025  public:
0026   virtual ~IGeant4PhysicalVolumeSelector() = default;
0027   /// @brief  The main interface method
0028   /// @param g4Phys the physical volume to be checked
0029   /// @return a boolean indicating if it should be selected or not
0030   virtual bool select(const G4VPhysicalVolume& g4Phys) const = 0;
0031 };
0032 
0033 namespace Geant4PhysicalVolumeSelectors {
0034 
0035 /// @brief  Struct that selects all G4VPhysicalVolume objects
0036 struct AllSelector : public IGeant4PhysicalVolumeSelector {
0037   bool select(const G4VPhysicalVolume& /*g4Phys*/) const final { return true; }
0038 };
0039 
0040 /// @brief Struct that selects G4VPhysicalVolume objects
0041 /// that match one of the provided names, exact or partially
0042 struct NameSelector : public IGeant4PhysicalVolumeSelector {
0043   /// List of volume names for selection criteria
0044   std::vector<std::string> names = {};
0045   /// Flag indicating exact name matching vs partial matching
0046   bool exact = false;
0047 
0048   /// Constructor with arguments
0049   /// @param ns the provided list of names
0050   /// @param e whether to select them exact or not
0051   explicit NameSelector(const std::vector<std::string>& ns, bool e = false)
0052       : names(ns), exact(e) {}
0053 
0054   /// Secect function for the volume
0055   /// @param g4PhysVol the volume that is checked
0056   /// @return a boolean indicating the selection
0057   bool select(const G4VPhysicalVolume& g4PhysVol) const final;
0058 };
0059 
0060 /// @brief Struct that selects G4VPhysicalVolume objects
0061 /// based on the allowed range of their position
0062 ///
0063 /// @note Can be used for preselection of volumes
0064 /// before a KDTree search. This way the memory
0065 /// consumption can be reduced, compromising the
0066 /// execution speed
0067 ///
0068 /// @note Careful with axis conventions as
0069 /// Geant4 uses a different one than Acts
0070 struct PositionSelector : public IGeant4PhysicalVolumeSelector {
0071   /// Map of axis indices to position ranges for volume selection
0072   std::map<unsigned int, std::tuple<double, double>> m_ranges;
0073 
0074   /// Constructor with arguments
0075   /// @param ranges the provided map of axes of ranges
0076   explicit PositionSelector(
0077       const std::map<unsigned int, std::tuple<double, double>>& ranges)
0078       : m_ranges(ranges) {}
0079 
0080   /// Secect function for the volume
0081   /// @param g4PhysVol the volume that is checked
0082   /// @return a boolean indicating the selection
0083   bool select(const G4VPhysicalVolume& g4PhysVol) const final;
0084 };
0085 
0086 }  // namespace Geant4PhysicalVolumeSelectors
0087 }  // namespace ActsPlugins