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