CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
Generator Class Reference

#include <Generator.h>

Public Member Functions

virtual const double eventWeight () const
 
 Generator (const edm::ParameterSet &p)
 
virtual const HepMC::GenEventgenEvent () const
 
virtual const math::XYZTLorentzVectorgenVertex () const
 
void HepMC2G4 (const HepMC::GenEvent *g, G4Event *e)
 
void nonCentralEvent2G4 (const HepMC::GenEvent *g, G4Event *e)
 
void setGenEvent (const HepMC::GenEvent *inpevt)
 
virtual ~Generator ()
 

Private Member Functions

bool isExotic (int pdgcode) const
 
bool isExoticNonDetectable (int pdgcode) const
 
bool IsInTheFilterList (int pdgcode) const
 
void particleAssignDaughters (G4PrimaryParticle *p, HepMC::GenParticle *hp, double length)
 
bool particlePassesPrimaryCuts (const G4ThreeVector &p) const
 
void setGenId (G4PrimaryParticle *p, int id) const
 

Private Attributes

HepMC::GenEventevt_
 
bool fEtaCuts
 
bool fFiductialCuts
 
LumiMonitorFilterfLumiFilter
 
bool fPCuts
 
bool fPDGFilter
 
bool fPhiCuts
 
bool fPtransCut
 
double maxZCentralCMS
 
std::vector< int > pdgFilter
 
bool pdgFilterSel
 
double theDecLenCut
 
double theDecRCut2
 
double theEtaCutForHector
 
double theMaxEtaCut
 
double theMaxPCut
 
double theMaxPhiCut
 
double theMinEtaCut
 
double theMinPCut
 
double theMinPhiCut
 
double theMinPtCut2
 
int verbose
 
math::XYZTLorentzVectorvtx_
 
double weight_
 
double Z_hector
 
double Z_lmax
 
double Z_lmin
 

Detailed Description

Definition at line 19 of file Generator.h.

Constructor & Destructor Documentation

◆ Generator()

Generator::Generator ( const edm::ParameterSet p)

Definition at line 23 of file Generator.cc.

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 }

References LumiMonitorFilter::Describe(), JetChargeProducer_cfi::exp, fEtaCuts, fFiductialCuts, fLumiFilter, fPCuts, fPDGFilter, fPhiCuts, fPtransCut, cuy::ii, BXlumiParameters_cfi::lumi, visualization-live-secondInstance_cfg::m, maxZCentralCMS, AlCaHLTBitMon_ParallelJobs::p, pdgFilter, pdgFilterSel, contentValuesCheck::ss, theDecLenCut, theDecRCut2, theEtaCutForHector, theMaxEtaCut, theMaxPCut, theMaxPhiCut, theMinEtaCut, theMinPCut, theMinPhiCut, theMinPtCut2, Z_hector, Z_lmax, and Z_lmin.

◆ ~Generator()

Generator::~Generator ( )
virtual

Definition at line 110 of file Generator.cc.

110 { delete fLumiFilter; }

References fLumiFilter.

Member Function Documentation

◆ eventWeight()

virtual const double Generator::eventWeight ( ) const
inlinevirtual

Definition at line 32 of file Generator.h.

32 { return weight_; }

References weight_.

Referenced by RunManagerMTWorker::produce(), and RunManager::produce().

◆ genEvent()

virtual const HepMC::GenEvent* Generator::genEvent ( ) const
inlinevirtual

Definition at line 30 of file Generator.h.

30 { return evt_; }

References evt_.

Referenced by RunManagerMTWorker::produce(), and RunManager::produce().

◆ genVertex()

virtual const math::XYZTLorentzVector* Generator::genVertex ( ) const
inlinevirtual

Definition at line 31 of file Generator.h.

31 { return vtx_; }

References vtx_.

Referenced by RunManagerMTWorker::produce(), and RunManager::produce().

◆ HepMC2G4()

void Generator::HepMC2G4 ( const HepMC::GenEvent g,
G4Event *  e 
)

Definition at line 112 of file Generator.cc.

