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();
169 if(
std::abs(pdg) == 9900015) status = 3;
181 <<
"GenVertex barcode = " << (*vitr)->barcode()
182 <<
" selected for GenParticle barcode = " << (*pitr)->barcode();
188 else if (status == 2) {
189 if ( (*pitr)->end_vertex() !=
nullptr ) {
190 double xx = (*pitr)->end_vertex()->position().x();
191 double yy = (*pitr)->end_vertex()->position().y();
192 double r_dd = xx*xx+yy*
yy;
196 <<
"GenVertex barcode = " << (*vitr)->barcode()
197 <<
" selected for GenParticle barcode = " 198 << (*pitr)->barcode() <<
" radius = " <<
std::sqrt(r_dd);
216 double x1 = (*vitr)->position().x()*mm;
217 double y1 = (*vitr)->position().y()*mm;
218 double z1 = (*vitr)->position().z()*mm;
219 double t1 = (*vitr)->position().t()*mm/c_light;
221 G4PrimaryVertex* g4vtx =
new G4PrimaryVertex(x1, y1, z1, t1);
226 int status = (*pitr)->status();
227 int pdg = (*pitr)->pdg_id();
228 bool hasDecayVertex = (
nullptr != (*pitr)->end_vertex()) ?
true :
false;
235 <<
" Skiped GenParticle barcode= " << (*pitr)->barcode()
237 <<
" status= " << status
240 <<
" isInTheList: " << isInTheList
241 <<
" hasDecayVertex: " << hasDecayVertex;
248 <<
" status= " << status
249 <<
" hasPreDefinedDecay: " << hasDecayVertex
255 status = hasDecayVertex ? 2 : 1;
259 if (2 == status && !hasDecayVertex) {
261 << g4evt->GetEventID()
264 <<
" has status=2 but has no decay vertex, so will be fully tracked by Geant4";
268 if(
std::abs(pdg) == 9900015) status = 3;
273 double decay_length = 0.0;
275 x2 = (*pitr)->end_vertex()->position().x();
276 y2 = (*pitr)->end_vertex()->position().y();
277 z2 = (*pitr)->end_vertex()->position().z();
278 decay_length =
std::sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+(z2-z1)*(z2-z1));
281 bool toBeAdded =
false;
282 double px = (*pitr)->momentum().px();
283 double py = (*pitr)->momentum().py();
284 double pz = (*pitr)->momentum().pz();
285 double ptot =
std::sqrt(px*px + py*py + pz*pz);
294 const double minTan = 1.e-20;
296 if(pz > 0.0) { zimpact =
Z_hector; }
298 double del = (zimpact - z1)/pz;
302 double rimpact2 = ximpact*ximpact + yimpact*yimpact;
305 <<
"Processing GenParticle barcode= " << (*pitr)->barcode()
307 <<
" status= " << (*pitr)->status()
309 <<
" rimpact(cm)= " <<
std::sqrt(rimpact2)/cm
310 <<
" zimpact(cm)= " << zimpact/cm
311 <<
" ptot(GeV)= " << ptot
312 <<
" pz(GeV)= " << pz;
320 <<
"GenParticle barcode = " << (*pitr)->barcode()
334 double phi =
p.phi();
350 if((zi >=
Z_lmax) & (pz < 0.0)) {
352 }
else if((zi <=
Z_lmin) & (pz > 0.0)) {
355 if(pz > 0) { zi =
Z_lmax; }
358 double del = (zi - z1)/pz;
372 <<
"GenParticle barcode = " << (*pitr)->barcode()
378 }
else if(2 == status &&
383 <<
"GenParticle barcode = " << (*pitr)->barcode()
385 <<
" decay_length(cm)= " << decay_length/cm;
389 G4PrimaryParticle* g4prim=
390 new G4PrimaryParticle(pdg, px*
GeV, py*GeV, pz*GeV);
392 if ( g4prim->GetG4code() !=
nullptr ){
393 g4prim->SetMass( g4prim->GetG4code()->GetPDGMass() );
394 double charge = g4prim->GetG4code()->GetPDGCharge();
402 g4prim->SetCharge(charge);
408 setGenId( g4prim, (*pitr)->barcode() );
414 if (
verbose > 1 ) g4prim->Print();
415 g4vtx->SetPrimary(g4prim);
419 if (
verbose > 1 ) g4vtx->Print();
420 g4evt->AddPrimaryVertex(g4vtx);
427 G4PrimaryVertex* g4vtx =
new G4PrimaryVertex(0.0, 0.0, 0.0, 0.0);
428 if (
verbose > 1 ) g4vtx->Print();
429 g4evt->AddPrimaryVertex(g4vtx);
441 <<
"Special case of long decay length \n" 442 <<
"Assign daughters with to mother with decaylength=" 443 << decaylength/cm <<
" cm";
446 vp->momentum().pz(), vp->momentum().e());
449 double proper_time = decaylength/(
p.Beta()*
p.Gamma()*c_light);
450 g4p->SetProperTime(proper_time);
453 LogDebug(
"SimG4CoreGenerator") <<
" px= "<<
p.px()
457 <<
" beta= "<<
p.Beta()
458 <<
" gamma= " <<
p.Gamma()
459 <<
" Proper time= " <<proper_time/ns <<
" ns";
464 double x1 = vp->end_vertex()->position().x();
465 double y1 = vp->end_vertex()->position().y();
466 double z1 = vp->end_vertex()->position().z();
468 for (HepMC::GenVertex::particle_iterator
474 (*vpdec)->momentum().py(),
475 (*vpdec)->momentum().pz(),
476 (*vpdec)->momentum().e());
479 G4PrimaryParticle * g4daught=
480 new G4PrimaryParticle((*vpdec)->pdg_id(), pdec.x()*
GeV,
481 pdec.y()*
GeV, pdec.z()*
GeV);
483 if ( g4daught->GetG4code() !=
nullptr )
485 g4daught->SetMass( g4daught->GetG4code()->GetPDGMass() ) ;
486 g4daught->SetCharge( g4daught->GetG4code()->GetPDGCharge() ) ;
491 setGenId( g4daught, (*vpdec)->barcode() );
494 <<
"Assigning a "<< (*vpdec)->pdg_id()
495 <<
" as daughter of a " << vp->pdg_id();
496 if ( (*vpdec)->status() == 2 && (*vpdec)->end_vertex() !=
nullptr)
498 double x2 = (*vpdec)->end_vertex()->position().x();
499 double y2 = (*vpdec)->end_vertex()->position().y();
500 double z2 = (*vpdec)->end_vertex()->position().z();
501 double dd =
std::sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
504 (*vpdec)->set_status(1000+(*vpdec)->status());
505 g4p->SetDaughter(g4daught);
507 if (
verbose > 1 ) g4daught->Print();
515 double ptot = p.mag();
521 if(ptot < pz + 1.
e-10) {
525 double eta = 0.5*G4Log((ptot + pz)/(ptot - pz));
532 double phi = p.phi();
539 <<
"Generator ptot(GeV)= " << ptot/GeV <<
" eta= " << p.eta()
540 <<
" phi= " << p.phi() <<
" Flag= " <<
flag;
548 return ((pdgid >= 1000000 && pdgid < 4000000 && pdgid != 3000022) ||
559 int charge = pid.threeCharge();
560 return ((charge==0) && (pdgid >= 1000000 && pdgid < 1000040))
574 for(HepMC::GenEvent::particle_const_iterator it = evt->particles_begin();
575 it != evt->particles_end(); ++it ) {
578 int g_status = gp->status();
581 int g_id = gp->pdg_id();
582 G4PrimaryParticle * g4p =
583 new G4PrimaryParticle(g_id,gp->momentum().px()*
GeV,
584 gp->momentum().py()*
GeV,
585 gp->momentum().pz()*
GeV);
586 if (g4p->GetG4code() !=
nullptr) {
587 g4p->SetMass(g4p->GetG4code()->GetPDGMass());
588 g4p->SetCharge(g4p->GetG4code()->GetPDGCharge());
592 G4PrimaryVertex *
v =
593 new G4PrimaryVertex(gp->production_vertex()->position().x()*mm,
594 gp->production_vertex()->position().y()*mm,
595 gp->production_vertex()->position().z()*mm,
596 gp->production_vertex()->position().t()*mm/c_light);
598 g4evt->AddPrimaryVertex(v);
599 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