36.1. Geant4 Class Cheat Sheet
Table of Contents
Overview
This cheat sheet summarizes some of the most common Geant4 classes you will encounter in beginner and intermediate applications. It is organized by topic so you can quickly find the relevant class name and its main purpose.
Whenever you see a name that starts with G4V..., it is usually an abstract base class that you must derive from in your own code.
Important rule: **Never try to instantiate a G4V* (virtual) class directly.
Always create your own derived class and implement the required virtual methods.**
Where useful, small notes describe what you, as a user, typically implement or call.
Core Framework and Run Control
This group covers classes that control the overall simulation lifecycle.
| Class name | Role in a beginner application |
|---|---|
G4RunManager | Central class that controls initialization and execution of a run. You usually create it in main() for single-threaded applications. |
G4MTRunManager | Multithreaded variant of the run manager. Use it in main() when running with multiple threads. |
G4Run | Represents a full run (many events). Geant4 creates it. You can access it in RunAction. |
G4UserRunAction | Base class for user-defined run actions. Override to define what to do at the start and end of a run. |
G4UserEventAction | Base class for user-defined event actions. Override to react at the start and end of each event. |
G4UserSteppingAction | Base class for user-defined stepping actions. Override to inspect or modify each simulation step. |
G4UserTrackingAction | Base class for actions executed when a track starts or ends. Useful for per-track bookkeeping. |
G4UserStackingAction | Base class that lets you classify and manage new tracks (primaries and secondaries). |
G4VUserActionInitialization | Base class where you register all your user actions. You typically define this class and provide it to the run manager. |
G4VUserPrimaryGeneratorAction | Base class for primary particle generation. You derive from it and define how primaries are created. |
Key pattern: **You never call Geant4 user actions directly.
You implement your own subclasses, then register them with the run manager, and Geant4 calls them at the appropriate time.**
Geometry and Volumes
These classes define the geometry, including the world and all detector volumes.
| Class name | Role and usage |
|---|---|
G4VUserDetectorConstruction | Base class for user detector construction. You derive from it and implement Construct(). |
G4GeometryManager | Controls high level geometry operations, like closing geometry. Mostly used via commands or helpers. |
G4Box | Solid class representing a rectangular box. Used to define box-shaped volumes. |
G4Tubs | Solid class for a cylindrical volume. Very common for detectors, pipes, and targets. |
G4Sphere | Solid class for a spherical volume. |
G4Cons | Solid class for a truncated cone. Often used for tapered shapes. |
G4Orb | Solid class for a full sphere with a single radius parameter. |
G4LogicalVolume | Combines a solid with a material and properties like sensitive detectors and visualization. |
G4PVPlacement | Represents a single placement of a logical volume in the geometry hierarchy. |
G4PVReplica | Represents repeated volumes created by splitting a mother volume into equal parts. |
G4PVParameterised | Represents parameterized placements, where shape or position depend on copy number. |
G4RotationMatrix | Represents a rotation. Used when placing volumes with rotations. |
G4ThreeVector | 3D vector class used for positions, directions, and translations. |
G4Transform3D | Combination of rotation and translation to describe full placement transforms. |
G4Navigator | Internal navigation through geometry. Usually accessed indirectly through Geant4. |
Important usage rule: **Every physical volume must have a mother volume,
and the world volume must fully contain all other volumes.**
Boolean and Complex Geometry
Boolean solids let you build complex shapes from simpler ones.
| Class name | Role and usage |
|---|---|
G4UnionSolid | Boolean union of two solids. Combines them into a single solid. |
G4SubtractionSolid | Boolean subtraction of one solid from another. Useful for holes or cutouts. |
G4IntersectionSolid | Boolean intersection of two solids. Keeps only the overlapping volume. |
Materials and Elements
Materials describe what volumes are made of, including element composition and density.
| Class name | Role and usage |
|---|---|
G4Element | Represents a chemical element, with name, symbol, atomic number, and atomic weight. |
G4Material | Represents a material or mixture with density and composition. |
G4Isotope | Represents a specific isotope. Used if you need isotopic composition. |
G4NistManager | Helper singleton providing predefined NIST materials and elements. |
Best practice: Prefer G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER") and other NIST names when possible, to avoid mistakes in composition or density.
Primary Particle Generation
These classes are used for defining how primary particles enter your simulation.
| Class name | Role and usage |
|---|---|
G4VUserPrimaryGeneratorAction | Base class for your primary generator. Implement GeneratePrimaries(). |
G4ParticleGun | Simple primary generator class for monoenergetic beams or simple sources. |
G4GeneralParticleSource | More flexible primary generator with macro-configurable distributions. |
G4ParticleTable | Provides access to all predefined particles in Geant4. |
G4ParticleDefinition | Describes a specific particle type, including mass, charge, and PDG code. |
Physics Lists and Processes
Physics lists control which particles exist and how they interact with matter.
| Class name | Role and usage |
|---|---|
G4VUserPhysicsList | Base class for user-defined physics lists. You implement processes and cuts. |
G4VModularPhysicsList | Base class to build physics lists from modular physics builders. |
G4VPhysicsConstructor | Base class for modular physics components, such as EM or hadronic physics. |
G4PhysListFactory | Helper that creates reference physics lists by name (for example FTFP_BERT). |
G4ProductionCutsTable | Manages production cuts for secondaries. |
G4Region | Allows different production cuts in different parts of the geometry. |
Common electromagnetic process classes (usually used indirectly through reference physics lists):
| Class name | Typical meaning |
|---|---|
G4eIonisation | Ionization process for electrons and positrons. |
G4eBremsstrahlung | Bremsstrahlung process for electrons and positrons. |
G4ComptonScattering | Compton scattering for gamma rays. |
G4PhotoElectricEffect | Photoelectric effect for gamma rays. |
G4GammaConversion | Pair production for gamma rays. |
Key recommendation: For most beginner applications, use a predefined reference physics list like FTFP_BERT instead of building your own from scratch.
Tracking, Steps, and Particle Information
These classes let you access what happens to particles as they move and interact.
| Class name | Role and usage |
|---|---|
G4Event | Represents a single event. You can access event-level information in EventAction. |
G4Track | Represents a single particle track. Accessible in TrackingAction and SteppingAction. |
G4Step | Represents one simulation step of a track. Main access point for energy deposition. |
G4StepPoint | Represents the state of a track at the start or end of a step. |
G4TouchableHandle | Encapsulates the full geometry history of a step point, including copy numbers. |
G4VTouchable | Abstract interface for touchables. Touchables encode where in the geometry a step happened. |
G4VProcess | Base class for physics processes that act on tracks. Usually used indirectly. |
Common methods (you will see them in documentation and examples):
| Object | Common methods in beginner code |
|---|---|
G4Track | GetTrackID(), GetParentID(), GetDefinition(), GetKineticEnergy() |
G4Step | GetTotalEnergyDeposit(), GetPreStepPoint(), GetPostStepPoint() |
G4StepPoint | GetPosition(), GetGlobalTime(), GetTouchableHandle() |
Core fact: **Energy deposition in a detector is usually obtained from G4Step::GetTotalEnergyDeposit().
You normally accumulate this quantity per event or per detector element.**
Sensitive Detectors and Hits
Sensitive detectors record what happens inside selected volumes. Hits are your custom records of those interactions.
| Class name | Role and usage |
|---|---|
G4VSensitiveDetector | Base class for sensitive detectors. You derive from it and implement ProcessHits(). |
G4SDManager | Singleton that manages all sensitive detectors and their hit collections. |
G4VHit | Base class for a single hit. You derive from it and define what information to store. |
G4THitsCollection<T> | Template class to store hits of type T in a collection. |
G4HCofThisEvent | Container holding all hit collections for one event. |
Typical user pattern:
- Define your own hit class inheriting from
G4VHit. - Define your own sensitive detector inheriting from
G4VSensitiveDetector. - Assign the sensitive detector to a logical volume.
- In
EventAction, retrieve the hit collections fromG4HCofThisEvent.
Units, Constants, and Types
Geant4 uses its own internally consistent unit system.
| Class / namespace | Role and usage |
|---|---|
G4SystemOfUnits | Defines unit constants such as mm, cm, m, MeV, ns, etc. |
G4PhysicalConstants | Defines physical constants such as c_light, pi, and more. |
G4Types | Defines type aliases like G4double, G4int. |
G4UnitsTable | Utility to convert numbers into strings with units for printing. |
Important rule: **Always multiply numerical values by explicit units like 10 cm or 1.0 MeV.
Never assume that raw numbers are in SI units.**
Visualization
Visualization classes control how geometry and tracks are displayed.
| Class name | Role and usage |
|---|---|
G4VisManager | Central visualization manager. You create and initialize it in your main() when using built-in drivers. |
G4VVisManager | Abstract base class for the visualization manager. |
G4VGraphicsSystem | Base class for graphics systems (for example OpenGL). Typically used indirectly. |
G4VisAttributes | Controls visual attributes of logical volumes, such as color and visibility. |
G4Colour | Represents an RGB color for visualization. |
G4Trajectory | Default implementation for drawing tracks in visualization. |
G4TrajectoryContainer | Holds trajectories for an event. |
Typical usage for logical volume attributes:
auto visAttr = new G4VisAttributes(G4Colour(0.0, 1.0, 0.0));
visAttr->SetVisibility(true);
logicVolume->SetVisAttributes(visAttr);Analysis
The Geant4 analysis system helps you create histograms and ntuples, and write them to files.
| Class name | Role and usage |
|---|---|
G4AnalysisManager | Main interface for creating histograms and ntuples, and writing output files. |
G4VAnalysisManager | Abstract base class for analysis managers. |
G4HistoManager | Helper class in some examples to organize histogram creation. |
Typical workflow with G4AnalysisManager:
- Get the singleton instance with
G4AnalysisManager::Instance(). - Create histograms and ntuples during initialization.
- Fill histograms and ntuples in your user actions.
- Open and close files in
RunActionor similar.
Multithreading and Concurrency
These classes are relevant when you run Geant4 in multithreaded mode.
| Class name | Role and usage |
|---|---|
G4MTRunManager | Multithreaded run manager. Use instead of G4RunManager for MT. |
G4Threading | Utilities related to threading and thread identification. |
G4Cache<T> | Helper template to store per-thread data safely. |
G4AutoLock | RAII-based lock for protecting shared resources across threads. |
Safety rule: **Avoid sharing writable global or static objects across threads.
Use per-thread data or proper locking when necessary.**
Random Numbers
Random numbers underpin Monte Carlo sampling in Geant4.
| Class name | Role and usage |
|---|---|
CLHEP::HepRandom | Core CLHEP random number interface used by Geant4. |
CLHEP::HepRandomEngine | Base class for specific random engines. |
CLHEP::RanecuEngine | A commonly used random engine. |
G4RandomTools | Helper functions for random-related tasks in Geant4. |
Typical usage:
Set the engine and seed before your run, then Geant4 and physics processes draw random numbers internally.
Configuration and Commands
These classes support the Geant4 command line and macro system.
| Class name | Role and usage |
|---|---|
G4UImanager | Central UI manager that executes commands from macros or interactive sessions. |
G4UIcommand | Represents a single UI command. |
G4UIdirectory | Groups related UI commands under a directory path. |
G4UIExecutive | Helper class for starting interactive UI sessions (Qt, Xm, etc.). |
G4VisExecutive | Helper class to initialize all predefined visualization drivers. |
Typical pattern in main():
- Create
G4RunManagerorG4MTRunManager. - Create
G4UIExecutiveif running interactively. - Create and initialize
G4VisExecutive. - Use
/control/executeto run macro files.
Practical Look-Up Examples
This section lists a few common tasks and the class you typically need.
| Task | Relevant class or classes |
|---|---|
| Define the world and detector geometry | G4VUserDetectorConstruction, G4LogicalVolume, G4PVPlacement |
| Define materials | G4NistManager, G4Material, G4Element |
| Create a simple primary particle beam | G4VUserPrimaryGeneratorAction, G4ParticleGun |
| Use a flexible, macro-defined source | G4GeneralParticleSource |
| Choose and configure physics | G4VModularPhysicsList, G4PhysListFactory |
| Record energy deposition in a volume | G4VSensitiveDetector, G4VHit, G4Step |
| Access position and time of interactions | G4StepPoint, G4ThreeVector, GetGlobalTime() |
| Build histograms and output to ROOT or CSV | G4AnalysisManager |
| Visualize geometry and tracks | G4VisManager, G4VisAttributes, G4Colour |
| Run in multithreaded mode | G4MTRunManager, G4VUserActionInitialization |
This cheat sheet is meant as a quick reference. When you see any of these classes in examples or documentation, you can refer back here to remind yourself of their main purpose and how they fit into a typical Geant4 application.
Views: 11
KAHIBARO