[1463] | 1 | #include "machdefs.h"
|
---|
| 2 | #include "toimanager.h"
|
---|
| 3 | #include "pexceptions.h"
|
---|
| 4 | #include "ctimer.h"
|
---|
| 5 | #include "toi2map.h"
|
---|
| 6 |
|
---|
| 7 | ////////////////////////////////////////////////////////////////////////
|
---|
| 8 | TOI2Map::TOI2Map(SphereHEALPix<r_8>* sph,SphereHEALPix<r_8>* wsph)
|
---|
[1516] | 9 | : mSph(sph), mWSph(wsph), mWSphInternal(false)
|
---|
[1463] | 10 | {
|
---|
[1516] | 11 | SetEquinox();
|
---|
| 12 | SetCoorIn();
|
---|
| 13 | SetCoorOut();
|
---|
| 14 |
|
---|
[1463] | 15 | if(mSph->NbPixels()<1) {
|
---|
| 16 | cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mSph "
|
---|
| 17 | <<mSph->NbPixels()<<endl;
|
---|
| 18 | throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
|
---|
| 19 | }
|
---|
| 20 | mSph->SetPixels(0.);
|
---|
| 21 | int nlat = mSph->SizeIndex();
|
---|
| 22 |
|
---|
| 23 | if(mWSph==NULL) {
|
---|
| 24 | mWSph = new SphereHEALPix<r_8>(nlat);
|
---|
| 25 | mWSphInternal = true;
|
---|
| 26 | } else {
|
---|
| 27 | mWSphInternal = false;
|
---|
| 28 | if(nlat != mWSph->SizeIndex()) mWSph->Resize(nlat);
|
---|
| 29 | }
|
---|
| 30 | if(mWSph->NbPixels()<1) {
|
---|
| 31 | cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mWSph "
|
---|
| 32 | <<mWSph->NbPixels()<<endl;
|
---|
| 33 | throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
|
---|
| 34 | }
|
---|
| 35 | mWSph->SetPixels(0);
|
---|
| 36 |
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | TOI2Map::~TOI2Map()
|
---|
| 40 | {
|
---|
| 41 | if(mWSph && !mWSphInternal) delete mWSph;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | ////////////////////////////////////////////////////////////////////////
|
---|
| 45 | void TOI2Map::init() {
|
---|
| 46 | cout << "TOI2Map::init" << endl;
|
---|
[1498] | 47 | declareInput("Coord1In"); // input index 0
|
---|
| 48 | declareInput("Coord2In"); // input index 1
|
---|
[1516] | 49 | declareInput("BoloIn"); // input index 2
|
---|
[1463] | 50 | }
|
---|
| 51 |
|
---|
| 52 | ////////////////////////////////////////////////////////////////////////
|
---|
| 53 | void TOI2Map::run()
|
---|
| 54 | {
|
---|
| 55 | long snb = getMinIn();
|
---|
| 56 | long sne = getMaxIn();
|
---|
| 57 |
|
---|
| 58 | if(snb>sne) {
|
---|
| 59 | cout<<"TOI2Map::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
|
---|
| 60 | throw ParmError("TOI2Map::run() - Bad sample interval");
|
---|
| 61 | }
|
---|
| 62 | if(!checkInputTOIIndex(0) || !checkInputTOIIndex(1) || !checkInputTOIIndex(2)) {
|
---|
[1498] | 63 | cout<<"TOI2Map::run() - Input TOI (Coord1In or Coord2In or BoloIn) not connected! "<<endl;
|
---|
| 64 | throw ParmError("TOI2Map::run() Output TOI (Coord1In or Coord2In or BoloIn) not connected!");
|
---|
[1463] | 65 | }
|
---|
[1516] | 66 | if( !(mTypCoorIn&TypCoordEq || mTypCoorIn&TypCoordGal) ) {
|
---|
| 67 | cout<<"TOI2Map::run() - Input Coordinates not Eq or Gal! "<<endl;
|
---|
| 68 | throw ParmError("TOI2Map::run() - Input Coordinates not Eq or Gal!");
|
---|
| 69 | }
|
---|
| 70 | if( !(mTypCoorOut&TypCoordEq || mTypCoorOut&TypCoordGal) ) {
|
---|
| 71 | cout<<"TOI2Map::run() - Output Coordinates not Eq or Gal! "<<endl;
|
---|
| 72 | throw ParmError("TOI2Map::run() - Output Coordinates not Eq or Gal!");
|
---|
| 73 | }
|
---|
[1463] | 74 |
|
---|
| 75 | //---------------------------------------------------------
|
---|
| 76 | #define NFILL 25
|
---|
| 77 | try {
|
---|
| 78 |
|
---|
| 79 | int ii;
|
---|
| 80 | uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL];
|
---|
| 81 | for(ii=0;ii<NFILL;ii++) NFill[ii]=0;
|
---|
[1516] | 82 | double mjd = MJDfrYear(mActualYear);
|
---|
[1463] | 83 |
|
---|
| 84 | // Remplissage des spheres
|
---|
| 85 | for(int s=snb;s<=sne;s++) {
|
---|
[1516] | 86 | int_8 fgbolo = 0;
|
---|
[1466] | 87 | double bolo;
|
---|
[1516] | 88 | // Equatoriales / Galactiques
|
---|
| 89 | // coord1,2 = alpha,delta / gLon,gLat
|
---|
| 90 | double coord1 = getData(0,s);
|
---|
| 91 | double coord2 = getData(1,s);
|
---|
[1463] | 92 |
|
---|
[1466] | 93 | getData(2,s,bolo,fgbolo);
|
---|
[1516] | 94 | if(bolo<-32767.) continue; // Bidouille (A CORRIGER QUAND FGBOLO DISPO)
|
---|
[1463] | 95 |
|
---|
[1516] | 96 | // sphere phi entre [0,2*Pi] en radians
|
---|
| 97 | // sphere theta entre [0,Pi] en radians
|
---|
| 98 | double phi,theta;
|
---|
| 99 | CoordConvertToStd(mTypCoorIn,coord1,coord2);
|
---|
| 100 | if(mTypCoorIn&TypCoordEq && mTypCoorOut&TypCoordGal) { // Eq -> Gal
|
---|
| 101 | EqtoGal(mjd,coord1,coord2,&coord1,&coord2);
|
---|
| 102 | phi = coord1 * M_PI/180.;
|
---|
| 103 | } else if(mTypCoorIn&TypCoordGal && mTypCoorOut&TypCoordEq) { // Gal -> Eq
|
---|
| 104 | GaltoEq(mjd,coord1,coord2,&coord1,&coord2);
|
---|
| 105 | phi = coord1 * M_PI/12.;
|
---|
| 106 | } else if(mTypCoorOut&TypCoordGal) { // Gal -> Gal
|
---|
| 107 | phi = coord1 * M_PI/180.;
|
---|
| 108 | } else if(mTypCoorOut&TypCoordEq) { // Eq -> Eq
|
---|
| 109 | phi = coord1 * M_PI/12.;
|
---|
[1498] | 110 | }
|
---|
[1516] | 111 | theta = (90.-coord2) * M_PI/180.;
|
---|
| 112 | if(phi<0. || phi>=2*M_PI) continue;
|
---|
| 113 | if(theta<0. || theta>=M_PI) continue;
|
---|
[1498] | 114 |
|
---|
[1516] | 115 | int_4 ipix = mSph->PixIndexSph(theta,phi);
|
---|
| 116 | (*mSph)(ipix) += bolo;
|
---|
| 117 | ((*mWSph)(ipix))++;
|
---|
| 118 | mNSnFill++;
|
---|
[1463] | 119 | }
|
---|
| 120 |
|
---|
| 121 | // Remplissage des spheres
|
---|
| 122 | for(int_4 i=0;i<mSph->NbPixels();i++) {
|
---|
| 123 | r_8 wf = (*mWSph)(i);
|
---|
| 124 | if( wf > 0. ) {
|
---|
| 125 | mNpixFill++;
|
---|
| 126 | (*mSph)(i) /= wf;
|
---|
| 127 | }
|
---|
| 128 | int_4 nf = int_4(wf);
|
---|
| 129 | if(nf>=NFILL) nf=NFILL-1; NFill[nf]++;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | cout<<"TOI2Map::run(): mNpixTot="<<mSph->NbPixels()
|
---|
| 133 | <<" mNpixFill="<<mNpixFill
|
---|
| 134 | <<" mNSnFill="<<mNSnFill<<endl
|
---|
[1516] | 135 | <<" --> FracSky="<<mNpixFill*100./(double)mSph->NbPixels()<<"%"
|
---|
| 136 | <<" NFill["<<NFILL<<"] ="<<endl;
|
---|
| 137 | for(ii=0;ii<NFILL;ii++) {cout<<NFill[ii]<<" "; if(ii%10==9) cout<<endl;}
|
---|
[1463] | 138 | cout<<endl;
|
---|
| 139 |
|
---|
| 140 | //---------------------------------------------------------
|
---|
| 141 | } catch (PException & exc) {
|
---|
| 142 | cout<<"TOI2Map: Catched Exception "<<(string)typeid(exc).name()
|
---|
| 143 | <<"\n .... Msg= "<<exc.Msg()<<endl;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | return;
|
---|
| 147 | }
|
---|