CMS 3D CMS Logo

Functions

geometryDiffVisualization Namespace Reference

Functions

def csc_colors
def draw_disk
def draw_station
def draw_wheel
def dt_colors

Function Documentation

def geometryDiffVisualization::csc_colors (   endcap,
  station,
  ring,
  chamber 
)

Definition at line 10 of file geometryDiffVisualization.py.

00011                                               :
00012     return rgb(0.1, 0.9, 0.)

def geometryDiffVisualization::draw_disk (   geom1,
  geom2,
  endcap,
  station,
  filename,
  length_factor = 1.,
  angle_factor = 100.,
  colors = csc_colors 
)

Definition at line 113 of file geometryDiffVisualization.py.

00114                                                                                                               :
00115     if station == 1: disk_template = load_svg("disk1_template.svg")
00116     if station in (2, 3): disk_template = load_svg("disk23_template.svg")
00117     if endcap == 1 and station == 4: disk_template = load_svg("diskp4_template.svg")
00118     if endcap == 2 and station == 4: disk_template = load_svg("diskm4_template.svg")
00119 
00120     scale_factor = 0.233
00121     
00122     new_boxes = SVG("g")
00123 
00124     for treeindex, svgitem in disk_template:
00125         if isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"] == "fakecenter":
00126             fakecenter = pathtoPath(pathtoPath(svgitem).SVG())
00127             sumx = 0.
00128             sumy = 0.
00129             sum1 = 0.
00130             for i, di in enumerate(fakecenter.d):
00131                 if di[0] in ("M", "L"):
00132                     sumx += di[1]
00133                     sumy += di[2]
00134                     sum1 += 1.
00135             originx = sumx/sum1
00136             originy = sumy/sum1
00137 
00138     for treeindex, svgitem in disk_template:
00139         if isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"][:3] == "ME_":
00140             m = re.match("ME_([0-9]+)_([0-9]+)", svgitem["id"])
00141             if m is None: raise Exception
00142 
00143             ring, chamber = int(m.group(1)), int(m.group(2))
00144             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]
00145             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]
00146             phizdiff = -angle_factor * (geom1.csc[endcap, station, ring, chamber].phiz - geom2.csc[endcap, station, ring, chamber].phiz) * signConventions["CSC", endcap, station, ring, chamber][2]
00147 
00148             svgitem["style"] = "fill:#e1e1e1;fill-opacity:1;stroke:#000000;stroke-width:1.0;stroke-dasharray:1, 1;stroke-dashoffset:0"
00149 
00150             newBox = pathtoPath(svgitem)
00151 
00152             # Inkscape outputs wrong SVG: paths are filled with movetos, rather than linetos; this fixes that
00153             first = True
00154             for i, di in enumerate(newBox.d):
00155                 if not first and di[0] == "m":
00156                     di = list(di)
00157                     di[0] = "l"
00158                     newBox.d[i] = tuple(di)
00159                 first = False
00160 
00161             # convert to absolute coordinates
00162             newBox = pathtoPath(newBox.SVG())
00163 
00164             # find the center of the object
00165             sumx = 0.
00166             sumy = 0.
00167             sum1 = 0.
00168             for i, di in enumerate(newBox.d):
00169                 if di[0] == "L":
00170                     sumx += di[1]
00171                     sumy += di[2]
00172                     sum1 += 1.
00173             centerx = sumx/sum1
00174             centery = sumy/sum1
00175 
00176             phipos = atan2(centery - originy, centerx - originx) - pi/2.
00177             for i, di in enumerate(newBox.d):
00178                 if di[0] in ("M", "L"):
00179                     di = list(di)
00180                     di[1] += cos(phipos)*xdiff - sin(phipos)*ydiff
00181                     di[2] += sin(phipos)*xdiff + cos(phipos)*ydiff
00182                     newBox.d[i] = tuple(di)
00183 
00184             centerx += cos(phipos)*xdiff - sin(phipos)*ydiff
00185             centery += sin(phipos)*xdiff + cos(phipos)*ydiff
00186 
00187             for i, di in enumerate(newBox.d):
00188                 if di[0] in ("M", "L"):
00189                     di = list(di)
00190                     dispx = cos(phizdiff) * (di[1] - centerx) - sin(phizdiff) * (di[2] - centery)
00191                     dispy = sin(phizdiff) * (di[1] - centerx) + cos(phizdiff) * (di[2] - centery)
00192                     di[1] = dispx + centerx
00193                     di[2] = dispy + centery
00194                     newBox.d[i] = tuple(di)
00195 
00196             newBox = newBox.SVG()
00197             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)
00198             newBox["id"] = newBox["id"] + "_moved"
00199 
00200             new_boxes.append(newBox)
00201 
00202     for treeindex, svgitem in disk_template:
00203         if isinstance(svgitem, SVG) and svgitem.t == "g" and "id" in svgitem.attr and svgitem["id"] == "chambers":
00204             svgitem.append(new_boxes)
00205 
00206         elif isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"] == "diskx":
00207             if endcap == 1: svgitem[0] = "Disk %+d" % station
00208             else: svgitem[0] = "Disk %+d" % (-station)
00209             svgitem[0] += " (length x%g, angle x%g)" % (length_factor, angle_factor)
00210 
00211     disk_template.save(filename)
def geometryDiffVisualization::draw_station (   geom1,
  geom2,
  station,
  filename,
  length_factor = 100.,
  angle_factor = 100.,
  colors = dt_colors 
)

