| 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, double lambda)
 | 
|---|
| 12 |   : typ_(typ), dx_((dx>1.e-3)?dx:1.), dy_((dy>1.e-3)?dy:1.)
 | 
|---|
| 13 | {
 | 
|---|
| 14 |   setLambdaRef(lambda);
 | 
|---|
| 15 |   setLambda(lambda);
 | 
|---|
| 16 | }
 | 
|---|
| 17 | 
 | 
|---|
| 18 | // Return the response for the wave vecteor (kx,ky)
 | 
|---|
| 19 | double Four2DResponse::Value(double kx, double ky)
 | 
|---|
| 20 | {
 | 
|---|
| 21 |   kx *= lambda_ratio_;
 | 
|---|
| 22 |   ky *= lambda_ratio_;
 | 
|---|
| 23 |   double wk,wkx,wky;
 | 
|---|
| 24 |   switch (typ_) 
 | 
|---|
| 25 |     {
 | 
|---|
| 26 |     case 1:   // Reponse gaussienne parabole diametre D exp[ -(1/8) (lambda  k_g / D )^2 ]
 | 
|---|
| 27 |       wk = sqrt(kx*kx+ky*ky)/dx_;
 | 
|---|
| 28 |       wk = wk*wk/8.;
 | 
|---|
| 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 22:   // Reponse parabole diametre D  Triangle <= kmax= 2 pi D / lambda + trou au centre
 | 
|---|
| 36 |       wk = sqrt(kx*kx+ky*ky)/dx_/2./M_PI;
 | 
|---|
| 37 |       if (wk<0.025) return 39.*wk;
 | 
|---|
| 38 |       else if (wk<1.) return (1.-wk);
 | 
|---|
| 39 |       else return 0.;
 | 
|---|
| 40 |       break;
 | 
|---|
| 41 |     case 3:   // Reponse rectangle Dx x Dy  Triangle (|kx|,|k_y|) <= (2 pi Dx / lambda, 2 pi Dx / lambda) 
 | 
|---|
| 42 |       wkx = fabs(kx)/2./M_PI/dx_; 
 | 
|---|
| 43 |       wky = fabs(ky)/2./M_PI/dy_; 
 | 
|---|
| 44 |       return ( ((wkx<1.)&&(wky<1.))?((1.-wkx)*(1-wky)):0.);
 | 
|---|
| 45 |       break;
 | 
|---|
| 46 |     default:
 | 
|---|
| 47 |       return 1.;
 | 
|---|
| 48 |     }
 | 
|---|
| 49 | }
 | 
|---|
| 50 | // Return a vector representing the power spectrum (for checking) 
 | 
|---|
| 51 | Histo2D Four2DResponse::GetResponse(int nx, int ny)
 | 
|---|
| 52 | {
 | 
|---|
| 53 |   double kxmx = 1.2*DeuxPI*dx_;
 | 
|---|
| 54 |   double kymx = 1.2*DeuxPI*dy_;
 | 
|---|
| 55 |   if (typ_<3) kymx=kxmx; 
 | 
|---|
| 56 |   Histo2D h2(-kxmx,kxmx,nx,-kymx,kymx,ny);
 | 
|---|
| 57 | 
 | 
|---|
| 58 |   double xbc,ybc;
 | 
|---|
| 59 |   for(int_4 j=0; j<h2.NBinY(); j++) 
 | 
|---|
| 60 |     for(int_4 i=0; i<h2.NBinX(); i++) {
 | 
|---|
| 61 |       h2.BinCenter(i,j,xbc,ybc);
 | 
|---|
| 62 |       h2(i,j) = Value(xbc,ybc);
 | 
|---|
| 63 |     }
 | 
|---|
| 64 |   return h2;    
 | 
|---|
| 65 | }
 | 
|---|
| 66 | 
 | 
|---|
| 67 | HProf Four2DResponse::GetProjNoiseLevel(int nbin, bool fgnorm1)
 | 
