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

Last change on this file was 2397, checked in by aubourg, 22 years ago

securisation

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