Skip to content

Commit c9769d5

Browse files
factor out geometry part of AdePTGeant4Integration
1 parent b605b08 commit c9769d5

6 files changed

Lines changed: 418 additions & 360 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ endif()
445445
#----------------------------------------------------------------------------#
446446
set(ADEPT_G4_INTEGRATION_SRCS
447447
src/AdePTHepEmHostData.cpp
448+
src/AdePTGeometryBridge.cpp
448449
src/G4HepEmTrackingManagerSpecialized.cc
449450
src/AdePTTrackingManager.cc
450451
src/G4EmStandardPhysics_AdePT.cc

include/AdePT/integration/AdePTGeant4Integration.hh

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717
#include <G4EventManager.hh>
1818
#include <G4Event.hh>
1919

20-
#include <unordered_map>
2120
#include <span>
2221

23-
struct G4HepEmData;
24-
2522
namespace AdePTGeant4Integration_detail {
2623
struct ScoringObjects;
2724
struct Deleter {
@@ -40,31 +37,6 @@ public:
4037
AdePTGeant4Integration(AdePTGeant4Integration &&) = default;
4138
AdePTGeant4Integration &operator=(AdePTGeant4Integration &&) = default;
4239

43-
#ifdef VECGEOM_GDML_SUPPORT
44-
/// @brief Initializes VecGeom geometry
45-
/// @details Currently VecGeom geometry is initialized by loading it from a GDML file,
46-
/// however ideally this function will call the G4 to VecGeom geometry converter
47-
static void CreateVecGeomWorld(/*Temporary parameter*/ std::string filename);
48-
#endif
49-
50-
/// @brief Construct VecGeom geometry from Geant4 physical volume
51-
/// @details This calls the G4VG converter
52-
/// @throws std::runtime_error if input or output volumes are nullptr
53-
static void CreateVecGeomWorld(G4VPhysicalVolume const *physvol);
54-
55-
/// @brief This function compares G4 and VecGeom geometries and reports any differences
56-
static void CheckGeometry(G4HepEmData const *hepEmData);
57-
58-
/// @brief Fills the auxiliary data needed for AdePT
59-
static void InitVolAuxData(adeptint::VolAuxData *volAuxData, G4HepEmData const *hepEmData,
60-
G4HepEmTrackingManagerSpecialized *hepEmTM, bool trackInAllRegions,
61-
std::vector<std::string> const *gpuRegionNames, adeptint::WDTHostRaw &wdtRaw);
62-
63-
/// @brief Returns a mapping of VecGeom placed volume IDs to Geant4 physical volumes and a mapping of VecGeom logical
64-
/// volume IDs to Geant4 logical volumes
65-
static void MapVecGeomToG4(std::vector<G4VPhysicalVolume const *> &vecgeomPvToG4Map,
66-
std::vector<G4LogicalVolume const *> &vecgeomLvToG4Map);
67-
6840
/// @brief Reconstructs GPU hits on host and calls the user-defined sensitive detector code
6941
void ProcessGPUStep(std::span<const GPUHit> gpuSteps, bool const callUserSteppingAction = false,
7042
bool const callUserTrackingaction = false);
@@ -127,8 +99,6 @@ private:
12799
// helper class to provide the CPU-only data for the returning GPU tracks
128100
std::unique_ptr<HostTrackDataMapper> fHostTrackDataMapper;
129101

130-
static std::vector<G4VPhysicalVolume const *> fglobal_vecgeom_pv_to_g4_map;
131-
static std::vector<G4LogicalVolume const *> fglobal_vecgeom_lv_to_g4_map;
132102
std::unique_ptr<AdePTGeant4Integration_detail::ScoringObjects, AdePTGeant4Integration_detail::Deleter>
133103
fScoringObjects{nullptr};
134104
};
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// SPDX-FileCopyrightText: 2026 CERN
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
#ifndef ADEPT_GEOMETRY_BRIDGE_HH
5+
#define ADEPT_GEOMETRY_BRIDGE_HH
6+
7+
#include <AdePT/core/CommonStruct.h>
8+
#include <AdePT/integration/G4HepEmTrackingManagerSpecialized.hh>
9+
10+
#include <VecGeom/base/Config.h>
11+
12+
#include <string>
13+
#include <vector>
14+
15+
class G4LogicalVolume;
16+
class G4VPhysicalVolume;
17+
struct G4HepEmData;
18+
19+
/// @brief Global bridge between Geant4 host geometry and the VecGeom world used by AdePT.
20+
/// @details
21+
/// The geometry world and the VecGeom-to-Geant4 lookup tables are process-global,
22+
/// so this bridge provides the corresponding global services needed during setup and
23+
/// touchable reconstruction.
24+
class AdePTGeometryBridge {
25+
public:
26+
#ifdef VECGEOM_GDML_SUPPORT
27+
/// @brief Initializes the VecGeom world from a GDML file.
28+
/// @details
29+
/// This is the temporary path used when a standalone VecGeom GDML description is
30+
/// provided instead of converting the Geant4 world through G4VG.
31+
static void CreateVecGeomWorld(std::string filename);
32+
#endif
33+
34+
/// @brief Converts the Geant4 world volume into the process-global VecGeom world.
35+
/// @throws std::runtime_error if the input Geant4 world or resulting VecGeom world is null.
36+
static void CreateVecGeomWorld(G4VPhysicalVolume const *physvol);
37+
38+
/// @brief Verifies that the Geant4 and VecGeom geometries match.
39+
static void CheckGeometry(G4HepEmData const *hepEmData);
40+
41+
/// @brief Fills the auxiliary per-volume data needed by AdePT.
42+
static void InitVolAuxData(adeptint::VolAuxData *volAuxData, G4HepEmData const *hepEmData,
43+
G4HepEmTrackingManagerSpecialized *hepEmTM, bool trackInAllRegions,
44+
std::vector<std::string> const *gpuRegionNames, adeptint::WDTHostRaw &wdtRaw);
45+
46+
/// @brief Returns the Geant4 placed volume matching a VecGeom placed volume.
47+
/// @throws std::runtime_error if the VecGeom placed volume is not present in the global lookup table.
48+
static G4VPhysicalVolume const *GetG4PhysicalVolume(vecgeom::VPlacedVolume const *placedVolume);
49+
50+
private:
51+
/// @brief Builds the lookup tables from VecGeom placed/logical volume ids to Geant4 volumes.
52+
static void MapVecGeomToG4(std::vector<G4VPhysicalVolume const *> &vecgeomPvToG4Map,
53+
std::vector<G4LogicalVolume const *> &vecgeomLvToG4Map);
54+
55+
static std::vector<G4VPhysicalVolume const *> fGlobalVecGeomPvToG4Map;
56+
static std::vector<G4LogicalVolume const *> fGlobalVecGeomLvToG4Map;
57+
};
58+
59+
#endif

0 commit comments

Comments
 (0)