Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand committed Nov 22, 2024
1 parent dca7052 commit 1fa479b
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,84 @@ class RegionCreator;
} // namespace Geant4
} // namespace ActsExamples

class G4VUserDetectorConstruction;

namespace ActsExamples {

struct Gen1GeometryHolder {
Acts::GeometryContext geometryContext;
class DetectorBase {
public:
virtual ~DetectorBase() = default;

std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry;
std::vector<std::shared_ptr<ActsExamples::IContextDecorator>>
contextDecorators;
std::vector<std::shared_ptr<const Acts::DetectorElementBase>> detectorStore;
};
virtual const Acts::GeometryContext& geometryContext() const = 0;

struct Gen2GeometryHolder {
Acts::GeometryContext geometryContext;
virtual const std::vector<std::shared_ptr<const Acts::DetectorElementBase>>&
detectorStore() const = 0;
virtual const std::shared_ptr<const Acts::TrackingGeometry>& gen1Geometry()
const = 0;
virtual const std::shared_ptr<Acts::Experimental::Detector>& gen2Geometry()
const = 0;
virtual const std::vector<std::shared_ptr<ActsExamples::IContextDecorator>>&
contextDecorators() const = 0;

std::shared_ptr<Acts::Experimental::Detector> detector;
std::vector<std::shared_ptr<ActsExamples::IContextDecorator>>
contextDecorators;
std::vector<std::shared_ptr<const Acts::DetectorElementBase>> detectorStore;
virtual const std::shared_ptr<Geant4DetectorConstructionFactory>&
geant4DetectorConstructionFactory() const = 0;
};

class DetectorBase {
class DetectorFactoryBase {
public:
explicit DetectorBase(std::unique_ptr<const Acts::Logger> logger);
DetectorBase(const DetectorBase&) = delete;
DetectorBase(DetectorBase&&);
virtual ~DetectorBase();
DetectorBase& operator=(const DetectorBase&) = delete;
DetectorBase& operator=(DetectorBase&&);
explicit DetectorFactoryBase(std::unique_ptr<const Acts::Logger> logger);
DetectorFactoryBase(const DetectorFactoryBase&) = delete;
DetectorFactoryBase(DetectorFactoryBase&&);
virtual ~DetectorFactoryBase();
DetectorFactoryBase& operator=(const DetectorFactoryBase&) = delete;
DetectorFactoryBase& operator=(DetectorFactoryBase&&);

virtual Gen1GeometryHolder buildGen1Geometry();

virtual Gen2GeometryHolder buildGen2Geometry();

virtual std::shared_ptr<Geant4DetectorConstructionFactory>
buildGeant4DetectorConstructionFactory();
virtual std::shared_ptr<DetectorBase> buildDetector() const = 0;

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

const Acts::Logger& logger() const { return *m_logger; }
const Acts::Logger& logger() const;
};

class PreConstructedDetector : public DetectorBase {
public:
PreConstructedDetector(
Acts::GeometryContext geometryContext,
std::vector<std::shared_ptr<const Acts::DetectorElementBase>>
detectorStore,
std::shared_ptr<const Acts::TrackingGeometry> gen1Geometry,
std::shared_ptr<Acts::Experimental::Detector> gen2Geometry,
std::vector<std::shared_ptr<ActsExamples::IContextDecorator>>
contextDecorators,
std::shared_ptr<Geant4DetectorConstructionFactory>
geant4DetectorConstructionFactory);
~PreConstructedDetector() override;

const Acts::GeometryContext& geometryContext() const override;

const std::vector<std::shared_ptr<const Acts::DetectorElementBase>>&
detectorStore() const override;

const std::shared_ptr<const Acts::TrackingGeometry>& gen1Geometry()
const override;

const std::shared_ptr<Acts::Experimental::Detector>& gen2Geometry()
const override;

const std::vector<std::shared_ptr<ActsExamples::IContextDecorator>>&
contextDecorators() const override;

const std::shared_ptr<Geant4DetectorConstructionFactory>&
geant4DetectorConstructionFactory() const override;

private:
Acts::GeometryContext m_geometryContext;
std::vector<std::shared_ptr<const Acts::DetectorElementBase>> m_detectorStore;
std::shared_ptr<const Acts::TrackingGeometry> m_gen1Geometry;
std::shared_ptr<Acts::Experimental::Detector> m_gen2Geometry;
std::vector<std::shared_ptr<ActsExamples::IContextDecorator>>
m_contextDecorators;
std::shared_ptr<Geant4DetectorConstructionFactory>
m_geant4DetectorConstructionFactory;
};

} // namespace ActsExamples
69 changes: 56 additions & 13 deletions Examples/Detectors/Common/src/DetectorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,74 @@

#include "ActsExamples/DetectorCommons/DetectorBase.hpp"

#include "Acts/Utilities/Logger.hpp"
#include "Acts/Detector/Detector.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "ActsExamples/DetectorCommons/Geant4DetectorConstructionFactory.hpp"
#include "ActsExamples/Framework/IContextDecorator.hpp"

namespace ActsExamples {

DetectorBase::DetectorBase(std::unique_ptr<const Acts::Logger> logger)
DetectorFactoryBase::DetectorFactoryBase(
std::unique_ptr<const Acts::Logger> logger)
: m_logger(std::move(logger)) {}

DetectorBase::DetectorBase(DetectorBase&&) = default;
DetectorFactoryBase::DetectorFactoryBase(DetectorFactoryBase&&) = default;

DetectorBase::~DetectorBase() = default;
DetectorFactoryBase::~DetectorFactoryBase() = default;

DetectorBase& DetectorBase::operator=(DetectorBase&&) = default;
DetectorFactoryBase& DetectorFactoryBase::operator=(DetectorFactoryBase&&) =
default;

Gen1GeometryHolder DetectorBase::buildGen1Geometry() {
throw std::runtime_error("Gen1 geometry not implemented");
const Acts::Logger& DetectorFactoryBase::logger() const {
return *m_logger;
}

Gen2GeometryHolder DetectorBase::buildGen2Geometry() {
throw std::runtime_error("Gen2 geometry not implemented");
PreConstructedDetector::PreConstructedDetector(
Acts::GeometryContext geometryContext,
std::vector<std::shared_ptr<const Acts::DetectorElementBase>> detectorStore,
std::shared_ptr<const Acts::TrackingGeometry> gen1Geometry,
std::shared_ptr<Acts::Experimental::Detector> gen2Geometry,
std::vector<std::shared_ptr<IContextDecorator>> contextDecorators,
std::shared_ptr<Geant4DetectorConstructionFactory>
geant4DetectorConstructionFactory)
: m_geometryContext(std::move(geometryContext)),
m_detectorStore(std::move(detectorStore)),
m_gen1Geometry(std::move(gen1Geometry)),
m_gen2Geometry(std::move(gen2Geometry)),
m_contextDecorators(std::move(contextDecorators)),
m_geant4DetectorConstructionFactory(
std::move(geant4DetectorConstructionFactory)) {}

PreConstructedDetector::~PreConstructedDetector() = default;

const Acts::GeometryContext& PreConstructedDetector::geometryContext() const {
return m_geometryContext;
}

const std::vector<std::shared_ptr<const Acts::DetectorElementBase>>&
PreConstructedDetector::detectorStore() const {
return m_detectorStore;
}

const std::shared_ptr<const Acts::TrackingGeometry>&
PreConstructedDetector::gen1Geometry() const {
return m_gen1Geometry;
}

const std::shared_ptr<Acts::Experimental::Detector>&
PreConstructedDetector::gen2Geometry() const {
return m_gen2Geometry;
}

const std::vector<std::shared_ptr<IContextDecorator>>&
PreConstructedDetector::contextDecorators() const {
return m_contextDecorators;
}

std::shared_ptr<Geant4DetectorConstructionFactory>
DetectorBase::buildGeant4DetectorConstructionFactory() {
throw std::runtime_error(
"Geant4 detector construction factory not implemented");
const std::shared_ptr<Geant4DetectorConstructionFactory>&
PreConstructedDetector::geant4DetectorConstructionFactory() const {
return m_geant4DetectorConstructionFactory;
}

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,44 @@ namespace ActsExamples {

void sortFCChhDetElements(std::vector<dd4hep::DetElement>& det);

/// @class DD4hepDetector
class DD4hepDetector : public PreConstructedDetector,
public std::enable_shared_from_this<DD4hepDetector> {
public:
DD4hepDetector(Acts::GeometryContext geometryContext,
std::vector<std::shared_ptr<const Acts::DetectorElementBase>>
detectorStore,
std::shared_ptr<const Acts::TrackingGeometry> gen1Geometry,
std::shared_ptr<Acts::Experimental::Detector> gen2Geometry,
std::vector<std::shared_ptr<ActsExamples::IContextDecorator>>
contextDecorators,
std::shared_ptr<Geant4DetectorConstructionFactory>
geant4DetectorConstructionFactory,
std::unique_ptr<dd4hep::Detector> detector);

/// Interface method to access to the DD4hep geometry
dd4hep::Detector& dd4hepDetector();

/// Interface method to access the DD4hep geometry
/// @return The world DD4hep DetElement
dd4hep::DetElement dd4hepGeometry();

/// Interface method to Access the TGeo geometry
/// @return The world TGeoNode (physical volume)
TGeoNode& tgeoGeometry();

private:
/// Pointer to the interface to the DD4hep geometry
std::unique_ptr<dd4hep::Detector> m_detector;
};

/// @class DD4hepDetectorFactory
///
/// @brief geometries from dd4hep input
///
/// The DD4hepDetector creates the DD4hep, the TGeo and the ACTS
/// The DD4hepDetectorFactory creates the DD4hep, the TGeo and the ACTS
/// TrackingGeometry from DD4hep xml input. The geometries are created only on
/// demand.
class DD4hepDetector : public DetectorBase,
public std::enable_shared_from_this<DD4hepDetector> {
class DD4hepDetectorFactory : public DetectorFactoryBase {
public:
/// @brief The context decorators
using ContextDecorators =
Expand Down Expand Up @@ -85,37 +114,23 @@ class DD4hepDetector : public DetectorBase,
std::make_shared<const Acts::GeometryIdentifierHook>();
};

explicit DD4hepDetector(const Config& cfg);
DD4hepDetector(const DD4hepDetector&) = delete;
DD4hepDetector(DD4hepDetector&&);
~DD4hepDetector() override;
DD4hepDetector& operator=(const DD4hepDetector&) = delete;
DD4hepDetector& operator=(DD4hepDetector&&);
explicit DD4hepDetectorFactory(const Config& cfg);
DD4hepDetectorFactory(const DD4hepDetectorFactory&) = delete;
DD4hepDetectorFactory(DD4hepDetectorFactory&&);
~DD4hepDetectorFactory() override;
DD4hepDetectorFactory& operator=(const DD4hepDetectorFactory&) = delete;
DD4hepDetectorFactory& operator=(DD4hepDetectorFactory&&);

/// Interface method to access to the DD4hep geometry
dd4hep::Detector& dd4hepDetector();

/// Interface method to access the DD4hep geometry
/// @return The world DD4hep DetElement
dd4hep::DetElement dd4hepGeometry();

/// Interface method to Access the TGeo geometry
/// @return The world TGeoNode (physical volume)
TGeoNode& tgeoGeometry();

Gen1GeometryHolder buildGen1Geometry() override;
std::unique_ptr<dd4hep::Detector> buildDD4hepGeometry() const;

std::shared_ptr<Geant4DetectorConstructionFactory>
buildGeant4DetectorConstructionFactory() override;
buildGeant4DetectorConstructionFactory() const;

private:
/// Private method to initiate building of the DD4hep geometry
void buildDD4hepGeometry();
std::shared_ptr<DetectorBase> buildDetector() const override;

private:
/// The config class
Config m_cfg;
/// Pointer to the interface to the DD4hep geometry
std::unique_ptr<dd4hep::Detector> m_detector;
};

} // namespace ActsExamples
Loading

0 comments on commit 1fa479b

Please sign in to comment.