112  {
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
156  int status = (*pitr)->status();
157  int pdg = (*pitr)->pdg_id();
158  if (status > 3 && isExotic(pdg) && (!(isExoticNonDetectable(pdg)))) {
159  // In Pythia 8, there are many status codes besides 1, 2, 3.
160  // By setting the status to 2 for exotic particles, they will be
161  // checked: if its decay vertex is outside the beampipe, it will be
162  // propagated by GEANT. Some Standard Model particles, e.g., K0, cannot
163  // be propagated by GEANT, so do not change their status code.
164  status = 2;
165  }
166 
167  // Particles which are not decayed by generator
168  if (status == 1) {
169  // filter out unwanted particles and vertices
171  continue;
172  }
173 
174  qvtx = true;
175  if (verbose > 2)
176  LogDebug("SimG4CoreGenerator") << "GenVertex barcode = " << (*vitr)->barcode()
177  << " selected for GenParticle barcode = " << (*pitr)->barcode();
178  break;
179  }
180  // The selection is made considering if the partcile with status = 2
181  // have the end_vertex with a radius greater than the radius of beampipe
182  // cylinder (no requirement on the Z of the vertex is applyed).
183  else if (status == 2) {
184  if ((*pitr)->end_vertex() != nullptr) {
185  double xx = (*pitr)->end_vertex()->position().x();
186  double yy = (*pitr)->end_vertex()->position().y();
187  double r_dd = xx * xx + yy * yy;
188  if (r_dd > theDecRCut2) {
189  qvtx = true;
190  if (verbose > 2)
191  LogDebug("SimG4CoreGenerator")
192  << "GenVertex barcode = " << (*vitr)->barcode()
193  << " selected for GenParticle barcode = " << (*pitr)->barcode() << " radius = " << std::sqrt(r_dd);
194  break;
195  }
196  } else {
197  // particles with status 2 without end_vertex are
198  // equivalent to stable
199  qvtx = true;
200  break;
201  }
202  }
203  }
204 
205  // if this vertex is inside fiductial volume inside the beam pipe
206  // and has no long-lived secondary the vertex is not saved
207  if (!qvtx) {
208  continue;
209  }
210 
211  double x1 = (*vitr)->position().x() * CLHEP::mm;
212  double y1 = (*vitr)->position().y() * CLHEP::mm;
213  double z1 = (*vitr)->position().z() * CLHEP::mm;
214  double t1 = (*vitr)->position().t() * CLHEP::mm / CLHEP::c_light;
215 
216  G4PrimaryVertex *g4vtx = new G4PrimaryVertex(x1, y1, z1, t1);
217 
218  for (pitr = (*vitr)->particles_begin(HepMC::children); pitr != (*vitr)->particles_end(HepMC::children); ++pitr) {
219  int status = (*pitr)->status();
220  int pdg = (*pitr)->pdg_id();
221  bool hasDecayVertex = (nullptr != (*pitr)->end_vertex());
222 
223  // Filter on allowed particle species if required
224  if (fPDGFilter) {
225  bool isInTheList = IsInTheFilterList(pdg);
226  if ((!pdgFilterSel && isInTheList) || (pdgFilterSel && !isInTheList)) {
227  if (0 < verbose)
228  edm::LogVerbatim("SimG4CoreGenerator")
229  << " Skiped GenParticle barcode= " << (*pitr)->barcode() << " PDGid= " << pdg << " status= " << status
230  << " isExotic: " << isExotic(pdg) << " isExoticNotDet: " << isExoticNonDetectable(pdg)
231  << " isInTheList: " << isInTheList << " hasDecayVertex: " << hasDecayVertex;
232  continue;
233  }
234  }
235 
236  if (0 < verbose) {
237  edm::LogVerbatim("SimG4CoreGenerator")
238  << "Generator: pdg= " << pdg << " status= " << status << " hasPreDefinedDecay: " << hasDecayVertex
239  << "\n isExotic: " << isExotic(pdg) << " isExoticNotDet: " << isExoticNonDetectable(pdg)
240  << " isInTheList: " << IsInTheFilterList(pdg) << "\n"
241  << " MaxZCentralCMS = " << maxZCentralCMS / CLHEP::m << " m; (x,y,z,t): (" << x1 << "," << y1 << "," << z1
242  << "," << t1 << ")";
243  }
244  if (status > 3 && isExotic(pdg) && (!(isExoticNonDetectable(pdg)))) {
245  status = hasDecayVertex ? 2 : 1;
246  }
247 
248  // this particle has predefined decay but has no vertex
249  if (2 == status && !hasDecayVertex) {
250  edm::LogWarning("SimG4CoreGenerator: in event ")
251  << g4evt->GetEventID() << " a particle "
252  << " pdgid= " << pdg << " has status=2 but has no decay vertex, so will be fully tracked by Geant4";
253  status = 1;
254  }
255 
256  double x2 = x1;
257  double y2 = y1;
258  double z2 = z1;
259  double decay_length = 0.0;
260  if (2 == status) {
261  x2 = (*pitr)->end_vertex()->position().x();
262  y2 = (*pitr)->end_vertex()->position().y();
263  z2 = (*pitr)->end_vertex()->position().z();
264  decay_length = std::sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1));
265  }
266 
267  bool toBeAdded = !fFiductialCuts;
268 
269  double px = (*pitr)->momentum().px();
270  double py = (*pitr)->momentum().py();
271  double pz = (*pitr)->momentum().pz();
272  double ptot = std::sqrt(px * px + py * py + pz * pz);
273  math::XYZTLorentzVector p(px, py, pz, (*pitr)->momentum().e());
274 
275  double ximpact = x1;
276  double yimpact = y1;
277  double zimpact = z1;
278 
279  // protection against numerical problems for extremely low momenta
280  // compute impact point at transition to Hector
281  const double minTan = 1.e-20;
282  if (std::abs(z1) < Z_hector && std::abs(pz) >= minTan * ptot) {
283  zimpact = (pz > 0.0) ? Z_hector : -Z_hector;
284  double del = (zimpact - z1) / pz;
285  ximpact += del * px;
286  yimpact += del * py;
287  }
288  double rimpact2 = ximpact * ximpact + yimpact * yimpact;
289 
290  if (verbose > 2)
291  LogDebug("SimG4CoreGenerator") << "Processing GenParticle barcode= " << (*pitr)->barcode() << " pdg= " << pdg
292  << " status= " << (*pitr)->status() << " st= " << status
293  << " rimpact(cm)= " << std::sqrt(rimpact2) / cm
294  << " zimpact(cm)= " << zimpact / cm << " ptot(GeV)= " << ptot
295  << " pz(GeV)= " << pz;
296 
297  // Particles of status 1 trasnported along the beam pipe
298  // HECTOR transport of protons are done in corresponding PPS producer
299  if (1 == status && std::abs(zimpact) >= Z_hector && rimpact2 <= theDecRCut2) {
300  // very forward n, nbar, gamma are allowed
301  toBeAdded = (2112 == std::abs(pdg) || 22 == pdg);
302  if (verbose > 1) {
303  edm::LogVerbatim("SimG4CoreGenerator")
304  << "GenParticle barcode = " << (*pitr)->barcode() << " very forward; to be added: " << toBeAdded;
305  }
306  } else {
307  // Standard case: particles not decayed by the generator and not forward
308  if (1 == status && (std::abs(zimpact) < Z_hector || rimpact2 > theDecRCut2)) {
309  // Ptot cut for all particles
310  if (fPCuts && (ptot < theMinPCut || ptot > theMaxPCut)) {
311  continue;
312  }
313  // phi cut is applied mainly for particle gun
314  if (fPhiCuts) {
315  double phi = p.phi();
316  if (phi < theMinPhiCut || phi > theMaxPhiCut) {
317  continue;
318  }
319  }
320  // eta cut is applied if position of the decay
321  // is within vacuum chamber and limited in Z
322  if (fEtaCuts) {
323  // eta cut
324  double xi = x1;
325  double yi = y1;
326  double zi = z1;
327 
328  // can be propagated along Z
329  if (std::abs(pz) >= minTan * ptot) {
330  if ((zi >= Z_lmax) & (pz < 0.0)) {
331  zi = Z_lmax;
332  } else if ((zi <= Z_lmin) & (pz > 0.0)) {
333  zi = Z_lmin;
334  } else {
335  if (pz > 0) {
336  zi = Z_lmax;
337  } else {
338  zi = Z_lmin;
339  }
340  }
341  double del = (zi - z1) / pz;
342  xi += del * px;
343  yi += del * py;
344  }
345  // check eta cut
346  if ((zi >= Z_lmin) & (zi <= Z_lmax) & (xi * xi + yi * yi < theDecRCut2)) {
347  continue;
348  }
349  }
350  if (fLumiFilter && !fLumiFilter->isGoodForLumiMonitor(*pitr)) {
351  continue;
352  }
353  toBeAdded = true;
354  if (verbose > 1)
355  edm::LogVerbatim("SimG4CoreGenerator")
356  << "GenParticle barcode = " << (*pitr)->barcode() << " passed case 1";
357 
358  // Decay chain outside the fiducial cylinder defined by theRDecLenCut
359  // are used for Geant4 tracking with predefined decay channel
360  // In the case of decay in vacuum particle is not tracked by Geant4
361  } else if (2 == status && x2 * x2 + y2 * y2 >= theDecRCut2 && std::abs(z2) < Z_hector) {
362  toBeAdded = true;
363  if (verbose > 1)
364  edm::LogVerbatim("SimG4CoreGenerator") << "GenParticle barcode = " << (*pitr)->barcode() << " passed case 2"
365  << " decay_length(cm)= " << decay_length / CLHEP::cm;
366  }
367  }
368  if (toBeAdded) {
369  G4PrimaryParticle *g4prim = new G4PrimaryParticle(pdg, px * GeV, py * GeV, pz * GeV);
370 
371  if (g4prim->GetG4code() != nullptr) {
372  g4prim->SetMass(g4prim->GetG4code()->GetPDGMass());
373  double charge = g4prim->GetG4code()->GetPDGCharge();
374 
375  // apply Pt cut
376  if (fPtransCut && 1 == status && 0.0 != charge && px * px + py * py < theMinPtCut2) {
377  delete g4prim;
378  continue;
379  }
380  g4prim->SetCharge(charge);
381  }
382 
383  // V.I. do not use SetWeight but the same code
384  // value of the code compute inside TrackWithHistory
385  // g4prim->SetWeight( 10000*(*vpitr)->barcode() ) ;
386  setGenId(g4prim, (*pitr)->barcode());
387 
388  if (2 == status) {
389  particleAssignDaughters(g4prim, (HepMC::GenParticle *)*pitr, decay_length);
390  }
391  if (verbose > 1)
392  g4prim->Print();
393 
394  ++ng4par;
395  g4vtx->SetPrimary(g4prim);
396  edm::LogVerbatim("SimG4CoreGenerator") << " " << ng4par << ". new Geant4 particle pdg= " << pdg
397  << " Ptot(GeV/c)= " << ptot << " Pt= " << std::sqrt(px * px + py * py)
398  << " status= " << status << "; dir= " << g4prim->GetMomentumDirection();
399  }
400  }
401 
402  if (verbose > 1)
403  g4vtx->Print();
404  g4evt->AddPrimaryVertex(g4vtx);
405  ++ng4vtx;
406  }
407 
408  // Add a protection for completely empty events (produced by LHCTransport):
409  // add a dummy vertex with no particle attached to it
410  if (ng4vtx == 0) {
411  G4PrimaryVertex *g4vtx = new G4PrimaryVertex(0.0, 0.0, 0.0, 0.0);
412  if (verbose > 1)
413  g4vtx->Print();
414 
415  g4evt->AddPrimaryVertex(g4vtx);
416  }
417 
418  edm::LogVerbatim("SimG4CoreGenerator") << "The list of Geant4 primaries includes " << ng4par << " particles in "
419  << ng4vtx << " vertex";
420  delete evt;
421 }

