Juggler
Juggling algorithms and event processing using gaudi framework
GeoSvc.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-or-later
2 // Copyright (C) 2022 Whitney Armstrong, Wouter Deconinck
3 
4 //
5 // GeoSvc.h
6 //
7 //
8 // Created by Julia Hrdinka on 30/03/15.
9 //
10 //
11 
12 #ifndef GEOSVC_H
13 #define GEOSVC_H
14 
15 // Interface
16 #include "JugBase/IGeoSvc.h"
17 
18 // ACTS
19 #include "Acts/Utilities/Logger.hpp"
20 #include "Acts/Definitions/Units.hpp"
21 #include "Acts/Surfaces/Surface.hpp"
22 #include "Acts/Definitions/Common.hpp"
23 #include "Acts/Geometry/TrackingGeometry.hpp"
24 #include "Acts/Plugins/DD4hep/DD4hepDetectorElement.hpp"
25 #include <Acts/Material/IMaterialDecorator.hpp>
26 
27 // Gaudi
28 #include "GaudiKernel/MsgStream.h"
29 #include "GaudiKernel/Service.h"
30 #include "GaudiKernel/ServiceHandle.h"
31 
32 // DD4Hep
33 #include "DD4hep/Detector.h"
34 #include "DDRec/CellIDPositionConverter.h"
35 #include "DDRec/SurfaceManager.h"
36 #include "DDRec/Surface.h"
37 #include "DD4hep/DD4hepUnits.h"
38 
40 
41 
42 /** Draw the surfaces and save to obj file.
43  * This is useful for debugging the ACTS geometry. The obj file can
44  * be loaded into various tools, such as FreeCAD, for inspection.
45  */
46 void draw_surfaces(std::shared_ptr<const Acts::TrackingGeometry> trk_geo, const std::string& fname);
47 
48 class GeoSvc : public extends<Service, IGeoSvc> {
49 public:
50  using VolumeSurfaceMap = std::unordered_map<uint64_t, const Acts::Surface*>;
51 
52 private:
53 
54  /** DD4hep detector interface class.
55  * This is the main dd4hep detector handle.
56  * <a href="https://dd4hep.web.cern.ch/dd4hep/reference/classdd4hep_1_1Detector.html">See DD4hep Detector documentation</a>
57  */
58  dd4hep::Detector* m_dd4hepGeo = nullptr;
59 
60  /// DD4hep surface map
61  std::map< int64_t, dd4hep::rec::Surface* > m_surfaceMap ;
62 
63  /// Genfit DetPlane map
64  std::map< int64_t, std::shared_ptr<genfit::DetPlane> > m_detPlaneMap ;
65 
66  /// ACTS Logging Level
67  Acts::Logging::Level m_actsLoggingLevel = Acts::Logging::INFO;
68 
69  /// ACTS Tracking Geometry Context
70  Acts::GeometryContext m_trackingGeoCtx;
71 
72  /// ACTS Tracking Geometry
73  std::shared_ptr<const Acts::TrackingGeometry> m_trackingGeo{nullptr};
74 
75  /// ACTS Material Decorator
76  std::shared_ptr<const Acts::IMaterialDecorator> m_materialDeco{nullptr};
77 
78  /// ACTS surface lookup container for hit surfaces that generate smeared hits
79  VolumeSurfaceMap m_surfaces;
80 
81  /** DD4hep CellID tool.
82  * Use to lookup geometry information for a hit with cellid number (int64_t).
83  * <a href="https://dd4hep.web.cern.ch/dd4hep/reference/classdd4hep_1_1rec_1_1CellIDPositionConverter.html">See DD4hep CellIDPositionConverter documentation</a>
84  */
85  std::shared_ptr<const dd4hep::rec::CellIDPositionConverter> m_cellid_converter = nullptr;
86 
87  /// Acts magnetic field
88  std::shared_ptr<const Jug::BField::DD4hepBField> m_magneticField = nullptr;
89 
90  /// XML-files with the detector description
91  Gaudi::Property<std::vector<std::string>> m_xmlFileNames{
92  this, "detectors", {}, "Detector descriptions XML-files"};
93 
94  /// JSON-file with the material map
95  Gaudi::Property<std::string> m_jsonFileName{
96  this, "materials", "", "Material map JSON-file"};
97 
98  /// Gaudi logging output
99  MsgStream m_log;
100 
101 public:
102  GeoSvc(const std::string& name, ISvcLocator* svc);
103 
104  virtual ~GeoSvc();
105 
106  virtual StatusCode initialize() final;
107 
108  virtual StatusCode finalize() final;
109 
110  /** Build the dd4hep geometry.
111  * This function generates the DD4hep geometry.
112  */
113  StatusCode buildDD4HepGeo();
114 
115  /** Get the top level DetElement.
116  * DD4hep Geometry
117  */
118  virtual dd4hep::DetElement getDD4HepGeo() override;
119 
120  /** Get the CellID geometry tool.
121  * It is constructed in init.
122  * <a href="https://dd4hep.web.cern.ch/dd4hep/reference/classdd4hep_1_1rec_1_1CellIDPositionConverter.html">See DD4hep CellIDPositionConverter documentation</a>
123  */
124  virtual std::shared_ptr<const dd4hep::rec::CellIDPositionConverter> cellIDPositionConverter() const
125  {
126  return m_cellid_converter;
127  }
128 
129  /** Get the main dd4hep Detector.
130  * Returns the pointer to the main dd4hep detector class.
131  * <a href="https://dd4hep.web.cern.ch/dd4hep/reference/classdd4hep_1_1Detector.html">See DD4hep Detector documentation</a>
132  */
133  virtual dd4hep::Detector* detector() override;
134 
135  /** Gets the ACTS tracking geometry.
136  */
137  virtual std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry() const;
138 
139  virtual std::shared_ptr<const Acts::MagneticFieldProvider> getFieldProvider() const override { return m_magneticField; }
140 
141  virtual double centralMagneticField() const
142  {
143  return m_dd4hepGeo->field().magneticField({0, 0, 0}).z() * (Acts::UnitConstants::T / dd4hep::tesla);
144  }
145 
146  virtual const VolumeSurfaceMap& surfaceMap() const { return m_surfaces; }
147 
148  // Note this hsould return a const& but is just copied for the moment to get around genfit's api
149  virtual std::map<int64_t, std::shared_ptr<genfit::DetPlane>> getDetPlaneMap() const { return m_detPlaneMap; }
150 
151  virtual std::map< int64_t, dd4hep::rec::Surface* > getDD4hepSurfaceMap() const { return m_surfaceMap ;}
152 };
153 
154 inline std::shared_ptr<const Acts::TrackingGeometry> GeoSvc::trackingGeometry() const
155 {
156  return m_trackingGeo;
157 }
158 
159 #endif // GEOSVC_H
IGeoSvc.h
draw_surfaces
void draw_surfaces(std::shared_ptr< const Acts::TrackingGeometry > trk_geo, const std::string &fname)
GeoSvc::GeoSvc
GeoSvc(const std::string &name, ISvcLocator *svc)
Definition: GeoSvc.cpp:84
GeoSvc::getFieldProvider
virtual std::shared_ptr< const Acts::MagneticFieldProvider > getFieldProvider() const override
Definition: GeoSvc.h:139
GeoSvc::initialize
virtual StatusCode initialize() final
Definition: GeoSvc.cpp:98
GeoSvc::buildDD4HepGeo
StatusCode buildDD4HepGeo()
Definition: GeoSvc.cpp:224
GeoSvc::cellIDPositionConverter
virtual std::shared_ptr< const dd4hep::rec::CellIDPositionConverter > cellIDPositionConverter() const
Definition: GeoSvc.h:124
GeoSvc::getDD4HepGeo
virtual dd4hep::DetElement getDD4HepGeo() override
Definition: GeoSvc.cpp:242
GeoSvc::trackingGeometry
virtual std::shared_ptr< const Acts::TrackingGeometry > trackingGeometry() const
Definition: GeoSvc.h:154
GeoSvc::VolumeSurfaceMap
std::unordered_map< uint64_t, const Acts::Surface * > VolumeSurfaceMap
Definition: GeoSvc.h:50
GeoSvc
Definition: GeoSvc.h:48
DD4hepBField.h
GeoSvc::~GeoSvc
virtual ~GeoSvc()
Definition: GeoSvc.cpp:88
GeoSvc::getDD4hepSurfaceMap
virtual std::map< int64_t, dd4hep::rec::Surface * > getDD4hepSurfaceMap() const
Definition: GeoSvc.h:151
GeoSvc::finalize
virtual StatusCode finalize() final
Definition: GeoSvc.cpp:222
GeoSvc::centralMagneticField
virtual double centralMagneticField() const
Definition: GeoSvc.h:141
GeoSvc::getDetPlaneMap
virtual std::map< int64_t, std::shared_ptr< genfit::DetPlane > > getDetPlaneMap() const
Definition: GeoSvc.h:149
dd4hep
Definition: IGeoSvc.h:10
GeoSvc::surfaceMap
virtual const VolumeSurfaceMap & surfaceMap() const
Definition: GeoSvc.h:146
GeoSvc::detector
virtual dd4hep::Detector * detector() override
Definition: GeoSvc.cpp:240