Two-Stage Analysis¶
Warning
UNDERGOING MODIFICATION
Two-Stage analysis (TSA) is a variance reduction method which can be employed in simulation cases where radiation transport through a large scale geometry down to very small but very complex local systems is required. In this method, the radiation is first propagated to the surface of one or more system/instrument enclosures, or some external boundary to those enclosures, within the larger overall geometry setup. Then a series of second simulations are performed to quantify the particle environment for internal components which can be modelled in greater details. Options are included in the second stage to:
Allow the simulation to be performed on the equipment subsystem rather than the complete spacecraft geometry if preferred. The only requirement is that the “source” volume on which the particles are started in the second stage is identical in shape and dimensions as the “detect” volume from the first stage.
The physical volume for the “source” and “detect” volume can be any type. However, if it is derived from a G4Box, G4Tubs or G4Sphere, it is possible to perform position resampling (“dithering”) over a grid on the surface of the volume.
The directions of the particles in the second stage can be resampled, with constraints applied by the user to control the maximum angle of deviation from the original particle directions.
Each particle from the first stage can be resampled multiple times with “dithering” applied in position and direction from the surface of the “source” volume.
Although the technique and GRAS module are referred to as “Two-Stage Simulation”, it is possible to define further “detect” volumes in the second stage, and the particle tracks which enter those volumes recorded and used for a third-stage simulation.
1st Stage Simulation¶
The first stage of the analysis involves setting up a TSA “detect” module which defines a collection of “detect” volumes:
/gras/twoStage/detect/addModule <detectModule>`
where <detectModule>
is the name of the TSA module. Each module is
then associated with one or more physical volumes using the command:
/gras/twoStage/<detectModule>/selectVolume <pVolName> <copyNoMin> <copyNoMax>
where <pVolName>
, <copyNoMin>
and <copyNoMax>
are the
physical volume name and range of copy numbers for the selected
volume(s). if <copyNoMax>
=-1, all copies are selected. To save the
results from the TSA modules, one or more phase-space files must be
defined and then associated with the module:
/gras/twoStage/detect/addPSFile <fileModuleName> <fileName> <fileType>
/gras/twoStage/detect/<detectModule>/setPSFile <fileModuleName>
where <fileModuleName>
is the designation of the phase-space (PS)
file and <fileName>
is the filename including directory prefix if
required and any file suffix (file suffixes are not added
automatically). <fileType>
can take the values:
ROOT
: CERN ROOT file format.
The event interval at which results should be save to the phase-space file should also be defined:
/gras/twoStage/detect/<fileModuleName>/dumpInterval <nEvtInterval>
where nEvtInterval>
is >=1. This should be set so that the
phase-space results are saved sufficiently frequently to avoid losing
too much data should the simulation crash, but not too frequently that
harddisk activity is impacted significantly. Note that the same value of
<nEvtInterval>
will be applied to all detect modules.
The following macro commands will define one TSA module (col1
) and
assign physical volumes v1_out_PV
and v3_out_pv
to it. The
results will be saved to a file named test1_stage1_col1.root
in ROOT
format.
/gras/twoStage/detect/addModule col1
/gras/twoStage/detect/col1/selectVolume v1_out_PV 0 0
/gras/twoStage/detect/col1/selectVolume v3_out_PV 0 0
/gras/twoStage/detect/addPSFile PSFile1 test1_stage1_col1.root
In this instance, the association between PSFile1
and col1
is
made automatically and a /gras/twoStage/detect/col1/setPSFile
command is not required (when a new phase-space file is defined, any TSA
modules which are not already linked to an existing PS file will be
associated automatically with the new file).
Other command options under /gras/twoStage/detect/
are described in
[#INSERT REF].
The above commands are part of a TSA example (test1_stage1.g4mac
)
where two electronic equipment boxes are irradiated with a
unidirectional beam of protons. The interactions of the particles with
physical volumes v1_out_PV
and v3_out_PV
(shown as red in the
figure below) will result in any incident particles approaching from the
bottom right in the picture being recorded to the PS file and then
killed in the first stage.
2nd Stage Simulation¶
A similar approach to the first stage analysis is used here to select the relevant phase-space information recorded and to place those events on a geometry within the second stage. First, in order to switch to using a PS file as a particle generator, use the commands:
/gps/useTwoStage true
/gras/twoStage/source/syncEvents <syncEvtOpt>
where <syncEvtOpt>
is an integer value between 0 and 2 inclusive.
This specifies the level of synchronisation of the events numbers
between the first and second stages of the simulation. The options
available are discussed further below[#HERE].
The following command will identify the PS file used for input:
/gras/twoStage/source/selectPSFile <fileModuleName> <fileName> <fileType>
where the parameters ‘<fileModuleName>’, ‘<fileName>’ and ‘<fileType>’ are as defined in the previous section.
To define a source based on the particles incident upon physical volume
<pVolName>
and copy number <copyNo>
in the first-stage
simulation, first define a TSA “source” module:
/gras/twoStage/source/addSource <sourceModule> <fileModuleName> <pVolName> <copyNo>
By default, the particles read from the PS file which are incident upon
<pVolName>
and <copyNo>
will be a source on the same physical
volume in the second-stage simulation. However, the source can be
considered as incident upon a different phyiscal volume in the second
stage provided with volumes have the same shape and dimensions. The
command to do this is:
/gras/twoStage/source/<sourceModule>/targetVolume <pVolNameTarget> <copyNoTarget>
where <pVolNameTarget>
and <copyNoTarget>
define the “target”
physical volume for the source in the second stage.
By default, the Two-Stage module does not apply any splitting or resampling in particle start position or direction is performed. Therefore, unless requested by the user, each particle from the PS file that is mapped (explicitly or implicitly) to a target physical volume in the second-stage geometry is treated without modification.
There are several controls to split each particle from the PS file into more than one particle (with lower weight) in the second-stage analysis:
/gras/twoStage/source/<PSFile>/split <samples> <tries> <useLast> <useOrig> <failLev>
where:
<samples>
: (int >0) Is the number of times the original particle is resampled. Obviously, if<samples>
= 1, then each particle on the PS file is used only once in the second stage.<tries>
: (int >0) If the resample position doesn’t connect with the target volume, this is maximum number of times that sampling process should be performed.<useLast>
: (bool) Iftrue
then after<tries>
unsuccessful attempts at sampling the position/direction, if one of the previous event samples is valid, this is used instead.<useOrig>
: (bool) Iftrue
then after<tries>
unsuccessful attempts at sampling the position/direction, the original position and direction are used.<failLev>
: (int) If after the above processes, no valid particle is generated from the sampling of the event then the resulting action depends upon<failLev>
:<failLev>
= 0: Use the resampled particle anyway since, even if it’s not valid, it may still be sufficiently accurate, especially for grid-resampling.<failLev>
= 1: Use one of the samples from a list of previous events if a valid event is available. However, this does risk having inaccurate coordination in particle hits/energy deposition, as we’re selecting information from completely different events.<failLev>
= 2: Reject the current event for all samples of the event, and skip to the next event.
To resample (“dither”) the particle position you can use the following command for any source volume shape:
/gras/twoStage/source/<sourceModule>/resample/position <distributionType> <radius> <units>
Here, <distributionType>
can take values of:
NONE
: No repositioning of particles so that original position from PS file is always used.UNIFORM
: The particle position is uniformly resampled over a circle normal to physical volume surface normal (at the original particle point of impact). The radius of the circle is defined by<radius>
and<units>
.GAUSS
: The particle position is resampled as a radial gaussian distribution, again normal to the surface at the position of impact. The standard deviation is defined as<radius>
and<units>
For source volumes that are a G4Box, G4Tubs or G4Sphere, it is possible to resample the position on a grid:
/gras/twoStage/source/<sourceModule>/resample/grid <n1> <n2> <n3>
Where <n1>
, <n2>
and <n3>
are integer values defining
linearly-spaced intervals of the grid in coordinates:
G4Box : X, Y and Z.
G4Tubs : r, θ; and Z.
G4Sphere : θ and φ; (the parameter
<n3>
is ignored). When this option is selected, particles read from the PS file are resampled within the same grid interval (“tile”). So If the volume is a G4box and the particle strikes face +Z, at position x, y (x,,i,,≤x≤x,,i+1,,, and y,,j,,≤y≤y,,j+1,,, 0≤i<i+1≤`<n1>``; 0≤j<j+1≤`<n2>``), a new values for x and y are randomly sampled constrained to x,,i,,≤x≤x,,i+1,,, and y,,j,,≤y≤y,,j+1,,. The volume shape is determined automatically from the contents of the phase-space file and the user is not able to control this explicitly. Note that, although the interval angles in θ and φ are linear, when particles are resampled in these angles (for G4Tubs or G4Sphere) the impact on the change in the effective surface area presented to the particle (the so-called ‘’cosθ’’ factor) is accounted for in the sampling within the grid.
“Dithering” of the direction of the particle in the second stage is achieved using the command:
/gras/twoStage/source/<sourceModule>/resample/angle <distributionType> <angle> <units>
Here, <distributionType>
can take values of:
NONE
: No “dithering” in particle direction is applied so that original momentum vector from the PS file is always used.UNIFORM
: The new particle direction is resampled uniformly in solid angle over a cone around the original particle direction. For this option<angle>
and<units>
define the half-angle of the cone.
A further parameter controlling the source particles helps control the
tolerance between the coordinates identified for the particle in the PS
file and the surface of the target volume. The coordinates are compared
in the frame of the G4VSolid (not the global physical geometry) and if
there is a mismatch greater than the parameter <maxDist>
, the
sampling is repeated depending on the number of tries so far and the
value of <samples>
. By default, the tolerance is 1 micrometre, but
can be modified using the command:
/gras/twoStage/source/<sourceModule>/tolerance <maxDist> <units>
As mentioned above, the user can if needed define TSA detect modules in the second-stage simulation and the results from these then used in a third stage, ‘’etc.’’ Furthermore, multiple volumes and multiple sources can be defined within the second stage.
The following macro is an extract from TSA example
test1_stage2A.g4mac
. This takes each event from the ROOT file
test1_stage1_col1.root
for which the particles are incident upon
physical volume v1_out_PV
. Each event is used as a source in both
volumes v1_out_PV
and v2_out_PV
in the second stage, with each
original particle split into 20 separate particles. For the source at
v1_out_PV
, the second stage particles are resampled uniformly over a
disc of radius 1 cm centred on the original point of impact, and no
angular “dithering” is applied. For the source at v2_out_PV
, the
positions of the source particles are resampled on a 5 x 5 x 5 grid over
the equipment box and an angular resampling (5^o^ half-angle) is also
applied. The figure below shows the results for this macro for the first
two particles read from the PS file.
/gps/useTwoStage true
/gras/twoStage/source/syncEvents 2
/gras/twoStage/source/selectPSFile PSFile1 test1_stage1_col1.root
/gras/twoStage/source/addSource sourceVol1 PSFile1 v1_out_PV 0
/gras/twoStage/source/PSFile1/split 20 1 true true 1
/gras/twoStage/source/sourceVol1/resample/position UNIFORM 1.0 cm
/gras/twoStage/source/addSource sourceVol2 PSFile2 v1_out_PV 0
/gras/twoStage/source/sourceVol2/targetVolume v2_out_PV 0
/gras/twoStage/source/sourceVol2/resample/angle uniform 5.0 deg
/gras/twoStage/source/sourceVol2/resample/grid 5 5 5
Other command options under /gras/twoStage/source/
are described in
[#INSERT REF].
Event Sychronisation Between the 1st and 2nd Stage Simulations¶
The <syncEvtOpt>
parameter used with the
/gras/twoStage/source/syncEvents
command controls the
synchronisation of events from different PS files, and also the event
number of the first stage with respect to the second stage:
<syncEvtOpt>
= 0 : No synchronisation is applied even between different PS files:Every time there is a “non-event” for one of the PS file, the GRASTwoStageSourceManager skips that event
Please use this option with caution: it is difficult to normalise results without very careful consideration
<syncEvtOpt>
= 1 : Partial synchronisation, ‘’i.e.’’ between event numbers on different PS files, but not with respect to the event number of the first stage.The same value of samples should be used with all PS files.
If there are
nEvents1
in the first simulation, then there are fewer thannEvents1 x <samples>
events for the second stage.There is no need to generate dummy Geantino events, but a log is maintained of the number of non-events skipped.
Events can also be skipped if they generate invalid vertices and
<failLev>
= 2.The number of skipped events is displayed at the end of the simulation.
Overall normalisation applied by the user must take into consideration the number of events simulated in second stage and the number of events skipped.
<syncEvtOpt>
= 2 : Full synchronisation of the event number is maintained with the first-stage simulation.The same value of samples should be used with all PS files.
If there are
nEvents1
in the first simulation, then there are potentiallynEvents1 x <samples>
events for the second stage.There will likely be events which have no records in the PS file (no fits on the volume(s) of interest, or “non-events”). A dummy vertex is generated for each of these events, this vertex corresponding to a Geantino of 1eV located at 10^10^ km from the volume centre.
This is required to avoid a segmentation fault in GRASAnalysisManager.
Events can be skipped if they generate invalid vertices and
<failLev>
= 2.The number of skipped events is displayed at the end of the simulation.
GRAS/trunk/r2242