pyg4ometry.compare

Submodules

Classes

_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

Tests

Set of options of which tests to perform and potentially with what tolerance.

TestResult

A test result can be either pass, fail or not conducted.

TestResultNamed

ComparisonResult

Holder for a test result. Roughly a dict[testname] = list(TestResultNamed)

Functions

_evaluateToFloat(reg, obj)

gdmlFiles(referenceFile, otherFile[, tests, ...])

geometry(referenceLV, otherLV[, tests, ...])

logicalVolumes(referenceLV, otherLV, tests[, ...])

Compare two LogicalVolume instances with a set of tests.

physicalVolumes(referencePV, otherPV, tests[, ...])

lvName is an optional parent object name to help in print out details decode where the placement is.

assemblyVolumes(referenceAV, otherAV, tests[, ...])

_checkPVLikeDaughters(referencePVLikeObject, ...[, ...])

_testDaughterNameSets(referenceDaughterNameSet, ...)

replicaVolumes(referenceRV, otherRV, tests[, ...])

divisionVolumes(referenceRV, otherRV, tests[, ...])

Compare two DivisionVolume instances with a set of tests.

parameterisedVolumes(referenceRV, otherRV, tests[, ...])

Compare two ParameterisedVolume instances with a set of tests.

materials(referenceMaterial, otherMaterial, tests[, ...])

Compare two materials with a set of tests.

_elements(referenceElement, otherElement, tests[, ...])

solids(referenceSolid, otherSolid, tests[, lvName, ...])

Compare any two solids with a set of tests.

_names(testName, str1, str2[, parentName, ...])

_namesIgnorePointer(testName, str1, str2[, ...])

_vector(vectortype, r1, r2, tests[, parentName, ...])

_copyNumber(pvname, c1, c2, tests[, includeAllTestResults])

_getBoundingBox(obj)

_getRawMesh(obj)

_meshes(lvname, referenceMesh, otherMesh, tests[, ...])

Package Contents

pyg4ometry.compare._evaluateToFloat(reg, obj)
class pyg4ometry.compare._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.compare._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.compare.Tests(*testsByNameToTurnOn)

Set of options of which tests to perform and potentially with what tolerance.

Parameters:

testsByNameToTurnOn (str, list of) – optional strings of tests to turn on. If any, all will be turned off first.

