Skip to content
Snippets Groups Projects
Commit b181c903 authored by lintao@ihep.ac.cn's avatar lintao@ihep.ac.cn
Browse files

Merge branch 'lintao/gen/pythia' into 'master'

GtPythiaTool: add mother and daughter.

See merge request cepc/CEPCSW!147
parents 23fc4295 b856dd5d
No related branches found
No related tags found
1 merge request!147GtPythiaTool: add mother and daughter.
Pipeline #13690 passed with stage
in 17 minutes and 21 seconds
#include "GtPythiaTool.hh"
DECLARE_COMPONENT(GtPythiaTool)
StatusCode GtPythiaTool::initialize() {
StatusCode sc;
m_pythia = std::make_unique<Pythia8::Pythia>();
// configure with the card file first
m_pythia->readFile(m_card.value());
// tune with the additional commands
for (auto cmd: m_cmds.value()) {
m_pythia->readString(cmd);
}
// initialize pythia
m_pythia->init();
return sc;
}
StatusCode GtPythiaTool::finalize() {
StatusCode sc;
return sc;
}
bool GtPythiaTool::mutate(Gen::GenEvent& event) {
// generate the event
while(!m_pythia->next()) {
// if failed, try again
}
// get the particles
auto& pythia_particles = m_pythia->event;
// loop over the particles
for (int i = 0; i < pythia_particles.size(); ++i) {
auto& p = pythia_particles[i];
// create the MCParticle
auto mcp = event.getMCVec().create();
// set the properties
mcp.setPDG(p.id());
int status = 0;
if (p.isFinal()) {
status = 1;
} else {
status = 0;
}
mcp.setGeneratorStatus(status);
mcp.setCharge(p.charge());
mcp.setTime(p.tau());
mcp.setMass(p.m());
mcp.setVertex(edm4hep::Vector3d(p.xProd(), p.yProd(), p.zProd()));
mcp.setEndpoint(edm4hep::Vector3d(p.xDec(), p.yDec(), p.zDec()));
mcp.setMomentum(edm4hep::Vector3f(p.px(), p.py(), p.pz()));
}
return true;
}
bool GtPythiaTool::finish() {
return true;
}
bool GtPythiaTool::configure_gentool() {
return true;
#include "GtPythiaTool.hh"
DECLARE_COMPONENT(GtPythiaTool)
StatusCode GtPythiaTool::initialize() {
StatusCode sc;
m_pythia = std::make_unique<Pythia8::Pythia>();
// configure with the card file first
m_pythia->readFile(m_card.value());
// tune with the additional commands
for (auto cmd: m_cmds.value()) {
m_pythia->readString(cmd);
}
// initialize pythia
m_pythia->init();
return sc;
}
StatusCode GtPythiaTool::finalize() {
StatusCode sc;
return sc;
}
bool GtPythiaTool::mutate(Gen::GenEvent& event) {
// generate the event
while(!m_pythia->next()) {
// if failed, try again
}
// get the particles
auto& pythia_particles = m_pythia->event;
// loop over the particles
for (int i = 0; i < pythia_particles.size(); ++i) {
auto& p = pythia_particles[i];
// create the MCParticle
auto mcp = event.getMCVec().create();
// set the properties
mcp.setPDG(p.id());
int status = 0;
if (p.isFinal()) {
status = 1;
} else {
status = 0;
}
mcp.setGeneratorStatus(status);
mcp.setCharge(p.charge());
mcp.setTime(p.tProd());
mcp.setMass(p.m());
mcp.setVertex(edm4hep::Vector3d(p.xProd(), p.yProd(), p.zProd()));
// update the endpoint later
mcp.setEndpoint(edm4hep::Vector3d(p.xProd(), p.yProd(), p.zProd()));
mcp.setMomentum(edm4hep::Vector3f(p.px(), p.py(), p.pz()));
}
// setup the relationships (mother and daughter)
for (int i = 0; i < pythia_particles.size(); ++i) {
auto& p = pythia_particles[i];
auto mcp = event.getMCVec()[i];
auto mother_list = p.motherList();
for (auto idx: mother_list) {
auto mother = event.getMCVec()[idx];
mcp.addToParents(mother);
}
auto daughter_list = p.daughterList();
bool need_endpoint = true;
for (auto idx: daughter_list) {
auto daughter = event.getMCVec()[idx];
mcp.addToDaughters(daughter);
// Update the endpoint to the daughter's vertex
if (need_endpoint) {
mcp.setEndpoint(daughter.getVertex());
need_endpoint = false;
}
}
}
return true;
}
bool GtPythiaTool::finish() {
return true;
}
bool GtPythiaTool::configure_gentool() {
return true;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment