I am loading an external electric field in Geant. My file coordinates x,y,z have units of meters and the electric field components are in V/m.
My question is, how does G4 interpret my external file? I am loading the external field and grid w.o specifying any unit.
For example : if I try to multiply the Ex component by volt/meter, it completely changes the value. I’ve read on multiple sources that it will interpret the field in V/mm but also MV/m and I am a bit confused and not sure how to use this information.
Is there a way to simply set the unit when loading the file? Or do I have to export my field first in MV/m or V/mm to avoid any intepretation issues?
Geant4 units are simply multiplicative factors (see $G4INCLUDE/CLHEP/Units/SystemOfUnits.h for the definitions), which have been carefully chosen to provide consistent behaviour when doing arithmetic with “dimensional” quantities. There are specific units which are defined in Geant4 to be multipliers of 1. – these are the so-called “internal units” that correspond to the numerical value of a dimensional variable.
For example, in G4 the “mm” unit is the base. So if you define a quantity like G4double detLength = 35.*meter;, you’ll discover that the number stored in detLength is actually 35000. But you can print it in any length unit by dividing by the unit you want:
The unit “volt” is not one of the G4 “internal units”. I don’t remember it’s value, but it’s not 1, nor a simple power of 10. So if you define your electric field magnitude as G4double efield = 25*V/m, the numeric value isn’t going to be anything like “25.”
When reading numbers from a file, they almost certainly don’t have Geant4 unit multipliers, so it’s your responsibility, in your code, to turn them into properly dimensional Geant4 quantities:
// Reading mesh field (x,y,z) in meters, E in V/m
G4double x,y,z,E;
meshin >> x >> y >> z >> E >> std::endl;
x *= meter;
y *= meter;
z *= meter;
E *= volt/meter;
If you want to print out your field magnitudes in V/mm, or MV/m or whatever, you can do that:
As an aside, if you want to put the unit name strings into your file, e.g.,
0.235 0.472 -0.015 m 237.8 V/m
You can read them in as strings (however you like to do that), and convert them to unit multipliers with e.g., G4UnitDefinition::GetValueOf(lengthName). Just don’t mix and match. Don’t multiply your length numbers by the voltage unit!
Thank you Michael. I have tried multiplying the values with [m] and [volt/meter] after being parsed in, and that changed their values, so I figured a conversion was going on.
I will do it like you mentioned: assign them unit multipliers when reading the data.