source: trunk/Documentation/geant4/UserDocumentation/UsersGuides/ForApplicationDeveloper/html/ch03s03.html @ 901

Last change on this file since 901 was 901, checked in by garnier, 16 years ago

Add Geant4 Documentation at 8.12.2008

File size: 8.6 KB
Line 
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">
2function 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. 
9System 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. 
11Toolkit 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. 
13System 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. 
15Basic units
16</h3></div></div></div><p>
17Geant4 offers the user the possibility to choose and use the
18units he prefers for any quantity. In fact, the Geant4 kernel takes
19care of the units. Internally it uses a consistent set on units
20based 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>
34All other units are defined from the basic ones.
35</p><p>
36For 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>
46In the file
47<code class="literal">source/global/management/include/SystemOfUnits.h</code> you will
48find all of these definitions. That file is part of CLHEP.
49</p><p>
50Moreover, the user is free to change the system of units to be
51used 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. 
53Input 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. 
55Avoid 'hard coded' data
56</h4></div></div></div><p>
57You <span class="bold"><strong>must</strong></span> give the units for the
58data you are going to
59introduce:
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>
65Indeed, the full Geant4 code is written respecting these
66specifications, and this makes it independent of the units chosen
67by the user.
68</p><p>
69If the units are not specified, it is understood that the data
70is implicitly in the internal G4 system, but this is strongly
71discouraged.
72</p><p>
73If the data set comes from an array or from an external file, it
74is strongly recommended to set the units as soon as the data are
75read, before any treatment. For instance:
76
77</p><div class="informalexample"><pre class="programlisting">
78  for (int j=0, j&lt;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. 
84Interactive commands
85</h4></div></div></div><p>
86Some built-in commands from the User Interface (UI) also require
87the units to be specified.
88</p><p>
89For 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>
96If the units are not specified, or are not valid, the command is
97refused.
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. 
99Output your data
100</h3></div></div></div><p>
101You can output your data with the units you wish. To do so, it is
102sufficient to <span class="bold"><strong>divide</strong></span> the data by the
103corresponding unit:
104
105</p><div class="informalexample"><pre class="programlisting">     
106      G4cout &lt;&lt; KineticEnergy/keV &lt;&lt; " keV";
107      G4cout &lt;&lt; density/(g/cm3)   &lt;&lt; " g/cm3";
108</pre></div><p>     
109</p><p>
110Of course, <code class="literal">G4cout &lt;&lt; KineticEnergy</code> will print the
111energy in the internal units system.
112</p><p>
113There is another way to output your data. Let Geant4 choose the
114most appropriate units for the actual numerical value of your data.
115It 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 &lt;&lt; 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.
123depending 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. 
125Introduce new units
126</h3></div></div></div><p>
127If 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. 
161Print the list of units
162</h3></div></div></div><p>
163You can print the list of units with the static function:
164<code class="literal">G4UnitDefinition::PrintUnitsTable();</code>
165</p><p>
166or 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. 
168Global 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. 
170Run
171</td></tr></table></div></body></html>
Note: See TracBrowser for help on using the repository browser.