GEANT4 offers the user the possibility to choose and use the units he prefers for any quantity. In fact the Geant4 kernel takes care of the units. Internaly it uses a consistent set on units based on:
millimeter (mm) nanosecond (ns) Mega electron Volt (MeV) positron charge (eplus) degree Kelvin (kelvin) the amount of substance (mole) luminous intensity (candela) radian (radian) steradian (steradian)
All the others units are defined from the basic ones.
In the file: source/global/management/include/SystemOfUnits.h you will find all these definitions. That file is part of CLHEP.
G4UnitDefinition::PrintUnitsTable(); Idle> /units/list
You must give the unit of the data you are going to introduce:
G4double Size = 15*km, KineticEnergy = 90.3*GeV, density = 11*mg/cm3;
If the unit is not specified, it is understood that the data is implicitely in the internal G4 system, but this is discouraged.
If the data set comes from an array or from an external file, it is strongly recommanded to set the unit as soon as the data are read, before any treatement. For instance, immediatly after to have read a file of cross sections expressed in millibarn:
for (int j=0, j<jmax, j++) CrossSection[j] *= millibarn; ........................................................ ...... my calculations .................................
Some built-in commands from the User Interface (UI) also require the unit.
/gun/energy 15.2 keV /gun/position 3 2 -7 meter
If the unit is not specified or not valid the command is refused.
G4cout << KineticEnergy/keV << " keV" ; G4cout << density/(g/cm3) << " g/cm3" ;
(of course: G4cout << KineticEnergy will print the energy in the internal system of units)
G4cout << G4BestUnit(StepSize, "Length");
StepSize will be printed in km, m, mm or ... fermi depending of its actual value.
you may wish introduce new units.
In this way it is not easy to define composed units.
example 1: define a few units for speed
G4UnitDefinition ("km/hour" , "km/h", "Speed", km/(3600*s) ); G4UnitDefinition ("meter/ns", "m/ns", "Speed", m/ns );The category "Speed" does not exist by default in G4UnitsTable, but it will be created automatically.
example 2: introduce pseudo-length and pseudo-energy
G4UnitDefinition ("g/cm2" , "g/cm2" , "speudoLength", g/cm2); G4UnitDefinition ("mg/cm2", "mg/cm2", "speudoLength", mg/cm2); G4UnitDefinition ("MeV.g-1.cm2", "MeV.g-1.cm2", "speudoEnergy", MeV*cm2/g );
The class G4UnitDefinition is located in source/global/management
The user is free to change the system of units to be used internally by the G4
To do so, one must redefine the basic units in SystemOfUnits.h and recompile the full Geant4 kernel, since the units are heavily used elsewhere (especially in the phycics sector).
Indeed the full Geant4 code is written respecting the above conventions and this makes it independent of the units chosen by the user.
The file source/global/management/include/G4UnitsTest.hh is an example of redefinition of the units: International System of units.
example of a shower profile
more examples can be found in source/global/management/test/G4UnitsTableTest.cc