[904] | 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 | units he prefers for any quantity. In fact, the Geant4 kernel takes |
---|
| 27 | care of the units. Internally it uses a consistent set on units |
---|
| 28 | based 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> |
---|
| 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>source/global/management/include/SystemOfUnits.h</literal> you will |
---|
| 66 | find all of these definitions. That file is part of CLHEP. |
---|
| 67 | </para> |
---|
| 68 | |
---|
| 69 | <para> |
---|
| 70 | Moreover, the user is free to change the system of units to be |
---|
| 71 | used by the kernel. |
---|
| 72 | </para> |
---|
| 73 | |
---|
| 74 | </sect2> |
---|
| 75 | |
---|
| 76 | <!-- ******************* Section (Level#2) ****************** --> |
---|
| 77 | <sect2 id="sect.SysUni.InputData"> |
---|
| 78 | <title> |
---|
| 79 | Input your data |
---|
| 80 | </title> |
---|
| 81 | |
---|
| 82 | <!-- ******************* Section (Level#3) ****************** --> |
---|
| 83 | <sect3 id="sect.SysUni.InputData.AvoidHardCoded"> |
---|
| 84 | <title> |
---|
| 85 | Avoid 'hard coded' data |
---|
| 86 | </title> |
---|
| 87 | |
---|
| 88 | <para> |
---|
| 89 | You <emphasis role="bold">must</emphasis> give the units for the |
---|
| 90 | data you are going to |
---|
| 91 | introduce: |
---|
| 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> |
---|
| 101 | Indeed, the full Geant4 code is written respecting these |
---|
| 102 | specifications, and this makes it independent of the units chosen |
---|
| 103 | by the user. |
---|
| 104 | </para> |
---|
| 105 | |
---|
| 106 | <para> |
---|
| 107 | If the units are not specified, it is understood that the data |
---|
| 108 | is implicitly in the internal G4 system, but this is strongly |
---|
| 109 | discouraged. |
---|
| 110 | </para> |
---|
| 111 | |
---|
| 112 | <para> |
---|
| 113 | If the data set comes from an array or from an external file, it |
---|
| 114 | is strongly recommended to set the units as soon as the data are |
---|
| 115 | read, before any treatment. For instance: |
---|
| 116 | |
---|
| 117 | <informalexample> |
---|
| 118 | <programlisting> |
---|
| 119 | for (int j=0, j<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> |
---|
| 132 | Interactive commands |
---|
| 133 | </title> |
---|
| 134 | |
---|
| 135 | <para> |
---|
| 136 | Some built-in commands from the User Interface (UI) also require |
---|
| 137 | the units to be specified. |
---|
| 138 | </para> |
---|
| 139 | |
---|
| 140 | <para> |
---|
| 141 | For 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> |
---|
| 152 | If the units are not specified, or are not valid, the command is |
---|
| 153 | refused. |
---|
| 154 | </para> |
---|
| 155 | |
---|
| 156 | </sect3> |
---|
| 157 | </sect2> |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | <!-- ******************* Section (Level#2) ****************** --> |
---|
| 161 | <sect2 id="sect.SysUni.OutputData"> |
---|
| 162 | <title> |
---|
| 163 | Output your data |
---|
| 164 | </title> |
---|
| 165 | |
---|
| 166 | <para> |
---|
| 167 | You can output your data with the units you wish. To do so, it is |
---|
| 168 | sufficient to <emphasis role="bold">divide</emphasis> the data by the |
---|
| 169 | corresponding unit: |
---|
| 170 | |
---|
| 171 | <informalexample> |
---|
| 172 | <programlisting> |
---|
| 173 | G4cout << KineticEnergy/keV << " keV"; |
---|
| 174 | G4cout << density/(g/cm3) << " g/cm3"; |
---|
| 175 | </programlisting> |
---|
| 176 | </informalexample> |
---|
| 177 | </para> |
---|
| 178 | |
---|
| 179 | <para> |
---|
| 180 | Of course, <literal>G4cout << KineticEnergy</literal> will print the |
---|
| 181 | energy in the internal units system. |
---|
| 182 | </para> |
---|
| 183 | |
---|
| 184 | <para> |
---|
| 185 | There is another way to output your data. Let Geant4 choose the |
---|
| 186 | most appropriate units for the actual numerical value of your data. |
---|
| 187 | It is sufficient to specify to which category your data belong |
---|
| 188 | (Length, Time, Energy, etc.). For example |
---|
| 189 | |
---|
| 190 | <informalexample> |
---|
| 191 | <programlisting> |
---|
| 192 | G4cout << 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. |
---|
| 199 | depending of its actual value. |
---|
| 200 | </para> |
---|
| 201 | |
---|
| 202 | </sect2> |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | <!-- ******************* Section (Level#2) ****************** --> |
---|
| 206 | <sect2 id="sect.SysUni.IntroNewUnits"> |
---|
| 207 | <title> |
---|
| 208 | Introduce new units |
---|
| 209 | </title> |
---|
| 210 | |
---|
| 211 | <para> |
---|
| 212 | If 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> |
---|
| 261 | Print the list of units |
---|
| 262 | </title> |
---|
| 263 | |
---|
| 264 | <para> |
---|
| 265 | You can print the list of units with the static function: |
---|
| 266 | <literal>G4UnitDefinition::PrintUnitsTable();</literal> |
---|
| 267 | </para> |
---|
| 268 | |
---|
| 269 | <para> |
---|
| 270 | or with the interactive command: <literal>/units/list</literal> |
---|
| 271 | </para> |
---|
| 272 | |
---|
| 273 | |
---|
| 274 | </sect2> |
---|
| 275 | </sect1> |
---|