# When calculating a volume mass, why do I have to multiply the value by the charge of an electron to get the real value in grams?

Hi there,

I have run into a strange situation where I am trying to retrieve the mass of a water cavity using:

``````material = aStep->GetTrack()->GetMaterial();
density  = material->GetDensity();
G4double cavityVolume = (aStep->GetTrack()->GetVolume()->GetLogicalVolume()->GetSolid()->GetCubicVolume()) / 1000; //cm3
G4double massOfCavity = cavityVolume * density;
``````

However, this method prints a massOfCavity in the order of 10^14.
After calculating the volume manually I divided the number here by the true number and this returned the charge of an electron i.e. 1.602… x10^-19.

Does anyone know why the density needs to be multiplied by the charge of an electron in order to return it to the unit of g?

Thanks

I don’t think you have understood the G4 system of units. Do not do your own conversions! Only convert the canonical way at output.

material = aStep->GetTrack()->GetMaterial();
density = material->GetDensity();
G4double cavityVolume = (aStep->GetTrack()->GetVolume()->GetLogicalVolume()->GetSolid()->GetCubicVolume());
G4double massOfCavity = cavityVolume * density;
G4cout << “mass is " << massOfCavity/kg << " kg” << G4endl; // Or g or mg, etc.

Thanks for your answer. Are you able to explain a little about why it is massOfCavity / kg, please? I am looking at the System Of Units and kg is defined as (joule x second x second) / (meter x meter). I am trying to rearrange the dimensions in order to figure out what is happening, but I don’t know what units are the raw output from G4 functions, therefore it is difficult to convert. For example, I think I have made mistakes in the past by doing cavityVolume x cm3, in order to return a volume in cm3, as would be done in DetectorConstruction e.g. when defining geometry sizes (length x cm).

Thanks again.

You should not need to know what the internal units of Geant4 are. As you saw, kg is defined as (joule x second x second) / (meter x meter). In other words, it is defined as energy, and uses Einstein’s famous equivalence between mass and energy, `E=mc^2`.

To return a quantity to human recognition, you should divide by cm3 - `cavityVolume/cm3`. (In the opposite situation, entering quantities into Geant4, you should multiply - `volume=18*cm3`).

Thank you, the first part was mainly a point of interest and I was thinking that since the output number was so big it is likely to be due to it being defined by E=mc2.

To reiterate. Always and only ever use the Geant4 unit constants defined in `G4SystemOfUnits.hh` to convert from internal quantities to physical units. Do not try to do “by hand” conversions on your own.

The Geant4 code, all the way through, has been built in an internally consistent way with respect to units; the unit constants are provided specifically for conversion to external, human readable quantities.

The units of kinematical quantities are all done in “particle physics” style: that is, mass, momentum and energy are all handled in MeV (that is, a system where c=1). Thus, in Geant4, `m = sqrt(E*E - p*p)`, without any factors of c_light. This is, as John Allison noted above, handled properly by units. So you can print, for example

``````G4double proton = G4Proton::GetDefintion()->GetPDGMass();
G4cout << "Proton mass: " << proton/GeV << " GeV" << G4endl;
G4cout << "Proton mass: " << proton/kg << " kg" << G4endl;
``````

and you’ll get the expected values of 0.938 GeV and 1.673e-27 kg.

System of units is explained in user doc : book for application developers -> toolkit fundamentals -> system of units.
On output, I recommend G4cout << G4BestUnit (massOfCavity, “Mass”)