Skip to content

Commit 543decd

Browse files
author
Cyrille Pierre Henri Favreau
committed
Particles as vectors
1 parent 6c0efcf commit 543decd

File tree

2 files changed

+92
-33
lines changed

2 files changed

+92
-33
lines changed

notebooks/events_collide.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"be = BioExplorer(be_url)\n",
2121
"core = be.core_api()\n",
2222
"nmv = NuonModelVisualizer(\n",
23-
" bio_explorer=be,\n",
23+
" bio_explorer=be, particles_as_vectors=True,\n",
2424
" root_proton_file='keep_findall_64004.root',\n",
2525
" root_collision_file='collide_298792_events.root')"
2626
]
@@ -33,8 +33,8 @@
3333
"source": [
3434
"def set_field_parameters(nmv):\n",
3535
" nmv.set_field_parameters(\n",
36-
" cutoff_distance=350,\n",
37-
" sampling_rate=1.25,\n",
36+
" cutoff_distance=50,\n",
37+
" sampling_rate=0.25,\n",
3838
" gradient_shading=False, gradient_offset=0.01, epsilon=1.5, \n",
3939
" accumulation_steps=0,\n",
4040
" use_octree=True\n",
@@ -72,7 +72,7 @@
7272
"params.gi_ray_length = 1000.0\n",
7373
"params.shadow_intensity = 0.0\n",
7474
"params.soft_shadow_strength = 0.25\n",
75-
"params.epsilon_multiplier = 1.0\n",
75+
"params.epsilon_multiplier = 100.0\n",
7676
"params.max_ray_depth = 30\n",
7777
"params.show_background = False\n",
7878
"params.main_exposure = 10.0\n",
@@ -99,7 +99,7 @@
9999
"nmv.render_event(\n",
100100
" event_id, 'nuons.1dt',\n",
101101
" timestamp=1.0, \n",
102-
" magnetic=True, value_range=[-0.005, 0.08], voxel_size=0.1,\n",
102+
" magnetic=True, value_range=[-0.005, 0.1], voxel_size=0.1,\n",
103103
" show_plot=False, show_grid=False,\n",
104104
" marker_size=2.0)"
105105
]

nuon_model_visualizer/nuon_model_visualizer.py

Lines changed: 87 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
class NuonModelVisualizer:
3030

