| 1 | /* |
| 2 | * This file is part of Healpix_cxx. |
| 3 | * |
| 4 | * Healpix_cxx is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * Healpix_cxx is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with Healpix_cxx; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | * |
| 18 | * For more information about HEALPix, see http://healpix.sourceforge.net |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik |
| 23 | * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt |
| 24 | * (DLR). |
| 25 | */ |
| 26 | |
| 27 | /* |
| 28 | * Copyright (C) 2003-2015 Max-Planck-Society |
| 29 | * Author: Martin Reinecke |
| 30 | */ |
| 31 | |
| 32 | #include "powspec.h"cxx . . $ `<file>/Healpix_cxx/powspec.h`/ |
| 33 | #include "lsconstants.h"cxx . . $ `<file>/cxxsupport/lsconstants.h`/ |
| 34 | |
| 35 | using namespace std; |
| 36 | |
| 37 | void PowSpeccxx . . $ PowSpec#::dealloccxx . . $ PowSpec#dealloc(49f6e7a06ebc5aa8).() |
| 38 | { |
| 39 | tt_cxx . . $ PowSpec#tt_..dealloccxx . . $ arrT#dealloc(49f6e7a06ebc5aa8).(); |
| 40 | gg_cxx . . $ PowSpec#gg_..dealloccxx . . $ arrT#dealloc(49f6e7a06ebc5aa8).(); |
| 41 | cc_cxx . . $ PowSpec#cc_..dealloccxx . . $ arrT#dealloc(49f6e7a06ebc5aa8).(); |
| 42 | tg_cxx . . $ PowSpec#tg_..dealloccxx . . $ arrT#dealloc(49f6e7a06ebc5aa8).(); |
| 43 | tc_cxx . . $ PowSpec#tc_..dealloccxx . . $ arrT#dealloc(49f6e7a06ebc5aa8).(); |
| 44 | gc_cxx . . $ PowSpec#gc_..dealloccxx . . $ arrT#dealloc(49f6e7a06ebc5aa8).(); |
| 45 | } |
| 46 | |
| 47 | PowSpeccxx . . $ PowSpec#::PowSpeccxx . . $ PowSpec#PowSpec(3e454b8ccf442868).(int nspec, int lmax) |
| 48 | { Setcxx . . $ PowSpec#Set(3e454b8ccf442868).(nspec,lmax); } |
| 49 | |
| 50 | PowSpeccxx . . $ PowSpec#::~cxx . . $ PowSpec#`~PowSpec`(ced63f7c635d850d).PowSpeccxx . . $ PowSpec#() |
| 51 | {} |
| 52 | |
| 53 | void PowSpeccxx . . $ PowSpec#::assertArraySizescxx . . $ PowSpec#assertArraySizes(83f5f38750778ac8).() const |
| 54 | { |
| 55 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`!((num_specs==1) || (num_specs==4) || (num_specs==6), |
| 56 | "incorrect number of spectral components"); |
| 57 | if (num_specscxx . . $ PowSpec#num_specs.==1) |
| 58 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`!(multiequal(tsize(0),gg_.size(),cc_.size(),tg_.size(), |
| 59 | tc_.size(),gc_.size()), "incorrect array sizes"); |
| 60 | if (num_specscxx . . $ PowSpec#num_specs.==4) |
| 61 | { |
| 62 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`!(multiequal(tt_.size(),gg_.size(),cc_.size(),tg_.size()), |
| 63 | "incorrect array sizes"); |
| 64 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`!(multiequal(tsize(0),tc_.size(),gc_.size()), |
| 65 | "incorrect array sizes"); |
| 66 | } |
| 67 | if (num_specscxx . . $ PowSpec#num_specs.==6) |
| 68 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`!(multiequal(tt_.size(),gg_.size(),cc_.size(),tg_.size(), |
| 69 | tc_.size(),gc_.size()), "incorrect array sizes"); |
| 70 | } |
| 71 | |
| 72 | bool PowSpeccxx . . $ PowSpec#::consistentAutoPowspeccxx . . $ PowSpec#consistentAutoPowspec(50ce9a9e25b4a850).() const |
| 73 | { |
| 74 | for (tsizecxx . . $ tsize# l=0; l<tt_cxx . . $ PowSpec#tt_..sizecxx . . $ arr_ref#size(fe4d2d262d4164a8).(); ++l) |
| 75 | if (tt_cxx . . $ PowSpec#tt_.[cxx . . $ arr_ref#`operator[]`(8b9804babe762405).l]<0) return false; |
| 76 | if (num_specscxx . . $ PowSpec#num_specs.>=4) |
| 77 | for (tsizecxx . . $ tsize# l=0; l<tt_cxx . . $ PowSpec#tt_..sizecxx . . $ arr_ref#size(fe4d2d262d4164a8).(); ++l) |
| 78 | { |
| 79 | if (gg_cxx . . $ PowSpec#gg_.[cxx . . $ arr_ref#`operator[]`(8b9804babe762405).l]<0) return false; |
| 80 | if (cc_cxx . . $ PowSpec#cc_.[cxx . . $ arr_ref#`operator[]`(8b9804babe762405).l]<0) return false; |
| 81 | if (abs(tg_cxx . . $ PowSpec#tg_.[cxx . . $ arr_ref#`operator[]`(8b9804babe762405).l])>sqrt(tt_cxx . . $ PowSpec#tt_.[cxx . . $ arr_ref#`operator[]`(8b9804babe762405).l]*gg_cxx . . $ PowSpec#gg_.[cxx . . $ arr_ref#`operator[]`(8b9804babe762405).l])) return false; |
| 82 | } |
| 83 | if (num_specscxx . . $ PowSpec#num_specs.==6) |
| 84 | for (tsizecxx . . $ tsize# l=0; l<tt_cxx . . $ PowSpec#tt_..sizecxx . . $ arr_ref#size(fe4d2d262d4164a8).(); ++l) |
| 85 | { |
| 86 | if (abs(tc_cxx . . $ PowSpec#tc_.[cxx . . $ arr_ref#`operator[]`(8b9804babe762405).l])>sqrt(tt_cxx . . $ PowSpec#tt_.[cxx . . $ arr_ref#`operator[]`(8b9804babe762405).l]*cc_cxx . . $ PowSpec#cc_.[cxx . . $ arr_ref#`operator[]`(8b9804babe762405).l])) return false; |
| 87 | if (abs(gc_cxx . . $ PowSpec#gc_.[cxx . . $ arr_ref#`operator[]`(8b9804babe762405).l])>sqrt(gg_cxx . . $ PowSpec#gg_.[cxx . . $ arr_ref#`operator[]`(8b9804babe762405).l]*cc_cxx . . $ PowSpec#cc_.[cxx . . $ arr_ref#`operator[]`(8b9804babe762405).l])) return false; |
| 88 | } |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | void PowSpeccxx . . $ PowSpec#::Setcxx . . $ PowSpec#Set(3e454b8ccf442868).(int nspec, int lmax) |
| 93 | { |
| 94 | num_specscxx . . $ PowSpec#num_specs.=nspec; |
| 95 | planck_assertcxx . . $ `cxxsupport/error_handling.h:79:9`! ((num_specs==1) || (num_specs==4) || (num_specs==6), |
| 96 | "wrong number of spectrums"); |
| 97 | tt_cxx . . $ PowSpec#tt_..alloccxx . . $ arrT#alloc(2c44cd906ae4e829).(lmax+1); |
| 98 | if (num_specscxx . . $ PowSpec#num_specs.>1) |
| 99 | { |
| 100 | gg_cxx . . $ PowSpec#gg_..alloccxx . . $ arrT#alloc(2c44cd906ae4e829).(lmax+1); |
| 101 | cc_cxx . . $ PowSpec#cc_..alloccxx . . $ arrT#alloc(2c44cd906ae4e829).(lmax+1); |
| 102 | tg_cxx . . $ PowSpec#tg_..alloccxx . . $ arrT#alloc(2c44cd906ae4e829).(lmax+1); |
| 103 | } |
| 104 | if (num_specscxx . . $ PowSpec#num_specs.>4) |
| 105 | { |
| 106 | tc_cxx . . $ PowSpec#tc_..alloccxx . . $ arrT#alloc(2c44cd906ae4e829).(lmax+1); |
| 107 | gc_cxx . . $ PowSpec#gc_..alloccxx . . $ arrT#alloc(2c44cd906ae4e829).(lmax+1); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | void PowSpeccxx . . $ PowSpec#::Setcxx . . $ PowSpec#Set(2521c29848e43f5d).(arrcxx . . $ arr#<double> &tt_new) |
| 112 | { |
| 113 | dealloccxx . . $ PowSpec#dealloc(49f6e7a06ebc5aa8).(); |
| 114 | num_specscxx . . $ PowSpec#num_specs. = 1; |
| 115 | tt_cxx . . $ PowSpec#tt_..transfercxx . . $ arrT#transfer(e78c6dd6d6820bc0).(tt_new); |
| 116 | //FIXME: temporarily relaxed to allow cross-spectra |
| 117 | if (!consistentAutoPowspeccxx . . $ PowSpec#consistentAutoPowspec(50ce9a9e25b4a850).()) |
| 118 | cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Warning: negative values in TT spectrum" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 119 | } |
| 120 | |
| 121 | void PowSpeccxx . . $ PowSpec#::Setcxx . . $ PowSpec#Set(2d679bf1e16595e8).(arrcxx . . $ arr#<double> &tt_new, arrcxx . . $ arr#<double> &gg_new, |
| 122 | arrcxx . . $ arr#<double> &cc_new, arrcxx . . $ arr#<double> &tg_new) |
| 123 | { |
| 124 | dealloccxx . . $ PowSpec#dealloc(49f6e7a06ebc5aa8).(); |
| 125 | num_specscxx . . $ PowSpec#num_specs. = 4; |
| 126 | tt_cxx . . $ PowSpec#tt_..transfercxx . . $ arrT#transfer(e78c6dd6d6820bc0).(tt_new); gg_cxx . . $ PowSpec#gg_..transfercxx . . $ arrT#transfer(e78c6dd6d6820bc0).(gg_new); |
| 127 | cc_cxx . . $ PowSpec#cc_..transfercxx . . $ arrT#transfer(e78c6dd6d6820bc0).(cc_new); tg_cxx . . $ PowSpec#tg_..transfercxx . . $ arrT#transfer(e78c6dd6d6820bc0).(tg_new); |
| 128 | assertArraySizescxx . . $ PowSpec#assertArraySizes(83f5f38750778ac8).(); |
| 129 | } |
| 130 | |
| 131 | void PowSpeccxx . . $ PowSpec#::Setcxx . . $ PowSpec#Set(870091046dc3355b).(arrcxx . . $ arr#<double> &tt_new, arrcxx . . $ arr#<double> &gg_new, arrcxx . . $ arr#<double> &cc_new, |
| 132 | arrcxx . . $ arr#<double> &tg_new, arrcxx . . $ arr#<double> &tc_new, arrcxx . . $ arr#<double> &gc_new) |
| 133 | { |
| 134 | Setcxx . . $ PowSpec#Set(2d679bf1e16595e8). (tt_new, gg_new, cc_new, tg_new); |
| 135 | num_specscxx . . $ PowSpec#num_specs. = 6; |
| 136 | tc_cxx . . $ PowSpec#tc_..transfercxx . . $ arrT#transfer(e78c6dd6d6820bc0).(tc_new); gc_cxx . . $ PowSpec#gc_..transfercxx . . $ arrT#transfer(e78c6dd6d6820bc0).(gc_new); |
| 137 | assertArraySizescxx . . $ PowSpec#assertArraySizes(83f5f38750778ac8).(); |
| 138 | } |
| 139 | |
| 140 | void PowSpeccxx . . $ PowSpec#::smoothWithGausscxx . . $ PowSpec#smoothWithGauss(ba8836b59fb42830). (double fwhm) |
| 141 | { |
| 142 | double sigma = fwhm*fwhm2sigmacxx . . $ fwhm2sigma.; |
| 143 | double fact_pol = exp(2*sigma*sigma); |
| 144 | for (tsizecxx . . $ tsize# l=0; l<tt_cxx . . $ PowSpec#tt_..sizecxx . . $ arr_ref#size(fe4d2d262d4164a8).(); ++l) |
| 145 | { |
| 146 | double f1 = exp(-.5*l*(l+1)*sigma*sigma); |
| 147 | double f2 = f1*fact_pol; |
| 148 | tt_cxx . . $ PowSpec#tt_.[cxx . . $ arr_ref#`operator[]`(b190d49faf30c5be).l] *= f1*f1; |
| 149 | if (num_specscxx . . $ PowSpec#num_specs.>1) |
| 150 | { |
| 151 | gg_cxx . . $ PowSpec#gg_.[cxx . . $ arr_ref#`operator[]`(b190d49faf30c5be).l] *= f2*f2; |
| 152 | cc_cxx . . $ PowSpec#cc_.[cxx . . $ arr_ref#`operator[]`(b190d49faf30c5be).l] *= f2*f2; |
| 153 | tg_cxx . . $ PowSpec#tg_.[cxx . . $ arr_ref#`operator[]`(b190d49faf30c5be).l] *= f1*f2; |
| 154 | if (num_specscxx . . $ PowSpec#num_specs.>4) |
| 155 | { |
| 156 | tc_cxx . . $ PowSpec#tc_.[cxx . . $ arr_ref#`operator[]`(b190d49faf30c5be).l] *= f1*f2; |
| 157 | gc_cxx . . $ PowSpec#gc_.[cxx . . $ arr_ref#`operator[]`(b190d49faf30c5be).l] *= f2*f2; |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | } |