pyg4ometry.geant4

Geant4 classes. The classes mainly match those of Geant4

Subpackages

Submodules

Attributes

Classes

_OverlapType

LogicalVolume

LogicalVolume : G4LogicalVolume

PhysicalVolume

PhysicalVolume : G4VPhysicalVolume, G4PVPlacement

AssemblyVolume

AssemblyVolume : similar to a logical volume but does not have a sense of

_PhysicalVolume

PhysicalVolume : G4VPhysicalVolume, G4PVPlacement

_OverlapType

ReplicaVolume

ReplicaVolume: G4PVReplica

_ReplicaVolume

ReplicaVolume: G4PVReplica

ParameterisedVolume

ParametrisedVolume

_PhysicalVolume

PhysicalVolume : G4VPhysicalVolume, G4PVPlacement

DivisionVolume

DivisionVolume: G4PVDivision

LogicalVolume

LogicalVolume : G4LogicalVolume

SurfaceBase

SkinSurface

PhysicalVolume

PhysicalVolume : G4VPhysicalVolume, G4PVPlacement

SurfaceBase

BorderSurface

Registry

Object to store geometry for input and output.

GeometryComplexityInformation

MaterialBase

Material

This class provides an interface to GDML material definitions.

Element

This class provides an interface to GDML material definitions. Because of the different options

Isotope

This class that handles isotopes as components of composite materials. An element can be

Functions

IsAReplica(logicalVolume)

Utility function to test if an LV is really a replica volume. A replica is a special case

_solid2tessellated(solid)

solidName(var)

removeprefix(string, prefix, /)

AnalyseGeometryComplexity(logicalVolume)

Analyse a geometry tree starting from a logical volume.

_UpdateComplexity(lv, info)

AnalyseGeometryStructure(registry[, lv_name, debug, ...])

Produce a pandas dataframe representing the structure of the geometry.

DumpGeometryStructureTree(lv[, depth])

getNistMaterialDict()

getNistMaterialList()

getNistElementZToName()

_getClassVariables(obj)

_makeNISTCompoundList()

_safeName(name)

loadNISTMaterialDict()

nist_materials_name_lookup(name)

nist_materials_z_lookup(z)

nist_element_2geant4Element(name[, reg])

This returns and instance of either ElementSimple or ElementIsotopeMixture.

nist_material_2geant4Material(name[, reg])

MaterialPredefined(name[, registry])

Proxy method to construct a NIST compound material - this is just a handle as nothing

MaterialArbitrary(name[, registry])

Just a name of a material. WARNING: It is left to the

MaterialSingleElement(name, atomic_number, ...[, ...])

Proxy method to construct a simple material - full description of the element contained is contained in one definition

MaterialCompound(name, density, number_of_components)

Proxy method to construct a composite material - can be any mixture of Elements and/or Materials

ElementSimple(name, symbol, Z, A[, registry])

Proxy method to construct a simple element - full description of the element contained is contained in one definition

ElementIsotopeMixture(name, symbol, n_comp[, ...])

Proxy method to construct a composite element - a mixture of predefined isotopes

Package Contents

pyg4ometry.geant4.IsAReplica(logicalVolume)

Utility function to test if an LV is really a replica volume. A replica is a special case where we have an in-effect dummy mother and is detectable by there only being 1 daughter and it being a ReplicaVolume instance.

class pyg4ometry.geant4._OverlapType
protrusion = 1
overlap = 2
coplanar = 3
pyg4ometry.geant4._solid2tessellated(solid)
class pyg4ometry.geant4.LogicalVolume(solid, material, name, registry=None, addRegistry=True, **kwargs)

LogicalVolume : G4LogicalVolume

Parameters:
  • solid

  • material

  • name (str)

  • registry

  • addRegistry (bool)

type = 'logical'
solid
name
daughterVolumes = []
_daughterVolumesDict
bdsimObjects = []
auxiliary = []
registry
overlapChecked = False
__repr__()
reMesh(recursive=False)

Regenerate the visualisation for this logical volume. Required if the geometry is modified and overlap checking is subsequently required or revisualisation.

add(physicalVolume)

Add physical volume to this logicalVolume

Parameters:

physicalVolume (PhysicalVolume, ReplicaVolume, ParameterisedVolume, DivisionVolume) – physical volume to add

addBDSIMObject(bdsimobject)
_getPhysicalDaughterMesh(pv, warn=True)

Return a (cloned from the lv) mesh of a given pv with rotation,scale, translation evaluated.

cullDaughtersOutsideSolid(solid, rotation=None, position=None)

Given a solid with a placement rotation and position inside this logical volume, remove (cull) any daughters that would not lie entirely within it. The rotation and position are applied to the solid w.r.t. the frame of this logical volume.

Parameters:
  • rotation (list(float, float, float) or None - 3 values in radians) – Tait-Bryan angles for rotation of the solid w.r.t. this lv

  • position (list(float, float, float) or None - 3 values in mm) – translation of the solid w.r.t. this lv

transformDaughters(rotation=(0, 0, 0), position=(0, 0, 0), runit='rad', punit='mm')

Transform the daugter volumes (without clipping)

Parameters:
  • rotation (list(float, float, float) or None - 3 values in radians) – Tait-Bryan angles for rotation of the solid w.r.t. this lv

  • position (list(float, float, float) or None - 3 values in mm) – translation of the solid w.r.t. this lv

  • runit (str) – angular unit for rotation (rad,deg)

  • punit (str) – length unit for position (m,mm,km)

replaceSolid(newSolid, rotation=(0, 0, 0), position=(0, 0, 0), runit='rad', punit='mm')

Replace the outer solid with optional position and rotation

Parameters:
  • newSolid (pyg4ometry.geant4.solid) – object to clip the geometry to

  • rotation (list(float, float, float) or None - 3 values in radians) – Tait-Bryan angles for rotation of the solid w.r.t. this lv

  • position (list(float, float, float) or None - 3 values in mm) – translation of the solid w.r.t. this lv

  • runit (str) – angular unit for rotation (rad,deg)

  • punit (str) – length unit for position (m,mm,km)

