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

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

copyright

File size: 5.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.11 2001-11-08 15:47:46 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 if(mSph->NbPixels()<1) {
25 cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mSph "
26 <<mSph->NbPixels()<<endl;
27 throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
28 }
29 mSph->SetPixels(0.);
30 int nlat = mSph->SizeIndex();
31
32 if(mWSph==NULL) {
33 mWSph = new SphereHEALPix<r_8>(nlat);
34 mWSphInternal = true;
35 } else {
36 mWSphInternal = false;
37 if(nlat != mWSph->SizeIndex()) mWSph->Resize(nlat);
38 }
39 if(mWSph->NbPixels()<1) {
40 cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mWSph "
41 <<mWSph->NbPixels()<<endl;
42 throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
43 }
44 mWSph->SetPixels(0);
45
46}
47
48TOI2Map::~TOI2Map()
49{
50 if(mWSph && mWSphInternal) delete mWSph;
51}
52
53////////////////////////////////////////////////////////////////////////
54void TOI2Map::Print(ostream & os)
55{
56 os<<"TOI2Map::Print -- Sphere NLat = "<<mSph->SizeIndex()<<endl
57
58 <<" - Equinoxe="<<mActualYear<<endl
59
60 <<" - TypCoorIn: Gal("<<((mTypCoorIn&TypCoordGal)?1:0)
61 <<") Eq("<<((mTypCoorIn&TypCoordEq)?1:0)
62 <<") Deg("<<((mTypCoorIn&TypCoordDD)?1:0)
63 <<") Hour("<<((mTypCoorIn&TypCoordHD)?1:0)
64 <<") Rad("<<((mTypCoorIn&TypCoordRR)?1:0)<<")"<<endl
65
66 <<" - TypCoorOut: Gal("<<((mTypCoorOut&TypCoordGal)?1:0)
67 <<") Eq("<<((mTypCoorOut&TypCoordEq)?1:0)
68 <<") Deg("<<((mTypCoorOut&TypCoordDD)?1:0)
69 <<") Hour("<<((mTypCoorOut&TypCoordHD)?1:0)
70 <<") Rad("<<((mTypCoorOut&TypCoordRR)?1:0)<<")"<<endl
71
72 <<" - Tests: Flag("<<mTFlag<<") bad="<<mBadFlag
73 <<" / Value Min("<<mTMin<<")="<<mValMin
74 <<" , Max("<<mTMax<<")="<<mValMax<<endl;
75}
76
77////////////////////////////////////////////////////////////////////////
78void TOI2Map::init() {
79 cout << "TOI2Map::init" << endl;
80 declareInput("Coord1In"); // input index 0
81 declareInput("Coord2In"); // input index 1
82 declareInput("BoloIn"); // input index 2
83}
84
85////////////////////////////////////////////////////////////////////////
86void TOI2Map::run()
87{
88long snb = getMinIn();
89long sne = getMaxIn();
90
91if(snb>sne) {
92 cout<<"TOI2Map::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
93 throw ParmError("TOI2Map::run() - Bad sample interval");
94}
95if(!checkInputTOIIndex(0) || !checkInputTOIIndex(1) || !checkInputTOIIndex(2)) {
96 cout<<"TOI2Map::run() - Input TOI (Coord1In or Coord2In or BoloIn) not connected! "<<endl;
97 throw ParmError("TOI2Map::run() Output TOI (Coord1In or Coord2In or BoloIn) not connected!");
98}
99if( !(mTypCoorIn&TypCoordEq || mTypCoorIn&TypCoordGal) ) {
100 cout<<"TOI2Map::run() - Input Coordinates not Eq or Gal! "<<endl;
101 throw ParmError("TOI2Map::run() - Input Coordinates not Eq or Gal!");
102}
103if( !(mTypCoorOut&TypCoordEq || mTypCoorOut&TypCoordGal) ) {
104 cout<<"TOI2Map::run() - Output Coordinates not Eq or Gal! "<<endl;
105 throw ParmError("TOI2Map::run() - Output Coordinates not Eq or Gal!");
106}
107
108//---------------------------------------------------------
109#define NFILL 25
110try {
111
112int ii;
113uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL];
114for(ii=0;ii<NFILL;ii++) NFill[ii]=0;
115double mjd = MJDfrYear(mActualYear);
116
117// Remplissage des spheres
118for(int s=snb;s<=sne;s++) {
119 uint_8 fgbolo = 0;
120 double bolo;
121 // Equatoriales / Galactiques
122 // coord1,2 = alpha,delta / gLon,gLat
123 double coord1 = getData(0,s);
124 double coord2 = getData(1,s);
125
126 getData(2,s,bolo,fgbolo);
127 if (s%100 == 0) wontNeedBefore(s-1);
128 if(mTFlag && fgbolo&mBadFlag) continue;
129 if(mTMin && bolo<mValMin) continue;
130 if(mTMax && bolo>mValMax) continue;
131
132 // sphere phi entre [0,2*Pi] en radians
133 // sphere theta entre [0,Pi] en radians
134 double phi=-1.,theta;
135 CoordConvertToStd(mTypCoorIn,coord1,coord2);
136 if(mTypCoorIn&TypCoordEq && mTypCoorOut&TypCoordGal) { // Eq -> Gal
137 EqtoGal(mjd,coord1,coord2,&coord1,&coord2);
138 phi = coord1 * M_PI/180.;
139 } else if(mTypCoorIn&TypCoordGal && mTypCoorOut&TypCoordEq) { // Gal -> Eq
140 GaltoEq(mjd,coord1,coord2,&coord1,&coord2);
141 phi = coord1 * M_PI/12.;
142 } else if(mTypCoorOut&TypCoordGal) { // Gal -> Gal
143 phi = coord1 * M_PI/180.;
144 } else if(mTypCoorOut&TypCoordEq) { // Eq -> Eq
145 phi = coord1 * M_PI/12.;
146 }
147 theta = (90.-coord2) * M_PI/180.;
148 if(phi<0. || phi>=2*M_PI) continue;
149 if(theta<0. || theta>=M_PI) continue;
150
151 int_4 ipix = mSph->PixIndexSph(theta,phi);
152 (*mSph)(ipix) += bolo;
153 ((*mWSph)(ipix)) += 1;
154 mNSnFill++;
155}
156
157 cout<<"TOI2Map::run(): Fin de boucle sur les sampleNum"<<endl;
158
159// Remplissage des spheres
160 for(int_4 i=0;i<mSph->NbPixels();i++) {
161 r_8 wf = (*mWSph)(i);
162 if( wf > 0. ) {
163 mNpixFill++;
164 (*mSph)(i) /= wf;
165 }
166 int_4 nf = int_4(wf);
167 if(nf>=NFILL) nf=NFILL-1; NFill[nf]++;
168 }
169
170 cout<<"TOI2Map::run(): mNpixTot="<<mSph->NbPixels()
171 <<" mNpixFill="<<mNpixFill
172 <<" mNSnFill="<<mNSnFill<<endl
173 <<" --> FracSky="<<mNpixFill*100./(double)mSph->NbPixels()<<"%"
174 <<" NFill["<<NFILL<<"] ="<<endl;
175 for(ii=0;ii<NFILL;ii++) {cout<<NFill[ii]<<" "; if(ii%10==9) cout<<endl;}
176 cout<<endl;
177
178//---------------------------------------------------------
179} catch (PException & exc) {
180 cout<<"TOI2Map: Catched Exception "<<(string)typeid(exc).name()
181 <<"\n .... Msg= "<<exc.Msg()<<endl;
182}
183
184return;
185}
Note: See TracBrowser for help on using the repository browser.