Message: Re: adding new units to example B1 Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Feedback Re: adding new units to example B1 

Forum: Documentation and Examples
Re: Question adding new units to example B1 (Tim Meehan)
Date: 20 Jul, 2017
From: Michael H. Kelsey <Michael H. Kelsey>

I needed something similar for my experiment (which uses Imperial units for some major components...). I wrote a simple "mySystemOfUnits.hh" file with global constants:

  #include "G4SystemOfUnits.hh"

  static const double inch = 25.4*mm;
  static const double foot = 12.*inch;
  static const double yard = 36.*inch;
  static const double mile = 5280.*foot;
  static const double mil  = 0.001*inch;

Using the #include in my file, as above, means we can simply replace the usual line everywhere.

I also wrote a "myUnitsTable.hh" and .cc singleton, along the same lines as G4UnitsTable. In the constructor of the singleton, I have:

myUnitsTable::myUnitsTable() {
  new G4UnitDefinition("mil",  "mil", "Length", mil);
  new G4UnitDefinition("inch", "in",  "Length", inch);
  new G4UnitDefinition("foot", "ft",  "Length", foot);
  new G4UnitDefinition("yard", "yd",  "Length", yard);
  new G4UnitDefinition("mile", "mi",  "Length", mile);

  new G4UnitDefinition("perCent", "%",   "Fraction", perCent);
  new G4UnitDefinition("perMil",  "ppt", "Fraction", perThousand);
  new G4UnitDefinition("perMillion", "ppm", "Fraction", perMillion);
  new G4UnitDefinition("perBillion", "ppb", "Fraction", 0.001*perMillion);
}

I call myUnitsTable::Init() to instantiate it in my geometry construction class' own constructor. That way it's present right from the beginning of the job, even before the UI appears. The advantage to having the unit defintions above is that the strings are available for user macro commands (so a user could write "/exper/Vessel/Length 65 in" to set the cryostat length, rather than having to convert engineering drawing dimensions).

The other advantage, and disadvantage, is that the new units get included into the list of available units in the "Length" category. When you call G4BestUnit(value, "Length"), you can get results in mm, cm, m, whatever, but you can also get results in inches or feet! This can lead to unfortunate diagnostic output like a 3 cm value being printed as "1.18 in".

That's probably not a problem for your use case, but it is something to keep in mind.

  -- Michael Kelsey

 Add Message Add Message
to: "Re: adding new units to example B1"

 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 ]