Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-22 10:35:43

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Whitney Armstrong, Wouter Deconinck
0003 
0004 //
0005 //  GeoSvc.h
0006 //
0007 //
0008 //  Created by Julia Hrdinka on 30/03/15.
0009 //
0010 //
0011 
0012 #ifndef GEOSVC_H
0013 #define GEOSVC_H
0014 
0015 // Interface
0016 #include "JugTrack/IActsGeoSvc.h"
0017 
0018 // ACTS
0019 #include "Acts/Utilities/Logger.hpp"
0020 #include "Acts/Definitions/Units.hpp"
0021 #include "Acts/Surfaces/Surface.hpp"
0022 #include "Acts/Definitions/Common.hpp"
0023 #include "Acts/Geometry/TrackingGeometry.hpp"
0024 #include <Acts/Material/IMaterialDecorator.hpp>
0025 
0026 #if Acts_VERSION_MAJOR >= 44
0027 #include "ActsPlugins/DD4hep/DD4hepDetectorElement.hpp"
0028 #else
0029 #include "Acts/Plugins/DD4hep/DD4hepDetectorElement.hpp"
0030 #endif
0031 
0032 // Gaudi
0033 #include "GaudiKernel/MsgStream.h"
0034 #include "GaudiKernel/Service.h"
0035 #include "GaudiKernel/ServiceHandle.h"
0036 
0037 // DD4Hep
0038 #include "DD4hep/Detector.h"
0039 #include "DDRec/CellIDPositionConverter.h"
0040 #include "DDRec/SurfaceManager.h"
0041 #include "DDRec/Surface.h"
0042 #include "DD4hep/DD4hepUnits.h"
0043 
0044 #include "JugTrack/DD4hepBField.h"
0045 
0046 
0047 namespace Jug::Reco {
0048 
0049 class ActsGeoSvc : public extends<Service, IActsGeoSvc> {
0050 public:
0051   using VolumeSurfaceMap = std::unordered_map<uint64_t, const Acts::Surface*>;
0052 
0053 private:
0054 
0055   /** DD4hep detector interface class.
0056    * This is the main dd4hep detector handle.
0057    * <a href="https://dd4hep.web.cern.ch/dd4hep/reference/classdd4hep_1_1Detector.html">See DD4hep Detector documentation</a>
0058    */
0059   dd4hep::Detector* m_dd4hepGeo = nullptr;
0060 
0061   /// ACTS Logging Level
0062   Acts::Logging::Level m_actsLoggingLevel = Acts::Logging::INFO;
0063 
0064   /// ACTS Tracking Geometry Context
0065   Acts::GeometryContext m_trackingGeoCtx;
0066 
0067   /// ACTS Tracking Geometry
0068   std::shared_ptr<const Acts::TrackingGeometry> m_trackingGeo{nullptr};
0069 
0070   /// ACTS Material Decorator
0071   std::shared_ptr<const Acts::IMaterialDecorator> m_materialDeco{nullptr};
0072 
0073   /// ACTS surface lookup container for hit surfaces that generate smeared hits
0074   VolumeSurfaceMap m_surfaces;
0075 
0076   /// Acts magnetic field
0077   std::shared_ptr<const Jug::BField::DD4hepBField> m_magneticField = nullptr;
0078 
0079   /// XML-files with the detector description
0080   Gaudi::Property<std::vector<std::string>> m_xmlFileNames{
0081       this, "detectors", {}, "Detector descriptions XML-files"};
0082 
0083   /// JSON-file with the material map
0084   Gaudi::Property<std::string> m_jsonFileName{
0085       this, "materials", "", "Material map JSON-file"};
0086 
0087   /// Gaudi logging output
0088   MsgStream m_log;
0089 
0090 public:
0091   ActsGeoSvc(const std::string& name, ISvcLocator* svc);
0092 
0093   virtual ~ActsGeoSvc();
0094 
0095   virtual StatusCode initialize() final;
0096 
0097   virtual StatusCode finalize() final;
0098 
0099   /** Build the dd4hep geometry.
0100    * This function generates the DD4hep geometry.
0101    */
0102   StatusCode buildDD4HepGeo();
0103 
0104   /** Gets the ACTS tracking geometry.
0105    */
0106   virtual std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry() const;
0107 
0108   virtual std::shared_ptr<const Acts::MagneticFieldProvider> getFieldProvider() const { return m_magneticField; }
0109 
0110   virtual double centralMagneticField() const
0111   {
0112     return m_dd4hepGeo->field().magneticField({0, 0, 0}).z() * (Acts::UnitConstants::T / dd4hep::tesla);
0113   }
0114 
0115   virtual const VolumeSurfaceMap& surfaceMap() const { return m_surfaces; }
0116 };
0117 
0118 inline std::shared_ptr<const Acts::TrackingGeometry> ActsGeoSvc::trackingGeometry() const
0119 {
0120   return m_trackingGeo;
0121 }
0122 
0123 }
0124 
0125 #endif // GEOSVC_H