source: Sophya/trunk/ArchTOIPipe/ProcWSophya/Bolos2ring.cc@ 1988

Last change on this file since 1988 was 1984, checked in by cecile, 23 years ago

pour release juin 02 de L2 gph 425

File size: 9.9 KB
Line 
1// This may look like C code, but it's really -*- C++ -*-
2
3/////////////////////////////
4// Bolos2ring.cc //
5/////////////////////////////
6
7/// This is a processor for ArchTOIPipe using the Sophya Library.
8/// An example of the use of it is in the file gph425_5.cc
9///
10/// The goal of this processor is to give Q and U rings
11// computed with either 3 timelines coming from the
12// two channels of 1 PSB and one of the channels of a second PSB,
13// or with the differences of the two channels of each PSB.
14// The first of these two cases can be used if one channel is out
15// or order, the second one is supposed to be better when all channels
16// work fine, since it fully uses the advantage of PSB's.
17// Both methods should give the same results when the 4 channels work ok.
18
19// Authors CR/NP, rcecile@in2p3.fr, ponthieu@isn.in2p3.fr
20//////////////////////////////////////////////////////////////////////////////////////
21
22#include <stdlib.h>
23#include <stdio.h>
24#include <math.h>
25#include <vector>
26//#include <strstream>
27#include "spherehealpix.h"
28#include "tmatrix.h"
29#include "tvector.h"
30#include "vector3d.h"
31#include "fitsfile.h"
32#include "ctimer.h"
33#include "intflapack.h"
34#include "smathconst.h"
35#include "ring33.h"
36#include "Bolos2ring.h"
37
38#define UNSEEN_HEALPIX (-1.6375e30)
39
40// Constructor
41Bolos2ring::Bolos2ring(SphereHEALPix<r_8>* ringQ,
42 SphereHEALPix<r_8>* ringU,
43 SphereHEALPix<r_8>* ringQW,
44 SphereHEALPix<r_8>* ringUW,
45 const vector<r_8>& table_angle,
46 int_4 *bolos_ok,
47 int_4 wsz)
48 : ringq(ringQ), ringu(ringU), ringqw(ringQW), ringuw(ringUW), TableFP_(table_angle), Bolos_OK(bolos_ok)
49{
50 SetWSize(wsz);
51 totsncount_ = 0;
52
53 if( ringq->NbPixels()<1) {
54 cout << "Bolos2ring::Bolos2ring : bad number of pixel in ringQ "
55 << ringq->NbPixels() << endl;
56 throw ParmError("Bolos2ring::Bolos2ring : bad number of pixel in ringQ");
57 }
58 if( ringu->NbPixels()<1) {
59 cout << "Bolos2ring::Bolos2ring : bad number of pixel in ringU "
60 << ringu->NbPixels()
61 << endl;
62 throw ParmError("Bolos2ring::Bolos2ring : bad number of pixel in ringU");
63 }
64
65 if( ringqw->NbPixels()<1) {
66 cout << "Bolos2ring::Bolos2ring : bad number of pixel in ringQW "
67 << ringqw->NbPixels() << endl;
68 throw ParmError("Bolos2ring::Bolos2ring : bad number of pixel in ringQW");
69 }
70 if( ringuw->NbPixels()<1) {
71 cout << "Bolos2ring::Bolos2ring : bad number of pixel in ringUW "
72 << ringuw->NbPixels() << endl;
73 throw ParmError("Bolos2ring::Bolos2ring : bad number of pixel in ringUW");
74 }
75
76 if( ringq->NbPixels() != ringu->NbPixels())
77 throw(ParmError("Bolos2ring::Bolos2ring : rings don't have the same size!!"));
78
79 Npix_ = ringq->NbPixels();
80 int nlat = ringq->SizeIndex();
81 if(nlat != ringqw->SizeIndex()) ringqw->Resize(nlat);
82 if(nlat != ringuw->SizeIndex()) ringuw->Resize(nlat);
83 cout << "RINGS of " <<ringu->NbPixels() << " pixels" << endl;
84
85 ringq->SetPixels(0.);
86 ringu->SetPixels(0.);
87 ringqw->SetPixels(0);
88 ringuw->SetPixels(0);
89}
90
91// Destructor
92Bolos2ring::~Bolos2ring()
93{
94}
95
96void Bolos2ring::PrintStatus(ostream& os)
97{
98 os << "____________________________________________" << endl
99 << " Bolos2ring::PrintStatus() - wsize= "<<wsize_<< endl;
100 TOIProcessor::PrintStatus(os);
101 os << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
102 os << "____________________________________________" << endl;
103}
104
105void Bolos2ring::init()
106{
107 cout << "Bolos2ring::init" << endl;
108
109 // on branche les TOIs des 4 bolos (l'un peut etre "vide")
110 for(int i=0; i < 4; i++)
111 {
112 char str[80];
113 sprintf(str,"Bolo%d",i);
114 cout << str << endl;
115 declareInput(str);
116 }
117
118 // on branche le pointage des 2 PSB
119 for(int i=0; i < 2; i++)
120 {
121 char str[80];
122 sprintf(str,"theta_pointing%d",i);
123 cout << str << endl;
124 declareInput(str);
125 sprintf(str,"phi_pointing%d",i);
126 cout << str << endl;
127 declareInput(str);
128 }
129
130 name = "Bolos2ring";
131}
132
133void Bolos2ring::run()
134{
135 int snb = getMinIn();
136 int sne = getMaxIn();
137
138 if (!checkInputTOIIndex(0) && !checkInputTOIIndex(1)) {
139 cerr << " Bolos2ring::run() - Input TOIs (in1, in2 and in3, in4) not connected! "
140 << endl;
141 throw ParmError("Bolos2ring::run() Input TOIs (in1, in2 and in3, in4) not connected!");
142 }
143
144 cout << " Bolo2ring::run() SNRange=" << snb << " - " << sne << endl;
145
146
147 for(int i=0; i<4; i++)
148 if( !checkInputTOIIndex(i) )
149 {
150 cerr << " Bolos2ring::run() - Input TOIs not connected! ("
151 << i << ')' << endl;
152 throw ParmError("Bolos2ring::run() - Input TOIs not connected!");
153 }
154
155 cout << "Bolos2ring::run() - SNRange="<< snb << '-' << sne << endl;
156
157 try {
158
159 cout << " *** combine bolometers without computing the difference *** " << endl;
160
161 double v0, v1, v2, v3; // values of bolometers outputs
162 double l0, b0, l1, b1; // galactic coordinates
163 uint_8 vfg0, vfg1, vfg2, vfg3;
164 double theta0, phi0, theta1, phi1;
165 int_4 pixel0, pixel1; // pour chaque PSB
166
167 // Matrix* sts = new Matrix[Npix_]; // matrice de calcul des param Stokes
168 // Vector* stm = new Vector[Npix_]; // St * vecteur de mesures
169
170 Matrix stm(Npix_, 3);
171 RingOfMatrix3x3 ring(Npix_);
172 cout << "****************************" << endl;
173 cout << " Ring declaration done" << endl;
174 cout << "****************************" << endl;
175
176
177 for(int i =0; i<4; i++) TableFP_[i] *= Pi/180. ;
178
179 for(int s=snb; s<= sne; s++) {
180
181 getData(0, s, v0, vfg0);
182 getData(1, s, v1, vfg1);
183 getData(2, s, v2, vfg2);
184 getData(3, s, v3, vfg3);
185 l0 = getData(4, s);
186 b0 = getData(5, s);
187 l1 = getData(6, s);
188 b1 = getData(7, s);
189
190 theta0 = (90. - b0)/180. * Pi;
191 phi0 = l0/180. * Pi;
192 theta1 = (90. - b1)/180. * Pi;
193 phi1 = l1/180. *Pi;
194
195 pixel0 = ringq->PixIndexSph(theta0, phi0); // Index of the hit pixel
196 pixel1 = ringu->PixIndexSph(theta1, phi1);
197
198 if ((Bolos_OK[0] == 0) || (vfg0 > 0)) v0 = 0.;
199 if ((Bolos_OK[1] == 0) || (vfg1 > 0)) v1 = 0.;
200 if ((Bolos_OK[2] == 0) || (vfg2 > 0)) v2 = 0.;
201 if ((Bolos_OK[3] == 0) || (vfg3 > 0)) v3 = 0.;
202
203 // Filling pixel0
204 ring.GetElement(pixel0)(0, 0) += 0.25 * 2;
205 ring.GetElement(pixel0)(0, 1) += 0.25 *( cos(2*TableFP_[0]) + cos(2*TableFP_[1]));
206 ring.GetElement(pixel0)(0, 2) += 0.25 *( sin(2*TableFP_[0]) + sin(2*TableFP_[1]));
207
208 ring.GetElement(pixel0)(1, 0) += 0.25 *( cos(2*TableFP_[0]) + cos(2*TableFP_[1]));
209 ring.GetElement(pixel0)(1, 1) += 0.125 *( 2 + cos(4*TableFP_[0]) + cos(4*TableFP_[1]));
210 ring.GetElement(pixel0)(1, 2) += 0.125*( sin(4*TableFP_[0]) + sin(4*TableFP_[1]));
211
212 ring.GetElement(pixel0)(2, 0) += 0.25 *( sin(2*TableFP_[0]) + sin(2*TableFP_[1]));
213 ring.GetElement(pixel0)(2, 1) += 0.125*( sin(4*TableFP_[0]) + sin(4*TableFP_[1]));
214 ring.GetElement(pixel0)(2, 2) += 0.125*( 2 - cos(4*TableFP_[0]) - cos(4*TableFP_[1]));
215
216 stm(pixel0, 0) += 0.5*(v0 + v1);
217 stm(pixel0, 1) += 0.5*( cos(2*TableFP_[0])*v0 + cos(2*TableFP_[1])*v1);
218 stm(pixel0, 2) += 0.5*( sin(2*TableFP_[0])*v0 + sin(2*TableFP_[1])*v1);
219
220 if((Bolos_OK[0] == 0) || (Bolos_OK[1] == 0) || (vfg0 >0) || (vfg1 >0))
221 {
222 ringqw->PixVal(pixel0) += 1 ; // nombre de hits dans le pixel
223 ringuw->PixVal(pixel0) += 1 ;
224 }
225 else
226 {
227 ringqw->PixVal(pixel0) += 2 ;
228 ringuw->PixVal(pixel0) += 2 ;
229 }
230
231 ring.GetElement(pixel1)(0, 0) += 0.25 * 2;
232 ring.GetElement(pixel1)(0, 1) += 0.25 *( cos(2*TableFP_[2]) + cos(2*TableFP_[3]));
233 ring.GetElement(pixel1)(0, 2) += 0.25 *( sin(2*TableFP_[2]) + sin(2*TableFP_[3]));
234
235 ring.GetElement(pixel1)(1, 0) += 0.25 *( cos(2*TableFP_[2]) + cos(2*TableFP_[3]));
236 ring.GetElement(pixel1)(1, 1) += 0.125*( 2 + cos(4*TableFP_[2]) + cos(4*TableFP_[3]));
237 ring.GetElement(pixel1)(1, 2) += 0.125*( sin(4*TableFP_[2]) + sin(4*TableFP_[3]));
238
239 ring.GetElement(pixel1)(2, 0) += 0.25 *( sin(2*TableFP_[2]) + sin(2*TableFP_[3]));
240 ring.GetElement(pixel1)(2, 1) += 0.125*( sin(4*TableFP_[2]) + sin(4*TableFP_[3]));
241 ring.GetElement(pixel1)(2, 2) += 0.125*( 2 - cos(4*TableFP_[2]) - cos(4*TableFP_[3]));
242
243 stm(pixel1, 0) += 0.5*( v2 + v3);
244 stm(pixel1, 1) += 0.5*( cos(2*TableFP_[2])*v2 + cos(2*TableFP_[3])*v3);
245 stm(pixel1, 2) += 0.5*( sin(2*TableFP_[2])*v2 + sin(2*TableFP_[3])*v3);
246
247 if((Bolos_OK[2] == 0) || (Bolos_OK[3] == 0)|| (vfg2 >0) || (vfg3 >0))
248 {
249 ringqw->PixVal(pixel1) += 1 ; // nombre de hits dans le pixel
250 ringuw->PixVal(pixel1) += 1 ;
251 }
252 else
253 {
254 ringqw->PixVal(pixel1) += 2 ;
255 ringuw->PixVal(pixel1) += 2 ;
256 }
257
258
259 if (!(s%10000)) cout << " sample " << s << " ****** filling matrices ****** " << endl;
260
261 }// fin de la boucle sur les samplenums qui normalement a rempli
262 // la matrice et le vecteur projete. Y'a plus qu'a inverser...
263
264 // Ca devrait suffire de definir un ringw seulement dans ce cas la,
265 // mais je garde le ringqw pour pas bugguer l'entree.
266
267 cout << endl << "Start to fill rings :" << endl;
268
269 for(int pix=0 ; pix < Npix_ ; pix++) {// pour chaque pixel
270
271 if( ringqw->PixVal(pix) < 4.0 )
272 //pixel pas vu, 4 a cause des 2 PSB ici, a changer
273 ringq->PixVal(pix) = ringu->PixVal(pix) = UNSEEN_HEALPIX;
274
275 else{
276
277 Matrix3x3 sts;
278 Matrix stsm1(3, 3);
279 Vector s(3);
280 Vector stokes_param(3);
281
282 s(0) = stm(pix, 0);
283 s(1) = stm(pix, 1);
284 s(2) = stm(pix, 2);
285 sts = ring.GetElement(pix); // get the sts matrix of pix
286 sts = sts.Inverse();
287
288 // voir si on peut arreter de bricoler pour que Matrix3x3 soit aussi une Matrix
289 for(int r=0; r<=2; r++)
290 for(int c=0; c<=2; c++)
291 stsm1(r, c) = sts(r, c);
292
293 stokes_param = stsm1 * s;
294 ringq->PixVal(pix) = stokes_param(0);
295 ringu->PixVal(pix) = stokes_param(2);
296
297 }
298
299 }
300
301 }
302
303
304
305 catch( PThrowable& exc )
306 {
307 cerr << " Exception: " << exc.Msg() << endl;
308 }
309
310 return;
311}
Note: See TracBrowser for help on using the repository browser.