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  evtgenDecays->readDecayFile("evtgen_userfile.dec");
65  }
66 
67  return true;
68 
69 }
70 
72 {
73 
74  Event* pythiaEvent = &(fMasterGen->event);
75 
76  int NPartsBeforeDecays = pythiaEvent->size()-1; // do NOT count the very 1st "system" particle
77  // in Pythia8::Event record; it does NOT even
78  // get translated by the HepMCInterface to the
79  // HepMC::GenEvent record !!!
80  int NPartsAfterDecays = event().get()->particles_size();
81 
82  if(NPartsAfterDecays == NPartsBeforeDecays) return true;
83 
84  bool result = true;
85 
86  for ( int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
87  {
88 
89  HepMC::GenParticle* part = event().get()->barcode_to_particle( ipart );
90 
91  if ( part->status() == 1 && (fDecayer->particleData).canDecay(part->pdg_id()) )
92  {
93  fDecayer->event.reset();
94  Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
95  part->momentum().x(),
96  part->momentum().y(),
97  part->momentum().z(),
98  part->momentum().t(),
99  part->generated_mass() );
100  HepMC::GenVertex* ProdVtx = part->production_vertex();
101  py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
102  ProdVtx->position().z(), ProdVtx->position().t() );
103  py8part.tau( (fDecayer->particleData).tau0( part->pdg_id() ) );
104  fDecayer->event.append( py8part );
105  int nentries = fDecayer->event.size();
106  if ( !fDecayer->event[nentries-1].mayDecay() ) continue;
107  fDecayer->next();
108  int nentries1 = fDecayer->event.size();
109  if ( nentries1 <= nentries ) continue; //same number of particles, no decays...
110 
111  part->set_status(2);
112 
113  result = toHepMC.fill_next_event( *(fDecayer.get()), event().get(), -1, true, part);
114 
115  }
116  }
117 
118  return result;
119 
120 }
121 
123 {
124 
125  //******** Verbosity ********
126 
127  if (maxEventsToPrint > 0 &&
130  {
133  {
134  fMasterGen->info.list(std::cout);
135  fMasterGen->event.list(std::cout);
136  }
137 
139  {
140  std::cout << "Event process = "
141  << fMasterGen->info.code() << "\n"
142  << "----------------------" << std::endl;
143  event()->print();
144  }
146  std::cout << "Event process = "
147  << fMasterGen->info.code() << "\n"
148  << "----------------------" << std::endl;
149  ascii_io->write_event(event().get());
150  }
151  }
152 
153  return;
154 }
155 
157 {
158 
159  fMasterGen->stat();
160 
161  double xsec = fMasterGen->info.sigmaGen(); // cross section in mb
162  xsec *= 1.0e9; // translate to pb (CMS/Gen "convention" as of May 2009)
163  runInfo().setInternalXSec(xsec);
164  return;
165 
166 }
167 
168 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
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:71
void finalizeEvent()
Definition: Py8GunBase.cc:122
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:121
static const std::string kPythia8
void setExternalXSecNLO(const XSec &xsec)
GenRunInfoProduct & runInfo()
Definition: Py8GunBase.h:68
void setExternalXSecLO(const XSec &xsec)