Definition at line 13 of file geometryDiffVisualization.py.

00014                                                                                                           :
00015     if station == 4: station_template = load_svg("station4_template.svg")
00016     else: station_template = load_svg("station_template.svg")
00017 
00018     if station == 1: x_scale_factor = 1/6.
00019     if station == 2: x_scale_factor = 1/7.
00020     if station == 3: x_scale_factor = 1/8.5
00021     if station == 4: x_scale_factor = 1/10.
00022     y_scale_factor = 1/7.
00023 
00024     # make a new group to put the moved chambers into
00025     new_boxes = SVG("g")
00026 
00027     # loop over the SVG tree, looking for our chambers (by id)
00028     for treeindex, svgitem in station_template:
00029         if isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"][:3] == "MB_":
00030             m = re.match("MB_([0-9mpz]+)_([0-9]+)", svgitem["id"])
00031             if m is None: raise Exception
00032 
00033             wheel = m.group(1)
00034             if wheel == "m2": wheel = -2
00035             elif wheel == "m1": wheel = -1
00036             elif wheel == "z": wheel = 0
00037             elif wheel == "p1": wheel = 1
00038             elif wheel == "p2": wheel = 2
00039             sector = int(m.group(2))
00040 
00041             xdiff = x_scale_factor * length_factor * (geom1.dt[wheel, station, sector].x - geom2.dt[wheel, station, sector].x) * signConventions["DT", wheel, station, sector][0]
00042             ydiff = -y_scale_factor * length_factor * (geom1.dt[wheel, station, sector].y - geom2.dt[wheel, station, sector].y) * signConventions["DT", wheel, station, sector][1]
00043             phizdiff = -angle_factor * (geom1.dt[wheel, station, sector].phiz - geom2.dt[wheel, station, sector].phiz) * signConventions["DT", wheel, station, sector][2]
00044 
00045             sx = float(svgitem["x"]) + float(svgitem["width"])/2.
00046             sy = float(svgitem["y"]) + float(svgitem["height"])/2.
00047 
00048             svgitem["transform"] = "translate(%g,%g)" % (sx, sy)
00049             svgitem["x"] = -float(svgitem["width"])/2.
00050             svgitem["y"] = -float(svgitem["height"])/2.
00051 
00052             svgitem["style"] = "fill:#e1e1e1;fill-opacity:1;stroke:#000000;stroke-width:1.0;stroke-dasharray:1, 1;stroke-dashoffset:0"
00053 
00054             newBox = svgitem.clone()
00055             newBox["transform"] = "translate(%g,%g) rotate(%g) " % (sx + xdiff, sy + ydiff, phizdiff * 180./pi)
00056             newBox["style"] = "fill:%s;fill-opacity:0.5;stroke:#000000;stroke-width:1.0;stroke-opacity:1;stroke-dasharray:none" % colors(wheel, station, sector)
00057 
00058             new_boxes.append(newBox)
00059             
00060     for treeindex, svgitem in station_template:
00061         if isinstance(svgitem, SVG) and svgitem.t == "g" and "id" in svgitem.attr and svgitem["id"] == "chambers":
00062             svgitem.append(new_boxes)
00063 
00064         elif isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"] == "stationx":
00065             svgitem[0] = "Station %d" % station
00066             svgitem[0] += " (length x%g, angle x%g)" % (length_factor, angle_factor)
00067 
00068     station_template.save(filename)

