| 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 OutPk  [InRenormFactor] [PixNoiseLevel] " << 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[3]);
 | 
|---|
| 56 |       fgaddnoise=true;
 | 
|---|
| 57 |     }
 | 
|---|
| 58 | 
 | 
|---|
| 59 |     cout << "calcpk[1] : reading 3D map from file " << inppfname << endl;
 | 
|---|
| 60 |     TArray<r_4> inmap;
 | 
|---|
| 61 |     {
 | 
|---|
| 62 |       PInPersist pin(inppfname);
 | 
|---|
| 63 |       pin >> inmap;
 | 
|---|
| 64 |     }
 | 
|---|
| 65 |     if (fgrenfact) { 
 | 
|---|
| 66 |       cout << "  Applying RenormFactor inmap = inmap*rfact, rfact=" << renfact << endl;
 | 
|---|
| 67 |       inmap *= renfact;
 | 
|---|
| 68 |     }
 | 
|---|
| 69 |     double mean, sigma;
 | 
|---|
| 70 |     MeanSigma(inmap, mean, sigma);
 | 
|---|
| 71 |     cout << " InMap sizes " << inmap.InfoString() << endl;
 | 
|---|
| 72 |     inmap.Show(); 
 | 
|---|
| 73 |     cout << "  Mean=" << mean << " Sigma=" << sigma << endl;
 | 
|---|
| 74 |     if (fgaddnoise) { 
 | 
|---|
| 75 |       BeamEffect::AddNoise(inmap, pixsignoise);
 | 
|---|
| 76 |     }
 | 
|---|
| 77 | 
 | 
|---|
| 78 |     tm.Split(" After read ");
 | 
|---|
| 79 |     
 | 
|---|
| 80 |     cout << "calcpk[2] : computing 3D Fourier coefficients ... " << endl;
 | 
|---|
| 81 |     FFTWServer ffts;
 | 
|---|
| 82 |     TArray< complex<r_4> > four3d;
 | 
|---|
| 83 |     ffts.FFTForward(inmap, four3d);
 | 
|---|
| 84 |     tm.Split(" After FFTForward ");
 | 
|---|
| 85 | 
 | 
|---|
| 86 |     cout << "calcpk[3] : computing power spectrum ... " << endl;
 | 
|---|
| 87 |     RandomGenerator rg;
 | 
|---|
| 88 |     Four3DPk pkc(four3d, rg);
 | 
|---|
| 89 |     double dkxmpc = DeuxPI/(double)inmap.SizeX()/XCellSizeMpc;
 | 
|---|
| 90 |     double dkympc = DeuxPI/(double)inmap.SizeY()/YCellSizeMpc;
 | 
|---|
| 91 |     double dkzmpc = DeuxPI/(double)inmap.SizeZ()/ZCellSizeMpc;
 | 
|---|
| 92 |     pkc.SetCellSize(dkxmpc, dkympc, dkzmpc);
 | 
|---|
| 93 | 
 | 
|---|
| 94 |     HProf hp = pkc.ComputePk(0.,256);
 | 
|---|
| 95 |     {
 | 
|---|
| 96 |       cout << "calcpk[4] : writing profile P(k) to PPF file  " << outname << endl;
 | 
|---|
| 97 |       POutPersist po(outname);
 | 
|---|
| 98 |       po << hp;
 | 
|---|
| 99 |       outname = "f3d_" + outname;
 | 
|---|
| 100 |       cout << "calcpk[4.b] : writing four3d to PPF file  " << outname << endl;
 | 
|---|
| 101 |       POutPersist pof(outname);
 | 
|---|
| 102 |       pof << four3d;
 | 
|---|
| 103 |     }
 | 
|---|
| 104 |     tm.Split(" Done CalcP(k) ");    
 | 
|---|
| 105 |   }  // End of try bloc 
 | 
|---|
| 106 |   catch (PThrowable & exc) {  // catching SOPHYA exceptions
 | 
|---|
| 107 |     cerr << " calcpk.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name() 
 | 
|---|
| 108 |          << "\n...exc.Msg= " << exc.Msg() << endl;
 | 
|---|
| 109 |     rc = 99;
 | 
|---|
| 110 |   }
 | 
|---|
| 111 |   catch (std::exception & e) {  // catching standard C++ exceptions
 | 
|---|
| 112 |     cerr << " calcpk.cc: Catched std::exception "  << " - what()= " << e.what() << endl;
 | 
|---|
| 113 |     rc = 98;
 | 
|---|
| 114 |   }
 | 
|---|
| 115 |   catch (...) {  // catching other exceptions
 | 
|---|
| 116 |     cerr << " calcpk.cc: some other exception (...) was caught ! " << endl;
 | 
|---|
| 117 |     rc = 97;
 | 
|---|
| 118 |   }
 | 
|---|
| 119 |   cout << " ==== End of calcpk.cc program  Rc= " << rc << endl;
 | 
|---|
| 120 |   return rc;    
 | 
|---|
| 121 | }
 | 
|---|