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

GtPythiaTool: add mother and daughter.

parent 23fc4295
No related branches found
No related tags found
No related merge requests found
#include "GtPythiaTool.hh" #include "GtPythiaTool.hh"
DECLARE_COMPONENT(GtPythiaTool) DECLARE_COMPONENT(GtPythiaTool)
StatusCode GtPythiaTool::initialize() { StatusCode GtPythiaTool::initialize() {
StatusCode sc; StatusCode sc;
m_pythia = std::make_unique<Pythia8::Pythia>(); m_pythia = std::make_unique<Pythia8::Pythia>();
// configure with the card file first // configure with the card file first
m_pythia->readFile(m_card.value()); m_pythia->readFile(m_card.value());
// tune with the additional commands // tune with the additional commands
for (auto cmd: m_cmds.value()) { for (auto cmd: m_cmds.value()) {
m_pythia->readString(cmd); m_pythia->readString(cmd);
} }
// initialize pythia // initialize pythia
m_pythia->init(); m_pythia->init();
return sc; return sc;
} }
StatusCode GtPythiaTool::finalize() { StatusCode GtPythiaTool::finalize() {
StatusCode sc; StatusCode sc;
return sc; return sc;
} }
bool GtPythiaTool::mutate(Gen::GenEvent& event) { bool GtPythiaTool::mutate(Gen::GenEvent& event) {
// generate the event // generate the event
while(!m_pythia->next()) { while(!m_pythia->next()) {
// if failed, try again // if failed, try again
} }
// get the particles // get the particles
auto& pythia_particles = m_pythia->event; auto& pythia_particles = m_pythia->event;
// loop over the particles // loop over the particles
for (int i = 0; i < pythia_particles.size(); ++i) { for (int i = 0; i < pythia_particles.size(); ++i) {
auto& p = pythia_particles[i]; auto& p = pythia_particles[i];
// create the MCParticle // create the MCParticle
auto mcp = event.getMCVec().create(); auto mcp = event.getMCVec().create();
// set the properties // set the properties
mcp.setPDG(p.id()); mcp.setPDG(p.id());
int status = 0; int status = 0;
if (p.isFinal()) { if (p.isFinal()) {
status = 1; status = 1;
} else { } else {
status = 0; status = 0;
} }
mcp.setGeneratorStatus(status); mcp.setGeneratorStatus(status);
mcp.setCharge(p.charge()); mcp.setCharge(p.charge());
mcp.setTime(p.tau()); mcp.setTime(p.tProd());
mcp.setMass(p.m()); mcp.setMass(p.m());
mcp.setVertex(edm4hep::Vector3d(p.xProd(), p.yProd(), p.zProd())); mcp.setVertex(edm4hep::Vector3d(p.xProd(), p.yProd(), p.zProd()));
mcp.setEndpoint(edm4hep::Vector3d(p.xDec(), p.yDec(), p.zDec())); // update the endpoint later
mcp.setMomentum(edm4hep::Vector3f(p.px(), p.py(), p.pz())); mcp.setEndpoint(edm4hep::Vector3d(p.xProd(), p.yProd(), p.zProd()));
} mcp.setMomentum(edm4hep::Vector3f(p.px(), p.py(), p.pz()));
return true; }
} // setup the relationships (mother and daughter)
for (int i = 0; i < pythia_particles.size(); ++i) {
bool GtPythiaTool::finish() { auto& p = pythia_particles[i];
return true; auto mcp = event.getMCVec()[i];
}
auto mother_list = p.motherList();
bool GtPythiaTool::configure_gentool() { for (auto idx: mother_list) {
return true; 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