-
Notifications
You must be signed in to change notification settings - Fork 31
/
GeantGeoParams.hh
126 lines (95 loc) · 3.87 KB
/
GeantGeoParams.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//----------------------------------*-C++-*----------------------------------//
// Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file geocel/g4/GeantGeoParams.hh
//---------------------------------------------------------------------------//
#pragma once
#include <string>
#include "corecel/Types.hh"
#include "corecel/cont/LabelIdMultiMap.hh"
#include "corecel/data/ParamsDataInterface.hh"
#include "geocel/BoundingBox.hh"
#include "geocel/GeoParamsInterface.hh"
#include "geocel/Types.hh"
#include "GeantGeoData.hh"
class G4VPhysicalVolume;
namespace celeritas
{
//---------------------------------------------------------------------------//
class ScopedGeantLogger;
class ScopedGeantExceptionHandler;
//---------------------------------------------------------------------------//
/*!
* Shared Geant4 geometry model wrapper.
*
* This can be constructed directly by loading a GDML file, or in-memory using
* an existing physical volume. One "gotcha" is that due to persistent static
* variables in Geant4, the volume IDs will be offset if a geometry has been
* loaded and closed previously.
*/
class GeantGeoParams final : public GeoParamsInterface,
public ParamsDataInterface<GeantGeoParamsData>
{
public:
// Construct from a GDML filename
explicit GeantGeoParams(std::string const& gdml_filename);
// Create a VecGeom model from a pre-existing Geant4 geometry
explicit GeantGeoParams(G4VPhysicalVolume const* world);
// Clean up on destruction
~GeantGeoParams();
//! Access the world volume
G4VPhysicalVolume const* world() const { return host_ref_.world; }
//! Whether safety distance calculations are accurate and precise
bool supports_safety() const final { return true; }
//! Outer bounding box of geometry
BBox const& bbox() const final { return bbox_; }
//// VOLUMES ////
//! Number of volumes
VolumeId::size_type num_volumes() const final
{
return vol_labels_.size();
}
// Get the label for a placed volume ID
Label const& id_to_label(VolumeId vol_id) const final;
//! \cond
using GeoParamsInterface::find_volume;
//! \endcond
// Get the volume ID corresponding to a unique label name
VolumeId find_volume(std::string const& name) const final;
// Get the volume ID corresponding to a unique label
VolumeId find_volume(Label const& label) const final;
// Get the volume ID corresponding to a Geant4 logical volume
VolumeId find_volume(G4LogicalVolume const* volume) const final;
// Get zero or more volume IDs corresponding to a name
SpanConstVolumeId find_volumes(std::string const& name) const final;
// Get the Geant4 logical volume corresponding to a volume ID
G4LogicalVolume const* id_to_lv(VolumeId vol_id) const;
//// DATA ACCESS ////
//! Access geometry data on host
HostRef const& host_ref() const final { return host_ref_; }
//! No GPU support code
DeviceRef const& device_ref() const final
{
CELER_NOT_IMPLEMENTED("Geant4 on GPU");
}
private:
//// DATA ////
bool loaded_gdml_{false};
bool closed_geometry_{false};
std::unique_ptr<ScopedGeantLogger> scoped_logger_;
std::unique_ptr<ScopedGeantExceptionHandler> scoped_exceptions_;
// Host metadata/access
LabelIdMultiMap<VolumeId> vol_labels_;
BBox bbox_;
// Host/device storage and reference
HostRef host_ref_;
//// HELPER FUNCTIONS ////
// Complete geometry construction
void build_tracking();
// Construct labels and other host-only metadata
void build_metadata();
};
//---------------------------------------------------------------------------//
} // namespace celeritas