9 #include "HepPDT/ParticleID.hh" 13 #include "G4HEPEvtParticle.hh" 14 #include "G4ParticleDefinition.hh" 15 #include "G4UnitsTable.hh" 16 #include "G4SystemOfUnits.hh" 17 #include "G4PhysicalConstants.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)),
50 double theRDecLenCut = p.
getParameter<
double>(
"RDecLenCut")*cm;
58 if ( p.
exists(
"PDGselection") ) {
60 getParameter<bool>(
"PDGfilterSel");
62 getParameter<std::vector< int > >(
"PDGfilter");
63 if(!pdgFilter.empty()) {
66 ss <<
"SimG4Core/Generator: ";
68 ss <<
" Selecting only PDG ID = ";
70 ss <<
" Filtering out PDG ID = ";
72 for (
unsigned int ii = 0;
ii < pdgFilter.size(); ++
ii) {
73 ss << pdgFilter[
ii] <<
" ";
88 <<
" Rdecaycut= " << theRDecLenCut/cm
89 <<
" cm; Zdecaycut= " << theDecLenCut/cm
91 <<
" cm; Z_hector = " <<
Z_hector <<
" cm\n" 95 <<
" ApplyLumiMonitorCuts: " <<
lumi;
109 if ( *(evt->vertices_begin()) ==
nullptr ) {
110 std::stringstream ss;
111 ss <<
"SimG4Core/Generator: in event " << g4evt->GetEventID()
112 <<
" Corrupted Event - GenEvent with no vertex \n";
116 if (!evt->weights().empty()) {
119 for (
unsigned int iw=1; iw<evt->weights().size(); ++iw) {
122 if ( evt->weights()[iw] <= 0 )
break;
123 weight_ *= evt->weights()[iw] ;
127 if (
vtx_ !=
nullptr) {
delete vtx_; }
129 (*(evt->vertices_begin()))->position().y(),
130 (*(evt->vertices_begin()))->position().z(),
131 (*(evt->vertices_begin()))->position().t());
135 LogDebug(
"SimG4CoreGenerator") <<
"Primary Vertex = (" 141 unsigned int ng4vtx = 0;
143 for(HepMC::GenEvent::vertex_const_iterator vitr= evt->vertices_begin();
144 vitr != evt->vertices_end(); ++vitr ) {
151 HepMC::GenVertex::particle_iterator pitr;
159 int status = (*pitr)->status();
160 int pdg = (*pitr)->pdg_id();
180 <<
"GenVertex barcode = " << (*vitr)->barcode()
181 <<
" selected for GenParticle barcode = " << (*pitr)->barcode();
187 else if (status == 2) {
188 if ( (*pitr)->end_vertex() !=
nullptr ) {
189 double xx = (*pitr)->end_vertex()->position().x();
190 double yy = (*pitr)->end_vertex()->position().y();
191 double r_dd = xx*xx+yy*
yy;
195 <<
"GenVertex barcode = " << (*vitr)->barcode()
196 <<
" selected for GenParticle barcode = " 197 << (*pitr)->barcode() <<
" radius = " <<
std::sqrt(r_dd);
215 double x1 = (*vitr)->position().x()*mm;
216 double y1 = (*vitr)->position().y()*mm;
217 double z1 = (*vitr)->position().z()*mm;
218 double t1 = (*vitr)->position().t()*mm/c_light;
220 G4PrimaryVertex* g4vtx =
new G4PrimaryVertex(x1, y1, z1, t1);
225 int status = (*pitr)->status();
226 int pdg = (*pitr)->pdg_id();
227 bool hasDecayVertex = (
nullptr != (*pitr)->end_vertex()) ?
true :
false;
234 <<
" Skiped GenParticle barcode= " << (*pitr)->barcode()
236 <<
" status= " << status
239 <<
" isInTheList: " << isInTheList
240 <<
" hasDecayVertex: " << hasDecayVertex;
247 <<
" status= " << status
248 <<
" hasPreDefinedDecay: " << hasDecayVertex
254 status = hasDecayVertex ? 2 : 1;
258 if (2 == status && !hasDecayVertex) {
260 << g4evt->GetEventID()
263 <<
" has status=2 but has no decay vertex, so will be fully tracked by Geant4";
270 double decay_length = 0.0;
272 x2 = (*pitr)->end_vertex()->position().x();
273 y2 = (*pitr)->end_vertex()->position().y();
274 z2 = (*pitr)->end_vertex()->position().z();
275 decay_length =
std::sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+(z2-z1)*(z2-z1));
278 bool toBeAdded =
false;
279 double px = (*pitr)->momentum().px();
280 double py = (*pitr)->momentum().py();
281 double pz = (*pitr)->momentum().pz();
282 double ptot =
std::sqrt(px*px + py*py + pz*pz);
291 const double minTan = 1.e-20;
293 if(pz > 0.0) { zimpact =
Z_hector; }
295 double del = (zimpact - z1)/pz;
299 double rimpact2 = ximpact*ximpact + yimpact*yimpact;
302 <<
"Processing GenParticle barcode= " << (*pitr)->barcode()
304 <<
" status= " << (*pitr)->status()
306 <<
" rimpact(cm)= " <<
std::sqrt(rimpact2)/cm
307 <<
" zimpact(cm)= " << zimpact/cm
308 <<
" ptot(GeV)= " << ptot
309 <<
" pz(GeV)= " << pz;
317 <<
"GenParticle barcode = " << (*pitr)->barcode()
331 double phi =
p.phi();
347 if((zi >=
Z_lmax) & (pz < 0.0)) {
349 }
else if((zi <=
Z_lmin) & (pz > 0.0)) {
352 if(pz > 0) { zi =
Z_lmax; }
355 double del = (zi - z1)/pz;
369 <<
"GenParticle barcode = " << (*pitr)->barcode()
375 }
else if(2 == status &&
380 <<
"GenParticle barcode = " << (*pitr)->barcode()
382 <<
" decay_length(cm)= " << decay_length/cm;
386 G4PrimaryParticle* g4prim=
387 new G4PrimaryParticle(pdg, px*
GeV, py*GeV, pz*GeV);
389 if ( g4prim->GetG4code() !=
nullptr ){
390 g4prim->SetMass( g4prim->GetG4code()->GetPDGMass() );
391 double charge = g4prim->GetG4code()->GetPDGCharge();
399 g4prim->SetCharge(charge);
405 setGenId( g4prim, (*pitr)->barcode() );
411 if (
verbose > 1 ) g4prim->Print();
412 g4vtx->SetPrimary(g4prim);
416 if (
verbose > 1 ) g4vtx->Print();
417 g4evt->AddPrimaryVertex(g4vtx);
424 G4PrimaryVertex* g4vtx =
new G4PrimaryVertex(0.0, 0.0, 0.0, 0.0);
425 if (
verbose > 1 ) g4vtx->Print();
426 g4evt->AddPrimaryVertex(g4vtx);
438 <<
"Special case of long decay length \n" 439 <<
"Assign daughters with to mother with decaylength=" 440 << decaylength/cm <<
" cm";
443 vp->momentum().pz(), vp->momentum().e());
446 double proper_time = decaylength/(
p.Beta()*
p.Gamma()*c_light);
447 g4p->SetProperTime(proper_time);
450 LogDebug(
"SimG4CoreGenerator") <<
" px= "<<
p.px()
454 <<
" beta= "<<
p.Beta()
455 <<
" gamma= " <<
p.Gamma()
456 <<
" Proper time= " <<proper_time/ns <<
" ns";
461 double x1 = vp->end_vertex()->position().x();
462 double y1 = vp->end_vertex()->position().y();
463 double z1 = vp->end_vertex()->position().z();
465 for (HepMC::GenVertex::particle_iterator
471 (*vpdec)->momentum().py(),
472 (*vpdec)->momentum().pz(),
473 (*vpdec)->momentum().e());
476 G4PrimaryParticle * g4daught=
477 new G4PrimaryParticle((*vpdec)->pdg_id(), pdec.x()*
GeV,
478 pdec.y()*
GeV, pdec.z()*
GeV);
480 if ( g4daught->GetG4code() !=
nullptr )
482 g4daught->SetMass( g4daught->GetG4code()->GetPDGMass() ) ;
483 g4daught->SetCharge( g4daught->GetG4code()->GetPDGCharge() ) ;
488 setGenId( g4daught, (*vpdec)->barcode() );
491 <<
"Assigning a "<< (*vpdec)->pdg_id()
492 <<
" as daughter of a " << vp->pdg_id();
493 if ( (*vpdec)->status() == 2 && (*vpdec)->end_vertex() !=
nullptr)
495 double x2 = (*vpdec)->end_vertex()->position().x();
496 double y2 = (*vpdec)->end_vertex()->position().y();
497 double z2 = (*vpdec)->end_vertex()->position().z();
498 double dd =
std::sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
501 (*vpdec)->set_status(1000+(*vpdec)->status());
502 g4p->SetDaughter(g4daught);
504 if (
verbose > 1 ) g4daught->Print();
512 double ptot = p.mag();
518 if(ptot < pz + 1.
e-10) {
522 double eta = 0.5*G4Log((ptot + pz)/(ptot - pz));
529 double phi = p.phi();
536 <<
"Generator ptot(GeV)= " << ptot/GeV <<
" eta= " << p.eta()
537 <<
" phi= " << p.phi() <<
" Flag= " <<
flag;
545 return ((pdgid >= 1000000 && pdgid < 4000000) ||
556 int charge = pid.threeCharge();
557 return ((charge==0) && (pdgid >= 1000000 && pdgid < 1000040))
571 for(HepMC::GenEvent::particle_const_iterator it = evt->particles_begin();
572 it != evt->particles_end(); ++it ) {
575 int g_status = gp->status();
578 int g_id = gp->pdg_id();
579 G4PrimaryParticle * g4p =
580 new G4PrimaryParticle(g_id,gp->momentum().px()*
GeV,
581 gp->momentum().py()*
GeV,
582 gp->momentum().pz()*
GeV);
583 if (g4p->GetG4code() !=
nullptr) {
584 g4p->SetMass(g4p->GetG4code()->GetPDGMass());
585 g4p->SetCharge(g4p->GetG4code()->GetPDGCharge());
589 G4PrimaryVertex *
v =
590 new G4PrimaryVertex(gp->production_vertex()->position().x()*mm,
591 gp->production_vertex()->position().y()*mm,
592 gp->production_vertex()->position().z()*mm,
593 gp->production_vertex()->position().t()*mm/c_light);
595 g4evt->AddPrimaryVertex(v);
596 if(
verbose > 0) { v->Print(); }
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