clipGeometry(newSolid, rotation=(0, 0, 0), position=(0, 0, 0), runit='rad', punit='mm', replace=False, depth=0, solidUsageCount=_defaultdict(int), lvUsageCount=_defaultdict(int))

Clip the geometry to newSolid, placed with rotation and position.

Parameters:
  • newSolid (pyg4ometry.geant4.solid) – object to clip the geometry to

  • rotation (list(float, float, float) or None - 3 values in radians) – Tait-Bryan angles for rotation of the solid w.r.t. this lv

  • position (list(float, float, float) or None - 3 values in mm) – translation of the solid w.r.t. this lv

  • runit (str) – angular unit for rotation (rad,deg)

  • punit (str) – length unit for position (m,mm,km)

  • replace (bool) – replace the outer solid or not

  • depth (int) – recursion depth (DO NOT USE)

  • solidUsageCount (defaultdict) – solid name dictionary for replacement recursion (DO NOT USE)

  • lvUsageCount (defaultdict) – lv name dictionary for replacement recursion (DO NOT USE)

changeSolidAndTrimGeometry(newSolid, rotation=(0, 0, 0), position=(0, 0, 0), runit='rad', punit='mm')

Change the solid of this logical volume, remove any daughters that will lie outside it, and form new Boolean intersection solids for any daughters that cross the boundary (intersect) it. The rotation and translation are with respect to the original frame and all daughters will now be replaced with respect to the new frame. Therefore, that same rotation and translation should be use to re-place this logical volume if desired. The default is none though, so the frame would nominally remain the same.

Parameters:
  • newSolid (any of pyg4ometry.geant4.solid) – new solid to use for this logical volume

  • rotation (list(float, float, float) or None - 3 values in radians) – Tait-Bryan rotation for the new solid w.r.t. old frame (i.e. current lv)

  • position (list(float, float, float) or None - 3 values in mm) – translation for the new solid w.r.t. old frame (i.e. current lv)

checkOverlaps(recursive=False, coplanar=False, debugIO=False, printOut=True, nOverlapsDetected=[0])

Check based on the meshes in each logical volume if there are any geometrical overlaps. By default, overlaps are checked between daughter volumes and with the mother volume itself (protrusion). Coplanar overlaps may also be checked (default on).

Print out will be given for any overlaps detected and the visualiser will show the colour coded overlaps.

Parameters:
  • recursive – bool - Whether to descend into the daughter volumes and check their contents also.

  • coplanar – bool - Whether to check for coplanar overlaps

  • debugIO – bool - Print out for every check made

  • printOut – bool - (internal) Whether to print out a summary of N overlaps detected

  • nOverlapsDetected – [int] - (internal) counter for recursion - ignore

setSolid(solid)

Set (replace) the outer solid. Does not change the placement of the daughters in the volume. If there is a transformation then use replaceSolid

makeSolidTessellated()

Make solid tesselated. Sometimes useful when a boolean cannot be visualised in Geant4

addAuxiliaryInfo(auxiliary)

Add auxilary information to logical volume :param auxiliary: auxiliary information for the logical volume :type auxiliary: tuple or list

extent(includeBoundingSolid=False)

Compute the axis aligned extent of the logical volume.

Parameters:

includeBoundingSolid (bool) – Include the bounding solid or not

depth(depth=0)

Depth for LV-PV tree

clipSolid(lengthSafety=1e-06)

Assuming the solid of this LV is a Box, reduce its dimensions and re-placement all daughters to reduce the box to the minimum (axis-aligned) bounding box. This updates the dimensions of the box and the translation of each daughter physical volume.

Parameters:

lengthSafety (float) – safety length

makeLogicalPhysicalNameSets()

Return a set of logical names and physical names used in this logical volume and any daughters. This is built up recursively by checking all daughters etc.

findLogicalByName(name)

Return a list of LogicalVolume instances used inside this logical volume as daughters (at any level inside) with the given name.

Parameters:

name (str) – lv name

makeMaterialNameSet()

Return a set of material names used in this logical volume and any daughters. This is built up recursively by checking all daughters etc etc.

assemblyVolume(materialName='G4_AIR0x7f8441173ac0')

Return an assembly volume of this logical volume, in effect removing the solid and material of this logical volume, but retaining all of the relative daughter placements.

makeWorldVolume(worldMaterial='G4_Galactic')

This will create a container box according to the extents of this logical volume: an axis-aligned bounding-box. It will be filled with the given material (predefined by name) and assigned as the world volume (outermost) of the registry according to this logical volume.

dumpStructure(depth=0)
class pyg4ometry.geant4.PhysicalVolume(rotation, position, logicalVolume, name, motherVolume, registry=None, copyNumber=0, addRegistry=True, scale=None)

PhysicalVolume : G4VPhysicalVolume, G4PVPlacement

Parameters:
  • rotation – [float,float,float] - rotations about x,y,z axes of mother volume

  • position – [float,float,float] - translation with respect to mother volume

  • logicalVolumepyg4ometry.geant4.LogicalVolume - instance to place

  • name – str - name of this placement

  • motherVolumepyg4ometry.geant4.LogicalVolume - mother volume to place into

  • registrypyg4ometry.geant4.Registry - registry to register to

  • copyNumber – int - copy number of the placement that can be used for sensitivity

  • addRegistry – bool - whether to add to the registry or not

type = 'placement'
rotation
position
scale
logicalVolume
name
motherVolume
copyNumber
visOptions
registry
__repr__()
extent(includeBoundingSolid=True)
getAABBMesh()

return CSG.core (symmetric around the origin) axis aligned bounding box mesh

class pyg4ometry.geant4.AssemblyVolume(name, registry=None, addRegistry=True)