>>> t = Tests()
>>> t = Tests("nDaughters") # only nDaughters will be tested
>>> t = Tests("nDaughters", "shapeArea") # only nDaughters and shapeArea will be tested
_testNames = ['names', 'namesIgnorePointer', 'nDaughters', 'solidExact', 'solidExtent', 'shapeExtent',...
names = True
namesIgnorePointer = True
nDaughters = True
solidExact = True
shapeExtent = True
shapeVolume = True
shapeArea = True
placement = True
scale = True
copyNumber = True
materials = True
materialClassType = True
materialCompositionType = True
testDaughtersByName = True
toleranceSolidParameterFraction = 0.001
toleranceSolidExtentFraction = 1e-06
toleranceVolumeFraction = 0.01
toleranceAreaFraction = 0.01
toleranceTranslationFraction = 1e-06
toleranceScaleFraction = 0.001
toleranceRotationFraction = 1e-06
toleranceMaterialDensityFraction = 0.0001
toleranceMaterialMassFraction = 0.0001
setAllFalse()

Utility to turn off all tests at once. Then can just turn on the one we want.

setFalse(testName)

Safely set a test by name to False.

__len__()
classmethod printAllTestNames()

Print all tests names - the exact strings that can be used to turn them off or on.

__repr__()
class pyg4ometry.compare.TestResult

Bases: enum.Enum

A test result can be either pass, fail or not conducted.

Use 0,1 so we can also implicitly construct this with a Boolean.

Use the bitwise or operator | and not the keyword or. This bitwise or operator returns Failed if either have failed. Only returns NotTested if both are not tested. Cannot use bitwise |= as we cannot update an Enum internally.

Use TestResult.All() for a list of all possible results - useful as an argument for printing.

Failed = 0
Passed = 1
NotTested = 2
__or__(other)
__ior__(other)
static All()

Utility function to get a list of all test types in one.

class pyg4ometry.compare.TestResultNamed(nameIn, testResultIn=TestResult.Failed, detailsIn='')
testResult
name
details
__str__()
class pyg4ometry.compare.ComparisonResult

Holder for a test result. Roughly a dict[testname] = list(TestResultNamed)

Use + and += to append to this object. Uses a default dictionary so no need to initialise any key names. Should always append a list even if only 1 item.

>>> cr = ComparisonResult()
>>> cr['nDaughtersTest'] += [TestResultNamed('volume_1', TestResult.Failed, 'different number')]
>>> cr.print()

print() can take a list of test result outcomes to print. e.g. TestResult.All()

test
result
__getitem__(key)
__setitem__(key, value)
__add__(other)
__iadd__(other)
__len__()
testNames()
print(testName=None, testResultsToPrint=[TestResult.Failed, TestResult.NotTested], allTests=False)
Parameters:
  • testName (str) – (optional) name of specific single test to print - see testNames()

  • testResultsToPrint (list(TestResult)) – (optional) list of result outcomes to print

  • allTests (bool) – (optional) print all tests irrespective of the result

Print failed tests and ones relevant but not implemented yet by default. Control level of print out with optional argument of list of test outcomes to print, or allTests=True.

>>> cr.print()
>>> cr.print('solidName')
>>> cr.print(testResultsToPrint=TestResult.All())
>>> cr.print(allTests=True)
pyg4ometry.compare.gdmlFiles(referenceFile, otherFile, tests=Tests(), includeAllTestResults=False)
Parameters:
  • referenceFile (str.) – GDML file to use as a reference.

  • otherFile (str.) – GDML file to compare.

  • tests (pyg4ometry.compare._Compare.Tests.) – Tests instance to use.

  • includeAllTestResults (bool.) – document all tests attempted in result.

pyg4ometry.compare.geometry(referenceLV, otherLV, tests=Tests(), includeAllTestResults=False)
Parameters:
  • referenceLV (LogicalVolume) – LogicalVolume instance to compare against.

  • otherLV (LogicalVolume) – LogicalVolume instance to compare with referenceLV.

  • tests (pyg4ometry.compare._Compare.Tests.) – Tests instance to use.

  • includeAllTestResults (bool.) – document all tests attempted in result.

pyg4ometry.compare.logicalVolumes(referenceLV, otherLV, tests, recursive=False, includeAllTestResults=False, testsAlreadyDone=[])

Compare two LogicalVolume instances with a set of tests.

testsAlreadyDone should be purposively given as an empty list if using more than once. This is an artefact of the only way we can nicely pass by reference a set of tests while we use these functions recursively. However, this is defined on import and must be updated if reused.

pyg4ometry.compare.physicalVolumes(referencePV, otherPV, tests, recursive=False, lvName='', includeAllTestResults=False, testsAlreadyDone=[])

lvName is an optional parent object name to help in print out details decode where the placement is.

pyg4ometry.compare.assemblyVolumes(referenceAV, otherAV, tests, recursive=False, includeAllTestResults=False, testsAlreadyDone=[])
pyg4ometry.compare._checkPVLikeDaughters(referencePVLikeObject, otherPVLikeObject, tests, parentName, testName, result, recursive=True, includeAllTestResults=True, testsAlreadyDone=[])
pyg4ometry.compare._testDaughterNameSets(referenceDaughterNameSet, otherDaughterNameSet, result, testName, includeAllTestResults)
pyg4ometry.compare.replicaVolumes(referenceRV, otherRV, tests, recursive=True, includeAllTestResults=False, testsAlreadyDone=[])
pyg4ometry.compare.divisionVolumes(referenceRV, otherRV, tests, includeAllTestResults=False, testsAlreadyDone=[])

Compare two DivisionVolume instances with a set of tests.

pyg4ometry.compare.parameterisedVolumes(referenceRV, otherRV, tests, includeAllTestResults=False, testsAlreadyDone=[])

Compare two ParameterisedVolume instances with a set of tests.

pyg4ometry.compare.materials(referenceMaterial, otherMaterial, tests, lvName='', includeAllTestResults=False, testsAlreadyDone=[])

Compare two materials with a set of tests.

This tests assumes both referenceMaterial and otherMaterial are derived from the type pyg4ometry.geant4._Material.Material.

Compares, name, classname, density, n components

pyg4ometry.compare._elements(referenceElement, otherElement, tests, lvName='', includeAllTestResults=False)
pyg4ometry.compare.solids(referenceSolid, otherSolid, tests, lvName='', includeAllTestResults=False)

Compare any two solids with a set of tests.

pyg4ometry.compare._names(testName, str1, str2, parentName='', includeAllTestResults=False)
pyg4ometry.compare._namesIgnorePointer(testName, str1, str2, parentName='', includeAllTestResults=False)
pyg4ometry.compare._vector(vectortype, r1, r2, tests, parentName='', includeAllTestResults=False)
pyg4ometry.compare._copyNumber(pvname, c1, c2, tests, includeAllTestResults=False)
pyg4ometry.compare._getBoundingBox(obj)
pyg4ometry.compare._getRawMesh(obj)
pyg4ometry.compare._meshes(lvname, referenceMesh, otherMesh, tests, includeAllTestResults=False)