G4Material::GetDensity() HUGE and incomprehensible value

Hi everyone,

I have a weird thing happening when I call the function G4Material::GetDensity(). The density set for Germanium is 5.310*g/cm3 but when I call G4Material::GetMaterial(“Germanium”)->GetDensity() I got a HUGE value which I do not understand. Here is some line and the output, if anyone has an explanation…

Thanks in advance,
Mael.

Blockquote
double GermaniumBolometerBuilder::GetCrystalMass() {
std::cout << “Germanium density : " << G4Material::GetMaterial(“Germanium”)->GetDensity() <<”\n";//MAEL
//std::cout << “Germanium volume : " << GetCrystalVolume() <<”\n";
std::cout << G4Material::GetMaterial(“Germanium”) << “\n”;
return GetCrystalVolume() * G4Material::GetMaterial(“Germanium”)->GetDensity();
}
Blockquote
The output :

Blockquote
Germanium density : 3.31424e+19
Material: Germanium density: 5.310 g/cm3 RadL: 2.307 cm Nucl.Int.Length: 27.501 cm
Imean: 350.000 eV temperature: 293.15 K pressure: 1.00 atm

—> Element: Germanium naturel (Ge) Z = 32.0 N = 73 A = 72.630 g/mole
—> Isotope: Ge70 Z = 32 N = 70 A = 69.92 g/mole abundance: 20.518 %
—> Isotope: Ge72 Z = 32 N = 72 A = 71.92 g/mole abundance: 27.427 %
—> Isotope: Ge73 Z = 32 N = 73 A = 72.92 g/mole abundance: 7.759 %
—> Isotope: Ge74 Z = 32 N = 74 A = 73.92 g/mole abundance: 36.536 %
—> Isotope: Ge76 Z = 32 N = 76 A = 75.92 g/mole abundance: 7.759 %
ElmMassFraction: 100.00 % ElmAbundance 100.00 %

Blockquote

You don’t have any units included in your output, so you’re seeing G4’s “internal value”. The Geant4 internal system of units has MeV=1, mm=1, ns=1. From that information, you can derive what the internal units of density are (hint: they are not g/cm^3!).

Write your output statement as:

G4cout << "Germanium density : " << G4Material::GetMaterial(“Germanium”)->GetDensity()/(g/cm3)
       << " g/cm^3" << G4endl;

Also,

  • Use G4cout and not std::cout in your G4 code, so that multithreaded output is properly handled;
  • Always use G4endl (or std::endl with std::cout) to ensure that line buffers are properly flushed out.

the command: /units/list will print all available units and their internal value

Thanks you !
it worked, I just had to change the unit with CLHEP::g/CLHEP::cm3, and thanks for the advices.
Maël.

If you include G4SystemOfUnits.hh in your .cc file, then you don’t have to use the “CLHEP::” prefix (that .hh file has a bunch of using statements).