33 #include "lsconstants.h" 42 void PolarizationHolder::getQU(
const pointing &p,
double &q,
double &u)
const 45 fix_arr<double,4> wgt;
46 Q.get_interpol(p,pix,wgt);
48 for (tsize i=0;i<4;++i) {q+=Q[pix[i]]*wgt[i];u+=U[pix[i]]*wgt[i]; }
51 vec3 PolarizationHolder::getQUDir(
const vec3 &loc)
const 56 if (abs(loc.x)+abs(loc.y) > 0.0)
57 east = vec3(-loc.y,loc.x,0).Norm();
58 vec3 north = crossprod(loc, east);
59 double angle = 0.5*safe_atan2(u,q);
60 return north*(-cos(angle)) + east*sin(angle);
64 double PolarizationHolder::getQUMagnitude(
const pointing& p)
const 68 return sqrt(q*q + u*u);
72 void get_step(
const PolarizationHolder &ph, vec3 &loc, vec3 &dir,
double theta)
74 loc=(loc+dir*theta).Norm();
75 vec3 tdir=ph.getQUDir(loc);
76 dir = (dotprod(dir,tdir)<0) ? -tdir : tdir;
96 double theta, arr<vec3> &locs)
98 vec3 first_dir=ph.getQUDir(location);
102 locs[locs.size()/2] = loc;
104 for(
int i = 1 + locs.size()/2; i<int(locs.size()); i++)
112 for(
int i = -1 + locs.size()/2; i>=0; i--)
122 for(tsize i=0; i<kernel.size(); i++)
124 double sinx = sin(pi*(i+1) / (kernel.size()+1));
125 kernel[i] = sinx*sinx;
130 void convolve(
const arr<double> &kernel,
const arr<double> &raw, arr<double> &convolution)
132 convolution.alloc(raw.size()-kernel.size()+1);
133 for(tsize i=0; i<convolution.size(); i++)
136 for (tsize j=0; j<kernel.size(); j++)
137 total += kernel[j] * raw[i+j];
138 convolution[i] = total;
145 int kernel_steps,
double step_radian)
147 arr<double> kernel(kernel_steps), convolution, rawtexture;
149 arr<vec3> curve(steps);
154 for(
int i=0; i<texture.
Npix(); i++)
160 rawtexture.alloc(curve.size());
161 for (tsize i2=0; i2<curve.size(); i2++)
163 convolve(kernel, rawtexture, convolution);
164 for (tsize j=0; j<convolution.size(); j++)
166 int k = texture.
vec2pix(curve[j+kernel.size()/2]);
167 texture[k] += convolution[j];
178 int steps,
int kernel_steps,
double step_radian,
double polmin,
double polmax)
180 PolarizationHolder ph;
186 for (
int i=0; i<mag.
Npix(); i++)
190 mag[i] = min(polmax,max(polmin,ph.getQUMagnitude(p)));
194 lic_function(hit, tex, ph, th, steps, kernel_steps, step_radian);
196 for (
int i=0; i<tex.
Npix(); ++i)
198 double tmin,tmax,mmin,mmax;
201 for (
int i=0; i<tex.
Npix(); ++i)
203 mag[i]*=(tex[i]-tmin);
204 tex[i]=1.0-(tex[i]-tmin)/(tmax-tmin);
207 for (
int i=0; i<mag.
Npix(); ++i)
208 mag[i]=1.0-(mag[i]-mmin)/(mmax-mmin);
void minmax(T &Min, T &Max) const
vec3 pix2vec(I pix) const
I vec2pix(const vec3 &vec) const
void lic_main(const Healpix_Map< double > &Q, const Healpix_Map< double > &U, const Healpix_Map< double > &th, Healpix_Map< double > &hit, Healpix_Map< double > &tex, Healpix_Map< double > &mag, int steps, int kernel_steps, double step_radian, double polmin, double polmax)
void make_kernel(arr< double > &kernel)
int lic_function(Healpix_Map< double > &hitcount, Healpix_Map< double > &texture, const PolarizationHolder &ph, const Healpix_Map< double > &th, int steps, int kernel_steps, double step_radian)
void runge_kutta_2(const vec3 &location, const PolarizationHolder &ph, double theta, arr< vec3 > &locs)
T interpolated_value(const pointing &ptg) const
void get_step(const PolarizationHolder &ph, vec3 &loc, vec3 &dir, double theta)
pointing pix2ang(I pix) const
void convolve(const arr< double > &kernel, const arr< double > &raw, arr< double > &convolution)
void runge_kutta_step(vec3 &loc, vec3 &dir, const PolarizationHolder &ph, double theta)