Commit ffd03f26 authored by cortes_c's avatar cortes_c
Browse files

getting rid of the bug which caused a discrepancy between OPAL Single mode...

getting rid of the bug which caused a discrepancy between OPAL Single mode tracking and Closed Orbit Finder
parent 619e4aef
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
* *
* @author Matthias Frey * @author Matthias Frey
* @version 1.0 * @version 1.0
* @version 1.1
* Added rotate(), for the case where theta != 0
* Fixed bugg in getOrbit()
*/ */
#ifndef CLOSEDORBITFINDER_H #ifndef CLOSEDORBITFINDER_H
...@@ -74,13 +77,13 @@ class ClosedOrbitFinder ...@@ -74,13 +77,13 @@ class ClosedOrbitFinder
bool domain = true); bool domain = true);
/// Returns the inverse bending radius (size of container N+1) /// Returns the inverse bending radius (size of container N+1)
container_type& getInverseBendingRadius(); container_type& getInverseBendingRadius(value_type angle = 0);
/// Returns the step lengths of the path (size of container N+1) /// Returns the step lengths of the path (size of container N+1)
container_type& getPathLength(); container_type& getPathLength(value_type angle = 0);
/// Returns the field index (size of container N+1) /// Returns the field index (size of container N+1)
container_type& getFieldIndex(); container_type& getFieldIndex(value_type angle = 0);
/// Returns the radial and vertical tunes (in that order) /// Returns the radial and vertical tunes (in that order)
std::pair<value_type,value_type> getTunes(); std::pair<value_type,value_type> getTunes();
...@@ -137,6 +140,9 @@ class ClosedOrbitFinder ...@@ -137,6 +140,9 @@ class ClosedOrbitFinder
/// This function computes nzcross_ which is used to compute the tune in z-direction and the frequency error /// This function computes nzcross_ which is used to compute the tune in z-direction and the frequency error
void computeVerticalOscillations(); void computeVerticalOscillations();
/// This function rotates the calculated closed orbit finder properties to the initial angle
container_type rotate(value_type angle, container_type& orbitProperty);
/// Stores current position in horizontal direction for the solutions of the ODE with different initial values /// Stores current position in horizontal direction for the solutions of the ODE with different initial values
std::array<value_type,2> x_m; // x_m = [x1, x2] std::array<value_type,2> x_m; // x_m = [x1, x2]
...@@ -268,7 +274,6 @@ ClosedOrbitFinder<Value_type, ...@@ -268,7 +274,6 @@ ClosedOrbitFinder<Value_type,
lastOrbitVal_m(0.0), lastMomentumVal_m(0.0), lastOrbitVal_m(0.0), lastMomentumVal_m(0.0),
vertOscDone_m(false), domain_m(domain), stepper_m(), rguess_m(rguess), bField_m(fmapfn, nSector) vertOscDone_m(false), domain_m(domain), stepper_m(), rguess_m(rguess), bField_m(fmapfn, nSector)
{ {
if ( Emin_m > Emax_m ) if ( Emin_m > Emax_m )
throw OpalException("ClosedOrbitFinder::ClosedOrbitFinder()", throw OpalException("ClosedOrbitFinder::ClosedOrbitFinder()",
"Incorrect cyclotron energy (MeV) bounds: Maximum cyclotron energy smaller than minimum cyclotron energy."); "Incorrect cyclotron energy (MeV) bounds: Maximum cyclotron energy smaller than minimum cyclotron energy.");
...@@ -285,9 +290,7 @@ ClosedOrbitFinder<Value_type, ...@@ -285,9 +290,7 @@ ClosedOrbitFinder<Value_type,
throw OpalException("ClosedOrbitFinder::ClosedOrbitFinder()", "Relativistic factor equal zero."); throw OpalException("ClosedOrbitFinder::ClosedOrbitFinder()", "Relativistic factor equal zero.");
// if domain_m = true --> integrate over a single sector // if domain_m = true --> integrate over a single sector
if (domain_m) { if (domain_m) N_m /= nSector_m;
N_m /= nSector_m;
}
// reserve storage for the orbit and momentum (--> size = 0, capacity = N_m+1) // reserve storage for the orbit and momentum (--> size = 0, capacity = N_m+1)
/* /*
...@@ -314,22 +317,25 @@ ClosedOrbitFinder<Value_type, ...@@ -314,22 +317,25 @@ ClosedOrbitFinder<Value_type,
template<typename Value_type, typename Size_type, class Stepper> template<typename Value_type, typename Size_type, class Stepper>
inline typename ClosedOrbitFinder<Value_type, Size_type, Stepper>::container_type& inline typename ClosedOrbitFinder<Value_type, Size_type, Stepper>::container_type&
ClosedOrbitFinder<Value_type, Size_type, Stepper>::getInverseBendingRadius() ClosedOrbitFinder<Value_type, Size_type, Stepper>::getInverseBendingRadius(value_type angle)
{ {
if (angle != 0.0) h_m = rotate(angle, h_m);
return h_m; return h_m;
} }
template<typename Value_type, typename Size_type, class Stepper> template<typename Value_type, typename Size_type, class Stepper>
inline typename ClosedOrbitFinder<Value_type, Size_type, Stepper>::container_type& inline typename ClosedOrbitFinder<Value_type, Size_type, Stepper>::container_type&
ClosedOrbitFinder<Value_type, Size_type, Stepper>::getPathLength() ClosedOrbitFinder<Value_type, Size_type, Stepper>::getPathLength(value_type angle)
{ {
if (angle != 0.0) ds_m = rotate(angle, ds_m);
return ds_m; return ds_m;
} }
template<typename Value_type, typename Size_type, class Stepper> template<typename Value_type, typename Size_type, class Stepper>
inline typename ClosedOrbitFinder<Value_type, Size_type, Stepper>::container_type& inline typename ClosedOrbitFinder<Value_type, Size_type, Stepper>::container_type&
ClosedOrbitFinder<Value_type, Size_type, Stepper>::getFieldIndex() ClosedOrbitFinder<Value_type, Size_type, Stepper>::getFieldIndex(value_type angle)
{ {
if (angle != 0.0) fidx_m = rotate(angle, fidx_m);
return fidx_m; return fidx_m;
} }
...@@ -352,23 +358,8 @@ template<typename Value_type, typename Size_type, class Stepper> ...@@ -352,23 +358,8 @@ template<typename Value_type, typename Size_type, class Stepper>
inline typename ClosedOrbitFinder<Value_type, Size_type, Stepper>::container_type inline typename ClosedOrbitFinder<Value_type, Size_type, Stepper>::container_type
ClosedOrbitFinder<Value_type, Size_type, Stepper>::getOrbit(value_type angle) ClosedOrbitFinder<Value_type, Size_type, Stepper>::getOrbit(value_type angle)
{ {
container_type r = r_m; if (angle != 0.0) r_m = rotate(angle, r_m);
return r_m;
if (angle != 0.0) {
// compute the number of steps per degree
value_type deg_step = N_m / 360.0;
// compute starting point
size_type start = deg_step * angle;
// copy end to start
std::copy(r_m.begin() + start, r_m.end(), r.begin());
// copy start to end
std::copy_n(r_m.begin(), start, r.end() - start);
}
return r;
} }
template<typename Value_type, typename Size_type, class Stepper> template<typename Value_type, typename Size_type, class Stepper>
...@@ -377,19 +368,8 @@ inline typename ClosedOrbitFinder<Value_type, Size_type, Stepper>::container_typ ...@@ -377,19 +368,8 @@ inline typename ClosedOrbitFinder<Value_type, Size_type, Stepper>::container_typ
{ {
container_type pr = pr_m; container_type pr = pr_m;
if (angle != 0.0) { if (angle != 0.0) pr = rotate(angle, pr_m);
// compute the number of steps per degree
value_type deg_step = N_m / 360.0;
// compute starting point
size_type start = deg_step * angle;
// copy end to start
std::copy(pr_m.begin() + start, pr_m.end(), pr.begin());
// copy start to end
std::copy_n(pr_m.begin(), start, pr.end() - start);
}
// change units from meters to \beta * \gamma // change units from meters to \beta * \gamma
/* in Gordon paper: /* in Gordon paper:
* *
...@@ -407,10 +387,9 @@ inline typename ClosedOrbitFinder<Value_type, Size_type, Stepper>::container_typ ...@@ -407,10 +387,9 @@ inline typename ClosedOrbitFinder<Value_type, Size_type, Stepper>::container_typ
* *
* The momentum in \beta * \gamma is obtained by dividing by "a" * The momentum in \beta * \gamma is obtained by dividing by "a"
*/ */
value_type factor = 1.0 / acon_m(wo_m);
std::for_each(pr.begin(), pr.end(), [factor](value_type p) { return p * factor; }); value_type factor = 1.0 / acon_m(wo_m);
std::for_each(pr.begin(), pr.end(), [factor](value_type& p) { p *= factor; });
return pr; return pr;
} }
...@@ -433,7 +412,7 @@ template<typename Value_type, typename Size_type, class Stepper> ...@@ -433,7 +412,7 @@ template<typename Value_type, typename Size_type, class Stepper>
typename ClosedOrbitFinder<Value_type, Size_type, Stepper>::value_type typename ClosedOrbitFinder<Value_type, Size_type, Stepper>::value_type
ClosedOrbitFinder<Value_type, Size_type, Stepper>::getFrequencyError() ClosedOrbitFinder<Value_type, Size_type, Stepper>::getFrequencyError()
{ {
// if the vertical oscillations aren't computed, we have to, since there we also compuote the frequency error. // if the vertical oscillations aren't computed, we have to, since there we also compute the frequency error.
if(!vertOscDone_m) if(!vertOscDone_m)
computeVerticalOscillations(); computeVerticalOscillations();
...@@ -467,7 +446,7 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc ...@@ -467,7 +446,7 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc
// store acon and bcon locally // store acon and bcon locally
value_type acon = acon_m(wo_m); // [acon] = m value_type acon = acon_m(wo_m); // [acon] = m
value_type invbcon = 1.0 / bcon_m(E0_m, wo_m); // [bcon] = MeV*s/(C*m^2) = 10^6 T = 10^7 kG (kilo Gauss) value_type invbcon = 1.0 / bcon_m(E0_m, wo_m); // [bcon] = MeV*s/(C*m^2) = 10^6 T = 10^7 kG (kilo Gauss)
// helper constants // helper constants
value_type p2; // p^2 = p*p value_type p2; // p^2 = p*p
value_type pr2; // squared radial momentum (pr^2 = pr*pr) value_type pr2; // squared radial momentum (pr^2 = pr*pr)
...@@ -492,20 +471,19 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc ...@@ -492,20 +471,19 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc
// define the six ODEs (using lambda function) // define the six ODEs (using lambda function)
std::function<void(const state_type&, state_type&, const double)> orbit_integration = [&](const state_type &y, std::function<void(const state_type&, state_type&, const double)> orbit_integration = [&](const state_type &y,
state_type &dydt, state_type &dydt,
const double theta) const double theta)
{ {
pr2 = y[1] * y[1]; pr2 = y[1] * y[1];
if (p2 < pr2) if (p2 < pr2)
throw OpalException("ClosedOrbitFinder::findOrbit()", "p_{r}^2 > p^{2} (defined in Gordon paper) --> Square root of negative number."); throw OpalException("ClosedOrbitFinder::findOrbit()", "p_{r}^2 > p^{2} (defined in Gordon paper) --> Square root of negative number.");
// Gordon, formula (5c) // Gordon, formula (5c)
ptheta = std::sqrt(p2 - pr2); ptheta = std::sqrt(p2 - pr2);
invptheta = 1.0 / ptheta; invptheta = 1.0 / ptheta;
// interpolate values of magnetic field // interpolate values of magnetic field
bField_m.interpolate(bint, brint, btint, y[0], theta * 180.0 / Physics::pi); bField_m.interpolate(bint, brint, btint, y[0], theta /* * 180.0 / Physics::pi*/);
bint *= invbcon; bint *= invbcon;
brint *= invbcon; brint *= invbcon;
...@@ -514,7 +492,7 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc ...@@ -514,7 +492,7 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc
// Gordon, formula (5b) // Gordon, formula (5b)
dydt[1] = ptheta - y[0] * bint; dydt[1] = ptheta - y[0] * bint;
// Gordon, formulas (9a) and (9b) // Gordon, formulas (9a) and (9b)
for (size_type i = 2; i < 5; i += 2) { for (size_type i = 2; i < 6; i += 2) {
dydt[i] = (y[1] * y[i] + y[0] * p2 * y[i+1] * invptheta * invptheta) * invptheta; dydt[i] = (y[1] * y[i] + y[0] * p2 * y[i+1] * invptheta * invptheta) * invptheta;
dydt[i+1] = - y[1] * y[i+1] * invptheta - (bint + y[0] * brint) * y[i]; dydt[i+1] = - y[1] * y[i+1] * invptheta - (bint + y[0] * brint) * y[i];
} }
...@@ -522,7 +500,6 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc ...@@ -522,7 +500,6 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc
// define initial state container for integration: y = {r, pr, x1, px1, x2, px2} // define initial state container for integration: y = {r, pr, x1, px1, x2, px2}
state_type y(6); state_type y(6);
// difference of last and first value of r (1. element) and pr (2. element) // difference of last and first value of r (1. element) and pr (2. element)
container_type err(2); container_type err(2);
// correction term for initial values: r = r + dr, pr = pr + dpr; Gordon, formula (17) // correction term for initial values: r = r + dr, pr = pr + dpr; Gordon, formula (17)
...@@ -570,7 +547,7 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc ...@@ -570,7 +547,7 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc
// set initial values for radius and radial momentum for lowest energy Emin // set initial values for radius and radial momentum for lowest energy Emin
// orbit, [r] = m; Gordon, formula (20) // orbit, [r] = m; Gordon, formula (20)
// radial momentum; Gordon, formula (20) // radial momentum; Gordon, formula (20)
container_type init; container_type init;
if (rguess_m < 0) if (rguess_m < 0)
init = {beta * acon, 0.0}; init = {beta * acon, 0.0};
...@@ -595,13 +572,13 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc ...@@ -595,13 +572,13 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc
px_m[1] = 1.0; // px2; Gordon, formula (10) px_m[1] = 1.0; // px2; Gordon, formula (10)
nxcross_m = 0; // counts the number of crossings of x-axis (excluding first step) nxcross_m = 0; // counts the number of crossings of x-axis (excluding first step)
idx = 0; // index for looping over r and pr arrays idx = 0; // index for looping over r and pr arrays
//real_theta = 0.0;
// fill container with initial states // fill container with initial states
y = {init[0],init[1], x_m[0], px_m[0], x_m[1], px_m[1]}; y = {init[0],init[1], x_m[0], px_m[0], x_m[1], px_m[1]};
// integrate from 0 to 2*pi (one has to get back to the "origin") // integrate from 0 to 2*pi (one has to get back to the "origin")
boost::numeric::odeint::integrate_n_steps(stepper_m,orbit_integration,y,0.0,dtheta_m,N_m,store); boost::numeric::odeint::integrate_n_steps(stepper_m,orbit_integration,y,0.0,dtheta_m,N_m,store);
// write new state // write new state
x_m[0] = y[2]; x_m[0] = y[2];
px_m[0] = y[3]; px_m[0] = y[3];
...@@ -624,7 +601,8 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc ...@@ -624,7 +601,8 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc
// compute amplitude of the error // compute amplitude of the error
error = std::sqrt(delta[0] * delta[0] + delta[1] * delta[1] * invgamma4) / r_m[0]; error = std::sqrt(delta[0] * delta[0] + delta[1] * delta[1] * invgamma4) / r_m[0];
} while (error > accuracy && niterations++ < maxit);
} while (error > accuracy && niterations++ < maxit);
// reset iteration counter // reset iteration counter
niterations = 0; niterations = 0;
...@@ -662,7 +640,27 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc ...@@ -662,7 +640,27 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc
// returns true if converged, otherwise false // returns true if converged, otherwise false
return error < accuracy; return error < accuracy;
} }
template<typename Value_type, typename Size_type, class Stepper>
inline typename ClosedOrbitFinder<Value_type, Size_type, Stepper>::container_type
ClosedOrbitFinder<Value_type, Size_type, Stepper>::rotate(value_type angle, container_type &orbitProperty){
container_type orbitPropertyCopy = orbitProperty;
// compute the number of steps per degree
value_type deg_step = N_m / 360.0;
// compute starting point
size_type start = deg_step * angle;
// copy end to start
std::copy(orbitProperty.begin() + start, orbitProperty.end(), orbitPropertyCopy.begin());
// copy start to end
std::copy_n(orbitProperty.begin(), start, orbitPropertyCopy.end() - start);
return orbitPropertyCopy;
}
template<typename Value_type, typename Size_type, class Stepper> template<typename Value_type, typename Size_type, class Stepper>
Value_type ClosedOrbitFinder<Value_type, Size_type, Stepper>::computeTune(const std::array<value_type,2>& y, Value_type ClosedOrbitFinder<Value_type, Size_type, Stepper>::computeTune(const std::array<value_type,2>& y,
value_type py2, size_type ncross) value_type py2, size_type ncross)
...@@ -743,10 +741,11 @@ void ClosedOrbitFinder<Value_type, Size_type, Stepper>::computeOrbitProperties() ...@@ -743,10 +741,11 @@ void ClosedOrbitFinder<Value_type, Size_type, Stepper>::computeOrbitProperties()
h_m.resize(N_m); h_m.resize(N_m);
fidx_m.resize(N_m); fidx_m.resize(N_m);
ds_m.resize(N_m); ds_m.resize(N_m);
for (size_type i = 0; i < N_m; ++i) { for (size_type i = 0; i < N_m; ++i) {
// interpolate magnetic field // interpolate magnetic field
bField_m.interpolate(bint, brint, btint, r_m[i], theta * 180.0 / Physics::pi); bField_m.interpolate(bint, brint, btint, r_m[i], theta);
bint *= invbcon; bint *= invbcon;
brint *= invbcon; brint *= invbcon;
btint *= invbcon; btint *= invbcon;
...@@ -764,7 +763,6 @@ void ClosedOrbitFinder<Value_type, Size_type, Stepper>::computeOrbitProperties() ...@@ -764,7 +763,6 @@ void ClosedOrbitFinder<Value_type, Size_type, Stepper>::computeOrbitProperties()
// increase angle // increase angle
theta += dtheta_m; theta += dtheta_m;
} }
// compute average radius // compute average radius
ravg_m = std::accumulate(r_m.begin(),r_m.end(),0.0) / value_type(r_m.size()); ravg_m = std::accumulate(r_m.begin(),r_m.end(),0.0) / value_type(r_m.size());
} }
...@@ -804,7 +802,7 @@ void ClosedOrbitFinder<Value_type, Size_type, Stepper>::computeVerticalOscillati ...@@ -804,7 +802,7 @@ void ClosedOrbitFinder<Value_type, Size_type, Stepper>::computeVerticalOscillati
invptheta = 1.0 / ptheta; invptheta = 1.0 / ptheta;
// intepolate values of magnetic field // intepolate values of magnetic field
bField_m.interpolate(bint, brint, btint, y[0], theta * 180.0 / Physics::pi); bField_m.interpolate(bint, brint, btint, y[0], theta);
bint *= invbcon; bint *= invbcon;
brint *= invbcon; brint *= invbcon;
......
...@@ -1301,7 +1301,7 @@ void Distribution::createMatchedGaussDistribution(size_t numberOfParticles, doub ...@@ -1301,7 +1301,7 @@ void Distribution::createMatchedGaussDistribution(size_t numberOfParticles, doub
<< " PHIINIT= " << CyclotronElement->getPHIinit() << endl; << " PHIINIT= " << CyclotronElement->getPHIinit() << endl;
*gmsg << "* ----------------------------------------------------" << endl; *gmsg << "* ----------------------------------------------------" << endl;
const double wo = CyclotronElement->getRfFrequ()*1E6/CyclotronElement->getCyclHarm()*2.0*Physics::pi; const double wo = CyclotronElement->getRfFrequ()*1E6*2.0*Physics::pi/CyclotronElement->getCyclHarm();
const double fmLowE = CyclotronElement->getFMLowE(); const double fmLowE = CyclotronElement->getFMLowE();
const double fmHighE = CyclotronElement->getFMHighE(); const double fmHighE = CyclotronElement->getFMHighE();
...@@ -1312,7 +1312,7 @@ void Distribution::createMatchedGaussDistribution(size_t numberOfParticles, doub ...@@ -1312,7 +1312,7 @@ void Distribution::createMatchedGaussDistribution(size_t numberOfParticles, doub
"'CYCLOTRON' definition."); "'CYCLOTRON' definition.");
} }
int Nint = 1440; int Nint = 1440*2;
double scaleFactor = 1.0; double scaleFactor = 1.0;
bool writeMap = true; bool writeMap = true;
......
...@@ -50,7 +50,7 @@ void MagneticField::interpolate(double& bint, ...@@ -50,7 +50,7 @@ void MagneticField::interpolate(double& bint,
// x horizontal // x horizontal
// y longitudinal // y longitudinal
// z is vertical // z is vertical
const double xir = (rad - BP.rmin) / (BP.delr); const double xir = (rad - BP.rmin) / BP.delr;
// ir : the number of path whose radius is less than the 4 points of cell which surround the particle. // ir : the number of path whose radius is less than the 4 points of cell which surround the particle.
const int ir = (int)xir; const int ir = (int)xir;
...@@ -59,21 +59,19 @@ void MagneticField::interpolate(double& bint, ...@@ -59,21 +59,19 @@ void MagneticField::interpolate(double& bint,
const double wr1 = xir - (double)ir; const double wr1 = xir - (double)ir;
// wr2 : the relative distance to the outer path radius // wr2 : the relative distance to the outer path radius
const double wr2 = 1.0 - wr1; const double wr2 = 1.0 - wr1;
double tet_rad = theta;
// the actual angle of particle // the actual angle of particle
// tet_rad = theta / Physics::pi * 180.0; double tet = theta / Physics::pi * 180.0;
// the corresponding angle on the field map // the corresponding angle on the field map
// Note: this does not work if the start point of field map does not equal zero. // Note: this does not work if the start point of field map does not equal zero.
double tet_map = fmod(tet_rad, 360.0 / this->getSymmetry()); double tet_map = fmod(tet, 360.0 / this->getSymmetry());
double xit = tet_map / BP.dtet; double xit = tet_map / BP.dtet;
int it = (int) xit; int it = (int) xit;
const double wt1 = xit - (double)it; const double wt1 = xit - (double)it;
const double wt2 = 1.0 - wt1; const double wt2 = 1.0 - wt1;
...@@ -82,30 +80,30 @@ void MagneticField::interpolate(double& bint, ...@@ -82,30 +80,30 @@ void MagneticField::interpolate(double& bint,
it = it + 1; it = it + 1;
int r1t1, r2t1, r1t2, r2t2; int r1t1, r2t1, r1t2, r2t2;
// int ntetS = Bfield.ntet + 1; int ntetS = Bfield.ntet + 1;
// r1t1 : the index of the "min angle, min radius" point in the 2D field array. // r1t1 : the index of the "min angle, min radius" point in the 2D field array.
// considering the array start with index of zero, minus 1. // considering the array start with index of zero, minus 1.
// if(myBFieldType_m != FFAGBF) { if(1) {
/* /*
For FFAG this does not work For FFAG this does not work
*/ */
// r1t1 = it + ntetS * ir - 1; r1t1 = it + ntetS * ir - 1;
// r1t2 = r1t1 + 1; r1t2 = r1t1 + 1;
// r2t1 = r1t1 + ntetS; r2t1 = r1t1 + ntetS;
// r2t2 = r2t1 + 1 ; r2t2 = r2t1 + 1 ;
// } else { } else {
// /* /*
// With this we have B-field AND this is far more With this we have B-field AND this is far more
// intuitive for me .... intuitive for me ....
// */ */
r1t1 = idx(ir, it); r1t1 = idx(ir, it);
r2t1 = idx(ir + 1, it); r2t1 = idx(ir + 1, it);
r1t2 = idx(ir, it + 1); r1t2 = idx(ir, it + 1);
r2t2 = idx(ir + 1, it + 1); r2t2 = idx(ir + 1, it + 1);
// } }
bint = 0.0; bint = 0.0;
brint = 0.0; brint = 0.0;
...@@ -115,21 +113,22 @@ void MagneticField::interpolate(double& bint, ...@@ -115,21 +113,22 @@ void MagneticField::interpolate(double& bint,
// dB_{z}/dr // dB_{z}/dr
brint = (Bfield.dbr[r1t1] * wr2 * wt2 + brint = (Bfield.dbr[r1t1] * wr2 * wt2 +
Bfield.dbr[r2t1] * wr1 * wt2 + Bfield.dbr[r2t1] * wr1 * wt2 +
Bfield.dbr[r1t2] * wr2 * wt1 + Bfield.dbr[r1t2] * wr2 * wt1 +
Bfield.dbr[r2t2] * wr1 * wt1); Bfield.dbr[r2t2] * wr1 * wt1);
// dB_{z}/dtheta // dB_{z}/dtheta
btint = Bfield.dbt[r1t1] * wr2 * wt2 + btint = (Bfield.dbt[r1t1] * wr2 * wt2 +
Bfield.dbt[r2t1] * wr1 * wt2 + Bfield.dbt[r2t1] * wr1 * wt2 +
Bfield.dbt[r1t2] * wr2 * wt1 + Bfield.dbt[r1t2] * wr2 * wt1 +
Bfield.dbt[r2t2] * wr1 * wt1; Bfield.dbt[r2t2] * wr1 * wt1);
// B_{z} // B_{z}
bint = Bfield.bfld[r1t1] * wr2 * wt2 + bint = (Bfield.bfld[r1t1] * wr2 * wt2 +
Bfield.bfld[r2t1] * wr1 * wt2 + Bfield.bfld[r2t1] * wr1 * wt2 +
Bfield.bfld[r1t2] * wr2 * wt1 + Bfield.bfld[r1t2] * wr2 * wt1 +
Bfield.bfld[r2t2] * wr1 * wt1; Bfield.bfld[r2t2] * wr1 * wt1);
//bint *= -1.0;
} }
} }
...@@ -159,4 +158,4 @@ const BGeometryBase &MagneticField::getGeometry() const { ...@@ -159,4 +158,4 @@ const BGeometryBase &MagneticField::getGeometry() const {
BGeometryBase &MagneticField::getGeometry() { BGeometryBase &MagneticField::getGeometry() {
return nullGeom_m; return nullGeom_m;
} }
\ No newline at end of file
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include <gsl/gsl_eigen.h> #include <gsl/gsl_eigen.h>
#include <boost/numeric/odeint/stepper/runge_kutta4.hpp> #include <boost/numeric/odeint/stepper/runge_kutta4.hpp>