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 nonBeamEvent2G4 (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
 
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 24 of file Generator.cc.

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")), // in radians (CMS standard)
30  theMaxPhiCut(p.getParameter<double>("MaxPhiCut")),
31  theMinEtaCut(p.getParameter<double>("MinEtaCut")),
32  theMaxEtaCut(p.getParameter<double>("MaxEtaCut")),
33  theMinPCut(p.getParameter<double>("MinPCut")), // in GeV (CMS standard)
34  theMaxPCut(p.getParameter<double>("MaxPCut")),
35  theEtaCutForHector(p.getParameter<double>("EtaCutForHector")),
36  verbose(p.getUntrackedParameter<int>("Verbosity", 0)),
37  fLumiFilter(nullptr),
38  evt_(nullptr),
39  vtx_(nullptr),
40  weight_(0),
41  Z_lmin(0),
42  Z_lmax(0),
43  Z_hector(0),
44  pdgFilterSel(false),
45  fPDGFilter(false) {
46  bool lumi = p.getParameter<bool>("ApplyLumiMonitorCuts");
47  if (lumi) {
49  }
50 
51  double theRDecLenCut = p.getParameter<double>("RDecLenCut") * cm;
52  theDecRCut2 = theRDecLenCut * theRDecLenCut;
53 
55 
56  double theDecLenCut = p.getParameter<double>("LDecLenCut") * cm;
57 
59 
60  pdgFilter.resize(0);
61  if (p.exists("PDGselection")) {
62  pdgFilterSel = (p.getParameter<edm::ParameterSet>("PDGselection")).getParameter<bool>("PDGfilterSel");
63  pdgFilter = (p.getParameter<edm::ParameterSet>("PDGselection")).getParameter<std::vector<int>>("PDGfilter");
64  if (!pdgFilter.empty()) {
65  fPDGFilter = true;
66  std::stringstream ss;
67  ss << "SimG4Core/Generator: ";
68  if (pdgFilterSel) {
69  ss << " Selecting only PDG ID = ";
70  } else {
71  ss << " Filtering out PDG ID = ";
72  }
73  for (unsigned int ii = 0; ii < pdgFilter.size(); ++ii) {
74  ss << pdgFilter[ii] << " ";
75  }
76  edm::LogVerbatim("SimG4CoreGenerator") << ss.str();
77  }
78  }
79 
80  if (fEtaCuts) {
81  Z_lmax = theRDecLenCut * ((1 - exp(-2 * theMaxEtaCut)) / (2 * exp(-theMaxEtaCut)));
82  Z_lmin = theRDecLenCut * ((1 - exp(-2 * theMinEtaCut)) / (2 * exp(-theMinEtaCut)));
83  }
84 
85  Z_hector = theRDecLenCut * ((1 - exp(-2 * theEtaCutForHector)) / (2 * exp(-theEtaCutForHector)));
86 
87  edm::LogVerbatim("SimG4CoreGenerator") << "SimG4Core/Generator: Rdecaycut= " << theRDecLenCut / cm
88  << " cm; Zdecaycut= " << theDecLenCut / cm << "Z_min= " << Z_lmin / cm
89  << " cm; Z_max= " << Z_lmax << " cm; Z_hector = " << Z_hector << " cm\n"
90  << " ApplyCuts: " << fFiductialCuts
91  << " PCuts: " << fPCuts << " PtransCut: " << fPtransCut
92  << " EtaCut: " << fEtaCuts << " PhiCut: " << fPhiCuts
93  << " LumiMonitorCut: " << lumi;
94  if (lumi) {
96  }
97 }

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

◆ ~Generator()

Generator::~Generator ( )
virtual

Definition at line 99 of file Generator.cc.

99 { 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 101 of file Generator.cc.

101  {
102  HepMC::GenEvent *evt = new HepMC::GenEvent(*evt_orig);
103 
104  if (*(evt->vertices_begin()) == nullptr) {
105  std::stringstream ss;
106  ss << "SimG4Core/Generator: in event " << g4evt->GetEventID() << " Corrupted Event - GenEvent with no vertex \n";
107  throw SimG4Exception(ss.str());
108  }
109 
110  if (!evt->weights().empty()) {
111  weight_ = evt->weights()[0];
112  for (unsigned int iw = 1; iw < evt->weights().size(); ++iw) {
113  // terminate if the vector of weights contains a zero-weight
114  if (evt->weights()[iw] <= 0)
115  break;
116  weight_ *= evt->weights()[iw];
117  }
118  }
119 
120  if (vtx_ != nullptr) {
121  delete vtx_;
122  }
123  vtx_ = new math::XYZTLorentzVector((*(evt->vertices_begin()))->position().x(),
124  (*(evt->vertices_begin()))->position().y(),
125  (*(evt->vertices_begin()))->position().z(),
126  (*(evt->vertices_begin()))->position().t());
127 
128  edm::LogVerbatim("SimG4CoreGenerator") << "Generator: primary Vertex = (" << vtx_->x() << ", " << vtx_->y() << ", "
129  << vtx_->z() << ")";
130 
131  unsigned int ng4vtx = 0;
132 
133  for (HepMC::GenEvent::vertex_const_iterator vitr = evt->vertices_begin(); vitr != evt->vertices_end(); ++vitr) {
134  // loop for vertex, is it a real vertex?
135  // Set qvtx to true for any particles that should be propagated by GEANT,
136  // i.e., status 1 particles or status 2 particles that decay outside the
137  // beampipe.
138  G4bool qvtx = false;
139  HepMC::GenVertex::particle_iterator pitr;
140  for (pitr = (*vitr)->particles_begin(HepMC::children); pitr != (*vitr)->particles_end(HepMC::children); ++pitr) {
141  // For purposes of this function, the status is defined as follows:
142  // 1: particles are not decayed by generator
143  // 2: particles are decayed by generator but need to be propagated by
144  // GEANT 3: particles are decayed by generator but do not need to be
145  // propagated by GEANT
146  int status = (*pitr)->status();
147  int pdg = (*pitr)->pdg_id();
148  if (status > 3 && isExotic(pdg) && (!(isExoticNonDetectable(pdg)))) {
149  // In Pythia 8, there are many status codes besides 1, 2, 3.
150  // By setting the status to 2 for exotic particles, they will be
151  // checked: if its decay vertex is outside the beampipe, it will be
152  // propagated by GEANT. Some Standard Model particles, e.g., K0, cannot
153  // be propagated by GEANT, so do not change their status code.
154  status = 2;
155  }
156 
157  // Particles which are not decayed by generator
158  if (status == 1) {
159  // filter out unwanted particles and vertices
161  continue;
162  }
163 
164  qvtx = true;
165  if (verbose > 2)
166  LogDebug("SimG4CoreGenerator") << "GenVertex barcode = " << (*vitr)->barcode()
167  << " selected for GenParticle barcode = " << (*pitr)->barcode();
168  break;
169  }
170  // The selection is made considering if the partcile with status = 2
171  // have the end_vertex with a radius greater than the radius of beampipe
172  // cylinder (no requirement on the Z of the vertex is applyed).
173  else if (status == 2) {
174  if ((*pitr)->end_vertex() != nullptr) {
175  double xx = (*pitr)->end_vertex()->position().x();
176  double yy = (*pitr)->end_vertex()->position().y();
177  double r_dd = xx * xx + yy * yy;
178  if (r_dd > theDecRCut2) {
179  qvtx = true;
180  if (verbose > 2)
181  LogDebug("SimG4CoreGenerator")
182  << "GenVertex barcode = " << (*vitr)->barcode()
183  << " selected for GenParticle barcode = " << (*pitr)->barcode() << " radius = " << std::sqrt(r_dd);
184  break;
185  }
186  } else {
187  // particles with status 2 without end_vertex are
188  // equivalent to stable
189  qvtx = true;
190  break;
191  }
192  }
193  }
194 
195  // if this vertex is inside fiductial volume inside the beam pipe
196  // and has no long-lived secondary the vertex is not saved
197  if (!qvtx) {
198  continue;
199  }
200 
201  double x1 = (*vitr)->position().x() * mm;
202  double y1 = (*vitr)->position().y() * mm;
203  double z1 = (*vitr)->position().z() * mm;
204  double t1 = (*vitr)->position().t() * mm / c_light;
205 
206  G4PrimaryVertex *g4vtx = new G4PrimaryVertex(x1, y1, z1, t1);
207 
208  for (pitr = (*vitr)->particles_begin(HepMC::children); pitr != (*vitr)->particles_end(HepMC::children); ++pitr) {
209  int status = (*pitr)->status();
210  int pdg = (*pitr)->pdg_id();
211  bool hasDecayVertex = (nullptr != (*pitr)->end_vertex()) ? true : false;
212 
213  // Filter on allowed particle species if required
214  if (fPDGFilter) {
215  bool isInTheList = IsInTheFilterList(pdg);
216  if ((!pdgFilterSel && isInTheList) || (pdgFilterSel && !isInTheList)) {
217  edm::LogVerbatim("SimG4CoreGenerator")
218  << " Skiped GenParticle barcode= " << (*pitr)->barcode() << " PDGid= " << pdg << " status= " << status
219  << " isExotic: " << isExotic(pdg) << " isExoticNotDet: " << isExoticNonDetectable(pdg)
220  << " isInTheList: " << isInTheList << " hasDecayVertex: " << hasDecayVertex;
221  continue;
222  }
223  }
224 
225  edm::LogVerbatim("SimG4CoreGenerator")
226  << "Generator: pdg= " << pdg << " status= " << status << " hasPreDefinedDecay: " << hasDecayVertex
227  << " isExotic: " << isExotic(pdg) << " isExoticNotDet: " << isExoticNonDetectable(pdg)
228  << " isInTheList: " << IsInTheFilterList(pdg) << "\n (x,y,z,t): (" << x1 << "," << y1 << "," << z1
229  << "," << t1 << ")";
230 
231  if (status > 3 && isExotic(pdg) && (!(isExoticNonDetectable(pdg)))) {
232  status = hasDecayVertex ? 2 : 1;
233  }
234 
235  // this particle has predefined decay but has no vertex
236  if (2 == status && !hasDecayVertex) {
237  edm::LogWarning("SimG4CoreGenerator: in event ") << g4evt->GetEventID() << " a particle "
238  << " pdgid= " << pdg
239  << " has status=2 but has no decay vertex, so will be fully "
240  "tracked by Geant4";
241  status = 1;
242  }
243 
244  double x2 = x1;
245  double y2 = y1;
246  double z2 = z1;
247  double decay_length = 0.0;
248  if (2 == status) {
249  x2 = (*pitr)->end_vertex()->position().x();
250  y2 = (*pitr)->end_vertex()->position().y();
251  z2 = (*pitr)->end_vertex()->position().z();
252  decay_length = std::sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1));
253  }
254 
255  bool toBeAdded = (fFiductialCuts) ? false : true;
256 
257  double px = (*pitr)->momentum().px();
258  double py = (*pitr)->momentum().py();
259  double pz = (*pitr)->momentum().pz();
260  double ptot = std::sqrt(px * px + py * py + pz * pz);
261  math::XYZTLorentzVector p(px, py, pz, (*pitr)->momentum().e());
262 
263  double ximpact = x1;
264  double yimpact = y1;
265  double zimpact = z1;
266 
267  // protection against numerical problems for extremely low momenta
268  // compute impact point at transition to Hector
269  const double minTan = 1.e-20;
270  if (std::abs(z1) < Z_hector && std::abs(pz) >= minTan * ptot) {
271  if (pz > 0.0) {
272  zimpact = Z_hector;
273  } else {
274  zimpact = -Z_hector;
275  }
276  double del = (zimpact - z1) / pz;
277  ximpact += del * px;
278  yimpact += del * py;
279  }
280  double rimpact2 = ximpact * ximpact + yimpact * yimpact;
281 
282  if (verbose > 2)
283  LogDebug("SimG4CoreGenerator") << "Processing GenParticle barcode= " << (*pitr)->barcode() << " pdg= " << pdg
284  << " status= " << (*pitr)->status() << " st= " << status
285  << " rimpact(cm)= " << std::sqrt(rimpact2) / cm
286  << " zimpact(cm)= " << zimpact / cm << " ptot(GeV)= " << ptot
287  << " pz(GeV)= " << pz;
288 
289  // Particles of status 1 trasnported along the beam pipe for forward
290  // detectors (HECTOR) always pass to Geant4 without cuts
291  if (1 == status && std::abs(zimpact) >= Z_hector && rimpact2 <= theDecRCut2) {
292  toBeAdded = true;
293  if (verbose > 2)
294  LogDebug("SimG4CoreGenerator") << "GenParticle barcode = " << (*pitr)->barcode() << " passed case 3";
295  } else {
296  // Standard case: particles not decayed by the generator
297  if (1 == status && (std::abs(zimpact) < Z_hector || rimpact2 > theDecRCut2)) {
298  // Ptot cut for all particles
299  if (fPCuts && (ptot < theMinPCut || ptot > theMaxPCut)) {
300  continue;
301  }
302  // phi cut is applied mainly for particle gun
303  if (fPhiCuts) {
304  double phi = p.phi();
305  if (phi < theMinPhiCut || phi > theMaxPhiCut) {
306  continue;
307  }
308  }
309  // eta cut is applied if position of the decay
310  // is within vacuum chamber and limited in Z
311  if (fEtaCuts) {
312  // eta cut
313  double xi = x1;
314  double yi = y1;
315  double zi = z1;
316 
317  // can be propagated along Z
318  if (std::abs(pz) >= minTan * ptot) {
319  if ((zi >= Z_lmax) & (pz < 0.0)) {
320  zi = Z_lmax;
321  } else if ((zi <= Z_lmin) & (pz > 0.0)) {
322  zi = Z_lmin;
323  } else {
324  if (pz > 0) {
325  zi = Z_lmax;
326  } else {
327  zi = Z_lmin;
328  }
329  }
330  double del = (zi - z1) / pz;
331  xi += del * px;
332  yi += del * py;
333  }
334  // check eta cut
335  if ((zi >= Z_lmin) & (zi <= Z_lmax) & (xi * xi + yi * yi < theDecRCut2)) {
336  continue;
337  }
338  }
339  if (fLumiFilter && !fLumiFilter->isGoodForLumiMonitor(*pitr)) {
340  continue;
341  }
342  toBeAdded = true;
343  if (verbose > 2)
344  LogDebug("SimG4CoreGenerator") << "GenParticle barcode = " << (*pitr)->barcode() << " passed case 1";
345 
346  // Decay chain outside the fiducial cylinder defined by theRDecLenCut
347  // are used for Geant4 tracking with predefined decay channel
348  // In the case of decay in vacuum particle is not tracked by Geant4
349  } else if (2 == status && x2 * x2 + y2 * y2 >= theDecRCut2 && std::abs(z2) < Z_hector) {
350  toBeAdded = true;
351  if (verbose > 2)
352  LogDebug("SimG4CoreGenerator") << "GenParticle barcode = " << (*pitr)->barcode() << " passed case 2"
353  << " decay_length(cm)= " << decay_length / cm;
354  }
355  }
356  if (toBeAdded) {
357  G4PrimaryParticle *g4prim = new G4PrimaryParticle(pdg, px * GeV, py * GeV, pz * GeV);
358 
359  if (g4prim->GetG4code() != nullptr) {
360  g4prim->SetMass(g4prim->GetG4code()->GetPDGMass());
361  double charge = g4prim->GetG4code()->GetPDGCharge();
362 
363  // apply Pt cut
364  if (fPtransCut && 0.0 != charge && px * px + py * py < theMinPtCut2) {
365  delete g4prim;
366  continue;
367  }
368  g4prim->SetCharge(charge);
369  }
370 
371  // V.I. do not use SetWeight but the same code
372  // value of the code compute inside TrackWithHistory
373  // g4prim->SetWeight( 10000*(*vpitr)->barcode() ) ;
374  setGenId(g4prim, (*pitr)->barcode());
375 
376  if (2 == status) {
377  particleAssignDaughters(g4prim, (HepMC::GenParticle *)*pitr, decay_length);
378  }
379  if (verbose > 1)
380  g4prim->Print();
381  g4vtx->SetPrimary(g4prim);
382  edm::LogVerbatim("SimG4CoreGenerator") << "Generator: new particle pdg= " << pdg << " Ptot(GeV/c)= " << ptot
383  << " Pt= " << std::sqrt(px * px + py * py);
384  }
385  }
386 
387  if (verbose > 1)
388  g4vtx->Print();
389  g4evt->AddPrimaryVertex(g4vtx);
390  ++ng4vtx;
391  }
392 
393  // Add a protection for completely empty events (produced by LHCTransport):
394  // add a dummy vertex with no particle attached to it
395  if (ng4vtx == 0) {
396  G4PrimaryVertex *g4vtx = new G4PrimaryVertex(0.0, 0.0, 0.0, 0.0);
397  if (verbose > 1)
398  g4vtx->Print();
399  g4evt->AddPrimaryVertex(g4vtx);
400  }
401 
402  delete evt;
403 }

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, AlCaHLTBitMon_ParallelJobs::p, particleAssignDaughters(), 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 498 of file Generator.cc.

