File indexing completed on 2026-05-17 07:41:12
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
0030
0031 #include "SingleParticleGun.hh"
0032
0033 #include "G4Event.hh"
0034 #include "G4ParticleDefinition.hh"
0035 #include "G4ParticleGun.hh"
0036 #include "G4ParticleTable.hh"
0037 #include "G4ThreeVector.hh"
0038 #include "Randomize.hh"
0039
0040
0041 #include "G4TauMinus.hh"
0042 #include "G4TauPlus.hh"
0043
0044
0045
0046 SingleParticleGun::SingleParticleGun(const G4String& pname, const double pmom)
0047 : G4VUserPrimaryGeneratorAction(), fGun(nullptr), fMomentum(pmom)
0048 {
0049 int nparts = 1;
0050 fGun = new G4ParticleGun(nparts);
0051
0052 G4ParticleTable* pdt = G4ParticleTable::GetParticleTable();
0053 G4ParticleDefinition* pd = pdt->FindParticle(pname);
0054 fGun->SetParticleDefinition(pd);
0055 fGun->SetParticlePosition(G4ThreeVector(0., 0., 0.));
0056 double mass = pd->GetPDGMass();
0057 double energy = std::sqrt(fMomentum * fMomentum + mass * mass);
0058 fGun->SetParticleEnergy(energy);
0059
0060
0061
0062 }
0063
0064
0065
0066 SingleParticleGun::~SingleParticleGun()
0067 {
0068 delete fGun;
0069 }
0070
0071
0072
0073 void SingleParticleGun::GeneratePrimaries(G4Event* evt)
0074 {
0075 if (!fGun) {
0076 G4cout << " ParticleGun is NOT set up; BAIL OUT from this event " << G4endl;
0077 G4cout << " Check if you are using ctor "
0078 << "SinglePartGun(const G4string& partname, const double pmom ) " << G4endl;
0079 return;
0080 }
0081
0082 double phi = -1. * CLHEP::pi + CLHEP::twopi * G4UniformRand();
0083 double theta = CLHEP::pi / 4. + CLHEP::halfpi * G4UniformRand();
0084
0085 double x = std::sin(theta) * std::cos(phi);
0086 double y = std::sin(theta) * std::sin(phi);
0087 double z = std::cos(theta);
0088
0089 fGun->SetParticleMomentumDirection(G4ThreeVector(x, y, z));
0090
0091
0092
0093
0094
0095
0096 if (fGun->GetParticleDefinition() == G4TauMinus::TauMinus()) {
0097 fGun->SetParticlePolarization(G4ThreeVector(-1.0 * x, -1.0 * y, -1.0 * z));
0098 }
0099 else if (fGun->GetParticleDefinition() == G4TauPlus::TauPlus()) {
0100 fGun->SetParticlePolarization(G4ThreeVector(x, y, z));
0101 }
0102
0103 fGun->GeneratePrimaryVertex(evt);
0104
0105 return;
0106 }
0107
0108