source: Sophya/trunk/Cosmo/RadioBeam/calcpk2.cc@ 3794

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

Ajout du programme de calcul et sauvegarde reponse interfero, Reza 28/06/2010

File size: 6.1 KB
RevLine 
[3784]1/* ------------------------ Projet BAORadio --------------------
2 Programme de calcul du spectre de puissance (3D) a partir d'un
3 cube de delta T/T LSS, d'un cube delta T/T LSS synchrotron
4 ou radio-sources, apres ajustement / soustraction d'une loi de
5 puissance en frequence (l'axe Z du tableau doit etre en frequence)
6
7 R. Ansari , C. Magneville - Juin 2010
8
[3788]9Usage: calcpk2 InMapLSS convFacLSS InMapSync convFacSync InMapRadioSource convFacRsc OutPk
10 [PixNoiseLevel] [TargetBeamArcmin] [NSigSrcThr]
[3784]11--------------------------------------------------------------- */
12
13#include "machdefs.h"
14#include "sopnamsp.h"
15#include <iostream>
16#include <string>
17#include <math.h>
18
19#include <typeinfo>
20
21#include "specpk.h"
22#include "histats.h"
[3788]23#include "vector3d.h"
[3784]24
25#include "qhist.h"
[3787]26#include "lobe.h"
27#include "cubedef.h"
[3788]28#include "fgndsub.h"
29#include "radutil.h"
[3787]30
[3784]31#include "histinit.h"
32#include "fftwserver.h"
33#include "randr48.h"
34
35#include "ctimer.h"
36
37typedef ThSDR48RandGen RandomGenerator ;
38
39//-------------------------------------------------------------------------
40// ------------------ MAIN PROGRAM ------------------------------
41//-------------------------------------------------------------------------
42/* --Fonction-- */
43int main(int narg, const char* arg[])
44{
45 if (narg<6) {
[3788]46 cout << " Usage: calcpk2 InMapLSS convFacLSS InMapSync convFacSync OutPk \n"
47 << " [PixNoiseLevel] [TargetBeamArcmin] [NSigSrcThr]" << endl;
[3784]48 return 1;
49 }
50 Timer tm("calcpk2");
51 int rc = 0;
52 try {
53 string inppflss = arg[1];
54 r_4 rfaclss = atof(arg[2]);
55 string inppfsync = arg[3];
56 r_4 rfacsync = atof(arg[4]);
57 string outname = arg[5];
[3787]58
59 double pixsignoise = 0.;
60 bool fgaddnoise=false;
61 if (narg>6) {
62 pixsignoise=atof(arg[6]);
[3789]63 if (pixsignoise>1.e-6) fgaddnoise=true;
[3787]64 }
[3788]65
66 bool fgcorrbeam=true;
[3792]67 double tbeamDoL=135;
[3788]68 if (narg>7) {
[3792]69 tbeamDoL=atof(arg[7]);
70 if (tbeamDoL<1.) fgcorrbeam=false;
[3788]71 }
72 bool fgclnsrc=true;
73 double nsigsrc=5.;
74 if (narg>8) {
75 nsigsrc=atof(arg[8]);
76 if (nsigsrc<1.e-6) fgclnsrc=false;
77 }
[3787]78
[3788]79 TArray<r_4> maplss, mapsync;
80 const char * tits[2]={"LSS", "Sync/RadioSrc"};
[3784]81 for(int ks=0; ks<2; ks++) {
82 string& ppfname=inppflss;
83 r_4 rfac=rfaclss;
[3788]84 TArray<r_4>* inmap=&maplss;
85 if (ks==1) { ppfname=inppfsync; rfac=rfacsync; inmap=&mapsync; }
[3784]86 cout << "calcpk2[" << ks+1 << "] : reading 3D map " << tits[ks] << " from file " << ppfname
87 << " RenormFactor=" << rfac << endl;
88 PInPersist pin(ppfname);
89 pin >> (*inmap);
90 (*inmap) *= rfac;
91 double mean, sigma;
92 MeanSigma(*inmap, mean, sigma);
93 cout << " ...InMap sizes " << inmap->InfoString() << endl;
94 inmap->Show();
95 cout << " ... Mean=" << mean << " Sigma=" << sigma << endl;
96 }
[3787]97
[3788]98 bool smo;
99 if (!maplss.CompareSizes(mapsync,smo) ) {
100 cout << " calcpk2/ERROR sizes " << endl;
101 maplss.Show(); mapsync.Show();
102 return 99;
103 }
104
105 TArray<r_4> skycube(mapsync);
106 skycube += maplss;
107
[3787]108 if (fgaddnoise) {
[3788]109 cout << " calcpk2: adding noise to skycube cube ... " << endl;
110 BeamEffect::AddNoise(skycube, pixsignoise);
[3787]111 }
112
[3784]113 double mean, sigma;
[3788]114 MeanSigma(skycube, mean, sigma);
115 cout << " input sky cube : Mean=" << mean << " Sigma=" << sigma << endl;
116 tm.Split(" After input ");
117
118 H21Conversions conv;
119 conv.setFrequency(Freq0MHz);
120 double lambda = conv.getLambda();
[3789]121 Four2DResponse arep(2, InterfArrayDiametre/lambda, InterfArrayDiametre/lambda, lambda);
[3792]122 double DoL = tbeamDoL;
123 double tbeamarcmin = RadianToDegree(1.22/DoL)*60.;
[3788]124 Four2DResponse tbeam(2, DoL, DoL );
125 ForegroundCleaner cleaner(arep, tbeam, skycube);
126 if (fgcorrbeam) {
[3792]127 cout << "calcpk2[3.a] : calling cleaner.BeamCorrections() for target beam D/Lambda=" << DoL
128 << " -> arcmin " << tbeamarcmin << endl;
[3788]129 cleaner.BeamCorrections();
130 }
[3789]131 cout << " calcpk2[3.b] : calling cleaner.CleanNegatives() ... " << endl;
132 cleaner.CleanNegatives();
[3788]133 if (fgclnsrc) {
[3789]134 cout << "calcpk2[3.c] : calling cleaner.CleanPointSources() with threshold NSigma=" << nsigsrc << endl;
[3788]135 cleaner.CleanPointSources(nsigsrc);
136 }
137
138 cout << "calcpk2[4] : calling cleaner.extractLSSCube(...) " << endl;
139 TArray<r_4> synctemp, specidx;
140 TArray<r_4> exlss = cleaner.extractLSSCube(synctemp, specidx);
141
142 MeanSigma(exlss, mean, sigma);
143 cout << " After cleaning/extractLSS: Mean=" << mean << " Sigma=" << sigma << endl;
[3784]144 tm.Split(" After CleanForeground");
145
[3788]146 cout << "calcpk2[5] : computing 3D Fourier coefficients ... " << endl;
[3784]147 FFTWServer ffts;
148 TArray< complex<r_4> > four3d;
[3788]149 ffts.FFTForward(exlss, four3d);
[3784]150 tm.Split(" After FFTForward ");
151
[3788]152 cout << "calcpk2[6] : computing power spectrum ... " << endl;
[3784]153 RandomGenerator rg;
154 Four3DPk pkc(four3d, rg);
[3789]155 double dkxmpc = DeuxPI/(double)exlss.SizeX()/XCellSizeMpc;
156 double dkympc = DeuxPI/(double)exlss.SizeY()/YCellSizeMpc;
157 double dkzmpc = DeuxPI/(double)exlss.SizeZ()/ZCellSizeMpc;
158 pkc.SetCellSize(dkxmpc, dkympc, dkzmpc);
[3784]159
160 HProf hp = pkc.ComputePk(0.,256);
161
162 tm.Split(" Done ComputePk ");
163
[3788]164 cout << "calcpk2[7.a] : writing profile P(k) to " << outname << endl;
[3784]165 POutPersist po(outname);
[3788]166 po << hp;
167 outname = "fgm_" + outname;
168 cout << "calcpk2[7.b] : writing foreground maps to " << outname << endl;
169 POutPersist pom(outname);
170 pom << PPFNameTag("Tsync") << synctemp;
171 pom << PPFNameTag("async") << specidx;
[3784]172
173 } // End of try bloc
174 catch (PThrowable & exc) { // catching SOPHYA exceptions
175 cerr << " calcpk2.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
176 << "\n...exc.Msg= " << exc.Msg() << endl;
177 rc = 99;
178 }
179 catch (std::exception & e) { // catching standard C++ exceptions
180 cerr << " calcpk2.cc: Catched std::exception " << " - what()= " << e.what() << endl;
181 rc = 98;
182 }
183 catch (...) { // catching other exceptions
184 cerr << " calcpk2.cc: some other exception (...) was caught ! " << endl;
185 rc = 97;
186 }
[3788]187 cout << " ==== End of calcpk2.cc program Rc= " << rc << endl;
[3784]188 return rc;
189}
190
191
Note: See TracBrowser for help on using the repository browser.