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