[904] | 1 | <!-- ******************************************************** --> |
---|
| 2 | <!-- --> |
---|
| 3 | <!-- [History] --> |
---|
| 4 | <!-- Changed by: Katsuya Amako, 4-Aug-1998 --> |
---|
| 5 | <!-- Changed by: Dennis Wright, 29-Nov-2001 --> |
---|
| 6 | <!-- Proof read by: Joe Chuma, 15-Jun-1999 --> |
---|
| 7 | <!-- Converted to DocBook: Katsuya Amako, Aug-2006 --> |
---|
| 8 | <!-- --> |
---|
| 9 | <!-- ******************************************************** --> |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | <!-- ******************* Section (Level#1) ****************** --> |
---|
| 13 | <sect1 id="sect.HowToGenEvent"> |
---|
| 14 | <title> |
---|
| 15 | How to Generate a Primary Event |
---|
| 16 | </title> |
---|
| 17 | |
---|
| 18 | <!-- ******************* Section (Level#2) ****************** --> |
---|
| 19 | <sect2 id="sect.HowToGenEvent.GenPrimary"> |
---|
| 20 | <title> |
---|
| 21 | Generating Primary Events |
---|
| 22 | </title> |
---|
| 23 | |
---|
| 24 | <para> |
---|
| 25 | <emphasis>G4VuserPrimaryGeneratorAction</emphasis> is one of the mandatory |
---|
| 26 | classes available for deriving your own concrete class. In your |
---|
| 27 | concrete class, you have to specify how a primary event should be |
---|
| 28 | generated. Actual generation of primary particles will be done by |
---|
| 29 | concrete classes of <emphasis>G4VPrimaryGenerator</emphasis>, explained in the |
---|
| 30 | following sub-section. Your <emphasis>G4VUserPrimaryGeneratorAction</emphasis> |
---|
| 31 | concrete class just arranges the way primary particles are generated. |
---|
| 32 | |
---|
| 33 | <example id="programlist_HowToGenEvent_1"> |
---|
| 34 | <title> |
---|
| 35 | An example of a <emphasis>G4VUserPrimaryGeneratorAction</emphasis> |
---|
| 36 | concrete class using <emphasis>G4ParticleGun</emphasis>. |
---|
| 37 | For the usage of <emphasis>G4ParticleGun</emphasis> refer to the |
---|
| 38 | next subsection. |
---|
| 39 | </title> |
---|
| 40 | |
---|
| 41 | <programlisting> |
---|
| 42 | #ifndef ExN01PrimaryGeneratorAction_h |
---|
| 43 | #define ExN01PrimaryGeneratorAction_h 1 |
---|
| 44 | |
---|
| 45 | #include "G4VUserPrimaryGeneratorAction.hh" |
---|
| 46 | |
---|
| 47 | class G4ParticleGun; |
---|
| 48 | class G4Event; |
---|
| 49 | |
---|
| 50 | class ExN01PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction |
---|
| 51 | { |
---|
| 52 | public: |
---|
| 53 | ExN01PrimaryGeneratorAction(); |
---|
| 54 | ~ExN01PrimaryGeneratorAction(); |
---|
| 55 | |
---|
| 56 | public: |
---|
| 57 | void generatePrimaries(G4Event* anEvent); |
---|
| 58 | |
---|
| 59 | private: |
---|
| 60 | G4ParticleGun* particleGun; |
---|
| 61 | }; |
---|
| 62 | |
---|
| 63 | #endif |
---|
| 64 | |
---|
| 65 | #include "ExN01PrimaryGeneratorAction.hh" |
---|
| 66 | #include "G4Event.hh" |
---|
| 67 | #include "G4ParticleGun.hh" |
---|
| 68 | #include "G4ThreeVector.hh" |
---|
| 69 | #include "G4Geantino.hh" |
---|
| 70 | #include "globals.hh" |
---|
| 71 | |
---|
| 72 | ExN01PrimaryGeneratorAction::ExN01PrimaryGeneratorAction() |
---|
| 73 | { |
---|
| 74 | G4int n_particle = 1; |
---|
| 75 | particleGun = new G4ParticleGun(n_particle); |
---|
| 76 | |
---|
| 77 | particleGun->SetParticleDefinition(G4Geantino::GeantinoDefinition()); |
---|
| 78 | particleGun->SetParticleEnergy(1.0*GeV); |
---|
| 79 | particleGun->SetParticlePosition(G4ThreeVector(-2.0*m,0.0*m,0.0*m)); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | ExN01PrimaryGeneratorAction::~ExN01PrimaryGeneratorAction() |
---|
| 83 | { |
---|
| 84 | delete particleGun; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | void ExN01PrimaryGeneratorAction::generatePrimaries(G4Event* anEvent) |
---|
| 88 | { |
---|
| 89 | G4int i = anEvent->get_eventID() % 3; |
---|
| 90 | switch(i) |
---|
| 91 | { |
---|
| 92 | case 0: |
---|
| 93 | particleGun->SetParticleMomentumDirection(G4ThreeVector(1.0,0.0,0.0)); |
---|
| 94 | break; |
---|
| 95 | case 1: |
---|
| 96 | particleGun->SetParticleMomentumDirection(G4ThreeVector(1.0,0.1,0.0)); |
---|
| 97 | break; |
---|
| 98 | case 2: |
---|
| 99 | particleGun->SetParticleMomentumDirection(G4ThreeVector(1.0,0.0,0.1)); |
---|
| 100 | break; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | particleGun->generatePrimaryVertex(anEvent); |
---|
| 104 | } |
---|
| 105 | </programlisting> |
---|
| 106 | </example> |
---|
| 107 | |
---|
| 108 | </para> |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | <!-- ******************* Section (Level#3) ****************** --> |
---|
| 112 | <sect3 id="sect.HowToGenEvent.GenPrimary.SelectGenerator"> |
---|
| 113 | <title> |
---|
| 114 | Selection of the generator |
---|
| 115 | </title> |
---|
| 116 | |
---|
| 117 | <para> |
---|
| 118 | In the constructor of your <emphasis>G4VUserPrimaryGeneratorAction</emphasis>, |
---|
| 119 | you should instantiate the primary generator(s). If necessary, you |
---|
| 120 | need to set some initial conditions for the generator(s). |
---|
| 121 | </para> |
---|
| 122 | |
---|
| 123 | <para> |
---|
| 124 | In <xref linkend="programlist_HowToGenEvent_1" />, |
---|
| 125 | <emphasis>G4ParticleGun</emphasis> is constructed to |
---|
| 126 | use as the actual primary particle generator. Methods of |
---|
| 127 | <emphasis>G4ParticleGun</emphasis> are described in the following section. Please |
---|
| 128 | note that the primary generator object(s) you construct in your |
---|
| 129 | <emphasis>G4VUserPrimaryGeneratorAction</emphasis> concrete class must be deleted |
---|
| 130 | in your destructor. |
---|
| 131 | </para> |
---|
| 132 | |
---|
| 133 | </sect3> |
---|
| 134 | |
---|
| 135 | <!-- ******************* Section (Level#3) ****************** --> |
---|
| 136 | <sect3 id="sect.HowToGenEvent.GenPrimary.GenEvent"> |
---|
| 137 | <title> |
---|
| 138 | Generation of an event |
---|
| 139 | </title> |
---|
| 140 | |
---|
| 141 | <para> |
---|
| 142 | <emphasis>G4VUserPrimaryGeneratorAction</emphasis> has a pure virtual method |
---|
| 143 | named <literal>generatePrimaries()</literal>. This method is invoked at the |
---|
| 144 | beginning of each event. In this method, you have to invoke the |
---|
| 145 | <emphasis>G4VPrimaryGenerator</emphasis> concrete class you instantiated via the |
---|
| 146 | <literal>generatePrimaryVertex()</literal> method. |
---|
| 147 | </para> |
---|
| 148 | |
---|
| 149 | <para> |
---|
| 150 | You can invoke more than one generator and/or invoke one |
---|
| 151 | generator more than once. Mixing up several generators can produce |
---|
| 152 | a more complicated primary event. |
---|
| 153 | </para> |
---|
| 154 | |
---|
| 155 | </sect3> |
---|
| 156 | </sect2> |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | <!-- ******************* Section (Level#2) ****************** --> |
---|
| 160 | <sect2 id="sect.HowToGenEvent.G4VPrimGen"> |
---|
| 161 | <title> |
---|
| 162 | G4VPrimaryGenerator |
---|
| 163 | </title> |
---|
| 164 | |
---|
| 165 | <para> |
---|
| 166 | Geant4 provides two <emphasis>G4VPrimaryGenerator</emphasis> concrete classes. |
---|
| 167 | One is <emphasis>G4ParticleGun</emphasis>, which will be discussed here, and the |
---|
| 168 | other is <emphasis>G4HEPEvtInterface</emphasis>, which will be discussed in |
---|
| 169 | <xref linkend="sect.EventGen" />. |
---|
| 170 | </para> |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | <!-- ******************* Section (Level#3) ****************** --> |
---|
| 174 | <sect3 id="sect.HowToGenEvent.G4VPrimGen.G4PartGun"> |
---|
| 175 | <title> |
---|
| 176 | G4ParticleGun |
---|
| 177 | </title> |
---|
| 178 | |
---|
| 179 | <para> |
---|
| 180 | <emphasis>G4ParticleGun</emphasis> is a generator provided by Geant4. This class |
---|
| 181 | generates primary particle(s) with a given momentum and position. |
---|
| 182 | It does not provide any sort of randomizing. The constructor of |
---|
| 183 | <emphasis>G4ParticleGun</emphasis> takes an integer which causes the generation |
---|
| 184 | of one or more primaries of exactly same kinematics. It is a rather |
---|
| 185 | frequent user requirement to generate a primary with randomized |
---|
| 186 | energy, momentum, and/or position. Such randomization can be |
---|
| 187 | achieved by invoking various set methods provided by |
---|
| 188 | <emphasis>G4ParticleGun</emphasis>. The invocation of these methods should be |
---|
| 189 | implemented in the <literal>generatePrimaries()</literal> method of your |
---|
| 190 | concrete <emphasis>G4VUserPrimaryGeneratorAction</emphasis> class before invoking |
---|
| 191 | <literal>generatePrimaryVertex()</literal> of |
---|
| 192 | <emphasis>G4ParticleGun</emphasis>. |
---|
| 193 | Geant4 provides various random number generation methods with various |
---|
| 194 | distributions (see <xref linkend="sect.GlobClass" />). |
---|
| 195 | </para> |
---|
| 196 | |
---|
| 197 | </sect3> |
---|
| 198 | |
---|
| 199 | <!-- ******************* Section (Level#3) ****************** --> |
---|
| 200 | <sect3 id="sect.HowToGenEvent.G4VPrimGen.PublicMethG4PartGun"> |
---|
| 201 | <title> |
---|
| 202 | Public methods of <emphasis>G4ParticleGun</emphasis> |
---|
| 203 | </title> |
---|
| 204 | |
---|
| 205 | <para> |
---|
| 206 | The following methods are provided by <emphasis>G4ParticleGun</emphasis>, and all |
---|
| 207 | of them can be invoked from the <literal>generatePrimaries()</literal> method |
---|
| 208 | in your concrete <emphasis>G4VUserPrimaryGeneratorAction</emphasis> class. |
---|
| 209 | |
---|
| 210 | <itemizedlist spacing="compact"> |
---|
| 211 | <listitem><para> |
---|
| 212 | <literal>void SetParticleDefinition(G4ParticleDefinition*)</literal> |
---|
| 213 | </para></listitem> |
---|
| 214 | <listitem><para> |
---|
| 215 | <literal>void SetParticleMomentum(G4ParticleMomentum)</literal> |
---|
| 216 | </para></listitem> |
---|
| 217 | <listitem><para> |
---|
| 218 | <literal>void SetParticleMomentumDirection(G4ThreeVector)</literal> |
---|
| 219 | </para></listitem> |
---|
| 220 | <listitem><para> |
---|
| 221 | <literal>void SetParticleEnergy(G4double)</literal> |
---|
| 222 | </para></listitem> |
---|
| 223 | <listitem><para> |
---|
| 224 | <literal>void SetParticleTime(G4double)</literal> |
---|
| 225 | </para></listitem> |
---|
| 226 | <listitem><para> |
---|
| 227 | <literal>void SetParticlePosition(G4ThreeVector)</literal> |
---|
| 228 | </para></listitem> |
---|
| 229 | <listitem><para> |
---|
| 230 | <literal>void SetParticlePolarization(G4ThreeVector)</literal> |
---|
| 231 | </para></listitem> |
---|
| 232 | <listitem><para> |
---|
| 233 | <literal>void SetNumberOfParticles(G4int)</literal> |
---|
| 234 | </para></listitem> |
---|
| 235 | </itemizedlist> |
---|
| 236 | </para> |
---|
| 237 | |
---|
| 238 | |
---|
| 239 | </sect3> |
---|
| 240 | </sect2> |
---|
| 241 | </sect1> |
---|