source: Sophya/trunk/ArchTOIPipe/ProcWSophya/toi2map.cc@ 2390

Last change on this file since 2390 was 2314, checked in by aubourg, 23 years ago

patch temporaire pour corriger bug introduit en apparence par le nouveau constructeur

File size: 9.0 KB
RevLine 
[1738]1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
[2314]5// $Id: toi2map.cc,v 1.33 2003-01-27 07:56:04 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]19TOI2Map::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]28TOI2Map::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
35void 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]88TOI2Map::~TOI2Map()
[1463]89{
[1804]90 if(mWMap && mWMapInternal) delete mWMap;
[1463]91}
92
93////////////////////////////////////////////////////////////////////////
[1806]94void 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]108void 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]117void TOI2Map::run()
[1463]118{
119long snb = getMinIn();
120long sne = getMaxIn();
121
122if(snb>sne) {
[1806]123 cout<<"TOI2Map::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
124 throw ParmError("TOI2Map::run() - Bad sample interval");
[1463]125}
126if(!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]130if( !(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]134if( !(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
141try {
142
143int ii;
[2100]144uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL], BadCoorRange=0, nbadsn=0;
[1463]145for(ii=0;ii<NFILL;ii++) NFill[ii]=0;
[1516]146double mjd = MJDfrYear(mActualYear);
[1463]147
[1806]148cout<<"TOI2Map::run() from "<<snb<<" to "<<sne;
[1746]149#ifndef SANS_BUFFER
150int bufsz = 100;
151uint_8* bfgbolo = new uint_8[bufsz];
152double* bbolo = new double[bufsz];
153double* bc1 = new double[bufsz];
154double* bc2 = new double[bufsz];
155int i0 = -1;
156cout<<" (getData() bufferized)"<<endl;
157#else
158cout<<" (getData() not bufferized)"<<endl;
159#endif
[2311]160 cout << "calib = " << mCalibFactor << endl;
[1463]161// Remplissage des spheres
162for(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;
[2311]219 /*
220 if (mNSnFill % 1000 == 0) {
221 cout << ipix << " " << (*mMap)(ipix) << " + " << bolo*mCalibFactor <<
222 " " << ((*mWMap)(ipix)) << endl;
223 }
224 */
[2058]225 (*mMap)(ipix) += bolo*mCalibFactor;
[1804]226 ((*mWMap)(ipix)) += 1;
[1516]227 mNSnFill++;
[1463]228}
229
[2074]230 cout<<"TOI2Map::run(): End of SN loop - TotalProcessedSamples="
231 <<ProcessedSampleCount()<<" UsedSampleCount="<<UsedSampleCount()<<endl;
[1633]232
[1463]233// Remplissage des spheres
[1804]234 for(int_4 i=0;i<mMap->NbPixels();i++) {
235 r_8 wf = (*mWMap)(i);
[2311]236 /*
237 if (i%100 == 0) {
238 cout << "pix " << i << " w = " << wf << " map = " <<
239 (*mMap)(i);
240 }
241 */
[1809]242 if(wf>0.) {mNpixFill++; (*mMap)(i) /= wf;}
[2311]243 /*
244 if (i%100 == 0) {
245 cout << " -> " << (*mMap)(i);
246 }
247 */
[1463]248 int_4 nf = int_4(wf);
249 if(nf>=NFILL) nf=NFILL-1; NFill[nf]++;
250 }
251
[1806]252 cout<<"TOI2Map::run(): mNpixTot="<<mMap->NbPixels()
[1463]253 <<" mNpixFill="<<mNpixFill
[1804]254 <<" --> FracSky="<<mNpixFill*100./(double)mMap->NbPixels()<<"%"
[1516]255 <<" NFill["<<NFILL<<"] ="<<endl;
256 for(ii=0;ii<NFILL;ii++) {cout<<NFill[ii]<<" "; if(ii%10==9) cout<<endl;}
[1463]257 cout<<endl;
[2100]258 cout<<" mNSnFill="<<mNSnFill<<" NBadSn="<<nbadsn
259 <<" BadCoorRange="<<BadCoorRange<<endl;
[1463]260
[1746]261#ifndef SANS_BUFFER
262delete [] bbolo; delete [] bfgbolo;
263delete [] bc1; delete [] bc2;
264#endif
265
[2314]266/* if (mMapFName != "") {
[2228]267 cout << "saving maps" << endl;
268 {
269 FitsOutFile sfits(mMapFName,FitsFile::clear);
270 sfits << * (SphereHEALPix<r_8>*)mMap;
271 }
272 {
273 FitsOutFile sfits(mWMapFName,FitsFile::clear);
274 sfits << * (SphereHEALPix<r_8>*)mWMap;
275 }
276 }
[2314]277*/
[1463]278//---------------------------------------------------------
279} catch (PException & exc) {
[1806]280 cout<<"TOI2Map: Catched Exception "<<(string)typeid(exc).name()
[1463]281 <<"\n .... Msg= "<<exc.Msg()<<endl;
282}
283
284return;
285}
Note: See TracBrowser for help on using the repository browser.