| [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 | 
|---|
| [2240] | 41 |  | 
|---|
| [1984] | 42 | Bolos2ring::Bolos2ring(SphereHEALPix<r_8>* ringQ, | 
|---|
|  | 43 | SphereHEALPix<r_8>* ringU, | 
|---|
|  | 44 | SphereHEALPix<r_8>* ringQW, | 
|---|
|  | 45 | SphereHEALPix<r_8>* ringUW, | 
|---|
|  | 46 | const vector<r_8>& table_angle, | 
|---|
|  | 47 | int_4 *bolos_ok, | 
|---|
| [2240] | 48 | int_4 wsz) | 
|---|
| [1984] | 49 | : ringq(ringQ), ringu(ringU), ringqw(ringQW), ringuw(ringUW), TableFP_(table_angle), Bolos_OK(bolos_ok) | 
|---|
|  | 50 | { | 
|---|
| [2240] | 51 | init(wsz); | 
|---|
|  | 52 | } | 
|---|
|  | 53 |  | 
|---|
|  | 54 | Bolos2ring::Bolos2ring(SphereHEALPix<r_8>* ringQ, | 
|---|
|  | 55 | SphereHEALPix<r_8>* ringU, | 
|---|
|  | 56 | SphereHEALPix<r_8>* ringQW, | 
|---|
|  | 57 | SphereHEALPix<r_8>* ringUW, | 
|---|
|  | 58 | r_8 ang0, r_8 ang1, r_8 ang2, r_8 ang3, | 
|---|
|  | 59 | int_4 *bolos_ok, | 
|---|
|  | 60 | int_4 wsz) | 
|---|
|  | 61 | : ringq(ringQ), ringu(ringU), ringqw(ringQW), ringuw(ringUW), Bolos_OK(bolos_ok) | 
|---|
|  | 62 | { | 
|---|
|  | 63 | TableFP_.push_back(ang0); | 
|---|
|  | 64 | TableFP_.push_back(ang1); | 
|---|
|  | 65 | TableFP_.push_back(ang2); | 
|---|
|  | 66 | TableFP_.push_back(ang3); | 
|---|
|  | 67 | init(wsz); | 
|---|
|  | 68 | } | 
|---|
|  | 69 |  | 
|---|
|  | 70 |  | 
|---|
|  | 71 | void Bolos2ring::init(int_4 wsz) | 
|---|
|  | 72 | { | 
|---|
| [1984] | 73 | SetWSize(wsz); | 
|---|
|  | 74 | totsncount_ = 0; | 
|---|
|  | 75 |  | 
|---|
|  | 76 | if( ringq->NbPixels()<1) { | 
|---|
|  | 77 | cout << "Bolos2ring::Bolos2ring  : bad number of pixel in ringQ " | 
|---|
|  | 78 | << ringq->NbPixels() << endl; | 
|---|
|  | 79 | throw ParmError("Bolos2ring::Bolos2ring  : bad number of pixel in ringQ"); | 
|---|
|  | 80 | } | 
|---|
|  | 81 | if( ringu->NbPixels()<1) { | 
|---|
|  | 82 | cout << "Bolos2ring::Bolos2ring  : bad number of pixel in ringU " | 
|---|
|  | 83 | << ringu->NbPixels() | 
|---|
|  | 84 | << endl; | 
|---|
|  | 85 | throw ParmError("Bolos2ring::Bolos2ring  : bad number of pixel in ringU"); | 
|---|
|  | 86 | } | 
|---|
|  | 87 |  | 
|---|
|  | 88 | if( ringqw->NbPixels()<1) { | 
|---|
|  | 89 | cout << "Bolos2ring::Bolos2ring  : bad number of pixel in ringQW " | 
|---|
|  | 90 | << ringqw->NbPixels() << endl; | 
|---|
|  | 91 | throw ParmError("Bolos2ring::Bolos2ring  : bad number of pixel in ringQW"); | 
|---|
|  | 92 | } | 
|---|
|  | 93 | if( ringuw->NbPixels()<1) { | 
|---|
|  | 94 | cout << "Bolos2ring::Bolos2ring  : bad number of pixel in ringUW " | 
|---|
|  | 95 | << ringuw->NbPixels() << endl; | 
|---|
|  | 96 | throw ParmError("Bolos2ring::Bolos2ring  : bad number of pixel in ringUW"); | 
|---|
|  | 97 | } | 
|---|
|  | 98 |  | 
|---|
|  | 99 | if( ringq->NbPixels() != ringu->NbPixels()) | 
|---|
|  | 100 | throw(ParmError("Bolos2ring::Bolos2ring : rings don't have the same size!!")); | 
|---|
|  | 101 |  | 
|---|
|  | 102 | Npix_ = ringq->NbPixels(); | 
|---|
|  | 103 | int nlat = ringq->SizeIndex(); | 
|---|
|  | 104 | if(nlat != ringqw->SizeIndex()) ringqw->Resize(nlat); | 
|---|
|  | 105 | if(nlat != ringuw->SizeIndex()) ringuw->Resize(nlat); | 
|---|
|  | 106 | cout << "RINGS of " <<ringu->NbPixels() << " pixels" << endl; | 
|---|
|  | 107 |  | 
|---|
|  | 108 | ringq->SetPixels(0.); | 
|---|
|  | 109 | ringu->SetPixels(0.); | 
|---|
|  | 110 | ringqw->SetPixels(0); | 
|---|
|  | 111 | ringuw->SetPixels(0); | 
|---|
|  | 112 | } | 
|---|
|  | 113 |  | 
|---|
|  | 114 | // Destructor | 
|---|
|  | 115 | Bolos2ring::~Bolos2ring() | 
|---|
|  | 116 | { | 
|---|
|  | 117 | } | 
|---|
|  | 118 |  | 
|---|
|  | 119 | void Bolos2ring::PrintStatus(ostream& os) | 
|---|
|  | 120 | { | 
|---|
|  | 121 | os << "____________________________________________" << endl | 
|---|
|  | 122 | << "  Bolos2ring::PrintStatus() - wsize= "<<wsize_<< endl; | 
|---|
|  | 123 | TOIProcessor::PrintStatus(os); | 
|---|
|  | 124 | os << "  ProcessedSampleCount=" << ProcessedSampleCount() << endl; | 
|---|
|  | 125 | os << "____________________________________________" << endl; | 
|---|
|  | 126 | } | 
|---|
|  | 127 |  | 
|---|
|  | 128 | void Bolos2ring::init() | 
|---|
|  | 129 | { | 
|---|
|  | 130 | cout << "Bolos2ring::init" << endl; | 
|---|
|  | 131 |  | 
|---|
|  | 132 | // on branche les TOIs des 4 bolos (l'un peut etre "vide") | 
|---|
| [1996] | 133 | int i; | 
|---|
|  | 134 | for(i=0; i < 4; i++) | 
|---|
| [1984] | 135 | { | 
|---|
|  | 136 | char str[80]; | 
|---|
|  | 137 | sprintf(str,"Bolo%d",i); | 
|---|
|  | 138 | cout << str << endl; | 
|---|
|  | 139 | declareInput(str); | 
|---|
|  | 140 | } | 
|---|
|  | 141 |  | 
|---|
|  | 142 | // on branche le pointage des 2 PSB | 
|---|
| [1996] | 143 | for(i=0; i < 2; i++) | 
|---|
| [1984] | 144 | { | 
|---|
|  | 145 | char str[80]; | 
|---|
|  | 146 | sprintf(str,"theta_pointing%d",i); | 
|---|
|  | 147 | cout << str << endl; | 
|---|
|  | 148 | declareInput(str); | 
|---|
|  | 149 | sprintf(str,"phi_pointing%d",i); | 
|---|
|  | 150 | cout << str << endl; | 
|---|
|  | 151 | declareInput(str); | 
|---|
|  | 152 | } | 
|---|
|  | 153 |  | 
|---|
|  | 154 | name = "Bolos2ring"; | 
|---|
|  | 155 | } | 
|---|
|  | 156 |  | 
|---|
|  | 157 | void Bolos2ring::run() | 
|---|
|  | 158 | { | 
|---|
|  | 159 | int snb = getMinIn(); | 
|---|
|  | 160 | int sne = getMaxIn(); | 
|---|
|  | 161 |  | 
|---|
|  | 162 | if (!checkInputTOIIndex(0) && !checkInputTOIIndex(1)) { | 
|---|
|  | 163 | cerr << " Bolos2ring::run() - Input TOIs (in1, in2 and in3, in4) not connected! " | 
|---|
|  | 164 | << endl; | 
|---|
|  | 165 | throw ParmError("Bolos2ring::run() Input TOIs (in1, in2 and in3, in4) not connected!"); | 
|---|
|  | 166 | } | 
|---|
|  | 167 |  | 
|---|
|  | 168 | cout << " Bolo2ring::run() SNRange=" << snb << " - " << sne << endl; | 
|---|
|  | 169 |  | 
|---|
|  | 170 |  | 
|---|
|  | 171 | for(int i=0; i<4; i++) | 
|---|
|  | 172 | if( !checkInputTOIIndex(i) ) | 
|---|
|  | 173 | { | 
|---|
|  | 174 | cerr << " Bolos2ring::run() - Input TOIs not connected! (" | 
|---|
|  | 175 | << i << ')' << endl; | 
|---|
|  | 176 | throw ParmError("Bolos2ring::run() - Input TOIs not connected!"); | 
|---|
|  | 177 | } | 
|---|
|  | 178 |  | 
|---|
|  | 179 | cout << "Bolos2ring::run() - SNRange="<< snb << '-' << sne << endl; | 
|---|
|  | 180 |  | 
|---|
|  | 181 | try { | 
|---|
|  | 182 |  | 
|---|
|  | 183 | cout << " *** combine bolometers without computing the difference *** " << endl; | 
|---|
|  | 184 |  | 
|---|
|  | 185 | double v0, v1, v2, v3; // values of bolometers outputs | 
|---|
|  | 186 | double l0, b0, l1, b1; // galactic coordinates | 
|---|
|  | 187 | uint_8 vfg0, vfg1, vfg2, vfg3; | 
|---|
|  | 188 | double theta0, phi0, theta1, phi1; | 
|---|
|  | 189 | int_4 pixel0, pixel1; // pour chaque PSB | 
|---|
|  | 190 |  | 
|---|
|  | 191 | //  Matrix* sts = new Matrix[Npix_]; // matrice de calcul des param Stokes | 
|---|
|  | 192 | //  Vector* stm = new Vector[Npix_]; // St * vecteur de mesures | 
|---|
|  | 193 |  | 
|---|
|  | 194 | Matrix stm(Npix_, 3); | 
|---|
|  | 195 | RingOfMatrix3x3 ring(Npix_); | 
|---|
|  | 196 | cout << "****************************" << endl; | 
|---|
|  | 197 | cout << "   Ring declaration done" << endl; | 
|---|
|  | 198 | cout << "****************************" << endl; | 
|---|
|  | 199 |  | 
|---|
|  | 200 |  | 
|---|
|  | 201 | for(int i =0; i<4; i++) TableFP_[i] *= Pi/180. ; | 
|---|
|  | 202 |  | 
|---|
|  | 203 | for(int s=snb; s<= sne; s++) { | 
|---|
|  | 204 |  | 
|---|
|  | 205 | getData(0, s, v0, vfg0); | 
|---|
|  | 206 | getData(1, s, v1, vfg1); | 
|---|
|  | 207 | getData(2, s, v2, vfg2); | 
|---|
|  | 208 | getData(3, s, v3, vfg3); | 
|---|
|  | 209 | l0 = getData(4, s); | 
|---|
|  | 210 | b0 = getData(5, s); | 
|---|
|  | 211 | l1 = getData(6, s); | 
|---|
|  | 212 | b1 = getData(7, s); | 
|---|
|  | 213 |  | 
|---|
|  | 214 | theta0 = (90. - b0)/180. * Pi; | 
|---|
|  | 215 | phi0 = l0/180. * Pi; | 
|---|
|  | 216 | theta1 = (90. - b1)/180. * Pi; | 
|---|
|  | 217 | phi1 = l1/180. *Pi; | 
|---|
|  | 218 |  | 
|---|
|  | 219 | pixel0 = ringq->PixIndexSph(theta0, phi0); // Index of the hit pixel | 
|---|
|  | 220 | pixel1 = ringu->PixIndexSph(theta1, phi1); | 
|---|
|  | 221 |  | 
|---|
|  | 222 | if ((Bolos_OK[0] == 0) || (vfg0 > 0)) v0 = 0.; | 
|---|
|  | 223 | if ((Bolos_OK[1] == 0) || (vfg1 > 0)) v1 = 0.; | 
|---|
|  | 224 | if ((Bolos_OK[2] == 0) || (vfg2 > 0)) v2 = 0.; | 
|---|
|  | 225 | if ((Bolos_OK[3] == 0) || (vfg3 > 0)) v3 = 0.; | 
|---|
|  | 226 |  | 
|---|
|  | 227 | // Filling pixel0 | 
|---|
|  | 228 | ring.GetElement(pixel0)(0, 0) += 0.25 * 2; | 
|---|
|  | 229 | ring.GetElement(pixel0)(0, 1) += 0.25 *( cos(2*TableFP_[0]) + cos(2*TableFP_[1])); | 
|---|
|  | 230 | ring.GetElement(pixel0)(0, 2) += 0.25 *( sin(2*TableFP_[0]) + sin(2*TableFP_[1])); | 
|---|
|  | 231 |  | 
|---|
|  | 232 | ring.GetElement(pixel0)(1, 0) += 0.25 *( cos(2*TableFP_[0]) + cos(2*TableFP_[1])); | 
|---|
|  | 233 | ring.GetElement(pixel0)(1, 1) += 0.125 *( 2 + cos(4*TableFP_[0]) + cos(4*TableFP_[1])); | 
|---|
|  | 234 | ring.GetElement(pixel0)(1, 2) += 0.125*( sin(4*TableFP_[0]) + sin(4*TableFP_[1])); | 
|---|
|  | 235 |  | 
|---|
|  | 236 | ring.GetElement(pixel0)(2, 0) += 0.25 *( sin(2*TableFP_[0]) + sin(2*TableFP_[1])); | 
|---|
|  | 237 | ring.GetElement(pixel0)(2, 1) += 0.125*( sin(4*TableFP_[0]) + sin(4*TableFP_[1])); | 
|---|
|  | 238 | ring.GetElement(pixel0)(2, 2) += 0.125*( 2 - cos(4*TableFP_[0]) - cos(4*TableFP_[1])); | 
|---|
|  | 239 |  | 
|---|
|  | 240 | stm(pixel0, 0) += 0.5*(v0 + v1); | 
|---|
|  | 241 | stm(pixel0, 1) += 0.5*( cos(2*TableFP_[0])*v0 + cos(2*TableFP_[1])*v1); | 
|---|
|  | 242 | stm(pixel0, 2) += 0.5*( sin(2*TableFP_[0])*v0 + sin(2*TableFP_[1])*v1); | 
|---|
|  | 243 |  | 
|---|
|  | 244 | if((Bolos_OK[0] == 0) || (Bolos_OK[1] == 0) || (vfg0 >0) || (vfg1 >0)) | 
|---|
|  | 245 | { | 
|---|
|  | 246 | ringqw->PixVal(pixel0) += 1 ; // nombre de hits dans le pixel | 
|---|
|  | 247 | ringuw->PixVal(pixel0) += 1 ; | 
|---|
|  | 248 | } | 
|---|
|  | 249 | else | 
|---|
|  | 250 | { | 
|---|
|  | 251 | ringqw->PixVal(pixel0) += 2 ; | 
|---|
|  | 252 | ringuw->PixVal(pixel0) += 2 ; | 
|---|
|  | 253 | } | 
|---|
|  | 254 |  | 
|---|
|  | 255 | ring.GetElement(pixel1)(0, 0) += 0.25 * 2; | 
|---|
|  | 256 | ring.GetElement(pixel1)(0, 1) += 0.25 *( cos(2*TableFP_[2]) + cos(2*TableFP_[3])); | 
|---|
|  | 257 | ring.GetElement(pixel1)(0, 2) += 0.25 *( sin(2*TableFP_[2]) + sin(2*TableFP_[3])); | 
|---|
|  | 258 |  | 
|---|
|  | 259 | ring.GetElement(pixel1)(1, 0) += 0.25 *( cos(2*TableFP_[2]) + cos(2*TableFP_[3])); | 
|---|
|  | 260 | ring.GetElement(pixel1)(1, 1) += 0.125*( 2 + cos(4*TableFP_[2]) + cos(4*TableFP_[3])); | 
|---|
|  | 261 | ring.GetElement(pixel1)(1, 2) += 0.125*( sin(4*TableFP_[2]) + sin(4*TableFP_[3])); | 
|---|
|  | 262 |  | 
|---|
|  | 263 | ring.GetElement(pixel1)(2, 0) += 0.25 *( sin(2*TableFP_[2]) + sin(2*TableFP_[3])); | 
|---|
|  | 264 | ring.GetElement(pixel1)(2, 1) += 0.125*( sin(4*TableFP_[2]) + sin(4*TableFP_[3])); | 
|---|
|  | 265 | ring.GetElement(pixel1)(2, 2) += 0.125*( 2 - cos(4*TableFP_[2]) - cos(4*TableFP_[3])); | 
|---|
|  | 266 |  | 
|---|
|  | 267 | stm(pixel1, 0) += 0.5*( v2 + v3); | 
|---|
|  | 268 | stm(pixel1, 1) += 0.5*( cos(2*TableFP_[2])*v2 + cos(2*TableFP_[3])*v3); | 
|---|
|  | 269 | stm(pixel1, 2) += 0.5*( sin(2*TableFP_[2])*v2 + sin(2*TableFP_[3])*v3); | 
|---|
|  | 270 |  | 
|---|
|  | 271 | if((Bolos_OK[2] == 0) || (Bolos_OK[3] == 0)|| (vfg2 >0) || (vfg3 >0)) | 
|---|
|  | 272 | { | 
|---|
|  | 273 | ringqw->PixVal(pixel1) += 1 ; // nombre de hits dans le pixel | 
|---|
|  | 274 | ringuw->PixVal(pixel1) += 1 ; | 
|---|
|  | 275 | } | 
|---|
|  | 276 | else | 
|---|
|  | 277 | { | 
|---|
|  | 278 | ringqw->PixVal(pixel1) += 2 ; | 
|---|
|  | 279 | ringuw->PixVal(pixel1) += 2 ; | 
|---|
|  | 280 | } | 
|---|
|  | 281 |  | 
|---|
|  | 282 |  | 
|---|
|  | 283 | if (!(s%10000)) cout << " sample " << s << " ****** filling matrices  ****** " << endl; | 
|---|
|  | 284 |  | 
|---|
|  | 285 | }// fin de la boucle sur les samplenums qui normalement a rempli | 
|---|
|  | 286 | // la matrice et le vecteur projete. Y'a plus qu'a inverser... | 
|---|
|  | 287 |  | 
|---|
|  | 288 | // Ca devrait suffire de definir un ringw seulement dans ce cas la, | 
|---|
|  | 289 | // mais je garde le ringqw pour pas bugguer l'entree. | 
|---|
|  | 290 |  | 
|---|
|  | 291 | cout << endl << "Start to fill rings :" << endl; | 
|---|
|  | 292 |  | 
|---|
|  | 293 | for(int pix=0 ; pix < Npix_ ; pix++) {// pour chaque pixel | 
|---|
|  | 294 |  | 
|---|
|  | 295 | if( ringqw->PixVal(pix) < 4.0 ) | 
|---|
|  | 296 | //pixel pas vu, 4 a cause des 2 PSB ici, a changer | 
|---|
|  | 297 | ringq->PixVal(pix) = ringu->PixVal(pix) = UNSEEN_HEALPIX; | 
|---|
|  | 298 |  | 
|---|
|  | 299 | else{ | 
|---|
|  | 300 |  | 
|---|
|  | 301 | Matrix3x3 sts; | 
|---|
|  | 302 | Matrix stsm1(3, 3); | 
|---|
|  | 303 | Vector s(3); | 
|---|
|  | 304 | Vector stokes_param(3); | 
|---|
|  | 305 |  | 
|---|
|  | 306 | s(0) = stm(pix, 0); | 
|---|
|  | 307 | s(1) = stm(pix, 1); | 
|---|
|  | 308 | s(2) = stm(pix, 2); | 
|---|
|  | 309 | sts = ring.GetElement(pix); // get the sts matrix of pix | 
|---|
|  | 310 | sts = sts.Inverse(); | 
|---|
|  | 311 |  | 
|---|
|  | 312 | // voir si on peut arreter de bricoler pour que Matrix3x3 soit aussi une Matrix | 
|---|
|  | 313 | for(int r=0; r<=2; r++) | 
|---|
|  | 314 | for(int c=0; c<=2; c++) | 
|---|
|  | 315 | stsm1(r, c) = sts(r, c); | 
|---|
|  | 316 |  | 
|---|
|  | 317 | stokes_param = stsm1 * s; | 
|---|
|  | 318 | ringq->PixVal(pix) = stokes_param(0); | 
|---|
|  | 319 | ringu->PixVal(pix) = stokes_param(2); | 
|---|
|  | 320 |  | 
|---|
|  | 321 | } | 
|---|
|  | 322 |  | 
|---|
|  | 323 | } | 
|---|
|  | 324 |  | 
|---|
|  | 325 | } | 
|---|
|  | 326 |  | 
|---|
|  | 327 |  | 
|---|
|  | 328 |  | 
|---|
|  | 329 | catch( PThrowable& exc ) | 
|---|
|  | 330 | { | 
|---|
|  | 331 | cerr << " Exception: " << exc.Msg() << endl; | 
|---|
|  | 332 | } | 
|---|
|  | 333 |  | 
|---|
|  | 334 | return; | 
|---|
|  | 335 | } | 
|---|