14def compute_doca(name_values):
16 Computes DOCA between two tracks.
19 name_values (dict): Dictionary of numpy arrays containing px, py, pz, x, y, z.
22 numpy.ndarray: Array containing doca values.
26 px = name_values["px"]
27 py = name_values[
"py"]
28 pz = name_values[
"pz"]
33 p = np.array([px, py, pz]).T
34 r = np.array([x, y, z]).T
39 v = np.cross(p, p[:,
None]).reshape(-1, 3)
41 v_norm = np.linalg.norm(v, axis=1).reshape((-1, 1))
43 v_norm[v_norm == 0] = 1
47 dr = np.subtract(r, r[:,
None]).reshape(-1, 3)
50 np.dot(dr, v_u.T).diagonal().reshape((1, -1))
54 doca = np.linalg.norm(v_u * dr_x_vu.T - dr * (v_norm < eps), axis=1).reshape(
59 return doca[~np.eye(doca.shape[0], dtype=bool)]
62def compute_cosTheta(name_values):
64 Computes cosinus of angle between two tracks.
67 name_values (dict): Dictionary of numpy arrays containing p, px, py, pz.
70 numpy.ndarray: Array containing cosinus of theta values.
72 ux = name_values["px"] / name_values[
"p"]
73 uy = name_values[
"py"] / name_values[
"p"]
74 uz = name_values[
"pz"] / name_values[
"p"]
76 u = np.array([ux, uy, uz]).T
78 costheta = np.inner(u, u)
81 return costheta[~np.eye(costheta.shape[0], dtype=bool)]
86 "edge_costheta": compute_cosTheta,
87 "edge_doca": compute_doca,
91def _available_edge_features(feat, name_values):
93 Returns value of edge feature if contained
in dictionary available_features.
95 if feat
not in available_features:
97 "Requested edge feature not available, but you could add it in grafei/data/edge_features.py!"
100 return available_features[feat](name_values)
103def compute_edge_features(edge_feature_names, features, x):
105 Computes a series of edge features starting from node features.
108 edge_feature_names (list): List of edge features names.
109 features (list): List of node feature names.
110 x (numpy.ndarray): Array of node features.
113 numpy.ndarray: Array of edge features.
120 features = [f.replace(
"feat_",
"")
for f
in features]
123 name_values = dict(zip(features, x.T))
126 for feat
in edge_feature_names:
127 feature_values = _available_edge_features(feat, name_values)
128 edge_features.append(feature_values)
130 return np.array(edge_features).T