Bunch::Approx Class Reference

List of all members.


Detailed Description

class Approx does a 3-d histogram of the charge to generate an approximation for PoissonConvolve3D. Within each bin (voxel) it use the mean position and the total charge.

Public Member Functions

 Approx (int _nx, int _ny, int _nz)
void reset (Bunch *b)
void putCharge (double x, double y, double z, double c)
void computeApprox ()
void reduce ()
std::vector< ChargegetVector () const

Private Member Functions

int index (int ix, int iy, int iz)

Private Attributes

int nx
int ny
int nz
double totalC
double dx
double dy
double dz
double xMin
double yMin
double zMin
double * xx
double * yy
double * zz
double * cc
std::vector< Chargev

Constructor & Destructor Documentation

Bunch::Approx::Approx ( int  _nx,
int  _ny,
int  _nz 
) [inline]

References cc, nx, ny, nz, xx, yy, and zz.

00097                                                   : v() 
00098                 {       nx=_nx; ny=_ny; nz=_nz;
00099                         xx = new double[nx*ny*nz];
00100                         yy = new double[nx*ny*nz];
00101                         zz = new double[nx*ny*nz];
00102                         cc = new double[nx*ny*nz];
00103                 }


Member Function Documentation

int Bunch::Approx::index ( int  ix,
int  iy,
int  iz 
) [inline, private]

References nx, and ny.

Referenced by computeApprox(), putCharge(), and reduce().

00094                         { return ix+nx*(iy+ny*iz); }

void Bunch::Approx::reset ( Bunch b  )  [inline]

References Bunch::bound_x, Bunch::bound_y, Bunch::bound_z, cc, dx, dy, dz, nx, ny, nz, totalC, v, xMin, xx, yMin, yy, zMin, and zz.

Referenced by Bunch::Bunch(), and Bunch::computeField().

00104                                      {
00105                         totalC = 0.0;
00106                         dx = b->bound_x*2.0/nx; xMin = -b->bound_x;
00107                         dy = b->bound_y*2.0/ny; yMin = -b->bound_y;
00108                         dz = b->bound_z*2.0/nz; zMin = -b->bound_z;
00109                         int nBins3 = nx*ny*nz;
00110                         for(int i=0; i<nBins3; ++i)
00111                                 xx[i] = yy[i] = zz[i] = cc[i] = 0.0;
00112                         v.clear();
00113                 }

void Bunch::Approx::putCharge ( double  x,
double  y,
double  z,
double  c 
)

References cc, dx, dy, dz, index(), nx, ny, nz, totalC, xMin, xx, yMin, yy, zMin, and zz.

Referenced by Bunch::computeField().

01030 {
01031         // (Must add all charge somewhere, as it was put into the grid.)
01032         int ix=(int)floor((x-xMin)/dx);
01033         if(ix < 0 || ix >= nx) ix = nx/2;
01034         int iy=(int)floor((y-yMin)/dy);
01035         if(iy < 0 || iy >= ny) iy = ny/2;
01036         int iz=(int)floor((z-zMin)/dz);
01037         if(iz < 0 || iz >= nz) iz = nz/2;
01038         int i=index(ix,iy,iz);
01039         xx[i] += c*x;
01040         yy[i] += c*y;
01041         zz[i] += c*z;
01042         cc[i] += c;
01043         totalC += fabs(c);
01044 }

void Bunch::Approx::computeApprox (  ) 

References cc, index(), nx, ny, nz, reduce(), v, xx, yy, and zz.

Referenced by Bunch::computeField().

01047 {
01048         reduce();
01049         v.clear();
01050         for(int ix=0; ix<nx; ++ix) {
01051                 for(int iy=0; iy<ny; ++iy) {
01052                         for(int iz=0; iz<nz; ++iz) {
01053                                 int i=index(ix,iy,iz);
01054                                 if(cc[i] == 0.0) continue;
01055                                 v.push_back(Charge(xx[i]/cc[i], yy[i]/cc[i],
01056                                                         zz[i]/cc[i],cc[i]));
01057                         }
01058                 }
01059         }
01060 }

void Bunch::Approx::reduce (  ) 

References cc, index(), nx, ny, nz, totalC, xx, yy, and zz.

Referenced by computeApprox().

