[1984] | 1 | // This may look like C code, but it's really -*- C++ -*-
|
---|
| 2 |
|
---|
| 3 | /////////////////////////////
|
---|
| 4 | // PSB2ring.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 "tmatrix.h"
|
---|
| 28 | #include "tvector.h"
|
---|
| 29 | #include "vector3d.h"
|
---|
| 30 | #include "ctimer.h"
|
---|
| 31 | #include "PSB2ring.h"
|
---|
| 32 |
|
---|
| 33 | #define UNSEEN_HEALPIX (-1.6375e30)
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | // Constructor
|
---|
| 37 | PSB2ring::PSB2ring(SphereHEALPix<r_8>* ringQ,
|
---|
| 38 | SphereHEALPix<r_8>* ringU,
|
---|
| 39 | SphereHEALPix<r_8>* ringQW,
|
---|
| 40 | SphereHEALPix<r_8>* ringUW,
|
---|
| 41 | const vector<r_8>& table_angle,
|
---|
| 42 | int_4 wsz)
|
---|
| 43 | : ringq(ringQ), ringu(ringU), ringqw(ringQW), ringuw(ringUW), TableFP_(table_angle)
|
---|
| 44 | {
|
---|
| 45 | SetWSize(wsz);
|
---|
| 46 | totsncount_ = 0;
|
---|
| 47 |
|
---|
| 48 | if( ringq->NbPixels()<1) {
|
---|
| 49 | cout << "PSB2ring::PSB2ring : bad number of pixel in ringQ "
|
---|
| 50 | << ringq->NbPixels() << endl;
|
---|
| 51 | throw ParmError("PSB2ring::PSB2ring : bad number of pixel in ringQ");
|
---|
| 52 | }
|
---|
| 53 | if( ringu->NbPixels()<1) {
|
---|
| 54 | cout << "PSB2ring::PSB2ring : bad number of pixel in ringU "
|
---|
| 55 | << ringu->NbPixels()
|
---|
| 56 | << endl;
|
---|
| 57 | throw ParmError("PSB2ring::PSB2ring : bad number of pixel in ringU");
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | if( ringqw->NbPixels()<1) {
|
---|
| 61 | cout << "PSB2ring::PSB2ring : bad number of pixel in ringQW "
|
---|
| 62 | << ringqw->NbPixels() << endl;
|
---|
| 63 | throw ParmError("PSB2ring::PSB2ring : bad number of pixel in ringQW");
|
---|
| 64 | }
|
---|
| 65 | if( ringuw->NbPixels()<1) {
|
---|
| 66 | cout << "PSB2ring::PSB2ring : bad number of pixel in ringUW "
|
---|
| 67 | << ringuw->NbPixels() << endl;
|
---|
| 68 | throw ParmError("PSB2ring::PSB2ring : bad number of pixel in ringUW");
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | if( ringq->NbPixels() != ringu->NbPixels())
|
---|
| 72 | throw(ParmError("PSB2ring::PSB2ring : rings don't have the same size!!"));
|
---|
| 73 |
|
---|
| 74 | Npix_ = ringq->NbPixels();
|
---|
| 75 | int nlat = ringq->SizeIndex();
|
---|
| 76 | if(nlat != ringqw->SizeIndex()) ringqw->Resize(nlat);
|
---|
| 77 | if(nlat != ringuw->SizeIndex()) ringuw->Resize(nlat);
|
---|
| 78 | cout << "RINGS of " <<ringu->NbPixels() << " pixels" << endl;
|
---|
| 79 |
|
---|
| 80 | ringq->SetPixels(0.);
|
---|
| 81 | ringu->SetPixels(0.);
|
---|
| 82 | ringqw->SetPixels(0);
|
---|
| 83 | ringuw->SetPixels(0);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | // Destructor
|
---|
| 87 | PSB2ring::~PSB2ring()
|
---|
| 88 | {
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | void PSB2ring::PrintStatus(ostream& os)
|
---|
| 92 | {
|
---|
| 93 | os << "____________________________________________" << endl
|
---|
| 94 | << " PSB2ring::PrintStatus() - wsize= "<<wsize_<< endl;
|
---|
| 95 | TOIProcessor::PrintStatus(os);
|
---|
| 96 | os << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
|
---|
| 97 | os << "____________________________________________" << endl;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | void PSB2ring::init()
|
---|
| 101 | {
|
---|
| 102 | cout << "PSB2ring::init" << endl;
|
---|
| 103 |
|
---|
[1997] | 104 | int i;
|
---|
[1984] | 105 | // on branche les TOIs des 4 bolos (l'un peut etre "vide")
|
---|
[1997] | 106 | for(i=0; i < 4; i++)// if (PSB_ok[i] > 0)
|
---|
[1984] | 107 | {
|
---|
| 108 | char str[80];
|
---|
| 109 | sprintf(str,"Bolo%d",i);
|
---|
| 110 | cout << str << endl;
|
---|
| 111 | declareInput(str);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | // on branche le poinatge des 2 PSB
|
---|
[1997] | 115 | for(i=0; i < 2; i++)// if (PSB_ok[i] > 0)
|
---|
[1984] | 116 | {
|
---|
| 117 | char str[80];
|
---|
| 118 | sprintf(str,"theta_pointing%d",i);
|
---|
| 119 | cout << str << endl;
|
---|
| 120 | declareInput(str);
|
---|
| 121 | sprintf(str,"phi_pointing%d",i);
|
---|
| 122 | cout << str << endl;
|
---|
| 123 | declareInput(str);
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | declareOutput("out_toiQ");
|
---|
| 127 | declareOutput("out_toiU");
|
---|
| 128 |
|
---|
| 129 | name = "PSB2ring";
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | void PSB2ring::run()
|
---|
| 133 | {
|
---|
| 134 | int snb = getMinIn();
|
---|
| 135 | int sne = getMaxIn();
|
---|
| 136 |
|
---|
| 137 | if (!checkInputTOIIndex(0) && !checkInputTOIIndex(1)) {
|
---|
| 138 | cerr << " PSB2ring::run() - Input TOIs (in1, in2 and in3, in4) not connected! "
|
---|
| 139 | << endl;
|
---|
| 140 | throw ParmError("PSB2ring::run() Input TOIs (in1, in2 and in3, in4) not connected!");
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | cout << " Bolo2ring::run() SNRange=" << snb << " - " << sne << endl;
|
---|
| 144 |
|
---|
| 145 | for(int i=0; i<4; i++) //if (PSB_ok[i/2,i%2])
|
---|
| 146 | if( !checkInputTOIIndex(i) )
|
---|
| 147 | {
|
---|
| 148 | cerr << " PSB2ring::run() - Input TOIs not connected! ("
|
---|
| 149 | << i << ')' << endl;
|
---|
| 150 | throw ParmError("PSB2ring::run() - Input TOIs not connected!");
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | // pas de sortie a verifier
|
---|
| 154 |
|
---|
| 155 | cout << "PSB2ring::run() - SNRange="<< snb << '-' << sne << endl;
|
---|
| 156 |
|
---|
| 157 | try {
|
---|
| 158 |
|
---|
| 159 | Timer tm("PSB2ring::run()");
|
---|
| 160 | cout << "****************************" << endl;
|
---|
| 161 | cout << "****************************" << endl;
|
---|
| 162 | cout << "4 bolos working and ordered" << endl;
|
---|
| 163 |
|
---|
| 164 | // Generation des timelines
|
---|
| 165 | double v0,v1,v2,v3; // values of bolometers outputs
|
---|
| 166 | double l0, b0, l1, b1; // galactic coordinates
|
---|
| 167 | uint_8 vfg0,vfg1,vfg2,vfg3;
|
---|
| 168 | double Q,U;
|
---|
| 169 |
|
---|
| 170 | for(int s=snb;s<=sne;s++) {
|
---|
| 171 |
|
---|
| 172 | getData(0, s, v0, vfg0);
|
---|
| 173 | getData(1, s, v1, vfg1);
|
---|
| 174 | getData(2, s, v2, vfg2);
|
---|
| 175 | getData(3, s, v3, vfg3);
|
---|
| 176 |
|
---|
| 177 | l0 = getData(4, s);
|
---|
| 178 | b0 = getData(5, s);
|
---|
| 179 | l1 = getData(6, s);
|
---|
| 180 | b1 = getData(7, s);
|
---|
| 181 |
|
---|
| 182 | double theta0 = (90. - b0)/180 * 3.14159;
|
---|
| 183 | double phi0 = l0/180. * 3.14159;
|
---|
| 184 | double theta1 = (90. - b1)/180 * 3.14159;
|
---|
| 185 | double phi1 = l1/180 *3.14159;
|
---|
| 186 |
|
---|
| 187 |
|
---|
| 188 |
|
---|
| 189 | // cout << " ********** Q(t) and U(t) finished *********** " << endl;
|
---|
| 190 |
|
---|
| 191 | // cout << " ********** Projection on the ring ********* " << endl;
|
---|
| 192 |
|
---|
| 193 | //Projection
|
---|
| 194 |
|
---|
| 195 | if((vfg0 == 0) && (vfg1 == 0))
|
---|
| 196 | {
|
---|
| 197 | Q = v0 - v1;
|
---|
| 198 | int_4 pixelQ = ringq->PixIndexSph(theta0, phi0); // numero du pixel touche
|
---|
| 199 | ringqw->PixVal(pixelQ) += 1 ; // nombre de hits dans le pixel
|
---|
| 200 | ringq->PixVal(pixelQ) += Q ;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | if((vfg2 == 0) && (vfg3 == 0))
|
---|
| 204 | {
|
---|
| 205 | U = v2 - v3;
|
---|
| 206 | int_4 pixelU = ringu->PixIndexSph(theta1, phi1);
|
---|
| 207 | ringuw->PixVal(pixelU) += 1 ;
|
---|
| 208 | ringu->PixVal(pixelU) += U ;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | if (!(s%10000)) cout << s << " ****** filling rings ****** " << endl;
|
---|
| 212 |
|
---|
| 213 | putData(0, s, Q);
|
---|
| 214 | putData(1, s, U);
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | // Moyennage des pixels
|
---|
| 218 | // comme on bosse directement avec des timelines de Q et U
|
---|
| 219 | // dans ce cas precis, on a juste a prendre la moyenne des valeurs
|
---|
| 220 | // qui tombent dans un pixel pour avoir la carte
|
---|
| 221 | // on ne doit inverser de matrice etc que dans le cas
|
---|
| 222 | // trois bolos.
|
---|
| 223 |
|
---|
| 224 | for(int pix=0 ; pix < Npix_ ; pix++) {
|
---|
| 225 |
|
---|
| 226 | if( ringqw->PixVal(pix) < 1.0 ) //pixel pas vu
|
---|
| 227 | ringq->PixVal(pix) = ringu->PixVal(pix) = UNSEEN_HEALPIX;
|
---|
| 228 | else
|
---|
| 229 | ringq->PixVal(pix) = ringq->PixVal(pix) / ringqw->PixVal(pix);
|
---|
| 230 |
|
---|
| 231 | if( ringuw->PixVal(pix) < 1.0 )
|
---|
| 232 | ringu->PixVal(pix) = ringu->PixVal(pix) = UNSEEN_HEALPIX;
|
---|
| 233 | else
|
---|
| 234 | ringu->PixVal(pix) = ringu->PixVal(pix) / ringuw->PixVal(pix);
|
---|
| 235 |
|
---|
| 236 | }
|
---|
| 237 | cout << " ********** rings filled ********* " << endl;
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 |
|
---|
| 241 | catch( PThrowable& exc )
|
---|
| 242 | {
|
---|
| 243 | cerr << " Exception: " << exc.Msg() << endl;
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 |
|
---|
| 248 |
|
---|