source: trunk/examples/extended/field/field02/src/F02PrimaryGeneratorAction.cc @ 1287

Last change on this file since 1287 was 1230, checked in by garnier, 15 years ago

update to geant4.9.3

File size: 5.2 KB
Line 
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// $Id: F02PrimaryGeneratorAction.cc,v 1.5 2006/06/29 17:18:15 gunter Exp $
28// GEANT4 tag $Name: geant4-09-03-cand-01 $
29//
30//
31
32//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
33//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
34
35#include "F02PrimaryGeneratorAction.hh"
36
37#include "F02DetectorConstruction.hh"
38#include "F02PrimaryGeneratorMessenger.hh"
39
40#include "G4Event.hh"
41#include "G4ParticleGun.hh"
42#include "G4ParticleTable.hh"
43#include "G4ParticleDefinition.hh"
44#include "Randomize.hh"
45#include "G4ios.hh"
46
47//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
48 
49G4String F02PrimaryGeneratorAction::thePrimaryParticleName = "proton" ; 
50
51//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
52
53F02PrimaryGeneratorAction::F02PrimaryGeneratorAction(
54                                            F02DetectorConstruction* F02DC)
55  : F02Detector(F02DC), rndmFlag("off"),
56    xvertex(0.),yvertex(0.),zvertex(0.),
57    vertexdefined(false)
58{
59  G4int n_particle = 1;
60  particleGun  = new G4ParticleGun(n_particle);
61 
62  // create a messenger for this class
63  //
64  gunMessenger = new F02PrimaryGeneratorMessenger(this);
65
66  // default particle kinematic
67
68  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
69  G4String particleName;
70  G4ParticleDefinition* particle
71                    = particleTable->FindParticle(particleName="proton");
72  particleGun->SetParticleDefinition(particle);
73 
74  thePrimaryParticleName = particle->GetParticleName() ;
75
76  particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
77  particleGun->SetParticleEnergy(100.*GeV);
78
79  zvertex = 0. ; //  -0.5*(F02Detector->GetAbsorberThickness());
80  particleGun->SetParticlePosition(G4ThreeVector(xvertex,yvertex,zvertex));
81
82}
83
84//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
85
86F02PrimaryGeneratorAction::~F02PrimaryGeneratorAction()
87{
88  delete particleGun;
89  delete gunMessenger;
90}
91
92//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
93
94void F02PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
95{
96  // this function is called at the begining of event
97  //
98  thePrimaryParticleName = particleGun->GetParticleDefinition()->
99                                                GetParticleName() ;
100  G4double x0,y0,z0 ;
101  if(vertexdefined)
102  {
103    x0 = xvertex ;
104    y0 = yvertex ;
105    z0 = zvertex ;
106  }
107  else
108  {
109    x0 = 0. ;
110    y0 = 0. ;
111    z0 = 0. ; // -0.5*(F02Detector->GetWorldSizeZ()) ;
112  }
113  G4double r0,phi0 ;
114
115  if (rndmFlag == "on")
116  {
117      r0 = (F02Detector->GetAbsorberRadius())*std::sqrt(G4UniformRand());
118      phi0 = twopi*G4UniformRand();
119      x0 = r0*std::cos(phi0);
120      y0 = r0*std::sin(phi0);
121  } 
122
123  particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
124  particleGun->GeneratePrimaryVertex(anEvent);
125}
126
127///////////////////////////////////////////////////////////////////////
128//
129//
130
131G4String F02PrimaryGeneratorAction::GetPrimaryName()
132{
133   return thePrimaryParticleName ;
134}
135
136void F02PrimaryGeneratorAction::Setzvertex(G4double z)
137{
138  vertexdefined = true ;
139  zvertex = z ;
140  G4cout << " Z coordinate of the primary vertex = " << zvertex/mm <<
141            " mm." << G4endl;
142}
143void F02PrimaryGeneratorAction::Setxvertex(G4double x)
144{
145  vertexdefined = true ;
146  xvertex = x ;
147  G4cout << " X coordinate of the primary vertex = " << xvertex/mm <<
148            " mm." << G4endl;
149}
150
151void F02PrimaryGeneratorAction::Setyvertex(G4double y)
152{
153  vertexdefined = true ;
154  yvertex = y ;
155  G4cout << " Y coordinate of the primary vertex = " << yvertex/mm <<
156            " mm." << G4endl;
157}
Note: See TracBrowser for help on using the repository browser.