Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-09-28 07:03:49

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/Plugins/DD4hep/DD4hepDetectorElement.hpp"
0025 #include <Acts/Material/IMaterialDecorator.hpp>
0026 
0027 // Gaudi
0028 #include "GaudiKernel/MsgStream.h"
0029 #include "GaudiKernel/Service.h"
0030 #include "GaudiKernel/ServiceHandle.h"
0031 
0032 // DD4Hep
0033 #include "DD4hep/Detector.h"
0034 #include "DDRec/CellIDPositionConverter.h"
0035 #include "DDRec/SurfaceManager.h"
0036 #include "DDRec/Surface.h"
0037 #include "DD4hep/DD4hepUnits.h"
0038 
0039 #include "JugTrack/DD4hepBField.h"
0040 
0041 
0042 namespace Jug::Reco {
0043 
0044 class ActsGeoSvc : public extends<Service, IActsGeoSvc> {
0045 public:
0046   using VolumeSurfaceMap = std::unordered_map<uint64_t, const Acts::Surface*>;
0047 
0048 private:
0049 
0050   /** DD4hep detector interface class.
0051    * This is the main dd4hep detector handle.
0052    * <a href="https://dd4hep.web.cern.ch/dd4hep/reference/classdd4hep_1_1Detector.html">See DD4hep Detector documentation</a>
0053    */
0054   dd4hep::Detector* m_dd4hepGeo = nullptr;
0055 
0056   /// ACTS Logging Level
0057   Acts::Logging::Level m_actsLoggingLevel = Acts::Logging::INFO;
0058 
0059   /// ACTS Tracking Geometry Context
0060   Acts::GeometryContext m_trackingGeoCtx;
0061 
0062   /// ACTS Tracking Geometry
0063   std::shared_ptr<const Acts::TrackingGeometry> m_trackingGeo{nullptr};
0064 
0065   /// ACTS Material Decorator
0066   std::shared_ptr<const Acts::IMaterialDecorator> m_materialDeco{nullptr};
0067 
0068   /// ACTS surface lookup container for hit surfaces that generate smeared hits
0069   VolumeSurfaceMap m_surfaces;
0070 
0071   /// Acts magnetic field
0072   std::shared_ptr<const Jug::BField::DD4hepBField> m_magneticField = nullptr;
0073 
0074   /// XML-files with the detector description
0075   Gaudi::Property<std::vector<std::string>> m_xmlFileNames{
0076       this, "detectors", {}, "Detector descriptions XML-files"};
0077 
0078   /// JSON-file with the material map
0079   Gaudi::Property<std::string> m_jsonFileName{
0080       this, "materials", "", "Material map JSON-file"};
0081 
0082   /// Gaudi logging output
0083   MsgStream m_log;
0084 
0085 public:
0086   ActsGeoSvc(const std::string& name, ISvcLocator* svc);
0087 
0088   virtual ~ActsGeoSvc();
0089 
0090   virtual StatusCode initialize() final;
0091 
0092   virtual StatusCode finalize() final;
0093 
0094   /** Build the dd4hep geometry.
0095    * This function generates the DD4hep geometry.
0096    */
0097   StatusCode buildDD4HepGeo();
0098 
0099   /** Gets the ACTS tracking geometry.
0100    */
0101   virtual std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry() const;
0102 
0103   virtual std::shared_ptr<const Acts::MagneticFieldProvider> getFieldProvider() const { return m_magneticField; }
0104 
0105   virtual double centralMagneticField() const
0106   {
0107     return m_dd4hepGeo->field().magneticField({0, 0, 0}).z() * (Acts::UnitConstants::T / dd4hep::tesla);
0108   }
0109 
0110   virtual const VolumeSurfaceMap& surfaceMap() const { return m_surfaces; }
0111 };
0112 
0113 inline std::shared_ptr<const Acts::TrackingGeometry> ActsGeoSvc::trackingGeometry() const
0114 {
0115   return m_trackingGeo;
0116 }
0117 
0118 }
0119 
0120 #endif // GEOSVC_H