From 3edd5e5d61269ea8fb42e756dc6eb154f593c6db Mon Sep 17 00:00:00 2001 From: lintao <lintao51@gmail.com> Date: Sun, 8 Sep 2019 15:07:58 +0800 Subject: [PATCH] WIP: update. --- .../DetSimCore/src/G4PrimaryCnvTool.cpp | 28 +++++++++++++ .../DetSimCore/src/PrimaryGeneratorAction.cpp | 41 +++++++++---------- 2 files changed, 48 insertions(+), 21 deletions(-) diff --git a/Simulation/DetSimCore/src/G4PrimaryCnvTool.cpp b/Simulation/DetSimCore/src/G4PrimaryCnvTool.cpp index 717a447f..7ff3004a 100644 --- a/Simulation/DetSimCore/src/G4PrimaryCnvTool.cpp +++ b/Simulation/DetSimCore/src/G4PrimaryCnvTool.cpp @@ -1,6 +1,9 @@ #include "G4PrimaryCnvTool.h" #include "G4Event.hh" +#include "G4ParticleTable.hh" +#include "G4IonTable.hh" +#include "G4ParticleDefinition.hh" DECLARE_COMPONENT(G4PrimaryCnvTool) @@ -14,6 +17,31 @@ bool G4PrimaryCnvTool::mutate(G4Event* anEvent) { info() << " " << it->getObjectID().index; } info() << " ]; " << endmsg; + + // only the GeneratorStatus == 1 is used. + if (p.getGeneratorStatus() != 1) { + continue; + } + + // vertex + const plcio::DoubleThree& vertex = p.getVertex(); + double t = p.getMass(); + G4PrimaryVertex* g4vtx = new G4PrimaryVertex(vertex.x, vertex.y, vertex.z, t); + // pdg/particle + int pdgcode = p.getPDG(); + G4ParticleTable* particletbl = G4ParticleTable::GetParticleTable(); + G4ParticleDefinition* particle_def = particletbl->FindParticle(pdgcode); + + // momentum + const plcio::FloatThree& momentum = p.getMomentum(); + G4PrimaryParticle* g4prim = new G4PrimaryParticle(particle_def, + momentum.x, + momentum.y, + momentum.z); + + g4vtx->SetPrimary(g4prim); + + anEvent->AddPrimaryVertex(g4vtx); } return true; diff --git a/Simulation/DetSimCore/src/PrimaryGeneratorAction.cpp b/Simulation/DetSimCore/src/PrimaryGeneratorAction.cpp index 067bd8ce..30c7328b 100644 --- a/Simulation/DetSimCore/src/PrimaryGeneratorAction.cpp +++ b/Simulation/DetSimCore/src/PrimaryGeneratorAction.cpp @@ -23,26 +23,25 @@ PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) { tool->mutate(anEvent); } - - // Following is an example: - double x = 0.0; - double y = 0.0; - double z = 0.0; - double t = 0.0; - G4PrimaryVertex* g4vtx = new G4PrimaryVertex(x, y, z, t); - - - G4int pdgcode = 22; - // check the pdgid - G4ParticleTable* particletbl = G4ParticleTable::GetParticleTable(); - G4ParticleDefinition* particle_def = particletbl->FindParticle(pdgcode); - - double px = 0.0; - double py = 0.0; - double pz = 0.0; - G4PrimaryParticle* g4prim=new G4PrimaryParticle(particle_def, px, py, pz); - g4vtx->SetPrimary(g4prim); - - anEvent->AddPrimaryVertex(g4vtx); + // // Following is an example: + // double x = 0.0; + // double y = 0.0; + // double z = 0.0; + // double t = 0.0; + // G4PrimaryVertex* g4vtx = new G4PrimaryVertex(x, y, z, t); + + + // G4int pdgcode = 22; + // // check the pdgid + // G4ParticleTable* particletbl = G4ParticleTable::GetParticleTable(); + // G4ParticleDefinition* particle_def = particletbl->FindParticle(pdgcode); + + // double px = 0.0; + // double py = 0.0; + // double pz = 0.0; + // G4PrimaryParticle* g4prim=new G4PrimaryParticle(particle_def, px, py, pz); + // g4vtx->SetPrimary(g4prim); + + // anEvent->AddPrimaryVertex(g4vtx); } -- GitLab