GEANT4 MT Application

This section aims to detail how to take single threaded GEANT4 simulations and make them multi thread compatable. Please note, to complete this section, it would be useful to have a working cherenkov detector, macro definition and a multithreaded version of GEANT4 installed. More information on how to make these can be found in seperate sections within this site.

To begin, we return to our file. Here we need to include an if condition around our G4RunManager which relies on the declaration of G4MULTITHREADED. If this is defined that we are to use the G4MTRunManager instead. Here GEANT4 will check to see which installation we have sourced, if we've sourced the multithreaded version, this one will be used for the simulation. Next we look at the and action.hh files. Within the action.hh file, we need to create a new function in the class definition called BuildForMaster. Here, what's written inside the build function is for each worker thread where what's written inside the BuildForMaster function is for the master thread. Next we need to define this function in the file. Within this function we need to create the runAction and SetUserAction.

Returning to the file, we also need to look at the initialization of the run mangager. Currently this is hard written into our code but if we want to define the number of threads we want to use within our scripts then we need to make sure this definition is placed before the visualisation manager, otherwise it will throw and error. As such, we will place this definition within our run.mac macro file. With these setps complete, we can return to our simulation and test our code. Here, if we build in the same manner outlines previously, then run our siulation with the run.mac passed, you should be able to see the different worker threads producing their results.

One further point to note here, when your simulation produces results from mt mode, the results will be produced in several distinct files. As such, we need to make our results thread safe. This can be achived by merging each of these outputs using the command 'hadd test.root output0_t{0..3}.root'. This will add all of the output files into one centralised output, within test.root.