25 self.
documentdocument = [
'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.
definedefine[2].append([
'position',{
'name':name,
'x':x,
'y':y,
'z':z,
'unit':
'cm'},[]])
34 self.
definedefine[2].append([
'rotation',{
'name':name,
'x':x,
'y':y,
'z':z,
'unit':
'deg'},[]])
37 self.
materialsmaterials[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.
materialsmaterials[2].append([
'material',{
'name':name},
49 self.
materialsmaterials[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.
solidssolids[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.
solidssolids[2].append([
'box',{
'name':name,
'x':dx,
'y':dy,
'z':dz,
'lunit':
'cm'},[]])
59 self.
solidssolids[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.
solidssolids[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.
solidssolids[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.
solidssolids[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.
solidssolids[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.
solidssolids[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.
solidssolids[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.
solidssolids[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.
solidssolids[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.
solidssolids[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.
solidssolids[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.
solidssolids[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.
solidssolids[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.
solidssolids[2].append([
'xtru',{
'name':name,
'lunit':
'cm'}, elems])
130 self.
solidssolids[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.
solidssolids[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.
addPosaddPos(subels,
'position', rname+
'pos', rtr)
148 self.
addRotaddRot(subels,
'rotation', rname+
'rot', rrot)
149 self.
addPosaddPos(subels,
'firstposition', lname+
'pos', ltr)
150 self.
addRotaddRot(subels,
'firstrotation', lname+
'rot', lrot)
151 self.
solidssolids[2].append( [
'union',{
'name':name}, subels])
154 subels = [[
'first',{
'ref':lname},[]],
155 [
'second',{
'ref':rname},[]]]
156 self.
addPosaddPos(subels,
'position', rname+
'pos', rtr)
157 self.
addRotaddRot(subels,
'rotation', rname+
'rot', rrot)
158 self.
addPosaddPos(subels,
'firstposition', lname+
'pos', ltr)
159 self.
addRotaddRot(subels,
'firstrotation', lname+
'rot', lrot)
160 self.
solidssolids[2].append( [
'subtraction',{
'name':name}, subels])
163 subels = [[
'first',{
'ref':lname},[]],
164 [
'second',{
'ref':rname},[]]]
165 self.
addPosaddPos(subels,
'position', rname+
'pos', rtr)
166 self.
addRotaddRot(subels,
'rotation', rname+
'rot', rrot)
167 self.
addPosaddPos(subels,
'firstposition', lname+
'pos', ltr)
168 self.
addRotaddRot(subels,
'firstrotation', lname+
'rot', lrot)
169 self.
solidssolids[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.
structurestructure[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.
structurestructure[2].append([
'assembly',{
'name':volume}, subels])
198 self.
documentdocument[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')
220 writeElement(self.
documentdocument,
'')
def addSubtraction(self, name, lname, ltr, lrot, rname, rtr, rrot)
def addTrd(self, name, x1, x2, y1, y2, z)
def addTrap(self, name, z, theta, phi, y1, x1, x2, alpha1, y2, x3, x4, alpha2)
def addEltube(self, name, x, y, z)
def addMaterial(self, name, a, z, rho)
def addPara(self, name, x, y, z, alpha, theta, phi)
def addIntersection(self, name, lname, ltr, lrot, rname, rtr, rrot)
def addParaboloid(self, name, rlo, rhi, dz)
def addMixture(self, name, rho, elems)
def addSphere(self, name, rmin, rmax, startphi, deltaphi, starttheta, deltatheta)
def addElement(self, symb, name, z, a)
def addPolyhedra(self, name, startphi, deltaphi, numsides, zplanes)
def addTorus(self, name, r, rmin, rmax, startphi, deltaphi)
def addXtrusion(self, name, vertices, sections)
def addTube(self, name, rmin, rmax, z, startphi, deltaphi)
def addPos(self, subels, type, name, v)
def addSetup(self, name, version, world)
def addReflSolid(self, name, solid, dx, dy, dz, sx, sy, sz, rx, ry, rz)
def addPosition(self, name, x, y, z)
def addArb8(self, name, v1x, v1y, v2x, v2y, v3x, v3y, v4x, v4y, v5x, v5y, v6x, v6y, v7x, v7y, v8x, v8y, dz)
def addRotation(self, name, x, y, z)
def addVolume(self, volume, solid, material, daughters)
def addRot(self, subels, type, name, v)
def addAssembly(self, volume, daughters)
def addPolycone(self, name, startphi, deltaphi, zplanes)
def addHype(self, name, rmin, rmax, inst, outst, z)
def addBox(self, name, dx, dy, dz)
def addCutTube(self, name, rmin, rmax, z, startphi, deltaphi, lowX, lowY, lowZ, highX, highY, highZ)
def addUnion(self, name, lname, ltr, lrot, rname, rtr, rrot)
def addTwistedTrap(self, name, z, theta, phi, y1, x1, x2, alpha1, y2, x3, x4, alpha2, twist)
def __init__(self, fname)
def addCone(self, name, z, rmin1, rmin2, rmax1, rmax2, sphi, dphi)