10#include <generators/kkmc/KKGenInterface.h>
13#include <framework/gearbox/Const.h>
14#include <framework/gearbox/Unit.h>
15#include <framework/logging/Logger.h>
16#include <framework/particledb/EvtGenDatabasePDG.h>
17#include <framework/dataobjects/MCInitialParticles.h>
18#include <mdst/dataobjects/MCParticleGraph.h>
22#include <Math/LorentzRotation.h>
23#include <Math/Boost.h>
24#include <Math/Vector3D.h>
37 const std::string& taudecaytableFileName,
const std::string& KKMCOutputFileName)
39 B2DEBUG(20,
"Begin initialisation of KKGen Interface.");
42 char DatX_d[132], DatX_u[132], DatX_p[132], DatX_o[132];
43 for (
int i = 0; i < 132; ++i) {
49 strcpy(DatX_d, KKdefaultFileName.c_str());
50 int length = strlen(DatX_d);
52 strcpy(DatX_u, tauinputFileName.c_str());
53 length = strlen(DatX_u);
55 strcpy(DatX_p, taudecaytableFileName.c_str());
56 length = strlen(DatX_p);
58 strcpy(DatX_o, KKMCOutputFileName.c_str());
59 length = strlen(DatX_o);
62 kk_init_(DatX_d, DatX_u, DatX_p, &irand, DatX_o);
70 for (TObject*
object : *particlelist) {
73 B2FATAL(
"Something is wrong with the EvtGenDatabasePDG, got object not inheriting from EvtGenParticlePDG");
78 B2DEBUG(20,
"End initialisation of KKGen Interface.");
86 if (Ecms0 > 0. && Ecms0Spread >= 0.) {
88 double E0spread = Ecms0Spread / std::sqrt(2);
89 kk_begin_run_(&Ecms0, &E0spread);
91 B2DEBUG(100,
"Wrong beam info");
97 ROOT::Math::XYZVector vertex)
99 B2DEBUG(20,
"Start simulation of KKGen Interface.");
103 ROOT::Math::PxPyPzEVector pHERorg(hepevt_.
phep[0][0], hepevt_.
phep[0][1], hepevt_.
phep[0][2], hepevt_.
phep[0][3]);
104 ROOT::Math::PxPyPzEVector pLERorg(hepevt_.
phep[1][0], hepevt_.
phep[1][1], hepevt_.
phep[1][2], hepevt_.
phep[1][3]);
105 ROOT::Math::PxPyPzEVector pTotOrg = pHERorg + pLERorg;
110 ROOT::Math::LorentzRotation rotKKMC(ROOT::Math::Boost(pTotOrg.BoostToCM()));
113 double EcmsNow = pTotOrg.M();
116 Eigen::VectorXd transVec = lorentzGenerator.
generate(EcmsNow);
120 ROOT::Math::LorentzRotation rotTot = rot * rotKKMC;
122 for (
int i = 0; i < hepevt_.
nhep; ++i) {
123 ROOT::Math::PxPyPzEVector p4cms(hepevt_.
phep[i][0], hepevt_.
phep[i][1], hepevt_.
phep[i][2], hepevt_.
phep[i][3]);
126 ROOT::Math::PxPyPzEVector p4lab = rotTot * p4cms;
128 hepevt_.
phep[i][0] = p4lab.Px();
129 hepevt_.
phep[i][1] = p4lab.Py();
130 hepevt_.
phep[i][2] = p4lab.Pz();
131 hepevt_.
phep[i][3] = p4lab.E();
137 kk_shifttaudecayvtx_();
141 B2DEBUG(100,
"HepEVT table:");
143 for (
int i = 0; i < hepevt_.
nhep; ++i) {
146 "IntA: %3d %4d %8d %4d %4d %4d %9.4f %9.4f %9.4f %9.4f %9.4f",
150 hepevt_.
phep[i][1], hepevt_.
phep[i][2],
151 hepevt_.
phep[i][3], hepevt_.
phep[i][4]);
157 B2DEBUG(100,
"GraphParticles:");
160 for (
int i = 0; i < npar; ++i) {
164 sprintf(buf,
"IntB: %3d %4u %8d %4d %4d %4d %9.4f %9.4f %9.4f %9.4f",
165 p->getIndex(), p->getStatus(), p->getPDG(), moID,
166 p->getFirstDaughter(), p->getLastDaughter(),
167 p->get4Vector().Px(), p->get4Vector().Py(),
168 p->get4Vector().Pz(), p->get4Vector().E());
173 B2DEBUG(20,
"End simulation of KKGen Interface.");
183 if (hepevt_.
nhep < 5) {
184 B2ERROR(
"KKMC-generated event has not been produced correctty!");
188 std::vector <MCParticleGraph::GraphParticle*> MCPList;
191 for (
int i = 1; i <= hepevt_.
nhep; ++i) {
192 int position = graph.
size();
196 MCPList.push_back(p);
200 for (
int i = 4; i <= hepevt_.
nhep; ++i) {
202 if (hepevt_.
jmohep[i - 1][0] > 0 && hepevt_.
jmohep[i - 1][0] <= hepevt_.
nhep) {
203 int j = hepevt_.
jmohep[i - 1][0];
214 if (index < 1 || index > hepevt_.
nhep)
221 gParticle->
setPDG(iter->second);
231 if (abs(hepevt_.
idhep[index - 1]) == 11 &&
232 hepevt_.
jmohep[index - 1][0] == 0 &&
233 hepevt_.
jmohep[index - 1][1] == 0 &&
234 hepevt_.
isthep[index - 1] == 3 &&
240 if (hepevt_.
idhep[index - 1] == 23 || std::abs(hepevt_.
idhep[index - 1]) == 24) {
242 }
else if (hepevt_.
isthep[index - 1] == 1) {
247 if (hepevt_.
idhep[index - 1] == 22) {
250 if (hepevt_.
jmohep[index - 1][0] == 1) {
257 int moth = hepevt_.
jmohep[index - 1][0];
258 int mothid = hepevt_.
idhep[moth - 1];
259 int gmoth = hepevt_.
jmohep[moth - 1][0];
260 int gmothid = hepevt_.
idhep[gmoth - 1];
261 if (abs(mothid) == 15 || abs(mothid) == 24) {
262 B2DEBUG(200,
"moth, mothid, gmoth, gmothid = " << moth <<
" " << mothid <<
" " << gmoth <<
" " << gmothid);
264 int leptonicdecay = 0;
265 int mothdau1 = hepevt_.
jdahep[moth - 1][0];
266 int mothdau2 = hepevt_.
jdahep[moth - 1][1];
267 for (
int idau = mothdau1; idau <= mothdau2; ++idau) {
268 int dauid = abs(hepevt_.
idhep[idau - 1]);
269 if (dauid == 11 || dauid == 12 || dauid == 13 || dauid == 14 || dauid == 16) {
273 if (abs(mothid) == 15 && leptonicdecay > 1) {
274 B2DEBUG(200,
"mothdau1, mothdau2, leptonicdecay = " << mothdau1 <<
" " << mothdau2 <<
" " << leptonicdecay);
276 if ((abs(mothid) == 15) ||
277 (abs(mothid) == 24 && abs(gmothid) == 15)) {
278 if (leptonicdecay == 3) {
282 if (hepevt_.
jdahep[index - 1][0] == 0 && hepevt_.
jdahep[index - 1][1] == -1) {
291 ROOT::Math::PxPyPzEVector p4(hepevt_.
phep[index - 1][0],
292 hepevt_.
phep[index - 1][1],
293 hepevt_.
phep[index - 1][2],
294 hepevt_.
phep[index - 1][3]);
299 ROOT::Math::XYZVector pProductionVertex(hepevt_.
vhep[index - 1][0]*
Unit::mm,
303 pProductionVertex = pProductionVertex + vertex;
314 kk_term_(&xsec, &xsecerr);
Class implementing n-dimensional random number generator from Gaussian distribution where the first c...
Eigen::VectorXd generate(double x0) const
generate random vector based on the provided first component x0
static const double speedOfLight
[cm/ns]
static EvtGenDatabasePDG * Instance()
Instance method that loads the EvtGen table.
Helper class for setting additional TParticlePDG members and storing the ones it doesn't have yet.
int simulateEvent(MCParticleGraph &graph, const ConditionalGaussGenerator &lorentzGenerator, ROOT::Math::XYZVector vertex)
Simulate the events.
std::unordered_map< int, int > m_mapPythiaIDtoPDG
Map between PYTHIA id and PDG codes.
void term()
Terminate the generator.
int addParticles2Graph(MCParticleGraph &graph, ROOT::Math::XYZVector vertex)
Add particles to the MCParticleGraph.
int setup(const std::string &KKdefaultFileName, const std::string &tauinputFileName, const std::string &taudecaytableFileName, const std::string &KKMCOutputFileName)
Setup for KKMC and TAUOLA.
void updateGraphParticle(int, MCParticleGraph::GraphParticle *gParticle, ROOT::Math::XYZVector vertex)
Update the MCParticleGraph.
void set_beam_info(double Ecms0, double Ecms0Spread)
Setup for beams information.
static ROOT::Math::LorentzRotation cmsToLab(double bX, double bY, double bZ, double angleXZ, double angleYZ)
Return the LorentzRotation from CMS to LAB based on the following parameters.
Class to represent Particle data in graph.
Class to build, validate and sort a particle decay chain.
@ c_checkCyclic
Check for cyclic dependencies.
@ c_setDecayInfo
Set decay time and vertex.
size_t size() const
Return the number of particles in the graph.
void generateList(const std::string &name="", int options=c_setNothing)
Generates the MCParticle list and stores it in the StoreArray with the given name.
@ c_IsFSRPhoton
bit 7: Particle is from finial state radiation
@ c_Initial
bit 5: Particle is initial such as e+ or e- and not going to Geant4
@ c_IsPHOTOSPhoton
bit 8: Particle is an radiative photon from PHOTOS
@ c_PrimaryParticle
bit 0: Particle is primary particle.
@ c_IsVirtual
bit 4: Particle is virtual and not going to Geant4.
@ c_StableInGenerator
bit 1: Particle is stable, i.e., not decaying in the generator.
@ c_IsISRPhoton
bit 6: Particle is from initial state radiation
void setMass(float mass)
Set particle mass.
void addStatus(unsigned short int bitmask)
Add bitmask to current status.
bool hasStatus(unsigned short int bitmask) const
Return if specific status bit is set.
void setValidVertex(bool valid)
Set indication wether vertex and time information is valid or just default.
void setProductionVertex(const ROOT::Math::XYZVector &vertex)
Set production vertex position.
void setPDG(int pdg)
Set PDG code of the particle.
void set4Vector(const ROOT::Math::PxPyPzEVector &p4)
Sets the 4Vector of particle.
void setProductionTime(float time)
Set production time.
static const double mm
[millimeters]
GraphParticle & addParticle()
Add new particle to the graph.
Abstract base class for different kinds of events.
int jmohep[nmxhep][2]
parent particles.
int isthep[nmxhep]
status code.
double vhep[nmxhep][4]
vertex [mm].
int jdahep[nmxhep][2]
childreen particles.
double phep[nmxhep][5]
four-momentum, mass [GeV].
int idhep[nmxhep]
particle ident KF.
int nhep
number of particles.