|---|
| 68 | {
 | 
|---|
| 69 |   Histo2D h2w = GetResponse(2*nbin, 2*nbin);
 | 
|---|
| 70 |   r_8 vmin=h2w.VMin();
 | 
|---|
| 71 |   r_8 vmax=h2w.VMax();
 | 
|---|
| 72 |   double seuil=vmax/10000.;
 | 
|---|
| 73 |   if (seuil<1.e-6) seuil=1.e-6;
 | 
|---|
| 74 |   r_8 facnorm=((fgnorm1)?vmax:1.);
 | 
|---|
| 75 |   cout << " Four2DResponse::GetProjNoiseLevel Min,Max=" << vmin << " , " << vmax 
 | 
|---|
| 76 |        << " facnorm=" << facnorm << " seuil=" << seuil << endl;  
 | 
|---|
| 77 |   double kmax=2.*M_PI*D();
 | 
|---|
| 78 |   HProf hp(0,kmax,nbin);
 | 
|---|
| 79 |   double x,y;
 | 
|---|
| 80 |   for(sa_size_t j=0; j<h2w.NBinY(); j++) {
 | 
|---|
| 81 |     for(sa_size_t i=0; i<h2w.NBinX(); i++) {
 | 
|---|
| 82 |       h2w.BinCenter(i,j,x,y);
 | 
|---|
| 83 |       double yw=h2w(i,j);
 | 
|---|
| 84 |       if (yw<seuil) continue;
 | 
|---|
| 85 |       hp.Add(sqrt(x*x+y*y),facnorm/yw);
 | 
|---|
| 86 |     }
 | 
|---|
| 87 |   }
 | 
|---|
| 88 |   return hp;
 | 
|---|
| 89 | }
 | 
|---|
| 90 | 
 | 
|---|
| 91 | HProf Four2DResponse::GetProjResponse(int nbin, bool fgnorm1)
 | 
|---|
| 92 | {
 | 
|---|
| 93 |   Histo2D h2w = GetResponse(2*nbin, 2*nbin);
 | 
|---|
| 94 |   r_8 vmin=h2w.VMin();
 | 
|---|
| 95 |   r_8 vmax=h2w.VMax();
 | 
|---|
| 96 |   r_8 facnorm=((fgnorm1)?(1./vmax):1.);
 | 
|---|
| 97 |   cout << " Four2DResponse::GetProjResponse Min,Max=" << vmin << " , " << vmax 
 | 
|---|
| 98 |        << " facnorm=" << facnorm << endl; 
 | 
|---|
| 99 |   double kmax=2.*M_PI*D();
 | 
|---|
| 100 |   HProf hp(0,kmax,nbin);
 | 
|---|
| 101 |   double x,y;
 | 
|---|
| 102 |   for(sa_size_t j=0; j<h2w.NBinY(); j++) {
 | 
|---|
| 103 |     for(sa_size_t i=0; i<h2w.NBinX(); i++) {
 | 
|---|
| 104 |       h2w.BinCenter(i,j,x,y);
 | 
|---|
| 105 |       hp.Add(sqrt(x*x+y*y),h2w(i,j)*facnorm);
 | 
|---|
| 106 |     }
 | 
|---|
| 107 |   }
 | 
|---|
| 108 |   return hp;
 | 
|---|
| 109 | }
 | 
|---|
| 110 | 
 | 
|---|
| 111 | //---------------------------------------------------------------
 | 
|---|
| 112 | // -- Four2DRespTable : Reponse tabulee instrumentale ds le plan k_x,k_y (angles theta,phi) 
 | 
|---|
| 113 | //---------------------------------------------------------------
 | 
|---|
| 114 | Four2DRespTable::Four2DRespTable()
 | 
|---|
| 115 |   : Four2DResponse(0,1.,1.)
 | 
|---|
| 116 | {
 | 
|---|
| 117 | }
 | 
|---|
| 118 | 
 | 
|---|
| 119 | Four2DRespTable::Four2DRespTable(Histo2D const & hrep, double d, double lambda)
 | 
|---|
| 120 |   : Four2DResponse(0,d,d,lambda) , hrep_(hrep)
 | 
|---|
| 121 | {
 | 
|---|
| 122 | }
 | 
|---|
| 123 | 
 | 
|---|
| 124 | double Four2DRespTable::Value(double kx, double ky)
 | 
|---|
| 125 | {
 | 
|---|
| 126 |   kx *= lambda_ratio_;
 | 
|---|
| 127 |   ky *= lambda_ratio_;
 | 
|---|
| 128 |   int_4 i,j;
 | 
|---|
| 129 |   if ( (kx<=hrep_.XMin())||(kx>=hrep_.XMax()) || 
 | 
|---|
| 130 |        (ky<=hrep_.YMin())||(ky>=hrep_.YMax()) )  return 0.;
 | 
|---|
| 131 |   hrep_.FindBin(kx, ky, i, j);
 | 
|---|
| 132 |   return hrep_(i, j);
 | 
|---|
| 133 | }
 | 
