| 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 |   virtual ~Four3DPk(); 
 | 
|---|
| 49 | 
 | 
|---|
| 50 |   inline void SetCellSize(double dkx=DeuxPI, double dky=DeuxPI, double dkz=DeuxPI) 
 | 
|---|
| 51 |   { dkx_=dkx;  dky_=dky;  dkz_=dkz; } 
 | 
|---|
| 52 |   inline int SetPrtLevel(int lev=0, int prtmod=10) 
 | 
|---|
| 53 |   { int olev=prtlev_; prtlev_=lev; prtmodulo_=prtmod; return olev; }
 | 
|---|
| 54 |   void ComputeFourierAmp(SpectralShape& pk);
 | 
|---|
| 55 | // angscale is a multiplicative factor converting transverse k (wave number) values to angular wave numbers 
 | 
|---|
| 56 | // typically = ComovRadialDistance 
 | 
|---|
| 57 |   void ComputeNoiseFourierAmp(Four2DResponse& resp, double angscale=1., bool crmask=false);
 | 
|---|
| 58 |   void ComputeNoiseFourierAmp(Four2DResponse& resp, double f0, double df, Vector& angscales, Vector& noisp);
 | 
|---|
| 59 | 
 | 
|---|
| 60 | // Return the array size 
 | 
|---|
| 61 |   inline sa_size_t NCells() { return fourAmp.Size(); }
 | 
|---|
| 62 |   inline sa_size_t SizeX() { return fourAmp.SizeX(); }
 | 
|---|
| 63 |   inline sa_size_t SizeY() { return fourAmp.SizeY(); }
 | 
|---|
| 64 |   inline sa_size_t SizeZ() { return fourAmp.SizeZ(); }
 | 
|---|
| 65 | 
 | 
|---|
| 66 | // Set the cell size/step in Fourier Space
 | 
|---|
| 67 | // Return the fourier amplitude matrix  
 | 
|---|
| 68 |   TArray< complex<TF> > GetFourierAmp()
 | 
|---|
| 69 |     { return fourAmp; }
 | 
|---|
| 70 | // Return the mass density matrix    
 | 
|---|
| 71 |   TArray<TF> ComputeMassDens(); 
 | 
|---|
| 72 | 
 | 
|---|
| 73 | // Return the reconstructed power spectrum as a profile histogram   
 | 
|---|
| 74 |   HProf ComputePk(double s2cut=0., int nbin=256, double kmin=0., double kmax=-1., bool fgmodcnt=false);
 | 
|---|
| 75 |   void  ComputePkCumul();
 | 
|---|
| 76 | 
 | 
|---|
| 77 | // angscale is a multiplicative factor converting transverse k (wave number) values to angular wave numbers 
 | 
|---|
| 78 | // typically = ComovRadialDistance 
 | 
|---|
| 79 |   HProf ComputeNoisePk(Four2DResponse& resp, double angscale=1., double s2cut=0., 
 | 
|---|
| 80 |                        int nbin=256, double kmin=0., double kmax=-1.);
 | 
|---|
| 81 | 
 | 
|---|
| 82 |   // Fills a data table from the computed P(k) profile histogram and mode count 
 | 
|---|
| 83 |   Histo FillPkDataTable(DataTable& dt);
 | 
|---|
| 84 |   inline HProf& GetPk() { return *hp_pk_p_; }
 | 
|---|
| 85 | 
 | 
|---|
| 86 | protected:
 | 
|---|
| 87 |   // member attribute
 | 
|---|
| 88 |   RandomGeneratorInterface& rg_;
 | 
|---|
| 89 |   TArray< complex<TF> > fourAmp;  // complex array of fourier coefficients
 | 
|---|
| 90 |   double dkx_, dky_, dkz_;
 | 
|---|
| 91 |   int prtlev_;
 | 
|---|
| 92 |   int prtmodulo_;
 | 
|---|
| 93 |   // Profile histograms for power spectrum and number of modes 
 | 
|---|
| 94 |   HProf* hp_pk_p_;
 | 
|---|
| 95 |   Histo* hmcnt_p_;
 | 
|---|
| 96 |   Histo* hmcntok_p_;
 | 
|---|
| 97 |   double s2cut_;
 | 
|---|
| 98 | };
 | 
|---|
| 99 | 
 | 
|---|
| 100 | // --- PkNoiseCalculator : 
 | 
|---|
| 101 | // - Classe de calcul du spectre de bruit PNoise(k) determine par une reponse
 | 
|---|
| 102 | //   2D de l'instrument 
 | 
|---|
| 103 | class PkNoiseCalculator
 | 
