| 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" | 
|---|
| 21 | #include "lobe.h" | 
|---|
| 22 | #include "cubedef.h" | 
|---|
| 23 |  | 
|---|
| 24 | #include "histinit.h" | 
|---|
| 25 | #include "fftwserver.h" | 
|---|
| 26 | #include "randr48.h" | 
|---|
| 27 |  | 
|---|
| 28 | #include "ctimer.h" | 
|---|
| 29 |  | 
|---|
| 30 | typedef ThSDR48RandGen RandomGenerator ; | 
|---|
| 31 |  | 
|---|
| 32 | //------------------------------------------------------------------------- | 
|---|
| 33 | //      ------------------ MAIN PROGRAM ------------------------------ | 
|---|
| 34 | //------------------------------------------------------------------------- | 
|---|
| 35 | int main(int narg, const char* arg[]) | 
|---|
| 36 | { | 
|---|
| 37 | if (narg<3) { | 
|---|
| 38 | cout << " Usage: calcpk In3DMap_PPFName OutPk_PPFName  [InRenormFactor] [PixNoiseLevel] [Four3D_PPFName]" << endl; | 
|---|
| 39 | return 1; | 
|---|
| 40 | } | 
|---|
| 41 | Timer tm("calcpk"); | 
|---|
| 42 | int rc = 0; | 
|---|
| 43 | try { | 
|---|
| 44 | string inppfname = arg[1]; | 
|---|
| 45 | string outname = arg[2]; | 
|---|
| 46 | double renfact=1.; | 
|---|
| 47 | bool fgrenfact=false; | 
|---|
| 48 | if (narg>3) { | 
|---|
| 49 | renfact=atof(arg[3]); | 
|---|
| 50 | fgrenfact=true; | 
|---|
| 51 | } | 
|---|
| 52 | double pixsignoise = 0.; | 
|---|
| 53 | bool fgaddnoise=false; | 
|---|
| 54 | if (narg>4) { | 
|---|
| 55 | pixsignoise=atof(arg[4]); | 
|---|
| 56 | if (pixsignoise>1.e-9)  fgaddnoise=true; | 
|---|
| 57 | } | 
|---|
| 58 | bool fgsavef3d=false; | 
|---|
| 59 | string outf3dname="four3d.ppf"; | 
|---|
| 60 | if (narg>5) { | 
|---|
| 61 | outf3dname=arg[5]; | 
|---|
| 62 | fgsavef3d=true; | 
|---|
| 63 | } | 
|---|
| 64 |  | 
|---|
| 65 |  | 
|---|
| 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 | } | 
|---|
| 72 | if (fgrenfact) { | 
|---|
| 73 | cout << "  Applying RenormFactor inmap = inmap*rfact, rfact=" << renfact << endl; | 
|---|
| 74 | inmap *= renfact; | 
|---|
| 75 | } | 
|---|
| 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; | 
|---|
| 81 | if (fgaddnoise) { | 
|---|
| 82 | BeamEffect::AddNoise(inmap, pixsignoise); | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 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); | 
|---|
| 91 | cout << " calcpk[2.b] inmap.Norm2()=" << inmap.Norm2() << " four3d.Norm2()=" << four3d.Norm2() << endl; | 
|---|
| 92 |  | 
|---|
| 93 | tm.Split(" After FFTForward "); | 
|---|
| 94 |  | 
|---|
| 95 | cout << "calcpk[3] : computing power spectrum ... " << endl; | 
|---|
| 96 | RandomGenerator rg; | 
|---|
| 97 | Four3DPk pkc(four3d, rg); | 
|---|
| 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 |  | 
|---|
| 103 |  | 
|---|
| 104 | HProf hp = pkc.ComputePk(0.,HPk_NBin); | 
|---|
| 105 | { | 
|---|
| 106 | cout << "calcpk[4] : writing profile P(k) to PPF file  " << outname << endl; | 
|---|
| 107 | POutPersist po(outname); | 
|---|
| 108 | po << hp; | 
|---|
| 109 | } | 
|---|
| 110 | if (fgsavef3d)   { | 
|---|
| 111 | cout << "calcpk[4.b] : writing four3d to PPF file  " << outf3dname << endl; | 
|---|
| 112 | POutPersist pof(outf3dname); | 
|---|
| 113 | pof << four3d; | 
|---|
| 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 | } | 
|---|