CMS 3D CMS Logo

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