AssemblyVolume : similar to a logical volume but does not have a sense of shape, material or field :param name: of assembly volume :type name: str :param registry: :type registry: :param addRegistry: :type addRegistry: bool

type = 'assembly'
name
daughterVolumes = []
_daughterVolumesDict
registry
overlapChecked = False
__repr__()
add(physicalVolume)
_getDaughterMeshesByName(name)
_getDaughterMeshesByIndex(index)
_getDaughterMeshes()

Get daughter meshes for overlap checking. return [daughterMesh,..],[daughterBoundingMesh,..][daughterName,…]

_getPVMeshes(pv)

Can technically return more than one mesh if the daughter is also an assembly.

_getPhysicalDaughterMesh(pv, warn=True)

Return a (cloned from the lv) mesh of a given pv with rotation,scale, translation evaluated.

clipGeometry(newSolid, rotation=(0, 0, 0), position=(0, 0, 0), runit='rad', punit='mm', replace=False, depth=0, solidUsageCount=_defaultdict(int), lvUsageCount=_defaultdict(int))

Clip the geometry to newSolid, placed with rotation and position.

extent(includeBoundingSolid=True)
depth(depth=0)

Depth for LV-PV tree

getAABBMesh()

return CSG.core (symmetric around the origin) axis aligned bounding box mesh

logicalVolume(material='G4_Galactic', solidName='worldSolid')

Return an logical volume of this this assembly volume, in effect adding a cuboid solid and material of this logical volume, retaining all of the relative daughter placements.

makeWorldVolume(material='G4_Galactic')
dumpStructure(depth=0)
class pyg4ometry.geant4._PhysicalVolume(rotation, position, logicalVolume, name, motherVolume, registry=None, copyNumber=0, addRegistry=True, scale=None)

PhysicalVolume : G4VPhysicalVolume, G4PVPlacement

Parameters:
  • rotation – [float,float,float] - rotations about x,y,z axes of mother volume

  • position – [float,float,float] - translation with respect to mother volume

  • logicalVolumepyg4ometry.geant4.LogicalVolume - instance to place

  • name – str - name of this placement

  • motherVolumepyg4ometry.geant4.LogicalVolume - mother volume to place into

  • registrypyg4ometry.geant4.Registry - registry to register to

  • copyNumber – int - copy number of the placement that can be used for sensitivity

  • addRegistry – bool - whether to add to the registry or not

type = 'placement'
rotation
position
scale
logicalVolume
name
motherVolume
copyNumber
visOptions
registry
__repr__()
extent(includeBoundingSolid=True)
getAABBMesh()

return CSG.core (symmetric around the origin) axis aligned bounding box mesh

class pyg4ometry.geant4._OverlapType
protrusion = 1
overlap = 2
coplanar = 3
class pyg4ometry.geant4.ReplicaVolume(name, logicalVolume, motherVolume, axis, nreplicas, width, offset=0, registry=None, addRegistry=True, wunit='mm', ounit='mm')

Bases: pyg4ometry.geant4.PhysicalVolume.PhysicalVolume

ReplicaVolume: G4PVReplica

Parameters:
  • name – of physical volume

  • logical – volume to be placed

  • mother – logical volume,

  • axis – kXAxis,kYAxis,kZAxis,kRho,kPhi

  • ncopies – number of replicas

  • width – spacing between replicas along axis

  • offset – of grid

class Axis
kXAxis = 1
kYAxis = 2
kZAxis = 3
kRho = 4
kPhi = 5
type = 'replica'
name
logicalVolume
motherVolume
axis
nreplicas
width
offset
wunit
ounit
visOptions
registry
GetAxisName()
_checkInternalOverlaps(debugIO=False, nOverlapsDetected=[0])

Check if there are overlaps with the nominal mother volume. ie it possible to provide an incorrect mother volume / logical volume and parameterisation.

createReplicaMeshes()
getPhysicalVolumes()

return a list of temporary (ie not added to the relevant registry) PhysicalVolume instances with appropriate transforms including any daughter ReplicaVolumes.

The exception is for kRho axis where new unique solids and logical volumes are required. Therefore, these are added to the registry and inadvertently to the mother LV as PVS.

__repr__()
extent(includeBoundingSolid=True)
class pyg4ometry.geant4._ReplicaVolume(name, logicalVolume, motherVolume, axis, nreplicas, width, offset=0, registry=None, addRegistry=True, wunit='mm', ounit='mm')

Bases: pyg4ometry.geant4.PhysicalVolume.PhysicalVolume

ReplicaVolume: G4PVReplica

Parameters:
  • name – of physical volume

  • logical – volume to be placed

  • mother – logical volume,

  • axis – kXAxis,kYAxis,kZAxis,kRho,kPhi

  • ncopies – number of replicas

  • width – spacing between replicas along axis

  • offset – of grid

class Axis
kXAxis = 1
kYAxis = 2
kZAxis = 3
kRho = 4
kPhi = 5
type = 'replica'
name
logicalVolume
motherVolume
axis
nreplicas
width
offset
wunit
ounit
visOptions
registry
GetAxisName()
_checkInternalOverlaps(debugIO=False, nOverlapsDetected=[0])

Check if there are overlaps with the nominal mother volume. ie it possible to provide an incorrect mother volume / logical volume and parameterisation.

createReplicaMeshes()
getPhysicalVolumes()

return a list of temporary (ie not added to the relevant registry) PhysicalVolume instances with appropriate transforms including any daughter ReplicaVolumes.

The exception is for kRho axis where new unique solids and logical volumes are required. Therefore, these are added to the registry and inadvertently to the mother LV as PVS.

__repr__()
extent(includeBoundingSolid=True)
class pyg4ometry.geant4.ParameterisedVolume(name, logicalVolume, motherVolume, ncopies, paramData, transforms, registry=None, addRegistry=True)

Bases: pyg4ometry.geant4.ReplicaVolume.ReplicaVolume

