10 #include "G4HEPEvtParticle.hh"
11 #include "G4ParticleDefinition.hh"
12 #include "G4UnitsTable.hh"
13 #include "G4SystemOfUnits.hh"
14 #include "G4PhysicalConstants.hh"
23 fPCuts(p.getParameter<bool>(
"ApplyPCuts")),
24 fEtaCuts(p.getParameter<bool>(
"ApplyEtaCuts")),
25 fPhiCuts(p.getParameter<bool>(
"ApplyPhiCuts")),
26 theMinPhiCut(p.getParameter<double>(
"MinPhiCut")),
27 theMaxPhiCut(p.getParameter<double>(
"MaxPhiCut")),
28 theMinEtaCut(p.getParameter<double>(
"MinEtaCut")),
29 theMaxEtaCut(p.getParameter<double>(
"MaxEtaCut")),
30 theMinPCut(p.getParameter<double>(
"MinPCut")),
31 theMaxPCut(p.getParameter<double>(
"MaxPCut")),
32 theRDecLenCut(p.getParameter<double>(
"RDecLenCut")*cm),
33 theEtaCutForHector(p.getParameter<double>(
"EtaCutForHector")),
34 verbose(p.getUntrackedParameter<int>(
"Verbosity",0)),
45 if ( p.
exists(
"PDGselection") ) {
51 for (
unsigned int ii = 0;
ii < pdgFilter.size() ;
ii++ ) {
53 edm::LogWarning(
"SimG4CoreGenerator") <<
" *** Selecting only PDG ID = " << pdgFilter[
ii];
55 edm::LogWarning(
"SimG4CoreGenerator") <<
" *** Filtering out PDG ID = " << pdgFilter[
ii];
81 if ( *(evt_orig->vertices_begin()) == 0 )
83 throw SimG4Exception(
"SimG4CoreGenerator: Corrupted Event - GenEvent with no vertex" ) ;
87 HepMC::GenEvent* evt =
new HepMC::GenEvent(*evt_orig) ;
89 if ( evt->weights().size() > 0 )
92 for (
unsigned int iw=1; iw<evt->weights().size(); iw++ )
95 if ( evt->weights()[iw] <= 0 )
break;
102 (*(evt->vertices_begin()))->position().y(),
103 (*(evt->vertices_begin()))->position().z(),
104 (*(evt->vertices_begin()))->position().t());
108 LogDebug(
"SimG4CoreGenerator") <<
"Primary Vertex = (" <<
vtx_->x() <<
","
116 unsigned int ng4vtx = 0;
118 for(HepMC::GenEvent::vertex_const_iterator vitr= evt->vertices_begin();
119 vitr != evt->vertices_end(); ++vitr ) {
124 for (HepMC::GenVertex::particle_iterator pitr= (*vitr)->particles_begin(HepMC::children);
125 pitr != (*vitr)->particles_end(HepMC::children); ++pitr) {
127 if ((*pitr)->status()==1) {
130 <<
"GenVertex barcode = " << (*vitr)->barcode()
131 <<
" selected for GenParticle barcode = " << (*pitr)->barcode()
138 else if ( (*pitr)->status()== 2 ) {
139 if ( (*pitr)->end_vertex() != 0 ) {
142 double xx = (*pitr)->end_vertex()->position().x();
143 double yy = (*pitr)->end_vertex()->position().y();
148 <<
"GenVertex barcode = " << (*vitr)->barcode()
149 <<
" selected for GenParticle barcode = "
150 << (*pitr)->barcode() <<
" radius = " << r_dd << std::endl;
162 double x1 = (*vitr)->position().x();
163 double y1 = (*vitr)->position().y();
164 double z1 = (*vitr)->position().z();
165 double t1 = (*vitr)->position().t();
166 G4PrimaryVertex* g4vtx=
167 new G4PrimaryVertex(x1*mm, y1*mm, z1*mm, t1*mm/c_light);
169 for (HepMC::GenVertex::particle_iterator vpitr= (*vitr)->particles_begin(HepMC::children);
170 vpitr != (*vitr)->particles_end(HepMC::children); ++vpitr){
180 double r_decay_length=-1;
181 double decay_length=-1;
183 if ( (*vpitr)->status() == 1 || (*vpitr)->status() == 2 ) {
185 if ( (*vpitr)->end_vertex() != 0 ) {
190 double x2 = (*vpitr)->end_vertex()->position().x();
191 double y2 = (*vpitr)->end_vertex()->position().y();
192 double z2 = (*vpitr)->end_vertex()->position().z();
194 decay_length=
std::sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
200 bool toBeAdded =
false;
202 (*vpitr)->momentum().py(),
203 (*vpitr)->momentum().pz(),
204 (*vpitr)->momentum().e());
207 const double minTan = 1.e-20;
209 if ( fabs(z1) <
Z_hector && fabs(
p.pt()/
p.pz()) >= minTan ) {
215 <<
"Processing GenParticle barcode = " << (*vpitr)->barcode()
216 <<
" status = " << (*vpitr)->status()
217 <<
" zimpact = " << zimpact;
226 <<
"Skip GenParticle barcode = " << (*vpitr)->barcode()
227 <<
" PDG Id = " << (*vpitr)->pdg_id() << std::endl;
234 if( (*vpitr)->status() == 1 && fabs(zimpact) <
Z_hector ) {
240 <<
"GenParticle barcode = " << (*vpitr)->barcode()
241 <<
" passed case 1" << std::endl;
245 else if((*vpitr)->status() == 2 && r_decay_length >
theRDecLenCut &&
249 <<
"GenParticle barcode = " << (*vpitr)->barcode()
250 <<
" passed case 2" << std::endl;
255 else if( (*vpitr)->status() == 1 && fabs(zimpact) >=
Z_hector && fabs(z1) >=
Z_hector) {
258 <<
"GenParticle barcode = " << (*vpitr)->barcode()
259 <<
" passed case 3" << std::endl;
264 G4int pdgcode= (*vpitr)-> pdg_id();
265 G4PrimaryParticle* g4prim=
266 new G4PrimaryParticle(pdgcode,
p.Px()*GeV,
p.Py()*GeV,
p.Pz()*GeV);
268 if ( g4prim->GetG4code() != 0 ){
269 g4prim->SetMass( g4prim->GetG4code()->GetPDGMass() ) ;
270 g4prim->SetCharge( g4prim->GetG4code()->GetPDGCharge() ) ;
276 setGenId( g4prim, (*vpitr)->barcode() ) ;
278 if ( (*vpitr)->status() == 2 ) {
282 if (
verbose > 1 ) g4prim->Print();
283 g4vtx->SetPrimary(g4prim);
285 if ( (*vpitr)->status()==1 && (*vpitr)->end_vertex()!=0) {
286 double proper_time=decay_length/(
p.Beta()*
p.Gamma()*c_light);
288 <<
"Setting proper time for beta="<<
p.Beta()<<
" gamma="
289 <<
p.Gamma()<<
" Proper time=" <<proper_time/ns<<
" ns" ;
290 g4prim->SetProperTime(proper_time);
295 if (
verbose > 1 ) g4vtx->Print();
296 g4evt->AddPrimaryVertex(g4vtx);
306 G4PrimaryVertex* g4vtx=
307 new G4PrimaryVertex(x1*mm, y1*mm, z1*mm, t1*mm/c_light);
308 if (
verbose > 1 ) g4vtx->Print();
309 g4evt->AddPrimaryVertex(g4vtx);
320 if ( !(vp->end_vertex()) )
return ;
323 LogDebug(
"SimG4CoreGenerator") <<
"Special case of long decay length \n"
324 <<
"Assign daughters with to mother with decaylength=" << decaylength <<
"mm";
326 double proper_time=decaylength/(
p.Beta()*
p.Gamma()*c_light);
328 LogDebug(
"SimG4CoreGenerator") <<
" px="<<vp->momentum().px()
329 <<
" py="<<vp->momentum().py()
330 <<
" pz="<<vp->momentum().pz()
331 <<
" e="<<vp->momentum().e()
333 <<
" gamma="<<
p.Gamma()
334 <<
" Proper time=" <<proper_time<<
" ns" ;
336 g4p->SetProperTime(proper_time*ns);
337 double x1 = vp->end_vertex()->position().x();
338 double y1 = vp->end_vertex()->position().y();
339 double z1 = vp->end_vertex()->position().z();
340 for (HepMC::GenVertex::particle_iterator
341 vpdec= vp->end_vertex()->particles_begin(HepMC::children);
342 vpdec != vp->end_vertex()->particles_end(HepMC::children); ++vpdec) {
346 (*vpdec)->momentum().py(),
347 (*vpdec)->momentum().pz(),
348 (*vpdec)->momentum().e());
350 G4PrimaryParticle * g4daught=
351 new G4PrimaryParticle((*vpdec)->pdg_id(), pdec.x()*GeV, pdec.y()*GeV, pdec.z()*GeV);
352 if ( g4daught->GetG4code() != 0 )
354 g4daught->SetMass( g4daught->GetG4code()->GetPDGMass() ) ;
355 g4daught->SetCharge( g4daught->GetG4code()->GetPDGCharge() ) ;
360 setGenId( g4daught, (*vpdec)->barcode() ) ;
361 if (
verbose > 1 )
LogDebug(
"SimG4CoreGenerator") <<
"Assigning a "<<(*vpdec)->pdg_id()
362 <<
" as daughter of a " <<vp->pdg_id() ;
363 if ( (*vpdec)->status() == 2 && (*vpdec)->end_vertex() != 0 )
365 double x2 = (*vpdec)->end_vertex()->position().x();
366 double y2 = (*vpdec)->end_vertex()->position().y();
367 double z2 = (*vpdec)->end_vertex()->position().z();
368 double dd =
std::sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
371 (*vpdec)->set_status(1000+(*vpdec)->status());
372 g4p->SetDaughter(g4daught);
380 double phi = mom.Phi() ;
381 double nrg = mom.P() ;
392 if (
verbose > 2 )
LogDebug(
"SimG4CoreGenerator") <<
"Generator p = " << nrg <<
" z_imp = " << zimp <<
" phi = " << mom.Phi() <<
" Flag = " << flag;
400 G4ThreeVector mom = p->GetMomentum();
401 double phi = mom.phi() ;
402 double nrg =
sqrt(p->GetPx()*p->GetPx() + p->GetPy()*p->GetPy() + p->GetPz()*p->GetPz());
415 if (
verbose > 2 )
LogDebug(
"SimG4CoreGenerator") <<
"Generator p = " << nrg <<
" eta = " << eta <<
" theta = " << mom.theta() <<
" phi = " << phi <<
" Flag = " << flag;
424 for(HepMC::GenEvent::particle_const_iterator it = evt->particles_begin();
425 it != evt->particles_end(); ++it )
429 int g_status = g->status();
433 int g_id = g->pdg_id();
434 G4PrimaryParticle * g4p =
435 new G4PrimaryParticle(g_id,g->momentum().px()*GeV,g->momentum().py()*GeV,g->momentum().pz()*GeV);
436 if (g4p->GetG4code() != 0)
438 g4p->SetMass(g4p->GetG4code()->GetPDGMass());
439 g4p->SetCharge(g4p->GetG4code()->GetPDGCharge()) ;
447 G4PrimaryVertex *
v =
new
448 G4PrimaryVertex(g->production_vertex()->position().x()*mm,
449 g->production_vertex()->position().y()*mm,
450 g->production_vertex()->position().z()*mm,
451 g->production_vertex()->position().t()*mm/c_light);
453 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
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
void particleAssignDaughters(G4PrimaryParticle *p, HepMC::GenParticle *hp, double length)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Tan< T >::type tan(const T &t)
math::XYZTLorentzVector * vtx_
void nonBeamEvent2G4(const HepMC::GenEvent *g, G4Event *e)
return(e1-e2)*(e1-e2)+dp *dp
std::vector< int > pdgFilter
volatile std::atomic< bool > shutdown_flag false
bool particlePassesPrimaryCuts(const G4PrimaryParticle *p) const