#ifndef SPHERICALTRANFORMSERVER_SEEN #define SPHERICALTRANFORMSERVER_SEEN #include "sphericalmap.h" #include "spheregorski.h" #include "fftservintf.h" #include "fftpserver.h" #include "alm.h" #include "lambdaBuilder.h" namespace SOPHYA { // /*! Class for performing analysis and synthesis of sky maps using spin-0 or spin-2 spherical harmonics. */ template class SphericalTransformServer { public: SphericalTransformServer() { fftIntfPtr_=new FFTPackServer; fftIntfPtr_->setNormalize(false); }; ~SphericalTransformServer(){ if (fftIntfPtr_!=NULL) delete fftIntfPtr_;}; /*! Set a fft server. The constructor sets a default fft server (fft-pack). So it is not necessary to call this method for a standard use. */ void SetFFTServer(FFTServerInterface* srv=NULL) { if (fftIntfPtr_!=NULL) delete fftIntfPtr_; fftIntfPtr_=srv; fftIntfPtr_->setNormalize(false); } /*! synthesis of a temperature map from Alm coefficients */ void GenerateFromAlm( SphericalMap& map, int_4 pixelSizeIndex, const Alm& alm) const; /*! synthesis of a polarization map from Alm coefficients. The spheres mapq and mapu contain respectively the Stokes parameters. */ void GenerateFromAlm(SphericalMap& mapq, SphericalMap& mapu, int_4 pixelSizeIndex, const Alm& alme, const Alm& almb) const; /*! synthesis of a temperature map from power spectrum Cl (Alm's are generated randomly, following a gaussian distribution). */ void GenerateFromCl(SphericalMap& sph, int_4 pixelSizeIndex, const TVector& Cl, const r_8 fwhm) const; /*! synthesis of a polarization map from power spectra electric-Cl and magnetic-Cl (Alm's are generated randomly, following a gaussian distribution). \param fwhm FWHM in arcmin for random generation of Alm's (eg. 5) */ void GenerateFromCl(SphericalMap& sphq, SphericalMap& sphu, int_4 pixelSizeIndex, const TVector& Cle, const TVector& Clb, const r_8 fwhm) const; /*!return the Alm coefficients from analysis of a temperature map. nlmax : maximum value of the l index cos_theta_cut : cosinus of the symmetric cut EULER angle theta : cos_theta_cut=0 means no cut ; cos_theta_cut=1 all the sphere is cut. */ Alm DecomposeToAlm(const SphericalMap& map, int_4 nlmax, r_8 cos_theta_cut) const; /*analysis of a polarization map into Alm coefficients. The spheres mapq and mapu contain respectively the Stokes parameters. a2lme and a2lmb will receive respectively electric and magnetic Alm's nlmax : maximum value of the l index cos_theta_cut : cosinus of the symmetric cut EULER angle theta : cos_theta_cut=0 means no cut ; cos_theta_cut=1 all the sphere is cut. */ void DecomposeToAlm(const SphericalMap& mapq, const SphericalMap& mapu, Alm& a2lme, Alm& a2lmb, int_4 nlmax, r_8 cos_theta_cut) const; // /*return power spectrum from analysis of a temperature map. // nlmax : maximum value of the l index // cos_theta_cut : cosinus of the symmetric cut EULER angle theta : cos_theta_cut=0 means no cut ; cos_theta_cut=1 all the sphere is cut. // */ TVector DecomposeToCl(const SphericalMap& sph, int_4 nlmax, r_8 cos_theta_cut) const; private: /*! return a vector with nph elements which are sums :\f$\sum_{m=-mmax}^{mmax}b_m(\theta)e^{im\varphi}\f$ for nph values of \f$\varphi\f$ regularly distributed in \f$[0,\pi]\f$ ( calculated by FFT) The object b_m (\f$b_m\f$) of the class Bm is a special vector which index goes from -mmax to mmax. */ TVector< complex > fourierSynthesisFromB(const Bm >& b_m, int_4 nph, r_8 phi0) const; /*! same as fourierSynthesisFromB, but return a real vector, taking into account the fact that b(-m) is conjugate of b(m) */ TVector RfourierSynthesisFromB(const Bm >& b_m, int_4 nph, r_8 phi0) const; /*! return a vector with mmax elements which are sums : \f$\sum_{k=0}^{nphi}datain(\theta,\varphi_k)e^{im\varphi_k}\f$ for (mmax+1) values of \f$m\f$ from 0 to mmax. */ TVector< complex > CFromFourierAnalysis(int_4 mmax, const TVector > datain, r_8 phi0) const; /* same as previous one, but with a "datain" which is real (not complex) */ TVector< complex > CFromFourierAnalysis(int_4 mmax, const TVector datain, r_8 phi0) const; /*! Compute polarized Alm's as : \f[ a_{lm}^E=\frac{1}{\sqrt{2}}\sum_{slices}{\omega_{pix}\left(_{w}\lambda_l^m\tilde{Q}-i_{x}\lambda_l^m\tilde{U}\right)} \f] \f[ a_{lm}^B=\frac{1}{\sqrt{2}}\sum_{slices}{\omega_{pix}\left(i_{x}\lambda_l^m\tilde{Q}+_{w}\lambda_l^m\tilde{U}\right)} \f] where \f$\tilde{Q}\f$ and \f$\tilde{U}\f$ are C-coefficients computed by FFT (method CFromFourierAnalysis, called by present method) from the Stokes parameters. \f$\omega_{pix}\f$ are solid angle of each pixel. dataq, datau : Stokes parameters. */ void almFromWX(int_4 nlmax, int_4 nmmax, r_8 phi0, r_8 domega, r_8 theta, const TVector& dataq, const TVector& datau, Alm& alme, Alm& almb) const; /*! Compute polarized Alm's as : \f[ a_{lm}^E=-\frac{1}{2}\sum_{slices}{\omega_{pix}\left(_{+}\lambda_l^m\tilde{P^+}+_{-}\lambda_l^m\tilde{P^-}\right)} \f] \f[ a_{lm}^B=\frac{i}{2}\sum_{slices}{\omega_{pix}\left(_{+}\lambda_l^m\tilde{P^+}-_{-}\lambda_l^m\tilde{P^-}\right)} \f] where \f$\tilde{P^{\pm}}=\tilde{Q}\pm\tilde{U}\f$ computed by FFT (method CFromFourierAnalysis, called by present method) from the Stokes parameters,\f$Q\f$ and \f$U\f$ . \f$\omega_{pix}\f$ are solid angle of each pixel. dataq, datau : Stokes parameters. */ void almFromPM(int_4 nph, int_4 nlmax, int_4 nmmax, r_8 phi0, r_8 domega, r_8 theta, const TVector& dataq, const TVector& datau, Alm& alme, Alm& almb) const; /*! synthesis of Stokes parameters following formulae : \f[ Q=\sum_{m=-mmax}^{mmax}b_m^qe^{im\varphi} \f] \f[ U=\sum_{m=-mmax}^{mmax}b_m^ue^{im\varphi} \f] computed by FFT (method fourierSynthesisFromB called by the present one) with : \f[ b_m^q=-\frac{1}{\sqrt{2}}\sum_{l=|m|}^{lmax}{\left(_{w}\lambda_l^ma_{lm}^E-i_{x}\lambda_l^ma_{lm}^B\right) } \f] \f[ b_m^u=\frac{1}{\sqrt{2}}\sum_{l=|m|}^{lmax}{\left(i_{x}\lambda_l^ma_{lm}^E+_{w}\lambda_l^ma_{lm}^B\right) } \f] */ void mapFromWX(int_4 nlmax, int_4 nmmax, SphericalMap& mapq, SphericalMap& mapu, const Alm& alme, const Alm& almb) const; /*! synthesis of polarizations following formulae : \f[ P^+ = \sum_{m=-mmax}^{mmax} {b_m^+e^{im\varphi} } \f] \f[ P^- = \sum_{m=-mmax}^{mmax} {b_m^-e^{im\varphi} } \f] computed by FFT (method fourierSynthesisFromB called by the present one) with : \f[ b_m^+=-\sum_{l=|m|}^{lmax}{_{+}\lambda_l^m \left( a_{lm}^E+ia_{lm}^B \right) } \f] \f[ b_m^-=-\sum_{l=|m|}^{lmax}{_{+}\lambda_l^m \left( a_{lm}^E-ia_{lm}^B \right) } \f] */ void mapFromPM(int_4 nlmax, int_4 nmmax, SphericalMap& mapq, SphericalMap& mapu, const Alm& alme, const Alm& almb) const; FFTServerInterface* fftIntfPtr_; }; } // Fin du namespace #endif