diff --git a/Simulation/DetSimCore/src/G4PrimaryCnvTool.cpp b/Simulation/DetSimCore/src/G4PrimaryCnvTool.cpp index 717a447fdfdd31a316f96f0c9f6ef3a8e1b8f0f3..7ff3004acd3f656d7d31922ee6a79ce7ecc59505 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 067bd8ce9abb3154176621293b8796951f568126..30c7328b0fdec8e4cf63de891ea7261629b8c098 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); }