G4OCCT 0.1.0
Geant4 interface to Open CASCADE Technology (OCCT) geometry definitions
Loading...
Searching...
No Matches
G4OCCT_STEPSolid.cc
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2// Copyright (C) 2026 G4OCCT Contributors
3
20#include <DD4hep/DetFactoryHelper.h>
21#include <DD4hep/Printout.h>
23
24#include <stdexcept>
25#include <string>
26
27using namespace dd4hep;
28
29static Ref_t create_step_solid(Detector& description, xml_h e, SensitiveDetector /*sens*/) {
30 xml_det_t x_det = e;
31 xml_comp_t x_step = x_det.child(_Unicode(step_file));
32 xml_comp_t x_pos = x_det.child(_Unicode(position));
33 xml_comp_t x_rot = x_det.child(_Unicode(rotation));
34 xml_comp_t x_mat = x_det.child(_Unicode(material));
35
36 std::string name = x_det.nameStr();
37 std::string path = x_step.attr<std::string>(_Unicode(path));
38
39 TGeoOCCTSolid* stepSolid = nullptr;
40 try {
41 stepSolid = TGeoOCCTSolid::FromSTEP(name.c_str(), path);
42 } catch (const std::exception& ex) {
43 throw std::runtime_error("G4OCCT_STEPSolid: failed to import '" + path + "' (" + ex.what() +
44 ")");
45 }
46 if (!stepSolid) {
47 throw std::runtime_error("G4OCCT_STEPSolid: import of '" + path +
48 "' returned a null TGeoOCCTSolid");
49 }
50 printout(INFO, "G4OCCT_STEPSolid", "Imported '%s' from '%s' as exact TGeoOCCTSolid", name.c_str(),
51 path.c_str());
52
53 // ── DD4hep volume and placement ──────────────────────────────────────────
54 Material mat = description.material(x_mat.attr<std::string>(_Unicode(name)));
55 Volume vol(name + "_vol", Solid(stepSolid), mat);
56 vol.setVisAttributes(description, x_det.visStr());
57
58 DetElement det(name, x_det.id());
59 Position pos(x_pos.x(), x_pos.y(), x_pos.z());
60 RotationZYX rot(x_rot.z(), x_rot.y(), x_rot.x());
61 PlacedVolume pv = description.pickMotherVolume(det).placeVolume(vol, Transform3D(rot, pos));
62 pv.addPhysVolID("system", x_det.id());
63 det.setPlacement(pv);
64 return det;
65}
66
67DECLARE_DETELEMENT(G4OCCT_STEPSolid, create_step_solid)
static Ref_t create_step_solid(Detector &description, xml_h e, SensitiveDetector)
ROOT/TGeo shape adapter over the shared G4OCCT solid-query kernel.
ROOT/TGeo adapter backed by the shared G4OCCT solid-query kernel.
static TGeoOCCTSolid * FromSTEP(const char *name, const std::string &path)