Getting units from generic G4double

Very simple question that I cannot find an answer for in the documentation. How can I ask for the units of any general object (specifically a G4double)?

G4double a = 10*nm;

then some function I pass ‘a’ to get a CLHEP object or G4Unit

Geant4 Version: 11.0.1
Operating System: mac OS Ventura
Compiler/Version: gcc 14.0

Geant4 has no default unit, just an internal set.
To get the value of a in specific unit (and other tricks):

You cannot. Geant4 does not implement units as an object. They are simply numbers which multiply other numbers. Geant4’s “internal units” are the ones where those multipliers are unity (mm, ns, MeV, radians, others); see $G4INCLUDE/CLHEP/Units/SystemOfUnits.h to look at the numeric values.

You need to know outside the program what units any given variable is “supposed” to be (length, energy, time, etc.). Once you know that, then you can divide by the appropriate specific unit for printing messages, storing in an N-tuple, etc.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.