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(0 < pdgFilter.size()) {
65 for (
unsigned int ii = 0;
ii < pdgFilter.size(); ++
ii) {
68 <<
" *** Selecting only PDG ID = " << pdgFilter[
ii];
71 <<
" *** Filtering out PDG ID = " << pdgFilter[
ii];
86 <<
" Rdecaycut= " << theRDecLenCut/cm
87 <<
" cm; Zdecaycut= " << theDecLenCut/cm
89 <<
" cm; Z_hector = " <<
Z_hector <<
" cm\n" 93 <<
" ApplyLumiMonitorCuts: " <<
lumi;
105 HepMC::GenEvent *evt=
new HepMC::GenEvent(*evt_orig);
107 if ( *(evt->vertices_begin()) ==
nullptr ) {
108 throw SimG4Exception(
"SimG4CoreGenerator: Corrupted Event - GenEvent with no vertex");
111 if (evt->weights().size() > 0) {
114 for (
unsigned int iw=1; iw<evt->weights().size(); ++iw) {
117 if ( evt->weights()[iw] <= 0 )
break;
118 weight_ *= evt->weights()[iw] ;
122 if (
vtx_ !=
nullptr) {
delete vtx_; }
124 (*(evt->vertices_begin()))->position().y(),
125 (*(evt->vertices_begin()))->position().z(),
126 (*(evt->vertices_begin()))->position().t());
130 LogDebug(
"SimG4CoreGenerator") <<
"Primary Vertex = (" 136 unsigned int ng4vtx = 0;
138 for(HepMC::GenEvent::vertex_const_iterator vitr= evt->vertices_begin();
139 vitr != evt->vertices_end(); ++vitr ) {
146 HepMC::GenVertex::particle_iterator pitr;
154 int status = (*pitr)->status();
168 <<
"GenVertex barcode = " << (*vitr)->barcode()
169 <<
" selected for GenParticle barcode = " << (*pitr)->barcode();
175 else if (status == 2) {
176 if ( (*pitr)->end_vertex() != 0 ) {
177 double xx = (*pitr)->end_vertex()->position().x();
178 double yy = (*pitr)->end_vertex()->position().y();
179 double r_dd = xx*xx+yy*
yy;
183 <<
"GenVertex barcode = " << (*vitr)->barcode()
184 <<
" selected for GenParticle barcode = " 185 << (*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);
219 <<
"Skip GenParticle barcode = " << (*pitr)->barcode()
220 <<
" PDG Id = " << (*pitr)->pdg_id();
228 double decay_length = 0.0;
229 int status = (*pitr)->status();
236 if (1 == status || 2 == status) {
240 if ( !(*pitr)->end_vertex() ) {
243 x2 = (*pitr)->end_vertex()->position().x();
244 y2 = (*pitr)->end_vertex()->position().y();
245 z2 = (*pitr)->end_vertex()->position().z();
247 std::sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+(z2-z1)*(z2-z1));
251 bool toBeAdded =
false;
252 double px = (*pitr)->momentum().px();
253 double py = (*pitr)->momentum().py();
254 double pz = (*pitr)->momentum().pz();
255 double ptot =
std::sqrt(px*px + py*py + pz*pz);
264 const double minTan = 1.e-20;
265 if(fabs(z1) <
Z_hector && fabs(pz) >= minTan*ptot) {
266 if(pz > 0.0) { zimpact =
Z_hector; }
268 double del = (zimpact - z1)/pz;
272 double rimpact2 = ximpact*ximpact + yimpact*yimpact;
275 <<
"Processing GenParticle barcode= " << (*pitr)->barcode()
276 <<
" pdg= " << (*pitr)->
pdg_id()
277 <<
" status= " << (*pitr)->status()
279 <<
" rimpact(cm)= " <<
std::sqrt(rimpact2)/cm
280 <<
" zimpact(cm)= " << zimpact/cm
281 <<
" ptot(GeV)= " << ptot
282 <<
" pz(GeV)= " << pz;
290 <<
"GenParticle barcode = " << (*pitr)->barcode()
304 double phi =
p.phi();
319 if(fabs(pz) >= minTan*ptot) {
320 if((zi >=
Z_lmax) & (pz < 0.0)) {
322 }
else if((zi <=
Z_lmin) & (pz > 0.0)) {
325 if(pz > 0) { zi =
Z_lmax; }
328 double del = (zi - z1)/pz;
342 <<
"GenParticle barcode = " << (*pitr)->barcode()
348 }
else if(2 == status &&
353 <<
"GenParticle barcode = " << (*pitr)->barcode()
355 <<
" decay_length(cm)= " << decay_length/cm;
359 G4int pdgcode= (*pitr)->
pdg_id();
360 G4PrimaryParticle* g4prim=
361 new G4PrimaryParticle(pdgcode, px*
GeV, py*GeV, pz*GeV);
363 if ( g4prim->GetG4code() !=
nullptr ){
364 g4prim->SetMass( g4prim->GetG4code()->GetPDGMass() );
365 double charge = g4prim->GetG4code()->GetPDGCharge();
373 g4prim->SetCharge(charge);
379 setGenId( g4prim, (*pitr)->barcode() );
385 if (
verbose > 1 ) g4prim->Print();
386 g4vtx->SetPrimary(g4prim);
390 if (
verbose > 1 ) g4vtx->Print();
391 g4evt->AddPrimaryVertex(g4vtx);
398 G4PrimaryVertex* g4vtx =
new G4PrimaryVertex(0.0, 0.0, 0.0, 0.0);
399 if (
verbose > 1 ) g4vtx->Print();
400 g4evt->AddPrimaryVertex(g4vtx);
412 <<
"Special case of long decay length \n" 413 <<
"Assign daughters with to mother with decaylength=" 414 << decaylength/cm <<
" cm";
417 vp->momentum().pz(), vp->momentum().e());
420 double proper_time = decaylength/(
p.Beta()*
p.Gamma()*c_light);
421 g4p->SetProperTime(proper_time);
424 LogDebug(
"SimG4CoreGenerator") <<
" px= "<<
p.px()
428 <<
" beta= "<<
p.Beta()
429 <<
" gamma= " <<
p.Gamma()
430 <<
" Proper time= " <<proper_time/ns <<
" ns";
435 double x1 = vp->end_vertex()->position().x();
436 double y1 = vp->end_vertex()->position().y();
437 double z1 = vp->end_vertex()->position().z();
439 for (HepMC::GenVertex::particle_iterator
445 (*vpdec)->momentum().py(),
446 (*vpdec)->momentum().pz(),
447 (*vpdec)->momentum().e());
450 G4PrimaryParticle * g4daught=
451 new G4PrimaryParticle((*vpdec)->pdg_id(), pdec.x()*
GeV,
452 pdec.y()*
GeV, pdec.z()*
GeV);
454 if ( g4daught->GetG4code() != 0 )
456 g4daught->SetMass( g4daught->GetG4code()->GetPDGMass() ) ;
457 g4daught->SetCharge( g4daught->GetG4code()->GetPDGCharge() ) ;
462 setGenId( g4daught, (*vpdec)->barcode() );
465 <<
"Assigning a "<< (*vpdec)->pdg_id()
466 <<
" as daughter of a " << vp->pdg_id();
467 if ( (*vpdec)->status() == 2 && (*vpdec)->end_vertex() !=
nullptr)
469 double x2 = (*vpdec)->end_vertex()->position().x();
470 double y2 = (*vpdec)->end_vertex()->position().y();
471 double z2 = (*vpdec)->end_vertex()->position().z();
472 double dd =
std::sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
475 (*vpdec)->set_status(1000+(*vpdec)->status());
476 g4p->SetDaughter(g4daught);
478 if (
verbose > 1 ) g4daught->Print();
486 double ptot = p.mag();
492 if(ptot < pz + 1.
e-10) {
496 double eta = 0.5*G4Log((ptot + pz)/(ptot - pz));
503 double phi = p.phi();
510 <<
"Generator ptot(GeV)= " << ptot/GeV <<
" eta= " << p.eta()
511 <<
" phi= " << p.phi() <<
" Flag= " <<
flag;
519 if ((pdgid >= 1000000 && pdgid < 4000000) ||
535 if ((charge==0) && (pdgid >= 1000000 && pdgid < 1000040))
548 for(HepMC::GenEvent::particle_const_iterator it = evt->particles_begin();
549 it != evt->particles_end(); ++it ) {
552 int g_status = gp->status();
555 int g_id = gp->pdg_id();
556 G4PrimaryParticle * g4p =
557 new G4PrimaryParticle(g_id,gp->momentum().px()*
GeV,
558 gp->momentum().py()*
GeV,
559 gp->momentum().pz()*
GeV);
560 if (g4p->GetG4code() != 0) {
561 g4p->SetMass(g4p->GetG4code()->GetPDGMass());
562 g4p->SetCharge(g4p->GetG4code()->GetPDGCharge());
566 G4PrimaryVertex *
v =
567 new G4PrimaryVertex(gp->production_vertex()->position().x()*mm,
568 gp->production_vertex()->position().y()*mm,
569 gp->production_vertex()->position().z()*mm,
570 gp->production_vertex()->position().t()*mm/c_light);
572 g4evt->AddPrimaryVertex(v);
573 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
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
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(HepMC::GenParticle *p) 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 isExoticNonDetectable(HepMC::GenParticle *p) const