References funct::abs(), ALCARECOTkAlJpsiMuMu_cff::charge, class-composition::children, fEtaCuts, fFiductialCuts, fLumiFilter, fPCuts, fPDGFilter, fPhiCuts, fPtransCut, GenParticle::GenParticle, GeV, isExotic(), isExoticNonDetectable(), LumiMonitorFilter::isGoodForLumiMonitor(), IsInTheFilterList(), LogDebug, visualization-live-secondInstance_cfg::m, maxZCentralCMS, AlCaHLTBitMon_ParallelJobs::p, particleAssignDaughters(), dileptonTrigSettings_cff::pdg, pdgFilterSel, phi, multPhiCorr_741_25nsDY_cfi::px, multPhiCorr_741_25nsDY_cfi::py, setGenId(), mathSSE::sqrt(), contentValuesCheck::ss, mps_update::status, RandomServiceHelper::t1, theDecRCut2, theMaxPCut, theMaxPhiCut, theMinPtCut2, verbose, vtx_, weight_, testProducerWithPsetDescEmpty_cfi::x1, testProducerWithPsetDescEmpty_cfi::x2, hybridSuperClusters_cfi::xi, geometryCSVtoXML::xx, testProducerWithPsetDescEmpty_cfi::y1, testProducerWithPsetDescEmpty_cfi::y2, geometryCSVtoXML::yy, testProducerWithPsetDescEmpty_cfi::z2, Z_hector, Z_lmax, and Z_lmin.

