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"
65 m_PDGs.push_back( 300553 ) ;
66 m_PDGs.push_back( 511 ) ;
67 m_PDGs.push_back( 521 ) ;
68 m_PDGs.push_back( 523 ) ;
69 m_PDGs.push_back( 513 ) ;
70 m_PDGs.push_back( 533 ) ;
71 m_PDGs.push_back( 531 ) ;
73 m_PDGs.push_back( 15 ) ;
75 m_PDGs.push_back( 413 ) ;
76 m_PDGs.push_back( 423 ) ;
77 m_PDGs.push_back( 433 ) ;
78 m_PDGs.push_back( 411 ) ;
79 m_PDGs.push_back( 421 ) ;
80 m_PDGs.push_back( 431 ) ;
81 m_PDGs.push_back( 10411 );
82 m_PDGs.push_back( 10421 );
83 m_PDGs.push_back( 10413 );
84 m_PDGs.push_back( 10423 );
85 m_PDGs.push_back( 20413 );
86 m_PDGs.push_back( 20423 );
88 m_PDGs.push_back( 415 );
89 m_PDGs.push_back( 425 );
90 m_PDGs.push_back( 10431 );
91 m_PDGs.push_back( 20433 );
92 m_PDGs.push_back( 10433 );
93 m_PDGs.push_back( 435 );
95 m_PDGs.push_back( 310 );
96 m_PDGs.push_back( 311 );
97 m_PDGs.push_back( 313 );
98 m_PDGs.push_back( 323 );
99 m_PDGs.push_back( 10321 );
100 m_PDGs.push_back( 10311 );
101 m_PDGs.push_back( 10313 );
102 m_PDGs.push_back( 10323 );
103 m_PDGs.push_back( 20323 );
104 m_PDGs.push_back( 20313 );
105 m_PDGs.push_back( 325 );
106 m_PDGs.push_back( 315 );
108 m_PDGs.push_back( 100313 );
109 m_PDGs.push_back( 100323 );
110 m_PDGs.push_back( 30313 );
111 m_PDGs.push_back( 30323 );
112 m_PDGs.push_back( 30343 );
113 m_PDGs.push_back( 30353 );
114 m_PDGs.push_back( 30363 );
116 m_PDGs.push_back( 111 );
117 m_PDGs.push_back( 221 );
118 m_PDGs.push_back( 113 );
119 m_PDGs.push_back( 213 );
120 m_PDGs.push_back( 223 );
121 m_PDGs.push_back( 331 );
122 m_PDGs.push_back( 333 );
123 m_PDGs.push_back( 20213 );
124 m_PDGs.push_back( 20113 );
125 m_PDGs.push_back( 215 );
126 m_PDGs.push_back( 115 );
127 m_PDGs.push_back( 10213 );
128 m_PDGs.push_back( 10113 );
129 m_PDGs.push_back( 9000111 );
130 m_PDGs.push_back( 9000211 );
131 m_PDGs.push_back( 9010221 );
132 m_PDGs.push_back( 10221 );
133 m_PDGs.push_back( 20223 );
134 m_PDGs.push_back( 20333 );
135 m_PDGs.push_back( 225 );
136 m_PDGs.push_back( 9020221 );
137 m_PDGs.push_back( 335 );
138 m_PDGs.push_back( 10223 );
139 m_PDGs.push_back( 10333 );
140 m_PDGs.push_back( 100213 );
141 m_PDGs.push_back( 100113 );
143 m_PDGs.push_back( 441 );
144 m_PDGs.push_back( 100441 );
145 m_PDGs.push_back( 443 );
146 m_PDGs.push_back( 100443 );
147 m_PDGs.push_back( 9000443 );
148 m_PDGs.push_back( 9010443 );
149 m_PDGs.push_back( 9020443 );
150 m_PDGs.push_back( 10441 );
151 m_PDGs.push_back( 20443 );
152 m_PDGs.push_back( 445 );
154 m_PDGs.push_back( 30443 );
155 m_PDGs.push_back( 551 );
156 m_PDGs.push_back( 553 );
157 m_PDGs.push_back( 100553 );
158 m_PDGs.push_back( 200553 );
159 m_PDGs.push_back( 10551 );
160 m_PDGs.push_back( 20553 );
161 m_PDGs.push_back( 555 );
162 m_PDGs.push_back( 10553 );
164 m_PDGs.push_back( 110551 );
165 m_PDGs.push_back( 120553 );
166 m_PDGs.push_back( 100555 );
167 m_PDGs.push_back( 210551 );
168 m_PDGs.push_back( 220553 );
169 m_PDGs.push_back( 200555 );
170 m_PDGs.push_back( 30553 );
171 m_PDGs.push_back( 20555 );
173 m_PDGs.push_back( 557 );
174 m_PDGs.push_back( 130553 );
175 m_PDGs.push_back( 120555 );
176 m_PDGs.push_back( 100557 );
177 m_PDGs.push_back( 110553 );
178 m_PDGs.push_back( 210553 );
179 m_PDGs.push_back( 10555 );
180 m_PDGs.push_back( 110555 );
182 m_PDGs.push_back( 4122 );
183 m_PDGs.push_back( 4132 );
185 m_PDGs.push_back( 4112 );
186 m_PDGs.push_back( 4212 );
187 m_PDGs.push_back( 4232 );
188 m_PDGs.push_back( 4222 );
189 m_PDGs.push_back( 4322 );
190 m_PDGs.push_back( 4312 );
192 m_PDGs.push_back( 13122 );
193 m_PDGs.push_back( 13124 );
194 m_PDGs.push_back( 23122 );
195 m_PDGs.push_back( 33122 );
196 m_PDGs.push_back( 43122 );
197 m_PDGs.push_back( 53122 );
198 m_PDGs.push_back( 13126 );
199 m_PDGs.push_back( 13212 );
202 m_PDGs.push_back( 3126 );
203 m_PDGs.push_back( 3124 );
204 m_PDGs.push_back( 3122 );
205 m_PDGs.push_back( 3222 );
206 m_PDGs.push_back( 2214 );
207 m_PDGs.push_back( 2224 );
208 m_PDGs.push_back( 3324 );
209 m_PDGs.push_back( 2114 );
210 m_PDGs.push_back( 1114 );
211 m_PDGs.push_back( 3112 );
212 m_PDGs.push_back( 3212 );
213 m_PDGs.push_back( 3114 );
214 m_PDGs.push_back( 3224 );
215 m_PDGs.push_back( 3214 );
216 m_PDGs.push_back( 3216 );
217 m_PDGs.push_back( 3322 );
218 m_PDGs.push_back( 3312 );
219 m_PDGs.push_back( 3314 );
220 m_PDGs.push_back( 3334 );
222 m_PDGs.push_back( 4114 );
223 m_PDGs.push_back( 4214 );
224 m_PDGs.push_back( 4224 );
225 m_PDGs.push_back( 4314 );
226 m_PDGs.push_back( 4324 );
227 m_PDGs.push_back( 4332 );
228 m_PDGs.push_back( 4334 );
231 m_PDGs.push_back( 10443 );
233 m_PDGs.push_back( 5122 );
234 m_PDGs.push_back( 5132 );
235 m_PDGs.push_back( 5232 );
236 m_PDGs.push_back( 5332 );
237 m_PDGs.push_back( 5222 );
238 m_PDGs.push_back( 5112 );
239 m_PDGs.push_back( 5212 );
240 m_PDGs.push_back( 541 );
241 m_PDGs.push_back( 14122 );
242 m_PDGs.push_back( 14124 );
243 m_PDGs.push_back( 5312 );
244 m_PDGs.push_back( 5322 );
245 m_PDGs.push_back( 10521 );
246 m_PDGs.push_back( 20523 );
247 m_PDGs.push_back( 10523 );
249 m_PDGs.push_back( 525 );
250 m_PDGs.push_back( 10511 );
251 m_PDGs.push_back( 20513 );
252 m_PDGs.push_back( 10513 );
253 m_PDGs.push_back( 515 );
254 m_PDGs.push_back( 10531 );
255 m_PDGs.push_back( 20533 );
256 m_PDGs.push_back( 10533 );
257 m_PDGs.push_back( 535 );
258 m_PDGs.push_back( 543 );
259 m_PDGs.push_back( 545 );
260 m_PDGs.push_back( 5114 );
261 m_PDGs.push_back( 5224 );
262 m_PDGs.push_back( 5214 );
263 m_PDGs.push_back( 5314 );
264 m_PDGs.push_back( 5324 );
265 m_PDGs.push_back( 5334 );
266 m_PDGs.push_back( 10541 );
267 m_PDGs.push_back( 10543 );
268 m_PDGs.push_back( 20543 );
270 m_PDGs.push_back( 4424 );
271 m_PDGs.push_back( 4422 );
272 m_PDGs.push_back( 4414 );
273 m_PDGs.push_back( 4412 );
274 m_PDGs.push_back( 4432 );
275 m_PDGs.push_back( 4434 );
277 m_PDGs.push_back( 130 );
280 for(
unsigned int i=0;
i<m_PDGs.size();
i++){
281 int pdt=HepPID::translatePythiatoPDT (m_PDGs.at(
i));
282 if(pdt!=m_PDGs.at(
i))m_PDGs.at(
i)=pdt;
291 fSpecialSettings.push_back(
"Pythia8:ParticleDecays:mixB = off");
297 bool usePythia = fPSet->getUntrackedParameter<
bool>(
"use_internal_pythia",
true);
298 bool useTauola = fPSet->getUntrackedParameter<
bool>(
"use_internal_tauola",
true);
299 bool usePhotos = fPSet->getUntrackedParameter<
bool>(
"use_internal_photos",
true);
302 bool convertPythiaCodes=fPSet->getUntrackedParameter<
bool>(
"convertPythiaCodes",
true);
305 edm::LogError(
"EvtGenInterface::~EvtGenInterface") <<
"EvtGenInterface::init() PYTHIA8DATA not defined. Terminating program ";
309 bool useEvtGenRandom(
true);
312 EvtExternalGenList genList(convertPythiaCodes, pythiaDir, photonType, useEvtGenRandom);
313 EvtAbsRadCorr* radCorrEngine=0;
314 if(usePhotos) radCorrEngine = genList.getPhotosModel();
315 std::list<EvtDecayBase*> extraModels = genList.getListOfModels();
316 std::list<EvtDecayBase*> myExtraModels;
317 for(
unsigned int i=0;
i<extraModels.size();
i++){
318 std::list<EvtDecayBase*>::iterator it = extraModels.begin();
320 TString
name=(*it)->getName();
321 if(name.Contains(
"PYTHIA") && usePythia) myExtraModels.push_back(*it);
322 if(name.Contains(
"TAUOLA") && useTauola) myExtraModels.push_back(*it);
328 std::list<EvtDecayBase*> userModels = userList.
getUserModels();
329 for(
unsigned int i=0;
i<userModels.size();
i++){
330 std::list<EvtDecayBase*>::iterator it = userModels.begin();
332 TString
name=(*it)->getName();
333 edm::LogInfo(
"EvtGenInterface::~EvtGenInterface") <<
"Adding user model: "<<
name;
334 myExtraModels.push_back(*it);
340 BmixingOption = fPSet->getUntrackedParameter<
int>(
"B_Mixing",1);
341 if(BmixingOption!=0 && BmixingOption!=1){
342 throw cms::Exception(
"Configuration") <<
"EvtGenProducer requires B_Mixing to be 0 (coherent) or 1 (incoherent) \n"
343 "Please fix this in your configuration.";
348 m_EvtGen =
new EvtGen(decay_table.
fullPath().c_str(),pdt.
fullPath().c_str(),the_engine,radCorrEngine,&myExtraModels,BmixingOption);
351 if (fPSet->exists(
"user_decay_file")){
352 std::vector<std::string> user_decays = fPSet->getParameter<std::vector<std::string> >(
"user_decay_file");
353 for(
unsigned int i=0;
i<user_decays.size();
i++){
355 m_EvtGen->readUDecay(user_decay.fullPath().c_str());
359 if (fPSet->exists(
"user_decay_embedded")){
360 std::vector<std::string> user_decay_lines = fPSet->getParameter<std::vector<std::string> >(
"user_decay_embedded");
362 FILE* tmpf = std::fopen(user_decay_tmp.c_str(),
"w");
364 edm::LogError(
"EvtGenInterface::~EvtGenInterface") <<
"EvtGenInterface::init() fails when trying to open a temporary file for embedded user.dec. Terminating program ";
367 for (
unsigned int i=0;
i<user_decay_lines.size();
i++) {
368 user_decay_lines.at(
i) +=
"\n";
369 std::fputs(user_decay_lines.at(
i).c_str(), tmpf);
372 m_EvtGen->readUDecay(user_decay_tmp.c_str());
376 if (fPSet->exists(
"operates_on_particles")){
377 std::vector<int> tmpPIDs = fPSet->getParameter< std::vector<int> >(
"operates_on_particles");
379 bool goodinput=
false;
380 if(tmpPIDs.size()>0){
if(tmpPIDs.size()==1 && tmpPIDs[0]==0) goodinput=
false;
383 else{goodinput=
false;}
384 if(goodinput) m_PDGs = tmpPIDs;
385 else SetDefault_m_PDGs();
387 else SetDefault_m_PDGs();
389 for(
unsigned int i=0;
i<m_PDGs.size();
i++){
390 edm::LogInfo(
"EvtGenInterface::~EvtGenInterface") <<
"EvtGenInterface::init() Particles to Operate on: " << m_PDGs[
i];
394 polarize_ids = fPSet->getUntrackedParameter<std::vector<int> >(
"particles_to_polarize",std::vector<int>());
395 polarize_pol = fPSet->getUntrackedParameter<std::vector<double> >(
"particle_polarizations",std::vector<double>());
396 if (polarize_ids.size() != polarize_pol.size()) {
397 throw cms::Exception(
"Configuration") <<
"EvtGenProducer requires that the particles_to_polarize and particle_polarization\n"
398 "vectors be the same size. Please fix this in your configuration.";
400 for (
unsigned int ndx = 0; ndx < polarize_ids.size(); ndx++) {
401 if (polarize_pol[ndx] < -1. || polarize_pol[ndx] > 1.) {
402 throw cms::Exception(
"Configuration") <<
"EvtGenProducer error: particle polarizations must be in the range -1 < P < 1";
404 polarizations.insert(std::pair<int, float>(polarize_ids[ndx], polarize_pol[ndx]));
408 if (fPSet->exists(
"list_forced_decays")){
409 std::vector<std::string> forced_names = fPSet->getParameter< std::vector<std::string> >(
"list_forced_decays");
410 for(
unsigned int i=0;
i<forced_names.size();
i++){
412 if(found.getId() == -1)
throw cms::Exception(
"Configuration") <<
"name in part list for ignored decays not found: " << forced_names[
i];
413 if(found.getId() == found.getAlias())
throw cms::Exception(
"Configuration") <<
"name of ignored decays is not an alias: " << forced_names[
i];
414 forced_id.push_back(found);
415 forced_pdgids.push_back(EvtPDL::getStdHep(found));
418 edm::LogInfo(
"EvtGenInterface::~EvtGenInterface") <<
"Number of Forced Paricles is: " << forced_pdgids.size() << std::endl;
419 for(
unsigned int j=0;
j<forced_id.size();
j++){
420 edm::LogInfo(
"EvtGenInterface::~EvtGenInterface") <<
"Forced Paricles are: " << forced_pdgids.at(
j) <<
" " << forced_id.at(
j) << std::endl;
423 if (fPSet->exists(
"list_ignored_pdgids")){
424 ignore_pdgids = fPSet->getUntrackedParameter< std::vector<int> >(
"list_ignored_pdgids");
431 if(the_engine->engine() ==
nullptr){
433 <<
"The EvtGen code attempted to use a random number engine while\n"
434 <<
"the engine pointer was null in EvtGenInterface::decay. This might\n"
435 <<
"mean that the code was modified to generate a random number outside\n"
436 <<
"the event and beginLuminosityBlock methods, which is not allowed.\n";
438 CLHEP::RandFlat m_flat(*the_engine->engine(), 0., 1.);
441 unsigned int nisforced=0;
442 std::vector<std::vector<HepMC::GenParticle*> > forcedparticles;
443 for(
unsigned int i=0;
i<forced_pdgids.size();
i++) forcedparticles.push_back(std::vector<HepMC::GenParticle*>());
446 for (HepMC::GenEvent::particle_const_iterator
p= evt->particles_begin();
p != evt->particles_end(); ++
p){
447 if((*p)->status()==1){
448 int idHep = (*p)->pdg_id();
450 for(
unsigned int i=0;
i<ignore_pdgids.size();
i++){
451 if(idHep==ignore_pdgids[
i])isignore=
true;
455 for(
unsigned int i=0;
i<forced_pdgids.size();
i++){
456 if(idHep==forced_pdgids[
i]){
457 forcedparticles.at(i).push_back(*
p);
463 bool isDefaultEvtGen=
false;
464 for(
unsigned int i=0;
i<m_PDGs.size();
i++){
465 if(
abs(idHep)==
abs(m_PDGs[
i])){
466 isDefaultEvtGen=
true;
470 EvtId idEvt = EvtPDL::evtIdFromStdHep(idHep);
471 int ipart = idEvt.getId();
472 EvtDecayTable *evtDecayTable=EvtDecayTable::getInstance();
473 if(!isforced && isDefaultEvtGen && ipart!=-1 && evtDecayTable->getNMode(ipart)!=0){
474 addToHepMC(*
p,idEvt,evt,
true);
481 unsigned int which = (
unsigned int)(nisforced*flat());
482 if(which==nisforced && nisforced>0) which=nisforced-1;
485 for (
unsigned int i=0;
i<forcedparticles.size();
i++){
486 for (
unsigned int j=0;
j<forcedparticles.at(
i).size();
j++){
487 EvtId idEvt = EvtPDL::evtIdFromStdHep(forcedparticles.at(
i).at(
j)->pdg_id());
489 idEvt = forced_id[
i];
490 edm::LogInfo(
"EvtGenInterface::decay ") << EvtPDL::getStdHep(idEvt) <<
" will force to decay " << idx+1
491 <<
" out of " << nisforced << std::endl;
493 bool decayed =
false;
494 while(!decayed){decayed=addToHepMC(forcedparticles.at(
i).at(
j),idEvt,evt,
false);}
500 for (HepMC::GenEvent::particle_const_iterator
p= evt->particles_begin();
p != evt->particles_end(); ++
p){
501 if((*p)->end_vertex() && (*p)->status() == 1)
edm::LogWarning(
"EvtGenInterface::decay error: incorrect status!");
502 if((*p)->end_vertex() && (*p)->end_vertex()->particles_out_size()==0)
edm::LogWarning(
"EvtGenInterface::decay error: empty end vertex!");
511 EvtVector4R pInit(partHep->momentum().e(),partHep->momentum().px(),partHep->momentum().py(),partHep->momentum().pz());
512 EvtParticle* parent = EvtParticleFactory::particleFactory(idEvt, pInit);
513 HepMC::FourVector posHep = (partHep->production_vertex())->
position();
514 EvtVector4R vInit(posHep.t(),posHep.x(),posHep.y(),posHep.z());
516 if(EvtPDL::getSpinType(idEvt) == EvtSpinType::DIRAC && polarizations.count(partHep->pdg_id())>0){
517 HepMC::FourVector momHep = partHep->momentum();
519 momEvt.set(momHep.t(),momHep.x(),momHep.y(),momHep.z());
522 float pol = polarizations.find(partHep->pdg_id())->
second;
527 EvtSpinDensity theSpinDensity;
528 theSpinDensity.setDim(2);
529 theSpinDensity.set(0, 0, EvtComplex(1./2. + polVec.
z()/2., 0.));
530 theSpinDensity.set(0, 1, EvtComplex(polVec.
x()/2., -polVec.
y()/2.));
531 theSpinDensity.set(1, 0, EvtComplex(polVec.
x()/2., polVec.
y()/2.));
532 theSpinDensity.set(1, 1, EvtComplex(1./2. - polVec.
z()/2., 0.));
533 parent->setSpinDensityForwardHelicityBasis(theSpinDensity);
537 m_EvtGen->generateDecay(parent);
538 if (del_daug) go_through_daughters(parent);
541 EvtHepMCEvent evtHepMCEvent;
542 evtHepMCEvent.constructEvent(parent,vInit);
544 parent->deleteTree();
547 if(!evtGenHepMCTree->particles_empty()) update_particles(partHep,theEvent,(*evtGenHepMCTree->particles_begin()));
559 if(!partHep->end_vertex()){
560 HepMC::GenVertex* vtx =
new HepMC::GenVertex(p->end_vertex()->position());
561 theEvent->add_vertex(vtx);
562 vtx->add_particle_in(partHep);
564 if ( p->end_vertex()->particles_out_size()!=0 ){
566 for ( HepMC::GenVertex::particles_out_const_iterator
d=p->end_vertex()->particles_out_const_begin();
567 d!=p->end_vertex()->particles_out_const_end();
d++ ){
570 daughter->suggest_barcode(theEvent->particles_size()+1);
571 partHep->end_vertex()->add_particle_out(daughter);
572 if((*d)->end_vertex()) update_particles(daughter,theEvent,(*
d));
574 partHep->set_status(p->status());
580 the_engine->setRandomEngine(v);
585 if ( !fRandomEngine ) {
587 <<
"EvtGenInterface::flat: Attempt to generate random number when engine pointer is null\n"
588 <<
"This might mean that the code was modified to generate a random number outside the\n"
589 <<
"event and beginLuminosityBlock methods, which is not allowed.\n";
591 return fRandomEngine->flat();
597 if(p->end_vertex()->particles_out_size()!=0){
598 for(HepMC::GenVertex::particles_out_const_iterator
d=p->end_vertex()->particles_out_const_begin();
d!=p->end_vertex()->particles_out_const_end();
d++){
599 if(
abs((*d)->pdg_id())==
abs(p->pdg_id())){
612 if(p->end_vertex()->particles_out_size()!=0){
620 int NDaug=part->getNDaug();
622 EvtParticle* Daughter;
623 for (
int i=0;
i<NDaug;
i++) {
624 Daughter=part->getDaug(
i);
625 int idHep = Daughter->getPDGId();
627 for (
unsigned int j=0;
j<forced_pdgids.size();
j++) {
628 if (idHep == forced_pdgids[
j]) {
630 Daughter->deleteDaughters();
634 if (!found) go_through_daughters(Daughter);
virtual HepMC::GenEvent * decay(HepMC::GenEvent *)
static unsigned int getId(void)
void go_through_daughters(EvtParticle *part)
virtual void setRandomEngine(CLHEP::HepRandomEngine *v)
bool addToHepMC(HepMC::GenParticle *partHep, const EvtId &idEvt, HepMC::GenEvent *theEvent, bool del_daug)
def gen
run2 Cosmic #### Run 256259 @ 0T 2015C### Run 272133 @ 3.8T 2016B###
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
Abs< T >::type abs(const T &t)
Vector3DBase unit() const
void update_particles(HepMC::GenParticle *partHep, HepMC::GenEvent *theEvent, HepMC::GenParticle *p)
EvtGenInterface(const edm::ParameterSet &)
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
bool hasnoDaughter(HepMC::GenParticle *p)
static int position[264][3]
std::list< EvtDecayBase * > getUserModels()
bool findLastinChain(HepMC::GenParticle *&p)
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::string fullPath() const