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