def geometryDiffVisualization::draw_wheel (   geom1,
  geom2,
  wheel,
  filename,
  length_factor = 100.,
  angle_factor = 100.,
  colors = dt_colors 
)

Definition at line 69 of file geometryDiffVisualization.py.

00070                                                                                                       :
00071     wheel_template = load_svg("wheel_template.svg")
00072 
00073     # make a new group to put the moved chambers into
00074     new_boxes = SVG("g")
00075 
00076     # loop over the SVG tree, looking for our chambers (by id)
00077     for treeindex, svgitem in wheel_template:
00078         if isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"][:3] == "MB_":
00079             m = re.match("MB_([0-9]+)_([0-9]+)", svgitem["id"])
00080             if m is None: raise Exception
00081 
00082             station, sector = int(m.group(1)), int(m.group(2))
00083             xdiff = -length_factor * (geom1.dt[wheel, station, sector].x - geom2.dt[wheel, station, sector].x) * signConventions["DT", wheel, station, sector][0]
00084             zdiff = length_factor * (geom1.dt[wheel, station, sector].z - geom2.dt[wheel, station, sector].z) * signConventions["DT", wheel, station, sector][2]
00085             phiydiff = -angle_factor * (geom1.dt[wheel, station, sector].phiy - geom2.dt[wheel, station, sector].phiy) * signConventions["DT", wheel, station, sector][1]
00086 
00087             m = re.search("translate\(([0-9\.\-\+eE]+),\s([0-9\.\-\+eE]+)\)\srotate\(([0-9\.\-\+eE]+)\)",svgitem["transform"])
00088 
00089             tx = float(m.group(1))
00090             ty = float(m.group(2))
00091             tr = float(m.group(3))
00092 
00093             newBox = svgitem.clone()
00094 
00095             svgitem["style"] = "fill:#e1e1e1;fill-opacity:1;stroke:#000000;stroke-width:5.0;stroke-dasharray:1, 1;stroke-dashoffset:0"
00096             newBox["style"] = "fill:%s;fill-opacity:0.5;stroke:#000000;stroke-width:5.0;stroke-opacity:1;stroke-dasharray:none" % colors(wheel, station, sector)
00097             newBox["id"] = newBox["id"] + "_moved"
00098 
00099             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) 
00100 
00101             new_boxes.append(newBox)
00102 
00103     for treeindex, svgitem in wheel_template:
00104         if isinstance(svgitem, SVG) and svgitem.t == "g" and "id" in svgitem.attr and svgitem["id"] == "chambers":
00105             svgitem.append(new_boxes)
00106 
00107         elif isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"] == "wheelx":
00108             if wheel == 0: svgitem[0] = "Wheel 0"
00109             else: svgitem[0] = "Wheel %+d" % wheel
00110             svgitem[0] += " (length x%g, angle x%g)" % (length_factor, angle_factor)
00111 
00112     wheel_template.save(filename)

def geometryDiffVisualization::dt_colors (   wheel,
  station,
  sector 
)

Definition at line 7 of file geometryDiffVisualization.py.

00008                                      :
00009     return rgb(0.1, 0.9, 0.)