20 #include "HepMC/GenEvent.h"
25 #include "CLHEP/Random/RandFlat.h"
54 std::cout <<
" EvtGenProducer starting ... " << std::endl;
66 std::vector<double>());
67 if (polarize_ids.size() != polarize_pol.size()) {
69 <<
"EvtGenProducer requires that the particles_to_polarize and particle_polarization\n"
70 "vectors be the same size. Please fix this in your configuration.";
72 for (
unsigned int ndx = 0; ndx < polarize_ids.size(); ndx++) {
73 if (polarize_pol[ndx] < -1. || polarize_pol[ndx] > 1.) {
75 <<
"EvtGenProducer error: particle polarizations must be in the range -1 < P < 1";
77 polarizations.insert(std::pair<int, float>(polarize_ids[ndx], polarize_pol[ndx]));
81 decay_table_s = decay_table.
fullPath();
82 pdt_s = pdt.fullPath();
83 user_decay_s = user_decay.
fullPath();
89 forced_names = pset.
getParameter< std::vector<std::string> >(
"list_forced_decays");
98 m_PDGs.push_back( 300553 ) ;
99 m_PDGs.push_back( 511 ) ;
100 m_PDGs.push_back( 521 ) ;
101 m_PDGs.push_back( 523 ) ;
102 m_PDGs.push_back( 513 ) ;
103 m_PDGs.push_back( 533 ) ;
104 m_PDGs.push_back( 531 ) ;
106 m_PDGs.push_back( 15 ) ;
108 m_PDGs.push_back( 413 ) ;
109 m_PDGs.push_back( 423 ) ;
110 m_PDGs.push_back( 433 ) ;
111 m_PDGs.push_back( 411 ) ;
112 m_PDGs.push_back( 421 ) ;
113 m_PDGs.push_back( 431 ) ;
114 m_PDGs.push_back( 10411 );
115 m_PDGs.push_back( 10421 );
116 m_PDGs.push_back( 10413 );
117 m_PDGs.push_back( 10423 );
118 m_PDGs.push_back( 20413 );
119 m_PDGs.push_back( 20423 );
121 m_PDGs.push_back( 415 );
122 m_PDGs.push_back( 425 );
123 m_PDGs.push_back( 10431 );
124 m_PDGs.push_back( 20433 );
125 m_PDGs.push_back( 10433 );
126 m_PDGs.push_back( 435 );
128 m_PDGs.push_back( 310 );
129 m_PDGs.push_back( 311 );
130 m_PDGs.push_back( 313 );
131 m_PDGs.push_back( 323 );
132 m_PDGs.push_back( 10321 );
133 m_PDGs.push_back( 10311 );
134 m_PDGs.push_back( 10313 );
135 m_PDGs.push_back( 10323 );
136 m_PDGs.push_back( 20323 );
137 m_PDGs.push_back( 20313 );
138 m_PDGs.push_back( 325 );
139 m_PDGs.push_back( 315 );
141 m_PDGs.push_back( 100313 );
142 m_PDGs.push_back( 100323 );
143 m_PDGs.push_back( 30313 );
144 m_PDGs.push_back( 30323 );
145 m_PDGs.push_back( 30343 );
146 m_PDGs.push_back( 30353 );
147 m_PDGs.push_back( 30363 );
149 m_PDGs.push_back( 111 );
150 m_PDGs.push_back( 221 );
151 m_PDGs.push_back( 113 );
152 m_PDGs.push_back( 213 );
153 m_PDGs.push_back( 223 );
154 m_PDGs.push_back( 331 );
155 m_PDGs.push_back( 333 );
156 m_PDGs.push_back( 20213 );
157 m_PDGs.push_back( 20113 );
158 m_PDGs.push_back( 215 );
159 m_PDGs.push_back( 115 );
160 m_PDGs.push_back( 10213 );
161 m_PDGs.push_back( 10113 );
162 m_PDGs.push_back( 9000111 );
163 m_PDGs.push_back( 9000211 );
164 m_PDGs.push_back( 9010221 );
165 m_PDGs.push_back( 10221 );
166 m_PDGs.push_back( 20223 );
167 m_PDGs.push_back( 20333 );
168 m_PDGs.push_back( 225 );
169 m_PDGs.push_back( 9020221 );
170 m_PDGs.push_back( 335 );
171 m_PDGs.push_back( 10223 );
172 m_PDGs.push_back( 10333 );
173 m_PDGs.push_back( 100213 );
174 m_PDGs.push_back( 100113 );
176 m_PDGs.push_back( 441 );
177 m_PDGs.push_back( 100441 );
178 m_PDGs.push_back( 443 );
179 m_PDGs.push_back( 100443 );
180 m_PDGs.push_back( 9000443 );
181 m_PDGs.push_back( 9010443 );
182 m_PDGs.push_back( 9020443 );
183 m_PDGs.push_back( 10441 );
184 m_PDGs.push_back( 20443 );
185 m_PDGs.push_back( 445 );
187 m_PDGs.push_back( 30443 );
188 m_PDGs.push_back( 551 );
189 m_PDGs.push_back( 553 );
190 m_PDGs.push_back( 100553 );
191 m_PDGs.push_back( 200553 );
192 m_PDGs.push_back( 10551 );
193 m_PDGs.push_back( 20553 );
194 m_PDGs.push_back( 555 );
195 m_PDGs.push_back( 10553 );
197 m_PDGs.push_back( 110551 );
198 m_PDGs.push_back( 120553 );
199 m_PDGs.push_back( 100555 );
200 m_PDGs.push_back( 210551 );
201 m_PDGs.push_back( 220553 );
202 m_PDGs.push_back( 200555 );
203 m_PDGs.push_back( 30553 );
204 m_PDGs.push_back( 20555 );
206 m_PDGs.push_back( 557 );
207 m_PDGs.push_back( 130553 );
208 m_PDGs.push_back( 120555 );
209 m_PDGs.push_back( 100557 );
210 m_PDGs.push_back( 110553 );
211 m_PDGs.push_back( 210553 );
212 m_PDGs.push_back( 10555 );
213 m_PDGs.push_back( 110555 );
215 m_PDGs.push_back( 4122 );
216 m_PDGs.push_back( 4132 );
218 m_PDGs.push_back( 4112 );
219 m_PDGs.push_back( 4212 );
220 m_PDGs.push_back( 4232 );
221 m_PDGs.push_back( 4222 );
222 m_PDGs.push_back( 4322 );
223 m_PDGs.push_back( 4312 );
225 m_PDGs.push_back( 13122 );
226 m_PDGs.push_back( 13124 );
227 m_PDGs.push_back( 23122 );
228 m_PDGs.push_back( 33122 );
229 m_PDGs.push_back( 43122 );
230 m_PDGs.push_back( 53122 );
231 m_PDGs.push_back( 13126 );
232 m_PDGs.push_back( 13212 );
233 m_PDGs.push_back( 13241 );
235 m_PDGs.push_back( 3126 );
236 m_PDGs.push_back( 3124 );
237 m_PDGs.push_back( 3122 );
238 m_PDGs.push_back( 3222 );
239 m_PDGs.push_back( 2214 );
240 m_PDGs.push_back( 2224 );
241 m_PDGs.push_back( 3324 );
242 m_PDGs.push_back( 2114 );
243 m_PDGs.push_back( 1114 );
244 m_PDGs.push_back( 3112 );
245 m_PDGs.push_back( 3212 );
246 m_PDGs.push_back( 3114 );
247 m_PDGs.push_back( 3224 );
248 m_PDGs.push_back( 3214 );
249 m_PDGs.push_back( 3216 );
250 m_PDGs.push_back( 3322 );
251 m_PDGs.push_back( 3312 );
252 m_PDGs.push_back( 3314 );
253 m_PDGs.push_back( 3334 );
255 m_PDGs.push_back( 4114 );
256 m_PDGs.push_back( 4214 );
257 m_PDGs.push_back( 4224 );
258 m_PDGs.push_back( 4314 );
259 m_PDGs.push_back( 4324 );
260 m_PDGs.push_back( 4332 );
261 m_PDGs.push_back( 4334 );
264 m_PDGs.push_back( 10443 );
266 m_PDGs.push_back( 5122 );
267 m_PDGs.push_back( 5132 );
268 m_PDGs.push_back( 5232 );
269 m_PDGs.push_back( 5332 );
270 m_PDGs.push_back( 5222 );
271 m_PDGs.push_back( 5112 );
272 m_PDGs.push_back( 5212 );
273 m_PDGs.push_back( 541 );
274 m_PDGs.push_back( 14122 );
275 m_PDGs.push_back( 14124 );
276 m_PDGs.push_back( 5312 );
277 m_PDGs.push_back( 5322 );
278 m_PDGs.push_back( 10521 );
279 m_PDGs.push_back( 20523 );
280 m_PDGs.push_back( 10523 );
282 m_PDGs.push_back( 525 );
283 m_PDGs.push_back( 10511 );
284 m_PDGs.push_back( 20513 );
285 m_PDGs.push_back( 10513 );
286 m_PDGs.push_back( 515 );
287 m_PDGs.push_back( 10531 );
288 m_PDGs.push_back( 20533 );
289 m_PDGs.push_back( 10533 );
290 m_PDGs.push_back( 535 );
291 m_PDGs.push_back( 543 );
292 m_PDGs.push_back( 545 );
293 m_PDGs.push_back( 5114 );
294 m_PDGs.push_back( 5224 );
295 m_PDGs.push_back( 5214 );
296 m_PDGs.push_back( 5314 );
297 m_PDGs.push_back( 5324 );
298 m_PDGs.push_back( 5334 );
299 m_PDGs.push_back( 10541 );
300 m_PDGs.push_back( 10543 );
301 m_PDGs.push_back( 20543 );
303 m_PDGs.push_back( 4424 );
304 m_PDGs.push_back( 4422 );
305 m_PDGs.push_back( 4414 );
306 m_PDGs.push_back( 4412 );
307 m_PDGs.push_back( 4432 );
308 m_PDGs.push_back( 4434 );
310 m_PDGs.push_back( 130 );
313 if ( pset.
exists(
"operates_on_particles") )
315 std::vector<int> tmpPIDs = pset.
getParameter< std::vector<int> >(
"operates_on_particles");
316 if ( tmpPIDs.size() > 0 )
318 if ( tmpPIDs[0] > 0 )
330 std::cout <<
" EvtGenProducer terminating ... " << std::endl;
336 m_EvtGen =
new EvtGen (decay_table_s.c_str(), pdt_s.c_str(), the_engine);
339 if (!useDefault) m_EvtGen->readUDecay( user_decay_s.c_str() );
342 for (
auto const& forced_name : forced_names) {
345 if (found.getId() == -1) {
347 <<
"name in part list for forced decays not found: " << forced_name;
349 if (found.getId() == found.getAlias()) {
351 <<
"name in part list for forced decays is not an alias: " << forced_name;
353 forced_Evt.push_back(found);
354 forced_Hep.push_back(EvtPDL::getStdHep(found));
360 if (usePythia) EvtPythia::pythiaInit(0);
373 if(the_engine->engine() ==
nullptr) {
375 <<
"The EvtGen code attempted to use a random number engine while\n"
376 <<
"the engine pointer was null in EvtGenLHCInterface::decay. This might\n"
377 <<
"mean that the code was modified to generate a random number outside\n"
378 <<
"the event and beginLuminosityBlock methods, which is not allowed.\n";
380 CLHEP::RandFlat m_flat(*the_engine->engine(), 0., 1.);
391 nPythia = evt->particles_size();
400 for (HepMC::GenEvent::particle_const_iterator
p= evt->particles_begin();
p != evt->particles_end(); ++
p)
402 status = (*p)->status();
407 idHep = (*p)->pdg_id();
409 for(
int i=0;
i<nforced;
i++)
411 if(idHep == forced_Hep[
i])
413 update_candlist(i,*
p);
419 idEvt = EvtPDL::evtIdFromStdHep(idHep);
420 ipart = idEvt.getId();
421 if (ipart==-1)
continue;
422 if (EvtDecayTable::getNMode(ipart)==0)
continue;
423 addToHepMC(*
p,idEvt,evt,
true);
431 int which = (int)(nlist * m_flat.fire());
432 if (which == nlist) which = nlist-1;
434 for(
int k=0;
k < nlist;
k++)
436 if(
k == which || !usePythia) {
437 addToHepMC(listp[
k],forced_Evt[
index[k]],evt,
false);
441 int id_non_alias = forced_Evt[
index[
k]].getId();
442 EvtId non_alias(id_non_alias,id_non_alias);
443 addToHepMC(listp[
k],non_alias,evt,
false);
455 EvtSpinType::spintype stype = EvtPDL::getSpinType(idEvt);
456 EvtParticle* partEvt;
458 case EvtSpinType::SCALAR:
459 partEvt =
new EvtScalarParticle();
462 partEvt =
new EvtStringParticle();
464 case EvtSpinType::DIRAC:
465 partEvt =
new EvtDiracParticle();
467 case EvtSpinType::VECTOR:
468 partEvt =
new EvtVectorParticle();
470 case EvtSpinType::RARITASCHWINGER:
471 partEvt =
new EvtRaritaSchwingerParticle();
473 case EvtSpinType::TENSOR:
474 partEvt =
new EvtTensorParticle();
476 case EvtSpinType::SPIN5HALF:
case EvtSpinType::SPIN3:
case EvtSpinType::SPIN7HALF:
case EvtSpinType::SPIN4:
477 partEvt =
new EvtHighSpinParticle();
480 std::cout <<
"Unknown spintype in EvtSpinType!" << std::endl;
486 HepMC::FourVector momHep = partHep->momentum();
487 momEvt.set(momHep.t(),momHep.x(),momHep.y(),momHep.z());
489 HepMC::GenVertex* initVert = partHep->production_vertex();
490 HepMC::FourVector posHep = initVert->position();
491 posEvt.set(posHep.t(),posHep.x(),posHep.y(),posHep.z());
492 partEvt->init(idEvt,momEvt);
493 if (stype == EvtSpinType::DIRAC
494 && polarizations.find(partHep->pdg_id()) != polarizations.end()) {
499 float pol = polarizations.find(partHep->pdg_id())->
second;
508 EvtSpinDensity theSpinDensity;
509 theSpinDensity.SetDim(2);
510 theSpinDensity.Set(0, 0, EvtComplex(1./2. + polVec.
z()/2., 0.));
511 theSpinDensity.Set(0, 1, EvtComplex(polVec.
x()/2., -polVec.
y()/2.));
512 theSpinDensity.Set(1, 0, EvtComplex(polVec.
x()/2., polVec.
y()/2.));
513 theSpinDensity.Set(1, 1, EvtComplex(1./2. - polVec.
z()/2., 0.));
515 partEvt->setSpinDensityForwardHelicityBasis(theSpinDensity);
518 partEvt->setDiagonalSpinDensity();
524 if (del_daug) go_through_daughters(partEvt);
527 static EvtStdHep evtstdhep;
530 partEvt->makeStdHep(evtstdhep);
533 partEvt->deleteTree();
538 HepMC::GenVertex* theVerts[200];
539 for (
int ivert = 0; ivert < 200; ivert++) {
543 for (
int ipart = 0; ipart < evtstdhep.getNPart(); ipart++) {
544 int theMum = evtstdhep.getFirstMother(ipart);
545 if (theMum != -1 && !theVerts[theMum]) {
546 EvtVector4R theVpos = evtstdhep.getX4(ipart) + posEvt;
548 new HepMC::GenVertex(HepMC::FourVector(theVpos.get(1),
556 partHep->set_status(2);
557 if (theVerts[0]) theVerts[0]->add_particle_in( partHep );
559 for (
int ipart2 = 1; ipart2 < evtstdhep.getNPart(); ipart2++) {
560 int idHep = evtstdhep.getStdHepID(ipart2);
563 evtstdhep.getP4(ipart2).get(2),
564 evtstdhep.getP4(ipart2).get(3),
565 evtstdhep.getP4(ipart2).get(0)),
567 evtstdhep.getIStat(ipart2));
569 thePart->suggest_barcode(npartial + nPythia);
570 int theMum2 = evtstdhep.getFirstMother(ipart2);
571 if (theMum2 != -1 && theVerts[theMum2]) theVerts[theMum2]->add_particle_out( thePart );
572 if (theVerts[ipart2]) theVerts[ipart2]->add_particle_in( thePart );
576 for (
int ipart3 = 0; ipart3 < evtstdhep.getNPart(); ipart3++) {
577 if (theVerts[ipart3]) theEvent->add_vertex( theVerts[ipart3] );
595 int NDaug=part->getNDaug();
598 EvtParticle* Daughter;
599 for (
int i=0;
i<NDaug;
i++)
601 Daughter=part->getDaug(
i);
602 int idHep = EvtPDL::getStdHep(Daughter->getId());
604 for(
int k=0;
k<nforced;
k++)
606 if(idHep == forced_Hep[
k])
609 Daughter->deleteDaughters();
612 if (!found) go_through_daughters(Daughter);
622 bool isThere =
false;
625 if (listp[
check]->barcode() == thePart->barcode()) isThere =
true;
629 listp[nlist] = thePart;
636 <<
"more than 10 candidates to be forced ";
644 the_engine->setRandomEngine(v);
646 m_Py6Service->setRandomEngine(v);
650 if ( !fRandomEngine ) {
652 <<
"EvtGenLHCInterface::flat: Attempt to generate random number when engine pointer is null\n"
653 <<
"This might mean that the code was modified to generate a random number outside the\n"
654 <<
"event and beginLuminosityBlock methods, which is not allowed.\n";
656 return fRandomEngine->flat();
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
HepMC::GenEvent * decay(HepMC::GenEvent *)
static unsigned int getId(void)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
void addToHepMC(HepMC::GenParticle *partHep, EvtId idEvt, HepMC::GenEvent *theEvent, bool del_daug)
U second(std::pair< T, U > const &p)
static CLHEP::HepRandomEngine * fRandomEngine
void setRandomEngine(CLHEP::HepRandomEngine *v)
bool check(const std::string &)
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
void go_through_daughters(EvtParticle *part)
Vector3DBase unit() const
EvtGenLHCInterface(const edm::ParameterSet &)
void update_candlist(int theIndex, HepMC::GenParticle *thePart)
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::string fullPath() const
double phoran_(int *idummy)