Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-26 08:22:20

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2015 - 2024 Julia Hrdinka, Whitney Armstrong, Wouter Deconinck, Dmitry Romanov
0003 
0004 #pragma once
0005 
0006 // ACTS
0007 #include <Acts/Definitions/Units.hpp>
0008 #include <Acts/Geometry/GeometryContext.hpp>
0009 #include <Acts/Geometry/TrackingGeometry.hpp>
0010 #include <Acts/MagneticField/MagneticFieldContext.hpp>
0011 #include <Acts/MagneticField/MagneticFieldProvider.hpp>
0012 #include <Acts/Surfaces/Surface.hpp>
0013 #include <Acts/Utilities/CalibrationContext.hpp>
0014 #include <Acts/Visualization/ViewConfig.hpp>
0015 #include <DD4hep/Detector.h>
0016 #include <DD4hep/Fields.h>
0017 #include <Evaluator/DD4hepUnits.h>
0018 #include <Math/GenVector/Cartesian3D.h>
0019 #include <Math/GenVector/DisplacementVector3D.h>
0020 #include <spdlog/logger.h>
0021 #include <array>
0022 #include <cstdint>
0023 #include <map>
0024 #include <memory>
0025 #include <string>
0026 #include <unordered_map>
0027 
0028 namespace dd4hep::rec {
0029 class Surface;
0030 }
0031 
0032 /** Draw the surfaces and save to obj file.
0033  *  This is useful for debugging the ACTS geometry. The obj file can
0034  *  be loaded into various tools, such as FreeCAD, for inspection.
0035  */
0036 void draw_surfaces(std::shared_ptr<const Acts::TrackingGeometry> trk_geo,
0037                    std::shared_ptr<spdlog::logger> init_log, const std::string& fname);
0038 
0039 class ActsGeometryProvider {
0040 public:
0041   ActsGeometryProvider() {};
0042   virtual ~ActsGeometryProvider() = default;
0043 
0044   using VolumeSurfaceMap = std::unordered_map<uint64_t, const Acts::Surface*>;
0045 
0046   virtual void initialize(const dd4hep::Detector* dd4hep_geo, std::string material_file,
0047                           std::shared_ptr<spdlog::logger> log,
0048                           std::shared_ptr<spdlog::logger> init_log) final;
0049 
0050   const dd4hep::Detector* dd4hepDetector() const { return m_dd4hepDetector; }
0051 
0052   /** Gets the ACTS tracking geometry.
0053      */
0054   std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry() const { return m_trackingGeo; }
0055 
0056   std::shared_ptr<const Acts::MagneticFieldProvider> getFieldProvider() const;
0057 
0058   double centralMagneticField() const {
0059     return m_dd4hepDetector->field().magneticField({0, 0, 0}).z() *
0060            (Acts::UnitConstants::T / dd4hep::tesla);
0061   }
0062 
0063   const VolumeSurfaceMap& surfaceMap() const { return m_surfaces; }
0064 
0065   std::map<int64_t, dd4hep::rec::Surface*> getDD4hepSurfaceMap() const { return m_surfaceMap; }
0066 
0067   const Acts::GeometryContext& getActsGeometryContext() const { return m_trackingGeoCtx; }
0068   const Acts::MagneticFieldContext& getActsMagneticFieldContext() const {
0069     return m_magneticFieldCtx;
0070   }
0071   const Acts::CalibrationContext& getActsCalibrationContext() const { return m_calibrationCtx; }
0072 
0073   ///  ACTS general logger that is used for running ACTS
0074   std::shared_ptr<spdlog::logger> getActsRelatedLogger() const { return m_log; }
0075 
0076   /// Logger that is used for geometry initialization
0077   /// By default its level the same as ACTS general logger (m_log)
0078   /// But it might be customized to solely printout geometry information
0079   std::shared_ptr<spdlog::logger> getActsInitRelatedLogger() const { return m_init_log; }
0080 
0081 private:
0082   /** DD4hep detector interface class.
0083      * This is the main dd4hep detector handle.
0084      * <a href="https://dd4hep.web.cern.ch/dd4hep/reference/classdd4hep_1_1Detector.html">See DD4hep Detector documentation</a>
0085      */
0086   const dd4hep::Detector* m_dd4hepDetector = nullptr;
0087 
0088   /// DD4hep surface map
0089   std::map<int64_t, dd4hep::rec::Surface*> m_surfaceMap;
0090 
0091   /// ACTS Tracking Geometry Context
0092 #if Acts_VERSION_MAJOR >= 45
0093   Acts::GeometryContext m_trackingGeoCtx = Acts::GeometryContext::dangerouslyDefaultConstruct();
0094 #else
0095   Acts::GeometryContext m_trackingGeoCtx;
0096 #endif
0097 
0098   /// ACTS Magnetic Field Context
0099   Acts::MagneticFieldContext m_magneticFieldCtx;
0100 
0101   /// ACTS Calibration Context
0102   Acts::CalibrationContext m_calibrationCtx;
0103 
0104   /// ACTS Tracking Geometry
0105   std::shared_ptr<const Acts::TrackingGeometry> m_trackingGeo{nullptr};
0106 
0107   /// ACTS surface lookup container for hit surfaces that generate smeared hits
0108   VolumeSurfaceMap m_surfaces;
0109 
0110   /// Acts magnetic field
0111   std::shared_ptr<const Acts::MagneticFieldProvider> m_magneticField = nullptr;
0112 
0113   ///  ACTS general logger that is used for running ACTS
0114   std::shared_ptr<spdlog::logger> m_log;
0115 
0116   /// Logger that is used for geometry initialization
0117   /// By default its level the same as ACTS general logger (m_log)
0118   /// But it might be customized to solely printout geometry information
0119   std::shared_ptr<spdlog::logger> m_init_log;
0120 
0121   /// Configuration for obj export
0122   Acts::ViewConfig m_containerView{.color = {220, 220, 220}}; // alto
0123   Acts::ViewConfig m_volumeView{.color = {220, 220, 0}};      // barberry yellow
0124   Acts::ViewConfig m_sensitiveView{.color = {0, 180, 240}};   // picton blue
0125   Acts::ViewConfig m_passiveView{.color = {240, 180, 0}};     // lightning yellow
0126   Acts::ViewConfig m_gridView{.color = {220, 0, 0}};          // scarlet red
0127   bool m_objWriteIt{false};
0128   bool m_plyWriteIt{false};
0129   std::string m_outputTag{""};
0130   std::string m_outputDir{""};
0131 
0132 public:
0133   void setObjWriteIt(bool writeit) { m_objWriteIt = writeit; }
0134   bool getObjWriteIt() const { return m_objWriteIt; }
0135   void setPlyWriteIt(bool writeit) { m_plyWriteIt = writeit; }
0136   bool getPlyWriteIt() const { return m_plyWriteIt; }
0137 
0138   void setOutputTag(std::string tag) { m_outputTag = tag; }
0139   std::string getOutputTag() const { return m_outputTag; }
0140   void setOutputDir(std::string dir) { m_outputDir = dir; }
0141   std::string getOutputDir() const { return m_outputDir; }
0142 
0143   using Color = Acts::Color;
0144   void setContainerView(std::array<int, 3> c) { m_containerView.color = Color(c); }
0145   const Acts::ViewConfig& getContainerView() const { return m_containerView; }
0146   void setVolumeView(std::array<int, 3> c) { m_volumeView.color = Color(c); }
0147   const Acts::ViewConfig& getVolumeView() const { return m_volumeView; }
0148   void setSensitiveView(std::array<int, 3> c) { m_sensitiveView.color = Color(c); }
0149   const Acts::ViewConfig& getSensitiveView() const { return m_sensitiveView; }
0150   void setPassiveView(std::array<int, 3> c) { m_passiveView.color = Color(c); }
0151   const Acts::ViewConfig& getPassiveView() const { return m_passiveView; }
0152   void setGridView(std::array<int, 3> c) { m_gridView.color = Color(c); }
0153   const Acts::ViewConfig& getGridView() const { return m_gridView; }
0154 };