☰
◀ Previous △ Index Next ▶
F3.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.
e.g. 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
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
NOTES:
1. During loading of the input file in such a decorator is found
then corresponding what will be replaced by the function
expression.
2. 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.
3. 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.
4. 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.
5. 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
6. 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.
Global Variables and Functions
Name Value Description
----- ------- -------------------
Constants
~~~~~~~~~
a 1/137.035989561 Fine constant
pi 3.1415926535897931
e 2.7182818284590451 Euler's number
c 299792458e2 Speed of light cm/s
Na 6.0221367e23 Avogadro number
re 2.8179409183694872d-13 Electron radius
qe 1.60217646E-19 Electron charge
fwhm 2*sqrt(2*log(2)) Full width at half maximum
= 2.3548200450309493
Particle mass
~~~~~~~~~~~~~
amu 0.93149432 Atomic mass unit
amuC12 0.93123890 Carbon12 unified atomic mass unit
amugr 1.6605402E-24 Amu in g
Mp 0.93827231 Proton mass in GeV
Mn 0.93956563 Neutron mass in GeV
Me 0.510998910e-3 Electron mass in GeV
Metric distance
~~~~~~~~~~~~~~~
nm 0.1E-6 nano meter
um 0.1E-3 micro meter
mm 0.1 millimeter
cm 1 centimeter
dm 10 decimeter
m 100 meter
km 100E3 kilometer
Imperial distance
~~~~~~~~~~~~~~~~~
inch 2.54 imperial inch
feet 30.48 or ft imperial feet
mile 160934.4 or mi imperial mile
Time
~~~~
ns 1.0e-9 nano-second
us 1.0e-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 1e-9 electron volt
keV 1e-6 kilo electron volt
MeV 1e-3 Mega electron volt
GeV 1.0 Giga electron volt
TeV 1e3 Tera electron volt
PeV 1e6 Peta electron volt
J eV/qe Joule
Gy eV/qe/kg Gray
Metric
~~~~~~
yotta 1e24
zetta 1e21
exa 1e18
peta 1e15
tera 1e12
giga 1e9
mega 1e6
kilo 1e3
hecto 1e2
deca 1e1
deci 1e-1
centi 1e-2
milli 1e-3
micro 1e-6
nano 1e-9
pico 1e-12
femto 1e-15
atto 1e-18
zepto 1e-21
yocto 1e-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
Suffic +/- is replaced with p/n
Intermediate - are removed
e.g. PROTON mass = mPROTON
4-HELIUM mass = m4HELIUM
MUON- mass = mMUONn
MUON+ mass = mMUONp
Physics functions
-----------------
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
X0(Z,A) radiation length in [g/cm2]
lhad(A) ~hadronic interaction length (g/cm2) (1-100GeV)
Card reference functions
------------------------
body(n,w) return the w'th what of body named 'n'
body(BLKBODY,4) - return what(4) of BLKBODY
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
card(BEAM,0,1) - return BEAM energy of first BEAM card
card(USRBIN,enedep,1) - return what(1) of USRBIN with
name=enedep
spline(n,t) return the interpolation point/vector of spline names '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
=spline('camera.pos', frame).x
what(n) return the n'th what of current card
Mathematical Functions
--------------------------
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 e**x
log(x) Natural logarithm of x
log1p(x) log(1+x)
log10(x) Logarithm based 10 of x
sqrt(x)
pow(x,y) x**y
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) module x % y
hypot(x,y) hypotenuse sqrt(x**2+y**2)
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]
vector.x or vector[0]
Operators:
+ - addition/subtraction of two vectors a+/-b
* scale with a number 2.0*a
* dot dot product a*b or a.dot(b)
^ cross cross product a^b or a.cross(b)
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
direction() return string describing direction X/Y/Z
phi() return azimuthal angle of vector
theta() return polar angle of vector
perp() return perpendicular component of vector
Arrays, tuples and lists
~~~~~~~~~~~~~~~~~~~~~~~~
[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
and I can be used as a Loop variable from the Runs Frame to loop
from 0..2
◀ Previous △ Index Next ▶