pyg4ometry.gdml.Defines

Classes

BasicExpression

Holds an expression as a string and can use the expression parser

DefineBase

Common bits for a define. Must have a name and a registry. Adding

ScalarBase

Base class for all scalars (Constants, Quantity, Variable and 'Expression')

Constant

GDML constant define wrapper object

Quantity

GDML quantity define wrapper object

Variable

GDML variable define wrapper object

Expression

General expression, does not have an analogue in GDML

VectorBase

Position

GDML position define wrapper object

Rotation

GDML rotation define wrapper object

Scale

GDML scale define wrapper object

Matrix

GDML matrix define wrapper object

Auxiliary

Auxiliary information container object

Functions

upgradeToStringExpression(reg, obj)

Take a float, str, ScalarBase and return string expression.

evaluateToFloat(reg, obj)

upgradeToExpression(reg, obj)

Helper functions that takes a string and returns an expression object or a string

upgradeToVector(var, reg[, type, unit, addRegistry])

Take a list [x,y,z] and create a vector

upgradeToTransformation(var, reg[, addRegistry])

Take a list of lists [[rx,ry,rz],[x,y,z]] and create a transformation [Rotation,Position]

operationReturnType(name, strExpr, v1, v2, type1, ...)

sin(arg)

Sin of a ScalarBase object, returns a Constant

cos(arg)

Cosine of a ScalarBase object, returns a Constant

tan(arg)

Tangent of a ScalarBase object, returns a Constant

asin(arg)

ArcSin of a ScalarBase object, returns a Constant

acos(arg)

ArcCos of a ScalarBase object, returns a Constant

atan(arg)

ArcTan of a ScalarBase object, returns a Constant

exp(arg)

Exponential of a ScalarBase object, returns a Constant

log(arg)

Natural logarithm of a ScalarBase object, returns a Constant

log10(arg)

Base 10 logarithm of a ScalarBase object, returns a Constant

sqrt(arg)

Square root of a ScalarBase object, returns a Constant

pow(arg, power)

arg raised to power

abs(arg)

absolute value of arg

min(arg1, arg2)

absolute value of arg

max(arg1, arg2)

absolute value of arg

MatrixFromVectors(e, v, name, registry[, eunit, vunit])

Creates a GDML Matrix from an energy and a value vector

Module Contents

class pyg4ometry.gdml.Defines.BasicExpression(name, expressionString, registry)

Holds an expression as a string and can use the expression parser in the supplied registry to evaluate it. A registry is required.

Parameters:
  • name (str) – Name of the expression object

  • expressionString (str) – Expression itself as a string e.g. “12.0” or “a + 3.0”

  • registry (pyg4ometry.geant4.Registry.Registry) – The registry object to give context for any variables used.

>>> r = pyg4ometry.geant4.Registry()
>>> a = BasicExpression("a", "3.0", r)
>>> float(a)
>>> str(a)
name
expressionString
parseTree = None
registry
eval()
variables(allDependents=False)
simp()
__repr__()
__float__()
str()
pyg4ometry.gdml.Defines.upgradeToStringExpression(reg, obj)

Take a float, str, ScalarBase and return string expression.

Parameters:
Returns:

String expression

Return type:

str

pyg4ometry.gdml.Defines.evaluateToFloat(reg, obj)
pyg4ometry.gdml.Defines.upgradeToExpression(reg, obj)

Helper functions that takes a string and returns an expression object or a string

pyg4ometry.gdml.Defines.upgradeToVector(var, reg, type='position', unit='', addRegistry=False)

Take a list [x,y,z] and create a vector

Parameters:
pyg4ometry.gdml.Defines.upgradeToTransformation(var, reg, addRegistry=False)

Take a list of lists [[rx,ry,rz],[x,y,z]] and create a transformation [Rotation,Position]

Parameters:
pyg4ometry.gdml.Defines.operationReturnType(name, strExpr, v1, v2, type1, type2, reg)
class pyg4ometry.gdml.Defines.DefineBase(name='', registry=None)

Common bits for a define. Must have a name and a registry. Adding to the registry can’t be done here as it must be done by the derived type.

name
registry
setName(name)

Set name of the object.

Parameters:

name (str) – name of object

setRegistry(registry)
class pyg4ometry.gdml.Defines.ScalarBase(typeName, name='', registry=None)

Bases: DefineBase

Base class for all scalars (Constants, Quantity, Variable and ‘Expression’)

expression = None
_typeName
setName(name)

Set name of scalar

Parameters:

name (str) – name of object

setExpression(expressionString)

Take a string and make it into the BasicExpression type for this object.

Parameters:

expressionString (str) – Expression to store.

setRegistry(registry)
eval()

Evaluate the expression

Returns:

numerical evaluation of Constant

Return type:

float

__repr__()
__float__()
__add__(other)
__sub__(other)
__rsub__(other)
__mul__(other)
__truediv__(other)
__rtruediv__(other)
__neg__()
__abs__()
__pow__(power)
__radd__
__rmul__
pyg4ometry.gdml.Defines.sin(arg)

Sin of a ScalarBase object, returns a Constant

Parameters:

arg (Constant, Quantity, Variable or Expression) – Argument of sin

pyg4ometry.gdml.Defines.cos(arg)

Cosine of a ScalarBase object, returns a Constant

Parameters:

arg (Constant, Quantity, Variable or Expression) – Argument of cos

pyg4ometry.gdml.Defines.tan(arg)

Tangent of a ScalarBase object, returns a Constant

Parameters:

arg (Constant, Quantity, Variable or Expression) – Argument of tan

pyg4ometry.gdml.Defines.asin(arg)

ArcSin of a ScalarBase object, returns a Constant

