Skip to content

Commit

Permalink
refactor: Cleanup some more detector code in Examples (#3908)
Browse files Browse the repository at this point in the history
- organize includes and forward delerations
- remove special detector namespaces when possible
- make use of namespaces in source files

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
	- Simplified namespace structure across various classes for improved readability.
	- Updated method signatures to enhance clarity and reduce redundancy.
	- Enhanced error handling and logging in the `EDM4hepReader` class.
	- Introduced new member functions in the `GenericDetectorElement` class for better property access.
	- Added new member variables in the `Geant4Simulation` configuration structure for improved functionality.
	- Updated the `Config` struct in `EDM4hepReader` to simplify the `dd4hepDetector` reference.

- **Bug Fixes**
	- Improved checks for configuration parameters in the `EDM4hepReader` constructor.

- **Chores**
	- Removed unnecessary include directives to streamline dependencies.
	- Adjusted type references for various classes and methods to eliminate namespace prefixes.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
andiwand authored Nov 26, 2024
1 parent 832b327 commit f6f8df4
Show file tree
Hide file tree
Showing 46 changed files with 309 additions and 416 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ class G4VPhysicalVolume;
namespace dd4hep {
class Detector;
}

namespace ActsExamples {

namespace DD4hep {
struct DD4hepDetector;
}

/// Construct the Geant4 detector from a DD4hep description.
class DDG4DetectorConstruction final : public G4VUserDetectorConstruction {
public:
DDG4DetectorConstruction(
std::shared_ptr<DD4hep::DD4hepDetector> detector,
std::shared_ptr<DD4hepDetector> detector,
std::vector<std::shared_ptr<Geant4::RegionCreator>> regionCreators = {});
~DDG4DetectorConstruction() final;

Expand All @@ -45,7 +44,7 @@ class DDG4DetectorConstruction final : public G4VUserDetectorConstruction {

private:
/// The Acts DD4hep detector instance
std::shared_ptr<DD4hep::DD4hepDetector> m_detector;
std::shared_ptr<DD4hepDetector> m_detector;
/// Region creators
std::vector<std::shared_ptr<Geant4::RegionCreator>> m_regionCreators;
/// The world volume
Expand All @@ -59,15 +58,15 @@ class DDG4DetectorConstructionFactory final
: public Geant4::DetectorConstructionFactory {
public:
DDG4DetectorConstructionFactory(
std::shared_ptr<DD4hep::DD4hepDetector> detector,
std::shared_ptr<DD4hepDetector> detector,
std::vector<std::shared_ptr<Geant4::RegionCreator>> regionCreators = {});
~DDG4DetectorConstructionFactory() final;

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

private:
/// The Acts DD4hep detector instance
std::shared_ptr<DD4hep::DD4hepDetector> m_detector;
std::shared_ptr<DD4hepDetector> m_detector;
/// Region creators
std::vector<std::shared_ptr<Geant4::RegionCreator>> m_regionCreators;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class G4VPhysicalVolume;
class G4LogicalVolume;

namespace ActsExamples::Telescope {
namespace ActsExamples {

class TelescopeG4DetectorConstruction final
: public G4VUserDetectorConstruction {
Expand Down Expand Up @@ -53,4 +53,4 @@ class TelescopeG4DetectorConstructionFactory final
std::vector<std::shared_ptr<Geant4::RegionCreator>> m_regionCreators;
};

} // namespace ActsExamples::Telescope
} // namespace ActsExamples
4 changes: 2 additions & 2 deletions Examples/Algorithms/Geant4/src/DDG4DetectorConstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class G4VPhysicalVolume;
namespace ActsExamples {

DDG4DetectorConstruction::DDG4DetectorConstruction(
std::shared_ptr<DD4hep::DD4hepDetector> detector,
std::shared_ptr<DD4hepDetector> detector,
std::vector<std::shared_ptr<Geant4::RegionCreator>> regionCreators)
: G4VUserDetectorConstruction(),
m_detector(std::move(detector)),
Expand Down Expand Up @@ -60,7 +60,7 @@ G4VPhysicalVolume* DDG4DetectorConstruction::Construct() {
}

DDG4DetectorConstructionFactory::DDG4DetectorConstructionFactory(
std::shared_ptr<DD4hep::DD4hepDetector> detector,
std::shared_ptr<DD4hepDetector> detector,
std::vector<std::shared_ptr<Geant4::RegionCreator>> regionCreators)
: m_detector(std::move(detector)),
m_regionCreators(std::move(regionCreators)) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@

namespace ActsExamples {

Telescope::TelescopeG4DetectorConstruction::TelescopeG4DetectorConstruction(
TelescopeG4DetectorConstruction::TelescopeG4DetectorConstruction(
const TelescopeDetector::Config& cfg,
std::vector<std::shared_ptr<Geant4::RegionCreator>> regionCreators)
: m_cfg(cfg), m_regionCreators(std::move(regionCreators)) {
throw_assert(cfg.surfaceType ==
static_cast<int>(Telescope::TelescopeSurfaceType::Plane),
throw_assert(cfg.surfaceType == static_cast<int>(TelescopeSurfaceType::Plane),
"only plan is supported right now");
}

G4VPhysicalVolume* Telescope::TelescopeG4DetectorConstruction::Construct() {
G4VPhysicalVolume* TelescopeG4DetectorConstruction::Construct() {
if (m_world != nullptr) {
return m_world;
}
Expand Down Expand Up @@ -168,14 +167,13 @@ G4VPhysicalVolume* Telescope::TelescopeG4DetectorConstruction::Construct() {
return m_world;
}

Telescope::TelescopeG4DetectorConstructionFactory::
TelescopeG4DetectorConstructionFactory(
const TelescopeDetector::Config& cfg,
std::vector<std::shared_ptr<Geant4::RegionCreator>> regionCreators)
TelescopeG4DetectorConstructionFactory::TelescopeG4DetectorConstructionFactory(
const TelescopeDetector::Config& cfg,
std::vector<std::shared_ptr<Geant4::RegionCreator>> regionCreators)
: m_cfg(cfg), m_regionCreators(std::move(regionCreators)) {}

std::unique_ptr<G4VUserDetectorConstruction>
Telescope::TelescopeG4DetectorConstructionFactory::factorize() const {
TelescopeG4DetectorConstructionFactory::factorize() const {
return std::make_unique<TelescopeG4DetectorConstruction>(m_cfg,
m_regionCreators);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,16 @@ class IMaterialDecorator;
} // namespace Acts

namespace ActsExamples {

class IContextDecorator;
namespace Generic {
class GenericDetectorElement;
} // namespace Generic
} // namespace ActsExamples

namespace ActsExamples::Contextual {
class InternallyAlignedDetectorElement;
class InternalAlignmentDecorator;

class AlignedDetector {
public:
using ContextDecorators =
std::vector<std::shared_ptr<ActsExamples::IContextDecorator>>;
using ContextDecorators = std::vector<std::shared_ptr<IContextDecorator>>;
using TrackingGeometryPtr = std::shared_ptr<const Acts::TrackingGeometry>;

struct Config : public GenericDetector::Config {
Expand Down Expand Up @@ -69,15 +65,15 @@ class AlignedDetector {
const Config& cfg,
std::shared_ptr<const Acts::IMaterialDecorator> mdecorator);

std::vector<std::vector<std::shared_ptr<Generic::GenericDetectorElement>>>&
std::vector<std::vector<std::shared_ptr<GenericDetectorElement>>>&
detectorStore() {
return m_detectorStore;
}

private:
/// The Store of the detector elements (lifetime: job)
std::vector<std::vector<std::shared_ptr<Generic::GenericDetectorElement>>>
std::vector<std::vector<std::shared_ptr<GenericDetectorElement>>>
m_detectorStore;
};

} // namespace ActsExamples::Contextual
} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,10 @@
#pragma once

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/ContextualDetector/InternallyAlignedDetectorElement.hpp"
#include "ActsExamples/Framework/AlgorithmContext.hpp"
#include "ActsExamples/Framework/IContextDecorator.hpp"
#include "ActsExamples/Framework/RandomNumbers.hpp"

#include <iostream>
#include <mutex>
#include <vector>

namespace ActsExamples::Contextual {
namespace ActsExamples {

/// @brief A mockup service that rotates the modules in a
/// simple tracking geometry
Expand Down Expand Up @@ -85,4 +78,5 @@ class AlignmentDecorator : public IContextDecorator {
}
}
};
} // namespace ActsExamples::Contextual

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
#pragma once

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/ContextualDetector/AlignmentDecorator.hpp"
#include "ActsExamples/ContextualDetector/ExternallyAlignedDetectorElement.hpp"
#include "ActsExamples/Framework/AlgorithmContext.hpp"
#include "ActsExamples/Framework/IContextDecorator.hpp"
#include "ActsExamples/Framework/ProcessCode.hpp"

#include <cstddef>
Expand All @@ -31,8 +29,6 @@ class TrackingGeometry;
namespace ActsExamples {
struct AlgorithmContext;

namespace Contextual {

/// @brief A mockup service that rotates the modules in a
/// simple tracking geometry
///
Expand Down Expand Up @@ -96,6 +92,5 @@ class ExternalAlignmentDecorator : public AlignmentDecorator {
/// @param tGeometry the tracking geometry
void parseGeometry(const Acts::TrackingGeometry& tGeometry);
};
} // namespace Contextual

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "ActsExamples/GenericDetector/GenericDetectorElement.hpp"

#include <map>

namespace ActsExamples::Contextual {
namespace ActsExamples {

/// @class ExternallyAlignedDetectorElement extends GenericDetectorElement
///
Expand All @@ -34,8 +30,7 @@ namespace ActsExamples::Contextual {
/// In this simple implementation, it does rely on the Identifier
/// to be orderded from 0 to N-1, as the identifier is simply taken
/// as a vector index for the alignment store
class ExternallyAlignedDetectorElement
: public Generic::GenericDetectorElement {
class ExternallyAlignedDetectorElement : public GenericDetectorElement {
public:
struct AlignmentStore {
// GenericDetector identifiers are sequential
Expand All @@ -50,7 +45,7 @@ class ExternallyAlignedDetectorElement
std::shared_ptr<const AlignmentStore> alignmentStore{nullptr};
};

using Generic::GenericDetectorElement::GenericDetectorElement;
using GenericDetectorElement::GenericDetectorElement;

/// Return local to global transform associated with this identifier
///
Expand Down Expand Up @@ -80,4 +75,4 @@ inline const Acts::Transform3& ExternallyAlignedDetectorElement::transform(
return alignContext.alignmentStore->transforms[idValue];
}

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

#pragma once

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/ContextualDetector/AlignmentDecorator.hpp"
#include "ActsExamples/ContextualDetector/InternallyAlignedDetectorElement.hpp"
#include "ActsExamples/Framework/AlgorithmContext.hpp"
#include "ActsExamples/Framework/IContextDecorator.hpp"
#include "ActsExamples/Framework/ProcessCode.hpp"
#include "ActsExamples/Framework/RandomNumbers.hpp"

Expand All @@ -25,9 +23,6 @@
#include <vector>

namespace ActsExamples {
struct AlgorithmContext;

namespace Contextual {
class InternallyAlignedDetectorElement;

/// @brief A mockup service that rotates the modules in a
Expand Down Expand Up @@ -87,5 +82,5 @@ class InternalAlignmentDecorator : public AlignmentDecorator {
/// Private access to the logging instance
const Acts::Logger& logger() const { return *m_logger; }
};
} // namespace Contextual

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

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "ActsExamples/GenericDetector/GenericDetectorElement.hpp"

#include <iostream>
#include <memory>
#include <mutex>
#include <unordered_map>

namespace ActsExamples::Contextual {
namespace ActsExamples {

/// @class InternallyAlignedDetectorElement extends GenericDetectorElement
///
Expand All @@ -33,8 +29,7 @@ namespace ActsExamples::Contextual {
/// store and then in a contextual call the actual detector element
/// position is taken internal multi component store - the latter
/// has to be filled though from an external source
class InternallyAlignedDetectorElement
: public Generic::GenericDetectorElement {
class InternallyAlignedDetectorElement : public GenericDetectorElement {
public:
struct ContextType {
/// The current interval of validity
Expand All @@ -43,7 +38,7 @@ class InternallyAlignedDetectorElement
};

// Inherit constructor
using Generic::GenericDetectorElement::GenericDetectorElement;
using GenericDetectorElement::GenericDetectorElement;

/// Return local to global transform associated with this identifier
///
Expand Down Expand Up @@ -117,4 +112,4 @@ inline void InternallyAlignedDetectorElement::clearAlignedTransform(
}
}

} // namespace ActsExamples::Contextual
} // namespace ActsExamples
Loading

0 comments on commit f6f8df4

Please sign in to comment.