31 #include <boost/math/special_functions/chebyshev.hpp>
49 virtual bool checkHit(
const Vector_t &
R) = 0;
50 virtual double getPressure(
const Vector_t &
R) = 0;
53 explicit BeamStrippingInsideTester(
ElementBase * el) {
56 virtual bool checkHit(
const Vector_t &
R) {
59 double getPressure(
const Vector_t &R) {
60 return bstp_m->checkPressure(
R(0)*0.001,
R(1)*0.001);
88 const gsl_rng_type *
T;
92 unsigned long mySeed = tv.tv_sec + tv.tv_usec;
94 r_m = gsl_rng_alloc (T);
95 gsl_rng_set(
r_m, mySeed);
107 return "BeamStrippingPhysics";
111 const std::pair<Vector_t, double> &boundingSphere,
112 size_t numParticlesInSimulation) {
116 double mass = bunch->
getM()*1E-9;
126 gmsgALL <<
getName() <<
": Unsupported type of particle for residual gas interactions!"<<
endl;
127 gmsgALL <<
getName() <<
"-> Beam Stripping Physics not apply"<<
endl;
157 for (
size_t i = 0; i < bunch->
getLocalNum(); ++i) {
158 if ( (bunch->
Bin[i] != -1) && (tester->
checkHit(bunch->
R[i]))) {
160 bool pdead_GS =
false;
161 bool pdead_LS =
false;
168 beta =
sqrt(1.0 - 1.0 / (gamma * gamma));
169 deltas =
dT_m * beta *
c;
176 B = 0.1 *
sqrt(extB[0]*extB[0] + extB[1]*extB[1] + extB[2]*extB[2]);
177 E = gamma * beta * c * B;
181 if (pdead_GS ==
true || pdead_LS ==
true) {
182 lossDs_m->addParticle(bunch->
R[i]*0.001, bunch->
P[i], bunch->
ID[i],
188 <<
" is deleted by beam stripping" <<
endl;
194 <<
": Total number of particles after beam stripping = "
225 double molecularDensity[3] ={};
234 double CS_total = 0.0;
240 for (
int i = 0; i < 9; ++i)
247 for (
int i = 0; i < 9; ++i)
255 for (
int i = 0; i < 9; ++i)
262 for (
int i = 0; i < 9; ++i)
315 for (
int i = 0; i < 9; ++i)
329 CS_total = CS_a + CS_b + CS_c;
332 NCS_a = CS_a * 1E-4 * molecularDensity[0];
333 NCS_b = CS_b * 1E-4 * molecularDensity[0];
334 NCS_c = CS_c * 1E-4 * molecularDensity[0];
335 NCS_total = CS_total * 1E-4 * molecularDensity[0];
339 else if (
gas_m ==
"AIR") {
341 static const double fMolarFraction[3] = {
352 double NCS_single[3];
353 double NCS_double[3];
355 double NCS_single_all = 0.0;
356 double NCS_double_all = 0.0;
357 double NCS_total_all = 0.0;
359 for (
int i = 0; i < 3; ++i) {
361 molecularDensity[i] = 100 *
pressure_m * fMolarFraction[i] / (
kB *
q_e * temperature);
366 for (
int j = 0; j < 8; ++j)
372 for (
int j = 0; j < 8; ++j)
379 for (
int j = 0; j < 8; ++j)
386 for (
int j = 0; j < 8; ++j)
399 for (
int j = 0; j < 8; ++j)
405 for (
int j = 0; j < 8; ++j)
416 CS_single[i] = {0.0};
417 CS_double[i] = {0.0};
419 CS_total[i] = CS_single[i] + CS_double[i];
421 NCS_single[i] = CS_single[i] * 1E-4 * molecularDensity[i];
422 NCS_double[i] = CS_double[i] * 1E-4 * molecularDensity[i];
423 NCS_all[i] = CS_total[i] * 1E-4 * molecularDensity[i];
425 NCS_single_all += NCS_single[i];
426 NCS_double_all += NCS_double[i];
427 NCS_total_all += NCS_all[i];
429 NCS_a = NCS_single_all;
430 NCS_b = NCS_double_all;
435 "Residual gas not found ...");
443 const double sigma_0 = 1E-16;
449 f1 = sigma_0 *
b_m[i][0] *
pow((E1/E_R),
b_m[i][1]);
450 if(
b_m[i][2] != 0.0 &&
b_m[i][3] != 0.0)
453 sigma = f1 / (1 +
pow((E1/
b_m[i][4]),(
b_m[i][1]+
b_m[i][5])));
459 double a1,
double a2,
double a3,
double a4,
double a5,
double a6) {
461 const double sigma_0 = 1E-16;
467 f1 = sigma_0 * a1 *
pow((E1/(
E_ryd*1e6)),a2);
468 if(a3 != 0.0 && a4 != 0.0)
469 sigma = f1 / (1 +
pow((E1/a3),(a2+a4)) +
pow((E1/a5),(a2+a6)));
471 sigma = f1 / (1 +
pow((E1/a5),(a2+a6)));
480 double aT[8] = {0.0};
481 if(Eng > Emin && Eng < Emax) {
483 for (
int i = 0; i < 8; ++i) {
484 aT[i] = (
a_m[i+1] * boost::math::chebyshev_t(i+1, X));
487 sigma =
exp(0.5*
a_m[0] + sum_aT);
495 double xi = gsl_rng_uniform(
r_m);
505 double xi = gsl_rng_uniform(
r_m);
513 const double eps0 = 0.75419 *
q_e;
515 const double me =
m_e*1E9*q_e/(
c*
c);
516 const double p = 0.0126;
517 const double S0 = 0.783;
519 const double k0 =
sqrt(2 * me * eps0)/hbar;
520 const double N = (
sqrt(2 * k0 * (k0+a) * (2*k0+a)))/a;
521 double zT = eps0 / (q_e * E);
522 tau = (4 * me * zT)/(S0 * N * N * hbar * (1+p)*(1+p) * (1-1/(2*k0*zT))) *
exp(4*k0*zT/3);
523 fL = 1 -
exp( -
dT_m / (gamma * tau));
530 double r = gsl_rng_uniform(
r_m);
534 if (pdead_LS ==
true) {
619 <<
" is transformed to proton" <<
endl;
626 <<
" is transformed to neutral hydrogen" <<
endl;
633 <<
" is transformed to negative hydrogen ion" <<
endl;
640 <<
" is transformed to H3+" <<
endl;
653 bool beamstrippingAlive =
true;
654 return beamstrippingAlive;
665 {7.50E-04, 4.38E+02, 7.28E-01, 8.40E-01, 2.82E-01, 4.10E+01, 1.37E+00, 0.00E+00, 0.00E+00},
666 {-2.00E-04, 3.45E+02, 4.80E-01, 5.30E-02, 8.40E-02, 1.00E+01, 9.67E-01, 0.00E+00, 0.00E+00},
667 {1.70E-3, 2.47E+01, 3.36E-01, 7.00E+01, 5.00E-01, 9.90E+01, 7.80E-01, 0.00E+00, 0.00E+00}
670 {1.40E-02, 1.77E+00, 4.80E-01, 0.00E+00, 0.00E+00, 1.52E+02, 1.52E+00, 0.00E+00, 0.00E+00},
671 {1.30E-02, 1.90E+00, 6.20E-01, 0.00E+00, 0.00E+00, 5.20E+01, 9.93E-01, 0.00E+00, 0.00E+00},
672 {1.50E-02, 1.97E+00, 8.90E-01, 0.00E+00, 0.00E+00, 5.10E+01, 9.37E-01, 0.00E+00, 0.00E+00}
675 {2.00E-03, 1.93E+03, 1.64E+00, 1.98E+00, 6.69E-01, 2.19E+01, 4.15E+00, 3.23E-04, 1.00E+01},
676 {-1.50E-03, 3.86E+05, 1.60E+00, 6.93E-02, 3.28E-01, 7.86E+00, 3.92E+00, 3.20E-04, 1.00E+01},
677 {2.18E-03, 1.61E+04, 2.12E+00, 1.16E+00, 4.44E-01, 1.39E+01, 4.07E+00, 2.99E-04, 1.45E+01}
680 {2.90E-02, 2.90E-01, 1.50E+00, 1.39E+01, 1.65E+00, 3.94E+01, 5.79E+00, 0.00E+00, 0.00E+00},
681 {2.20E-02, 2.64E-01, 1.50E+00, 1.40E+01, 1.70E+00, 4.00E+01, 5.80E+00, 0.00E+00, 0.00E+00},
682 {2.90E-02, 1.40E-01, 1.87E+00, 2.40E+01, 1.60E+00, 3.37E+01, 4.93E+00, 4.50E-01, 2.00E-01}
685 {1.36E-02, 2.59E+03, 1.78E+00, 2.69E-01, -3.52E-01, 5.60E+00, 8.99E-01, 0.00E+00, 0.00E+00},
686 {1.36E-02, 3.29E+03, 1.85E+00, 2.89E-01, -2.72E-01, 8.20E+00, 1.09E+00, 0.00E+00, 0.00E+00},
687 {1.36E-02, 1.16E+12, 7.40E+00, 5.36E-01, -5.42E-01, 1.23E+00, 7.26E-01, 0.00E+00, 0.00E+00}
690 {1.48E-02, 1.15E+00, 1.18E+00, 1.15E+01, 1.19E+00, 3.88E+01, 3.38E+00, 1.00E-01, 2.82E-02},
691 {1.13E-02, 3.26E+00, 1.02E+00, 2.99E+00, 4.50E-01, 1.90E+01, 3.42E+00, 0.00E+00, 0.00E+00},
692 {1.50E-02, 1.24E+03, 3.38E+00, 2.46E+00, 5.20E-01, 7.00E+00, 2.56E+00, 9.10E-02, 1.95E-02}
697 2.1E-02, 9.73E-03, 2.38E+00, 1.39E-02, -5.51E-01, 7.7E-02, 2.12E+00, 1.97E-06, 2.051E+00, 5.5E+00, 6.62E-01, 2.02E+01, 3.62E+00
700 2.0E-02, 2.53E-04, 1.728E+00, 2.164E+00, 7.74E-01, 1.639E+00, 1.43E+01, 0, 0
703 5.0E-03, 6.34E+01, 1.78E+00, 1.38E-03, 4.06E-01, 1.63E-01, 3.27E-01, 1.554E+01, 3.903E+00, 1.735, 1.02E+01
706 0.00E+00, 6.05E+00, -5.247E-01, 4.088E-03, 2.872E+00, 7.3E-03, 6.99E+00
709 2.3, 1.7E+07, -73.1505813599, -1.7569509745, -2.0016760826, -0.1902804971, 0.0171353221, 0.1270833164, -0.1523126215, 0, 0
712 1.00E+03, 1.00E+07, -79.0158996582, -2.1025185585, -1.2407282591, 0.174798578, 0.1062489152, -0.0004342734, -0.0465673618, 0, 0
715 2.6E+00, 4.00E+06, -82.5164, -6.70755, -6.10977, -2.6281, 0.709759, 0.639033, 0.10298, 0.26124, -0.263817
718 200, 1.00E+06, -95.8165, -7.17049, -7.48288, -1.93034, 0.761153, 0.556689, -0.0542859, -0.270184, -0.0147
721 2.00E+03, 1.00E+05, -70.670173645, -0.632612288, -0.6065212488, -0.0915143117, -0.0121710282, 0.0168179292, 0.0104796877, 0, 0
ParticleAttrib< Vector_t > P
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
constexpr double kB
Boltzman's constant in eV/K.
Interface for basic beam line object.
int checkPoint(const double &x, const double &y, const double &z)
std::unique_ptr< LossDataSink > lossDs_m
constexpr double m_hm
The H- rest mass in GeV.
static const double csCoefDouble_Hminus[3][9]
static const double csCoefSingle_Hplus_Chebyshev[11]
void crossSection(const Vector_t &R, double Eng)
ElementBase * getElement()
void apply(PartBunchBase< double, 3 > *bunch, const std::pair< Vector_t, double > &boundingSphere, size_t numParticlesInSimulation=0)
static const double csCoefSingleCapt_H[3][9]
ParticleAttrib< double > Q
virtual ElementBase * removeWrappers()
Return the design element.
Tps< T > exp(const Tps< T > &x)
Exponential.
static const double csCoefDouble_Hplus_Chebyshev[11]
static const double csCoefSingle_Hminus[3][9]
constexpr double m_p
The proton rest mass in GeV.
virtual const std::string getType() const
virtual const std::string & getName() const
Get element name.
ParticleAttrib< short > bunchNum
bool stillAlive(PartBunchBase< double, 3 > *bunch)
void secondaryParticles(PartBunchBase< double, 3 > *bunch, size_t &i, bool pdead_LS)
Inform & level4(Inform &inf)
static const double csCoefSingle_Hplus[3][9]
size_t getTotalNum() const
Tps< T > log(const Tps< T > &x)
Natural logarithm.
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
virtual ElementType getType() const =0
Get element type std::string.
virtual bool apply(const size_t &id, const double &t, Vector_t &E, Vector_t &B)
constexpr double m_e
The electron rest mass in GeV.
constexpr double m_h3p
The H3+ rest mass in GeV.
static const double csCoefProtonProduction_H2plus_Tabata[11]
static const double csCoefH3plusProduction_H2plus_Tabata[7]
constexpr double E_ryd
Rydberg's energy (Rydberg's constant times hc) in GeV.
double csAnalyticFunctionNakai(double Eng, double Eth, int &i)
ParticleAttrib< short > PType
bool lorentzStripping(double &gamma, double &E)
static const double csCoefSingleLoss_H[3][9]
ElementBase::ElementType bstpshape_m
constexpr double c
The velocity of light in m/s.
constexpr double a0
Bohr radius in m.
virtual bool getStop() const
double getTemperature() const
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Vektor< double, 3 > Vector_t
static const double csCoefDouble_Hminus_Chebyshev[11]
void transformToHminus(PartBunchBase< double, 3 > *bunch, size_t &i)
void doPhysics(PartBunchBase< double, 3 > *bunch)
size_t getLocalNum() const
Tps< T > sqrt(const Tps< T > &x)
Square root.
static const double csCoefDouble_Hplus[3][9]
void transformToH3plus(PartBunchBase< double, 3 > *bunch, size_t &i)
constexpr double m_h2p
The H2+ rest mass in GeV.
constexpr double h_bar
The reduced Planck constant in GeVs.
void transformToProton(PartBunchBase< double, 3 > *bunch, size_t &i)
bool gasStripping(double &deltas)
constexpr double q_e
The elementary charge in As.
constexpr double m_h
The hydrogen atom rest mass in GeV.
static const double csCoefProtonProduction_H_Tabata[9]
virtual std::string getResidualGas() const
ParticleAttrib< int > Bin
static const double csCoefHminusProduction_H_Tabata[13]
ParticleAttrib< double > M
ElementBase * element_ref_m
BeamStrippingPhysics(const std::string &name, ElementBase *element)
double csChebyshevFitting(double Eng, double Emin, double Emax)
static const double csCoefHydrogenProduction_H2plus_Chebyshev[11]
virtual bool checkHit(const Vector_t &R, const Vector_t &P, double dt)=0
unsigned stoppedPartStat_m
static const double csCoefSingle_Hminus_Chebyshev[11]
Inform & endl(Inform &inf)
void transformToHydrogen(PartBunchBase< double, 3 > *bunch, size_t &i)
double csAnalyticFunctionTabata(double Eng, double Eth, double a1, double a2, double a3, double a4, double a5, double a6)