powspec.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
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 }