20 #include "HepMC/GenEvent.h"
25 #include "CLHEP/Random/RandFlat.h"
40 std::cout <<
" EvtGenProducer starting ... " << std::endl;
52 std::vector<double>());
53 if (polarize_ids.size() != polarize_pol.size()) {
55 <<
"EvtGenProducer requires that the particles_to_polarize and particle_polarization\n"
56 "vectors be the same size. Please fix this in your configuration.";
58 for (
unsigned int ndx = 0; ndx < polarize_ids.size(); ndx++) {
59 if (polarize_pol[ndx] < -1. || polarize_pol[ndx] > 1.) {
61 <<
"EvtGenProducer error: particle polarizations must be in the range -1 < P < 1";
63 polarizations.insert(std::pair<int, float>(polarize_ids[ndx], polarize_pol[ndx]));
67 decay_table_s = decay_table.
fullPath();
68 pdt_s = pdt.fullPath();
69 user_decay_s = user_decay.
fullPath();
75 forced_names = pset.
getParameter< std::vector<std::string> >(
"list_forced_decays");
84 m_PDGs.push_back( 300553 ) ;
85 m_PDGs.push_back( 511 ) ;
86 m_PDGs.push_back( 521 ) ;
87 m_PDGs.push_back( 523 ) ;
88 m_PDGs.push_back( 513 ) ;
89 m_PDGs.push_back( 533 ) ;
90 m_PDGs.push_back( 531 ) ;
92 m_PDGs.push_back( 15 ) ;
94 m_PDGs.push_back( 413 ) ;
95 m_PDGs.push_back( 423 ) ;
96 m_PDGs.push_back( 433 ) ;
97 m_PDGs.push_back( 411 ) ;
98 m_PDGs.push_back( 421 ) ;
99 m_PDGs.push_back( 431 ) ;
100 m_PDGs.push_back( 10411 );
101 m_PDGs.push_back( 10421 );
102 m_PDGs.push_back( 10413 );
103 m_PDGs.push_back( 10423 );
104 m_PDGs.push_back( 20413 );
105 m_PDGs.push_back( 20423 );
107 m_PDGs.push_back( 415 );
108 m_PDGs.push_back( 425 );
109 m_PDGs.push_back( 10431 );
110 m_PDGs.push_back( 20433 );
111 m_PDGs.push_back( 10433 );
112 m_PDGs.push_back( 435 );
114 m_PDGs.push_back( 310 );
115 m_PDGs.push_back( 311 );
116 m_PDGs.push_back( 313 );
117 m_PDGs.push_back( 323 );
118 m_PDGs.push_back( 10321 );
119 m_PDGs.push_back( 10311 );
120 m_PDGs.push_back( 10313 );
121 m_PDGs.push_back( 10323 );
122 m_PDGs.push_back( 20323 );
123 m_PDGs.push_back( 20313 );
124 m_PDGs.push_back( 325 );
125 m_PDGs.push_back( 315 );
127 m_PDGs.push_back( 100313 );
128 m_PDGs.push_back( 100323 );
129 m_PDGs.push_back( 30313 );
130 m_PDGs.push_back( 30323 );
131 m_PDGs.push_back( 30343 );
132 m_PDGs.push_back( 30353 );
133 m_PDGs.push_back( 30363 );
135 m_PDGs.push_back( 111 );
136 m_PDGs.push_back( 221 );
137 m_PDGs.push_back( 113 );
138 m_PDGs.push_back( 213 );
139 m_PDGs.push_back( 223 );
140 m_PDGs.push_back( 331 );
141 m_PDGs.push_back( 333 );
142 m_PDGs.push_back( 20213 );
143 m_PDGs.push_back( 20113 );
144 m_PDGs.push_back( 215 );
145 m_PDGs.push_back( 115 );
146 m_PDGs.push_back( 10213 );
147 m_PDGs.push_back( 10113 );
148 m_PDGs.push_back( 9000111 );
149 m_PDGs.push_back( 9000211 );
150 m_PDGs.push_back( 9010221 );
151 m_PDGs.push_back( 10221 );
152 m_PDGs.push_back( 20223 );
153 m_PDGs.push_back( 20333 );
154 m_PDGs.push_back( 225 );
155 m_PDGs.push_back( 9020221 );
156 m_PDGs.push_back( 335 );
157 m_PDGs.push_back( 10223 );
158 m_PDGs.push_back( 10333 );
159 m_PDGs.push_back( 100213 );
160 m_PDGs.push_back( 100113 );
162 m_PDGs.push_back( 441 );
163 m_PDGs.push_back( 100441 );
164 m_PDGs.push_back( 443 );
165 m_PDGs.push_back( 100443 );
166 m_PDGs.push_back( 9000443 );
167 m_PDGs.push_back( 9010443 );
168 m_PDGs.push_back( 9020443 );
169 m_PDGs.push_back( 10441 );
170 m_PDGs.push_back( 20443 );
171 m_PDGs.push_back( 445 );
173 m_PDGs.push_back( 30443 );
174 m_PDGs.push_back( 551 );
175 m_PDGs.push_back( 553 );
176 m_PDGs.push_back( 100553 );
177 m_PDGs.push_back( 200553 );
178 m_PDGs.push_back( 10551 );
179 m_PDGs.push_back( 20553 );
180 m_PDGs.push_back( 555 );
181 m_PDGs.push_back( 10553 );
183 m_PDGs.push_back( 110551 );
184 m_PDGs.push_back( 120553 );
185 m_PDGs.push_back( 100555 );
186 m_PDGs.push_back( 210551 );
187 m_PDGs.push_back( 220553 );
188 m_PDGs.push_back( 200555 );
189 m_PDGs.push_back( 30553 );
190 m_PDGs.push_back( 20555 );
192 m_PDGs.push_back( 557 );
193 m_PDGs.push_back( 130553 );
194 m_PDGs.push_back( 120555 );
195 m_PDGs.push_back( 100557 );
196 m_PDGs.push_back( 110553 );
197 m_PDGs.push_back( 210553 );
198 m_PDGs.push_back( 10555 );
199 m_PDGs.push_back( 110555 );
201 m_PDGs.push_back( 4122 );
202 m_PDGs.push_back( 4132 );
204 m_PDGs.push_back( 4112 );
205 m_PDGs.push_back( 4212 );
206 m_PDGs.push_back( 4232 );
207 m_PDGs.push_back( 4222 );
208 m_PDGs.push_back( 4322 );
209 m_PDGs.push_back( 4312 );
211 m_PDGs.push_back( 13122 );
212 m_PDGs.push_back( 13124 );
213 m_PDGs.push_back( 23122 );
214 m_PDGs.push_back( 33122 );
215 m_PDGs.push_back( 43122 );
216 m_PDGs.push_back( 53122 );
217 m_PDGs.push_back( 13126 );
218 m_PDGs.push_back( 13212 );
219 m_PDGs.push_back( 13241 );
221 m_PDGs.push_back( 3126 );
222 m_PDGs.push_back( 3124 );
223 m_PDGs.push_back( 3122 );
224 m_PDGs.push_back( 3222 );
225 m_PDGs.push_back( 2214 );
226 m_PDGs.push_back( 2224 );
227 m_PDGs.push_back( 3324 );
228 m_PDGs.push_back( 2114 );
229 m_PDGs.push_back( 1114 );
230 m_PDGs.push_back( 3112 );
231 m_PDGs.push_back( 3212 );
232 m_PDGs.push_back( 3114 );
233 m_PDGs.push_back( 3224 );
234 m_PDGs.push_back( 3214 );
235 m_PDGs.push_back( 3216 );
236 m_PDGs.push_back( 3322 );
237 m_PDGs.push_back( 3312 );
238 m_PDGs.push_back( 3314 );
239 m_PDGs.push_back( 3334 );
241 m_PDGs.push_back( 4114 );
242 m_PDGs.push_back( 4214 );
243 m_PDGs.push_back( 4224 );
244 m_PDGs.push_back( 4314 );
245 m_PDGs.push_back( 4324 );
246 m_PDGs.push_back( 4332 );
247 m_PDGs.push_back( 4334 );
250 m_PDGs.push_back( 10443 );
252 m_PDGs.push_back( 5122 );
253 m_PDGs.push_back( 5132 );
254 m_PDGs.push_back( 5232 );
255 m_PDGs.push_back( 5332 );
256 m_PDGs.push_back( 5222 );
257 m_PDGs.push_back( 5112 );
258 m_PDGs.push_back( 5212 );
259 m_PDGs.push_back( 541 );
260 m_PDGs.push_back( 14122 );
261 m_PDGs.push_back( 14124 );
262 m_PDGs.push_back( 5312 );
263 m_PDGs.push_back( 5322 );
264 m_PDGs.push_back( 10521 );
265 m_PDGs.push_back( 20523 );
266 m_PDGs.push_back( 10523 );
268 m_PDGs.push_back( 525 );
269 m_PDGs.push_back( 10511 );
270 m_PDGs.push_back( 20513 );
271 m_PDGs.push_back( 10513 );
272 m_PDGs.push_back( 515 );
273 m_PDGs.push_back( 10531 );
274 m_PDGs.push_back( 20533 );
275 m_PDGs.push_back( 10533 );
276 m_PDGs.push_back( 535 );
277 m_PDGs.push_back( 543 );
278 m_PDGs.push_back( 545 );
279 m_PDGs.push_back( 5114 );
280 m_PDGs.push_back( 5224 );
281 m_PDGs.push_back( 5214 );
282 m_PDGs.push_back( 5314 );
283 m_PDGs.push_back( 5324 );
284 m_PDGs.push_back( 5334 );
285 m_PDGs.push_back( 10541 );
286 m_PDGs.push_back( 10543 );
287 m_PDGs.push_back( 20543 );
289 m_PDGs.push_back( 4424 );
290 m_PDGs.push_back( 4422 );
291 m_PDGs.push_back( 4414 );
292 m_PDGs.push_back( 4412 );
293 m_PDGs.push_back( 4432 );
294 m_PDGs.push_back( 4434 );
296 m_PDGs.push_back( 130 );
299 if ( pset.
exists(
"operates_on_particles") )
301 std::vector<int> tmpPIDs = pset.
getParameter< std::vector<int> >(
"operates_on_particles");
302 if ( tmpPIDs.size() > 0 )
304 if ( tmpPIDs[0] > 0 )
316 std::cout <<
" EvtGenProducer terminating ... " << std::endl;
322 m_EvtGen =
new EvtGen (decay_table_s.c_str(), pdt_s.c_str(), the_engine);
325 if (!useDefault) m_EvtGen->readUDecay( user_decay_s.c_str() );
328 for (
auto const& forced_name : forced_names) {
331 if (found.getId() == -1) {
333 <<
"name in part list for forced decays not found: " << forced_name;
335 if (found.getId() == found.getAlias()) {
337 <<
"name in part list for forced decays is not an alias: " << forced_name;
339 forced_Evt.push_back(found);
340 forced_Hep.push_back(EvtPDL::getStdHep(found));
346 if (usePythia) EvtPythia::pythiaInit(0);
359 if(the_engine->engine() ==
nullptr) {
361 <<
"The EvtGen code attempted to use a random number engine while\n"
362 <<
"the engine pointer was null in EvtGenInterface::decay. This might\n"
363 <<
"mean that the code was modified to generate a random number outside\n"
364 <<
"the event and beginLuminosityBlock methods, which is not allowed.\n";
366 CLHEP::RandFlat m_flat(*the_engine->engine(), 0., 1.);
377 nPythia = evt->particles_size();
386 for (HepMC::GenEvent::particle_const_iterator
p= evt->particles_begin();
p != evt->particles_end(); ++
p)
388 status = (*p)->status();
393 idHep = (*p)->pdg_id();
395 for(
int i=0;
i<nforced;
i++)
397 if(idHep == forced_Hep[
i])
399 update_candlist(i,*
p);
405 idEvt = EvtPDL::evtIdFromStdHep(idHep);
406 ipart = idEvt.getId();
407 if (ipart==-1)
continue;
408 if (EvtDecayTable::getNMode(ipart)==0)
continue;
409 addToHepMC(*
p,idEvt,evt,
true);
417 int which = (int)(nlist * m_flat.fire());
418 if (which == nlist) which = nlist-1;
420 for(
int k=0;
k < nlist;
k++)
422 if(
k == which || !usePythia) {
423 addToHepMC(listp[
k],forced_Evt[
index[k]],evt,
false);
427 int id_non_alias = forced_Evt[
index[
k]].getId();
428 EvtId non_alias(id_non_alias,id_non_alias);
429 addToHepMC(listp[
k],non_alias,evt,
false);
441 EvtSpinType::spintype stype = EvtPDL::getSpinType(idEvt);
442 EvtParticle* partEvt;
444 case EvtSpinType::SCALAR:
445 partEvt =
new EvtScalarParticle();
448 partEvt =
new EvtStringParticle();
450 case EvtSpinType::DIRAC:
451 partEvt =
new EvtDiracParticle();
453 case EvtSpinType::VECTOR:
454 partEvt =
new EvtVectorParticle();
456 case EvtSpinType::RARITASCHWINGER:
457 partEvt =
new EvtRaritaSchwingerParticle();
459 case EvtSpinType::TENSOR:
460 partEvt =
new EvtTensorParticle();
462 case EvtSpinType::SPIN5HALF:
case EvtSpinType::SPIN3:
case EvtSpinType::SPIN7HALF:
case EvtSpinType::SPIN4:
463 partEvt =
new EvtHighSpinParticle();
466 std::cout <<
"Unknown spintype in EvtSpinType!" << std::endl;
472 HepMC::FourVector momHep = partHep->momentum();
473 momEvt.set(momHep.t(),momHep.x(),momHep.y(),momHep.z());
475 HepMC::GenVertex* initVert = partHep->production_vertex();
476 HepMC::FourVector posHep = initVert->position();
477 posEvt.set(posHep.t(),posHep.x(),posHep.y(),posHep.z());
478 partEvt->init(idEvt,momEvt);
479 if (stype == EvtSpinType::DIRAC
480 && polarizations.find(partHep->pdg_id()) != polarizations.end()) {
485 float pol = polarizations.find(partHep->pdg_id())->
second;
494 EvtSpinDensity theSpinDensity;
495 theSpinDensity.SetDim(2);
496 theSpinDensity.Set(0, 0, EvtComplex(1./2. + polVec.
z()/2., 0.));
497 theSpinDensity.Set(0, 1, EvtComplex(polVec.
x()/2., -polVec.
y()/2.));
498 theSpinDensity.Set(1, 0, EvtComplex(polVec.
x()/2., polVec.
y()/2.));
499 theSpinDensity.Set(1, 1, EvtComplex(1./2. - polVec.
z()/2., 0.));
501 partEvt->setSpinDensityForwardHelicityBasis(theSpinDensity);
504 partEvt->setDiagonalSpinDensity();
510 if (del_daug) go_through_daughters(partEvt);
513 static EvtStdHep evtstdhep;
516 partEvt->makeStdHep(evtstdhep);
519 partEvt->deleteTree();
524 HepMC::GenVertex* theVerts[200];
525 for (
int ivert = 0; ivert < 200; ivert++) {
529 for (
int ipart = 0; ipart < evtstdhep.getNPart(); ipart++) {
530 int theMum = evtstdhep.getFirstMother(ipart);
531 if (theMum != -1 && !theVerts[theMum]) {
532 EvtVector4R theVpos = evtstdhep.getX4(ipart) + posEvt;
534 new HepMC::GenVertex(HepMC::FourVector(theVpos.get(1),
542 partHep->set_status(2);
543 if (theVerts[0]) theVerts[0]->add_particle_in( partHep );
545 for (
int ipart2 = 1; ipart2 < evtstdhep.getNPart(); ipart2++) {
546 int idHep = evtstdhep.getStdHepID(ipart2);
549 evtstdhep.getP4(ipart2).get(2),
550 evtstdhep.getP4(ipart2).get(3),
551 evtstdhep.getP4(ipart2).get(0)),
553 evtstdhep.getIStat(ipart2));
555 thePart->suggest_barcode(npartial + nPythia);
556 int theMum2 = evtstdhep.getFirstMother(ipart2);
557 if (theMum2 != -1 && theVerts[theMum2]) theVerts[theMum2]->add_particle_out( thePart );
558 if (theVerts[ipart2]) theVerts[ipart2]->add_particle_in( thePart );
562 for (
int ipart3 = 0; ipart3 < evtstdhep.getNPart(); ipart3++) {
563 if (theVerts[ipart3]) theEvent->add_vertex( theVerts[ipart3] );
581 int NDaug=part->getNDaug();
584 EvtParticle* Daughter;
585 for (
int i=0;
i<NDaug;
i++)
587 Daughter=part->getDaug(
i);
588 int idHep = EvtPDL::getStdHep(Daughter->getId());
590 for(
int k=0;
k<nforced;
k++)
592 if(idHep == forced_Hep[
k])
595 Daughter->deleteDaughters();
598 if (!found) go_through_daughters(Daughter);
608 bool isThere =
false;
611 if (listp[
check]->barcode() == thePart->barcode()) isThere =
true;
615 listp[nlist] = thePart;
616 index[nlist++] = theIndex;
622 <<
"more than 10 candidates to be forced ";
630 the_engine->setRandomEngine(v);
631 m_Py6Service->setRandomEngine(v);
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)
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)
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