498  {
499  int pdgid = std::abs(pdgcode);
500  return ((pdgid >= 1000000 && pdgid < 4000000 && pdgid != 3000022) || // SUSY, R-hadron, and technicolor particles
501  pdgid == 17 || // 4th generation lepton
502  pdgid == 34 || // W-prime
503  pdgid == 37) // charged Higgs
504  ? true
505  : false;
506 }

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

Referenced by HepMC2G4().

◆ isExoticNonDetectable()

bool Generator::isExoticNonDetectable ( int  pdgcode) const
private

Definition at line 508 of file Generator.cc.

508  {
509  int pdgid = std::abs(pdgcode);
510  HepPDT::ParticleID pid(pdgcode);
511  int charge = pid.threeCharge();
512  return ((charge == 0) && (pdgid >= 1000000 && pdgid < 1000040)) // SUSY
513  ? true
514  : false;
515 }

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

Referenced by HepMC2G4().

◆ IsInTheFilterList()

bool Generator::IsInTheFilterList ( int  pdgcode) const
private

Definition at line 517 of file Generator.cc.

517  {
518  int pdgid = std::abs(pdgcode);
519  for (auto &pdg : pdgFilter) {
520  if (std::abs(pdg) == pdgid) {
521  return true;
522  }
523  }
524  return false;
525 }

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

