Skip to content

Latest commit

 

History

History
150 lines (106 loc) · 8.09 KB

construction.org

File metadata and controls

150 lines (106 loc) · 8.09 KB

Constructing geometry objects with gegede.

The object schema

The objects that gegede can produce follow a schema which describes the data members of every object that can be produced. The default schema is written as a Python data structure and is available as the dictionary gegede.schema.Schema, (in the source at ./python/gegede/schema/__init__.py). This schema should only be modified to add support for new types. Such modification may need to be carried through to the construction code described below.

Construction of a geometry

This section walks through how to construct a geometry.

The Geometry Object

A geometry is constructed into a fully contained, non-global instance of gegede.construct.Geometry. This allows multiple geometries to be constructed and exist at once. A geometry is first created like:

from gegede.construct import Geometry
geom = Geometry()

Note: in a builder context this geometry object is passed in through the argument to the builder object’s .construct(geom) method.

All geometry construction is then done through this Geometry object. This object has a number of attributes through which one may create instances supported by the geometry schema.

Shapes

The shapes geometry attribute lets one create volume shapes (aka “solids”). A shape is created by calling the associated method. In all cases the first argument must either be a unique name or None (which will cause GeGeDe to generate a unique name). Following this are some number of shape-specific keywords expected by the schema. For example:

box1 = geom.shapes.Box("box1", '1.0m', '2 m', '3 meter')
box2 = geom.shapes.Box("box2", '1m', '2m', dz='3m')
box3 = geom.shapes.Box("box3", dy='2m', dz='3m')

assert box1 == geom.store.shapes["box1"]

Items to note about this example:

  • Shapes must be created with name as their first argument that is unique to the geometry. This requirement is carried over from Geant4.
  • This name can be used to look up the shape from the managed store.
  • Arguments following the name may be positional or keyword in the usual Python fashion.
  • Unspecified arguments will take values as are provided by the schema, knowing these defaults lets it be said that the three boxes are equivalently defined.
  • All numerical quantities that have dimension must have units, while unitless quantities can be expressed as literal numbers or their string representations. Either way, these values are parsed by pint and must match the dimension for the value as given by its prototype in the schema. Otherwise, one is free to specify values in whatever supported unit happens to be convenient.

Materials

Materials are defined using the geometry matter attribute. There are two main classes of matter that can be defined. In all cases, elements and materials must have unique names.

The first type of matter describes elements, and compositions of isotopes. These are described by the atomic number (Z), and the atomic mass. For an element, the atomic mass is the average atomic mass of the element. A composition is composed of one or more isotopes.

elem_hydrogen= geom.matter.Element("Elem_Hydrogen",z=1,a="1.008 g/mole")
elem_helium = geom.matter.Element("Elem_Helium",z=2,a="4.003 g/mole")
elem_oxygen = geom.matter.Element("Elem_Oxygen",z=8,a="15.999 g/mole")

iso_helium3 = geom.matter.Isotope("Iso_Helium3",z=2,ia=3,a="3.016 g/mole")
iso_helium4 = geom.matter.Isotope("Iso_Helium4",z=2,ia=4,a="4.003 g/mole")
comp_helium = geom.matter.Composition("Comp_Helium",
                                      isotopes=(("Iso_Helium3", 0.000002),
                                                ("Iso_Helium4", 0.999998)))

The second type of matter describes materials that are used in simulations (e.g. “air”, “water”, “steel”). These materials are composed of elements, and other materials, and are defined using Molecule, Mixture, and Amalgam.

A Molecule defines a specific molecule composed of elements or compositions of isotopes. It is defined by the number of each element that occur in a single molecule, and comprises one or more elements. For example, gaseous helium will have a single element while liquid water has two.

helium = geom.matter.Molecule("Helium_Gas", density="0.1786 g/cc",
                              elements = (("Elem_Helium",1)))
water = geom.matter.Molecule("Water_Liquid", density="1.0 kg/l",
                             elements = (("Elem_Hydrogen", 2)
                                         ("Elem_Oxygen", 1)))

A Mixture defines a combination of elements and other materials. Mixtures are defined by the mass fraction of each component. For example, oxygenated water could be defined as

aquarium_water = geom.matter.Mixture("Aquarium_Water", density="1.0 kg/l",
                                     components = (("Elem_Oxygen", 0.01),
                                                   ("Water_Liquid", 0.99)))

An Amalgam defines a material with no specific elemental components. It is defined by it’s effective atomic number, and it’s effective atomic mass. For example, an amalgam for water might be

amalgam_water = geom.matter.Amalgam("Amal_Water", density = "1.0 kg/l",
                                    z="7.42", a="18.02 g/mole")

Specific material properties can be defined for materials defined by Molecule, Mixture, and Amalgam. These properties are used to fill the material property table for a material in GEANT4. An example of defining the property for water is

water = geom.matter.Molecule("Water_Liquid", density="1.0 kg/l",
                             elements = (("Elem_Hydrogen", 2)
                                         ("Elem_Oxygen", 1)),
                             properties = (("ABSLENGTH", (20.0, 30.0)),
                                           ("DIFFUSION", (1.0,))))

Volumes

A volume is essentially a composition of shape and material and zero or more placements of daughter volumes. In addition, any number of parameters may be associated. A volume with no daughters may be created like:

mat = ... # set material
box1 = ... # set the shape  
lv = geom.structure.Volume('my_volume', material = mat, shape=box1)

Strictly the material and shape must be set to their names and not their objects but an internal conversion will occur if an object is given. If the material and shape are both None, the volume will be considered an Assembly.

If the volume has daughters and if those daughters may be created before the parent they may be specified like:

mat = ... # set material
box1 = ... # set the shape  
children = make_daughters()
placements = place_daughters(children)
lv = geom.structure.Volume('my_volume', material = mat, shape=box1, placements = placements)

It is often the case that it is not convenient to create the daughters before the mother (particularly in real life). To accommodate that pattern one may set the placements to a list for later filling:

lv = geom.structure.Volume([...], placements = list())
# later...
child = make_child()
lv.placements.append(place_child(child))

FIXME: this should be cleaned up to make an empty list the default.

Creating placements, positions and rotations.

To create a placement itself one needs a (daughter) volume and to specify a position and rotation.

lv = get_volume_from_somewhere()
pos = geom.structure.Position(x='1m', y='2m', z='3m')
rot = geom.structure.Rotation(z='45 deg')
place = geom.structure.Placement(volume=lv, pos=pos, rot=rot)

# then:
mother = geom.structure.Volume(momname, ..., placements = [place])
# or
mother = geom.structure.Volume(momname, ..., placements = [])
mother.placements.append(place)

If a position is not specified the default of a null-displacement will be used. Likewise, no rotation given implies a null rotation.