22
22
namespace detray ::detail {
23
23
24
24
// / @brief Generate Jacobians
25
- template <typename frame_t >
26
- requires std::is_object_v< typename frame_t ::loc_point> struct jacobian_engine {
25
+ template <typename algebra_t >
26
+ struct jacobian_engine {
27
27
28
28
// / @name Type definitions for the struct
29
29
// / @{
30
- using frame_type = frame_t ;
31
- using jacobian_t = jacobian<frame_t >;
32
-
33
- using algebra_type = typename frame_t ::algebra_type;
30
+ using algebra_type = algebra_t ;
34
31
using transform3_type = dtransform3D<algebra_type>;
35
32
using scalar_type = dscalar<algebra_type>;
36
33
using point3_type = dpoint3D<algebra_type>;
@@ -42,39 +39,33 @@ requires std::is_object_v<typename frame_t::loc_point> struct jacobian_engine {
42
39
using path_to_free_matrix_type = path_to_free_matrix<algebra_type>;
43
40
// / @}
44
41
45
- template <typename mask_t >
46
- DETRAY_HOST_DEVICE static inline bound_to_free_matrix_type
47
- bound_to_free_jacobian (
48
- const transform3_type& trf3, const mask_t & mask,
49
- const bound_parameters_vector<algebra_type>& bound_vec) {
42
+ template <typename frame_t >
43
+ requires std::is_object_v<typename frame_t ::loc_point>
44
+ DETRAY_HOST_DEVICE static inline void bound_to_free_jacobian_step_1 (
45
+ bound_to_free_matrix_type& jac_to_global,
46
+ const transform3_type& trf3, const vector3_type& pos,
47
+ const vector3_type& dir) {
48
+ using jacobian_t = jacobian<frame_t >;
50
49
51
- // Declare jacobian for bound to free coordinate transform
52
- bound_to_free_matrix_type jac_to_global =
53
- matrix::zero<bound_to_free_matrix_type>();
50
+ // Set d(x,y,z)/d(loc0, loc1)
51
+ jacobian_t::set_bound_pos_to_free_pos_derivative (jac_to_global, trf3,
52
+ pos, dir);
53
+ }
54
+
55
+ DETRAY_HOST_DEVICE static inline void bound_to_free_jacobian_step_2 (
56
+ bound_to_free_matrix_type& jac_to_global,
57
+ const bound_parameters_vector<algebra_type>& bound_vec) {
58
+ // Set d(bound time)/d(free time)
59
+ getter::element (jac_to_global, e_free_time, e_bound_time) = 1 .f ;
54
60
55
61
// Get trigonometric values
56
62
const scalar_type theta{bound_vec.theta ()};
57
63
const scalar_type phi{bound_vec.phi ()};
58
-
59
64
const scalar_type cos_theta{math::cos (theta)};
60
65
const scalar_type sin_theta{math::sin (theta)};
61
66
const scalar_type cos_phi{math::cos (phi)};
62
67
const scalar_type sin_phi{math::sin (phi)};
63
68
64
- // Global position and direction
65
- const free_track_parameters<algebra_type> free_params =
66
- bound_to_free_vector (trf3, mask, bound_vec);
67
-
68
- const vector3_type pos = free_params.pos ();
69
- const vector3_type dir = free_params.dir ();
70
-
71
- // Set d(x,y,z)/d(loc0, loc1)
72
- jacobian_t::set_bound_pos_to_free_pos_derivative (jac_to_global, trf3,
73
- pos, dir);
74
-
75
- // Set d(bound time)/d(free time)
76
- getter::element (jac_to_global, e_free_time, e_bound_time) = 1 .f ;
77
-
78
69
// Set d(n_x,n_y,n_z)/d(phi, theta)
79
70
getter::element (jac_to_global, e_free_dir0, e_bound_phi) =
80
71
-sin_theta * sin_phi;
@@ -86,42 +77,71 @@ requires std::is_object_v<typename frame_t::loc_point> struct jacobian_engine {
86
77
cos_theta * sin_phi;
87
78
getter::element (jac_to_global, e_free_dir2, e_bound_theta) = -sin_theta;
88
79
getter::element (jac_to_global, e_free_qoverp, e_bound_qoverp) = 1 .f ;
80
+ }
81
+
82
+ template <typename frame_t >
83
+ requires std::is_object_v<typename frame_t ::loc_point>
84
+ DETRAY_HOST_DEVICE static inline void bound_to_free_jacobian_step_3 (
85
+ bound_to_free_matrix_type& jac_to_global,
86
+ const transform3_type& trf3, const vector3_type& pos,
87
+ const vector3_type& dir) {
88
+ using jacobian_t = jacobian<frame_t >;
89
89
90
90
// Set d(x,y,z)/d(phi, theta)
91
91
jacobian_t::set_bound_angle_to_free_pos_derivative (jac_to_global, trf3,
92
92
pos, dir);
93
-
94
- return jac_to_global;
95
93
}
96
94
97
- DETRAY_HOST_DEVICE
98
- static inline free_to_bound_matrix_type free_to_bound_jacobian (
99
- const transform3_type& trf3,
100
- const free_track_parameters<algebra_type>& free_params) {
101
-
102
- // Declare jacobian for bound to free coordinate transform
103
- free_to_bound_matrix_type jac_to_local =
104
- matrix::zero<free_to_bound_matrix_type >();
95
+ template < typename frame_t , typename mask_t >
96
+ requires std::is_object_v< typename frame_t ::loc_point>
97
+ DETRAY_HOST_DEVICE static inline bound_to_free_matrix_type
98
+ bound_to_free_jacobian (
99
+ const transform3_type& trf3, const mask_t & mask,
100
+ const bound_parameters_vector<algebra_type>& bound_vec) {
101
+ bound_to_free_matrix_type jac_to_global =
102
+ matrix::zero<bound_to_free_matrix_type >();
105
103
106
104
// Global position and direction
105
+ const free_track_parameters<algebra_type> free_params =
106
+ bound_to_free_vector (trf3, mask, bound_vec);
107
+
107
108
const vector3_type pos = free_params.pos ();
108
109
const vector3_type dir = free_params.dir ();
109
110
110
- const scalar_type theta{vector::theta (dir)};
111
- const scalar_type phi{vector::phi (dir)};
111
+ bound_to_free_jacobian_step_1<frame_t >(jac_to_global, trf3, pos, dir);
112
+ bound_to_free_jacobian_step_2 (jac_to_global, bound_vec);
113
+ bound_to_free_jacobian_step_3<frame_t >(jac_to_global, trf3, pos, dir);
112
114
113
- const scalar_type cos_theta{math::cos (theta)};
114
- const scalar_type sin_theta{math::sin (theta)};
115
- const scalar_type cos_phi{math::cos (phi)};
116
- const scalar_type sin_phi{math::sin (phi)};
115
+ return jac_to_global;
116
+ }
117
+
118
+ template <typename frame_t >
119
+ requires std::is_object_v<typename frame_t ::loc_point>
120
+ DETRAY_HOST_DEVICE static inline void free_to_bound_jacobian_step_1 (
121
+ free_to_bound_matrix_type& jac_to_local,
122
+ const transform3_type& trf3, const vector3_type& pos,
123
+ const vector3_type& dir) {
124
+ using jacobian_t = jacobian<frame_t >;
117
125
118
126
// Set d(loc0, loc1)/d(x,y,z)
119
127
jacobian_t::set_free_pos_to_bound_pos_derivative (jac_to_local, trf3,
120
128
pos, dir);
129
+ }
130
+
131
+ DETRAY_HOST_DEVICE static inline void free_to_bound_jacobian_step_2 (
132
+ free_to_bound_matrix_type& jac_to_local, const vector3_type& dir) {
121
133
122
134
// Set d(free time)/d(bound time)
123
135
getter::element (jac_to_local, e_bound_time, e_free_time) = 1 .f ;
124
136
137
+ const scalar_type theta{vector::theta (dir)};
138
+ const scalar_type phi{vector::phi (dir)};
139
+
140
+ const scalar_type cos_theta{math::cos (theta)};
141
+ const scalar_type sin_theta{math::sin (theta)};
142
+ const scalar_type cos_phi{math::cos (phi)};
143
+ const scalar_type sin_phi{math::sin (phi)};
144
+
125
145
// Set d(phi, theta)/d(n_x, n_y, n_z)
126
146
// @note This codes have a serious bug when theta is equal to zero...
127
147
getter::element (jac_to_local, e_bound_phi, e_free_dir0) =
@@ -136,17 +156,42 @@ requires std::is_object_v<typename frame_t::loc_point> struct jacobian_engine {
136
156
137
157
// Set d(Free Qop)/d(Bound Qop)
138
158
getter::element (jac_to_local, e_bound_qoverp, e_free_qoverp) = 1 .f ;
159
+ }
160
+
161
+ template <typename frame_t >
162
+ requires std::is_object_v<typename frame_t ::loc_point>
163
+ DETRAY_HOST_DEVICE static inline free_to_bound_matrix_type
164
+ free_to_bound_jacobian (
165
+ const transform3_type& trf3,
166
+ const free_track_parameters<algebra_type>& free_params) {
167
+
168
+ // Declare jacobian for bound to free coordinate transform
169
+ free_to_bound_matrix_type jac_to_local =
170
+ matrix::zero<free_to_bound_matrix_type>();
171
+
172
+ // Global position and direction
173
+ const vector3_type pos = free_params.pos ();
174
+ const vector3_type dir = free_params.dir ();
175
+
176
+ free_to_bound_jacobian_step_1<frame_t >(jac_to_local, trf3, pos, dir);
177
+ free_to_bound_jacobian_step_2 (jac_to_local, dir);
139
178
140
179
return jac_to_local;
141
180
}
142
181
143
- DETRAY_HOST_DEVICE static inline free_matrix<algebra_type> path_correction (
144
- const vector3_type& pos, const vector3_type& dir,
145
- const vector3_type& dtds, const scalar_type dqopds,
146
- const transform3_type& trf3) {
182
+ template <typename frame_t >
183
+ requires std::is_object_v<typename frame_t ::loc_point>
184
+ DETRAY_HOST_DEVICE static inline auto free_to_path_derivative (
185
+ const vector3_type& pos, const vector3_type& dir,
186
+ const vector3_type& dtds, const transform3_type& trf3) {
187
+ using jacobian_t = jacobian<frame_t >;
147
188
148
- free_to_path_matrix_type path_derivative =
149
- jacobian_t::path_derivative (trf3, pos, dir, dtds);
189
+ return jacobian_t::path_derivative (trf3, pos, dir, dtds);
190
+ }
191
+
192
+ DETRAY_HOST_DEVICE static inline auto path_to_free_derivative (
193
+ const vector3_type& dir, const vector3_type& dtds,
194
+ const scalar_type dqopds) {
150
195
151
196
path_to_free_matrix_type derivative =
152
197
matrix::zero<path_to_free_matrix_type>();
@@ -158,7 +203,18 @@ requires std::is_object_v<typename frame_t::loc_point> struct jacobian_engine {
158
203
getter::element (derivative, e_free_dir2, 0u ) = dtds[2 ];
159
204
getter::element (derivative, e_free_qoverp, 0u ) = dqopds;
160
205
161
- return derivative * path_derivative;
206
+ return derivative;
207
+ }
208
+
209
+ template <typename frame_t >
210
+ requires std::is_object_v<typename frame_t ::loc_point>
211
+ DETRAY_HOST_DEVICE static inline free_matrix<algebra_type>
212
+ path_correction (const vector3_type& pos, const vector3_type& dir,
213
+ const vector3_type& dtds, const scalar_type dqopds,
214
+ const transform3_type& trf3) {
215
+
216
+ return path_to_free_derivative (dir, dtds, dqopds) *
217
+ free_to_path_derivative<frame_t >(pos, dir, dtds, trf3);
162
218
}
163
219
};
164
220
0 commit comments