Referenced by RunManagerMTWorker::generateEvent(), and RunManager::generateEvent().

◆ isExotic()

bool Generator::isExotic ( int  pdgcode) const
private

Definition at line 517 of file Generator.cc.

517  {
518  int pdgid = std::abs(pdgcode);
519  return ((pdgid >= 1000000 && pdgid < 4000000 && pdgid != 3000022) || // SUSY, R-hadron, and technicolor particles
520  pdgid == 17 || // 4th generation lepton
521  pdgid == 34 || // W-prime
522  pdgid == 37); // charged Higgs
523 }

References funct::abs(), and EgammaValidation_cff::pdgid.

Referenced by HepMC2G4().

◆ isExoticNonDetectable()

bool Generator::isExoticNonDetectable ( int  pdgcode) const
private

Definition at line 525 of file Generator.cc.

525  {
526  int pdgid = std::abs(pdgcode);
527  HepPDT::ParticleID pid(pdgcode);
528  int charge = pid.threeCharge();
529  return ((charge == 0) && (pdgid >= 1000000 && pdgid < 1000040)); // SUSY
530 }

References funct::abs(), ALCARECOTkAlJpsiMuMu_cff::charge, LHEGenericFilter_cfi::ParticleID, and EgammaValidation_cff::pdgid.

