| 1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>3.2. Global Usage Classes</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="ch03.html" title="Chapter 3. Toolkit Fundamentals"><link rel="next" href="ch03s03.html" title="3.3. System of units"><script language="JavaScript">
|
|---|
| 2 | function 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.2.
|
|---|
| 9 | Global Usage Classes
|
|---|
| 10 | </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><th width="60%" align="center">Chapter 3.
|
|---|
| 11 | Toolkit Fundamentals
|
|---|
| 12 | </th><td width="20%" align="right"> <a accesskey="n" href="ch03s03.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.GlobClass"></a>3.2.
|
|---|
| 13 | Global Usage Classes
|
|---|
| 14 | </h2></div></div></div><p>
|
|---|
| 15 | The "global" category in Geant4 collects all classes, types,
|
|---|
| 16 | structures and constants which are considered of general use within
|
|---|
| 17 | the Geant4 toolkit. This category also defines the interface with
|
|---|
| 18 | third-party software libraries (CLHEP, STL, etc.) and
|
|---|
| 19 | system-related types, by defining, where appropriate,
|
|---|
| 20 | <code class="literal">typedef</code>s according to the Geant4 code conventions.
|
|---|
| 21 | </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.GlobClass.SignClass"></a>3.2.1.
|
|---|
| 22 | Signature of Geant4 classes
|
|---|
| 23 | </h3></div></div></div><p>
|
|---|
| 24 | In order to keep an homogeneous naming style, and according to
|
|---|
| 25 | the Geant4 coding style conventions, each class part of the Geant4
|
|---|
| 26 | kernel has its name beginning with the prefix <span class="emphasis"><em>G4</em></span>, e.g.,
|
|---|
| 27 | <span class="emphasis"><em>G4VHit, G4GeometryManager, G4ProcessVector,</em></span> etc. Instead of
|
|---|
| 28 | the raw C types, <span class="emphasis"><em>G4</em></span> types are used within the Geant4 code.
|
|---|
| 29 | For the basic numeric types (<code class="literal">int, float, double,</code> etc.),
|
|---|
| 30 | different compilers and different platforms provide different value
|
|---|
| 31 | ranges. In order to assure portability, the use of <span class="emphasis"><em>G4int,
|
|---|
| 32 | G4float, G4double,</em></span> which are base classes globally defined, is
|
|---|
| 33 | preferable. <span class="emphasis"><em>G4</em></span> types implement the right generic type for a
|
|---|
| 34 | given architecture.
|
|---|
| 35 | </p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.GlobClass.SignClass.BasicType"></a>3.2.1.1.
|
|---|
| 36 | Basic types
|
|---|
| 37 | </h4></div></div></div><p>
|
|---|
| 38 | The basic types in Geant4 are considered to be the
|
|---|
| 39 | following:
|
|---|
| 40 |
|
|---|
| 41 | </p><div class="itemizedlist"><ul type="disc" compact><li><p>
|
|---|
| 42 | <span class="emphasis"><em>G4int</em></span>,
|
|---|
| 43 | </p></li><li><p>
|
|---|
| 44 | <span class="emphasis"><em>G4long</em></span>,
|
|---|
| 45 | </p></li><li><p>
|
|---|
| 46 | <span class="emphasis"><em>G4float</em></span>,
|
|---|
| 47 | </p></li><li><p>
|
|---|
| 48 | <span class="emphasis"><em>G4double</em></span>,
|
|---|
| 49 | </p></li><li><p>
|
|---|
| 50 | <span class="emphasis"><em>G4bool</em></span>,
|
|---|
| 51 | </p></li><li><p>
|
|---|
| 52 | <span class="emphasis"><em>G4complex</em></span>,
|
|---|
| 53 | </p></li><li><p>
|
|---|
| 54 | <span class="emphasis"><em>G4String</em></span>.
|
|---|
| 55 | </p></li></ul></div><p>
|
|---|
| 56 |
|
|---|
| 57 | which currently consist of simple <code class="literal">typedef</code>s to
|
|---|
| 58 | respective types defined in the <span class="bold"><strong>CLHEP</strong></span>,
|
|---|
| 59 | <span class="bold"><strong>STL</strong></span> or system
|
|---|
| 60 | libraries. Most definitions of these basic types come with the
|
|---|
| 61 | inclusion of a single header file, <code class="literal">globals.hh</code>. This file
|
|---|
| 62 | also provides inclusion of required system headers, as well as some
|
|---|
| 63 | global utility functions needed and used within the Geant4
|
|---|
| 64 | kernel.
|
|---|
| 65 | </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.GlobClass.SignClass.Typedefs"></a>3.2.1.2.
|
|---|
| 66 | Typedefs to CLHEP classes and their usage
|
|---|
| 67 | </h4></div></div></div><p>
|
|---|
| 68 | The following classes are <code class="literal">typedef</code>s to the corresponding
|
|---|
| 69 | classes of the <span class="bold"><strong>CLHEP</strong></span>
|
|---|
| 70 | (<span class="bold"><strong>Computing Library for High Energy Physics</strong></span>)
|
|---|
| 71 | distribution. For more detailed documentation please refer to the
|
|---|
| 72 | <a href="http://cern.ch/clhep/manual/RefGuide/" target="_top">
|
|---|
| 73 | <span class="bold"><strong>CLHEP reference guide</strong></span>
|
|---|
| 74 | </a>
|
|---|
| 75 | and the
|
|---|
| 76 | <a href="http://cern.ch/clhep/manual/UserGuide/" target="_top">
|
|---|
| 77 | <span class="bold"><strong>CLHEP user manual</strong></span>
|
|---|
| 78 | </a>
|
|---|
| 79 | .
|
|---|
| 80 |
|
|---|
| 81 | </p><div class="itemizedlist"><ul type="disc" compact><li><p>
|
|---|
| 82 | <span class="emphasis"><em>G4ThreeVector, G4RotationMatrix, G4LorentzVector</em></span> and
|
|---|
| 83 | <span class="emphasis"><em>G4LorentzRotation</em></span>
|
|---|
| 84 | </p><p>
|
|---|
| 85 | Vector classes: defining 3-component (x,y,z) vector entities,
|
|---|
| 86 | rotation of such objects as 3x3 matrices,
|
|---|
| 87 | 4-component (x,y,z,t) vector entities and their rotation as 4x4 matrices.
|
|---|
| 88 | </p><p>
|
|---|
| 89 | </p></li><li><p>
|
|---|
| 90 | <span class="emphasis"><em>G4Plane3D, G4Transform3D, G4Normal3D, G4Point3D</em></span>, and
|
|---|
| 91 | <span class="emphasis"><em>G4Vector3D</em></span>
|
|---|
| 92 | </p><p>
|
|---|
| 93 | Geometrical classes: defining geometrical entities and
|
|---|
| 94 | transformations in 3D space.
|
|---|
| 95 | </p><p>
|
|---|
| 96 | </p></li></ul></div><p>
|
|---|
| 97 | </p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.GlobClass.HEPRandom"></a>3.2.2.
|
|---|
| 98 | The <span class="emphasis"><em>HEPRandom</em></span> module in CLHEP
|
|---|
| 99 | </h3></div></div></div><p>
|
|---|
| 100 | The <span class="emphasis"><em>HEPRandom</em></span> module, originally part of the Geant4
|
|---|
| 101 | kernel, and now distributed as a module of <span class="bold"><strong>CLHEP</strong></span>,
|
|---|
| 102 | has been designed and developed starting from the <span class="emphasis"><em>Random</em></span>
|
|---|
| 103 | class of MC++, the original <span class="bold"><strong>CLHEP</strong></span>'s
|
|---|
| 104 | <span class="emphasis"><em>HepRandom</em></span> module and the
|
|---|
| 105 | <span class="bold"><strong>Rogue Wave</strong></span> approach in the
|
|---|
| 106 | <span class="bold"><strong>Math.h++</strong></span> package. For
|
|---|
| 107 | detailed documentation on the <span class="emphasis"><em>HEPRandom</em></span> classes see the
|
|---|
| 108 |
|
|---|
| 109 | <a href="http://cern.ch/clhep/manual/RefGuide/" target="_top">
|
|---|
| 110 | <span class="bold"><strong>CLHEP reference guide</strong></span>
|
|---|
| 111 | </a>
|
|---|
| 112 | and the
|
|---|
| 113 | <a href="http://cern.ch/clhep/manual/UserGuide/" target="_top">
|
|---|
| 114 | <span class="bold"><strong>CLHEP user manual</strong></span>
|
|---|
| 115 | </a>
|
|---|
| 116 | .
|
|---|
| 117 | </p><p>
|
|---|
| 118 | Information written in this manual is extracted from the
|
|---|
| 119 | original
|
|---|
| 120 | <a href="http://cern.ch/clhep/manual/UserGuide/Random/Random.html" target="_top">
|
|---|
| 121 | manifesto
|
|---|
| 122 | </a>
|
|---|
| 123 | distributed with the <span class="emphasis"><em>HEPRandom</em></span>
|
|---|
| 124 | package.</p><p>
|
|---|
| 125 | The <span class="emphasis"><em>HEPRandom</em></span> module consists of classes implementing
|
|---|
| 126 | different random ``engines'' and different random
|
|---|
| 127 | ``distributions''. A distribution associated to an engine
|
|---|
| 128 | constitutes a random ``generator''. A distribution class can
|
|---|
| 129 | collect different algorithms and different calling sequences for
|
|---|
| 130 | each method to define distribution parameters or range-intervals.
|
|---|
| 131 | An engine implements the basic algorithm for pseudo-random numbers
|
|---|
| 132 | generation.
|
|---|
| 133 | </p><p>
|
|---|
| 134 | There are 3 different ways of shooting random values:
|
|---|
| 135 |
|
|---|
| 136 | </p><div class="orderedlist"><ol type="1" compact><li><p>
|
|---|
| 137 | Using the static generator defined in the <span class="emphasis"><em>HepRandom</em></span>
|
|---|
| 138 | class: random values are shot using static methods <code class="literal">shoot()</code>
|
|---|
| 139 | defined for each distribution class. The static generator will use,
|
|---|
| 140 | as default engine, a <span class="emphasis"><em>HepJamesRandom</em></span> object, and the user can
|
|---|
| 141 | set its properties or change it with a new instantiated engine
|
|---|
| 142 | object by using the static methods defined in the <span class="emphasis"><em>HepRandom</em></span>
|
|---|
| 143 | class.
|
|---|
| 144 | </p></li><li><p>
|
|---|
| 145 | Skipping the static generator and specifying an engine object:
|
|---|
| 146 | random values are shot using static methods
|
|---|
| 147 | <code class="literal">shoot(*HepRandomEngine)</code> defined for each distribution
|
|---|
| 148 | class. The user must instantiate an engine object and give it as
|
|---|
| 149 | argument to the shoot method. The generator mechanism will then be
|
|---|
| 150 | by-passed by using the basic <code class="literal">flat()</code> method of the
|
|---|
| 151 | specified engine. The user must take care of the engine objects
|
|---|
| 152 | he/she instantiates.
|
|---|
| 153 | </p></li><li><p>
|
|---|
| 154 | Skipping the static generator and instantiating a distribution
|
|---|
| 155 | object: random values are shot using <code class="literal">fire()</code> methods (NOT
|
|---|
| 156 | static) defined for each distribution class. The user must
|
|---|
| 157 | instantiate a distribution object giving as argument to the
|
|---|
| 158 | constructor an engine by pointer or by reference. By doing so, the
|
|---|
| 159 | engine will be associated to the distribution object and the
|
|---|
| 160 | generator mechanism will be by-passed by using the basic
|
|---|
| 161 | <code class="literal">flat()</code> method of that engine.
|
|---|
| 162 | </p></li></ol></div><p>
|
|---|
| 163 | </p><p>
|
|---|
| 164 | In this guide, we'll only focus on the static generator (point
|
|---|
| 165 | 1.), since the static interface of <span class="emphasis"><em>HEPRandom</em></span> is the only one
|
|---|
| 166 | used within the Geant4 toolkit.
|
|---|
| 167 | </p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.GlobClass.HEPRandom.Engines"></a>3.2.2.1.
|
|---|
| 168 | <span class="emphasis"><em>HEPRandom</em></span> engines
|
|---|
| 169 | </h4></div></div></div><p>
|
|---|
| 170 | The class <span class="emphasis"><em>HepRandomEngine</em></span> is the abstract class defining
|
|---|
| 171 | the interface for each random engine. It implements the
|
|---|
| 172 | <code class="literal">getSeed()</code> and <code class="literal">getSeeds()</code> methods which return the
|
|---|
| 173 | `initial seed' value and the initial array of seeds (if any)
|
|---|
| 174 | respectively. Many concrete random engines can be defined and added
|
|---|
| 175 | to the structure, simply making them inheriting from
|
|---|
| 176 | <span class="emphasis"><em>HepRandomEngine</em></span>. Several different engines are currently
|
|---|
| 177 | implemented in <span class="emphasis"><em>HepRandom</em></span>, we describe here five of them:
|
|---|
| 178 |
|
|---|
| 179 | </p><div class="itemizedlist"><ul type="disc" compact><li><p>
|
|---|
| 180 | <span class="emphasis"><em>HepJamesRandom</em></span>
|
|---|
| 181 | </p><p>
|
|---|
| 182 | It implements the algorithm described in ``F.James, Comp. Phys.
|
|---|
| 183 | Comm. 60 (1990) 329'' for pseudo-random number generation. This is
|
|---|
| 184 | the default random engine for the static generator; it will be
|
|---|
| 185 | invoked by each distribution class unless the user sets a different one.
|
|---|
| 186 | </p><p>
|
|---|
| 187 | </p></li><li><p>
|
|---|
| 188 | <span class="emphasis"><em>DRand48Engine</em></span>
|
|---|
| 189 | </p><p>
|
|---|
| 190 | Random engine using the <code class="literal">drand48()</code> and
|
|---|
| 191 | <code class="literal">srand48()</code> system functions from C standard library to
|
|---|
| 192 | implement the <code class="literal">flat()</code> basic distribution and for setting
|
|---|
| 193 | seeds respectively. <span class="emphasis"><em>DRand48Engine</em></span> uses the
|
|---|
| 194 | <code class="literal">seed48()</code>
|
|---|
| 195 | function from C standard library to retrieve the current internal
|
|---|
| 196 | status of the generator, which is represented by 3 short values.
|
|---|
| 197 | <span class="emphasis"><em>DRand48Engine</em></span> is the only engine defined in
|
|---|
| 198 | <span class="emphasis"><em>HEPRandom</em></span>
|
|---|
| 199 | which intrinsically works in 32 bits precision. Copies of an object
|
|---|
| 200 | of this kind are not allowed.
|
|---|
| 201 | </p><p>
|
|---|
| 202 | </p></li><li><p>
|
|---|
| 203 | <span class="emphasis"><em>RandEngine</em></span>
|
|---|
| 204 | </p><p>
|
|---|
| 205 | Simple random engine using the <code class="literal">rand()</code> and
|
|---|
| 206 | <code class="literal">srand()</code> system functions from the C standard library to
|
|---|
| 207 | implement the <code class="literal">flat()</code> basic distribution and for setting
|
|---|
| 208 | seeds respectively. Please note that it's well known that the
|
|---|
| 209 | spectral properties of <code class="literal">rand()</code> leave a great deal to be
|
|---|
| 210 | desired, therefore the usage of this engine is not recommended if a
|
|---|
| 211 | good randomness quality or a long period is required in your code.
|
|---|
| 212 | Copies of an object of this kind are not allowed.
|
|---|
| 213 | </p><p>
|
|---|
| 214 | </p></li><li><p>
|
|---|
| 215 | <span class="emphasis"><em>RanluxEngine</em></span>
|
|---|
| 216 | </p><p>
|
|---|
| 217 | The algorithm for <span class="emphasis"><em>RanluxEngine</em></span> has been taken from the
|
|---|
| 218 | original implementation in FORTRAN77 by Fred James, part of the
|
|---|
| 219 | <span class="bold"><strong>MATHLIB HEP</strong></span> library. The initialisation is
|
|---|
| 220 | carried out using
|
|---|
| 221 | a Multiplicative Congruential generator using formula constants of
|
|---|
| 222 | L'Ecuyer as described in ``F.James, Comp. Phys. Comm. 60 (1990)
|
|---|
| 223 | 329-344''. The engine provides five different luxury levels for
|
|---|
| 224 | quality of random generation. When instantiating a
|
|---|
| 225 | <span class="emphasis"><em>RanluxEngine</em></span>, the user can specify the luxury level to the
|
|---|
| 226 | constructor (if not, the default value 3 is taken). For example:
|
|---|
| 227 |
|
|---|
| 228 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 229 | RanluxEngine theRanluxEngine(seed,4);
|
|---|
| 230 | // instantiates an engine with `seed' and the best luxury-level
|
|---|
| 231 | ... or
|
|---|
| 232 | RanluxEngine theRanluxEngine;
|
|---|
| 233 | // instantiates an engine with default seed value and luxury-level
|
|---|
| 234 | ...
|
|---|
| 235 | </pre></div><p>
|
|---|
| 236 |
|
|---|
| 237 | The class provides a <code class="literal">getLuxury()</code> method to get the
|
|---|
| 238 | engine luxury level.
|
|---|
| 239 | </p><p>
|
|---|
| 240 | </p><p>
|
|---|
| 241 | The <code class="literal">SetSeed()</code> and <code class="literal">SetSeeds()</code>
|
|---|
| 242 | methods to set the initial seeds for the engine, can be invoked specifying
|
|---|
| 243 | the luxury level. For example:
|
|---|
| 244 |
|
|---|
| 245 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 246 | // static interface
|
|---|
| 247 | HepRandom::setTheSeed(seed,4); // sets the seed to `seed' and luxury to 4
|
|---|
| 248 | HepRandom::setTheSeed(seed); // sets the seed to `seed' keeping
|
|---|
| 249 | // the current luxury level
|
|---|
| 250 | </pre></div><p>
|
|---|
| 251 | </p><p>
|
|---|
| 252 | </p></li><li><p>
|
|---|
| 253 | <span class="emphasis"><em>RanecuEngine</em></span>
|
|---|
| 254 | </p><p>
|
|---|
| 255 | The algorithm for <span class="emphasis"><em>RanecuEngine</em></span> is taken from the one
|
|---|
| 256 | originally written in FORTRAN77 as part of the
|
|---|
| 257 | <span class="bold"><strong>MATHLIB HEP</strong></span>
|
|---|
| 258 | library. The initialisation is carried out using a Multiplicative
|
|---|
| 259 | Congruential generator using formula constants of L'Ecuyer as
|
|---|
| 260 | described in ``F.James, Comp. Phys. Comm. 60 (1990) 329-344''.
|
|---|
| 261 | Handling of seeds for this engine is slightly different than the
|
|---|
| 262 | other engines in <span class="emphasis"><em>HEPRandom</em></span>. Seeds are taken from a seed
|
|---|
| 263 | table given an index, the <code class="literal">getSeed()</code> method returns the
|
|---|
| 264 | current index of seed table. The <code class="literal">setSeeds()</code> method will
|
|---|
| 265 | set seeds in the local <code class="literal">SeedTable</code> at a given position index
|
|---|
| 266 | (if the index number specified exceeds the table's size,
|
|---|
| 267 | <code class="literal">[index%size]</code> is taken). For example:
|
|---|
| 268 |
|
|---|
| 269 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 270 | // static interface
|
|---|
| 271 | const G4long* table_entry;
|
|---|
| 272 | table_entry = HepRandom::getTheSeeds();
|
|---|
| 273 | // it returns a pointer `table_entry' to the local SeedTable
|
|---|
| 274 | // at the current `index' position. The couple of seeds
|
|---|
| 275 | // accessed represents the current `status' of the engine itself !
|
|---|
| 276 | ...
|
|---|
| 277 | G4int index=n;
|
|---|
| 278 | G4long seeds[2];
|
|---|
| 279 | HepRandom::setTheSeeds(seeds,index);
|
|---|
| 280 | // sets the new `index' for seeds and modify the values inside
|
|---|
| 281 | // the local SeedTable at the `index' position. If the index
|
|---|
| 282 | // is not specified, the current index in the table is considered.
|
|---|
| 283 | ...
|
|---|
| 284 | </pre></div><p>
|
|---|
| 285 | </p><p>
|
|---|
| 286 |
|
|---|
| 287 | </p><p>
|
|---|
| 288 | The <code class="literal">setSeed()</code> method resets the current `status' of the
|
|---|
| 289 | engine to the original seeds stored in the static table of seeds in
|
|---|
| 290 | <span class="emphasis"><em>HepRandom</em></span>, at the specified index.
|
|---|
| 291 | </p><p>
|
|---|
| 292 | </p></li></ul></div><p>
|
|---|
| 293 | </p><p>
|
|---|
| 294 | Except for the <span class="emphasis"><em>RanecuEngine</em></span>, for which the internal
|
|---|
| 295 | status is represented by just a couple of longs, all the other
|
|---|
| 296 | engines have a much more complex representation of their internal
|
|---|
| 297 | status, which currently can be obtained only through the methods
|
|---|
| 298 | <code class="literal">saveStatus()</code>, <code class="literal">restoreStatus()</code> and
|
|---|
| 299 | <code class="literal">showStatus()</code>, which can also be statically called from
|
|---|
| 300 | <span class="emphasis"><em>HepRandom</em></span>. The status of the generator is needed for example
|
|---|
| 301 | to be able to reproduce a run or an event in a run at a given stage
|
|---|
| 302 | of the simulation.
|
|---|
| 303 | </p><p>
|
|---|
| 304 | <span class="emphasis"><em>RanecuEngine</em></span> is probably the most suitable engine for
|
|---|
| 305 | this kind of operation, since its internal status can be
|
|---|
| 306 | fetched/reset by simply using
|
|---|
| 307 | <code class="literal">getSeeds()</code>/<code class="literal">setSeeds()</code>
|
|---|
| 308 | (<code class="literal">getTheSeeds()</code>/<code class="literal">setTheSeeds()</code> for the static
|
|---|
| 309 | interface in <span class="emphasis"><em>HepRandom</em></span>).
|
|---|
| 310 | </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.GlobClass.HEPRandom.StaticInt"></a>3.2.2.2.
|
|---|
| 311 | The static interface in the <span class="emphasis"><em>HepRandom</em></span> class
|
|---|
| 312 | </h4></div></div></div><p>
|
|---|
| 313 | <span class="emphasis"><em>HepRandom</em></span> a singleton class and using a
|
|---|
| 314 | <span class="emphasis"><em>HepJamesRandom</em></span> engine as default algorithm for pseudo-random
|
|---|
| 315 | number generation. <span class="emphasis"><em>HepRandom</em></span> defines a static private data
|
|---|
| 316 | member, <code class="literal">theGenerator</code>, and a set of static methods to
|
|---|
| 317 | manipulate it. By means of <code class="literal">theGenerator</code>, the user can
|
|---|
| 318 | change the underlying engine algorithm, get and set the seeds, and
|
|---|
| 319 | use any kind of defined random distribution. The static methods
|
|---|
| 320 | <code class="literal">setTheSeed()</code> and <code class="literal">getTheSeed()</code> will set and get
|
|---|
| 321 | respectively the `initial' seed to the main engine used by the
|
|---|
| 322 | static generator. For example:
|
|---|
| 323 |
|
|---|
| 324 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 325 | HepRandom::setTheSeed(seed); // to change the current seed to 'seed'
|
|---|
| 326 | int startSeed = HepRandom::getTheSeed(); // to get the current initial seed
|
|---|
| 327 | HepRandom::saveEngineStatus(); // to save the current engine status on file
|
|---|
| 328 | HepRandom::restoreEngineStatus(); // to restore the current engine to a previous
|
|---|
| 329 | // saved configuration
|
|---|
| 330 | HepRandom::showEngineStatus(); // to display the current engine status to stdout
|
|---|
| 331 | ...
|
|---|
| 332 | int index=n;
|
|---|
| 333 | long seeds[2];
|
|---|
| 334 | HepRandom::getTheTableSeeds(seeds,index);
|
|---|
| 335 | // fills `seeds' with the values stored in the global
|
|---|
| 336 | // seedTable at position `index'
|
|---|
| 337 | </pre></div><p>
|
|---|
| 338 | </p><p>
|
|---|
| 339 | Only one random engine can be active at a time, the user can
|
|---|
| 340 | decide at any time to change it, define a new one (if not done
|
|---|
| 341 | already) and set it. For example:
|
|---|
| 342 |
|
|---|
| 343 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 344 | RanecuEngine theNewEngine;
|
|---|
| 345 | HepRandom::setTheEngine(&theNewEngine);
|
|---|
| 346 | ...
|
|---|
| 347 | </pre></div><p>
|
|---|
| 348 |
|
|---|
| 349 | or simply setting it to an old instantiated engine (the old
|
|---|
| 350 | engine status is kept and the new random sequence will start
|
|---|
| 351 | exactly from the last one previously interrupted). For example:
|
|---|
| 352 |
|
|---|
| 353 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 354 | HepRandom::setTheEngine(&myOldEngine);
|
|---|
| 355 | </pre></div><p>
|
|---|
| 356 | </p><p>
|
|---|
| 357 | Other static methods defined in this class are:
|
|---|
| 358 |
|
|---|
| 359 | </p><div class="itemizedlist"><ul type="disc" compact><li><p>
|
|---|
| 360 | <code class="literal">void setTheSeeds(const G4long* seeds, G4int)</code>
|
|---|
| 361 | </p></li><li><p>
|
|---|
| 362 | <code class="literal">const G4long* getTheSeeds()</code>
|
|---|
| 363 | </p><p>
|
|---|
| 364 | To set/get an array of seeds for the generator, in the case of a
|
|---|
| 365 | <span class="emphasis"><em>RanecuEngine</em></span> this corresponds also to set/get the current
|
|---|
| 366 | status of the engine.
|
|---|
| 367 | </p><p>
|
|---|
| 368 | </p></li><li><p>
|
|---|
| 369 | <code class="literal">HepRandomEngine* getTheEngine()</code>
|
|---|
| 370 | </p><p>
|
|---|
| 371 | To get a pointer to the current engine used by the static
|
|---|
| 372 | generator.
|
|---|
| 373 | </p><p>
|
|---|
| 374 | </p></li></ul></div><p>
|
|---|
| 375 | </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.GlobClass.HEPRandom.Distri"></a>3.2.2.3.
|
|---|
| 376 | <span class="emphasis"><em>HEPRandom</em></span> distributions
|
|---|
| 377 | </h4></div></div></div><p>
|
|---|
| 378 | A distribution-class can collect different algorithms and
|
|---|
| 379 | different calling sequences for each method to define distribution
|
|---|
| 380 | parameters or range-intervals; it also collects methods to fill
|
|---|
| 381 | arrays, of specified size, of random values, according to the
|
|---|
| 382 | distribution. This class collects either static and not static
|
|---|
| 383 | methods. A set of distribution classes are defined in
|
|---|
| 384 | <span class="emphasis"><em>HEPRandom</em></span>. Here is the description of some of them:
|
|---|
| 385 |
|
|---|
| 386 | </p><div class="itemizedlist"><ul type="disc" compact><li><p>
|
|---|
| 387 | <span class="emphasis"><em>RandFlat</em></span>
|
|---|
| 388 | </p><p>
|
|---|
| 389 | Class to shoot flat random values (integers or double) within a
|
|---|
| 390 | specified interval. The class provides also methods to shoot just
|
|---|
| 391 | random bits.
|
|---|
| 392 | </p><p>
|
|---|
| 393 | </p></li><li><p>
|
|---|
| 394 | <span class="emphasis"><em>RandExponential</em></span>
|
|---|
| 395 | </p><p>
|
|---|
| 396 | Class to shoot exponential distributed random values, given a
|
|---|
| 397 | mean (default mean = 1)
|
|---|
| 398 | </p><p>
|
|---|
| 399 | </p></li><li><p>
|
|---|
| 400 | <span class="emphasis"><em>RandGauss</em></span>
|
|---|
| 401 | </p><p>
|
|---|
| 402 | Class to shoot Gaussian distributed random values, given a mean
|
|---|
| 403 | (default = 0) or specifying also a deviation (default = 1).
|
|---|
| 404 | Gaussian random numbers are generated two at the time, so every
|
|---|
| 405 | other time a number is shot, the number returned is the one
|
|---|
| 406 | generated the time before.
|
|---|
| 407 | </p><p>
|
|---|
| 408 | </p></li><li><p>
|
|---|
| 409 | <span class="emphasis"><em>RandBreitWigner</em></span>
|
|---|
| 410 | </p><p>
|
|---|
| 411 | Class to shoot numbers according to the Breit-Wigner
|
|---|
| 412 | distribution algorithms (plain or mean^2).
|
|---|
| 413 | </p><p>
|
|---|
| 414 | </p></li><li><p>
|
|---|
| 415 | <span class="emphasis"><em>RandPoisson</em></span>
|
|---|
| 416 | </p><p>
|
|---|
| 417 | Class to shoot numbers according to the Poisson distribution,
|
|---|
| 418 | given a mean (default = 1) (Algorithm taken from ``W.H.Press et
|
|---|
| 419 | al., Numerical Recipes in C, Second Edition'').
|
|---|
| 420 | </p><p>
|
|---|
| 421 | </p></li></ul></div><p>
|
|---|
| 422 | </p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.HEPNumerics"></a>3.2.3.
|
|---|
| 423 | The <span class="emphasis"><em>HEPNumerics</em></span> module
|
|---|
| 424 | </h3></div></div></div><p>
|
|---|
| 425 | A set of classes implementing numerical algorithms has been
|
|---|
| 426 | developed in Geant4. Most of the algorithms and methods have been
|
|---|
| 427 | implemented mainly based on recommendations given in the books:
|
|---|
| 428 |
|
|---|
| 429 | </p><div class="itemizedlist"><ul type="disc" compact><li><p>
|
|---|
| 430 | B.H. Flowers, ``An introduction to Numerical Methods In C++'',
|
|---|
| 431 | Claredon Press, Oxford 1995.
|
|---|
| 432 | </p></li><li><p>
|
|---|
| 433 | M. Abramowitz, I. Stegun, ``Handbook of mathematical
|
|---|
| 434 | functions'', DOVER Publications INC, New York 1965 ; chapters 9,
|
|---|
| 435 | 10, and 22.
|
|---|
| 436 | </p></li></ul></div><p>
|
|---|
| 437 | </p><p>
|
|---|
| 438 | This set of classes includes:
|
|---|
| 439 |
|
|---|
| 440 | </p><div class="itemizedlist"><ul type="disc" compact><li><p>
|
|---|
| 441 | <span class="emphasis"><em>G4ChebyshevApproximation</em></span>
|
|---|
| 442 | </p><p>
|
|---|
| 443 | Class creating the Chebyshev approximation for a function
|
|---|
| 444 | pointed by fFunction data member. The Chebyshev polynomial
|
|---|
| 445 | approximation provides an efficient evaluation of the minimax
|
|---|
| 446 | polynomial, which (among all polynomials of the same degree) has
|
|---|
| 447 | the smallest maximum deviation from the true function.
|
|---|
| 448 | </p><p>
|
|---|
| 449 | </p></li><li><p>
|
|---|
| 450 | <span class="emphasis"><em>G4DataInterpolation</em></span>
|
|---|
| 451 | </p><p>
|
|---|
| 452 | Class providing methods for data interpolations and
|
|---|
| 453 | extrapolations: Polynomial, Cubic Spline, ...
|
|---|
| 454 | </p><p>
|
|---|
| 455 | </p></li><li><p>
|
|---|
| 456 | <span class="emphasis"><em>G4GaussChebyshevQ</em></span>
|
|---|
| 457 | </p></li><li><p>
|
|---|
| 458 | <span class="emphasis"><em>G4GaussHermiteQ</em></span>
|
|---|
| 459 | </p></li><li><p>
|
|---|
| 460 | <span class="emphasis"><em>G4GaussJacobiQ</em></span>
|
|---|
| 461 | </p></li><li><p>
|
|---|
| 462 | <span class="emphasis"><em>G4GaussLaguerreQ</em></span>
|
|---|
| 463 | </p><p>
|
|---|
| 464 | Classes implementing the Gauss-Chebyshev, Gauss-Hermite,
|
|---|
| 465 | Gauss-Jacobi, Gauss-Laguerre and Gauss-Legendre quadrature methods.
|
|---|
| 466 | Roots of orthogonal polynomials and corresponding weights are
|
|---|
| 467 | calculated based on iteration method (by bisection Newton
|
|---|
| 468 | algorithm).
|
|---|
| 469 | </p><p>
|
|---|
| 470 | </p></li><li><p>
|
|---|
| 471 | <span class="emphasis"><em>G4Integrator</em></span>
|
|---|
| 472 | </p><p>
|
|---|
| 473 | Template class collecting integrator methods for generic
|
|---|
| 474 | functions (Legendre, Simpson, Adaptive Gauss, Laguerre, Hermite,
|
|---|
| 475 | Jacobi).
|
|---|
| 476 | </p><p>
|
|---|
| 477 | </p></li><li><p>
|
|---|
| 478 | <span class="emphasis"><em>G4SimpleIntegration</em></span>
|
|---|
| 479 | </p><p>
|
|---|
| 480 | Class implementing simple numerical methods (Trapezoidal,
|
|---|
| 481 | MidPoint, Gauss, Simpson, Adaptive Gauss, for integration of
|
|---|
| 482 | functions with signature: double f(double).
|
|---|
| 483 | </p><p>
|
|---|
| 484 | </p></li></ul></div><p>
|
|---|
| 485 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.GeneManage"></a>3.2.4.
|
|---|
| 486 | General management classes
|
|---|
| 487 | </h3></div></div></div><p>
|
|---|
| 488 | The `global' category defines also a set of `utility' classes
|
|---|
| 489 | generally used within the kernel of Geant4. These classes
|
|---|
| 490 | include:
|
|---|
| 491 |
|
|---|
| 492 | </p><div class="itemizedlist"><ul type="disc" compact><li><p>
|
|---|
| 493 | <span class="emphasis"><em>G4Allocator</em></span>
|
|---|
| 494 | </p><p>
|
|---|
| 495 | A class for fast allocation of objects to the heap through
|
|---|
| 496 | paging mechanism. It's meant to be used by associating it to the
|
|---|
| 497 | object to be allocated and defining for it <code class="literal">new</code> and
|
|---|
| 498 | <code class="literal">delete</code> operators via <code class="literal">MallocSingle()</code> and
|
|---|
| 499 | <code class="literal">FreeSingle()</code> methods of <span class="emphasis"><em>G4Allocator</em></span>.
|
|---|
| 500 | </p><p>
|
|---|
| 501 | </p><p>
|
|---|
| 502 | <span class="bold"><strong>Note</strong></span>: classes which are handled by
|
|---|
| 503 | <code class="literal">G4Allocator</code> should <span class="emphasis"><em>avoid</em></span> to be used
|
|---|
| 504 | as base classes for others and therefore define their (eventually empty)
|
|---|
| 505 | destructors to be virtual (and/or inlined). Such measure is necessary in order
|
|---|
| 506 | to prevent bad aliasing optimisations by compilers which may potentially
|
|---|
| 507 | lead to crashes in the attempt to free the allocated chunks of memory.
|
|---|
| 508 | </p><p>
|
|---|
| 509 | </p><p>
|
|---|
| 510 | The list of allocators implicitely defined and used in Geant4 is reported here:
|
|---|
| 511 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 512 | - events (G4Event): anEventAllocator
|
|---|
| 513 | - tracks (G4Track): aTrackAllocator
|
|---|
| 514 | - stacked tracks (G4StackedTrack): aStackedTrackAllocator
|
|---|
| 515 | - primary particles (G4PrimaryParticle): aPrimaryParticleAllocator
|
|---|
| 516 | - primary vertices (G4PrimaryVertex): aPrimaryVertexAllocator
|
|---|
| 517 | - decay products (G4DecayProducts): aDecayProductsAllocator
|
|---|
| 518 | - digits collections of an event (G4DCofThisEvent): anDCoTHAllocator
|
|---|
| 519 | - digits collections (G4DigiCollection): aDCAllocator
|
|---|
| 520 | - hits collections of an event (G4HCofThisEvent): anHCoTHAllocator
|
|---|
| 521 | - hits collections (G4HitsCollection): anHCAllocator
|
|---|
| 522 | - trajectories (G4Trajectory): aTrajectoryAllocator
|
|---|
| 523 | - trajectory points (G4TrajectoryPoint): aTrajectoryPointAllocator
|
|---|
| 524 | - trajectory containers (G4TrajectoryContainer): aTrajectoryContainerAllocator
|
|---|
| 525 | - navigation levels (G4NavigationLevel): aNavigationLevelAllocator
|
|---|
| 526 | - navigation level nodes (G4NavigationLevelRep): aNavigLevelRepAllocator
|
|---|
| 527 | - reference-counted handles (G4ReferenceCountedHandle<X>): aRCHAllocator
|
|---|
| 528 | - counted objects (G4CountedObject<X>): aCountedObjectAllocator
|
|---|
| 529 | - HEPEvt primary particles (G4HEPEvtParticle): aHEPEvtParticleAllocator
|
|---|
| 530 | - electron occupancy objects(G4ElectronOccupancy): aElectronOccupancyAllocator
|
|---|
| 531 | - "rich" trajectories (G4RichTrajectory): aRichTrajectoryAllocator
|
|---|
| 532 | - "rich" trajectory points (G4RichTrajectoryPoint): aRichTrajectoryPointAllocator
|
|---|
| 533 | - "smooth" trajectories (G4SmoothTrajectory): aSmoothTrajectoryAllocator
|
|---|
| 534 | - "smooth" trajectory points (G4SmoothTrajectoryPoint): aSmoothTrajectoryPointAllocator
|
|---|
| 535 | - "ray" trajectories (G4RayTrajectory): G4RayTrajectoryAllocator
|
|---|
| 536 | - "ray" trajectory points (G4RayTrajectoryPoint): G4RayTrajectoryPointAllocator
|
|---|
| 537 | </pre></div><p>
|
|---|
| 538 | For each of these allocators, accessible from the global namespace, it is
|
|---|
| 539 | possible to monitor the allocation in their memory pools or force them to
|
|---|
| 540 | release the allocated memory (for example at the end of a run):
|
|---|
| 541 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 542 | // Return the size of the total memory allocated for tracks
|
|---|
| 543 | //
|
|---|
| 544 | aTrackAllocator.GetAllocatedSize();
|
|---|
| 545 |
|
|---|
| 546 | // Return allocated storage for tracks to the free store
|
|---|
| 547 | //
|
|---|
| 548 | aTrackAllocator.ResetStorage();
|
|---|
| 549 | </pre></div><p>
|
|---|
| 550 | </p><p>
|
|---|
| 551 | </p></li><li><p>
|
|---|
| 552 | <span class="emphasis"><em>G4ReferenceCountedHandle</em></span>
|
|---|
| 553 | </p><p>
|
|---|
| 554 | Template class acting as a smart pointer and wrapping the type
|
|---|
| 555 | to be counted. It performs the reference counting during the
|
|---|
| 556 | life-time of the counted object.
|
|---|
| 557 | </p><p>
|
|---|
| 558 | </p></li><li><p>
|
|---|
| 559 | <span class="emphasis"><em>G4FastVector</em></span>
|
|---|
| 560 | </p><p>
|
|---|
| 561 | Template class defining a vector of pointers, not performing
|
|---|
| 562 | boundary checking.
|
|---|
| 563 | </p><p>
|
|---|
| 564 | </p></li><li><p>
|
|---|
| 565 | <span class="emphasis"><em>G4PhysicsVector</em></span>
|
|---|
| 566 | </p><p>
|
|---|
| 567 | Defines a physics vector which has values of energy-loss,
|
|---|
| 568 | cross-section, and other physics values of a particle in matter in
|
|---|
| 569 | a given range of the energy, momentum, etc. This class serves as
|
|---|
| 570 | the base class for a vector having various energy scale, for
|
|---|
| 571 | example like 'log' (<span class="emphasis"><em>G4PhysicsLogVector</em></span>) 'linear'
|
|---|
| 572 | (<span class="emphasis"><em>G4PhysicsLinearVector</em></span>), 'free'
|
|---|
| 573 | (<span class="emphasis"><em>G4PhysicsFreeVector</em></span>), etc.
|
|---|
| 574 | </p><p>
|
|---|
| 575 | </p></li><li><p>
|
|---|
| 576 | <span class="emphasis"><em>G4LPhysicsFreeVector</em></span>
|
|---|
| 577 | </p><p>
|
|---|
| 578 | Implements a free vector for low energy physics cross-section
|
|---|
| 579 | data. A subdivision method is used to find the energy|momentum
|
|---|
| 580 | bin.
|
|---|
| 581 | </p><p>
|
|---|
| 582 | </p></li><li><p>
|
|---|
| 583 | <span class="emphasis"><em>G4PhysicsOrderedFreeVector</em></span>
|
|---|
| 584 | </p><p>
|
|---|
| 585 | A physics ordered free vector inherits from
|
|---|
| 586 | <span class="emphasis"><em>G4PhysicsVector</em></span>. It provides, in addition, a method
|
|---|
| 587 | for the user to insert energy/value pairs in sequence. Methods to retrieve
|
|---|
| 588 | the max and min energies and values from the vector are also
|
|---|
| 589 | provided.
|
|---|
| 590 | </p><p>
|
|---|
| 591 | </p></li><li><p>
|
|---|
| 592 | <span class="emphasis"><em>G4Timer</em></span>
|
|---|
| 593 | </p><p>
|
|---|
| 594 | Utility class providing methods to measure elapsed user/system
|
|---|
| 595 | process time.
|
|---|
| 596 | Uses <code class="literal"><sys/times.h></code> and <code class="literal"><unistd.h></code> -
|
|---|
| 597 | POSIX.1.
|
|---|
| 598 | </p><p>
|
|---|
| 599 | </p></li><li><p>
|
|---|
| 600 | <span class="emphasis"><em>G4UserLimits</em></span>
|
|---|
| 601 | </p><p>
|
|---|
| 602 | Class collecting methods for get and set any kind of step
|
|---|
| 603 | limitation allowed in Geant4.
|
|---|
| 604 | </p><p>
|
|---|
| 605 | </p></li><li><p>
|
|---|
| 606 | <span class="emphasis"><em>G4UnitsTable</em></span>
|
|---|
| 607 | </p><p>
|
|---|
| 608 | Placeholder for the system of units in Geant4.
|
|---|
| 609 | </p><p>
|
|---|
| 610 | </p></li></ul></div><p>
|
|---|
| 611 | </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03.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="ch03s03.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 3.
|
|---|
| 612 | Toolkit Fundamentals
|
|---|
| 613 | </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.3.
|
|---|
| 614 | System of units
|
|---|
| 615 | </td></tr></table></div></body></html>
|
|---|