diff options
author | Thomas White <taw@physics.org> | 2023-07-10 15:52:35 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2023-07-28 13:22:05 +0200 |
commit | 25a59996689f0285f23e6c5d8221af80e8e06125 (patch) | |
tree | 395b5cf032c4fc3bdb602128e4aa3f77eb660b48 /tests/gradient_check.c | |
parent | 59709a8fb3b3f39fef4b2f4e97ad1b25a9358c8a (diff) |
Implement rotation gradients (with test)
Diffstat (limited to 'tests/gradient_check.c')
-rw-r--r-- | tests/gradient_check.c | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/tests/gradient_check.c b/tests/gradient_check.c index 46d366d6..7396b8ad 100644 --- a/tests/gradient_check.c +++ b/tests/gradient_check.c @@ -52,15 +52,47 @@ int main(int argc, char *argv[]) int fail = 0; double step; gsl_matrix **panel_matrices; + int didsomething = 0; + const double cx = -200.0; + const double cy = +100.0; + const double cz = -50.0; rps = make_test_image(&n_refls, &image); panel_matrices = make_panel_minvs(image.detgeom); before = make_dev_list(rps, n_refls, image.detgeom); - #ifdef MOVE_PANEL + #ifdef TRANSLATE_PANEL step = 0.1; /* Pixels */ image.detgeom->panels[0].THING_TO_MOVE += step; + didsomething = 1; + #endif + + #ifdef ROTATE_PANEL_X + struct detgeom_panel *p = &image.detgeom->panels[0]; + step = deg2rad(0.01); + rotate2d(&p->cnz, &p->cny, cz, cy, step); + rotate2d(&p->fsz, &p->fsy, 0, 0, step); + rotate2d(&p->ssz, &p->ssy, 0, 0, step); + didsomething = 1; + #endif + + #ifdef ROTATE_PANEL_Y + struct detgeom_panel *p = &image.detgeom->panels[0]; + step = deg2rad(0.01); + rotate2d(&p->cnx, &p->cnz, cx, cz, step); + rotate2d(&p->fsx, &p->fsz, 0, 0, step); + rotate2d(&p->ssx, &p->ssz, 0, 0, step); + didsomething = 1; + #endif + + #ifdef ROTATE_PANEL_Z + struct detgeom_panel *p = &image.detgeom->panels[0]; + step = deg2rad(0.01); + rotate2d(&p->cnx, &p->cny, cx, cy, step); + rotate2d(&p->fsx, &p->fsy, 0, 0, step); + rotate2d(&p->ssx, &p->ssy, 0, 0, step); + didsomething = 1; #endif #ifdef CHANGE_CELL @@ -74,8 +106,14 @@ int main(int argc, char *argv[]) cell_set_reciprocal(cell, asx, asy, asz, bsx, bsy, bsz, csx, csy, csz); + didsomething = 1; #endif + if ( !didsomething ) { + fprintf(stderr, "Nothing changed. Check the build system.\n"); + return 1; + } + update_predictions(image.crystals[0]); after = make_dev_list(rps, n_refls, image.detgeom); @@ -91,20 +129,27 @@ int main(int argc, char *argv[]) fs_ss_gradient(TEST_GPARAM, rps[i].refl, crystal_get_cell(image.crystals[0]), &image.detgeom->panels[rps[i].peak->pn], - panel_matrices[rps[i].peak->pn], + panel_matrices[rps[i].peak->pn], cx, cy, cz, &calc[1], &calc[2]); obs[0] = (after[0][i] - before[0][i]) / step; obs[1] = (after[1][i] - before[1][i]) / step; obs[2] = (after[2][i] - before[2][i]) / step; - #ifdef MOVE_PANEL + #ifdef TRANSLATE_PANEL if ( fabs(calc[0]) > 1e-12 ) n_wrong_r++; /* Should be zero */ if ( fabs(obs[0]) > 1e-12 ) n_wrong_obsr++; /* Should also be zero */ if ( fabs(obs[1] - calc[1]) > 1e-3 ) n_wrong_fs++; if ( fabs(obs[2] - calc[2]) > 1e-3 ) n_wrong_ss++; #endif + #if defined(ROTATE_PANEL_X) || defined(ROTATE_PANEL_Y) || defined(ROTATE_PANEL_Z) + if ( fabs(calc[0]) > 1e-12 ) n_wrong_r++; /* Should be zero */ + if ( fabs(obs[0]) > 1e-12 ) n_wrong_obsr++; /* Should also be zero */ + if ( fabs(obs[1] - calc[1]) > 1.0 ) n_wrong_fs++; /* Units are pixels/rad */ + if ( fabs(obs[2] - calc[2]) > 1.0 ) n_wrong_ss++; /* (numbers are big) */ + #endif + #ifdef CHANGE_CELL if ( fabs(obs[0] - calc[0]) > 1e-2 ) n_wrong_r++; if ( fabs(obs[1] - calc[1]) > 1e-8 ) n_wrong_fs++; |