Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 08:37:37

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 /// \file F06PrimaryGeneratorAction.cc
0027 /// \brief Implementation of the F06PrimaryGeneratorAction class
0028 
0029 #include "F06PrimaryGeneratorAction.hh"
0030 
0031 #include "F06DetectorConstruction.hh"
0032 
0033 #include "G4Event.hh"
0034 #include "G4ParticleDefinition.hh"
0035 #include "G4ParticleGun.hh"
0036 #include "G4ParticleTable.hh"
0037 #include "G4PhysicalConstants.hh"
0038 #include "G4SystemOfUnits.hh"
0039 #include "Randomize.hh"
0040 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 
0043 F06PrimaryGeneratorAction::F06PrimaryGeneratorAction()
0044 {
0045   G4int n_particle = 1;
0046   fParticleGun = new G4ParticleGun(n_particle);
0047 
0048   G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
0049 
0050   G4ParticleDefinition* particle = particleTable->FindParticle("proton");
0051   G4double mass_proton = particle->GetPDGMass();
0052 
0053   G4double muN = 0.5 * CLHEP::eplus * CLHEP::hbar_Planck / (mass_proton / CLHEP::c_squared);
0054 
0055   G4cout << " *** Neutron *** " << G4endl;
0056 
0057   particle = particleTable->FindParticle("neutron");
0058   G4double mass_neutron = particle->GetPDGMass();
0059 
0060   G4double magneticMoment = particle->GetPDGMagneticMoment();
0061   G4cout << " magneticMoment: " << magneticMoment / muN << G4endl;
0062 
0063   // g_factor for spin 1/2
0064 
0065   G4double g_factor = 2 * magneticMoment / muN;
0066   G4cout << " g_factor: " << g_factor << G4endl;
0067 
0068   G4double charge = particle->GetPDGCharge();
0069   G4cout << " charge: " << charge << G4endl;
0070 
0071   G4double anomaly = (g_factor - 2.) / 2.;
0072   G4cout << " anomaly: " << anomaly << G4endl;
0073 
0074   anomaly = (g_factor * (mass_neutron / mass_proton) - 2.) / 2.;
0075   G4cout << " corrected anomaly: " << anomaly << G4endl;
0076 
0077   muN = 0.5 * CLHEP::eplus * CLHEP::hbar_Planck / (mass_neutron / CLHEP::c_squared);
0078   g_factor = 2 * magneticMoment / muN;
0079 
0080   anomaly = (g_factor - 2.) / 2.;
0081   G4cout << " *** anomaly: " << anomaly << G4endl;
0082 
0083   G4cout << " *** MuonPlus *** " << G4endl;
0084 
0085   particle = particleTable->FindParticle("mu+");
0086   G4double mass_muon = particle->GetPDGMass();
0087 
0088   G4double muB = 0.5 * CLHEP::eplus * CLHEP::hbar_Planck / (mass_muon / CLHEP::c_squared);
0089 
0090   magneticMoment = particle->GetPDGMagneticMoment();
0091   G4cout << " magneticMoment: " << magneticMoment / muB << G4endl;
0092 
0093   // g_factor for spin 1/2
0094 
0095   g_factor = magneticMoment / muB;
0096   G4cout << " g_factor: " << g_factor << G4endl;
0097 
0098   charge = particle->GetPDGCharge();
0099   G4cout << " charge: " << charge << G4endl;
0100 
0101   anomaly = (g_factor - 2.) / 2.;
0102   G4cout << " anomaly: " << anomaly << G4endl;
0103 
0104   //  anomaly = particle->CalculateAnomaly();
0105   //  G4cout << " *** anomaly: " << anomaly << G4endl;
0106 
0107   particle = particleTable->FindParticle("neutron");
0108   fParticleGun->SetParticleDefinition(particle);
0109 }
0110 
0111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0112 
0113 F06PrimaryGeneratorAction::~F06PrimaryGeneratorAction()
0114 {
0115   delete fParticleGun;
0116 }
0117 
0118 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0119 
0120 void F06PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0121 {
0122   // this function is called at the begining of event
0123   //
0124 
0125   fParticleGun->SetParticlePosition(G4ThreeVector(0.0, 0.0, 0.0));
0126   fParticleGun->SetParticlePolarization(G4ThreeVector(0, 1, 0));
0127 
0128   G4double particleEnergy = G4UniformRand() * 1e-7 * eV;
0129   fParticleGun->SetParticleEnergy(particleEnergy);
0130 
0131   G4double theta = 2 * pi * G4UniformRand();
0132   G4double phi = std::acos(1 - 2 * G4UniformRand());
0133   if (phi > pi / 2 && phi < pi) phi = pi - phi;
0134 
0135   G4double z = std::sin(phi) * std::cos(theta);
0136   G4double x = std::sin(phi) * std::sin(theta);
0137   G4double y = std::cos(phi);
0138 
0139   fParticleGun->SetParticleMomentumDirection(G4ThreeVector(x, y, z));
0140 
0141   fParticleGun->GeneratePrimaryVertex(anEvent);
0142 }
0143 
0144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......