source: Sophya/trunk/SophyaProg/PMixer/skymixer.cc@ 950

Last change on this file since 950 was 937, checked in by ansari, 25 years ago

Sophie: changes to read the SphereHEALPIX with a limited amount
of needed memory

File size: 21.5 KB
Line 
1#include "pmixer.h"
2
3/*!
4 * \defgroup PMixer PMixer module
5 * This module contains programs which:
6 * <UL>
7 * <LI> add several sky components, taking into account their
8 * radiation spectra and convoluting them with a given filter
9 * response : skymixer
10 * <LI> create a map with point source : extractRS
11 * <LI> generate sky components, radiation spectra and spectral
12 * response (small generator of maps) : tgsky and tgrsr
13 * </UL>
14 * A detailed description may be found at:
15 */
16/*!
17 * \ingroup PMixer
18 * \file skymixer.cc
19 *\brief \b PROGRAM \b skyMixer <BR>
20 * add several sky components, taking into account their
21 *radiation spectra and convoluting them with a given filter
22 *response
23 */
24
25// -----------------------------------------------------------------
26// ------------- Function declaration ------------------------------
27int CheckCards(DataCards & dc, string & msg);
28char * BuildFITSFileName(string const & fname);
29SpectralResponse * getSpectralResponse(DataCards & dc);
30RadSpectra * getEmissionSpectra(DataCards & dc, int nc);
31void RadSpec2Nt(RadSpectra & rs, POutPersist & so, string name);
32void SpectralResponse2Nt(SpectralResponse& sr, POutPersist & so, string name);
33
34// to add different sky components and corresponding tools
35//----------------------------------------------------------
36template <class T>
37void addComponent(SpectralResponse& sr,
38 PixelMap<T>& finalMap,
39 PixelMap<T>& mapToAdd,
40 RadSpectra& rs, double K=1.);
41//
42template <class T>
43void addComponentBeta(SphereHEALPix<T>& finalMap,
44 SphereHEALPix<T>& mapToAdd,SpectralResponse& sr,
45 SphereHEALPix<T>& betaMap, double normFreq, double K);
46//
47template <class T>
48void integratedMap(SpectralResponse& sr,
49 SphereHEALPix<T>& betaMap, double normFreq, SphereHEALPix<T>& intBetaMap);
50
51//
52template <class T>
53void addComponentBeta(SphereHEALPix<T>& finalMap,
54 SphereHEALPix<T>& mapToAdd,
55 SphereHEALPix<T>& intBetaMap, double K);
56//
57template <class T>
58void addDipole(SpectralResponse& sr, PixelMap<T>& finalMap,
59 double theta,double phi,double amp,double temp);
60//
61// -----------------------------------------------------------------
62
63// ----- Global (static) variables ------------
64static bool rdmap = false; // true -> Read map first
65static char mapPath[256]; // Path for input maps
66static int hp_nside = 32; // HealPix NSide
67static int nskycomp = 0; // Number of sky components
68static int debuglev = 0; // Debug Level
69static int printlev = 0; // Print Level
70static POutPersist * so = NULL; // Debug PPFOut file
71
72// -------------------------------------------------------------------------
73// main program
74// -------------------------------------------------------------------------
75int main(int narg, char * arg[])
76{
77 if ((narg < 3) || ((narg > 1) && (strcmp(arg[1], "-h") == 0) )) {
78 cout << " Usage: skymixer parameterFile outputfitsname [outppfname]" << endl;
79 exit(0);
80 }
81
82 InitTim();
83
84 string msg;
85 int rc = 0;
86 RadSpectra * es = NULL;
87 SpectralResponse * sr = NULL;
88 double moy, sig;
89
90 DataCards dc;
91 so = NULL;
92
93 try {
94 string dcard = arg[1];
95 if(printlev > 1) cout << " Decoding parameters from file " << dcard << endl;
96 dc.ReadFile(dcard);
97
98 rc = CheckCards(dc, msg);
99 if (rc) {
100 cerr << " Error condition -> Rc= " << rc << endl;
101 cerr << " Msg= " << msg << endl;
102 return(rc);
103 }
104 }
105 catch (PException exc) {
106 msg = exc.Msg();
107 cerr << " !!!! skymixer/ Readcard - Catched exception - Msg= " << exc.Msg() << endl;
108 return(90);
109 }
110
111
112 cout << " skymix/Info : NComp = " << nskycomp << " SphereHEALPix_NSide= " << hp_nside << endl;
113 cout << " ... MapPath = " << (string)mapPath << " DebugLev= " << debuglev
114 << " PrintLev= " << printlev << endl;
115
116 // We create an output persist file for writing debug objects
117 if (debuglev > 0) so = new POutPersist("skymixdbg.ppf");
118
119 SphereHEALPix<float> outgs(hp_nside);
120 try{
121 if (rdmap) { // Reading map from FITS file
122 char ifnm[256];
123 strncpy(ifnm, dc.SParam("READMAP", 0).c_str(), 255);
124 ifnm[255] = '\0';
125 cout << " Reading output HealPix map from FITS file " << (string)ifnm << endl;
126 {
127 FITS_SphereHEALPix<float> fios(&outgs);
128 fios.ReadF(ifnm,2);
129 }
130 if(printlev>0)
131 cout << " Output HealPIx Map read - NbPixels= " <<
132 outgs.NbPixels() << endl;
133 if (printlev > 0) {
134 MeanSig(outgs.DataBlock(), moy, sig );
135 cout << " MeanSig for outpout map - Mean= " <<
136 moy << " Sigma= " << sig << endl;
137 }
138 }
139 else {
140 if(printlev>0)
141 cout << " Output HealPix Map created - NbPixels= " <<
142 outgs.NbPixels() << endl;
143 outgs.SetPixels(0.);
144 }
145
146 // Decoding detection pass-band filter
147 sr = getSpectralResponse(dc);
148 PrtTim(" After FilterCreation ");
149
150 char * flnm, buff[90];
151 string key;
152
153 double K = 1.;
154 double freqOfMap = 1.;
155 // Loop over sky component
156 int sk;
157 for(sk = 0; sk<nskycomp; sk++) {
158 cout << "------------------------------------" << endl;
159 cout << " Processing sky component No " << sk+1 << endl;
160
161
162 sprintf(buff, "%d", sk+1);
163 key = (string)"DIPOLE" + buff;
164 // check for an eventual dipole
165 if(dc.HasKey(key))
166 {
167 if (es) { delete es; es = NULL; }
168 double temp = -10.;
169 double theta= dc.DParam(key,1,1.);
170 double phi = dc.DParam(key,2,1.);
171 double amp = dc.DParam(key,3,1.);
172 if(dc.NbParam(key)>3)
173 {
174 temp = dc.DParam(key,4,1.);
175 }
176 cout << " creating dipole " << temp << " " << amp << " " << phi << " " << theta << " " << endl;
177 addDipole(*sr, outgs,theta,phi,amp,temp);
178 }
179 else
180 {
181 sprintf(buff, "%d", sk+1);
182 key = (string)"MAPFITSFILE" + buff;
183 flnm = BuildFITSFileName(dc.SParam(key, 0));
184
185 K = dc.DParam(key, 1, 1.);
186
187 cout << " Reading Input FITS map " << (string)flnm << endl;
188 SphereHEALPix<float> ings(hp_nside);
189 {
190 FITS_SphereHEALPix<float> fiosIn(&ings);
191 fiosIn.ReadF(flnm,2);
192 }
193 if (debuglev > 4) { // Writing the input map to the outppf
194 FIO_SphereHEALPix<float> fiog(ings);
195 fiog.Write(*so, key);
196 }
197 if (printlev > 2) {
198 MeanSig(ings.DataBlock(), moy, sig );
199 cout << " MeanSig for input map - Mean= " << moy << " Sigma= " << sig << endl;
200 }
201 bool mapDependentOfFreq = false;
202 key = (string)"BETAFITSFILE"+ buff;
203 if(dc.HasKey(key))
204 {
205 mapDependentOfFreq = true;
206 }
207
208 // getting Emission spectra
209 if(!mapDependentOfFreq)
210 {
211 if (es) { delete es; es = NULL; }
212 es = getEmissionSpectra(dc, sk);
213 addComponent(*sr, outgs, ings, *es, K);
214 }
215 else
216 {
217 key = (string)"BETAFITSFILE"+ buff;
218 //SphereHEALPix<float> betaMap;
219 flnm = BuildFITSFileName(dc.SParam(key, 0));
220 double normFreq = dc.DParam(key, 1, 1.);
221 if (printlev > 4) cout << "....BetaFits... normalization Freq = " << normFreq << endl;
222 int nSideForInt = dc.DParam(key, 2, 1.);
223 if (printlev > 4) cout << "....BetaFits... NSide for Integration map = " << nSideForInt << endl;
224 cout << "....BetaFits... Reading Beta FITS map " << (string)flnm << endl;
225 SphereHEALPix<float> betaMap(hp_nside);
226 {
227 FITS_SphereHEALPix<float> fiosBM(&betaMap);
228 fiosBM.ReadF(flnm,2);
229 }
230 if (printlev > 2) {
231 MeanSig(betaMap.DataBlock(), moy, sig );
232 cout << " MeanSig for Beta map - Mean= " << moy << " Sigma= " << sig << endl;
233 }
234 if (debuglev > 4) { // Writing the input map to the outppf
235 FIO_SphereHEALPix<float> fiogs(betaMap);
236 fiogs.Write(*so, key);
237 }
238
239 if(nSideForInt<0) nSideForInt = sqrt((double)betaMap.NbPixels()/12);
240 bool bydefault = true;
241 if(!bydefault)
242 addComponentBeta(outgs,ings,*sr,betaMap,normFreq, K);
243 else
244 {
245 // integrate the betamap over the SpectralResponse
246 SphereHEALPix<float> intBetaMap(nSideForInt);
247 integratedMap(*sr, betaMap, normFreq, intBetaMap);
248 if (debuglev > 4) { // Writing the input map to the outppf
249 FIO_SphereHEALPix<float> fiogs2(intBetaMap);
250 fiogs2.Write(*so, "INTBETAMAP");
251 }
252
253 betaMap.Resize(8);
254 if (printlev > 4)
255 {
256 MeanSig(intBetaMap.DataBlock(), moy, sig );
257 cout << "....BetaFits... MeanSig for intBetaMap - Mean= "
258 << moy << " Sigma= " << sig << endl;
259 }
260 // add the integrated beta map
261 addComponentBeta(outgs,ings,intBetaMap, K);
262 }
263 }
264
265 MeanSig(outgs.DataBlock(), moy, sig );
266 cout << " MeanSig for Sum map - Mean= " << moy << " Sigma= " << sig << endl;
267 cout << "-------------------------------------------------" << endl;
268
269 sprintf(buff, "End of Processing Component %d ", sk+1);
270 PrtTim(buff);
271 }
272 }
273 }
274 catch(PException exc)
275 {
276 cout << "catched PException" << endl;
277 msg = exc.Msg();
278 cerr << " !!!! skymixer - Catched exception - Msg= " << exc.Msg() << endl;
279 rc = 50;
280 return(50);
281 }
282
283 // Saving the output map in FITS format
284 cout << "Output Map (SphereHEALPix<float>) written to FITS file "
285 << (string)(arg[2]) << endl;
286 {
287 FITS_SphereHEALPix<float> fios2(outgs);
288 fios2.Write(arg[2]);
289 }
290 PrtTim("End of WriteFITS ");
291 // Saving the output map in PPF format
292 if (narg > 3) {
293 POutPersist s(arg[3]);
294 FIO_SphereHEALPix<float> fiog(&outgs) ;
295 fiog.Write(s);
296 cout << "Output Map (SphereHEALPix<float>) written to POutPersist file "
297 << (string)(arg[3]) << endl;
298 PrtTim("End of WritePPF ");
299 }
300 if (so) delete so; // Closing the debug ppf file
301 return(rc);
302}
303
304/* Nouvelle-Fonction */
305int CheckCards(DataCards & dc, string & msg)
306// Function to check datacards
307{
308rdmap = false;
309mapPath[0] = '\0';
310hp_nside = 32;
311nskycomp = 0;
312debuglev = 0;
313printlev = 0;
314
315int rc = 0;
316string key, key2,key3;
317
318 // Cheking datacards
319 if (dc.NbParam("SKYMIX") < 2) {
320 rc = 71;
321 msg = "Invalid parameters - Check @SKYMIX card ";
322 return(rc);
323 }
324 key = "READMAP";
325 if (dc.HasKey(key)) {
326 if (dc.NbParam(key) < 1) {
327 rc = 72;
328 msg = "Invalid parameters - Check @READMAP card ";
329 return(rc);
330 }
331 else rdmap = true;
332 }
333
334// Checking detection filter specification
335 key = "GAUSSFILTER";
336 key2 = "FILTERFITSFILE";
337 key3 = "DIPOLE";
338 if ( (dc.NbParam(key) < 5) && (dc.NbParam(key2) < 3) && (dc.NbParam(key3) < 3)) {
339 msg = "Missing card or parameters : Check @GAUSSFILTER or @FILTERFITSFILE or @DIPOLE";
340 rc = 73; return(rc);
341 }
342
343 // Decoding number of component and pixelisation parameter
344 int mg = 32;
345 int ncomp = 0;
346 ncomp = dc.IParam("SKYMIX", 0, 0);
347 mg = dc.IParam("SKYMIX", 1, 32);
348 if (ncomp < 1) {
349 msg = "Invalid parameters - Check datacards @SKYMIX ";
350 rc = 74;
351 return(rc);
352 }
353
354 // Checking detection filter specification
355 // Checking input FITS file specifications
356 int kc;
357 char buff[256];
358 bool pb = false;
359 string key4;
360 string key5;
361 string key6;
362 for(kc=0; kc<ncomp; kc++) {
363 sprintf(buff, "MAPFITSFILE%d", kc+1);
364 key = buff;
365 sprintf(buff, "DIPOLE%d", kc+1);
366 key3 = buff;
367 if (dc.NbParam(key) < 1 && dc.NbParam(key3)<1) {
368 msg = "Missing or invalid card : " + key + " " + key2 + " " + key3;
369 pb = true; break;
370 }
371 sprintf(buff, "SPECTRAFITSFILE%d", kc+1);
372 key = buff;
373 sprintf(buff, "BLACKBODY%d", kc+1);
374 key2 = buff;
375 sprintf(buff, "POWERLAWSPECTRA%d", kc+1);
376 key3 = buff;
377 sprintf(buff, "BETAFITSFILE%d", kc+1);
378 key4 = buff;
379 sprintf(buff, "DIPOLE%d", kc+1);
380 key5 = buff;
381 sprintf(buff, "DERIVBB%d", kc+1);
382 key6 = buff;
383 if ( (dc.NbParam(key) < 3) && (dc.NbParam(key2) < 1) && (dc.NbParam(key3) < 6) && (dc.NbParam(key4)<2)
384 && (dc.NbParam(key6)<1) && (dc.NbParam(key5)<3)) {
385 msg = "Missing card or invalid parameters : " + key + " " + key2 + " " + key3 + " " + key4+ " " + key5;
386 pb = true; break;
387 }
388
389 }
390
391 if (pb) {
392 rc = 75;
393 return(75);
394 }
395
396
397// Initialiazing parameters
398 rc = 0;
399 msg = "OK";
400 nskycomp = ncomp;
401 hp_nside = mg;
402
403// Checking for PATH definition card
404 key = "MAPPATH";
405 if (dc.NbParam(key) < 3) strncpy(mapPath, dc.SParam(key, 0).c_str(), 255);
406 mapPath[255] = '\0';
407 key = "DEBUGLEVEL";
408 debuglev = dc.IParam(key, 0, 0);
409 key = "PRINTLEVEL";
410 printlev = dc.IParam(key, 0, 0);
411 return(rc);
412}
413
414static char buff_flnm[1024]; // Mal protege !
415/* Nouvelle-Fonction */
416char* BuildFITSFileName(string const & fname)
417{
418if (mapPath[0] != '\0') sprintf(buff_flnm, "%s/%s", mapPath, fname.c_str());
419else sprintf(buff_flnm, "%s", fname.c_str());
420return(buff_flnm);
421}
422
423/* Nouvelle-Fonction */
424SpectralResponse * getSpectralResponse(DataCards & dc)
425{
426 SpectralResponse * filt = NULL;
427
428 string key = "FILTERFITSFILE";
429 string key2 = "GAUSSFILTER";
430 string ppfname = "filter";
431
432 if (dc.HasKey(key) ) { // Reading FITS filter file
433 FitsIoServer fios;
434 char ifnm[256];
435 strncpy(ifnm, dc.SParam(key, 1).c_str(), 255);
436 ifnm[255] = '\0';
437 Matrix mtx(2,10);
438 fios.load(mtx, ifnm);
439 double numin = dc.DParam(key, 2, 1.);
440 double numax = dc.DParam(key, 3, 9999.);
441 Vector nu(mtx.NCols());
442 Vector fnu(mtx.NCols());
443 for(int k=0; k<mtx.NCols(); k++) {
444 nu(k) = mtx(0, k);
445 fnu(k) = mtx(1, k);
446 }
447 filt = new SpecRespVec(nu, fnu, numin, numax);
448 ppfname = key;
449 }
450 else if (dc.HasKey(key2) ) { // creating GaussianFilter
451 double nu0 = dc.DParam(key2, 0, 10.);
452 double s = dc.DParam(key2, 1, 1.);
453 double a = dc.DParam(key2, 2, 1.);
454 double numin = dc.DParam(key2, 3, 0.1);
455 double numax = dc.DParam(key2, 4, 9999);
456 filt = new GaussianFilter(nu0, s, a, numin, numax);
457 ppfname = key2;
458 }
459 if (filt == NULL) throw ParmError("datacard error ! No detection filter");
460 if(printlev>0)
461 {
462 cout << endl;
463 cout << " Filter decoded - Created " << endl;
464 cout << *filt << endl;
465 }
466 // for debug
467 if (debuglev > 1) SpectralResponse2Nt(*filt, *so, ppfname);
468 return(filt);
469}
470
471/* Nouvelle-Fonction */
472RadSpectra * getEmissionSpectra(DataCards & dc, int nc)
473{
474 char numb[16];
475 sprintf(numb, "%d", nc+1);
476
477 string key = (string)"SPECTRAFITSFILE" + numb;
478 string key2 = (string)"BLACKBODY" + numb;
479 string key5 = (string)"DERIVBB" + numb;
480 string key3 = (string)"POWERLAWSPECTRA" + numb;
481 string ppfname = "espectra";
482
483 RadSpectra * rs = NULL;
484 if (dc.HasKey(key) ) { // Reading emission spectra from file
485 char * ifnm = BuildFITSFileName(dc.SParam(key, 0));
486 cout << " Reading Input FITS spectra file " << (string)ifnm << endl;
487 FitsIoServer fios;
488 Matrix mtx(2,10);
489 fios.load(mtx, ifnm);
490 double numin = dc.DParam(key, 2, 1.);
491 double numax = dc.DParam(key, 3, 9999.);
492 Vector nu(mtx.NCols());
493 Vector tnu(mtx.NCols());
494 for(int k=0; k<mtx.NCols(); k++) {
495 nu(k) = mtx(0, k);
496 tnu(k) = mtx(1, k);
497 }
498 rs = new RadSpectraVec(nu, tnu, numin, numax);
499 ppfname = key;
500 }
501 else if (dc.HasKey(key2) ) { // Creating BlackBody emission spectra
502 rs = new BlackBody(dc.DParam(key2, 0, 2.726));
503 ppfname = key2;
504 }
505 else if (dc.HasKey(key5) ) { // Creating Dipole
506 rs = new DerivBlackBody(dc.DParam(key5, 0, 3.E-3));
507 ppfname = key5;
508 }
509 else if (dc.HasKey(key3) ) { // Creating PowerLaw emission spectra
510 double a = dc.DParam(key3, 0, 1.);
511 double nu0 = dc.DParam(key3, 1, 100.);
512 double dnu = dc.DParam(key3, 2, 10.);
513 double b = dc.DParam(key3, 3, 0.);
514 double numin = dc.DParam(key3, 4, 0.1);
515 double numax = dc.DParam(key3, 5, 9999);
516 rs = new PowerLawSpectra(a, b, nu0, dnu, numin, numax);
517 ppfname = key3;
518 }
519 if (rs == NULL) throw ParmError("datacard error ! missing Emission spectra");
520 cout << " Emission spectra decoded - Created (" << ppfname << ")" << endl;
521 cout << *rs << endl;
522// for debug
523 if (debuglev > 2) RadSpec2Nt(*rs, *so, ppfname);
524 return(rs);
525}
526
527
528
529
530template <class T>
531void addDipole(SpectralResponse& sr, PixelMap<T>& finalMap,
532 double theta,double phi,double amp,double temp)
533{
534 DerivBlackBody dbb;
535 if(temp>0) dbb.setTemperature(temp);
536 double coeff = dbb.filteredIntegratedFlux(sr) * amp;
537 UnitVector vd(theta,phi);
538 UnitVector vc(theta,phi);
539
540 for(int i=0; i<finalMap.NbPixels(); i++)
541 {
542 double thetar,phir;
543 finalMap.PixThetaPhi(i,thetar,phir);
544 vc.SetThetaPhi(thetar, phir);
545 finalMap(i) += vd.Psc(vc)*coeff;
546 }
547 if (debuglev > 4) { // Writing the input map to the outppf
548 SphereHEALPix<float> ings(sqrt((double)finalMap.NbPixels()/12));
549 for(int i=0; i<finalMap.NbPixels(); i++)
550 {
551 double thetar,phir;
552 finalMap.PixThetaPhi(i,thetar,phir);
553 vc.SetThetaPhi(thetar, phir);
554 ings(i) = vd.Psc(vc);
555 }
556 FIO_SphereHEALPix<float> fiog(ings);
557 fiog.Write(*so, "dipole");
558 cout << "Debug the dipole map....saved in debug file !" << endl;
559 }
560}
561/* Nouvelle-Fonction */
562template <class T>
563void addComponent(SpectralResponse& sr, PixelMap<T>& finalMap,
564 PixelMap<T>& mapToAdd, RadSpectra& rs, double K)
565{
566 // finalMap = finalMap + coeff* mapToAdd
567 // coeff = convolution of sr and rs
568 // compute the coefficient corresponding to mapToAdd
569 if (finalMap.NbPixels() != mapToAdd.NbPixels())
570 throw SzMismatchError("addComponent()/Error: Unequal number of Input/Output map pixels");
571 double coeff = rs.filteredIntegratedFlux(sr) * K;
572 if (printlev > 1)
573 cout << " addComponent - Coeff= " << coeff << " (K= " << K << ")" << endl;
574 for(int i=0; i<finalMap.NbPixels(); i++)
575 {
576 finalMap(i) += coeff * mapToAdd(i);
577 }
578}
579/* Nouvelle-Fonction */
580template <class T>
581void addComponentBeta(SphereHEALPix<T>& finalMap,
582 SphereHEALPix<T>& mapToAdd,SpectralResponse& sr,
583 SphereHEALPix<T>& betaMap, double normFreq, double K)
584{
585 // finalMap = finalMap + coeff* mapToAdd
586 // coeff = convolution of sr and rs
587 // compute the coefficient corresponding to mapToAdd
588 // betaMap is the map of (beta(theta,phi))
589
590 int nbpix = finalMap.NbPixels();
591 if (nbpix != mapToAdd.NbPixels())
592 throw SzMismatchError("addComponentBeta()/Error: Unequal number of Input/Output map pixels");
593 if (printlev > 1)
594 {
595 cout << "addComponentBeta - Coeff= " << K << endl;
596 cout << "nb pixels: " << finalMap.NbPixels() << endl;
597 }
598 SphereHEALPix<T> bigBetaMap(sqrt((double)nbpix/12));
599 if(nbpix != betaMap.NbPixels())
600 {
601 Sph2Sph(betaMap,bigBetaMap);
602 }
603 for(int i=0; i<finalMap.NbPixels(); i++)
604 {
605 // coeff = integration of (nu/normFreq)^(-beta(theta,phi)) in each pixels
606 RadSpectra* rs = new PowerLawSpectra
607 (1.,-bigBetaMap(i), 0., normFreq, 0.01, 800.);
608 double coeff = rs->filteredIntegratedFlux(sr);
609 finalMap(i) += coeff*K*mapToAdd(i);
610 }
611}
612
613template <class T>
614void integratedMap(SpectralResponse& sr,
615 SphereHEALPix<T>& betaMap,
616 double normFreq,
617 SphereHEALPix<T>& intBetaMap)
618{
619 PowerLawSpectra rs(1.,-2., 0., normFreq);
620
621 if(betaMap.NbPixels()!=intBetaMap.NbPixels())
622 {
623 Sph2Sph(betaMap,intBetaMap);
624 for(int i=0; i<intBetaMap.NbPixels(); i++)
625 {
626 rs.setExp(-intBetaMap(i));
627 double coeff = rs.filteredIntegratedFlux(sr);
628 intBetaMap(i) = coeff;
629 }
630 }
631 else
632 {
633 for(int i=0; i<intBetaMap.NbPixels(); i++)
634 {
635 rs.setExp(-betaMap(i));
636 double coeff = rs.filteredIntegratedFlux(sr);
637 intBetaMap(i) = coeff;
638 }
639 }
640}
641
642template <class T>
643void addComponentBeta(SphereHEALPix<T>& finalMap,
644 SphereHEALPix<T>& mapToAdd,SphereHEALPix<T>& intBetaMap, double K)
645{
646 // finalMap = finalMap + coeff* mapToAdd
647 // coeff = convolution of sr and rs
648 // compute the coefficient corresponding to mapToAdd
649 // integBetaMap is the map of the integration (nu/normFreq)^(-beta(theta,phi)) over
650 // the spectralResponse
651 // different from addComponentBeta(PixelMap<T>& finalMap,
652 // PixelMap<T>& mapToAdd,SpectralResponse& sr, PixelMap<T>& betaMap, double normFreq, double K)
653 // since it permits to use a intBetaMap with a different number of pixels than
654 // the other maps
655
656 int nbpix = finalMap.NbPixels();
657 if (nbpix != mapToAdd.NbPixels())
658 throw SzMismatchError("addComponentBeta(PixelMap<T>&,PixelMap<T>&,PixelMap<T>&,double)/Error: Unequal number of Input/Output map pixels");
659 double coeff = K;
660
661 if(nbpix != intBetaMap.NbPixels())
662 {
663 for(int i=0; i<finalMap.NbPixels();i++)
664 {
665 double teta,phi,val;
666 finalMap.PixThetaPhi(i, teta, phi);
667 int pixel = intBetaMap.PixIndexSph(teta,phi);
668 val = intBetaMap.PixVal(pixel);
669 finalMap(i) += coeff*mapToAdd(i)*val;
670 }
671 }
672 else
673 {
674 for(int i=0; i<finalMap.NbPixels();i++)
675 {
676 finalMap(i) += coeff*mapToAdd(i)*intBetaMap(i);
677 }
678 }
679 if (printlev > 1)
680 {
681 cout << "addComponentBeta(SG<T>,SG<T>,SG<T>,double) - Coeff= " << K << endl;
682 }
683}
684
685
686
687
688
689/* Nouvelle-Fonction */
690
691/* Nouvelle-Fonction */
692void RadSpec2Nt(RadSpectra & rs, POutPersist & so, string name)
693{
694 char *ntn[2] = {"nu","fnu"};
695 NTuple nt(2,ntn); // Creation NTuple (AVEC new )
696 float xnt[2];
697 double nu;
698 double numin = rs.minFreq();
699 double numax = rs.maxFreq();
700 int nmax = 500;
701 double dnu = (numax-numin)/nmax;
702 for(int k=0; k<nmax; k++) {
703 nu = numin+k*dnu;
704 xnt[0] = nu;
705 xnt[1] = rs.flux(nu);
706 nt.Fill(xnt);
707 }
708 ObjFileIO<NTuple> oiont(nt);
709 oiont.Write(so, name);
710 return;
711}
712
713/* Nouvelle-Fonction */
714void SpectralResponse2Nt(SpectralResponse& sr, POutPersist & so, string name)
715{
716 char *ntn[2] = {"nu","tnu"};
717 NTuple nt(2,ntn); // Creation NTuple (AVEC new )
718 float xnt[2];
719 double nu;
720 double numin = sr.minFreq();
721 double numax = sr.maxFreq();
722 int nmax = 500;
723 double dnu = (numax-numin)/nmax;
724 for(int k=0; k<nmax; k++) {
725 nu = numin+k*dnu;
726 xnt[0] = nu;
727 xnt[1] = sr.transmission(nu);
728 nt.Fill(xnt);
729 }
730 ObjFileIO<NTuple> oiont(nt);
731 oiont.Write(so, name);
732 return;
733}
734
Note: See TracBrowser for help on using the repository browser.