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.
3 
5 
6 using namespace Pythia8;
7 
9 
10 namespace gen {
11 
12 Py8GunBase::Py8GunBase( edm::ParameterSet const& ps )
13  : Py8InterfaceBase(ps)
14 {
15 
17  ps.getUntrackedParameter<double>("filterEfficiency", -1.) );
19  GenRunInfoProduct::XSec(ps.getUntrackedParameter<double>("crossSection", -1.)) );
21  GenRunInfoProduct::XSec(ps.getUntrackedParameter<double>("crossSectionNLO", -1.)) );
22 
23 
24  // PGun specs
25  //
26  edm::ParameterSet pgun_params =
27  ps.getParameter<edm::ParameterSet>("PGunParameters");
28 
29  // although there's the method ParameterSet::empty(),
30  // it looks like it's NOT even necessary to check if it is,
31  // before trying to extract parameters - if it is empty,
32  // the default values seem to be taken
33  //
34  fPartIDs = pgun_params.getParameter< std::vector<int> >("ParticleID");
35  fMinPhi = pgun_params.getParameter<double>("MinPhi"); // ,-3.14159265358979323846);
36  fMaxPhi = pgun_params.getParameter<double>("MaxPhi"); // , 3.14159265358979323846);
37 
38 }
39 
40 // specific to Py8GunHad !!!
41 //
43 {
44 
45  // NO MATTER what was this setting below, override it before init
46  // - this is essencial for the PGun mode
47 
48  // Key requirement: switch off ProcessLevel, and thereby also PartonLevel.
49  fMasterGen->readString("ProcessLevel:all = off");
50  fMasterGen->readString("ProcessLevel::resonanceDecays=on");
51  fMasterGen->init();
52 
53  // init decayer
54  fDecayer->readString("ProcessLevel:all = off"); // Same trick!
55  fDecayer->readString("ProcessLevel::resonanceDecays=on");
56  fDecayer->init();
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  HepMC::Pythia8ToHepMCA toHepMCA;
76  bool result = true;
77 
78  for ( int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
79  {
80 
81  HepMC::GenParticle* part = event().get()->barcode_to_particle( ipart );
82 
83  if ( part->status() == 1 && (fDecayer->particleData).canDecay(part->pdg_id()) )
84  {
85  fDecayer->event.reset();
86  Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
87  part->momentum().x(),
88  part->momentum().y(),
89  part->momentum().z(),
90  part->momentum().t(),
91  part->generated_mass() );
92  HepMC::GenVertex* ProdVtx = part->production_vertex();
93  py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
94  ProdVtx->position().z(), ProdVtx->position().t() );
95  py8part.tau( (fDecayer->particleData).tau0( part->pdg_id() ) );
96  fDecayer->event.append( py8part );
97  int nentries = fDecayer->event.size();
98  if ( !fDecayer->event[nentries-1].mayDecay() ) continue;
99  fDecayer->next();
100  int nentries1 = fDecayer->event.size();
101  if ( nentries1 <= nentries ) continue; //same number of particles, no decays...
102 
103  part->set_status(2);
104 
105  result = toHepMCA.append_event( fDecayer->event, event().get(), part);
106 
107  }
108  }
109 
110  return result;
111 
112 }
113 
115 {
116 
117  //******** Verbosity ********
118 
119  if (maxEventsToPrint > 0 &&
122  {
125  {
126  fMasterGen->info.list(std::cout);
127  fMasterGen->event.list(std::cout);
128  }
129 
131  {
132  std::cout << "Event process = "
133  << fMasterGen->info.code() << "\n"
134  << "----------------------" << std::endl;
135  event()->print();
136  }
138  std::cout << "Event process = "
139  << fMasterGen->info.code() << "\n"
140  << "----------------------" << std::endl;
141  ascii_io->write_event(event().get());
142  }
143  }
144 
145  return;
146 }
147 
149 {
150 
151  fMasterGen->stat();
152 
153  double xsec = fMasterGen->info.sigmaGen(); // cross section in mb
154  xsec *= 1.0e9; // translate to pb (CMS/Gen "convention" as of May 2009)
155  runInfo().setInternalXSec(xsec);
156  return;
157 
158 }
159 
160 }
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:42
void setInternalXSec(const XSec &xsec)
virtual bool residualDecay()
Definition: Py8GunBase.cc:62
void finalizeEvent()
Definition: Py8GunBase.cc:114
tuple result
Definition: query.py:137
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
tuple cout
Definition: gather_cfg.py:121
static const std::string kPythia8
void setExternalXSecNLO(const XSec &xsec)
GenRunInfoProduct & runInfo()
Definition: Py8GunBase.h:68
bool append_event(Pythia8::Event &pyev, GenEvent *evt, GenParticle *rootpart, int ibarcode=-1, Pythia8::Info *pyinfo=0, Pythia8::Settings *pyset=0)
Definition: HepMCA2.h:74
void setExternalXSecLO(const XSec &xsec)