ParametrisedVolume :param name: of parametrised volume :type name: str :param logical: volume to be placed :type logical: logicalVolume :param mother: volume logical volume :type mother: logicalVolume :param ncopies: number of parametrised volumes :type ncopies: int

class BoxDimensions(pX, pY, pZ, lunit='mm')
pX
pY
pZ
lunit
class TubeDimensions(pRMin, pRMax, pDz, pSPhi, pDPhi, lunit='mm', aunit='rad')
pRMin
pRMax
pDz
pSPhi
pDPhi
lunit
aunit
class ConeDimensions(pRMin1, pRMax1, pRMin2, pRMax2, pDz, pSPhi, pDPhi, lunit='mm', aunit='rad')
pRMin1
pRMax1
pRMin2
pRMax2
pDz
pSPhi
pDPhi
lunit
aunit
class OrbDimensions(pRMax, lunit='mm')
pRMax
lunit
class SphereDimensions(pRMin, pRMax, pSPhi, pDPhi, pSTheta, pDTheta, lunit='mm', aunit='rad')
pRMin
pRMax
pSPhi
pDPhi
pSTheta
pDTheta
lunit
aunit
class TorusDimensions(pRMin, pRMax, pRTor, pSPhi, pDPhi, lunit='mm', aunit='rad')
pRMin
pRMax
pRTor
pSPhi
pDPhi
lunit
aunit
class HypeDimensions(innerRadius, outerRadius, innerStereo, outerStereo, lenZ, lunit='mm', aunit='rad')
innerRadius
outerRadius
innerStereo
outerStereo
lenZ
lunit
aunit
class ParaDimensions(pX, pY, pZ, pAlpha, pTheta, pPhi, lunit='mm', aunit='rad')
pX
pY
pZ
pAlpha
pTheta
pPhi
lunit
aunit
class TrdDimensions(pX1, pX2, pY1, pY2, pZ, lunit='mm')
pX1
pX2
pY1
pY2
pZ
lunit
class TrapDimensions(pDz, pTheta, pDPhi, pDy1, pDx1, pDx2, pAlp1, pDy2, pDx3, pDx4, pAlp2, lunit='mm', aunit='rad')
pDz
pTheta
pDPhi
pDy1
pDx1
pDx2
pAlp1
pDy2
pDx3
pDx4
pAlp2
lunit
aunit
class PolyconeDimensions(pSPhi, pDPhi, pZpl, pRMin, pRMax, lunit='mm', aunit='rad')
pSPhi
pDPhi
pZpl
pRMin
pRMax
lunit
aunit
class PolyhedraDimensions(pSPhi, pDPhi, numSide, pZpl, pRMin, pRMax, lunit='mm', aunit='rad')
pSPhi
pDPhi
numSide
pZpl
pRMin
pRMax
lunit
aunit
class EllipsoidDimensions(pxSemiAxis, pySemiAxis, pzSemiAxis, pzBottomCut, pzTopCut, lunit='mm')
pxSemiAxis
pySemiAxis
pzSemiAxis
pzBottomCut
pzTopCut
lunit
type = 'parametrised'
name
logicalVolume
motherVolume
ncopies
transforms
paramData
registry
visOptions
meshes
createParameterisedMeshes()
__repr__()
extent(includeBoundingSolid=True)
class pyg4ometry.geant4._PhysicalVolume(rotation, position, logicalVolume, name, motherVolume, registry=None, copyNumber=0, addRegistry=True, scale=None)

PhysicalVolume : G4VPhysicalVolume, G4PVPlacement

Parameters:
  • rotation – [float,float,float] - rotations about x,y,z axes of mother volume

  • position – [float,float,float] - translation with respect to mother volume

  • logicalVolumepyg4ometry.geant4.LogicalVolume - instance to place

  • name – str - name of this placement

  • motherVolumepyg4ometry.geant4.LogicalVolume - mother volume to place into

  • registrypyg4ometry.geant4.Registry - registry to register to

  • copyNumber – int - copy number of the placement that can be used for sensitivity

  • addRegistry – bool - whether to add to the registry or not

type = 'placement'
rotation
position
scale
logicalVolume
name
motherVolume
copyNumber
visOptions
registry
__repr__()
extent(includeBoundingSolid=True)
getAABBMesh()

return CSG.core (symmetric around the origin) axis aligned bounding box mesh

class pyg4ometry.geant4.DivisionVolume(name, logicalVolume, motherVolume, axis, ndivisions=-1, width=-1, offset=0, registry=None, addRegistry=True, unit='mm')

Bases: pyg4ometry.geant4.PhysicalVolume.PhysicalVolume

DivisionVolume: G4PVDivision

Parameters:
  • name – of physical volume

  • logical – volume to be placed

  • mother – logical volume,

  • axis – kXAxis,kYAxis,kZAxis,kRho,kPhi

  • ncopies – number of replicas

  • width – spacing between replicas along axis

  • offset – of grid

class Axis
kXAxis = 1
kYAxis = 2
kZAxis = 3
kRho = 4
kPhi = 5
type = 'division'
name
logicalVolume
motherVolume
axis
ndivisions
width
offset
unit
visOptions
position
rotation
scale
getMotherSize()
checkAxis(allowed_axes)
divideBox(offset, width, ndiv)
divideTubs(offset, width, ndiv)
divideCons(offset, width, ndiv)
dividePara(offset, width, ndiv)
divideTrd(offset, width, ndiv)
dividePolycone(offset, width, ndiv)
dividePolyhedra(offset, width, ndiv)
createDivisionMeshes()
__repr__()
extent(includeBoundingSolid=True)
class pyg4ometry.geant4.LogicalVolume(solid, material, name, registry=None, addRegistry=True, **kwargs)

LogicalVolume : G4LogicalVolume

Parameters:
  • solid

  • material

  • name (str)

  • registry

  • addRegistry (bool)

