source: Sophya/trunk/ArchTOIPipe/ProcWSophya/flag2map.cc@ 2208

Last change on this file since 2208 was 2038, checked in by cecile, 23 years ago

...

File size: 7.0 KB
Line 
1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
5// $Id: flag2map.cc,v 1.3 2002-05-31 09:55:42 cecile Exp $
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////////////////////////////////////////////////////////////////////////
16FLAG2Map::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
70FLAG2Map::~FLAG2Map()
71{
72 if(mWMap && mWMapInternal) delete mWMap;
73}
74
75////////////////////////////////////////////////////////////////////////
76void 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////////////////////////////////////////////////////////////////////////
88void 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
97void FLAG2Map::run()
98{
99long snb = getMinIn();
100long sne = getMaxIn();
101
102if(snb>sne) {
103 cout<<"FLAG2Map::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
104 throw ParmError("FLAG2Map::run() - Bad sample interval");
105}
106if(!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}
110if( !(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}
114if( !(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
121try {
122
123int ii;
124uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL], BadCoorRange=0;
125for(ii=0;ii<NFILL;ii++) NFill[ii]=0;
126double mjd = MJDfrYear(mActualYear);
127
128cout<<"FLAG2Map::run() from "<<snb<<" to "<<sne;
129cout<<" (getData() not bufferized)"<<endl;
130
131// Remplissage des spheres
132for(int s=snb;s<=sne;s++) {
133 uint_8 fgbolo = 0;
134 double bolo,coord1,coord2;
135 // Equatoriales / Galactiques
136 // coord1,2 = alpha,delta / gLon,gLat
137
138 coord1 = getData(0,s);
139 coord2 = getData(1,s);
140 getData(2,s,bolo,fgbolo);
141 totnscount++;
142
143 if (fgbolo > 0)
144 cout << "sn " << s << " val " << bolo << " fgbolo " << fgbolo << endl;
145
146 // Comme il n'y a pas de toi en sortie, il faut dire
147 // aux processeur/toi que l'on a plus besoin des donnees.
148 if (s%100 == 0) wontNeedBefore(s-1);
149 // if(mTFlag && fgbolo&mBadFlag) continue;
150 if(mTMin && bolo<mValMin) continue;
151 if(mTMax && bolo>mValMax) continue;
152
153
154 if (fgbolo != 2) continue;
155 // pas un glitch;
156
157 // sphere phi entre [0,2*Pi] en radians
158 // sphere theta entre [0,Pi] en radians
159 double phi=-1.;
160 CoordConvertToStd(mTypCoorIn,&coord1,&coord2);
161
162 if(mTypCoorIn&TypCoordEq && mTypCoorMap&TypCoordGal) { // Eq -> Gal
163 EqtoGal(mjd,coord1,coord2,&coord1,&coord2);
164 phi = coord1 * Pi/180.;
165 } else if(mTypCoorIn&TypCoordGal && mTypCoorMap&TypCoordEq) { // Gal -> Eq
166 GaltoEq(mjd,coord1,coord2,&coord1,&coord2);
167 phi = coord1 * Pi/12.;
168 } else if(mTypCoorMap&TypCoordGal) { // Gal -> Gal
169 phi = coord1 * Pi/180.;
170 } else if(mTypCoorMap&TypCoordEq) { // Eq -> Eq
171 phi = coord1 * Pi/12.;
172 }
173 ToCoLat(&coord2,TypUniteD);
174 double theta = coord2 * Pi/180.;
175
176 if(phi<0. | phi>=2*Pi || theta<0. || theta>Pi)
177 {BadCoorRange++; continue;}
178
179 int_4 ipix = mMap->PixIndexSph(theta,phi);
180 (*mMap)(ipix) += bolo;
181 ((*mWMap)(ipix)) += 1;
182 mNSnFill++;
183}
184
185 cout<<"FLAG2Map::run(): Fin de boucle sur les sampleNum"<<endl;
186
187// Remplissage des spheres
188 for(int_4 i=0;i<mMap->NbPixels();i++) {
189 r_8 wf = (*mWMap)(i);
190 if(wf>0.) {mNpixFill++; (*mMap)(i) /= wf;}
191 int_4 nf = int_4(wf);
192 if(nf>=NFILL) nf=NFILL-1; NFill[nf]++;
193 }
194
195 cout<<"FLAG2Map::run(): mNpixTot="<<mMap->NbPixels()
196 <<" mNpixFill="<<mNpixFill
197 <<" mNSnFill="<<mNSnFill<<endl
198 <<" --> FracSky="<<mNpixFill*100./(double)mMap->NbPixels()<<"%"
199 <<" NFill["<<NFILL<<"] ="<<endl;
200 for(ii=0;ii<NFILL;ii++) {cout<<NFill[ii]<<" "; if(ii%10==9) cout<<endl;}
201 cout<<endl;
202 cout<<" BadCoorRange="<<BadCoorRange<<endl;
203
204
205//---------------------------------------------------------
206} catch (PException & exc) {
207 cout<<"FLAG2Map: Catched Exception "<<(string)typeid(exc).name()
208 <<"\n .... Msg= "<<exc.Msg()<<endl;
209}
210
211return;
212}
Note: See TracBrowser for help on using the repository browser.