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