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