117 def draw_disk(geom1, geom2, endcap, station, filename, length_factor=1., angle_factor=100., colors=csc_colors, template_dir='./'):
119 disk_template = load_svg(template_dir +
"disk1_template.svg")
120 if station
in (2, 3):
121 disk_template = load_svg(template_dir +
"disk23_template.svg")
122 if endcap == 1
and station == 4:
123 disk_template = load_svg(template_dir +
"diskp4_template.svg")
124 if endcap == 2
and station == 4:
125 disk_template = load_svg(template_dir +
"diskm4_template.svg")
131 for treeindex, svgitem
in disk_template:
132 if isinstance(svgitem, SVG)
and "id" in svgitem.attr
and svgitem[
"id"] ==
"fakecenter":
137 for i, di
in enumerate(fakecenter.d):
138 if di[0]
in (
"M",
"L"):
145 for treeindex, svgitem
in disk_template:
146 if isinstance(svgitem, SVG)
and "id" in svgitem.attr
and svgitem[
"id"][:3] ==
"ME_":
147 m = re.match(
"ME_([0-9]+)_([0-9]+)", svgitem[
"id"])
148 if m
is None:
raise Exception
150 ring, chamber = int(m.group(1)), int(m.group(2))
151 xdiff = scale_factor * length_factor * (geom1.csc[endcap, station, ring, chamber].x - geom2.csc[endcap, station, ring, chamber].x) * signConventions[
"CSC", endcap, station, ring, chamber][0]
152 ydiff = -scale_factor * length_factor * (geom1.csc[endcap, station, ring, chamber].y - geom2.csc[endcap, station, ring, chamber].y) * signConventions[
"CSC", endcap, station, ring, chamber][1]
153 phizdiff = -angle_factor * (geom1.csc[endcap, station, ring, chamber].phiz - geom2.csc[endcap, station, ring, chamber].phiz) * signConventions[
"CSC", endcap, station, ring, chamber][2]
155 svgitem[
"style"] =
"fill:#e1e1e1;fill-opacity:1;stroke:#000000;stroke-width:1.0;stroke-dasharray:1, 1;stroke-dashoffset:0"
161 for i, di
in enumerate(newBox.d):
162 if not first
and di[0] ==
"m":
165 newBox.d[i] = tuple(di)
175 for i, di
in enumerate(newBox.d):
183 phipos = atan2(centery - originy, centerx - originx) - pi/2.
184 for i, di
in enumerate(newBox.d):
185 if di[0]
in (
"M",
"L"):
187 di[1] +=
cos(phipos)*xdiff -
sin(phipos)*ydiff
188 di[2] +=
sin(phipos)*xdiff +
cos(phipos)*ydiff
189 newBox.d[i] = tuple(di)
191 centerx +=
cos(phipos)*xdiff -
sin(phipos)*ydiff
192 centery +=
sin(phipos)*xdiff +
cos(phipos)*ydiff
194 for i, di
in enumerate(newBox.d):
195 if di[0]
in (
"M",
"L"):
197 dispx =
cos(phizdiff) * (di[1] - centerx) -
sin(phizdiff) * (di[2] - centery)
198 dispy =
sin(phizdiff) * (di[1] - centerx) +
cos(phizdiff) * (di[2] - centery)
199 di[1] = dispx + centerx
200 di[2] = dispy + centery
201 newBox.d[i] = tuple(di)
203 newBox = newBox.SVG()
204 newBox[
"style"] =
"fill:%s;fill-opacity:0.5;stroke:#000000;stroke-width:1.0;stroke-opacity:1;stroke-dasharray:none" %
colors(endcap, station, ring, chamber)
205 newBox[
"id"] = newBox[
"id"] +
"_moved"
207 new_boxes.append(newBox)
209 for treeindex, svgitem
in disk_template:
210 if isinstance(svgitem, SVG)
and svgitem.t ==
"g" and "id" in svgitem.attr
and svgitem[
"id"] ==
"chambers":
211 svgitem.append(new_boxes)
213 elif isinstance(svgitem, SVG)
and "id" in svgitem.attr
and svgitem[
"id"] ==
"diskx":
214 if endcap == 1: svgitem[0] =
"Disk %+d" % station
215 else: svgitem[0] =
"Disk %+d" % (-station)
216 svgitem[0] +=
" (length x%g, angle x%g)" % (length_factor, angle_factor)
218 disk_template.save(filename)
Sin< T >::type sin(const T &t)
Cos< T >::type cos(const T &t)