15#include "G4ParticleGun.hh"
16#include "G4ParticleTable.hh"
17#include "G4ParticleDefinition.hh"
18#include "G4ParticleMomentum.hh"
19#include "Randomize.hh"
20#include "G4HEPEvtInterface.hh"
40 particleGun =
new G4ParticleGun(1);
43 generatorName =
"tester";
47 if(generatorName ==
"cosmic")
49 std::string path = getenv(
"GENSIMROOT");
50 G4cout<<
"path: "<<path<<G4endl;
53 std::string pFile = path +
"ppdc.root";
54 std::string thetaFile = path +
"theta.root";
55 std::string phiFile = path +
"phi.root";
57 TFile*
f1 =
new TFile(pFile.c_str());
58 h1 = (TH1F*)
f1->Get(
"htemp");
60 TFile* f2 =
new TFile(thetaFile.c_str());
61 h2 = (TH1F*)f2->Get(
"htemp");
63 TFile* f3 =
new TFile(phiFile.c_str());
64 h3 = (TH1F*)f3->Get(
"htemp");
75 if(messenger)
delete messenger;
76 if(generatorName==
"genbes")
delete HEPEvt;
81 if(generatorName==
"tester")
83 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
84 G4ParticleDefinition* particle
85 = particleTable->FindParticle(particleName);
86 particleGun->SetParticleDefinition(particle);
87 particleGun->SetParticlePosition(G4ThreeVector(posX,posY,posZ));
88 particleGun->SetParticleTime(648*
ns);
91 for(G4int i=0; i<nParticle; i++)
93 G4double pMag = pMomentum;
95 if(deltaP>0.)pMag = pMomentum - deltaP*(1.0 - 2.0*G4UniformRand());
98 G4double
costheta = minCos +(maxCos - minCos)*G4UniformRand();
100 G4double phi = phiStart+(phiEnd-phiStart)*G4UniformRand();
104 G4ParticleMomentum aMomentum;
105 aMomentum[0] = pMag*sintheta*
cos(phi);
106 aMomentum[1] = pMag*sintheta*
sin(phi);
109 particleGun->SetParticleMomentum(aMomentum);
110 particleGun->GeneratePrimaryVertex(anEvent);
113 else if(generatorName==
"cosmic")
115 G4cout<<
"generatorName: "<<generatorName<<G4endl;
116 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
117 G4ParticleDefinition* particle
118 = particleTable->FindParticle(particleName);
119 G4cout<<
"particleName: "<<particleName<<G4endl;
121 particleGun->SetParticleDefinition(particle);
122 particleGun->SetParticlePosition(G4ThreeVector(posX,posY,posZ));
134 G4double pMag = h1->GetRandom()*GeV;
135 G4cout<<
"pMag: "<<pMag<<G4endl;
141 G4double theta =(Double_t)h2->GetRandom();
142 G4cout<<
"theta: "<<theta<<G4endl;
149 G4double phi = (Double_t)h3->GetRandom();
150 G4cout<<
"phi: "<<phi<<G4endl;
164 G4ParticleMomentum aMomentum;
165 aMomentum[0] = pMag*sintheta*
cos(phi);
166 aMomentum[1] = pMag*sintheta*
sin(phi);
169 particleGun->SetParticleMomentum(aMomentum);
170 particleGun->GeneratePrimaryVertex(anEvent);
173 else if(generatorName==
"genbes")
175 G4cout<<
"genbes called"<<G4endl;
179 HEPEvt=
new G4HEPEvtInterface(genbesName);
181 HEPEvt->SetParticleTime(648*
ns);
182 HEPEvt->GeneratePrimaryVertex(anEvent);
double sin(const BesAngle a)
double cos(const BesAngle a)
~BesPrimaryGeneratorAction()
BesPrimaryGeneratorAction()
void GeneratePrimaries(G4Event *anEvent)