CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 11 of file geometryDiffVisualization.py.

References svgfig.rgb().

11 
12 def csc_colors(endcap, station, ring, chamber):
13  return rgb(0.1, 0.9, 0.)
def rgb
Definition: svgfig.py:40
def geometryDiffVisualization.draw_disk (   geom1,
  geom2,
  endcap,
  station,
  filename,
  length_factor = 1.,
  angle_factor = 100.,
  colors = csc_colors,
  template_dir = './' 
)

Definition at line 116 of file geometryDiffVisualization.py.

References funct.cos(), svgfig.pathtoPath(), and funct.sin().

117 def draw_disk(geom1, geom2, endcap, station, filename, length_factor=1., angle_factor=100., colors=csc_colors, template_dir='./'):
118  if station == 1:
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")
126 
127  scale_factor = 0.233
128 
129  new_boxes = SVG("g")
130 
131  for treeindex, svgitem in disk_template:
132  if isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"] == "fakecenter":
133  fakecenter = pathtoPath(pathtoPath(svgitem).SVG())
134  sumx = 0.
135  sumy = 0.
136  sum1 = 0.
137  for i, di in enumerate(fakecenter.d):
138  if di[0] in ("M", "L"):
139  sumx += di[1]
140  sumy += di[2]
141  sum1 += 1.
142  originx = sumx/sum1
143  originy = sumy/sum1
144 
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
149 
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]
154 
155  svgitem["style"] = "fill:#e1e1e1;fill-opacity:1;stroke:#000000;stroke-width:1.0;stroke-dasharray:1, 1;stroke-dashoffset:0"
156 
157  newBox = pathtoPath(svgitem)
158 
159  # Inkscape outputs wrong SVG: paths are filled with movetos, rather than linetos; this fixes that
160  first = True
161  for i, di in enumerate(newBox.d):
162  if not first and di[0] == "m":
163  di = list(di)
164  di[0] = "l"
165  newBox.d[i] = tuple(di)
166  first = False
167 
168  # convert to absolute coordinates
169  newBox = pathtoPath(newBox.SVG())
170 
171  # find the center of the object
172  sumx = 0.
173  sumy = 0.
174  sum1 = 0.
175  for i, di in enumerate(newBox.d):
176  if di[0] == "L":
177  sumx += di[1]
178  sumy += di[2]
179  sum1 += 1.
180  centerx = sumx/sum1
181  centery = sumy/sum1
182 
183  phipos = atan2(centery - originy, centerx - originx) - pi/2.
184  for i, di in enumerate(newBox.d):
185  if di[0] in ("M", "L"):
186  di = list(di)
187  di[1] += cos(phipos)*xdiff - sin(phipos)*ydiff
188  di[2] += sin(phipos)*xdiff + cos(phipos)*ydiff
189  newBox.d[i] = tuple(di)
190 
191  centerx += cos(phipos)*xdiff - sin(phipos)*ydiff
192  centery += sin(phipos)*xdiff + cos(phipos)*ydiff
193 
194  for i, di in enumerate(newBox.d):
195  if di[0] in ("M", "L"):
196  di = list(di)
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)
202 
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"
206 
207  new_boxes.append(newBox)
208 
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)
212 
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)
217 
218  disk_template.save(filename)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
def pathtoPath
Definition: svgfig.py:1007
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Definition: colors.py:1
def geometryDiffVisualization.draw_station (   geom1,
  geom2,
  station,
  filename,
  length_factor = 100.,
  angle_factor = 100.,
  colors = dt_colors,
  template_dir = './' 
)

Definition at line 14 of file geometryDiffVisualization.py.

