CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
geometryDiffVisualization.py
Go to the documentation of this file.
1 import re
2 from math import *
3 from svgfig import rgb, SVG, pathtoPath, load as load_svg
4 from geometryXMLparser import *
5 from signConventions import *
6 
7 def dt_colors(wheel, station, sector):
8  return rgb(0.1, 0.9, 0.)
9 
10 def csc_colors(endcap, station, ring, chamber):
11  return rgb(0.1, 0.9, 0.)
12 
13 def draw_station(geom1, geom2, station, filename, length_factor=100., angle_factor=100., colors=dt_colors):
14  if station == 4: station_template = load_svg("station4_template.svg")
15  else: station_template = load_svg("station_template.svg")
16 
17  if station == 1: x_scale_factor = 1/6.
18  if station == 2: x_scale_factor = 1/7.
19  if station == 3: x_scale_factor = 1/8.5
20  if station == 4: x_scale_factor = 1/10.
21  y_scale_factor = 1/7.
22 
23  # make a new group to put the moved chambers into
24  new_boxes = SVG("g")
25 
26  # loop over the SVG tree, looking for our chambers (by id)
27  for treeindex, svgitem in station_template:
28  if isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"][:3] == "MB_":
29  m = re.match("MB_([0-9mpz]+)_([0-9]+)", svgitem["id"])
30  if m is None: raise Exception
31 
32  wheel = m.group(1)
33  if wheel == "m2": wheel = -2
34  elif wheel == "m1": wheel = -1
35  elif wheel == "z": wheel = 0
36  elif wheel == "p1": wheel = 1
37  elif wheel == "p2": wheel = 2
38  sector = int(m.group(2))
39 
40  xdiff = x_scale_factor * length_factor * (geom1.dt[wheel, station, sector].x - geom2.dt[wheel, station, sector].x) * signConventions["DT", wheel, station, sector][0]
41  ydiff = -y_scale_factor * length_factor * (geom1.dt[wheel, station, sector].y - geom2.dt[wheel, station, sector].y) * signConventions["DT", wheel, station, sector][1]
42  phizdiff = -angle_factor * (geom1.dt[wheel, station, sector].phiz - geom2.dt[wheel, station, sector].phiz) * signConventions["DT", wheel, station, sector][2]
43 
44  sx = float(svgitem["x"]) + float(svgitem["width"])/2.
45  sy = float(svgitem["y"]) + float(svgitem["height"])/2.
46 
47  svgitem["transform"] = "translate(%g,%g)" % (sx, sy)
48  svgitem["x"] = -float(svgitem["width"])/2.
49  svgitem["y"] = -float(svgitem["height"])/2.
50 
51  svgitem["style"] = "fill:#e1e1e1;fill-opacity:1;stroke:#000000;stroke-width:1.0;stroke-dasharray:1, 1;stroke-dashoffset:0"
52 
53  newBox = svgitem.clone()
54  newBox["transform"] = "translate(%g,%g) rotate(%g) " % (sx + xdiff, sy + ydiff, phizdiff * 180./pi)
55  newBox["style"] = "fill:%s;fill-opacity:0.5;stroke:#000000;stroke-width:1.0;stroke-opacity:1;stroke-dasharray:none" % colors(wheel, station, sector)
56 
57  new_boxes.append(newBox)
58 
59  for treeindex, svgitem in station_template:
60  if isinstance(svgitem, SVG) and svgitem.t == "g" and "id" in svgitem.attr and svgitem["id"] == "chambers":
61  svgitem.append(new_boxes)
62 
63  elif isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"] == "stationx":
64  svgitem[0] = "Station %d" % station
65  svgitem[0] += " (length x%g, angle x%g)" % (length_factor, angle_factor)
66 
67  station_template.save(filename)
68 
69 def draw_wheel(geom1, geom2, wheel, filename, length_factor=100., angle_factor=100., colors=dt_colors):
70  wheel_template = load_svg("wheel_template.svg")
71 
72  # make a new group to put the moved chambers into
73  new_boxes = SVG("g")
74 
75  # loop over the SVG tree, looking for our chambers (by id)
76  for treeindex, svgitem in wheel_template:
77  if isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"][:3] == "MB_":
78  m = re.match("MB_([0-9]+)_([0-9]+)", svgitem["id"])
79  if m is None: raise Exception
80 
81  station, sector = int(m.group(1)), int(m.group(2))
82  xdiff = -length_factor * (geom1.dt[wheel, station, sector].x - geom2.dt[wheel, station, sector].x) * signConventions["DT", wheel, station, sector][0]
83  zdiff = length_factor * (geom1.dt[wheel, station, sector].z - geom2.dt[wheel, station, sector].z) * signConventions["DT", wheel, station, sector][2]
84  phiydiff = -angle_factor * (geom1.dt[wheel, station, sector].phiy - geom2.dt[wheel, station, sector].phiy) * signConventions["DT", wheel, station, sector][1]
85 
86  m = re.search("translate\(([0-9\.\-\+eE]+),\s([0-9\.\-\+eE]+)\)\srotate\(([0-9\.\-\+eE]+)\)",svgitem["transform"])
87 
88  tx = float(m.group(1))
89  ty = float(m.group(2))
90  tr = float(m.group(3))
91 
92  newBox = svgitem.clone()
93 
94  svgitem["style"] = "fill:#e1e1e1;fill-opacity:1;stroke:#000000;stroke-width:5.0;stroke-dasharray:1, 1;stroke-dashoffset:0"
95  newBox["style"] = "fill:%s;fill-opacity:0.5;stroke:#000000;stroke-width:5.0;stroke-opacity:1;stroke-dasharray:none" % colors(wheel, station, sector)
96  newBox["id"] = newBox["id"] + "_moved"
97 
98  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)
99 
100  new_boxes.append(newBox)
101 
102  for treeindex, svgitem in wheel_template:
103  if isinstance(svgitem, SVG) and svgitem.t == "g" and "id" in svgitem.attr and svgitem["id"] == "chambers":
104  svgitem.append(new_boxes)
105 
106  elif isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"] == "wheelx":
107  if wheel == 0: svgitem[0] = "Wheel 0"
108  else: svgitem[0] = "Wheel %+d" % wheel
109  svgitem[0] += " (length x%g, angle x%g)" % (length_factor, angle_factor)
110 
111  wheel_template.save(filename)
112 
113 def draw_disk(geom1, geom2, endcap, station, filename, length_factor=1., angle_factor=100., colors=csc_colors):
114  if station == 1: disk_template = load_svg("disk1_template.svg")
115  if station in (2, 3): disk_template = load_svg("disk23_template.svg")
116  if endcap == 1 and station == 4: disk_template = load_svg("diskp4_template.svg")
117  if endcap == 2 and station == 4: disk_template = load_svg("diskm4_template.svg")
118 
119  scale_factor = 0.233
120 
121  new_boxes = SVG("g")
122 
123  for treeindex, svgitem in disk_template:
124  if isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"] == "fakecenter":
125  fakecenter = pathtoPath(pathtoPath(svgitem).SVG())
126  sumx = 0.
127  sumy = 0.
128  sum1 = 0.
129  for i, di in enumerate(fakecenter.d):
130  if di[0] in ("M", "L"):
131  sumx += di[1]
132  sumy += di[2]
133  sum1 += 1.
134  originx = sumx/sum1
135  originy = sumy/sum1
136 
137  for treeindex, svgitem in disk_template:
138  if isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"][:3] == "ME_":
139  m = re.match("ME_([0-9]+)_([0-9]+)", svgitem["id"])
140  if m is None: raise Exception
141 
142  ring, chamber = int(m.group(1)), int(m.group(2))
143  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]
144  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]
145  phizdiff = -angle_factor * (geom1.csc[endcap, station, ring, chamber].phiz - geom2.csc[endcap, station, ring, chamber].phiz) * signConventions["CSC", endcap, station, ring, chamber][2]
146 
147  svgitem["style"] = "fill:#e1e1e1;fill-opacity:1;stroke:#000000;stroke-width:1.0;stroke-dasharray:1, 1;stroke-dashoffset:0"
148 
149  newBox = pathtoPath(svgitem)
150 
151  # Inkscape outputs wrong SVG: paths are filled with movetos, rather than linetos; this fixes that
152  first = True
153  for i, di in enumerate(newBox.d):
154  if not first and di[0] == "m":
155  di = list(di)
156  di[0] = "l"
157  newBox.d[i] = tuple(di)
158  first = False
159 
160  # convert to absolute coordinates
161  newBox = pathtoPath(newBox.SVG())
162 
163  # find the center of the object
164  sumx = 0.
165  sumy = 0.
166  sum1 = 0.
167  for i, di in enumerate(newBox.d):
168  if di[0] == "L":
169  sumx += di[1]
170  sumy += di[2]
171  sum1 += 1.
172  centerx = sumx/sum1
173  centery = sumy/sum1
174 
175  phipos = atan2(centery - originy, centerx - originx) - pi/2.
176  for i, di in enumerate(newBox.d):
177  if di[0] in ("M", "L"):
178  di = list(di)
179  di[1] += cos(phipos)*xdiff - sin(phipos)*ydiff
180  di[2] += sin(phipos)*xdiff + cos(phipos)*ydiff
181  newBox.d[i] = tuple(di)
182 
183  centerx += cos(phipos)*xdiff - sin(phipos)*ydiff
184  centery += sin(phipos)*xdiff + cos(phipos)*ydiff
185 
186  for i, di in enumerate(newBox.d):
187  if di[0] in ("M", "L"):
188  di = list(di)
189  dispx = cos(phizdiff) * (di[1] - centerx) - sin(phizdiff) * (di[2] - centery)
190  dispy = sin(phizdiff) * (di[1] - centerx) + cos(phizdiff) * (di[2] - centery)
191  di[1] = dispx + centerx
192  di[2] = dispy + centery
193  newBox.d[i] = tuple(di)
194 
195  newBox = newBox.SVG()
196  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)
197  newBox["id"] = newBox["id"] + "_moved"
198 
199  new_boxes.append(newBox)
200 
201  for treeindex, svgitem in disk_template:
202  if isinstance(svgitem, SVG) and svgitem.t == "g" and "id" in svgitem.attr and svgitem["id"] == "chambers":
203  svgitem.append(new_boxes)
204 
205  elif isinstance(svgitem, SVG) and "id" in svgitem.attr and svgitem["id"] == "diskx":
206  if endcap == 1: svgitem[0] = "Disk %+d" % station
207  else: svgitem[0] = "Disk %+d" % (-station)
208  svgitem[0] += " (length x%g, angle x%g)" % (length_factor, angle_factor)
209 
210  disk_template.save(filename)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< Color_t > colors
Definition: eve_filter.cc:26
def rgb
Definition: svgfig.py:39
def pathtoPath
Definition: svgfig.py:1006
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run