Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-06-26 07:05:42

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/MagneticFieldProvider.hpp>
0011 #include <Acts/Surfaces/Surface.hpp>
0012 #include <Acts/Utilities/Logger.hpp>
0013 #include <Acts/Visualization/ViewConfig.hpp>
0014 #include <DD4hep/Detector.h>
0015 #include <DD4hep/Fields.h>
0016 #include <Evaluator/DD4hepUnits.h>
0017 #include <Math/GenVector/Cartesian3D.h>
0018 #include <Math/GenVector/DisplacementVector3D.h>
0019 #include <spdlog/logger.h>
0020 #include <array>
0021 #include <cstdint>
0022 #include <map>
0023 #include <memory>
0024 #include <string>
0025 #include <unordered_map>
0026 
0027 #include "DD4hepBField.h"
0028 
0029 namespace dd4hep::rec {
0030     class Surface;
0031 }
0032 
0033 /** Draw the surfaces and save to obj file.
0034  *  This is useful for debugging the ACTS geometry. The obj file can
0035  *  be loaded into various tools, such as FreeCAD, for inspection.
0036  */
0037 void draw_surfaces(std::shared_ptr<const Acts::TrackingGeometry> trk_geo, std::shared_ptr<spdlog::logger> init_log, const std::string &fname);
0038 
0039 class ActsGeometryProvider {
0040 public:
0041     ActsGeometryProvider() {}
0042     using VolumeSurfaceMap = std::unordered_map<uint64_t, const Acts::Surface *>;
0043 
0044     virtual void initialize(const dd4hep::Detector* dd4hep_geo,
0045                             std::string material_file,
0046                             std::shared_ptr<spdlog::logger> log,
0047                             std::shared_ptr<spdlog::logger> init_log) final;
0048 
0049     const dd4hep::Detector* dd4hepDetector() const { return m_dd4hepDetector; }
0050 
0051     /** Gets the ACTS tracking geometry.
0052      */
0053     std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry() const { return m_trackingGeo;}
0054 
0055     std::shared_ptr<const Acts::MagneticFieldProvider> getFieldProvider() const  { return m_magneticField; }
0056 
0057     double centralMagneticField() const  {
0058         return m_dd4hepDetector->field().magneticField({0, 0, 0}).z() * (Acts::UnitConstants::T / dd4hep::tesla);
0059     }
0060 
0061     const VolumeSurfaceMap &surfaceMap() const  { return m_surfaces; }
0062 
0063 
0064     std::map<int64_t, dd4hep::rec::Surface *> getDD4hepSurfaceMap() const { return m_surfaceMap; }
0065 
0066     const Acts::GeometryContext& getActsGeometryContext() const {return m_trackingGeoCtx;}
0067 
0068     ///  ACTS general logger that is used for running ACTS
0069     std::shared_ptr<spdlog::logger> getActsRelatedLogger() const { return m_log; }
0070 
0071     /// Logger that is used for geometry initialization
0072     /// By default its level the same as ACTS general logger (m_log)
0073     /// But it might be customized to solely printout geometry information
0074     std::shared_ptr<spdlog::logger> getActsInitRelatedLogger()  const { return m_init_log; }
0075 
0076 private:
0077 
0078     /** DD4hep detector interface class.
0079      * This is the main dd4hep detector handle.
0080      * <a href="https://dd4hep.web.cern.ch/dd4hep/reference/classdd4hep_1_1Detector.html">See DD4hep Detector documentation</a>
0081      */
0082     const dd4hep::Detector* m_dd4hepDetector = nullptr;
0083 
0084     /// DD4hep surface map
0085     std::map<int64_t, dd4hep::rec::Surface *> m_surfaceMap;
0086 
0087     /// ACTS Logging Level
0088     Acts::Logging::Level acts_log_level = Acts::Logging::INFO;
0089 
0090     /// ACTS Tracking Geometry Context
0091     Acts::GeometryContext m_trackingGeoCtx;
0092 
0093     /// ACTS Tracking Geometry
0094     std::shared_ptr<const Acts::TrackingGeometry> m_trackingGeo{nullptr};
0095 
0096     /// ACTS surface lookup container for hit surfaces that generate smeared hits
0097     VolumeSurfaceMap m_surfaces;
0098 
0099     /// Acts magnetic field
0100     std::shared_ptr<const eicrecon::BField::DD4hepBField> m_magneticField = nullptr;
0101 
0102     ///  ACTS general logger that is used for running ACTS
0103     std::shared_ptr<spdlog::logger> m_log;
0104 
0105     /// Logger that is used for geometry initialization
0106     /// By default its level the same as ACTS general logger (m_log)
0107     /// But it might be customized to solely printout geometry information
0108     std::shared_ptr<spdlog::logger> m_init_log;
0109 
0110     /// Configuration for obj export
0111     Acts::ViewConfig m_containerView{{220, 220, 220}};
0112     Acts::ViewConfig m_volumeView{{220, 220, 0}};
0113     Acts::ViewConfig m_sensitiveView{{0, 180, 240}};
0114     Acts::ViewConfig m_passiveView{{240, 280, 0}};
0115     Acts::ViewConfig m_gridView{{220, 0, 0}};
0116     bool m_objWriteIt{false};
0117     bool m_plyWriteIt{false};
0118     std::string m_outputTag{""};
0119     std::string m_outputDir{""};
0120 
0121 public:
0122     void setObjWriteIt(bool writeit) { m_objWriteIt = writeit; }
0123     bool getObjWriteIt() const { return m_objWriteIt; }
0124     void setPlyWriteIt(bool writeit) { m_plyWriteIt = writeit; }
0125     bool getPlyWriteIt() const { return m_plyWriteIt; }
0126 
0127     void setOutputTag(std::string tag) { m_outputTag = tag; }
0128     std::string getOutputTag() const { return m_outputTag; }
0129     void setOutputDir(std::string dir) { m_outputDir = dir; }
0130     std::string getOutputDir() const { return m_outputDir; }
0131 
0132     void setContainerView(std::array<int,3> view) { m_containerView = Acts::ViewConfig{view}; }
0133     const Acts::ViewConfig& getContainerView() const { return m_containerView; }
0134     void setVolumeView(std::array<int,3> view) { m_volumeView = Acts::ViewConfig{view}; }
0135     const Acts::ViewConfig& getVolumeView() const { return m_volumeView; }
0136     void setSensitiveView(std::array<int,3> view) { m_sensitiveView = Acts::ViewConfig{view}; }
0137     const Acts::ViewConfig& getSensitiveView() const { return m_sensitiveView; }
0138     void setPassiveView(std::array<int,3> view) { m_passiveView = Acts::ViewConfig{view}; }
0139     const Acts::ViewConfig& getPassiveView() const { return m_passiveView; }
0140     void setGridView(std::array<int,3> view) { m_gridView = Acts::ViewConfig{view}; }
0141     const Acts::ViewConfig& getGridView() const { return m_gridView; }
0142 
0143 };