type = 'logical'
solid
name
daughterVolumes = []
_daughterVolumesDict
bdsimObjects = []
auxiliary = []
registry
overlapChecked = False
__repr__()
reMesh(recursive=False)

Regenerate the visualisation for this logical volume. Required if the geometry is modified and overlap checking is subsequently required or revisualisation.

add(physicalVolume)

Add physical volume to this logicalVolume

Parameters:

physicalVolume (PhysicalVolume, ReplicaVolume, ParameterisedVolume, DivisionVolume) – physical volume to add

addBDSIMObject(bdsimobject)
_getPhysicalDaughterMesh(pv, warn=True)

Return a (cloned from the lv) mesh of a given pv with rotation,scale, translation evaluated.

cullDaughtersOutsideSolid(solid, rotation=None, position=None)

Given a solid with a placement rotation and position inside this logical volume, remove (cull) any daughters that would not lie entirely within it. The rotation and position are applied to the solid w.r.t. the frame of this logical volume.

Parameters:
  • rotation (list(float, float, float) or None - 3 values in radians) – Tait-Bryan angles for rotation of the solid w.r.t. this lv

  • position (list(float, float, float) or None - 3 values in mm) – translation of the solid w.r.t. this lv

transformDaughters(rotation=(0, 0, 0), position=(0, 0, 0), runit='rad', punit='mm')

Transform the daugter volumes (without clipping)

Parameters:
  • rotation (list(float, float, float) or None - 3 values in radians) – Tait-Bryan angles for rotation of the solid w.r.t. this lv

  • position (list(float, float, float) or None - 3 values in mm) – translation of the solid w.r.t. this lv

  • runit (str) – angular unit for rotation (rad,deg)

  • punit (str) – length unit for position (m,mm,km)

replaceSolid(newSolid, rotation=(0, 0, 0), position=(0, 0, 0), runit='rad', punit='mm')

Replace the outer solid with optional position and rotation

Parameters:
  • newSolid (pyg4ometry.geant4.solid) – object to clip the geometry to

  • rotation (list(float, float, float) or None - 3 values in radians) – Tait-Bryan angles for rotation of the solid w.r.t. this lv

  • position (list(float, float, float) or None - 3 values in mm) – translation of the solid w.r.t. this lv

  • runit (str) – angular unit for rotation (rad,deg)

  • punit (str) – length unit for position (m,mm,km)

clipGeometry(newSolid, rotation=(0, 0, 0), position=(0, 0, 0), runit='rad', punit='mm', replace=False, depth=0, solidUsageCount=_defaultdict(int), lvUsageCount=_defaultdict(int))

Clip the geometry to newSolid, placed with rotation and position.

Parameters:
  • newSolid (pyg4ometry.geant4.solid) – object to clip the geometry to

  • rotation (list(float, float, float) or None - 3 values in radians) – Tait-Bryan angles for rotation of the solid w.r.t. this lv

  • position (list(float, float, float) or None - 3 values in mm) – translation of the solid w.r.t. this lv

  • runit (str) – angular unit for rotation (rad,deg)

  • punit (str) – length unit for position (m,mm,km)

  • replace (bool) – replace the outer solid or not

  • depth (int) – recursion depth (DO NOT USE)

  • solidUsageCount (defaultdict) – solid name dictionary for replacement recursion (DO NOT USE)

  • lvUsageCount (defaultdict) – lv name dictionary for replacement recursion (DO NOT USE)

changeSolidAndTrimGeometry(newSolid, rotation=(0, 0, 0), position=(0, 0, 0), runit='rad', punit='mm')

Change the solid of this logical volume, remove any daughters that will lie outside it, and form new Boolean intersection solids for any daughters that cross the boundary (intersect) it. The rotation and translation are with respect to the original frame and all daughters will now be replaced with respect to the new frame. Therefore, that same rotation and translation should be use to re-place this logical volume if desired. The default is none though, so the frame would nominally remain the same.

Parameters:
  • newSolid (any of pyg4ometry.geant4.solid) – new solid to use for this logical volume

  • rotation (list(float, float, float) or None - 3 values in radians) – Tait-Bryan rotation for the new solid w.r.t. old frame (i.e. current lv)

  • position (list(float, float, float) or None - 3 values in mm) – translation for the new solid w.r.t. old frame (i.e. current lv)

checkOverlaps(recursive=False, coplanar=False, debugIO=False, printOut=True, nOverlapsDetected=[0])

Check based on the meshes in each logical volume if there are any geometrical overlaps. By default, overlaps are checked between daughter volumes and with the mother volume itself (protrusion). Coplanar overlaps may also be checked (default on).

Print out will be given for any overlaps detected and the visualiser will show the colour coded overlaps.

Parameters:
  • recursive – bool - Whether to descend into the daughter volumes and check their contents also.

  • coplanar – bool - Whether to check for coplanar overlaps

  • debugIO – bool - Print out for every check made

  • printOut – bool - (internal) Whether to print out a summary of N overlaps detected

  • nOverlapsDetected – [int] - (internal) counter for recursion - ignore

setSolid(solid)

Set (replace) the outer solid. Does not change the placement of the daughters in the volume. If there is a transformation then use replaceSolid

makeSolidTessellated()

Make solid tesselated. Sometimes useful when a boolean cannot be visualised in Geant4

addAuxiliaryInfo(auxiliary)

Add auxilary information to logical volume :param auxiliary: auxiliary information for the logical volume :type auxiliary: tuple or list

extent(includeBoundingSolid=False)

Compute the axis aligned extent of the logical volume.

Parameters:

includeBoundingSolid (bool) – Include the bounding solid or not

depth(depth=0)

Depth for LV-PV tree

clipSolid(lengthSafety=1e-06)

Assuming the solid of this LV is a Box, reduce its dimensions and re-placement all daughters to reduce the box to the minimum (axis-aligned) bounding box. This updates the dimensions of the box and the translation of each daughter physical volume.

Parameters:

lengthSafety (float) – safety length

