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> |
---|
15 | System of units |
---|
16 | </title> |
---|
17 | |
---|
18 | <!-- ******************* Section (Level#2) ****************** --> |
---|
19 | <sect2 id="sect.SysUni.BasicUni"> |
---|
20 | <title> |
---|
21 | Basic units |
---|
22 | </title> |
---|
23 | |
---|
24 | <para> |
---|
25 | Geant4 offers the user the possibility to choose and use the |
---|
26 | preferred units for any quantity. In fact, Geant4 takes |
---|
27 | care of the units. Internally a consistent set on units |
---|
28 | based on the <literal>HepSystemOfUnits</literal> is used: |
---|
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> |
---|
46 | All other units are defined from the basic ones. |
---|
47 | </para> |
---|
48 | |
---|
49 | <para> |
---|
50 | For 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> |
---|
64 | In the file |
---|
65 | <literal>$CLHEP_BASE_DIR/include/CLHEP/Units/SystemOfUnits.h</literal> |
---|
66 | from the CLHEP installation, one can find all untis definitions. |
---|
67 | </para> |
---|
68 | |
---|
69 | <para> |
---|
70 | One can also change the system of units to be used by the kernel. |
---|
71 | </para> |
---|
72 | |
---|
73 | </sect2> |
---|
74 | |
---|
75 | <!-- ******************* Section (Level#2) ****************** --> |
---|
76 | <sect2 id="sect.SysUni.InputData"> |
---|
77 | <title> |
---|
78 | Input your data |
---|
79 | </title> |
---|
80 | |
---|
81 | <!-- ******************* Section (Level#3) ****************** --> |
---|
82 | <sect3 id="sect.SysUni.InputData.AvoidHardCoded"> |
---|
83 | <title> |
---|
84 | Avoid 'hard coded' data |
---|
85 | </title> |
---|
86 | |
---|
87 | <para> |
---|
88 | The user <emphasis role="bold">must</emphasis> give the units for the |
---|
89 | data to introduce: |
---|
90 | |
---|
91 | <informalexample> |
---|
92 | <programlisting> |
---|
93 | G4double Size = 15*km, KineticEnergy = 90.3*GeV, density = 11*mg/cm3; |
---|
94 | </programlisting> |
---|
95 | </informalexample> |
---|
96 | </para> |
---|
97 | |
---|
98 | <para> |
---|
99 | Geant4 assumes that these specifications for the units are respected, |
---|
100 | in order to assure indeipendence from the units chosen in the client |
---|
101 | application. |
---|
102 | </para> |
---|
103 | |
---|
104 | <para> |
---|
105 | If units are not specified in the client application, data are implicitly |
---|
106 | treated in internal Geant4 system units; this practice is however strongly |
---|
107 | discouraged. |
---|
108 | </para> |
---|
109 | |
---|
110 | <para> |
---|
111 | If the data set comes from an array or from an external file, it |
---|
112 | is strongly recommended to set the units as soon as the data are |
---|
113 | read, before any treatment. For instance: |
---|
114 | |
---|
115 | <informalexample> |
---|
116 | <programlisting> |
---|
117 | for (int j=0, j<jmax, j++) CrossSection[j] *= millibarn; |
---|
118 | ... |
---|
119 | my calculations |
---|
120 | ... |
---|
121 | </programlisting> |
---|
122 | </informalexample> |
---|
123 | </para> |
---|
124 | |
---|
125 | </sect3> |
---|
126 | |
---|
127 | <!-- ******************* Section (Level#3) ****************** --> |
---|
128 | <sect3 id="sect.SysUni.InputData.Interactive"> |
---|
129 | <title> |
---|
130 | Interactive commands |
---|
131 | </title> |
---|
132 | |
---|
133 | <para> |
---|
134 | Some built-in commands from the User Interface (UI) also require |
---|
135 | units to be specified. |
---|
136 | </para> |
---|
137 | |
---|
138 | <para> |
---|
139 | For instance: |
---|
140 | |
---|
141 | <informalexample> |
---|
142 | <programlisting> |
---|
143 | /gun/energy 15.2 keV |
---|
144 | /gun/position 3 2 -7 meter |
---|
145 | </programlisting> |
---|
146 | </informalexample> |
---|
147 | </para> |
---|
148 | |
---|
149 | <para> |
---|
150 | If units are not specified, or are not valid, the command is refused. |
---|
151 | </para> |
---|
152 | |
---|
153 | </sect3> |
---|
154 | </sect2> |
---|
155 | |
---|
156 | |
---|
157 | <!-- ******************* Section (Level#2) ****************** --> |
---|
158 | <sect2 id="sect.SysUni.OutputData"> |
---|
159 | <title> |
---|
160 | Output your data |
---|
161 | </title> |
---|
162 | |
---|
163 | <para> |
---|
164 | You can output your data with the wished units. To do so, it is |
---|
165 | sufficient to <emphasis role="bold">divide</emphasis> the data by the |
---|
166 | corresponding unit: |
---|
167 | |
---|
168 | <informalexample> |
---|
169 | <programlisting> |
---|
170 | G4cout << KineticEnergy/keV << " keV"; |
---|
171 | G4cout << density/(g/cm3) << " g/cm3"; |
---|
172 | </programlisting> |
---|
173 | </informalexample> |
---|
174 | </para> |
---|
175 | |
---|
176 | <para> |
---|
177 | Of course, <literal>G4cout << KineticEnergy</literal> will print the |
---|
178 | energy in the internal units system. |
---|
179 | </para> |
---|
180 | |
---|
181 | <para> |
---|
182 | There is another way to output the data. Let Geant4 choose the |
---|
183 | most appropriate units for the actual numerical value of the data. |
---|
184 | It is sufficient to specify to which category the data belong to |
---|
185 | (Length, Time, Energy, etc.). For example |
---|
186 | |
---|
187 | <informalexample> |
---|
188 | <programlisting> |
---|
189 | G4cout << G4BestUnit(StepSize, "Length"); |
---|
190 | </programlisting> |
---|
191 | </informalexample> |
---|
192 | </para> |
---|
193 | |
---|
194 | <para> |
---|
195 | <literal>StepSize</literal> will be printed in km, m, mm, fermi, etc. |
---|
196 | depending of its actual value. |
---|
197 | </para> |
---|
198 | |
---|
199 | </sect2> |
---|
200 | |
---|
201 | |
---|
202 | <!-- ******************* Section (Level#2) ****************** --> |
---|
203 | <sect2 id="sect.SysUni.IntroNewUnits"> |
---|
204 | <title> |
---|
205 | Introduce new units |
---|
206 | </title> |
---|
207 | |
---|
208 | <para> |
---|
209 | If wished to introduce new units, there are two methods: |
---|
210 | |
---|
211 | <itemizedlist spacing="compact"> |
---|
212 | <listitem><para> |
---|
213 | You can complete the file <literal>SystemOfUnits.h</literal> |
---|
214 | |
---|
215 | <informalexample> |
---|
216 | <programlisting> |
---|
217 | #include "SystemOfUnits.h" |
---|
218 | |
---|
219 | static const G4double inch = 2.54*cm; |
---|
220 | </programlisting> |
---|
221 | </informalexample> |
---|
222 | |
---|
223 | Using this method, it is not easy to define composed units. It |
---|
224 | is better to do the following: |
---|
225 | </para></listitem> |
---|
226 | <listitem><para> |
---|
227 | Instantiate an object of the class |
---|
228 | <emphasis>G4UnitDefinition</emphasis> |
---|
229 | |
---|
230 | <informalexample> |
---|
231 | <programlisting> |
---|
232 | G4UnitDefinition ( name, symbol, category, value ) |
---|
233 | </programlisting> |
---|
234 | </informalexample> |
---|
235 | |
---|
236 | For example: define a few units for speed |
---|
237 | |
---|
238 | <informalexample> |
---|
239 | <programlisting> |
---|
240 | G4UnitDefinition ( "km/hour" , "km/h", "Speed", km/(3600*s) ); |
---|
241 | G4UnitDefinition ( "meter/ns", "m/ns", "Speed", m/ns ); |
---|
242 | </programlisting> |
---|
243 | </informalexample> |
---|
244 | |
---|
245 | The category "Speed" does not exist by default in |
---|
246 | <emphasis>G4UnitsTable</emphasis>, but it will be created automatically. |
---|
247 | The class <emphasis>G4UnitDefinition</emphasis> is located in |
---|
248 | <literal>source/global/management</literal>. |
---|
249 | </para></listitem> |
---|
250 | </itemizedlist> |
---|
251 | </para> |
---|
252 | |
---|
253 | </sect2> |
---|
254 | |
---|
255 | <!-- ******************* Section (Level#2) ****************** --> |
---|
256 | <sect2 id="sect.SysUni.PrintUnits"> |
---|
257 | <title> |
---|
258 | Print the list of units |
---|
259 | </title> |
---|
260 | |
---|
261 | <para> |
---|
262 | You can print the list of units with the static function: |
---|
263 | <literal>G4UnitDefinition::PrintUnitsTable();</literal> |
---|
264 | </para> |
---|
265 | |
---|
266 | <para> |
---|
267 | or with the interactive command: <literal>/units/list</literal> |
---|
268 | </para> |
---|
269 | |
---|
270 | |
---|
271 | </sect2> |
---|
272 | </sect1> |
---|