Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#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;