[1738] | 1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
| 2 | // Eric Aubourg
|
---|
| 3 | // Christophe Magneville
|
---|
| 4 | // Reza Ansari
|
---|
[1792] | 5 | // $Id: toi2map.cc,v 1.19 2001-11-27 12:12:12 aubourg Exp $
|
---|
[1738] | 6 |
|
---|
[1463] | 7 | #include "machdefs.h"
|
---|
| 8 | #include "toimanager.h"
|
---|
| 9 | #include "pexceptions.h"
|
---|
| 10 | #include "ctimer.h"
|
---|
| 11 | #include "toi2map.h"
|
---|
| 12 |
|
---|
| 13 | ////////////////////////////////////////////////////////////////////////
|
---|
| 14 | TOI2Map::TOI2Map(SphereHEALPix<r_8>* sph,SphereHEALPix<r_8>* wsph)
|
---|
[1516] | 15 | : mSph(sph), mWSph(wsph), mWSphInternal(false)
|
---|
[1463] | 16 | {
|
---|
[1516] | 17 | SetEquinox();
|
---|
| 18 | SetCoorIn();
|
---|
| 19 | SetCoorOut();
|
---|
[1530] | 20 | SetTestFlag();
|
---|
| 21 | SetTestMin();
|
---|
| 22 | SetTestMax();
|
---|
[1516] | 23 |
|
---|
[1792] | 24 | mIsColat = false;
|
---|
| 25 |
|
---|
[1463] | 26 | if(mSph->NbPixels()<1) {
|
---|
| 27 | cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mSph "
|
---|
| 28 | <<mSph->NbPixels()<<endl;
|
---|
| 29 | throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
|
---|
| 30 | }
|
---|
| 31 | mSph->SetPixels(0.);
|
---|
| 32 | int nlat = mSph->SizeIndex();
|
---|
| 33 |
|
---|
| 34 | if(mWSph==NULL) {
|
---|
| 35 | mWSph = new SphereHEALPix<r_8>(nlat);
|
---|
| 36 | mWSphInternal = true;
|
---|
| 37 | } else {
|
---|
| 38 | mWSphInternal = false;
|
---|
| 39 | if(nlat != mWSph->SizeIndex()) mWSph->Resize(nlat);
|
---|
| 40 | }
|
---|
| 41 | if(mWSph->NbPixels()<1) {
|
---|
| 42 | cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mWSph "
|
---|
| 43 | <<mWSph->NbPixels()<<endl;
|
---|
| 44 | throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
|
---|
| 45 | }
|
---|
| 46 | mWSph->SetPixels(0);
|
---|
| 47 |
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | TOI2Map::~TOI2Map()
|
---|
| 51 | {
|
---|
[1629] | 52 | if(mWSph && mWSphInternal) delete mWSph;
|
---|
[1463] | 53 | }
|
---|
| 54 |
|
---|
| 55 | ////////////////////////////////////////////////////////////////////////
|
---|
[1762] | 56 | void TOI2Map::Print(::ostream & os)
|
---|
[1530] | 57 | {
|
---|
| 58 | os<<"TOI2Map::Print -- Sphere NLat = "<<mSph->SizeIndex()<<endl
|
---|
| 59 |
|
---|
| 60 | <<" - Equinoxe="<<mActualYear<<endl
|
---|
| 61 |
|
---|
| 62 | <<" - TypCoorIn: Gal("<<((mTypCoorIn&TypCoordGal)?1:0)
|
---|
| 63 | <<") Eq("<<((mTypCoorIn&TypCoordEq)?1:0)
|
---|
| 64 | <<") Deg("<<((mTypCoorIn&TypCoordDD)?1:0)
|
---|
| 65 | <<") Hour("<<((mTypCoorIn&TypCoordHD)?1:0)
|
---|
| 66 | <<") Rad("<<((mTypCoorIn&TypCoordRR)?1:0)<<")"<<endl
|
---|
| 67 |
|
---|
| 68 | <<" - TypCoorOut: Gal("<<((mTypCoorOut&TypCoordGal)?1:0)
|
---|
| 69 | <<") Eq("<<((mTypCoorOut&TypCoordEq)?1:0)
|
---|
| 70 | <<") Deg("<<((mTypCoorOut&TypCoordDD)?1:0)
|
---|
| 71 | <<") Hour("<<((mTypCoorOut&TypCoordHD)?1:0)
|
---|
| 72 | <<") Rad("<<((mTypCoorOut&TypCoordRR)?1:0)<<")"<<endl
|
---|
| 73 |
|
---|
| 74 | <<" - Tests: Flag("<<mTFlag<<") bad="<<mBadFlag
|
---|
| 75 | <<" / Value Min("<<mTMin<<")="<<mValMin
|
---|
| 76 | <<" , Max("<<mTMax<<")="<<mValMax<<endl;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | ////////////////////////////////////////////////////////////////////////
|
---|
[1463] | 80 | void TOI2Map::init() {
|
---|
| 81 | cout << "TOI2Map::init" << endl;
|
---|
[1498] | 82 | declareInput("Coord1In"); // input index 0
|
---|
| 83 | declareInput("Coord2In"); // input index 1
|
---|
[1516] | 84 | declareInput("BoloIn"); // input index 2
|
---|
[1463] | 85 | }
|
---|
| 86 |
|
---|
| 87 | ////////////////////////////////////////////////////////////////////////
|
---|
[1746] | 88 | // define SANS_BUFFER
|
---|
[1463] | 89 | void TOI2Map::run()
|
---|
| 90 | {
|
---|
| 91 | long snb = getMinIn();
|
---|
| 92 | long sne = getMaxIn();
|
---|
| 93 |
|
---|
| 94 | if(snb>sne) {
|
---|
| 95 | cout<<"TOI2Map::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
|
---|
| 96 | throw ParmError("TOI2Map::run() - Bad sample interval");
|
---|
| 97 | }
|
---|
| 98 | if(!checkInputTOIIndex(0) || !checkInputTOIIndex(1) || !checkInputTOIIndex(2)) {
|
---|
[1498] | 99 | cout<<"TOI2Map::run() - Input TOI (Coord1In or Coord2In or BoloIn) not connected! "<<endl;
|
---|
| 100 | throw ParmError("TOI2Map::run() Output TOI (Coord1In or Coord2In or BoloIn) not connected!");
|
---|
[1463] | 101 | }
|
---|
[1516] | 102 | if( !(mTypCoorIn&TypCoordEq || mTypCoorIn&TypCoordGal) ) {
|
---|
| 103 | cout<<"TOI2Map::run() - Input Coordinates not Eq or Gal! "<<endl;
|
---|
| 104 | throw ParmError("TOI2Map::run() - Input Coordinates not Eq or Gal!");
|
---|
| 105 | }
|
---|
| 106 | if( !(mTypCoorOut&TypCoordEq || mTypCoorOut&TypCoordGal) ) {
|
---|
| 107 | cout<<"TOI2Map::run() - Output Coordinates not Eq or Gal! "<<endl;
|
---|
| 108 | throw ParmError("TOI2Map::run() - Output Coordinates not Eq or Gal!");
|
---|
| 109 | }
|
---|
[1463] | 110 |
|
---|
| 111 | //---------------------------------------------------------
|
---|
| 112 | #define NFILL 25
|
---|
| 113 | try {
|
---|
| 114 |
|
---|
| 115 | int ii;
|
---|
| 116 | uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL];
|
---|
| 117 | for(ii=0;ii<NFILL;ii++) NFill[ii]=0;
|
---|
[1516] | 118 | double mjd = MJDfrYear(mActualYear);
|
---|
[1463] | 119 |
|
---|
[1746] | 120 | cout<<"TOI2Map::run() from "<<snb<<" to "<<sne;
|
---|
| 121 | #ifndef SANS_BUFFER
|
---|
| 122 | int bufsz = 100;
|
---|
| 123 | uint_8* bfgbolo = new uint_8[bufsz];
|
---|
| 124 | double* bbolo = new double[bufsz];
|
---|
| 125 | double* bc1 = new double[bufsz];
|
---|
| 126 | double* bc2 = new double[bufsz];
|
---|
| 127 | int i0 = -1;
|
---|
| 128 | cout<<" (getData() bufferized)"<<endl;
|
---|
| 129 | #else
|
---|
| 130 | cout<<" (getData() not bufferized)"<<endl;
|
---|
| 131 | #endif
|
---|
[1744] | 132 |
|
---|
[1463] | 133 | // Remplissage des spheres
|
---|
| 134 | for(int s=snb;s<=sne;s++) {
|
---|
[1536] | 135 | uint_8 fgbolo = 0;
|
---|
[1746] | 136 | double bolo,coord1,coord2;
|
---|
[1516] | 137 | // Equatoriales / Galactiques
|
---|
| 138 | // coord1,2 = alpha,delta / gLon,gLat
|
---|
[1463] | 139 |
|
---|
[1746] | 140 | #ifndef SANS_BUFFER
|
---|
| 141 | if(i0<0 || s<i0 || s>=i0+bufsz) {
|
---|
| 142 | i0 = s;
|
---|
| 143 | int nget = (sne-s+1<bufsz)? nget=sne-s+1: bufsz;
|
---|
| 144 | getData(0,i0,nget,bc1);
|
---|
| 145 | getData(1,i0,nget,bc2);
|
---|
| 146 | getData(2,i0,nget,bbolo,bfgbolo);
|
---|
| 147 | }
|
---|
| 148 | bolo = bbolo[s-i0]; fgbolo = bfgbolo[s-i0];
|
---|
| 149 | coord1 = bc1[s-i0]; coord2 = bc2[s-i0];
|
---|
| 150 | #else
|
---|
| 151 | getData(2,s,bolo,fgbolo);
|
---|
| 152 | coord1 = getData(0,s);
|
---|
| 153 | coord2 = getData(1,s);
|
---|
| 154 | #endif
|
---|
| 155 |
|
---|
| 156 | // Comme il n'y a pas de toi en sortie, il faut dire
|
---|
| 157 | // aux processeur/toi que l'on a plus besoin des donnees.
|
---|
[1724] | 158 | if (s%100 == 0) wontNeedBefore(s-1);
|
---|
[1530] | 159 | if(mTFlag && fgbolo&mBadFlag) continue;
|
---|
| 160 | if(mTMin && bolo<mValMin) continue;
|
---|
| 161 | if(mTMax && bolo>mValMax) continue;
|
---|
[1463] | 162 |
|
---|
[1516] | 163 | // sphere phi entre [0,2*Pi] en radians
|
---|
| 164 | // sphere theta entre [0,Pi] en radians
|
---|
[1520] | 165 | double phi=-1.,theta;
|
---|
[1789] | 166 | CoordConvertToStd(mTypCoorIn,coord1,coord2);
|
---|
[1786] | 167 |
|
---|
[1516] | 168 | if(mTypCoorIn&TypCoordEq && mTypCoorOut&TypCoordGal) { // Eq -> Gal
|
---|
| 169 | EqtoGal(mjd,coord1,coord2,&coord1,&coord2);
|
---|
| 170 | phi = coord1 * M_PI/180.;
|
---|
| 171 | } else if(mTypCoorIn&TypCoordGal && mTypCoorOut&TypCoordEq) { // Gal -> Eq
|
---|
| 172 | GaltoEq(mjd,coord1,coord2,&coord1,&coord2);
|
---|
| 173 | phi = coord1 * M_PI/12.;
|
---|
| 174 | } else if(mTypCoorOut&TypCoordGal) { // Gal -> Gal
|
---|
| 175 | phi = coord1 * M_PI/180.;
|
---|
| 176 | } else if(mTypCoorOut&TypCoordEq) { // Eq -> Eq
|
---|
| 177 | phi = coord1 * M_PI/12.;
|
---|
[1498] | 178 | }
|
---|
[1790] | 179 |
|
---|
| 180 | if (phi<0) phi += 2*M_PI;
|
---|
| 181 | if (phi>=2*M_PI) phi -= 2*M_PI;
|
---|
[1792] | 182 | if (mIsColat) {
|
---|
| 183 | theta = coord2 * M_PI/180;
|
---|
| 184 | } else {
|
---|
| 185 | theta = (90.-coord2) * M_PI/180.;
|
---|
| 186 | }
|
---|
[1786] | 187 |
|
---|
[1516] | 188 | if(phi<0. || phi>=2*M_PI) continue;
|
---|
| 189 | if(theta<0. || theta>=M_PI) continue;
|
---|
[1498] | 190 |
|
---|
[1516] | 191 | int_4 ipix = mSph->PixIndexSph(theta,phi);
|
---|
| 192 | (*mSph)(ipix) += bolo;
|
---|
[1530] | 193 | ((*mWSph)(ipix)) += 1;
|
---|
[1516] | 194 | mNSnFill++;
|
---|
[1463] | 195 | }
|
---|
| 196 |
|
---|
[1633] | 197 | cout<<"TOI2Map::run(): Fin de boucle sur les sampleNum"<<endl;
|
---|
| 198 |
|
---|
[1463] | 199 | // Remplissage des spheres
|
---|
| 200 | for(int_4 i=0;i<mSph->NbPixels();i++) {
|
---|
| 201 | r_8 wf = (*mWSph)(i);
|
---|
| 202 | if( wf > 0. ) {
|
---|
| 203 | mNpixFill++;
|
---|
| 204 | (*mSph)(i) /= wf;
|
---|
| 205 | }
|
---|
| 206 | int_4 nf = int_4(wf);
|
---|
| 207 | if(nf>=NFILL) nf=NFILL-1; NFill[nf]++;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | cout<<"TOI2Map::run(): mNpixTot="<<mSph->NbPixels()
|
---|
| 211 | <<" mNpixFill="<<mNpixFill
|
---|
| 212 | <<" mNSnFill="<<mNSnFill<<endl
|
---|
[1516] | 213 | <<" --> FracSky="<<mNpixFill*100./(double)mSph->NbPixels()<<"%"
|
---|
| 214 | <<" NFill["<<NFILL<<"] ="<<endl;
|
---|
| 215 | for(ii=0;ii<NFILL;ii++) {cout<<NFill[ii]<<" "; if(ii%10==9) cout<<endl;}
|
---|
[1463] | 216 | cout<<endl;
|
---|
| 217 |
|
---|
[1746] | 218 | #ifndef SANS_BUFFER
|
---|
| 219 | delete [] bbolo; delete [] bfgbolo;
|
---|
| 220 | delete [] bc1; delete [] bc2;
|
---|
| 221 | #endif
|
---|
| 222 |
|
---|
[1463] | 223 | //---------------------------------------------------------
|
---|
| 224 | } catch (PException & exc) {
|
---|
| 225 | cout<<"TOI2Map: Catched Exception "<<(string)typeid(exc).name()
|
---|
| 226 | <<"\n .... Msg= "<<exc.Msg()<<endl;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | return;
|
---|
| 230 | }
|
---|