[807] | 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 | // |
---|
[1230] | 26 | // HadrontherapyPrimarygeneratorAction.cc; |
---|
| 27 | // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy |
---|
[807] | 28 | // ---------------------------------------------------------------------------- |
---|
| 29 | // GEANT 4 - Hadrontherapy example |
---|
| 30 | // ---------------------------------------------------------------------------- |
---|
| 31 | // Code developed by: |
---|
| 32 | // |
---|
[1230] | 33 | // G.A.P. Cirrone(a)*, F.Romano(a) |
---|
[807] | 34 | // |
---|
| 35 | // (a) Laboratori Nazionali del Sud |
---|
[1230] | 36 | // of the INFN, Catania, Italy |
---|
[807] | 37 | // |
---|
| 38 | // * cirrone@lns.infn.it |
---|
[1230] | 39 | // |
---|
| 40 | // ------------------------------------------------------------------------------ |
---|
| 41 | |
---|
[807] | 42 | #include "HadrontherapyPrimaryGeneratorAction.hh" |
---|
| 43 | #include "HadrontherapyPrimaryGeneratorMessenger.hh" |
---|
| 44 | #include "G4Event.hh" |
---|
| 45 | #include "G4ParticleGun.hh" |
---|
| 46 | #include "G4ParticleTable.hh" |
---|
| 47 | #include "G4ParticleDefinition.hh" |
---|
| 48 | #include "Randomize.hh" |
---|
[1230] | 49 | #include "HadrontherapyAnalysisManager.hh" |
---|
[807] | 50 | |
---|
| 51 | HadrontherapyPrimaryGeneratorAction::HadrontherapyPrimaryGeneratorAction() |
---|
| 52 | { |
---|
| 53 | // Define the messenger |
---|
| 54 | gunMessenger = new HadrontherapyPrimaryGeneratorMessenger(this); |
---|
| 55 | |
---|
| 56 | particleGun = new G4ParticleGun(); |
---|
| 57 | |
---|
| 58 | SetDefaultPrimaryParticle(); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | HadrontherapyPrimaryGeneratorAction::~HadrontherapyPrimaryGeneratorAction() |
---|
| 62 | { |
---|
| 63 | delete particleGun; |
---|
| 64 | |
---|
| 65 | delete gunMessenger; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | void HadrontherapyPrimaryGeneratorAction::SetDefaultPrimaryParticle() |
---|
| 69 | { |
---|
| 70 | // **************************** |
---|
| 71 | // Default primary particle |
---|
| 72 | // **************************** |
---|
| 73 | |
---|
| 74 | // Define primary particles: protons |
---|
| 75 | G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); |
---|
| 76 | G4ParticleDefinition* particle = particleTable -> FindParticle("proton"); |
---|
| 77 | particleGun -> SetParticleDefinition(particle); |
---|
| 78 | |
---|
| 79 | // Define the energy of primary particles: |
---|
[1230] | 80 | // gaussian distribution with mean energy = 62.0 *MeV |
---|
| 81 | // and sigma = 400.0 *keV |
---|
| 82 | G4double defaultMeanKineticEnergy = 62.0 *MeV; |
---|
[807] | 83 | meanKineticEnergy = defaultMeanKineticEnergy; |
---|
| 84 | |
---|
[1230] | 85 | G4double defaultsigmaEnergy = 400.0 *keV; |
---|
[807] | 86 | sigmaEnergy = defaultsigmaEnergy; |
---|
[1230] | 87 | |
---|
[1313] | 88 | #ifdef G4ANALYSIS_USE_ROOT |
---|
[1230] | 89 | // Write these values into the analysis if needed. Have to be written separately on change. |
---|
[1313] | 90 | HadrontherapyAnalysisManager::GetInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy); |
---|
[1230] | 91 | #endif |
---|
[807] | 92 | |
---|
| 93 | // Define the parameters of the initial position: |
---|
| 94 | // the y, z coordinates have a gaussian distribution |
---|
[1230] | 95 | |
---|
| 96 | G4double defaultX0 = -2700.0 *mm; |
---|
[807] | 97 | X0 = defaultX0; |
---|
| 98 | |
---|
| 99 | G4double defaultY0 = 0.0 *mm; |
---|
| 100 | Y0 = defaultY0; |
---|
| 101 | |
---|
| 102 | G4double defaultZ0 = 0.0 *mm; |
---|
| 103 | Z0 = defaultZ0; |
---|
| 104 | |
---|
| 105 | G4double defaultsigmaY = 1. *mm; |
---|
| 106 | sigmaY = defaultsigmaY; |
---|
| 107 | |
---|
| 108 | G4double defaultsigmaZ = 1. *mm; |
---|
| 109 | sigmaZ = defaultsigmaZ; |
---|
| 110 | |
---|
| 111 | // Define the parameters of the momentum of primary particles: |
---|
| 112 | // The momentum along the y and z axis has a gaussian distribution |
---|
| 113 | G4double defaultsigmaMomentumY = 0.0; |
---|
| 114 | sigmaMomentumY = defaultsigmaMomentumY; |
---|
| 115 | |
---|
| 116 | G4double defaultsigmaMomentumZ = 0.0; |
---|
| 117 | sigmaMomentumZ = defaultsigmaMomentumZ; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | void HadrontherapyPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) |
---|
| 121 | { |
---|
[1313] | 122 | #ifdef G4ANALYSIS_USE_ROOT |
---|
[1230] | 123 | // Increment the event counter |
---|
[1313] | 124 | HadrontherapyAnalysisManager::GetInstance()->startNewEvent(); |
---|
[1230] | 125 | #endif |
---|
| 126 | |
---|
[807] | 127 | // **************************************** |
---|
| 128 | // Set the beam angular apread |
---|
| 129 | // and spot size |
---|
| 130 | // beam spot size |
---|
| 131 | // **************************************** |
---|
| 132 | |
---|
| 133 | // Set the position of the primary particles |
---|
| 134 | G4double x = X0; |
---|
| 135 | G4double y = Y0; |
---|
| 136 | G4double z = Z0; |
---|
| 137 | |
---|
| 138 | if ( sigmaY > 0.0 ) |
---|
| 139 | { |
---|
| 140 | y += G4RandGauss::shoot( Y0, sigmaY ); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | if ( sigmaZ > 0.0 ) |
---|
| 144 | { |
---|
| 145 | z += G4RandGauss::shoot( Z0, sigmaZ ); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | particleGun -> SetParticlePosition(G4ThreeVector( x , y , z ) ); |
---|
| 149 | |
---|
| 150 | // ******************************************** |
---|
| 151 | // Set the beam energy and energy spread |
---|
| 152 | // ******************************************** |
---|
| 153 | |
---|
| 154 | G4double kineticEnergy = G4RandGauss::shoot( meanKineticEnergy, sigmaEnergy ); |
---|
| 155 | particleGun -> SetParticleEnergy ( kineticEnergy ); |
---|
| 156 | |
---|
| 157 | // Set the direction of the primary particles |
---|
| 158 | G4double momentumX = 1.0; |
---|
| 159 | G4double momentumY = 0.0; |
---|
| 160 | G4double momentumZ = 0.0; |
---|
| 161 | |
---|
| 162 | if ( sigmaMomentumY > 0.0 ) |
---|
| 163 | { |
---|
| 164 | momentumY += G4RandGauss::shoot( 0., sigmaMomentumY ); |
---|
| 165 | } |
---|
| 166 | if ( sigmaMomentumZ > 0.0 ) |
---|
| 167 | { |
---|
| 168 | momentumZ += G4RandGauss::shoot( 0., sigmaMomentumZ ); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | particleGun -> SetParticleMomentumDirection( G4ThreeVector(momentumX,momentumY,momentumZ) ); |
---|
| 172 | |
---|
| 173 | // Generate a primary particle |
---|
| 174 | particleGun -> GeneratePrimaryVertex( anEvent ); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | void HadrontherapyPrimaryGeneratorAction::SetmeanKineticEnergy (G4double val ) |
---|
[1230] | 178 | { |
---|
| 179 | meanKineticEnergy = val; |
---|
[1313] | 180 | #ifdef G4ANALYSIS_USE_ROOT |
---|
[1230] | 181 | // Update the beam-data in the analysis manager |
---|
[1313] | 182 | HadrontherapyAnalysisManager::GetInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy); |
---|
[1230] | 183 | #endif |
---|
[807] | 184 | |
---|
[1230] | 185 | } |
---|
| 186 | |
---|
[807] | 187 | void HadrontherapyPrimaryGeneratorAction::SetsigmaEnergy (G4double val ) |
---|
[1230] | 188 | { |
---|
| 189 | sigmaEnergy = val; |
---|
[1313] | 190 | #ifdef G4ANALYSIS_USE_ROOT |
---|
[1230] | 191 | // Update the sigmaenergy in the metadata. |
---|
[1313] | 192 | HadrontherapyAnalysisManager::GetInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy); |
---|
[1230] | 193 | #endif |
---|
| 194 | } |
---|
[807] | 195 | |
---|
| 196 | void HadrontherapyPrimaryGeneratorAction::SetXposition (G4double val ) |
---|
| 197 | { X0 = val;} |
---|
| 198 | |
---|
| 199 | void HadrontherapyPrimaryGeneratorAction::SetYposition (G4double val ) |
---|
| 200 | { Y0 = val;} |
---|
| 201 | |
---|
| 202 | void HadrontherapyPrimaryGeneratorAction::SetZposition (G4double val ) |
---|
| 203 | { Z0 = val;} |
---|
| 204 | |
---|
| 205 | void HadrontherapyPrimaryGeneratorAction::SetsigmaY (G4double val ) |
---|
| 206 | { sigmaY = val;} |
---|
| 207 | |
---|
| 208 | void HadrontherapyPrimaryGeneratorAction::SetsigmaZ (G4double val ) |
---|
| 209 | { sigmaZ = val;} |
---|
| 210 | |
---|
| 211 | void HadrontherapyPrimaryGeneratorAction::SetsigmaMomentumY (G4double val ) |
---|
| 212 | { sigmaMomentumY = val;} |
---|
| 213 | |
---|
| 214 | void HadrontherapyPrimaryGeneratorAction::SetsigmaMomentumZ (G4double val ) |
---|
| 215 | { sigmaMomentumZ = val;} |
---|
[1230] | 216 | |
---|
| 217 | G4double HadrontherapyPrimaryGeneratorAction::GetmeanKineticEnergy(void) |
---|
| 218 | { return meanKineticEnergy;} |
---|
[1313] | 219 | |
---|