Example #1
0
void	GSMS::Source::generate_G4(G4GeneralParticleSource*	dst, G4double	dAngle) {

    if (!dst) return;
    for(int i=0; i<m_gamma.size(); i++) {
        G4float	ene = m_gamma[i].first;
        G4float	act = m_gamma[i].second;

        dst->AddaSource(act);
        dst->SetParticleDefinition(G4Gamma::Gamma());
        G4SingleParticleSource*	src = dst->GetCurrentSource();
        src->GetEneDist()->SetMonoEnergy(ene);

        src->GetAngDist()->SetAngDistType("iso");
        src->GetPosDist()->SetPosDisType("Point");
        src->GetEneDist()->SetEnergyDisType("Mono");

        //src->GetPosDist()->SetCentreCoords(get_coords());
        //src->GetPosDist()->SetCentreCoords(G4ThreeVector(1., 0., 0.));
        src->GetPosDist()->SetCentreCoords(G4ThreeVector(m_x, m_y, m_z));

        G4double	basePhi = 0.0;
        m_x != 0.0 ? basePhi = std::atan(m_y/m_x) :
                               m_y > 0 ? basePhi = pi/2 : basePhi = -pi/2;

        if(m_x < 0.0 ) basePhi = -pi + basePhi;

        std::cerr << "X: " << m_x << " Y: " << m_y << " Phi: " << basePhi << std::endl;


        G4double	dPhi = GSMS::get_hull().get_delta_phi(get_coords());
        G4double	baseTheta = pi/2;//TODO

        G4double	dTheta = GSMS::get_hull().get_delta_theta(get_coords());
        std::cerr << "dPhi: " << dPhi*360/2/pi << "; dTheta" << dTheta*360/2/pi << std::endl;

        //dPhi = 3*pi/2/180;//2*pi/2/180;
        //dTheta = 16*pi/2/180;//6*pi/2/180;

        src->GetAngDist()->SetMinPhi(basePhi - dPhi);
        src->GetAngDist()->SetMaxPhi(basePhi + dPhi);
        src->GetAngDist()->SetMinTheta(baseTheta - dTheta);
        src->GetAngDist()->SetMaxTheta(baseTheta + dTheta);
        std::cerr << ene << std::endl;
        std::cerr << act << std::endl;
    }
}
Example #2
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);
}