#include "machdefs.h" #include #include #include #include #include #include #include "timing.h" #include "sambainit.h" #include "pexceptions.h" #include "datacards.h" #include "fitsioserver.h" #include "spheregorski.h" #include "radspecvector.h" #include "blackbody.h" #include "nupower.h" #include "squarefilt.h" #include "trianglefilt.h" #include "specrespvector.h" #include "gaussfilt.h" // ----------------------------------------------------------------- // ------------- Function declaration ------------------------------ int CheckCards(DataCards & dc, string & msg); char * BuildFITSFileName(string const & fname); SpectralResponse * getSpectralResponse(DataCards & dc); RadSpectra * getEmissionSpectra(DataCards & dc, int nc); void RadSpec2Nt(RadSpectra & rs, POutPersist & so, string name); void SpectralResponse2Nt(SpectralResponse& sr, POutPersist & so, string name); template void addComponent(SpectralResponse& sr, PixelMap& finalMap, PixelMap& mapToAdd, RadSpectra& rs, double K=1.); template void MeanSig(NDataBlock const & dbl, double& gmoy, double& gsig); // ----------------------------------------------------------------- // ----- Global (static) variables ------------ static bool rdmap = false; // true -> Read map first static char mapPath[256]; // Path for input maps static int hp_nside = 32; // HealPix NSide static int nskycomp = 0; // Number of sky components static int debuglev = 0; // Debug Level static int printlev = 0; // Print Level static POutPersist * so = NULL; // Debug PPFOut file // ------------------------------------------------------------------------- // main program // ------------------------------------------------------------------------- int main(int narg, char * arg[]) { if ((narg < 3) || ((narg > 1) && (strcmp(arg[1], "-h") == 0) )) { cout << " Usage: skymixer parameterFile outputfitsname [outppfname]" << endl; exit(0); } InitTim(); string msg; int rc = 0; RadSpectra * es = NULL; SpectralResponse * sr = NULL; double moy, sig; DataCards dc; so = NULL; try { string dcard = arg[1]; cout << " Decoding parameters from file " << dcard << endl; dc.ReadFile(dcard); rc = CheckCards(dc, msg); if (rc) { cerr << " Error condition -> Rc= " << rc << endl; cerr << " Msg= " << msg << endl; return(rc); } } catch (PException exc) { msg = exc.Msg(); cerr << " !!!! skymixer/ Readcard - Catched exception - Msg= " << exc.Msg() << endl; return(90); } cout << " skymix/Info : NComp = " << nskycomp << " SphereGorski_NSide= " << hp_nside << endl; cout << " ... MapPath = " << (string)mapPath << " DebugLev= " << debuglev << " PrintLev= " << printlev << endl; // We create an output persist file for writing debug objects if (debuglev > 0) so = new POutPersist("skymixdbg.ppf"); SphereGorski outgs(hp_nside); bool okout = false; try { if (rdmap) { // Reading map from FITS file FitsIoServer fios; char ifnm[256]; strncpy(ifnm, dc.SParam("READMAP", 1).c_str(), 255); ifnm[255] = '\0'; cout << " Reading output HealPix map from FITS file " << (string)ifnm << endl; fios.load(outgs, ifnm, 2); cout << " Output HealPIx Map read - NbPixels= " << outgs.NbPixels() << endl; } else { cout << " Output HealPix Map created - NbPixels= " << outgs.NbPixels() << endl; outgs.SetPixels(0.); } // Decoding detection pass-band filter sr = getSpectralResponse(dc); PrtTim(" After FilterCreation "); FitsIoServer fios; // Our FITS IO Server char * flnm, buff[90]; string key; SphereGorski ings(hp_nside); // The input map double K = 1.; // Loop over sky component int sk; for(sk = 0; sk 4) { // Writing tne input map to the outppf FIO_SphereGorski fiog(ings); fiog.Write(*so, key); } // getting Emission spectra if (es) { delete es; es = NULL; } es = getEmissionSpectra(dc, sk); if (printlev > 2) { MeanSig(ings.DataBlock(), moy, sig ); cout << " MeanSig for input map - Mean= " << moy << " Sigma= " << sig << endl; } addComponent(*sr, outgs, ings, *es, K); okout = true; if (printlev > 1) { MeanSig(outgs.DataBlock(), moy, sig ); cout << " MeanSig for Sum map - Mean= " << moy << " Sigma= " << sig << endl; } sprintf(buff, "End of Proc. Comp. %d ", sk+1); cout << " --------------------------------------- \n" << endl; PrtTim(buff); } // End of sky component loop } // End of try block catch (PException exc) { msg = exc.Msg(); cerr << " !!!! skymixer - Catched exception - Msg= " << exc.Msg() << endl; rc = 50; } // Saving the output map in FITS format if (okout) { FitsIoServer fios; fios.save(outgs, arg[2]); cout << "Output Map (SphereGorski) written to FITS file " << (string)(arg[2]) << endl; PrtTim("End of WriteFITS "); // Saving the output map in PPF format if (narg > 3) { POutPersist s(arg[3]); FIO_SphereGorski fiog(&outgs) ; fiog.Write(s); cout << "Output Map (SphereGorski) written to POutPersist file " << (string)(arg[3]) << endl; PrtTim("End of WritePPF "); } } if (so) delete so; // Closing the debug ppf file return(rc); } /* Nouvelle-Fonction */ int CheckCards(DataCards & dc, string & msg) // Function to check datacards { rdmap = false; mapPath[0] = '\0'; hp_nside = 32; nskycomp = 0; debuglev = 0; printlev = 0; int rc = 0; string key, key2; // Cheking datacards if (dc.NbParam("SKYMIX") < 2) { rc = 71; msg = "Invalid parameters - Check @SKYMIX card "; return(rc); } key = "READMAP"; if (dc.HasKey(key)) { if (dc.NbParam(key) < 1) { rc = 72; msg = "Invalid parameters - Check @READMAP card "; return(rc); } else rdmap = true; } // Checking detection filter specification key = "GAUSSFILTER"; key2 = "FILTERFITSFILE"; if ( (dc.NbParam(key) < 5) && (dc.NbParam(key2) < 3)) { msg = "Missing card or parameters : Check @GAUSSFILTER or @FILTERFITSFILE"; rc = 73; return(rc); } // Decoding number of component and pixelisation parameter int mg = 32; int ncomp = 0; ncomp = dc.IParam("SKYMIX", 0, 0); mg = dc.IParam("SKYMIX", 1, 32); if (ncomp < 1) { msg = "Invalid parameters - Check datacards @SKYMIX "; rc = 74; return(rc); } // Checking detection filter specification // Checking input FITS file specifications int kc; char buff[256]; bool pb = false; string key3; for(kc=0; kc 1) SpectralResponse2Nt(*filt, *so, ppfname); return(filt); } /* Nouvelle-Fonction */ RadSpectra * getEmissionSpectra(DataCards & dc, int nc) { char numb[16]; sprintf(numb, "%d", nc+1); string key = (string)"SPECTRAFITSFILE" + numb; string key2 = (string)"BLACKBODY" + numb; string key3 = (string)"POWERLAWSPECTRA" + numb; string ppfname = "espectra"; RadSpectra * rs = NULL; if (dc.HasKey(key) ) { // Reading emission spectra from file char * ifnm = BuildFITSFileName(dc.SParam(key, 0)); cout << " Reading Input FITS spectra file " << (string)ifnm << endl; FitsIoServer fios; Matrix mtx(2,10); fios.load(mtx, ifnm); double numin = dc.DParam(key, 2, 1.); double numax = dc.DParam(key, 3, 9999.); Vector nu(mtx.NCols()); Vector tnu(mtx.NCols()); for(int k=0; k 2) RadSpec2Nt(*rs, *so, ppfname); return(rs); } /* Nouvelle-Fonction */ template void addComponent(SpectralResponse& sr, PixelMap& finalMap, PixelMap& mapToAdd, RadSpectra& rs, double K) { // finalMap = finalMap + coeff* mapToAdd // coeff = convolution of sr and rs // compute the coefficient corresponding to mapToAdd if (finalMap.NbPixels() != mapToAdd.NbPixels()) throw SzMismatchError("addComponent()/Error: Unequal number of Input/Output map pixels"); double coeff = rs.filteredIntegratedFlux(sr) * K; if (printlev > 1) cout << " addComponent - Coeff= " << coeff << " (K= " << K << ")" << endl; for(int i=0; i void MeanSig(NDataBlock const & dbl, double& gmoy, double& gsig) { gmoy=0.; gsig = 0.; double valok; for(int k=0; k<(int)dbl.Size(); k++) { valok = dbl(k); gmoy += valok; gsig += valok*valok; } gmoy /= (double)dbl.Size(); gsig = gsig/(double)dbl.Size() - gmoy*gmoy; if (gsig >= 0.) gsig = sqrt(gsig); } /* Nouvelle-Fonction */ void RadSpec2Nt(RadSpectra & rs, POutPersist & so, string name) { char *ntn[2] = {"nu","fnu"}; NTuple nt(2,ntn); // Creation NTuple (AVEC new ) float xnt[2]; double nu; double numin = rs.minFreq(); double numax = rs.maxFreq(); int nmax = 500; double dnu = (numax-numin)/nmax; for(int k=0; k oiont(nt); oiont.Write(so, name); return; } /* Nouvelle-Fonction */ void SpectralResponse2Nt(SpectralResponse& sr, POutPersist & so, string name) { char *ntn[2] = {"nu","tnu"}; NTuple nt(2,ntn); // Creation NTuple (AVEC new ) float xnt[2]; double nu; double numin = sr.minFreq(); double numax = sr.maxFreq(); int nmax = 500; double dnu = (numax-numin)/nmax; for(int k=0; k oiont(nt); oiont.Write(so, name); return; }