Hi all,
I am very new with lua and my question could be stupid, but I don’t know how to solve my problem.
Basically I use lua language to givo special commands to another code for ion beam transport.
I have created a code to produce particles with an exponential energy distribution and it works fine.
What I want to do now is to add a cut-off to avoid that particle with energy aboove a certain value will be produced but I am not able to do that.
The code I use is:
-- Generate Exponential distributed random variable with parameter lambda. local rand = simion.rand local ln = math.log function exponential\_rand() return -ln(rand())/0.44 end ------------------------ -- if exponential\_rand()\*1e6 \< 8.9\*1e6 then function my\_dist() return exponential\_rand()\*1e6 --\< 8.9\*1e6 -- end end ----------------------- local t = {coordinates=0} for i=1,2000 do local ke = my\_dist() t[#t+1] = standard\_beam { n = 10, tob = 0, mass = 1.00727647, charge = 1, ke = ke, cwf = 1, color = 0, direction = cone\_direction\_distribution { axis = vector(0, 0, 1), half\_angle = - 6.188e-9\*(ke\*1e-6)^6 +2.155e-6\*(ke\*1e-6)^5 -0.0002876\*(ke\*1e-6)^4 + 0.01799\*(ke\*1e-6)^3 -0.497\*(ke\*1e-6)^2 + 3.215\*(ke\*1e-6)+ 69.44, fill = true }, position = gaussian3d\_distribution { mean = vector(0, 0, 0), stdev = vector(0.06, 0.06, 0) } } end particles(t)
I try to add the if condition in the second block of the code, but it has no effect, can you help me with that?
Thak you in advance