25 self.
document = [
'gdml',{
'xmlns:gdml':
"http://cern.ch/2001/Schemas/GDML",
26 'xmlns:xsi':
"http://www.w3.org/2001/XMLSchema-instance",
27 'xsi:noNamespaceSchemaLocation':
"gdml.xsd"},
31 self.
define[2].append([
'position',{
'name':name,
'x':x,
'y':y,
'z':z,
'unit':
'cm'},[]])
34 self.
define[2].append([
'rotation',{
'name':name,
'x':x,
'y':y,
'z':z,
'unit':
'deg'},[]])
37 self.
materials[2].append([
'material', {
'name':name,
'Z':z},
38 [[
'D',{
'value':rho},[]], [
'atom',{
'value':a},[]]] ] )
41 subel = [ [
'D',{
'value':rho},[]] ]
42 for el
in elems.keys():
43 subel.append([
'fraction',{
'n':elems[el],
'ref':el}, []])
45 self.
materials[2].append([
'material',{
'name':name},
49 self.
materials[2].append([
'element', {
'name':name,
'formula':symb,
'Z':z},
50 [[
'atom', {
'value':a},[]] ]])
52 def addReflSolid(self, name, solid, dx, dy, dz, sx, sy, sz, rx, ry, rz):
53 self.
solids[2].append([
'reflectedSolid',{
'name':name,
'solid':solid,
'dx':dx,
'dy':dy,
'dz':dz,
'sx':sx,
'sy':sy,
'sz':sz,
'rx':rx,
'ry':ry,
'rz':rz},[]])
56 self.
solids[2].append([
'box',{
'name':name,
'x':dx,
'y':dy,
'z':dz,
'lunit':
'cm'},[]])
59 self.
solids[2].append([
'paraboloid',{
'name':name,
'rlo':rlo,
'rhi':rhi,
'dz':dz,
'lunit':
'cm'},[]])
61 def addArb8(self, name, v1x, v1y, v2x, v2y, v3x, v3y, v4x, v4y, v5x, v5y, v6x, v6y, v7x, v7y, v8x, v8y, dz):
62 self.
solids[2].append([
'arb8',{
'name':name,
'v1x':v1x,
'v1y':v1y,
'v2x':v2x,
'v2y':v2y,
'v3x':v3x,
'v3y':v3y,
'v4x':v4x,
'v4y':v4y,
'v5x':v5x,
'v5y':v5y,
'v6x':v6x,
'v6y':v6y,
'v7x':v7x,
'v7y':v7y,
'v8x':v8x,
'v8y':v8y,
'dz':dz,
'lunit':
'cm'},[]])
64 def addSphere(self, name, rmin, rmax, startphi, deltaphi, starttheta, deltatheta):
65 self.
solids[2].append([
'sphere',{
'name':name,
'rmin':rmin,
'rmax':rmax,
66 'startphi':startphi,
'deltaphi':deltaphi,
67 'starttheta':starttheta,
'deltatheta':deltatheta,
68 'aunit':
'deg',
'lunit':
'cm'},[]])
70 def addCone(self, name, z, rmin1, rmin2, rmax1, rmax2, sphi, dphi):
71 self.
solids[2].append([
'cone',{
'name':name,
'z':z,
'rmin1':rmin1,
'rmin2':rmin2,
72 'rmax1':rmax1,
'rmax2':rmax2,
73 'startphi':sphi,
'deltaphi':dphi,
'lunit':
'cm',
'aunit':
'deg'}, []] )
75 def addPara(self, name, x, y, z, alpha, theta, phi):
76 self.
solids[2].append([
'para',{
'name':name,
'x':x,
'y':y,
'z':z,
77 'alpha':alpha,
'theta':theta,
'phi':phi,
'lunit':
'cm',
'aunit':
'deg'}, []] )
79 def addTrap(self, name, z, theta, phi, y1, x1, x2, alpha1, y2, x3, x4, alpha2):
80 self.
solids[2].append([
'trap', {
'name':name,
'z':z,
'theta':theta,
'phi':phi,
81 'x1':x1,
'x2':x2,
'x3':x3,
'x4':x4,
82 'y1':y1,
'y2':y2,
'alpha1':alpha1,
'alpha2':alpha2,
'lunit':
'cm',
'aunit':
'deg'}, []])
84 def addTwistedTrap(self, name, z, theta, phi, y1, x1, x2, alpha1, y2, x3, x4, alpha2, twist):
85 self.
solids[2].append([
'twistTrap', {
'name':name,
'z':z,
'theta':theta,
'phi':phi,
86 'x1':x1,
'x2':x2,
'x3':x3,
'x4':x4,
87 'y1':y1,
'y2':y2,
'alpha1':alpha1,
'alpha2':alpha2,
'twist':twist,
'aunit':
'deg',
'lunit':
'cm'}, []])
89 def addTrd(self, name, x1, x2, y1, y2, z):
90 self.
solids[2].append([
'trd',{
'name':name,
'x1':x1,
'x2':x2,
91 'y1':y1,
'y2':y2,
'z':z,
'lunit':
'cm'}, []])
93 def addTube(self, name, rmin, rmax, z, startphi, deltaphi):
94 self.
solids[2].append([
'tube',{
'name':name,
'rmin':rmin,
'rmax':rmax,
95 'z':z,
'startphi':startphi,
'deltaphi':deltaphi,
'lunit':
'cm',
'aunit':
'deg'},[]])
97 def addCutTube(self, name, rmin, rmax, z, startphi, deltaphi, lowX, lowY, lowZ, highX, highY, highZ):
98 self.
solids[2].append([
'cutTube',{
'name':name,
'rmin':rmin,
'rmax':rmax,
99 'z':z,
'startphi':startphi,
'deltaphi':deltaphi,
100 'lowX':lowX,
'lowY':lowY,
'lowZ':lowZ,
'highX':highX,
'highY':highY,
'highZ':highZ,
'lunit':
'cm',
'aunit':
'deg'},[]])
104 for zplane
in zplanes:
105 zpls.append( [
'zplane',{
'z':zplane[0],
'rmin':zplane[1],
'rmax':zplane[2]},[]] )
106 self.
solids[2].append([
'polycone',{
'name':name,
107 'startphi':startphi,
'deltaphi':deltaphi,
'lunit':
'cm',
'aunit':
'deg'}, zpls])
109 def addTorus(self, name, r, rmin, rmax, startphi, deltaphi):
110 self.
solids[2].append( [
'torus',{
'name':name,
'rtor':r,
'rmin':rmin,
'rmax':rmax,
111 'startphi':startphi,
'deltaphi':deltaphi,
'lunit':
'cm',
'aunit':
'deg'},[]] )
115 for zplane
in zplanes:
116 zpls.append( [
'zplane',{
'z':zplane[0],
'rmin':zplane[1],
'rmax':zplane[2]},[]] )
117 self.
solids[2].append([
'polyhedra',{
'name':name,
118 'startphi':startphi,
'deltaphi':deltaphi,
119 'numsides':numsides,
'lunit':
'cm',
'aunit':
'deg'}, zpls])
123 for vertex
in vertices:
124 elems.append( [
'twoDimVertex',{
'x':vertex[0],
'y':vertex[1]},[]] )
125 for section
in sections:
126 elems.append( [
'section',{
'zOrder':section[0],
'zPosition':section[1],
'xOffset':section[2],
'yOffset':section[3],
'scalingFactor':section[4]},[]] )
127 self.
solids[2].append([
'xtru',{
'name':name,
'lunit':
'cm'}, elems])
130 self.
solids[2].append( [
'eltube', {
'name':name,
'dx':x,
'dy':y,
'dz':z,
'lunit':
'cm'},[]] )
132 def addHype(self, name, rmin, rmax, inst, outst, z):
133 self.
solids[2].append( [
'hype', {
'name':name,
'rmin':rmin,
'rmax':rmax,
134 'inst':inst,
'outst':outst,
'z':z,
'lunit':
'cm',
'aunit':
'deg'},[]] )
137 if v[0]!=0.0
or v[1]!=0.0
or v[2]!=0.0:
138 subels.append( [type,{
'name':name,
'x':v[0],
'y':v[1],
'z':v[2],
'unit':
'cm'},[]] )
141 if v[0]!=0.0
or v[1]!=0.0
or v[2]!=0.0:
142 subels.append( [type,{
'name':name,
'x':v[0],
'y':v[1],
'z':v[2],
'unit':
'deg'},[]] )
144 def addUnion(self, name, lname, ltr, lrot, rname, rtr, rrot):
145 subels = [[
'first',{
'ref':lname},[]],
146 [
'second',{
'ref':rname},[]]]
147 self.
addPos(subels,
'position', rname+
'pos', rtr)
148 self.
addRot(subels,
'rotation', rname+
'rot', rrot)
149 self.
addPos(subels,
'firstposition', lname+
'pos', ltr)
150 self.
addRot(subels,
'firstrotation', lname+
'rot', lrot)
151 self.
solids[2].append( [
'union',{
'name':name}, subels])
154 subels = [[
'first',{
'ref':lname},[]],
155 [
'second',{
'ref':rname},[]]]
156 self.
addPos(subels,
'position', rname+
'pos', rtr)
157 self.
addRot(subels,
'rotation', rname+
'rot', rrot)
158 self.
addPos(subels,
'firstposition', lname+
'pos', ltr)
159 self.
addRot(subels,
'firstrotation', lname+
'rot', lrot)
160 self.
solids[2].append( [
'subtraction',{
'name':name}, subels])
163 subels = [[
'first',{
'ref':lname},[]],
164 [
'second',{
'ref':rname},[]]]
165 self.
addPos(subels,
'position', rname+
'pos', rtr)
166 self.
addRot(subels,
'rotation', rname+
'rot', rrot)
167 self.
addPos(subels,
'firstposition', lname+
'pos', ltr)
168 self.
addRot(subels,
'firstrotation', lname+
'rot', lrot)
169 self.
solids[2].append( [
'intersection',{
'name':name}, subels])
171 def addVolume(self, volume, solid, material, daughters):
172 subels = [[
'materialref',{
'ref':material},[]],
173 [
'solidref',{
'ref':solid},[]]]
174 for child
in daughters:
175 subsubels = [[
'volumeref',{
'ref':child[0]},[]],
176 [
'positionref',{
'ref':child[1]},[]]]
178 subsubels.append( [
'rotationref',{
'ref':child[2]},[]] )
180 subels.append( [
'physvol',{}, subsubels])
183 self.
structure[2].append([
'volume',{
'name':volume}, subels, used])
187 for child
in daughters:
188 subsubels = [[
'volumeref',{
'ref':child[0]},[]],
189 [
'positionref',{
'ref':child[1]},[]]]
191 subsubels.append( [
'rotationref',{
'ref':child[2]},[]] )
193 subels.append( [
'physvol',{}, subsubels])
195 self.
structure[2].append([
'assembly',{
'name':volume}, subels])
198 self.
document[2].append( [
'setup',{
'name':name,
'version':version},
199 [ [
'world',{
'ref':world},[]]] ] )
205 def writeElement(elem, offset):
206 offset = offset +
' '
207 file.write(offset+
'<%s' %(elem[0]))
208 for attr
in elem[1].keys():
209 file.write(
' %s="%s"' %(attr,elem[1][attr]))
210 if elem[2].__len__()>0:
212 for subel
in elem[2]:
213 writeElement(subel, offset)
215 file.write(offset+
'</%s>\n' %(elem[0]))
219 file.write(
'<?xml version="1.0" encoding="UTF-8" ?>\n')
addTorus(self, name, r, rmin, rmax, startphi, deltaphi)
addSphere(self, name, rmin, rmax, startphi, deltaphi, starttheta, deltatheta)
addArb8(self, name, v1x, v1y, v2x, v2y, v3x, v3y, v4x, v4y, v5x, v5y, v6x, v6y, v7x, v7y, v8x, v8y, dz)
addPolycone(self, name, startphi, deltaphi, zplanes)
addPara(self, name, x, y, z, alpha, theta, phi)
addReflSolid(self, name, solid, dx, dy, dz, sx, sy, sz, rx, ry, rz)
addRot(self, subels, type, name, v)
addSubtraction(self, name, lname, ltr, lrot, rname, rtr, rrot)
addCone(self, name, z, rmin1, rmin2, rmax1, rmax2, sphi, dphi)
addCutTube(self, name, rmin, rmax, z, startphi, deltaphi, lowX, lowY, lowZ, highX, highY, highZ)
addEltube(self, name, x, y, z)
addTrap(self, name, z, theta, phi, y1, x1, x2, alpha1, y2, x3, x4, alpha2)
addVolume(self, volume, solid, material, daughters)
addPos(self, subels, type, name, v)
addTrd(self, name, x1, x2, y1, y2, z)
addXtrusion(self, name, vertices, sections)
addMixture(self, name, rho, elems)
addRotation(self, name, x, y, z)
addBox(self, name, dx, dy, dz)
addSetup(self, name, version, world)
addPosition(self, name, x, y, z)
addUnion(self, name, lname, ltr, lrot, rname, rtr, rrot)
addElement(self, symb, name, z, a)
addHype(self, name, rmin, rmax, inst, outst, z)
addParaboloid(self, name, rlo, rhi, dz)
addTube(self, name, rmin, rmax, z, startphi, deltaphi)
addAssembly(self, volume, daughters)
addIntersection(self, name, lname, ltr, lrot, rname, rtr, rrot)
addPolyhedra(self, name, startphi, deltaphi, numsides, zplanes)
addTwistedTrap(self, name, z, theta, phi, y1, x1, x2, alpha1, y2, x3, x4, alpha2, twist)
addMaterial(self, name, a, z, rho)