14 
15 def draw_station(geom1, geom2, station, filename, length_factor=100., angle_factor=100., colors=dt_colors, template_dir='./'):
16  if station == 4:
17  station_template = load_svg(template_dir + "station4_template.svg")
18  else:
19  station_template = load_svg(template_dir + "station_template.svg")
20 
21  if station == 1: x_scale_factor = 1/6.
22  if station == 2: x_scale_factor = 1/7.
23  if station == 3: x_scale_factor = 1/8.5
24  if station == 4: x_scale_factor = 1/10.
25  y_scale_factor = 1/7.
26 
27  # make a new group to put the moved chambers into
28  new_boxes = SVG("g")
29 
30  # loop over the SVG tree, looking for our chambers (by id)
31  for treeindex, svgitem in station_template:
32  if isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"][:3] == "MB_":
33  m = re.match("MB_([0-9mpz]+)_([0-9]+)", svgitem["id"])
34  if m is None: raise Exception
35 
36  wheel = m.group(1)
37  if wheel == "m2": wheel = -2
38  elif wheel == "m1": wheel = -1
39  elif wheel == "z": wheel = 0
40  elif wheel == "p1": wheel = 1
41  elif wheel == "p2": wheel = 2
42  sector = int(m.group(2))
43 
44  xdiff = x_scale_factor * length_factor * (geom1.dt[wheel, station, sector].x - geom2.dt[wheel, station, sector].x) * signConventions["DT", wheel, station, sector][0]
45  ydiff = -y_scale_factor * length_factor * (geom1.dt[wheel, station, sector].y - geom2.dt[wheel, station, sector].y) * signConventions["DT", wheel, station, sector][1]
46  phizdiff = -angle_factor * (geom1.dt[wheel, station, sector].phiz - geom2.dt[wheel, station, sector].phiz) * signConventions["DT", wheel, station, sector][2]
47 
48  sx = float(svgitem["x"]) + float(svgitem["width"])/2.
49  sy = float(svgitem["y"]) + float(svgitem["height"])/2.
50 
51  svgitem["transform"] = "translate(%g,%g)" % (sx, sy)
52  svgitem["x"] = -float(svgitem["width"])/2.
53  svgitem["y"] = -float(svgitem["height"])/2.
54 
55  svgitem["style"] = "fill:#e1e1e1;fill-opacity:1;stroke:#000000;stroke-width:1.0;stroke-dasharray:1, 1;stroke-dashoffset:0"
56 
57  newBox = svgitem.clone()
58  newBox["transform"] = "translate(%g,%g) rotate(%g) " % (sx + xdiff, sy + ydiff, phizdiff * 180./pi)
59  newBox["style"] = "fill:%s;fill-opacity:0.5;stroke:#000000;stroke-width:1.0;stroke-opacity:1;stroke-dasharray:none" % colors(wheel, station, sector)
60 
61  new_boxes.append(newBox)
62 
63  for treeindex, svgitem in station_template:
64  if isinstance(svgitem, SVG) and svgitem.t == "g" and "id" in svgitem.attr and svgitem["id"] == "chambers":
65  svgitem.append(new_boxes)
66 
67  elif isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"] == "stationx":
68  svgitem[0] = "Station %d" % station
69  svgitem[0] += " (length x%g, angle x%g)" % (length_factor, angle_factor)
70 
71  station_template.save(filename)
Definition: colors.py:1
def geometryDiffVisualization.draw_wheel (   geom1,
  geom2,
  wheel,
  filename,
  length_factor = 100.,
  angle_factor = 100.,
  colors = dt_colors,
  template_dir = './' 
)

Definition at line 72 of file geometryDiffVisualization.py.

References funct.cos(), and funct.sin().

72 
73 def draw_wheel(geom1, geom2, wheel, filename, length_factor=100., angle_factor=100., colors=dt_colors, template_dir='./'):
74  wheel_template = load_svg(template_dir + "wheel_template.svg")
75 
76  # make a new group to put the moved chambers into
77  new_boxes = SVG("g")
78 
79  # loop over the SVG tree, looking for our chambers (by id)
80  for treeindex, svgitem in wheel_template:
81  if isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"][:3] == "MB_":
82  m = re.match("MB_([0-9]+)_([0-9]+)", svgitem["id"])
83  if m is None: raise Exception
84 
85  station, sector = int(m.group(1)), int(m.group(2))
86  xdiff = -length_factor * (geom1.dt[wheel, station, sector].x - geom2.dt[wheel, station, sector].x) * signConventions["DT", wheel, station, sector][0]
87  zdiff = length_factor * (geom1.dt[wheel, station, sector].z - geom2.dt[wheel, station, sector].z) * signConventions["DT", wheel, station, sector][2]
88  phiydiff = -angle_factor * (geom1.dt[wheel, station, sector].phiy - geom2.dt[wheel, station, sector].phiy) * signConventions["DT", wheel, station, sector][1]
89 
90  m = re.search("translate\(([0-9\.\-\+eE]+),\s([0-9\.\-\+eE]+)\)\srotate\(([0-9\.\-\+eE]+)\)",svgitem["transform"])
91 
92  tx = float(m.group(1))
93  ty = float(m.group(2))
94  tr = float(m.group(3))
95 
96  newBox = svgitem.clone()
97 
98  svgitem["style"] = "fill:#e1e1e1;fill-opacity:1;stroke:#000000;stroke-width:5.0;stroke-dasharray:1, 1;stroke-dashoffset:0"
99  newBox["style"] = "fill:%s;fill-opacity:0.5;stroke:#000000;stroke-width:5.0;stroke-opacity:1;stroke-dasharray:none" % colors(wheel, station, sector)
100  newBox["id"] = newBox["id"] + "_moved"
101 
102  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)
103 
104  new_boxes.append(newBox)
105 
106  for treeindex, svgitem in wheel_template:
107  if isinstance(svgitem, SVG) and svgitem.t == "g" and "id" in svgitem.attr and svgitem["id"] == "chambers":
108  svgitem.append(new_boxes)
109 
110  elif isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"] == "wheelx":
111  if wheel == 0: svgitem[0] = "Wheel 0"
112  else: svgitem[0] = "Wheel %+d" % wheel
113  svgitem[0] += " (length x%g, angle x%g)" % (length_factor, angle_factor)
114 
115  wheel_template.save(filename)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Definition: colors.py:1
def geometryDiffVisualization.dt_colors (   wheel,
  station,
  sector 
)

Definition at line 8 of file geometryDiffVisualization.py.

References svgfig.rgb().

8 
9 def dt_colors(wheel, station, sector):
10  return rgb(0.1, 0.9, 0.)
def rgb
Definition: svgfig.py:40