source: Sophya/trunk/Cosmo/RadioBeam/pknoise.cc@ 3947

Last change on this file since 3947 was 3947, checked in by ansari, 15 years ago

Amelioration et modifs diverses lors de la redaction du papier, Reza 13/02/2011

File size: 6.3 KB
RevLine 
[3930]1/* ------------------------ Projet BAORadio --------------------
2 Programme de calcul du spectre de puissance de bruit pour
3 un interferometre (spectre moyenne sur 3D -> P_noise(k) )
4
5 R. Ansari , C. Magneville - Juin 2010
6
[3931]7 Usage: pknoise pknoise [-parname value] Diameter/Four2DRespTableFile OutPPFName
8 -parname : -noise , -renmax , -scut , -ngen , -z , -prt
[3930]9--------------------------------------------------------------- */
10
[3756]11#include "machdefs.h"
12#include "sopnamsp.h"
13#include <iostream>
14#include <string>
15#include <math.h>
16
17#include <typeinfo>
18
19#include "mdish.h"
20#include "specpk.h"
[3792]21#include "interfconfigs.h"
[3930]22#include "radutil.h"
[3792]23
[3756]24#include "histinit.h"
25// #include "fiosinit.h"
26// #include "fitsioserver.h"
27
28#include "randr48.h"
29
30#include "timing.h"
31#include "ctimer.h"
32
33typedef DR48RandGen RandomGenerator ;
34
35// ---------------------------------------------------------------------
[3930]36// Test main
37// R. Ansari - Avril-Dec 2010
[3756]38// ---------------------------------------------------------------------
39
[3931]40void Usage()
41{
42 cout << " Usage: pknoise [-parname value] Diameter/Four2DRespTableFile OutPPFName \n"
43 << " -noise NoiseLevel (default=1.) \n"
44 << " -renmax MaxValue (default : Do NOT renormalize 2D response value \n"
45 << " -scut SCutValue (default=100.) \n"
[3947]46 << " -ngen NGen (default=0) number of noise fourier amp generations \n"
47 << " NGen=0 -> Call ComputeNoisePk(), else generate Fourier Amplitudes (random) \n"
[3931]48 << " -z redshift (default=0.7) \n"
49 << " -prt PrtLev,PrtModulo (default=0,10) " << endl;
50 return;
51}
[3756]52
[3769]53//-------------------------------------------------------------------------
54// ------------------ MAIN PROGRAM ------------------------------
55//-------------------------------------------------------------------------
[3756]56int main(int narg, const char* arg[])
57{
[3930]58 if ( (narg<3)||((narg>1)&&(strcmp(arg[1],"-h")==0)) ) {
[3931]59 Usage();
[3756]60 return 1;
61 }
[3930]62 cout << " ==== pknoise.cc : interferometer noise power spectrum computation ==== " << endl;
[3756]63 // make sure SOPHYA modules are initialized
64 SophyaInit();
65 // FitsIOServerInit();
66 InitTim();
67 //--- decoding command line arguments
[3930]68 string tits="pknoise";
69 char cbuff[64];
70 bool fgresptbl=false;
71 double DIAMETRE=100.;
72 string resptblname;
[3931]73 double NoiseLevel=1.;
74
75 bool fgrenorm=false;
76 double rmax=1.;
[3947]77 int NMAX = 0;
[3931]78 double SCut=0.;
79 double z_Redshift=0.7 ; // 21 cm at z=0.7 -> 0.357 m
80 int prtlev=0;
81 int prtmod=10;
82
83 int ka=1;
84 while (ka<(narg-1)) {
85 if (strcmp(arg[ka],"-noise")==0) {
86 NoiseLevel=atof(arg[ka+1]);
87 ka+=2;
88 }
89 else if (strcmp(arg[ka],"-renmax")==0) {
90 rmax=atof(arg[ka+1]); fgrenorm=true; ka+=2;
91 }
92 else if (strcmp(arg[ka],"-scut")==0) {
93 SCut=atof(arg[ka+1]); ka+=2;
94 }
95 else if (strcmp(arg[ka],"-ngen")==0) {
96 NMAX=atoi(arg[ka+1]); ka+=2;
97 }
98 else if (strcmp(arg[ka],"-z")==0) {
99 z_Redshift=atof(arg[ka+1]); ka+=2;
100 }
101 else if (strcmp(arg[ka],"-prt")==0) {
102 sscanf(arg[ka+1],"%d,%d",&prtlev,&prtmod); ka+=2;
103 }
104 else break;
105 }
106
107 if ((ka+1)>=narg) {
108 cout << " pknoise / Argument error " << endl;
109 Usage();
110 return 2;
111 }
112 if (isdigit(*arg[ka])) {
[3930]113 fgresptbl=false;
[3931]114 DIAMETRE=atof(arg[ka]);
[3930]115 sprintf(cbuff,"pknoise_Dish(%g m)", DIAMETRE);
116 }
117 else {
[3931]118 resptblname=arg[ka];
[3930]119 fgresptbl=true;
[3931]120 sprintf(cbuff,"pknoise_RespTblName=%s", arg[ka]);
[3930]121 }
122 tits=cbuff;
[3931]123 string outfile = arg[ka+1];
[3756]124 if (outfile==".") outfile = "pknoise.ppf";
[3931]125 //-- end command line arguments
[3756]126
127 int rc = 1;
128 try { // exception handling try bloc at top level
[3930]129 cout << " pknoise[0] : Executing, output file= " << outfile << endl;
[3756]130 POutPersist po(outfile);
131
[3930]132 H21Conversions conv;
133 conv.setRedshift(z_Redshift);
134 double lambda = conv.getLambda();
[3756]135
[3930]136 double Dol = DIAMETRE/lambda;
[3756]137
[3930]138 Four2DResponse arep(2, DIAMETRE/lambda, DIAMETRE/lambda, lambda);
139 Four2DResponse* arep_p=&arep;
140 Four2DRespTable resptbl;
141 if (fgresptbl) {
142 cout << "pknoise[1]: initializing Four2DRespTable from file" << resptblname << endl;
143 resptbl.readFromPPF(resptblname);
[3947]144 cout << "pknoise[1.b] Four2DRespTable.LambdaRef=" << resptbl.getLambdaRef() << " setLambda("
145 << lambda << ")" << endl;
146 resptbl.setLambda(lambda);
[3930]147 arep_p=&resptbl;
148 if (fgrenorm) {
[3947]149 cout << "pknoise[1.c] call to resptbl.renormalize(" << rmax << ")";
[3930]150 double omax=resptbl.renormalize(rmax);
151 cout << " ... Old Max=" << omax << endl;
152 }
[3769]153 }
[3930]154 else cout << " pknoise[1]: Four2DResponse ( Diameter=" << DIAMETRE << " Lambda= " << lambda
155 << " DoL=" << DIAMETRE/lambda << " ) " << endl;
[3769]156
[3756]157
[3930]158 cout << " pknoise[2]: Instanciating object type Four3DPk " << endl;
[3756]159 RandomGenerator rg;
160 Four3DPk m3d(rg);
161 m3d.SetCellSize(2.*DeuxPI, 2.*DeuxPI, 2.*DeuxPI);
[3930]162 m3d.SetPrtLevel(prtlev,prtmod);
[3756]163
[3930]164 cout << " pknoise[3]: Computing Noise P(k) using PkNoiseCalculator ..." << endl;
[3947]165 if (NMAX>0) {
166 PkNoiseCalculator pkn(m3d, *(arep_p), SCut, NMAX, tits.c_str());
167 pkn.SetPrtLevel(prtlev,prtmod);
168 HProf hpn = pkn.Compute();
169 po << hpn;
170 }
171 else {
172 Histo fracmodok;
173 DataTable dtnoise;
174 HProf hpn = m3d.ComputeNoisePk(*(arep_p),fracmodok,dtnoise,SCut);
175 po << hpn;
176 string outfile2 = "x"+outfile;
177 POutPersist po2(outfile2);
178 HProf h1dnoise=arep_p->GetProjNoiseLevel();
179 HProf h1drep=arep_p->GetProjResponse();
180 po2 << PPFNameTag("dtnoise") << dtnoise;
181 po2 << PPFNameTag("hpnoise") << hpn;
182 po2 << PPFNameTag("fracmodok") << fracmodok;
183 po2 << PPFNameTag("h1dnoise") << h1dnoise;
184 po2 << PPFNameTag("h1drep") << h1drep;
185 }
[3756]186 rc = 0;
187 } // End of try bloc
188 catch (PThrowable & exc) { // catching SOPHYA exceptions
189 cerr << " pknoise.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
190 << "\n...exc.Msg= " << exc.Msg() << endl;
191 rc = 99;
192 }
193 catch (std::exception & e) { // catching standard C++ exceptions
194 cerr << " pknoise.cc: Catched std::exception " << " - what()= " << e.what() << endl;
195 rc = 98;
196 }
197 catch (...) { // catching other exceptions
198 cerr << " pknoise.cc: some other exception (...) was caught ! " << endl;
199 rc = 97;
200 }
201 PrtTim("End-pknoise");
202 cout << " ==== End of pknoise.cc program Rc= " << rc << endl;
203 return rc;
204}
205
206
Note: See TracBrowser for help on using the repository browser.