1 | #include "machdefs.h"
|
---|
2 | #include "toimanager.h"
|
---|
3 | #include "pexceptions.h"
|
---|
4 | #include "ctimer.h"
|
---|
5 | #include "toi2map.h"
|
---|
6 | #include "xastropack.h"
|
---|
7 |
|
---|
8 | ////////////////////////////////////////////////////////////////////////
|
---|
9 | TOI2Map::TOI2Map(SphereHEALPix<r_8>* sph,SphereHEALPix<r_8>* wsph)
|
---|
10 | : mSph(sph), mWSph(wsph), mWSphInternal(false), mTypCoor(false), mActualYear(2001.)
|
---|
11 | {
|
---|
12 | if(mSph->NbPixels()<1) {
|
---|
13 | cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mSph "
|
---|
14 | <<mSph->NbPixels()<<endl;
|
---|
15 | throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
|
---|
16 | }
|
---|
17 | mSph->SetPixels(0.);
|
---|
18 | int nlat = mSph->SizeIndex();
|
---|
19 |
|
---|
20 | if(mWSph==NULL) {
|
---|
21 | mWSph = new SphereHEALPix<r_8>(nlat);
|
---|
22 | mWSphInternal = true;
|
---|
23 | } else {
|
---|
24 | mWSphInternal = false;
|
---|
25 | if(nlat != mWSph->SizeIndex()) mWSph->Resize(nlat);
|
---|
26 | }
|
---|
27 | if(mWSph->NbPixels()<1) {
|
---|
28 | cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mWSph "
|
---|
29 | <<mWSph->NbPixels()<<endl;
|
---|
30 | throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
|
---|
31 | }
|
---|
32 | mWSph->SetPixels(0);
|
---|
33 |
|
---|
34 | }
|
---|
35 |
|
---|
36 | TOI2Map::~TOI2Map()
|
---|
37 | {
|
---|
38 | if(mWSph && !mWSphInternal) delete mWSph;
|
---|
39 | }
|
---|
40 |
|
---|
41 | ////////////////////////////////////////////////////////////////////////
|
---|
42 | void TOI2Map::init() {
|
---|
43 | cout << "TOI2Map::init" << endl;
|
---|
44 | declareInput("AlphaIn"); // input index 0
|
---|
45 | declareInput("DeltaIn"); // input index 1
|
---|
46 | declareInput("BoloIn"); // input index 2
|
---|
47 | }
|
---|
48 |
|
---|
49 | ////////////////////////////////////////////////////////////////////////
|
---|
50 | void TOI2Map::run()
|
---|
51 | {
|
---|
52 | long snb = getMinIn();
|
---|
53 | long sne = getMaxIn();
|
---|
54 |
|
---|
55 | if(snb>sne) {
|
---|
56 | cout<<"TOI2Map::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
|
---|
57 | throw ParmError("TOI2Map::run() - Bad sample interval");
|
---|
58 | }
|
---|
59 | if(!checkInputTOIIndex(0) || !checkInputTOIIndex(1) || !checkInputTOIIndex(2)) {
|
---|
60 | cout<<"TOI2Map::run() - Input TOI (AlphaIn or DeltaIn or BoloIn) not connected! "<<endl;
|
---|
61 | throw ParmError("TOI2Map::run() Output TOI (AlphaIn or DeltaIn or BoloIn) not connected!");
|
---|
62 | }
|
---|
63 |
|
---|
64 | //---------------------------------------------------------
|
---|
65 | #define NFILL 25
|
---|
66 | try {
|
---|
67 |
|
---|
68 | int ii;
|
---|
69 | uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL];
|
---|
70 | for(ii=0;ii<NFILL;ii++) NFill[ii]=0;
|
---|
71 |
|
---|
72 | // Remplissage des spheres
|
---|
73 | for(int s=snb;s<=sne;s++) {
|
---|
74 | int_4 fgbolo = 0;
|
---|
75 |
|
---|
76 | double alpha = getData(0,s); // alpha entre [0,24[ en heures
|
---|
77 | double delta = getData(1,s); // delta entre [-90,90] en degres
|
---|
78 | double bolo = getData(2,s);
|
---|
79 | //fgbolo = getFlag(2,s);
|
---|
80 |
|
---|
81 | if(delta<-90. || delta>90.) fgbolo=1;
|
---|
82 | if(alpha<0. || alpha>=24.) fgbolo=1;
|
---|
83 | if(bolo<-32767.) fgbolo=1; // Bidouille Archeops
|
---|
84 |
|
---|
85 | if(!fgbolo) {
|
---|
86 | // sphere phi entre [0,2*Pi] en radians
|
---|
87 | // sphere theta entre [0,Pi] en radians
|
---|
88 | double phi,theta;
|
---|
89 | if(mTypCoor) {
|
---|
90 | double mjd = MJDfrYear(mActualYear);
|
---|
91 | EqtoGal(mjd,alpha,delta,&alpha,&delta);
|
---|
92 | phi = alpha * M_PI/180.;
|
---|
93 | } else phi = alpha * M_PI/12.;
|
---|
94 | theta = (90.-delta)*M_PI/180.;
|
---|
95 | int_4 ipix = mSph->PixIndexSph(theta,phi);
|
---|
96 | (*mSph)(ipix) += bolo;
|
---|
97 | ((*mWSph)(ipix))++;
|
---|
98 | mNSnFill++;
|
---|
99 | }
|
---|
100 |
|
---|
101 | }
|
---|
102 |
|
---|
103 | // Remplissage des spheres
|
---|
104 | for(int_4 i=0;i<mSph->NbPixels();i++) {
|
---|
105 | r_8 wf = (*mWSph)(i);
|
---|
106 | if( wf > 0. ) {
|
---|
107 | mNpixFill++;
|
---|
108 | (*mSph)(i) /= wf;
|
---|
109 | }
|
---|
110 | int_4 nf = int_4(wf);
|
---|
111 | if(nf>=NFILL) nf=NFILL-1; NFill[nf]++;
|
---|
112 | }
|
---|
113 |
|
---|
114 | cout<<"TOI2Map::run(): mNpixTot="<<mSph->NbPixels()
|
---|
115 | <<" mNpixFill="<<mNpixFill
|
---|
116 | <<" mNSnFill="<<mNSnFill<<endl
|
---|
117 | <<" --> FracSky="<<mNpixFill*100./(double)mSph->NbPixels()<<"%"<<endl
|
---|
118 | <<"NFill["<<NFILL<<"] = "<<endl;
|
---|
119 | for(ii=0;ii<NFILL;ii++) cout<<NFill[ii]<<" ";
|
---|
120 | cout<<endl;
|
---|
121 |
|
---|
122 | //---------------------------------------------------------
|
---|
123 | } catch (PException & exc) {
|
---|
124 | cout<<"TOI2Map: Catched Exception "<<(string)typeid(exc).name()
|
---|
125 | <<"\n .... Msg= "<<exc.Msg()<<endl;
|
---|
126 | }
|
---|
127 |
|
---|
128 | return;
|
---|
129 | }
|
---|