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 (shape && shape->IsA() == TGeoOCCTSolid::Class()) {
34 if (G4VSolid* cached = data().g4Solids[shape]) {
35 return cached;
36 }
37 auto* occtShape = static_cast<const TGeoOCCTSolid*>(shape);
38 auto* exact = new G4OCCTSolid(name.c_str(), occtShape->GetOCCTShape());
39 data().g4Solids[shape] = exact;
40 printout(outputLevel, "G4OCCTGeant4Converter",
41 "Converted TGeoOCCTSolid '%s' to exact G4OCCTSolid", name.c_str());
42 return exact;
43 }
44 return Geant4Converter::handleSolid(name, shape);
45 }
46 };
47
49 class G4OCCTDetectorGeometryConstruction final : public Geant4DetectorConstruction {
50 unsigned long m_dumpHierarchy{0};
51 long m_debugVolManager{0};
52 bool m_haveVolManager{true};
53
54 bool m_debugMaterials{false};
55 bool m_debugElements{false};
56 bool m_debugShapes{false};
57 bool m_debugVolumes{false};
58 bool m_debugPlacements{false};
59 bool m_debugReflections{false};
60 bool m_debugRegions{false};
61 bool m_debugLimits{false};
62 bool m_debugSurfaces{false};
63
64 bool m_printPlacements{false};
65 bool m_printSensitives{false};
66
67 int m_geoInfoPrintLevel{DEBUG};
68
69 public:
70 G4OCCTDetectorGeometryConstruction(Geant4Context* ctxt, const std::string& name)
71 : Geant4DetectorConstruction(ctxt, name) {
72 declareProperty("DebugMaterials", m_debugMaterials);
73 declareProperty("DebugElements", m_debugElements);
74 declareProperty("DebugShapes", m_debugShapes);
75 declareProperty("DebugVolumes", m_debugVolumes);
76 declareProperty("DebugPlacements", m_debugPlacements);
77 declareProperty("DebugReflections", m_debugReflections);
78 declareProperty("DebugRegions", m_debugRegions);
79 declareProperty("DebugLimits", m_debugLimits);
80 declareProperty("DebugSurfaces", m_debugSurfaces);
81 declareProperty("DebugVolManager", m_debugVolManager);
82 declareProperty("HaveVolManager", m_haveVolManager);
83 declareProperty("PrintPlacements", m_printPlacements);
84 declareProperty("PrintSensitives", m_printSensitives);
85 declareProperty("GeoInfoPrintLevel", m_geoInfoPrintLevel);
86 declareProperty("DumpHierarchy", m_dumpHierarchy);
87 }
88
89 void constructGeo(Geant4DetectorConstructionContext* ctxt) override {
90 Geant4Mapping& g4map = Geant4Mapping::instance();
91 DetElement world = ctxt->description.world();
92
93 G4OCCTGeant4Converter conv(ctxt->description, outputLevel());
94 conv.debugMaterials = m_debugMaterials;
95 conv.debugElements = m_debugElements;
96 conv.debugShapes = m_debugShapes;
97 conv.debugVolumes = m_debugVolumes;
98 conv.debugRegions = m_debugRegions;
99 conv.debugSurfaces = m_debugSurfaces;
100 conv.debugPlacements = m_debugPlacements;
101 conv.debugReflections = m_debugReflections;
102 conv.debugLimits = m_debugLimits;
103 conv.printPlacements = m_printPlacements;
104 conv.printSensitives = m_printSensitives;
105
106 ctxt->geometry = conv.create(world).detach();
107 ctxt->geometry->printLevel = static_cast<PrintLevel>(m_geoInfoPrintLevel);
108 g4map.attach(ctxt->geometry);
109
110 G4VPhysicalVolume* w = ctxt->geometry->world();
111 context()->kernel().setWorld(w);
112
113 g4map.debugVolManager = m_debugVolManager;
114 g4map.haveVolManager = m_haveVolManager;
115 if (m_haveVolManager) {
116 g4map.volumeManager();
117 }
118 if (m_dumpHierarchy != 0) {
119 Geant4HierarchyDump dmp(ctxt->description, m_dumpHierarchy);
120 dmp.dump("", w);
121 }
122 ctxt->world = w;
123 }
124 };
125
126} // namespace sim
127} // namespace dd4hep
128
129using namespace dd4hep::sim;
130DECLARE_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