CMS 3D CMS Logo

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
gen::Py8InterfaceBase::fMasterGen
std::unique_ptr< Pythia8::Pythia > fMasterGen
Definition: Py8InterfaceBase.h:44
mps_fire.i
i
Definition: mps_fire.py:355
gen::Py8GunBase::fMinPhi
double fMinPhi
Definition: Py8GunBase.h:58
MessageLogger.h
gen::Py8GunBase::initializeForInternalPartons
bool initializeForInternalPartons() override
Definition: Py8GunBase.cc:32
gen::Py8InterfaceBase::ascii_io
HepMC::IO_AsciiParticles * ascii_io
Definition: Py8InterfaceBase.h:54
gen::Py8GunBase::statistics
void statistics() override
Definition: Py8GunBase.cc:135
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::LogInfo
Definition: MessageLogger.h:254
GenRunInfoProduct::setInternalXSec
void setInternalXSec(const XSec &xsec)
Definition: GenRunInfoProduct.h:26
gen::Py8GunBase::residualDecay
virtual bool residualDecay()
Definition: Py8GunBase.cc:56
gen::Py8InterfaceBase::evtgenDecays
std::shared_ptr< EvtGenDecays > evtgenDecays
Definition: Py8InterfaceBase.h:59
edm::SharedResourceNames::kPythia8
static const std::string kPythia8
Definition: SharedResourceNames.h:27
part
part
Definition: HCALResponse.h:20
Pythia8
Definition: PythiaDecays.h:21
gen::Py8GunBase::p8SharedResources
static const std::vector< std::string > p8SharedResources
Definition: Py8GunBase.h:62
gen::Py8GunBase::evtGenDecay
void evtGenDecay()
Definition: Py8GunBase.cc:144
gen::Py8InterfaceBase::useEvtGen
bool useEvtGen
Definition: Py8InterfaceBase.h:58
gen::Py8InterfaceBase::pythiaHepMCVerbosityParticles
bool pythiaHepMCVerbosityParticles
Definition: Py8InterfaceBase.h:52
SharedResourceNames.h
gen
Definition: PythiaDecays.h:13
gen::Py8InterfaceBase::evtgenUserFiles
std::vector< std::string > evtgenUserFiles
Definition: Py8InterfaceBase.h:62
gen::Py8InterfaceBase::pythiaPylistVerbosity
unsigned int pythiaPylistVerbosity
Definition: Py8InterfaceBase.h:50
edm::ParameterSet
Definition: ParameterSet.h:36
gen::Py8InterfaceBase::evtgenPdlFile
std::string evtgenPdlFile
Definition: Py8InterfaceBase.h:61
gen::Py8InterfaceBase::maxEventsToPrint
unsigned int maxEventsToPrint
Definition: Py8InterfaceBase.h:53
gen::Py8GunBase::fPartIDs
std::vector< int > fPartIDs
Definition: Py8GunBase.h:57
get
#define get
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
GenParticle.GenParticle
GenParticle
Definition: GenParticle.py:18
gen::BaseHadronizer::event
std::unique_ptr< HepMC::GenEvent > & event()
Definition: BaseHadronizer.h:86
gen::Py8InterfaceBase::pythiaHepMCVerbosity
bool pythiaHepMCVerbosity
Definition: Py8InterfaceBase.h:51
gen::Py8InterfaceBase::toHepMC
HepMC::Pythia8ToHepMC toHepMC
Definition: Py8InterfaceBase.h:46
Particle
Definition: Particle.py:1
mps_fire.result
result
Definition: mps_fire.py:303
gen::Py8GunBase::fMaxPhi
double fMaxPhi
Definition: Py8GunBase.h:59
Py8GunBase.h
gen::BaseHadronizer::runInfo
GenRunInfoProduct & runInfo()
Definition: BaseHadronizer.h:85
gen::Py8InterfaceBase
Definition: Py8InterfaceBase.h:25
gen::Py8InterfaceBase::fDecayer
std::unique_ptr< Pythia8::Pythia > fDecayer
Definition: Py8InterfaceBase.h:45
gen::Py8GunBase::finalizeEvent
void finalizeEvent() override
Definition: Py8GunBase.cc:110
gen::Py8InterfaceBase::evtgenDecFile
std::string evtgenDecFile
Definition: Py8InterfaceBase.h:60