| 1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>3.3. System of units</title><link rel="stylesheet" href="../xml/XSLCustomizationLayer/G4HTMLStylesheet.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.71.1"><link rel="start" href="index.html" title="Geant4 User's Guide for Application Developers"><link rel="up" href="ch03.html" title="Chapter 3. Toolkit Fundamentals"><link rel="prev" href="ch03s02.html" title="3.2. Global Usage Classes"><link rel="next" href="ch03s04.html" title="3.4. Run"><script language="JavaScript">
|
|---|
| 2 | function remote_win(fName)
|
|---|
| 3 | {
|
|---|
| 4 | var url = "AllResources/Detector/geometry.src/" + fName;
|
|---|
| 5 | RemoteWin=window.open(url,"","resizable=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,width=520,height=520")
|
|---|
| 6 | RemoteWin.creator=self
|
|---|
| 7 | }
|
|---|
| 8 | </script></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3.3.
|
|---|
| 9 | System of units
|
|---|
| 10 | </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s02.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><th width="60%" align="center">Chapter 3.
|
|---|
| 11 | Toolkit Fundamentals
|
|---|
| 12 | </th><td width="20%" align="right"> <a accesskey="n" href="ch03s04.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sect.SysUni"></a>3.3.
|
|---|
| 13 | System of units
|
|---|
| 14 | </h2></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.SysUni.BasicUni"></a>3.3.1.
|
|---|
| 15 | Basic units
|
|---|
| 16 | </h3></div></div></div><p>
|
|---|
| 17 | Geant4 offers the user the possibility to choose and use the
|
|---|
| 18 | units he prefers for any quantity. In fact, the Geant4 kernel takes
|
|---|
| 19 | care of the units. Internally it uses a consistent set on units
|
|---|
| 20 | based on the <code class="literal">HepSystemOfUnits</code>:
|
|---|
| 21 |
|
|---|
| 22 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 23 | millimeter (mm)
|
|---|
| 24 | nanosecond (ns)
|
|---|
| 25 | Mega electron Volt (MeV)
|
|---|
| 26 | positron charge (eplus)
|
|---|
| 27 | degree Kelvin (kelvin)
|
|---|
| 28 | the amount of substance (mole)
|
|---|
| 29 | luminous intensity (candela)
|
|---|
| 30 | radian (radian)
|
|---|
| 31 | steradian (steradian)
|
|---|
| 32 | </pre></div><p>
|
|---|
| 33 | </p><p>
|
|---|
| 34 | All other units are defined from the basic ones.
|
|---|
| 35 | </p><p>
|
|---|
| 36 | For instance:
|
|---|
| 37 |
|
|---|
| 38 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 39 | millimeter = mm = 1;
|
|---|
| 40 | meter = m = 1000*mm;
|
|---|
| 41 | ...
|
|---|
| 42 | m3 = m*m*m;
|
|---|
| 43 | ...
|
|---|
| 44 | </pre></div><p>
|
|---|
| 45 | </p><p>
|
|---|
| 46 | In the file
|
|---|
| 47 | <code class="literal">source/global/management/include/SystemOfUnits.h</code> you will
|
|---|
| 48 | find all of these definitions. That file is part of CLHEP.
|
|---|
| 49 | </p><p>
|
|---|
| 50 | Moreover, the user is free to change the system of units to be
|
|---|
| 51 | used by the kernel.
|
|---|
| 52 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.SysUni.InputData"></a>3.3.2.
|
|---|
| 53 | Input your data
|
|---|
| 54 | </h3></div></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.SysUni.InputData.AvoidHardCoded"></a>3.3.2.1.
|
|---|
| 55 | Avoid 'hard coded' data
|
|---|
| 56 | </h4></div></div></div><p>
|
|---|
| 57 | You <span class="bold"><strong>must</strong></span> give the units for the
|
|---|
| 58 | data you are going to
|
|---|
| 59 | introduce:
|
|---|
| 60 |
|
|---|
| 61 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 62 | G4double Size = 15*km, KineticEnergy = 90.3*GeV, density = 11*mg/cm3;
|
|---|
| 63 | </pre></div><p>
|
|---|
| 64 | </p><p>
|
|---|
| 65 | Indeed, the full Geant4 code is written respecting these
|
|---|
| 66 | specifications, and this makes it independent of the units chosen
|
|---|
| 67 | by the user.
|
|---|
| 68 | </p><p>
|
|---|
| 69 | If the units are not specified, it is understood that the data
|
|---|
| 70 | is implicitly in the internal G4 system, but this is strongly
|
|---|
| 71 | discouraged.
|
|---|
| 72 | </p><p>
|
|---|
| 73 | If the data set comes from an array or from an external file, it
|
|---|
| 74 | is strongly recommended to set the units as soon as the data are
|
|---|
| 75 | read, before any treatment. For instance:
|
|---|
| 76 |
|
|---|
| 77 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 78 | for (int j=0, j<jmax, j++) CrossSection[j] *= millibarn;
|
|---|
| 79 | ...
|
|---|
| 80 | my calculations
|
|---|
| 81 | ...
|
|---|
| 82 | </pre></div><p>
|
|---|
| 83 | </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.SysUni.InputData.Interactive"></a>3.3.2.2.
|
|---|
| 84 | Interactive commands
|
|---|
| 85 | </h4></div></div></div><p>
|
|---|
| 86 | Some built-in commands from the User Interface (UI) also require
|
|---|
| 87 | the units to be specified.
|
|---|
| 88 | </p><p>
|
|---|
| 89 | For instance:
|
|---|
| 90 |
|
|---|
| 91 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 92 | /gun/energy 15.2 keV
|
|---|
| 93 | /gun/position 3 2 -7 meter
|
|---|
| 94 | </pre></div><p>
|
|---|
| 95 | </p><p>
|
|---|
| 96 | If the units are not specified, or are not valid, the command is
|
|---|
| 97 | refused.
|
|---|
| 98 | </p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.SysUni.OutputData"></a>3.3.3.
|
|---|
| 99 | Output your data
|
|---|
| 100 | </h3></div></div></div><p>
|
|---|
| 101 | You can output your data with the units you wish. To do so, it is
|
|---|
| 102 | sufficient to <span class="bold"><strong>divide</strong></span> the data by the
|
|---|
| 103 | corresponding unit:
|
|---|
| 104 |
|
|---|
| 105 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 106 | G4cout << KineticEnergy/keV << " keV";
|
|---|
| 107 | G4cout << density/(g/cm3) << " g/cm3";
|
|---|
| 108 | </pre></div><p>
|
|---|
| 109 | </p><p>
|
|---|
| 110 | Of course, <code class="literal">G4cout << KineticEnergy</code> will print the
|
|---|
| 111 | energy in the internal units system.
|
|---|
| 112 | </p><p>
|
|---|
| 113 | There is another way to output your data. Let Geant4 choose the
|
|---|
| 114 | most appropriate units for the actual numerical value of your data.
|
|---|
| 115 | It is sufficient to specify to which category your data belong
|
|---|
| 116 | (Length, Time, Energy, etc.). For example
|
|---|
| 117 |
|
|---|
| 118 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 119 | G4cout << G4BestUnit(StepSize, "Length");
|
|---|
| 120 | </pre></div><p>
|
|---|
| 121 | </p><p>
|
|---|
| 122 | <code class="literal">StepSize</code> will be printed in km, m, mm, fermi, etc.
|
|---|
| 123 | depending of its actual value.
|
|---|
| 124 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.SysUni.IntroNewUnits"></a>3.3.4.
|
|---|
| 125 | Introduce new units
|
|---|
| 126 | </h3></div></div></div><p>
|
|---|
| 127 | If you wish to introduce new units, there are two methods:
|
|---|
| 128 |
|
|---|
| 129 | </p><div class="itemizedlist"><ul type="disc" compact><li><p>
|
|---|
| 130 | You can complete the file <code class="literal">SystemOfUnits.h</code>
|
|---|
| 131 |
|
|---|
| 132 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 133 | #include "SystemOfUnits.h"
|
|---|
| 134 |
|
|---|
| 135 | static const G4double inch = 2.54*cm;
|
|---|
| 136 | </pre></div><p>
|
|---|
| 137 |
|
|---|
| 138 | Using this method, it is not easy to define composed units. It
|
|---|
| 139 | is better to do the following:
|
|---|
| 140 | </p></li><li><p>
|
|---|
| 141 | You can instantiate an object of the class
|
|---|
| 142 | <span class="emphasis"><em>G4UnitDefinition</em></span>
|
|---|
| 143 |
|
|---|
| 144 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 145 | G4UnitDefinition ( name, symbol, category, value )
|
|---|
| 146 | </pre></div><p>
|
|---|
| 147 |
|
|---|
| 148 | For example: define a few units for speed
|
|---|
| 149 |
|
|---|
| 150 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 151 | G4UnitDefinition ( "km/hour" , "km/h", "Speed", km/(3600*s) );
|
|---|
| 152 | G4UnitDefinition ( "meter/ns", "m/ns", "Speed", m/ns );
|
|---|
| 153 | </pre></div><p>
|
|---|
| 154 |
|
|---|
| 155 | The category "Speed" does not exist by default in
|
|---|
| 156 | <span class="emphasis"><em>G4UnitsTable</em></span>, but it will be created automatically.
|
|---|
| 157 | The class <span class="emphasis"><em>G4UnitDefinition</em></span> is located in
|
|---|
| 158 | <code class="literal">source/global/management</code>.
|
|---|
| 159 | </p></li></ul></div><p>
|
|---|
| 160 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.SysUni.PrintUnits"></a>3.3.5.
|
|---|
| 161 | Print the list of units
|
|---|
| 162 | </h3></div></div></div><p>
|
|---|
| 163 | You can print the list of units with the static function:
|
|---|
| 164 | <code class="literal">G4UnitDefinition::PrintUnitsTable();</code>
|
|---|
| 165 | </p><p>
|
|---|
| 166 | or with the interactive command: <code class="literal">/units/list</code>
|
|---|
| 167 | </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s02.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><td width="20%" align="center"><a accesskey="u" href="ch03.html"><img src="AllResources/IconsGIF/up.gif" alt="Up"></a></td><td width="40%" align="right"> <a accesskey="n" href="ch03s04.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr><tr><td width="40%" align="left" valign="top">3.2.
|
|---|
| 168 | Global Usage Classes
|
|---|
| 169 | </td><td width="20%" align="center"><a accesskey="h" href="index.html"><img src="AllResources/IconsGIF/home.gif" alt="Home"></a></td><td width="40%" align="right" valign="top"> 3.4.
|
|---|
| 170 | Run
|
|---|
| 171 | </td></tr></table></div></body></html>
|
|---|