Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:22:18

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // Hadrontherapy advanced example for Geant4
0027 // See more at: https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy
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