9 #include "HepPDT/ParticleID.hh" 13 #include "G4HEPEvtParticle.hh" 15 #include "G4ParticleDefinition.hh" 16 #include "G4PhysicalConstants.hh" 17 #include "G4SystemOfUnits.hh" 18 #include "G4UnitsTable.hh" 25 : fPCuts(p.getParameter<
bool>(
"ApplyPCuts")),
26 fPtransCut(p.getParameter<
bool>(
"ApplyPtransCut")),
27 fEtaCuts(p.getParameter<
bool>(
"ApplyEtaCuts")),
28 fPhiCuts(p.getParameter<
bool>(
"ApplyPhiCuts")),
29 theMinPhiCut(p.getParameter<double>(
"MinPhiCut")),
30 theMaxPhiCut(p.getParameter<double>(
"MaxPhiCut")),
31 theMinEtaCut(p.getParameter<double>(
"MinEtaCut")),
32 theMaxEtaCut(p.getParameter<double>(
"MaxEtaCut")),
33 theMinPCut(p.getParameter<double>(
"MinPCut")),
34 theMaxPCut(p.getParameter<double>(
"MaxPCut")),
35 theEtaCutForHector(p.getParameter<double>(
"EtaCutForHector")),
36 verbose(p.getUntrackedParameter<
int>(
"Verbosity", 0)),
51 double theRDecLenCut = p.
getParameter<
double>(
"RDecLenCut") * cm;
61 if (p.
exists(
"PDGselection")) {
64 if (!pdgFilter.empty()) {
67 ss <<
"SimG4Core/Generator: ";
69 ss <<
" Selecting only PDG ID = ";
71 ss <<
" Filtering out PDG ID = ";
73 for (
unsigned int ii = 0;
ii < pdgFilter.size(); ++
ii) {
74 ss << pdgFilter[
ii] <<
" ";
87 edm::LogVerbatim(
"SimG4CoreGenerator") <<
"SimG4Core/Generator: Rdecaycut= " << theRDecLenCut / cm
88 <<
" cm; Zdecaycut= " << theDecLenCut / cm <<
"Z_min= " <<
Z_lmin / cm
89 <<
" cm; Z_max= " <<
Z_lmax <<
" cm; Z_hector = " <<
Z_hector <<
" cm\n" 90 <<
" ApplyCuts: " << fFiductialCuts
93 <<
" LumiMonitorCut: " <<
lumi;
104 if (*(evt->vertices_begin()) ==
nullptr) {
105 std::stringstream ss;
106 ss <<
"SimG4Core/Generator: in event " << g4evt->GetEventID() <<
" Corrupted Event - GenEvent with no vertex \n";
110 if (!evt->weights().empty()) {
112 for (
unsigned int iw = 1; iw < evt->weights().size(); ++iw) {
114 if (evt->weights()[iw] <= 0)
120 if (
vtx_ !=
nullptr) {
124 (*(evt->vertices_begin()))->position().y(),
125 (*(evt->vertices_begin()))->position().z(),
126 (*(evt->vertices_begin()))->position().t());
131 unsigned int ng4vtx = 0;
133 for (HepMC::GenEvent::vertex_const_iterator vitr = evt->vertices_begin(); vitr != evt->vertices_end(); ++vitr) {
139 HepMC::GenVertex::particle_iterator pitr;
146 int status = (*pitr)->status();
147 int pdg = (*pitr)->pdg_id();
166 LogDebug(
"SimG4CoreGenerator") <<
"GenVertex barcode = " << (*vitr)->barcode()
167 <<
" selected for GenParticle barcode = " << (*pitr)->barcode();
173 else if (status == 2) {
174 if ((*pitr)->end_vertex() !=
nullptr) {
175 double xx = (*pitr)->end_vertex()->position().x();
176 double yy = (*pitr)->end_vertex()->position().y();
177 double r_dd = xx * xx + yy *
yy;
182 <<
"GenVertex barcode = " << (*vitr)->barcode()
183 <<
" selected for GenParticle barcode = " << (*pitr)->barcode() <<
" radius = " <<
std::sqrt(r_dd);
201 double x1 = (*vitr)->position().x() * mm;
202 double y1 = (*vitr)->position().y() * mm;
203 double z1 = (*vitr)->position().z() * mm;
204 double t1 = (*vitr)->position().t() * mm / c_light;
206 G4PrimaryVertex *g4vtx =
new G4PrimaryVertex(x1, y1, z1, t1);
209 int status = (*pitr)->status();
210 int pdg = (*pitr)->pdg_id();
211 bool hasDecayVertex = (
nullptr != (*pitr)->end_vertex()) ?
true :
false;
218 <<
" Skiped GenParticle barcode= " << (*pitr)->barcode() <<
" PDGid= " << pdg <<
" status= " << status
220 <<
" isInTheList: " << isInTheList <<
" hasDecayVertex: " << hasDecayVertex;
226 <<
"Generator: pdg= " << pdg <<
" status= " << status <<
" hasPreDefinedDecay: " << hasDecayVertex
228 <<
" isInTheList: " <<
IsInTheFilterList(pdg) <<
"\n (x,y,z,t): (" << x1 <<
"," << y1 <<
"," << z1
232 status = hasDecayVertex ? 2 : 1;
236 if (2 == status && !hasDecayVertex) {
237 edm::LogWarning(
"SimG4CoreGenerator: in event ") << g4evt->GetEventID() <<
" a particle " 239 <<
" has status=2 but has no decay vertex, so will be fully " 247 double decay_length = 0.0;
249 x2 = (*pitr)->end_vertex()->position().x();
250 y2 = (*pitr)->end_vertex()->position().y();
251 z2 = (*pitr)->end_vertex()->position().z();
252 decay_length =
std::sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1));
257 double px = (*pitr)->momentum().px();
258 double py = (*pitr)->momentum().py();
259 double pz = (*pitr)->momentum().pz();
260 double ptot =
std::sqrt(px * px + py * py + pz * pz);
269 const double minTan = 1.e-20;
276 double del = (zimpact - z1) / pz;
280 double rimpact2 = ximpact * ximpact + yimpact * yimpact;
283 LogDebug(
"SimG4CoreGenerator") <<
"Processing GenParticle barcode= " << (*pitr)->barcode() <<
" pdg= " << pdg
284 <<
" status= " << (*pitr)->status() <<
" st= " << status
285 <<
" rimpact(cm)= " <<
std::sqrt(rimpact2) / cm
286 <<
" zimpact(cm)= " << zimpact / cm <<
" ptot(GeV)= " << ptot
287 <<
" pz(GeV)= " << pz;
294 LogDebug(
"SimG4CoreGenerator") <<
"GenParticle barcode = " << (*pitr)->barcode() <<
" passed case 3";
304 double phi =
p.phi();
318 if (
std::abs(pz) >= minTan * ptot) {
319 if ((zi >=
Z_lmax) & (pz < 0.0)) {
321 }
else if ((zi <=
Z_lmin) & (pz > 0.0)) {
330 double del = (zi - z1) / pz;
344 LogDebug(
"SimG4CoreGenerator") <<
"GenParticle barcode = " << (*pitr)->barcode() <<
" passed case 1";
352 LogDebug(
"SimG4CoreGenerator") <<
"GenParticle barcode = " << (*pitr)->barcode() <<
" passed case 2" 353 <<
" decay_length(cm)= " << decay_length / cm;
357 G4PrimaryParticle *g4prim =
new G4PrimaryParticle(pdg, px *
GeV, py * GeV, pz * GeV);
359 if (g4prim->GetG4code() !=
nullptr) {
360 g4prim->SetMass(g4prim->GetG4code()->GetPDGMass());
361 double charge = g4prim->GetG4code()->GetPDGCharge();
368 g4prim->SetCharge(charge);
374 setGenId(g4prim, (*pitr)->barcode());
381 g4vtx->SetPrimary(g4prim);
382 edm::LogVerbatim(
"SimG4CoreGenerator") <<
"Generator: new particle pdg= " << pdg <<
" Ptot(GeV/c)= " << ptot
383 <<
" Pt= " <<
std::sqrt(px * px + py * py);
389 g4evt->AddPrimaryVertex(g4vtx);
396 G4PrimaryVertex *g4vtx =
new G4PrimaryVertex(0.0, 0.0, 0.0, 0.0);
399 g4evt->AddPrimaryVertex(g4vtx);
407 LogDebug(
"SimG4CoreGenerator") <<
"Special case of long decay length \n" 408 <<
"Assign daughters with to mother with decaylength=" << decaylength / cm <<
" cm";
413 double proper_time = decaylength / (
p.Beta() *
p.Gamma() * c_light);
414 g4p->SetProperTime(proper_time);
417 LogDebug(
"SimG4CoreGenerator") <<
" px= " <<
p.px() <<
" py= " <<
p.py() <<
" pz= " <<
p.pz() <<
" e= " <<
p.e()
418 <<
" beta= " <<
p.Beta() <<
" gamma= " <<
p.Gamma()
419 <<
" Proper time= " << proper_time / ns <<
" ns";
424 double x1 = vp->end_vertex()->position().x();
425 double y1 = vp->end_vertex()->position().y();
426 double z1 = vp->end_vertex()->position().z();
428 for (HepMC::GenVertex::particle_iterator vpdec = vp->end_vertex()->particles_begin(
HepMC::children);
433 (*vpdec)->momentum().px(), (*vpdec)->momentum().py(), (*vpdec)->momentum().pz(), (*vpdec)->momentum().e());
436 G4PrimaryParticle *g4daught =
437 new G4PrimaryParticle((*vpdec)->pdg_id(), pdec.x() *
GeV, pdec.y() *
GeV, pdec.z() *
GeV);
439 if (g4daught->GetG4code() !=
nullptr) {
440 g4daught->SetMass(g4daught->GetG4code()->GetPDGMass());
441 g4daught->SetCharge(g4daught->GetG4code()->GetPDGCharge());
446 setGenId(g4daught, (*vpdec)->barcode());
449 LogDebug(
"SimG4CoreGenerator") <<
"Assigning a " << (*vpdec)->pdg_id() <<
" as daughter of a " << vp->pdg_id();
450 if ((*vpdec)->status() == 2 && (*vpdec)->end_vertex() !=
nullptr) {
451 double x2 = (*vpdec)->end_vertex()->position().x();
452 double y2 = (*vpdec)->end_vertex()->position().y();
453 double z2 = (*vpdec)->end_vertex()->position().z();
454 double dd =
std::sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
457 (*vpdec)->set_status(1000 + (*vpdec)->status());
458 g4p->SetDaughter(g4daught);
468 double ptot = p.mag();
474 if (ptot < pz + 1.
e-10) {
478 double eta = 0.5 * G4Log((ptot + pz) / (ptot - pz));
485 double phi = p.phi();
492 LogDebug(
"SimG4CoreGenerator") <<
"Generator ptot(GeV)= " << ptot / GeV <<
" eta= " << p.eta()
493 <<
" phi= " << p.phi() <<
" Flag= " <<
flag;
500 return ((pdgid >= 1000000 && pdgid < 4000000 && pdgid != 3000022) ||
511 int charge = pid.threeCharge();
512 return ((charge == 0) && (pdgid >= 1000000 && pdgid < 1000040))
529 for (HepMC::GenEvent::particle_const_iterator it = evt->particles_begin(); it != evt->particles_end(); ++it) {
532 int g_status = gp->status();
535 int g_id = gp->pdg_id();
536 G4PrimaryParticle *g4p =
537 new G4PrimaryParticle(g_id, gp->momentum().px() *
GeV, gp->momentum().py() *
GeV, gp->momentum().pz() *
GeV);
538 if (g4p->GetG4code() !=
nullptr) {
539 g4p->SetMass(g4p->GetG4code()->GetPDGMass());
540 g4p->SetCharge(g4p->GetG4code()->GetPDGCharge());
544 G4PrimaryVertex *
v =
new G4PrimaryVertex(gp->production_vertex()->position().x() * mm,
545 gp->production_vertex()->position().y() * mm,
546 gp->production_vertex()->position().z() * mm,
547 gp->production_vertex()->position().t() * mm / c_light);
549 g4evt->AddPrimaryVertex(v);
T getParameter(std::string const &) const
void setGenId(G4PrimaryParticle *p, int id) const
double theEtaCutForHector
void HepMC2G4(const HepMC::GenEvent *g, G4Event *e)
Generator(const edm::ParameterSet &p)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
bool isExoticNonDetectable(int pdgcode) const
void particleAssignDaughters(G4PrimaryParticle *p, HepMC::GenParticle *hp, double length)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
LumiMonitorFilter * fLumiFilter
Abs< T >::type abs(const T &t)
bool isExotic(int pdgcode) const
bool isGoodForLumiMonitor(const HepMC::GenParticle *) const
math::XYZTLorentzVector * vtx_
void nonBeamEvent2G4(const HepMC::GenEvent *g, G4Event *e)
bool particlePassesPrimaryCuts(const G4ThreeVector &p) const
std::vector< int > pdgFilter
bool IsInTheFilterList(int pdgcode) const