6 from ROOT
import gSystem
8 gSystem.Load(
'libtracking_trackFindingCDC')
10 from ROOT
import Belle2
16 Helper class to generated the svg image from the various tracking objects.
17 This is a tiny wrapper around the TrackFindingCDC.EventDataPlotter.
23 @param animate switch indicating if an animated SVG should be generated
45 Make a copy of the current status of the plotter.
53 Transfer the styling information to the attribute map
57 for key, value
in list(styling.items()):
58 attribute_map[str(key)] = str(value)
64 Draw the CDC superlayer boundaries
71 Draw the interaction point
77 Draw the CDC outer wall
84 Draw the CDC inner wall
91 """Mapping function to unpack the attributes from the attribute maps. Mechanism and interface inspired by d3.js"""
93 for (key, value)
in list(styling.items()):
94 if isinstance(value, collections.Callable):
95 result[key] = value(i_obj, obj)
96 elif isinstance(value, str):
98 elif hasattr(value,
'__getitem__'):
99 result[key] = value[i_obj % len(value)]
106 Draw one or more items with the specified styling
110 for (i_obj, obj)
in enumerate(iterable):
112 draw(obj, **obj_styling)
116 Draw information in a vector from the DataStore with the specified styling
118 print(
'Drawing vector from DataStore:', storeobj_name, end=
' ')
124 wrapped_vector = pystoreobj.obj()
125 vector = wrapped_vector.get()
127 print(
'with', vector.size(),
'entries')
128 print(
'Attributes are')
129 for (key, value)
in list(styling.items()):
130 print(str(key),
':', str(value))
135 print(
"### not present in the DataStore")
136 print(
"Current content of the DataStore")
137 print(
"StoreArrays:")
139 print(
"StoreObjPtr:")
144 Draw information from a StoreArray with the specified styling
146 print(
'Drawing StoreArray:', storearray_name, end=
' ')
150 print(
'with', storearray.getEntries(),
'entries')
151 print(
'Attributes are')
152 for (key, value)
in list(styling.items()):
153 print(str(key),
':', str(value))
158 print(
"### not present in the DataStore")
159 print(
"Current content of the DataStore")
160 print(
"StoreArrays:")
162 print(
"StoreObjPtr:")
165 def draw(self, obj, **styling):
167 Draw an object with the specified styling
174 Save the current dom object representation to disk.
179 boundingBox = eventdata_plotter.getBoundingBox()
181 height = boundingBox.getHeight()
182 width = boundingBox.getWidth()
184 totalPoints = 1120 * 1120
185 svgHeight = round(math.sqrt(totalPoints * float(height) / width))
186 svgWidth = round(math.sqrt(totalPoints * float(width) / height))
188 eventdata_plotter.setCanvasHeight(svgHeight)
189 eventdata_plotter.setCanvasWidth(svgWidth)
191 return eventdata_plotter.save(svgFileName)
195 Save the current dom object representation to disk as a png.
201 temp_file_name =
"tmp.svg"
204 boundingBox = eventdata_plotter.getBoundingBox()
206 height = boundingBox.getHeight()
207 width = boundingBox.getWidth()
209 totalPoints = 1120 * 1120
210 svgHeight = round(math.sqrt(totalPoints * float(height) / width))
211 svgWidth = round(math.sqrt(totalPoints * float(width) / height))
213 eventdata_plotter.setCanvasHeight(svgHeight)
214 eventdata_plotter.setCanvasWidth(svgWidth)
216 eventdata_plotter.save(temp_file_name)
218 with open(temp_file_name,
"r")
as temp_file:
219 with open(pngFileName,
"w")
as output_file:
220 svg_code = temp_file.read()
221 cairosvg.svg2png(bytestring=svg_code, write_to=output_file)
223 os.remove(temp_file_name)