Referenced by HepMC2G4().

◆ IsInTheFilterList()

bool Generator::IsInTheFilterList ( int  pdgcode) const
private

Definition at line 532 of file Generator.cc.

532  {
533  int pdgid = std::abs(pdgcode);
534  for (auto &pdg : pdgFilter) {
535  if (std::abs(pdg) == pdgid) {
536  return true;
537  }
538  }
539  return false;
540 }

References funct::abs(), pdgFilter, and EgammaValidation_cff::pdgid.

Referenced by HepMC2G4().

◆ nonCentralEvent2G4()

void Generator::nonCentralEvent2G4 ( const HepMC::GenEvent g,
G4Event *  e 
)

Definition at line 542 of file Generator.cc.

542  {
543  int i = g4evt->GetNumberOfPrimaryVertex();
544  for (HepMC::GenEvent::particle_const_iterator it = evt->particles_begin(); it != evt->particles_end(); ++it) {
545  ++i;
546  HepMC::GenParticle *gp = (*it);
547 
548  // storing only particle with status == 1
549  if (gp->status() != 1)
550  continue;
551 
552  int pdg = gp->pdg_id();
553  G4PrimaryParticle *g4p = new G4PrimaryParticle(
554  pdg, gp->momentum().px() * CLHEP::GeV, gp->momentum().py() * CLHEP::GeV, gp->momentum().pz() * CLHEP::GeV);
555  if (g4p->GetG4code() != nullptr) {
556  g4p->SetMass(g4p->GetG4code()->GetPDGMass());
557  g4p->SetCharge(g4p->GetG4code()->GetPDGCharge());
558  }
559  setGenId(g4p, i);
560  G4PrimaryVertex *v = new G4PrimaryVertex(gp->production_vertex()->position().x() * CLHEP::mm,
561  gp->production_vertex()->position().y() * CLHEP::mm,
562  gp->production_vertex()->position().z() * CLHEP::mm,
563  gp->production_vertex()->position().t() * CLHEP::mm / CLHEP::c_light);
564  v->SetPrimary(g4p);
565  g4evt->AddPrimaryVertex(v);
566  if (verbose > 0)
567  v->Print();
568  } // end loop on HepMC particles
569 }

