| 1 | //  Class examples to generate mass distribution | 
|---|
| 2 | // R.A. for A. Abate , Nov. 2008 | 
|---|
| 3 |  | 
|---|
| 4 | #ifndef SPECPK_SEEN | 
|---|
| 5 | #define SPECPK_SEEN | 
|---|
| 6 |  | 
|---|
| 7 | #include "machdefs.h" | 
|---|
| 8 | #include "sopnamsp.h" | 
|---|
| 9 | #include <math.h> | 
|---|
| 10 | #include <iostream> | 
|---|
| 11 | #include <vector> | 
|---|
| 12 | #include <string> | 
|---|
| 13 |  | 
|---|
| 14 | #include "genericfunc.h" | 
|---|
| 15 | #include "array.h" | 
|---|
| 16 | #include "histats.h" | 
|---|
| 17 | #include "fftwserver.h" | 
|---|
| 18 | #include "randinterf.h" | 
|---|
| 19 |  | 
|---|
| 20 | #include "mdish.h" | 
|---|
| 21 |  | 
|---|
| 22 | #define DeuxPI 2.*M_PI | 
|---|
| 23 |  | 
|---|
| 24 | // -- SpectralShape class : test P(k) class | 
|---|
| 25 | class SpectralShape : public GenericFunc { | 
|---|
| 26 | public: | 
|---|
| 27 | SpectralShape(int typ); | 
|---|
| 28 | // Return the value of power spectrum for wave number wk | 
|---|
| 29 | virtual double operator() (double wk); | 
|---|
| 30 | inline  double Value(double wk) { return((*this)(wk)); } | 
|---|
| 31 | // Return a vector representing the power spectrum (for checking) | 
|---|
| 32 | Histo GetPk(int n=256); | 
|---|
| 33 | double Sommek2Pk(double kmax=1000., int n=5000); | 
|---|
| 34 | inline void SetRenormFac(double f=1.) { renorm_fac=f; } | 
|---|
| 35 | int typ_; | 
|---|
| 36 | double renorm_fac; | 
|---|
| 37 | }; | 
|---|
| 38 |  | 
|---|
| 39 |  | 
|---|
| 40 | #define TF  r_4 | 
|---|
| 41 |  | 
|---|
| 42 | // -- Four3DPk class :  3D fourier amplitudes and power spectrum | 
|---|
| 43 | class Four3DPk { | 
|---|
| 44 | public: | 
|---|
| 45 | // Constructor | 
|---|
| 46 | Four3DPk(TArray< complex<TF> > & fourcoedd, RandomGeneratorInterface& rg); | 
|---|
| 47 | Four3DPk(RandomGeneratorInterface& rg, sa_size_t szx=128, sa_size_t szy=256, sa_size_t szz=128); | 
|---|
| 48 | inline void SetCellSize(double dkx=DeuxPI, double dky=DeuxPI, double dkz=DeuxPI) | 
|---|
| 49 | { dkx_=dkx;  dky_=dky;  dkz_=dkz; } | 
|---|
| 50 | inline int SetPrtLevel(int lev=0, int prtmod=10) | 
|---|
| 51 | { int olev=prtlev_; prtlev_=lev; prtmodulo_=prtmod; return olev; } | 
|---|
| 52 | void ComputeFourierAmp(SpectralShape& pk); | 
|---|
| 53 | void ComputeNoiseFourierAmp(Four2DResponse& resp, bool crmask=false); | 
|---|
| 54 | // Return the array size | 
|---|
| 55 | inline sa_size_t NCells() { return fourAmp.Size(); } | 
|---|
| 56 | // Set the cell size/step in Fourier Space | 
|---|
| 57 | // Return the fourier amplitude matrix | 
|---|
| 58 | TArray< complex<TF> > GetFourierAmp() | 
|---|
| 59 | { return fourAmp; } | 
|---|
| 60 | // Return the mass density matrix | 
|---|
| 61 | TArray<TF> ComputeMassDens(); | 
|---|
| 62 |  | 
|---|
| 63 | // Return the reconstructed power spectrum as a profile histogram | 
|---|
| 64 | HProf ComputePk(double s2cut=0., int nbin=256, double kmin=0., double kmax=-1.); | 
|---|
| 65 | void  ComputePkCumul(HProf& hp, double s2cut=0.); | 
|---|
| 66 |  | 
|---|
| 67 | HProf ComputeNoisePk(Four2DResponse& resp, Histo& fracmodok, DataTable& dt, | 
|---|
| 68 | double s2cut=0., int nbin=256, double kmin=0., double kmax=-1.); | 
|---|
| 69 |  | 
|---|
| 70 | protected: | 
|---|
| 71 | // member attribute | 
|---|
| 72 | RandomGeneratorInterface& rg_; | 
|---|
| 73 | TArray< complex<TF> > fourAmp;  // complex array of fourier coefficients | 
|---|
| 74 | double dkx_, dky_, dkz_; | 
|---|
| 75 | int prtlev_; | 
|---|
| 76 | int prtmodulo_; | 
|---|
| 77 | }; | 
|---|
| 78 |  | 
|---|
| 79 | // --- PkNoiseCalculator : | 
|---|
| 80 | // - Classe de calcul du spectre de bruit PNoise(k) determine par une reponse | 
|---|
| 81 | //   2D de l'instrument | 
|---|
| 82 | class PkNoiseCalculator | 
|---|
| 83 | { | 
|---|
| 84 | public: | 
|---|
| 85 | PkNoiseCalculator(Four3DPk& pk3, Four2DResponse& rep, double s2cut=100., int ngen=1, const char* tit="PkNoise"); | 
|---|
| 86 |  | 
|---|
| 87 | inline void SetS2Cut(double s2cut=100.) | 
|---|
| 88 | {  S2CUT=s2cut; } | 
|---|
| 89 | inline double GetS2Cut() { return S2CUT; } | 
|---|
| 90 | HProf Compute(); | 
|---|
| 91 | inline int SetPrtLevel(int lev=0, int prtmod=10) | 
|---|
| 92 | { int olev=prtlev_; prtlev_=lev; prtmodulo_=prtmod; return olev; } | 
|---|
| 93 |  | 
|---|
| 94 | protected: | 
|---|
| 95 | Four3DPk& pkn3d; | 
|---|
| 96 | Four2DResponse& frep; | 
|---|
| 97 | double S2CUT; | 
|---|
| 98 | int NGEN; | 
|---|
| 99 | string title; | 
|---|
| 100 | int prtlev_; | 
|---|
| 101 | int prtmodulo_; | 
|---|
| 102 | }; | 
|---|
| 103 |  | 
|---|
| 104 |  | 
|---|
| 105 |  | 
|---|
| 106 | // -- MassDist2D class :  2D mass distribution | 
|---|
| 107 | class MassDist2D { | 
|---|
| 108 | public: | 
|---|
| 109 | // Constructor | 
|---|
| 110 | MassDist2D(GenericFunc& pk, int size=1024, double meandens=1.); | 
|---|
| 111 | // Do the computation | 
|---|
| 112 | void Compute(); | 
|---|
| 113 | // Return the array size | 
|---|
| 114 | inline sa_size_t ArrSize() { return sizeA; } | 
|---|
| 115 | // Return the fourier amplitude matrix | 
|---|
| 116 | TMatrix< complex<r_8> > GetFourierAmp() | 
|---|
| 117 | { if (!fg_fourAmp) ComputeFourierAmp(); return fourAmp; } | 
|---|
| 118 | // Return the mass density matrix | 
|---|
| 119 | Matrix GetMassDens() | 
|---|
| 120 | { if (!fg_massDens) ComputeMassDens(); return massDens; } | 
|---|
| 121 |  | 
|---|
| 122 | // Return the reconstructed power spectrum as a profile histogram | 
|---|
| 123 | HProf ReconstructPk(int nbin=0); | 
|---|
| 124 | protected: | 
|---|
| 125 | void ComputeFourierAmp(); | 
|---|
| 126 | void ComputeMassDens(); | 
|---|
| 127 |  | 
|---|
| 128 | // member attribute | 
|---|
| 129 | GenericFunc& pkSpec;   // The spectralShape | 
|---|
| 130 | sa_size_t sizeA;       // 2D array size | 
|---|
| 131 | double meanRho;       // Mean Density | 
|---|
| 132 | bool fg_fourAmp;  // true -> fourAmp computed | 
|---|
| 133 | TMatrix< complex<r_8> > fourAmp;  // complex array of fourier coefficients | 
|---|
| 134 | bool fg_massDens;  // true -> MassDens computed | 
|---|
| 135 | TMatrix< r_8 > massDens;      // real array of d rho/rho | 
|---|
| 136 | }; | 
|---|
| 137 |  | 
|---|
| 138 |  | 
|---|
| 139 | #endif | 
|---|