Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
environments/g4py/site-modules/primaries/MedicalBeam/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 // $Id: MedicalBeam.cc 66892 2013-01-17 10:57:59Z gunter $
27 // ====================================================================
28 // MedicalBeam.cc
29 //
30 // 2005 Q
31 // ====================================================================
32 #include "MedicalBeam.hh"
33 #include "Randomize.hh"
34 #include "G4Event.hh"
35 #include "G4ParticleTable.hh"
36 #include "G4PrimaryVertex.hh"
37 
38 using namespace CLHEP;
39 
40 #include <cmath>
41 
42 // ====================================================================
43 //
44 // class description
45 //
46 // ====================================================================
47 
48 ///////////////////////////////////
50  : particle(0),
51  kineticE(1.*MeV),
52  sourcePosition(G4ThreeVector()),
53  SSD(1.*m),
54  fieldShape(MedicalBeam::SQUARE),
55  fieldR(10.*cm)
56 ///////////////////////////////////
57 {
58  fieldXY[0]= fieldXY[1]= 10.*cm;
59 }
60 
61 
62 ///////////////////////////
64 ///////////////////////////
65 {
66 }
67 
68 
69 ////////////////////////////////////////////////////////
71 ////////////////////////////////////////////////////////
72 {
73  // uniform distribution in a limitted solid angle
74  G4double dr;
75  if(fieldShape == MedicalBeam::SQUARE) {
76  dr= std::sqrt(sqr(fieldXY[0]/2.)+sqr(fieldXY[1]/2.));
77  } else {
78  dr= fieldR;
79  }
80 
81  G4double sin0= dr/SSD;
82  G4double cos0= std::sqrt(1.-sqr(sin0));
83 
84  G4double dcos, dsin, dphi, z;
85 
87  G4double y= DBL_MAX;
88 
89  G4double xmax, ymax;
90  if(fieldShape == MedicalBeam::SQUARE) {
91  xmax= fieldXY[0]/2./SSD;
92  ymax= fieldXY[1]/2./SSD;
93  } else {
94  xmax= ymax= DBL_MAX-1.;
95  }
96 
97  while(! (std::abs(x)< xmax && std::abs(y)< ymax) ) {
98  dcos= RandFlat::shoot(cos0, 1.);
99  dsin= std::sqrt(1.-sqr(dcos));
100  dphi= RandFlat::shoot(0., twopi);
101 
102  x= std::cos(dphi)*dsin*dcos;
103  y= std::sin(dphi)*dsin*dcos;
104  }
105  z= dcos;
106 
107  return G4ThreeVector(x,y,z);
108 }
109 
110 
111 /////////////////////////////////////////////////////
113 /////////////////////////////////////////////////////
114 {
115  if(particle==0) return;
116 
117  // create a new vertex
118  G4PrimaryVertex* vertex= new G4PrimaryVertex(sourcePosition, 0.*ns);
119 
120  // momentum
121  G4double mass= particle-> GetPDGMass();
122  G4double p= std::sqrt(sqr(mass+kineticE)-sqr(mass));
123  G4ThreeVector pmon= p*GenerateBeamDirection();
124  G4PrimaryParticle* primary= new G4PrimaryParticle(particle,
125  pmon.x(),
126  pmon.y(),
127  pmon.z());
128  // set primary to vertex
129  vertex-> SetPrimary(primary);
130 
131  // set vertex to event
132  anEvent-> AddPrimaryVertex(vertex);
133 }
134 
virtual void GeneratePrimaries(G4Event *anEvent)
ThreeVector shoot(const G4int Ap, const G4int Af)
CLHEP::Hep3Vector G4ThreeVector
double x() const
G4double z
Definition: TRTMaterials.hh:39
G4ThreeVector GenerateBeamDirection() const
const char * p
Definition: xmltok.h:285
double z() const
double y() const
T sqr(const T &x)
Definition: templates.hh:145
double G4double
Definition: G4Types.hh:76
#define DBL_MAX
Definition: templates.hh:83
#define ns
Definition: xmlparse.cc:597