27 #include "CLHEP/Random/RandFlat.h"
30 #include "EvtGen/EvtGen.hh"
31 #include "EvtGenExternal/EvtExternalGenList.hh"
32 #include "EvtGenBase/EvtAbsRadCorr.hh"
33 #include "EvtGenBase/EvtDecayBase.hh"
34 #include "EvtGenBase/EvtId.hh"
35 #include "EvtGenBase/EvtDecayTable.hh"
36 #include "EvtGenBase/EvtParticle.hh"
37 #include "EvtGenBase/EvtParticleFactory.hh"
38 #include "EvtGenBase/EvtHepMCEvent.hh"
40 #include "HepPID/ParticleIDTranslations.hh"
62 m_PDGs.push_back( 300553 ) ;
63 m_PDGs.push_back( 511 ) ;
64 m_PDGs.push_back( 521 ) ;
65 m_PDGs.push_back( 523 ) ;
66 m_PDGs.push_back( 513 ) ;
67 m_PDGs.push_back( 533 ) ;
68 m_PDGs.push_back( 531 ) ;
70 m_PDGs.push_back( 15 ) ;
72 m_PDGs.push_back( 413 ) ;
73 m_PDGs.push_back( 423 ) ;
74 m_PDGs.push_back( 433 ) ;
75 m_PDGs.push_back( 411 ) ;
76 m_PDGs.push_back( 421 ) ;
77 m_PDGs.push_back( 431 ) ;
78 m_PDGs.push_back( 10411 );
79 m_PDGs.push_back( 10421 );
80 m_PDGs.push_back( 10413 );
81 m_PDGs.push_back( 10423 );
82 m_PDGs.push_back( 20413 );
83 m_PDGs.push_back( 20423 );
85 m_PDGs.push_back( 415 );
86 m_PDGs.push_back( 425 );
87 m_PDGs.push_back( 10431 );
88 m_PDGs.push_back( 20433 );
89 m_PDGs.push_back( 10433 );
90 m_PDGs.push_back( 435 );
92 m_PDGs.push_back( 310 );
93 m_PDGs.push_back( 311 );
94 m_PDGs.push_back( 313 );
95 m_PDGs.push_back( 323 );
96 m_PDGs.push_back( 10321 );
97 m_PDGs.push_back( 10311 );
98 m_PDGs.push_back( 10313 );
99 m_PDGs.push_back( 10323 );
100 m_PDGs.push_back( 20323 );
101 m_PDGs.push_back( 20313 );
102 m_PDGs.push_back( 325 );
103 m_PDGs.push_back( 315 );
105 m_PDGs.push_back( 100313 );
106 m_PDGs.push_back( 100323 );
107 m_PDGs.push_back( 30313 );
108 m_PDGs.push_back( 30323 );
109 m_PDGs.push_back( 30343 );
110 m_PDGs.push_back( 30353 );
111 m_PDGs.push_back( 30363 );
113 m_PDGs.push_back( 111 );
114 m_PDGs.push_back( 221 );
115 m_PDGs.push_back( 113 );
116 m_PDGs.push_back( 213 );
117 m_PDGs.push_back( 223 );
118 m_PDGs.push_back( 331 );
119 m_PDGs.push_back( 333 );
120 m_PDGs.push_back( 20213 );
121 m_PDGs.push_back( 20113 );
122 m_PDGs.push_back( 215 );
123 m_PDGs.push_back( 115 );
124 m_PDGs.push_back( 10213 );
125 m_PDGs.push_back( 10113 );
126 m_PDGs.push_back( 9000111 );
127 m_PDGs.push_back( 9000211 );
128 m_PDGs.push_back( 9010221 );
129 m_PDGs.push_back( 10221 );
130 m_PDGs.push_back( 20223 );
131 m_PDGs.push_back( 20333 );
132 m_PDGs.push_back( 225 );
133 m_PDGs.push_back( 9020221 );
134 m_PDGs.push_back( 335 );
135 m_PDGs.push_back( 10223 );
136 m_PDGs.push_back( 10333 );
137 m_PDGs.push_back( 100213 );
138 m_PDGs.push_back( 100113 );
140 m_PDGs.push_back( 441 );
141 m_PDGs.push_back( 100441 );
142 m_PDGs.push_back( 443 );
143 m_PDGs.push_back( 100443 );
144 m_PDGs.push_back( 9000443 );
145 m_PDGs.push_back( 9010443 );
146 m_PDGs.push_back( 9020443 );
147 m_PDGs.push_back( 10441 );
148 m_PDGs.push_back( 20443 );
149 m_PDGs.push_back( 445 );
151 m_PDGs.push_back( 30443 );
152 m_PDGs.push_back( 551 );
153 m_PDGs.push_back( 553 );
154 m_PDGs.push_back( 100553 );
155 m_PDGs.push_back( 200553 );
156 m_PDGs.push_back( 10551 );
157 m_PDGs.push_back( 20553 );
158 m_PDGs.push_back( 555 );
159 m_PDGs.push_back( 10553 );
161 m_PDGs.push_back( 110551 );
162 m_PDGs.push_back( 120553 );
163 m_PDGs.push_back( 100555 );
164 m_PDGs.push_back( 210551 );
165 m_PDGs.push_back( 220553 );
166 m_PDGs.push_back( 200555 );
167 m_PDGs.push_back( 30553 );
168 m_PDGs.push_back( 20555 );
170 m_PDGs.push_back( 557 );
171 m_PDGs.push_back( 130553 );
172 m_PDGs.push_back( 120555 );
173 m_PDGs.push_back( 100557 );
174 m_PDGs.push_back( 110553 );
175 m_PDGs.push_back( 210553 );
176 m_PDGs.push_back( 10555 );
177 m_PDGs.push_back( 110555 );
179 m_PDGs.push_back( 4122 );
180 m_PDGs.push_back( 4132 );
182 m_PDGs.push_back( 4112 );
183 m_PDGs.push_back( 4212 );
184 m_PDGs.push_back( 4232 );
185 m_PDGs.push_back( 4222 );
186 m_PDGs.push_back( 4322 );
187 m_PDGs.push_back( 4312 );
189 m_PDGs.push_back( 13122 );
190 m_PDGs.push_back( 13124 );
191 m_PDGs.push_back( 23122 );
192 m_PDGs.push_back( 33122 );
193 m_PDGs.push_back( 43122 );
194 m_PDGs.push_back( 53122 );
195 m_PDGs.push_back( 13126 );
196 m_PDGs.push_back( 13212 );
199 m_PDGs.push_back( 3126 );
200 m_PDGs.push_back( 3124 );
201 m_PDGs.push_back( 3122 );
202 m_PDGs.push_back( 3222 );
203 m_PDGs.push_back( 2214 );
204 m_PDGs.push_back( 2224 );
205 m_PDGs.push_back( 3324 );
206 m_PDGs.push_back( 2114 );
207 m_PDGs.push_back( 1114 );
208 m_PDGs.push_back( 3112 );
209 m_PDGs.push_back( 3212 );
210 m_PDGs.push_back( 3114 );
211 m_PDGs.push_back( 3224 );
212 m_PDGs.push_back( 3214 );
213 m_PDGs.push_back( 3216 );
214 m_PDGs.push_back( 3322 );
215 m_PDGs.push_back( 3312 );
216 m_PDGs.push_back( 3314 );
217 m_PDGs.push_back( 3334 );
219 m_PDGs.push_back( 4114 );
220 m_PDGs.push_back( 4214 );
221 m_PDGs.push_back( 4224 );
222 m_PDGs.push_back( 4314 );
223 m_PDGs.push_back( 4324 );
224 m_PDGs.push_back( 4332 );
225 m_PDGs.push_back( 4334 );
228 m_PDGs.push_back( 10443 );
230 m_PDGs.push_back( 5122 );
231 m_PDGs.push_back( 5132 );
232 m_PDGs.push_back( 5232 );
233 m_PDGs.push_back( 5332 );
234 m_PDGs.push_back( 5222 );
235 m_PDGs.push_back( 5112 );
236 m_PDGs.push_back( 5212 );
237 m_PDGs.push_back( 541 );
238 m_PDGs.push_back( 14122 );
239 m_PDGs.push_back( 14124 );
240 m_PDGs.push_back( 5312 );
241 m_PDGs.push_back( 5322 );
242 m_PDGs.push_back( 10521 );
243 m_PDGs.push_back( 20523 );
244 m_PDGs.push_back( 10523 );
246 m_PDGs.push_back( 525 );
247 m_PDGs.push_back( 10511 );
248 m_PDGs.push_back( 20513 );
249 m_PDGs.push_back( 10513 );
250 m_PDGs.push_back( 515 );
251 m_PDGs.push_back( 10531 );
252 m_PDGs.push_back( 20533 );
253 m_PDGs.push_back( 10533 );
254 m_PDGs.push_back( 535 );
255 m_PDGs.push_back( 543 );
256 m_PDGs.push_back( 545 );
257 m_PDGs.push_back( 5114 );
258 m_PDGs.push_back( 5224 );
259 m_PDGs.push_back( 5214 );
260 m_PDGs.push_back( 5314 );
261 m_PDGs.push_back( 5324 );
262 m_PDGs.push_back( 5334 );
263 m_PDGs.push_back( 10541 );
264 m_PDGs.push_back( 10543 );
265 m_PDGs.push_back( 20543 );
267 m_PDGs.push_back( 4424 );
268 m_PDGs.push_back( 4422 );
269 m_PDGs.push_back( 4414 );
270 m_PDGs.push_back( 4412 );
271 m_PDGs.push_back( 4432 );
272 m_PDGs.push_back( 4434 );
274 m_PDGs.push_back( 130 );
277 for(
unsigned int i=0;
i<m_PDGs.size();
i++){
278 int pdt=HepPID::translatePythiatoPDT (m_PDGs.at(
i));
279 if(pdt!=m_PDGs.at(
i))m_PDGs.at(
i)=pdt;
290 bool usePythia = fPSet->getUntrackedParameter<
bool>(
"use_internal_pythia",
true);
291 bool useTauola = fPSet->getUntrackedParameter<
bool>(
"use_internal_tauola",
true);
292 bool usePhotos = fPSet->getUntrackedParameter<
bool>(
"use_internal_photos",
true);
295 bool convertPythiaCodes=fPSet->getUntrackedParameter<
bool>(
"convertPythiaCodes",
true);
298 std::cout <<
"EvtGenInterface::init() PYTHIA8DATA not defined. Terminating program " << std::endl;
exit(0);
301 bool useEvtGenRandom(
true);
304 EvtExternalGenList genList(convertPythiaCodes, pythiaDir, photonType, useEvtGenRandom);
305 EvtAbsRadCorr* radCorrEngine=0;
306 if(usePhotos) radCorrEngine = genList.getPhotosModel();
307 std::list<EvtDecayBase*> extraModels = genList.getListOfModels();
308 std::list<EvtDecayBase*> myExtraModels;
309 for(
unsigned int i=0;
i<extraModels.size();
i++){
310 std::list<EvtDecayBase*>::iterator it = extraModels.begin();
312 TString
name=(*it)->getName();
313 if(name.Contains(
"PYTHIA") && usePythia) myExtraModels.push_back(*it);
314 if(name.Contains(
"TAUOLA") && useTauola) myExtraModels.push_back(*it);
319 m_EvtGen =
new EvtGen(decay_table.
fullPath().c_str(),pdt.
fullPath().c_str(),the_engine,radCorrEngine,&myExtraModels);
322 if (fPSet->exists(
"user_decay_file")){
323 std::vector<std::string> user_decays = fPSet->getParameter<std::vector<std::string> >(
"user_decay_files");
324 for(
unsigned int i=0;
i<user_decays.size();
i++){
326 m_EvtGen->readUDecay(user_decay.fullPath().c_str());
331 if (fPSet->exists(
"operates_on_particles")){
332 std::vector<int> tmpPIDs = fPSet->getParameter< std::vector<int> >(
"operates_on_particles");
334 bool goodinput=
false;
335 if(tmpPIDs.size()>0){
if(tmpPIDs.size()==1 && tmpPIDs[0]==0) goodinput=
false;}
336 else{goodinput=
false;}
337 if(goodinput) m_PDGs = tmpPIDs;
338 else SetDefault_m_PDGs();
340 else SetDefault_m_PDGs();
344 for(
unsigned int i=0;
i<m_PDGs.size();
i++){
345 std::cout <<
"EvtGenInterface::init() Particles to Operate on: " << m_PDGs[
i] << std::endl;
349 polarize_ids = fPSet->getUntrackedParameter<std::vector<int> >(
"particles_to_polarize",std::vector<int>());
350 polarize_pol = fPSet->getUntrackedParameter<std::vector<double> >(
"particle_polarizations",std::vector<double>());
351 if (polarize_ids.size() != polarize_pol.size()) {
352 throw cms::Exception(
"Configuration") <<
"EvtGenProducer requires that the particles_to_polarize and particle_polarization\n"
353 "vectors be the same size. Please fix this in your configuration.";
355 for (
unsigned int ndx = 0; ndx < polarize_ids.size(); ndx++) {
356 if (polarize_pol[ndx] < -1. || polarize_pol[ndx] > 1.) {
357 throw cms::Exception(
"Configuration") <<
"EvtGenProducer error: particle polarizations must be in the range -1 < P < 1";
359 polarizations.insert(std::pair<int, float>(polarize_ids[ndx], polarize_pol[ndx]));
363 if (fPSet->exists(
"list_forced_decays")){
364 std::vector<std::string> forced_names = fPSet->getParameter< std::vector<std::string> >(
"list_forced_decays");
365 for(
unsigned int i=0;
i<forced_names.size();
i++){
367 if(found.getId() == -1)
throw cms::Exception(
"Configuration") <<
"name in part list for ignored decays not found: " << forced_names[
i];
368 if(found.getId() == found.getAlias())
throw cms::Exception(
"Configuration") <<
"name of ignored decays is not an alias: " << forced_names[
i];
369 forced_id.push_back(found);
370 forced_pdgids.push_back(EvtPDL::getStdHep(found));
375 if (fPSet->exists(
"list_ignored_pdgids")){
376 ignore_pdgids = fPSet->getUntrackedParameter< std::vector<int> >(
"list_ignored_pdgids");
383 if(the_engine->engine() ==
nullptr){
385 <<
"The EvtGen code attempted to use a random number engine while\n"
386 <<
"the engine pointer was null in EvtGenInterface::decay. This might\n"
387 <<
"mean that the code was modified to generate a random number outside\n"
388 <<
"the event and beginLuminosityBlock methods, which is not allowed.\n";
390 CLHEP::RandFlat m_flat(*the_engine->engine(), 0., 1.);
392 for (HepMC::GenEvent::particle_const_iterator
p= evt->particles_begin();
p != evt->particles_end(); ++
p){
393 if((*p)->status()==1){
394 int idHep = (*p)->pdg_id();
395 EvtId idEvt = EvtPDL::evtIdFromStdHep(idHep);
396 for(
unsigned int i=0;
i<forced_pdgids.size();
i++){
397 if(idHep == forced_pdgids[
i]){
398 idEvt = forced_id[
i];
401 int ipart = idEvt.getId();
402 if (ipart==-1)
continue;
403 EvtDecayTable *evtDecayTable=EvtDecayTable::getInstance();
404 if (evtDecayTable->getNMode(ipart)==0)
continue;
405 addToHepMC(*
p,idEvt,evt);
415 EvtVector4R pInit(partHep->momentum().e(),partHep->momentum().px(),partHep->momentum().py(),partHep->momentum().pz());
416 EvtParticle*
parent = EvtParticleFactory::particleFactory(idEvt, pInit);
418 if(EvtPDL::getSpinType(idEvt) == EvtSpinType::DIRAC && polarizations.count(partHep->pdg_id())>0){
419 HepMC::FourVector momHep = partHep->momentum();
421 momEvt.set(momHep.t(),momHep.x(),momHep.y(),momHep.z());
424 float pol = polarizations.find(partHep->pdg_id())->
second;
429 EvtSpinDensity theSpinDensity;
430 theSpinDensity.setDim(2);
431 theSpinDensity.set(0, 0, EvtComplex(1./2. + polVec.
z()/2., 0.));
432 theSpinDensity.set(0, 1, EvtComplex(polVec.
x()/2., -polVec.
y()/2.));
433 theSpinDensity.set(1, 0, EvtComplex(polVec.
x()/2., polVec.
y()/2.));
434 theSpinDensity.set(1, 1, EvtComplex(1./2. - polVec.
z()/2., 0.));
435 parent->setSpinDensityForwardHelicityBasis(theSpinDensity);
439 m_EvtGen->generateDecay(parent);
442 EvtHepMCEvent evtHepMCEvent;
443 evtHepMCEvent.constructEvent(parent);
444 HepMC::GenEvent* evtGenHepMCTree = evtHepMCEvent.getEvent();
447 if(!evtGenHepMCTree->particles_empty()) update_particles(partHep,theEvent,(*evtGenHepMCTree->particles_begin()));
450 parent->deleteTree();
457 if(!partHep->end_vertex()){
458 HepMC::GenVertex* vtx =
new HepMC::GenVertex(p->end_vertex()->position());
459 theEvent->add_vertex(vtx);
460 vtx->add_particle_in(partHep);
462 if(p->end_vertex()->particles_out_size()!=0){
463 for(HepMC::GenVertex::particles_out_const_iterator d=p->end_vertex()->particles_out_const_begin(); d!=p->end_vertex()->particles_out_const_end();d++){
467 daughter->suggest_barcode(theEvent->particles_size()+1);
468 partHep->end_vertex()->add_particle_out(daughter);
472 for(
unsigned int i=0;
i<forced_pdgids.size();
i++){
473 if(daughter->pdg_id()==forced_pdgids[
i]){
474 addToHepMC(daughter,forced_id[
i],theEvent);
478 if(isforced)
continue;
482 for(
unsigned int i=0;
i<ignore_pdgids.size();
i++){
483 if(daughter->pdg_id()==ignore_pdgids[
i])isignore=
true;
487 if((*d)->end_vertex() && !isignore) update_particles(daughter,theEvent,(*d));
494 the_engine->setRandomEngine(v);
499 if ( !fRandomEngine ) {
501 <<
"EvtGenInterface::flat: Attempt to generate random number when engine pointer is null\n"
502 <<
"This might mean that the code was modified to generate a random number outside the\n"
503 <<
"event and beginLuminosityBlock methods, which is not allowed.\n";
505 return fRandomEngine->flat();
virtual HepMC::GenEvent * decay(HepMC::GenEvent *)
static unsigned int getId(void)
virtual void setRandomEngine(CLHEP::HepRandomEngine *v)
U second(std::pair< T, U > const &p)
static CLHEP::HepRandomEngine * fRandomEngine
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Vector3DBase unit() const
void update_particles(HepMC::GenParticle *partHep, HepMC::GenEvent *theEvent, HepMC::GenParticle *p)
EvtGenInterface(const edm::ParameterSet &)
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::string fullPath() const
void addToHepMC(HepMC::GenParticle *partHep, const EvtId &idEvt, HepMC::GenEvent *theEvent)