31-
def __init__(self, bio_explorer, root_proton_file, root_collision_file, radius_multiplier=0.01):
31+
def __init__(self, bio_explorer, root_proton_file, root_collision_file, radius_multiplier=0.01, particles_as_vectors=False):
3232
self._bio_explorer = bio_explorer
3333
self._core = bio_explorer.core_api()
3434
self._root_proton_file = ROOT.TFile.Open(root_proton_file)
@@ -43,6 +43,7 @@ def __init__(self, bio_explorer, root_proton_file, root_collision_file, radius_m
4343
self._Rfactor = 1.94
4444

4545
self._radius_multiplier = radius_multiplier
46+
self._particles_as_vectors = particles_as_vectors
4647

4748
@staticmethod
4849
def _rotate_z(point, angle):
@@ -94,9 +95,15 @@ def _load_proton_1(self, ax, sub_particles_to_ignore, marker_size=1.0, position=
9495
drp1 = np.array(getattr(self._T_protons, 'drp'))
9596

9697
v1p_positions = list()
98+
v1p_targets = list()
9799
v1p_radii = list()
100+
v1p_target_radii = list()
101+
98102
v1n_positions = list()
103+
v1n_targets = list()
99104
v1n_radii = list()
105+
v1n_target_radii = list()
106+
100107
for i in range(len(vypart1)):
101108
if i in sub_particles_to_ignore:
102109
continue
@@ -118,29 +125,45 @@ def _load_proton_1(self, ax, sub_particles_to_ignore, marker_size=1.0, position=
118125
rotated_v1n = self._rotate_z(point, z_rotation_angle)
119126

120127
radius = marker_size
128+
121129
v1p_positions.append(
122130
Vector3(rotated_v1p[0] + position[0], rotated_v1p[1] + position[1], z + position[2]))
123131
v1p_radii.append(radius * self._radius_multiplier)
132+
v1p_targets.append(
133+
Vector3(rotated_v1p[0] + position[0], rotated_v1p[1] + position[1], z + position[2] + radius * self._radius_multiplier))
134+
v1p_target_radii.append(0.0)
135+
124136
v1n_positions.append(
125137
Vector3(rotated_v1n[0] + position[0], rotated_v1n[1] + position[1], z + position[2]))
138+
v1n_targets.append(
139+
Vector3(rotated_v1n[0] + position[0], rotated_v1n[1] + position[1], z + position[2] + radius * self._radius_multiplier))
126140
v1n_radii.append(radius * self._radius_multiplier)
141+
v1n_target_radii.append(0.0)
127142

128143
if ax:
129144
ax.plot(vx1p, vy1p, marker='o', color='red', markersize=radius)
130145
ax.plot(vx1n, vy1n, marker='o', color='blue', markersize=radius)
131146
ax.plot([vx1p, vx1n], [vy1p, vy1n], color='grey', linestyle='--', linewidth=0.5)
132-
133-
status = self._bio_explorer.add_spheres('Proton 1 P', v1p_positions, v1p_radii, Vector3(1, 0, 0))
134-
status = self._bio_explorer.add_spheres('Proton 1 N', v1n_positions, v1n_radii, Vector3(0, 0, 1))
147+
148+
if self._particles_as_vectors:
149+
self._bio_explorer.add_cones('Proton 1 P', v1p_positions, v1p_targets, v1p_radii, v1p_target_radii, Vector3(1, 0, 0))
150+
self._bio_explorer.add_cones('Proton 1 N', v1n_positions, v1n_targets,v1n_radii, v1n_target_radii, Vector3(0, 0, 1))
151+
else:
152+
self._bio_explorer.add_spheres('Proton 1 P', v1p_positions, v1p_radii, Vector3(1, 0, 0))
153+
self._bio_explorer.add_spheres('Proton 1 N', v1n_positions, v1n_radii, Vector3(0, 0, 1))
135154

136155
def _load_proton_2(self, ax, sub_particles_to_ignore, marker_size=1.0, position=[0, 0, 0], z_rotation_angle=0.0, z_scale=1.0):
137156
i2 = getattr(self._T_collisions, 'i2')
138157
phi2 = getattr(self._T_collisions, 'phi2')
139158

140159
v2p_positions = list()
160+
v2p_targets = list()
141161
v2p_radii = list()
162+
v2p_target_radii = list()
142163
v2n_positions = list()
164+
v2n_targets = list()
143165
v2n_radii = list()
166+
v2n_target_radii = list()
144167

145168
self._T_protons.GetEntry(i2)
146169
vxpart2 = np.array(getattr(self._T_protons, 'x'))
@@ -171,18 +194,29 @@ def _load_proton_2(self, ax, sub_particles_to_ignore, marker_size=1.0, position=
171194
radius = marker_size
172195
v2p_positions.append(
173196
Vector3(rotated_v2p[0] + position[0], rotated_v2p[1] + position[1], z + position[2]))
197+
v2p_targets.append(
198+
Vector3(rotated_v2p[0] + position[0], rotated_v2p[1] + position[1], z + position[2] + radius * self._radius_multiplier))
174199
v2p_radii.append(radius * self._radius_multiplier)
200+
v2p_target_radii.append(0.0)
201+
175202
v2n_positions.append(
176203
Vector3(rotated_v2n[0] + position[0], rotated_v2n[1] + position[1], z + position[2]))
204+
v2n_targets.append(
205+
Vector3(rotated_v2n[0] + position[0], rotated_v2n[1] + position[1], z + position[2] + radius * self._radius_multiplier))
177206
v2n_radii.append(radius * self._radius_multiplier)
207+
v2n_target_radii.append(0.0)
178208

179209
if ax:
180210
ax.plot(vx2p, vy2p, marker='o', color='magenta', markersize=radius)
181211
ax.plot(vx2n, vy2n, marker='o', color='cyan', markersize=radius)
182212
ax.plot([vx2p, vx2n], [vy2p, vy2n], color='grey', linestyle='--', linewidth=0.5)
183213

184-
status = self._bio_explorer.add_spheres('Proton 2 P', v2p_positions, v2p_radii, Vector3(0, 1, 1))
185-
status = self._bio_explorer.add_spheres('Proton 2 N', v2n_positions, v2n_radii, Vector3(1, 0, 1))
214+
if self._particles_as_vectors:
215+
self._bio_explorer.add_cones('Proton 2 P', v2p_positions, v2p_targets, v2p_radii, v2p_target_radii, Vector3(1, 0, 0))
216+
self._bio_explorer.add_cones('Proton 2 N', v2n_positions, v2n_targets, v2n_radii, v2n_target_radii, Vector3(0, 0, 1))
217+
else:
218+
self._bio_explorer.add_spheres('Proton 2 P', v2p_positions, v2p_radii, Vector3(1, 0, 0))
219+
self._bio_explorer.add_spheres('Proton 2 N', v2n_positions, v2n_radii, Vector3(0, 0, 1))
186220

187221
def _load_collisions(self, ax, collision_maker_size=2.0, j_cut=1.0):
188222
njetsCMS = getattr(self._T_collisions, 'njetsCMS')
@@ -204,7 +238,9 @@ def _load_collisions(self, ax, collision_maker_size=2.0, j_cut=1.0):
204238
proton_2_sub_particle_ids = list()
205239

206240
col_positions = list()
241+
col_targets = list()
207242
col_radii = list()
243+
col_target_radii = list()
208244

209245
nj = 0
210246
for i in range(njetsCMS):
@@ -234,12 +270,17 @@ def _load_collisions(self, ax, collision_maker_size=2.0, j_cut=1.0):
234270
markersize=radius)
235271

236272
col_positions.append(Vector3(x, y, 0.0))
273+
col_targets.append(Vector3(x, y, radius))
237274
col_radii.append(radius * self._radius_multiplier)
275+
col_target_radii.append(0.0)
238276

239277
proton_1_sub_particle_ids.append(icol[i])
240278
proton_2_sub_particle_ids.append(jcol[i])
241279

242-
status = self._bio_explorer.add_spheres('Collisions', col_positions, col_radii, Vector3(0, 1, 0))
280+
if self._particles_as_vectors:
281+
self._bio_explorer.add_cones('Collisions', col_positions, col_targets, col_radii, col_target_radii, Vector3(0, 1, 0))
282+
else:
283+
self._bio_explorer.add_spheres('Collisions', col_positions, col_radii, Vector3(0, 1, 0))
243284
return proton_1_sub_particle_ids, proton_2_sub_particle_ids
244285

245286
def _load_particles(self, ax, magnetic, timestamp=1.0):
@@ -324,15 +365,22 @@ def _load_particles(self, ax, magnetic, timestamp=1.0):
324365

325366
for t in types:
326367
if magnetic:
327-
# self._bio_explorer.add_spheres(
328-
# name='Jets origins %d' % t,
329-
# positions=origins[t], radii=origins_radii[t],
330-
# color=colors[t]
331-
# )
332-
self._bio_explorer.add_spheres(
333-
name='Jets targets %d' % t,
334-
positions=targets[t], radii=targets_radii[t],
335-
color=colors[t]
368+
if self._particles_as_vectors:
369+
self._bio_explorer.add_cones(
370+
name='Line %03d' % t,
371+
origins=origins[t], origins_radii=origins_radii[t],
372+
targets=targets[t], targets_radii=targets_radii[t],
373+
color=colors[t])
374+
else:
375+
# self._bio_explorer.add_spheres(
376+
# name='Jets origins %d' % t,
377+
# positions=origins[t], radii=origins_radii[t],
378+
# color=colors[t]
379+
# )
380+
self._bio_explorer.add_spheres(
381+
name='Jets targets %d' % t,
382+
positions=targets[t], radii=targets_radii[t],
383+
color=colors[t]
336384
)
337385
else:
338386
if ax:
@@ -441,16 +489,23 @@ def _load_jets(self, magnetic, nchj, jetphi, jettheta, timestamp):
441489

442490
for t in types:
443491
if magnetic:
444-
self._bio_explorer.add_spheres(
445-
name='Jets origins %d' % t,
446-
positions=origins[t], radii=origins_radii[t],
447-
color=colors[t]
448-
)
449-
# self._bio_explorer.add_spheres(
450-
# name='Jets targets %d' % t,
451-
# positions=targets[t], radii=targets_radii[t],
452-
# color=colors[t]
453-
# )
492+
if self._particles_as_vectors:
493+
self._bio_explorer.add_cones(
494+
name='Jets %d' % t,
495+
origins=origins[t], origins_radii=origins_radii[t],
496+
targets=targets[t], targets_radii=targets_radii[t],
497+
color=colors[t], opacity=0.3)
498+
else:
499+
self._bio_explorer.add_spheres(
500+
name='Jets origins %d' % t,
501+
positions=origins[t], radii=origins_radii[t],
502+
color=colors[t]
503+
)
504+
# self._bio_explorer.add_spheres(
505+
# name='Jets targets %d' % t,
506+
# positions=targets[t], radii=targets_radii[t],
507+
# color=colors[t]
508+
# )
454509
else:
455510
self._bio_explorer.add_cones(
456511
name='Jets %d' % t,
@@ -474,7 +529,7 @@ def render_event(self, event_id, colormap=None, magnetic=False, timestamp=0.0, v
474529
fig = None
475530
ax = None
476531
if show_plot:
477-
plt.subplots(figsize=(6,6))
532+
fig, ax = plt.subplots(figsize=(6,6))
478533

479534
x2offset = getattr(self._T_collisions, 'x2offset')
480535
y2offset = getattr(self._T_collisions, 'y2offset')
@@ -524,7 +579,11 @@ def render_event(self, event_id, colormap=None, magnetic=False, timestamp=0.0, v
524579
],
525580
radii=[0.0001, 0.0001])
526581

527-
status = self._bio_explorer.build_fields(voxel_size=voxel_size)
582+
data_type = self._bio_explorer.FIELD_DATA_TYPE_POINT
583+
if self._particles_as_vectors:
584+
data_type = self._bio_explorer.FIELD_DATA_TYPE_VECTOR
585+
self._bio_explorer.build_fields(
586+
voxel_size=voxel_size, data_type=data_type)
528587
model_id = self._bio_explorer.get_model_ids()['ids'][-1:][0]
529588
tf = TransferFunction(
530589
bioexplorer=self._bio_explorer, model_id=model_id,

0 commit comments

Comments
 (0)