Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // << 27 /// \file medical/GammaTherapy/src/PrimaryGene 26 /// \file medical/GammaTherapy/src/PrimaryGeneratorAction.cc 28 /// \brief Implementation of the PrimaryGenera 27 /// \brief Implementation of the PrimaryGeneratorAction class 29 // 28 // 30 29 31 //-------------------------------------------- 30 //--------------------------------------------------------------------------- 32 // 31 // 33 // ClassName: PrimaryGeneratorAction 32 // ClassName: PrimaryGeneratorAction 34 // 33 // 35 // Description: Generate primary beam 34 // Description: Generate primary beam 36 // 35 // 37 // Authors: V.Grichine, V.Ivanchenko 36 // Authors: V.Grichine, V.Ivanchenko 38 // 37 // 39 // Modified: 38 // Modified: 40 // 39 // 41 //-------------------------------------------- 40 //---------------------------------------------------------------------------- 42 // 41 // 43 42 44 #include "PrimaryGeneratorAction.hh" 43 #include "PrimaryGeneratorAction.hh" 45 << 46 #include "DetectorConstruction.hh" 44 #include "DetectorConstruction.hh" 47 #include "PrimaryGeneratorMessenger.hh" 45 #include "PrimaryGeneratorMessenger.hh" 48 << 46 #include "Randomize.hh" 49 #include "G4ParticleDefinition.hh" << 50 #include "G4ParticleGun.hh" 47 #include "G4ParticleGun.hh" 51 #include "G4ParticleTable.hh" 48 #include "G4ParticleTable.hh" >> 49 #include "G4ParticleDefinition.hh" 52 #include "G4PhysicalConstants.hh" 50 #include "G4PhysicalConstants.hh" 53 #include "G4SystemOfUnits.hh" 51 #include "G4SystemOfUnits.hh" 54 #include "Randomize.hh" << 52 #include "Histo.hh" 55 53 56 //....oooOO0OOooo........oooOO0OOooo........oo 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 57 //....oooOO0OOooo........oooOO0OOooo........oo 55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 58 56 59 PrimaryGeneratorAction::PrimaryGeneratorAction << 57 PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction* pDet): >> 58 fDetector(pDet) 60 { 59 { 61 InitializeMe(); 60 InitializeMe(); 62 } 61 } 63 62 64 //....oooOO0OOooo........oooOO0OOooo........oo 63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 65 64 66 void PrimaryGeneratorAction::InitializeMe() 65 void PrimaryGeneratorAction::InitializeMe() 67 { 66 { 68 fVerbose = fDetector->GetVerbose(); << 69 fMessenger = new PrimaryGeneratorMessenger(t 67 fMessenger = new PrimaryGeneratorMessenger(this); 70 fParticleGun = new G4ParticleGun(); 68 fParticleGun = new G4ParticleGun(); 71 fCounter = 0; 69 fCounter = 0; >> 70 fVerbose = 0; 72 fX0 = 0.0; 71 fX0 = 0.0; 73 fY0 = 0.0; 72 fY0 = 0.0; 74 fZ0 = 0.0; 73 fZ0 = 0.0; 75 fSigmaX = 1.5 * mm; << 74 fSigmaX = 1.5*mm; 76 fSigmaY = 1.5 * mm; << 75 fSigmaY = 1.5*mm; 77 fSigmaZ = 0.0; 76 fSigmaZ = 0.0; 78 fSigmaE = 0.0; 77 fSigmaE = 0.0; 79 fRMax2 = 2.5 * 2.5 * mm * mm; << 78 fRMax2 = 2.5*2.5*mm*mm; 80 fSigmaTheta = 0.0; 79 fSigmaTheta = 0.0; 81 // fSigmaTheta = 0.17*degree; 80 // fSigmaTheta = 0.17*degree; 82 fMinCosTheta = 2.0; 81 fMinCosTheta = 2.0; 83 SetBeamEnergy(50.0 * MeV); << 82 SetBeamEnergy(50.0*MeV); 84 fPosition = G4ThreeVector(fX0, fY0, fZ0); << 83 fPosition = G4ThreeVector(fX0,fY0,fZ0); 85 fDirection = G4ThreeVector(0.0, 0.0, 1.0); << 84 fDirection = G4ThreeVector(0.0,0.0,1.0); 86 fGauss = true; 85 fGauss = true; >> 86 if(fEnergy < (Histo::GetPointer())->GetMaxEnergy()) { >> 87 (Histo::GetPointer())->SetMaxEnergy(fEnergy); >> 88 } 87 } 89 } 88 90 89 //....oooOO0OOooo........oooOO0OOooo........oo 91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 90 92 91 PrimaryGeneratorAction::~PrimaryGeneratorActio 93 PrimaryGeneratorAction::~PrimaryGeneratorAction() 92 { 94 { 93 delete fParticleGun; 95 delete fParticleGun; 94 delete fMessenger; 96 delete fMessenger; 95 } 97 } 96 98 97 //....oooOO0OOooo........oooOO0OOooo........oo 99 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 98 100 99 void PrimaryGeneratorAction::GeneratePrimaries 101 void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) 100 { 102 { 101 fCounter++; << 103 fCounter++ ; >> 104 fVerbose = (Histo::GetPointer())->GetVerbose(); 102 105 103 // Simulation of beam position 106 // Simulation of beam position 104 G4double x = fX0; 107 G4double x = fX0; 105 G4double y = fY0; 108 G4double y = fY0; 106 G4double z = fDetector->GetGeneratorPosZ(); 109 G4double z = fDetector->GetGeneratorPosZ(); 107 do { 110 do { 108 if (0.0 < fSigmaX) { << 111 if(0.0 < fSigmaX) { x = G4RandGauss::shoot(fX0,fSigmaX); } 109 x = G4RandGauss::shoot(fX0, fSigmaX); << 112 if(0.0 < fSigmaY) { y = G4RandGauss::shoot(fY0,fSigmaY); } 110 } << 113 } while (x*x + y*y > fRMax2); 111 if (0.0 < fSigmaY) { << 112 y = G4RandGauss::shoot(fY0, fSigmaY); << 113 } << 114 } while (x * x + y * y > fRMax2); << 115 114 116 fPosition = G4ThreeVector(x, y, z); << 115 fPosition = G4ThreeVector(x,y,z); 117 fParticleGun->SetParticlePosition(fPosition) 116 fParticleGun->SetParticlePosition(fPosition); 118 117 119 // Simulation of beam direction 118 // Simulation of beam direction 120 G4double ux = fDirection.x(); 119 G4double ux = fDirection.x(); 121 G4double uy = fDirection.y(); 120 G4double uy = fDirection.y(); 122 G4double uz = fDirection.z(); 121 G4double uz = fDirection.z(); 123 122 124 // Beam particles are uniformly distributed 123 // Beam particles are uniformly distributed over phi, cosTheta 125 if (1.0 > fMinCosTheta) { << 124 if(1.0 > fMinCosTheta) { 126 uz = fMinCosTheta + (1.0 - fMinCosTheta) * << 125 uz = fMinCosTheta + (1.0 - fMinCosTheta)*G4UniformRand() ; 127 ux = std::sqrt((1.0 - uz) * (1.0 + uz)); << 126 ux = std::sqrt((1.0 - uz)*(1.0 + uz)) ; 128 } << 127 } else if (fSigmaTheta > 0.0) { 129 else if (fSigmaTheta > 0.0) { << 128 ux = G4RandGauss::shoot(0.0,fSigmaTheta); 130 ux = G4RandGauss::shoot(0.0, fSigmaTheta); << 129 uz = std::sqrt((1.0 - ux)*(1.0 + ux)); 131 uz = std::sqrt((1.0 - ux) * (1.0 + ux)); << 132 } 130 } 133 131 134 G4double phi = twopi * G4UniformRand(); << 132 G4double phi = twopi*G4UniformRand() ; 135 uy = ux; 133 uy = ux; 136 ux *= std::cos(phi); << 134 ux *= std::cos(phi) ; 137 uy *= std::sin(phi); << 135 uy *= std::sin(phi) ; 138 fDirection = G4ThreeVector(ux, uy, uz); << 136 fDirection = G4ThreeVector(ux,uy,uz) ; 139 137 140 fParticleGun->SetParticleMomentumDirection(f 138 fParticleGun->SetParticleMomentumDirection(fDirection); 141 139 142 // Simulation of beam kinetic energy 140 // Simulation of beam kinetic energy 143 G4double kinEnergy = fEnergy; 141 G4double kinEnergy = fEnergy; 144 142 145 if (fGauss == "flatE") { << 143 if(fGauss == "flatE") { 146 kinEnergy = fEnergy - fSigmaE + 2. * fSigm << 144 kinEnergy = fEnergy - fSigmaE + 2.*fSigmaE*G4UniformRand(); 147 } << 145 } else if(0.0 < fSigmaE) { 148 else if (0.0 < fSigmaE) { << 146 kinEnergy = fEnergy + G4RandGauss::shoot(0.0,fSigmaE); 149 kinEnergy = fEnergy + G4RandGauss::shoot(0 << 150 } 147 } 151 fParticleGun->SetParticleEnergy(kinEnergy); 148 fParticleGun->SetParticleEnergy(kinEnergy); 152 149 153 if (fVerbose > 0) { << 150 if(fVerbose > 0) { 154 G4ParticleDefinition* particle = fParticle 151 G4ParticleDefinition* particle = fParticleGun->GetParticleDefinition(); 155 G4String particleName = particle->GetParti << 152 G4String particleName = particle->GetParticleName() ; 156 G4cout << "Event# " << fCounter << " Bea << 153 G4cout << "Event# " << fCounter >> 154 << " Beam particle is generated by PrimaryGeneratorAction " 157 << G4endl; 155 << G4endl; 158 G4cout << "ParticleName= " << particleName << 156 G4cout << "ParticleName= " << particleName 159 << std::setprecision(5) << " KinE << 157 << " PDGcode= " << particle->GetPDGEncoding() 160 << " x(mm)= " << x / mm << " y(mm << 158 << std::setprecision(5) 161 << " ux= " << ux << " uy= " << uy << 159 << " KinEnergy(GeV)= " 162 } << 160 << fEnergy/GeV >> 161 << " x(mm)= " >> 162 << x/mm >> 163 << " y(mm)= " >> 164 << y/mm >> 165 << " z(mm)= " >> 166 << z/mm >> 167 << " ux= " >> 168 << ux >> 169 << " uy= " >> 170 << uy >> 171 << " uz= " >> 172 << uz >> 173 << G4endl; >> 174 } 163 175 164 fParticleGun->GeneratePrimaryVertex(anEvent) 176 fParticleGun->GeneratePrimaryVertex(anEvent); 165 } 177 } 166 178 167 //....oooOO0OOooo........oooOO0OOooo........oo 179 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 168 180 169 void PrimaryGeneratorAction::SetBeamEnergy(G4d 181 void PrimaryGeneratorAction::SetBeamEnergy(G4double val) 170 { 182 { 171 fEnergy = val; 183 fEnergy = val; 172 if (fEnergy < fDetector->GetMaxEnergy()) fDe << 184 if(fEnergy < (Histo::GetPointer())->GetMaxEnergy()) { >> 185 (Histo::GetPointer())->SetMaxEnergy(fEnergy); >> 186 } 173 } 187 } 174 188 175 //....oooOO0OOooo........oooOO0OOooo........oo 189 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 190 >> 191 >> 192 176 193