3.6. Function evaluation
Flair has the ability to evaluate functions in the place of numerical values in the CARD’s what. Functions can be defined by entering the expression starting with the equal sign ‘=’
The same function evaluation can be used on the built-in calculator frame (under Tools). The expression is evaluated with the press of [Return] key.
[Shift-Return] to add an extra line. To show that this is a continuation line insert a space character in front.
Dx: =1.5*mm*fwhm cosx: =sind(ang)
with ang defined as #define ang 10
with a previous card
Set in the BEAM
card the beam size to 1.5mm in FWHM The functions are kept in
the input file as special decorator comments preceding the card with the format
!@what.#=<func>
The input file will be saved as:
!@what.4=1.5*mm*fwhm BEAM -20.0 -0.082425 -1.7 .353223007 1.0PROTON *...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....
The special functions what(), body() and card() allow the user to refer to whats from the current card, another body card or any other card in the input file
- e.g
* create a symmetric box around 0. All [XYZ]max are the * positive of the [XYZ]min RPP box Xmin:-10 Xmax:=-what(1) Ymin:-20 Ymax:=-what(3) Zmin:-30 Zmax:=-what(5) * create a plane using the what(6) of body 'box' plus 2mm XYP PlaneZ Z:=body(box,6)+2*mm * or using the card() function XYP PlaneZ Z:=card(RPP,box,6)+2*mm
Note
During loading of the input file in such a decorator is found then corresponding what will be replaced by the function expression.
During saving of the input file the card will be written with the decorator comment preceding it and the correct numerical evaluation of the function.
WARNING: If you manually change the numerical value in the input file with an editor, then next time you open through flair it will replace the value with the function evaluation.
What’s where the sign is controlling the type of the value have to be manually inserted by the user and not by flair with the drop down box. For example in BEAM what(1) if positive means momentum, negative is energy. By entering a function in what(1) the drop down box in flair controlling the sign will be ignored.
Function can return also a string value e.g. a material name for dynamic material substitution
#define MAT CARBON
and later in the code
ASSIGNMAT =MAT MYREGION
Due to limitation in processing speed of python, all #define are evaluated once. Therefore multiple #define will be overridden with the last value. This functionality is due to change in the future if a way is found.
3.6.1. Global Variables
Name |
Value |
Description |
---|---|---|
Constants: |
||
a |
1/137.035989561 |
Fine constant |
pi |
3.1415926535897931 |
|
e |
2.7182818284590451 |
Euler’s number |
c |
299792458 102 |
Speed of light cm/s |
Na |
6.0221367 1023 |
Avogadro number |
re |
2.8179409183694872 10-13 |
Electron radius |
qe |
1.60217646 10-19 |
Electron charge |
fwhm |
\(2 \sqrt{2 log(2)}\) = 2.3548200450309493 |
Full width at half maximum |
Particle mass: |
||
amu |
0.93149432 |
Atomic mass unit |
amuC12 |
0.93123890 |
Carbon12 unified atomic mass unit |
amugr |
1.6605402 10-24 |
Amu in g |
Mp |
0.93827231 |
Proton mass in GeV |
Mn |
0.93956563 |
Neutron mass in GeV |
Me |
0.510998910 10-3 |
Electron mass in GeV |
Metric distance: |
||
nm |
0.1 10-6 |
nano meter |
um |
0.1 10-3 |
micro meter |
mm |
0.1 |
millimeter |
cm |
1 |
centimeter |
dm |
10 |
decimeter |
m |
100 |
meter |
km |
100 103 |
kilometer |
Imperial distance: |
||
inch |
2.54 |
imperial inch |
feet or ft |
30.48 |
imperial feet |
mile or mi |
160934.4 |
imperial mile |
Time: |
||
ns |
1.0 10-9 |
nano-second |
us |
1.0 10-6 |
micro-second |
ms |
0.001 |
milli-second |
s |
1 |
second |
min |
60 |
minute |
hour |
3600 |
hour |
day |
86400 |
day |
week |
7*86400 |
week |
month |
365.25/12*86400 |
month as 1/12th of a year |
year |
365.25*86400 |
year |
Energy: |
||
eV |
10-9 |
electron volt |
keV |
10-6 |
kilo electron volt |
MeV |
10-3 |
Mega electron volt |
GeV |
1.0 |
Giga electron volt |
TeV |
103 |
Tera electron volt |
PeV |
106 |
Peta electron volt |
J |
eV/qe |
Joule |
Gy |
eV/qe/kg |
Gray |
Metric: |
||
yotta |
1024 |
|
zetta |
1021 |
|
exa |
1018 |
|
peta |
1015 |
|
tera |
1012 |
|
giga |
109 |
|
mega |
106 |
|
kilo |
103 |
|
hecto |
102 |
|
deca |
101 |
|
deci |
10-1 |
|
centi |
10-2 |
|
milli |
10-3 |
|
micro |
10-6 |
|
nano |
10-9 |
|
pico |
10-12 |
|
femto |
10-15 |
|
atto |
10-18 |
|
zepto |
10-21 |
|
yocto |
10-24 |
- Special variables
- frame:
Frame number as set in the timeframe
Mass of particles
To get the mass of particles as defined in FLUKA use the name particle name prefixed with the letter m The suffix +/- is replaced with p/n Intermediate - symbol are removed
- e.g.
PROTON
mass:=
mPROTON
4-HELIUM
mass:=
m4HELIUM
MUON-
mass:=
mMUONn
MUON+
mass:=
mMUONp
3.6.2. Functions
Function |
Description |
---|---|
p2T(p,m) |
convert momentum in kinetic energy |
T2p(T,m) |
convert kinetic energy to momentum |
dT2dp(T,dT,m) |
convert kinetic energy spread into momentum spread |
T2g(T,m) |
convert kinetic energy to relativistic gamma |
g2b(g) |
gamma to beta |
b2g(b) |
beta to gamma |
X0(Z,A) |
radiation length in [g/cm²] |
lhad(A) |
~hadronic interaction length (g/cm²) (1-100GeV) |
Function |
Description |
---|---|
body(n,w) |
return the w’th what of body named ‘n’
|
card(t,n,w) |
return the w’th what of card tag ‘t’ with name ‘n’ if n is string or ordered ‘n’ if n is integer
|
spline(n,t) |
return the interpolation point/vector of spline name ‘n’ for time t. It can be used for movies, setting the camera position from the frame number, or dose calculations for the intervention planning tool
|
what(n) |
return the n’th what of current card |
Mathematical Functions
Function |
Description |
---|---|
acos(x) |
radian based trig functions |
asin(x) |
|
atan(x) |
|
cos(x) |
|
sin(x) |
|
tan(x) |
|
acosd(x) |
degrees based trig functions |
asind(x) |
|
atand(x) |
|
cosd(x) |
|
sind(x) |
|
tand(x) |
|
atan2(y,x) |
return arctan(y/x) |
omega(x) |
return solid angle for x-radians polar angle |
omegad(x) |
return solid angle for x-degrees polar angle |
radians(x) |
convert degrees to radians |
degrees(x) |
convert radians to degrees |
acosh(x) |
Hyperbolic functions |
asinh(x) |
|
atanh(x) |
|
cosh(x) |
|
sinh(x) |
|
tanh(x) |
|
exp(x) |
Exponential ex |
log(x) |
Natural logarithm of x |
log1p(x) |
log(1+x) |
log10(x) |
Logarithm based 10 of x |
\(\sqrt{x}\) |
|
pow(x,y) |
xy |
factorial(n) |
n! |
abs(x) |
absolute value of x |
ceil(x) |
ceiling, smallest integral variable >= x |
copysign(x,y) |
return x with sign of y |
float(x) |
return x as float, 0 on failure |
floor(x) |
largest integral variable <= x |
fmod(x,y) |
modulo x % y |
hypot(x,y) |
hypotenuse \(\sqrt{x²+y²}\) |
int(x) |
return integer part of x, 0 on failure (e.g. with string) |
len(x) |
return length of string, number of items in a vector |
trunc(x) |
return the nearest integral towards 0 |
Vector operations:
Vectors can be defined as
Vector(x,y,x)
or with curly brackets
{x, y, z}
Coordinates can be accessed as
.x .y .z
or[0], [1], [2]
- e.g.
vector.x
orvector[0]
Operators:
Operator |
Description |
---|---|
+ - |
addition/subtraction of two vectors |
* |
scale with a number |
* dot |
dot product |
^ cross |
cross product |
- Vector Methods:
length()
length of vector
a.length()
norm()
normalize vector
x(), y(), z()
return x, y or z component
orthogonal()
return a vector orthogonal to current
A.orthogonal
direction()
return string describing direction X/Y/Z
phi()
return azimuthal angle of vector
theta()
return polar angle of vector
perp()
return the transverse component of a vector. radius in the cylindrical system
A.perp() = sqrt(A.x^2+A.y^2)
Arrays, tuples and lists:
Syntax |
Description |
---|---|
[1,2,…] |
[] define lists or arrays which are mutable |
(1,2,…) |
() defines tuples which are immutable |
LIST[index] |
[index] returns the index item of list |
TUPLE[index] |
[index] returns the index item of list |
Tuples can be used for multiple runs with different materials assignments e.g.
#define MATS ('LEAD', 'GOLD', 'SILICON', 'COPPER') #define I 0 ASSIGNMAT =MATS[I] REGION
the variable I can be used as a Loop variable from the Runs Frame to loop from 0..2