[3756] | 1 | // Classes to compute 2D
|
---|
| 2 | // R. Ansari - Nov 2008, May 2010
|
---|
| 3 |
|
---|
| 4 | #include "mdish.h"
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 | //--------------------------------------------------
|
---|
| 8 | // -- Four2DResponse class
|
---|
| 9 | //--------------------------------------------------
|
---|
| 10 | // Constructor
|
---|
| 11 | Four2DResponse::Four2DResponse(int typ, double dx, double dy)
|
---|
| 12 | : typ_(typ), dx_((dx>1.e-3)?dx:1.), dy_((dy>1.e-3)?dy:1.)
|
---|
| 13 | {
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | // Return the response for the wave vecteor (kx,ky)
|
---|
| 17 | double Four2DResponse::Value(double kx, double ky)
|
---|
| 18 | {
|
---|
| 19 | double wk,wkx,wky;
|
---|
| 20 | switch (typ_)
|
---|
| 21 | {
|
---|
| 22 | case 1: // Reponse gaussienne parabole diametre D exp[ - 0.5 (lambda k_g / D )^2 ]
|
---|
| 23 | wk = sqrt(kx*kx+ky*ky)/dx_;
|
---|
| 24 | wk = 0.5*wk*wk;
|
---|
| 25 | return exp(-wk);
|
---|
| 26 | break;
|
---|
| 27 | case 2: // Reponse parabole diametre D Triangle <= kmax= 2 pi D / lambda
|
---|
| 28 | wk = sqrt(kx*kx+ky*ky)/dx_/2./M_PI;
|
---|
| 29 | return ( (wk<1.)?(1.-wk):0.);
|
---|
| 30 | break;
|
---|
| 31 | case 3: // Reponse rectangle Dx x Dy Triangle (|kx|,|k_y|) <= (2 pi Dx / lambda, 2 pi Dx / lambda)
|
---|
| 32 | wkx = kx/2./M_PI/dx_;
|
---|
| 33 | wky = ky/2./M_PI/dy_;
|
---|
| 34 | return ( ((wkx<1.)&&(wky<1.))?((1.-wkx)*(1-wky)):0.);
|
---|
| 35 | break;
|
---|
| 36 | default:
|
---|
| 37 | return 1.;
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 | // Return a vector representing the power spectrum (for checking)
|
---|
| 41 | Histo2D Four2DResponse::GetResponse(int nx, int ny)
|
---|
| 42 | {
|
---|
| 43 | double kxmx = 1.2*DeuxPI*dx_;
|
---|
| 44 | double kymx = 1.2*DeuxPI*dy_;
|
---|
| 45 | if (typ_<3) kymx=kxmx;
|
---|
| 46 | Histo2D h2(0.,kxmx,nx,0.,kymx,ny);
|
---|
| 47 |
|
---|
| 48 | for(int j=0; j<h2.NBinY(); j++)
|
---|
| 49 | for(int i=0; i<h2.NBinX(); i++)
|
---|
| 50 | h2(i,j) = Value((i+0.5)*h2.WBinX(), (j+0.5)*h2.WBinY());
|
---|
| 51 | return h2;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | //---------------------------------------------------------------
|
---|
| 55 | // -- Four2DRespTable : Reponse tabulee instrumentale ds le plan k_x,k_y (angles theta,phi)
|
---|
| 56 | //---------------------------------------------------------------
|
---|
| 57 | Four2DRespTable::Four2DRespTable(Histo2D const & hrep, double d)
|
---|
| 58 | : Four2DResponse(0,d,d) , hrep_(hrep)
|
---|
| 59 | {
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | double Four2DRespTable::Value(double kx, double ky)
|
---|
| 63 | {
|
---|
| 64 | int_4 i,j;
|
---|
| 65 | if ( (kx<=hrep_.XMin())||(kx>=hrep_.XMax()) ||
|
---|
| 66 | (ky<=hrep_.YMin())||(ky>=hrep_.YMax()) ) return 0.;
|
---|
| 67 | hrep_.FindBin(kx, ky, i, j);
|
---|
| 68 | return hrep_(i, j);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | //--- Classe simple pour le calcul de rotation
|
---|
| 72 | class Rotation {
|
---|
| 73 | public:
|
---|
| 74 | Rotation(double tet, double phi)
|
---|
| 75 | {
|
---|
| 76 | // (Teta,Phi) = Direction de visee
|
---|
| 77 | // Les angles d'Euler correspondants sont Teta, Phi+Pi/2
|
---|
| 78 | // Le Pi/2 vient que les rotations d'euler se font dans l'ordre
|
---|
| 79 | // Autour de oZ d'angle Phi, autour de oN (nouvel axe X) d'angle Teta
|
---|
| 80 | // Autour du nouvel axe Z (x3) d'angle Psi (Psi=0 -> cp=1, sp=0.;
|
---|
| 81 | double ct = cos(tet);
|
---|
| 82 | double st = sin(tet);
|
---|
| 83 | // Le Pi/2 echange les axes X<>Y pour theta=phi=0 !
|
---|
| 84 | // double cf = cos(phi+M_PI/2);
|
---|
| 85 | // double sf = sin(phi+M_PI/2);
|
---|
| 86 | double cf = cos(phi);
|
---|
| 87 | double sf = sin(phi);
|
---|
| 88 | double cp = 1.; // cos((double)pO);
|
---|
| 89 | double sp = 0.; // sin((double)pO);
|
---|
| 90 | RE[0][0] = cf*cp-sf*ct*sp; RE[0][1] = sf*cp+cf*ct*sp; RE[0][2] = st*sp;
|
---|
| 91 | RE[1][0] = -cf*sp-sf*ct*cp; RE[1][1] = -sf*sp+cf*ct*cp; RE[1][2] = st*cp;
|
---|
| 92 | RE[2][0] = sf*st; RE[2][1] = -cf*st; RE[2][2] = ct;
|
---|
| 93 | }
|
---|
| 94 | inline void Do(double& x, double& y)
|
---|
| 95 | {
|
---|
| 96 | double xx=x;
|
---|
| 97 | double yy=y;
|
---|
| 98 | x = RE[0][0]*xx+RE[0][1]*yy;
|
---|
| 99 | y = RE[1][0]*xx+RE[1][1]*yy;
|
---|
| 100 | }
|
---|
| 101 | double RE[3][3];
|
---|
| 102 | };
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 | //----------------------------------------------------------------------
|
---|
| 106 | // -- Pour calculer la reponse ds le plan kx,ky d'un system MultiDish
|
---|
| 107 | //----------------------------------------------------------------------
|
---|
| 108 | MultiDish::MultiDish(double lambda, double dmax, vector<Dish>& dishes, bool fgnoauto)
|
---|
| 109 | : lambda_(lambda), dmax_(dmax), dishes_(dishes), fgnoauto_(fgnoauto)
|
---|
| 110 | {
|
---|
| 111 | SetThetaPhiRange();
|
---|
| 112 | SetRespHisNBins();
|
---|
| 113 | mcnt_=0;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | Histo2D MultiDish::GetResponse()
|
---|
| 117 | {
|
---|
| 118 | cout << " MultiDish::GetResponse() - NDishes=" << dishes_.size() << " nx=" << nx_ << " ny=" << ny_ << endl;
|
---|
| 119 | double kmx = 1.2*DeuxPI*dmax_/lambda_;
|
---|
[3769] | 120 | double dkmx = kmx/(double)nx_;
|
---|
| 121 | double dkmy = kmx/(double)ny_;
|
---|
| 122 | double kmxx = ((double)nx_+0.5)*dkmx;
|
---|
| 123 | double kmxy = ((double)ny_+0.5)*dkmy;
|
---|
| 124 | h2w_.Define(-kmxx,kmxx,2*nx_+1,-kmxy,kmxy,2*ny_+1);
|
---|
| 125 | h2w_.SetZeroBin(0.,0.);
|
---|
[3756] | 126 |
|
---|
| 127 | double dold = dishes_[0].D/lambda_;
|
---|
| 128 | double dolx = dishes_[0].Dx/lambda_;
|
---|
| 129 | double doly = dishes_[0].Dy/lambda_;
|
---|
| 130 |
|
---|
| 131 | Four2DResponse rd(2, dold, dold);
|
---|
| 132 | Four2DResponse rdr(3, dolx, doly);
|
---|
| 133 |
|
---|
| 134 | if (!dishes_[0].isCircular()) rd = rdr;
|
---|
| 135 |
|
---|
| 136 | double dtet = thetamax_/(double)ntet_;
|
---|
| 137 | double dphi = phimax_/(double)ntet_;
|
---|
| 138 |
|
---|
| 139 | double sumw = 0.;
|
---|
| 140 | for(int kt=0; kt<ntet_; kt++)
|
---|
| 141 | for(int jp=0; jp<nphi_; jp++)
|
---|
| 142 | sumw += CumulResp(rd, (double)kt*dtet, (double)jp*dphi);
|
---|
| 143 |
|
---|
[3769] | 144 | double kx1 = DeuxPI*(dishes_[0].DiameterX())/lambda_;
|
---|
| 145 | double ky1 = DeuxPI*(dishes_[0].DiameterY())/lambda_;
|
---|
| 146 | int_4 ib,jb;
|
---|
[3756] | 147 | // h2w_ /= h2cnt_;
|
---|
| 148 | Histo2D h2 = h2w_.Convert();
|
---|
[3769] | 149 | h2.FindBin(kx1, ky1, ib, jb);
|
---|
| 150 | if ((kx1<0)||(ky1<0)||(kx1>=h2.NBinX())||(ky1>=h2.NBinY())) {
|
---|
| 151 | cout << " MultiDish::GetResponse[1]/ERROR kx1,ky1=" << kx1 <<","<< ky1 << " --> ib,jb=" << ib <<","<< jb << endl;
|
---|
| 152 | ib=jb=0;
|
---|
| 153 | }
|
---|
| 154 | double vmax=h2.VMax();
|
---|
| 155 | cout << " MultiDish::GetResponse[1] VMin=" << h2.VMin() << " VMax= " << vmax
|
---|
| 156 | << " h(0,0)=" << h2(0,0) << " kx1,ky1->h(" << ib <<"," << jb << ")=" << h2(ib,jb) <<endl;
|
---|
[3756] | 157 | // double fnorm=sqrt((double)dishes_.size())/h2.VMax();
|
---|
| 158 | double fnorm=1.;
|
---|
[3769] | 159 | if (vmax > sumw) {
|
---|
[3756] | 160 | fnorm=(double)dishes_.size()/h2.VMax();
|
---|
[3769] | 161 | cout << " MultiDish::GetResponse[2]/Warning h2.VMax()=" << vmax << " > sumw=" << sumw << endl;
|
---|
| 162 | cout << " ... NDishes=" << dishes_.size() << " sumw=" << sumw
|
---|
| 163 | << " Renormalizing x NDishes/VMax " << fnorm << endl;
|
---|
[3756] | 164 | }
|
---|
| 165 | else {
|
---|
[3769] | 166 | fnorm=(double)dishes_.size()/sumw;
|
---|
| 167 | cout << " MultiDish::GetResponse[3] NDishes=" << dishes_.size() << " sumw=" << sumw
|
---|
| 168 | << " Renormalizing x NDishes/sumw " << fnorm << endl;
|
---|
[3756] | 169 | }
|
---|
| 170 | h2 *= fnorm;
|
---|
[3769] | 171 | cout << " ---- MultiDish::GetResponse/[4] APRES VMin=" << h2.VMin() << " VMax= " << h2.VMax() << " h(0,0)="
|
---|
[3756] | 172 | << h2(0,0) << endl;
|
---|
| 173 | return h2;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
[3769] | 176 | Histo2D MultiDish::PosDist(int nx, int ny, double dmax)
|
---|
[3756] | 177 | {
|
---|
[3769] | 178 | if (dmax<1e-3) dmax=nx*dishes_[0].Diameter();
|
---|
| 179 | double dd = dmax/nx/2.;
|
---|
| 180 | Histo2D hpos(-dd,dmax+dd,nx+1,-dd,dmax+dd,ny+1);
|
---|
| 181 | for(size_t i=0; i<NbDishes(); i++) {
|
---|
| 182 | hpos.Add(dishes_[i].X, dishes_[i].Y);
|
---|
[3756] | 183 | }
|
---|
[3769] | 184 | return hpos;
|
---|
[3756] | 185 | }
|
---|
| 186 |
|
---|
| 187 | double MultiDish::AddToHisto(double kx0, double ky0, double x, double y, double w, bool fgfh)
|
---|
| 188 | {
|
---|
| 189 | double xxp = kx0+x;
|
---|
| 190 | double yyp = ky0+y;
|
---|
| 191 | double sumw=0.;
|
---|
| 192 | sumw += h2w_.Add(xxp, yyp, w, fgfh);
|
---|
| 193 | double xxm=kx0-x;
|
---|
| 194 | double yym=ky0-y;
|
---|
[3769] | 195 | // if (xxm>0.) {
|
---|
| 196 | sumw += h2w_.Add(xxm, yyp, w, fgfh);
|
---|
| 197 | // if (yym>0.)
|
---|
| 198 | sumw += h2w_.Add(xxm, yym, w, fgfh);
|
---|
| 199 | // }
|
---|
| 200 | // if (yym>0.)
|
---|
| 201 | sumw += h2w_.Add(xxp, yym, w, fgfh);
|
---|
[3756] | 202 | return sumw;
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | double MultiDish::CumulResp(Four2DResponse& rd, double theta, double phi)
|
---|
| 206 | {
|
---|
| 207 | // cout << " MultiDish::CumulResp() theta=" << theta << " phi=" << phi << endl;
|
---|
| 208 |
|
---|
| 209 | double dx = h2w_.WBinX()/5;
|
---|
| 210 | double dy = h2w_.WBinY()/5;
|
---|
[3769] | 211 | int nbx = DeuxPI*rd.Dx()/dx+1;
|
---|
| 212 | int nby = DeuxPI*rd.Dy()/dy+1;
|
---|
[3756] | 213 | dx = DeuxPI*rd.Dx()/(double)nbx;
|
---|
| 214 | dy = DeuxPI*rd.Dy()/(double)nby;
|
---|
| 215 | if (mcnt_==0)
|
---|
| 216 | cout << " CumulResp() nbx=" << nbx << " nby=" << nby << " dx=" << dx << " dy=" << dy << endl;
|
---|
| 217 | mcnt_++;
|
---|
| 218 |
|
---|
| 219 | double sumw = 0.;
|
---|
| 220 | Rotation rot(theta, phi);
|
---|
| 221 |
|
---|
| 222 | for(size_t i=0; i<dishes_.size(); i++) {
|
---|
[3769] | 223 | for(size_t j=0; j<dishes_.size(); j++) {
|
---|
| 224 | double kx0 = DeuxPI*(dishes_[i].X-dishes_[j].X)/lambda_;
|
---|
| 225 | double ky0 = DeuxPI*(dishes_[i].Y-dishes_[j].Y)/lambda_;
|
---|
[3756] | 226 | rot.Do(kx0, ky0);
|
---|
[3769] | 227 | // if (kx0<0) kx0=-kx0;
|
---|
| 228 | // if (ky0<0) ky0=-ky0;
|
---|
[3756] | 229 | bool fgfh= (!fgnoauto_ || (dishes_[i].ReflectorId()!=dishes_[j].ReflectorId()));
|
---|
| 230 | for(int ix=0; ix<nbx; ix++)
|
---|
| 231 | for(int jy=0; jy<nby; jy++) {
|
---|
| 232 | double x = ix*dx;
|
---|
[3769] | 233 | double y = jy*dy;
|
---|
| 234 | if ((ix>0)&&(jy>0)) {
|
---|
| 235 | sumw += AddToHisto(kx0, ky0, x, y, rd(x,y), fgfh);
|
---|
| 236 | }
|
---|
| 237 | else {
|
---|
| 238 | if ((ix==0)&&(jy==0))
|
---|
| 239 | sumw += h2w_.Add(kx0, ky0, rd(0.,0.), fgfh);
|
---|
| 240 | else {
|
---|
| 241 | double w = rd(x,y);
|
---|
| 242 | if (ix==0) {
|
---|
| 243 | sumw += h2w_.Add(kx0, ky0+y, w, fgfh);
|
---|
| 244 | sumw += h2w_.Add(kx0, ky0-y, w, fgfh);
|
---|
| 245 | }
|
---|
| 246 | else {
|
---|
| 247 | sumw += h2w_.Add(kx0+x, ky0, w, fgfh);
|
---|
| 248 | sumw += h2w_.Add(kx0-x, ky0, w, fgfh);
|
---|
| 249 | }
|
---|
| 250 | }
|
---|
| 251 | //
|
---|
| 252 | }
|
---|
[3756] | 253 | }
|
---|
| 254 | // if (i%10==0)
|
---|
| 255 | // cout << " MultiDish::CumulResp() done i=" << i << " / imax=" << dishes_.size()
|
---|
| 256 | // << " theta=" << theta << " phi=" << phi << endl;
|
---|
[3769] | 257 | }
|
---|
[3756] | 258 | }
|
---|
| 259 | return sumw;
|
---|
| 260 | }
|
---|
| 261 |
|
---|