| 1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 6. User Actions</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="index.html" title="Geant4 User's Guide for Application Developers"><link rel="prev" href="ch05s08.html" title="5.8. Track Error Propagation"><link rel="next" href="ch06s02.html" title="6.2. Optional User Actions"><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">Chapter 6.
|
|---|
| 9 | User Actions
|
|---|
| 10 | </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch05s08.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch06s02.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="chap.UserActions"></a>Chapter 6.
|
|---|
| 11 | User Actions
|
|---|
| 12 | </h2></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sect.ManUAct"></a>6.1.
|
|---|
| 13 | Mandatory User Actions and Initializations
|
|---|
| 14 | </h2></div></div></div><p>
|
|---|
| 15 | Geant4 has three virtual classes whose methods the user must
|
|---|
| 16 | override in order to implement a simulation. They require the user
|
|---|
| 17 | to define the detector, specify the physics to be used, and
|
|---|
| 18 | describe how initial particles are to be generated.
|
|---|
| 19 | </p><h5><a name="id490579"></a>
|
|---|
| 20 | <code class="literal">G4VUserDetectorConstruction</code>
|
|---|
| 21 | </h5><p>
|
|---|
| 22 | </p><div class="example"><a name="programlist_ManUAct_1"></a><p class="title"><b>Example 6.1.
|
|---|
| 23 | <code class="literal">G4VUserDetectorConstruction</code>
|
|---|
| 24 | </b></p><div class="example-contents"><pre class="programlisting">
|
|---|
| 25 | class G4VUserDetectorConstruction
|
|---|
| 26 | {
|
|---|
| 27 | public:
|
|---|
| 28 | G4VUserDetectorConstruction();
|
|---|
| 29 | virtual ~G4VUserDetectorConstruction();
|
|---|
| 30 |
|
|---|
| 31 | public:
|
|---|
| 32 | virtual G4VPhysicalVolume* Construct() = 0;
|
|---|
| 33 | };
|
|---|
| 34 | </pre></div></div><p><br class="example-break">
|
|---|
| 35 | </p><h5><a name="id490620"></a>
|
|---|
| 36 | <code class="literal">G4VUserPhysicsList</code>
|
|---|
| 37 | </h5><p>
|
|---|
| 38 | This is an abstract class for constructing particles and
|
|---|
| 39 | processes. The user must derive a concrete class from it and
|
|---|
| 40 | implement three virtual methods:
|
|---|
| 41 |
|
|---|
| 42 | </p><div class="itemizedlist"><ul type="disc" compact><li><p>
|
|---|
| 43 | <code class="literal">ConstructParticle()</code> to instantiate each requested
|
|---|
| 44 | particle type,
|
|---|
| 45 | </p></li><li><p>
|
|---|
| 46 | <code class="literal">ConstructPhysics()</code> to instantiate the desired physics
|
|---|
| 47 | processes and register each of them with the process managers of
|
|---|
| 48 | the appropriate particles, and
|
|---|
| 49 | </p></li><li><p>
|
|---|
| 50 | <code class="literal">SetCuts(G4double aValue)</code> to set a cut value in range
|
|---|
| 51 | for all particles in the particle table, which invokes the
|
|---|
| 52 | rebuilding of the physics table.
|
|---|
| 53 | </p></li></ul></div><p>
|
|---|
| 54 | </p><p>
|
|---|
| 55 | When called, the <code class="literal">Construct()</code> method of
|
|---|
| 56 | <span class="emphasis"><em>G4VUserPhysicsList</em></span> first invokes
|
|---|
| 57 | <code class="literal">ConstructParticle()</code> and then <code class="literal">ConstructProcess()</code>.
|
|---|
| 58 | The <code class="literal">ConstructProcess()</code> method must always invoke the
|
|---|
| 59 | <code class="literal">AddTransportation()</code> method in order to insure particle
|
|---|
| 60 | transportation. <code class="literal">AddTransportation()</code> must never be
|
|---|
| 61 | overridden.
|
|---|
| 62 | </p><p>
|
|---|
| 63 | <span class="emphasis"><em>G4VUserPhysicsList</em></span> provides several utility methods for
|
|---|
| 64 | the implementation of the above virtual methods. They are presented
|
|---|
| 65 | with comments in the class declaration in <a href="ch06.html#programlist_ManUAct_2" title="Example 6.2.
|
|---|
| 66 | G4VUserPhysicsList
|
|---|
| 67 | ">Example 6.2</a>.
|
|---|
| 68 |
|
|---|
| 69 | </p><div class="example"><a name="programlist_ManUAct_2"></a><p class="title"><b>Example 6.2.
|
|---|
| 70 | <code class="literal">G4VUserPhysicsList</code>
|
|---|
| 71 | </b></p><div class="example-contents"><pre class="programlisting">
|
|---|
| 72 | class G4VUserPhysicsList
|
|---|
| 73 | {
|
|---|
| 74 | public:
|
|---|
| 75 | G4VUserPhysicsList();
|
|---|
| 76 | virtual ~G4VUserPhysicsList();
|
|---|
| 77 |
|
|---|
| 78 | public: // with description
|
|---|
| 79 | // By calling the "Construct" method,
|
|---|
| 80 | // particles and processes are created
|
|---|
| 81 | void Construct();
|
|---|
| 82 |
|
|---|
| 83 | protected: // with description
|
|---|
| 84 | // These two methods of ConstructParticle() and ConstructProcess()
|
|---|
| 85 | // will be invoked in the Construct() method.
|
|---|
| 86 |
|
|---|
| 87 | // each particle type will be instantiated
|
|---|
| 88 | virtual void ConstructParticle() = 0;
|
|---|
| 89 |
|
|---|
| 90 | // each physics process will be instantiated and
|
|---|
| 91 | // registered to the process manager of each particle type
|
|---|
| 92 | virtual void ConstructProcess() = 0;
|
|---|
| 93 |
|
|---|
| 94 | protected: // with description
|
|---|
| 95 | // User must invoke this method in his ConstructProcess()
|
|---|
| 96 | // implementation in order to insures particle transportation.
|
|---|
| 97 | // !! Caution: this class must not be overriden !!
|
|---|
| 98 | void AddTransportation();
|
|---|
| 99 |
|
|---|
| 100 | /////////////////////////////////////////////////////////////////
|
|---|
| 101 | public: // with description
|
|---|
| 102 | // "SetCuts" method sets a cut value for all particle types
|
|---|
| 103 | // in the particle table
|
|---|
| 104 | virtual void SetCuts() = 0;
|
|---|
| 105 |
|
|---|
| 106 | public: // with description
|
|---|
| 107 | // set/get the default cut value
|
|---|
| 108 | // Calling SetDefaultCutValue causes re-calcuration of cut values
|
|---|
| 109 | // and physics tables just before the next event loop
|
|---|
| 110 | void SetDefaultCutValue(G4double newCutValue);
|
|---|
| 111 | G4double GetDefaultCutValue() const;
|
|---|
| 112 | </pre></div></div><p><br class="example-break">
|
|---|
| 113 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 114 | /////////////////////////////////////////////////////////////////////
|
|---|
| 115 | public: // with description
|
|---|
| 116 | // Invoke BuildPhysicsTable for all processes for all particles
|
|---|
| 117 | // In case of "Retrieve" flag is ON, PhysicsTable will be
|
|---|
| 118 | // retrieved from files
|
|---|
| 119 | void BuildPhysicsTable();
|
|---|
| 120 |
|
|---|
| 121 | // do BuildPhysicsTable for specified particle type
|
|---|
| 122 | void BuildPhysicsTable(G4ParticleDefinition* );
|
|---|
| 123 |
|
|---|
| 124 | // Store PhysicsTable together with both material and cut value
|
|---|
| 125 | // information in files under the specified directory.
|
|---|
| 126 | // (return true if files are sucessfully created)
|
|---|
| 127 | G4bool StorePhysicsTable(const G4String& directory = ".");
|
|---|
| 128 |
|
|---|
| 129 | // Return true if "Retrieve" flag is ON.
|
|---|
| 130 | // (i.e. PhysicsTable will be retrieved from files)
|
|---|
| 131 | G4bool IsPhysicsTableRetrieved() const;
|
|---|
| 132 | G4bool IsStoredInAscii() const;
|
|---|
| 133 |
|
|---|
| 134 | // Get directory path for physics table files.
|
|---|
| 135 | const G4String& GetPhysicsTableDirectory() const;
|
|---|
| 136 |
|
|---|
| 137 | // Set "Retrieve" flag
|
|---|
| 138 | // Directory path can be set together.
|
|---|
| 139 | // Null string (default) means directory is not changed
|
|---|
| 140 | // from the current value
|
|---|
| 141 | void SetPhysicsTableRetrieved(const G4String& directory = "");
|
|---|
| 142 | void SetStoredInAscii();
|
|---|
| 143 |
|
|---|
| 144 | // Reset "Retrieve" flag
|
|---|
| 145 | void ResetPhysicsTableRetrieved();
|
|---|
| 146 | void ResetStoredInAscii();
|
|---|
| 147 |
|
|---|
| 148 | ///////////////////////////////////////////////////////////////////////
|
|---|
| 149 | public: // with description
|
|---|
| 150 | // Print out the List of registered particles types
|
|---|
| 151 | void DumpList() const;
|
|---|
| 152 |
|
|---|
| 153 | public: // with description
|
|---|
| 154 | // Request to print out information of cut values
|
|---|
| 155 | // Printing will be performed when all tables are made
|
|---|
| 156 | void DumpCutValuesTable(G4int nParticles=3);
|
|---|
| 157 |
|
|---|
| 158 | // The following method actually trigger the print-out requested
|
|---|
| 159 | // by the above method. This method must be invoked by RunManager
|
|---|
| 160 | // at the proper moment.
|
|---|
| 161 | void DumpCutValuesTableIfRequested();
|
|---|
| 162 |
|
|---|
| 163 | public: // with description
|
|---|
| 164 | void SetVerboseLevel(G4int value);
|
|---|
| 165 | G4int GetVerboseLevel() const;
|
|---|
| 166 | // set/get controle flag for output message
|
|---|
| 167 | // 0: Silent
|
|---|
| 168 | // 1: Warning message
|
|---|
| 169 | // 2: More
|
|---|
| 170 | </pre></div><p>
|
|---|
| 171 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 172 | ///////////////////////////////////////////////////////////////////////////
|
|---|
| 173 | public: // with description
|
|---|
| 174 | // "SetCutsWithDefault" method sets the default cut value
|
|---|
| 175 | // for all particles for the default region.
|
|---|
| 176 | void SetCutsWithDefault();
|
|---|
| 177 |
|
|---|
| 178 | // Following are utility methods for SetCuts
|
|---|
| 179 |
|
|---|
| 180 | // SetCutValue sets a cut value for a particle type for the default region
|
|---|
| 181 | void SetCutValue(G4double aCut, const G4String& pname);
|
|---|
| 182 |
|
|---|
| 183 | // SetCutValue sets a cut value for a particle type for a region
|
|---|
| 184 | void SetCutValue(G4double aCut, const G4String& pname, const G4String& rname);
|
|---|
| 185 |
|
|---|
| 186 | // Invoke SetCuts for specified particle for a region
|
|---|
| 187 | // If the pointer to the region is NULL, the default region is used
|
|---|
| 188 | // In case of "Retrieve" flag is ON,
|
|---|
| 189 | // Cut values will be retrieved from files
|
|---|
| 190 | void SetParticleCuts(G4double cut,G4ParticleDefinition* particle,G4Region* region=0);
|
|---|
| 191 |
|
|---|
| 192 | // Invoke SetCuts for all particles in a region
|
|---|
| 193 | void SetCutsForRegion(G4double aCut, const G4String& rname);
|
|---|
| 194 |
|
|---|
| 195 | // Following are utility methods are obsolete
|
|---|
| 196 | void ResetCuts();
|
|---|
| 197 |
|
|---|
| 198 | ///////////////////////////////////////////////////////////////////
|
|---|
| 199 | public:
|
|---|
| 200 | // Get/SetApplyCuts gets/sets the flag for ApplyCuts
|
|---|
| 201 | void SetApplyCuts(G4bool value, const G4String& name);
|
|---|
| 202 | G4bool GetApplyCuts(const G4String& name) const;
|
|---|
| 203 |
|
|---|
| 204 | ///////////////////////////////////////////////////////////////////////////////
|
|---|
| 205 | protected:
|
|---|
| 206 | // do BuildPhysicsTable for make the integral schema
|
|---|
| 207 | void BuildIntegralPhysicsTable(G4VProcess* ,G4ParticleDefinition* );
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 | protected:
|
|---|
| 211 | // Retrieve PhysicsTable from files for proccess belongng the particle.
|
|---|
| 212 | // Normal BuildPhysics procedure of processes will be invoked,
|
|---|
| 213 | // if it fails (in case of Process's RetrievePhysicsTable returns false)
|
|---|
| 214 | virtual void RetrievePhysicsTable(G4ParticleDefinition* ,
|
|---|
| 215 | const G4String& directory,
|
|---|
| 216 | G4bool ascii = false);
|
|---|
| 217 |
|
|---|
| 218 | /////////////////////////////////////////////////////////////////
|
|---|
| 219 | protected:
|
|---|
| 220 | // adds new ProcessManager to all particles in the Particle Table
|
|---|
| 221 | // this routine is used in Construct()
|
|---|
| 222 | void InitializeProcessManager();
|
|---|
| 223 |
|
|---|
| 224 | public: // with description
|
|---|
| 225 | // remove and delete ProcessManagers for all particles in tha Particle Table
|
|---|
| 226 | // this routine is invoked from RunManager
|
|---|
| 227 | void RemoveProcessManager();
|
|---|
| 228 |
|
|---|
| 229 | public: // with description
|
|---|
| 230 | // add process manager for particles created on-the-fly
|
|---|
| 231 | void AddProcessManager(G4ParticleDefinition* newParticle,
|
|---|
| 232 | G4ProcessManager* newManager = 0 );
|
|---|
| 233 |
|
|---|
| 234 | };
|
|---|
| 235 | </pre></div><p>
|
|---|
| 236 | </p><h5><a name="id490880"></a>
|
|---|
| 237 | <code class="literal">G4VUserPrimaryGeneratorAction</code>
|
|---|
| 238 | </h5><p>
|
|---|
| 239 | </p><div class="example"><a name="programlist_ManUAct_3"></a><p class="title"><b>Example 6.3.
|
|---|
| 240 | <code class="literal">G4VUserPrimaryGeneratorAction</code>
|
|---|
| 241 | </b></p><div class="example-contents"><pre class="programlisting">
|
|---|
| 242 | class G4VUserPrimaryGeneratorAction
|
|---|
| 243 | {
|
|---|
| 244 | public:
|
|---|
| 245 | G4VUserPrimaryGeneratorAction();
|
|---|
| 246 | virtual ~G4VUserPrimaryGeneratorAction();
|
|---|
| 247 |
|
|---|
| 248 | public:
|
|---|
| 249 | virtual void GeneratePrimaries(G4Event* anEvent) = 0;
|
|---|
| 250 | };
|
|---|
| 251 | </pre></div></div><p><br class="example-break">
|
|---|
| 252 | </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch05s08.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="ch06s02.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr><tr><td width="40%" align="left" valign="top">5.8.
|
|---|
| 253 | Track Error Propagation
|
|---|
| 254 | </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"> 6.2.
|
|---|
| 255 | Optional User Actions
|
|---|
| 256 | </td></tr></table></div></body></html>
|
|---|