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 | <!-- Added GPS description: Katsuya Amako, Dec-2009 --> |
---|
9 | <!-- --> |
---|
10 | <!-- ******************************************************** --> |
---|
11 | |
---|
12 | |
---|
13 | <!-- ******************* Section (Level#1) ****************** --> |
---|
14 | <sect1 id="sect.HowToGenEvent"> |
---|
15 | <title> |
---|
16 | How to Generate a Primary Event |
---|
17 | </title> |
---|
18 | |
---|
19 | <!-- ******************* Section (Level#2) ****************** --> |
---|
20 | <sect2 id="sect.HowToGenEvent.GenPrimary"> |
---|
21 | <title> |
---|
22 | Generating Primary Events |
---|
23 | </title> |
---|
24 | |
---|
25 | <para> |
---|
26 | <emphasis>G4VuserPrimaryGeneratorAction</emphasis> is one of the mandatory |
---|
27 | classes available for deriving your own concrete class. In your |
---|
28 | concrete class, you have to specify how a primary event should be |
---|
29 | generated. Actual generation of primary particles will be done by |
---|
30 | concrete classes of <emphasis>G4VPrimaryGenerator</emphasis>, explained in the |
---|
31 | following sub-section. Your <emphasis>G4VUserPrimaryGeneratorAction</emphasis> |
---|
32 | concrete class just arranges the way primary particles are generated. |
---|
33 | |
---|
34 | <example id="programlist_HowToGenEvent_1"> |
---|
35 | <title> |
---|
36 | An example of a <emphasis>G4VUserPrimaryGeneratorAction</emphasis> |
---|
37 | concrete class using <emphasis>G4ParticleGun</emphasis>. |
---|
38 | For the usage of <emphasis>G4ParticleGun</emphasis> refer to the |
---|
39 | next subsection. |
---|
40 | </title> |
---|
41 | |
---|
42 | <programlisting> |
---|
43 | #ifndef ExN01PrimaryGeneratorAction_h |
---|
44 | #define ExN01PrimaryGeneratorAction_h 1 |
---|
45 | |
---|
46 | #include "G4VUserPrimaryGeneratorAction.hh" |
---|
47 | |
---|
48 | class G4ParticleGun; |
---|
49 | class G4Event; |
---|
50 | |
---|
51 | class ExN01PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction |
---|
52 | { |
---|
53 | public: |
---|
54 | ExN01PrimaryGeneratorAction(); |
---|
55 | ~ExN01PrimaryGeneratorAction(); |
---|
56 | |
---|
57 | public: |
---|
58 | void generatePrimaries(G4Event* anEvent); |
---|
59 | |
---|
60 | private: |
---|
61 | G4ParticleGun* particleGun; |
---|
62 | }; |
---|
63 | |
---|
64 | #endif |
---|
65 | |
---|
66 | #include "ExN01PrimaryGeneratorAction.hh" |
---|
67 | #include "G4Event.hh" |
---|
68 | #include "G4ParticleGun.hh" |
---|
69 | #include "G4ThreeVector.hh" |
---|
70 | #include "G4Geantino.hh" |
---|
71 | #include "globals.hh" |
---|
72 | |
---|
73 | ExN01PrimaryGeneratorAction::ExN01PrimaryGeneratorAction() |
---|
74 | { |
---|
75 | G4int n_particle = 1; |
---|
76 | particleGun = new G4ParticleGun(n_particle); |
---|
77 | |
---|
78 | particleGun->SetParticleDefinition(G4Geantino::GeantinoDefinition()); |
---|
79 | particleGun->SetParticleEnergy(1.0*GeV); |
---|
80 | particleGun->SetParticlePosition(G4ThreeVector(-2.0*m,0.0*m,0.0*m)); |
---|
81 | } |
---|
82 | |
---|
83 | ExN01PrimaryGeneratorAction::~ExN01PrimaryGeneratorAction() |
---|
84 | { |
---|
85 | delete particleGun; |
---|
86 | } |
---|
87 | |
---|
88 | void ExN01PrimaryGeneratorAction::generatePrimaries(G4Event* anEvent) |
---|
89 | { |
---|
90 | G4int i = anEvent->get_eventID() % 3; |
---|
91 | switch(i) |
---|
92 | { |
---|
93 | case 0: |
---|
94 | particleGun->SetParticleMomentumDirection(G4ThreeVector(1.0,0.0,0.0)); |
---|
95 | break; |
---|
96 | case 1: |
---|
97 | particleGun->SetParticleMomentumDirection(G4ThreeVector(1.0,0.1,0.0)); |
---|
98 | break; |
---|
99 | case 2: |
---|
100 | particleGun->SetParticleMomentumDirection(G4ThreeVector(1.0,0.0,0.1)); |
---|
101 | break; |
---|
102 | } |
---|
103 | |
---|
104 | particleGun->generatePrimaryVertex(anEvent); |
---|
105 | } |
---|
106 | </programlisting> |
---|
107 | </example> |
---|
108 | |
---|
109 | </para> |
---|
110 | |
---|
111 | |
---|
112 | <!-- ******************* Section (Level#3) ****************** --> |
---|
113 | <sect3 id="sect.HowToGenEvent.GenPrimary.SelectGenerator"> |
---|
114 | <title> |
---|
115 | Selection of the generator |
---|
116 | </title> |
---|
117 | |
---|
118 | <para> |
---|
119 | In the constructor of your <emphasis>G4VUserPrimaryGeneratorAction</emphasis>, |
---|
120 | you should instantiate the primary generator(s). If necessary, you |
---|
121 | need to set some initial conditions for the generator(s). |
---|
122 | </para> |
---|
123 | |
---|
124 | <para> |
---|
125 | In <xref linkend="programlist_HowToGenEvent_1" />, |
---|
126 | <emphasis>G4ParticleGun</emphasis> is constructed to |
---|
127 | use as the actual primary particle generator. Methods of |
---|
128 | <emphasis>G4ParticleGun</emphasis> are described in the following section. Please |
---|
129 | note that the primary generator object(s) you construct in your |
---|
130 | <emphasis>G4VUserPrimaryGeneratorAction</emphasis> concrete class must be deleted |
---|
131 | in your destructor. |
---|
132 | </para> |
---|
133 | |
---|
134 | </sect3> |
---|
135 | |
---|
136 | <!-- ******************* Section (Level#3) ****************** --> |
---|
137 | <sect3 id="sect.HowToGenEvent.GenPrimary.GenEvent"> |
---|
138 | <title> |
---|
139 | Generation of an event |
---|
140 | </title> |
---|
141 | |
---|
142 | <para> |
---|
143 | <emphasis>G4VUserPrimaryGeneratorAction</emphasis> has a pure virtual method |
---|
144 | named <literal>generatePrimaries()</literal>. This method is invoked at the |
---|
145 | beginning of each event. In this method, you have to invoke the |
---|
146 | <emphasis>G4VPrimaryGenerator</emphasis> concrete class you instantiated via the |
---|
147 | <literal>generatePrimaryVertex()</literal> method. |
---|
148 | </para> |
---|
149 | |
---|
150 | <para> |
---|
151 | You can invoke more than one generator and/or invoke one |
---|
152 | generator more than once. Mixing up several generators can produce |
---|
153 | a more complicated primary event. |
---|
154 | </para> |
---|
155 | |
---|
156 | </sect3> |
---|
157 | </sect2> |
---|
158 | |
---|
159 | |
---|
160 | <!-- ******************* Section (Level#2) ****************** --> |
---|
161 | <sect2 id="sect.HowToGenEvent.G4VPrimGen"> |
---|
162 | <title> |
---|
163 | G4VPrimaryGenerator |
---|
164 | </title> |
---|
165 | |
---|
166 | <para> |
---|
167 | Geant4 provides three <emphasis>G4VPrimaryGenerator</emphasis> concrete |
---|
168 | classes. Among these <emphasis>G4ParticleGun</emphasis> and |
---|
169 | <emphasis> G4GeneralParticleSource</emphasis> will be discussed here. |
---|
170 | The third one is <emphasis>G4HEPEvtInterface</emphasis>, which will be |
---|
171 | discussed in <xref linkend="sect.EventGen" />. |
---|
172 | </para> |
---|
173 | |
---|
174 | |
---|
175 | <!-- ******************* Section (Level#3) ****************** --> |
---|
176 | <sect3 id="sect.HowToGenEvent.G4VPrimGen.G4PartGun"> |
---|
177 | <title> |
---|
178 | G4ParticleGun |
---|
179 | </title> |
---|
180 | |
---|
181 | <para> |
---|
182 | <emphasis>G4ParticleGun</emphasis> is a generator provided by Geant4. This class |
---|
183 | generates primary particle(s) with a given momentum and position. |
---|
184 | It does not provide any sort of randomizing. The constructor of |
---|
185 | <emphasis>G4ParticleGun</emphasis> takes an integer which causes the generation |
---|
186 | of one or more primaries of exactly same kinematics. It is a rather |
---|
187 | frequent user requirement to generate a primary with randomized |
---|
188 | energy, momentum, and/or position. Such randomization can be |
---|
189 | achieved by invoking various set methods provided by |
---|
190 | <emphasis>G4ParticleGun</emphasis>. The invocation of these methods should be |
---|
191 | implemented in the <literal>generatePrimaries()</literal> method of your |
---|
192 | concrete <emphasis>G4VUserPrimaryGeneratorAction</emphasis> class before invoking |
---|
193 | <literal>generatePrimaryVertex()</literal> of |
---|
194 | <emphasis>G4ParticleGun</emphasis>. |
---|
195 | Geant4 provides various random number generation methods with various |
---|
196 | distributions (see <xref linkend="sect.GlobClass" />). |
---|
197 | </para> |
---|
198 | |
---|
199 | </sect3> |
---|
200 | |
---|
201 | <!-- ******************* Section (Level#3) ****************** --> |
---|
202 | <sect3 id="sect.HowToGenEvent.G4VPrimGen.PublicMethG4PartGun"> |
---|
203 | <title> |
---|
204 | Public methods of <emphasis>G4ParticleGun</emphasis> |
---|
205 | </title> |
---|
206 | |
---|
207 | <para> |
---|
208 | The following methods are provided by <emphasis>G4ParticleGun</emphasis>, and all |
---|
209 | of them can be invoked from the <literal>generatePrimaries()</literal> method |
---|
210 | in your concrete <emphasis>G4VUserPrimaryGeneratorAction</emphasis> class. |
---|
211 | |
---|
212 | <itemizedlist spacing="compact"> |
---|
213 | <listitem><para> |
---|
214 | <literal>void SetParticleDefinition(G4ParticleDefinition*)</literal> |
---|
215 | </para></listitem> |
---|
216 | <listitem><para> |
---|
217 | <literal>void SetParticleMomentum(G4ParticleMomentum)</literal> |
---|
218 | </para></listitem> |
---|
219 | <listitem><para> |
---|
220 | <literal>void SetParticleMomentumDirection(G4ThreeVector)</literal> |
---|
221 | </para></listitem> |
---|
222 | <listitem><para> |
---|
223 | <literal>void SetParticleEnergy(G4double)</literal> |
---|
224 | </para></listitem> |
---|
225 | <listitem><para> |
---|
226 | <literal>void SetParticleTime(G4double)</literal> |
---|
227 | </para></listitem> |
---|
228 | <listitem><para> |
---|
229 | <literal>void SetParticlePosition(G4ThreeVector)</literal> |
---|
230 | </para></listitem> |
---|
231 | <listitem><para> |
---|
232 | <literal>void SetParticlePolarization(G4ThreeVector)</literal> |
---|
233 | </para></listitem> |
---|
234 | <listitem><para> |
---|
235 | <literal>void SetNumberOfParticles(G4int)</literal> |
---|
236 | </para></listitem> |
---|
237 | </itemizedlist> |
---|
238 | </para> |
---|
239 | </sect3> |
---|
240 | |
---|
241 | <!-- ******************* Section (Level#3) ****************** --> |
---|
242 | <sect3 id="sect.HowToGenEvent.G4VPrimGen.G4GPS"> |
---|
243 | <title> |
---|
244 | G4GeneralParticleSource |
---|
245 | </title> |
---|
246 | |
---|
247 | <para> |
---|
248 | For many applications <literal>G4ParticleGun</literal> is a suitable |
---|
249 | particle generator. Howevr if you want to generate primary particles |
---|
250 | in more sophisticated manner, you can utilize |
---|
251 | <literal>G4GeneralParticleSource</literal> - Geant4 General Particle |
---|
252 | Source module (GPS). |
---|
253 | </para> |
---|
254 | |
---|
255 | <para> |
---|
256 | Using this tool, you can control the following characteristics of |
---|
257 | primary particles: |
---|
258 | |
---|
259 | |
---|
260 | <itemizedlist spacing="compact"> |
---|
261 | <listitem><para> |
---|
262 | Spectrum: linear, exponential, power-law, Gaussian, blackbody, or |
---|
263 | piece-wise fits to data. |
---|
264 | </para></listitem> |
---|
265 | <listitem><para> |
---|
266 | Angular distribution: unidirectional, isotropic, cosine-law, |
---|
267 | beam or arbitrary (user defined). |
---|
268 | </para></listitem> |
---|
269 | <listitem><para> |
---|
270 | Spatial sampling: on simple 2D or 3D surfaces such as discs, spheres, |
---|
271 | and boxes. |
---|
272 | </para></listitem> |
---|
273 | <listitem><para> |
---|
274 | Multiple sources: multiple independent sources can be used in the same run. |
---|
275 | </para></listitem> |
---|
276 | </itemizedlist> |
---|
277 | </para> |
---|
278 | |
---|
279 | <para> |
---|
280 | Details of information on the General Source Particle Module can be |
---|
281 | found in the documents |
---|
282 | <ulink url="http://reat.space.qinetiq.com/gps/"> |
---|
283 | Geant4 General Particle Source</ulink>. |
---|
284 | </para> |
---|
285 | |
---|
286 | </sect3> |
---|
287 | </sect2> |
---|
288 | </sect1> |
---|