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();
156 if(
std::abs(pdg) == 9900015) status = 3;
167 LogDebug(
"SimG4CoreGenerator") <<
"GenVertex barcode = " << (*vitr)->barcode()
168 <<
" selected for GenParticle barcode = " << (*pitr)->barcode();
174 else if (status == 2) {
175 if ((*pitr)->end_vertex() !=
nullptr) {
176 double xx = (*pitr)->end_vertex()->position().x();
177 double yy = (*pitr)->end_vertex()->position().y();
178 double r_dd = xx * xx + yy *
yy;
183 <<
"GenVertex barcode = " << (*vitr)->barcode()
184 <<
" selected for GenParticle barcode = " << (*pitr)->barcode() <<
" radius = " <<
std::sqrt(r_dd);
202 double x1 = (*vitr)->position().x() * mm;
203 double y1 = (*vitr)->position().y() * mm;
204 double z1 = (*vitr)->position().z() * mm;
205 double t1 = (*vitr)->position().t() * mm / c_light;
207 G4PrimaryVertex *g4vtx =
new G4PrimaryVertex(x1, y1, z1, t1);
210 int status = (*pitr)->status();
211 int pdg = (*pitr)->pdg_id();
212 bool hasDecayVertex = (
nullptr != (*pitr)->end_vertex()) ?
true :
false;
219 <<
" Skiped GenParticle barcode= " << (*pitr)->barcode() <<
" PDGid= " << pdg <<
" status= " << status
221 <<
" isInTheList: " << isInTheList <<
" hasDecayVertex: " << hasDecayVertex;
227 <<
"Generator: pdg= " << pdg <<
" status= " << status <<
" hasPreDefinedDecay: " << hasDecayVertex
229 <<
" isInTheList: " <<
IsInTheFilterList(pdg) <<
"\n (x,y,z,t): (" << x1 <<
"," << y1 <<
"," << z1
233 status = hasDecayVertex ? 2 : 1;
237 if (2 == status && !hasDecayVertex) {
238 edm::LogWarning(
"SimG4CoreGenerator: in event ") << g4evt->GetEventID() <<
" a particle " 240 <<
" has status=2 but has no decay vertex, so will be fully " 245 if(
std::abs(pdg) == 9900015) status = 3;
250 double decay_length = 0.0;
252 x2 = (*pitr)->end_vertex()->position().x();
253 y2 = (*pitr)->end_vertex()->position().y();
254 z2 = (*pitr)->end_vertex()->position().z();
255 decay_length =
std::sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1));
260 double px = (*pitr)->momentum().px();
261 double py = (*pitr)->momentum().py();
262 double pz = (*pitr)->momentum().pz();
263 double ptot =
std::sqrt(px * px + py * py + pz * pz);
272 const double minTan = 1.e-20;
279 double del = (zimpact - z1) / pz;
283 double rimpact2 = ximpact * ximpact + yimpact * yimpact;
286 LogDebug(
"SimG4CoreGenerator") <<
"Processing GenParticle barcode= " << (*pitr)->barcode() <<
" pdg= " << pdg
287 <<
" status= " << (*pitr)->status() <<
" st= " << status
288 <<
" rimpact(cm)= " <<
std::sqrt(rimpact2) / cm
289 <<
" zimpact(cm)= " << zimpact / cm <<
" ptot(GeV)= " << ptot
290 <<
" pz(GeV)= " << pz;
297 LogDebug(
"SimG4CoreGenerator") <<
"GenParticle barcode = " << (*pitr)->barcode() <<
" passed case 3";
307 double phi =
p.phi();
321 if (
std::abs(pz) >= minTan * ptot) {
322 if ((zi >=
Z_lmax) & (pz < 0.0)) {
324 }
else if ((zi <=
Z_lmin) & (pz > 0.0)) {
333 double del = (zi - z1) / pz;
347 LogDebug(
"SimG4CoreGenerator") <<
"GenParticle barcode = " << (*pitr)->barcode() <<
" passed case 1";
355 LogDebug(
"SimG4CoreGenerator") <<
"GenParticle barcode = " << (*pitr)->barcode() <<
" passed case 2" 356 <<
" decay_length(cm)= " << decay_length / cm;
360 G4PrimaryParticle *g4prim =
new G4PrimaryParticle(pdg, px *
GeV, py * GeV, pz * GeV);
362 if (g4prim->GetG4code() !=
nullptr) {
363 g4prim->SetMass(g4prim->GetG4code()->GetPDGMass());
364 double charge = g4prim->GetG4code()->GetPDGCharge();
371 g4prim->SetCharge(charge);
377 setGenId(g4prim, (*pitr)->barcode());
384 g4vtx->SetPrimary(g4prim);
385 edm::LogVerbatim(
"SimG4CoreGenerator") <<
"Generator: new particle pdg= " << pdg <<
" Ptot(GeV/c)= " << ptot
386 <<
" Pt= " <<
std::sqrt(px * px + py * py);
392 g4evt->AddPrimaryVertex(g4vtx);
399 G4PrimaryVertex *g4vtx =
new G4PrimaryVertex(0.0, 0.0, 0.0, 0.0);
402 g4evt->AddPrimaryVertex(g4vtx);
410 LogDebug(
"SimG4CoreGenerator") <<
"Special case of long decay length \n" 411 <<
"Assign daughters with to mother with decaylength=" << decaylength / cm <<
" cm";
416 double proper_time = decaylength / (
p.Beta() *
p.Gamma() * c_light);
417 g4p->SetProperTime(proper_time);
420 LogDebug(
"SimG4CoreGenerator") <<
" px= " <<
p.px() <<
" py= " <<
p.py() <<
" pz= " <<
p.pz() <<
" e= " <<
p.e()
421 <<
" beta= " <<
p.Beta() <<
" gamma= " <<
p.Gamma()
422 <<
" Proper time= " << proper_time / ns <<
" ns";
427 double x1 = vp->end_vertex()->position().x();
428 double y1 = vp->end_vertex()->position().y();
429 double z1 = vp->end_vertex()->position().z();
431 for (HepMC::GenVertex::particle_iterator vpdec = vp->end_vertex()->particles_begin(
HepMC::children);
436 (*vpdec)->momentum().px(), (*vpdec)->momentum().py(), (*vpdec)->momentum().pz(), (*vpdec)->momentum().e());
439 G4PrimaryParticle *g4daught =
440 new G4PrimaryParticle((*vpdec)->pdg_id(), pdec.x() *
GeV, pdec.y() *
GeV, pdec.z() *
GeV);
442 if (g4daught->GetG4code() !=
nullptr) {
443 g4daught->SetMass(g4daught->GetG4code()->GetPDGMass());
444 g4daught->SetCharge(g4daught->GetG4code()->GetPDGCharge());
449 setGenId(g4daught, (*vpdec)->barcode());
452 LogDebug(
"SimG4CoreGenerator") <<
"Assigning a " << (*vpdec)->pdg_id() <<
" as daughter of a " << vp->pdg_id();
453 if ((*vpdec)->status() == 2 && (*vpdec)->end_vertex() !=
nullptr) {
454 double x2 = (*vpdec)->end_vertex()->position().x();
455 double y2 = (*vpdec)->end_vertex()->position().y();
456 double z2 = (*vpdec)->end_vertex()->position().z();
457 double dd =
std::sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
460 (*vpdec)->set_status(1000 + (*vpdec)->status());
461 g4p->SetDaughter(g4daught);
471 double ptot = p.mag();
477 if (ptot < pz + 1.
e-10) {
481 double eta = 0.5 * G4Log((ptot + pz) / (ptot - pz));
488 double phi = p.phi();
495 LogDebug(
"SimG4CoreGenerator") <<
"Generator ptot(GeV)= " << ptot / GeV <<
" eta= " << p.eta()
496 <<
" phi= " << p.phi() <<
" Flag= " <<
flag;
503 return ((pdgid >= 1000000 && pdgid < 4000000 && pdgid != 3000022) ||
514 int charge = pid.threeCharge();
515 return ((charge == 0) && (pdgid >= 1000000 && pdgid < 1000040))
532 for (HepMC::GenEvent::particle_const_iterator it = evt->particles_begin(); it != evt->particles_end(); ++it) {
535 int g_status = gp->status();
538 int g_id = gp->pdg_id();
539 G4PrimaryParticle *g4p =
540 new G4PrimaryParticle(g_id, gp->momentum().px() *
GeV, gp->momentum().py() *
GeV, gp->momentum().pz() *
GeV);
541 if (g4p->GetG4code() !=
nullptr) {
542 g4p->SetMass(g4p->GetG4code()->GetPDGMass());
543 g4p->SetCharge(g4p->GetG4code()->GetPDGCharge());
547 G4PrimaryVertex *
v =
new G4PrimaryVertex(gp->production_vertex()->position().x() * mm,
548 gp->production_vertex()->position().y() * mm,
549 gp->production_vertex()->position().z() * mm,
550 gp->production_vertex()->position().t() * mm / c_light);
552 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