|---|
| 134 | 
 | 
|---|
| 135 | double Four2DRespTable::renormalize(double max)
 | 
|---|
| 136 | {
 | 
|---|
| 137 |   double cmx = hrep_.VMax();
 | 
|---|
| 138 |   hrep_ *= (max/cmx);
 | 
|---|
| 139 |   return cmx;
 | 
|---|
| 140 | }
 | 
|---|
| 141 | 
 | 
|---|
| 142 | void Four2DRespTable::writeToPPF(string flnm)
 | 
|---|
| 143 | {
 | 
|---|
| 144 |   DVList dvinfo;
 | 
|---|
| 145 |   dvinfo["DoL"] = dx_;
 | 
|---|
| 146 |   dvinfo["LambdaRef"] = lambdaref_;
 | 
|---|
| 147 |   dvinfo["Lambda"] = lambda_;
 | 
|---|
| 148 |   POutPersist po(flnm);
 | 
|---|
| 149 |   po << hrep_;
 | 
|---|
| 150 |   po << dvinfo;
 | 
|---|
| 151 | }
 | 
|---|
| 152 | 
 | 
|---|
| 153 | void Four2DRespTable::readFromPPF(string flnm)
 | 
|---|
| 154 | {
 | 
|---|
| 155 |   PInPersist pin(flnm);
 | 
|---|
| 156 |   DVList dvinfo;
 | 
|---|
| 157 |   pin >> hrep_;
 | 
|---|
| 158 |   pin >> dvinfo;
 | 
|---|
| 159 |   dx_ = dy_ = dvinfo["DoL"];
 | 
|---|
| 160 |   setLambdaRef((double)dvinfo["LambdaRef"]);
 | 
|---|
| 161 |   setLambda((double)dvinfo["Lambda"]); 
 | 
|---|
| 162 | }
 | 
|---|
| 163 | 
 | 
|---|
| 164 | 
 | 
|---|
| 165 | 
 | 
|---|
| 166 | //---------------------------------------------------------------
 | 
|---|
| 167 | // -- Four2DRespRatio : rapport de la reponse entre deux objets Four2DResponse
 | 
|---|
| 168 | //---------------------------------------------------------------
 | 
|---|
| 169 | Four2DRespRatio::Four2DRespRatio(Four2DResponse& a, Four2DResponse& b, double maxratio)
 | 
|---|
| 170 |   : Four2DResponse(0, a.D(), a.D()), a_(a), b_(b), maxratio_(maxratio), zerothr_(.5/maxratio)
 | 
|---|
| 171 | {
 | 
|---|
| 172 | }
 | 
|---|
| 173 | 
 | 
|---|
| 174 | double Four2DRespRatio::Value(double kx, double ky)
 | 
|---|
| 175 | {
 | 
|---|
| 176 |   double ra = a_.Value(kx,ky);
 | 
|---|
| 177 |   double rb = b_.Value(kx,ky);
 | 
|---|
| 178 |   if ((ra<zerothr_)||(rb<zerothr_))  return 0.;
 | 
|---|
| 179 |   double rval=ra/rb;
 | 
|---|
| 180 |   if (rval<maxratio_) return rval;
 | 
|---|
| 181 |   return maxratio_;
 | 
|---|
| 182 | }
 | 
|---|
| 183 | 
 | 
|---|
| 184 | //---------------------------------------------------------------
 | 
|---|
| 185 | //--- Classe simple pour le calcul de rotation 
 | 
