40 #include <EvtGen/EvtGen.hh>
41 #include <EvtGenBase/EvtAbsRadCorr.hh>
42 #include <EvtGenBase/EvtHepMCEvent.hh>
43 #include <EvtGenBase/EvtId.hh>
44 #include <EvtGenBase/EvtPDL.hh>
45 #include <EvtGenBase/EvtParticle.hh>
46 #include <EvtGenBase/EvtParticleFactory.hh>
47 #include <EvtGenBase/EvtRandom.hh>
48 #include <EvtGenBase/EvtVector4R.hh>
49 #include <EvtGenExternal/EvtExternalGenList.hh>
51 #include <HepMC3/Attribute.h>
52 #include <HepMC3/FourVector.h>
53 #include <HepMC3/GenEvent.h>
54 #include <HepMC3/GenParticle.h>
55 #include <HepMC3/GenParticle_fwd.h>
56 #include <HepMC3/GenVertex.h>
57 #include <HepMC3/GenVertex_fwd.h>
58 #include <HepMC3/Print.h>
60 #include <Geant4/G4DecayProducts.hh>
61 #include <Geant4/G4DynamicParticle.hh>
62 #include <Geant4/G4ParticleDefinition.hh>
63 #include <Geant4/G4ParticleTable.hh>
64 #include <Geant4/G4String.hh>
65 #include <Geant4/G4SystemOfUnits.hh>
66 #include <Geant4/G4ThreeVector.hh>
67 #include <Geant4/G4Track.hh>
68 #include <Geant4/G4Types.hh>
69 #include <Geant4/G4VExtDecayer.hh>
84 : G4VExtDecayer(
"G4EvtGenDecayer")
96 const char* offline_main = getenv(
"OFFLINE_MAIN");
103 string decay =
string(offline_main) +
"/share/EvtGen/DECAY.DEC";
104 string evt =
string(offline_main) +
"/share/EvtGen/evt.pdl";
127 G4int pdgEncoding = ParPDGID;
128 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
129 G4ParticleDefinition* particleDefinition =
nullptr;
130 if (pdgEncoding != 0)
132 particleDefinition = particleTable->FindParticle(pdgEncoding);
135 return particleDefinition;
144 G4ThreeVector
momentum = track.GetMomentum();
145 G4double etot = track.GetDynamicParticle()->GetTotalEnergy();
147 G4ParticleDefinition* particleDef = track.GetDefinition();
148 G4int pdgEncoding = particleDef->GetPDGEncoding();
150 EvtVector4R p_init(etot /
GeV, momentum.x() /
GeV, momentum.y() /
GeV, momentum.z() /
GeV);
152 EvtId parentID = EvtPDL::evtIdFromLundKC(pdgEncoding);
154 auto mParticle = EvtParticleFactory::particleFactory(parentID, p_init);
156 mEvtGen->generateDecay(mParticle);
158 EvtHepMCEvent theEvent;
160 theEvent.constructEvent(mParticle);
162 HepMC3::GenEvent* evt = theEvent.getEvent();
164 G4DecayProducts* decayProducts =
new G4DecayProducts(*(track.GetDynamicParticle()));
166 std::stack<HepMC3::GenParticlePtr>
stack;
168 auto part = evt->particles()[0];
170 if (part->pdg_id() != pdgEncoding)
172 std::cout <<
"Issue Found: The first particle in the decay chain is NOT the incoming particle decayed by EvtGen" << std::endl;
177 while (!stack.empty())
182 for (
const auto& children :
particle->children())
184 float EvtWidth = 9999;
185 int pdg = children->pdg_id();
188 if (EvtPDL::evtIdFromLundKC(pdg).getId() != -1)
190 EvtWidth = EvtPDL::getWidth(EvtPDL::evtIdFromLundKC(pdg)) * 1000000;
195 bool SameVtxPos =
true;
197 if (children->production_vertex()->position().x() !=
particle->end_vertex()->position().x() || children->production_vertex()->position().y() !=
particle->end_vertex()->position().y() || children->production_vertex()->position().z() !=
particle->end_vertex()->position().z() || children->production_vertex()->position().t() !=
particle->end_vertex()->position().t())
203 std::cout <<
"Issue Found: in this vertex, particles pushed to GEANT have different production positions, need to check and understand why!!!" << std::endl;
204 std::cout <<
"This is due to the particle PDGID: " << children->pdg_id() <<
" from the decay vertex of the parent particle:" <<
particle->pdg_id() << std::endl;
205 std::cout <<
"Here is the Event Content" << std::endl;
206 const HepMC3::GenEvent& CheckEvent = *evt;
207 HepMC3::Print::content(CheckEvent);
210 G4ThreeVector G4Mom = G4ThreeVector(children->momentum().px() *
GeV, children->momentum().py() *
GeV, children->momentum().pz() *
GeV);
211 G4DynamicParticle* dynamicParticle =
new G4DynamicParticle(particleDefinition, G4Mom);
217 std::cout <<
" G4 particle name: "
218 << dynamicParticle->GetDefinition()->GetParticleName()
222 decayProducts->PushProducts(dynamicParticle);
226 std::cout <<
"Dynamical particle to be pushed from EvtGen to GEANT 4 is not properly defined: need to check why this happens!" << std::endl;
232 stack.push(children);
238 mParticle->deleteTree();
239 return decayProducts;
246 mEvtGen->readUDecay(decayTable, useXml);