makeLogicalPhysicalNameSets()

Return a set of logical names and physical names used in this logical volume and any daughters. This is built up recursively by checking all daughters etc.

findLogicalByName(name)

Return a list of LogicalVolume instances used inside this logical volume as daughters (at any level inside) with the given name.

Parameters:

name (str) – lv name

makeMaterialNameSet()

Return a set of material names used in this logical volume and any daughters. This is built up recursively by checking all daughters etc etc.

assemblyVolume(materialName='G4_AIR0x7f8441173ac0')

Return an assembly volume of this logical volume, in effect removing the solid and material of this logical volume, but retaining all of the relative daughter placements.

makeWorldVolume(worldMaterial='G4_Galactic')

This will create a container box according to the extents of this logical volume: an axis-aligned bounding-box. It will be filled with the given material (predefined by name) and assigned as the world volume (outermost) of the registry according to this logical volume.

dumpStructure(depth=0)
class pyg4ometry.geant4.SurfaceBase(name, type, surface_property, registry, addRegistry)
name
type
registry
surface_property
_chkType(obj, t, prop)
class pyg4ometry.geant4.SkinSurface(name, volumeref, surface_property, registry, addRegistry=True)

Bases: pyg4ometry.geant4.SurfaceBase.SurfaceBase

volumeref
__repr__()
class pyg4ometry.geant4.PhysicalVolume(rotation, position, logicalVolume, name, motherVolume, registry=None, copyNumber=0, addRegistry=True, scale=None)

PhysicalVolume : G4VPhysicalVolume, G4PVPlacement

Parameters:
  • rotation – [float,float,float] - rotations about x,y,z axes of mother volume

  • position – [float,float,float] - translation with respect to mother volume

  • logicalVolumepyg4ometry.geant4.LogicalVolume - instance to place

  • name – str - name of this placement

  • motherVolumepyg4ometry.geant4.LogicalVolume - mother volume to place into

  • registrypyg4ometry.geant4.Registry - registry to register to

  • copyNumber – int - copy number of the placement that can be used for sensitivity

  • addRegistry – bool - whether to add to the registry or not

type = 'placement'
rotation
position
scale
logicalVolume
name
motherVolume
copyNumber
visOptions
registry
__repr__()
extent(includeBoundingSolid=True)
getAABBMesh()

return CSG.core (symmetric around the origin) axis aligned bounding box mesh

class pyg4ometry.geant4.SurfaceBase(name, type, surface_property, registry, addRegistry)
name
type
registry
surface_property
_chkType(obj, t, prop)
class pyg4ometry.geant4.BorderSurface(name, physref1, physref2, surface_property, registry, addRegistry=True)

Bases: pyg4ometry.geant4.SurfaceBase.SurfaceBase

physref1
physref2
__repr__()
pyg4ometry.geant4.solidName(var)
pyg4ometry.geant4.removeprefix(string, prefix, /)
Parameters:
Return type:

str

class pyg4ometry.geant4.Registry

Object to store geometry for input and output. All of the pyg4ometry classes can be used without storing them in the Registry. The registry is used to write the GDML output file. A registry needs to be used in conjunction with GDML Define objects for evaluation of expressions.

materialList = []
defineDict
materialDict
solidDict
logicalVolumeDict
assemblyVolumeDict
physicalVolumeDict
surfaceDict
loopDict
logicalVolumeList = []
solidUsageCountDict
volumeTypeCountDict
physicalVolumeCountDict
surfaceTypeCountDict
logicalVolumeMeshSkip = []
userInfo = []
defineNameCount
materialNameCount
materialUsageCount
solidNameCount
logicalVolumeNameCount
assemblyVolumeNameCount
physicalVolumeNameCount
surfaceNameCount
solidTypeCountDict
logicalVolumeUsageCountDict
editedSolids = []
expressionParser = None
clear()

Empty all internal structures

getExpressionParser()
registerSolidEdit(solid)
addMaterial(material, dontWarnIfAlreadyAdded=False)

Register a material with this registry.

Parameters:

material (Material) – Material object for storage

transferMaterial(material, incrementRenameDict={}, userRenameDict=None)

Transfer a material to this registry. This can operate on a Material, an Isotope and an Element instance.

addSolid(solid)

Register a solid with this registry.

Parameters:

solid (One of the geant4 solids) – Solid object for storage

transferSolid(solid, incrementRenameDict={}, userRenameDict=None)

Transfer a solid to this registry. Doesn’t handle any members’ transferal - only the solid itself.

Parameters:

solid (One of the geant4 solids) – Solid object for storage

addLogicalVolume(volume)

Register a logical volume with this registry. Also accepts Assembly Volumes.

Parameters:

volume (LogicalVolume) – LogicalVolume object for storage

transferLogicalVolume(volume, incrementRenameDict={}, userRenameDict=None)

Transfer a logical volume to this registry. Doesn’t handle any members’ transferal - only the logical volume itself.

addPhysicalVolume(volume)

Registry a physical volume with this registry.

Parameters:

volume (PhysicalVolume) – PhysicalVolume object for storage

transferPhysicalVolume(volume, incrementRenameDict={}, userRenameDict=None)

Transfer a physical volume to this registry. Doesn’t handle any members’ transferal - only the physical volume itself.

addSurface(surface)

Register a surface with this registry.

Parameters:

surface (pyg4ometry.geant4.BorderSurface or pyg4ometry.geant4.SkinSurface) – Surface

transferSurface(surface, incrementRenameDict={}, userRenameDict=None)

Transfer a surface to this registry.

addAuxiliary(auxiliary)
addDefine(define)

Register a define with this registry.

Parameters:

define (Constant, Quantity, Variable, Matrix) – Definition object for storage

transferDefine(define, incrementRenameDict={}, userRenameDict=None)

Transfer a single define from another registry to this one. No checking on previous registry or not.

transferDefines(var, otherRegistry, incrementRenameDict={}, userRenameDict=None)