|---|
| 186 | class Rotation {
 | 
|---|
| 187 | public:
 | 
|---|
| 188 |   Rotation(double tet, double phi)
 | 
|---|
| 189 |   {
 | 
|---|
| 190 | // (Teta,Phi) = Direction de visee 
 | 
|---|
| 191 | // Les angles d'Euler correspondants sont Teta, Phi+Pi/2
 | 
|---|
| 192 | // Le Pi/2 vient que les rotations d'euler se font dans l'ordre
 | 
|---|
| 193 | //  Autour de oZ d'angle Phi, autour de oN (nouvel axe X) d'angle Teta
 | 
|---|
| 194 | //  Autour du nouvel axe Z (x3) d'angle Psi  (Psi=0 -> cp=1, sp=0.;
 | 
|---|
| 195 |   double ct = cos(tet);
 | 
|---|
| 196 |   double st = sin(tet);
 | 
|---|
| 197 |   // Le Pi/2 echange les axes X<>Y pour theta=phi=0 !
 | 
|---|
| 198 |   //  double cf = cos(phi+M_PI/2);
 | 
|---|
| 199 |   //  double sf = sin(phi+M_PI/2);
 | 
|---|
| 200 |   double cf = cos(phi);
 | 
|---|
| 201 |   double sf = sin(phi);
 | 
|---|
| 202 |   double cp = 1.; // cos((double)pO);
 | 
|---|
| 203 |   double sp = 0.; // sin((double)pO);
 | 
|---|
| 204 |   RE[0][0] = cf*cp-sf*ct*sp;     RE[0][1] = sf*cp+cf*ct*sp;      RE[0][2] = st*sp;
 | 
|---|
| 205 |   RE[1][0] = -cf*sp-sf*ct*cp;    RE[1][1] = -sf*sp+cf*ct*cp;     RE[1][2] = st*cp;
 | 
|---|
| 206 |   RE[2][0] = sf*st;              RE[2][1] = -cf*st;              RE[2][2] = ct;
 | 
|---|
| 207 |   }
 | 
|---|
| 208 |   inline void Do(double& x, double& y)
 | 
|---|
| 209 |   {
 | 
|---|
| 210 |     double xx=x; 
 | 
|---|
| 211 |     double yy=y;
 | 
|---|
| 212 |     x = RE[0][0]*xx+RE[0][1]*yy;
 | 
|---|
| 213 |     y = RE[1][0]*xx+RE[1][1]*yy;
 | 
|---|
| 214 |   }
 | 
|---|
| 215 |   double RE[3][3];
 | 
|---|
| 216 | };
 | 
|---|
| 217 | 
 | 
|---|
| 218 | 
 | 
|---|
| 219 | //----------------------------------------------------------------------
 | 
|---|
| 220 | //  -- Pour calculer la reponse ds le plan kx,ky d'un system MultiDish 
 | 
|---|
| 221 | //----------------------------------------------------------------------
 | 
|---|
| 222 | MultiDish::MultiDish(double lambda, double dmax, vector<Dish>& dishes, bool fgnoauto)
 | 
|---|
| 223 |   : lambda_(lambda), dmax_(dmax), dishes_(dishes), fgnoauto_(fgnoauto)
 | 
|---|
| 224 | { 
 | 
|---|
| 225 |   SetThetaPhiRange();
 | 
|---|
| 226 |   SetRespHisNBins();
 | 
|---|
| 227 |   SetBeamNSamples();
 | 
|---|
| 228 |   SetPrtLevel();
 | 
|---|
| 229 |   fgcomputedone_=false;
 | 
|---|
| 230 |   mcnt_=0;
 | 
|---|
| 231 | }
 | 
|---|
| 232 | 
 | 
|---|
| 233 | void MultiDish::ComputeResponse()
 | 
