source: trunk/source/geometry/magneticfield/test/NTST/src/NTSTGunGenerator.cc@ 1256

Last change on this file since 1256 was 1199, checked in by garnier, 16 years ago

nvx fichiers dans CVS

File size: 3.9 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// $Id: NTSTGunGenerator.cc,v 1.5 2006/06/29 18:26:16 gunter Exp $
27// GEANT4 tag $Name: HEAD $
28//
29//
30
31//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
32
33#include "NTSTGunGenerator.hh"
34#include "NTSTGunMessenger.hh"
35#include "G4Event.hh"
36#include "G4ParticleTable.hh"
37#include "G4ParticleDefinition.hh"
38#include "Randomize.hh"
39
40//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
41
42NTSTGunGenerator::NTSTGunGenerator()
43: dMeanVertex(0.,0.,0.), dRmsVertex (0.,0.,0.), dPolarization(0.,0.,0.),
44 dPlow(1.), dPhigh(1.), dCoslow(-1.), dCoshigh(+1.0),
45 dPhilow(0.),dPhihigh(2*pi), dT0(0.), dN(1)
46{
47 messenger = new NTSTGunMessenger(this);
48 MeanVertex = dMeanVertex;
49 RmsVertex = dRmsVertex;
50 Polarization = dPolarization;
51 Plow = dPlow;
52 Phigh = dPhigh;
53 Coslow = dCoslow;
54 Coshigh = dCoshigh;
55 Philow = dPhilow;
56 Phihigh = dPhihigh;
57 T0 = dT0;
58 N = dN;
59}
60
61//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
62
63NTSTGunGenerator::~NTSTGunGenerator()
64{
65 delete messenger;
66}
67
68//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
69
70void
71NTSTGunGenerator::GeneratePrimaryVertex(G4Event* anEvent)
72{
73 // this function is called at the begining of event
74 //
75 // generate primary vertex
76 G4double x = MeanVertex.x();
77 if (RmsVertex.x()!=0) x += RmsVertex.x()*Gauss();
78 G4double y = MeanVertex.y();
79 if (RmsVertex.y()!=0) y += RmsVertex.y()*Gauss();
80 G4double z = MeanVertex.z();
81 if (RmsVertex.z()!=0) z += RmsVertex.z()*Gauss();
82 G4double t=0*ns;
83
84 G4PrimaryVertex* vertex = new G4PrimaryVertex(x, y, z, t);
85
86 for (int ipart=0; ipart<GetNumberOfParticles(); ipart++){
87 //
88 // generate random direction (modifiy later to select an angular range)
89 G4double cth = 2.*(G4UniformRand()-0.5);
90 G4double sth = std::sqrt(1.-cth*cth);
91 G4double phi = 2*pi*G4UniformRand();
92 G4double cfi = std::cos(phi);
93 G4double sfi = std::sin(phi);
94 G4double p = (Plow + G4UniformRand()*(Phigh - Plow))*GeV;
95 //
96 G4PrimaryParticle* part = new G4PrimaryParticle(GetParticleDefinition(),
97 p*sth*cfi, p*sth*sfi, p*cth);
98 //
99 // add to vertex
100 vertex->SetPrimary( part );
101 }
102 //
103 // add vertex to event
104 anEvent->AddPrimaryVertex( vertex );
105}
106
107
108
109
Note: See TracBrowser for help on using the repository browser.