Warning, /geant4/examples/extended/eventgenerator/particleGun/README is written in an unsupported language. File is not indexed.
0001 -------------------------------------------------------------------
0002
0003 =========================================================
0004 Geant4 - an Object-Oriented Toolkit for Simulation in HEP
0005 =========================================================
0006
0007 ParticleGun
0008 -----------
0009
0010 History:
0011 10-06-2010 : Makoto Asai - merge into one example
0012 13-05-2010 : Michel Maire - create as three examples
0013
0014 This example demonstrates 5 ways of the use of G4ParticleGun shooting
0015 primary particles in different cases. These are
0016 0) uniform particle direction in a given solid angle
0017 1) Generate several vertices and particles per event
0018 2) Show how to sample a tabulated function (eg. energy spectrum)
0019 3) Divergent beam in an arbitrary direction
0020 4) Shooting primaries in spherical coordinates with rotation matrix.
0021
0022 These use cases can be chosen by a UI command
0023 /gunExample/selectGunAction <actionID>
0024 where <actionID> corresponds to the above cases.
0025
0026 1- Geometry construction
0027 ---------------------
0028
0029 It is a simple box which represents an 'infinite' homogeneous medium.
0030
0031 2- Physics list
0032 ------------
0033
0034 PhysicsList.cc defines only geantino and transportation process.
0035
0036 3- Primary generator
0037 -----------------
0038
0039 There are 5 concrete primary generator action classes
0040 (PrimaryGeneratorActionN, N=0,1,2,3,4) which can be used as an independent sample
0041 code.
0042 PrimaryGeneratorAction is the class which uses and switches between these
0043 5 concrete action classes. Each concrete generator action shoots geantinoes
0044 in a distribution decribed below.
0045
0046 3.0- uniform particle direction in a given solid angle
0047 -------------------------------------------------
0048 spherical angles (alpha,psi) respective to z axis
0049 Histograms 5,6 show momentum direction in master frame.
0050
0051 3.1- Generate several vertices and particles per event
0052 -------------------------------------------------
0053
0054 particle 1 : a geantino uniformly randomized on a cylinder surface.
0055 particle 2 and 3 : symetric to particle 1.
0056 In addition, time_zero of each event is randomized.
0057
0058 3.2- Show how to sample a tabulated function (energy spectrum)
0059 ---------------------------------------------------------
0060
0061 Energy is sampled from a tabulated function defined in InitFunction().
0062 The function is assumed positive, linear per segment, continuous.
0063 Two sampling methods are illustrated : RejectAccept() and InverseCumul()
0064 (see Particle Data Group: pdg.lbl.gov --> Monte Carlo techniques)
0065 Histogram 1 shows generated energy spectrum.
0066
0067 3.3- Divergent beam in an arbitrary direction with rotation matrix
0068 -------------------------------------------------------------
0069
0070 A geantino uniformly randomized around a given direction (theta, phi).
0071 One wants to limit particle direction uniformly around this direction.
0072 First, one generates momentum direction in the master frame (eg. World).
0073 AlphaMax = opening angle around z axis.
0074 Then one rotates momentum in local frame, using rotateUz() function.
0075 RotateUz() transforms uz to newUz. It is composition of two simple rotations:
0076 theta around oy, then phi around oz (non commutative).
0077 http://proj-clhep.web.cern.ch/proj-clhep/manual/UserGuide/VectorDefs/node49.html
0078 Histograms 5,6 show momentum direction in local frame.
0079
0080 3.4- Shooting primaries in spherical coordinates with rotation matrix
0081 ----------------------------------------------------------------
0082
0083 a geantino uniformly randomized within a spherical shell.
0084
0085 a) Vertex position
0086 One wishes to shoot uniformly within a spherical shell.
0087 One works in spherical coordinates. One uses inverse cumulative method with
0088 analytical formulae.
0089 Histograms 2,3,4 demonstrate uniform distribution of vertex position.
0090
0091 b) Momentum direction
0092 One wants to limit particle direction uniformly within (alphaMin, alphaMax).
0093 First, one generates momentum direction in the master frame (eg. World).
0094 Then, one rotates momentum in vertex_position frame, using rotateUz() function.
0095 RotateUz() transforms uz to ur. It is composition of two elementary rotations:
0096 theta around oy, then phi around oz (non commutative).
0097 http://proj-clhep.web.cern.ch/proj-clhep/manual/UserGuide/VectorDefs/node49.html
0098 Histograms 5,6 show momentum direction in vertex_position frame.
0099
0100 4- Visualisation
0101 -------------
0102
0103 Visualization Manager is set in the main().
0104 Initialisation of the drawing is done via the commands
0105 /vis/.. in the macro vis.mac. This macro is automatically read from the main
0106 in case of interactive running mode.
0107
0108 5- How to start ?
0109 --------------
0110
0111 - execute particleGun in 'batch' mode from macro files
0112 % ParticleGun run1.mac
0113
0114 - execute particleGun in 'interactive mode' with visualization
0115 % particleGun
0116 ....
0117 Idle> ---> type your commands. For instance:
0118 Idle> /gunExample/selectGunAction 1
0119 Idle> /run/beamOn 10
0120 ....
0121 Idle> exit
0122
0123 - Macros provided in this example:
0124 - run0.mac: see above primaryGenerator, case 0
0125 - run1.mac: see above primaryGenerator, case 1
0126 - run2.mac: see above primaryGenerator, case 2
0127 - run3.mac: see above primaryGenerator, case 3
0128 - run4.mac: see above primaryGenerator, case 4
0129 - particleGun.in: macro used in Geant4 testing (similar to run0.mac)
0130
0131 6- Histograms
0132 ----------
0133
0134 particleGun produces several 1D histograms which are saved as
0135 particleGun.root by default.
0136
0137 1 : energy spectrum dN/dE = f(E)
0138 2 : vertex position: radial distr dN/dv = f(r)
0139 3 : vertex position: cos(theta)
0140 4 : vertex position: phi
0141 5 : particle direction in local frame: cos(alpha)
0142 6 : particle direction in local frame: psi
0143
0144 Please note that histogram 1 will be filled only if you use
0145 PrimaryGeneratorAction2, histos 5,6 with PrimaryGeneratorAction0 and 3
0146 and 2 through 6 will be filled with PrimaryGeneratorAction4.
0147
0148 The histograms are managed by the HistoManager class and its Messenger.
0149 The histos can be individually activated with the command :
0150 /analysis/h1/set id nbBins valMin valMax unit
0151 where unit is the desired unit for the histo (MeV or keV, deg or mrad, etc..)
0152
0153 One can control the name of the histograms file with the command:
0154 /analysis/h1/setFileName name (default particleGun)
0155
0156 It is possible to choose the format of the histogram file : root (default),
0157 xml, csv, by using namespace in HistoManager.hh
0158
0159 It is also possible to print selected histograms on an ascii file:
0160 /analysis/h1/setAscii id
0161 All selected histos will be written on a file name.ascii (default gunExample)