FLUKAFLUKAAdvanced Biasing
FLUKA Users MeetingCERN 31/05/2007
CERN FLUKA Users Meeting 2
Outline Sampling
Random numbers Sampling from discrete & generic distributions Sampling from biased distributions
FLUKA User biasing routines USIMBS UDCDRL SOURCE
Application: n_TOF biasing example
CERN FLUKA Users Meeting 3
Pseudo-Random number All computers provide a pseudo random number
generator. The FLUKA PRNG is provided by the function
FLRNDM(DUMMY). A 64-bit random number generator returning a double precision number.
All such generators return a sequence of numbers uniformly distributed between [0,1). To avoid overflows sometimes, you need to change to (0,1] then use 1.0-FLRNDM(x)
Uniform and Random are independent concepts. For MC sometimes uniformity is more important than randomness, but not if correlations are important
It is important also that sampled histories are uncorrelated with each other
CERN FLUKA Users Meeting 4
FLUKA Random number generators Function FLRNDM(DUMMY)
The main FLUKA PRNG. Returns a double precision random number uniformly distributed in the [0,1) interval
Subroutine SFECFE(SFE, CFE)returns a random azimuthal sine and cosine
Subroutine RACO(TXX, TYY, TZZ)returns the cosines of a randomly oriented vector
Subroutine SFLOOD(XXX, YYY, ZZZ, UXX, VXX, WXX)returns a random position and direction on the surface of a sphere of unit radius (generating a uniform and isotropic field inside the sphere)
Subroutine FLNRRN(RGAUSS)returns a random number normally distributed with unit variance
CERN FLUKA Users Meeting 5
Sampling from a discrete distribution Suppose to have a discrete random variable x, that can
assume values x1,x2,…,xn with probability p1,p2,…,pn
Assume ipi = 1, or normalize it Divide the interval [0,1) in n subintervals with limits
y0=0, y1=p1, y2=p1+p2, …, yn=ipi
Generate a uniform random number Find in which of the i y-intervals it is
WARNING: This can be a time consuming process: Use optimized search techniques like Binary search (look
n_TOF example) Use of equal-probability bins (not recommended when tails
are present) Select the corresponding xi as sampled value Since is uniformly random, we have
P(xi) = P(yi-1 < < yi) = yi – yi-1 = pi
CERN FLUKA Users Meeting 6
Sampling from a Generic Distribution
Using one random numberUsing one random number Integrate the distribution function, analytically or
numerically, and normalize to 1 to obtain the normalized cumulative distribution
Sample a uniform pseudo-random number Get the desired result by finding the inverse value x=F-
1(), analytically or most often by interpolation (table lookup)
Since is uniformly random, we have
max
min
min
)(
)()( x
x
x
x
dxxf
dxxfxF
b
adxxfaFbFbFaFPbxaP )()()()]()([)(
CERN FLUKA Users Meeting 7
Example
Practical rule: a distribution can be sampled directly if and Practical rule: a distribution can be sampled directly if and only if its pdf can be integrated and the integral invertedonly if its pdf can be integrated and the integral inverted
t = - λ log (1 – ξ)
CERN FLUKA Users Meeting 8
Sampling from a Generic DistributionUsing two random numbers (Rejection technique)Using two random numbers (Rejection technique) Choose a constant value C > f(x) for any x Sample two random numbers 1 and 2
1, C2) represents a point on the 2D space
If 2<f(1)/C then X=1
otherwise re-sample 1, 2
The probability that a 1 value is
accepted is f(1)/C for any 1
P(x)dx = P(1=x)dx f(1=x)/C
Since P(1)dx = const,P(x) = const f(x)
CERN FLUKA Users Meeting 9
Sampling from a biased distribution
CERN FLUKA Users Meeting 10
Example
CERN FLUKA Users Meeting 11
Uniform sampling from a steep distribution
CERN FLUKA Users Meeting 12
User written biasingFLUKA offers the following routines for user-written biasing ubsset.f: User BiaSing SETting
called after reading in the input file and before the first event allows to alter almost any biasing weight on a region-dependent
basis usimbs.f: USer defined IMportance BiaSing
if activated, called at every particle step allows to implement any importance biasing scheme based on
region number and/or phase space coordinates udcdrl.f: User defined DeCay DiRection biasing and Lambda
only for neutrinos emitted in decays: bias the direction of emitted neutrino
Not biasing by itself, but it could be used for generating biased runs
source.f: User written source to sample primary particle properties from distribution in space,
energy, time…
CERN FLUKA Users Meeting 13
User Defined Importance Biasing Typical problem: Spend a lot of time to write the problem
input, geometry and on the first runs you realize that statistics are not good
First method (and safest) is to introduce region importance biasing. In FLUKA you can introduce it with two ways:
1st Manually slice the geometry and increase the number of regions. Modifying an existing geometry to introduce biasing can be a very cumbersome process
2nd Introduce the “importance biasing” information with a user fortran routine independent of the regions defined in the geometry
Routine: usimbs.f
USer defined IMportance BiaSing
Allows to implement any importance biasing scheme based on region number and/or phase space coordinates
CERN FLUKA Users Meeting 14
User Defined Importance Biasing Enable the call to USIMBS routine with the BIASING card:
WHAT(1) Particles to be biased WHAT(2) and WHAT(3) ≠ 1.0 (Any value) WHAT(4) Lower bound of region WHAT(5) Upper bound of region WHAT(6) Step SDUM = USER
CERN FLUKA Users Meeting 15
usimbs.f – RoutineThe routine is called on every
particle step!WARNING: can slow down theexecution speed! Use with caution.
Input: Region information at the
beginning and end of the step X,Y,Z coordinates through the
TRACKR common.Beginning: X, Y, Ztrack(0)End: X, Y, Ztrack(Ntrack)
Particle type and Energy could be used for even more advanced biasing schemes
Output:The routine must return the importance ratio to the new position (end/beginning) in the variable FIMP
SUBROUTINE USIMBS ( MREG, NEWREG, FIMP )
INCLUDE '(DBLPRC)' INCLUDE '(DIMPAR)' INCLUDE '(IOUNIT)'**----------------------------------------------------------------------** ** USer defined IMportance BiaSing: ** ** Created on 02 july 2001 by Alfredo Ferrari & Paola Sala ** Infn - Milan ** ** Last change on 09-jul-01 by Alfredo Ferrari ** ** Input variables: ** Mreg = region at the beginning of the step ** Newreg = region at the end of the step ** (thru common TRACKR): ** Jtrack = particle id. (Paprop numbering) ** Etrack = particle total energy (GeV) ** X,Y,Ztrack(0) = position at the beginning of the step ** X,Y,Ztrack(Ntrack) = position at the end of the step ** ** Output variable: ** Fimp = importance ratio (new position/original one) ** **----------------------------------------------------------------------*e INCLUDE '(TRACKR)'* FIMP = ONEONE RETURN END
CERN FLUKA Users Meeting 16
usimbs.f – Important Notes The routine has only a relative effect on the weight of the
particle Beam particles can have any weight.
Importance ratio will be limited by WW-THRESh card The Russian Roulette / Splitting will take place at the end
of the step, and not on a fixed region boundary.The biasing position will be a little fuzzy depending on the particle step. This has a visible effect when it is applied to low density materials (i.e. air)
Results will similar but not be the same as with the manual region biasing.
Is a great time saver for complex geometries, as well different biasing schemes
Combined with the particle type and energy could become very powerful
CERN FLUKA Users Meeting 17
usimbs.f: Simple Example Biasing a factor of 2 every 50 cm on the Z direction from
100cm to 500cm
ZSTART = ZTRACK(0)IF (ZSTART .LT. 100.0D0) THEN
FSTART = ONEONEELSE IF (ZSTART .GT. 500.0D0) THEN
FSTART = TWOTWO ** NINT((500.0D0-100.0D0)/50.0D0)ELSE
FSTART = TWOTWO ** NINT((ZSTART-100.0D0)/50.0D0)ENDIFZEND = ZTRACK(NTRACK)
* Similarly calculate the FEND from ZEND…FIMP = FEND / FSTART
Initial position
Final position
Importance Ratio
CERN FLUKA Users Meeting 18
usimbs.f: Function example Introduce an importance biasing assuming an exponential
law of attenuation in the R direction exp(- R), for R>1cm
RSTART = SQRT(XTRACK(0)**2 + YTRACK(0)**2 + ZTRACK(0)**2)REND = SQRT(XTRACK(NTRACK)**2 + YTRACK(NTRACK)**2 +
ZTRACK(NTRACK)**2)IF (RSTART .LT. ONEONE) THEN
FSTART = ONEONEELSE
FSTART = EXP(-ALAMBDA * RSTART)ENDIFIF (REND .LT. ONEONE) THEN
FEND = ONEONEELSE
FEND = EXP(-ALAMBDA * REND)ENDIFFIMP = FEND / FSTART
CERN FLUKA Users Meeting 19
Neutrino Decay Biasing There is a special routine udcdrl.f where one can bias the
direction of the emitted neutrino in decays.
DOUBLE PRECISION FUNCTION UDCDRL( IJ, KPB, NDCY, UDCDRB, VDCDRB, WDCDRB)
Input variables:IJ decaying particleKPB outgoing neutrino
Output variables:U,V,W DCDRB preferential outgoing direction for the neutrinoUDCDRL Lambda for direction biasing (1-cos())
The biasing expression is of the form:
e-(1-cos/)
Useful for neutrino applications like CNGS, Beta Beams… For a fixed direction the LAM-BIAS card with SDUM=DCY-DIRE
could be used instead
CERN FLUKA Users Meeting 20
Direction Biasing Example (n_TOF) Bias the direction of the neutrino in the pion decay so the
daughter muon to be directed to the exp. area @(-120,0,18500). The direction is given in the lab-frame, and in this example the energies we are dealing are small, so safely we can assume that also in the lab-frame, the neutrino and muon go in opposite directions. The lambda is ¼ wide enough to cover the whole exp area.
Direction in the lab frame
Width [1-cos()]
CERN FLUKA Users Meeting 21
Source routine The user can prepare a biased source.f routine, when needed
to sample from biased distributions Most often encountered to sample from a biased source energy Common use also to sample from a biased spatial and/or angular
distribution Using a two step approach reading particle histories from
another program or another simulation Of course in such cases it is the user’s responsibility to
ensure that weights are adjusted in statistically correct way.
Tip:Tip: The user should assign the correct weight to the primary particles generated by the source routine WTFLK, but it is recommended that the WEIPRI variable which contains the total weight of the primary particles to be increased by one (instead of the weight of the particle WTFLK). At the end of the run the user should renormalize everything to the correct total weight of the primary particles
CERN FLUKA Users Meeting 22
Source: Spatial distribution sampling In this example we want to create a biased-uniform
distribution on a disc surface giving emphasis to the center Sampling from 1/sqrt(r)
= 2 FLRNDM(x)SFE=sin()CFE=cos()
CERN FLUKA Users Meeting 23
Source: Biased energy sampling In this example the energy is given by the tabulated
distribution SPPROT(E). The sampling is divided into two parts below the one using the functions 1/E- and the other as 1/E
CERN FLUKA Users Meeting 24
Sampling from an Existing Event History Applications:
Linking different codes (e.g., tracking and cascade codes) Sampling a particle distribution given as external data file Two-step approach in order to better sample a certain part
of the geometry (e.g., detectors)
It is important to carefully adjust the source particle weight corresponding to the way how the original source was calculated
1) If the first step of a calculation included biasing the weights have to be adjusted accordingly Weight = original_Weight
2) Source particle corresponds to a single original event Weight = 1.0 (or Weight = original_Weight)
3) Selected source particle is only part of the original event Weight = 1.0 / #Particles_per_Event (or Weight = original_Weight / #Particles_per_Event)
CERN FLUKA Users Meeting 25
Important for the Final NormalizationTracking Code Example: Ingredients:
Number of particles tracked (and hypothetically absorbed in all machine components) in the tracking simulations: all_Tracked
Number of particles intercepted by the element(s) of interest: sel_Events
Ratio of particles on the considered machine element(s) sel_Events / all_Tracked
This ratio has then to be used to rescale the respective normalization valid for the required application e.g., particle loss rate (LossRate): Nf =
ppb: particles per bunch #b: number of circulating bunches t: beam lifetime
Final normalization:Nf = LossRate x sel_Events/all_Tracked
CERN FLUKA Users Meeting 26
Sampling from a File - Part 1 using e.g., coordinates generated by tracking codes; 1st loading the
file
* | | Load file given on SDUM of the SOURCE card -> FileName FILEN
WRITE (LUNOUT,*) 'Read source particles from '// FILEN
CALL OAUXFI(FILEN,LUNRDB,'OLD',IERR)
IF ( IERR .GT. 0 )
+ CALL FLABRT('SOURCE','Error opening file '//FILEN)
NIN = 0
10 CONTINUE
READ( LUNRDB, '(A)', ERR=9999, END=20 ) LINE
IF ( LINE(1:1) .EQ. '#' ) GO TO 10
NIN = NIN + 1
IF (NIN.GT.NINMAX) CALL FLABRT('SOURCE','Increase NINMAX')
READ (LINE,*) XIN(NIN), YIN(NIN), ZIN(NIN),
+ UIN(NIN), VIN(NIN)
GOTO 10
20 CONTINUE
WRITE (LUNOUT,*) NIN,' particles loaded'
CLOSE(UNIT=LUNRDB)
Read all coordinates to be sampled from!
CERN FLUKA Users Meeting 27
Sampling from a File - Part 2 2nd sampling it* | Choose a random particle
RNDSIG = FLRNDM (RNDSIG)
N = NINT(NIN*RNDSIG)+1
IF (N.GT.NIN) N=NIN
* TEST BEAM: uncomment the following line
IJIJ = IJBEAM
WEE = BEAWEI
* Cosines (tx,ty,tz)
TXI = UIN(N)
TYI = VIN(N)
TZI = SQRT ( ONEONE - TXI**2 - TYI**2 )
IF (WBEAM.LT.ZERZER) TZI = -TZI
* Particle coordinates
XXX = XIN(N)
YYY = YIN(N)
ZZZ = ZIN(N)
* Energy and Momentum
POO = PBEAM
EKE = SQRT ( PBEAM**2 + AM (IJBEAM)**2 ) - AM (IJBEAM)
ELKE = LOG (EKE)
WTFLK (NPFLKA) = WEE
Select a random particle
Set the direction cosines
The coordinates
+ the energy and momentum
and the weight
CERN FLUKA Users Meeting 28
Bibliography
A Third Monte Carlo Sampler( A revision and Extension of Samplers I and II)C.J. Everett and E.D.CashwellLA-9721-MS, UC-32, March 1983
Application: n_TOF Background
FLUKA Users MeetingCERN 31/05/2007
CERN FLUKA Users Meeting 30
n_TOF Facility
High flux spallation neutron source ~200 m time of flight
Measurements of neutron induced cross-sections ADS applications Astrophysics
Proton Beam CERN-PS: 20 GeV/c, Ip=4 bunches 7 1012 pr / 14.4 s
Neutron Source Features Wide energy range: thermal up to GeV High flux: ~ 6105 n/cm2/7 1012pr @ 200 m Resolution: E/E 210-4 @ 1 keV, 210-3 @ 1 MeV Low background 10-6
FOR MORE INFO...
http://cern.ch/ntof, CERN/LHC/98-02 (EET), CERN/INTC/2000-004, CERN/SPSC 99-8
CERN FLUKA Users Meeting 31
n_TOF Virtual Tour
Lead Container
Sweeping Magnet
2nd Collimator
Exp. Area
CERN FLUKA Users Meeting 32
Background Problem June 2001
Background Features 50 larger than simulations Three time components
400 ns “flash” (after the -flash)
20 s – fast neutrons > 16 ms – thermal neutrons
Position depended Strong Left-Right asymmetry Strong ionization signal Not sample related
CERN FLUKA Users Meeting 33
Background Possible Sources
There were plenty of theories trying to describe the origin: Elements in the neutron Tube
Collimators Escape line
Insufficient concrete shielding in the exp. area Charged Particles deflected from the magnet High energy neutron leaking from the target area …
Challenges: Tiny solid angle Huge attenuation factors
CERN FLUKA Users Meeting 34
Topview of the Simulated Geometry
CERN FLUKA Users Meeting 35
1st Attempt: Elements on the neutron tube
Using a two (three) step approach:1. Simulating only the spallation target. Record particle histories
with a modified FLUSCW.F routine when particles enter in the neutron time of flight tube.
2. Filter particles using a condition of vz/v > cos10o, cos5o, cos1o
bias slightly the direction with preference the element of interest, e.g. 2nd collimator, escape line.
3. Full n_TOF simulation, using as source particles from step 2 Extra Biasing used:
Importance biasing with USIMBS.F subroutine. Increasing a factor of x5 for every 50cm of concrete on the shielding upstream of the experimental area and decreasing downstream
CERN FLUKA Users Meeting 36
USIMBSUsing the USRICALL to set dynamically the filename from the
inputusrini.f
tt2a.inpUSRICALL 1.0 usrbias
The usrbias.dat file defines the Z position of each change in importance, and the importance ratio with the previous Z-section
170.0 5.0175.0 5.0180.0 5.0..200.0 0.2250.0 0.2
CERN FLUKA Users Meeting 37
USIMBS: Loading the file
CERN FLUKA Users Meeting 38
USIMBS: Importance ratio
CERN FLUKA Users Meeting 39
USIMBS: Binary Search
CERN FLUKA Users Meeting 40
1st) Background from NEL & Collimator
Neutron Background from:Neutron Escape Line Collimator
CERN FLUKA Users Meeting 41
2nd Attempt: Fast neutron streaming from the spallation area
There are visible paths where the shielding is not enough
Find weak points in geometry with the use of the RAY particle
CERN FLUKA Users Meeting 42
2nd) Minimum mass calculation Special “simulation” using the RAY particle of FLUKA. RAY is a straight-line trajectory through the geometry. The
program tracks all the objects lying in the given direction calculating a number of various quantities like distance traversed in each material, mass, number of interaction lengths etc…
Using a modified source.f routine a scan was performed on all the possible directions starting from a vertical plane located at Z=+7m (X [-120, 280 cm], Y [-120, 230 cm]), to a vertical plane at Z=+185 m (X [-250, 200 cm], Y [-200, 210 cm]) from the center of the lead target.
500,000 rays were generated scanning the geometry starting from a grid of 1010 on the former plane to a grid of 5050 to the later plane and vice versa.
Recording on a 2D histogram the position for the trajectory were the surface density is minimized.
CERN FLUKA Users Meeting 43
2nd) Minimum Mass Calculation
Revealed paths with minimum mass of 1.4 kg/cm2
Equivalent to 2 GeV/c energy losses for Minimum ionizing particle Minimum ionizing particles like muons could easily penetrate the
experimental area High energy protons could also generate a background
CERN FLUKA Users Meeting 44
3rd) Simulation for High Energy neutrons Starting directly from the protons on the lead target Enabling Leading particle biasing and Weight windows
LAM-BIAS, WW-FACTOr, WW-THRESh Using the USIMBS biasing:
Factor of 2 every 100cm around the spallation area Factor of 2 every 10m in the tunnel (and neutron tube) Factor of 5 every 50cm in the concrete shielding
With LOW-BIAS stop neutrons with E<1MeV in the spallation area
No EMF calculation
CERN FLUKA Users Meeting 45
3rd) Neutron Fluence (per fast neutron)
CERN FLUKA Users Meeting 46
3rd) Muon Fluence
Simulated muon fluence at the entrance of the exp. area per proton pulse of 7 1012 protons
CERN FLUKA Users Meeting 47
1st,2nd,3rd) Results
Bad newsBad newsAll studied possible background sources: Fast neutrons, Neutron Escape line, collimator, gave consistent result of 0.01n/cm2/pulse in the experimental area. 50-100 times lower than what was measured
Good NewsGood NewsStrong muon component, that can explain the ionization signal measured with the TLD’s and the strong asymmetry left/right in the tunnel (fast-flash signal)
Last hopeLast hopeFollowing the disappointing results from all previous efforts, last resource was to leave running the simulation as long as possible, searching blindly using brute force. 8 CPU’s
CERN FLUKA Users Meeting 48
Nice Surprise After ~few weeks x 8 CPU’s of simulation one event
appeared with ~100 times higher importance than the rest.
To identify the origin of the event we needed to record the history of all particles reaching the exp. area. This includes tracking information (which regions traverse), last interaction point, last decay point (if any), parent id, energy etc.
CERN FLUKA Users Meeting 49
Recording particle history (stuprf.f)Extra USER informationfor each particle ISPARK: array of integersSPAREK: array of floating point
CERN FLUKA Users Meeting 50
Write to file history info (fluscw.f)Note the change of nameSPAREK SPAUSRISPARK ISPUSR
CERN FLUKA Users Meeting 51
Identification of the event The event was identified as a ~1 MeV neutron generated in the
concrete surrounding the experimental area, originated from a negative muon being stopped at the experimental area, generated by a pion decay
Neutron generation by muons is a known process, important for underground sites or atmospheric showers at ground level where muons:
Photo-nuclear interactions via virtual photons Negative muon capture with - brought to rest through the weak process
The former process involves muons of (relatively) high energy and has a mean free path of a few hundred meters in earth (not important for n_TOF).
Negative muon capture occurs when - brought to rest is captured forming muonic atom. The capture usually occurs in a relatively loosely bound state and then the muon jumps into progressively deeper levels emitting hard x-rays. Due to the mass being much larger than the electron one, the muon wave functions are significantly overlapping the nucleus, and nuclear capture becomes competitive with decay.
The assumptions used in FLUKA simulation models predict that ~50% of - stopping in concrete undergo nuclear capture. Experimental spectra of neutrons emitted following - captures show an evaporation peak, plus a low intensity tail extending up to several tens of MeV.
CERN FLUKA Users Meeting 52
Muons arriving at Exp. Area
Blue: Decay Position
Red: Inelastic reaction where the parent of muon was created
CERN FLUKA Users Meeting 53
Biasing to enhance the - captureKnowing the origin of the problem a more sophisticated biasing
wasintroduced to enhance the muon fluence at the experimental
area.
Keep all previous settings of the high energy neutron biasing Forcing the decay of the parent pions every one meter, to
increase the number of muons arriving at the experimental area
Reducing (Increasing) the mean life of the muons by a factor of 0.01, to enhance the capture probability versus the muon decay.
CERN FLUKA Users Meeting 54
Muon direction (udcdrl.f)Biasing the direction of the neutrino from the pion decay such as the daughter muon to go in the direction of the experimental area with the routine UDCDRL
Direction in the lab frame
Width [1-cos()]
CERN FLUKA Users Meeting 55
Neutron Fluence at Exp. Area
Computed neutron fluence (n/cm2) inside the experimentalarea (topview) for a standard pulse of 71012 protons
CERN FLUKA Users Meeting 56
Background neutron sources
CERN FLUKA Users Meeting 57
Neutron Time Distribution
CERN FLUKA Users Meeting 58
Possible Remedies
Stop the parent pions Iron & Concrete shielding near the target area
Stop the muons Place iron shielding near the target area Iron shielding after the sweeping magnet
Absorb the neutron in the experimental area Use borated polyethylene lining
CERN FLUKA Users Meeting 59
The 3m “muon” wall The simulation results have clearly demonstrated the
ineffectiveness of a possible wall close to the target area: 50% of parent pions are still in the tube at the exit of the
target shielding 10% of muons/parent pions are still in the tube as far as
60 m from the target Therefore a suitable shielding should be located where
the fraction of muons/pions in the pipe is minimal or just after the sweeping magnet
3 m of Iron will lower the muon energy of 3.5 GeV
CERN FLUKA Users Meeting 60
Muon wall effectiveness
CERN FLUKA Users Meeting 61
Final Reduction