|
|
|
|
@@ -15,6 +15,7 @@
|
|
|
|
|
#include "HEP/Geant/EmitterPrimary.hh"
|
|
|
|
|
#include "Math/ContainerBox.h"
|
|
|
|
|
#include "Math/Dense.h"
|
|
|
|
|
#include "Math/Units.h"
|
|
|
|
|
#include "Vtk/uLibVtkViewer.h"
|
|
|
|
|
#include "Vtk/HEP/Geant/vtkGeantEvent.h"
|
|
|
|
|
#include "Vtk/vtkContainerBox.h"
|
|
|
|
|
@@ -38,24 +39,21 @@ using namespace uLib;
|
|
|
|
|
class RandomEmitter : public Geant::EmitterPrimary {
|
|
|
|
|
public:
|
|
|
|
|
virtual void GeneratePrimaries(G4Event* anEvent) override {
|
|
|
|
|
// Start from a random point in a square at z = 5m
|
|
|
|
|
// Note: unit in Geant4 is mm by default if not specified,
|
|
|
|
|
// but here we use the constants from G4SystemOfUnits.h
|
|
|
|
|
double x = (G4UniformRand() - 0.5) * 2000; // -1m to 1m
|
|
|
|
|
double y = (G4UniformRand() - 0.5) * 2000; // -1m to 1m
|
|
|
|
|
double z = 5000.0; // 5m above origin
|
|
|
|
|
// Start from a random point on the top face of the world box (z = 15m)
|
|
|
|
|
double x = 0_m;
|
|
|
|
|
double y = 0_m;
|
|
|
|
|
double z = 14.9_m; // Top face
|
|
|
|
|
|
|
|
|
|
fParticleGun->SetParticlePosition(G4ThreeVector(x, y, z));
|
|
|
|
|
|
|
|
|
|
// Aim at a random point within the cube (which is at origin, size 1m)
|
|
|
|
|
double tx = (G4UniformRand() - 0.5) * 1000;
|
|
|
|
|
double ty = (G4UniformRand() - 0.5) * 1000;
|
|
|
|
|
double tz = (G4UniformRand() - 0.5) * 1000;
|
|
|
|
|
// Aim at a random point on the bottom face (z = -15m)
|
|
|
|
|
double tx = 0_m;
|
|
|
|
|
double ty = 0_m;
|
|
|
|
|
double tz = -14.9_m; // Bottom face
|
|
|
|
|
|
|
|
|
|
G4ThreeVector dir(tx - x, ty - y, tz - z);
|
|
|
|
|
dir = dir.unit();
|
|
|
|
|
fParticleGun->SetParticleMomentumDirection(dir);
|
|
|
|
|
|
|
|
|
|
fParticleGun->SetParticleMomentumDirection(dir.unit());
|
|
|
|
|
fParticleGun->SetParticleEnergy(15_GeV);
|
|
|
|
|
fParticleGun->GeneratePrimaryVertex(anEvent);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -91,16 +89,20 @@ void KeyPressCallbackFunction(vtkObject* caller, long unsigned int eventId, void
|
|
|
|
|
state->viewer->GetRenderer()->Render();
|
|
|
|
|
state->viewer->GetRenderWindow()->Render();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
std::cout << " No event collected." << std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
|
// 1. Setup Geant4 Scene
|
|
|
|
|
ContainerBox world_box(Vector3f(30000, 30000, 30000));
|
|
|
|
|
Geant::Scene scene;
|
|
|
|
|
scene.ConstructWorldBox(&world_box, "G4_AIR");
|
|
|
|
|
scene.ConstructWorldBox(Vector3f(30_m, 30_m, 30_m), "G4_AIR");
|
|
|
|
|
|
|
|
|
|
ContainerBox iron_box(Vector3f(1000, 1000, 1000));
|
|
|
|
|
ContainerBox iron_box;
|
|
|
|
|
iron_box.Scale(Vector3f(10_m, 10_m, 10_m));
|
|
|
|
|
iron_box.SetPosition(Vector3f(-5_m, -5_m, -5_m));
|
|
|
|
|
Geant::BoxSolid* iron_cube = new Geant::BoxSolid("IronCube", &iron_box);
|
|
|
|
|
iron_cube->SetNistMaterial("G4_Fe");
|
|
|
|
|
iron_cube->Update();
|
|
|
|
|
@@ -114,8 +116,16 @@ int main(int argc, char** argv) {
|
|
|
|
|
Vtk::Viewer viewer;
|
|
|
|
|
viewer.GetRenderer()->SetBackground(0.05, 0.05, 0.1);
|
|
|
|
|
|
|
|
|
|
// Visualize world box
|
|
|
|
|
Vtk::vtkContainerBox* vtkWorld = new Vtk::vtkContainerBox(scene.GetWorldBox());
|
|
|
|
|
// vtkWorld->ShowBoundingBox(true);
|
|
|
|
|
vtkWorld->ShowScaleMeasures(true);
|
|
|
|
|
viewer.AddPuppet(*vtkWorld);
|
|
|
|
|
|
|
|
|
|
// Visualize iron cube
|
|
|
|
|
Vtk::vtkContainerBox* vtkIron = new Vtk::vtkContainerBox(&iron_box);
|
|
|
|
|
vtkIron->SetOpacity(0.2);
|
|
|
|
|
vtkIron->SetRepresentation(Vtk::Puppet::Surface);
|
|
|
|
|
viewer.AddPuppet(*vtkIron);
|
|
|
|
|
|
|
|
|
|
// 3. Event Handling
|
|
|
|
|
|