powspec.cc

00001 /*
00002  *  This file is part of Healpix_cxx.
00003  *
00004  *  Healpix_cxx is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  Healpix_cxx is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with Healpix_cxx; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  *  For more information about HEALPix, see http://healpix.sourceforge.net
00019  */
00020 
00021 /*
00022  *  Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
00023  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00024  *  (DLR).
00025  */
00026 
00027 /*
00028  *  Copyright (C) 2003-2015 Max-Planck-Society
00029  *  Author: Martin Reinecke
00030  */
00031 
00032 #include "powspec.h"
00033 #include "lsconstants.h"
00034 
00035 using namespace std;
00036 
00037 void PowSpec::dealloc()
00038   {
00039   tt_.dealloc();
00040   gg_.dealloc();
00041   cc_.dealloc();
00042   tg_.dealloc();
00043   tc_.dealloc();
00044   gc_.dealloc();
00045   }
00046 
00047 PowSpec::PowSpec(int nspec, int lmax)
00048   { Set(nspec,lmax); }
00049 
00050 PowSpec::~PowSpec()
00051   {}
00052 
00053 void PowSpec::assertArraySizes() const
00054   {
00055   planck_assert((num_specs==1) || (num_specs==4) || (num_specs==6),
00056     "incorrect number of spectral components");
00057   if (num_specs==1)
00058     planck_assert(multiequal(tsize(0),gg_.size(),cc_.size(),tg_.size(),
00059       tc_.size(),gc_.size()), "incorrect array sizes");
00060   if (num_specs==4)
00061     {
00062     planck_assert(multiequal(tt_.size(),gg_.size(),cc_.size(),tg_.size()),
00063       "incorrect array sizes");
00064     planck_assert(multiequal(tsize(0),tc_.size(),gc_.size()),
00065       "incorrect array sizes");
00066     }
00067   if (num_specs==6)
00068     planck_assert(multiequal(tt_.size(),gg_.size(),cc_.size(),tg_.size(),
00069       tc_.size(),gc_.size()), "incorrect array sizes");
00070   }
00071 
00072 bool PowSpec::consistentAutoPowspec() const
00073   {
00074   for (tsize l=0; l<tt_.size(); ++l)
00075     if (tt_[l]<0) return false;
00076   if (num_specs>=4)
00077     for (tsize l=0; l<tt_.size(); ++l)
00078       {
00079       if (gg_[l]<0) return false;
00080       if (cc_[l]<0) return false;
00081       if (abs(tg_[l])>sqrt(tt_[l]*gg_[l])) return false;
00082       }
00083   if (num_specs==6)
00084     for (tsize l=0; l<tt_.size(); ++l)
00085       {
00086       if (abs(tc_[l])>sqrt(tt_[l]*cc_[l])) return false;
00087       if (abs(gc_[l])>sqrt(gg_[l]*cc_[l])) return false;
00088       }
00089   return true;
00090   }
00091 
00092 void PowSpec::Set(int nspec, int lmax)
00093   {
00094   num_specs=nspec;
00095   planck_assert ((num_specs==1) || (num_specs==4) || (num_specs==6),
00096     "wrong number of spectrums");
00097   tt_.alloc(lmax+1);
00098   if (num_specs>1)
00099     {
00100     gg_.alloc(lmax+1);
00101     cc_.alloc(lmax+1);
00102     tg_.alloc(lmax+1);
00103     }
00104   if (num_specs>4)
00105     {
00106     tc_.alloc(lmax+1);
00107     gc_.alloc(lmax+1);
00108     }
00109   }
00110 
00111 void PowSpec::Set(arr<double> &tt_new)
00112   {
00113   dealloc();
00114   num_specs = 1;
00115   tt_.transfer(tt_new);
00116 //FIXME: temporarily relaxed to allow cross-spectra
00117   if (!consistentAutoPowspec())
00118     cerr << "Warning: negative values in TT spectrum" << endl;
00119   }
00120 
00121 void PowSpec::Set(arr<double> &tt_new, arr<double> &gg_new,
00122   arr<double> &cc_new, arr<double> &tg_new)
00123   {
00124   dealloc();
00125   num_specs = 4;
00126   tt_.transfer(tt_new); gg_.transfer(gg_new);
00127   cc_.transfer(cc_new); tg_.transfer(tg_new);
00128   assertArraySizes();
00129   }
00130 
00131 void PowSpec::Set(arr<double> &tt_new, arr<double> &gg_new, arr<double> &cc_new,
00132   arr<double> &tg_new, arr<double> &tc_new, arr<double> &gc_new)
00133   {
00134   Set (tt_new, gg_new, cc_new, tg_new);
00135   num_specs = 6;
00136   tc_.transfer(tc_new); gc_.transfer(gc_new);
00137   assertArraySizes();
00138   }
00139 
00140 void PowSpec::smoothWithGauss (double fwhm)
00141   {
00142   double sigma = fwhm*fwhm2sigma;
00143   double fact_pol = exp(2*sigma*sigma);
00144   for (tsize l=0; l<tt_.size(); ++l)
00145     {
00146     double f1 = exp(-.5*l*(l+1)*sigma*sigma);
00147     double f2 = f1*fact_pol;
00148     tt_[l] *= f1*f1;
00149     if (num_specs>1)
00150       {
00151       gg_[l] *= f2*f2;
00152       cc_[l] *= f2*f2;
00153       tg_[l] *= f1*f2;
00154       if (num_specs>4)
00155         {
00156         tc_[l] *= f1*f2;
00157         gc_[l] *= f2*f2;
00158         }
00159       }
00160     }
00161   }

Generated on Thu Oct 8 14:48:52 2015 for Healpix C++