|---|
| 234 | {
 | 
|---|
| 235 |   cout << " MultiDish::ComputeResponse() - NDishes=" << dishes_.size() << " nx=" << nx_ << " ny=" << ny_ << endl;
 | 
|---|
| 236 |   double kmx = 1.2*DeuxPI*dmax_/lambda_;
 | 
|---|
| 237 |   double dkmx = kmx/(double)nx_;
 | 
|---|
| 238 |   double dkmy = kmx/(double)ny_;
 | 
|---|
| 239 |   double kmxx = ((double)nx_+0.5)*dkmx;
 | 
|---|
| 240 |   double kmxy = ((double)ny_+0.5)*dkmy;
 | 
|---|
| 241 |   h2w_.Define(-kmxx,kmxx,2*nx_+1,-kmxy,kmxy,2*ny_+1);
 | 
|---|
| 242 |   h2w_.SetZeroBin(0.,0.);
 | 
|---|
| 243 |   kmax_=kmx;
 | 
|---|
| 244 | 
 | 
|---|
| 245 |   double dold = dishes_[0].Diameter()/lambda_;
 | 
|---|
| 246 |   double dolx = dishes_[0].DiameterX()/lambda_;
 | 
|---|
| 247 |   double doly = dishes_[0].DiameterY()/lambda_;
 | 
|---|
| 248 | 
 | 
|---|
| 249 |   Four2DResponse rd(2, dold, dold);
 | 
|---|
| 250 |   Four2DResponse rdr(3, dolx, doly);
 | 
|---|
| 251 | 
 | 
|---|
| 252 |   if (!dishes_[0].isCircular())  rd = rdr;
 | 
|---|
| 253 | 
 | 
|---|
| 254 |   double dtet = thetamax_/(double)ntet_;
 | 
|---|
| 255 |   double dphi = phimax_/(double)nphi_;
 | 
|---|
| 256 |   cout << " MultiDish::ComputeResponse() - ThetaMax=" << thetamax_ << " NTheta=" << ntet_ 
 | 
|---|
| 257 |        << " PhiMax=" <<  phimax_ << " NPhi=" << nphi_ << endl;
 | 
|---|
| 258 | 
 | 
|---|
| 259 |   double sumw = 0.;
 | 
|---|
| 260 |   for(int kt=0; kt<ntet_; kt++) {
 | 
|---|
| 261 |     double theta=(double)kt*dtet;
 | 
|---|
| 262 |     for(int jp=0; jp<nphi_; jp++) {
 | 
|---|
| 263 |       double phi=(double)jp*dphi;
 | 
|---|
| 264 |       sumw += CumulResp(rd, theta, phi);
 | 
|---|
| 265 |       if (theta<1.e-9) continue;
 | 
|---|
| 266 |       sumw += CumulResp(rd, theta, -phi);
 | 
|---|
| 267 |       sumw += CumulResp(rd, theta, phi+M_PI);
 | 
|---|
| 268 |       sumw += CumulResp(rd, theta, -(phi+M_PI));
 | 
|---|
| 269 |     }
 | 
|---|
| 270 |     if (prtlev_>0) 
 | 
|---|
| 271 |       cout << "  MultiDish::ComputeResponse() done ktheta=" << kt << " / MaxNTheta= " 
 | 
|---|
| 272 |            << ntet_ << endl; 
 | 
|---|
| 273 |   }
 | 
|---|
| 274 |   r_8 rmin,rmax;
 | 
|---|
| 275 |   h2w_.GetMinMax(rmin,rmax);
 | 
|---|
| 276 |   cout << "  MultiDish::ComputeResponse() finished : Rep_min,max=" << rmin << "," << rmax << " sumW0=" 
 | 
|---|
| 277 |        << sumw << " ?=" << h2w_.SumWBinZero() << endl;
 | 
|---|
| 278 |   fgcomputedone_=true;
 | 
|---|
| 279 |   return;
 | 
|---|
| 280 | }
 | 
|---|
| 281 | 
 | 
|---|
| 282 | Histo2D MultiDish::GetResponse()
 | 
