source: sasview/src/sas/models/c_extension/c_smearer/smearer2d_helper.cpp @ b2669f5

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since b2669f5 was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 2.4 KB
Line 
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>
17using 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 */
28Smearer_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 */
44void 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        double rbin = 0.0;
49        double phibin = 0.0;
50        double qr = 0.0;
51        double qphi = 0.0;
52        double Pi = 4.0*atan(1.0);
53       
54        // Loop over q-values and multiply apply matrix
55        for(int i=0; i<nrbins; i++){
56                rbin = rbin_size * (double(i) + 0.5);
57                for(int j=0; j<nphibins; j++){
58                        phibin_size =  2.0 * Pi / double(nphibins);
59                        phibin = phibin_size * (double(j));
60                        for(int q_i=0; q_i<npoints; q_i++){
61                                qr = sqrt(qx_values[q_i]*qx_values[q_i] + qy_values[q_i]*qy_values[q_i]);
62                                qphi = atan(qy_values[q_i]/qx_values[q_i]);
63                                qx_out[q_i + npoints*(nrbins * j + i)] = (rbin*dqx_values[q_i]*cos(phibin) + qr)*cos(qphi)-
64                                                                                rbin*dqy_values[q_i]*sin(phibin)*sin(qphi);
65                                qy_out[q_i + npoints*(nrbins * j + i)] = (rbin*dqx_values[q_i]*cos(phibin) + qr)*sin(qphi)+
66                                                                                rbin*dqy_values[q_i]*sin(phibin)*cos(qphi);
67                                if (q_i==0){
68                                        weights[nrbins * j + i] = exp(-0.5 * ((rbin - rbin_size / 2.0) *
69                                                        (rbin - rbin_size / 2.0)))- exp(-0.5 * ((rbin + rbin_size / 2.0 ) *
70                                                                        (rbin + rbin_size / 2.0)));
71                        }
72                }
73        }
74        }
75}
76
Note: See TracBrowser for help on using the repository browser.