[87615a48] | 1 | /** |
---|
| 2 | This software was developed by the University of Tennessee as part of the |
---|
| 3 | Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
| 4 | project funded by the US National Science Foundation. |
---|
| 5 | |
---|
| 6 | If you use DANSE applications to do scientific research that leads to |
---|
| 7 | publication, we ask that you acknowledge the use of the software with the |
---|
| 8 | following sentence: |
---|
| 9 | |
---|
| 10 | "This work benefited from DANSE software developed under NSF award DMR-0520547." |
---|
| 11 | |
---|
| 12 | copyright 2009, University of Tennessee |
---|
| 13 | */ |
---|
| 14 | #include "smearer2d_helper.hh" |
---|
| 15 | #include <stdio.h> |
---|
| 16 | #include <math.h> |
---|
| 17 | using namespace std; |
---|
| 18 | |
---|
| 19 | /** |
---|
| 20 | * Constructor for BaseSmearer |
---|
| 21 | * |
---|
| 22 | * binning |
---|
| 23 | * @param qx: array of Qx values |
---|
| 24 | * @param qy: array of Qy values |
---|
| 25 | * @param nrbins: number of r bins |
---|
| 26 | * @param nphibins: number of phi bins |
---|
| 27 | */ |
---|
| 28 | Smearer_helper :: Smearer_helper(int npoints, double* qx, double* qy, |
---|
| 29 | double* dqx, double* dqy, double rlimit, int nrbins, int nphibins) { |
---|
| 30 | // Number of bins |
---|
| 31 | this->npoints = npoints; |
---|
| 32 | this->rlimit = rlimit; |
---|
| 33 | this->nrbins = nrbins; |
---|
| 34 | this->nphibins = nphibins; |
---|
| 35 | this->qx_values = qx; |
---|
| 36 | this->qy_values = qy; |
---|
| 37 | this->dqx_values = dqx; |
---|
| 38 | this->dqy_values = dqy; |
---|
| 39 | }; |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | * Compute the point smearing matrix |
---|
| 43 | */ |
---|
| 44 | void Smearer_helper :: smear2d(double *weights, double *qx_out, double *qy_out){ |
---|
| 45 | |
---|
| 46 | double rbin_size = rlimit / double(nrbins); |
---|
| 47 | double phibin_size = 0.0; |
---|
| 48 | int tot_nbins = nrbins * nphibins; |
---|
| 49 | double rbin = 0.0; |
---|
| 50 | double phibin = 0.0; |
---|
| 51 | double qr = 0.0; |
---|
| 52 | double qphi = 0.0; |
---|
| 53 | double Pi = 4.0*atan(1.0); |
---|
| 54 | // Loop over q-values and multiply apply matrix |
---|
| 55 | |
---|
| 56 | for(int i=0; i<nrbins; i++){ |
---|
| 57 | rbin = rbin_size * (double(i) + 0.5); |
---|
| 58 | for(int j=0; j<nphibins; j++){ |
---|
| 59 | phibin_size = 2.0 * Pi / double(nphibins); |
---|
| 60 | phibin = phibin_size * (double(j)); |
---|
| 61 | for(int q_i=0; q_i<npoints; q_i++){ |
---|
| 62 | qr = sqrt(qx_values[q_i]*qx_values[q_i] + qy_values[q_i]*qy_values[q_i]); |
---|
| 63 | qphi = atan(qy_values[q_i]/qx_values[q_i]); |
---|
| 64 | qx_out[q_i + npoints*(nrbins * j + i)] = (rbin*dqx_values[q_i]*cos(phibin) + qr)*cos(qphi)- |
---|
| 65 | rbin*dqy_values[q_i]*sin(phibin)*sin(qphi); |
---|
| 66 | qy_out[q_i + npoints*(nrbins * j + i)] = (rbin*dqx_values[q_i]*cos(phibin) + qr)*sin(qphi)+ |
---|
| 67 | rbin*dqy_values[q_i]*sin(phibin)*cos(qphi); |
---|
| 68 | if (q_i==0){ |
---|
| 69 | weights[nrbins * j + i] = exp(-0.5 * ((rbin - rbin_size / 2.0) * |
---|
| 70 | (rbin - rbin_size / 2.0)))- exp(-0.5 * ((rbin + rbin_size / 2.0 ) * |
---|
| 71 | (rbin + rbin_size / 2.0))); |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | |
---|