Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
{
"cells": [
{
"cell_type": "code",
"execution_count": 24,
"id": "0dc0eac1-8214-4d13-b3d6-55d28ed5d86a",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from scipy.optimize import root_scalar\n",
"import xraylib\n",
"import matplotlib.pyplot as plt\n",
"import epics\n",
"import time\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "07b6fc70-6c8a-44bb-a25d-afd559cd9817",
"metadata": {},
"outputs": [],
"source": [
"# Beamline input block\n",
"energy = 15000.0 # Energy in eV\n",
"energy_keV = energy/1000.0 # Energy in keV\n",
"wl = 1239.84 / (energy * 10**9)\n",
"d_StoL1 = 51.9 # Source-to-CRL1 distance, in m\n",
"d_StoL2 = 62.1 # Source-to-CRL2 distance, in m\n",
"d_Stof = 66.2 # Source-to-focus distance, in m\n",
"\n",
"#slit1_H = 500.0e-6 # H slit size before CRL 1\n",
"#slit1_V = 300.0e-6 # V slit size before CRL 1\n",
"#slit2_H = 500.0e-6 # H slit size before CRL 2\n",
"#slit2_V = 300.0e-6 # V slit size before CRL 2"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f7317f0f-e9f5-461c-8576-8f7d03113fd4",
"metadata": {},
"outputs": [],
"source": [
"# CRL input block\n",
"d_min = 3.0e-5 # Minimum thickness at the apex in m\n",
"stack_d = 50.0e-3 # Stack thickness in m\n",
"L1_n = np.array([1, 1, 1, 1, 1, 1, 2, 4, 8, 16]) # CRL1 number of lenses in each stack\n",
"L1_R = np.array([2.0e-3, 1.0e-3, 5.0e-4, 3.0e-4, 2.0e-4, 1.0e-4, 1.0e-4, 1.0e-4, 1.0e-4, 1.0e-4]) # CRL1 lens radius in each stack\n",
"L1_mater= np.array([\"Be\", \"Be\", \"Be\", \"Be\", \"Be\", \"Be\", \"Be\", \"Be\", \"Be\", \"Be\"]) # CRL1 lens material in each stack\n",
"L1_loc = np.array([4.5, 3.5, 2.5, 1.5, 0.5, -0.5, -1.5, -2.5, -3.5, -4.5])*stack_d # CRL1 lens stack location relative to center stack, positive means upstream\n",
"L1_HE = np.array([1.0e-6, 1.0e-6, 1.0e-6, 1.0e-6, 1.0e-6, 1.0e-6, 1.4e-6, 2.0e-6, 2.8e-6, 4.0e-6]) # CRL1 lens RMS thickness error\n",
"L2_n = np.array([1, 1, 1, 1, 1, 1, 2, 4, 8, 16]) # CRL2 number of lenses in each stack\n",
"L2_R = np.array([2.0e-3, 1.0e-3, 5.0e-4, 3.0e-4, 2.0e-4, 1.0e-4, 1.0e-4, 1.0e-4, 1.0e-4, 1.0e-4]) # CRL2 lens radius in each stack\n",
"L2_mater= np.array([\"Be\", \"Be\", \"Be\", \"Be\", \"Be\", \"Be\", \"Be\", \"Be\", \"Be\", \"Be\"]) # CRL2 lens material in each stack\n",
"L2_loc = np.array([4.5, 3.5, 2.5, 1.5, 0.5, -0.5, -1.5, -2.5, -3.5, -4.5])*stack_d # CRL2 lens stack location relative to center stack, positive means upstream\n",
"L2_HE = np.array([1.0e-6, 1.0e-6, 1.0e-6, 1.0e-6, 1.0e-6, 1.0e-6, 1.4e-6, 2.0e-6, 2.8e-6, 4.0e-6]) # CRL2 lens RMS thickness error\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "c1d1228a-2bdd-47d4-ba9e-0d6e79c635a4",
"metadata": {},
"outputs": [],
"source": [
"# Source size input block\n",
"L_und = 4.7 # undulator length\n",
"sigmaH_e = 14.8e-6 # Sigma electron source size in H direction in m\n",
"sigmaV_e = 3.7e-6 # Sigma electron source size in V direction in m\n",
"sigmaHp_e = 2.8e-6 # Sigma electron divergence in H direction in rad\n",
"sigmaVp_e = 1.5e-6 # Sigma electron divergence in V direction in rad\n",
"sigmaH = (sigmaH_e**2 + wl*L_und/2/np.pi/np.pi)**0.5\n",
"sigmaV = (sigmaV_e**2 + wl*L_und/2/np.pi/np.pi)**0.5\n",
"sigmaHp = (sigmaHp_e**2 + wl/L_und/2)**0.5\n",
"sigmaVp = (sigmaVp_e**2 + wl/L_und/2)**0.5\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "b6ff87f5-75b3-43bd-94fd-ec8fd880ab7f",
"metadata": {},
"outputs": [],
"source": [
"# Lookup table where each entry is a tuple (column1, column2)\n",
"Lens_diameter_table = [\n",
" (50, 450.0),\n",
" (100, 632.0),\n",
" (200, 894.0),\n",
" (300, 1095.0),\n",
" (500, 1414.0),\n",
" (1000, 2000.0),\n",
" (1500, 2450.0),\n",
"]\n",
"\n",
"# Convert the lookup table to a dictionary for faster lookup\n",
"Lens_diameter_dict = {int(col1): col2 for col1, col2 in Lens_diameter_table}\n",
"\n",
"def lookup_diameter(lens_radius):\n",
" # Convert the input float to an integer\n",
" input_int = int(round(lens_radius*1.0e6))\n",
" return Lens_diameter_dict.get(input_int, (lens_radius*1.0e6)**0.5*63.222+ 0.73)/1.0e6\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "401b6573-1cbb-4503-bbda-e864bd8c5969",
"metadata": {},
"outputs": [],
"source": [
"def index_to_binary_list(index, length):\n",
" \"\"\"\n",
" Converts an index number to its binary representation as a list of digits,\n",
" and pads the list with zeros in front to achieve the desired length.\n",
"\n",
" Parameters:\n",
" index (int): The index number to be converted.\n",
" length (int): The desired length of the binary list.\n",
"\n",
" Returns:\n",
" list: A list of digits representing the binary representation of the index.\n",
" \"\"\"\n",
" # Convert the index to a binary string and remove the '0b' prefix\n",
" binary_str = bin(index)[2:]\n",
"\n",
" # Pad the binary string with zeros in front to achieve the desired length\n",
" #padded_binary_str = binary_str.zfill(length)\n",
"\n",
" # Reverse the binary string\n",
" reversed_binary_str = binary_str[::-1]\n",
"\n",
" # Convert the reversed binary string to a list of integers\n",
" binary_list = [int(digit) for digit in reversed_binary_str]\n",
"\n",
" # Pad the list with zeros at the end to achieve the desired length\n",
" while len(binary_list) < length:\n",
" binary_list.append(0)\n",
" return binary_list"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "7c6792ad-6436-4864-bdb9-68ad571d13ba",
"metadata": {},
"outputs": [],
"source": [
"def binary_list_to_index(binary_list, length):\n",
" \"\"\"\n",
" Converts a list of binary digits in reverse order to its integer representation,\n",
" padding the list with zeros at the end to have a fixed number of elements.\n",
"\n",
" Parameters:\n",
" binary_list (list): A list of digits representing the binary number in reverse order.\n",
" length (int): The fixed number of elements the list should have.\n",
"\n",
" Returns:\n",
" int: The integer representation of the binary number.\n",
" \"\"\"\n",
" # Pad the list with zeros at the end to achieve the desired length\n",
" while len(binary_list) < length:\n",
" binary_list.append(0)\n",
"\n",
" # Convert the binary list to an integer\n",
" index = 0\n",
" for i, digit in enumerate(binary_list):\n",
" index += digit * 2**i\n",
"\n",
" return index"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "620e8ed0-0098-463f-8035-0e69ee7bc216",
"metadata": {},
"outputs": [],
"source": [
"def materials_to_deltas(material_list, energy):\n",
" \"\"\"\n",
" Convert a list of material names to a list of delta values at a given energy.\n",
"\n",
" Parameters:\n",
" material_list (list): A list of material names.\n",
" energy (float): The energy in keV.\n",
"\n",
" Returns:\n",
" list: A list of delta values for the given materials at the given energy.\n",
" \"\"\"\n",
" # The list to store delta values\n",
" delta_list = []\n",
"\n",
" # Iterate through each material in the input list\n",
" for material in material_list:\n",
" # Compute the delta value for the current material at the given energy\n",
" Z = xraylib.SymbolToAtomicNumber(material)\n",
" density = xraylib.ElementDensity(Z)\n",
Loading
Loading full blame...