39 particleGun =
new G4ParticleGun( 1 );
42 generatorName =
"tester";
46 if ( generatorName ==
"cosmic" )
48 std::string path = getenv(
"GENSIMROOT" );
49 G4cout <<
"path: " << path << G4endl;
52 std::string pFile = path +
"ppdc.root";
53 std::string thetaFile = path +
"theta.root";
54 std::string phiFile = path +
"phi.root";
56 TFile*
f1 =
new TFile( pFile.c_str() );
57 h1 = (TH1F*)
f1->Get(
"htemp" );
59 TFile* f2 =
new TFile( thetaFile.c_str() );
60 h2 = (TH1F*)f2->Get(
"htemp" );
62 TFile* f3 =
new TFile( phiFile.c_str() );
63 h3 = (TH1F*)f3->Get(
"htemp" );
78 if ( generatorName ==
"tester" )
80 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
81 G4ParticleDefinition* particle = particleTable->FindParticle( particleName );
82 particleGun->SetParticleDefinition( particle );
83 particleGun->SetParticlePosition( G4ThreeVector( posX, posY, posZ ) );
84 particleGun->SetParticleTime( 648 *
ns );
87 for ( G4int i = 0; i < nParticle; i++ )
89 G4double pMag = pMomentum;
91 if ( deltaP > 0. ) pMag = pMomentum - deltaP * ( 1.0 - 2.0 * G4UniformRand() );
94 G4double costheta = minCos + ( maxCos - minCos ) * G4UniformRand();
96 G4double phi = phiStart + ( phiEnd - phiStart ) * G4UniformRand();
98 G4double sintheta = sqrt( 1. - costheta * costheta );
100 G4ParticleMomentum aMomentum;
101 aMomentum[0] = pMag * sintheta *
cos( phi );
102 aMomentum[1] = pMag * sintheta *
sin( phi );
103 aMomentum[2] = pMag * costheta;
105 particleGun->SetParticleMomentum( aMomentum );
106 particleGun->GeneratePrimaryVertex( anEvent );
109 else if ( generatorName ==
"cosmic" )
111 G4cout <<
"generatorName: " << generatorName << G4endl;
112 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
113 G4ParticleDefinition* particle = particleTable->FindParticle( particleName );
114 G4cout <<
"particleName: " << particleName << G4endl;
116 particleGun->SetParticleDefinition( particle );
117 particleGun->SetParticlePosition( G4ThreeVector( posX, posY, posZ ) );
129 G4double pMag = h1->GetRandom() * GeV;
130 G4cout <<
"pMag: " << pMag << G4endl;
136 G4double theta = (Double_t)h2->GetRandom();
137 G4cout <<
"theta: " << theta << G4endl;
138 G4double costheta =
cos( theta );
144 G4double phi = (Double_t)h3->GetRandom();
145 G4cout <<
"phi: " << phi << G4endl;
157 G4double sintheta = sqrt( 1. - costheta * costheta );
159 G4ParticleMomentum aMomentum;
160 aMomentum[0] = pMag * sintheta *
cos( phi );
161 aMomentum[1] = pMag * sintheta *
sin( phi );
162 aMomentum[2] = pMag * costheta;
164 particleGun->SetParticleMomentum( aMomentum );
165 particleGun->GeneratePrimaryVertex( anEvent );
168 else if ( generatorName ==
"genbes" )
170 G4cout <<
"genbes called" << G4endl;
174 HEPEvt =
new G4HEPEvtInterface( genbesName );
176 HEPEvt->SetParticleTime( 648 *
ns );
177 HEPEvt->GeneratePrimaryVertex( anEvent );