source: trunk/documents/UserDoc/DocBookUsersGuides/ForApplicationDeveloper/xml/Fundamentals/unitSystem.xml @ 1013

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

ajout de la doc

File size: 6.9 KB
Line 
1<!-- ******************************************************** -->
2<!--                                                          -->
3<!--  [History]                                               -->
4<!--    Converted to DocBook: Katsuya Amako, Aug-2006         -->
5<!--    Changed by: Katsuya Amako, 14-Jul-1998                -->
6<!--    Changed by: Katsuya Amako, 30-Nov-1998                -->
7<!--    Changed by: Dennis Wright, 20-Nov-2001                -->
8<!--    Proof read by: Joe Chuma,  28-Jun-1999                -->
9<!--                                                          -->
10<!-- ******************************************************** -->
11
12<!-- ******************* Section (Level#1) ****************** -->
13<sect1 id="sect.SysUni">
14<title>
15System of units
16</title>
17
18<!-- ******************* Section (Level#2) ****************** -->
19<sect2 id="sect.SysUni.BasicUni">
20<title>
21Basic units
22</title>
23
24<para>
25Geant4 offers the user the possibility to choose and use the
26units he prefers for any quantity. In fact, the Geant4 kernel takes
27care of the units. Internally it uses a consistent set on units
28based on the <literal>HepSystemOfUnits</literal>:
29
30<informalexample>
31<programlisting>
32                millimeter              (mm)
33                nanosecond              (ns)
34                Mega electron Volt      (MeV)
35                positron charge         (eplus)
36                degree Kelvin           (kelvin)
37                the amount of substance (mole)
38                luminous intensity      (candela)
39                radian                  (radian)
40                steradian               (steradian)
41</programlisting>
42</informalexample>
43</para>
44
45<para>
46All other units are defined from the basic ones.
47</para>
48
49<para>
50For instance:
51
52<informalexample>
53<programlisting>
54                 millimeter = mm = 1;
55                 meter = m = 1000*mm;
56                 ...
57                 m3 = m*m*m;
58                 ...
59</programlisting>
60</informalexample>
61</para>
62
63<para>
64In the file
65<literal>source/global/management/include/SystemOfUnits.h</literal> you will
66find all of these definitions. That file is part of CLHEP.
67</para>
68
69<para>
70Moreover, the user is free to change the system of units to be
71used by the kernel.
72</para>
73
74</sect2>
75
76<!-- ******************* Section (Level#2) ****************** -->
77<sect2 id="sect.SysUni.InputData">
78<title>
79Input your data
80</title>
81
82<!-- ******************* Section (Level#3) ****************** -->
83<sect3 id="sect.SysUni.InputData.AvoidHardCoded">
84<title>
85Avoid 'hard coded' data
86</title>
87
88<para>
89You <emphasis role="bold">must</emphasis> give the units for the
90data you are going to
91introduce:
92
93<informalexample>
94<programlisting>
95 G4double Size = 15*km, KineticEnergy = 90.3*GeV, density = 11*mg/cm3;
96</programlisting>
97</informalexample>
98</para>
99
100<para>
101Indeed, the full Geant4 code is written respecting these
102specifications, and this makes it independent of the units chosen
103by the user.
104</para>
105
106<para>
107If the units are not specified, it is understood that the data
108is implicitly in the internal G4 system, but this is strongly
109discouraged.
110</para>
111
112<para>
113If the data set comes from an array or from an external file, it
114is strongly recommended to set the units as soon as the data are
115read, before any treatment. For instance:
116
117<informalexample>
118<programlisting>
119  for (int j=0, j&lt;jmax, j++) CrossSection[j] *= millibarn;
120  ...
121  my calculations
122  ...
123</programlisting>
124</informalexample>
125</para>
126
127</sect3>
128
129<!-- ******************* Section (Level#3) ****************** -->
130<sect3 id="sect.SysUni.InputData.Interactive">
131<title>
132Interactive commands
133</title>
134
135<para>
136Some built-in commands from the User Interface (UI) also require
137the units to be specified.
138</para>
139
140<para>
141For instance:
142
143<informalexample>
144<programlisting>
145    /gun/energy 15.2 keV
146    /gun/position 3 2 -7 meter
147</programlisting>
148</informalexample>
149</para>
150
151<para>
152If the units are not specified, or are not valid, the command is
153refused.
154</para>
155
156</sect3>
157</sect2>
158
159
160<!-- ******************* Section (Level#2) ****************** -->
161<sect2 id="sect.SysUni.OutputData">
162<title>
163Output your data
164</title>
165
166<para>
167You can output your data with the units you wish. To do so, it is
168sufficient to <emphasis role="bold">divide</emphasis> the data by the
169corresponding unit:
170
171<informalexample>
172<programlisting>     
173      G4cout &lt;&lt; KineticEnergy/keV &lt;&lt; " keV";
174      G4cout &lt;&lt; density/(g/cm3)   &lt;&lt; " g/cm3";
175</programlisting>
176</informalexample>     
177</para>
178
179<para>
180Of course, <literal>G4cout &lt;&lt; KineticEnergy</literal> will print the
181energy in the internal units system.
182</para>
183
184<para>
185There is another way to output your data. Let Geant4 choose the
186most appropriate units for the actual numerical value of your data.
187It is sufficient to specify to which category your data belong
188(Length, Time, Energy, etc.). For example
189
190<informalexample>
191<programlisting>     
192      G4cout &lt;&lt; G4BestUnit(StepSize, "Length");
193</programlisting>
194</informalexample>     
195</para>
196
197<para>
198<literal>StepSize</literal> will be printed in km, m, mm, fermi, etc.
199depending of its actual value.
200</para>
201
202</sect2>
203
204
205<!-- ******************* Section (Level#2) ****************** -->
206<sect2 id="sect.SysUni.IntroNewUnits">
207<title>
208Introduce new units
209</title>
210
211<para>
212If you wish to introduce new units, there are two methods:
213
214<itemizedlist spacing="compact">
215  <listitem><para>
216    You can complete the file <literal>SystemOfUnits.h</literal>
217
218    <informalexample>
219    <programlisting>       
220      #include "SystemOfUnits.h"
221     
222      static const G4double inch = 2.54*cm;
223    </programlisting>
224    </informalexample>     
225
226    Using this method, it is not easy to define composed units. It
227    is better to do the following:
228  </para></listitem>
229  <listitem><para>
230    You can instantiate an object of the class
231    <emphasis>G4UnitDefinition</emphasis>
232
233    <informalexample>
234    <programlisting>       
235      G4UnitDefinition ( name, symbol, category, value )
236    </programlisting>
237    </informalexample>       
238
239    For example: define a few units for speed
240
241    <informalexample>
242    <programlisting>       
243      G4UnitDefinition ( "km/hour" , "km/h", "Speed", km/(3600*s) );
244      G4UnitDefinition ( "meter/ns", "m/ns", "Speed", m/ns );
245    </programlisting>
246    </informalexample>       
247
248    The category "Speed" does not exist by default in
249    <emphasis>G4UnitsTable</emphasis>, but it will be created automatically.
250    The class <emphasis>G4UnitDefinition</emphasis> is located in
251    <literal>source/global/management</literal>.
252  </para></listitem>
253</itemizedlist>
254</para>
255
256</sect2>
257
258<!-- ******************* Section (Level#2) ****************** -->
259<sect2 id="sect.SysUni.PrintUnits">
260<title>
261Print the list of units
262</title>
263
264<para>
265You can print the list of units with the static function:
266<literal>G4UnitDefinition::PrintUnitsTable();</literal>
267</para>
268
269<para>
270or with the interactive command: <literal>/units/list</literal>
271</para>
272
273
274</sect2>
275</sect1>
Note: See TracBrowser for help on using the repository browser.