19 #include "HepMC/GenEvent.h"
24 #include "CLHEP/Random/RandFlat.h"
53 std::cout <<
" EvtGenProducer starting ... " << std::endl;
65 std::vector<double>());
66 if (polarize_ids.size() != polarize_pol.size()) {
68 <<
"EvtGenProducer requires that the particles_to_polarize and particle_polarization\n"
69 "vectors be the same size. Please fix this in your configuration.";
71 for (
unsigned int ndx = 0; ndx < polarize_ids.size(); ndx++) {
72 if (polarize_pol[ndx] < -1. || polarize_pol[ndx] > 1.) {
74 <<
"EvtGenProducer error: particle polarizations must be in the range -1 < P < 1";
76 polarizations.insert(std::pair<int, float>(polarize_ids[ndx], polarize_pol[ndx]));
80 decay_table_s = decay_table.
fullPath();
81 pdt_s = pdt.fullPath();
82 user_decay_s = user_decay.
fullPath();
88 forced_names = pset.
getParameter< std::vector<std::string> >(
"list_forced_decays");
97 m_PDGs.push_back( 300553 ) ;
98 m_PDGs.push_back( 511 ) ;
99 m_PDGs.push_back( 521 ) ;
100 m_PDGs.push_back( 523 ) ;
101 m_PDGs.push_back( 513 ) ;
102 m_PDGs.push_back( 533 ) ;
103 m_PDGs.push_back( 531 ) ;
105 m_PDGs.push_back( 15 ) ;
107 m_PDGs.push_back( 413 ) ;
108 m_PDGs.push_back( 423 ) ;
109 m_PDGs.push_back( 433 ) ;
110 m_PDGs.push_back( 411 ) ;
111 m_PDGs.push_back( 421 ) ;
112 m_PDGs.push_back( 431 ) ;
113 m_PDGs.push_back( 10411 );
114 m_PDGs.push_back( 10421 );
115 m_PDGs.push_back( 10413 );
116 m_PDGs.push_back( 10423 );
117 m_PDGs.push_back( 20413 );
118 m_PDGs.push_back( 20423 );
120 m_PDGs.push_back( 415 );
121 m_PDGs.push_back( 425 );
122 m_PDGs.push_back( 10431 );
123 m_PDGs.push_back( 20433 );
124 m_PDGs.push_back( 10433 );
125 m_PDGs.push_back( 435 );
127 m_PDGs.push_back( 310 );
128 m_PDGs.push_back( 311 );
129 m_PDGs.push_back( 313 );
130 m_PDGs.push_back( 323 );
131 m_PDGs.push_back( 10321 );
132 m_PDGs.push_back( 10311 );
133 m_PDGs.push_back( 10313 );
134 m_PDGs.push_back( 10323 );
135 m_PDGs.push_back( 20323 );
136 m_PDGs.push_back( 20313 );
137 m_PDGs.push_back( 325 );
138 m_PDGs.push_back( 315 );
140 m_PDGs.push_back( 100313 );
141 m_PDGs.push_back( 100323 );
142 m_PDGs.push_back( 30313 );
143 m_PDGs.push_back( 30323 );
144 m_PDGs.push_back( 30343 );
145 m_PDGs.push_back( 30353 );
146 m_PDGs.push_back( 30363 );
148 m_PDGs.push_back( 111 );
149 m_PDGs.push_back( 221 );
150 m_PDGs.push_back( 113 );
151 m_PDGs.push_back( 213 );
152 m_PDGs.push_back( 223 );
153 m_PDGs.push_back( 331 );
154 m_PDGs.push_back( 333 );
155 m_PDGs.push_back( 20213 );
156 m_PDGs.push_back( 20113 );
157 m_PDGs.push_back( 215 );
158 m_PDGs.push_back( 115 );
159 m_PDGs.push_back( 10213 );
160 m_PDGs.push_back( 10113 );
161 m_PDGs.push_back( 9000111 );
162 m_PDGs.push_back( 9000211 );
163 m_PDGs.push_back( 9010221 );
164 m_PDGs.push_back( 10221 );
165 m_PDGs.push_back( 20223 );
166 m_PDGs.push_back( 20333 );
167 m_PDGs.push_back( 225 );
168 m_PDGs.push_back( 9020221 );
169 m_PDGs.push_back( 335 );
170 m_PDGs.push_back( 10223 );
171 m_PDGs.push_back( 10333 );
172 m_PDGs.push_back( 100213 );
173 m_PDGs.push_back( 100113 );
175 m_PDGs.push_back( 441 );
176 m_PDGs.push_back( 100441 );
177 m_PDGs.push_back( 443 );
178 m_PDGs.push_back( 100443 );
179 m_PDGs.push_back( 9000443 );
180 m_PDGs.push_back( 9010443 );
181 m_PDGs.push_back( 9020443 );
182 m_PDGs.push_back( 10441 );
183 m_PDGs.push_back( 20443 );
184 m_PDGs.push_back( 445 );
186 m_PDGs.push_back( 30443 );
187 m_PDGs.push_back( 551 );
188 m_PDGs.push_back( 553 );
189 m_PDGs.push_back( 100553 );
190 m_PDGs.push_back( 200553 );
191 m_PDGs.push_back( 10551 );
192 m_PDGs.push_back( 20553 );
193 m_PDGs.push_back( 555 );
194 m_PDGs.push_back( 10553 );
196 m_PDGs.push_back( 110551 );
197 m_PDGs.push_back( 120553 );
198 m_PDGs.push_back( 100555 );
199 m_PDGs.push_back( 210551 );
200 m_PDGs.push_back( 220553 );
201 m_PDGs.push_back( 200555 );
202 m_PDGs.push_back( 30553 );
203 m_PDGs.push_back( 20555 );
205 m_PDGs.push_back( 557 );
206 m_PDGs.push_back( 130553 );
207 m_PDGs.push_back( 120555 );
208 m_PDGs.push_back( 100557 );
209 m_PDGs.push_back( 110553 );
210 m_PDGs.push_back( 210553 );
211 m_PDGs.push_back( 10555 );
212 m_PDGs.push_back( 110555 );
214 m_PDGs.push_back( 4122 );
215 m_PDGs.push_back( 4132 );
217 m_PDGs.push_back( 4112 );
218 m_PDGs.push_back( 4212 );
219 m_PDGs.push_back( 4232 );
220 m_PDGs.push_back( 4222 );
221 m_PDGs.push_back( 4322 );
222 m_PDGs.push_back( 4312 );
224 m_PDGs.push_back( 13122 );
225 m_PDGs.push_back( 13124 );
226 m_PDGs.push_back( 23122 );
227 m_PDGs.push_back( 33122 );
228 m_PDGs.push_back( 43122 );
229 m_PDGs.push_back( 53122 );
230 m_PDGs.push_back( 13126 );
231 m_PDGs.push_back( 13212 );
232 m_PDGs.push_back( 13241 );
234 m_PDGs.push_back( 3126 );
235 m_PDGs.push_back( 3124 );
236 m_PDGs.push_back( 3122 );
237 m_PDGs.push_back( 3222 );
238 m_PDGs.push_back( 2214 );
239 m_PDGs.push_back( 2224 );
240 m_PDGs.push_back( 3324 );
241 m_PDGs.push_back( 2114 );
242 m_PDGs.push_back( 1114 );
243 m_PDGs.push_back( 3112 );
244 m_PDGs.push_back( 3212 );
245 m_PDGs.push_back( 3114 );
246 m_PDGs.push_back( 3224 );
247 m_PDGs.push_back( 3214 );
248 m_PDGs.push_back( 3216 );
249 m_PDGs.push_back( 3322 );
250 m_PDGs.push_back( 3312 );
251 m_PDGs.push_back( 3314 );
252 m_PDGs.push_back( 3334 );
254 m_PDGs.push_back( 4114 );
255 m_PDGs.push_back( 4214 );
256 m_PDGs.push_back( 4224 );
257 m_PDGs.push_back( 4314 );
258 m_PDGs.push_back( 4324 );
259 m_PDGs.push_back( 4332 );
260 m_PDGs.push_back( 4334 );
263 m_PDGs.push_back( 10443 );
265 m_PDGs.push_back( 5122 );
266 m_PDGs.push_back( 5132 );
267 m_PDGs.push_back( 5232 );
268 m_PDGs.push_back( 5332 );
269 m_PDGs.push_back( 5222 );
270 m_PDGs.push_back( 5112 );
271 m_PDGs.push_back( 5212 );
272 m_PDGs.push_back( 541 );
273 m_PDGs.push_back( 14122 );
274 m_PDGs.push_back( 14124 );
275 m_PDGs.push_back( 5312 );
276 m_PDGs.push_back( 5322 );
277 m_PDGs.push_back( 10521 );
278 m_PDGs.push_back( 20523 );
279 m_PDGs.push_back( 10523 );
281 m_PDGs.push_back( 525 );
282 m_PDGs.push_back( 10511 );
283 m_PDGs.push_back( 20513 );
284 m_PDGs.push_back( 10513 );
285 m_PDGs.push_back( 515 );
286 m_PDGs.push_back( 10531 );
287 m_PDGs.push_back( 20533 );
288 m_PDGs.push_back( 10533 );
289 m_PDGs.push_back( 535 );
290 m_PDGs.push_back( 543 );
291 m_PDGs.push_back( 545 );
292 m_PDGs.push_back( 5114 );
293 m_PDGs.push_back( 5224 );
294 m_PDGs.push_back( 5214 );
295 m_PDGs.push_back( 5314 );
296 m_PDGs.push_back( 5324 );
297 m_PDGs.push_back( 5334 );
298 m_PDGs.push_back( 10541 );
299 m_PDGs.push_back( 10543 );
300 m_PDGs.push_back( 20543 );
302 m_PDGs.push_back( 4424 );
303 m_PDGs.push_back( 4422 );
304 m_PDGs.push_back( 4414 );
305 m_PDGs.push_back( 4412 );
306 m_PDGs.push_back( 4432 );
307 m_PDGs.push_back( 4434 );
309 m_PDGs.push_back( 130 );
312 if ( pset.
exists(
"operates_on_particles") )
314 std::vector<int> tmpPIDs = pset.
getParameter< std::vector<int> >(
"operates_on_particles");
315 if ( tmpPIDs.size() > 0 )
317 if ( tmpPIDs[0] > 0 )
329 std::cout <<
" EvtGenProducer terminating ... " << std::endl;
335 m_EvtGen =
new EvtGen (decay_table_s.c_str(), pdt_s.c_str(), the_engine);
338 if (!useDefault) m_EvtGen->readUDecay( user_decay_s.c_str() );
341 for (
auto const& forced_name : forced_names) {
344 if (found.getId() == -1) {
346 <<
"name in part list for forced decays not found: " << forced_name;
348 if (found.getId() == found.getAlias()) {
350 <<
"name in part list for forced decays is not an alias: " << forced_name;
352 forced_Evt.push_back(found);
353 forced_Hep.push_back(EvtPDL::getStdHep(found));
359 if (usePythia) EvtPythia::pythiaInit(0);
372 if(the_engine->engine() ==
nullptr) {
374 <<
"The EvtGen code attempted to use a random number engine while\n"
375 <<
"the engine pointer was null in EvtGenInterface::decay. This might\n"
376 <<
"mean that the code was modified to generate a random number outside\n"
377 <<
"the event and beginLuminosityBlock methods, which is not allowed.\n";
379 CLHEP::RandFlat m_flat(*the_engine->engine(), 0., 1.);
390 nPythia = evt->particles_size();
399 for (HepMC::GenEvent::particle_const_iterator
p= evt->particles_begin();
p != evt->particles_end(); ++
p)
401 status = (*p)->status();
406 idHep = (*p)->pdg_id();
408 for(
int i=0;
i<nforced;
i++)
410 if(idHep == forced_Hep[
i])
412 update_candlist(i,*
p);
418 idEvt = EvtPDL::evtIdFromStdHep(idHep);
419 ipart = idEvt.getId();
420 if (ipart==-1)
continue;
421 if (EvtDecayTable::getNMode(ipart)==0)
continue;
422 addToHepMC(*
p,idEvt,evt,
true);
430 int which = (int)(nlist * m_flat.fire());
431 if (which == nlist) which = nlist-1;
433 for(
int k=0;
k < nlist;
k++)
435 if(
k == which || !usePythia) {
436 addToHepMC(listp[
k],forced_Evt[
index[k]],evt,
false);
440 int id_non_alias = forced_Evt[
index[
k]].getId();
441 EvtId non_alias(id_non_alias,id_non_alias);
442 addToHepMC(listp[
k],non_alias,evt,
false);
454 EvtSpinType::spintype stype = EvtPDL::getSpinType(idEvt);
455 EvtParticle* partEvt;
457 case EvtSpinType::SCALAR:
458 partEvt =
new EvtScalarParticle();
461 partEvt =
new EvtStringParticle();
463 case EvtSpinType::DIRAC:
464 partEvt =
new EvtDiracParticle();
466 case EvtSpinType::VECTOR:
467 partEvt =
new EvtVectorParticle();
469 case EvtSpinType::RARITASCHWINGER:
470 partEvt =
new EvtRaritaSchwingerParticle();
472 case EvtSpinType::TENSOR:
473 partEvt =
new EvtTensorParticle();
475 case EvtSpinType::SPIN5HALF:
case EvtSpinType::SPIN3:
case EvtSpinType::SPIN7HALF:
case EvtSpinType::SPIN4:
476 partEvt =
new EvtHighSpinParticle();
479 std::cout <<
"Unknown spintype in EvtSpinType!" << std::endl;
485 HepMC::FourVector momHep = partHep->momentum();
486 momEvt.set(momHep.t(),momHep.x(),momHep.y(),momHep.z());
488 HepMC::GenVertex* initVert = partHep->production_vertex();
489 HepMC::FourVector posHep = initVert->position();
490 posEvt.set(posHep.t(),posHep.x(),posHep.y(),posHep.z());
491 partEvt->init(idEvt,momEvt);
492 if (stype == EvtSpinType::DIRAC
493 && polarizations.find(partHep->pdg_id()) != polarizations.end()) {
498 float pol = polarizations.find(partHep->pdg_id())->
second;
507 EvtSpinDensity theSpinDensity;
508 theSpinDensity.SetDim(2);
509 theSpinDensity.Set(0, 0, EvtComplex(1./2. + polVec.
z()/2., 0.));
510 theSpinDensity.Set(0, 1, EvtComplex(polVec.
x()/2., -polVec.
y()/2.));
511 theSpinDensity.Set(1, 0, EvtComplex(polVec.
x()/2., polVec.
y()/2.));
512 theSpinDensity.Set(1, 1, EvtComplex(1./2. - polVec.
z()/2., 0.));
514 partEvt->setSpinDensityForwardHelicityBasis(theSpinDensity);
517 partEvt->setDiagonalSpinDensity();
523 if (del_daug) go_through_daughters(partEvt);
526 static EvtStdHep evtstdhep;
529 partEvt->makeStdHep(evtstdhep);
532 partEvt->deleteTree();
537 HepMC::GenVertex* theVerts[200];
538 for (
int ivert = 0; ivert < 200; ivert++) {
542 for (
int ipart = 0; ipart < evtstdhep.getNPart(); ipart++) {
543 int theMum = evtstdhep.getFirstMother(ipart);
544 if (theMum != -1 && !theVerts[theMum]) {
545 EvtVector4R theVpos = evtstdhep.getX4(ipart) + posEvt;
547 new HepMC::GenVertex(HepMC::FourVector(theVpos.get(1),
555 partHep->set_status(2);
556 if (theVerts[0]) theVerts[0]->add_particle_in( partHep );
558 for (
int ipart2 = 1; ipart2 < evtstdhep.getNPart(); ipart2++) {
559 int idHep = evtstdhep.getStdHepID(ipart2);
562 evtstdhep.getP4(ipart2).get(2),
563 evtstdhep.getP4(ipart2).get(3),
564 evtstdhep.getP4(ipart2).get(0)),
566 evtstdhep.getIStat(ipart2));
568 thePart->suggest_barcode(npartial + nPythia);
569 int theMum2 = evtstdhep.getFirstMother(ipart2);
570 if (theMum2 != -1 && theVerts[theMum2]) theVerts[theMum2]->add_particle_out( thePart );
571 if (theVerts[ipart2]) theVerts[ipart2]->add_particle_in( thePart );
575 for (
int ipart3 = 0; ipart3 < evtstdhep.getNPart(); ipart3++) {
576 if (theVerts[ipart3]) theEvent->add_vertex( theVerts[ipart3] );
594 int NDaug=part->getNDaug();
597 EvtParticle* Daughter;
598 for (
int i=0;
i<NDaug;
i++)
600 Daughter=part->getDaug(
i);
601 int idHep = EvtPDL::getStdHep(Daughter->getId());
603 for(
int k=0;
k<nforced;
k++)
605 if(idHep == forced_Hep[
k])
608 Daughter->deleteDaughters();
611 if (!found) go_through_daughters(Daughter);
621 bool isThere =
false;
624 if (listp[
check]->barcode() == thePart->barcode()) isThere =
true;
628 listp[nlist] = thePart;
635 <<
"more than 10 candidates to be forced ";
643 the_engine->setRandomEngine(v);
645 m_Py6Service->setRandomEngine(v);
649 if ( !fRandomEngine ) {
651 <<
"EvtGenInterface::flat: Attempt to generate random number when engine pointer is null\n"
652 <<
"This might mean that the code was modified to generate a random number outside the\n"
653 <<
"event and beginLuminosityBlock methods, which is not allowed.\n";
655 return fRandomEngine->flat();
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
HepMC::GenEvent * decay(HepMC::GenEvent *)
void addToHepMC(HepMC::GenParticle *partHep, EvtId idEvt, HepMC::GenEvent *theEvent, bool del_daug)
void update_candlist(int theIndex, HepMC::GenParticle *thePart)
double phoran_(int *idummy)
static unsigned int getId(void)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
void go_through_daughters(EvtParticle *part)
void setRandomEngine(CLHEP::HepRandomEngine *v)
U second(std::pair< T, U > const &p)
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
static CLHEP::HepRandomEngine * fRandomEngine
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Vector3DBase unit() const
EvtGenInterface(const edm::ParameterSet &)
std::string fullPath() const