corrected layer order
This commit is contained in:
+63
-21
@@ -36,7 +36,10 @@ class G4System(_G4System):
|
||||
df = ttree["Hits;1"].arrays(library="pd")
|
||||
return df
|
||||
|
||||
def displayEvent(self, particleSpec, minEnergy_GeV, maxEnergy_GeV=-1, sensor_width=np.array([50])):
|
||||
def displayEvent(self, particleSpec, minEnergy_GeV, maxEnergy_GeV=-1, sensor_width=50):
|
||||
if not isinstance(sensor_width, np.ndarray):
|
||||
sensor_width = np.array([sensor_width])
|
||||
|
||||
# for loop over all layers
|
||||
event = self.run_batch(1, particleSpec, minEnergy_GeV, maxEnergy_GeV)
|
||||
to_plot = []
|
||||
@@ -44,8 +47,9 @@ class G4System(_G4System):
|
||||
|
||||
z0=0
|
||||
# loop over materials
|
||||
for layer_i, layer in enumerate(reversed(self.cw.getLayers())):
|
||||
layer_i = len(self.cw.getLayers()) - layer_i -1
|
||||
for layer_i, layer in enumerate(self.cw.getLayers()):
|
||||
#layer_i = len(self.cw.getLayers()) - layer_i -1
|
||||
print(layer_i)
|
||||
|
||||
#
|
||||
# plot layers
|
||||
@@ -54,6 +58,7 @@ class G4System(_G4System):
|
||||
layer_hy = sensor_width / 2.
|
||||
layer_z = layer.thickness
|
||||
layer_material = layer.material
|
||||
print(layer_material)
|
||||
|
||||
# add material to materials if it is not already in there
|
||||
if layer_material not in material_dict.keys():
|
||||
@@ -70,13 +75,14 @@ class G4System(_G4System):
|
||||
to_plot.append(go.Mesh3d(
|
||||
# 8 vertices of a cube
|
||||
x = np.array([-1, -1, 1, 1, -1, -1, 1, 1]) * layer_hx,
|
||||
y = np.array([-1, 1, 1, -1, -1, 1, 1, -1]) * layer_hy,
|
||||
z = np.array([0, 0, 0, 0, -layer_z, -layer_z, -layer_z, -layer_z]) + z0,
|
||||
z = np.array([-1, 1, 1, -1, -1, 1, 1, -1]) * layer_hy,
|
||||
y = np.array([0, 0, 0, 0, layer_z, layer_z, layer_z, layer_z]) + z0,
|
||||
**ijk_cube,
|
||||
**material_dict[layer_material]
|
||||
))
|
||||
z0 += layer_z
|
||||
|
||||
|
||||
#
|
||||
# sensors
|
||||
#
|
||||
@@ -84,6 +90,7 @@ class G4System(_G4System):
|
||||
# if there are sensors in the current layer, add them
|
||||
if layer_i in event['sensor_layer'].to_numpy():
|
||||
is_in_layer = event['sensor_layer'].to_numpy() == layer_i
|
||||
print(event['sensor_energy'].to_numpy()[is_in_layer].sum())
|
||||
z = event['sensor_dz'].to_numpy()[is_in_layer]
|
||||
n_sensors = len(z)
|
||||
z=z[0]
|
||||
@@ -95,8 +102,8 @@ class G4System(_G4System):
|
||||
to_plot.append(go.Mesh3d(
|
||||
# 8 vertices of a cube
|
||||
x = np.array([-1, -1, 1, 1, -1, -1, 1, 1]) * hwidth + x_center,
|
||||
y = np.array([-1, 1, 1, -1, -1, 1, 1, -1]) * hwidth + y_center,
|
||||
z = np.array([0, 0, 0, 0, z, z, z, z]) + z0,
|
||||
z = np.array([-1, 1, 1, -1, -1, 1, 1, -1]) * hwidth + y_center,
|
||||
y = np.array([0, 0, 0, 0, z, z, z, z]) + z0,
|
||||
**ijk_cube,
|
||||
flatshading=True,
|
||||
color='black',
|
||||
@@ -106,6 +113,10 @@ class G4System(_G4System):
|
||||
))
|
||||
|
||||
z0 += z
|
||||
|
||||
|
||||
|
||||
|
||||
# add legend entry for sensors
|
||||
to_plot.append(go.Mesh3d(x=[None], y=[None], z=[None], i=[0], j=[0], k=[0],
|
||||
color='black', showlegend=True, name='Sensors'))
|
||||
@@ -113,6 +124,8 @@ class G4System(_G4System):
|
||||
# add black-white colorbar for sensor hits
|
||||
to_plot.append(go.Surface(
|
||||
z=[[0, 0], [0, 0]],
|
||||
x=[[0, 0], [0, 0]],
|
||||
y=[[0, 0], [0, 0]],
|
||||
colorscale=[[0, 'white'], [1, 'black']],
|
||||
showscale=True,
|
||||
cmin=0,
|
||||
@@ -126,21 +139,50 @@ class G4System(_G4System):
|
||||
),
|
||||
))
|
||||
|
||||
|
||||
#
|
||||
# add red arrow for incoming particle
|
||||
#
|
||||
to_plot.append(
|
||||
go.Scatter3d(
|
||||
x=[0, 0],
|
||||
y=[0, 0],
|
||||
z=[-10, -2],
|
||||
mode='lines+text',
|
||||
line=dict(color='red', width=3), # You can change the color and width of the arrow
|
||||
text=['Incoming ' + particleSpec],
|
||||
textposition='bottom center',
|
||||
hoverinfo='text',
|
||||
showlegend=False,
|
||||
))
|
||||
|
||||
# Define the start and end points of the line
|
||||
start_point = [0, 0, - z0*0.1]
|
||||
end_point = [0, 0, - z0*0.25]
|
||||
|
||||
# Create the line trace
|
||||
line_trace = go.Scatter3d(
|
||||
x=[start_point[0], end_point[0]],
|
||||
z=[start_point[1], end_point[1]],
|
||||
y=[start_point[2], end_point[2]],
|
||||
mode='lines',
|
||||
line=dict(color='red', width=5),
|
||||
name='Incoming ' + particleSpec + ' @{} GeV'.format(minEnergy_GeV),
|
||||
showlegend=True,
|
||||
)
|
||||
|
||||
# Calculate the direction vector for the arrow
|
||||
direction_vector = [(end_point[0] - start_point[0]), (end_point[1] - start_point[1]), (end_point[2] - start_point[2])]
|
||||
|
||||
# Create the arrowhead at the start point with the opposite direction
|
||||
arrowhead_trace = go.Cone(
|
||||
x=[start_point[0]],
|
||||
z=[start_point[1]],
|
||||
y=[start_point[2]],
|
||||
u=[-direction_vector[0]],
|
||||
w=[-direction_vector[1]],
|
||||
v=[-direction_vector[2]],
|
||||
sizemode='scaled',
|
||||
sizeref=0.8,
|
||||
showscale=False,
|
||||
colorscale='Reds',
|
||||
opacity=1.0,
|
||||
anchor='tail',
|
||||
)
|
||||
|
||||
# Create the 3D scatter plot with both traces
|
||||
to_plot.append(line_trace)
|
||||
to_plot.append(arrowhead_trace)
|
||||
|
||||
|
||||
|
||||
#
|
||||
# finally show plot
|
||||
@@ -168,8 +210,8 @@ def calculate_sensor_centers(X, square_size):
|
||||
|
||||
for j in range(int(np.sqrt(X))):
|
||||
for i in range(int(np.sqrt(X))):
|
||||
x_center = -25 + (i + 0.5) * sensor_size
|
||||
y_center = -25 + (j + 0.5) * sensor_size
|
||||
x_center = -square_size/2 + (i + 0.5) * sensor_size
|
||||
y_center = -square_size/2 + (j + 0.5) * sensor_size
|
||||
centers.append((x_center[0], y_center[0]))
|
||||
|
||||
return centers, hsensor_size[0]
|
||||
|
||||
Reference in New Issue
Block a user