Functions | |
def | csc_colors |
def | draw_disk |
def | draw_station |
def | draw_wheel |
def | dt_colors |
def geometryDiffVisualization::csc_colors | ( | endcap, | |
station, | |||
ring, | |||
chamber | |||
) |
Definition at line 10 of file geometryDiffVisualization.py.
def geometryDiffVisualization::draw_disk | ( | geom1, | |
geom2, | |||
endcap, | |||
station, | |||
filename, | |||
length_factor = 1. , |
|||
angle_factor = 100. , |
|||
colors = csc_colors , |
|||
template_dir = './' |
|||
) |
Definition at line 115 of file geometryDiffVisualization.py.
00116 : 00117 if station == 1: 00118 disk_template = load_svg(template_dir + "disk1_template.svg") 00119 if station in (2, 3): 00120 disk_template = load_svg(template_dir + "disk23_template.svg") 00121 if endcap == 1 and station == 4: 00122 disk_template = load_svg(template_dir + "diskp4_template.svg") 00123 if endcap == 2 and station == 4: 00124 disk_template = load_svg(template_dir + "diskm4_template.svg") 00125 00126 scale_factor = 0.233 00127 00128 new_boxes = SVG("g") 00129 00130 for treeindex, svgitem in disk_template: 00131 if isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"] == "fakecenter": 00132 fakecenter = pathtoPath(pathtoPath(svgitem).SVG()) 00133 sumx = 0. 00134 sumy = 0. 00135 sum1 = 0. 00136 for i, di in enumerate(fakecenter.d): 00137 if di[0] in ("M", "L"): 00138 sumx += di[1] 00139 sumy += di[2] 00140 sum1 += 1. 00141 originx = sumx/sum1 00142 originy = sumy/sum1 00143 00144 for treeindex, svgitem in disk_template: 00145 if isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"][:3] == "ME_": 00146 m = re.match("ME_([0-9]+)_([0-9]+)", svgitem["id"]) 00147 if m is None: raise Exception 00148 00149 ring, chamber = int(m.group(1)), int(m.group(2)) 00150 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] 00151 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] 00152 phizdiff = -angle_factor * (geom1.csc[endcap, station, ring, chamber].phiz - geom2.csc[endcap, station, ring, chamber].phiz) * signConventions["CSC", endcap, station, ring, chamber][2] 00153 00154 svgitem["style"] = "fill:#e1e1e1;fill-opacity:1;stroke:#000000;stroke-width:1.0;stroke-dasharray:1, 1;stroke-dashoffset:0" 00155 00156 newBox = pathtoPath(svgitem) 00157 00158 # Inkscape outputs wrong SVG: paths are filled with movetos, rather than linetos; this fixes that 00159 first = True 00160 for i, di in enumerate(newBox.d): 00161 if not first and di[0] == "m": 00162 di = list(di) 00163 di[0] = "l" 00164 newBox.d[i] = tuple(di) 00165 first = False 00166 00167 # convert to absolute coordinates 00168 newBox = pathtoPath(newBox.SVG()) 00169 00170 # find the center of the object 00171 sumx = 0. 00172 sumy = 0. 00173 sum1 = 0. 00174 for i, di in enumerate(newBox.d): 00175 if di[0] == "L": 00176 sumx += di[1] 00177 sumy += di[2] 00178 sum1 += 1. 00179 centerx = sumx/sum1 00180 centery = sumy/sum1 00181 00182 phipos = atan2(centery - originy, centerx - originx) - pi/2. 00183 for i, di in enumerate(newBox.d): 00184 if di[0] in ("M", "L"): 00185 di = list(di) 00186 di[1] += cos(phipos)*xdiff - sin(phipos)*ydiff 00187 di[2] += sin(phipos)*xdiff + cos(phipos)*ydiff 00188 newBox.d[i] = tuple(di) 00189 00190 centerx += cos(phipos)*xdiff - sin(phipos)*ydiff 00191 centery += sin(phipos)*xdiff + cos(phipos)*ydiff 00192 00193 for i, di in enumerate(newBox.d): 00194 if di[0] in ("M", "L"): 00195 di = list(di) 00196 dispx = cos(phizdiff) * (di[1] - centerx) - sin(phizdiff) * (di[2] - centery) 00197 dispy = sin(phizdiff) * (di[1] - centerx) + cos(phizdiff) * (di[2] - centery) 00198 di[1] = dispx + centerx 00199 di[2] = dispy + centery 00200 newBox.d[i] = tuple(di) 00201 00202 newBox = newBox.SVG() 00203 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) 00204 newBox["id"] = newBox["id"] + "_moved" 00205 00206 new_boxes.append(newBox) 00207 00208 for treeindex, svgitem in disk_template: 00209 if isinstance(svgitem, SVG) and svgitem.t == "g" and "id" in svgitem.attr and svgitem["id"] == "chambers": 00210 svgitem.append(new_boxes) 00211 00212 elif isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"] == "diskx": 00213 if endcap == 1: svgitem[0] = "Disk %+d" % station 00214 else: svgitem[0] = "Disk %+d" % (-station) 00215 svgitem[0] += " (length x%g, angle x%g)" % (length_factor, angle_factor) 00216 00217 disk_template.save(filename)
def geometryDiffVisualization::draw_station | ( | geom1, | |
geom2, | |||
station, | |||
filename, | |||
length_factor = 100. , |
|||
angle_factor = 100. , |
|||
colors = dt_colors , |
|||
template_dir = './' |
|||
) |
Definition at line 13 of file geometryDiffVisualization.py.
00014 : 00015 if station == 4: 00016 station_template = load_svg(template_dir + "station4_template.svg") 00017 else: 00018 station_template = load_svg(template_dir + "station_template.svg") 00019 00020 if station == 1: x_scale_factor = 1/6. 00021 if station == 2: x_scale_factor = 1/7. 00022 if station == 3: x_scale_factor = 1/8.5 00023 if station == 4: x_scale_factor = 1/10. 00024 y_scale_factor = 1/7. 00025 00026 # make a new group to put the moved chambers into 00027 new_boxes = SVG("g") 00028 00029 # loop over the SVG tree, looking for our chambers (by id) 00030 for treeindex, svgitem in station_template: 00031 if isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"][:3] == "MB_": 00032 m = re.match("MB_([0-9mpz]+)_([0-9]+)", svgitem["id"]) 00033 if m is None: raise Exception 00034 00035 wheel = m.group(1) 00036 if wheel == "m2": wheel = -2 00037 elif wheel == "m1": wheel = -1 00038 elif wheel == "z": wheel = 0 00039 elif wheel == "p1": wheel = 1 00040 elif wheel == "p2": wheel = 2 00041 sector = int(m.group(2)) 00042 00043 xdiff = x_scale_factor * length_factor * (geom1.dt[wheel, station, sector].x - geom2.dt[wheel, station, sector].x) * signConventions["DT", wheel, station, sector][0] 00044 ydiff = -y_scale_factor * length_factor * (geom1.dt[wheel, station, sector].y - geom2.dt[wheel, station, sector].y) * signConventions["DT", wheel, station, sector][1] 00045 phizdiff = -angle_factor * (geom1.dt[wheel, station, sector].phiz - geom2.dt[wheel, station, sector].phiz) * signConventions["DT", wheel, station, sector][2] 00046 00047 sx = float(svgitem["x"]) + float(svgitem["width"])/2. 00048 sy = float(svgitem["y"]) + float(svgitem["height"])/2. 00049 00050 svgitem["transform"] = "translate(%g,%g)" % (sx, sy) 00051 svgitem["x"] = -float(svgitem["width"])/2. 00052 svgitem["y"] = -float(svgitem["height"])/2. 00053 00054 svgitem["style"] = "fill:#e1e1e1;fill-opacity:1;stroke:#000000;stroke-width:1.0;stroke-dasharray:1, 1;stroke-dashoffset:0" 00055 00056 newBox = svgitem.clone() 00057 newBox["transform"] = "translate(%g,%g) rotate(%g) " % (sx + xdiff, sy + ydiff, phizdiff * 180./pi) 00058 newBox["style"] = "fill:%s;fill-opacity:0.5;stroke:#000000;stroke-width:1.0;stroke-opacity:1;stroke-dasharray:none" % colors(wheel, station, sector) 00059 00060 new_boxes.append(newBox) 00061 00062 for treeindex, svgitem in station_template: 00063 if isinstance(svgitem, SVG) and svgitem.t == "g" and "id" in svgitem.attr and svgitem["id"] == "chambers": 00064 svgitem.append(new_boxes) 00065 00066 elif isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"] == "stationx": 00067 svgitem[0] = "Station %d" % station 00068 svgitem[0] += " (length x%g, angle x%g)" % (length_factor, angle_factor) 00069 00070 station_template.save(filename)
def geometryDiffVisualization::draw_wheel | ( | geom1, | |
geom2, | |||
wheel, | |||
filename, | |||
length_factor = 100. , |
|||
angle_factor = 100. , |
|||
colors = dt_colors , |
|||
template_dir = './' |
|||
) |
Definition at line 71 of file geometryDiffVisualization.py.
00072 : 00073 wheel_template = load_svg(template_dir + "wheel_template.svg") 00074 00075 # make a new group to put the moved chambers into 00076 new_boxes = SVG("g") 00077 00078 # loop over the SVG tree, looking for our chambers (by id) 00079 for treeindex, svgitem in wheel_template: 00080 if isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"][:3] == "MB_": 00081 m = re.match("MB_([0-9]+)_([0-9]+)", svgitem["id"]) 00082 if m is None: raise Exception 00083 00084 station, sector = int(m.group(1)), int(m.group(2)) 00085 xdiff = -length_factor * (geom1.dt[wheel, station, sector].x - geom2.dt[wheel, station, sector].x) * signConventions["DT", wheel, station, sector][0] 00086 zdiff = length_factor * (geom1.dt[wheel, station, sector].z - geom2.dt[wheel, station, sector].z) * signConventions["DT", wheel, station, sector][2] 00087 phiydiff = -angle_factor * (geom1.dt[wheel, station, sector].phiy - geom2.dt[wheel, station, sector].phiy) * signConventions["DT", wheel, station, sector][1] 00088 00089 m = re.search("translate\(([0-9\.\-\+eE]+),\s([0-9\.\-\+eE]+)\)\srotate\(([0-9\.\-\+eE]+)\)",svgitem["transform"]) 00090 00091 tx = float(m.group(1)) 00092 ty = float(m.group(2)) 00093 tr = float(m.group(3)) 00094 00095 newBox = svgitem.clone() 00096 00097 svgitem["style"] = "fill:#e1e1e1;fill-opacity:1;stroke:#000000;stroke-width:5.0;stroke-dasharray:1, 1;stroke-dashoffset:0" 00098 newBox["style"] = "fill:%s;fill-opacity:0.5;stroke:#000000;stroke-width:5.0;stroke-opacity:1;stroke-dasharray:none" % colors(wheel, station, sector) 00099 newBox["id"] = newBox["id"] + "_moved" 00100 00101 newBox["transform"] = "translate(%g,%g) rotate(%g)" % (tx - xdiff*cos(tr*pi/180.) + zdiff*sin(tr*pi/180.), ty - xdiff*sin(tr*pi/180.) - zdiff*cos(tr*pi/180.), tr - phiydiff*180./pi) 00102 00103 new_boxes.append(newBox) 00104 00105 for treeindex, svgitem in wheel_template: 00106 if isinstance(svgitem, SVG) and svgitem.t == "g" and "id" in svgitem.attr and svgitem["id"] == "chambers": 00107 svgitem.append(new_boxes) 00108 00109 elif isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"] == "wheelx": 00110 if wheel == 0: svgitem[0] = "Wheel 0" 00111 else: svgitem[0] = "Wheel %+d" % wheel 00112 svgitem[0] += " (length x%g, angle x%g)" % (length_factor, angle_factor) 00113 00114 wheel_template.save(filename)
def geometryDiffVisualization::dt_colors | ( | wheel, | |
station, | |||
sector | |||
) |
Definition at line 7 of file geometryDiffVisualization.py.