the monte carlo method - pavia fisica home pagefontana/download/lect/cadi7.pdf · the central...
TRANSCRIPT
The Monte Carlo method
Invented by John von Neumann, Stanislaw Ulam and
Nicholas Metropolis (who gave it its name), and
independently by Enrico Fermi
N. Metropolis S. Ulam J. von Neumann E. Fermi
The ENIACElectronic Numerical Integrator And Computer
Simulation?
What is the Monte Carlo method?
Originally it was not a simulation method, but a device to
solve a multidimensional integro-differential equation by
building a stochastic process such that some parameters
of the resulting distributions would satisfy that equation
The equation itself did not necessarily refer to a physical
process, and if it did, that process was not necessarily
stochastic
Simulation Calculations28
Integration efficiency
• Traditional numerical integration methods (e.g., Simpson) converge to the true
value as N-1/n, where N = number of “points” (intervals) and n = number of
dimensions
• Monte Carlo converges as N-1/2, independent of the number of dimensions
• Therefore:
n = 1 MC is not convenient
n = 2 MC is about equivalent to traditional methods
n > 2 MC converges faster (and the more so the greater the dimensions)
• With the integro-differential Boltzmann equation the dimensions are the 7 of
phase space, but we use the integral form: the dimensions are those of the largest
number of “collisions” per history (the Neumann term of highest order) • Note that the term “collision” comes from low-energy neutron/photon transport
theory. Here it should be understood in the extended meaning of “interaction where the particle changes its direction and/or energy, or produces new particles”
Simulation? In special cases
• It was soon realized, however, that when the
method was applied to an equation describing a
physical stochastic process, such as neutron
diffusion, the model (in this case a random walk)
could be identified with the process itself
• In these cases the method (analog Monte Carlo)
has become known as a simulation technique,
since every step of the model corresponds to an
identical step in the simulated process
Simulation Calculations29
Random sampling: the key to Monte Carlo
The central problem of the Monte Carlo method:
Given a Probability Density Function (pdf), f(x), generate a sample of x’s distributed according to f(x) (x can be multidimensional)
f(x)
x
The use of random sampling techniques is the distinctive feature of Monte Carlo
Solving the integral Boltzmann transport equation by Monte Carlo consists of:
• Geometry and material description of the problem
• Random sampling from probability distributions of the outcome of physical events
Simulation Calculations30
(Pseudo)random numbers
• The basis of all Monte Carlo integrations are random numbers, i.e. random
values of a variable distributed according to a pdf
• In real world: the random outcomes of physical processes
• In computer world: pseudo-random numbers
• The basic pdf is the uniform distribution:
101)( f• Pseudo-random numbers (PRN) are sequences that reproduce the uniform
distribution, constructed from mathematical algorithms (PRN generators). A
PRN sequence looks random but it is not: it can be successfully tested for
statistical randomness although it is generated deterministically
• A pseudo-random process is easier to produce than a really random one, and
has the advantage that it can be reproduced exactly
• PRN generators have a period, after which the sequence is identically
repeated. However, a repeated number does not imply that the end of the
period has been reached. Some available generators have periods >1061
Numeri casualiSimulazione di processi fisici -> generazione di numeri casuali con distribuzione uniforme nell’ intervallo [0,1].Sequenza di numeri casuali: - non prevedibile;- non riproducibile.Esempi in natura: decadimento radioattivo di nuclei instabili,
rumore termico di apparecchiatura elettronica…Come fare per ottenere sequenze di numeri casuali (o random)?- misurare fenomeni naturali casuali: poco pratico - usare calcolatori per memorizzare tabelle precalcolate: uso di spazio in memoria - usare calcolatori collegati a strumenti: richiede tempo Generazione di numeri “casuali” con algoritmi matematici!
Numeri pseudocasualiSequenze di numeri generate al calcolatore: sono sempre prevedibili ed esattamente riproducibili (seme), ma hanno le stesse proprieta’ delle sequenze casuali vere.Generatori di numeri casuali: funzioni disponibili in ogni linguaggio di programmazione (C, C++, Fortran) per generare sequenze pseudocasuali con algoritmi matematici. Vari metodi disponibili:
metodo del medio quadrato(J. von Neumann, fine 2^a G.M.) metodi congruenziali
(vari autori, anni ’60-’80) metodo di Fibonacci
Metodo del medio quadratoOgni numero della sequenza e’ generato elevando al quadratoil predecessore e prendendo le cifre di mezzo del risultato.Lavorando con 4 cifre e partendo da x0=5678, si ha:x0=5678 (x0^2=32239684) x1=2396 (x1^2=05740816)x2=7408 …Caratteristiche delle sequenze pseudocasuali:- ogni numero viene ricavato da quello precedente e, se un numero ricompare nella sequenza, tutti i numeri successivi vengono ripetuti (periodo di ogni algoritmo)- la correlazione tra i numeri non e’ mai nulla.
Metodo congruenzialeOgni numero della sequenza e’ generato a partire da altri trenumeri: m (modulo), a (incremento) e x0 (valore iniziale), secondo il seguente schema:
xi a xi1modmi xi/mMetodo di Fibonacci
Ogni elemento della sequenza e’ la somma dei due elementiprecedenti (routine RANLUX della libreria del CERN).Esempio con a=5, x0 =1 e m=64:1,5,25,61,49,53,9,45,33,37,57,29,17,21… (sempre dispari!)
Tests di casualita’Non tutte le sequenze sono equivalenti: in generale, anche a parita’ di algoritmo, si hanno sequenze differenti su calcolatori differenti ed esistono sequenze di numeri pseudocasuali che sono “migliori” o “piu’ casuali” di altre.
Misura del periodo Test di compatibilita’ statistica Test sulla media di N numeri pseudocasuali:semplice controllo per generatore uniforme Test di equidistribuzione: reale uniformita’dei numeri generati Test seriale: reale uniformita’ di coppie di numeri generati Test del gap: la distanza tra due numeri uguali nella sequenza segue una distribuzione geometrica Test del poker: controllo su numeri uguali entro quintuple casuali consecutive
Programmi Classi di ROOT: Trandom, TRandom1, TRandom2, TRandom3 Period (macro ROOT e eseguibile compilato) Uniform UniTest: gap + poker UniTest ridotto Langton Drunken Buffon Central Sfera Rigetto Phasespace
TRandomTRandom1
TRandom2TRandom3
Distribuzione uniformeSemplice test da fare su un calcolatore: generare N numeripseudocasuali secondo la distribuzione uniforme e stimaremedia e deviazione standard con errori e CL gaussiani.Entro 1s,la statistica di base prevede che le stime di media m e deviazione standard s per dati che provengono da distribuzioni qualunque siano: 1)(N4s sDs Nsm 2 44
con livelli di confidenza gaussiani. D4 e’ il momento di quarto ordine della distribuzione: i 4i4 m)(xN1D
Risultati del test sulla mediastatistica: 10000m(em)=0.499446(0.00285817)intervallo: 0.496587-0.502304 esatto: 0.5s(es)=0.285817(0.00453816) intervallo: 0.281278-0.290355 esatto: 0.288675Sequenza Istogramma
Risultati del test del gapLa probabilita’ pr di avere un gap di lunghezza r e’ data da:rr p)(1pp
cioe’ segue una distribuzione geometrica.Gap tra gli “0”di un sequenza casuale di numerinell’ intervallo[0,9].
Test del pokerSi considerano N gruppi consecutivi di 5 interi consecutivie si cerca in quale categoria cade ogni quintupla consideratain base al numero di valori distinti in essa contenuti:5 tutti diversi a,b,c,d,e4 coppia a,a,b,c,d3 doppia coppia o tris a,a,b,b,c o a,a,a,b,c2 full o poker a,a,a,b,b o a,a,a,a,b1 colore a,a,a,a,aSi conta il numero di occorrenze di ogni quintupla e si confrontano le distribuzioni con le probabilita’ teoriche (note esattamente dal calcolo combinatorio).
Teoria del pokerProbabilita’ che, considerati N gruppi di k numeri successivi(tra d elementi), in uno di essi ci siano r numeri diversi:
rkd 1)r1)...(dd(dp kr Coefficiente di Stirling (tabulato):numero di ripartizioni di un insieme di k oggetti in r parti. kd 1)r1)...(dd(d
rk Disposizioni con ripetizione di d oggetti in classe k (in gruppi di k). Numero di scelte ordinate di r oggettidiversi da un insieme di d oggetti.dal Knuth
Risultati del test del pokerPer il poker con 10 cifre [0,9] e gruppi di 5 cifre si ha: d=10, k=5 e r=5,4,3,2,1.Usando il generatore di numeri casuali uniforme del C++, si ottengono, con una statistica di 200000 quintuple, questi risultati:N=200000 dato teoriatutti diversi 60803 60480coppia 100722 100800doppia coppia/tris 35802 36000full/poker 2650 2700colore 23 20
Altre distribuzioni casualiGrazie al teorema della distribuzione cumulativa, se X e’ una variabile aleatoria con densita’ qualunque p(x), la variabile aleatoria cumulativa C:
Xp(x)dxC(X)
e’ uniforme nell’ intervallo [0,1].
Se l’ integrale e’ noto in modo analitico, si puo’ scrivere:Usando un generatore casuale uniforme su un calcolatore, si possono generare variabili aventi una densita’ qualsiasi usandol’ equazione: (random)FX 1
F(x)c
La Formica di LangtonUna formica cammina su una grande griglia di quadrati, inizialmente tutti bianchi. Quando la formica arriva su un quadrato bianco, lo colora di nero e gira a destra. Quandoarriva su un quadrato nero, lo colora di bianco e gira a sinistra.Per circa 10000 passi, la formica continua a girare, tornando sui propri passi e creando questa distribuzione di punti apparentemente caotica. Ma a un certo punto, crea un percorso chiuso lungo un’ “autostrada” e riesce a scappare!
Primi passi della Formica
La Formica ubriacaUna delle molte possibili varianti della formica, con un elemento casuale (random walker):la formica adesso ha una moneta con se e la lancia ad ogni passo: se esce testa, gira a destra, mentre se esce croce gira a sinistra. Inoltre, se la casella e’ bianca la colora di nero e viceversa. Il moto risultante e’ (ad esempio) il seguente:La formica non sembra
finire piu’ in un “loop” e cammina proprio a caso, come se fosse ubriaca!
Tests di casualita’ e FormicheVogliamo verificare se le sequenze di numeri (che ne rappresentano il moto) generate dalle due formiche sono generate in modo casuale oppure no.Due possibilita’ (coincidenti per Langton): a. Sequenza di 0 e 1 a seconda che la formica colori la casella di nero o di bianco (rispettivamente).b. Sequenza di 0 e 1 a seconda che la formica giri a destra o a sinistra (rispettivamente).Esempio di sequenza da studiare:
0,0,1,1,0,1,1,0,1,1,0,0,0,0,1,1,0,0,0,1,0,1,1,0…
Test di frequenza e FormicheLangton UbriacaNon uniforme e correlatoal colore iniziale del foglio. Uniforme
Test del gap e FormicheLangton Ubriaca
Il poker delle Formiche!Per il poker con 2 cifre [0,1] e gruppi di 5 cifre si ha: d=2, k=5 e r=3,2,1.Infatti, in questo poker semplificato, sono definibili solo full, poker e colore.N=20000 dato teoriafull 12578 12500poker 6175 6248colore 1247 1248 Risultati del test del poker ridotto per il generatoreuniforme del C++.full: 00111 00011poker: 01111 00001colore: 00000 11111
Test del poker e FormicheLangtonUbriacaN=11654 dato teoriafull 1197 1457poker 1133 728colore 0 145N=13879 dato teoriafull a. 1507 b. 1716 1735poker a. 887b. 874 867colore a. 381b. 165 173Probabilita’ teoriche date da legge binomiale:full 0.3125 (x2)poker 0.1562 (x2)colore 0.0312 (x2)
Caso o Caos?Formica di Langton: sistema non casuale che fallisce i tests statistici di casualita’.Comportamento caotico.Formica ubriaca: sistema casuale, governato dalle leggi della statistica, che puo’ presentare
proprieta’ non casuali in casi particolari.Occorre discriminare tra distribuzioni casuali (cioe’ non deterministiche) e distribuzioni caotiche (ma deterministiche):distribuzioni di punti “disordinate”, apparentemente simili, possono in realta’ essere molto diverse.Caos e Caso sono concetti molto diversi, ma e’ difficile capire dove sta il confine che li separa: i tests di casualita’ sono uno strumento che ci puo’ aiutare…
Logistic Map
Logistic Map
Logistic Map
Logistic Map
Un paio di articoli interessanti
Simulation Calculations18
Phase Space
• Phase Space: a concept of classical Statistical Mechanics
• Each Phase Space dimension a particle degree of freedom
• 3 dimensions correspond to Position in (real) space: x, y, z
• 3 dimensions correspond to Momentum: px, py, pz
(or Energy and direction: E, θ, φ)
• More dimensions, corresponding to other possible degrees of freedom: quantum numbers (e.g. spin), particle type...
• Each particle is represented by a point in phase space
• Time can also be considered as a coordinate, or it can be considered as an independent variable: the variation of the other phase space coordinates as a function of time (the trajectory of a phase space point) constitutes a particle ”history''
n-Particle Phase space, n=32 Observables
– From four vectors 12
– Conservation laws -4
– Meson masses -3
– Free rotation -3
– Σ 2
Usual choice
– Invariant mass m12
– Invariant mass m13
π3
π2pp
π1
Dalitz plot
Interference problem
PWA
– The phase space diagram in hadron physics shows a patterndue to interference and spin effects
– This is the unbiased measurement
– What has to be determined ?
Analogy Optics PWA
– # lamps # level
– # slits # resonances
– positions of slits masses
– sizes of slits widths
– bias due to hypothetical spin-parity assumption
Optics
I(x)=|A1(x)+A2(x)e-iφ|2
Dalitz plot
I(m)=|A1(m)+A2(m)e-iφ|2
but only if spins
are properly assigned
It’s All a Question of Statistics ...pp 3p0
with
100 events
It’s All a Question of Statistics ... ...pp 3p0
with
100 events
1000 events
It’s All a Question of Statistics ... ... ...
pp 3p0
with
100 events
1000 events
10000 events
It’s All a Question of Statistics ... ... ... ...
pp 3p0
with
100 events
1000 events
10000 events
100000 events
Particle transport• Particle transport is a typical physical process described by probabilities
(cross sections = interaction probabilities per unit distance)
• Therefore it lends itself naturally to be simulated by Monte Carlo
• Many applications, especially in high energy physics and medicine, are based on simulations where the history of each particle (trajectory, interactions) is reproduced in detail
• However in other types of application, typically shielding design, the user is interested only in the expectation values of some quantities (fluence and dose) at some space point or region, which are calculated as solutions of a mathematical equation
• This equation (the Boltzmann equation), describes the statistical distribution of particles in phase space and therefore does indeed represent a physical stochastic process
• But in order to estimate the desired expectation values it is not necessary that the Monte Carlo process be identical to it
Particle transport Monte Carlo
Assumptions made by most MC codes:• Static, homogeneous, isotropic, amorphous media and geometry
Problems: e.g. moving targets, atmosphere must be represented by discrete
layers of uniform density, radioactive decay may take place in a geometry different from that in which the radionuclides were produced
• Markovian process: the fate of a particle depends only on its actual present properties, not on previous events or histories
• Particles do not interact with each otherProblem: e.g. the Chudakov effect (charges cancelling in e+e– pairs)
• Particles interact with individual electrons / atoms / nuclei / moleculesProblem: invalid at low energies
• Material properties are not affected by particle reactionsProblem: e.g. burnup
Particle transport
Application of Monte Carlo to particle transport and interaction:
• Each particle is followed on its path through matter
• At each step the occurrence and outcome of interactions are decided by random selection from the appropriate probability distributions
• All the secondaries issued from the same primary are stored in a “stack” or “bank” and are transported before a new history is started
• The accuracy and reliability of a Monte Carlo depend on the models or data on which the probability distribution functions are based
• Statistical accuracy of results depends on the number of “histories"
• Statistical convergence can be accelerated by “biasing" techniques.
Analog vs non-analog simulation
Analogue vs non-analogue• What is analogue simulation ?
– Sample using natural probability distribution, N(x)– Predicts mean with correct fluctuations– Can be inefficient for certain applications
• What is non-analogue/event biased simulation ?– Cheat - apply artificial biasing probability distribution, B(x) in place of natural one, N(x)
• B(x) enhances production of whatever it is that is interesting• To get meaningful results, must apply a weight correction
– Predicts same analogue mean with smaller variance• Increases efficiency of the Monte Carlo
– Does ’t predi t orre t flu tuatio s– Should be used with care
Monte Carlo Flavors: microscopic
Microscopic Analog Monte Carlo
• Uses theoretical models to describe physical processes whenever possible
• Samples from actual physical phase space distributions
• Predicts average quantities and all statistical moments of any order
• Preserves correlations (provided the physics is correct, of course!)
• Reproduces fluctuations (provided. . . see above)
• Is (almost) safe and (sometimes) can be used as a “black box" (idem)
But:• Can be inefficient and converge slowly• Can fail to predict contributions due to rare events
Monte Carlo Flavors: macroscopic
Macroscopic Monte Carlo:
• Instead of simulating interactions, use parametrizations of the reaction product distributions, obtained from fits to data and extrapolations
• Fast, especially when reactions are complex
• Can be more accurate than microscopic MC if the theory contains uncertainties/approximations
But:
• The single probability distribution functions are reproduced, but the correlations among interaction products are not
• Cannot be extended outside the data range
Monte Carlo Flavors: biasedBiased Monte Carlo:
• samples from artificial distributions, and applies a weight to the particles to correct for the bias (similar to an integration by a change of variable)
• predicts average quantities, but not the higher moments (on the contrary, its goal is to minimize the second moment!)
• same mean with smaller variance faster convergence
• allows sometimes to obtain acceptable statistics where an analog Monte Carlo would take years of CPU time to converge
But:• cannot reproduce correlations and fluctuations
• only privileged observables converge faster (some regions of phase space are sampled more than others)
Results from a MC calculation
EstimatorsIt is often said that Monte Carlo is a “mathematical experiment”. Each aspect of a real experiment has its Monte Carlo equivalent:
Experimental technique EstimatorInstrument DetectorMeasurement Score, or TallyResult of an experiment Monte Carlo result
Just as a real measurement, a score is obtained by sampling from a statistical distributionAs an experimental result consists in an average of the measurements, a statistical error and a systematic error, a MC result is an average of scores, a statistical error (and a systematic error, generally unknown)There are often several different techniques to measure the same physical quantity: in the same way the same quantity can be calculated with different kinds of estimators
Estimator types
Various types of estimators, depending on the quantity to be estimated andon the topology (phase space region over which the quantity is integrated)
Boundary Crossing.Quantity: the fluence or the current of particles Phase space: a physical boundary between two space regions. Result: mono or multi-differential fluence spectra, function of energy,
angle, particle type, … Track length.
Quantity: the fluence of particles Phase space: a region of real spaceResult: fluence spectra as a function of particle energy , based on the
path length of the particles within the region volume
Estimator typesPulse-height detector (e.g. simulation of a Ge spectrometer):
Quantity: energy deposited Phase space: a region of real space Result: spectrum of deposited energy within the region volume
Scalar integral estimator: Quantity: deposited energy, inelastic interactions (stars), activity... Phase space: a region of real space Result: amount of given quantity (or its density) within the volume
Mesh: Quantity: fluence, energy deposition, stars…Phase space: regular subdivision of a portion of real space in sub-
volumes, generally independent from the tracking geometry
Result: a 2D or 3D spatial distribution of the estimated quantity
Estimator Extensions
Most Monte Carlo codes have built-in estimators, to be activated and
tailored by the user. The results are usually averaged over one run and
normalized to one primary particle. Additional flexibility can be achieved
by:
Convolution off-line or on-line. For instance: convolution of
differential fluence with energy-dependent conversion factors to
obtain effective dose or ambient dose equivalent
Event-by-event estimators for correlated data analysis
Full or partial dumping of events: steps, interactions, etc, for off-line
analysis. To be used only if absolutely necessary
Detectors
While an estimator is a technique to “measure” a certain quantity, a detector is an instantiation (a concrete application) of an estimator in a particular region of phase space. For instance:
Estimator Quantity Detector
Tracklength est. Fluence A sphere of radius 10 cm centered at 8, 43, 9
Often a MC user wants to get a result at one or more detectors, and has no interest
in what happens elsewhere. In this case, biasing can be used to accelerate
convergence near a detector, at the expense of other parts of phase space. (But if
biasing is done correctly, for N → ∞ the integration will converge to the true value everywhere, although at a different speed)
Thanks to the modern fast computers, however, it has often become possible to
obtain a good result with a multiple detector covering a large region of real space: a
mesh detector. This kind of detector can be very useful to identify shielding weaknesses in unexpected places
Statistical Errors
The variance of the mean of an estimated quantity x (e.g., fluence), calculated in N batches, is:
mean of squares – square of means
N – 1
where:ni = number of histories in the i th batchn = Σni = total number of histories in the N batchesxi = average of x in the i th batch:
In the limit N = n, ni =1, the formula applies to single history statistics
2
1
2
12
1
1
n
xn
n
xn
N
N
iii
N
i
x
in
ji
ij
in
xx
1
Statistical Errors
• Can be calculated for single histories, or for batches of several histories each (not necessarily the same identical number)
• Distribution of scoring contributions by single histories can be very asymmetric (many histories contribute little or zero)
• Scoring distribution from batches tends to Gaussian for N , provided 2 . (Central Limit Theorem)
• The standard deviation of an estimator calculated from batches or from single histories is an estimate of the standard deviation of the actual distribution (“error of the mean”)
• How good is such an estimate depends on the type of estimator and on
the particular problem (but it converges to the true value for N )
Statistical Errors
Practical tips:
• Use always at least 5-10 batches of comparable size (it is not at all
mandatory that they be of equal size)
• Never forget that the variance itself is a stochastic variable subject to
fluctuations
• Be careful about the way convergence is achieved: often (particularly
with biasing) apparently good statistics with few isolated spikes could
point to a lack of sampling of the most relevant phase-space part
• Plot 2D and 3D distributions! In those cases the eye is the best tool in
judging the quality of the result
Statistical errors, systematic errors, and... mistakes
Statistical errors, due to sampling (in)efficiencyRelative error Quality of Tally (from the MCNP Manual)
50 to 100% Garbage
20 to 50% Factor of a few
10 to 20% Questionable
< 10% Generally reliable except for point detectors
< 5% Generally reliable for point detectors
Why does a 30% σ mean an uncertainty of a “factor of a few”?Because σ in fact corresponds to the sum (in quadrature) of two uncertainties:
one due to the fraction of histories which give a zero contribution, and one which reflects the spread of the non-zero contributions
The MCNP guideline is empirically based on experience, not on a mathematical proof. But it has been generally confirmed also working with other codes
Small penetrations and cracks are very difficult to handle by MC, because the
“detector” is too small and too few non-zero contributions can be sampled, even by biasing
Statistical errors, systematic errors, and... mistakes
Systematic errors, due to code weaknessesApart from the statistical error, which other factors affect the accuracy of MC results?
• physics: different codes are based on different physics models. Some models are better than others. Some models are better in a certain energy range. Model quality is best shown by benchmarks at the microscopic level (e.g. thin targets)
• artifacts: due to imperfect algorithms, e.g., energy deposited in the middle of a step, inaccurate path length correction for multiple scattering, missing correction for cross section and dE/dx change over a step, etc. Algorithm quality is best shown by benchmarks at the macroscopic level (thick targets, complex geometries)
• data uncertainty: an error of 1% in the absorption cross section can lead to an error of a factor 2.8 in the effectiveness of a thick shielding wall (10 attenuation lengths). Results can never be better than allowed by available experimental data!
Statistical errors, systematic errors, and... mistakes
Systematic errors, due to user ignoranceMissing information:
• material composition not always well known. In particular concrete/soil composition (how much water content? Can be critical)
• beam losses: most of the time these can only be guessed. Close interaction with engineers and designers is needed
• presence of additional material, not well defined (cables, supports...)
• Is it worth to do a very detailed simulation when some parameters are unknown or badly known?
Systematic errors, due to simplificationGeometries that cannot be reproduced exactly (or would require too much effort)Air contains humidity and pollutants, has a density variable with pressure
Statistical errors, systematic errors, and... mistakes
Code mistakes (“bugs”)MC codes can contain bugs:
• Physics bugs: I have seen pair production cross sections fitted by a
polynomial... and oscillating instead of saturating at high energies, non-uniform azimuthal scattering distributions, energy non-conservation...
• Programming bugs (as in any other software, of course)
User mistakes
mis-typing the input: some codes are more or less good at checking, but the final responsibility is the user’serror in user code: use the built-in features as much as possible
wrong units
wrong normalization: quite common
unfair biasing: energy/space cuts cannot be avoided, but must be done with much care
forgetting to check that gamma production is available in the neutron cross sections
Some of the most popular codes
EGS5: http://rcwww.kek.jp/research/egs/egs5.html
EGSnrc: http://www.irs.inms.nrc.ca/EGSnrc/EGSnrc.html
FLUKA : http://www.fluka.org (multiparticle)
Geant4: http://www.geant4.org (multiparticle)
MARS: http://www-ap.fnal.gov/MARS (multiparticle)
MCNP: http://mcnp-green.lanl.gov (neutrons, e- e+ γ)MCNPX: http://mcnpx.lanl.gov (multiparticle)
PENELOPE: http://www.nea.fr/abs/html/nea-1525.html (e- e+ γ)PHITS: http://phits.jaea.go.jp (multiparticle)
TRIPOLI: http://www.nea.fr/abs/html/nea-1716.html (neutrons, e- e+ γ)
Specialized:
CORSIKA: http://www-ik.fzk.de/corsika (cosmic rays)
PEREGRINE: https://www.llnl.gov/str/Moses.html (radiotherapy)
(e- e+ γ)