30 #include "CLHEP/Random/RandFlat.h" 33 #include "EvtGen/EvtGen.hh" 34 #include "EvtGenExternal/EvtExternalGenList.hh" 35 #include "EvtGenBase/EvtAbsRadCorr.hh" 36 #include "EvtGenBase/EvtDecayBase.hh" 37 #include "EvtGenBase/EvtId.hh" 38 #include "EvtGenBase/EvtDecayTable.hh" 39 #include "EvtGenBase/EvtParticle.hh" 40 #include "EvtGenBase/EvtParticleFactory.hh" 41 #include "EvtGenBase/EvtHepMCEvent.hh" 43 #include "HepPID/ParticleIDTranslations.hh" 50 #include "boost/filesystem.hpp" 51 #include "boost/filesystem/path.hpp" 69 m_PDGs.push_back( 300553 ) ;
70 m_PDGs.push_back( 511 ) ;
71 m_PDGs.push_back( 521 ) ;
72 m_PDGs.push_back( 523 ) ;
73 m_PDGs.push_back( 513 ) ;
74 m_PDGs.push_back( 533 ) ;
75 m_PDGs.push_back( 531 ) ;
77 m_PDGs.push_back( 15 ) ;
79 m_PDGs.push_back( 413 ) ;
80 m_PDGs.push_back( 423 ) ;
81 m_PDGs.push_back( 433 ) ;
82 m_PDGs.push_back( 411 ) ;
83 m_PDGs.push_back( 421 ) ;
84 m_PDGs.push_back( 431 ) ;
85 m_PDGs.push_back( 10411 );
86 m_PDGs.push_back( 10421 );
87 m_PDGs.push_back( 10413 );
88 m_PDGs.push_back( 10423 );
89 m_PDGs.push_back( 20413 );
90 m_PDGs.push_back( 20423 );
92 m_PDGs.push_back( 415 );
93 m_PDGs.push_back( 425 );
94 m_PDGs.push_back( 10431 );
95 m_PDGs.push_back( 20433 );
96 m_PDGs.push_back( 10433 );
97 m_PDGs.push_back( 435 );
99 m_PDGs.push_back( 310 );
100 m_PDGs.push_back( 311 );
101 m_PDGs.push_back( 313 );
102 m_PDGs.push_back( 323 );
103 m_PDGs.push_back( 10321 );
104 m_PDGs.push_back( 10311 );
105 m_PDGs.push_back( 10313 );
106 m_PDGs.push_back( 10323 );
107 m_PDGs.push_back( 20323 );
108 m_PDGs.push_back( 20313 );
109 m_PDGs.push_back( 325 );
110 m_PDGs.push_back( 315 );
112 m_PDGs.push_back( 100313 );
113 m_PDGs.push_back( 100323 );
114 m_PDGs.push_back( 30313 );
115 m_PDGs.push_back( 30323 );
116 m_PDGs.push_back( 30343 );
117 m_PDGs.push_back( 30353 );
118 m_PDGs.push_back( 30363 );
120 m_PDGs.push_back( 111 );
121 m_PDGs.push_back( 221 );
122 m_PDGs.push_back( 113 );
123 m_PDGs.push_back( 213 );
124 m_PDGs.push_back( 223 );
125 m_PDGs.push_back( 331 );
126 m_PDGs.push_back( 333 );
127 m_PDGs.push_back( 20213 );
128 m_PDGs.push_back( 20113 );
129 m_PDGs.push_back( 215 );
130 m_PDGs.push_back( 115 );
131 m_PDGs.push_back( 10213 );
132 m_PDGs.push_back( 10113 );
133 m_PDGs.push_back( 9000111 );
134 m_PDGs.push_back( 9000211 );
135 m_PDGs.push_back( 9010221 );
136 m_PDGs.push_back( 10221 );
137 m_PDGs.push_back( 20223 );
138 m_PDGs.push_back( 20333 );
139 m_PDGs.push_back( 225 );
140 m_PDGs.push_back( 9020221 );
141 m_PDGs.push_back( 335 );
142 m_PDGs.push_back( 10223 );
143 m_PDGs.push_back( 10333 );
144 m_PDGs.push_back( 100213 );
145 m_PDGs.push_back( 100113 );
147 m_PDGs.push_back( 441 );
148 m_PDGs.push_back( 100441 );
149 m_PDGs.push_back( 443 );
150 m_PDGs.push_back( 100443 );
151 m_PDGs.push_back( 9000443 );
152 m_PDGs.push_back( 9010443 );
153 m_PDGs.push_back( 9020443 );
154 m_PDGs.push_back( 10441 );
155 m_PDGs.push_back( 20443 );
156 m_PDGs.push_back( 445 );
158 m_PDGs.push_back( 30443 );
159 m_PDGs.push_back( 551 );
160 m_PDGs.push_back( 553 );
161 m_PDGs.push_back( 100553 );
162 m_PDGs.push_back( 200553 );
163 m_PDGs.push_back( 10551 );
164 m_PDGs.push_back( 20553 );
165 m_PDGs.push_back( 555 );
166 m_PDGs.push_back( 10553 );
168 m_PDGs.push_back( 110551 );
169 m_PDGs.push_back( 120553 );
170 m_PDGs.push_back( 100555 );
171 m_PDGs.push_back( 210551 );
172 m_PDGs.push_back( 220553 );
173 m_PDGs.push_back( 200555 );
174 m_PDGs.push_back( 30553 );
175 m_PDGs.push_back( 20555 );
177 m_PDGs.push_back( 557 );
178 m_PDGs.push_back( 130553 );
179 m_PDGs.push_back( 120555 );
180 m_PDGs.push_back( 100557 );
181 m_PDGs.push_back( 110553 );
182 m_PDGs.push_back( 210553 );
183 m_PDGs.push_back( 10555 );
184 m_PDGs.push_back( 110555 );
186 m_PDGs.push_back( 4122 );
187 m_PDGs.push_back( 4132 );
189 m_PDGs.push_back( 4112 );
190 m_PDGs.push_back( 4212 );
191 m_PDGs.push_back( 4232 );
192 m_PDGs.push_back( 4222 );
193 m_PDGs.push_back( 4322 );
194 m_PDGs.push_back( 4312 );
196 m_PDGs.push_back( 13122 );
197 m_PDGs.push_back( 13124 );
198 m_PDGs.push_back( 23122 );
199 m_PDGs.push_back( 33122 );
200 m_PDGs.push_back( 43122 );
201 m_PDGs.push_back( 53122 );
202 m_PDGs.push_back( 13126 );
203 m_PDGs.push_back( 13212 );
206 m_PDGs.push_back( 3126 );
207 m_PDGs.push_back( 3124 );
208 m_PDGs.push_back( 3122 );
209 m_PDGs.push_back( 3222 );
210 m_PDGs.push_back( 2214 );
211 m_PDGs.push_back( 2224 );
212 m_PDGs.push_back( 3324 );
213 m_PDGs.push_back( 2114 );
214 m_PDGs.push_back( 1114 );
215 m_PDGs.push_back( 3112 );
216 m_PDGs.push_back( 3212 );
217 m_PDGs.push_back( 3114 );
218 m_PDGs.push_back( 3224 );
219 m_PDGs.push_back( 3214 );
220 m_PDGs.push_back( 3216 );
221 m_PDGs.push_back( 3322 );
222 m_PDGs.push_back( 3312 );
223 m_PDGs.push_back( 3314 );
224 m_PDGs.push_back( 3334 );
226 m_PDGs.push_back( 4114 );
227 m_PDGs.push_back( 4214 );
228 m_PDGs.push_back( 4224 );
229 m_PDGs.push_back( 4314 );
230 m_PDGs.push_back( 4324 );
231 m_PDGs.push_back( 4332 );
232 m_PDGs.push_back( 4334 );
235 m_PDGs.push_back( 10443 );
237 m_PDGs.push_back( 5122 );
238 m_PDGs.push_back( 5132 );
239 m_PDGs.push_back( 5232 );
240 m_PDGs.push_back( 5332 );
241 m_PDGs.push_back( 5222 );
242 m_PDGs.push_back( 5112 );
243 m_PDGs.push_back( 5212 );
244 m_PDGs.push_back( 541 );
245 m_PDGs.push_back( 14122 );
246 m_PDGs.push_back( 14124 );
247 m_PDGs.push_back( 5312 );
248 m_PDGs.push_back( 5322 );
249 m_PDGs.push_back( 10521 );
250 m_PDGs.push_back( 20523 );
251 m_PDGs.push_back( 10523 );
253 m_PDGs.push_back( 525 );
254 m_PDGs.push_back( 10511 );
255 m_PDGs.push_back( 20513 );
256 m_PDGs.push_back( 10513 );
257 m_PDGs.push_back( 515 );
258 m_PDGs.push_back( 10531 );
259 m_PDGs.push_back( 20533 );
260 m_PDGs.push_back( 10533 );
261 m_PDGs.push_back( 535 );
262 m_PDGs.push_back( 543 );
263 m_PDGs.push_back( 545 );
264 m_PDGs.push_back( 5114 );
265 m_PDGs.push_back( 5224 );
266 m_PDGs.push_back( 5214 );
267 m_PDGs.push_back( 5314 );
268 m_PDGs.push_back( 5324 );
269 m_PDGs.push_back( 5334 );
270 m_PDGs.push_back( 10541 );
271 m_PDGs.push_back( 10543 );
272 m_PDGs.push_back( 20543 );
274 m_PDGs.push_back( 4424 );
275 m_PDGs.push_back( 4422 );
276 m_PDGs.push_back( 4414 );
277 m_PDGs.push_back( 4412 );
278 m_PDGs.push_back( 4432 );
279 m_PDGs.push_back( 4434 );
281 m_PDGs.push_back( 130 );
284 for(
unsigned int i=0;
i<m_PDGs.size();
i++){
285 int pdt=HepPID::translatePythiatoPDT (m_PDGs.at(
i));
286 if(pdt!=m_PDGs.at(
i))m_PDGs.at(
i)=pdt;
295 fSpecialSettings.push_back(
"Pythia8:ParticleDecays:mixB = off");
301 bool usePythia = fPSet->getUntrackedParameter<
bool>(
"use_internal_pythia",
true);
302 bool useTauola = fPSet->getUntrackedParameter<
bool>(
"use_internal_tauola",
true);
303 bool usePhotos = fPSet->getUntrackedParameter<
bool>(
"use_internal_photos",
true);
306 bool convertPythiaCodes=fPSet->getUntrackedParameter<
bool>(
"convertPythiaCodes",
true);
308 if(pythiaDir.empty()){
309 edm::LogError(
"EvtGenInterface::~EvtGenInterface") <<
"EvtGenInterface::init() PYTHIA8DATA not defined. Terminating program ";
313 bool useEvtGenRandom(
true);
316 EvtExternalGenList genList(convertPythiaCodes, pythiaDir, photonType, useEvtGenRandom);
317 EvtAbsRadCorr* radCorrEngine=
nullptr;
318 if(usePhotos) radCorrEngine = genList.getPhotosModel();
319 std::list<EvtDecayBase*> extraModels = genList.getListOfModels();
320 std::list<EvtDecayBase*> myExtraModels;
321 for(
unsigned int i=0;
i<extraModels.size();
i++){
322 std::list<EvtDecayBase*>::iterator it = extraModels.begin();
324 TString
name=(*it)->getName();
325 if(name.Contains(
"PYTHIA") && usePythia) myExtraModels.push_back(*it);
326 if(name.Contains(
"TAUOLA") && useTauola) myExtraModels.push_back(*it);
332 std::list<EvtDecayBase*> userModels = userList.
getUserModels();
333 for(
unsigned int i=0;
i<userModels.size();
i++){
334 std::list<EvtDecayBase*>::iterator it = userModels.begin();
336 TString
name=(*it)->getName();
337 edm::LogInfo(
"EvtGenInterface::~EvtGenInterface") <<
"Adding user model: "<<
name;
338 myExtraModels.push_back(*it);
344 BmixingOption = fPSet->getUntrackedParameter<
int>(
"B_Mixing",1);
345 if(BmixingOption!=0 && BmixingOption!=1){
346 throw cms::Exception(
"Configuration") <<
"EvtGenProducer requires B_Mixing to be 0 (coherent) or 1 (incoherent) \n" 347 "Please fix this in your configuration.";
352 m_EvtGen =
new EvtGen(decay_table.
fullPath().c_str(),pdt.
fullPath().c_str(),the_engine,radCorrEngine,&myExtraModels,BmixingOption);
355 if (fPSet->exists(
"user_decay_file")){
356 std::vector<std::string> user_decays = fPSet->getParameter<std::vector<std::string> >(
"user_decay_file");
357 for(
unsigned int i=0;
i<user_decays.size();
i++){
359 m_EvtGen->readUDecay(user_decay.fullPath().c_str());
363 if (fPSet->exists(
"user_decay_embedded")){
364 std::vector<std::string> user_decay_lines = fPSet->getParameter<std::vector<std::string> >(
"user_decay_embedded");
365 auto tmp_dir = boost::filesystem::temp_directory_path();
366 tmp_dir +=
"/%%%%-%%%%-%%%%-%%%%";
367 auto tmp_path = boost::filesystem::unique_path(tmp_dir);
369 FILE* tmpf = std::fopen(user_decay_tmp.c_str(),
"w");
371 edm::LogError(
"EvtGenInterface::~EvtGenInterface") <<
"EvtGenInterface::init() fails when trying to open a temporary file for embedded user.dec. Terminating program ";
374 for (
unsigned int i=0;
i<user_decay_lines.size();
i++) {
375 user_decay_lines.at(
i) +=
"\n";
376 std::fputs(user_decay_lines.at(
i).c_str(), tmpf);
379 m_EvtGen->readUDecay(user_decay_tmp.c_str());
383 if (fPSet->exists(
"operates_on_particles")){
384 std::vector<int> tmpPIDs = fPSet->getParameter< std::vector<int> >(
"operates_on_particles");
386 bool goodinput=
false;
387 if(!tmpPIDs.empty()){
if(tmpPIDs.size()==1 && tmpPIDs[0]==0) goodinput=
false;
390 else{goodinput=
false;}
391 if(goodinput) m_PDGs = tmpPIDs;
392 else SetDefault_m_PDGs();
394 else SetDefault_m_PDGs();
396 for(
unsigned int i=0;
i<m_PDGs.size();
i++){
397 edm::LogInfo(
"EvtGenInterface::~EvtGenInterface") <<
"EvtGenInterface::init() Particles to Operate on: " << m_PDGs[
i];
401 polarize_ids = fPSet->getUntrackedParameter<std::vector<int> >(
"particles_to_polarize",std::vector<int>());
402 polarize_pol = fPSet->getUntrackedParameter<std::vector<double> >(
"particle_polarizations",std::vector<double>());
403 if (polarize_ids.size() != polarize_pol.size()) {
404 throw cms::Exception(
"Configuration") <<
"EvtGenProducer requires that the particles_to_polarize and particle_polarization\n" 405 "vectors be the same size. Please fix this in your configuration.";
407 for (
unsigned int ndx = 0; ndx < polarize_ids.size(); ndx++) {
408 if (polarize_pol[ndx] < -1. || polarize_pol[ndx] > 1.) {
409 throw cms::Exception(
"Configuration") <<
"EvtGenProducer error: particle polarizations must be in the range -1 < P < 1";
411 polarizations.insert(std::pair<int, float>(polarize_ids[ndx], polarize_pol[ndx]));
415 if (fPSet->exists(
"list_forced_decays")){
416 std::vector<std::string> forced_names = fPSet->getParameter< std::vector<std::string> >(
"list_forced_decays");
417 for(
unsigned int i=0;
i<forced_names.size();
i++){
419 if(found.getId() == -1)
throw cms::Exception(
"Configuration") <<
"name in part list for ignored decays not found: " << forced_names[
i];
420 if(found.getId() == found.getAlias())
throw cms::Exception(
"Configuration") <<
"name of ignored decays is not an alias: " << forced_names[
i];
421 forced_id.push_back(found);
422 forced_pdgids.push_back(EvtPDL::getStdHep(found));
425 edm::LogInfo(
"EvtGenInterface::~EvtGenInterface") <<
"Number of Forced Paricles is: " << forced_pdgids.size() << std::endl;
426 for(
unsigned int j=0;j<forced_id.size();j++){
427 edm::LogInfo(
"EvtGenInterface::~EvtGenInterface") <<
"Forced Paricles are: " << forced_pdgids.at(j) <<
" " << forced_id.at(j) << std::endl;
430 if (fPSet->exists(
"list_ignored_pdgids")){
431 ignore_pdgids = fPSet->getUntrackedParameter< std::vector<int> >(
"list_ignored_pdgids");
438 if(the_engine->engine() ==
nullptr){
440 <<
"The EvtGen code attempted to use a random number engine while\n" 441 <<
"the engine pointer was null in EvtGenInterface::decay. This might\n" 442 <<
"mean that the code was modified to generate a random number outside\n" 443 <<
"the event and beginLuminosityBlock methods, which is not allowed.\n";
445 CLHEP::RandFlat m_flat(*the_engine->engine(), 0., 1.);
448 unsigned int nisforced=0;
449 std::vector<std::vector<HepMC::GenParticle*> > forcedparticles;
450 for(
unsigned int i=0;
i<forced_pdgids.size();
i++) forcedparticles.push_back(std::vector<HepMC::GenParticle*>());
453 for (HepMC::GenEvent::particle_const_iterator
p= evt->particles_begin();
p != evt->particles_end(); ++
p){
454 if((*p)->status()==1){
455 int idHep = (*p)->pdg_id();
457 for(
unsigned int i=0;
i<ignore_pdgids.size();
i++){
458 if(idHep==ignore_pdgids[
i])isignore=
true;
462 for(
unsigned int i=0;
i<forced_pdgids.size();
i++){
463 if(idHep==forced_pdgids[
i]){
464 forcedparticles.at(i).push_back(*
p);
470 bool isDefaultEvtGen=
false;
471 for(
unsigned int i=0;
i<m_PDGs.size();
i++){
472 if(
abs(idHep)==
abs(m_PDGs[
i])){
473 isDefaultEvtGen=
true;
477 EvtId idEvt = EvtPDL::evtIdFromStdHep(idHep);
478 int ipart = idEvt.getId();
479 EvtDecayTable *evtDecayTable=EvtDecayTable::getInstance();
480 if(!isforced && isDefaultEvtGen && ipart!=-1 && evtDecayTable->getNMode(ipart)!=0){
481 addToHepMC(*
p,idEvt,evt,
true);
488 unsigned int which = (
unsigned int)(nisforced*flat());
489 if(which==nisforced && nisforced>0) which=nisforced-1;
492 for (
unsigned int i=0;
i<forcedparticles.size();
i++){
493 for (
unsigned int j=0; j<forcedparticles.at(
i).size(); j++){
494 EvtId idEvt = EvtPDL::evtIdFromStdHep(forcedparticles.at(
i).at(j)->pdg_id());
496 idEvt = forced_id[
i];
497 edm::LogInfo(
"EvtGenInterface::decay ") << EvtPDL::getStdHep(idEvt) <<
" will force to decay " << idx+1
498 <<
" out of " << nisforced << std::endl;
500 bool decayed =
false;
501 while(!decayed){decayed=addToHepMC(forcedparticles.at(
i).at(j),idEvt,evt,
false);}
507 for (HepMC::GenEvent::particle_const_iterator
p= evt->particles_begin();
p != evt->particles_end(); ++
p){
508 if((*p)->end_vertex() && (*p)->status() == 1)
edm::LogWarning(
"EvtGenInterface::decay error: incorrect status!");
509 if((*p)->end_vertex() && (*p)->end_vertex()->particles_out_size()==0)
edm::LogWarning(
"EvtGenInterface::decay error: empty end vertex!");
518 EvtVector4R pInit(partHep->momentum().e(),partHep->momentum().px(),partHep->momentum().py(),partHep->momentum().pz());
519 EvtParticle*
parent = EvtParticleFactory::particleFactory(idEvt, pInit);
520 HepMC::FourVector posHep = (partHep->production_vertex())->
position();
521 EvtVector4R vInit(posHep.t(),posHep.x(),posHep.y(),posHep.z());
523 if(EvtPDL::getSpinType(idEvt) == EvtSpinType::DIRAC && polarizations.count(partHep->pdg_id())>0){
524 const HepMC::FourVector& momHep = partHep->momentum();
526 momEvt.set(momHep.t(),momHep.x(),momHep.y(),momHep.z());
529 float pol = polarizations.find(partHep->pdg_id())->
second;
534 EvtSpinDensity theSpinDensity;
535 theSpinDensity.setDim(2);
536 theSpinDensity.set(0, 0, EvtComplex(1./2. + polVec.
z()/2., 0.));
537 theSpinDensity.set(0, 1, EvtComplex(polVec.
x()/2., -polVec.
y()/2.));
538 theSpinDensity.set(1, 0, EvtComplex(polVec.
x()/2., polVec.
y()/2.));
539 theSpinDensity.set(1, 1, EvtComplex(1./2. - polVec.
z()/2., 0.));
540 parent->setSpinDensityForwardHelicityBasis(theSpinDensity);
544 m_EvtGen->generateDecay(parent);
545 if (del_daug) go_through_daughters(parent);
548 EvtHepMCEvent evtHepMCEvent;
549 evtHepMCEvent.constructEvent(parent,vInit);
550 HepMC::GenEvent* evtGenHepMCTree = evtHepMCEvent.getEvent();
551 parent->deleteTree();
554 if(!evtGenHepMCTree->particles_empty()) update_particles(partHep,theEvent,(*evtGenHepMCTree->particles_begin()));
566 if(!partHep->end_vertex()){
567 HepMC::GenVertex*
vtx =
new HepMC::GenVertex(p->end_vertex()->position());
568 theEvent->add_vertex(vtx);
569 vtx->add_particle_in(partHep);
571 if ( p->end_vertex()->particles_out_size()!=0 ){
573 for ( HepMC::GenVertex::particles_out_const_iterator
d=p->end_vertex()->particles_out_const_begin();
574 d!=p->end_vertex()->particles_out_const_end();
d++ ){
577 daughter->suggest_barcode(theEvent->particles_size()+1);
578 partHep->end_vertex()->add_particle_out(daughter);
579 if((*d)->end_vertex()) update_particles(daughter,theEvent,(*
d));
581 partHep->set_status(p->status());
587 the_engine->setRandomEngine(v);
592 if ( !fRandomEngine ) {
594 <<
"EvtGenInterface::flat: Attempt to generate random number when engine pointer is null\n" 595 <<
"This might mean that the code was modified to generate a random number outside the\n" 596 <<
"event and beginLuminosityBlock methods, which is not allowed.\n";
598 return fRandomEngine->flat();
604 if(p->end_vertex()->particles_out_size()!=0){
605 for(HepMC::GenVertex::particles_out_const_iterator
d=p->end_vertex()->particles_out_const_begin();
d!=p->end_vertex()->particles_out_const_end();
d++){
606 if(
abs((*d)->pdg_id())==
abs(p->pdg_id())){
619 if(p->end_vertex()->particles_out_size()!=0){
627 int NDaug=part->getNDaug();
629 EvtParticle* Daughter;
630 for (
int i=0;
i<NDaug;
i++) {
631 Daughter=part->getDaug(
i);
632 int idHep = Daughter->getPDGId();
634 for (
unsigned int j=0;j<forced_pdgids.size();j++) {
635 if (idHep == forced_pdgids[j]) {
637 Daughter->deleteDaughters();
641 if (!found) go_through_daughters(Daughter);
~EvtGenInterface() override
static unsigned int getId()
void go_through_daughters(EvtParticle *part)
bool addToHepMC(HepMC::GenParticle *partHep, const EvtId &idEvt, HepMC::GenEvent *theEvent, bool del_daug)
U second(std::pair< T, U > const &p)
void setRandomEngine(CLHEP::HepRandomEngine *v) override
static CLHEP::HepRandomEngine * fRandomEngine
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Abs< T >::type abs(const T &t)
HepMC::GenEvent * decay(HepMC::GenEvent *) override
Vector3DBase unit() const
void update_particles(HepMC::GenParticle *partHep, HepMC::GenEvent *theEvent, HepMC::GenParticle *p)
EvtGenInterface(const edm::ParameterSet &)
bool hasnoDaughter(HepMC::GenParticle *p)
static int position[264][3]
std::list< EvtDecayBase * > getUserModels()
bool findLastinChain(HepMC::GenParticle *&p)
std::string fullPath() const
#define DEFINE_EDM_PLUGIN(factory, type, name)