G4OCCT 0.1.0
Geant4 interface to Open CASCADE Technology (OCCT) geometry definitions
Loading...
Searching...
No Matches
G4OCCT_DDG4DetectorGeometryConstruction.cc
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2// Copyright (C) 2026 G4OCCT Contributors
3
6
7#include <DD4hep/DetElement.h>
8#include <DD4hep/Printout.h>
9
10#include <DDG4/Factories.h>
11#include <DDG4/Geant4Converter.h>
12#include <DDG4/Geant4DetectorConstruction.h>
13#include <DDG4/Geant4HierarchyDump.h>
14#include <DDG4/Geant4Kernel.h>
15#include <DDG4/Geant4Mapping.h>
16
17#include <G4VPhysicalVolume.hh>
18
19#include "G4OCCT/G4OCCTSolid.hh"
21
22#include <string>
23
24namespace dd4hep {
25namespace sim {
26
28 class G4OCCTGeant4Converter final : public Geant4Converter {
29 public:
30 using Geant4Converter::Geant4Converter;
31
32 void* handleSolid(const std::string& name, const TGeoShape* shape) const override {
33 if (const auto* occtShape = dynamic_cast<const TGeoOCCTSolid*>(shape)) {
34 if (G4VSolid* cached = data().g4Solids[shape]) {
35 return cached;
36 }
37 auto* exact = new G4OCCTSolid(name.c_str(), occtShape->GetOCCTShape());
38 data().g4Solids[shape] = exact;
39 printout(outputLevel, "G4OCCTGeant4Converter",
40 "Converted TGeoOCCTSolid '%s' to exact G4OCCTSolid", name.c_str());
41 return exact;
42 }
43 return Geant4Converter::handleSolid(name, shape);
44 }
45 };
46
48 class G4OCCTDetectorGeometryConstruction final : public Geant4DetectorConstruction {
49 unsigned long m_dumpHierarchy{0};
50 long m_debugVolManager{0};
51 bool m_haveVolManager{true};
52
53 bool m_debugMaterials{false};
54 bool m_debugElements{false};
55 bool m_debugShapes{false};
56 bool m_debugVolumes{false};
57 bool m_debugPlacements{false};
58 bool m_debugReflections{false};
59 bool m_debugRegions{false};
60 bool m_debugLimits{false};
61 bool m_debugSurfaces{false};
62
63 bool m_printPlacements{false};
64 bool m_printSensitives{false};
65
66 int m_geoInfoPrintLevel{DEBUG};
67
68 public:
69 G4OCCTDetectorGeometryConstruction(Geant4Context* ctxt, const std::string& name)
70 : Geant4DetectorConstruction(ctxt, name) {
71 declareProperty("DebugMaterials", m_debugMaterials);
72 declareProperty("DebugElements", m_debugElements);
73 declareProperty("DebugShapes", m_debugShapes);
74 declareProperty("DebugVolumes", m_debugVolumes);
75 declareProperty("DebugPlacements", m_debugPlacements);
76 declareProperty("DebugReflections", m_debugReflections);
77 declareProperty("DebugRegions", m_debugRegions);
78 declareProperty("DebugLimits", m_debugLimits);
79 declareProperty("DebugSurfaces", m_debugSurfaces);
80 declareProperty("DebugVolManager", m_debugVolManager);
81 declareProperty("HaveVolManager", m_haveVolManager);
82 declareProperty("PrintPlacements", m_printPlacements);
83 declareProperty("PrintSensitives", m_printSensitives);
84 declareProperty("GeoInfoPrintLevel", m_geoInfoPrintLevel);
85 declareProperty("DumpHierarchy", m_dumpHierarchy);
86 }
87
88 void constructGeo(Geant4DetectorConstructionContext* ctxt) override {
89 Geant4Mapping& g4map = Geant4Mapping::instance();
90 DetElement world = ctxt->description.world();
91
92 G4OCCTGeant4Converter conv(ctxt->description, outputLevel());
93 conv.debugMaterials = m_debugMaterials;
94 conv.debugElements = m_debugElements;
95 conv.debugShapes = m_debugShapes;
96 conv.debugVolumes = m_debugVolumes;
97 conv.debugRegions = m_debugRegions;
98 conv.debugSurfaces = m_debugSurfaces;
99 conv.debugPlacements = m_debugPlacements;
100 conv.debugReflections = m_debugReflections;
101 conv.debugLimits = m_debugLimits;
102 conv.printPlacements = m_printPlacements;
103 conv.printSensitives = m_printSensitives;
104
105 ctxt->geometry = conv.create(world).detach();
106 ctxt->geometry->printLevel = static_cast<PrintLevel>(m_geoInfoPrintLevel);
107 g4map.attach(ctxt->geometry);
108
109 G4VPhysicalVolume* w = ctxt->geometry->world();
110 context()->kernel().setWorld(w);
111
112 g4map.debugVolManager = m_debugVolManager;
113 g4map.haveVolManager = m_haveVolManager;
114 if (m_haveVolManager) {
115 g4map.volumeManager();
116 }
117 if (m_dumpHierarchy != 0) {
118 Geant4HierarchyDump dmp(ctxt->description, m_dumpHierarchy);
119 dmp.dump("", w);
120 }
121 ctxt->world = w;
122 }
123 };
124
125} // namespace sim
126} // namespace dd4hep
127
128using namespace dd4hep::sim;
129DECLARE_GEANT4ACTION(G4OCCTDetectorGeometryConstruction)
Declaration of G4OCCTSolid.
ROOT/TGeo shape adapter over the shared G4OCCT solid-query kernel.
Geant4 solid wrapping an Open CASCADE Technology (OCCT) TopoDS_Shape.
ROOT/TGeo adapter backed by the shared G4OCCT solid-query kernel.
DDG4 geometry-construction action using G4OCCTGeant4Converter.
void constructGeo(Geant4DetectorConstructionContext *ctxt) override
G4OCCTDetectorGeometryConstruction(Geant4Context *ctxt, const std::string &name)
Geant4 converter extension that maps TGeoOCCTSolid -> exact G4OCCTSolid.
void * handleSolid(const std::string &name, const TGeoShape *shape) const override