| 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: F01PrimaryGeneratorAction.cc,v 1.8 2006/06/29 17:16:43 gunter Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-04-beta-01 $
|
|---|
| 29 | //
|
|---|
| 30 | //
|
|---|
| 31 |
|
|---|
| 32 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 33 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 34 |
|
|---|
| 35 | #include "F01PrimaryGeneratorAction.hh"
|
|---|
| 36 |
|
|---|
| 37 | #include "F01DetectorConstruction.hh"
|
|---|
| 38 | #include "F01PrimaryGeneratorMessenger.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 F01PrimaryGeneratorAction::thePrimaryParticleName = "e-" ;
|
|---|
| 50 |
|
|---|
| 51 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 52 |
|
|---|
| 53 | F01PrimaryGeneratorAction::F01PrimaryGeneratorAction(
|
|---|
| 54 | F01DetectorConstruction* F01DC)
|
|---|
| 55 | : F01Detector(F01DC), 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 | gunMessenger = new F01PrimaryGeneratorMessenger(this);
|
|---|
| 64 |
|
|---|
| 65 | // default particle kinematic
|
|---|
| 66 |
|
|---|
| 67 | G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
|
|---|
| 68 | G4String particleName;
|
|---|
| 69 | G4ParticleDefinition* particle
|
|---|
| 70 | = particleTable->FindParticle(particleName="e-");
|
|---|
| 71 | particleGun->SetParticleDefinition(particle);
|
|---|
| 72 |
|
|---|
| 73 | thePrimaryParticleName = particle->GetParticleName() ;
|
|---|
| 74 |
|
|---|
| 75 | particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,-1.));
|
|---|
| 76 | particleGun->SetParticleEnergy(0.5*GeV);
|
|---|
| 77 |
|
|---|
| 78 | zvertex = F01Detector->GetAbsorberZpos() -0.5*(F01Detector->GetAbsorberThickness());
|
|---|
| 79 | particleGun->SetParticlePosition(G4ThreeVector(xvertex,yvertex,zvertex));
|
|---|
| 80 |
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 84 |
|
|---|
| 85 | F01PrimaryGeneratorAction::~F01PrimaryGeneratorAction()
|
|---|
| 86 | {
|
|---|
| 87 | delete particleGun;
|
|---|
| 88 | delete gunMessenger;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 92 |
|
|---|
| 93 | void F01PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
|
|---|
| 94 | {
|
|---|
| 95 | // this function is called at the begining of event
|
|---|
| 96 | //
|
|---|
| 97 | thePrimaryParticleName = particleGun->GetParticleDefinition()->
|
|---|
| 98 | GetParticleName() ;
|
|---|
| 99 | G4double x0,y0,z0 ;
|
|---|
| 100 | if(vertexdefined)
|
|---|
| 101 | {
|
|---|
| 102 | x0 = xvertex ;
|
|---|
| 103 | y0 = yvertex ;
|
|---|
| 104 | z0 = zvertex ;
|
|---|
| 105 | }
|
|---|
| 106 | else
|
|---|
| 107 | {
|
|---|
| 108 | x0 = 0. ;
|
|---|
| 109 | y0 = 0. ;
|
|---|
| 110 | z0 = F01Detector->GetAbsorberZpos()-0.5*(F01Detector->GetAbsorberThickness());
|
|---|
| 111 | }
|
|---|
| 112 | G4double r0,phi0 ;
|
|---|
| 113 |
|
|---|
| 114 | if (rndmFlag == "on")
|
|---|
| 115 | {
|
|---|
| 116 | r0 = (F01Detector->GetAbsorberRadius())*std::sqrt(G4UniformRand());
|
|---|
| 117 | phi0 = twopi*G4UniformRand();
|
|---|
| 118 | x0 = r0*std::cos(phi0);
|
|---|
| 119 | y0 = r0*std::sin(phi0);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
|
|---|
| 123 | particleGun->GeneratePrimaryVertex(anEvent);
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | ///////////////////////////////////////////////////////////////////////
|
|---|
| 127 | //
|
|---|
| 128 | //
|
|---|
| 129 |
|
|---|
| 130 | G4String F01PrimaryGeneratorAction::GetPrimaryName()
|
|---|
| 131 | {
|
|---|
| 132 | return thePrimaryParticleName ;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | void F01PrimaryGeneratorAction::Setzvertex(G4double z)
|
|---|
| 136 | {
|
|---|
| 137 | vertexdefined = true ;
|
|---|
| 138 | zvertex = z ;
|
|---|
| 139 | G4cout << " Z coordinate of the primary vertex = " << zvertex/mm <<
|
|---|
| 140 | " mm." << G4endl;
|
|---|
| 141 | }
|
|---|
| 142 | void F01PrimaryGeneratorAction::Setxvertex(G4double x)
|
|---|
| 143 | {
|
|---|
| 144 | vertexdefined = true ;
|
|---|
| 145 | xvertex = x ;
|
|---|
| 146 | G4cout << " X coordinate of the primary vertex = " << xvertex/mm <<
|
|---|
| 147 | " mm." << G4endl;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | void F01PrimaryGeneratorAction::Setyvertex(G4double y)
|
|---|
| 151 | {
|
|---|
| 152 | vertexdefined = true ;
|
|---|
| 153 | yvertex = y ;
|
|---|
| 154 | G4cout << " Y coordinate of the primary vertex = " << yvertex/mm <<
|
|---|
| 155 | " mm." << G4endl;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|