[2015] | 1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
| 2 | // Eric Aubourg
|
---|
| 3 | // Christophe Magneville
|
---|
| 4 | // Reza Ansari
|
---|
[2020] | 5 | // $Id: flag2map.cc,v 1.2 2002-05-29 10:18:45 ansari Exp $
|
---|
[2015] | 6 |
|
---|
| 7 | #include "machdefs.h"
|
---|
| 8 | #include "toimanager.h"
|
---|
| 9 | #include "pexceptions.h"
|
---|
| 10 | #include "ctimer.h"
|
---|
| 11 | #include "flag2map.h"
|
---|
| 12 | // La valeur "Pi" doit etre celle de smathconst.h a cause du test sur theta
|
---|
| 13 | #include "smathconst.h"
|
---|
| 14 |
|
---|
| 15 | ////////////////////////////////////////////////////////////////////////
|
---|
| 16 | FLAG2Map::FLAG2Map(PixelMap<r_8>* map,PixelMap<r_8>* wmap)
|
---|
| 17 | : mMap(map), mWMap(wmap), mWMapInternal(false), totnscount(0)
|
---|
| 18 | {
|
---|
| 19 | SetEquinox();
|
---|
| 20 | SetCoorIn();
|
---|
| 21 | SetCoorMap();
|
---|
| 22 | SetTestFlag();
|
---|
| 23 | SetTestMin();
|
---|
| 24 | SetTestMax();
|
---|
| 25 |
|
---|
| 26 | if(mMap->NbPixels()<1) {
|
---|
| 27 | cout<<"FLAG2Map::FLAG2Map() Bad number of pixels in sphere mMap "
|
---|
| 28 | <<mMap->NbPixels()<<endl;
|
---|
| 29 | throw ParmError("FLAG2Map::FLAG2Map() - Bad number of pixels in sphere");
|
---|
| 30 | }
|
---|
| 31 | mMap->SetPixels(0.);
|
---|
| 32 | int nlat = mMap->SizeIndex();
|
---|
| 33 | string typmap = mMap->TypeOfMap();
|
---|
| 34 |
|
---|
| 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 {
|
---|
| 42 | cout << "FLAG2Map::FLAG2Map() cannot handle map of type " << typmap << endl;
|
---|
| 43 | throw ParmError("FLAG2Map::FLAG2Map() - bad type of map");
|
---|
| 44 | }
|
---|
| 45 | mWMapInternal = true;
|
---|
| 46 | } else {
|
---|
| 47 | mWMapInternal = false;
|
---|
| 48 | if(nlat != mWMap->SizeIndex()) {
|
---|
| 49 | cout<<"FLAG2Map::FLAG2Map() Bad size for sphere mWMap, does not "
|
---|
| 50 | <<"correspond to mMap : "<<mMap->SizeIndex()<<", "<<mWMap->SizeIndex()<<endl;
|
---|
| 51 | if (typmap == "LOCAL") {
|
---|
| 52 | throw ParmError("FLAG2Map::FLAG2Map() - 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 << "FLAG2Map::FLAG2Map() cannot handle map of type " << typmap << endl;
|
---|
| 58 | throw ParmError("FLAG2Map::FLAG2Map() - bad type of map");
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | if(mWMap->NbPixels()<1) {
|
---|
| 63 | cout<<"FLAG2Map::FLAG2Map() Bad number of pixels in sphere mWMap "
|
---|
| 64 | <<mWMap->NbPixels()<<endl;
|
---|
| 65 | throw ParmError("FLAG2Map::FLAG2Map() - Bad number of pixels in sphere");
|
---|
| 66 | }
|
---|
| 67 | mWMap->SetPixels(0);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | FLAG2Map::~FLAG2Map()
|
---|
| 71 | {
|
---|
| 72 | if(mWMap && mWMapInternal) delete mWMap;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | ////////////////////////////////////////////////////////////////////////
|
---|
| 76 | void FLAG2Map::Print(::ostream & os)
|
---|
| 77 | {
|
---|
| 78 | os<<"FLAG2Map::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;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | ////////////////////////////////////////////////////////////////////////
|
---|
| 88 | void FLAG2Map::init() {
|
---|
| 89 | cout << "FLAG2Map::init" << endl;
|
---|
| 90 | declareInput("Coord1In"); // input index 0
|
---|
| 91 | declareInput("Coord2In"); // input index 1
|
---|
| 92 | declareInput("BoloIn"); // input index 2
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | ////////////////////////////////////////////////////////////////////////
|
---|
| 96 | // define SANS_BUFFER
|
---|
| 97 | void FLAG2Map::run()
|
---|
| 98 | {
|
---|
| 99 | long snb = getMinIn();
|
---|
| 100 | long sne = getMaxIn();
|
---|
| 101 |
|
---|
| 102 | if(snb>sne) {
|
---|
| 103 | cout<<"FLAG2Map::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
|
---|
| 104 | throw ParmError("FLAG2Map::run() - Bad sample interval");
|
---|
| 105 | }
|
---|
| 106 | if(!checkInputTOIIndex(0) || !checkInputTOIIndex(1) || !checkInputTOIIndex(2)) {
|
---|
| 107 | cout<<"FLAG2Map::run() - Input TOI (Coord1In or Coord2In or BoloIn) not connected! "<<endl;
|
---|
| 108 | throw ParmError("FLAG2Map::run() Output TOI (Coord1In or Coord2In or BoloIn) not connected!");
|
---|
| 109 | }
|
---|
| 110 | if( !(mTypCoorIn&TypCoordEq || mTypCoorIn&TypCoordGal) ) {
|
---|
| 111 | cout<<"FLAG2Map::run() - Input Coordinates not Eq or Gal! "<<endl;
|
---|
| 112 | throw ParmError("FLAG2Map::run() - Input Coordinates not Eq or Gal!");
|
---|
| 113 | }
|
---|
| 114 | if( !(mTypCoorMap&TypCoordEq || mTypCoorMap&TypCoordGal) ) {
|
---|
| 115 | cout<<"FLAG2Map::run() - Output Coordinates not Eq or Gal! "<<endl;
|
---|
| 116 | throw ParmError("FLAG2Map::run() - Output Coordinates not Eq or Gal!");
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | //---------------------------------------------------------
|
---|
| 120 | #define NFILL 25
|
---|
| 121 | try {
|
---|
| 122 |
|
---|
| 123 | int ii;
|
---|
| 124 | uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL], BadCoorRange=0;
|
---|
| 125 | for(ii=0;ii<NFILL;ii++) NFill[ii]=0;
|
---|
| 126 | double mjd = MJDfrYear(mActualYear);
|
---|
| 127 |
|
---|
| 128 | cout<<"FLAG2Map::run() from "<<snb<<" to "<<sne;
|
---|
| 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
|
---|
| 140 |
|
---|
| 141 | // Remplissage des spheres
|
---|
| 142 | for(int s=snb;s<=sne;s++) {
|
---|
| 143 | uint_8 fgbolo = 0;
|
---|
| 144 | double bolo,coord1,coord2;
|
---|
| 145 | // Equatoriales / Galactiques
|
---|
| 146 | // coord1,2 = alpha,delta / gLon,gLat
|
---|
| 147 |
|
---|
| 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);
|
---|
| 155 | totnscount += nget;
|
---|
| 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);
|
---|
| 163 | totnscount++;
|
---|
| 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.
|
---|
| 168 | if (s%100 == 0) wontNeedBefore(s-1);
|
---|
| 169 | // if(mTFlag && fgbolo&mBadFlag) continue;
|
---|
| 170 | if(mTMin && bolo<mValMin) continue;
|
---|
| 171 | if(mTMax && bolo>mValMax) continue;
|
---|
| 172 |
|
---|
[2020] | 173 | cout << "sn " << s << " val " << bolo << " fgbolo " << fgbolo << endl;
|
---|
[2015] | 174 |
|
---|
| 175 |
|
---|
| 176 | if (fgbolo != 2) continue;
|
---|
| 177 | // pas un glitch;
|
---|
| 178 |
|
---|
| 179 | // sphere phi entre [0,2*Pi] en radians
|
---|
| 180 | // sphere theta entre [0,Pi] en radians
|
---|
| 181 | double phi=-1.;
|
---|
| 182 | CoordConvertToStd(mTypCoorIn,&coord1,&coord2);
|
---|
| 183 |
|
---|
| 184 | if(mTypCoorIn&TypCoordEq && mTypCoorMap&TypCoordGal) { // Eq -> Gal
|
---|
| 185 | EqtoGal(mjd,coord1,coord2,&coord1,&coord2);
|
---|
| 186 | phi = coord1 * Pi/180.;
|
---|
| 187 | } else if(mTypCoorIn&TypCoordGal && mTypCoorMap&TypCoordEq) { // Gal -> Eq
|
---|
| 188 | GaltoEq(mjd,coord1,coord2,&coord1,&coord2);
|
---|
| 189 | phi = coord1 * Pi/12.;
|
---|
| 190 | } else if(mTypCoorMap&TypCoordGal) { // Gal -> Gal
|
---|
| 191 | phi = coord1 * Pi/180.;
|
---|
| 192 | } else if(mTypCoorMap&TypCoordEq) { // Eq -> Eq
|
---|
| 193 | phi = coord1 * Pi/12.;
|
---|
| 194 | }
|
---|
| 195 | ToCoLat(&coord2,TypUniteD);
|
---|
| 196 | double theta = coord2 * Pi/180.;
|
---|
| 197 |
|
---|
| 198 | if(phi<0. | phi>=2*Pi || theta<0. || theta>Pi)
|
---|
| 199 | {BadCoorRange++; continue;}
|
---|
| 200 |
|
---|
| 201 | int_4 ipix = mMap->PixIndexSph(theta,phi);
|
---|
| 202 | (*mMap)(ipix) += bolo;
|
---|
| 203 | ((*mWMap)(ipix)) += 1;
|
---|
| 204 | mNSnFill++;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | cout<<"FLAG2Map::run(): Fin de boucle sur les sampleNum"<<endl;
|
---|
| 208 |
|
---|
| 209 | // Remplissage des spheres
|
---|
| 210 | for(int_4 i=0;i<mMap->NbPixels();i++) {
|
---|
| 211 | r_8 wf = (*mWMap)(i);
|
---|
| 212 | if(wf>0.) {mNpixFill++; (*mMap)(i) /= wf;}
|
---|
| 213 | int_4 nf = int_4(wf);
|
---|
| 214 | if(nf>=NFILL) nf=NFILL-1; NFill[nf]++;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | cout<<"FLAG2Map::run(): mNpixTot="<<mMap->NbPixels()
|
---|
| 218 | <<" mNpixFill="<<mNpixFill
|
---|
| 219 | <<" mNSnFill="<<mNSnFill<<endl
|
---|
| 220 | <<" --> FracSky="<<mNpixFill*100./(double)mMap->NbPixels()<<"%"
|
---|
| 221 | <<" NFill["<<NFILL<<"] ="<<endl;
|
---|
| 222 | for(ii=0;ii<NFILL;ii++) {cout<<NFill[ii]<<" "; if(ii%10==9) cout<<endl;}
|
---|
| 223 | cout<<endl;
|
---|
| 224 | cout<<" BadCoorRange="<<BadCoorRange<<endl;
|
---|
| 225 |
|
---|
| 226 | #ifndef SANS_BUFFER
|
---|
| 227 | delete [] bbolo; delete [] bfgbolo;
|
---|
| 228 | delete [] bc1; delete [] bc2;
|
---|
| 229 | #endif
|
---|
| 230 |
|
---|
| 231 | //---------------------------------------------------------
|
---|
| 232 | } catch (PException & exc) {
|
---|
| 233 | cout<<"FLAG2Map: Catched Exception "<<(string)typeid(exc).name()
|
---|
| 234 | <<"\n .... Msg= "<<exc.Msg()<<endl;
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | return;
|
---|
| 238 | }
|
---|