Healpix C++  3.83
powspec.cc
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"
33 #include "lsconstants.h"
34 
35 using namespace std;
36 
37 void PowSpec::dealloc()
38  {
39  tt_.dealloc();
40  gg_.dealloc();
41  cc_.dealloc();
42  tg_.dealloc();
43  tc_.dealloc();
44  gc_.dealloc();
45  }
46 
47 PowSpec::PowSpec(int nspec, int lmax)
48  { Set(nspec,lmax); }
49 
50 PowSpec::~PowSpec()
51  {}
52 
54  {
55  planck_assert((num_specs==1) || (num_specs==4) || (num_specs==6),
56  "incorrect number of spectral components");
57  if (num_specs==1)
58  planck_assert(multiequal(tsize(0),gg_.size(),cc_.size(),tg_.size(),
59  tc_.size(),gc_.size()), "incorrect array sizes");
60  if (num_specs==4)
61  {
62  planck_assert(multiequal(tt_.size(),gg_.size(),cc_.size(),tg_.size()),
63  "incorrect array sizes");
64  planck_assert(multiequal(tsize(0),tc_.size(),gc_.size()),
65  "incorrect array sizes");
66  }
67  if (num_specs==6)
68  planck_assert(multiequal(tt_.size(),gg_.size(),cc_.size(),tg_.size(),
69  tc_.size(),gc_.size()), "incorrect array sizes");
70  }
71 
73  {
74  for (tsize l=0; l<tt_.size(); ++l)
75  if (tt_[l]<0) return false;
76  if (num_specs>=4)
77  for (tsize l=0; l<tt_.size(); ++l)
78  {
79  if (gg_[l]<0) return false;
80  if (cc_[l]<0) return false;
81  if (abs(tg_[l])>sqrt(tt_[l]*gg_[l])) return false;
82  }
83  if (num_specs==6)
84  for (tsize l=0; l<tt_.size(); ++l)
85  {
86  if (abs(tc_[l])>sqrt(tt_[l]*cc_[l])) return false;
87  if (abs(gc_[l])>sqrt(gg_[l]*cc_[l])) return false;
88  }
89  return true;
90  }
91 
92 void PowSpec::Set(int nspec, int lmax)
93  {
94  num_specs=nspec;
95  planck_assert ((num_specs==1) || (num_specs==4) || (num_specs==6),
96  "wrong number of spectrums");
97  tt_.alloc(lmax+1);
98  if (num_specs>1)
99  {
100  gg_.alloc(lmax+1);
101  cc_.alloc(lmax+1);
102  tg_.alloc(lmax+1);
103  }
104  if (num_specs>4)
105  {
106  tc_.alloc(lmax+1);
107  gc_.alloc(lmax+1);
108  }
109  }
110 
111 void PowSpec::Set(arr<double> &tt_new)
112  {
113  dealloc();
114  num_specs = 1;
115  tt_.transfer(tt_new);
116 //FIXME: temporarily relaxed to allow cross-spectra
117  if (!consistentAutoPowspec())
118  cerr << "Warning: negative values in TT spectrum" << endl;
119  }
120 
121 void PowSpec::Set(arr<double> &tt_new, arr<double> &gg_new,
122  arr<double> &cc_new, arr<double> &tg_new)
123  {
124  dealloc();
125  num_specs = 4;
126  tt_.transfer(tt_new); gg_.transfer(gg_new);
127  cc_.transfer(cc_new); tg_.transfer(tg_new);
128  assertArraySizes();
129  }
130 
131 void PowSpec::Set(arr<double> &tt_new, arr<double> &gg_new, arr<double> &cc_new,
132  arr<double> &tg_new, arr<double> &tc_new, arr<double> &gc_new)
133  {
134  Set (tt_new, gg_new, cc_new, tg_new);
135  num_specs = 6;
136  tc_.transfer(tc_new); gc_.transfer(gc_new);
137  assertArraySizes();
138  }
139 
140 void PowSpec::smoothWithGauss (double fwhm)
141  {
142  double sigma = fwhm*fwhm2sigma;
143  double fact_pol = exp(2*sigma*sigma);
144  for (tsize l=0; l<tt_.size(); ++l)
145  {
146  double f1 = exp(-.5*l*(l+1)*sigma*sigma);
147  double f2 = f1*fact_pol;
148  tt_[l] *= f1*f1;
149  if (num_specs>1)
150  {
151  gg_[l] *= f2*f2;
152  cc_[l] *= f2*f2;
153  tg_[l] *= f1*f2;
154  if (num_specs>4)
155  {
156  tc_[l] *= f1*f2;
157  gc_[l] *= f2*f2;
158  }
159  }
160  }
161  }
void Set(int nspec, int lmax)
Definition: powspec.cc:92
void smoothWithGauss(double fwhm)
Definition: powspec.cc:140
void assertArraySizes() const
Definition: powspec.cc:53
bool consistentAutoPowspec() const
Definition: powspec.cc:72

Generated on Wed Nov 13 2024 12:18:30 for Healpix C++