How to post code snippets

To effectively help with coding/output problems, we need to see that code or output clearly. Discourse provides all the tools here to make this easy once you know how to use them. There are really only two simple guidelines:

  1. Use fenced code blocks to post code snippets
    • They help show where you code begins and ends. Plus it doesn’t mess with your spacing or indents which help to make the structure clear, and will scale it appropriately to the screen size.
    • When people are communicating code and there is no indentation and lousy spacing, code is super-hard to read.
  2. Do not post screenshots of code/messages
    • Can be tricky to read, snippets/corrections take more time to write/quote.
    • Takes less time to copy/paste than to take/post screenshot!
    • The one exception to this is for errors in Geant4 GUI/Vis displays

How do I use fenced code blocks?
A fenced code block begins with three backticks, i.e., ```, followed by your code or output, then the block is closed with another three backticks ```. You’re not limited to C++ here, any terminal commands or output can be put in these blocks.

For example, we could write a code block as:

```
int main(int argc,char** argv)
{
auto* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
runManager->SetUserInitialization(new DetectorConstruction());
runManager->SetUserInitialization(new QBBC);
runManager->SetUserInitialization(new ActionInitialization());

G4UImanager* UImanager = G4UImanager::GetUIpointer();
G4String command = "/control/execute ";
G4String fileName = argv[1];
UImanager->ApplyCommand(command+fileName);

delete runManager;
}
```

which will be displayed in the post as:

int main(int argc,char** argv)
{
  auto* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
  runManager->SetUserInitialization(new DetectorConstruction());
  runManager->SetUserInitialization(new QBBC);
  runManager->SetUserInitialization(new ActionInitialization());

  G4UImanager* UImanager = G4UImanager::GetUIpointer();
  G4String command = "/control/execute ";
  G4String fileName = argv[1];
  UImanager->ApplyCommand(command+fileName);

  delete runManager;
}

Much nicer!

