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