# jeffersonlab/g4sbs architecture

> Architecture diagram of the GitHub repository jeffersonlab/g4sbs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jeffersonlab/g4sbs
- Repository: https://github.com/jeffersonlab/g4sbs

## Overview

G4SBS is a Geant4 detector simulation whose principal workflow configures a run, generates physics events, transports particles through constructed geometry, and writes ROOT output. The repository also includes ROOT-based analysis and tree-reading tools, plus farm job generators. The graph emphasizes runtime stages and documented capabilities; several connections come from SOURCE INDEX references rather than complete excerpts, so unsampled details are not expanded.

Main entry points: [`src/G4SBSDetectorConstruction.cc`](https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSDetectorConstruction.cc) (Detector construction), [`g4sbs.cc`](https://github.com/jeffersonlab/g4sbs/blob/master/g4sbs.cc) (Run application), [`src`](https://github.com/jeffersonlab/g4sbs/tree/master/src) (Run actions), [`src/G4SBSEventGen.cc`](https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSEventGen.cc) (Event generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Simulation runtime"]
  node_app["Run application<br/>[g4sbs.cc]"]
  node_actions["Run actions"]
end

subgraph group_physics["Physics and geometry"]
  node_eventgen["Event generation<br/>[G4SBSEventGen.cc]"]
  node_pdf["CTEQ PDFs<br/>[cteqpdf.c]"]
  node_wiser["Wiser pion model<br/>[wiser_pion.h]"]
  node_construction["Detector construction"]
  node_target["Target geometry"]
  node_beamline["Beamline geometry"]
  node_earm["Electron arm"]
  node_harm["Hadron arm"]
end

subgraph group_output["Output and data"]
  node_io["ROOT output<br/>[G4SBSIO.cc]"]
end

subgraph group_analysis["Analysis tools"]
  node_simc["SIMC tree reader<br/>[simc_tree.h]"]
  node_pythia["Pythia tree reader<br/>[Pythia6_tree.h]"]
  node_spinanalysis["Spin correlation analysis"]
  node_farmjobs["Farm job generation"]
end

node_user(("User"))

node_user -->|"runs"| node_app
node_app -->|"configures"| node_actions
node_app -.->|"initializes"| node_construction
node_actions -.->|"generates events"| node_eventgen
node_eventgen -.->|"uses PDFs"| node_pdf
node_eventgen -->|"uses model"| node_wiser
node_construction -->|"builds geometry"| node_target
node_construction -->|"builds geometry"| node_beamline
node_construction -->|"builds geometry"| node_earm
node_construction -->|"builds geometry"| node_harm
node_actions -.->|"writes output"| node_io
node_io -.->|"ROOT data"| node_simc
node_io -.->|"ROOT data"| node_pythia
node_simc -.->|"analyzes data"| node_spinanalysis

click node_app "https://github.com/jeffersonlab/g4sbs/blob/master/g4sbs.cc"
click node_actions "https://github.com/jeffersonlab/g4sbs/tree/master/src"
click node_eventgen "https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSEventGen.cc"
click node_pdf "https://github.com/jeffersonlab/g4sbs/blob/master/src/cteq/cteqpdf.c"
click node_wiser "https://github.com/jeffersonlab/g4sbs/blob/master/include/wiser_pion.h"
click node_construction "https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSDetectorConstruction.cc"
click node_target "https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSTargetBuilder.cc"
click node_beamline "https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSBeamlineBuilder.cc"
click node_earm "https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSEArmBuilder.cc"
click node_harm "https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSHArmBuilder.cc"
click node_io "https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSIO.cc"
click node_simc "https://github.com/jeffersonlab/g4sbs/blob/master/include/simc_tree.h"
click node_pythia "https://github.com/jeffersonlab/g4sbs/blob/master/include/Pythia6_tree.h"
click node_spinanalysis "https://github.com/jeffersonlab/g4sbs/blob/master/root_macros/ElasticEP_Correlation_Analysis_withSpinTrans_julytest.C"
click node_farmjobs "https://github.com/jeffersonlab/g4sbs/tree/master/farmsub_scripts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_actions,node_user toneBlue
class node_eventgen,node_pdf,node_wiser,node_construction,node_target,node_beamline,node_earm,node_harm toneAmber
class node_io toneMint
class node_simc,node_pythia,node_spinanalysis,node_farmjobs toneRose
```

## Components

### Simulation runtime

- [Run application](https://github.com/jeffersonlab/g4sbs/blob/master/g4sbs.cc): `g4sbs.cc`
- [Run actions](https://github.com/jeffersonlab/g4sbs/tree/master/src): `src`

### Physics and geometry

- [Event generation](https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSEventGen.cc): `src/G4SBSEventGen.cc`
- [CTEQ PDFs](https://github.com/jeffersonlab/g4sbs/blob/master/src/cteq/cteqpdf.c): `src/cteq/cteqpdf.c`
- [Wiser pion model](https://github.com/jeffersonlab/g4sbs/blob/master/include/wiser_pion.h): `include/wiser_pion.h`
- [Detector construction](https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSDetectorConstruction.cc): `src/G4SBSDetectorConstruction.cc`
- [Target geometry](https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSTargetBuilder.cc): `src/G4SBSTargetBuilder.cc`
- [Beamline geometry](https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSBeamlineBuilder.cc): `src/G4SBSBeamlineBuilder.cc`
- [Electron arm](https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSEArmBuilder.cc): `src/G4SBSEArmBuilder.cc`
- [Hadron arm](https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSHArmBuilder.cc): `src/G4SBSHArmBuilder.cc`

### Output and data

- [ROOT output](https://github.com/jeffersonlab/g4sbs/blob/master/src/G4SBSIO.cc): `src/G4SBSIO.cc`

### Analysis tools

- [SIMC tree reader](https://github.com/jeffersonlab/g4sbs/blob/master/include/simc_tree.h): `include/simc_tree.h`
- [Pythia tree reader](https://github.com/jeffersonlab/g4sbs/blob/master/include/Pythia6_tree.h): `include/Pythia6_tree.h`
- [Spin correlation analysis](https://github.com/jeffersonlab/g4sbs/blob/master/root_macros/ElasticEP_Correlation_Analysis_withSpinTrans_julytest.C): `root_macros/ElasticEP_Correlation_Analysis_withSpinTrans_julytest.C`
- [Farm job generation](https://github.com/jeffersonlab/g4sbs/tree/master/farmsub_scripts): `farmsub_scripts`

### Other components

- **User**

## Connections

- User → Run application: runs
- Run application → Run actions: configures (evidence: `g4sbs.cc`)
- Run application → Detector construction: initializes
- Run actions → Event generation: generates events
- Event generation → CTEQ PDFs: uses PDFs
- Event generation → Wiser pion model: uses model (evidence: `src/G4SBSEventGen.cc`)
- Detector construction → Target geometry: builds geometry (evidence: `src/G4SBSDetectorConstruction.cc`)
- Detector construction → Beamline geometry: builds geometry (evidence: `src/G4SBSDetectorConstruction.cc`)
- Detector construction → Electron arm: builds geometry (evidence: `src/G4SBSDetectorConstruction.cc`)
- Detector construction → Hadron arm: builds geometry (evidence: `src/G4SBSDetectorConstruction.cc`)
- Run actions → ROOT output: writes output
- ROOT output → SIMC tree reader: ROOT data
- ROOT output → Pythia tree reader: ROOT data
- SIMC tree reader → Spin correlation analysis: analyzes data
