1 | // |
---|
2 | // ******************************************************************** |
---|
3 | // * License and Disclaimer * |
---|
4 | // * * |
---|
5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
7 | // * conditions of the Geant4 Software License, included in the file * |
---|
8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
9 | // * include a list of copyright holders. * |
---|
10 | // * * |
---|
11 | // * Neither the authors of this software system, nor their employing * |
---|
12 | // * institutes,nor the agencies providing financial support for this * |
---|
13 | // * work make any representation or warranty, express or implied, * |
---|
14 | // * regarding this software system or assume any liability for its * |
---|
15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
16 | // * for the full disclaimer and the limitation of liability. * |
---|
17 | // * * |
---|
18 | // * This code implementation is the result of the scientific and * |
---|
19 | // * technical work of the GEANT4 collaboration. * |
---|
20 | // * By using, copying, modifying or distributing the software (or * |
---|
21 | // * any work based on the software) you agree to acknowledge its * |
---|
22 | // * use in resulting scientific publications, and indicate your * |
---|
23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
24 | // ******************************************************************** |
---|
25 | // |
---|
26 | // |
---|
27 | // SprayParticleGun |
---|
28 | // |
---|
29 | // Implementation of test particle gun |
---|
30 | // |
---|
31 | |
---|
32 | #include "SprayParticleGun.hh" |
---|
33 | #include "SprayParticleGunMessenger.hh" |
---|
34 | |
---|
35 | #include "G4PrimaryParticle.hh" |
---|
36 | #include "G4ParticleTypes.hh" |
---|
37 | #include "G4Event.hh" |
---|
38 | |
---|
39 | // |
---|
40 | // Constructor (no arguments) |
---|
41 | // |
---|
42 | SprayParticleGun::SprayParticleGun() |
---|
43 | { |
---|
44 | SetDefaults(); |
---|
45 | } |
---|
46 | |
---|
47 | // |
---|
48 | // Constructor (position specified) |
---|
49 | // |
---|
50 | SprayParticleGun::SprayParticleGun( G4ThreeVector inStart ) |
---|
51 | { |
---|
52 | SetDefaults(); |
---|
53 | start = inStart; |
---|
54 | } |
---|
55 | |
---|
56 | // |
---|
57 | // Destructor |
---|
58 | // |
---|
59 | SprayParticleGun::~SprayParticleGun() { |
---|
60 | delete messenger; |
---|
61 | } |
---|
62 | |
---|
63 | // |
---|
64 | // SetDefaults |
---|
65 | // |
---|
66 | // Set default parameters |
---|
67 | // |
---|
68 | void SprayParticleGun::SetDefaults() |
---|
69 | { |
---|
70 | start = G4ThreeVector(0,0,0); |
---|
71 | spray[0] = 7; |
---|
72 | spray[1] = 7; |
---|
73 | spray[2] = 2; |
---|
74 | |
---|
75 | particleType = G4Geantino::GeantinoDefinition(); |
---|
76 | |
---|
77 | messenger = new SprayParticleGunMessenger(this); |
---|
78 | } |
---|
79 | |
---|
80 | // |
---|
81 | // GeneratePrimaryVertex |
---|
82 | // |
---|
83 | // Make the event |
---|
84 | // |
---|
85 | void SprayParticleGun::GeneratePrimaryVertex( G4Event *evt ) |
---|
86 | { |
---|
87 | // |
---|
88 | // Create a new vertex |
---|
89 | // |
---|
90 | G4PrimaryVertex *vertex = new G4PrimaryVertex( start, 0.0 ); |
---|
91 | |
---|
92 | // |
---|
93 | // Loop over the three dimensions, creating particles |
---|
94 | // as specified |
---|
95 | // |
---|
96 | G4double px = -1.0; |
---|
97 | G4int ix = 1; |
---|
98 | do { |
---|
99 | if (!(spray[0]&ix)) continue; |
---|
100 | |
---|
101 | G4double py = -1.0; |
---|
102 | G4int iy = 1; |
---|
103 | do { |
---|
104 | if (!(spray[1]&iy)) continue; |
---|
105 | |
---|
106 | G4double pz = -1.0; |
---|
107 | G4int iz = 1; |
---|
108 | do { |
---|
109 | if (!(spray[2]&iz)) continue; |
---|
110 | |
---|
111 | if (ix==2 && iy==2 && iz==2) continue; |
---|
112 | |
---|
113 | G4PrimaryParticle *particle = new G4PrimaryParticle( particleType, px, py, pz ); |
---|
114 | vertex->SetPrimary( particle ); |
---|
115 | } while( pz += 1.0, iz <<= 1, iz < 8 ); |
---|
116 | } while( py += 1.0, iy <<= 1, iy < 8 ); |
---|
117 | } while( px += 1.0, ix <<= 1, ix < 8 ); |
---|
118 | |
---|
119 | // |
---|
120 | // Give this sucker to the event |
---|
121 | // |
---|
122 | evt->AddPrimaryVertex( vertex ); |
---|
123 | } |
---|