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

Last change on this file since 1792 was 1792, checked in by aubourg, 24 years ago

gestion colatitude un peu nettoyee

File size: 6.8 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.19 2001-11-27 12:12:12 aubourg Exp $
6
7#include "machdefs.h"
8#include "toimanager.h"
9#include "pexceptions.h"
10#include "ctimer.h"
11#include "toi2map.h"
12
13////////////////////////////////////////////////////////////////////////
14TOI2Map::TOI2Map(SphereHEALPix<r_8>* sph,SphereHEALPix<r_8>* wsph)
15 : mSph(sph), mWSph(wsph), mWSphInternal(false)
16{
17 SetEquinox();
18 SetCoorIn();
19 SetCoorOut();
20 SetTestFlag();
21 SetTestMin();
22 SetTestMax();
23
24 mIsColat = false;
25
26 if(mSph->NbPixels()<1) {
27 cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mSph "
28 <<mSph->NbPixels()<<endl;
29 throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
30 }
31 mSph->SetPixels(0.);
32 int nlat = mSph->SizeIndex();
33
34 if(mWSph==NULL) {
35 mWSph = new SphereHEALPix<r_8>(nlat);
36 mWSphInternal = true;
37 } else {
38 mWSphInternal = false;
39 if(nlat != mWSph->SizeIndex()) mWSph->Resize(nlat);
40 }
41 if(mWSph->NbPixels()<1) {
42 cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mWSph "
43 <<mWSph->NbPixels()<<endl;
44 throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
45 }
46 mWSph->SetPixels(0);
47
48}
49
50TOI2Map::~TOI2Map()
51{
52 if(mWSph && mWSphInternal) delete mWSph;
53}
54
55////////////////////////////////////////////////////////////////////////
56void TOI2Map::Print(::ostream & os)
57{
58 os<<"TOI2Map::Print -- Sphere NLat = "<<mSph->SizeIndex()<<endl
59
60 <<" - Equinoxe="<<mActualYear<<endl
61
62 <<" - TypCoorIn: Gal("<<((mTypCoorIn&TypCoordGal)?1:0)
63 <<") Eq("<<((mTypCoorIn&TypCoordEq)?1:0)
64 <<") Deg("<<((mTypCoorIn&TypCoordDD)?1:0)
65 <<") Hour("<<((mTypCoorIn&TypCoordHD)?1:0)
66 <<") Rad("<<((mTypCoorIn&TypCoordRR)?1:0)<<")"<<endl
67
68 <<" - TypCoorOut: Gal("<<((mTypCoorOut&TypCoordGal)?1:0)
69 <<") Eq("<<((mTypCoorOut&TypCoordEq)?1:0)
70 <<") Deg("<<((mTypCoorOut&TypCoordDD)?1:0)
71 <<") Hour("<<((mTypCoorOut&TypCoordHD)?1:0)
72 <<") Rad("<<((mTypCoorOut&TypCoordRR)?1:0)<<")"<<endl
73
74 <<" - Tests: Flag("<<mTFlag<<") bad="<<mBadFlag
75 <<" / Value Min("<<mTMin<<")="<<mValMin
76 <<" , Max("<<mTMax<<")="<<mValMax<<endl;
77}
78
79////////////////////////////////////////////////////////////////////////
80void TOI2Map::init() {
81 cout << "TOI2Map::init" << endl;
82 declareInput("Coord1In"); // input index 0
83 declareInput("Coord2In"); // input index 1
84 declareInput("BoloIn"); // input index 2
85}
86
87////////////////////////////////////////////////////////////////////////
88// define SANS_BUFFER
89void TOI2Map::run()
90{
91long snb = getMinIn();
92long sne = getMaxIn();
93
94if(snb>sne) {
95 cout<<"TOI2Map::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
96 throw ParmError("TOI2Map::run() - Bad sample interval");
97}
98if(!checkInputTOIIndex(0) || !checkInputTOIIndex(1) || !checkInputTOIIndex(2)) {
99 cout<<"TOI2Map::run() - Input TOI (Coord1In or Coord2In or BoloIn) not connected! "<<endl;
100 throw ParmError("TOI2Map::run() Output TOI (Coord1In or Coord2In or BoloIn) not connected!");
101}
102if( !(mTypCoorIn&TypCoordEq || mTypCoorIn&TypCoordGal) ) {
103 cout<<"TOI2Map::run() - Input Coordinates not Eq or Gal! "<<endl;
104 throw ParmError("TOI2Map::run() - Input Coordinates not Eq or Gal!");
105}
106if( !(mTypCoorOut&TypCoordEq || mTypCoorOut&TypCoordGal) ) {
107 cout<<"TOI2Map::run() - Output Coordinates not Eq or Gal! "<<endl;
108 throw ParmError("TOI2Map::run() - Output Coordinates not Eq or Gal!");
109}
110
111//---------------------------------------------------------
112#define NFILL 25
113try {
114
115int ii;
116uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL];
117for(ii=0;ii<NFILL;ii++) NFill[ii]=0;
118double mjd = MJDfrYear(mActualYear);
119
120cout<<"TOI2Map::run() from "<<snb<<" to "<<sne;
121#ifndef SANS_BUFFER
122int bufsz = 100;
123uint_8* bfgbolo = new uint_8[bufsz];
124double* bbolo = new double[bufsz];
125double* bc1 = new double[bufsz];
126double* bc2 = new double[bufsz];
127int i0 = -1;
128cout<<" (getData() bufferized)"<<endl;
129#else
130cout<<" (getData() not bufferized)"<<endl;
131#endif
132
133// Remplissage des spheres
134for(int s=snb;s<=sne;s++) {
135 uint_8 fgbolo = 0;
136 double bolo,coord1,coord2;
137 // Equatoriales / Galactiques
138 // coord1,2 = alpha,delta / gLon,gLat
139
140#ifndef SANS_BUFFER
141 if(i0<0 || s<i0 || s>=i0+bufsz) {
142 i0 = s;
143 int nget = (sne-s+1<bufsz)? nget=sne-s+1: bufsz;
144 getData(0,i0,nget,bc1);
145 getData(1,i0,nget,bc2);
146 getData(2,i0,nget,bbolo,bfgbolo);
147 }
148 bolo = bbolo[s-i0]; fgbolo = bfgbolo[s-i0];
149 coord1 = bc1[s-i0]; coord2 = bc2[s-i0];
150#else
151 getData(2,s,bolo,fgbolo);
152 coord1 = getData(0,s);
153 coord2 = getData(1,s);
154#endif
155
156 // Comme il n'y a pas de toi en sortie, il faut dire
157 // aux processeur/toi que l'on a plus besoin des donnees.
158 if (s%100 == 0) wontNeedBefore(s-1);
159 if(mTFlag && fgbolo&mBadFlag) continue;
160 if(mTMin && bolo<mValMin) continue;
161 if(mTMax && bolo>mValMax) continue;
162
163 // sphere phi entre [0,2*Pi] en radians
164 // sphere theta entre [0,Pi] en radians
165 double phi=-1.,theta;
166 CoordConvertToStd(mTypCoorIn,coord1,coord2);
167
168 if(mTypCoorIn&TypCoordEq && mTypCoorOut&TypCoordGal) { // Eq -> Gal
169 EqtoGal(mjd,coord1,coord2,&coord1,&coord2);
170 phi = coord1 * M_PI/180.;
171 } else if(mTypCoorIn&TypCoordGal && mTypCoorOut&TypCoordEq) { // Gal -> Eq
172 GaltoEq(mjd,coord1,coord2,&coord1,&coord2);
173 phi = coord1 * M_PI/12.;
174 } else if(mTypCoorOut&TypCoordGal) { // Gal -> Gal
175 phi = coord1 * M_PI/180.;
176 } else if(mTypCoorOut&TypCoordEq) { // Eq -> Eq
177 phi = coord1 * M_PI/12.;
178 }
179
180 if (phi<0) phi += 2*M_PI;
181 if (phi>=2*M_PI) phi -= 2*M_PI;
182 if (mIsColat) {
183 theta = coord2 * M_PI/180;
184 } else {
185 theta = (90.-coord2) * M_PI/180.;
186 }
187
188 if(phi<0. || phi>=2*M_PI) continue;
189 if(theta<0. || theta>=M_PI) continue;
190
191 int_4 ipix = mSph->PixIndexSph(theta,phi);
192 (*mSph)(ipix) += bolo;
193 ((*mWSph)(ipix)) += 1;
194 mNSnFill++;
195}
196
197 cout<<"TOI2Map::run(): Fin de boucle sur les sampleNum"<<endl;
198
199// Remplissage des spheres
200 for(int_4 i=0;i<mSph->NbPixels();i++) {
201 r_8 wf = (*mWSph)(i);
202 if( wf > 0. ) {
203 mNpixFill++;
204 (*mSph)(i) /= wf;
205 }
206 int_4 nf = int_4(wf);
207 if(nf>=NFILL) nf=NFILL-1; NFill[nf]++;
208 }
209
210 cout<<"TOI2Map::run(): mNpixTot="<<mSph->NbPixels()
211 <<" mNpixFill="<<mNpixFill
212 <<" mNSnFill="<<mNSnFill<<endl
213 <<" --> FracSky="<<mNpixFill*100./(double)mSph->NbPixels()<<"%"
214 <<" NFill["<<NFILL<<"] ="<<endl;
215 for(ii=0;ii<NFILL;ii++) {cout<<NFill[ii]<<" "; if(ii%10==9) cout<<endl;}
216 cout<<endl;
217
218#ifndef SANS_BUFFER
219delete [] bbolo; delete [] bfgbolo;
220delete [] bc1; delete [] bc2;
221#endif
222
223//---------------------------------------------------------
224} catch (PException & exc) {
225 cout<<"TOI2Map: Catched Exception "<<(string)typeid(exc).name()
226 <<"\n .... Msg= "<<exc.Msg()<<endl;
227}
228
229return;
230}
Note: See TracBrowser for help on using the repository browser.