Optimising the CPU time of your application

We recommend you to spend some time in optimising the CPU time spent by your application, as you may save a big amount of CPU time with not too much effort.

Knowing where the time is spent

Before starting your optimisation it may be very useful to understand where the time is spent. For example if most of the time is spent tracking some type of particle, some volumes, or particles created by some process. To get a report of where the time is spent GAMOS provides the user action GmTimeStudyUA, that you can combine with one or more classifiers to get a detailed report.

Production cuts

The production cuts are the minimum energy of the electrons produced by ionisation and of gammas produced by bremsstrahlung (and also of the positrons produced by pair production process of muons if you are using these particles). If the cut values are very big, it means that you are not creating electrons or gammas of high energy but instead you count all their energy as energy deposited at the last step position.. so you should check that your value is not too high. On the other side, the number of these particles produces grows exponentially as you diminish these cuts, so you should check that your value is not too low.

The cut is given in Geant4 as a distance value, meaning that you are not creating an electron or gamma if (in average) it is not going to travel a distance longer than the cut value. A rule of thumb may be that you set a cut value of the order of 1/10 of the resolution you have, so that your results are not affected much (of course if you want to have a very high precision the effect of the cut should be reduced even further). The default cut value in GAMOS is 0.1 mm. You may change it with the Geant4 command:

/run/setCut VALUE mm

You should also take into account the possibility of using different cut for different parts of your geometry (regions). For example a bigger cut in regions where you do not measure anything and a lower cut in your sensitive regions; or a big cut if the particles created in a region are far from you detectors so that they have a very small probability of reaching them. To set cuts per region see section production cuts by region.

To understand if the changing of cuts may have an important effect in your CPU time, you may do first a time study checking if the particles created by ionisation or bremsstrahlung are taking a big proportion of the time, by adding the command:

/gamos/userAction GmTimeStudyUA GmClassifierByCreatorProcess

If your application is a nuclear medicine detector or a radiotherapy treatment, we recommend you to read the sections of automatic optimisation of production cuts, which may help you in getting the best cut values.

By default the production cuts only affect ionisation and bremsstrahlung, but you may force that they are also used in all processes by using the command:

/gamos/physics/applyCutsForAllProcesses 1

Killing particles of small energy

An alternative or complementary approach of the optimisation of production cuts is the optimisation of the user limits that kill the particles when their energy becomes small (see section on User limits). It is likely logic that if you put a production cut to kill particles of small range, you kill the particles when their energy becomes small so that they will not travel more than that range value. For efficiency reasons we recommend that you use the user limit:

/gamos/physics/userLimits/setMinEKinByRange USER_LIMITS_NAME LOGICAL_VOLUME_NAME PARTICLE_NAME MIN_RANGE

If your application is a nuclear medicine detector or a radiotherapy treatment, we recommend you to read the sections of automatic optimisation of user limits, which may help you in getting the best values.

Killing particles

The two user actions GmKillAtStackingUA and GmKillAtSteppingUA combined with the filtering mechanism can help you to kill those particles that you know are not affecting your result by a sensible amount. For example you may kill the neutrinos produced in a radioactive decay, or the electrons in an application where you are scoring neutrons.

Optimising the particle generation

GAMOS provides a wide variety of primary generator distributions with which to simulate in detail the primary particles that correspond to your application. But you may consider that some particles will not reach your detector (or will reach it with a very small probability) and modify your distributions so that those particles are never produced. Another alternative is to use a biasing distribution (see section on Biasing generator distributions.

Limiting the number of user actions

Some of the user actions (for example those that fill lots of histograms) may consume a non negligible amount of CPU time. Therefore a simple recommendation is to check that you deactivate all the user actions you do not need when you are making a big production of events.

Using variance reduction techniques

Several variance reduction techniques are provided by GAMOS to optimise the CPU time for specific applications. See the section on Variance reduction techniques or the corresponding application.