This example illustrates the use of Reverse Monte Carlo in Geant4.
This example code and the adjoint classes in the G4 toolkit have been developed by L.Desorgher (SpaceIT GmbH) under the ESA contract 21435/08/NL/AT. For any (reasonable) question you may contact the author at the following email address : desor.nosp@m.gher.nosp@m.@spac.nosp@m.eit..nosp@m.ch
This is the README file for the first G4 example illustrating the use of the Reverse Monte Carlo (RMC) mode in a Geant4 application. The Reverse Monte Carlo method is also known as the Adjoint Monte Carlo (AMC) method and in this document we will alternate both Reverse and Adjoint terms.
See also the section 3.7.3 Adjoint/Reverse Monte carlo in the Geant4 User guide for application developers.
When the sensitive part of a detector is small compared to its entire size and to the size of the external extended primary particle source, a lot of computing time is spent during a normal Monte Carlo run in the simulation of particle showers that are not contributing to the detector signal.
In such particular case the Reverse Monte Carlo (RMC) method, also known as the Adjoint Monte Carlo method, can be used. In this method particles are generated in or on the external surface of the sensitive volume of the instrument and then are tracked backward in the geometry till they reach the source surface, or exceed an energy threshold. During the reverse tracking reverse reactions are applied to the particles.
(See also the section 3.7.3 Adjoint/Reverse Monte carlo in the Geant4 User guide for application developers.)
Different G4Adjoint classes have been implemented into the Geant4 toolkit to run an adjoint/reverse simulation in a Geant4 application. In this implementation an adjoint run is divided in a succession of alternative adjoint and forward tracking of adjoint and normal particles. One Geant4 event treats one of this tracking phase.
Adjoint particles (adjoint_e-, adjoint_gamma,...) are generated one by one on the so called adjoint source with random position, energy (1/E distribution) and direction. The adjoint source is the external surface of a user defined volume or of a user defined sphere. The adjoint source should contain one or several sensitive volumes and should be small compared to the entire geometry. The user can set the minimum and maximum energy of the adjoint source. After its generation the adjoint primary particle is tracked backward in the geometry till a user defined external surface (spherical or boundary of a volume) or is killed before if it reaches a user defined upper energy limit that represents the maximum energy of the external source. During the reverse tracking, reverse processes take place where the adjoint particle being tracked can be either scattered or transformed in another type of adjoint particle. During the reverse tracking the G4AdjointSimulationManager replaces the user defined primary, run, stepping, ... actions, by its own actions.
When an adjoint particle reaches the external surface its weight, type, position, and direction are registered and a normal primary particle with a type equivalent to the last generated adjoint primary is generated with the same energy, position but opposite direction and is tracked in the forward direction in the sensitive region as in a forward MC simulation. During this forward tracking phase the event, stacking, stepping, tracking actions defined by the user for its general forward application are used. By this clear separation between adjoint and forward tracking phases, the code of the user developed for a forward simulation should be only slightly modified to adapt it for an adjoint simulation. Indeed the computation of the signal is done by the same user actions or analysis classes that the one used in the forward simulation mode. Before the G4.10.0 release the reverse and forward tracking mode took place in separated events. Since the G4.10.0 release, in order to preapre to the migration of the ReverseMC to the G4 Multiple Threading mode, the reverse and forward tracking phase of corresponding adjoint and forward primaries have been merged in the same event.
During the reverse tracking phase reverse processes act on the adjoint particles. The Reverse processes that are available at the moment in Geant4 are the:
It is important to note that the electromagnetic reverse processes are cut dependent as their equivalent forward processes. The implementation of the reverse processes is based on the forward processes implemented in the G4 standard electromagnetic package.
The list of type of adjoint and forward particles that are generated on the adjoint source and considered in the simulation is a function of the adjoint processes declared in the physics list. For example if only the e- and gamma electromagnetic processes are considered , only adjoint e- and adjoint gamma will be considered as primaries. In this case an adjoint event will be divided in two G4 events. The first event will consist into the coupled reverse and forward tracking of an adjoint e- and its equivalent forward e-, while the second events will process the reverse and forward trackings of corresponsing adjoint and forward primary gamms. In this case a run of 100 adjoint events will consist into 200 Geant4 events. If the proton ionization is also considered adjoint and forward protons are also generated as primaries and 300 Geant4 events are processed for 100 adjoint events.
(for more details see also the section 3.7.3 Adjoint/Reverse Monte carlo in the Geant4 User guide for application developers.)
Due the clear separation between the reverse and forward tracking phase only few modifications are needed to an existing Geant4 application in order to adapt it for the use of the reverse simulation mode. Except in the physics list where all the reverse processes and their forward equivalent have to be declared, the principal code modifications are needed only in the analysis phase at the end of the forward tracking where computed signals have to be multiplied by the weight of the last reverse tracks and then normalized to different user defined spectra and angular distribution representing the external source. The weight of the adjoint tracks is computed by the G4Adjoint classes and the user needs only to multiply them to the primary differential, directional spectrum of its choice. The adjoint weight a the end of tracks can be also registered if needed in answer matrices.
More precisely, in order to be able to use the Reverse MC method in his simulation, the user should modify its code as such:
Modify the analysis part of the code to normalize the signal computed during the forward phase to the weight of the last adjoint particle that reaches the external surface. This is done by using the following method of G4AdjointSimManager:
In order to have a code working for both forward and adjoint simulation mode, the extra code needed in user actions for the adjoint simulation mode can be separated to the code needed only for the normal forward simulation by using the following method:
The example RMC01 illustrates how to modify a G4 application in order to use both forward and reverse MC modes in the same code.
The following simple geometry is considered:
The free parameters of the geometry that can bes set by the user are:
The physical processes considered are:
These processes are implemented in the class G4AdjointPhysicsList distributed with the example. The G4AdjointPhysicsMessenger allows the user to switch on/off some processes for testing purpose. By default all processes cited above are considered except the proton ionization that has to be specifically switch on in the macro file by the user.
The example computes the energy deposited in the sensitive Si cylinder and the current of e-, protons, and gamma entering this cylinder. The Hits are registered in the sensitive detector class RMC01SD that is a typical G4 sensitive detector class used in a forward simulation and is not modified at all for the adjoint simulation mode. The analysis of the registered hits during forward events is done by the RMCO1AnalysisManager. That is the class that illustrates how to adapt an analysis code of a fwd simulation in order to use it also for an adjoint simulation. In this class during a forward simulation the method EndOfEventForForwardSimulation is used at the end of an event while during an adjoint simulation at the end of fwd tracking event the method EndOfEventForAdjointSimulation is called. By looking at the source of RMCO1AnalysisManager and more particularly to its method EndOfEventForAdjointSimulation the user will learn how to adapt its G4 analysis code for an adjoint simulation.
The outputs of an adjoint simulation are:
The outputs of a forward simulation are:
The following example run macro files are distributed with the code:
It is the responsibility of the user to select in the macro file the same external spectrum for both the forward and adjoint simulations and to normalize the per event results of the forward simulation to the fluence considered in the adjoint simulation.
For the macro files that are provided with the examples it consists into multiplying the forward results by pi*100. This normalization factor is explained by the following:
Different G4 macro UI commands are provided to control the RMC01 example and the adjoint simulation. Some macro commands are provided within the geant4 toolkit and appears in a G4 application when the singleton class G4AdjointSimManager is called somewhere in the code, the other macro commands are declared in the code distributed within the example.
The macro command directory /adjoint appears in a user application when the singleton class G4AdjointSimManager is called somewhere in the code. It allows to control the adjoint source, the external source and start an adjoint simulation.
The command to start an adjoint run is:
The commands to control the adjoint source are:
The commands to control the external source are:
These commands allow to control the electromagnetic processes that will be considered in the simulation.
The processes that can be used are:
The commands that can be used to switch on of these processes are:
The user can also fix the maximum energy Emax and minimum energy Emin of the adjoint physical processes used in the simulation. The adjoint process will be applied to particles within the energy range [Emin, Emax] and will produce adjoint secondary only in this energy range. It is recommended to fix Emin to the minimum energy of the adjoint source and fix Emax to the maximum energy of the external source.
The commands controlling Emin and Emax are:
Commands/RMC01/geometry/ to control the geometry:
Commands /RMC01/analysis/ to control the primary spectrum used for the normalization of the adjoint simulation results and fix the expected precision of the computed Edep:
In rare cases an adjoint track may get a much too high weight when reaching the external source. While this happen not often it may corrupt the simulation results significantly. The reason of this high weight is the joint use at low e- and gamma energy of both the photoelectric and bremsstrahlung processes. Unfortunately we still need some investigations to remove this problem at the level of physical processes. However this problem can be solved at the level of event action in the user code by adding a test on the adjoint weight. Such test has been implemented in the example RMC01. In this implementation an event is rejected when the relative error of the computed normalised edep increase during one event by more than 50% when the precision is already below 10%.
The difference between the differential cross sections used in the adjoint and forward bremsstrahlung models is the source of a higher flux of >100 keV gamma in the reverse simulation compared to the forward simulation. The adjoint processes/models should make use of the direct differential cross section to sample the adjoint secondaries and compute the adjoint cross section. The differential cross section used in G4AdjointeBremstrahlungModel is obtained by the numerical derivation over the cut energy of the direct cross section provided by G4eBremsstrahlungModel. This would be a correct procedure if the distribution of secondary in G4eBremsstrahlungModel
would match this differential cross section. Unfortunately it is not the case as independent parameterization are used in G4eBremsstrahlungModel for both the cross sections and the sample of secondary. (It means that in the forward case if one would integrate the effective differential cross section considered in the simulation we would not find back the used cross section). In the future we plan to correct this problem by using an extra weight correction factor after the occurrence of a reverse bremsstrahlung. This weight factor should be the ratio between the differential CS used in the adjoint simulation and the one effectively used in the forward processes. As it is impossible to have access to the forward differential CS in G4eBremsstrahlungModel we are investigating the feasibility to use the differential CS considered in
G4Penelope models.
For the reverse multiple scattering we are using the same models than for the forward case. This approximation makes that the discrepancy between the adjoint and forward simulation cases can get to a level of ~ 10-15% relative differences in the test cases that we have considered. In the future we plan to improve the adjoint multiple scattering models by forcing the computation of multiple scattering effect at the end of an adjoint step.