|---|
| 104 | {
 | 
|---|
| 105 | public:
 | 
|---|
| 106 |   PkNoiseCalculator(Four3DPk& pk3, Four2DResponse& rep, double s2cut=100., int ngen=1, const char* tit="PkNoise");
 | 
|---|
| 107 |   
 | 
|---|
| 108 |   inline void SetFreqRange(double freq0=835.,double dfreq=0.5)
 | 
|---|
| 109 |   { freq0_=freq0;  dfreq_=dfreq; }
 | 
|---|
| 110 |   inline void SetAngScaleConversion(double angscale=1.)
 | 
|---|
| 111 |   { angscales_=angscale; }
 | 
|---|
| 112 |   inline void SetAngScaleConversion(Vector& angscs)
 | 
|---|
| 113 |   { angscales_=angscs; }
 | 
|---|
| 114 |   inline void SetPNoiseFactor(double pnoisef=1.)
 | 
|---|
| 115 |   { pnoisefac_=pnoisef; }
 | 
|---|
| 116 |   inline void SetPNoiseFactor(Vector& pnoisefac)
 | 
|---|
| 117 |   { pnoisefac_=pnoisefac; }
 | 
|---|
| 118 |   inline void SetS2Cut(double s2cut=100.)
 | 
|---|
| 119 |   {  S2CUT=s2cut; }
 | 
|---|
| 120 |   inline double GetS2Cut() { return S2CUT; }
 | 
|---|
| 121 |   HProf Compute(int nbin=256, double kmin=0., double kmax=-1.);
 | 
|---|
| 122 |   inline int SetPrtLevel(int lev=0, int prtmod=10) 
 | 
|---|
| 123 |   { int olev=prtlev_; prtlev_=lev; prtmodulo_=prtmod; return olev; }
 | 
|---|
| 124 | 
 | 
|---|
| 125 | protected:
 | 
|---|
| 126 |   Four3DPk& pkn3d;
 | 
|---|
| 127 |   Four2DResponse& frep;
 | 
|---|
| 128 |   double freq0_,dfreq_;
 | 
|---|
| 129 |   Vector angscales_; 
 | 
|---|
| 130 |   Vector pnoisefac_; 
 | 
|---|
| 131 |   double S2CUT;
 | 
|---|
| 132 |   int NGEN;
 | 
|---|
| 133 |   string title;
 | 
|---|
| 134 |   int prtlev_;
 | 
|---|
| 135 |   int prtmodulo_;
 | 
|---|
| 136 | };
 | 
|---|
| 137 | 
 | 
|---|
| 138 | 
 | 
|---|
| 139 | 
 | 
|---|
| 140 | // -- MassDist2D class :  2D mass distribution 
 | 
|---|
| 141 | class MassDist2D {
 | 
|---|
| 142 | public:
 | 
|---|
| 143 | // Constructor
 | 
|---|
| 144 |   MassDist2D(GenericFunc& pk, int size=1024, double meandens=1.);
 | 
|---|
| 145 | // Do the computation 
 | 
|---|
| 146 |   void Compute();
 | 
|---|
| 147 | // Return the array size 
 | 
|---|
| 148 |   inline sa_size_t ArrSize() { return sizeA; }
 | 
|---|
| 149 | // Return the fourier amplitude matrix  
 | 
|---|
| 150 |   TMatrix< complex<r_8> > GetFourierAmp()
 | 
|---|
| 151 |     { if (!fg_fourAmp) ComputeFourierAmp(); return fourAmp; }
 | 
|---|
| 152 | // Return the mass density matrix    
 | 
|---|
| 153 |   Matrix GetMassDens()
 | 
|---|
| 154 |     { if (!fg_massDens) ComputeMassDens(); return massDens; }
 | 
|---|
| 155 | 
 | 
|---|
| 156 | // Return the reconstructed power spectrum as a profile histogram   
 | 
|---|
| 157 |   HProf ReconstructPk(int nbin=0);
 | 
|---|
| 158 | protected:
 | 
|---|
| 159 |   void ComputeFourierAmp();
 | 
|---|
| 160 |   void ComputeMassDens();
 | 
|---|
| 161 |   
 | 
|---|
| 162 | // member attribute
 | 
|---|
| 163 |   GenericFunc& pkSpec;   // The spectralShape
 | 
|---|
| 164 |   sa_size_t sizeA;       // 2D array size
 | 
|---|
| 165 |   double meanRho;       // Mean Density
 | 
|---|
| 166 |   bool fg_fourAmp;  // true -> fourAmp computed 
 | 
|---|
| 167 |   TMatrix< complex<r_8> > fourAmp;  // complex array of fourier coefficients
 | 
|---|
| 168 |   bool fg_massDens;  // true -> MassDens computed 
 | 
|---|
| 169 |   TMatrix< r_8 > massDens;      // real array of d rho/rho 
 | 
|---|
| 170 | };
 | 
|---|
| 171 | 
 | 
|---|
| 172 | 
 | 
|---|
| 173 | #endif 
 | 
|---|