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