Geant4 has three user initialization classes and one user action class whose methods the user must override in order to implement a simulation. They require the user to define the detector, specify the physics to be used, and describe how initial particles are to be generated.
Three user initialization class objects are registered with
the Section 3.4.1.2 in the
user's main()
program, which takes ownership. The user
must not delete these objects directly, and they must be created using
'new'.
G4VUserDetectorConstruction
Example 6.1.
G4VUserDetectorConstruction
class G4VUserDetectorConstruction { public: G4VUserDetectorConstruction(); virtual ~G4VUserDetectorConstruction(); public: virtual G4VPhysicalVolume* Construct() = 0; virtual void ConstructSDandField() = 0; };
In the Construct()
method, material and geometry has to be descrived.
Detailed discussions on material and geometry are given in Sections Section 2.3
and Section 2.2. Detector sensitivity and electromagnetic field should
be defined in ConstructSDandField()
, as objects defined in this method are
thread-local if they are used in multi-threaded mode. Detailed discussions on
Detector sensitivity and electromagnetic field are given in Sections Section 4.4
and Section 4.3.
G4VUserPhysicsList
This is an abstract class for constructing particles and processes. There are several methods to define Physics List.
The user must
derive a concrete class from G4VUserPhysicsList
and implement three virtual methods:
ConstructParticle()
to instantiate each requested
particle type;ConstructPhysics()
to instantiate the desired physics
processes and register each of them;SetCuts(G4double aValue)
to set a cut value in range
for all particles in the particle table, which invokes the
rebuilding of the physics table.
At early stage of the initialisation of Geant4 the method
ConstructParticle()
of
G4VUserPhysicsList
is invoked.
The ConstructProcess()
method must always invoke the
AddTransportation()
method in order to insure particle
transportation. AddTransportation()
must never be
overridden. This is done automatically if G4VUserPhysicsList
inherits of G4VModularPhysicsList
. It is recommended for
users as the most robust interface to Physics List. Geant4 examples demonstrate
different methods how to create user Physics List.
Number of ready to use Physics Lists are available with Geant4 kernel. Below an example of instantiation of FTFP_BERT Physics List class is shown. The full set of reference Physics Lists is described in Geant4 web.
Example 6.2. Creating FTFP_BERT Physics List.
G4int verbose = 1; FTFP_BERT* physlist = new FTFP_BERT(verbose); runManager->SetUserInitialization(physlist);
Geant4 provides a class G4PhysListFactory
allowing
to defined Physics List by its name. The last for characters in the name defines
an electromagnetic (EM) physics options. By default standard EM physics is used,
"_EMV" corresponding to standard option1, "_EMX" - to standard option2,
"_LIV" to EM Livermore physics, "_PEN" - to EM Penelope physics.
Example 6.3. Creating Physics List by name.
G4int verbose = 1; G4PhysListFactory factory; G4VModularPhysicsList* physlist = factory.GetReferencePhysList("FTFP_BERT_EMV"); physlist.SetVerboseLevel(verbose); runManager->SetUserInitialization(physlist);
The class G4PhysListFactory
provides also another interface
allowing to defined Physics List by the environment variable PHYSLIST.
Example 6.4. Creating Physics List by name.
G4int verbose = 1; G4PhysListFactory factory; G4VModularPhysicsList* physlist = factory.ReferencePhysList(); physlist.SetVerboseLevel(verbose); runManager->SetUserInitialization(physlist);
The user Physics List class may be created from
components provided by Geant4 kernel and by user application.
For that G4VModularPhysList
should be implemented.
Example 6.5. Creating Physics List by name.
MyPhysicsList::MyPhysicsList():G4VModularPhysicsList() { G4DataQuestionaire it(photon, neutron, no, no, no, neutronxs); G4cout << "<<< Geant4 Physics List: MyPhysicsList " <<G4endl; G4cout <<G4endl; defaultCutValue = 0.7*mm; G4int ver = 1; SetVerboseLevel(ver); // EM Physics RegisterPhysics( new G4EmStandardPhysics(ver) ); // Synchroton Radiation & GN Physics RegisterPhysics( new G4EmExtraPhysics(ver) ); // Decays RegisterPhysics( new G4DecayPhysics(ver) ); // Hadron physics RegisterPhysics( new G4HadronElasticPhysicsXS(ver) ); RegisterPhysics( new G4QStoppingPhysics(ver) ); RegisterPhysics( new G4IonBinaryCascadePhysics(ver) ); RegisterPhysics( new G4HadronInelasticQBBC(ver)); // Neutron tracking cut RegisterPhysics( new G4NeutronTrackingCut(ver) ); }
G4VUserActionInitialization
Example 6.6.
G4VUserActionInitialization
class G4VUserActionInitialization { public: G4VUserActionInitialization(); virtual ~G4VUserActionInitialization(); public: virtual void Build() const = 0; virtual void BuildForMaster() const; virtual G4VSteppingVerbose* InitializeSteppingVerbose() const; protected: void SetUserAction(G4VUserPrimaryGeneratorAction*) const; void SetUserAction(G4UserRunAction*) const; void SetUserAction(G4UserEventAction*) const; void SetUserAction(G4UserStackingAction*) const; void SetUserAction(G4UserTrackingAction*) const; void SetUserAction(G4UserSteppingAction*) const; };
All user action classes must be defined through the protected method
SetUserAction()
.
Build()
methos should be used for defining user action classes
for worker threads as well as for the sequential mode. BuildForMaster()
should be used only for defining UserRunAction for the master thread.
BuildForMaster()
is not invoked in the sequential mode.
In case the user uses his/her own SteppingVerbose
class,
it must be instantiated in the method InitializeSteppingVerbose()
and returned.
G4VUserPrimaryGeneratorAction
Example 6.7.
G4VUserPrimaryGeneratorAction
class G4VUserPrimaryGeneratorAction { public: G4VUserPrimaryGeneratorAction(); virtual ~G4VUserPrimaryGeneratorAction(); public: virtual void GeneratePrimaries(G4Event* anEvent) = 0; };