Multiple User Actions

Starting from Geant4 Version 10.3 it is possible to attach multiple instances of the same type of user action to a single run manager. This is achieved via the use of a special proxy classes to which multiple child user actions are attached. This is allowed for run-, event-, tracking- and stepping-type user actions (G4UserRunAction, G4UserEventAction,G4UserTrackingAction,G4UserSteppingAction).

The kernel still sees a single user action of each type, the proxy will forward the calls from kernel to all the attached child user actions.

Listing 95 An example of the use of the use of multiple user-actions.
#include "G4MultiRunAction.hh"
#include "G4MultiEventAction.hh"
#include "G4MultiTrackingAction.hh"
#include "G4MultiSteppingAction.hh"
//...
void MyUserActionInitialization::Build()
{
  //...
  // Example with multiple-event action, similarly
  // for the other cases
  // multi- user actions extend std::vector
  auto multiAction = new G4MultiEventAction { new MyEventAction1, new MyEventAction2 } ;
  //...
  multiAction->push_back( new MyEventAction3 );
  SetUserAction( multiAction );
  //...
}

Exceptions

This functionality is not implemented for the the stacking user action and primary generation action. There is no multiple G4UserStackingAction equivalent since this would require a complex handling of the case in which conflicting classifications are issued. For the case of G4VUserPrimaryGeneratorAction the use case of the multiple user actions is already addressed by the design of the class itself. User can implement one or more generators in the actions.

For the case of G4MultiRunAction only one of the child user actions can implement the G4UserRunAction::GenerateRun() method returning a non null, user derived G4Run object, otherwise an exception is thrown.