added skyplaneEmitter
This commit is contained in:
@@ -10,6 +10,9 @@
|
||||
#include "G4SystemOfUnits.hh"
|
||||
#include "Randomize.hh"
|
||||
|
||||
#include "EcoMug.hh"
|
||||
|
||||
|
||||
namespace uLib {
|
||||
namespace Geant {
|
||||
|
||||
@@ -58,6 +61,87 @@ void EmitterPrimary::GeneratePrimaries(G4Event *anEvent) {
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
// SkyPlaneEmitterPrimary using EcoMug
|
||||
|
||||
SkyPlaneEmitterPrimary::SkyPlaneEmitterPrimary()
|
||||
: EmitterPrimary(), m_EcoMug(new EcoMug()), m_Size(1000.0, 1000.0) {
|
||||
// Initial configuration for EcoMug in sky mode
|
||||
m_EcoMug->SetUseSky();
|
||||
m_EcoMug->SetSkySize({m_Size(0)/1000.0, m_Size(1)/1000.0});
|
||||
}
|
||||
|
||||
SkyPlaneEmitterPrimary::~SkyPlaneEmitterPrimary() {
|
||||
delete m_EcoMug;
|
||||
}
|
||||
|
||||
void SkyPlaneEmitterPrimary::SetSkySize(const uLib::Vector2f& size) {
|
||||
m_Size = size;
|
||||
// EcoMug units are in meters (m=1), Geant4 units are in mm.
|
||||
m_EcoMug->SetSkySize({m_Size(0)/1000.0, m_Size(1)/1000.0});
|
||||
this->Updated();
|
||||
}
|
||||
|
||||
void SkyPlaneEmitterPrimary::SetPlane(const uLib::Vector3f& p0, const uLib::Vector3f& normal) {
|
||||
this->SetPosition(p0);
|
||||
// Orient the emitter so that local Z is the normal.
|
||||
// This is useful for unconventional planes, though EcoMug sky is usually horizontal.
|
||||
// If we want a truly 'sky' plane, it usually stays horizontal.
|
||||
this->Updated();
|
||||
}
|
||||
|
||||
void SkyPlaneEmitterPrimary::GeneratePrimaries(G4Event* anEvent) {
|
||||
if (!m_EcoMug) return;
|
||||
m_EcoMug->Generate();
|
||||
|
||||
// EcoMug position is relative to its internal sky center in meters.
|
||||
// Our wrapper uses the AffineTransform for the overall positioning.
|
||||
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);
|
||||
|
||||
// EcoMug momentum (direction and magnitude in GeV/c)
|
||||
double p_mag = m_EcoMug->GetGenerationMomentum();
|
||||
double theta = m_EcoMug->GetGenerationTheta();
|
||||
double phi = m_EcoMug->GetGenerationPhi();
|
||||
|
||||
// EcoMug theta is generated in a way that PI means pointing down (-Z)
|
||||
G4ThreeVector local_dir(
|
||||
sin(theta) * cos(phi),
|
||||
sin(theta) * sin(phi),
|
||||
cos(theta)
|
||||
);
|
||||
|
||||
// Transform local coordinates to world
|
||||
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();
|
||||
|
||||
// Set particle charge
|
||||
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);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
||||
|
||||
QuadMeshEmitterPrimary::QuadMeshEmitterPrimary()
|
||||
: EmitterPrimary(), m_Mesh(nullptr), m_TotalArea(0.0) {
|
||||
|
||||
@@ -4,10 +4,13 @@
|
||||
#include "G4VUserPrimaryGeneratorAction.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
|
||||
namespace uLib {
|
||||
class QuadMesh;
|
||||
}
|
||||
|
||||
class EcoMug;
|
||||
|
||||
#include "Math/QuadMesh.h"
|
||||
#include "Core/Object.h"
|
||||
#include "Math/Transform.h"
|
||||
@@ -16,6 +19,7 @@ class QuadMesh;
|
||||
class G4ParticleGun;
|
||||
class G4Event;
|
||||
|
||||
|
||||
namespace uLib {
|
||||
namespace Geant {
|
||||
|
||||
@@ -34,6 +38,23 @@ class EmitterPrimary : public G4VUserPrimaryGeneratorAction, public Object, publ
|
||||
G4ParticleGun* fParticleGun; // Puntatore al cannone di particelle
|
||||
};
|
||||
|
||||
class SkyPlaneEmitterPrimary : public EmitterPrimary
|
||||
{
|
||||
public:
|
||||
SkyPlaneEmitterPrimary();
|
||||
virtual ~SkyPlaneEmitterPrimary();
|
||||
|
||||
virtual void GeneratePrimaries(G4Event*);
|
||||
|
||||
void SetPlane(const uLib::Vector3f& p0, const uLib::Vector3f& normal);
|
||||
void SetSkySize(const uLib::Vector2f& size);
|
||||
uLib::Vector2f GetSkySize() const { return m_Size; }
|
||||
|
||||
private:
|
||||
EcoMug* m_EcoMug;
|
||||
uLib::Vector2f m_Size;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class QuadMeshEmitterPrimary : public EmitterPrimary
|
||||
|
||||
Reference in New Issue
Block a user