Skip to content

Commit

Permalink
chore: Cleanup some Geant4 Examples code (#3895)
Browse files Browse the repository at this point in the history
Accumulated changes I wanted to branch out from #3498

- Improve namespaces
- Use namespaces in source files
- Clean includes
  • Loading branch information
andiwand authored Nov 23, 2024
1 parent be30786 commit cafee58
Show file tree
Hide file tree
Showing 45 changed files with 304 additions and 300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DDG4DetectorConstruction final : public G4VUserDetectorConstruction {
public:
DDG4DetectorConstruction(
std::shared_ptr<DD4hep::DD4hepDetector> detector,
std::vector<std::shared_ptr<RegionCreator>> regionCreators = {});
std::vector<std::shared_ptr<Geant4::RegionCreator>> regionCreators = {});
~DDG4DetectorConstruction() final;

/// Convert the stored DD4hep detector to a Geant4 description.
Expand All @@ -47,7 +47,7 @@ class DDG4DetectorConstruction final : public G4VUserDetectorConstruction {
/// The Acts DD4hep detector instance
std::shared_ptr<DD4hep::DD4hepDetector> m_detector;
/// Region creators
std::vector<std::shared_ptr<RegionCreator>> m_regionCreators;
std::vector<std::shared_ptr<Geant4::RegionCreator>> m_regionCreators;
/// The world volume
G4VPhysicalVolume* m_world = nullptr;

Expand All @@ -56,11 +56,11 @@ class DDG4DetectorConstruction final : public G4VUserDetectorConstruction {
};

class DDG4DetectorConstructionFactory final
: public DetectorConstructionFactory {
: public Geant4::DetectorConstructionFactory {
public:
DDG4DetectorConstructionFactory(
std::shared_ptr<DD4hep::DD4hepDetector> detector,
std::vector<std::shared_ptr<RegionCreator>> regionCreators = {});
std::vector<std::shared_ptr<Geant4::RegionCreator>> regionCreators = {});
~DDG4DetectorConstructionFactory() final;

std::unique_ptr<G4VUserDetectorConstruction> factorize() const override;
Expand All @@ -69,7 +69,7 @@ class DDG4DetectorConstructionFactory final
/// The Acts DD4hep detector instance
std::shared_ptr<DD4hep::DD4hepDetector> m_detector;
/// Region creators
std::vector<std::shared_ptr<RegionCreator>> m_regionCreators;
std::vector<std::shared_ptr<Geant4::RegionCreator>> m_regionCreators;
};

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <G4VUserDetectorConstruction.hh>

namespace ActsExamples {
namespace ActsExamples::Geant4 {

/// Silly Geant4 will destroy the detector construction after the run manager is
/// destructed. This class works around it by factorizing a factory.
Expand All @@ -23,4 +23,4 @@ class DetectorConstructionFactory {
virtual std::unique_ptr<G4VUserDetectorConstruction> factorize() const = 0;
};

} // namespace ActsExamples
} // namespace ActsExamples::Geant4
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
#include "G4Types.hh"

namespace ActsExamples {

class WhiteBoard;
}

namespace ActsExamples::Geant4 {

/// Common event store for all Geant4 related sub algorithms
struct EventStore {
Expand Down Expand Up @@ -80,4 +82,4 @@ struct EventStore {
std::unordered_map<BarcodeWithoutSubparticle, std::size_t> subparticleMap;
};

} // namespace ActsExamples
} // namespace ActsExamples::Geant4
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GdmlDetectorConstruction final : public G4VUserDetectorConstruction {
/// @param regionCreators are the region creators
GdmlDetectorConstruction(
std::string path,
std::vector<std::shared_ptr<RegionCreator>> regionCreators = {});
std::vector<std::shared_ptr<Geant4::RegionCreator>> regionCreators = {});

/// Read the file and parse it to construct the Geant4 description
///
Expand All @@ -38,25 +38,25 @@ class GdmlDetectorConstruction final : public G4VUserDetectorConstruction {
/// Path to the Gdml file
std::string m_path;
/// Region creators
std::vector<std::shared_ptr<RegionCreator>> m_regionCreators;
std::vector<std::shared_ptr<Geant4::RegionCreator>> m_regionCreators;
/// Cached world volume
G4VPhysicalVolume* m_world = nullptr;
};

class GdmlDetectorConstructionFactory final
: public DetectorConstructionFactory {
: public Geant4::DetectorConstructionFactory {
public:
GdmlDetectorConstructionFactory(
std::string path,
std::vector<std::shared_ptr<RegionCreator>> regionCreators = {});
std::vector<std::shared_ptr<Geant4::RegionCreator>> regionCreators = {});

std::unique_ptr<G4VUserDetectorConstruction> factorize() const override;

private:
/// Path to the Gdml file
std::string m_path;
/// Region creators
std::vector<std::shared_ptr<RegionCreator>> m_regionCreators;
std::vector<std::shared_ptr<Geant4::RegionCreator>> m_regionCreators;
};

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ class G4VUserPhysicsList;

namespace ActsExamples {

class PhysicsListFactory;
class Geant4Manager;
namespace Geant4 {
class PhysicsListFactory;
}

/// Manages the life time of G4RunManager and G4VUserPhysicsList.
///
Expand Down Expand Up @@ -75,12 +77,14 @@ class Geant4Manager {
/// Registers a named physics list factory to the manager for easy
/// instantiation when needed.
void registerPhysicsListFactory(
std::string name, std::shared_ptr<PhysicsListFactory> physicsListFactory);
std::string name,
std::shared_ptr<Geant4::PhysicsListFactory> physicsListFactory);
std::unique_ptr<G4VUserPhysicsList> createPhysicsList(
const std::string &name) const;

/// Get the current list of physics list factories.
const std::unordered_map<std::string, std::shared_ptr<PhysicsListFactory>> &
const std::unordered_map<std::string,
std::shared_ptr<Geant4::PhysicsListFactory>> &
getPhysicsListFactories() const;

private:
Expand All @@ -89,7 +93,7 @@ class Geant4Manager {

bool m_created = false;
std::weak_ptr<Geant4Handle> m_handle;
std::unordered_map<std::string, std::shared_ptr<PhysicsListFactory>>
std::unordered_map<std::string, std::shared_ptr<Geant4::PhysicsListFactory>>
m_physicsListFactories;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ class MagneticFieldProvider;
class Volume;
} // namespace Acts

class G4VUserDetectorConstruction;

namespace ActsExamples {
struct Geant4Handle;

namespace Geant4 {
class DetectorConstructionFactory;
class SensitiveSurfaceMapper;
struct EventStore;
struct Geant4Handle;
class RegionCreator;
} // namespace Geant4

/// Abstracts common Geant4 Acts algorithm behaviour.
class Geant4SimulationBase : public IAlgorithm {
Expand All @@ -61,7 +62,8 @@ class Geant4SimulationBase : public IAlgorithm {

/// Detector construction object.
/// G4RunManager will take care of deletion
std::shared_ptr<DetectorConstructionFactory> detectorConstructionFactory;
std::shared_ptr<Geant4::DetectorConstructionFactory>
detectorConstructionFactory;

/// Optional Geant4 instance overwrite.
std::shared_ptr<Geant4Handle> geant4Handle;
Expand Down Expand Up @@ -91,11 +93,11 @@ class Geant4SimulationBase : public IAlgorithm {

G4RunManager& runManager() const;

EventStore& eventStore() const;
Geant4::EventStore& eventStore() const;

std::unique_ptr<const Acts::Logger> m_logger;

std::shared_ptr<EventStore> m_eventStore;
std::shared_ptr<Geant4::EventStore> m_eventStore;

int m_geant4Level{};

Expand All @@ -122,8 +124,8 @@ class Geant4Simulation final : public Geant4SimulationBase {
std::string outputParticles = "particles_simulated";

/// The ACTS sensitive surfaces in a mapper, used for hit creation
std::shared_ptr<const SensitiveSurfaceMapper> sensitiveSurfaceMapper =
nullptr;
std::shared_ptr<const Geant4::SensitiveSurfaceMapper>
sensitiveSurfaceMapper = nullptr;

/// The ACTS Magnetic field provider
std::shared_ptr<const Acts::MagneticFieldProvider> magneticField = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Acts {
class MagneticFieldProvider;
}

namespace ActsExamples {
namespace ActsExamples::Geant4 {

/// A magnetic field wrapper for the Acts magnetic field
/// to be used with Geant4.
Expand Down Expand Up @@ -58,4 +58,4 @@ class MagneticFieldWrapper : public G4MagneticField {
std::unique_ptr<const Acts::Logger> m_logger;
};

} // namespace ActsExamples
} // namespace ActsExamples::Geant4
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@

#include <memory>
#include <string>
#include <vector>

#include <G4VUserPhysicsList.hh>

namespace ActsExamples {
namespace ActsExamples::Geant4 {

/// @class MaterialPhysicsList
///
Expand Down Expand Up @@ -57,4 +56,4 @@ class MaterialPhysicsList final : public G4VUserPhysicsList {
std::unique_ptr<const Acts::Logger> m_logger;
};

} // namespace ActsExamples
} // namespace ActsExamples::Geant4
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class G4Step;

namespace ActsExamples {
namespace ActsExamples::Geant4 {

/// @class MaterialSteppingAction
///
Expand Down Expand Up @@ -66,4 +66,4 @@ class MaterialSteppingAction final : public G4UserSteppingAction {
std::unique_ptr<const Acts::Logger> m_logger;
};

} // namespace ActsExamples
} // namespace ActsExamples::Geant4
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Acts {
class Volume;
} // namespace Acts

namespace ActsExamples {
namespace ActsExamples::Geant4 {

/// A G4SteppingAction that is called for every step in the simulation process.
///
Expand Down Expand Up @@ -67,4 +67,4 @@ class ParticleKillAction : public G4UserSteppingAction {
std::unique_ptr<const Acts::Logger> m_logger;
};

} // namespace ActsExamples
} // namespace ActsExamples::Geant4
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#pragma once

#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/EventData/SimHit.hpp"
#include "ActsExamples/EventData/SimParticle.hpp"
#include "ActsExamples/Geant4/EventStore.hpp"

Expand All @@ -22,7 +21,7 @@

class G4Track;

namespace ActsExamples {
namespace ActsExamples::Geant4 {

/// The G4UserTrackingAction that is called for every track in
/// the simulation process.
Expand Down Expand Up @@ -82,4 +81,4 @@ class ParticleTrackingAction : public G4UserTrackingAction {
std::unique_ptr<const Acts::Logger> m_logger;
};

} // namespace ActsExamples
} // namespace ActsExamples::Geant4
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class G4VUserPhysicsList;

namespace ActsExamples {
namespace ActsExamples::Geant4 {

/// A factory around G4VUserPhysicsList which allows on demand instantiation.
class PhysicsListFactory {
Expand All @@ -36,4 +36,4 @@ class PhysicsListFactoryFunction final : public PhysicsListFactory {
Function m_function;
};

} // namespace ActsExamples
} // namespace ActsExamples::Geant4
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <string>
#include <vector>

namespace ActsExamples {
namespace ActsExamples::Geant4 {

/// Geant4 Region Creator
///
Expand Down Expand Up @@ -49,7 +49,7 @@ class RegionCreator {
Acts::Logging::Level level);

/// Construct the region
void Construct();
void construct();

/// Readonly access to the configuration
const Config& config() const { return m_cfg; }
Expand All @@ -68,4 +68,4 @@ class RegionCreator {
std::unique_ptr<const Acts::Logger> m_logger;
};

} // namespace ActsExamples
} // namespace ActsExamples::Geant4
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Acts {
class Surface;
}

namespace ActsExamples {
namespace ActsExamples::Geant4 {

/// The G4SteppingAction that is called for every step in
/// the simulation process.
Expand Down Expand Up @@ -83,4 +83,4 @@ class SensitiveSteppingAction : public G4UserSteppingAction {
m_surfaceMapping;
};

} // namespace ActsExamples
} // namespace ActsExamples::Geant4
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Utilities/GridAccessHelpers.hpp"
#include "Acts/Utilities/Logger.hpp"

#include <map>
Expand All @@ -26,7 +25,7 @@ namespace Acts {
class Surface;
}

namespace ActsExamples {
namespace ActsExamples::Geant4 {

struct SensitiveCandidatesBase {
/// Get the sensitive surfaces for a given position
Expand Down Expand Up @@ -148,4 +147,4 @@ class SensitiveSurfaceMapper {
std::unique_ptr<const Acts::Logger> m_logger;
};

} // namespace ActsExamples
} // namespace ActsExamples::Geant4
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class G4Event;

namespace ActsExamples {
namespace ActsExamples::Geant4 {

/// @class SimParticleTranslation
///
Expand Down Expand Up @@ -81,4 +81,4 @@ class SimParticleTranslation final : public G4VUserPrimaryGeneratorAction {
std::unique_ptr<const Acts::Logger> m_logger;
};

} // namespace ActsExamples
} // namespace ActsExamples::Geant4
Loading

0 comments on commit cafee58

Please sign in to comment.