add cylinder emitter
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "Randomize.hh"
|
||||
|
||||
#include "EcoMug.hh"
|
||||
#include "Math/Cylinder.h"
|
||||
|
||||
|
||||
namespace uLib {
|
||||
@@ -126,6 +127,66 @@ void SkyPlaneEmitterPrimary::GeneratePrimaries(G4Event* anEvent) {
|
||||
|
||||
fParticleGun->GeneratePrimaryVertex(anEvent);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
// CylinderEmitterPrimary using EcoMug
|
||||
|
||||
CylinderEmitterPrimary::CylinderEmitterPrimary()
|
||||
: EmitterPrimary(), m_EcoMug(new EcoMug()), m_Radius(1000.0), m_Height(1000.0) {
|
||||
m_EcoMug->SetUseCylinder();
|
||||
m_EcoMug->SetCylinderRadius(m_Radius/1000.0);
|
||||
m_EcoMug->SetCylinderHeight(m_Height/1000.0);
|
||||
m_EcoMug->SetCylinderCenterPosition({0.0, 0.0, m_Height/2000.0});
|
||||
}
|
||||
|
||||
CylinderEmitterPrimary::~CylinderEmitterPrimary() {
|
||||
delete m_EcoMug;
|
||||
}
|
||||
|
||||
void CylinderEmitterPrimary::SetRadius(float r) {
|
||||
m_Radius = r;
|
||||
m_EcoMug->SetCylinderRadius(m_Radius/1000.0);
|
||||
this->Updated();
|
||||
}
|
||||
|
||||
void CylinderEmitterPrimary::SetHeight(float h) {
|
||||
m_Height = h;
|
||||
m_EcoMug->SetCylinderHeight(m_Height/1000.0);
|
||||
m_EcoMug->SetCylinderCenterPosition({0.0, 0.0, m_Height/2000.0});
|
||||
this->Updated();
|
||||
}
|
||||
|
||||
void CylinderEmitterPrimary::GeneratePrimaries(G4Event* anEvent) {
|
||||
if (!m_EcoMug) return;
|
||||
m_EcoMug->Generate();
|
||||
|
||||
std::array<double, 3> pos_m = m_EcoMug->GetGenerationPosition();
|
||||
G4ThreeVector local_pos(pos_m[0]*1000.0, pos_m[1]*1000.0, pos_m[2]*1000.0);
|
||||
|
||||
double p_mag = m_EcoMug->GetGenerationMomentum();
|
||||
double theta = m_EcoMug->GetGenerationTheta();
|
||||
double phi = m_EcoMug->GetGenerationPhi();
|
||||
|
||||
G4ThreeVector local_dir(
|
||||
sin(theta) * cos(phi),
|
||||
sin(theta) * sin(phi),
|
||||
cos(theta)
|
||||
);
|
||||
|
||||
Matrix4f world_mat = this->GetWorldMatrix();
|
||||
Vector3f world_pos = (world_mat * Vector4f(local_pos.x(), local_pos.y(), local_pos.z(), 1.0)).head<3>();
|
||||
Vector3f world_dir = (world_mat * Vector4f(local_dir.x(), local_dir.y(), local_dir.z(), 0.0)).head<3>().normalized();
|
||||
|
||||
G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable();
|
||||
G4String particleName = (m_EcoMug->GetCharge() > 0) ? "mu+" : "mu-";
|
||||
fParticleGun->SetParticleDefinition(particleTable->FindParticle(particleName));
|
||||
|
||||
fParticleGun->SetParticlePosition(G4ThreeVector(world_pos(0), world_pos(1), world_pos(2)));
|
||||
fParticleGun->SetParticleMomentumDirection(G4ThreeVector(world_dir(0), world_dir(1), world_dir(2)));
|
||||
fParticleGun->SetParticleEnergy(p_mag * GeV);
|
||||
|
||||
fParticleGun->GeneratePrimaryVertex(anEvent);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
||||
|
||||
Reference in New Issue
Block a user