test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Pythia8Hadronizer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <string>
4 #include <memory>
5 #include <stdint.h>
6 #include <vector>
7 
8 #include "HepMC/GenEvent.h"
9 #include "HepMC/GenParticle.h"
10 
11 #include "Pythia8/Pythia.h"
12 #include "Pythia8Plugins/HepMC2.h"
13 
14 using namespace Pythia8;
15 
17 
19 
20 // PS matchning prototype
21 //
23 #include "Pythia8Plugins/JetMatching.h"
24 #include "Pythia8Plugins/aMCatNLOHooks.h"
25 
27 
28 // Emission Veto Hooks
29 //
30 #include "Pythia8Plugins/PowhegHooks.h"
32 
33 //decay filter hook
35 
36 //decay filter hook
38 
39 // EvtGen plugin
40 //
41 #include "Pythia8Plugins/EvtGen.h"
42 
48 
51 
55 
57 
58 #include "HepPID/ParticleIDTranslations.hh"
59 
61 
62 namespace CLHEP {
63  class HepRandomEngine;
64 }
65 
66 using namespace gen;
67 
68 
70 
71  public:
72 
73  Pythia8Hadronizer(const edm::ParameterSet &params);
75 
76  bool initializeForInternalPartons() override;
77  bool initializeForExternalPartons();
78 
79  bool generatePartonsAndHadronize() override;
80  bool hadronize();
81 
82  virtual bool residualDecay();
83 
84  void finalizeEvent() override;
85 
86  void statistics() override;
87 
88  const char *classname() const override { return "Pythia8Hadronizer"; }
89 
90  private:
91 
92  virtual void doSetRandomEngine(CLHEP::HepRandomEngine* v) override { p8SetRandomEngine(v); }
93  virtual std::vector<std::string> const& doSharedResources() const override { return p8SharedResources; }
94 
96  double comEnergy;
97 
99  std::auto_ptr<LHAupLesHouches> lhaUP;
100 
101  enum { PP, PPbar, ElectronPositron };
102  int fInitialState ; // pp, ppbar, or e-e+
103 
104  double fBeam1PZ;
105  double fBeam2PZ;
106 
107  //helper class to allow multiple user hooks simultaneously
109 
110  // Reweight user hooks
111  //
112  UserHooks* fReweightUserHook;
113  UserHooks* fReweightRapUserHook;
115 
116  // PS matching prototype
117  //
119  Pythia8::JetMatchingMadgraph *fJetMatchingPy8InternalHook;
120  Pythia8::amcnlo_unitarised_interface *fMergingHook;
121 
122  // Emission Veto Hooks
123  //
124  PowhegHooks* fEmissionVetoHook;
126 
127  //resonance decay filter hook
129 
130  //PT filter hook
132 
141 
142  static const std::vector<std::string> p8SharedResources;
143 
145 
146  vector<float> DJR;
147  int nME;
149 
150  int nISRveto;
151  int nFSRveto;
152 
153  int NHooks;
154 
155 };
156 
158 
160  BaseHadronizer(params), Py8InterfaceBase(params),
161  comEnergy(params.getParameter<double>("comEnergy")),
162  LHEInputFileName(params.getUntrackedParameter<std::string>("LHEInputFileName","")),
163  fInitialState(PP),
164  fMultiUserHook(new MultiUserHook), fReweightUserHook(0),fReweightRapUserHook(0),fReweightPtHatRapUserHook(0),
165  fJetMatchingHook(0),fJetMatchingPy8InternalHook(0), fMergingHook(0),
166  fEmissionVetoHook(0), fEmissionVetoHook1(0), fResonanceDecayFilterHook(0), fPTFilterHook(0), nME(-1), nMEFiltered(-1), nISRveto(0), nFSRveto(0),
167  NHooks(0)
168 {
169 
170  // J.Y.: the following 3 parameters are hacked "for a reason"
171  //
172  if ( params.exists( "PPbarInitialState" ) )
173  {
174  if ( fInitialState == PP )
175  {
177  edm::LogImportant("GeneratorInterface|Pythia8Interface")
178  << "Pythia8 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
179  << "This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
180  }
181  else
182  {
183  // probably need to throw on attempt to override ?
184  }
185  }
186  else if ( params.exists( "ElectronPositronInitialState" ) )
187  {
188  if ( fInitialState == PP )
189  {
191  edm::LogInfo("GeneratorInterface|Pythia8Interface")
192  << "Pythia8 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
193  << "This is a user-request change from the DEFAULT PROTON-PROTON initial state.";
194  }
195  else
196  {
197  // probably need to throw on attempt to override ?
198  }
199  }
200  else if ( params.exists( "ElectronProtonInitialState" ) || params.exists( "PositronProtonInitialState" ) )
201  {
202  // throw on unknown initial state !
203  throw edm::Exception(edm::errors::Configuration,"Pythia8Interface")
204  <<" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
205  }
206 
207  if( params.exists( "SLHAFileForPythia8" ) ) {
208  std::string slhafilenameshort = params.getParameter<std::string>("SLHAFileForPythia8");
209  edm::FileInPath f1( slhafilenameshort );
210 
211  fMasterGen->settings.mode("SLHA:readFrom", 2);
212  fMasterGen->settings.word("SLHA:file", f1.fullPath());
213 
215  line != fParameters.end(); ++line ) {
216  if (line->find("SLHA:file") != std::string::npos)
217  throw cms::Exception("PythiaError") << "Attempted to set SLHA file name twice, "
218  << "using Pythia8 card SLHA:file and Pythia8Interface card SLHAFileForPythia8"
219  << std::endl;
220  }
221  }
222  else if( params.exists( "SLHATableForPythia8" ) ) {
223  std::string slhatable = params.getParameter<std::string>("SLHATableForPythia8");
224 
225  char tempslhaname[] = "pythia8SLHAtableXXXXXX";
226  int fd = mkstemp(tempslhaname);
227  write(fd,slhatable.c_str(),slhatable.size());
228  close(fd);
229 
230  slhafile_ = tempslhaname;
231 
232  fMasterGen->settings.mode("SLHA:readFrom", 2);
233  fMasterGen->settings.word("SLHA:file", slhafile_);
234 
236  line != fParameters.end(); ++line ) {
237  if (line->find("SLHA:file") != std::string::npos)
238  throw cms::Exception("PythiaError") << "Attempted to set SLHA file name twice, "
239  << "using Pythia8 card SLHA:file and Pythia8Interface card SLHATableForPythia8"
240  << std::endl;
241  }
242  }
243 
244  //add settings for resonance decay filter
245  fMasterGen->settings.addFlag("ResonanceDecayFilter:filter",false);
246  fMasterGen->settings.addFlag("ResonanceDecayFilter:exclusive",false);
247  fMasterGen->settings.addFlag("ResonanceDecayFilter:eMuAsEquivalent",false);
248  fMasterGen->settings.addFlag("ResonanceDecayFilter:eMuTauAsEquivalent",false);
249  fMasterGen->settings.addFlag("ResonanceDecayFilter:allNuAsEquivalent",false);
250  fMasterGen->settings.addFlag("ResonanceDecayFilter:udscAsEquivalent",false);
251  fMasterGen->settings.addFlag("ResonanceDecayFilter:udscbAsEquivalent",false);
252  fMasterGen->settings.addMVec("ResonanceDecayFilter:mothers",std::vector<int>(),false,false,0,0);
253  fMasterGen->settings.addMVec("ResonanceDecayFilter:daughters",std::vector<int>(),false,false,0,0);
254 
255  //add settings for PT filter
256  fMasterGen->settings.addFlag("PTFilter:filter",false);
257  fMasterGen->settings.addMode("PTFilter:quarkToFilter", 5 ,true,true,3, 6);
258  fMasterGen->settings.addParm("PTFilter:scaleToFilter", 0.4,true,true,0.0, 10.);
259  fMasterGen->settings.addParm("PTFilter:quarkRapidity",10.0,true,true,0.0, 10.);
260  fMasterGen->settings.addParm("PTFilter:quarkPt", -.1,true,true,-.1,100.);
261 
262  // Reweight user hook
263  //
264  if( params.exists( "reweightGen" ) )
266  if( params.exists( "reweightGenRap" ) )
267  {
268  edm::LogInfo("Pythia8Interface") << "Start setup for reweightGenRap";
269  edm::ParameterSet rgrParams =
270  params.getParameter<edm::ParameterSet>("reweightGenRap");
272  new RapReweightUserHook(rgrParams.getParameter<std::string>("yLabSigmaFunc"),
273  rgrParams.getParameter<double>("yLabPower"),
274  rgrParams.getParameter<std::string>("yCMSigmaFunc"),
275  rgrParams.getParameter<double>("yCMPower"),
276  rgrParams.getParameter<double>("pTHatMin"),
277  rgrParams.getParameter<double>("pTHatMax"));
278  edm::LogInfo("Pythia8Interface") << "End setup for reweightGenRap";
279  }
280  if( params.exists( "reweightGenPtHatRap" ) )
281  {
282  edm::LogInfo("Pythia8Interface") << "Start setup for reweightGenPtHatRap";
283  edm::ParameterSet rgrParams =
284  params.getParameter<edm::ParameterSet>("reweightGenPtHatRap");
286  new PtHatRapReweightUserHook(rgrParams.getParameter<std::string>("yLabSigmaFunc"),
287  rgrParams.getParameter<double>("yLabPower"),
288  rgrParams.getParameter<std::string>("yCMSigmaFunc"),
289  rgrParams.getParameter<double>("yCMPower"),
290  rgrParams.getParameter<double>("pTHatMin"),
291  rgrParams.getParameter<double>("pTHatMax"));
292  edm::LogInfo("Pythia8Interface") << "End setup for reweightGenPtHatRap";
293  }
294 
295  if( params.exists( "useUserHook" ) )
296  throw edm::Exception(edm::errors::Configuration,"Pythia8Interface")
297  <<" Obsolete parameter: useUserHook \n Please use the actual one instead \n";
298 
299  // PS matching prototype
300  //
301  if ( params.exists("jetMatching") )
302  {
303  edm::ParameterSet jmParams =
304  params.getUntrackedParameter<edm::ParameterSet>("jetMatching");
305  std::string scheme = jmParams.getParameter<std::string>("scheme");
306  if ( scheme == "Madgraph" || scheme == "MadgraphFastJet" )
307  {
308  fJetMatchingHook = new JetMatchingHook( jmParams, &fMasterGen->info );
309  }
310  }
311 
312  // Pythia8Interface emission veto
313  //
314  if ( params.exists("emissionVeto1") )
315  {
316  EV1_nFinal = -1;
317  if(params.exists("EV1_nFinal")) EV1_nFinal = params.getParameter<int>("EV1_nFinal");
318  EV1_vetoOn = true;
319  if(params.exists("EV1_vetoOn")) EV1_vetoOn = params.getParameter<bool>("EV1_vetoOn");
320  EV1_maxVetoCount = 10;
321  if(params.exists("EV1_maxVetoCount")) EV1_maxVetoCount = params.getParameter<int>("EV1_maxVetoCount");
322  EV1_pThardMode = 1;
323  if(params.exists("EV1_pThardMode")) EV1_pThardMode = params.getParameter<int>("EV1_pThardMode");
324  EV1_pTempMode = 0;
325  if(params.exists("EV1_pTempMode")) EV1_pTempMode = params.getParameter<int>("EV1_pTempMode");
326  if(EV1_pTempMode > 2 || EV1_pTempMode < 0)
327  throw edm::Exception(edm::errors::Configuration,"Pythia8Interface")
328  <<" Wrong value for EV1_pTempMode code\n";
329  EV1_emittedMode = 0;
330  if(params.exists("EV1_emittedMode")) EV1_emittedMode = params.getParameter<int>("EV1_emittedMode");
331  EV1_pTdefMode = 1;
332  if(params.exists("EV1_pTdefMode")) EV1_pTdefMode = params.getParameter<int>("EV1_pTdefMode");
333  EV1_MPIvetoOn = false;
334  if(params.exists("EV1_MPIvetoOn")) EV1_MPIvetoOn = params.getParameter<bool>("EV1_MPIvetoOn");
338  }
339 
343  if(fJetMatchingHook) NHooks++;
345  if(NHooks > 1)
346  throw edm::Exception(edm::errors::Configuration,"Pythia8Interface")
347  <<" Too many User Hooks. \n Please choose one from: reweightGen, reweightGenRap, reweightGenPtHatRap, jetMatching, emissionVeto1 \n";
352  if(fEmissionVetoHook1) {
353  edm::LogInfo("Pythia8Interface") << "Turning on Emission Veto Hook 1 from CMSSW Pythia8Interface";
355  }
356 
357 }
358 
359 
361 {
362 // do we need to delete UserHooks/JetMatchingHook here ???
365  if (fMultiUserHook) {
366  delete fMultiUserHook;
367  fMultiUserHook = 0;
368  }
369 
370  //clean up temp file
371  if (!slhafile_.empty()) {
372  std::remove(slhafile_.c_str());
373  }
374 
375 }
376 
378 {
379 
380  bool status = false, status1 = false;
381 
382  if ( fInitialState == PP ) // default
383  {
384  fMasterGen->settings.mode("Beams:idA", 2212);
385  fMasterGen->settings.mode("Beams:idB", 2212);
386  }
387  else if ( fInitialState == PPbar )
388  {
389  fMasterGen->settings.mode("Beams:idA", 2212);
390  fMasterGen->settings.mode("Beams:idB", -2212);
391  }
392  else if ( fInitialState == ElectronPositron )
393  {
394  fMasterGen->settings.mode("Beams:idA", 11);
395  fMasterGen->settings.mode("Beams:idB", -11);
396  }
397  else
398  {
399  // throw on unknown initial state !
400  throw edm::Exception(edm::errors::Configuration,"Pythia8Interface")
401  <<" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron \n";
402  }
403 
404  bool resonanceDecayFilter = fMasterGen->settings.flag("ResonanceDecayFilter:filter");
405  if (resonanceDecayFilter && !fResonanceDecayFilterHook) {
408  }
409 
410  bool PTFilter = fMasterGen->settings.flag("PTFilter:filter");
411  if (PTFilter && !fPTFilterHook) {
414  }
415 
416  if (fMultiUserHook->nHooks()>0) {
417  fMasterGen->setUserHooksPtr(fMultiUserHook);
418  }
419 
420  fMasterGen->settings.parm("Beams:eCM", comEnergy);
421  edm::LogInfo("Pythia8Interface") << "Initializing MasterGen";
422  status = fMasterGen->init();
423 
424  if ( pythiaPylistVerbosity > 10 )
425  {
426  if ( pythiaPylistVerbosity == 11 || pythiaPylistVerbosity == 13 )
427  fMasterGen->settings.listAll();
428  if ( pythiaPylistVerbosity == 12 || pythiaPylistVerbosity == 13 )
429  fMasterGen->particleData.listAll();
430  }
431 
432  // init decayer
433  fDecayer->settings.flag("ProcessLevel:all", false ); // trick
434  fDecayer->settings.flag("ProcessLevel:resonanceDecays", true );
435  edm::LogInfo("Pythia8Interface") << "Initializing Decayer";
436  status1 = fDecayer->init();
437 
438  if (useEvtGen) {
439  edm::LogInfo("Pythia8Interface") << "Creating and initializing pythia8 EvtGen plugin";
440 
441  evtgenDecays = new EvtGenDecays(fMasterGen.get(), evtgenDecFile.c_str(), evtgenPdlFile.c_str());
442  evtgenDecays->readDecayFile("evtgen_userfile.dec");
443  }
444 
445  return (status&&status1);
446 }
447 
448 
450 {
451 
452  edm::LogInfo("Pythia8Interface") << "Initializing for external partons";
453 
454  bool status = false, status1 = false;
455 
456  if((fMasterGen->settings.mode("POWHEG:veto") > 0 || fMasterGen->settings.mode("POWHEG:MPIveto") > 0) && !fEmissionVetoHook) {
457 
459  throw edm::Exception(edm::errors::Configuration,"Pythia8Interface")
460  <<" Attempt to turn on PowhegHooks by pythia8 settings but there are incompatible hooks on \n Incompatible are : jetMatching, emissionVeto1 \n";
461 
462  fEmissionVetoHook = new PowhegHooks();
463 
464  edm::LogInfo("Pythia8Interface") << "Turning on Emission Veto Hook from pythia8 code";
466 
467  }
468 
469  //adapted from main89.cc in pythia8 examples
470  bool internalMatching = fMasterGen->settings.flag("JetMatching:merge");
471  bool internalMerging = !(fMasterGen->settings.word("Merging:Process").compare("void")==0);
472 
473  if (internalMatching && internalMerging) {
474  throw edm::Exception(edm::errors::Configuration,"Pythia8Interface")
475  <<" Only one jet matching/merging scheme can be used at a time. \n";
476  }
477 
478  if (internalMatching && !fJetMatchingPy8InternalHook) {
479  fJetMatchingPy8InternalHook = new Pythia8::JetMatchingMadgraph;
481  }
482 
483  if (internalMerging && !fMergingHook) {
484  int scheme = ( fMasterGen->settings.flag("Merging:doUMEPSTree")
485  || fMasterGen->settings.flag("Merging:doUMEPSSubt")) ?
486  1 :
487  ( ( fMasterGen->settings.flag("Merging:doUNLOPSTree")
488  || fMasterGen->settings.flag("Merging:doUNLOPSSubt")
489  || fMasterGen->settings.flag("Merging:doUNLOPSLoop")
490  || fMasterGen->settings.flag("Merging:doUNLOPSSubtNLO")) ?
491  2 :
492  0 );
493  fMergingHook = new Pythia8::amcnlo_unitarised_interface(scheme);
495  }
496 
497  bool resonanceDecayFilter = fMasterGen->settings.flag("ResonanceDecayFilter:filter");
498  if (resonanceDecayFilter && !fResonanceDecayFilterHook) {
501  }
502 
503  bool PTFilter = fMasterGen->settings.flag("PTFilter:filter");
504  if (PTFilter && !fPTFilterHook) {
507  }
508 
509  if (fMultiUserHook->nHooks()>0) {
510  fMasterGen->setUserHooksPtr(fMultiUserHook);
511  }
512 
513  if(LHEInputFileName != std::string()) {
514 
515  edm::LogInfo("Pythia8Interface") << "Initialize direct pythia8 reading from LHE file "
516  << LHEInputFileName;
517  edm::LogInfo("Pythia8Interface") << "Some LHE information can be not stored";
518  fMasterGen->settings.mode("Beams:frameType", 4);
519  fMasterGen->settings.word("Beams:LHEF", LHEInputFileName);
520  status = fMasterGen->init();
521 
522  } else {
523 
524  lhaUP.reset(new LHAupLesHouches());
525  lhaUP->setScalesFromLHEF(fMasterGen->settings.flag("Beams:setProductionScalesFromLHEF"));
526  lhaUP->loadRunInfo(lheRunInfo());
527 
528  if ( fJetMatchingHook )
529  {
531  }
532 
533  fMasterGen->settings.mode("Beams:frameType", 5);
534  fMasterGen->setLHAupPtr(lhaUP.get());
535  edm::LogInfo("Pythia8Interface") << "Initializing MasterGen";
536  status = fMasterGen->init();
537  }
538 
539  if ( pythiaPylistVerbosity > 10 )
540  {
541  if ( pythiaPylistVerbosity == 11 || pythiaPylistVerbosity == 13 )
542  fMasterGen->settings.listAll();
543  if ( pythiaPylistVerbosity == 12 || pythiaPylistVerbosity == 13 )
544  fMasterGen->particleData.listAll();
545  }
546 
547  // init decayer
548  fDecayer->settings.flag("ProcessLevel:all", false ); // trick
549  fDecayer->settings.flag("ProcessLevel:resonanceDecays", true );
550  edm::LogInfo("Pythia8Interface") << "Initializing Decayer";
551  status1 = fDecayer->init();
552 
553  if (useEvtGen) {
554  edm::LogInfo("Pythia8Interface") << "Creating and initializing pythia8 EvtGen plugin";
555 
556  std::string evtgenpath(getenv("EVTGENDATA"));
557  evtgenDecays = new EvtGenDecays(fMasterGen.get(), evtgenDecFile.c_str(), evtgenPdlFile.c_str());
558  evtgenDecays->readDecayFile("evtgen_userfile.dec");
559  }
560 
561  return (status&&status1);
562 }
563 
564 
566 {
567  fMasterGen->stat();
568 
569  if(fEmissionVetoHook) {
570  edm::LogPrint("Pythia8Interface") << "\n"
571  << "Number of ISR vetoed = " << nISRveto;
572  edm::LogPrint("Pythia8Interface")
573  << "Number of FSR vetoed = " << nFSRveto;
574  }
575 
576  double xsec = fMasterGen->info.sigmaGen(); // cross section in mb
577  xsec *= 1.0e9; // translate to pb (CMS/Gen "convention" as of May 2009)
578  double err = fMasterGen->info.sigmaErr(); // cross section err in mb
579  err *= 1.0e9; // translate to pb (CMS/Gen "convention" as of May 2009)
581 }
582 
583 
585 {
586 
587  if (!fMasterGen->next()) return false;
588 
589  if (evtgenDecays) evtgenDecays->decay();
590 
591  event().reset(new HepMC::GenEvent);
592  return toHepMC.fill_next_event( *(fMasterGen.get()), event().get());
593 
594 }
595 
596 
598 {
599  DJR.resize(0);
600  nME = -1;
601  nMEFiltered = -1;
602  if(LHEInputFileName == std::string()) lhaUP->loadEvent(lheEvent());
603 
604  if ( fJetMatchingHook )
605  {
608  }
609 
610  bool py8next = fMasterGen->next();
611 
612  double mergeweight = fMasterGen.get()->info.mergingWeightNLO();
613  if (fMergingHook) {
614  mergeweight *= fMergingHook->getNormFactor();
615  }
616 
617 
618  //protect against 0-weight from ckkw or similar
619  if (!py8next || std::abs(mergeweight)==0.)
620  {
621  lheEvent()->count( lhef::LHERunInfo::kSelected, 1.0, mergeweight );
622  event().reset();
623  return false;
624  }
625 
627  const std::vector<double> djrmatch = fJetMatchingPy8InternalHook->GetDJR();
628  //cap size of djr vector to save storage space (keep only up to first 6 elements)
629  unsigned int ndjr = std::min(djrmatch.size(), std::vector<double>::size_type(6));
630  for (unsigned int idjr=0; idjr<ndjr; ++idjr) {
631  DJR.push_back(djrmatch[idjr]);
632  }
633 
634  nME=fJetMatchingPy8InternalHook->nMEpartons().first;
635  nMEFiltered=fJetMatchingPy8InternalHook->nMEpartons().second;
636  }
637 
638  // update LHE matching statistics
639  //
640  lheEvent()->count( lhef::LHERunInfo::kAccepted, 1.0, mergeweight );
641 
642  if (evtgenDecays) evtgenDecays->decay();
643 
644  event().reset(new HepMC::GenEvent);
645  bool py8hepmc = toHepMC.fill_next_event( *(fMasterGen.get()), event().get());
646  if (!py8hepmc) {
647  return false;
648  }
649 
650  //add ckkw/umeps/unlops merging weight
651  if (mergeweight!=1.) {
652  event()->weights()[0] *= mergeweight;
653  }
654 
655  if (fEmissionVetoHook) {
656  nISRveto += fEmissionVetoHook->getNISRveto();
657  nFSRveto += fEmissionVetoHook->getNFSRveto();
658  }
659 
660  return true;
661 
662 }
663 
664 
666 {
667 
668  Event* pythiaEvent = &(fMasterGen->event);
669 
670  int NPartsBeforeDecays = pythiaEvent->size();
671  int NPartsAfterDecays = event().get()->particles_size();
672 
673  if(NPartsAfterDecays == NPartsBeforeDecays) return true;
674 
675  bool result = true;
676 
677  for ( int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
678  {
679 
680  HepMC::GenParticle* part = event().get()->barcode_to_particle( ipart );
681 
682  if ( part->status() == 1 && (fDecayer->particleData).canDecay(part->pdg_id()) )
683  {
684  fDecayer->event.reset();
685  Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
686  part->momentum().x(),
687  part->momentum().y(),
688  part->momentum().z(),
689  part->momentum().t(),
690  part->generated_mass() );
691  HepMC::GenVertex* ProdVtx = part->production_vertex();
692  py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
693  ProdVtx->position().z(), ProdVtx->position().t() );
694  py8part.tau( (fDecayer->particleData).tau0( part->pdg_id() ) );
695  fDecayer->event.append( py8part );
696  int nentries = fDecayer->event.size();
697  if ( !fDecayer->event[nentries-1].mayDecay() ) continue;
698  fDecayer->next();
699  int nentries1 = fDecayer->event.size();
700  if ( nentries1 <= nentries ) continue; //same number of particles, no decays...
701 
702  part->set_status(2);
703 
704  result = toHepMC.fill_next_event( *(fDecayer.get()), event().get(), -1, true, part);
705 
706  }
707  }
708 
709  return result;
710 
711 }
712 
713 
715 {
716  bool lhe = lheEvent() != 0;
717 
718  // now create the GenEventInfo product from the GenEvent and fill
719  // the missing pieces
720  eventInfo().reset( new GenEventInfoProduct( event().get() ) );
721 
722  // in pythia pthat is used to subdivide samples into different bins
723  // in LHE mode the binning is done by the external ME generator
724  // which is likely not pthat, so only filling it for Py6 internal mode
725  if (!lhe) {
726  eventInfo()->setBinningValues(std::vector<double>(1, fMasterGen->info.pTHat()));
727  }
728 
729  eventInfo()->setDJR(DJR);
730  eventInfo()->setNMEPartons(nME);
731  eventInfo()->setNMEPartonsFiltered(nMEFiltered);
732 
733  //******** Verbosity ********
734 
735  if (maxEventsToPrint > 0 &&
739  if (pythiaPylistVerbosity) {
740  fMasterGen->info.list(std::cout);
741  fMasterGen->event.list(std::cout);
742  }
743 
744  if (pythiaHepMCVerbosity) {
745  std::cout << "Event process = "
746  << fMasterGen->info.code() << "\n"
747  << "----------------------" << std::endl;
748  event()->print();
749  }
751  std::cout << "Event process = "
752  << fMasterGen->info.code() << "\n"
753  << "----------------------" << std::endl;
754  ascii_io->write_event(event().get());
755  }
756  }
757 }
758 
761 
762 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual bool residualDecay()
ParameterCollector fParameters
double comEnergy
Center-of-Mass energy.
std::auto_ptr< Pythia8::Pythia > fMasterGen
EmissionVetoHook1 * fEmissionVetoHook1
edm::GeneratorFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8GeneratorFilter
bool initializeForInternalPartons() override
UserHooks * fReweightUserHook
void addHook(Pythia8::UserHooks *hook)
Definition: MultiUserHook.h:11
HepMC::IO_AsciiParticles * ascii_io
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void statistics() override
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::string LHEInputFileName
Pythia8::JetMatchingMadgraph * fJetMatchingPy8InternalHook
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
Definition: LHEEvent.cc:207
void setInternalXSec(const XSec &xsec)
uint16_t size_type
PowhegHooks * fEmissionVetoHook
virtual void beforeHadronization(lhef::LHEEvent *lhee)
std::auto_ptr< HepMC::GenEvent > & event()
virtual std::vector< std::string > const & doSharedResources() const override
GenRunInfoProduct & runInfo()
std::auto_ptr< LHAupLesHouches > lhaUP
lhef::LHEEvent * lheEvent()
UserHooks * fReweightPtHatRapUserHook
tuple result
Definition: query.py:137
EvtGenDecays * evtgenDecays
static const std::vector< std::string > p8SharedResources
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned int pythiaPylistVerbosity
const char * classname() const override
T min(T a, T b)
Definition: MathUtil.h:58
PTFilterHook * fPTFilterHook
UserHooks * fReweightRapUserHook
std::auto_ptr< GenEventInfoProduct > & eventInfo()
lhef::LHERunInfo * lheRunInfo()
bool generatePartonsAndHadronize() override
virtual void init(lhef::LHERunInfo *runInfo)
Pythia8::amcnlo_unitarised_interface * fMergingHook
JetMatchingHook * fJetMatchingHook
part
Definition: HCALResponse.h:20
unsigned int maxEventsToPrint
MultiUserHook * fMultiUserHook
std::auto_ptr< Pythia8::Pythia > fDecayer
Pythia8Hadronizer(const edm::ParameterSet &params)
vector< float > DJR
void resetMatchingStatus()
const_iterator end() const
const_iterator begin() const
HepMC::Pythia8ToHepMC toHepMC
tuple cout
Definition: gather_cfg.py:121
ResonanceDecayFilterHook * fResonanceDecayFilterHook
unsigned int nHooks() const
Definition: MultiUserHook.h:10
static const std::string kPythia8
void finalizeEvent() override
tuple status
Definition: ntuplemaker.py:245
virtual void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
edm::HadronizerFilter< Pythia8Hadronizer, ExternalDecayDriver > Pythia8HadronizerFilter