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::GenEvent * genEvent () 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::GenEvent * evt_
 
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 ( const edm::ParameterSet p)

Definition at line 24 of file Generator.cc.

References LumiMonitorFilter::Describe(), edm::ParameterSet::exists(), JetChargeProducer_cfi::exp, fEtaCuts, fFiductialCuts, fLumiFilter, fPCuts, fPDGFilter, fPhiCuts, fPtransCut, edm::ParameterSet::getParameter(), cuy::ii, csvLumiCalc::lumi, pdgFilter, pdgFilterSel, theDecLenCut, theDecRCut2, theEtaCutForHector, theMaxEtaCut, theMinEtaCut, theMinPCut, theMinPtCut2, Z_hector, Z_lmax, and Z_lmin.

24  :
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 {
47  bool lumi = p.getParameter<bool>("ApplyLumiMonitorCuts");
48  if(lumi) { fLumiFilter = new LumiMonitorFilter(); }
49 
50  double theRDecLenCut = p.getParameter<double>("RDecLenCut")*cm;
51  theDecRCut2 = theRDecLenCut*theRDecLenCut;
52 
54 
55  double theDecLenCut = p.getParameter<double>("LDecLenCut")*cm;
56 
58 
59  pdgFilter.resize(0);
60  if ( p.exists("PDGselection") ) {
61  pdgFilterSel = (p.getParameter<edm::ParameterSet>("PDGselection")).
62  getParameter<bool>("PDGfilterSel");
63  pdgFilter = (p.getParameter<edm::ParameterSet>("PDGselection")).
64  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))
87  / ( 2*exp(-theEtaCutForHector) ) );
88 
89  edm::LogVerbatim("SimG4CoreGenerator")
90  << "SimG4Core/Generator: Rdecaycut= " << theRDecLenCut/cm
91  << " cm; Zdecaycut= " << theDecLenCut/cm
92  << "Z_min= " << Z_lmin/cm << " cm; Z_max= " << Z_lmax
93  << " cm; Z_hector = " << Z_hector << " cm\n"
94  << " ApplyCuts: " << fFiductialCuts
95  << " PCuts: " << fPCuts << " PtransCut: " << fPtransCut
96  << " EtaCut: " << fEtaCuts
97  << " PhiCut: " << fPhiCuts
98  << " LumiMonitorCut: " << lumi;
99  if(lumi) { fLumiFilter->Describe(); }
100 }
double theDecRCut2
Definition: Generator.h:57
bool fPhiCuts
Definition: Generator.h:48
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
double theMinPtCut2
Definition: Generator.h:55
double theEtaCutForHector
Definition: Generator.h:58
double Z_lmax
Definition: Generator.h:65
double theMaxPhiCut
Definition: Generator.h:51
bool fPtransCut
Definition: Generator.h:46
bool exists(std::string const &parameterName) const
checks if a parameter exists
double theDecLenCut
Definition: Generator.h:59
double theMinEtaCut
Definition: Generator.h:52
bool pdgFilterSel
Definition: Generator.h:67
double theMinPCut
Definition: Generator.h:54
LumiMonitorFilter * fLumiFilter
Definition: Generator.h:61
bool fFiductialCuts
Definition: Generator.h:49
bool fPDGFilter
Definition: Generator.h:68
double theMinPhiCut
Definition: Generator.h:50
double weight_
Definition: Generator.h:64
double theMaxEtaCut
Definition: Generator.h:53
ii
Definition: cuy.py:590
double theMaxPCut
Definition: Generator.h:56
void Describe() const
math::XYZTLorentzVector * vtx_
Definition: Generator.h:63
HepMC::GenEvent * evt_
Definition: Generator.h:62
double Z_lmin
Definition: Generator.h:65
int verbose
Definition: Generator.h:60
std::vector< int > pdgFilter
Definition: Generator.h:66
bool fEtaCuts
Definition: Generator.h:47
double Z_hector
Definition: Generator.h:65
bool fPCuts
Definition: Generator.h:45
Generator::~Generator ( )
virtual

Definition at line 102 of file Generator.cc.

References fLumiFilter.

103 {
104  delete fLumiFilter;
105 }
LumiMonitorFilter * fLumiFilter
Definition: Generator.h:61

Member Function Documentation

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

Definition at line 29 of file Generator.h.

References evt_.

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

29 { return evt_; }
HepMC::GenEvent * evt_
Definition: Generator.h:62
virtual const math::XYZTLorentzVector* Generator::genVertex ( ) const
inlinevirtual