|---|
| 283 | {
 | 
|---|
| 284 |   if (!fgcomputedone_) ComputeResponse();
 | 
|---|
| 285 | 
 | 
|---|
| 286 |   double kx1 = DeuxPI*(dishes_[0].DiameterX())/lambda_;
 | 
|---|
| 287 |   double ky1 = DeuxPI*(dishes_[0].DiameterY())/lambda_;
 | 
|---|
| 288 |   int_4 ib,jb;
 | 
|---|
| 289 |   //  h2w_ /= h2cnt_; 
 | 
|---|
| 290 |   Histo2D h2 = h2w_.Convert();
 | 
|---|
| 291 |   h2.FindBin(kx1, ky1, ib, jb);
 | 
|---|
| 292 |   if ((kx1<0)||(ky1<0)||(kx1>=h2.NBinX())||(ky1>=h2.NBinY())) {
 | 
|---|
| 293 |     cout << " MultiDish::GetResponse[1]/ERROR kx1,ky1=" << kx1 <<","<< ky1 << " --> ib,jb=" << ib <<","<< jb << endl;
 | 
|---|
| 294 |     ib=jb=0;
 | 
|---|
| 295 |   }
 | 
|---|
| 296 |   double sumw=h2w_.SumWBinZero();
 | 
|---|
| 297 |   double vmax=h2.VMax();
 | 
|---|
| 298 |   cout << " MultiDish::GetResponse[1] VMin=" << h2.VMin() << " VMax= " << vmax  
 | 
|---|
| 299 |        << " h(0,0)=" << h2(0,0) << " kx1,ky1->h(" << ib <<"," << jb << ")=" << h2(ib,jb) <<endl;
 | 
|---|
| 300 |   //  double fnorm=sqrt((double)dishes_.size())/h2.VMax();
 | 
|---|
| 301 |   double fnorm=1.;
 | 
|---|
| 302 |   if (vmax > sumw) {
 | 
|---|
| 303 |     fnorm=(double)dishes_.size()/h2.VMax();
 | 
|---|
| 304 |     cout << " MultiDish::GetResponse[2]/Warning h2.VMax()=" << vmax << " >  sumw=" << sumw << endl;  
 | 
|---|
| 305 |     cout << "   ... NDishes=" << dishes_.size() << " sumw=" << sumw 
 | 
|---|
| 306 |          << " Renormalizing x NDishes/VMax  " << fnorm << endl;
 | 
|---|
| 307 |   }
 | 
|---|
| 308 |   else {
 | 
|---|
| 309 |     fnorm=(double)dishes_.size()/sumw;
 | 
|---|
| 310 |     cout << " MultiDish::GetResponse[3] NDishes=" << dishes_.size() << " sumw=" << sumw  
 | 
|---|
| 311 |          << " Renormalizing x NDishes/sumw   " << fnorm << endl;
 | 
|---|
| 312 |   }
 | 
|---|
| 313 |   h2 *= fnorm;
 | 
|---|
| 314 |   cout << " ---- MultiDish::GetResponse/[4] APRES VMin=" << h2.VMin() << " VMax= " << h2.VMax() << " h(0,0)=" 
 | 
|---|
| 315 |        << h2(0,0) << endl;
 | 
|---|
| 316 |   return h2;
 | 
|---|
| 317 | }
 | 
|---|
| 318 | 
 | 
|---|
| 319 | HProf MultiDish::GetProjNoiseLevel(int nbin, bool fgnorm1)
 | 
|---|
| 320 | {
 | 
|---|
| 321 |   r_8 vmin,vmax;
 | 
|---|
| 322 |   h2w_.GetMinMax(vmin,vmax);
 | 
|---|
| 323 |   double seuil=vmax/10000.;
 | 
|---|
| 324 |   if (seuil<1.e-6) seuil=1.e-6;
 | 
|---|
| 325 |   r_8 facnorm=((fgnorm1)?vmax:1.);
 | 
|---|
| 326 |   cout << " MultiDish::GetProjNoiseLevel Min,Max=" << vmin << " , " << vmax 
 | 
|---|
| 327 |        << " facnorm=" << facnorm << " seuil=" << seuil << endl;  
 | 
|---|
| 328 |   HProf hp(0,kmax_,nbin);
 | 
|---|
| 329 |   for(sa_size_t j=0; j<h2w_.NBinY(); j++) {
 | 
|---|
| 330 |     double y=h2w_.Y(j);
 | 
|---|
| 331 |     for(sa_size_t i=0; i<h2w_.NBinX(); i++) {
 | 
|---|
| 332 |       double x=h2w_.X(i);
 | 
|---|
| 333 |       double yw=h2w_(i,j);
 | 
|---|
| 334 |       if (yw<seuil) continue;
 | 
|---|
| 335 |       hp.Add(sqrt(x*x+y*y),facnorm/yw);
 | 
|---|
| 336 |     }
 | 
|---|
| 337 |   }
 | 
|---|
| 338 |   return hp;
 | 
|---|
| 339 | }
 | 
|---|
| 340 | 
 | 
|---|
| 341 | HProf MultiDish::GetProjResponse(int nbin, bool fgnorm1)
 | 
|---|
| 342 | {
 | 
|---|
| 343 |   r_8 vmin,vmax;
 | 
|---|
| 344 |   h2w_.GetMinMax(vmin,vmax);
 | 
|---|
| 345 |   r_8 facnorm=((fgnorm1)?(1./vmax):1.);
 | 
|---|
| 346 |   cout << " MultiDish::GetProjResponse Min,Max=" << vmin << " , " << vmax 
 | 
|---|
| 347 |        << " facnorm=" << facnorm << endl;  
 | 
|---|
| 348 |   HProf hp(0,kmax_,nbin);
 | 
|---|
| 349 |   for(sa_size_t j=0; j<h2w_.NBinY(); j++) {
 | 
|---|
| 350 |     double y=h2w_.Y(j);
 | 
|---|
| 351 |     for(sa_size_t i=0; i<h2w_.NBinX(); i++) {
 | 
|---|
| 352 |       double x=h2w_.X(i);
 | 
|---|
| 353 |       hp.Add(sqrt(x*x+y*y),h2w_(i,j)*facnorm);
 | 
|---|
| 354 |     }
 | 
|---|
| 355 |   }
 | 
|---|
| 356 |   return hp;
 | 
|---|
| 357 | }
 | 
