ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
F06PrimaryGeneratorAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file F06PrimaryGeneratorAction.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
29 //
30 
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
35 
37 
38 #include "G4Event.hh"
39 #include "G4ParticleGun.hh"
40 #include "G4ParticleTable.hh"
41 #include "G4ParticleDefinition.hh"
42 #include "Randomize.hh"
43 #include "G4PhysicalConstants.hh"
44 #include "G4SystemOfUnits.hh"
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
49 {
50  G4int n_particle = 1;
51  fParticleGun = new G4ParticleGun(n_particle);
52 
54 
55  G4ParticleDefinition* particle = particleTable->FindParticle("proton");
56  G4double mass_proton = particle->GetPDGMass();
57 
59  (mass_proton/CLHEP::c_squared);
60 
61  G4cout << " *** Neutron *** " << G4endl;
62 
63  particle = particleTable->FindParticle("neutron");
64  G4double mass_neutron = particle->GetPDGMass();
65 
66  G4double magneticMoment = particle->GetPDGMagneticMoment();
67  G4cout << " magneticMoment: " << magneticMoment/muN << G4endl;
68 
69  // g_factor for spin 1/2
70 
71  G4double g_factor = 2 * magneticMoment/muN;
72  G4cout << " g_factor: " << g_factor << G4endl;
73 
74  G4double charge = particle->GetPDGCharge();
75  G4cout << " charge: " << charge << G4endl;
76 
77  G4double anomaly = (g_factor - 2.)/2.;
78  G4cout << " anomaly: " << anomaly << G4endl;
79 
80  anomaly = (g_factor * (mass_neutron/mass_proton) - 2.)/2.;
81  G4cout << " corrected anomaly: " << anomaly << G4endl;
82 
83  muN = 0.5*CLHEP::eplus*CLHEP::hbar_Planck/(mass_neutron/CLHEP::c_squared);
84  g_factor = 2 * magneticMoment/muN;
85 
86  anomaly = (g_factor - 2.)/2.;
87  G4cout << " *** anomaly: " << anomaly << G4endl;
88 
89  G4cout << " *** MuonPlus *** " << G4endl;
90 
91  particle = particleTable->FindParticle("mu+");
92  G4double mass_muon = particle->GetPDGMass();
93 
95  (mass_muon/CLHEP::c_squared);
96 
97  magneticMoment = particle->GetPDGMagneticMoment();
98  G4cout << " magneticMoment: " << magneticMoment/muB << G4endl;
99 
100  // g_factor for spin 1/2
101 
102  g_factor = magneticMoment/muB;
103  G4cout << " g_factor: " << g_factor << G4endl;
104 
105  charge = particle->GetPDGCharge();
106  G4cout << " charge: " << charge << G4endl;
107 
108  anomaly = (g_factor - 2.)/2.;
109  G4cout << " anomaly: " << anomaly << G4endl;
110 
111 // anomaly = particle->CalculateAnomaly();
112 // G4cout << " *** anomaly: " << anomaly << G4endl;
113 
114  particle = particleTable->FindParticle("neutron");
116 }
117 
118 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
119 
121 {
122  delete fParticleGun;
123 }
124 
125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
126 
128 {
129  //this function is called at the begining of event
130  //
131 
134 
135  G4double particleEnergy = G4UniformRand()*1e-7*eV;
136  fParticleGun->SetParticleEnergy(particleEnergy);
137 
139  G4double phi = std::acos(1-2*G4UniformRand());
140  if (phi > pi/2 && phi < pi) phi = pi-phi;
141 
142  G4double z = std::sin(phi)*std::cos(theta);
143  G4double x = std::sin(phi)*std::sin(theta);
144  G4double y = std::cos(phi);
145 
147 
149 }
150 
151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......