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