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 // ******************************************************************** >> 22 // $Id: HadrontherapyPositronPrimaryGeneratorAction.cc; May 2005 >> 23 // ---------------------------------------------------------------------------- >> 24 // GEANT 4 - Hadrontherapy example >> 25 // ---------------------------------------------------------------------------- >> 26 // Code developed by: 25 // 27 // 26 // Hadrontherapy advanced example for Geant4 << 28 // G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a) 27 // See more at: https://twiki.cern.ch/twiki/bi << 29 // 28 << 30 // (a) Laboratori Nazionali del Sud >> 31 // of the National Institute for Nuclear Physics, Catania, Italy >> 32 // (b) National Institute for Nuclear Physics Section of Genova, genova, Italy >> 33 // >> 34 // * cirrone@lns.infn.it >> 35 // ---------------------------------------------------------------------------- 29 #include "HadrontherapyPrimaryGeneratorAction. 36 #include "HadrontherapyPrimaryGeneratorAction.hh" >> 37 #include "HadrontherapyDetectorConstruction.hh" 30 #include "HadrontherapyPrimaryGeneratorMesseng 38 #include "HadrontherapyPrimaryGeneratorMessenger.hh" 31 << 32 #include "HadrontherapyMatrix.hh" << 33 #include "HadrontherapyDetectorSD.hh" << 34 #include "G4SystemOfUnits.hh" << 35 #include "G4Event.hh" 39 #include "G4Event.hh" 36 #include "G4ParticleGun.hh" 40 #include "G4ParticleGun.hh" 37 #include "G4GeneralParticleSource.hh" << 38 #include "G4ParticleTable.hh" 41 #include "G4ParticleTable.hh" 39 #include "G4ParticleDefinition.hh" 42 #include "G4ParticleDefinition.hh" 40 #include "Randomize.hh" 43 #include "Randomize.hh" 41 #include "G4IonTable.hh" << 42 << 43 << 44 #include "G4VUserPrimaryGeneratorAction.hh" << 45 #include "G4ParticleTable.hh" << 46 << 47 #include "G4Event.hh" << 48 #include "G4Timer.hh" << 49 << 50 #include "G4RunManager.hh" << 51 44 52 << 45 HadrontherapyPrimaryGeneratorAction::HadrontherapyPrimaryGeneratorAction() 53 << 54 ////////////////////////////////////////////// << 55 HadrontherapyPrimaryGeneratorAction::Hadronthe << 56 fNewSource(false) << 57 { 46 { 58 PrimaryGeneratorMessenger = new Hadronther << 47 gunMessenger = new HadrontherapyPrimaryGeneratorMessenger(this); 59 particleGun = new G4GeneralParticleSource( << 48 particleGun = new G4ParticleGun(); 60 calculatedPhaseSpaceFileIN = "NULL"; << 49 SetDefaultPrimaryParticle(); 61 } << 50 } 62 51 63 ////////////////////////////////////////////// << 64 HadrontherapyPrimaryGeneratorAction::~Hadronth 52 HadrontherapyPrimaryGeneratorAction::~HadrontherapyPrimaryGeneratorAction() 65 { 53 { 66 delete PrimaryGeneratorMessenger; << 54 delete particleGun; 67 delete particleGun; << 55 delete gunMessenger; >> 56 } >> 57 >> 58 void HadrontherapyPrimaryGeneratorAction::SetDefaultPrimaryParticle() >> 59 { >> 60 // **************************** >> 61 // Default primary particle >> 62 // **************************** >> 63 >> 64 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); >> 65 G4ParticleDefinition* particle = particleTable->FindParticle("proton"); >> 66 particleGun->SetParticleDefinition(particle); >> 67 particleGun->SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.)); >> 68 >> 69 G4double defaultMeanKineticEnergy = 63.450 *MeV; >> 70 meanKineticEnergy = defaultMeanKineticEnergy; >> 71 >> 72 G4double defaultsigmaEnergy = 400.0 *keV; >> 73 sigmaEnergy = defaultsigmaEnergy; >> 74 >> 75 G4double defaultX0 = -3248.59 *mm; >> 76 X0 = defaultX0; >> 77 >> 78 G4double defaultY0 = 0.0 *mm; >> 79 Y0 = defaultY0; >> 80 >> 81 G4double defaultZ0 = 0.0 *mm; >> 82 Z0 = defaultZ0; >> 83 >> 84 G4double defaultsigmaY = 1 *mm; >> 85 sigmaY = defaultsigmaY; >> 86 >> 87 G4double defaultsigmaZ = 1 *mm; >> 88 sigmaZ = defaultsigmaZ; >> 89 >> 90 G4double defaultsigmaMomentumY = 0.0001; >> 91 sigmaMomentumY = defaultsigmaMomentumY; >> 92 >> 93 G4double defaultsigmaMomentumZ = 0.0001; >> 94 sigmaMomentumZ = defaultsigmaMomentumZ; 68 } 95 } 69 96 70 ////////////////////////////////////////////// << 71 void HadrontherapyPrimaryGeneratorAction::Gene 97 void HadrontherapyPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) 72 { 98 { 73 if(fNewSource==true) << 99 // **************************************** >> 100 // Set the beam angular apread >> 101 // and spot size >> 102 // beam spot size >> 103 // **************************************** >> 104 >> 105 // Set the position of the primary particles >> 106 G4double x = X0; >> 107 G4double y = Y0; >> 108 G4double z = Z0; >> 109 >> 110 if ( sigmaY > 0.0 ) 74 { 111 { 75 std::ifstream in(calculatedPhaseSpaceFil << 112 y += G4RandGauss::shoot( Y0, sigmaY ); 76 G4double e, xpos, ypos, zpos,dirx,diry,d << 77 G4int PDG; << 78 G4ThreeVector pos,dir; << 79 << 80 if(in.eof()) << 81 { << 82 G4Exception("HadrontherapyPrimaryGenerator << 83 } << 84 << 85 while(!in.eof()) << 86 { << 87 << 88 in >> e >> xpos >> ypos >>zpos >>dirx>>dir << 89 dir= G4ThreeVector(dirx,diry,dirz); << 90 particleGun->GetCurrentSource()->GetEneDis << 91 << 92 particleGun->GetCurrentSource()->GetPartic << 93 particleGun->GetCurrentSource()->GetPartic << 94 particleGun->GetCurrentSource()->GetPartic << 95 particleGun->GetCurrentSource()->GetAngDis << 96 << 97 G4ParticleDefinition* particleDef = nullpt << 98 if (PDG > 1000000000) << 99 { << 100 int a=(PDG-1000000000)-(((PDG-10000000 << 101 if(a>0) << 102 { << 103 PDG=PDG-a; << 104 particleDef = G4IonTable::GetIonTable()- << 105 G4String Nome = particleDef->GetParticle << 106 } << 107 << 108 else << 109 { << 110 particleDef = G4IonTable::GetIonTable()- << 111 G4String Nome = particleDef->GetParticle << 112 } << 113 } << 114 << 115 else << 116 { << 117 particleDef = G4ParticleTable::GetPart << 118 } << 119 << 120 particleGun->GetCurrentSource()->SetPartic << 121 particleGun->GeneratePrimaryVertex(anEvent << 122 << 123 } << 124 << 125 in.close(); << 126 << 127 } 113 } 128 else << 114 >> 115 if ( sigmaZ > 0.0 ) 129 { 116 { 130 particleGun->GeneratePrimaryVertex(anE << 117 z += G4RandGauss::shoot( Z0, sigmaZ ); 131 } 118 } 132 << 133 } << 134 119 >> 120 particleGun -> SetParticlePosition(G4ThreeVector( x , y , z ) ); >> 121 >> 122 // ******************************************** >> 123 // Set the beam energy and energy spread >> 124 // ******************************************** >> 125 >> 126 G4double kineticEnergy = G4RandGauss::shoot( meanKineticEnergy, sigmaEnergy ); >> 127 particleGun -> SetParticleEnergy ( kineticEnergy ); >> 128 >> 129 // Set the direction of the primary particles >> 130 G4double momentumY = 0.0; >> 131 G4double momentumZ = 0.0; >> 132 >> 133 if ( sigmaMomentumY > 0.0 ) >> 134 { >> 135 momentumY += G4RandGauss::shoot( 0., sigmaMomentumY ); >> 136 } >> 137 if ( sigmaMomentumZ > 0.0 ) >> 138 { >> 139 momentumZ += G4RandGauss::shoot( 0., sigmaMomentumZ ); >> 140 } >> 141 >> 142 particleGun->SetParticleMomentumDirection(G4ThreeVector(1,momentumY,momentumZ)); >> 143 // Generate a primary particle >> 144 particleGun -> GeneratePrimaryVertex( anEvent ); >> 145 } >> 146 >> 147 >> 148 void HadrontherapyPrimaryGeneratorAction::SetmeanKineticEnergy (G4double val ) >> 149 { meanKineticEnergy = val;} >> 150 >> 151 void HadrontherapyPrimaryGeneratorAction::SetsigmaEnergy (G4double val ) >> 152 { sigmaEnergy = val;} >> 153 >> 154 void HadrontherapyPrimaryGeneratorAction::SetXposition (G4double val ) >> 155 { X0 = val;} >> 156 >> 157 void HadrontherapyPrimaryGeneratorAction::SetYposition (G4double val ) >> 158 { Y0 = val;} >> 159 >> 160 void HadrontherapyPrimaryGeneratorAction::SetZposition (G4double val ) >> 161 { Z0 = val;} >> 162 >> 163 void HadrontherapyPrimaryGeneratorAction::SetsigmaY (G4double val ) >> 164 { sigmaY = val;} >> 165 >> 166 void HadrontherapyPrimaryGeneratorAction::SetsigmaZ (G4double val ) >> 167 { sigmaZ = val;} >> 168 >> 169 void HadrontherapyPrimaryGeneratorAction::SetsigmaMomentumY (G4double val ) >> 170 { sigmaMomentumY = val;} 135 171 >> 172 void HadrontherapyPrimaryGeneratorAction::SetsigmaMomentumZ (G4double val ) >> 173 { sigmaMomentumZ = val;} 136 174