1 | #include <iostream> |
---|
2 | #include <vector> |
---|
3 | #include <string> |
---|
4 | #include <cmath> |
---|
5 | #include "StandardCollimator.h" |
---|
6 | using namespace std; |
---|
7 | |
---|
8 | |
---|
9 | StandardCollimator::StandardCollimator(const double& ALFX, const double& ALFY, const double& APER_1, const double& APER_2, const double& APER_3, const double& APER_4, const string& APERTYPE, const double& BETX, const double& BETY, const double& DPX, const double& DPY, const double& DX, const double& DY, const string& KEYWORD, const double& L, const double& MUX, const double& MUY, const string& NAME, const double& PTC, const double& PXC, const double& PYC, const double& S, const double& TC, const double& XC, const double& YC, const double& K0L, const double& K0SL, const double& K1L, const double& K1SL, const double& K2L, const double& K2SL, const string& PARENT, const string& meth, const long double& hgap, const long double& hgap2, const double& collang, const long double& pdepth, const long double& pdepth2, const double& tcang, const double& nsig) |
---|
10 | : Collimator(ALFX, ALFY, APER_1, APER_2, APER_3, APER_4, APERTYPE, BETX, BETY, DPX, DPY, DX, DY, KEYWORD, L, MUX, MUY, NAME, PTC, PXC, PYC, S, TC, XC, YC, K0L, K0SL, K1L, K1SL, K2L, K2SL, PARENT, meth, hgap, hgap2, collang, pdepth, pdepth2, tcang, nsig) |
---|
11 | {}; |
---|
12 | |
---|
13 | StandardCollimator::StandardCollimator(Element elt, const double& tcang, const double& nsig, const string& meth, const string& material) |
---|
14 | : Collimator(elt, tcang, nsig, meth, material) |
---|
15 | { |
---|
16 | }; |
---|
17 | |
---|
18 | |
---|
19 | StandardCollimator::StandardCollimator(const StandardCollimator& obj) |
---|
20 | : Collimator(obj) |
---|
21 | {}; |
---|
22 | |
---|
23 | |
---|
24 | void StandardCollimator::collipass(Particle& p1, double& dpopeff, const double& scaleorbit, const double& R11X, const double& R12X, const double& R21X, const double& R22X, const double& R11Y, const double& R12Y, const double& R21Y, const double& R22Y, const double& dx1, const double& dpx1, const double& dy1, const double& dpy1, const double& delta_s, const double& Apr, const double& Zpr, const double& betgam) |
---|
25 | { |
---|
26 | |
---|
27 | long double ca, sa; |
---|
28 | |
---|
29 | sa = sin(this->tcang); |
---|
30 | ca = cos(this->tcang); |
---|
31 | |
---|
32 | //account for positioning of collmators on orbit |
---|
33 | p1.coordonnees[0][0] = p1.coordonnees[0][0] - scaleorbit * this->XC; |
---|
34 | p1.coordonnees[0][2] = p1.coordonnees[0][2] - scaleorbit * this->YC; |
---|
35 | |
---|
36 | long double xl, xsl, alf, lcolleff; |
---|
37 | |
---|
38 | |
---|
39 | //Calculate effective x and x' in the rotated collimator coordinate system |
---|
40 | xl = p1.coordonnees[0][0] * ca + p1.coordonnees[0][2] * sa; |
---|
41 | xsl = p1.coordonnees[0][1] * ca + p1.coordonnees[0][3] * sa; |
---|
42 | this->pdepth = abs(xl) - this->hgap;//the depth in the collimator at the entrance |
---|
43 | this->pdepth2 = abs(xl + this->L * xsl) - this->hgap2; //the depth in the collimator at the exit |
---|
44 | |
---|
45 | |
---|
46 | if (this->pdepth > 0) { //the particle is impacting on the front end of the collimator |
---|
47 | |
---|
48 | |
---|
49 | //impact angle on collimator |
---|
50 | if (xl < 0) { |
---|
51 | alf = this->phi + xsl;//impact angle on collimator |
---|
52 | } else { |
---|
53 | alf = this->phi - xsl; |
---|
54 | } |
---|
55 | |
---|
56 | //alpha is negative for particles hitting on the face |
---|
57 | |
---|
58 | lcolleff = this->pdepth / alf; //effective length of orbit inside collimator |
---|
59 | |
---|
60 | if ((lcolleff > this->L) || (lcolleff < 0)) { |
---|
61 | lcolleff = this->L; |
---|
62 | } |
---|
63 | |
---|
64 | //Apply a thin collimator at the entrance |
---|
65 | |
---|
66 | collipassInteraction(p1, Apr, Zpr, betgam, lcolleff); |
---|
67 | |
---|
68 | if (p1.Ap0 == 0) { |
---|
69 | return; |
---|
70 | } |
---|
71 | |
---|
72 | p1.coordonnees[0][0] = p1.coordonnees[1][0] + scaleorbit * this->XC; |
---|
73 | p1.coordonnees[0][2] = p1.coordonnees[1][2] + scaleorbit * this->YC; |
---|
74 | p1.coordonnees[0][4] = p1.coordonnees[1][4]; |
---|
75 | |
---|
76 | //Twiss transform the particle to the end of the collimator |
---|
77 | |
---|
78 | dpopeff = (p1.Ap0 * Zpr) / (p1.Zp0 * Apr) * (1 + p1.coordonnees[0][4]) - 1; |
---|
79 | |
---|
80 | p1.coordonnees[1][0] = R11X * p1.coordonnees[0][0] + R12X * p1.coordonnees[1][1] + (this->DX - R11X * dx1 - R12X * dpx1) * dpopeff; |
---|
81 | p1.coordonnees[1][1] = R21X * p1.coordonnees[0][0] + R22X * p1.coordonnees[1][1] + (this->DPX - R21X * dx1 - R22X * dpx1) * dpopeff; |
---|
82 | p1.coordonnees[1][2] = R11Y * p1.coordonnees[0][2] + R12Y * p1.coordonnees[1][3] + (this->DY - R11Y * dy1 - R12Y * dpy1) * dpopeff; |
---|
83 | p1.coordonnees[1][3] = R21Y * p1.coordonnees[0][2] + R22Y * p1.coordonnees[1][3] + (this->DPY - R21Y * dy1 - R22Y * dpy1) * dpopeff; |
---|
84 | |
---|
85 | } else if (this->pdepth2 > 0) { //Particles impacting along the jaw (outside the gap at the end but inside in beginning) |
---|
86 | |
---|
87 | double sImp, xint, yint, xsint, ysint; |
---|
88 | |
---|
89 | if ((xl + L * xsl) < 0) { |
---|
90 | alf = -this->phi - xsl; |
---|
91 | } else { |
---|
92 | alf = -this->phi + xsl; |
---|
93 | } |
---|
94 | |
---|
95 | //impact angle on collimator. The sign determines which jaw is hit and therefore if the jaw angle should be added or subtracted. |
---|
96 | lcolleff = this->pdepth2 / alf; |
---|
97 | |
---|
98 | if ((lcolleff > this->L) || (lcolleff < 0)) { |
---|
99 | lcolleff = this->L; |
---|
100 | } |
---|
101 | |
---|
102 | sImp = -this->pdepth / alf; //distance from beginning of collimator to impact |
---|
103 | |
---|
104 | //Move particle to this point. Drift => angles don't change, x,y change as straight line |
---|
105 | xint = p1.coordonnees[0][0] + p1.coordonnees[0][1] * sImp; |
---|
106 | yint = p1.coordonnees[0][2] + p1.coordonnees[0][3] * sImp; |
---|
107 | xsint = p1.coordonnees[0][1]; |
---|
108 | ysint = p1.coordonnees[0][3]; |
---|
109 | |
---|
110 | //Apply thin collimator at impact position |
---|
111 | |
---|
112 | Particle ptemp(xint, xsint, yint, ysint, p1.coordonnees[0][4], 0, p1.Ap0, p1.Zp0, p1.coordonnees[0][4]); |
---|
113 | |
---|
114 | collipassInteraction(ptemp, Apr, Zpr, betgam, lcolleff); |
---|
115 | |
---|
116 | if (ptemp.Ap0 == 0) { |
---|
117 | return; |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | //Move particle to the end of collimator region as defined in MADX. Drift => angles don't change, x,y change as straight line |
---|
122 | xint = ptemp.coordonnees[1][0]; |
---|
123 | yint = ptemp.coordonnees[1][2]; |
---|
124 | xsint = ptemp.coordonnees[1][1]; |
---|
125 | ysint = ptemp.coordonnees[1][3]; |
---|
126 | p1.Ap0 = ptemp.Ap0; |
---|
127 | p1.Zp0 = ptemp.Zp0; |
---|
128 | p1.coordonnees[0][4] = ptemp.coordonnees[1][4]; |
---|
129 | |
---|
130 | xint = xint + scaleorbit * this->XC; |
---|
131 | yint = yint + scaleorbit * this->YC; |
---|
132 | p1.coordonnees[0][0] = p1.coordonnees[0][0] + scaleorbit * this->XC; |
---|
133 | p1.coordonnees[0][2] = p1.coordonnees[0][2] + scaleorbit * this->YC; |
---|
134 | |
---|
135 | dpopeff = (p1.Ap0 * Zpr) / (p1.Zp0 * Apr) * (1 + p1.coordonnees[0][4]) - 1; |
---|
136 | |
---|
137 | p1.coordonnees[1][0] = xint + xsint * (delta_s - sImp); |
---|
138 | p1.coordonnees[1][2] = yint + ysint * (delta_s - sImp); |
---|
139 | p1.coordonnees[1][1] = xsint; |
---|
140 | p1.coordonnees[1][3] = ysint; |
---|
141 | p1.coordonnees[1][4] = p1.coordonnees[0][4]; |
---|
142 | } else {//Particle don't hit the collimator |
---|
143 | |
---|
144 | p1.coordonnees[0][0] = p1.coordonnees[0][0] + scaleorbit * this->XC; |
---|
145 | p1.coordonnees[0][2] = p1.coordonnees[0][2] + scaleorbit * this->YC; |
---|
146 | |
---|
147 | //Twiss transform the particle to the end of the collimator |
---|
148 | dpopeff = (p1.Ap0 * Zpr) / (p1.Zp0 * Apr) * (1 + p1.coordonnees[0][4]) - 1; |
---|
149 | |
---|
150 | p1.coordonnees[1][0] = R11X * p1.coordonnees[0][0] + R12X * p1.coordonnees[0][1] + (this->DX - R11X * dx1 - R12X * dpx1) * dpopeff; |
---|
151 | p1.coordonnees[1][1] = R21X * p1.coordonnees[0][0] + R22X * p1.coordonnees[0][1] + (this->DPX - R21X * dx1 - R22X * dpx1) * dpopeff; |
---|
152 | p1.coordonnees[1][2] = R11Y * p1.coordonnees[0][2] + R12Y * p1.coordonnees[0][3] + (this->DY - R11Y * dy1 - R12Y * dpy1) * dpopeff; |
---|
153 | p1.coordonnees[1][3] = R21Y * p1.coordonnees[0][2] + R22Y * p1.coordonnees[0][3] + (this->DPY - R21Y * dy1 - R22Y * dpy1) * dpopeff; |
---|
154 | p1.coordonnees[1][4] = p1.coordonnees[0][4]; |
---|
155 | |
---|
156 | } |
---|
157 | }; |
---|
158 | |
---|
159 | void StandardCollimator::affiche() |
---|
160 | { |
---|
161 | |
---|
162 | cout << "Standard collimator:" << endl; |
---|
163 | |
---|
164 | this->Collimator::affiche(); |
---|
165 | }; |
---|