Referenced by HepMC2G4().

◆ nonBeamEvent2G4()

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

Definition at line 527 of file Generator.cc.

527  {
528  int i = 0;
529  for (HepMC::GenEvent::particle_const_iterator it = evt->particles_begin(); it != evt->particles_end(); ++it) {
530  ++i;
531  HepMC::GenParticle *gp = (*it);
532  int g_status = gp->status();
533  // storing only particle with status == 1
534  if (g_status == 1) {
535  int g_id = gp->pdg_id();
536  G4PrimaryParticle *g4p =
537  new G4PrimaryParticle(g_id, gp->momentum().px() * GeV, gp->momentum().py() * GeV, gp->momentum().pz() * GeV);
538  if (g4p->GetG4code() != nullptr) {
539  g4p->SetMass(g4p->GetG4code()->GetPDGMass());
540  g4p->SetCharge(g4p->GetG4code()->GetPDGCharge());
541  }
542  setGenId(g4p, i);
543  if (particlePassesPrimaryCuts(g4p->GetMomentum())) {
544  G4PrimaryVertex *v = new G4PrimaryVertex(gp->production_vertex()->position().x() * mm,
545  gp->production_vertex()->position().y() * mm,
546  gp->production_vertex()->position().z() * mm,
547  gp->production_vertex()->position().t() * mm / c_light);
548  v->SetPrimary(g4p);
549  g4evt->AddPrimaryVertex(v);
550  if (verbose > 0) {
551  v->Print();
552  }
553 
554  } else {
555  delete g4p;
556  }
557  }
558  } // end loop on HepMC particles
559 }

