Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 /// \file field/field01/src/F01PrimaryGenerato << 27 /// \brief Implementation of the F01PrimaryGen << 28 // 23 // >> 24 // $Id: F01PrimaryGeneratorAction.cc,v 1.7 2004/12/03 16:07:23 gcosmo Exp $ >> 25 // GEANT4 tag $Name: geant4-08-00-patch-01 $ 29 // 26 // 30 // << 27 // 31 // << 28 32 //....oooOO0OOooo........oooOO0OOooo........oo << 29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 33 //....oooOO0OOooo........oooOO0OOooo........oo << 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 34 31 35 #include "F01PrimaryGeneratorAction.hh" 32 #include "F01PrimaryGeneratorAction.hh" 36 33 37 #include "F01DetectorConstruction.hh" 34 #include "F01DetectorConstruction.hh" 38 #include "F01PrimaryGeneratorMessenger.hh" 35 #include "F01PrimaryGeneratorMessenger.hh" 39 36 40 #include "G4Event.hh" 37 #include "G4Event.hh" 41 #include "G4ParticleDefinition.hh" << 42 #include "G4ParticleGun.hh" 38 #include "G4ParticleGun.hh" 43 #include "G4ParticleTable.hh" 39 #include "G4ParticleTable.hh" 44 #include "G4PhysicalConstants.hh" << 40 #include "G4ParticleDefinition.hh" 45 #include "G4SystemOfUnits.hh" << 46 #include "Randomize.hh" 41 #include "Randomize.hh" >> 42 #include "G4ios.hh" 47 43 48 //....oooOO0OOooo........oooOO0OOooo........oo << 44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 49 << 45 50 G4ParticleDefinition* F01PrimaryGeneratorActio << 46 G4String F01PrimaryGeneratorAction::thePrimaryParticleName = "e-" ; 51 << 47 52 //....oooOO0OOooo........oooOO0OOooo........oo << 48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 53 << 49 54 F01PrimaryGeneratorAction::F01PrimaryGenerator << 50 F01PrimaryGeneratorAction::F01PrimaryGeneratorAction( >> 51 F01DetectorConstruction* F01DC) >> 52 : F01Detector(F01DC), rndmFlag("off"), >> 53 xvertex(0.), yvertex(0.), zvertex(0.), >> 54 vertexdefined(false) 55 { 55 { 56 G4int n_particle = 1; 56 G4int n_particle = 1; 57 fParticleGun = new G4ParticleGun(n_particle) << 57 particleGun = new G4ParticleGun(n_particle); 58 << 58 59 // create a messenger for this class 59 // create a messenger for this class 60 fGunMessenger = new F01PrimaryGeneratorMesse << 60 gunMessenger = new F01PrimaryGeneratorMessenger(this); 61 61 62 // default particle kinematic 62 // default particle kinematic 63 63 64 G4ParticleTable* particleTable = G4ParticleT 64 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); 65 G4String particleName; 65 G4String particleName; 66 G4ParticleDefinition* particle = particleTab << 66 G4ParticleDefinition* particle 67 fParticleGun->SetParticleDefinition(particle << 67 = particleTable->FindParticle(particleName="e-"); >> 68 particleGun->SetParticleDefinition(particle); >> 69 >> 70 thePrimaryParticleName = particle->GetParticleName() ; 68 71 69 fgPrimaryParticle = particle; << 72 particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,-1.)); >> 73 particleGun->SetParticleEnergy(0.5*GeV); 70 74 71 fParticleGun->SetParticleMomentumDirection(G << 75 zvertex = F01Detector->GetAbsorberZpos() -0.5*(F01Detector->GetAbsorberThickness()); 72 fParticleGun->SetParticleEnergy(0.5 * GeV); << 76 particleGun->SetParticlePosition(G4ThreeVector(xvertex,yvertex,zvertex)); 73 77 74 fZVertex = fDetector->GetAbsorberZpos() - 0. << 75 fParticleGun->SetParticlePosition(G4ThreeVec << 76 } 78 } 77 79 78 //....oooOO0OOooo........oooOO0OOooo........oo << 80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 79 81 80 F01PrimaryGeneratorAction::~F01PrimaryGenerato 82 F01PrimaryGeneratorAction::~F01PrimaryGeneratorAction() 81 { 83 { 82 delete fParticleGun; << 84 delete particleGun; 83 delete fGunMessenger; << 85 delete gunMessenger; 84 } 86 } 85 87 86 //....oooOO0OOooo........oooOO0OOooo........oo << 88 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 87 89 88 void F01PrimaryGeneratorAction::GeneratePrimar 90 void F01PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) 89 { 91 { 90 // this function is called at the begining o 92 // this function is called at the begining of event 91 // << 93 // 92 fgPrimaryParticle = fParticleGun->GetParticl << 94 thePrimaryParticleName = particleGun->GetParticleDefinition()-> 93 << 95 GetParticleName() ; 94 G4double x0, y0, z0; << 96 G4double x0,y0,z0 ; 95 if (fVertexDefined) { << 97 if(vertexdefined) 96 x0 = fXVertex; << 98 { 97 y0 = fYVertex; << 99 x0 = xvertex ; 98 z0 = fZVertex; << 100 y0 = yvertex ; >> 101 z0 = zvertex ; 99 } 102 } 100 else { << 103 else 101 x0 = 0.; << 104 { 102 y0 = 0.; << 105 x0 = 0. ; 103 z0 = fDetector->GetAbsorberZpos() - 0.5 * << 106 y0 = 0. ; >> 107 z0 = F01Detector->GetAbsorberZpos()-0.5*(F01Detector->GetAbsorberThickness()); 104 } 108 } >> 109 G4double r0,phi0 ; 105 110 106 G4double r0, phi0; << 111 if (rndmFlag == "on") 107 if (fRndmFlag == "on") { << 112 { 108 r0 = (fDetector->GetAbsorberRadius()) * st << 113 r0 = (F01Detector->GetAbsorberRadius())*std::sqrt(G4UniformRand()); 109 phi0 = twopi * G4UniformRand(); << 114 phi0 = twopi*G4UniformRand(); 110 x0 = r0 * std::cos(phi0); << 115 x0 = r0*std::cos(phi0); 111 y0 = r0 * std::sin(phi0); << 116 y0 = r0*std::sin(phi0); 112 } << 117 } 113 118 114 fParticleGun->SetParticlePosition(G4ThreeVec << 119 particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0)); 115 fParticleGun->GeneratePrimaryVertex(anEvent) << 120 particleGun->GeneratePrimaryVertex(anEvent); 116 } 121 } 117 122 118 //....oooOO0OOooo........oooOO0OOooo........oo << 123 /////////////////////////////////////////////////////////////////////// >> 124 // >> 125 // 119 126 120 G4String F01PrimaryGeneratorAction::GetPrimary 127 G4String F01PrimaryGeneratorAction::GetPrimaryName() 121 { 128 { 122 return fgPrimaryParticle->GetParticleName(); << 129 return thePrimaryParticleName ; 123 } 130 } 124 131 125 //....oooOO0OOooo........oooOO0OOooo........oo << 132 void F01PrimaryGeneratorAction::Setzvertex(G4double z) 126 << 127 void F01PrimaryGeneratorAction::SetZVertex(G4d << 128 { 133 { 129 fVertexDefined = true; << 134 vertexdefined = true ; 130 fZVertex = z; << 135 zvertex = z ; 131 G4cout << " Z coordinate of the primary vert << 136 G4cout << " Z coordinate of the primary vertex = " << zvertex/mm << >> 137 " mm." << G4endl; 132 } 138 } 133 << 139 void F01PrimaryGeneratorAction::Setxvertex(G4double x) 134 //....oooOO0OOooo........oooOO0OOooo........oo << 135 << 136 void F01PrimaryGeneratorAction::SetXVertex(G4d << 137 { 140 { 138 fVertexDefined = true; << 141 vertexdefined = true ; 139 fXVertex = x; << 142 xvertex = x ; 140 G4cout << " X coordinate of the primary vert << 143 G4cout << " X coordinate of the primary vertex = " << xvertex/mm << >> 144 " mm." << G4endl; 141 } 145 } 142 146 143 //....oooOO0OOooo........oooOO0OOooo........oo << 147 void F01PrimaryGeneratorAction::Setyvertex(G4double y) 144 << 145 void F01PrimaryGeneratorAction::SetYVertex(G4d << 146 { 148 { 147 fVertexDefined = true; << 149 vertexdefined = true ; 148 fYVertex = y; << 150 yvertex = y ; 149 G4cout << " Y coordinate of the primary vert << 151 G4cout << " Y coordinate of the primary vertex = " << yvertex/mm << >> 152 " mm." << G4endl; 150 } 153 } 151 154 152 //....oooOO0OOooo........oooOO0OOooo........oo << 155 >> 156 >> 157 >> 158 >> 159 >> 160 >> 161 >> 162 >> 163 >> 164 153 165