Units

From Daya Bay

Jump to: navigation, search
Offline Documentation: [Offline Category] [FAQ] [Howto] [Reference] [Manual]


Offline Documentation
This article is part
of the Offline Documentation
Other pages...

Offline Category
FAQ
How Tos
Reference
Manual
Getting Started
Software Installation

See also...

General Help on this Wiki


In NuWa software, all quantities that have units should work within a specific "system of units". When a variable holds a quantity one should not "know" what unit the quantity is in. On the other hand, when expressing a quantity as a literal number it should always have an explicit unit. Some examples are given:

Saving a quantity with a unit in a variable

C++:

# include "GaudiKernel/SystemOfUnits.h"
using namespace Gaudi; // all units are in Gaudi::Units name space
...
double energy = 8 * Units::MeV;

Python:

import GaudiPython.SystemOfUnits as units
...
energy = 8 * units.MeV

Extracting a quantity in a specific unit

C++:

cout << "The energy is " << energy/Units::MeV " MeV\n";

Python:

print 'The energy is %f MeV'%energy/units.MeV

Handling values with units on the command line

Users should be able to use units from either the nuwa.py command line or from job module command lines. For example:

nuwa.py -A 30*microsecond

will set the default AES window to be 30e-6 seconds long.

In your job module code you should interpret any command line argument that can have units using the unitify() function from the DybPython.Tools module. For example:

def configure(argv):
  from DybPython.Tools import unitify
  val = argv[0]      # get string from command line
  val = unitify(val) # now a numeric in our system-of-units

It is possible to specify a default unit which will be applied if the user does not specify an explicit unit:

  val = unitify(val,"second")

Implicit Units

Try to avoid using implicit units on the command line. But, if they must be used it is best to be consistent across all job modules. Use MKS (meter, kg, second). Modules allowing implicit units should still use unitify() as described above.

What units are available

To see what units are available run pydoc GaudiKernel.SystemOfUnits which will print:

shell> pydoc GaudiKernel.SystemOfUnits
Help on module GaudiKernel.SystemOfUnits in GaudiKernel:

NAME
   GaudiKernel.SystemOfUnits

FILE
   /data0/bv/offline/NuWa-trunk/gaudi/InstallArea/python/GaudiKernel/SystemOfUnits.py

DESCRIPTION
   # File: AthenaCommon/share/SystemOfUnits.py
   # Author: Wim Lavrijsen (LBNL, WLavrijsen@lbl.gov)
   # Created: 01/21/04
   # Last: 01/21/04

DATA
   GeV = 1000.0
   MeV = 1.0
   PeV = 1000000000.0
   TeV = 1000000.0
   ampere = 6241506363.094028
   angstrom = 1.0000000000000001e-07
   atmosphere = 632420632.2405024
   bar = 624150636.3094027
   barn = 9.999999999999999e-23
   becquerel = 1e-09
   candela = 1.0
   centimeter = 10.0
   centimeter2 = 100.0
   centimeter3 = 1000.0
   cm = 10.0
   cm2 = 100.0
   cm3 = 1000.0
   coulomb = 6.241506363094028e+18
   curie = 37.0
   deg = 0.017453292519943295
   degree = 0.017453292519943295
   eV = 1e-06
   e_SI = 1.60217733e-19
   electronvolt = 1e-06
   eplus = 1.0
   farad = 6.241506363094028e+24
   femtosecond = 1.0000000000000002e-06
   fermi = 1e-12
   g = 6.241506363094027e+21
   gauss = 1.0000000000000001e-07
   gigaelectronvolt = 1000.0
   gram = 6.241506363094027e+21
   gray = 1e-12
   henry = 1.6021773299999997e-07
   hep_pascal = 6241.506363094028
   hertz = 1e-09
   joule = 6241506363094.027
   keV = 0.001
   kelvin = 1.0
   kg = 6.241506363094027e+24
   kiloelectronvolt = 0.001
   kilogauss = 0.0001
   kilogram = 6.241506363094027e+24
   kilohertz = 1.0000000000000002e-06
   kilometer = 1000000.0
   kilometer2 = 1000000000000.0
   kilometer3 = 1e+18
   kilovolt = 0.001
   km = 1000000.0
   km2 = 1000000000000.0
   km3 = 1e+18
   lumen = 1.0
   lux = 1e-06
   m = 1000.0
   m2 = 1000000.0
   m3 = 1000000000.0
   megaelectronvolt = 1.0
   megahertz = 0.001
   megavolt = 1.0
   meter = 1000.0
   meter2 = 1000000.0
   meter3 = 1000000000.0
   mg = 6.241506363094027e+18
   microampere = 6241.5063630940285
   microbarn = 9.999999999999999e-29
   microfarad = 6.241506363094028e+18
   micrometer = 0.001
   microsecond = 1000.0
   milliampere = 6241506.363094029
   millibarn = 9.999999999999999e-26
   millifarad = 6.241506363094028e+21
   milligram = 6.241506363094027e+18
   millimeter = 1.0
   millimeter2 = 1.0
   millimeter3 = 1.0
   milliradian = 0.001
   millisecond = 1000000.0
   mm = 1.0
   mm2 = 1.0
   mm3 = 1.0
   mole = 1.0
   mrad = 0.001
   ms = 1000000.0
   nanoampere = 6.241506363094029
   nanobarn = 1e-31
   nanofarad = 6241506363094029.0
   nanometer = 1.0000000000000002e-06
   nanosecond = 1.0
   newton = 6241506363.0940275
   ns = 1.0
   ohm = 1.6021773299999997e-16
   parsec = 3.0856775807e+19
   pascal = 6241.506363094028
   pc = 3.0856775807e+19
   perCent = 0.01
   perMillion = 1e-06
   perThousand = 0.001
   petaelectronvolt = 1000000000.0
   picobarn = 1e-34
   picofarad = 6241506363094.028
   picosecond = 0.001
   rad = 1.0
   radian = 1.0
   s = 1000000000.0
   second = 1000000000.0
   sr = 1.0
   steradian = 1.0
   teraelectronvolt = 1000000.0
   tesla = 0.001
   volt = 1e-06
   watt = 6241.506363094028
   weber = 1000.0


Offline Software Documentation: [Offline Categories] [FAQ] [Offline Reference Category]
Personal tools