References GenParticle::GenParticle, GeV, runTauDisplay::gp, mps_fire::i, particlePassesPrimaryCuts(), 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 405 of file Generator.cc.

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

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 466 of file Generator.cc.

466  {
467  bool flag = true;
468  double ptot = p.mag();
469  if (fPCuts && (ptot < theMinPCut * GeV || ptot > theMaxPCut * GeV)) {
470  flag = false;
471  }
472  if (fEtaCuts && flag) {
473  double pz = p.z();
474  if (ptot < pz + 1.e-10) {
475  flag = false;
476 
477  } else {
478  double eta = 0.5 * G4Log((ptot + pz) / (ptot - pz));
479  if (eta < theMinEtaCut || eta > theMaxEtaCut) {
480  flag = false;
481  }
482  }
483  }
484  if (fPhiCuts && flag) {
485  double phi = p.phi();
486  if (phi < theMinPhiCut || phi > theMaxPhiCut) {
487  flag = false;
488  }
489  }
490 
491  if (verbose > 2)
492  LogDebug("SimG4CoreGenerator") << "Generator ptot(GeV)= " << ptot / GeV << " eta= " << p.eta()
493  << " phi= " << p.phi() << " Flag= " << flag;
494 
495  return flag;
496 }

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

Referenced by nonBeamEvent2G4().

