[1984] | 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
|
---|
| 41 | Bolos2ring::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
|
---|
| 92 | Bolos2ring::~Bolos2ring()
|
---|
| 93 | {
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | void 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 |
|
---|
| 105 | void Bolos2ring::init()
|
---|
| 106 | {
|
---|
| 107 | cout << "Bolos2ring::init" << endl;
|
---|
| 108 |
|
---|
| 109 | // on branche les TOIs des 4 bolos (l'un peut etre "vide")
|
---|
[1996] | 110 | int i;
|
---|
| 111 | for(i=0; i < 4; i++)
|
---|
[1984] | 112 | {
|
---|
| 113 | char str[80];
|
---|
| 114 | sprintf(str,"Bolo%d",i);
|
---|
| 115 | cout << str << endl;
|
---|
| 116 | declareInput(str);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | // on branche le pointage des 2 PSB
|
---|
[1996] | 120 | for(i=0; i < 2; i++)
|
---|
[1984] | 121 | {
|
---|
| 122 | char str[80];
|
---|
| 123 | sprintf(str,"theta_pointing%d",i);
|
---|
| 124 | cout << str << endl;
|
---|
| 125 | declareInput(str);
|
---|
| 126 | sprintf(str,"phi_pointing%d",i);
|
---|
| 127 | cout << str << endl;
|
---|
| 128 | declareInput(str);
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | name = "Bolos2ring";
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | void Bolos2ring::run()
|
---|
| 135 | {
|
---|
| 136 | int snb = getMinIn();
|
---|
| 137 | int sne = getMaxIn();
|
---|
| 138 |
|
---|
| 139 | if (!checkInputTOIIndex(0) && !checkInputTOIIndex(1)) {
|
---|
| 140 | cerr << " Bolos2ring::run() - Input TOIs (in1, in2 and in3, in4) not connected! "
|
---|
| 141 | << endl;
|
---|
| 142 | throw ParmError("Bolos2ring::run() Input TOIs (in1, in2 and in3, in4) not connected!");
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | cout << " Bolo2ring::run() SNRange=" << snb << " - " << sne << endl;
|
---|
| 146 |
|
---|
| 147 |
|
---|
| 148 | for(int i=0; i<4; i++)
|
---|
| 149 | if( !checkInputTOIIndex(i) )
|
---|
| 150 | {
|
---|
| 151 | cerr << " Bolos2ring::run() - Input TOIs not connected! ("
|
---|
| 152 | << i << ')' << endl;
|
---|
| 153 | throw ParmError("Bolos2ring::run() - Input TOIs not connected!");
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | cout << "Bolos2ring::run() - SNRange="<< snb << '-' << sne << endl;
|
---|
| 157 |
|
---|
| 158 | try {
|
---|
| 159 |
|
---|
| 160 | cout << " *** combine bolometers without computing the difference *** " << endl;
|
---|
| 161 |
|
---|
| 162 | double v0, v1, v2, v3; // values of bolometers outputs
|
---|
| 163 | double l0, b0, l1, b1; // galactic coordinates
|
---|
| 164 | uint_8 vfg0, vfg1, vfg2, vfg3;
|
---|
| 165 | double theta0, phi0, theta1, phi1;
|
---|
| 166 | int_4 pixel0, pixel1; // pour chaque PSB
|
---|
| 167 |
|
---|
| 168 | // Matrix* sts = new Matrix[Npix_]; // matrice de calcul des param Stokes
|
---|
| 169 | // Vector* stm = new Vector[Npix_]; // St * vecteur de mesures
|
---|
| 170 |
|
---|
| 171 | Matrix stm(Npix_, 3);
|
---|
| 172 | RingOfMatrix3x3 ring(Npix_);
|
---|
| 173 | cout << "****************************" << endl;
|
---|
| 174 | cout << " Ring declaration done" << endl;
|
---|
| 175 | cout << "****************************" << endl;
|
---|
| 176 |
|
---|
| 177 |
|
---|
| 178 | for(int i =0; i<4; i++) TableFP_[i] *= Pi/180. ;
|
---|
| 179 |
|
---|
| 180 | for(int s=snb; s<= sne; s++) {
|
---|
| 181 |
|
---|
| 182 | getData(0, s, v0, vfg0);
|
---|
| 183 | getData(1, s, v1, vfg1);
|
---|
| 184 | getData(2, s, v2, vfg2);
|
---|
| 185 | getData(3, s, v3, vfg3);
|
---|
| 186 | l0 = getData(4, s);
|
---|
| 187 | b0 = getData(5, s);
|
---|
| 188 | l1 = getData(6, s);
|
---|
| 189 | b1 = getData(7, s);
|
---|
| 190 |
|
---|
| 191 | theta0 = (90. - b0)/180. * Pi;
|
---|
| 192 | phi0 = l0/180. * Pi;
|
---|
| 193 | theta1 = (90. - b1)/180. * Pi;
|
---|
| 194 | phi1 = l1/180. *Pi;
|
---|
| 195 |
|
---|
| 196 | pixel0 = ringq->PixIndexSph(theta0, phi0); // Index of the hit pixel
|
---|
| 197 | pixel1 = ringu->PixIndexSph(theta1, phi1);
|
---|
| 198 |
|
---|
| 199 | if ((Bolos_OK[0] == 0) || (vfg0 > 0)) v0 = 0.;
|
---|
| 200 | if ((Bolos_OK[1] == 0) || (vfg1 > 0)) v1 = 0.;
|
---|
| 201 | if ((Bolos_OK[2] == 0) || (vfg2 > 0)) v2 = 0.;
|
---|
| 202 | if ((Bolos_OK[3] == 0) || (vfg3 > 0)) v3 = 0.;
|
---|
| 203 |
|
---|
| 204 | // Filling pixel0
|
---|
| 205 | ring.GetElement(pixel0)(0, 0) += 0.25 * 2;
|
---|
| 206 | ring.GetElement(pixel0)(0, 1) += 0.25 *( cos(2*TableFP_[0]) + cos(2*TableFP_[1]));
|
---|
| 207 | ring.GetElement(pixel0)(0, 2) += 0.25 *( sin(2*TableFP_[0]) + sin(2*TableFP_[1]));
|
---|
| 208 |
|
---|
| 209 | ring.GetElement(pixel0)(1, 0) += 0.25 *( cos(2*TableFP_[0]) + cos(2*TableFP_[1]));
|
---|
| 210 | ring.GetElement(pixel0)(1, 1) += 0.125 *( 2 + cos(4*TableFP_[0]) + cos(4*TableFP_[1]));
|
---|
| 211 | ring.GetElement(pixel0)(1, 2) += 0.125*( sin(4*TableFP_[0]) + sin(4*TableFP_[1]));
|
---|
| 212 |
|
---|
| 213 | ring.GetElement(pixel0)(2, 0) += 0.25 *( sin(2*TableFP_[0]) + sin(2*TableFP_[1]));
|
---|
| 214 | ring.GetElement(pixel0)(2, 1) += 0.125*( sin(4*TableFP_[0]) + sin(4*TableFP_[1]));
|
---|
| 215 | ring.GetElement(pixel0)(2, 2) += 0.125*( 2 - cos(4*TableFP_[0]) - cos(4*TableFP_[1]));
|
---|
| 216 |
|
---|
| 217 | stm(pixel0, 0) += 0.5*(v0 + v1);
|
---|
| 218 | stm(pixel0, 1) += 0.5*( cos(2*TableFP_[0])*v0 + cos(2*TableFP_[1])*v1);
|
---|
| 219 | stm(pixel0, 2) += 0.5*( sin(2*TableFP_[0])*v0 + sin(2*TableFP_[1])*v1);
|
---|
| 220 |
|
---|
| 221 | if((Bolos_OK[0] == 0) || (Bolos_OK[1] == 0) || (vfg0 >0) || (vfg1 >0))
|
---|
| 222 | {
|
---|
| 223 | ringqw->PixVal(pixel0) += 1 ; // nombre de hits dans le pixel
|
---|
| 224 | ringuw->PixVal(pixel0) += 1 ;
|
---|
| 225 | }
|
---|
| 226 | else
|
---|
| 227 | {
|
---|
| 228 | ringqw->PixVal(pixel0) += 2 ;
|
---|
| 229 | ringuw->PixVal(pixel0) += 2 ;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | ring.GetElement(pixel1)(0, 0) += 0.25 * 2;
|
---|
| 233 | ring.GetElement(pixel1)(0, 1) += 0.25 *( cos(2*TableFP_[2]) + cos(2*TableFP_[3]));
|
---|
| 234 | ring.GetElement(pixel1)(0, 2) += 0.25 *( sin(2*TableFP_[2]) + sin(2*TableFP_[3]));
|
---|
| 235 |
|
---|
| 236 | ring.GetElement(pixel1)(1, 0) += 0.25 *( cos(2*TableFP_[2]) + cos(2*TableFP_[3]));
|
---|
| 237 | ring.GetElement(pixel1)(1, 1) += 0.125*( 2 + cos(4*TableFP_[2]) + cos(4*TableFP_[3]));
|
---|
| 238 | ring.GetElement(pixel1)(1, 2) += 0.125*( sin(4*TableFP_[2]) + sin(4*TableFP_[3]));
|
---|
| 239 |
|
---|
| 240 | ring.GetElement(pixel1)(2, 0) += 0.25 *( sin(2*TableFP_[2]) + sin(2*TableFP_[3]));
|
---|
| 241 | ring.GetElement(pixel1)(2, 1) += 0.125*( sin(4*TableFP_[2]) + sin(4*TableFP_[3]));
|
---|
| 242 | ring.GetElement(pixel1)(2, 2) += 0.125*( 2 - cos(4*TableFP_[2]) - cos(4*TableFP_[3]));
|
---|
| 243 |
|
---|
| 244 | stm(pixel1, 0) += 0.5*( v2 + v3);
|
---|
| 245 | stm(pixel1, 1) += 0.5*( cos(2*TableFP_[2])*v2 + cos(2*TableFP_[3])*v3);
|
---|
| 246 | stm(pixel1, 2) += 0.5*( sin(2*TableFP_[2])*v2 + sin(2*TableFP_[3])*v3);
|
---|
| 247 |
|
---|
| 248 | if((Bolos_OK[2] == 0) || (Bolos_OK[3] == 0)|| (vfg2 >0) || (vfg3 >0))
|
---|
| 249 | {
|
---|
| 250 | ringqw->PixVal(pixel1) += 1 ; // nombre de hits dans le pixel
|
---|
| 251 | ringuw->PixVal(pixel1) += 1 ;
|
---|
| 252 | }
|
---|
| 253 | else
|
---|
| 254 | {
|
---|
| 255 | ringqw->PixVal(pixel1) += 2 ;
|
---|
| 256 | ringuw->PixVal(pixel1) += 2 ;
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 |
|
---|
| 260 | if (!(s%10000)) cout << " sample " << s << " ****** filling matrices ****** " << endl;
|
---|
| 261 |
|
---|
| 262 | }// fin de la boucle sur les samplenums qui normalement a rempli
|
---|
| 263 | // la matrice et le vecteur projete. Y'a plus qu'a inverser...
|
---|
| 264 |
|
---|
| 265 | // Ca devrait suffire de definir un ringw seulement dans ce cas la,
|
---|
| 266 | // mais je garde le ringqw pour pas bugguer l'entree.
|
---|
| 267 |
|
---|
| 268 | cout << endl << "Start to fill rings :" << endl;
|
---|
| 269 |
|
---|
| 270 | for(int pix=0 ; pix < Npix_ ; pix++) {// pour chaque pixel
|
---|
| 271 |
|
---|
| 272 | if( ringqw->PixVal(pix) < 4.0 )
|
---|
| 273 | //pixel pas vu, 4 a cause des 2 PSB ici, a changer
|
---|
| 274 | ringq->PixVal(pix) = ringu->PixVal(pix) = UNSEEN_HEALPIX;
|
---|
| 275 |
|
---|
| 276 | else{
|
---|
| 277 |
|
---|
| 278 | Matrix3x3 sts;
|
---|
| 279 | Matrix stsm1(3, 3);
|
---|
| 280 | Vector s(3);
|
---|
| 281 | Vector stokes_param(3);
|
---|
| 282 |
|
---|
| 283 | s(0) = stm(pix, 0);
|
---|
| 284 | s(1) = stm(pix, 1);
|
---|
| 285 | s(2) = stm(pix, 2);
|
---|
| 286 | sts = ring.GetElement(pix); // get the sts matrix of pix
|
---|
| 287 | sts = sts.Inverse();
|
---|
| 288 |
|
---|
| 289 | // voir si on peut arreter de bricoler pour que Matrix3x3 soit aussi une Matrix
|
---|
| 290 | for(int r=0; r<=2; r++)
|
---|
| 291 | for(int c=0; c<=2; c++)
|
---|
| 292 | stsm1(r, c) = sts(r, c);
|
---|
| 293 |
|
---|
| 294 | stokes_param = stsm1 * s;
|
---|
| 295 | ringq->PixVal(pix) = stokes_param(0);
|
---|
| 296 | ringu->PixVal(pix) = stokes_param(2);
|
---|
| 297 |
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 |
|
---|
| 305 |
|
---|
| 306 | catch( PThrowable& exc )
|
---|
| 307 | {
|
---|
| 308 | cerr << " Exception: " << exc.Msg() << endl;
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 | return;
|
---|
| 312 | }
|
---|