References GenParticle::GenParticle, GeV, runTauDisplay::gp, mps_fire::i, setGenId(), findQualityFiles::v, and verbose.

Referenced by RunManagerMTWorker::generateEvent(), and RunManager::generateEvent().

◆ particleAssignDaughters()

void Generator::particleAssignDaughters ( G4PrimaryParticle *  p,
HepMC::GenParticle *  hp,
double  length 
)
private

Definition at line 423 of file Generator.cc.

423  {
424  if (verbose > 1) {
425  LogDebug("SimG4CoreGenerator") << "Special case of long decay length \n"
426  << "Assign daughters with to mother with decaylength=" << decaylength / cm << " cm";
427  }
428  math::XYZTLorentzVector p(vp->momentum().px(), vp->momentum().py(), vp->momentum().pz(), vp->momentum().e());
429 
430  // defined preassigned decay time
431  double proper_time = decaylength / (p.Beta() * p.Gamma() * c_light);
432  g4p->SetProperTime(proper_time);
433 
434  if (verbose > 2) {
435  LogDebug("SimG4CoreGenerator") << " px= " << p.px() << " py= " << p.py() << " pz= " << p.pz() << " e= " << p.e()
436  << " beta= " << p.Beta() << " gamma= " << p.Gamma()
437  << " Proper time= " << proper_time / ns << " ns";
438  }
439 
440  // the particle will decay after the same length if it
441  // has not interacted before
442  double x1 = vp->end_vertex()->position().x();
443  double y1 = vp->end_vertex()->position().y();
444  double z1 = vp->end_vertex()->position().z();
445 
446  for (HepMC::GenVertex::particle_iterator vpdec = vp->end_vertex()->particles_begin(HepMC::children);
447  vpdec != vp->end_vertex()->particles_end(HepMC::children);
448  ++vpdec) {
449  // transform decay products such that in the rest frame of mother
451  (*vpdec)->momentum().px(), (*vpdec)->momentum().py(), (*vpdec)->momentum().pz(), (*vpdec)->momentum().e());
452 
453  // children should only be taken into account once
454  G4PrimaryParticle *g4daught =
455  new G4PrimaryParticle((*vpdec)->pdg_id(), pdec.x() * CLHEP::GeV, pdec.y() * CLHEP::GeV, pdec.z() * CLHEP::GeV);
456 
457  if (g4daught->GetG4code() != nullptr) {
458  g4daught->SetMass(g4daught->GetG4code()->GetPDGMass());
459  g4daught->SetCharge(g4daught->GetG4code()->GetPDGCharge());
460  }
461 
462  // V.I. do not use SetWeight but the same code
463  // value of the code compute inside TrackWithHistory
464  setGenId(g4daught, (*vpdec)->barcode());
465 
466  if (verbose > 2)
467  LogDebug("SimG4CoreGenerator") << "Assigning a " << (*vpdec)->pdg_id() << " as daughter of a " << vp->pdg_id();
468 
469  if ((*vpdec)->status() == 2 && (*vpdec)->end_vertex() != nullptr) {
470  double x2 = (*vpdec)->end_vertex()->position().x();
471  double y2 = (*vpdec)->end_vertex()->position().y();
472  double z2 = (*vpdec)->end_vertex()->position().z();
473  double dd = std::sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
474  particleAssignDaughters(g4daught, *vpdec, dd);
475  }
476  (*vpdec)->set_status(1000 + (*vpdec)->status());
477  g4p->SetDaughter(g4daught);
478 
479  if (verbose > 1)
480  g4daught->Print();
481  }
482 }

References class-composition::children, createTree::dd, GeV, LogDebug, AlCaHLTBitMon_ParallelJobs::p, setGenId(), mathSSE::sqrt(), verbose, testProducerWithPsetDescEmpty_cfi::x1, testProducerWithPsetDescEmpty_cfi::x2, testProducerWithPsetDescEmpty_cfi::y1, testProducerWithPsetDescEmpty_cfi::y2, and testProducerWithPsetDescEmpty_cfi::z2.

Referenced by HepMC2G4().

◆ particlePassesPrimaryCuts()

