File indexing completed on 2025-01-31 09:22:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "HadrontherapyPrimaryGeneratorAction.hh"
0030 #include "HadrontherapyPrimaryGeneratorMessenger.hh"
0031
0032 #include "HadrontherapyMatrix.hh"
0033 #include "HadrontherapyDetectorSD.hh"
0034 #include "G4SystemOfUnits.hh"
0035 #include "G4Event.hh"
0036 #include "G4ParticleGun.hh"
0037 #include "G4GeneralParticleSource.hh"
0038 #include "G4ParticleTable.hh"
0039 #include "G4ParticleDefinition.hh"
0040 #include "Randomize.hh"
0041 #include "G4IonTable.hh"
0042
0043
0044 #include "G4VUserPrimaryGeneratorAction.hh"
0045 #include "G4ParticleTable.hh"
0046
0047 #include "G4Event.hh"
0048 #include "G4Timer.hh"
0049
0050 #include "G4RunManager.hh"
0051
0052
0053
0054
0055 HadrontherapyPrimaryGeneratorAction::HadrontherapyPrimaryGeneratorAction() :
0056 fNewSource(false)
0057 {
0058 PrimaryGeneratorMessenger = new HadrontherapyPrimaryGeneratorMessenger(this);
0059 particleGun = new G4GeneralParticleSource();
0060 calculatedPhaseSpaceFileIN = "NULL";
0061 }
0062
0063
0064 HadrontherapyPrimaryGeneratorAction::~HadrontherapyPrimaryGeneratorAction()
0065 {
0066 delete PrimaryGeneratorMessenger;
0067 delete particleGun;
0068 }
0069
0070
0071 void HadrontherapyPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0072 {
0073 if(fNewSource==true)
0074 {
0075 std::ifstream in(calculatedPhaseSpaceFileIN);
0076 G4double e, xpos, ypos, zpos,dirx,diry,dirz;
0077 G4int PDG;
0078 G4ThreeVector pos,dir;
0079
0080 if(in.eof())
0081 {
0082 G4Exception("HadrontherapyPrimaryGeneratorAction", "NoParticles", FatalException, "No more particles in the file");
0083 }
0084
0085 while(!in.eof())
0086 {
0087
0088 in >> e >> xpos >> ypos >>zpos >>dirx>>diry>>dirz >> PDG;
0089 dir= G4ThreeVector(dirx,diry,dirz);
0090 particleGun->GetCurrentSource()->GetEneDist()->SetMonoEnergy(e);
0091
0092 particleGun->GetCurrentSource()->GetParticlePosition().setX(xpos);
0093 particleGun->GetCurrentSource()->GetParticlePosition().setY(ypos);
0094 particleGun->GetCurrentSource()->GetParticlePosition().setZ(zpos);
0095 particleGun->GetCurrentSource()->GetAngDist()->SetParticleMomentumDirection(dir);
0096
0097 G4ParticleDefinition* particleDef = nullptr;
0098 if (PDG > 1000000000)
0099 {
0100 int a=(PDG-1000000000)-(((PDG-1000000000)/10)*10);
0101 if(a>0)
0102 {
0103 PDG=PDG-a;
0104 particleDef = G4IonTable::GetIonTable()->GetIon(PDG);
0105 G4String Nome = particleDef->GetParticleName();
0106 }
0107
0108 else
0109 {
0110 particleDef = G4IonTable::GetIonTable()->GetIon(PDG);
0111 G4String Nome = particleDef->GetParticleName();
0112 }
0113 }
0114
0115 else
0116 {
0117 particleDef = G4ParticleTable::GetParticleTable()->FindParticle(PDG);
0118 }
0119
0120 particleGun->GetCurrentSource()->SetParticleDefinition(particleDef);
0121 particleGun->GeneratePrimaryVertex(anEvent);
0122
0123 }
0124
0125 in.close();
0126
0127 }
0128 else
0129 {
0130 particleGun->GeneratePrimaryVertex(anEvent);
0131 }
0132
0133 }
0134
0135