|---|
| 358 | 
 | 
|---|
| 359 | 
 | 
|---|
| 360 | Histo2D MultiDish::PosDist(int nx, int ny, double dmax)
 | 
|---|
| 361 | {
 | 
|---|
| 362 |   if (dmax<1e-3)  dmax=nx*dishes_[0].Diameter();
 | 
|---|
| 363 |   double dd = dmax/nx/2.;
 | 
|---|
| 364 |   Histo2D hpos(-dd,dmax+dd,nx+1,-dd,dmax+dd,ny+1);
 | 
|---|
| 365 |   for(size_t i=0; i<NbDishes(); i++) {
 | 
|---|
| 366 |     hpos.Add(dishes_[i].X, dishes_[i].Y);
 | 
|---|
| 367 |   }
 | 
|---|
| 368 |   return hpos;
 | 
|---|
| 369 | }
 | 
|---|
| 370 | 
 | 
|---|
| 371 | double MultiDish::AddToHisto(double kx0, double ky0, double x, double y, double w, bool fgfh)
 | 
|---|
| 372 | {
 | 
|---|
| 373 |   double xxp = kx0+x;
 | 
|---|
| 374 |   double yyp = ky0+y;
 | 
|---|
| 375 |   double sumw=0.;
 | 
|---|
| 376 |   sumw += h2w_.Add(xxp, yyp, w, fgfh);
 | 
|---|
| 377 |   double xxm=kx0-x;
 | 
|---|
| 378 |   double yym=ky0-y;
 | 
|---|
| 379 |   //  if (xxm>0.)  {
 | 
|---|
| 380 |   sumw += h2w_.Add(xxm, yyp, w, fgfh);
 | 
|---|
| 381 |   // if (yym>0.)  
 | 
|---|
| 382 |   sumw += h2w_.Add(xxm, yym, w, fgfh);
 | 
|---|
| 383 |   //  }
 | 
|---|
| 384 |   // if (yym>0.)  
 | 
|---|
| 385 |   sumw += h2w_.Add(xxp, yym, w, fgfh);
 | 
|---|
| 386 |   return sumw; 
 | 
|---|
| 387 | }
 | 
|---|
| 388 | 
 | 
|---|
| 389 | double MultiDish::CumulResp(Four2DResponse& rd, double theta, double phi)
 | 