Parameters:

arg (Constant, Quantity, Variable or Expression) – Argument of asin

pyg4ometry.gdml.Defines.acos(arg)

ArcCos of a ScalarBase object, returns a Constant

Parameters:

arg (Constant, Quantity, Variable or Expression) – Argument of acos

pyg4ometry.gdml.Defines.atan(arg)

ArcTan of a ScalarBase object, returns a Constant

Parameters:

arg (Constant, Quantity, Variable or Expression) – Argument of tan

pyg4ometry.gdml.Defines.exp(arg)

Exponential of a ScalarBase object, returns a Constant

Parameters:

arg (Constant, Quantity, Variable or Expression) – Argument of exp

pyg4ometry.gdml.Defines.log(arg)

Natural logarithm of a ScalarBase object, returns a Constant

Parameters:

arg (Constant, Quantity, Variable or Expression) – Argument of log

pyg4ometry.gdml.Defines.log10(arg)

Base 10 logarithm of a ScalarBase object, returns a Constant

Parameters:

arg (Constant, Quantity, Variable or Expression) – Argument of log10

pyg4ometry.gdml.Defines.sqrt(arg)

Square root of a ScalarBase object, returns a Constant

Parameters:

arg (Constant, Quantity, Variable or Expression) – Argument of sin

pyg4ometry.gdml.Defines.pow(arg, power)

arg raised to power

Parameters:
pyg4ometry.gdml.Defines.abs(arg)

absolute value of arg

Parameters:

arg (Constant, Quantity, Variable or Expression) – Argument of abs(arg)

pyg4ometry.gdml.Defines.min(arg1, arg2)

absolute value of arg

Parameters:

arg (Constant, Quantity, Variable or Expression) – Argument of abs(arg)

pyg4ometry.gdml.Defines.max(arg1, arg2)

absolute value of arg

Parameters:

arg (Constant, Quantity, Variable or Expression) – Argument of abs(arg)

class pyg4ometry.gdml.Defines.Constant(name, value, registry, addRegistry=True)

Bases: ScalarBase

GDML constant define wrapper object

Parameters:
expression
__eq__(other)
__ne__(other)
__lt__(other)
__gt__(other)
__le__(other)
__ge__(other)
class pyg4ometry.gdml.Defines.Quantity(name, value, unit, type, registry, addRegistry=True)

Bases: ScalarBase

GDML quantity define wrapper object

Parameters:
  • name (str) – of constant for registry

  • value (float,str,Constant,Quantity,Variable) – expression for constant

  • unit (str) – unit of the quantity

  • type (not sure) – type of quantity

  • registry (Registry) – for storing define

  • addRegistry (bool) – add constant to registry

unit
type
expression
__repr__()
eval()

Evaluate the expression

Returns:

numerical evaluation of Constant

Return type:

float

class pyg4ometry.gdml.Defines.Variable(name, value, registry, addRegistry=True)

Bases: ScalarBase

GDML variable define wrapper object

Parameters:
expression
class pyg4ometry.gdml.Defines.Expression(name, value, registry, addRegistry=False)

Bases: ScalarBase

General expression, does not have an analogue in GDML

Parameters:
expression
__int__()
class pyg4ometry.gdml.Defines.VectorBase(typeName, name, registry)
_typeName
name
registry
x = None
y = None
z = None
unit = None
__repr__()
__add__(other)
__sub__(other)
__mul__(other)
__rmul__
__truediv__(other)
setName(name)

Set name of vector

Parameters:

name (str) – name of object

eval()

Evaluate vector

Returns:

numerical evaluation of vector

Return type:

list of floats

nonzero()

Evaluate vector

Returns:

Check if the vector is trivial (all elements zero)

Return type:

bool

__getitem__(key)
setRegistry(registry)
class pyg4ometry.gdml.Defines.Position(name, x, y, z, unit='mm', registry=None, addRegistry=True)

Bases: VectorBase

GDML position define wrapper object

Parameters:
x
y
z
class pyg4ometry.gdml.Defines.Rotation(name, rx, ry, rz, unit='rad', registry=None, addRegistry=True)

Bases: VectorBase

GDML rotation define wrapper object

Parameters:
x
y
z
class pyg4ometry.gdml.Defines.Scale(name, sx, sy, sz, unit=None, registry=None, addRegistry=True)

Bases: VectorBase

GDML scale define wrapper object

Parameters:
x
y
z
class pyg4ometry.gdml.Defines.Matrix(name, coldim, values, registry=None, addRegistry=True)

GDML matrix define wrapper object

Parameters:
  • name (str) – of matrix for registry

  • coldim – is number of columns

  • coldim – int

  • values (list of float, str, Constant, Quantity, Variable) – list of values for matrix

  • registry (Registry) – for storing define

  • addRegistry (bool) – add matrix to registry

name
coldim
registry
values = []
values_asarray
eval()

Evaluate matrix

Returns:

numerical evaluation of matrix

Return type:

numpy.array

__repr__()
__getitem__(key)
pyg4ometry.gdml.Defines.MatrixFromVectors(e, v, name, registry, eunit='eV', vunit='')

Creates a GDML Matrix from an energy and a value vector

Parameters:
  • name (str) – of matrix of registry

  • 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

  • registry (Registry) – for storing define

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

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

class pyg4ometry.gdml.Defines.Auxiliary(auxtype, auxvalue, registry=None, unit='', addRegistry=True)

Auxiliary information container object

auxtype
auxvalue
auxunit
subaux = []
registry
addSubAuxiliary(aux)

Add a sub-auxiliary inside the scope of the current auxiliary

Parameters:

aux (object, gdml.Defines.Auxiliary) – auxiliary definition