#include "OpticsModel.hh" const double OpticsModel::_fieldTolerance=1e-9; double OpticsModel::GetKquad(PhaseSpaceVector referenceParticle) const { // k = 1e3 sqrt(q[e] dB/dx[T/m] / pz [eV/c] // minimum quad aperture 0.1 mm! double x = 0.1; double B[6] = {0,0,0,0,0,0}; double point[4] = {x,0,referenceParticle.z(),0}; _theField->GetFieldValue(point, B); double dBdx = B[1]*CLHEP::tesla/point[0]*CLHEP::meter; //dBy/dx double p = referenceParticle.P()/CLHEP::electronvolt; double k = 1e3 * sqrt( fabs(CLHEP::eplus * dBdx / p) ); return k; } double OpticsModel::GetKrf_t(PhaseSpaceVector referenceParticle) const { SetFields(referenceParticle); double Ez = referenceParticle.Ez(); double omega = 2*CLHEP::pi*_data->opticsRfFrequency(); double phi0 = _data->rfAccelerationPhase(); double k = 0.003405; //mm^-1 return Ez*sin(phi0)*k*k/(4*omega);//Natural unit for omega is GHz } double OpticsModel::GetKrf_l(PhaseSpaceVector referenceParticle) const { SetFields(referenceParticle); double Ez = referenceParticle.Ez(); double omega = 2*CLHEP::pi*_data->opticsRfFrequency(); double phi0 = _data->rfAccelerationPhase(); return omega*Ez*sin(phi0);//Natural unit is GHz } double OpticsModel::GetBz(PhaseSpaceVector referenceParticle) const { double point[4] = {0,0,referenceParticle.z(),0}; double bfield[6] = {0,0,0,0,0,0}; _theField->GetFieldValue(point, bfield); return bfield[2]; } double OpticsModel::GetB0(PhaseSpaceVector referenceParticle) const { //compare with solenoid kappa = (0.15*1e3*Bz/p)^2 = (eplus*Bz/2*p)^2 double B0 = CLHEP::c_light*GetBz(referenceParticle)*CLHEP::eplus; return B0; } double OpticsModel::GetdEdz(PhaseSpaceVector referenceParticle) const { SetFields(referenceParticle); double RFEGain = referenceParticle.Ez()*CLHEP::eplus; return RFEGain; } void OpticsModel::SetFields(PhaseSpaceVector& referenceParticle) const { double point[4] = {referenceParticle.x(), referenceParticle.y(), referenceParticle.z(), referenceParticle.t()}; double field[6] = {0,0,0,0,0,0}; _theField->GetFieldValue(point, field); Hep3Vector b(field[0], field[1], field[2]); Hep3Vector e(field[3], field[4], field[5]); HepLorentzVector A(_theField->GetVectorPotential(referenceParticle.fourPosition())); referenceParticle.setB(b); referenceParticle.setE(e); referenceParticle.setFourPotential(A); } CLHEP::Hep3Vector OpticsModel::GetBField(CLHEP::HepLorentzVector position) const { double pos[4] = {position.x(), position.y(), position.z(), position.t()}; double field[6] = {0,0,0,0,0,0}; _theField->GetFieldValue(pos, field); return Hep3Vector(field[0], field[1], field[2]); } CLHEP::Hep3Vector OpticsModel::GetEField(CLHEP::HepLorentzVector position) const { double pos[4] = {position.x(), position.y(), position.z(), position.t()}; double field[6] = {0,0,0,0,0,0}; _theField->GetFieldValue(pos, field); return Hep3Vector(field[3], field[4], field[5]); } double* OpticsModel::NewFourierDecomposition(int power, double zStart, double zEnd) const { int nPoints = 1; for(int i=0; i OpticsModel::MomentumOfStopBands(int power, double zStart, double zEnd, int nMax) const { std::vector theStopBands; double* FourierTransform = NewFourierDecomposition(power, zStart, zEnd); double MeanSquareBz = GetMeanSquareBz(power, zStart, zEnd); double length = zEnd - zStart; for(int n = 0; n