Geant4-11
MedicalBeam.cc
Go to the documentation of this file.
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// MedicalBeam.cc
28//
29// 2005 Q
30// ====================================================================
31#include "MedicalBeam.hh"
32#include "Randomize.hh"
33#include "G4Event.hh"
34#include "G4ParticleTable.hh"
35#include "G4PrimaryVertex.hh"
36
37using namespace CLHEP;
38
39#include <cmath>
40
41// ====================================================================
42//
43// class description
44//
45// ====================================================================
46
49 : particle(0),
50 kineticE(1.*MeV),
51 sourcePosition(G4ThreeVector()),
52 SSD(1.*m),
53 fieldShape(MedicalBeam::SQUARE),
54 fieldR(10.*cm)
56{
57 fieldXY[0]= fieldXY[1]= 10.*cm;
58}
59
60
64{
65}
66
67
71{
72 // uniform distribution in a limitted solid angle
73 G4double dr;
74 if(fieldShape == MedicalBeam::SQUARE) {
75 dr= std::sqrt(sqr(fieldXY[0]/2.)+sqr(fieldXY[1]/2.));
76 } else {
77 dr= fieldR;
78 }
79
80 G4double sin0= dr/SSD;
81 G4double cos0= std::sqrt(1.-sqr(sin0));
82
85
86 G4double xmax, ymax;
87 if(fieldShape == MedicalBeam::SQUARE) {
88 xmax= fieldXY[0]/2./SSD;
89 ymax= fieldXY[1]/2./SSD;
90 } else {
91 xmax= ymax= DBL_MAX-1.;
92 }
93
94 G4double dcos{0.0};
95 G4double dsin{0.0};
96 G4double dphi{0.0};
97
98 while(! (std::abs(x)< xmax && std::abs(y)< ymax) ) {
99 dcos= RandFlat::shoot(cos0, 1.);
100 dsin= std::sqrt(1.-sqr(dcos));
101 dphi= RandFlat::shoot(0., twopi);
102
103 x= std::cos(dphi)*dsin*dcos;
104 y= std::sin(dphi)*dsin*dcos;
105 }
106
107 G4double z= dcos;
108
109 return G4ThreeVector(x,y,z);
110}
111
112
116{
117 if(particle==0) return;
118
119 // create a new vertex
120 G4PrimaryVertex* vertex= new G4PrimaryVertex(sourcePosition, 0.*ns);
121
122 // momentum
123 G4double mass= particle-> GetPDGMass();
124 G4double p= std::sqrt(sqr(mass+kineticE)-sqr(mass));
125 G4ThreeVector pmon= p*GenerateBeamDirection();
126 G4PrimaryParticle* primary= new G4PrimaryParticle(particle,
127 pmon.x(),
128 pmon.y(),
129 pmon.z());
130 // set primary to vertex
131 vertex-> SetPrimary(primary);
132
133 // set vertex to event
134 anEvent-> AddPrimaryVertex(vertex);
135}
136
static constexpr double m
Definition: G4SIunits.hh:109
static constexpr double twopi
Definition: G4SIunits.hh:56
static constexpr double MeV
Definition: G4SIunits.hh:200
static constexpr double cm
Definition: G4SIunits.hh:99
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:83
double z() const
double x() const
double y() const
G4double fieldXY[2]
Definition: MedicalBeam.hh:56
virtual void GeneratePrimaries(G4Event *anEvent)
Definition: MedicalBeam.cc:114
G4ThreeVector GenerateBeamDirection() const
Definition: MedicalBeam.cc:69
Definition: DoubConv.h:17
ThreeVector shoot(const G4int Ap, const G4int Af)
T sqr(const T &x)
Definition: templates.hh:128
#define DBL_MAX
Definition: templates.hh:62
#define ns
Definition: xmlparse.cc:614