[318b5bbb] | 1 | /** |
---|
| 2 | Computes the (magnetic) scattering form sld (n and m) profile |
---|
| 3 | */ |
---|
| 4 | #include "sld2i.hh" |
---|
| 5 | #include <stdio.h> |
---|
| 6 | #include <math.h> |
---|
| 7 | using namespace std; |
---|
| 8 | extern "C" { |
---|
| 9 | #include "libmultifunc/libfunc.h" |
---|
| 10 | #include "libmultifunc/librefl.h" |
---|
| 11 | } |
---|
| 12 | /** |
---|
| 13 | * Constructor for GenI |
---|
| 14 | * |
---|
| 15 | * binning |
---|
| 16 | * //@param qx: array of Qx values |
---|
| 17 | * //@param qy: array of Qy values |
---|
| 18 | * //@param qz: array of Qz values |
---|
| 19 | * @param x: array of x values |
---|
| 20 | * @param y: array of y values |
---|
| 21 | * @param z: array of z values |
---|
| 22 | * @param sldn: array of sld n |
---|
| 23 | * @param mx: array of sld mx |
---|
| 24 | * @param my: array of sld my |
---|
| 25 | * @param mz: array of sld mz |
---|
| 26 | * @param in_spin: ratio of up spin in Iin |
---|
| 27 | * @param out_spin: ratio of up spin in Iout |
---|
| 28 | * @param s_theta: angle (from x-axis) of the up spin in degree |
---|
| 29 | */ |
---|
| 30 | GenI :: GenI(int npix, double* x, double* y, double* z, double* sldn, |
---|
[b1174ec] | 31 | double* mx, double* my, double* mz, double* voli, |
---|
[318b5bbb] | 32 | double in_spin, double out_spin, |
---|
| 33 | double s_theta) { |
---|
| 34 | //this->qx_val = qx; |
---|
| 35 | //this->qy_val = qy; |
---|
| 36 | //this->qz_val = qz; |
---|
| 37 | this->n_pix = npix; |
---|
| 38 | this->x_val = x; |
---|
| 39 | this->y_val = y; |
---|
| 40 | this->z_val = z; |
---|
| 41 | this->sldn_val = sldn; |
---|
| 42 | this->mx_val = mx; |
---|
| 43 | this->my_val = my; |
---|
| 44 | this->mz_val = mz; |
---|
[b1174ec] | 45 | this->vol_pix = voli; |
---|
[318b5bbb] | 46 | this->inspin = in_spin; |
---|
| 47 | this->outspin = out_spin; |
---|
| 48 | this->stheta = s_theta; |
---|
| 49 | }; |
---|
| 50 | |
---|
| 51 | /** |
---|
| 52 | * Compute |
---|
| 53 | */ |
---|
| 54 | void GenI :: genicom(int npoints, double *qx, double *qy, double *I_out){ |
---|
[3657667] | 55 | //npoints is given negative for angular averaging |
---|
[b1174ec] | 56 | // Assumes that q doesn't have qz component and sld_n is all real |
---|
[318b5bbb] | 57 | double q = 0.0; |
---|
[3657667] | 58 | int is_avg = 0; |
---|
[318b5bbb] | 59 | //double Pi = 4.0*atan(1.0); |
---|
| 60 | polar_sld b_sld; |
---|
| 61 | double qr = 0.0; |
---|
| 62 | complex iqr = cassign(0.0, 0.0); |
---|
| 63 | complex ephase = cassign(0.0, 0.0); |
---|
| 64 | complex comp_sld = cassign(0.0, 0.0); |
---|
| 65 | complex sumj; |
---|
| 66 | complex sumj_uu; |
---|
| 67 | complex sumj_ud; |
---|
| 68 | complex sumj_du; |
---|
| 69 | complex sumj_dd; |
---|
| 70 | complex temp_fi; |
---|
| 71 | |
---|
[b1174ec] | 72 | double count = 0.0; |
---|
[3657667] | 73 | //check if this computation is for averaging |
---|
| 74 | if (n_pix < 0 ){ |
---|
| 75 | is_avg = 1; |
---|
| 76 | n_pix = fabs(n_pix); |
---|
| 77 | } |
---|
[b1174ec] | 78 | //Assume that pixel volumes are given in vol_pix in A^3 unit |
---|
[318b5bbb] | 79 | //int x_size = 0; //in Ang |
---|
| 80 | //int y_size = 0; //in Ang |
---|
| 81 | //int z_size = 0; //in Ang |
---|
| 82 | // Loop over q-values and multiply apply matrix |
---|
| 83 | |
---|
| 84 | for(int i=0; i<npoints; i++){ |
---|
| 85 | //I_out[i] = 0.0; |
---|
| 86 | sumj = cassign(0.0, 0.0); |
---|
| 87 | sumj_uu = cassign(0.0, 0.0); |
---|
| 88 | sumj_ud = cassign(0.0, 0.0); |
---|
| 89 | sumj_du = cassign(0.0, 0.0); |
---|
| 90 | sumj_dd = cassign(0.0, 0.0); |
---|
| 91 | //printf ("%d ", i); |
---|
[b1174ec] | 92 | q = sqrt(qx[i]*qx[i] + qy[i]*qy[i]); // + qz[i]*qz[i]); |
---|
[318b5bbb] | 93 | |
---|
| 94 | for(int j=0; j<n_pix; j++){ |
---|
| 95 | |
---|
| 96 | if (sldn_val[j]!=0.0||mx_val[j]!=0.0||my_val[j]!=0.0||mz_val[j]!=0.0) |
---|
| 97 | { |
---|
| 98 | temp_fi = cassign(0.0, 0.0); |
---|
| 99 | b_sld = cal_msld(0, qx[i], qy[i], sldn_val[j], |
---|
| 100 | mx_val[j], my_val[j], mz_val[j], |
---|
| 101 | inspin, outspin, stheta); |
---|
[3657667] | 102 | if (is_avg < 1){ |
---|
| 103 | //anisotropic |
---|
| 104 | qr = (qx[i]*x_val[j] + qy[i]*y_val[j]); |
---|
| 105 | iqr = cassign(0.0, qr); |
---|
| 106 | ephase = cplx_exp(iqr); |
---|
| 107 | } |
---|
| 108 | else{ |
---|
| 109 | //isotropic |
---|
| 110 | qr = sqrt(x_val[j]*x_val[j]+y_val[j]*y_val[j]+z_val[j]*z_val[j]); |
---|
| 111 | qr *= q; |
---|
| 112 | if (qr == 0.0){ |
---|
| 113 | ephase = cassign(0.0, 1.0); |
---|
| 114 | } |
---|
| 115 | else{ |
---|
| 116 | qr = sin(qr) / qr; |
---|
| 117 | ephase = cassign(qr, 0.0); |
---|
| 118 | } |
---|
| 119 | } |
---|
[5917637] | 120 | //Let's multiply pixel(atomic) volume here |
---|
| 121 | ephase = rcmult(vol_pix[j], ephase); |
---|
[318b5bbb] | 122 | //up_up |
---|
| 123 | if (inspin > 0.0 && outspin > 0.0){ |
---|
| 124 | comp_sld = cassign(b_sld.uu, 0.0); |
---|
| 125 | temp_fi = cplx_mult(comp_sld, ephase); |
---|
| 126 | sumj_uu = cplx_add(sumj_uu, temp_fi); |
---|
| 127 | } |
---|
| 128 | //down_down |
---|
| 129 | if (inspin < 1.0 && outspin < 1.0){ |
---|
| 130 | comp_sld = cassign(b_sld.dd, 0.0); |
---|
| 131 | temp_fi = cplx_mult(comp_sld, ephase); |
---|
| 132 | sumj_dd = cplx_add(sumj_dd, temp_fi); |
---|
| 133 | } |
---|
| 134 | //up_down |
---|
| 135 | if (inspin > 0.0 && outspin < 1.0){ |
---|
| 136 | comp_sld = cassign(b_sld.re_ud, b_sld.im_ud); |
---|
| 137 | temp_fi = cplx_mult(comp_sld, ephase); |
---|
| 138 | sumj_ud = cplx_add(sumj_ud, temp_fi); |
---|
| 139 | } |
---|
| 140 | //down_up |
---|
| 141 | if (inspin < 1.0 && outspin > 0.0){ |
---|
| 142 | comp_sld = cassign(b_sld.re_du, b_sld.im_du); |
---|
| 143 | temp_fi = cplx_mult(comp_sld, ephase); |
---|
| 144 | sumj_du = cplx_add(sumj_du, temp_fi); |
---|
| 145 | } |
---|
| 146 | if (i == 0){ |
---|
[b1174ec] | 147 | count += vol_pix[j]; |
---|
[318b5bbb] | 148 | } |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | //printf("aa%d=%g %g %d\n", i, (sumj_uu.re*sumj_uu.re + sumj_uu.im*sumj_uu.im), (sumj_dd.re*sumj_dd.re + sumj_dd.im*sumj_dd.im), count); |
---|
| 152 | I_out[i] = (sumj_uu.re*sumj_uu.re + sumj_uu.im*sumj_uu.im); |
---|
| 153 | I_out[i] += (sumj_ud.re*sumj_ud.re + sumj_ud.im*sumj_ud.im); |
---|
| 154 | I_out[i] += (sumj_du.re*sumj_du.re + sumj_du.im*sumj_du.im); |
---|
| 155 | I_out[i] += (sumj_dd.re*sumj_dd.re + sumj_dd.im*sumj_dd.im); |
---|
| 156 | I_out[i] *= (1.0E+8 / count); //in cm (unit) / number; //to be multiplied by vol_pix |
---|
| 157 | } |
---|
| 158 | //printf ("count = %d %g %g %g %g\n", count, sldn_val[0],mx_val[0], my_val[0], mz_val[0]); |
---|
| 159 | } |
---|