◆ 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(), nonBeamEvent2G4(), and particleAssignDaughters().

Member Data Documentation

◆ evt_

HepMC::GenEvent* Generator::evt_
private

Definition at line 60 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 59 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 66 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().

◆ pdgFilter

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

Definition at line 64 of file Generator.h.

Referenced by Generator(), and IsInTheFilterList().

◆ pdgFilterSel

bool Generator::pdgFilterSel
private

Definition at line 65 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 HepMC2G4(), and particlePassesPrimaryCuts().

◆ theMaxPhiCut

double Generator::theMaxPhiCut
private

Definition at line 49 of file Generator.h.

Referenced by 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.

◆ 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 61 of file Generator.h.

Referenced by genVertex(), and HepMC2G4().

◆ weight_

double Generator::weight_
private

Definition at line 62 of file Generator.h.

Referenced by eventWeight(), and HepMC2G4().

◆ Z_hector

double Generator::Z_hector
private

Definition at line 63 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

◆ Z_lmax

double Generator::Z_lmax
private

Definition at line 63 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

◆ Z_lmin

double Generator::Z_lmin
private

Definition at line 63 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

Generator::Z_lmax
double Z_lmax
Definition: Generator.h:63
Generator::theMaxPhiCut
double theMaxPhiCut
Definition: Generator.h:49
mps_fire.i
i
Definition: mps_fire.py:355
mps_update.status
status
Definition: mps_update.py:69
Generator::theDecLenCut
double theDecLenCut
Definition: Generator.h:57
Generator::particlePassesPrimaryCuts
bool particlePassesPrimaryCuts(const G4ThreeVector &p) const
Definition: Generator.cc:466
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:508
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
SimG4Exception
Definition: SimG4Exception.h:13
hybridSuperClusters_cfi.xi
xi
Definition: hybridSuperClusters_cfi.py:10
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:517
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:498
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:66
PVValHelper::eta
Definition: PVValidationHelpers.h:69
Generator::weight_
double weight_
Definition: Generator.h:62
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:63
createTree.dd
string dd
Definition: createTree.py:154
Generator::particleAssignDaughters
void particleAssignDaughters(G4PrimaryParticle *p, HepMC::GenParticle *hp, double length)
Definition: Generator.cc:405
Generator::theMaxPCut
double theMaxPCut
Definition: Generator.h:54
edm::LogWarning
Definition: MessageLogger.h:141
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
funct::true
true
Definition: Factorize.h:173
Generator::theMinPCut
double theMinPCut
Definition: Generator.h:52
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
Generator::fLumiFilter
LumiMonitorFilter * fLumiFilter
Definition: Generator.h:59
edm::ParameterSet
Definition: ParameterSet.h:36
geometryCSVtoXML.yy
yy
Definition: geometryCSVtoXML.py:19
GeV
const double GeV
Definition: MathUtil.h:16
Generator::pdgFilterSel
bool pdgFilterSel
Definition: Generator.h:65
Generator::theMinPhiCut
double theMinPhiCut
Definition: Generator.h:48
edm::LogVerbatim
Definition: MessageLogger.h:297
Generator::Z_hector
double Z_hector
Definition: Generator.h:63
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
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
pdg
Definition: pdg_functions.h:28
Generator::vtx_
math::XYZTLorentzVector * vtx_
Definition: Generator.h:61
Generator::evt_
HepMC::GenEvent * evt_
Definition: Generator.h:60
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:58
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:64
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37