01063 {
01064         // This routine finds bins in the 3-d histogram that contain less than
01065         // minFrac of the total charge, and moves their charge 1 bin towards
01066         // the center. This reduces the number of charges in the approximation.
01067         // For tests with gaussian beams and nx=ny=nz=9, the reduction was from
01068         // 124 to 26.
01069         const double minFrac=0.02;
01070 
01071         // ix<nx/2 region
01072         for(int ix=0; ix<nx/2; ++ix) {
01073                 for(int iy=0; iy<ny; ++iy) {
01074                         for(int iz=0; iz<nz; ++iz) {
01075                                 int i=index(ix,iy,iz);
01076                                 if(cc[i] == 0.0) continue;
01077                                 if(fabs(cc[i]) < totalC*minFrac) {
01078                                         int j=index(ix+1,iy,iz);
01079                                         xx[j] += xx[i];
01080                                         yy[j] += yy[i];
01081                                         zz[j] += zz[i];
01082                                         cc[j] += cc[i];
01083                                         xx[i] = yy[i] = zz[i] = cc[i] = 0.0;
01084                                 }
01085                         }
01086                 }
01087         }
01088 
01089         // ix>nx/2 region
01090         for(int ix=nx/2+1; ix<nx; ++ix) {
01091                 for(int iy=0; iy<ny; ++iy) {
01092                         for(int iz=0; iz<nz; ++iz) {
01093                                 int i=index(ix,iy,iz);
01094                                 if(cc[i] == 0.0) continue;
01095                                 if(fabs(cc[i]) < totalC*minFrac) {
01096                                         int j=index(ix-1,iy,iz);
01097                                         xx[j] += xx[i];
01098                                         yy[j] += yy[i];
01099                                         zz[j] += zz[i];
01100                                         cc[j] += cc[i];
01101                                         xx[i] = yy[i] = zz[i] = cc[i] = 0.0;
01102                                 }
01103                         }
01104                 }
01105         }
01106 
01107         // iy<ny/2 region
01108         for(int iy=0; iy<ny/2; ++iy) {
01109                 for(int ix=0; ix<nx; ++ix) {
01110                         for(int iz=0; iz<nz; ++iz) {
01111                                 int i=index(ix,iy,iz);
01112                                 if(cc[i] == 0.0) continue;
01113                                 if(fabs(cc[i]) < totalC*minFrac) {
01114                                         int j=index(ix,iy+1,iz);
01115                                         xx[j] += xx[i];
01116                                         yy[j] += yy[i];
01117                                         zz[j] += zz[i];
01118                                         cc[j] += cc[i];
01119                                         xx[i] = yy[i] = zz[i] = cc[i] = 0.0;
01120                                 }
01121                         }
01122                 }
01123         }
01124 
01125         // iy>ny/2 region
01126         for(int iy=ny/2+1; iy<ny; ++iy) {
01127                 for(int ix=0; ix<nx; ++ix) {
01128                         for(int iz=0; iz<nz; ++iz) {
01129                                 int i=index(ix,iy,iz);
01130                                 if(cc[i] == 0.0) continue;
01131                                 if(fabs(cc[i]) < totalC*minFrac) {
01132                                         int j=index(ix,iy-1,iz);
01133                                         xx[j] += xx[i];
01134                                         yy[j] += yy[i];
01135                                         zz[j] += zz[i];
01136                                         cc[j] += cc[i];
01137                                         xx[i] = yy[i] = zz[i] = cc[i] = 0.0;
01138                                 }
01139                         }
01140                 }
01141         }
01142 
01143         // iz<nz/2 region
01144         for(int iz=0; iz<nz/2; ++iz) {
01145                 for(int ix=0; ix<nx; ++ix) {
01146                         for(int iy=0; iy<ny; ++iy) {
01147                                 int i=index(ix,iy,iz);
01148                                 if(cc[i] == 0.0) continue;
01149                                 if(fabs(cc[i]) < totalC*minFrac) {
01150                                         int j=index(ix,iy,iz+1);
01151                                         xx[j] += xx[i];
01152                                         yy[j] += yy[i];
01153                                         zz[j] += zz[i];
01154                                         cc[j] += cc[i];
01155                                         xx[i] = yy[i] = zz[i] = cc[i] = 0.0;
01156                                 }
01157                         }
01158                 }
01159         }
01160 
01161         // iz>nz/2 region
01162         for(int iz=nz/2+1; iz<nz; ++iz) {
01163                 for(int ix=0; ix<nx; ++ix) {
01164                         for(int iy=0; iy<ny; ++iy) {
01165                                 int i=index(ix,iy,iz);
01166                                 if(cc[i] == 0.0) continue;
01167                                 if(fabs(cc[i]) < totalC*minFrac) {
01168                                         int j=index(ix,iy,iz-1);
01169                                         xx[j] += xx[i];
01170                                         yy[j] += yy[i];
01171                                         zz[j] += zz[i];
01172                                         cc[j] += cc[i];
01173                                         xx[i] = yy[i] = zz[i] = cc[i] = 0.0;
01174                                 }
01175                         }
01176                 }
01177         }
01178 }

std::vector<Charge> Bunch::Approx::getVector (  )  const [inline]

References v.

Referenced by Bunch::computeField(), and Bunch::getNapprox().

00117 { return v; }


Member Data Documentation

int Bunch::Approx::nx [private]

int Bunch::Approx::ny [private]

int Bunch::Approx::nz [private]

double Bunch::Approx::totalC [private]

Referenced by putCharge(), reduce(), and reset().

double Bunch::Approx::dx [private]

Referenced by putCharge(), and reset().

double Bunch::Approx::dy [private]

Referenced by putCharge(), and reset().

double Bunch::Approx::dz [private]

Referenced by putCharge(), and reset().

double Bunch::Approx::xMin [private]

Referenced by putCharge(), and reset().

double Bunch::Approx::yMin [private]

Referenced by putCharge(), and reset().

double Bunch::Approx::zMin [private]

Referenced by putCharge(), and reset().

double* Bunch::Approx::xx [private]

double * Bunch::Approx::yy [private]

double * Bunch::Approx::zz [private]

double * Bunch::Approx::cc [private]

std::vector<Charge> Bunch::Approx::v [private]

Referenced by computeApprox(), getVector(), and reset().


The documentation for this class was generated from the following file:
g4beamline