Ejemplo n.º 1
0
void Geant4ShowerGenerator::
generate_showers(unsigned num_events,
                calin::simulation::tracker::ParticleType type,
                double total_energy,
                const Eigen::Vector3d& x0,
                const Eigen::Vector3d& u0,
                double weight)
{
  G4GeneralParticleSource* gps = new G4GeneralParticleSource();

  // default particle kinematic
  G4ParticleTable* particle_table = G4ParticleTable::GetParticleTable();
  G4ParticleDefinition* particle
      = particle_table->FindParticle(particle_type_to_pdg_type(type));

  if(total_energy * CLHEP::MeV < particle->GetPDGMass())
    throw std::invalid_argument(
      "Total energy must be larger than particle rest mass ("
      + std::to_string(particle->GetPDGMass()/CLHEP::MeV) + " MeV)");

  G4ThreeVector position;
  eigen_to_g4vec(position, x0, CLHEP::cm);

  G4ThreeVector momentum_direction;
  eigen_to_g4vec(momentum_direction, u0);

  G4SingleParticleSource* sps = gps->GetCurrentSource();
  sps->SetParticleDefinition(particle);
  sps->GetPosDist()->SetPosDisType("Point");
  sps->GetPosDist()->SetCentreCoords(position);
  sps->GetAngDist()->SetAngDistType("planar");
  sps->GetAngDist()->SetParticleMomentumDirection(momentum_direction);
  sps->GetEneDist()->SetEnergyDisType("Mono");
  sps->GetEneDist()->SetMonoEnergy(total_energy * CLHEP::MeV - particle->GetPDGMass());

  gen_action_->setGPS(gps);

  // start a run
  run_manager_->BeamOn(num_events);
}
void CollimationEventAction::SetOutputParticle(double x, double px, double y, double py, double p)
{
	OutputParticle->x = x;
	OutputParticle->xp = px;
	OutputParticle->y = y;
	OutputParticle->yp = py;

	G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
	G4ParticleDefinition* particle = particleTable->FindParticle("proton");
	const G4double mp = particle->GetPDGMass();
	double pp= sqrt(p*p + mp*mp);

	OutputParticle->p = pp;
	size_t oldprec = std::cout.precision(15);
	//std::cout << "OUT: " << x << "\t" << px << "\t" << y << "\t" << py << "\t" << pp << std::endl;
	std::cout.precision(oldprec);
}