CMS 3D CMS Logo

Generator.cc
Go to the documentation of this file.
4 
6 
8 
9 #include "HepPDT/ParticleID.hh"
10 
11 #include "G4Event.hh"
12 #include "G4HEPEvtParticle.hh"
13 #include "G4Log.hh"
14 #include "G4ParticleDefinition.hh"
15 #include "G4PhysicalConstants.hh"
16 #include "G4SystemOfUnits.hh"
17 #include "G4UnitsTable.hh"
18 
19 #include <sstream>
20 
21 using namespace edm;
22 
24  : fPCuts(p.getParameter<bool>("ApplyPCuts")),
25  fPtransCut(p.getParameter<bool>("ApplyPtransCut")),
26  fEtaCuts(p.getParameter<bool>("ApplyEtaCuts")),
27  fPhiCuts(p.getParameter<bool>("ApplyPhiCuts")),
28  theMinPhiCut(p.getParameter<double>("MinPhiCut")), // in radians (CMS standard)
29  theMaxPhiCut(p.getParameter<double>("MaxPhiCut")),
30  theMinEtaCut(p.getParameter<double>("MinEtaCut")),
31  theMaxEtaCut(p.getParameter<double>("MaxEtaCut")),
32  theMinPCut(p.getParameter<double>("MinPCut")), // in GeV (CMS standard)
33  theMaxPCut(p.getParameter<double>("MaxPCut")),
34  theEtaCutForHector(p.getParameter<double>("EtaCutForHector")),
35  verbose(p.getUntrackedParameter<int>("Verbosity", 0)),
36  fLumiFilter(nullptr),
37  evt_(nullptr),
38  vtx_(nullptr),
39  weight_(0),
40  Z_lmin(0),
41  Z_lmax(0),
42  Z_hector(0),
43  pdgFilterSel(false),
44  fPDGFilter(false) {
45  bool lumi = p.getParameter<bool>("ApplyLumiMonitorCuts");
46  if (lumi) {
48  }
49 
50  double theRDecLenCut = p.getParameter<double>("RDecLenCut") * CLHEP::cm;
51  theDecRCut2 = theRDecLenCut * theRDecLenCut;
52 
54 
55  double theDecLenCut = p.getParameter<double>("LDecLenCut") * CLHEP::cm;
56 
57  maxZCentralCMS = p.getParameter<double>("MaxZCentralCMS") * CLHEP::m;
58 
60 
61  pdgFilter.resize(0);
62  if (p.exists("PDGselection")) {
63  pdgFilterSel = (p.getParameter<edm::ParameterSet>("PDGselection")).getParameter<bool>("PDGfilterSel");
64  pdgFilter = (p.getParameter<edm::ParameterSet>("PDGselection")).getParameter<std::vector<int>>("PDGfilter");
65  if (!pdgFilter.empty()) {
66  fPDGFilter = true;
67  std::stringstream ss;
68  ss << "SimG4Core/Generator: ";
69  if (pdgFilterSel) {
70  ss << " Selecting only PDG ID = ";
71  } else {
72  ss << " Filtering out PDG ID = ";
73  }
74  for (unsigned int ii = 0; ii < pdgFilter.size(); ++ii) {
75  ss << pdgFilter[ii] << " ";
76  }
77  edm::LogVerbatim("SimG4CoreGenerator") << ss.str();
78  }
79  }
80 
81  if (fEtaCuts) {
82  Z_lmax = theRDecLenCut * ((1 - exp(-2 * theMaxEtaCut)) / (2 * exp(-theMaxEtaCut)));
83  Z_lmin = theRDecLenCut * ((1 - exp(-2 * theMinEtaCut)) / (2 * exp(-theMinEtaCut)));
84  }
85 
86  Z_hector = theRDecLenCut * ((1 - exp(-2 * theEtaCutForHector)) / (2 * exp(-theEtaCutForHector)));
87 
88  edm::LogVerbatim("SimG4CoreGenerator") << "SimG4Core/Generator: Rdecaycut= " << theRDecLenCut / CLHEP::cm
89  << " cm; Zdecaycut= " << theDecLenCut / CLHEP::cm
90  << "Z_min= " << Z_lmin / CLHEP::cm << " cm; Z_max= " << Z_lmax / CLHEP::cm
91  << " cm;\n"
92  << " MaxZCentralCMS = " << maxZCentralCMS / CLHEP::m
93  << " m;"
94  << " Z_hector = " << Z_hector / CLHEP::cm << " cm\n"
95  << " ApplyCuts: " << fFiductialCuts
96  << " PCuts: " << fPCuts << " PtransCut: " << fPtransCut
97  << " EtaCut: " << fEtaCuts << " PhiCut: " << fPhiCuts
98  << " LumiMonitorCut: " << lumi;
99  if (fFiductialCuts) {
100  edm::LogVerbatim("SimG4CoreGenerator")
101  << "SimG4Core/Generator: Pmin(GeV)= " << theMinPCut << "; Pmax(GeV)= " << theMaxPCut
102  << "; EtaMin= " << theMinEtaCut << "; EtaMax= " << theMaxEtaCut << "; PhiMin(rad)= " << theMinPhiCut
103  << "; PhiMax(rad)= " << theMaxPhiCut;
104  }
105  if (lumi) {
107  }
108 }
109 
111 
112 void Generator::HepMC2G4(const HepMC::GenEvent *evt_orig, G4Event *g4evt) {
113  HepMC::GenEvent *evt = new HepMC::GenEvent(*evt_orig);
114 
115  if (*(evt->vertices_begin()) == nullptr) {
116  std::stringstream ss;
117  ss << "SimG4Core/Generator: in event " << g4evt->GetEventID() << " Corrupted Event - GenEvent with no vertex \n";
118  throw SimG4Exception(ss.str());
119  }
120 
121  if (!evt->weights().empty()) {
122  weight_ = evt->weights()[0];
123  for (unsigned int iw = 1; iw < evt->weights().size(); ++iw) {
124  // terminate if the vector of weights contains a zero-weight
125  if (evt->weights()[iw] <= 0)
126  break;
127  weight_ *= evt->weights()[iw];
128  }
129  }
130 
131  if (vtx_ != nullptr) {
132  delete vtx_;
133  }
134  vtx_ = new math::XYZTLorentzVector((*(evt->vertices_begin()))->position().x(),
135  (*(evt->vertices_begin()))->position().y(),
136  (*(evt->vertices_begin()))->position().z(),
137  (*(evt->vertices_begin()))->position().t());
138 
139  edm::LogVerbatim("SimG4CoreGenerator") << "Generator: primary Vertex = (" << vtx_->x() << ", " << vtx_->y() << ", "
140  << vtx_->z() << ")";
141 
142  unsigned int ng4vtx = 0;
143  unsigned int ng4par = 0;
144 
145  for (HepMC::GenEvent::vertex_const_iterator vitr = evt->vertices_begin(); vitr != evt->vertices_end(); ++vitr) {
146  // loop for vertex, is it a real vertex?
147  // Set qvtx to true for any particles that should be propagated by GEANT,
148  // i.e., status 1 particles or status 2 particles that decay outside the
149  // beampipe.
150  G4bool qvtx = false;
151  HepMC::GenVertex::particle_iterator pitr;
152  for (pitr = (*vitr)->particles_begin(HepMC::children); pitr != (*vitr)->particles_end(HepMC::children); ++pitr) {
153  // For purposes of this function, the status is defined as follows:
154  // 1: particles are not decayed by generator
155  // 2: particles are decayed by generator but need to be propagated by GEANT
156  // 3: particles are decayed by generator and do not need to be propagated by GEANT
157  int status = (*pitr)->status();
158  int pdg = (*pitr)->pdg_id();
159  if (status > 3 && isExotic(pdg) && (!(isExoticNonDetectable(pdg)))) {
160  // In Pythia 8, there are many status codes besides 1, 2, 3.
161  // By setting the status to 2 for exotic particles, they will be
162  // checked: if its decay vertex is outside the beampipe, it will be
163  // propagated by GEANT. Some Standard Model particles, e.g., K0, cannot
164  // be propagated by GEANT, so do not change their status code.
165  status = 2;
166  }
167  if (status == 2 && abs(pdg) == 9900015) {
168  status = 3;
169  }
170 
171  // Particles which are not decayed by generator
172  if (status == 1) {
173  // filter out unwanted particles and vertices
175  continue;
176  }
177 
178  qvtx = true;
179  if (verbose > 2)
180  LogDebug("SimG4CoreGenerator") << "GenVertex barcode = " << (*vitr)->barcode()
181  << " selected for GenParticle barcode = " << (*pitr)->barcode();
182  break;
183  }
184  // The selection is made considering if the partcile with status = 2
185  // have the end_vertex with a radius greater than the radius of beampipe
186  // cylinder (no requirement on the Z of the vertex is applyed).
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;
192  if (r_dd > theDecRCut2) {
193  qvtx = true;
194  if (verbose > 2)
195  LogDebug("SimG4CoreGenerator")
196  << "GenVertex barcode = " << (*vitr)->barcode()
197  << " selected for GenParticle barcode = " << (*pitr)->barcode() << " radius = " << std::sqrt(r_dd);
198  break;
199  }
200  } else {
201  // particles with status 2 without end_vertex are
202  // equivalent to stable
203  qvtx = true;
204  break;
205  }
206  }
207  }
208 
209  // if this vertex is inside fiductial volume inside the beam pipe
210  // and has no long-lived secondary the vertex is not saved
211  if (!qvtx) {
212  continue;
213  }
214 
215  double x1 = (*vitr)->position().x() * CLHEP::mm;
216  double y1 = (*vitr)->position().y() * CLHEP::mm;
217  double z1 = (*vitr)->position().z() * CLHEP::mm;
218  double t1 = (*vitr)->position().t() * CLHEP::mm / CLHEP::c_light;
219 
220  G4PrimaryVertex *g4vtx = new G4PrimaryVertex(x1, y1, z1, t1);
221 
222  for (pitr = (*vitr)->particles_begin(HepMC::children); pitr != (*vitr)->particles_end(HepMC::children); ++pitr) {
223  int status = (*pitr)->status();
224  int pdg = (*pitr)->pdg_id();
225  bool hasDecayVertex = (nullptr != (*pitr)->end_vertex());
226 
227  // Filter on allowed particle species if required
228  if (fPDGFilter) {
229  bool isInTheList = IsInTheFilterList(pdg);
230  if ((!pdgFilterSel && isInTheList) || (pdgFilterSel && !isInTheList)) {
231  if (0 < verbose)
232  edm::LogVerbatim("SimG4CoreGenerator")
233  << " Skiped GenParticle barcode= " << (*pitr)->barcode() << " PDGid= " << pdg << " status= " << status
234  << " isExotic: " << isExotic(pdg) << " isExoticNotDet: " << isExoticNonDetectable(pdg)
235  << " isInTheList: " << isInTheList << " hasDecayVertex: " << hasDecayVertex;
236  continue;
237  }
238  }
239 
240  if (0 < verbose) {
241  edm::LogVerbatim("SimG4CoreGenerator")
242  << "Generator: pdg= " << pdg << " status= " << status << " hasPreDefinedDecay: " << hasDecayVertex
243  << "\n isExotic: " << isExotic(pdg) << " isExoticNotDet: " << isExoticNonDetectable(pdg)
244  << " isInTheList: " << IsInTheFilterList(pdg) << "\n"
245  << " MaxZCentralCMS = " << maxZCentralCMS / CLHEP::m << " m; (x,y,z,t): (" << x1 << "," << y1 << "," << z1
246  << "," << t1 << ")";
247  }
248  if (status > 3 && isExotic(pdg) && (!(isExoticNonDetectable(pdg)))) {
249  status = hasDecayVertex ? 2 : 1;
250  }
251  if (status == 2 && abs(pdg) == 9900015) {
252  status = 3;
253  }
254 
255  // this particle has predefined decay but has no vertex
256  if (2 == status && !hasDecayVertex) {
257  edm::LogWarning("SimG4CoreGenerator: in event ")
258  << g4evt->GetEventID() << " a particle "
259  << " pdgid= " << pdg << " has status=2 but has no decay vertex, so will be fully tracked by Geant4";
260  status = 1;
261  }
262 
263  double x2 = x1;
264  double y2 = y1;
265  double z2 = z1;
266  double decay_length = 0.0;
267  if (2 == status) {
268  x2 = (*pitr)->end_vertex()->position().x();
269  y2 = (*pitr)->end_vertex()->position().y();
270  z2 = (*pitr)->end_vertex()->position().z();
271  decay_length = std::sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1));
272  }
273 
274  bool toBeAdded = !fFiductialCuts;
275 
276  double px = (*pitr)->momentum().px();
277  double py = (*pitr)->momentum().py();
278  double pz = (*pitr)->momentum().pz();
279  double ptot = std::sqrt(px * px + py * py + pz * pz);
280  math::XYZTLorentzVector p(px, py, pz, (*pitr)->momentum().e());
281 
282  double ximpact = x1;
283  double yimpact = y1;
284  double zimpact = z1;
285 
286  // protection against numerical problems for extremely low momenta
287  // compute impact point at transition to Hector
288  const double minTan = 1.e-20;
289  if (std::abs(z1) < Z_hector && std::abs(pz) >= minTan * ptot) {
290  zimpact = (pz > 0.0) ? Z_hector : -Z_hector;
291  double del = (zimpact - z1) / pz;
292  ximpact += del * px;
293  yimpact += del * py;
294  }
295  double rimpact2 = ximpact * ximpact + yimpact * yimpact;
296 
297  if (verbose > 2)
298  LogDebug("SimG4CoreGenerator") << "Processing GenParticle barcode= " << (*pitr)->barcode() << " pdg= " << pdg
299  << " status= " << (*pitr)->status() << " st= " << status
300  << " rimpact(cm)= " << std::sqrt(rimpact2) / cm
301  << " zimpact(cm)= " << zimpact / cm << " ptot(GeV)= " << ptot
302  << " pz(GeV)= " << pz;
303 
304  // Particles of status 1 trasnported along the beam pipe
305  // HECTOR transport of protons are done in corresponding PPS producer
306  if (1 == status && std::abs(zimpact) >= Z_hector && rimpact2 <= theDecRCut2) {
307  // very forward n, nbar, gamma are allowed
308  toBeAdded = (2112 == std::abs(pdg) || 22 == pdg);
309  if (verbose > 1) {
310  edm::LogVerbatim("SimG4CoreGenerator")
311  << "GenParticle barcode = " << (*pitr)->barcode() << " very forward; to be added: " << toBeAdded;
312  }
313  } else {
314  // Standard case: particles not decayed by the generator and not forward
315  if (1 == status && (std::abs(zimpact) < Z_hector || rimpact2 > theDecRCut2)) {
316  // Ptot cut for all particles
317  if (fPCuts && (ptot < theMinPCut || ptot > theMaxPCut)) {
318  continue;
319  }
320  // phi cut is applied mainly for particle gun
321  if (fPhiCuts) {
322  double phi = p.phi();
323  if (phi < theMinPhiCut || phi > theMaxPhiCut) {
324  continue;
325  }
326  }
327  // eta cut is applied if position of the decay
328  // is within vacuum chamber and limited in Z
329  if (fEtaCuts) {
330  // eta cut
331  double xi = x1;
332  double yi = y1;
333  double zi = z1;
334 
335  // can be propagated along Z
336  if (std::abs(pz) >= minTan * ptot) {
337  if ((zi >= Z_lmax) & (pz < 0.0)) {
338  zi = Z_lmax;
339  } else if ((zi <= Z_lmin) & (pz > 0.0)) {
340  zi = Z_lmin;
341  } else {
342  if (pz > 0) {
343  zi = Z_lmax;
344  } else {
345  zi = Z_lmin;
346  }
347  }
348  double del = (zi - z1) / pz;
349  xi += del * px;
350  yi += del * py;
351  }
352  // check eta cut
353  if ((zi >= Z_lmin) & (zi <= Z_lmax) & (xi * xi + yi * yi < theDecRCut2)) {
354  continue;
355  }
356  }
357  if (fLumiFilter && !fLumiFilter->isGoodForLumiMonitor(*pitr)) {
358  continue;
359  }
360  toBeAdded = true;
361  if (verbose > 1)
362  edm::LogVerbatim("SimG4CoreGenerator")
363  << "GenParticle barcode = " << (*pitr)->barcode() << " passed case 1";
364 
365  // Decay chain outside the fiducial cylinder defined by theRDecLenCut
366  // are used for Geant4 tracking with predefined decay channel
367  // In the case of decay in vacuum particle is not tracked by Geant4
368  } else if (2 == status && x2 * x2 + y2 * y2 >= theDecRCut2 && std::abs(z2) < Z_hector) {
369  toBeAdded = true;
370  if (verbose > 1)
371  edm::LogVerbatim("SimG4CoreGenerator") << "GenParticle barcode = " << (*pitr)->barcode() << " passed case 2"
372  << " decay_length(cm)= " << decay_length / CLHEP::cm;
373  }
374  }
375  if (toBeAdded) {
376  G4PrimaryParticle *g4prim = new G4PrimaryParticle(pdg, px * GeV, py * GeV, pz * GeV);
377 
378  if (g4prim->GetG4code() != nullptr) {
379  g4prim->SetMass(g4prim->GetG4code()->GetPDGMass());
380  double charge = g4prim->GetG4code()->GetPDGCharge();
381 
382  // apply Pt cut
383  if (fPtransCut && 1 == status && 0.0 != charge && px * px + py * py < theMinPtCut2) {
384  delete g4prim;
385  continue;
386  }
387  g4prim->SetCharge(charge);
388  }
389 
390  // V.I. do not use SetWeight but the same code
391  // value of the code compute inside TrackWithHistory
392  // g4prim->SetWeight( 10000*(*vpitr)->barcode() ) ;
393  setGenId(g4prim, (*pitr)->barcode());
394 
395  if (2 == status) {
396  particleAssignDaughters(g4prim, (HepMC::GenParticle *)*pitr, decay_length);
397  }
398  if (verbose > 1)
399  g4prim->Print();
400 
401  ++ng4par;
402  g4vtx->SetPrimary(g4prim);
403  edm::LogVerbatim("SimG4CoreGenerator") << " " << ng4par << ". new Geant4 particle pdg= " << pdg
404  << " Ptot(GeV/c)= " << ptot << " Pt= " << std::sqrt(px * px + py * py)
405  << " status= " << status << "; dir= " << g4prim->GetMomentumDirection();
406  }
407  }
408 
409  if (verbose > 1)
410  g4vtx->Print();
411  g4evt->AddPrimaryVertex(g4vtx);
412  ++ng4vtx;
413  }
414 
415  // Add a protection for completely empty events (produced by LHCTransport):
416  // add a dummy vertex with no particle attached to it
417  if (ng4vtx == 0) {
418  G4PrimaryVertex *g4vtx = new G4PrimaryVertex(0.0, 0.0, 0.0, 0.0);
419  if (verbose > 1)
420  g4vtx->Print();
421 
422  g4evt->AddPrimaryVertex(g4vtx);
423  }
424 
425  edm::LogVerbatim("SimG4CoreGenerator") << "The list of Geant4 primaries includes " << ng4par << " particles in "
426  << ng4vtx << " vertex";
427  delete evt;
428 }
429 
430 void Generator::particleAssignDaughters(G4PrimaryParticle *g4p, HepMC::GenParticle *vp, double decaylength) {
431  if (verbose > 1) {
432  LogDebug("SimG4CoreGenerator") << "Special case of long decay length \n"
433  << "Assign daughters with to mother with decaylength=" << decaylength / cm << " cm";
434  }
435  math::XYZTLorentzVector p(vp->momentum().px(), vp->momentum().py(), vp->momentum().pz(), vp->momentum().e());
436 
437  // defined preassigned decay time
438  double proper_time = decaylength / (p.Beta() * p.Gamma() * c_light);
439  g4p->SetProperTime(proper_time);
440 
441  if (verbose > 2) {
442  LogDebug("SimG4CoreGenerator") << " px= " << p.px() << " py= " << p.py() << " pz= " << p.pz() << " e= " << p.e()
443  << " beta= " << p.Beta() << " gamma= " << p.Gamma()
444  << " Proper time= " << proper_time / ns << " ns";
445  }
446 
447  // the particle will decay after the same length if it
448  // has not interacted before
449  double x1 = vp->end_vertex()->position().x();
450  double y1 = vp->end_vertex()->position().y();
451  double z1 = vp->end_vertex()->position().z();
452 
453  for (HepMC::GenVertex::particle_iterator vpdec = vp->end_vertex()->particles_begin(HepMC::children);
454  vpdec != vp->end_vertex()->particles_end(HepMC::children);
455  ++vpdec) {
456  // transform decay products such that in the rest frame of mother
458  (*vpdec)->momentum().px(), (*vpdec)->momentum().py(), (*vpdec)->momentum().pz(), (*vpdec)->momentum().e());
459 
460  // children should only be taken into account once
461  G4PrimaryParticle *g4daught =
462  new G4PrimaryParticle((*vpdec)->pdg_id(), pdec.x() * CLHEP::GeV, pdec.y() * CLHEP::GeV, pdec.z() * CLHEP::GeV);
463 
464  if (g4daught->GetG4code() != nullptr) {
465  g4daught->SetMass(g4daught->GetG4code()->GetPDGMass());
466  g4daught->SetCharge(g4daught->GetG4code()->GetPDGCharge());
467  }
468 
469  // V.I. do not use SetWeight but the same code
470  // value of the code compute inside TrackWithHistory
471  setGenId(g4daught, (*vpdec)->barcode());
472 
473  if (verbose > 2)
474  LogDebug("SimG4CoreGenerator") << "Assigning a " << (*vpdec)->pdg_id() << " as daughter of a " << vp->pdg_id();
475 
476  if ((*vpdec)->status() == 2 && (*vpdec)->end_vertex() != nullptr) {
477  double x2 = (*vpdec)->end_vertex()->position().x();
478  double y2 = (*vpdec)->end_vertex()->position().y();
479  double z2 = (*vpdec)->end_vertex()->position().z();
480  double dd = std::sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
481  particleAssignDaughters(g4daught, *vpdec, dd);
482  }
483  (*vpdec)->set_status(1000 + (*vpdec)->status());
484  g4p->SetDaughter(g4daught);
485 
486  if (verbose > 1)
487  g4daught->Print();
488  }
489 }
490 
491 // Used for non-beam particles
492 bool Generator::particlePassesPrimaryCuts(const G4ThreeVector &p) const {
493  bool flag = true;
494  double ptot = p.mag();
495  if (fPCuts && (ptot < theMinPCut * CLHEP::GeV || ptot > theMaxPCut * CLHEP::GeV)) {
496  flag = false;
497  }
498  if (fEtaCuts && flag) {
499  double pz = p.z();
500  if (ptot < pz + 1.e-10) {
501  flag = false;
502 
503  } else {
504  double eta = 0.5 * G4Log((ptot + pz) / (ptot - pz));
505  if (eta < theMinEtaCut || eta > theMaxEtaCut) {
506  flag = false;
507  }
508  }
509  }
510  if (fPhiCuts && flag) {
511  double phi = p.phi();
512  if (phi < theMinPhiCut || phi > theMaxPhiCut) {
513  flag = false;
514  }
515  }
516 
517  if (verbose > 2)
518  LogDebug("SimG4CoreGenerator") << "Generator ptot(GeV)= " << ptot / GeV << " eta= " << p.eta()
519  << " phi= " << p.phi() << " Flag= " << flag;
520 
521  return flag;
522 }
523 
524 bool Generator::isExotic(int pdgcode) const {
525  int pdgid = std::abs(pdgcode);
526  return ((pdgid >= 1000000 && pdgid < 4000000 && pdgid != 3000022) || // SUSY, R-hadron, and technicolor particles
527  pdgid == 17 || // 4th generation lepton
528  pdgid == 34 || // W-prime
529  pdgid == 37); // charged Higgs
530 }
531 
532 bool Generator::isExoticNonDetectable(int pdgcode) const {
533  int pdgid = std::abs(pdgcode);
534  HepPDT::ParticleID pid(pdgcode);
535  int charge = pid.threeCharge();
536  return ((charge == 0) && (pdgid >= 1000000 && pdgid < 1000040)); // SUSY
537 }
538 
539 bool Generator::IsInTheFilterList(int pdgcode) const {
540  int pdgid = std::abs(pdgcode);
541  for (auto &pdg : pdgFilter) {
542  if (std::abs(pdg) == pdgid) {
543  return true;
544  }
545  }
546  return false;
547 }
548 
549 void Generator::nonCentralEvent2G4(const HepMC::GenEvent *evt, G4Event *g4evt) {
550  int i = g4evt->GetNumberOfPrimaryVertex();
551  for (HepMC::GenEvent::particle_const_iterator it = evt->particles_begin(); it != evt->particles_end(); ++it) {
552  ++i;
553  HepMC::GenParticle *gp = (*it);
554 
555  // storing only particle with status == 1
556  if (gp->status() != 1)
557  continue;
558 
559  int pdg = gp->pdg_id();
560  G4PrimaryParticle *g4p = new G4PrimaryParticle(
561  pdg, gp->momentum().px() * CLHEP::GeV, gp->momentum().py() * CLHEP::GeV, gp->momentum().pz() * CLHEP::GeV);
562  if (g4p->GetG4code() != nullptr) {
563  g4p->SetMass(g4p->GetG4code()->GetPDGMass());
564  g4p->SetCharge(g4p->GetG4code()->GetPDGCharge());
565  }
566  setGenId(g4p, i);
567  G4PrimaryVertex *v = new G4PrimaryVertex(gp->production_vertex()->position().x() * CLHEP::mm,
568  gp->production_vertex()->position().y() * CLHEP::mm,
569  gp->production_vertex()->position().z() * CLHEP::mm,
570  gp->production_vertex()->position().t() * CLHEP::mm / CLHEP::c_light);
571  v->SetPrimary(g4p);
572  g4evt->AddPrimaryVertex(v);
573  if (verbose > 0)
574  v->Print();
575  } // end loop on HepMC particles
576 }
Generator::Z_lmax
double Z_lmax
Definition: Generator.h:64
electrons_cff.bool
bool
Definition: electrons_cff.py:366
Generator::theMaxPhiCut
double theMaxPhiCut
Definition: Generator.h:49
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
mps_update.status
status
Definition: mps_update.py:68
Generator::theDecLenCut
double theDecLenCut
Definition: Generator.h:57
Generator::particlePassesPrimaryCuts
bool particlePassesPrimaryCuts(const G4ThreeVector &p) const
Definition: Generator.cc:492
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
edm
HLT enums.
Definition: AlignableModifier.h:19
LumiMonitorFilter::isGoodForLumiMonitor
bool isGoodForLumiMonitor(const HepMC::GenParticle *) const
Definition: LumiMonitorFilter.cc:15
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
class-composition.children
children
Definition: class-composition.py:98
Generator::isExoticNonDetectable
bool isExoticNonDetectable(int pdgcode) const
Definition: Generator.cc:532
SimG4Exception
Definition: SimG4Exception.h:13
Generator::nonCentralEvent2G4
void nonCentralEvent2G4(const HepMC::GenEvent *g, G4Event *e)
Definition: Generator.cc:549
dileptonTrigSettings_cff.pdg
pdg
Definition: dileptonTrigSettings_cff.py:6
Generator::theMinPtCut2
double theMinPtCut2
Definition: Generator.h:53
findQualityFiles.v
v
Definition: findQualityFiles.py:179
Generator::IsInTheFilterList
bool IsInTheFilterList(int pdgcode) const
Definition: Generator.cc:539
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
Generator::fEtaCuts
bool fEtaCuts
Definition: Generator.h:45
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
Generator::isExotic
bool isExotic(int pdgcode) const
Definition: Generator.cc:524
Generator::fPCuts
bool fPCuts
Definition: Generator.h:43
testProducerWithPsetDescEmpty_cfi.z2
z2
Definition: testProducerWithPsetDescEmpty_cfi.py:41
Generator::fFiductialCuts
bool fFiductialCuts
Definition: Generator.h:47
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
BXlumiParameters_cfi.lumi
lumi
Definition: BXlumiParameters_cfi.py:6
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition: testProducerWithPsetDescEmpty_cfi.py:29
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
Generator.h
LumiMonitorFilter::Describe
void Describe() const
Definition: LumiMonitorFilter.cc:13
Generator::fPDGFilter
bool fPDGFilter
Definition: Generator.h:67
PVValHelper::eta
Definition: PVValidationHelpers.h:70
Generator::weight_
double weight_
Definition: Generator.h:63
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:79
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
Generator::theMaxEtaCut
double theMaxEtaCut
Definition: Generator.h:51
verbose
static constexpr int verbose
Definition: HLTExoticaSubAnalysis.cc:25
Generator::theEtaCutForHector
double theEtaCutForHector
Definition: Generator.h:56
Generator::Z_lmin
double Z_lmin
Definition: Generator.h:64
Generator::~Generator
virtual ~Generator()
Definition: Generator.cc:110
createTree.dd
string dd
Definition: createTree.py:154
Generator::particleAssignDaughters
void particleAssignDaughters(G4PrimaryParticle *p, HepMC::GenParticle *hp, double length)
Definition: Generator.cc:430
Generator::theMaxPCut
double theMaxPCut
Definition: Generator.h:54
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
testProducerWithPsetDescEmpty_cfi.y2
y2
Definition: testProducerWithPsetDescEmpty_cfi.py:30
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
Generator::setGenId
void setGenId(G4PrimaryParticle *p, int id) const
Definition: Generator.h:40
SimG4Exception.h
Generator::theMinPCut
double theMinPCut
Definition: Generator.h:52
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
Generator::fLumiFilter
LumiMonitorFilter * fLumiFilter
Definition: Generator.h:60
edm::ParameterSet
Definition: ParameterSet.h:47
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
geometryCSVtoXML.yy
yy
Definition: geometryCSVtoXML.py:19
GeV
const double GeV
Definition: MathUtil.h:16
Generator::pdgFilterSel
bool pdgFilterSel
Definition: Generator.h:66
createfilelist.int
int
Definition: createfilelist.py:10
Generator::theMinPhiCut
double theMinPhiCut
Definition: Generator.h:48
Generator::Z_hector
double Z_hector
Definition: Generator.h:64
Generator::theDecRCut2
double theDecRCut2
Definition: Generator.h:55
Generator::fPhiCuts
bool fPhiCuts
Definition: Generator.h:46
DDAxes::phi
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
protons_cff.xi
xi
Definition: protons_cff.py:31
GenParticle.GenParticle
GenParticle
Definition: GenParticle.py:18
HepMCParticle.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
Generator::maxZCentralCMS
double maxZCentralCMS
Definition: Generator.h:58
pdg
Definition: pdg_functions.h:28
Generator::vtx_
math::XYZTLorentzVector * vtx_
Definition: Generator.h:62
LumiMonitorFilter
Definition: LumiMonitorFilter.h:6
Generator::HepMC2G4
void HepMC2G4(const HepMC::GenEvent *g, G4Event *e)
Definition: Generator.cc:112
Generator::Generator
Generator(const edm::ParameterSet &p)
Definition: Generator.cc:23
Generator::fPtransCut
bool fPtransCut
Definition: Generator.h:44
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Generator::verbose
int verbose
Definition: Generator.h:59
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
EgammaValidation_cff.pdgid
pdgid
Definition: EgammaValidation_cff.py:29
lumi
Definition: LumiSectionData.h:20
Generator::theMinEtaCut
double theMinEtaCut
Definition: Generator.h:50
LHEGenericFilter_cfi.ParticleID
ParticleID
Definition: LHEGenericFilter_cfi.py:6
cuy.ii
ii
Definition: cuy.py:589
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
Generator::pdgFilter
std::vector< int > pdgFilter
Definition: Generator.h:65
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:117
LumiMonitorFilter.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37