source: trunk/source/geometry/magneticfield/test/field03/src/F03PrimaryGeneratorAction.cc @ 1347

Last change on this file since 1347 was 1347, checked in by garnier, 13 years ago

geant4 tag 9.4

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