Definition at line 30 of file Generator.h.

References vtx_.

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

30 { return vtx_; }
math::XYZTLorentzVector * vtx_
Definition: Generator.h:63
void Generator::HepMC2G4 ( const HepMC::GenEvent *  g,
G4Event *  e 
)

Definition at line 107 of file Generator.cc.

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, nullptr, AlCaHLTBitMon_ParallelJobs::p, particleAssignDaughters(), pdgFilterSel, phi, setGenId(), mathSSE::sqrt(), mps_update::status, theDecRCut2, theMaxPCut, theMaxPhiCut, theMinPtCut2, vtx_, weight_, globals_cff::x1, globals_cff::x2, hybridSuperClusters_cfi::xi, geometryCSVtoXML::xx, geometryCSVtoXML::yy, Z_hector, Z_lmax, and Z_lmin.

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

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

Definition at line 546 of file Generator.cc.

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

Referenced by eventWeight(), and HepMC2G4().

547 {
548  int pdgid = std::abs(pdgcode);
549  return ((pdgid >= 1000000 && pdgid < 4000000) || // SUSY, R-hadron, and technicolor particles
550  pdgid == 17 || // 4th generation lepton
551  pdgid == 34 || // W-prime
552  pdgid == 37) // charged Higgs
553  ? true : false;
554 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool Generator::isExoticNonDetectable ( int  pdgcode) const
private

Definition at line 556 of file Generator.cc.

References funct::abs(), ALCARECOTkAlJpsiMuMu_cff::charge, source_particleGun_cfi::ParticleID, BPhysicsValidation_cfi::pdgid, and sysUtil::pid.

Referenced by eventWeight(), and HepMC2G4().

557 {
558  int pdgid = std::abs(pdgcode);
559  HepPDT::ParticleID pid(pdgcode);
560  int charge = pid.threeCharge();
561  return ((charge==0) && (pdgid >= 1000000 && pdgid < 1000040)) // SUSY
562  ? true : false;
563 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool Generator::IsInTheFilterList ( int  pdgcode) const
private

Definition at line 565 of file Generator.cc.

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

Referenced by eventWeight(), and HepMC2G4().

566 {
567  int pdgid = std::abs(pdgcode);
568  for(auto & pdg : pdgFilter) { if(std::abs(pdg) == pdgid) { return true; } }
569  return false;
570 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< int > pdgFilter
Definition: Generator.h:66
void Generator::nonBeamEvent2G4 ( const HepMC::GenEvent *  g,
G4Event *  e 
)

Definition at line 572 of file Generator.cc.

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

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

573 {
574  int i = 0;
575  for(HepMC::GenEvent::particle_const_iterator it = evt->particles_begin();
576  it != evt->particles_end(); ++it ) {
577  ++i;
578  HepMC::GenParticle * gp = (*it);
579  int g_status = gp->status();
580  // storing only particle with status == 1
581  if (g_status == 1) {
582  int g_id = gp->pdg_id();
583  G4PrimaryParticle * g4p =
584  new G4PrimaryParticle(g_id,gp->momentum().px()*GeV,
585  gp->momentum().py()*GeV,
586  gp->momentum().pz()*GeV);
587  if (g4p->GetG4code() != nullptr) {
588  g4p->SetMass(g4p->GetG4code()->GetPDGMass());
589  g4p->SetCharge(g4p->GetG4code()->GetPDGCharge());
590  }
591  setGenId(g4p,i);
592  if (particlePassesPrimaryCuts(g4p->GetMomentum())) {
593  G4PrimaryVertex * v =
594  new G4PrimaryVertex(gp->production_vertex()->position().x()*mm,
595  gp->production_vertex()->position().y()*mm,
596  gp->production_vertex()->position().z()*mm,
597  gp->production_vertex()->position().t()*mm/c_light);
598  v->SetPrimary(g4p);
599  g4evt->AddPrimaryVertex(v);
600  if(verbose > 0) { v->Print(); }
601 
602  } else {
603  delete g4p;
604  }
605  }
606  } // end loop on HepMC particles
607 }
void setGenId(G4PrimaryParticle *p, int id) const
Definition: Generator.h:41
const double GeV
Definition: MathUtil.h:16
bool particlePassesPrimaryCuts(const G4ThreeVector &p) const
Definition: Generator.cc:513
void Generator::particleAssignDaughters ( G4PrimaryParticle *  p,
HepMC::GenParticle *  hp,
double  length 
)
private

Definition at line 436 of file Generator.cc.

References class-composition::children, GeV, LogDebug, nullptr, AlCaHLTBitMon_ParallelJobs::p, setGenId(), mathSSE::sqrt(), globals_cff::x1, and globals_cff::x2.

Referenced by eventWeight(), and HepMC2G4().

439 {
440  if ( verbose > 1 ) {
441  LogDebug("SimG4CoreGenerator")
442  << "Special case of long decay length \n"
443  << "Assign daughters with to mother with decaylength="
444  << decaylength/cm << " cm";
445  }
446  math::XYZTLorentzVector p(vp->momentum().px(), vp->momentum().py(),
447  vp->momentum().pz(), vp->momentum().e());
448 
449  // defined preassigned decay time
450  double proper_time = decaylength/(p.Beta()*p.Gamma()*c_light);
451  g4p->SetProperTime(proper_time);
452 
453  if( verbose > 2 ) {
454  LogDebug("SimG4CoreGenerator") <<" px= "<< p.px()
455  <<" py= "<< p.py()
456  <<" pz= "<< p.pz()
457  <<" e= " << p.e()
458  <<" beta= "<< p.Beta()
459  <<" gamma= " << p.Gamma()
460  <<" Proper time= " <<proper_time/ns <<" ns";
461  }
462 
463  // the particle will decay after the same length if it
464  // has not interacted before
465  double x1 = vp->end_vertex()->position().x();
466  double y1 = vp->end_vertex()->position().y();
467  double z1 = vp->end_vertex()->position().z();
468 
469  for (HepMC::GenVertex::particle_iterator
470  vpdec= vp->end_vertex()->particles_begin(HepMC::children);
471  vpdec != vp->end_vertex()->particles_end(HepMC::children); ++vpdec) {
472 
473  //transform decay products such that in the rest frame of mother
474  math::XYZTLorentzVector pdec((*vpdec)->momentum().px(),
475  (*vpdec)->momentum().py(),
476  (*vpdec)->momentum().pz(),
477  (*vpdec)->momentum().e());
478 
479  // children should only be taken into account once
480  G4PrimaryParticle * g4daught=
481  new G4PrimaryParticle((*vpdec)->pdg_id(), pdec.x()*GeV,
482  pdec.y()*GeV, pdec.z()*GeV);
483 
484  if ( g4daught->GetG4code() != nullptr )
485  {
486  g4daught->SetMass( g4daught->GetG4code()->GetPDGMass() ) ;
487  g4daught->SetCharge( g4daught->GetG4code()->GetPDGCharge() ) ;
488  }
489 
490  // V.I. do not use SetWeight but the same code
491  // value of the code compute inside TrackWithHistory
492  setGenId( g4daught, (*vpdec)->barcode() );
493 
494  if ( verbose > 2 ) LogDebug("SimG4CoreGenerator")
495  <<"Assigning a "<< (*vpdec)->pdg_id()
496  <<" as daughter of a " << vp->pdg_id();
497  if ( (*vpdec)->status() == 2 && (*vpdec)->end_vertex() != nullptr)
498  {
499  double x2 = (*vpdec)->end_vertex()->position().x();
500  double y2 = (*vpdec)->end_vertex()->position().y();
501  double z2 = (*vpdec)->end_vertex()->position().z();
502  double dd = std::sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
503  particleAssignDaughters(g4daught,*vpdec,dd);
504  }
505  (*vpdec)->set_status(1000+(*vpdec)->status());
506  g4p->SetDaughter(g4daught);
507 
508  if ( verbose > 1 ) g4daught->Print();
509  }
510 }
#define LogDebug(id)
void setGenId(G4PrimaryParticle *p, int id) const
Definition: Generator.h:41
const double GeV
Definition: MathUtil.h:16
#define nullptr
void particleAssignDaughters(G4PrimaryParticle *p, HepMC::GenParticle *hp, double length)
Definition: Generator.cc:436
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
T sqrt(T t)
Definition: SSEVec.h:18
Definition: DDUnits.h:8
bool Generator::particlePassesPrimaryCuts ( const G4ThreeVector &  p) const
private

Definition at line 513 of file Generator.cc.

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

Referenced by eventWeight(), and nonBeamEvent2G4().

514 {
515  bool flag = true;
516  double ptot = p.mag();
517  if (fPCuts && (ptot < theMinPCut*GeV || ptot > theMaxPCut*GeV)) {
518  flag = false;
519  }
520  if (fEtaCuts && flag) {
521  double pz = p.z();
522  if(ptot < pz + 1.e-10) {
523  flag = false;
524 
525  } else {
526  double eta = 0.5*G4Log((ptot + pz)/(ptot - pz));
527  if(eta < theMinEtaCut || eta > theMaxEtaCut) {
528  flag = false;
529  }
530  }
531  }
532  if (fPhiCuts && flag) {
533  double phi = p.phi();
534  if(phi < theMinPhiCut || phi > theMaxPhiCut) {
535  flag = false;
536  }
537  }
538 
539  if ( verbose > 2 ) LogDebug("SimG4CoreGenerator")
540  << "Generator ptot(GeV)= " << ptot/GeV << " eta= " << p.eta()
541  << " phi= " << p.phi() << " Flag= " << flag;
542 
543  return flag;
544 }
#define LogDebug(id)
bool fPhiCuts
Definition: Generator.h:48
const double GeV
Definition: MathUtil.h:16
double theMaxPhiCut
Definition: Generator.h:51
double theMaxEtaCut
Definition: Generator.h:53
double theMaxPCut
Definition: Generator.h:56
bool fEtaCuts
Definition: Generator.h:47
bool fPCuts
Definition: Generator.h:45
void Generator::setGenEvent ( const HepMC::GenEvent *  inpevt)
inline

Definition at line 25 of file Generator.h.

References MillePedeFileConverter_cfg::e, evt_, g, HepMC2G4(), nonBeamEvent2G4(), and mathSSE::return().

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

26  { evt_ = (HepMC::GenEvent*)inpevt; return ; }
return((rh^lh)&mask)
HepMC::GenEvent * evt_
Definition: Generator.h:62
void Generator::setGenId ( G4PrimaryParticle *  p,
int  id 
) const
inlineprivate

Definition at line 41 of file Generator.h.

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

Member Data Documentation

HepMC::GenEvent* Generator::evt_
private

Definition at line 62 of file Generator.h.

Referenced by genEvent(), and setGenEvent().

bool Generator::fEtaCuts
private

Definition at line 47 of file Generator.h.

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

bool Generator::fFiductialCuts
private

Definition at line 49 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

LumiMonitorFilter* Generator::fLumiFilter
private

Definition at line 61 of file Generator.h.

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

bool Generator::fPCuts
private

Definition at line 45 of file Generator.h.

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

bool Generator::fPDGFilter
private

Definition at line 68 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

bool Generator::fPhiCuts
private

Definition at line 48 of file Generator.h.

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

bool Generator::fPtransCut
private

Definition at line 46 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

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

Definition at line 66 of file Generator.h.

Referenced by Generator(), and IsInTheFilterList().

bool Generator::pdgFilterSel
private

Definition at line 67 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

double Generator::theDecLenCut
private

Definition at line 59 of file Generator.h.

Referenced by Generator().

double Generator::theDecRCut2
private

Definition at line 57 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

double Generator::theEtaCutForHector
private

Definition at line 58 of file Generator.h.

Referenced by Generator().

double Generator::theMaxEtaCut
private

Definition at line 53 of file Generator.h.

Referenced by Generator(), and particlePassesPrimaryCuts().

double Generator::theMaxPCut
private

Definition at line 56 of file Generator.h.

Referenced by HepMC2G4(), and particlePassesPrimaryCuts().

double Generator::theMaxPhiCut
private

Definition at line 51 of file Generator.h.

Referenced by HepMC2G4(), and particlePassesPrimaryCuts().

double Generator::theMinEtaCut
private

Definition at line 52 of file Generator.h.

Referenced by Generator().

double Generator::theMinPCut
private

Definition at line 54 of file Generator.h.

Referenced by Generator().

double Generator::theMinPhiCut
private

Definition at line 50 of file Generator.h.

double Generator::theMinPtCut2
private

Definition at line 55 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

int Generator::verbose
private

Definition at line 60 of file Generator.h.

math::XYZTLorentzVector* Generator::vtx_
private

Definition at line 63 of file Generator.h.

Referenced by genVertex(), and HepMC2G4().

double Generator::weight_
private

Definition at line 64 of file Generator.h.

Referenced by eventWeight(), and HepMC2G4().

double Generator::Z_hector
private

Definition at line 65 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

double Generator::Z_lmax
private

Definition at line 65 of file Generator.h.

Referenced by Generator(), and HepMC2G4().

double Generator::Z_lmin
private

Definition at line 65 of file Generator.h.

Referenced by Generator(), and HepMC2G4().