bool Generator::particlePassesPrimaryCuts ( const G4ThreeVector &  p) const
private

Definition at line 485 of file Generator.cc.

485  {
486  bool flag = true;
487  double ptot = p.mag();
488  if (fPCuts && (ptot < theMinPCut * CLHEP::GeV || ptot > theMaxPCut * CLHEP::GeV)) {
489  flag = false;
490  }
491  if (fEtaCuts && flag) {
492  double pz = p.z();
493  if (ptot < pz + 1.e-10) {
494  flag = false;
495 
496  } else {
497  double eta = 0.5 * G4Log((ptot + pz) / (ptot - pz));
498  if (eta < theMinEtaCut || eta > theMaxEtaCut) {
499  flag = false;
500  }
501  }
502  }
503  if (fPhiCuts && flag) {
504  double phi = p.phi();
505  if (phi < theMinPhiCut || phi > theMaxPhiCut) {
506  flag = false;
507  }
508  }
509 
510  if (verbose > 2)
511  LogDebug("SimG4CoreGenerator") << "Generator ptot(GeV)= " << ptot / GeV << " eta= " << p.eta()
512  << " phi= " << p.phi() << " Flag= " << flag;
513 
514  return flag;
515 }

References MillePedeFileConverter_cfg::e, PVValHelper::eta, fEtaCuts, RemoveAddSevLevel::flag, fPCuts, fPhiCuts, GeV, LogDebug, AlCaHLTBitMon_ParallelJobs::p, phi, theMaxEtaCut, theMaxPCut, theMaxPhiCut, and verbose.

◆ setGenEvent()

void Generator::setGenEvent ( const HepMC::GenEvent inpevt)
inline

Definition at line 24 of file Generator.h.

24  {
25  evt_ = (HepMC::GenEvent *)inpevt;
26  return;
27  }

References evt_.

Referenced by RunManagerMTWorker::generateEvent(), and RunManager::generateEvent().

◆ setGenId()

void Generator::setGenId ( G4PrimaryParticle *  p,
int  id 
) const
inlineprivate

Definition at line 40 of file Generator.h.

40 { p->SetUserInformation(new GenParticleInfo(id)); }

References AlCaHLTBitMon_ParallelJobs::p.

Referenced by HepMC2G4(), nonCentralEvent2G4(), and particleAssignDaughters().

Member Data Documentation

◆ evt_

HepMC::GenEvent* Generator::evt_
private

Definition at line 61 of file Generator.h.

Referenced by genEvent(), and setGenEvent().

◆ fEtaCuts

bool Generator::fEtaCuts
private

Definition at line 45 of file Generator.h.

Referenced by Generator(), HepMC2G4(), and particlePassesPrimaryCuts().

◆ fFiductialCuts

bool Generator::fFiductialCuts
private

Definition at line 47 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

◆ fLumiFilter

LumiMonitorFilter* Generator::fLumiFilter
private

Definition at line 60 of file Generator.h.

Referenced by Generator(), HepMC2G4(), and ~Generator().

◆ fPCuts

bool Generator::fPCuts
private

Definition at line 43 of file Generator.h.

Referenced by Generator(), HepMC2G4(), and particlePassesPrimaryCuts().

◆ fPDGFilter

bool Generator::fPDGFilter
private

Definition at line 67 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

◆ fPhiCuts

bool Generator::fPhiCuts
private

Definition at line 46 of file Generator.h.

Referenced by Generator(), HepMC2G4(), and particlePassesPrimaryCuts().

◆ fPtransCut

bool Generator::fPtransCut
private

Definition at line 44 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

◆ maxZCentralCMS

double Generator::maxZCentralCMS
private

Definition at line 58 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

◆ pdgFilter

std::vector<int> Generator::pdgFilter
private

Definition at line 65 of file Generator.h.

Referenced by Generator(), and IsInTheFilterList().

◆ pdgFilterSel

bool Generator::pdgFilterSel
private

Definition at line 66 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

◆ theDecLenCut

double Generator::theDecLenCut
private

Definition at line 57 of file Generator.h.

Referenced by Generator().

◆ theDecRCut2

double Generator::theDecRCut2
private

Definition at line 55 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

◆ theEtaCutForHector

double Generator::theEtaCutForHector
private

