Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:19

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