Class RMGVertexConfinement¶
Defined in File RMGVertexConfinement.hh
Nested Relationships¶
Nested Types¶
Inheritance Relationships¶
Base Type¶
public RMGVVertexGenerator(Class RMGVVertexGenerator)
Class Documentation¶
-
class RMGVertexConfinement : public RMGVVertexGenerator¶
Class for generating vertices in physical or geometrical volumes.
Public Types
-
enum class GeometricalSolidType¶
Different types of geometrical (user) defined solids.
Values:
-
enumerator kSphere¶
-
enumerator kCylinder¶
-
enumerator kBox¶
-
enumerator kSphere¶
-
enum class SamplingMode¶
Strategy for sampling physical and geometrical volumes.
Can be either:
kIntersectPhysicalWithGeometrical: In which case vertices are generated in the intersection of the set of physical and geometrical volumes.kUnionAllGenerate in the union of all volumes, weighted by surface area / volume.kSubtractGeometrical: Similar tokIntersectPhysicalWithGeometricalbut specified regions can also be excluded.
Values:
-
enumerator kIntersectPhysicalWithGeometrical¶
-
enumerator kUnionAll¶
-
enumerator kSubtractGeometrical¶
Public Functions
-
RMGVertexConfinement()¶
-
virtual void BeginOfRunAction(const G4Run *run) override¶
-
virtual void EndOfRunAction(const G4Run *run) override¶
-
virtual bool GenerateVertex(G4ThreeVector &v) override¶
Generate the actual vertex, according to the sampling mode (see RMGVertexConfinement::SamplingMode).
-
void AddPhysicalVolumeNameRegex(std::string name, std::string copy_nr = ".*")¶
This function is used by the messenger command to add a physical volume(s) to the list of volumes to consider for sampling.
- Parameters:
name – The name of the physical volume or a regular expression supported by
std::regexcopy_nr – The copy number of the physical volume or a regular expression supported by
std::regex
-
inline void AddGeometricalVolume(GenericGeometricalSolidData &data)¶
-
void Reset()¶
-
inline void SetSamplingMode(SamplingMode mode)¶
-
inline void SetFirstSamplingVolumeType(VolumeType type)¶
-
inline void SetWeightByMass(bool mode)¶
-
inline void SetWeightByMassIsotope(int z, int n)¶
-
inline std::vector<GenericGeometricalSolidData> &GetGeometricalSolidDataList()¶
-
struct GenericGeometricalSolidData¶
Information about the geometrical (user) defined solids.
Public Members
-
GeometricalSolidType solid_type = GeometricalSolidType::kBox¶
-
G4ThreeVector volume_center = G4ThreeVector(0, 0, 0)¶
-
double sphere_inner_radius = 0¶
-
double sphere_outer_radius = -1¶
-
double cylinder_inner_radius = 0¶
-
double cylinder_outer_radius = -1¶
-
double cylinder_height = -1¶
-
double cylinder_starting_angle = 0¶
-
double cylinder_spanning_angle = CLHEP::twopi¶
-
double box_x_length = -1¶
-
double box_y_length = -1¶
-
double box_z_length = -1¶
-
GeometricalSolidType solid_type = GeometricalSolidType::kBox¶
-
struct DepthProfile¶
Depth profile for displacing surface-sampled vertices into the material.
When surface sampling is enabled, an optional depth can be sampled from a statistical distribution. The vertex is then displaced inward from the surface by that depth along the outward surface normal, i.e.:
Three distributions are supported in addition to the default of no depth offset:vertex -= depth * solid->SurfaceNormal(vertex);
Exponential: physically motivated model for e.g. alpha/beta surface contamination, characterised by a mean implantation depth.
Truncated Gaussian: Gaussian distribution restricted to a finite range, suitable when a peak depth with physical cut-offs is needed.
Uniform: flat distribution over a user-defined range.
Note
The depth profile is applied in the local coordinate system of the solid before the global rotation and translation are applied. The sampled depth is clamped to the distance from the surface point to the far boundary along the inward normal (via
G4VSolid::DistanceToOut), so the displaced vertex can never cross to the other side of the solid or leave it. For thin volumes this means an over-large sampled depth is silently reduced; choose parameters consistent with the local thickness to keep the resulting depth distribution meaningful.Public Types
-
enum class Type¶
Distribution type for the depth profile.
See also
DepthProfile for a description of each type.
Values:
-
enumerator kNone¶
No depth profile: vertex remains on the surface.
-
enumerator kExponential¶
Exponential distribution parametrised by
mean.
-
enumerator kTruncatedGaussian¶
Gaussian distribution truncated to [
range_lo,range_hi].
-
enumerator kUniform¶
Uniform distribution over [
range_lo,range_hi].
-
enumerator kNone¶
Public Functions
-
double Sample() const¶
Sample a depth value from the configured distribution.
kNone:always returns 0.kExponential:inverse-CDF sampling from Exp(mean), all returned values ≥ 0.kTruncatedGaussian:Box-Muller Gaussian with rejection outside [range_lo,range_hi]. Aborts with a warning if10000consecutive attempts all fall outside the range (mis-configured parameters).kUniform:uniform over [range_lo,range_hi].
- Returns:
The sampled depth in Geant4 length units (mm by default).
-
void Validate() const¶
Validate the configured parameters, aborting with a fatal error on bad input.
Enforces the invariants each distribution needs for Sample to be well-defined:
mean> 0 forkExponential;range_hi> range_lo >= 0 forkUniform; and additionallysigma> 0 forkTruncatedGaussian. Should be called once, before sampling starts.kNonealways validates.
Public Members
-
double mean = 0¶
Mean depth for the exponential and truncated-Gaussian distributions.
For
kExponentialthis is the sole parameter (1/λ). ForkTruncatedGaussianit is the centre of the underlying Gaussian before truncation. Value is in Geant4 length units (mm by default).
-
double sigma = 0¶
Standard deviation for the truncated-Gaussian distribution.
Only used when
typeiskTruncatedGaussian. Value is in Geant4 length units (mm by default).
-
double range_lo = 0¶
Lower bound of the depth range for uniform and truncated-Gaussian distributions.
For
kUniform:minimum sampled depth. ForkTruncatedGaussian:values below this bound are rejected. Value is in Geant4 length units (mm by default).
-
double range_hi = 0¶
Upper bound of the depth range for uniform and truncated-Gaussian distributions.
For
kUniform:maximum sampled depth. ForkTruncatedGaussian:values above this bound are rejected. Value is in Geant4 length units (mm by default).
-
struct SampleableObject¶
An object which we can generate position samples in. Based on either a
G4VPhysicalVolumeor geometrical volume defined by aG4VSolid. The sampling can be performed either on the surface or in the volume of the solid.This structure must contain at least a non-null pointer, between the
physical_volumeandsampling_solidarguments. The idea is that:physical volumes get always a bounding box assigned, but at later time
purely geometrical volumes only have the sampling_solid member defined
Public Functions
-
SampleableObject() = default¶
-
SampleableObject(const SampleableObject&) = default¶
-
SampleableObject(G4VPhysicalVolume *physvol, G4RotationMatrix rot, G4ThreeVector trans, G4VSolid *solid, bool is_native_sampleable = false, bool on_surface = false)¶
SampleableObject constructor.
- Parameters:
physvol – The physical volume.
rot – A rotation matrix for the sampling solid.
trans – A translation vector for the sampling solid.
solid – A solid for geometrical volume sampling or for generating candidate points or rejection sampling.
is_native_sampleable – A flag of whether the solid is natively sampeable.
on_surface – A flag of whether the solid should be sampled on the surface.
-
~SampleableObject() = default¶
-
bool IsInside(const G4ThreeVector &vertex) const¶
Check if the vertex is inside the solid.
- Parameters:
vertex – The sampled vertex.
- Returns:
Boolean flag of whether the vertex is inside the solid.
-
bool Sample(G4ThreeVector &vertex, size_t max_attempts, bool force_containment_check, size_t &n_trials) const¶
Generate a sample from the solid.
Depending on if the solid is a basic one either sample natively, or using rejection sampling. Either samples the volume or the surface depending on the
surface_samplemember.For surface sampling mode the solid is either natively sampled (if this is implemented), or is sampled with SampleableObject::GenerateSurfacePoint
For volume sampling, if the solid is not natively sampleable, points are generated in a bounding box and then rejection sampling is used using SampleableObject::IsInside.
- Parameters:
vertex – The sampled vertex.
max_attempts – The maximum number of candidate vertices for rejection sampling.
force_containment_check – Whether to force a check on where the point is inside the solid.
n_trials – The total number of trials performed.
-
bool GenerateSurfacePoint(G4ThreeVector &vertex, size_t max_attempts, size_t max_intersections) const¶
Generate a point on the surface of the solid.
This follows the algorithm from https://arxiv.org/abs/0802.2960.
Produce a direction vector corresponding to a uniform flux in a bounding sphere.
Find the intersections of this line with the solid.
Pick one intersection, or repeat.
- Parameters:
vertex – The sampled vertex,
max_attempts – The maximum number of attempts to find a valid vertex.
max_intersections – The maximum number of intersections possible for the solid, can be an overestimate.
-
std::vector<G4ThreeVector> GetIntersections(G4ThreeVector start, G4ThreeVector dir) const¶
Get the number of intersections between the solid and the line starting at
startwith directiondir.This is used in the generic surface sampling algorithm. This function makes use of the methods
DistanceToIn(p,v)andDistanceToOut(p,v)ofG4VSolid. It continually looks for the distance to the next boundary (along the line) until this becomes zero indicating there are no more intersections.- Parameters:
start – The starting vector of the line, note this should be outside the solid.
dir – The direction vector.
- Returns:
A vector of the points of intersection.
-
void GetDirection(G4ThreeVector &dir, G4ThreeVector &pos) const¶
Get a position and direction for the generic surface sampling algorithm.
This generates a point on a bounding sphere, then shifts by some impact parameter, following the algorithm from https://arxiv.org/abs/0802.2960. This produces a uniform and isotropic flux inside the bounding sphere.
- Parameters:
dir – The direction vector for the point.
pos – The initial position for the point.
-
void ApplyDepthProfile(G4ThreeVector &local_vertex, const G4VSolid *solid) const¶
Displace a surface point inward according to depth_profile.
Samples a depth from depth_profile and moves
local_vertexinward along the outward surface normal ofsolid. The depth is clamped to the distance to the far boundary (G4VSolid::DistanceToOut) so the vertex stays inside the solid. Does nothing when the profile type isDepthProfile::Type::kNone.- Parameters:
local_vertex – The surface point, in the local frame of
solid. Modified in place.solid – The solid whose surface
local_vertexlies on.
-
void RecalcMass(int z, int n)¶
Public Members
-
G4VPhysicalVolume *physical_volume = nullptr¶
-
G4VSolid *sampling_solid = nullptr¶
-
G4RotationMatrix rotation¶
-
G4ThreeVector translation¶
-
double volume = -1¶
-
double mass = -1¶
-
double surface = -1¶
-
bool surface_sample = false¶
-
bool native_sample = false¶
-
size_t max_num_intersections = 0¶
-
DepthProfile depth_profile = {}¶
Depth profile applied when displacing vertices inward from the surface.
Only used when
surface_sampleistrue. Defaults to no displacement (DepthProfile::Type::kNone).
-
struct SampleableObjectCollection¶
A collection of
SampleableObjectobjects. It can be used to sample from by selecting a volume weighted by surface area or volume.Public Functions
-
SampleableObjectCollection() = default¶
-
inline ~SampleableObjectCollection()¶
-
const SampleableObject &SurfaceWeightedRand() const¶
Select a
SampleableObjectfrom the collection, weighted by surface area.- Returns:
a reference to the chosen
SampleableObject.
-
const SampleableObject &VolumeWeightedRand(bool weight_by_mass) const¶
Select a
SampleableObjectfrom the collection, weighted by volume.- Parameters:
weight_by_mass – A flag of whether the volume weighting should be done by mass and not by volume.
- Returns:
a reference to the chosen
SampleableObject.
-
bool IsInside(const G4ThreeVector &vertex) const¶
-
inline size_t size() const¶
-
inline SampleableObject &at(size_t i)¶
-
inline bool empty() const¶
-
inline SampleableObject &back()¶
-
inline void clear()¶
-
inline void insert(SampleableObjectCollection &other)¶
-
void recalc_total(bool weigh_by_mass, int mass_isotope_z, int mass_istotope_n)¶
Public Members
-
std::vector<SampleableObject> data¶
-
double total_volume = 0¶
-
double total_mass = 0¶
-
double total_surface = 0¶
-
SampleableObjectCollection() = default¶
-
enum class GeometricalSolidType¶