|---|
| 390 | {
 | 
|---|
| 391 |   //  cout << " MultiDish::CumulResp()  theta=" << theta << " phi=" << phi << endl;
 | 
|---|
| 392 |   /*
 | 
|---|
| 393 |   double dx = h2w_.WBinX()/5;
 | 
|---|
| 394 |   double dy = h2w_.WBinY()/5;
 | 
|---|
| 395 |   int nbx = DeuxPI*rd.Dx()/dx+1;
 | 
|---|
| 396 |   int nby = DeuxPI*rd.Dy()/dy+1;
 | 
|---|
| 397 |   */
 | 
|---|
| 398 |   double dx,dy;
 | 
|---|
| 399 |   int nbx=beamnx_; 
 | 
|---|
| 400 |   int nby=beamny_;
 | 
|---|
| 401 |   dx = DeuxPI*rd.Dx()/(double)nbx;
 | 
|---|
| 402 |   dy = DeuxPI*rd.Dy()/(double)nby;
 | 
|---|
| 403 |   if (mcnt_==0) 
 | 
|---|
| 404 |     cout << " CumulResp() nbx=" << nbx << " nby=" << nby << " dx=" << dx << " dy=" << dy << endl;
 | 
|---|
| 405 |   mcnt_++;
 | 
|---|
| 406 | 
 | 
|---|
| 407 |   double sumw = 0.;
 | 
|---|
| 408 |   Rotation rot(theta, phi);
 | 
|---|
| 409 | 
 | 
|---|
| 410 |   for(size_t i=0; i<dishes_.size(); i++) {
 | 
|---|
| 411 |     for(size_t j=i; j<dishes_.size(); j++) {
 | 
|---|
| 412 |       double kx0 = DeuxPI*(dishes_[i].X-dishes_[j].X)/lambda_;
 | 
|---|
| 413 |       double ky0 = DeuxPI*(dishes_[i].Y-dishes_[j].Y)/lambda_;
 | 
|---|
| 414 |       double pgain=dishes_[i].Gain()*dishes_[j].Gain();
 | 
|---|
| 415 |       rot.Do(kx0, ky0);
 | 
|---|
| 416 |       //    if (kx0<0) kx0=-kx0;
 | 
|---|
| 417 |       //    if (ky0<0) ky0=-ky0;
 | 
|---|
| 418 |       bool fgfh= (!fgnoauto_ || (dishes_[i].ReflectorId()!=dishes_[j].ReflectorId()));
 | 
|---|
| 419 |       for(int ix=0; ix<nbx; ix++) 
 | 
|---|
| 420 |         for(int jy=0; jy<nby; jy++) { 
 | 
|---|
| 421 |           double x = ix*dx;  
 | 
|---|
| 422 |           double y = jy*dy;
 | 
|---|
| 423 |           if ((ix>0)&&(jy>0)) {
 | 
|---|
| 424 |             sumw += AddToHisto(kx0, ky0, x, y, rd(x,y)*pgain, fgfh);
 | 
|---|
| 425 |             if (j!=i) sumw += AddToHisto(-kx0, -ky0, x, y, rd(x,y)*pgain, fgfh);
 | 
|---|
| 426 |           }
 | 
|---|
| 427 |           else {
 | 
|---|
| 428 |             if ((ix==0)&&(jy==0)) {
 | 
|---|
| 429 |               sumw += h2w_.Add(kx0, ky0, rd(0.,0.)*pgain, fgfh);
 | 
|---|
| 430 |               if (j!=i) sumw += h2w_.Add(-kx0, -ky0, rd(0.,0.)*pgain, fgfh);
 | 
|---|
| 431 |             }
 | 
|---|
| 432 |             else {
 | 
|---|
| 433 |               double w = rd(x,y)*pgain;
 | 
|---|
| 434 |               if (ix==0) {
 | 
|---|
| 435 |                 sumw += h2w_.Add(kx0, ky0+y, w, fgfh);
 | 
|---|
| 436 |                 sumw += h2w_.Add(kx0, ky0-y, w, fgfh);
 | 
|---|
| 437 |                 if (j!=i) {
 | 
|---|
| 438 |                   sumw += h2w_.Add(-kx0, -ky0+y, w, fgfh);
 | 
|---|
| 439 |                   sumw += h2w_.Add(-kx0, -ky0-y, w, fgfh);
 | 
|---|
| 440 |                 }
 | 
|---|
| 441 |               }
 | 
|---|
| 442 |               else {
 | 
|---|
| 443 |                 sumw += h2w_.Add(kx0+x, ky0, w, fgfh);
 | 
|---|
| 444 |                 sumw += h2w_.Add(kx0-x, ky0, w, fgfh);
 | 
|---|
| 445 |                 if (j!=i) {
 | 
|---|
| 446 |                   sumw += h2w_.Add(-kx0+x, -ky0, w, fgfh);
 | 
|---|
| 447 |                   sumw += h2w_.Add(-kx0-x, -ky0, w, fgfh);
 | 
|---|
| 448 |                 }               
 | 
|---|
| 449 |               }
 | 
|---|
| 450 |             }
 | 
|---|
| 451 |             //   
 | 
|---|
| 452 |           }
 | 
|---|
| 453 |         }
 | 
|---|
| 454 |     //    if (i%10==0) 
 | 
|---|
| 455 |     //      cout << " MultiDish::CumulResp() done i=" << i << " / imax=" << dishes_.size() 
 | 
|---|
| 456 |     //     << " theta=" << theta << " phi=" << phi << endl;
 | 
|---|
| 457 |     }
 | 
|---|
| 458 |   }
 | 
|---|
| 459 |   return sumw;
 | 
|---|
| 460 | }
 | 
|---|
| 461 | 
 | 
|---|