source: Sophya/trunk/Cosmo/RadioBeam/calcpk.cc@ 4053

Last change on this file since 4053 was 3973, checked in by ansari, 14 years ago

Corrections diverses: choix lobe gaussien/triangle et specif DishDiameter au lieu de DoL ds applobe/calcpk2, possibilite application lobe freq.independante ds applobe, Reza 18/04/2011

File size: 3.9 KB
RevLine 
[3783]1/* ------------------------ Projet BAORadio --------------------
2 Programme de calcul du spectre de puissance (3D) a partir d'un
3 cube de donnees (delta rho/rho ou delta T/T)
4 R. Ansari , C. Magneville - Juin 2010
5
6 Usage: calcpk In3DMap OutPk [InRenormFactor]
7--------------------------------------------------------------- */
8
9#include "machdefs.h"
10#include "sopnamsp.h"
11#include <iostream>
12#include <string>
13#include <math.h>
14
15#include <typeinfo>
16
17#include "specpk.h"
18#include "histats.h"
19
20#include "qhist.h"
[3787]21#include "lobe.h"
[3789]22#include "cubedef.h"
[3787]23
[3783]24#include "histinit.h"
25#include "fftwserver.h"
26#include "randr48.h"
27
28#include "ctimer.h"
29
30typedef ThSDR48RandGen RandomGenerator ;
31
32//-------------------------------------------------------------------------
33// ------------------ MAIN PROGRAM ------------------------------
34//-------------------------------------------------------------------------
35int main(int narg, const char* arg[])
36{
37 if (narg<3) {
[3829]38 cout << " Usage: calcpk In3DMap_PPFName OutPk_PPFName [InRenormFactor] [PixNoiseLevel] [Four3D_PPFName]" << endl;
[3783]39 return 1;
40 }
41 Timer tm("calcpk");
42 int rc = 0;
43 try {
44 string inppfname = arg[1];
45 string outname = arg[2];
[3787]46 double renfact=1.;
[3783]47 bool fgrenfact=false;
48 if (narg>3) {
49 renfact=atof(arg[3]);
50 fgrenfact=true;
51 }
[3787]52 double pixsignoise = 0.;
53 bool fgaddnoise=false;
54 if (narg>4) {
[3825]55 pixsignoise=atof(arg[4]);
[3829]56 if (pixsignoise>1.e-9) fgaddnoise=true;
[3787]57 }
[3829]58 bool fgsavef3d=false;
59 string outf3dname="four3d.ppf";
60 if (narg>5) {
61 outf3dname=arg[5];
62 fgsavef3d=true;
63 }
[3787]64
[3829]65
[3783]66 cout << "calcpk[1] : reading 3D map from file " << inppfname << endl;
67 TArray<r_4> inmap;
68 {
69 PInPersist pin(inppfname);
70 pin >> inmap;
71 }
[3787]72 if (fgrenfact) {
73 cout << " Applying RenormFactor inmap = inmap*rfact, rfact=" << renfact << endl;
74 inmap *= renfact;
75 }
[3783]76 double mean, sigma;
77 MeanSigma(inmap, mean, sigma);
78 cout << " InMap sizes " << inmap.InfoString() << endl;
79 inmap.Show();
80 cout << " Mean=" << mean << " Sigma=" << sigma << endl;
[3787]81 if (fgaddnoise) {
82 BeamEffect::AddNoise(inmap, pixsignoise);
83 }
84
[3783]85 tm.Split(" After read ");
86
87 cout << "calcpk[2] : computing 3D Fourier coefficients ... " << endl;
88 FFTWServer ffts;
89 TArray< complex<r_4> > four3d;
90 ffts.FFTForward(inmap, four3d);
[3829]91 cout << " calcpk[2.b] inmap.Norm2()=" << inmap.Norm2() << " four3d.Norm2()=" << four3d.Norm2() << endl;
92
[3783]93 tm.Split(" After FFTForward ");
94
95 cout << "calcpk[3] : computing power spectrum ... " << endl;
96 RandomGenerator rg;
97 Four3DPk pkc(four3d, rg);
[3789]98 double dkxmpc = DeuxPI/(double)inmap.SizeX()/XCellSizeMpc;
99 double dkympc = DeuxPI/(double)inmap.SizeY()/YCellSizeMpc;
100 double dkzmpc = DeuxPI/(double)inmap.SizeZ()/ZCellSizeMpc;
101 pkc.SetCellSize(dkxmpc, dkympc, dkzmpc);
102
[3829]103
[3973]104 HProf hp = pkc.ComputePk(0.,HPk_NBin);
[3783]105 {
106 cout << "calcpk[4] : writing profile P(k) to PPF file " << outname << endl;
107 POutPersist po(outname);
108 po << hp;
[3829]109 }
110 if (fgsavef3d) {
111 cout << "calcpk[4.b] : writing four3d to PPF file " << outf3dname << endl;
112 POutPersist pof(outf3dname);
[3789]113 pof << four3d;
[3783]114 }
115 tm.Split(" Done CalcP(k) ");
116 } // End of try bloc
117 catch (PThrowable & exc) { // catching SOPHYA exceptions
118 cerr << " calcpk.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
119 << "\n...exc.Msg= " << exc.Msg() << endl;
120 rc = 99;
121 }
122 catch (std::exception & e) { // catching standard C++ exceptions
123 cerr << " calcpk.cc: Catched std::exception " << " - what()= " << e.what() << endl;
124 rc = 98;
125 }
126 catch (...) { // catching other exceptions
127 cerr << " calcpk.cc: some other exception (...) was caught ! " << endl;
128 rc = 97;
129 }
130 cout << " ==== End of calcpk.cc program Rc= " << rc << endl;
131 return rc;
132}
Note: See TracBrowser for help on using the repository browser.