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

Last change on this file since 2330 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
Line 
1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
5// $Id: toi2map.cc,v 1.33 2003-01-27 07:56:04 aubourg Exp $
6
7#include "machdefs.h"
8#include "toimanager.h"
9#include "pexceptions.h"
10#include "ctimer.h"
11#include "toi2map.h"
12// La valeur "Pi" doit etre celle de smathconst.h a cause du test sur theta
13#include "smathconst.h"
14
15#include "fitsspherehealpix.h"
16
17
18////////////////////////////////////////////////////////////////////////
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////////////////////////////////////////////////////////////////////////
28TOI2Map::TOI2Map(PixelMap<r_8>* map,PixelMap<r_8>* wmap)
29 : mMap(map), mWMap(wmap), mWMapInternal(false), totnscount(0), usednscount(0),
30 mMapFName(""), mWMapFName("")
31{
32 commonConst();
33}
34
35void TOI2Map::commonConst() {
36 SetEquinox();
37 SetCoorIn();
38 SetCoorMap();
39 SetCalibrationFactor();
40 SetTestFlag();
41 SetTestMin();
42 SetTestMax();
43
44 if(mMap->NbPixels()<1) {
45 cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mMap "
46 <<mMap->NbPixels()<<endl;
47 throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
48 }
49 mMap->SetPixels(0.);
50 int nlat = mMap->SizeIndex();
51 string typmap = mMap->TypeOfMap();
52
53 if(mWMap==NULL) {
54 // We would need a cloning function in maps. $$TBD$$ $CHECK$
55 if (typmap == "LOCAL") {
56 mWMap = new LocalMap<r_8>(*(LocalMap<r_8>*)mMap,false);
57 } else if (typmap == "RING") {
58 mWMap = new SphereHEALPix<r_8>(nlat);
59 } else {
60 cout << "TOI2Map::TOI2Map() cannot handle map of type " << typmap << endl;
61 throw ParmError("TOI2Map::TOI2Map() - bad type of map");
62 }
63 mWMapInternal = true;
64 } else {
65 mWMapInternal = false;
66 if(nlat != mWMap->SizeIndex()) {
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 }
78 }
79 }
80 if(mWMap->NbPixels()<1) {
81 cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mWMap "
82 <<mWMap->NbPixels()<<endl;
83 throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
84 }
85 mWMap->SetPixels(0);
86}
87
88TOI2Map::~TOI2Map()
89{
90 if(mWMap && mWMapInternal) delete mWMap;
91}
92
93////////////////////////////////////////////////////////////////////////
94void TOI2Map::Print(::ostream & os)
95{
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;
103 os<<" TotalProcessedSamples="<<ProcessedSampleCount()
104 <<" UsedSampleCount="<<UsedSampleCount()<<endl;
105}
106
107////////////////////////////////////////////////////////////////////////
108void TOI2Map::init() {
109 cout << "TOI2Map::init" << endl;
110 declareInput("Coord1In"); // input index 0
111 declareInput("Coord2In"); // input index 1
112 declareInput("BoloIn"); // input index 2
113}
114
115////////////////////////////////////////////////////////////////////////
116// define SANS_BUFFER
117void TOI2Map::run()
118{
119long snb = getMinIn();
120long sne = getMaxIn();
121
122if(snb>sne) {
123 cout<<"TOI2Map::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
124 throw ParmError("TOI2Map::run() - Bad sample interval");
125}
126if(!checkInputTOIIndex(0) || !checkInputTOIIndex(1) || !checkInputTOIIndex(2)) {
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!");
129}
130if( !(mTypCoorIn&TypCoordEq || mTypCoorIn&TypCoordGal) ) {
131 cout<<"TOI2Map::run() - Input Coordinates not Eq or Gal! "<<endl;
132 throw ParmError("TOI2Map::run() - Input Coordinates not Eq or Gal!");
133}
134if( !(mTypCoorMap&TypCoordEq || mTypCoorMap&TypCoordGal) ) {
135 cout<<"TOI2Map::run() - Output Coordinates not Eq or Gal! "<<endl;
136 throw ParmError("TOI2Map::run() - Output Coordinates not Eq or Gal!");
137}
138
139//---------------------------------------------------------
140#define NFILL 25
141try {
142
143int ii;
144uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL], BadCoorRange=0, nbadsn=0;
145for(ii=0;ii<NFILL;ii++) NFill[ii]=0;
146double mjd = MJDfrYear(mActualYear);
147
148cout<<"TOI2Map::run() from "<<snb<<" to "<<sne;
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
160 cout << "calib = " << mCalibFactor << endl;
161// Remplissage des spheres
162for(int s=snb;s<=sne;s++) {
163 uint_8 fgbolo = 0;
164 double bolo,coord1,coord2;
165 // Equatoriales / Galactiques
166 // coord1,2 = alpha,delta / gLon,gLat
167
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);
175 totnscount += nget;
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);
183 totnscount++;
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.
188 if (s%100 == 0) wontNeedBefore(s-1);
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;}
193 usednscount++;
194
195 // sphere phi entre [0,2*Pi] en radians
196 // sphere theta entre [0,Pi] en radians
197 double phi=-1.;
198 CoordConvertToStd(mTypCoorIn,&coord1,&coord2);
199
200 if(mTypCoorIn&TypCoordEq && mTypCoorMap&TypCoordGal) { // Eq -> Gal
201 EqtoGal(mjd,coord1,coord2,&coord1,&coord2);
202 phi = coord1 * Pi/180.;
203 } else if(mTypCoorIn&TypCoordGal && mTypCoorMap&TypCoordEq) { // Gal -> Eq
204 GaltoEq(mjd,coord1,coord2,&coord1,&coord2);
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.;
210 }
211 ToCoLat(&coord2,TypUniteD);
212 double theta = coord2 * Pi/180.;
213
214 if(phi<0. | phi>=2*Pi || theta<0. || theta>Pi)
215 {BadCoorRange++; continue;}
216
217 int_4 ipix = mMap->PixIndexSph(theta,phi);
218 if ((ipix < 0) || (ipix >= mMap->NbPixels()) ) continue;
219 /*
220 if (mNSnFill % 1000 == 0) {
221 cout << ipix << " " << (*mMap)(ipix) << " + " << bolo*mCalibFactor <<
222 " " << ((*mWMap)(ipix)) << endl;
223 }
224 */
225 (*mMap)(ipix) += bolo*mCalibFactor;
226 ((*mWMap)(ipix)) += 1;
227 mNSnFill++;
228}
229
230 cout<<"TOI2Map::run(): End of SN loop - TotalProcessedSamples="
231 <<ProcessedSampleCount()<<" UsedSampleCount="<<UsedSampleCount()<<endl;
232
233// Remplissage des spheres
234 for(int_4 i=0;i<mMap->NbPixels();i++) {
235 r_8 wf = (*mWMap)(i);
236 /*
237 if (i%100 == 0) {
238 cout << "pix " << i << " w = " << wf << " map = " <<
239 (*mMap)(i);
240 }
241 */
242 if(wf>0.) {mNpixFill++; (*mMap)(i) /= wf;}
243 /*
244 if (i%100 == 0) {
245 cout << " -> " << (*mMap)(i);
246 }
247 */
248 int_4 nf = int_4(wf);
249 if(nf>=NFILL) nf=NFILL-1; NFill[nf]++;
250 }
251
252 cout<<"TOI2Map::run(): mNpixTot="<<mMap->NbPixels()
253 <<" mNpixFill="<<mNpixFill
254 <<" --> FracSky="<<mNpixFill*100./(double)mMap->NbPixels()<<"%"
255 <<" NFill["<<NFILL<<"] ="<<endl;
256 for(ii=0;ii<NFILL;ii++) {cout<<NFill[ii]<<" "; if(ii%10==9) cout<<endl;}
257 cout<<endl;
258 cout<<" mNSnFill="<<mNSnFill<<" NBadSn="<<nbadsn
259 <<" BadCoorRange="<<BadCoorRange<<endl;
260
261#ifndef SANS_BUFFER
262delete [] bbolo; delete [] bfgbolo;
263delete [] bc1; delete [] bc2;
264#endif
265
266/* if (mMapFName != "") {
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 }
277*/
278//---------------------------------------------------------
279} catch (PException & exc) {
280 cout<<"TOI2Map: Catched Exception "<<(string)typeid(exc).name()
281 <<"\n .... Msg= "<<exc.Msg()<<endl;
282}
283
284return;
285}
Note: See TracBrowser for help on using the repository browser.