[1738] | 1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
| 2 | // Eric Aubourg
|
---|
| 3 | // Christophe Magneville
|
---|
| 4 | // Reza Ansari
|
---|
[2160] | 5 | // $Id: toi2map.cc,v 1.30 2002-08-05 16:25:13 cmv 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)
|
---|
[2074] | 17 | : mMap(map), mWMap(wmap), mWMapInternal(false), totnscount(0), usednscount(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") {
|
---|
[2160] | 39 | mWMap = new LocalMap<r_8>(*(LocalMap<r_8>*)mMap,false);
|
---|
[1804] | 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;
|
---|
[2074] | 86 | os<<" TotalProcessedSamples="<<ProcessedSampleCount()
|
---|
| 87 | <<" UsedSampleCount="<<UsedSampleCount()<<endl;
|
---|
[1530] | 88 | }
|
---|
| 89 |
|
---|
| 90 | ////////////////////////////////////////////////////////////////////////
|
---|
[1806] | 91 | void TOI2Map::init() {
|
---|
| 92 | cout << "TOI2Map::init" << endl;
|
---|
[1498] | 93 | declareInput("Coord1In"); // input index 0
|
---|
| 94 | declareInput("Coord2In"); // input index 1
|
---|
[1516] | 95 | declareInput("BoloIn"); // input index 2
|
---|
[1463] | 96 | }
|
---|
| 97 |
|
---|
| 98 | ////////////////////////////////////////////////////////////////////////
|
---|
[1746] | 99 | // define SANS_BUFFER
|
---|
[1806] | 100 | void TOI2Map::run()
|
---|
[1463] | 101 | {
|
---|
| 102 | long snb = getMinIn();
|
---|
| 103 | long sne = getMaxIn();
|
---|
| 104 |
|
---|
| 105 | if(snb>sne) {
|
---|
[1806] | 106 | cout<<"TOI2Map::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
|
---|
| 107 | throw ParmError("TOI2Map::run() - Bad sample interval");
|
---|
[1463] | 108 | }
|
---|
| 109 | if(!checkInputTOIIndex(0) || !checkInputTOIIndex(1) || !checkInputTOIIndex(2)) {
|
---|
[1806] | 110 | cout<<"TOI2Map::run() - Input TOI (Coord1In or Coord2In or BoloIn) not connected! "<<endl;
|
---|
| 111 | throw ParmError("TOI2Map::run() Output TOI (Coord1In or Coord2In or BoloIn) not connected!");
|
---|
[1463] | 112 | }
|
---|
[1516] | 113 | if( !(mTypCoorIn&TypCoordEq || mTypCoorIn&TypCoordGal) ) {
|
---|
[1806] | 114 | cout<<"TOI2Map::run() - Input Coordinates not Eq or Gal! "<<endl;
|
---|
| 115 | throw ParmError("TOI2Map::run() - Input Coordinates not Eq or Gal!");
|
---|
[1516] | 116 | }
|
---|
[1809] | 117 | if( !(mTypCoorMap&TypCoordEq || mTypCoorMap&TypCoordGal) ) {
|
---|
[1806] | 118 | cout<<"TOI2Map::run() - Output Coordinates not Eq or Gal! "<<endl;
|
---|
| 119 | throw ParmError("TOI2Map::run() - Output Coordinates not Eq or Gal!");
|
---|
[1516] | 120 | }
|
---|
[1463] | 121 |
|
---|
| 122 | //---------------------------------------------------------
|
---|
| 123 | #define NFILL 25
|
---|
| 124 | try {
|
---|
| 125 |
|
---|
| 126 | int ii;
|
---|
[2100] | 127 | uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL], BadCoorRange=0, nbadsn=0;
|
---|
[1463] | 128 | for(ii=0;ii<NFILL;ii++) NFill[ii]=0;
|
---|
[1516] | 129 | double mjd = MJDfrYear(mActualYear);
|
---|
[1463] | 130 |
|
---|
[1806] | 131 | cout<<"TOI2Map::run() from "<<snb<<" to "<<sne;
|
---|
[1746] | 132 | #ifndef SANS_BUFFER
|
---|
| 133 | int bufsz = 100;
|
---|
| 134 | uint_8* bfgbolo = new uint_8[bufsz];
|
---|
| 135 | double* bbolo = new double[bufsz];
|
---|
| 136 | double* bc1 = new double[bufsz];
|
---|
| 137 | double* bc2 = new double[bufsz];
|
---|
| 138 | int i0 = -1;
|
---|
| 139 | cout<<" (getData() bufferized)"<<endl;
|
---|
| 140 | #else
|
---|
| 141 | cout<<" (getData() not bufferized)"<<endl;
|
---|
| 142 | #endif
|
---|
[1744] | 143 |
|
---|
[1463] | 144 | // Remplissage des spheres
|
---|
| 145 | for(int s=snb;s<=sne;s++) {
|
---|
[1536] | 146 | uint_8 fgbolo = 0;
|
---|
[1746] | 147 | double bolo,coord1,coord2;
|
---|
[1516] | 148 | // Equatoriales / Galactiques
|
---|
| 149 | // coord1,2 = alpha,delta / gLon,gLat
|
---|
[1463] | 150 |
|
---|
[1746] | 151 | #ifndef SANS_BUFFER
|
---|
| 152 | if(i0<0 || s<i0 || s>=i0+bufsz) {
|
---|
| 153 | i0 = s;
|
---|
| 154 | int nget = (sne-s+1<bufsz)? nget=sne-s+1: bufsz;
|
---|
| 155 | getData(0,i0,nget,bc1);
|
---|
| 156 | getData(1,i0,nget,bc2);
|
---|
| 157 | getData(2,i0,nget,bbolo,bfgbolo);
|
---|
[2012] | 158 | totnscount += nget;
|
---|
[1746] | 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);
|
---|
[2012] | 166 | totnscount++;
|
---|
[1746] | 167 | #endif
|
---|
| 168 |
|
---|
| 169 | // Comme il n'y a pas de toi en sortie, il faut dire
|
---|
| 170 | // aux processeur/toi que l'on a plus besoin des donnees.
|
---|
[1724] | 171 | if (s%100 == 0) wontNeedBefore(s-1);
|
---|
[2100] | 172 | //if(fgbolo>0) cout<<fgbolo<<" , "<<(fgbolo&mBadFlag)<<endl;
|
---|
| 173 | if(mTFlag && (fgbolo&mBadFlag)) {nbadsn++; continue;}
|
---|
| 174 | if(mTMin && (bolo<mValMin)) {nbadsn++; continue;}
|
---|
| 175 | if(mTMax && (bolo>mValMax)) {nbadsn++; continue;}
|
---|
[2074] | 176 | usednscount++;
|
---|
[1463] | 177 |
|
---|
[1516] | 178 | // sphere phi entre [0,2*Pi] en radians
|
---|
| 179 | // sphere theta entre [0,Pi] en radians
|
---|
[1809] | 180 | double phi=-1.;
|
---|
| 181 | CoordConvertToStd(mTypCoorIn,&coord1,&coord2);
|
---|
[1786] | 182 |
|
---|
[1809] | 183 | if(mTypCoorIn&TypCoordEq && mTypCoorMap&TypCoordGal) { // Eq -> Gal
|
---|
[1516] | 184 | EqtoGal(mjd,coord1,coord2,&coord1,&coord2);
|
---|
[1809] | 185 | phi = coord1 * Pi/180.;
|
---|
| 186 | } else if(mTypCoorIn&TypCoordGal && mTypCoorMap&TypCoordEq) { // Gal -> Eq
|
---|
[1516] | 187 | GaltoEq(mjd,coord1,coord2,&coord1,&coord2);
|
---|
[1809] | 188 | phi = coord1 * Pi/12.;
|
---|
| 189 | } else if(mTypCoorMap&TypCoordGal) { // Gal -> Gal
|
---|
| 190 | phi = coord1 * Pi/180.;
|
---|
| 191 | } else if(mTypCoorMap&TypCoordEq) { // Eq -> Eq
|
---|
| 192 | phi = coord1 * Pi/12.;
|
---|
[1498] | 193 | }
|
---|
[1809] | 194 | ToCoLat(&coord2,TypUniteD);
|
---|
| 195 | double theta = coord2 * Pi/180.;
|
---|
[1790] | 196 |
|
---|
[1809] | 197 | if(phi<0. | phi>=2*Pi || theta<0. || theta>Pi)
|
---|
| 198 | {BadCoorRange++; continue;}
|
---|
[1786] | 199 |
|
---|
[1804] | 200 | int_4 ipix = mMap->PixIndexSph(theta,phi);
|
---|
[2054] | 201 | if ((ipix < 0) || (ipix >= mMap->NbPixels()) ) continue;
|
---|
[2058] | 202 | (*mMap)(ipix) += bolo*mCalibFactor;
|
---|
[1804] | 203 | ((*mWMap)(ipix)) += 1;
|
---|
[1516] | 204 | mNSnFill++;
|
---|
[1463] | 205 | }
|
---|
| 206 |
|
---|
[2074] | 207 | cout<<"TOI2Map::run(): End of SN loop - TotalProcessedSamples="
|
---|
| 208 | <<ProcessedSampleCount()<<" UsedSampleCount="<<UsedSampleCount()<<endl;
|
---|
[1633] | 209 |
|
---|
[1463] | 210 | // Remplissage des spheres
|
---|
[1804] | 211 | for(int_4 i=0;i<mMap->NbPixels();i++) {
|
---|
| 212 | r_8 wf = (*mWMap)(i);
|
---|
[1809] | 213 | if(wf>0.) {mNpixFill++; (*mMap)(i) /= wf;}
|
---|
[1463] | 214 | int_4 nf = int_4(wf);
|
---|
| 215 | if(nf>=NFILL) nf=NFILL-1; NFill[nf]++;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
[1806] | 218 | cout<<"TOI2Map::run(): mNpixTot="<<mMap->NbPixels()
|
---|
[1463] | 219 | <<" mNpixFill="<<mNpixFill
|
---|
[1804] | 220 | <<" --> FracSky="<<mNpixFill*100./(double)mMap->NbPixels()<<"%"
|
---|
[1516] | 221 | <<" NFill["<<NFILL<<"] ="<<endl;
|
---|
| 222 | for(ii=0;ii<NFILL;ii++) {cout<<NFill[ii]<<" "; if(ii%10==9) cout<<endl;}
|
---|
[1463] | 223 | cout<<endl;
|
---|
[2100] | 224 | cout<<" mNSnFill="<<mNSnFill<<" NBadSn="<<nbadsn
|
---|
| 225 | <<" BadCoorRange="<<BadCoorRange<<endl;
|
---|
[1463] | 226 |
|
---|
[1746] | 227 | #ifndef SANS_BUFFER
|
---|
| 228 | delete [] bbolo; delete [] bfgbolo;
|
---|
| 229 | delete [] bc1; delete [] bc2;
|
---|
| 230 | #endif
|
---|
| 231 |
|
---|
[1463] | 232 | //---------------------------------------------------------
|
---|
| 233 | } catch (PException & exc) {
|
---|
[1806] | 234 | cout<<"TOI2Map: Catched Exception "<<(string)typeid(exc).name()
|
---|
[1463] | 235 | <<"\n .... Msg= "<<exc.Msg()<<endl;
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | return;
|
---|
| 239 | }
|
---|