11#include "BesPrimaryGeneratorAction.hh"
12#include "BesPrimaryGeneratorMessenger.hh"
15#include "G4ParticleGun.hh"
16#include "G4ParticleTable.hh"
17#include "G4ParticleDefinition.hh"
18#include "G4ParticleMomentum.hh"
19#include "Randomize.hh"
20#include "G4HEPEvtInterface.hh"
38 particleGun =
new G4ParticleGun(1);
41 generatorName =
"tester";
45 if(generatorName ==
"cosmic")
47 std::string path = getenv(
"GENSIMROOT");
48 G4cout<<
"path: "<<path<<G4endl;
51 std::string pFile = path +
"ppdc.root";
52 std::string thetaFile = path +
"theta.root";
53 std::string phiFile = path +
"phi.root";
55 TFile*
f1 =
new TFile(pFile.c_str());
56 h1 = (TH1F*)
f1->Get(
"htemp");
58 TFile* f2 =
new TFile(thetaFile.c_str());
59 h2 = (TH1F*)f2->Get(
"htemp");
61 TFile* f3 =
new TFile(phiFile.c_str());
62 h3 = (TH1F*)f3->Get(
"htemp");
73 if(messenger)
delete messenger;
74 if(generatorName==
"genbes")
delete HEPEvt;
79 if(generatorName==
"tester")
81 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
82 G4ParticleDefinition* particle
83 = particleTable->FindParticle(particleName);
84 particleGun->SetParticleDefinition(particle);
85 particleGun->SetParticlePosition(G4ThreeVector(posX,posY,posZ));
88 for(G4int i=0; i<nParticle; i++)
90 G4double pMag = pMomentum;
92 if(deltaP>0.)pMag = pMomentum - deltaP*(1.0 - 2.0*G4UniformRand());
95 G4double costheta = minCos +(maxCos - minCos)*G4UniformRand();
97 G4double phi = phiStart+(phiEnd-phiStart)*G4UniformRand();
99 G4double sintheta = sqrt(1.-costheta*costheta);
101 G4ParticleMomentum aMomentum;
102 aMomentum[0] = pMag*sintheta*
cos(phi);
103 aMomentum[1] = pMag*sintheta*
sin(phi);
104 aMomentum[2] = pMag*costheta;
106 particleGun->SetParticleMomentum(aMomentum);
107 particleGun->GeneratePrimaryVertex(anEvent);
110 else if(generatorName==
"cosmic")
112 G4cout<<
"generatorName: "<<generatorName<<G4endl;
113 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
114 G4ParticleDefinition* particle
115 = particleTable->FindParticle(particleName);
116 G4cout<<
"particleName: "<<particleName<<G4endl;
118 particleGun->SetParticleDefinition(particle);
119 particleGun->SetParticlePosition(G4ThreeVector(posX,posY,posZ));
131 G4double pMag = h1->GetRandom()*GeV;
132 G4cout<<
"pMag: "<<pMag<<G4endl;
138 G4double theta =(Double_t)h2->GetRandom();
139 G4cout<<
"theta: "<<theta<<G4endl;
140 G4double costheta =
cos(theta);
146 G4double phi = (Double_t)h3->GetRandom();
147 G4cout<<
"phi: "<<phi<<G4endl;
159 G4double sintheta = sqrt(1.-costheta*costheta);
161 G4ParticleMomentum aMomentum;
162 aMomentum[0] = pMag*sintheta*
cos(phi);
163 aMomentum[1] = pMag*sintheta*
sin(phi);
164 aMomentum[2] = pMag*costheta;
166 particleGun->SetParticleMomentum(aMomentum);
167 particleGun->GeneratePrimaryVertex(anEvent);
170 else if(generatorName==
"genbes")
172 G4cout<<
"genbes called"<<G4endl;
176 HEPEvt=
new G4HEPEvtInterface(genbesName);
178 HEPEvt->GeneratePrimaryVertex(anEvent);
double sin(const BesAngle a)
double cos(const BesAngle a)
~BesPrimaryGeneratorAction()
BesPrimaryGeneratorAction()
void GeneratePrimaries(G4Event *anEvent)