Definition at line 56 of file Generator.h.

Referenced by Generator().

◆ theMaxEtaCut

double Generator::theMaxEtaCut
private

Definition at line 51 of file Generator.h.

Referenced by Generator(), and particlePassesPrimaryCuts().

◆ theMaxPCut

double Generator::theMaxPCut
private

Definition at line 54 of file Generator.h.

Referenced by Generator(), HepMC2G4(), and particlePassesPrimaryCuts().

◆ theMaxPhiCut

double Generator::theMaxPhiCut
private

Definition at line 49 of file Generator.h.

Referenced by Generator(), HepMC2G4(), and particlePassesPrimaryCuts().

◆ theMinEtaCut

double Generator::theMinEtaCut
private

Definition at line 50 of file Generator.h.

Referenced by Generator().

◆ theMinPCut

double Generator::theMinPCut
private

Definition at line 52 of file Generator.h.

Referenced by Generator().

◆ theMinPhiCut

double Generator::theMinPhiCut
private

Definition at line 48 of file Generator.h.

Referenced by Generator().

◆ theMinPtCut2

double Generator::theMinPtCut2
private

Definition at line 53 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

◆ verbose

int Generator::verbose
private

◆ vtx_

math::XYZTLorentzVector* Generator::vtx_
private

Definition at line 62 of file Generator.h.

Referenced by genVertex(), and HepMC2G4().

◆ weight_

double Generator::weight_
private

Definition at line 63 of file Generator.h.

Referenced by eventWeight(), and HepMC2G4().

◆ Z_hector

double Generator::Z_hector
private

Definition at line 64 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

◆ Z_lmax

double Generator::Z_lmax
private

Definition at line 64 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

◆ Z_lmin

double Generator::Z_lmin
private

Definition at line 64 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

Generator::Z_lmax
double Z_lmax
Definition: Generator.h:64
Generator::theMaxPhiCut
double theMaxPhiCut
Definition: Generator.h:49
mps_fire.i
i
Definition: mps_fire.py:428
mps_update.status
status
Definition: mps_update.py:69
Generator::theDecLenCut
double theDecLenCut
Definition: Generator.h:57
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
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:88
Generator::isExoticNonDetectable
bool isExoticNonDetectable(int pdgcode) const
Definition: Generator.cc:525
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
SimG4Exception
Definition: SimG4Exception.h:13
hybridSuperClusters_cfi.xi
xi
Definition: hybridSuperClusters_cfi.py:10
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:532
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:517
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
LumiMonitorFilter::Describe
void Describe() const
Definition: LumiMonitorFilter.cc:13
Generator::fPDGFilter
bool fPDGFilter
Definition: Generator.h:67
PVValHelper::eta
Definition: PVValidationHelpers.h:69
Generator::weight_
double weight_
Definition: Generator.h:63
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
Generator::theMaxEtaCut
double theMaxEtaCut
Definition: Generator.h:51
Generator::theEtaCutForHector
double theEtaCutForHector
Definition: Generator.h:56
Generator::Z_lmin
double Z_lmin
Definition: Generator.h:64
createTree.dd
string dd
Definition: createTree.py:154
Generator::particleAssignDaughters
void particleAssignDaughters(G4PrimaryParticle *p, HepMC::GenParticle *hp, double length)
Definition: Generator.cc:423
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
Generator::theMinPCut
double theMinPCut
Definition: Generator.h:52
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
Generator::fLumiFilter
LumiMonitorFilter * fLumiFilter
Definition: Generator.h:60
edm::ParameterSet
Definition: ParameterSet.h:47
geometryCSVtoXML.yy
yy
Definition: geometryCSVtoXML.py:19
GeV
const double GeV
Definition: MathUtil.h:16
Generator::pdgFilterSel
bool pdgFilterSel
Definition: Generator.h:66
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
GenParticleInfo
Definition: GenParticleInfo.h:6
GenParticle.GenParticle
GenParticle
Definition: GenParticle.py:18
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
Generator::evt_
HepMC::GenEvent * evt_
Definition: Generator.h:61
LumiMonitorFilter
Definition: LumiMonitorFilter.h:6
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:30
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:590
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
Generator::pdgFilter
std::vector< int > pdgFilter
Definition: Generator.h:65
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37