source: trunk/documents/UserDoc/DocBookUsersGuides/ForApplicationDeveloper/xml/GettingStarted/eventDef.xml

Last change on this file was 1211, checked in by garnier, 15 years ago

CVS update

File size: 9.0 KB
Line 
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>
16How to Generate a Primary Event
17</title>
18
19<!-- ******************* Section (Level#2) ****************** -->
20<sect2 id="sect.HowToGenEvent.GenPrimary">
21<title>
22Generating Primary Events
23</title>
24
25<para>
26<emphasis>G4VuserPrimaryGeneratorAction</emphasis> is one of the mandatory
27classes available for deriving your own concrete class. In your
28concrete class, you have to specify how a primary event should be
29generated. Actual generation of primary particles will be done by
30concrete classes of <emphasis>G4VPrimaryGenerator</emphasis>, explained in the
31following sub-section. Your <emphasis>G4VUserPrimaryGeneratorAction</emphasis>
32concrete class just arranges the way primary particles are generated.
33
34<example id="programlist_HowToGenEvent_1">
35<title>
36An example of a <emphasis>G4VUserPrimaryGeneratorAction</emphasis> 
37concrete class using <emphasis>G4ParticleGun</emphasis>.
38For the usage of <emphasis>G4ParticleGun</emphasis> refer to the
39next subsection.
40</title>
41
42<programlisting>
43#ifndef ExN01PrimaryGeneratorAction_h
44#define ExN01PrimaryGeneratorAction_h 1
45
46#include "G4VUserPrimaryGeneratorAction.hh"
47
48class G4ParticleGun;
49class G4Event;
50
51class 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
73ExN01PrimaryGeneratorAction::ExN01PrimaryGeneratorAction()
74{
75  G4int n_particle = 1;
76  particleGun = new G4ParticleGun(n_particle);
77
78  particleGun-&gt;SetParticleDefinition(G4Geantino::GeantinoDefinition());
79  particleGun-&gt;SetParticleEnergy(1.0*GeV);
80  particleGun-&gt;SetParticlePosition(G4ThreeVector(-2.0*m,0.0*m,0.0*m));
81}
82
83ExN01PrimaryGeneratorAction::~ExN01PrimaryGeneratorAction()
84{
85  delete particleGun;
86}
87
88void ExN01PrimaryGeneratorAction::generatePrimaries(G4Event* anEvent)
89{
90  G4int i = anEvent-&gt;get_eventID() % 3;
91  switch(i)
92  {
93    case 0:
94      particleGun-&gt;SetParticleMomentumDirection(G4ThreeVector(1.0,0.0,0.0));
95      break;
96    case 1:
97      particleGun-&gt;SetParticleMomentumDirection(G4ThreeVector(1.0,0.1,0.0));
98      break;
99    case 2:
100      particleGun-&gt;SetParticleMomentumDirection(G4ThreeVector(1.0,0.0,0.1));
101      break;
102  }
103
104  particleGun-&gt;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>
115Selection of the generator
116</title>
117
118<para>
119In the constructor of your <emphasis>G4VUserPrimaryGeneratorAction</emphasis>,
120you should instantiate the primary generator(s). If necessary, you
121need to set some initial conditions for the generator(s).
122</para>
123
124<para>
125In <xref linkend="programlist_HowToGenEvent_1" />,
126<emphasis>G4ParticleGun</emphasis> is constructed to
127use as the actual primary particle generator. Methods of
128<emphasis>G4ParticleGun</emphasis> are described in the following section. Please
129note that the primary generator object(s) you construct in your
130<emphasis>G4VUserPrimaryGeneratorAction</emphasis> concrete class must be deleted
131in your destructor.
132</para>
133
134</sect3>
135
136<!-- ******************* Section (Level#3) ****************** -->
137<sect3 id="sect.HowToGenEvent.GenPrimary.GenEvent">
138<title>
139Generation of an event
140</title>
141
142<para>
143<emphasis>G4VUserPrimaryGeneratorAction</emphasis> has a pure virtual method
144named <literal>generatePrimaries()</literal>. This method is invoked at the
145beginning 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>
151You can invoke more than one generator and/or invoke one
152generator more than once. Mixing up several generators can produce
153a 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>
163G4VPrimaryGenerator
164</title>
165
166<para>
167Geant4 provides three <emphasis>G4VPrimaryGenerator</emphasis> concrete
168classes. Among these <emphasis>G4ParticleGun</emphasis> and
169<emphasis> G4GeneralParticleSource</emphasis> will be discussed here.
170The third one is <emphasis>G4HEPEvtInterface</emphasis>, which will be
171discussed in <xref linkend="sect.EventGen" />.
172</para>
173
174
175<!-- ******************* Section (Level#3) ****************** -->
176<sect3 id="sect.HowToGenEvent.G4VPrimGen.G4PartGun">
177<title>
178G4ParticleGun
179</title>
180
181<para>
182<emphasis>G4ParticleGun</emphasis> is a generator provided by Geant4. This class
183generates primary particle(s) with a given momentum and position.
184It does not provide any sort of randomizing. The constructor of
185<emphasis>G4ParticleGun</emphasis> takes an integer which causes the generation
186of one or more primaries of exactly same kinematics. It is a rather
187frequent user requirement to generate a primary with randomized
188energy, momentum, and/or position. Such randomization can be
189achieved by invoking various set methods provided by
190<emphasis>G4ParticleGun</emphasis>. The invocation of these methods should be
191implemented in the <literal>generatePrimaries()</literal> method of your
192concrete <emphasis>G4VUserPrimaryGeneratorAction</emphasis> class before invoking
193<literal>generatePrimaryVertex()</literal> of
194<emphasis>G4ParticleGun</emphasis>.
195Geant4 provides various random number generation methods with various
196distributions (see <xref linkend="sect.GlobClass" />).
197</para>
198
199</sect3>
200
201<!-- ******************* Section (Level#3) ****************** -->
202<sect3 id="sect.HowToGenEvent.G4VPrimGen.PublicMethG4PartGun">
203<title>
204Public methods of <emphasis>G4ParticleGun</emphasis>
205</title>
206
207<para>
208The following methods are provided by <emphasis>G4ParticleGun</emphasis>, and all
209of them can be invoked from the <literal>generatePrimaries()</literal> method
210in 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>
244G4GeneralParticleSource
245</title>
246
247<para>
248For many applications <literal>G4ParticleGun</literal> is a suitable
249particle generator. Howevr if you want to generate primary particles
250in more sophisticated manner, you can utilize
251<literal>G4GeneralParticleSource</literal> - Geant4 General Particle
252Source module (GPS).
253</para>
254
255<para>
256Using this tool, you can control the following characteristics of
257primary 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>
280Details of information on the General Source Particle Module can be
281found in the documents
282<ulink url="http://reat.space.qinetiq.com/gps/">
283Geant4 General Particle Source</ulink>.
284</para>
285
286</sect3>
287</sect2>
288</sect1>
Note: See TracBrowser for help on using the repository browser.