8#include "TClonesArray.h"
9#include "TLorentzVector.h"
10#include "TMCProcess.h"
17#include "EvtGen/EvtGen.hh"
18#include "EvtGenBase/EvtAbsRadCorr.hh"
19#include "EvtGenBase/EvtId.hh"
20#include "EvtGenBase/EvtMTRandomEngine.hh"
21#include "EvtGenBase/EvtPDL.hh"
22#include "EvtGenBase/EvtParticle.hh"
23#include "EvtGenBase/EvtParticleFactory.hh"
24#include "EvtGenBase/EvtRandom.hh"
25#include "EvtGenBase/EvtVector4R.hh"
26#include "EvtGenExternal/EvtExternalGenList.hh"
30 : TVirtualMCDecayer(),
61 UInt_t seed = gRandom->GetSeed();
64 TPythia8* pythia8 = TPythia8::Instance();
66 pythia8->Pythia8()->readString(Form(
"Random:seed = %u", seed));
67 pythia8->Pythia8()->readString(
"Random:setSeed = on");
68 pythia8->Pythia8()->init();
69 LOG(
debug) <<
"TEvtGenDecayer: Pythia8 RNG seeded with " << seed;
72 EvtRandomEngine* randomEngine =
new EvtMTRandomEngine(seed);
73 EvtRandom::setRandomEngine(randomEngine);
75 LOG(info) <<
"TEvtGenDecayer: Random engine initialized with seed " << seed;
78 std::string photonType(
"gamma");
79 bool useEvtGenRandom(
true);
80 bool convertPythiaCodes(
false);
81 std::string pythiaDir(
"");
83 EvtExternalGenList* externalGenList =
new EvtExternalGenList(
84 convertPythiaCodes, pythiaDir, photonType, useEvtGenRandom);
87 EvtAbsRadCorr* radCorrEngine = externalGenList->getPhotosModel();
89 LOG(info) <<
"TEvtGenDecayer: PHOTOS radiative corrections enabled";
91 LOG(warning) <<
"TEvtGenDecayer: PHOTOS not available, proceeding "
92 "without radiative corrections";
96 std::list<EvtDecayBase*> extraModels = externalGenList->getListOfModels();
100 radCorrEngine, &extraModels, 1,
false);
102 LOG(
debug) <<
"TEvtGenDecayer: EvtGen created with " << EvtPDL::entries()
103 <<
" particle entries";
105 LOG(info) <<
"TEvtGenDecayer: EvtGen initialized with decay file: "
110 <<
"TEvtGenDecayer: No EvtGen files specified, using Pythia8 only";
114 LOG(info) <<
"TEvtGenDecayer initialized - EvtGen: "
129 LOG(debug2) <<
"TEvtGenDecayer::Decay called for PDG " << pdg
130 <<
" (E=" << p->E() <<
", p=" << p->P() <<
")";
134 Bool_t evtGenAvailable = (
fEvtGen !=
nullptr);
136 LOG(debug1) <<
"UseEvtGenForParticle(" << pdg <<
") = " << useEvtGen
137 <<
", EvtGen available = " << evtGenAvailable;
139 if (useEvtGen && evtGenAvailable) {
140 LOG(
debug) <<
"Routing PDG " << pdg <<
" to EvtGen";
143 LOG(
debug) <<
"Routing PDG " << pdg <<
" to Pythia8 fallback";
151 LOG(debug2) <<
"UseEvtGenForParticle: Checking PDG " << pdg
152 <<
" against EvtGen particle list";
155 if (pdg == evtGenPdg) {
156 LOG(debug2) <<
"UseEvtGenForParticle: Match found - PDG " << pdg
157 <<
" should use EvtGen";
162 LOG(
debug) <<
"UseEvtGenForParticle: PDG " << pdg
163 <<
" not in EvtGen particle list, falling back to Pythia8";
177 LOG(debug1) <<
"DecayWithEvtGen: Decaying PDG " << pdg <<
" with EvtGen";
181 EvtVector4R p4(p->E(), p->Px(), p->Py(), p->Pz());
184 EvtId evtId = EvtPDL::evtIdFromStdHep(pdg);
187 if (evtId.getId() < 0 ||
188 static_cast<size_t>(evtId.getId()) >= EvtPDL::entries()) {
189 LOG(warning) <<
"TEvtGenDecayer: Invalid EvtId for PDG " << pdg
190 <<
" (EvtId: " << evtId.getId()
191 <<
"), falling back to Pythia8";
197 EvtParticle* parent = EvtParticleFactory::particleFactory(evtId, p4);
201 fEvtGen->generateDecay(parent);
207 <<
"TEvtGenDecayer: EvtGen decay products converted and stored";
210 parent->deleteTree();
212 LOG(warning) <<
"TEvtGenDecayer: Could not create EvtParticle for PDG "
217 }
catch (
const std::exception& e) {
218 LOG(error) <<
"TEvtGenDecayer: EvtGen exception for PDG " << pdg <<
": "
232 int nDaughters = parent->getNDaug();
233 LOG(debug2) <<
"ConvertEvtGenDecay: Converting " << nDaughters
234 <<
" daughter particles";
237 for (
int i = 0; i < nDaughters; i++) {
238 EvtParticle* daughter = parent->getDaug(i);
239 EvtVector4R p4 = daughter->getP4();
240 int pdgId = EvtPDL::getStdHep(daughter->getId());
243 TParticle* particle =
new ((*fEvtGenProducts)[i]) TParticle();
244 particle->SetPdgCode(pdgId);
245 particle->SetMomentum(p4.get(1), p4.get(2), p4.get(3),
247 particle->SetProductionVertex(0, 0, 0, 0);
248 particle->SetStatusCode(1);
250 LOG(debug2) <<
" Daughter " << i <<
": PDG=" << pdgId
251 <<
", E=" << p4.get(0) <<
", px=" << p4.get(1)
252 <<
", py=" << p4.get(2) <<
", pz=" << p4.get(3);
255 LOG(debug1) <<
"ConvertEvtGenDecay: Stored "
262 LOG(debug1) <<
"DecayWithPythia8: Handling PDG " << pdg <<
" with Pythia8";
277 LOG(debug1) <<
"ImportParticles: Returning "
283 for (
int i = 0; i < nParticles; i++) {
284 TParticle* srcParticle =
static_cast<TParticle*
>(
fEvtGenProducts->At(i));
285 new ((*particles)[i]) TParticle(*srcParticle);
293 LOG(debug1) <<
"ImportParticles: Delegating to Pythia8";
314 LOG(info) <<
"TEvtGenDecayer: Added PDG " << pdg <<
" to EvtGen particle list"
std::vector< Int_t > fEvtGenParticles
void ReadDecayTable() override
Int_t ImportParticles(TClonesArray *particles) override
void SetForceDecay(Int_t type) override
void DecayWithPythia8(Int_t pdg, TLorentzVector *p)
void AddEvtGenParticle(Int_t pdg)
void SetEvtGenParticleFile(const char *particleFile)
Float_t GetLifetime(Int_t kf) override
TClonesArray * fEvtGenProducts
void Decay(Int_t pdg, TLorentzVector *p) override
void ForceDecay() override
Float_t GetPartialBranchingRatio(Int_t ipart) override
void ConvertEvtGenDecay(EvtParticle *parent)
void SetEvtGenDecayFile(const char *decayFile)
~TEvtGenDecayer() override
void DecayWithEvtGen(Int_t pdg, TLorentzVector *p)
TPythia8Decayer * fPythia8Decayer
Bool_t UseEvtGenForParticle(Int_t pdg)