source: trunk/documents/UserDoc/UsersGuides/ForApplicationDeveloper/html/Fundamentals/unitSystem.html @ 1231

Last change on this file since 1231 was 1208, checked in by garnier, 15 years ago

CVS update

File size: 5.5 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
2<HTML>
3<HEAD>
4<TITLE></TITLE>
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<META NAME="GENERATOR" CONTENT="Mozilla/3.0Gold (X11; I; OSF1 V4.0 alpha) [Netscape]">
11</HEAD>
12<BODY>
13<TABLE WIDTH="100%" >
14<TR>
15<TD>
16
17</A>
18<A HREF="index.html">
19<IMG SRC="../../../../resources/html/IconsGIF/Contents.gif" ALT="Contents" HEIGHT=16 WIDTH=59></A>
20<A HREF="global.html">
21<IMG SRC="../../../../resources/html/IconsGIF/Previous.gif" ALT="Previous" HEIGHT=16 WIDTH=59>
22<A HREF="run.html">
23<IMG SRC="../../../../resources/html/IconsGIF/Next.gif" ALT="Next" HEIGHT=16 WIDTH=59></A>
24</TD>
25
26<TD ALIGN="Right"><FONT COLOR="#238E23"><FONT SIZE=-1>
27<B>Geant4 User's Guide</B> <BR>
28<B>For Application Developers</B> <BR>
29<B>Toolkit Fundamentals</B> </FONT></FONT> 
30</TD>
31</TR>
32</TABLE>
33
34<P><BR>
35<CENTER><FONT COLOR="#238E23"><FONT SIZE=+3>
36<B>3.3 System of units </B>
37</FONT></FONT> <BR>
38</CENTER>
39<BR>
40
41<HR ALIGN="Center" SIZE="7%">
42<P>
43
44<a name="3.3.1">
45<H2>3.3.1 Basic units</h2></a>
46
47<P>
48 Geant4 offers the user the possibility to choose and use the units
49 he prefers for any quantity. In fact, the Geant4 kernel takes care of
50 the units. Internally it uses a consistent set on units based on the
51 <tt>HepSystemOfUnits</tt>:
52<P> 
53<PRE>
54                millimeter              (mm)
55                nanosecond              (ns)
56                Mega electron Volt      (MeV)
57                positron charge         (eplus)
58                degree Kelvin           (kelvin)
59                the amount of substance (mole)
60                luminous intensity      (candela)
61                radian                  (radian)
62                steradian               (steradian)
63</PRE>
64<P>
65 All other units are defined from the basic ones.
66<P> 
67 For instance:
68<PRE>
69                 millimeter = mm = 1;
70                 meter = m = 1000*mm;
71                 ...
72                 m3 = m*m*m;
73                 ...
74</PRE>
75<P>
76 In the file <TT>source/global/management/include/SystemOfUnits.h</TT>
77 you will find all of these definitions. That file is part of CLHEP.
78<P>
79 Moreover, the user is free to change the system of units to be used by the
80 kernel.
81<p>
82
83<HR>
84<a name="3.3.2">
85<H2>3.3.2 Input your data</H2></a>
86
87<b>Avoid 'hard coded' data</b>
88<P>
89 You <B>must</B> give the units for the data you are going to introduce:
90<PRE>
91 G4double Size = 15*km, KineticEnergy = 90.3*GeV, density = 11*mg/cm3;
92</PRE>
93<P>
94 Indeed, the full Geant4 code is written respecting these specifications,
95 and this makes it independent of the units chosen by the user.
96<P>
97 If the units are not specified, it is understood that the data is implicitly
98 in the internal G4 system, but this is strongly discouraged.
99<P> 
100 If the data set comes from an array or from an external file, it is strongly
101 recommended to set the units as soon as the data are read, before any
102 treatment. For instance:
103<P>
104<PRE>
105  for (int j=0, j&lt;jmax, j++) CrossSection[j] *= millibarn;
106  ...
107  my calculations
108  ...
109</PRE>
110<P><BR>
111
112<b>Interactive commands</b>
113
114<P>
115 Some built-in commands from the User Interface (UI) also require the units
116 to be specified.
117<P> 
118 For instance:
119<PRE>
120    /gun/energy 15.2 keV
121    /gun/position 3 2 -7 meter
122</PRE>
123<P>
124 If the units are not specified, or are not valid, the command is refused.
125<P>
126
127<HR>
128<a name="3.3.3">
129<H2>3.3.3 Output your data</H2></a>
130
131 You can output your data with the units you wish. To do so, it
132 is sufficient to <b>divide</b> the data by the corresponding unit:
133 <PRE>     
134      G4cout << KineticEnergy/keV << " keV";
135      G4cout << density/(g/cm3)   << " g/cm3";
136 </PRE>
137 <P>
138 Of course, <tt>G4cout << KineticEnergy</tt> will print the energy in the
139  internal units system.
140 <P>
141 There is another way to output your data. Let Geant4 choose the most
142 appropriate units for the actual numerical value of your data. It is
143 sufficient to specify to which category your data belong (Length, Time,
144 Energy, etc.). For example
145 <PRE>
146      G4cout << G4BestUnit(StepSize, "Length");
147 </PRE>
148 <P>
149 <tt>StepSize</tt> will be printed in km, m, mm, fermi, etc. depending of
150 its actual value.
151<P>
152
153<HR>
154<a name="3.3.4">
155<H2>3.3.4 Introduce new units</H2></a>
156
157<P>
158 If you wish to introduce new units, there are two methods:
159
160<UL>
161 <P>
162 <LI> You can complete the file <tt>SystemOfUnits.h</tt> </LI>
163 
164 <PRE> 
165      #include "SystemOfUnits.h"
166     
167      static const G4double inch = 2.54*cm;
168 </PRE>
169 <P>
170 Using this method, it is not easy to define composed units. It is better
171 to do the following:
172 <P>
173 <LI> You can instantiate an object of the class <i>G4UnitDefinition</i> </LI>
174
175 <PRE>   
176      G4UnitDefinition ( name, symbol, category, value )
177 </PRE>
178 <P>
179 For example: define a few units for speed
180
181 <PRE> 
182      G4UnitDefinition ( "km/hour" , "km/h", "Speed", km/(3600*s) );
183      G4UnitDefinition ( "meter/ns", "m/ns", "Speed", m/ns );
184 </PRE>
185 <P>
186 The category "Speed" does not exist by default in <i>G4UnitsTable</i>,
187 but it will be created automatically.
188 <P> 
189 The class <i>G4UnitDefinition</i> is located in <tt>source/global/management</tt>.
190</UL>
191<P>
192
193<HR>
194<a name="3.3.5">
195<H2>3.3.5 Print the list of units</H2></a>
196
197<P>
198 You can print the list of units with the static function:
199 <tt>G4UnitDefinition::PrintUnitsTable();</tt>
200<P>
201 or with the interactive command: <TT>/units/list</TT>
202
203<P><BR><BR>
204
205<HR>
206<A HREF="../../../../Authors/html/subjectsToAuthors.html">
207<I>About the authors</A></I>   
208
209</BODY>
210</HTML>
Note: See TracBrowser for help on using the repository browser.