[ae3ce4e] | 1 | /** |
---|
| 2 | * Scattering model for a cylinder |
---|
| 3 | * @author: Mathieu Doucet / UTK |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | #include "cylinder.h" |
---|
| 7 | #include "smeared_cylinder.h" |
---|
| 8 | #include <math.h> |
---|
| 9 | #include "libCylinder.h" |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | /** |
---|
| 13 | * Function to evaluate 1D scattering function |
---|
| 14 | * @param pars: parameters of the cylinder |
---|
| 15 | * @param q: q-value |
---|
| 16 | * @return: function value |
---|
| 17 | */ |
---|
| 18 | double smeared_cylinder_analytical_1D(SmearCylinderParameters *pars, double q) { |
---|
| 19 | double dp[5]; |
---|
| 20 | int i_r; |
---|
| 21 | double r_0, r, step_r, min_r; |
---|
| 22 | int npts; |
---|
| 23 | double weight, func, norm; |
---|
| 24 | |
---|
| 25 | // Fill paramater array |
---|
| 26 | dp[0] = pars->scale; |
---|
| 27 | dp[1] = pars->radius; |
---|
| 28 | dp[2] = pars->length; |
---|
| 29 | dp[3] = pars->contrast; |
---|
| 30 | dp[4] = pars->background; |
---|
| 31 | |
---|
| 32 | if(pars->sigma_radius==0) { |
---|
| 33 | return CylinderForm(dp, q); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | // Central value is the current value |
---|
| 37 | r_0 = pars->radius; |
---|
| 38 | |
---|
| 39 | npts = 100; |
---|
| 40 | step_r = 4.0*pars->sigma_radius/npts; |
---|
| 41 | min_r = r_0 - 2.0*pars->sigma_radius; |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | norm = 0.0; |
---|
| 45 | func = 0.0; |
---|
| 46 | |
---|
| 47 | for (i_r=0; i_r<100; i_r++) { |
---|
| 48 | r = min_r + step_r*i_r; |
---|
| 49 | dp[1] = r; |
---|
| 50 | |
---|
| 51 | // Weigth for that position |
---|
| 52 | weight = smeared_cylinder_dist( r, r_0, pars->sigma_radius ); |
---|
| 53 | norm += weight; |
---|
| 54 | |
---|
| 55 | // Evaluate I(q) at that r-value |
---|
| 56 | func += weight * CylinderForm(dp, q); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | return func/norm; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * Function to evaluate 2D scattering function |
---|
| 65 | * @param pars: parameters of the cylinder |
---|
| 66 | * @param q: q-value |
---|
| 67 | * @return: function value |
---|
| 68 | */ |
---|
| 69 | double smeared_cylinder_analytical_2D(SmearCylinderParameters *pars, double q, double phi) { |
---|
| 70 | CylinderParameters cyl_pars; |
---|
| 71 | int i_theta, i_phi, i_r; |
---|
| 72 | int n_theta, n_phi, n_r; |
---|
| 73 | double theta_0, phi_0, r_0; |
---|
| 74 | int npts; |
---|
| 75 | double weight_theta, weight_phi, weight_r; |
---|
| 76 | double min_theta, min_phi, min_r; |
---|
| 77 | double step_theta, step_phi, step_r; |
---|
| 78 | double func, norm; |
---|
| 79 | double n_width = 3.0; |
---|
| 80 | |
---|
| 81 | // Fill paramater struct |
---|
| 82 | cyl_pars.scale = pars->scale; |
---|
| 83 | cyl_pars.radius = pars->radius; |
---|
| 84 | cyl_pars.length = pars->length; |
---|
| 85 | cyl_pars.contrast = pars->contrast; |
---|
| 86 | cyl_pars.background = pars->background; |
---|
| 87 | cyl_pars.cyl_phi = pars->cyl_phi; |
---|
| 88 | cyl_pars.cyl_theta = pars->cyl_theta; |
---|
| 89 | |
---|
| 90 | theta_0 = pars->cyl_theta; |
---|
| 91 | phi_0 = pars->cyl_phi; |
---|
| 92 | r_0 = pars->radius; |
---|
| 93 | |
---|
| 94 | npts = 25; |
---|
| 95 | step_theta = 2.0*n_width*pars->sigma_theta/npts; |
---|
| 96 | step_phi = 2.0*n_width*pars->sigma_phi/npts; |
---|
| 97 | step_r = 2.0*n_width*pars->sigma_radius/npts; |
---|
| 98 | |
---|
| 99 | if (step_theta>0) { |
---|
| 100 | n_theta = npts; |
---|
| 101 | } else { |
---|
| 102 | n_theta = 1; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | if (step_phi>0) { |
---|
| 106 | n_phi = npts; |
---|
| 107 | } else { |
---|
| 108 | n_phi = 1; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | if (step_r>0) { |
---|
| 112 | n_r = npts; |
---|
| 113 | } else { |
---|
| 114 | n_r = 1; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | min_theta = theta_0 - n_width*pars->sigma_theta; |
---|
| 120 | min_phi = phi_0 - n_width*pars->sigma_phi; |
---|
| 121 | min_r = r_0 - n_width*pars->sigma_radius; |
---|
| 122 | |
---|
| 123 | func = 0.0; |
---|
| 124 | norm = 0.0; |
---|
| 125 | |
---|
| 126 | for (i_theta=0; i_theta<n_theta; i_theta++) { |
---|
| 127 | |
---|
| 128 | // Weight for that position |
---|
| 129 | if(pars->sigma_theta>0) { |
---|
| 130 | cyl_pars.cyl_theta = min_theta + step_theta*i_theta; |
---|
| 131 | weight_theta = smeared_cylinder_dist( cyl_pars.cyl_theta, theta_0, pars->sigma_theta ); |
---|
| 132 | } else { |
---|
| 133 | weight_theta = 1.0; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | for (i_phi=0; i_phi<n_phi; i_phi++) { |
---|
| 137 | |
---|
| 138 | // Weight for that position |
---|
| 139 | if(pars->sigma_phi>0) { |
---|
| 140 | cyl_pars.cyl_phi = min_phi + step_phi*i_phi; |
---|
| 141 | weight_phi = smeared_cylinder_dist( cyl_pars.cyl_phi, phi_0, pars->sigma_phi ); |
---|
| 142 | } else { |
---|
| 143 | weight_phi = 1.0; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | for (i_r=0; i_r<n_r; i_r++) { |
---|
| 147 | |
---|
| 148 | if(pars->sigma_radius>0) { |
---|
| 149 | cyl_pars.radius = min_r + step_r*i_r; |
---|
| 150 | |
---|
| 151 | // Weight for that position |
---|
| 152 | weight_r = smeared_cylinder_dist( cyl_pars.radius, r_0, pars->sigma_radius ); |
---|
| 153 | } else { |
---|
| 154 | weight_r = 1.0; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | // Evaluate I(q) at that r-value |
---|
| 158 | func += weight_theta * weight_r * weight_phi * cylinder_analytical_2D(&cyl_pars, q, phi); |
---|
| 159 | norm += weight_theta * weight_r * weight_phi; |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | return func/norm; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | double smeared_cylinder_dist( double x, double mean, double sigma ) { |
---|
| 169 | double vary; |
---|
| 170 | double expo; |
---|
| 171 | |
---|
| 172 | //return 1.0; |
---|
| 173 | |
---|
| 174 | vary = x-mean; |
---|
| 175 | expo = -vary*vary/(2.0*sigma*sigma); |
---|
| 176 | return exp(expo); |
---|
| 177 | |
---|
| 178 | } |
---|