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