CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Py8GunBase.cc
Go to the documentation of this file.
4 
5 // EvtGen plugin
6 //
7 #include "Pythia8Plugins/EvtGen.h"
8 
9 using namespace Pythia8;
10 
12 
13 namespace gen {
14 
15  Py8GunBase::Py8GunBase(edm::ParameterSet const& ps) : Py8InterfaceBase(ps) {
16  // PGun specs
17  //
18  edm::ParameterSet pgun_params = ps.getParameter<edm::ParameterSet>("PGunParameters");
19 
20  // although there's the method ParameterSet::empty(),
21  // it looks like it's NOT even necessary to check if it is,
22  // before trying to extract parameters - if it is empty,
23  // the default values seem to be taken
24  //
25  fPartIDs = pgun_params.getParameter<std::vector<int> >("ParticleID");
26  fMinPhi = pgun_params.getParameter<double>("MinPhi"); // ,-3.14159265358979323846);
27  fMaxPhi = pgun_params.getParameter<double>("MaxPhi"); // , 3.14159265358979323846);
28  }
29 
30  // specific to Py8GunHad !!!
31  //
33  // NO MATTER what was this setting below, override it before init
34  // - this is essencial for the PGun mode
35 
36  // Key requirement: switch off ProcessLevel, and thereby also PartonLevel.
37  fMasterGen->readString("ProcessLevel:all = off");
38  fMasterGen->readString("ProcessLevel::resonanceDecays=on");
39  fMasterGen->init();
40 
41  // init decayer
42  fDecayer->readString("ProcessLevel:all = off"); // Same trick!
43  fDecayer->readString("ProcessLevel::resonanceDecays=on");
44  fDecayer->init();
45 
46  if (useEvtGen) {
47  edm::LogInfo("Pythia8Interface") << "Creating and initializing pythia8 EvtGen plugin";
48  evtgenDecays.reset(new EvtGenDecays(fMasterGen.get(), evtgenDecFile, evtgenPdlFile));
49  for (unsigned int i = 0; i < evtgenUserFiles.size(); i++)
50  evtgenDecays->readDecayFile(evtgenUserFiles.at(i));
51  }
52 
53  return true;
54  }
55 
57  Event* pythiaEvent = &(fMasterGen->event);
58 
59  int NPartsBeforeDecays = pythiaEvent->size() - 1; // do NOT count the very 1st "system" particle
60  // in Pythia8::Event record; it does NOT even
61  // get translated by the HepMCInterface to the
62  // HepMC::GenEvent record !!!
63  int NPartsAfterDecays = event().get()->particles_size();
64 
65  if (NPartsAfterDecays == NPartsBeforeDecays)
66  return true;
67 
68  bool result = true;
69 
70  for (int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
71  HepMC::GenParticle* part = event().get()->barcode_to_particle(ipart);
72 
73  if (part->status() == 1 && (fDecayer->particleData).canDecay(part->pdg_id())) {
74  fDecayer->event.reset();
75  Particle py8part(part->pdg_id(),
76  93,
77  0,
78  0,
79  0,
80  0,
81  0,
82  0,
83  part->momentum().x(),
84  part->momentum().y(),
85  part->momentum().z(),
86  part->momentum().t(),
87  part->generated_mass());
88  HepMC::GenVertex* ProdVtx = part->production_vertex();
89  py8part.vProd(
90  ProdVtx->position().x(), ProdVtx->position().y(), ProdVtx->position().z(), ProdVtx->position().t());
91  py8part.tau((fDecayer->particleData).tau0(part->pdg_id()));
92  fDecayer->event.append(py8part);
93  int nentries = fDecayer->event.size();
94  if (!fDecayer->event[nentries - 1].mayDecay())
95  continue;
96  fDecayer->next();
97  int nentries1 = fDecayer->event.size();
98  if (nentries1 <= nentries)
99  continue; //same number of particles, no decays...
100 
101  part->set_status(2);
102 
103  result = toHepMC.fill_next_event(*(fDecayer.get()), event().get(), -1, true, part);
104  }
105  }
106 
107  return result;
108  }
109 
111  //******** Verbosity ********
112 
115  if (pythiaPylistVerbosity) {
116  fMasterGen->info.list();
117  fMasterGen->event.list();
118  }
119 
120  if (pythiaHepMCVerbosity) {
121  std::cout << "Event process = " << fMasterGen->info.code() << "\n"
122  << "----------------------" << std::endl;
123  event()->print();
124  }
126  std::cout << "Event process = " << fMasterGen->info.code() << "\n"
127  << "----------------------" << std::endl;
128  ascii_io->write_event(event().get());
129  }
130  }
131 
132  return;
133  }
134 
136  fMasterGen->stat();
137 
138  double xsec = fMasterGen->info.sigmaGen(); // cross section in mb
139  xsec *= 1.0e9; // translate to pb (CMS/Gen "convention" as of May 2009)
140  runInfo().setInternalXSec(xsec);
141  return;
142  }
143 
145  if (evtgenDecays.get())
146  evtgenDecays->decay();
147  }
148 
149 } // namespace gen
void finalizeEvent() override
Definition: Py8GunBase.cc:110
std::shared_ptr< Pythia8::EvtGenDecays > evtgenDecays
std::unique_ptr< Pythia8::Pythia > fDecayer
HepMC::IO_AsciiParticles * ascii_io
double fMinPhi
Definition: Py8GunBase.h:58
bool initializeForInternalPartons() override
Definition: Py8GunBase.cc:32
void statistics() override
Definition: Py8GunBase.cc:135
void setInternalXSec(const XSec &xsec)
virtual bool residualDecay()
Definition: Py8GunBase.cc:56
std::vector< std::string > evtgenUserFiles
tuple result
Definition: mps_fire.py:311
GenRunInfoProduct & runInfo()
void evtGenDecay()
Definition: Py8GunBase.cc:144
static const std::vector< std::string > p8SharedResources
Definition: Py8GunBase.h:62
unsigned int pythiaPylistVerbosity
std::unique_ptr< HepMC::GenEvent > & event()
std::vector< int > fPartIDs
Definition: Py8GunBase.h:57
Log< level::Info, false > LogInfo
part
Definition: HCALResponse.h:20
unsigned int maxEventsToPrint
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double fMaxPhi
Definition: Py8GunBase.h:59
HepMC::Pythia8ToHepMC toHepMC
tuple cout
Definition: gather_cfg.py:144
std::unique_ptr< Pythia8::Pythia > fMasterGen
static const std::string kPythia8