1 | <HTML> |
---|
2 | <TITLE> |
---|
3 | </TITLE> |
---|
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 | |
---|
8 | <BODY> |
---|
9 | <TABLE WIDTH="100%"><TR> |
---|
10 | <TD> |
---|
11 | |
---|
12 | |
---|
13 | <A HREF="index.html"> |
---|
14 | <IMG SRC="../../../../resources/html/IconsGIF/Contents.gif" ALT="Contents"></A> |
---|
15 | <A HREF="physicsDef.html"> |
---|
16 | <IMG SRC="../../../../resources/html/IconsGIF/Previous.gif" ALT="Previous"></A> |
---|
17 | <A HREF="makeFile.html"> |
---|
18 | <IMG SRC="../../../../resources/html/IconsGIF/Next.gif" ALT="Next"></A> |
---|
19 | </TD> |
---|
20 | <TD ALIGN="Right"> |
---|
21 | <FONT SIZE="-1" COLOR="#238E23"> |
---|
22 | <B>Geant4 User's Guide</B> |
---|
23 | <BR> |
---|
24 | <B>For Application Developers</B> |
---|
25 | <BR> |
---|
26 | <B>Getting Started with Geant4</B> |
---|
27 | </FONT> |
---|
28 | </TD> |
---|
29 | </TR></TABLE> |
---|
30 | <BR><BR> |
---|
31 | |
---|
32 | <P ALIGN="Center"> |
---|
33 | <FONT SIZE="+3" COLOR="#238E23"> |
---|
34 | <B>2.6 How to Generate a Primary Event</B> |
---|
35 | </FONT> |
---|
36 | <BR><BR> |
---|
37 | |
---|
38 | <HR ALIGN="Center" SIZE="7%"> |
---|
39 | <P> |
---|
40 | |
---|
41 | <a name="2.6.1"> |
---|
42 | <H2>2.6.1 Generating Primary Events</H2></a> |
---|
43 | |
---|
44 | <I>G4VuserPrimaryGeneratorAction</I> is one of the mandatory classes |
---|
45 | available for deriving your own concrete class. In your concrete class, you |
---|
46 | have to specify how a primary event should be generated. Actual |
---|
47 | generation of primary particles will be done by concrete classes of |
---|
48 | <I>G4VPrimaryGenerator</I>, explained in the following sub-section. |
---|
49 | Your <I>G4VUserPrimaryGeneratorAction</I> concrete class just arranges |
---|
50 | the way primary particles are generated. |
---|
51 | <P> |
---|
52 | <center> |
---|
53 | <table border=2 cellpadding=10> |
---|
54 | <tr> |
---|
55 | <td> |
---|
56 | <PRE> |
---|
57 | <FONT FACE="Courier New"> |
---|
58 | #ifndef ExN01PrimaryGeneratorAction_h |
---|
59 | #define ExN01PrimaryGeneratorAction_h 1 |
---|
60 | |
---|
61 | #include "G4VUserPrimaryGeneratorAction.hh" |
---|
62 | |
---|
63 | class G4ParticleGun; |
---|
64 | class G4Event; |
---|
65 | |
---|
66 | class ExN01PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction |
---|
67 | { |
---|
68 | public: |
---|
69 | ExN01PrimaryGeneratorAction(); |
---|
70 | ~ExN01PrimaryGeneratorAction(); |
---|
71 | |
---|
72 | public: |
---|
73 | void generatePrimaries(G4Event* anEvent); |
---|
74 | |
---|
75 | private: |
---|
76 | G4ParticleGun* particleGun; |
---|
77 | }; |
---|
78 | |
---|
79 | #endif |
---|
80 | |
---|
81 | #include "ExN01PrimaryGeneratorAction.hh" |
---|
82 | #include "G4Event.hh" |
---|
83 | #include "G4ParticleGun.hh" |
---|
84 | #include "G4ThreeVector.hh" |
---|
85 | #include "G4Geantino.hh" |
---|
86 | #include "globals.hh" |
---|
87 | |
---|
88 | ExN01PrimaryGeneratorAction::ExN01PrimaryGeneratorAction() |
---|
89 | { |
---|
90 | G4int n_particle = 1; |
---|
91 | particleGun = new G4ParticleGun(n_particle); |
---|
92 | |
---|
93 | particleGun->SetParticleDefinition(G4Geantino::GeantinoDefinition()); |
---|
94 | particleGun->SetParticleEnergy(1.0*GeV); |
---|
95 | particleGun->SetParticlePosition(G4ThreeVector(-2.0*m,0.0*m,0.0*m)); |
---|
96 | } |
---|
97 | |
---|
98 | ExN01PrimaryGeneratorAction::~ExN01PrimaryGeneratorAction() |
---|
99 | { |
---|
100 | delete particleGun; |
---|
101 | } |
---|
102 | |
---|
103 | void ExN01PrimaryGeneratorAction::generatePrimaries(G4Event* anEvent) |
---|
104 | { |
---|
105 | G4int i = anEvent->get_eventID() % 3; |
---|
106 | switch(i) |
---|
107 | { |
---|
108 | case 0: |
---|
109 | particleGun->SetParticleMomentumDirection(G4ThreeVector(1.0,0.0,0.0)); |
---|
110 | break; |
---|
111 | case 1: |
---|
112 | particleGun->SetParticleMomentumDirection(G4ThreeVector(1.0,0.1,0.0)); |
---|
113 | break; |
---|
114 | case 2: |
---|
115 | particleGun->SetParticleMomentumDirection(G4ThreeVector(1.0,0.0,0.1)); |
---|
116 | break; |
---|
117 | } |
---|
118 | |
---|
119 | particleGun->generatePrimaryVertex(anEvent); |
---|
120 | } |
---|
121 | </PRE> |
---|
122 | </FONT> |
---|
123 | </td> |
---|
124 | </tr> |
---|
125 | <tr> |
---|
126 | <td align=center> |
---|
127 | Source listing 2.6.1<BR> |
---|
128 | An example of a <I>G4VUserPrimaryGeneratorAction</I> |
---|
129 | concrete class using <I>G4ParticleGun</I>. For the usage of <I>G4ParticleGun</I> |
---|
130 | refer to 2.6.2. |
---|
131 | </td> |
---|
132 | </tr> |
---|
133 | </table></center> |
---|
134 | <P> |
---|
135 | |
---|
136 | <h4>2.6.1.1 Selection of the generator</h4> |
---|
137 | |
---|
138 | In the constructor of your <I>G4VUserPrimaryGeneratorAction</I>, |
---|
139 | you should instantiate the primary generator(s). If necessary, you need to |
---|
140 | set some initial conditions for the generator(s). |
---|
141 | <P> |
---|
142 | In Source listing 2.6.1, <I>G4ParticleGun</I> is constructed to use |
---|
143 | as the actual primary particle generator. Methods of <I>G4ParticleGun</I> |
---|
144 | are described in the following section. Please note that the primary |
---|
145 | generator object(s) you construct in your <I>G4VUserPrimaryGeneratorAction</I> |
---|
146 | concrete class must be deleted in your destructor. |
---|
147 | <P> |
---|
148 | |
---|
149 | <h4>2.6.1.2 Generation of an event</h4> |
---|
150 | |
---|
151 | <I>G4VUserPrimaryGeneratorAction</I> has a pure virtual method |
---|
152 | named <tt>generatePrimaries()</tt>. This method is invoked at the |
---|
153 | beginning of each event. In this method, you have to invoke the |
---|
154 | <I>G4VPrimaryGenerator</I> concrete class you instantiated via |
---|
155 | the <tt>generatePrimaryVertex()</tt> method. |
---|
156 | <P> |
---|
157 | You can invoke more than one generator and/or invoke one generator |
---|
158 | more than once. Mixing up several generators can produce a more |
---|
159 | complicated primary event. |
---|
160 | <P> |
---|
161 | |
---|
162 | <HR> |
---|
163 | <a name="2.6.2"> |
---|
164 | <H2>2.6.2 <i>G4VPrimaryGenerator</i></H2></a> |
---|
165 | |
---|
166 | Geant4 provides two <I>G4VPrimaryGenerator</I> concrete classes. One is |
---|
167 | <I>G4ParticleGun</I>, which will be discussed here, and the other is |
---|
168 | <I>G4HEPEvtInterface</I>, which will be discussed in |
---|
169 | <a href="../Fundamentals/eventGenerator.html">Section 3.6</a>. |
---|
170 | <P> |
---|
171 | <h4>2.6.2.1 <i>G4ParticleGun</i></h4> |
---|
172 | |
---|
173 | <I>G4ParticleGun</I> is a generator provided by Geant4. This class generates |
---|
174 | primary particle(s) with a given momentum and position. It does not provide |
---|
175 | any sort of randomizing. The constructor of <I>G4ParticleGun</I> takes an |
---|
176 | integer which causes the generation of one or more primaries of exactly same |
---|
177 | kinematics. It is a rather frequent user requirement to generate a primary |
---|
178 | with randomized energy, momentum, and/or position. Such randomization can |
---|
179 | be achieved by invoking various set methods provided by <I>G4ParticleGun</I>. |
---|
180 | The invocation of these methods should be implemented in the |
---|
181 | <tt>generatePrimaries()</tt> method of your concrete |
---|
182 | <I>G4VUserPrimaryGeneratorAction</I> class before invoking |
---|
183 | <tt>generatePrimaryVertex()</tt> of <I>G4ParticleGun</I>. Geant4 provides |
---|
184 | various random number generation methods with various distributions (see |
---|
185 | <a href="../Fundamentals/global.html">Section 3.2</a>). |
---|
186 | <P> |
---|
187 | |
---|
188 | <h4>2.6.2.2 Public methods of <I>G4ParticleGun</I></h4> |
---|
189 | |
---|
190 | The following methods are provided by <I>G4ParticleGun</I>, and all of |
---|
191 | them can be invoked from the <tt>generatePrimaries()</tt> method in your |
---|
192 | concrete <I>G4VUserPrimaryGeneratorAction</I> class. |
---|
193 | <UL> |
---|
194 | <li><tt>void SetParticleDefinition(G4ParticleDefinition*)</tt> |
---|
195 | <li><tt>void SetParticleMomentum(G4ParticleMomentum)</tt> |
---|
196 | <li><tt>void SetParticleMomentumDirection(G4ThreeVector)</tt> |
---|
197 | <li><tt>void SetParticleEnergy(G4double)</tt> |
---|
198 | <li><tt>void SetParticleTime(G4double)</tt> |
---|
199 | <li><tt>void SetParticlePosition(G4ThreeVector)</tt> |
---|
200 | <li><tt>void SetParticlePolarization(G4ThreeVector)</tt> |
---|
201 | <li><tt>void SetNumberOfParticles(G4int)</tt> |
---|
202 | </UL> |
---|
203 | <p> |
---|
204 | |
---|
205 | <HR> |
---|
206 | <A HREF="../../../../Authors/html/subjectsToAuthors.html"> |
---|
207 | <I>About the authors</I></A> |
---|
208 | |
---|
209 | </BODY> |
---|
210 | </HTML> |
---|
211 | |
---|
212 | |
---|
213 | |
---|
214 | |
---|
215 | |
---|
216 | |
---|
217 | |
---|