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

Last change on this file since 921 was 904, checked in by garnier, 16 years ago

ajout de la doc

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