This function tolerates all types of defines including vector ones.

Transfer defines from one registry to another recursively. A define may not be part of the old registry so won’t be added to this one. A define may be a vector or composite and its ‘bits’ may be in the (old) registry so each part should be checked.

In “3x + 2”, “x” would be a variable”. In “3.5*2” there would be no variables.

setWorld(worldIn)

The argument can either be the name of logical volume of the world or the pyg4ometry.geant4.LogicalVolume instance of the world volume. The term world is used to refer to the outermost volume of the hierarchy.

setWorldVolume(worldIn)

An alias for some of us who can’t remember.

_orderMaterialList(materials, materials_ordered=[])
orderMaterials()

Need to have a ordered list of all material entities for writing to GDML. GDML needs to have the isotopes/elements/materials defined in use order

orderLogicalVolumes(lvName, first=True)

Need to have an ordered list from most basic (solid) object upto physical/logical volumes for writing to GDML. GDML needs to have the solids/booleans/volumes defined in order

addVolumeRecursive(volume, collapseAssemblies=False, incrementRenameDict=None, userRenameDict=None)

Transfer a volume hierarchy to this registry. Any objects that had a registry set to another will be set to this one and will be owned by it effectively. :param volume: PhysicalVolume or LogicalVolume or AssemblyVolume. :type volume: pyg4ometry.geant4.PhysicalVolume, pyg4ometry.geant4.LogicalVolume, pyg4ometry.geant4.AssemblyVolume. :param collapseAssemblies: if True, daughters of AssemblyVolume’s will be attached directly to the mother of the assembly and the AssemblyVolume itself will be eliminated from the geometry tree :param incrementRenameDict: ignore - dictionary used internally for potentially incrementing names :param userRenameDict: a dictionary of find/replace regex strings to be used to rename volumes/materials/etc.

In the case where some object or variable has a name (e.g. ‘X’) that already exists in this registry, it will be incremented to ‘X_1’.

addAndCollapseAssemblyVolumeRecursive(assemblyPV, motherVol, positions, rotations, scales, names, incrementRenameDict, userRenameDict)

Transfer and collapse an AssemblyVolume hierarchy to this registry. Daughter volumes are copied, renamed, and attached to the supplied mother LogicalVolume with the correct position/rotation. Any objects that had a registry set to another will be set to this one and will be owned by it effectively. :param assemblyPV: the PhysicalVolume that places an AssemblyVolume :param motherVol: the LogicalVolume to which all daughters of the AssemblyVolume (including any daughters of nested AssemblyVolume’s) should be attached :param positions: a list (initially empty) to hold position objects for each AssemblyVolume in a hierarchy of nested assemblies (used to correctly set the transformation of daughters within the motherVol) :param rotations: a list (initially empty) to hold rotation objects for each AssemblyVolume in a hierarchy of nested assemblies (used to correctly set the transformation of daughters within the motherVol) :param scales: a list (initially empty) to hold scale objects for each AssemblyVolume in a hierarchy of nested assemblies (used to correctly set the transformation of daughters within the motherVol) :param names: a list (initially empty) to hold the names of each AssemblyVolume in a hierarchy of nested assemblies (used to set unique names for the daughters within the motherVol) :param incrementRenameDict: ignore - dictionary used internally for potentially incrementing names :param userRenameDict: a dictionary of find/replace regex strings to be used to rename volumes/materials/etc.

transferSolidDefines(solid, incrementRenameDict={}, userRenameDict=None)

For each parameter in a given solid (unique to each) check if it’s a define and transfer that over.

volumeTree(lvName)

Not sure what this method is used for

solidTree(solidName)

Not sure what this method is used for

getWorldVolume()
printStats()
structureAnalysis(lv_name=None, debug=False, level=0, df=None)
_findDictByName(dic, nameFragment)

Find a object which name matches (or partially matches) nameFragment, returns a list of objects

findSolidByName(nameFragment='box')

Find a solid which name matches (or partially matches) nameFragment, returns a list of solids

findMaterialByName(nameFragment='G4_AIR')

Find a material which name matches (or partially matches) nameFragment, returns a list of materials

findLogicalVolumeByName(nameFragment='World')

Find a logical volume which name matches (or partially matches) nameFragment, returns a list of LogicalVolumes

findPhysicalVolumeByName(nameFragment)

Find a physical volume which name matches (or partially matches) nameFragment, returns a list of LogicalVolumes

class pyg4ometry.geant4.GeometryComplexityInformation
solids
nDaughtersPerLV
nDaughters
booleanDepthCount
booleanDepth
printSummary(boolDepthLimit=3)
pyg4ometry.geant4.AnalyseGeometryComplexity(logicalVolume)

Analyse a geometry tree starting from a logical volume. Produces an instance of GeometryComplexityInformation with summary information. Provides:

  • count per solid type

  • number of daughters per logical volume

  • dictionary of N daughters for each logical volume name

  • depth count of Boolean solids

ie a Boolean of a Boolean returns 2, a Boolean of two primitives returns 1

  • a dictionary of boolean depth for each logical volume name

Example:

info = AnalyseGeometryComplexity(lv)
info.printSummary()
pyg4ometry.geant4._UpdateComplexity(lv, info)
pyg4ometry.geant4.AnalyseGeometryStructure(registry, lv_name=None, debug=False, level=0, df=None)

Produce a pandas dataframe representing the structure of the geometry.

pyg4ometry.geant4.DumpGeometryStructureTree(lv, depth=0)
pyg4ometry.geant4._nistMaterialDict = None
pyg4ometry.geant4._nistMaterialList = None
pyg4ometry.geant4._nistElementZToName = None
pyg4ometry.geant4.getNistMaterialDict()
pyg4ometry.geant4.getNistMaterialList()
pyg4ometry.geant4.getNistElementZToName()
pyg4ometry.geant4._getClassVariables(obj)
pyg4ometry.geant4._makeNISTCompoundList()
pyg4ometry.geant4._safeName(name)
pyg4ometry.geant4.loadNISTMaterialDict()
pyg4ometry.geant4.nist_materials_name_lookup(name)
pyg4ometry.geant4.nist_materials_z_lookup(z)
pyg4ometry.geant4.nist_element_2geant4Element(name, reg=None)

