Jump to content

A simple main() method of Geant4

From Luter 345 Experiments
Revision as of 17:58, 24 December 2024 by Brash99 (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The contents of main() will vary according to the needs of a given simulation application and therefore must be supplied by the user

First you must include all of the files you will be calling into the main() method

#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "ExG4DetectorConstruction01.hh"
#include "ExG4PhysicsList00.hh"
#include "ExG4ActionInitialization01.hh"

Secondly construct the default run manager

 G4RunManager* runManager = new G4RunManager;

Then you need to set the mandatory initialization classes

runManager->SetUserInitialization(new ExG4DetectorConstruction01);
runManager->SetUserInitialization(new ExG4PhysicsList00);
runManager->SetUserInitialization(new ExG4ActionInitialization01);
//this code initializes G4DetectorConstruction, G4PhysicsList, G4ActionInitialization

Initialization of the G4 kernel

runManager->Initialize();

The next step for a simple main() method would be getting the pointer to the UI(User Interface) manager and set verbosities

G4UImanager* UI = G4UImanager::GetUIpointer();
UI->ApplyCommand("/run/verbose 1");
UI->ApplyCommand("/event/verbose 1");
UI->ApplyCommand("/tracking/verbose 1")

Starting the run process

int numberOfEvent = 3; //you can put however many events you would like this example is set at 3.
runManager->BeamOn(numberOfEvent);

Then you need to terminate the job and close the main() method

delete runManager;
  return 0;
}