7 Likes
Cosmic ray and Geant4
Change from Particlegun to GPS
I want to find out how to run my STCyclotron example successfully
A beginner at geant4
The install of geant4-v11.2.0.beta
Radiobiology module - add new lines in data/rbe/lem1.csv
Generation of two particles with event using nd280Geant4Sim_7.14
Confused by output of AuNP example
Generation of two particles particle gun fur ND280, T2K simulation
Microyz Cmake and make
Compiling geant4 Again
How does Geant4 compute the uncertainty of simulation results
Getting charge in G4_Galactic from a neutral heavy ion beam
Again build Geant4
Brachytherapy example
Deflection in magnetic field with zero charge heavy ion
Potential Issue in G4CompetitiveFission::GetEmissionProbability: Incorrect Excitation Energy Leading to Zero Fission Probability
Can't open my own example
Issues Running Geant4 B1 Example Inside EIC Shell Container
G4UserLimits causes corruption of output file
BooleanProcessor: corrupted input polyhedron
Unexpected energy deposition by neutrons
Geant4 Windows Binary static library issue
Irradiate ICRP 110 phantom and record spectra
Dnadamage1 - underestimation of indirect SB after irradiation with alpha-partciles
Physics models of nuclear reactions
Method volume and Get Copy Number problem
Compilation of Geant 4 Library on Mac
Crash with low energy particles by gps
Which interface I should use to set up the temperature dependence of neutron reaction cross sections in Geant4?
Slight overlap in the detector structure
HPGe efficiency in low energy
There is some difference when I using GPS and ParticleGun
How to define the particle angle information
How to Properly Implement HPGe Detector Characteristics (Resolution and Efficiency) in Geant4
molecularDNA example: no DNA damage outputs or histograms after >72 hours when using monoenergetic C-12 ions
Cout EventAction information in the EndOfRunAction()
G4NEutronhpdata for BNCT simulation
Problem with rendering of fonts
The yield of scintillation is not as same as the before set
Generate source particles
Geant4 int to string problem
The dielectric process of ions seems not activated in Geant4’s microelectonics example
Problem in Installation of Geant4
To calculate flux
Running Geant 4 files
Problem in Installation of Geant4
Installation of Geant4 with CMake
The problem of physics list
No isotope cross section found for neutron off Element Pu240 in PuO2 Z= 94 A= 240 E(MeV)= 27.3642
Geant 4 installation on ubuntu 24.04 problems also qt5 is not availble how to install it
Hadr09 and G4PhysListFactory
Capture cross section
DICOM example: Missing class/header
The meaning of Time
When compiling Geant4 on Mac, I encountered an unsolved system error saying: ld: framework 'AGL' not found clang++: error: linker command failed with exit code 1
Simulating decay processes in neutron detectors
Alpha particles from proton boron fusion reaction
The problems about chem4
TS materials showing unnatural results
Photonuclear cross sections for 197Au
Default value for Specularspike constant
Assistance Required for GEANT4 Simulation of p(⁷Li, n)⁷Be Reaction
Measuring mass attenuation coefficient of CsI
Charge state models for ions(heavy ions)
Geometry and physic characteristics
Geant4 visualization
How to desgine a geant4 project?
How to define H- ions in Geant4 with GPS or G4ParticleGun
How to remove fatal error while working on geant4
How to model neutron‑induced DNA damage with molecularDNA?
To evaluate the gamma rays emitted only by bismuth-21
Gamma dose in air
My two sensitive detectors are not communicating and the one attached to scintillator has no output
Steplimits and QGSP_BIC_AllHP
Dose Kernel question
Missing library during linking
Command thresholdForVeryLongDecayTime for radioactive decay
No Radioactive decay Command thresholdForVeryLongDecayTime
Geant4_DNA;UHDR
Issue compiling Geant 4 V11.3.1 on MacOS 15.4
Geant4 on windows, Nistmanager not working?
How to visualized the geometry
Track stuck in nanoscale volumes
Creating Electric field in specific volume using fieldBuilder
Cmake environment variables error
GetProcessName in G4VProcess
Scattering energy dependance with angle
Neutron simulation
Appropriate Physicslist for Neutron production
Optical photons do not refract
Switch from proton to e-
Problem with reading more than one .gdml file
How to accessing which material caused G4OpWLS process
NeutronHP Warning with QGSP_BERT_HP
SaG4n error about netron data library
Vertex location with Bremsstrahlung process
Physics list for decay chain and gamma cascades
Force a Run to stop or kill
How to use tinyxml2 for Geant4 project
How to Generate Custom Plasmid Structures for MolecularDNA Simulations?
Header files wrong
Magnetic field not working for Logical Volume
Problem in exampleB1 visualization
Font issue in Fedora
Nesting calorimeters not working
Boundary issue on detector
Ways to visualizing only primary particles
Geant4-DNA Tracking individual molecules?
Error in Geant4 Installation
Sanity check my generated xcode project?
Run B1 example after installing geant4
Problem of generate random 4pi vectors
Geant4 microyz modified to neurons geometry parameters
Geant4 11.3.0 Issue in build /link: undefined reference
Biased radioactive decay
Primary particle count per event
Unable to Emit All Particles; Program Freezes During Execution
Problems on Killing track and Secondaries
The problem of Stuck Track: potential geometry or navigation problem. Track stuck, not moving for 10 steps
Runtime issues while making examples due to issues with CommandLineTools SDKs
Can someone explain how to use a histogram energy spectrum as a source input for GPS
Mac os qt5 vis need update
Example B1 execution
Not able to see photons in my visualization
The position of radicals over time
Entry Point Not Found (file.exe)
Pdb4dna- geant4.11.2
Missing atomic relaxation for Tb-161 / Dy-161
G4SiPM Visualization GUI window
Visualization window open, show axes and particles' trajectories but doesn't show volume
Electron trajectories at low energy in a low electric field
How to get the the name of parent particle that created the current track?
Tracking Decay Event "forward"
Compiler Error when filling Ntuples with a vector
Issue with optical photons crossing a boundary
Proton and boron-11 cross-section
No Geometry simulated (ExampleB1)
The particle source of UHDR
G4Tubs Center Of mass
Multi-thread problems
Retrieving and saving particle/track information
Symbol lookup error
Download geant4.11.2
Possible bug in EmLivermore and optical photon generation
Scoring mesh has an unexpected blank row: A bug or misunderstanding of how score meshes or angle biasing work in Geant4?
Hadr02 core dumb error
Building Geant4 with cmake-gui and Qt6 Installed
nCapture cross section in QGSP_BERT_HP model
What determines where an application looks for Dataset
Inactivate nuclear processes
Geant4-DNA and G4MoleculeCounter
'unknown type name QT6_VIRTUAL' on MacOS
Run time for optical photon scintillation process
Neutron emission from Isotope decay
How to get information of the scattering nuclei?
CMakeList.txt - extra include directories
Scintillation Photons in Geant4Py?
I am trying to run the basic B1 example but running into some problem
An issue in my CMakeLists.txt
Direction of delta electrons
Getting Wrong Electron Behaviour in E-Field
Install Geant4 from Source on a Mac
GEANT4 configuration warning
Missing Data_Galactic.dat file when modifying microelectronics example
How to Place or Delete Geometries via Messenger?
Low-energy dipole neutron-electron interaction
Problems from histogram filling
CZT or Cd-113 with thermal neutrons
Does cutting out secondary particles not always reduce the CPU time?
GEANT4 visualization taking a lot of time to load
Frame of reference for secondaries in Hadronic Interactions
Can anyone please guide me, how can I import stp file in geant4?
Scintillator with tyvek skin
INSTALL Build MSB3073 The Command "Setlocal Error
Simulating lead burger scintillator solid angle acceptance
Error compiling with TiMemory support
How to calculate standard error for RE02 example
Geometry, craeting
Geant4 installation in windows, getting error in cmake
Any VTK examples?
I'm facing an issue with core dump
Error with ToolsSG function : GetOrCreateNode
Error with ToolsSG
Non-physical chord lengths with COMSOL electric field
I'm trying to generate hit map but its showing an error
Get particle position at the end of a step
non-Uniform ElectricField from COMSOL
Not able visualise the geometry
Different source definitions
Control the initial and ending regions of particle emission
Without creating a root file when using detectors to collect particle information, the program cannot continue to run
Trouble running simulation in non-uniform electric field
How to improve the accuracy of Geant4 simulation
Helium beam range in Geant4 11.x
Getting B2a and b to run
Water radiolysis products
Retrieve position at a given time
Erroe when installing GEANT4 in ubuntu22.04.4
Why is the chronological order of recording secondary particles from largest to smallest
Add Magnetic Field from COMSOL to Geant4
Different processes for different regions
Error running geant4.csh
Get a Gaussian Energy deposited Spectrum
Error with SetSpline in detector build
PhysicsList for ionizing radiation shielding
How to get the photo-peak efficiency of a scinitllator?
Determening mean ionization energy for some material
DCMTK in DICOM example
Cannot generate root output file
I am creating a LaBr3 scintillator but getting more particle deposits than particles thrown
I am creating a LaBr3 scintillator but getting more particle deposits than particles thrown
[Installation Error] Install with Qt6 in Windows
How to stop a neutron with a specific energy to enter to a volume?
Thermal Neutrons : zsh.killed
Imported target "Geant4::G4OpenGL" includes non-existent path
To measure the precise position of beam strike on the front and back chamber and the number of beams passed through the middle block
Simple Gamma Detection Simulation
Question about G4PVParameterised
How to determine whether a particle is in an excited state
How to increase the probability of a hadronic process
Best way to install Qt5 on Ubuntu 23.10
Geant4-DNA: how to visualize the nucleosomes in moleculardna
Cannot create ions, GenericIon not ready
Merging output files (.csv) when operating in MULTITHREAD mode
Runtime exception during execution, leading to a crash
Cannot open output ROOT file
Determining basic components
I cannot start the simulation
Could not get the results
Issues with B1 on HPC
Possible error building geant4 10.7 on rhel9
Error C2039 '_finite' is not a member of 'std' in the file xlocnum
How to record particle's deposited energy spectrum for each process
MT-threading in the example of chem4
Error in EventAction.cc
B2a example crash
How to detect Gamma photons through composite material By NaI Detector
OpNovice Example
How to define a carbon ion
ReinitializeGemotry will cause SensitiveDetector crash
In Hadron 00 the result I got began with N column with entris from 0 to 799 I want to know what it stands forentries from 0
What event seed means
Problem with definition of ion source
The wrong decay spectrum is obtained
Object lifetimes (C++ lifetimes)
Detector overlapping porblem
Error running example ICRP145_HumanPhantoms
Steeping action and EventAction
Error on B1 compillation
Neutron energy spectrum
Neutron Detector
Application Seg Faulting on Triton production
Simulating neutron source from Am241/Be9
Beta decay of 11Be
WorldLV is registered to the default region?
Installation of G4.10.6.3 fails on ubuntu22.04
Specular reflection of neutron
Geant4 in RockyLinux
Geant visualization
Problem related to crashing/ break segmentation
Can not construct PhysicsList for proton
Gamma and neutron simulation
Multi-thread Issue in ICRP110_HumanPhantom
Kill particles born in the wrong volume
How to generate Gaussian peak?
Geant4-v11.1.2 PTL error on macOS Sonoma
GEANT4 error WARNING: Scene "none" not found. /vis/scene/list to see scenes
Secondary electron
E-/e+ pair production test
Inquiring about Optical properties to perform Optical Simulations at NIR-II (1000-1700 nm) wavelengths through adipose tissue, fats, and intralipid
Installation error with FindCoin.cmake
Physics List for x-ray spectrum simulation
Error in Detector Construction.cc while compilation
Help with G4ExtrudedSolid
How to correctly simulate Particle Discrimination?
Record Species in different Volume & copynum
The link ftp://gdo-nuclear.ucllnl.org/ is now broken,where can i download G4LENDDATA?
2H(2H,n) yield as a function of theta incorrect
Why detectorconstruction class pointer can not access its solution?
Tips for effective and successful posting
Core dump Track information is not available at this moment
Error on the definition of the material
Error on the definition of the material
Silicon detector
Detector will not show in any examples
Error in DetectorConstruction.cc
Error on ActionInitialization
How to run the root example of brachytherapy
Error on the hits
Erreur de segmentation (core dumped)
How do I apply ProjectX to the image using the root library? I was filling firsty_bin and lasty_bin as I wish, but the projectionX is not coming
Start a processus radioactive
How to get the specified molecule from methon GetRecordedMolecules
Recording theta, phi and psi
The puzzle about example B1
Error on Geant4config.cmake
TextGeom manual
Modeling of the Sarad EQF 3600 detector
Visualization failure
Please how do i resolve the problem in the process of creating my detector
How to get the pulse waveform data when a particle hits the scintillator?
Having issue running my first example for the second time and this error message prompt up, please i do nee guidance thanks
Difficulty in installs package
Difficulty in installs package
Qt5config.cmake error when downloading to apple silicon device
Simulation results changes when I increase the number of primary particles
Running rdecay02, no run1.mac included
-- Looking for IceConnectionNumber in ICE - not found
Incompatible PTL
Linker error: cannot find /: File format not recognized
Dataset cannot be downloaded
Example b1: error
Installing Geant4 v11 with conda
Example B5 on geant 4.11
How to change the GUI to OGLQT rather than OGLWin32
Installing Geant4 v10.0.0
Geant4 extended example : gammatherapie
How to use Multithreads to read a file?
error_CLHEp_GEANTv4.11
Trying to upgrade to v11.1.1 from v10.7.4
Visualization command not working
Installation of data files
Non finding G4processes.so despite finding other libraries
How to disable configuration warnings
Maybe the Intel cpu with "Large and small nuclei" is not for multithreads mode in Geant4?
Thermal neutron capture time and spectra disagreement with NNDC data for 12C
Neutron Multiplicity Counting: Reducing Computational Load and Managing Time
Qt6CoreConfig.cmake missing on Mac
Scintillation photons are not produced
Unsuccessful compile - libG4ToolsSG: fat file missing arch 'arm64', file has 'i386,x86_64'