Skip to content

Commit

Permalink
refactor options; fix detector creation
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand committed Nov 22, 2024
1 parent 7d92a2e commit a13e204
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class GdmlDetectorConstructionFactory final
explicit GdmlDetectorConstructionFactory(std::string path);

std::unique_ptr<G4VUserDetectorConstruction> factorize(
const std::vector<std::shared_ptr<Geant4::RegionCreator>>& regionCreators)
const override;
const Options& options) const override;

private:
/// Path to the Gdml file
Expand Down
7 changes: 3 additions & 4 deletions Examples/Algorithms/Geant4/src/GdmlDetectorConstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ GdmlDetectorConstructionFactory::GdmlDetectorConstructionFactory(
: m_path(std::move(path)) {}

std::unique_ptr<G4VUserDetectorConstruction>
GdmlDetectorConstructionFactory::factorize(
const std::vector<std::shared_ptr<Geant4::RegionCreator>>& regionCreators)
const {
return std::make_unique<GdmlDetectorConstruction>(m_path, regionCreators);
GdmlDetectorConstructionFactory::factorize(const Options& options) const {
return std::make_unique<GdmlDetectorConstruction>(m_path,
options.regionCreators);
}

} // namespace ActsExamples
3 changes: 2 additions & 1 deletion Examples/Algorithms/Geant4/src/Geant4Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ void Geant4SimulationBase::commonInitialization() {
// G4RunManager will take care of deletion
m_detectorConstruction =
config()
.detectorConstructionFactory->factorize(config().regionCreators)
.detectorConstructionFactory
->factorize({.regionCreators = config().regionCreators})
.release();
runManager().SetUserInitialization(m_detectorConstruction);
runManager().InitializeGeometry();
Expand Down
3 changes: 2 additions & 1 deletion Examples/Algorithms/Geant4HepMC/src/EventRecording.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ EventRecording::EventRecording(const EventRecording::Config& config,

// G4RunManager deals with the lifetime of these objects
m_runManager->SetUserInitialization(
m_cfg.detectorConstructionFactory->factorize(m_cfg.regionCreators)
m_cfg.detectorConstructionFactory
->factorize({.regionCreators = m_cfg.regionCreators})
.release());
m_runManager->SetUserInitialization(new FTFP_BERT);
m_runManager->SetUserAction(new Geant4::HepMC3::RunAction());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ namespace ActsExamples {

class Geant4DetectorConstructionFactory {
public:
struct Options {
std::vector<std::shared_ptr<Geant4::RegionCreator>> regionCreators;
};

virtual ~Geant4DetectorConstructionFactory() = default;

virtual std::unique_ptr<G4VUserDetectorConstruction> factorize(
const std::vector<std::shared_ptr<Geant4::RegionCreator>>& regionCreators)
const = 0;
const Options& options) const = 0;
};

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class DDG4DetectorConstructionFactory final
std::shared_ptr<DD4hepDetector> detector);

std::unique_ptr<G4VUserDetectorConstruction> factorize(
const std::vector<std::shared_ptr<Geant4::RegionCreator>>& regionCreators)
const override;
const Options& options) const override;

private:
std::shared_ptr<DD4hepDetector> m_detector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ DDG4DetectorConstructionFactory::DDG4DetectorConstructionFactory(
: m_detector(std::move(detector)) {}

std::unique_ptr<G4VUserDetectorConstruction>
DDG4DetectorConstructionFactory::factorize(
const std::vector<std::shared_ptr<Geant4::RegionCreator>>& regionCreators)
const {
return std::make_unique<DDG4DetectorConstruction>(m_detector, regionCreators);
DDG4DetectorConstructionFactory::factorize(const Options& options) const {
return std::make_unique<DDG4DetectorConstruction>(m_detector,
options.regionCreators);
}

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class GeoModelGeant4DetectorConstructionFactory final
const Acts::GeoModelTree& geoModelTree);

std::unique_ptr<G4VUserDetectorConstruction> factorize(
const std::vector<std::shared_ptr<Geant4::RegionCreator>>& regionCreators)
const override;
const Options& options) const override;

private:
/// The GeoModel tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ GeoModelGeant4DetectorConstructionFactory::

std::unique_ptr<G4VUserDetectorConstruction>
GeoModelGeant4DetectorConstructionFactory::factorize(
const std::vector<std::shared_ptr<Geant4::RegionCreator>>& regionCreators)
const {
return std::make_unique<GeoModelGeant4DetectorConstruction>(m_geoModelTree,
regionCreators);
const Options& options) const {
return std::make_unique<GeoModelGeant4DetectorConstruction>(
m_geoModelTree, options.regionCreators);
}

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class TelescopeG4DetectorConstructionFactory final
const TelescopeDetector::Config& cfg);

std::unique_ptr<G4VUserDetectorConstruction> factorize(
const std::vector<std::shared_ptr<Geant4::RegionCreator>>& regionCreators)
const override;
const Options& options) const override;

private:
/// The configuration of the telescope detector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,9 @@ TelescopeG4DetectorConstructionFactory::TelescopeG4DetectorConstructionFactory(

std::unique_ptr<G4VUserDetectorConstruction>
TelescopeG4DetectorConstructionFactory::factorize(
const std::vector<std::shared_ptr<Geant4::RegionCreator>>& regionCreators)
const {
return std::make_unique<TelescopeG4DetectorConstruction>(m_cfg,
regionCreators);
const Options& options) const {
return std::make_unique<TelescopeG4DetectorConstruction>(
m_cfg, options.regionCreators);
}

} // namespace ActsExamples
8 changes: 5 additions & 3 deletions Examples/Python/python/acts/_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ def create(*args, mdecorator=None, **kwargs):
setattr(cfg, k, v)
if hasattr(cfg, "materialDecorator"):
setattr(cfg, "materialDecorator", mdecorator)
det = cls(cfg)
tg, deco, _ = det.trackingGeometry()
detector = cls(cfg)
gen1holder = detector.buildGen1Geometry()
trackingGeometry = gen1holder.trackingGeometry
decorators = gen1holder.contextDecorators
Detector = namedtuple(
"Detector", ["detector", "trackingGeometry", "decorators"]
)
Expand All @@ -132,7 +134,7 @@ def __enter__(self):
def __exit__(self, *args):
pass

return DetectorContextManager(det, tg, deco)
return DetectorContextManager(detector, trackingGeometry, decorators)

return create

Expand Down

0 comments on commit a13e204

Please sign in to comment.