Message: int-conversion with unit Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None int-conversion with unit 

Keywords: explicit cast with unit
Forum: Geometry
Date: 21 Mar, 2007
From: Sylvia Studeny <>

Hi, I discovered a strange thing in Gean4 concerning units: First I wanted to have an integer-number of the radius of an orb in order to put this into the filename (with sprintf). I solved this in a better way (posting 98): G4UIcommand::ConvertToString((radius/cm)*2./2.54)

The thing I descovered is, that there seems to be something strange with the units:

In DetectorConstruction: inchFactor = 2.54*cm; radius = 6.*inchFactor/2.;

In RunAction I get this radius with a Get-funktion, then I try :
G4cout << "=============================================================" <<G4endl;
  G4cout << "Int-ausgabe der kugelgröße : "<< G4endl;
   G4double zahl1,zahl2;
  G4cout <<"Radius of sphere(cm): "<< radius/cm<<G4endl;
  G4cout <<"Radius=7.62 of sphere(cm) as Integer with zahl1: "<< G4int(zahl1) <<G4endl;
  G4cout << "Radius=radius/cm of sphere(cm) as Integer with zahl2: "<<G4int(zahl2)<<G4endl;
  G4cout << "Radius of sphere(cm) as Integer: "<<G4int((radius/cm)*2./2.54) <<G4endl;
  G4cout <<"Radius of sphere(cm) as double: "<<(radius/cm)*2./2.54<< G4endl;
  G4cout << "=============================================================" <<G4endl;

I get the following output: ============================================================= Int-ausgabe der kugelgröße :

Radius of sphere(cm): 7.62

Radius=7.62 of sphere(cm) as Integer with zahl1: 6

Radius=radius/cm of sphere(cm) as Integer with zahl2: 5

Radius of sphere(cm) as Integer: 5

Radius of sphere(cm) as double: 6


Why is there this 5?????? I saw the same thing with energies(only at lower energies:<keV) Has it got something to do with the unit?????

I hope this only concerns the converting to int. Greetings, Sylvia

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 Feedback: Re: int-conversion with unit   (Gabriele Cosmo - 05 Apr, 2007)
 Add Message Add Message
to: "int-conversion with unit"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]