This returns and instance of either ElementSimple or ElementIsotopeMixture.

pyg4ometry.geant4.nist_material_2geant4Material(name, reg=None)
pyg4ometry.geant4.MaterialPredefined(name, registry=None)

Proxy method to construct a NIST compound material - this is just a handle as nothing needs to be additionally defined for a NIST compound. A check is performed on the name to ensure it is a valid NIST specifier.

Inputs:

name - string

pyg4ometry.geant4.MaterialArbitrary(name, registry=None)

Just a name of a material. WARNING: It is left to the user to ensure that the name is valid.

Inputs:

name - string

pyg4ometry.geant4.MaterialSingleElement(name, atomic_number, atomic_weight, density, registry=None, tolerateZeroDensity=False)

Proxy method to construct a simple material - full description of the element contained is contained in one definition

Inputs:

name - string atomic_number - int, number of protons, commonly known as ‘Z’ atomic_weight - molar weight in g/mole, commonly known as ‘A’ density - float, material density in g/cm3

pyg4ometry.geant4.MaterialCompound(name, density, number_of_components, registry=None, tolerateZeroDensity=False, state=None)

Proxy method to construct a composite material - can be any mixture of Elements and/or Materials

Inputs:

name - string density - float, material density in g/cm3 number_of_components - int, number of components in the mixture

pyg4ometry.geant4.ElementSimple(name, symbol, Z, A, registry=None)

Proxy method to construct a simple element - full description of the element contained is contained in one definition

Inputs:

name - string symbol - string, chemical formula of the compound Z - int, Atomic number A - float, mass number

pyg4ometry.geant4.ElementIsotopeMixture(name, symbol, n_comp, registry=None, state=None)

Proxy method to construct a composite element - a mixture of predefined isotopes

Inputs:

name - string symbol - string, chemical formula of the compound n_comp - int, number of isotope components

class pyg4ometry.geant4.MaterialBase(name, state=None, registry=None)
name
state
registry
_addToRegistry()
get_material_oject(material)
set_registry(registry, dontWarnIfAlreadyAdded=False)
set_state(state)
__repr__()
class pyg4ometry.geant4.Material(**kwargs)

Bases: MaterialBase

This class provides an interface to GDML material definitions.

Because of the different options for constructing a material instance the constructor is kwarg only. Proxy methods are provided to instantiate particular types of material. Those proxy methods are:

MaterialSingleElement MaterialCompound MaterialPredefined

It is possible to instantiate a material directly through kwargs. The possible kwargs are (but note some are mutually exclusive): name - string density - float atomic_number - int atomic_weight - float number_of_components - int state - string pressure - float pressure_unit - string temperature - float temperature_unit - string

density
atomic_number
atomic_weight
number_of_components
components = []
properties
_state_variables
_NIST_compounds
add_element_massfraction(element, massfraction)

Add an element as a component to a material as a fraction of the material mass. Can only add elements to materials defined as composite.

Inputs:

element - pyg4ometry.geant4.Material.Element instance massfraction - float, 0.0 < massfraction <= 1.0

add_element_natoms(element, natoms)

Add an element as a component to a material as a number of atoms in the material molecule. Can only add elements to materials defined as composite.

Inputs:

element - pyg4ometry.geant4.Material.Element instance natoms - int, number of atoms in the compound molecule

add_material(material, fractionmass)

Add a material as a component to another material (mixture) as a fraction of the mixture mass. Can only add new materials to materials defined as composite.

Inputs:

material - pyg4ometry.geant4.Material.Material instance massfraction - float, 0.0 < massfraction <= 1.0

set_pressure(value, unit='pascal')
set_temperature(value, unit='K')
property state_variables
__str__()
addProperty(name, matrix)

Add a material property from a matrix.

Parameters:
  • name (str) – key of the material property

  • matrix (Matrix) – matrix defining the value(s) of the property

addVecProperty(name, e, v, eunit='eV', vunit='')

Add a property from an energy and a value vector to this object.

Parameters:
  • name (str) – key of property

  • e (list or numpy.array - shape (1,)) – energy list/vector in units of eunit

  • v (list or numpy.array - shape (1,)) – value list/vector in units of vunit

  • eunit (str) – unit for the energy vector (default: eV)

  • vunit (str) – unit for the value vector (default: unitless)

addConstProperty(name, value, vunit='')

Add a constant scalar property to this object.

Parameters:
  • name (str) – key of property

  • value (str,float,int) – constant value for this property

  • vunit (str) – unit for the value vector (default: unitless)

class pyg4ometry.geant4.Element(**kwargs)

Bases: MaterialBase

This class provides an interface to GDML material definitions. Because of the different options for constructing a material instance the constructor is kwarg only. Proxy methods are provided to instantiate particular types of material. Those proxy methods are:

ElementSimple ElementIsotopeMixture

It is possible to instantiate a material directly through kwargs. The possible kwargs are (but note some are mutually exclusive): name - string symbol - string Z - int A - int n_comp - int

symbol
n_comp
Z
A
components = []
add_isotope(isotope, abundance)

Add an isotope as a component to an element as an abundance fraction in the element.

Inputs:

element - pyg4ometry.geant4.Material.Isotope instance abundance - float, 0.0 < abundance <= 1.0

class pyg4ometry.geant4.Isotope(name, Z, N, a, registry=None)

Bases: MaterialBase

This class that handles isotopes as components of composite materials. An element can be defined as a mixture of isotopes.

Inputs:

name - string Z - int, atomic number N - int, mass number a - float, molar weight in g/mole

Z
N
a
type = 'isotope'