CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
Pythia8Hadronizer Class Reference
Inheritance diagram for Pythia8Hadronizer:
gen::BaseHadronizer

Public Member Functions

const char * classname () const
 
bool decay ()
 
bool declareSpecialSettings (const std::vector< std::string >)
 
bool declareStableParticles (const std::vector< int > &pdgIds)
 
void finalizeEvent ()
 
bool generatePartonsAndHadronize ()
 
bool hadronize ()
 
bool initializeForExternalPartons ()
 
bool initializeForInternalPartons ()
 
 Pythia8Hadronizer (const edm::ParameterSet &params)
 
bool residualDecay ()
 
void statistics ()
 
 ~Pythia8Hadronizer ()
 
- Public Member Functions inherited from gen::BaseHadronizer
 BaseHadronizer (edm::ParameterSet const &ps)
 
edm::EventgetEDMEvent () const
 
HepMC::GenEvent * getGenEvent ()
 
GenEventInfoProductgetGenEventInfo ()
 
GenRunInfoProductgetGenRunInfo ()
 
const boost::shared_ptr
< lhef::LHERunInfo > & 
getLHERunInfo () const
 
void resetEvent (HepMC::GenEvent *event)
 
void resetEventInfo (GenEventInfoProduct *eventInfo)
 
void setEDMEvent (edm::Event &event)
 
void setLHEEvent (lhef::LHEEvent *event)
 
void setLHERunInfo (lhef::LHERunInfo *runInfo)
 
 ~BaseHadronizer ()
 

Private Attributes

double comEnergy
 Center-of-Mass energy. More...
 
std::auto_ptr< LHAupLesHoucheslhaUP
 
string LHEInputFileName
 
unsigned int maxEventsToPrint
 Events to print if verbosity. More...
 
ParameterCollector parameters
 
std::auto_ptr< Pythia > pythia
 
EventpythiaEvent
 
bool pythiaHepMCVerbosity
 HepMC verbosity flag. More...
 
unsigned int pythiaPylistVerbosity
 Pythia PYLIST Verbosity flag. More...
 
HepMC::I_Pythia8 toHepMC
 
bool useUserHook
 Switch User Hook flag. More...
 

Additional Inherited Members

- Protected Member Functions inherited from gen::BaseHadronizer
std::auto_ptr< HepMC::GenEvent > & event ()
 
std::auto_ptr
< GenEventInfoProduct > & 
eventInfo ()
 
lhef::LHEEventlheEvent ()
 
lhef::LHERunInfolheRunInfo ()
 
GenRunInfoProductrunInfo ()
 

Detailed Description

Definition at line 39 of file Pythia8Hadronizer.cc.

Constructor & Destructor Documentation

Pythia8Hadronizer::Pythia8Hadronizer ( const edm::ParameterSet params)

Definition at line 86 of file Pythia8Hadronizer.cc.

References edm::ParameterSet::exists(), gen::getEngineReference(), edm::ParameterSet::getParameter(), randomEngine, and useUserHook.

86  :
87  BaseHadronizer(params),
88  parameters(params.getParameter<edm::ParameterSet>("PythiaParameters")),
89  comEnergy(params.getParameter<double>("comEnergy")),
90  pythiaPylistVerbosity(params.getUntrackedParameter<int>("pythiaPylistVerbosity", 0)),
91  pythiaHepMCVerbosity(params.getUntrackedParameter<bool>("pythiaHepMCVerbosity", false)),
92  maxEventsToPrint(params.getUntrackedParameter<int>("maxEventsToPrint", 0)),
93  LHEInputFileName(params.getUntrackedParameter<string>("LHEInputFileName","")),
94  useUserHook(false)
95 {
96  if( params.exists( "useUserHook" ) )
97  useUserHook = params.getParameter<bool>("useUserHook");
99 }
bool pythiaHepMCVerbosity
HepMC verbosity flag.
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
double comEnergy
Center-of-Mass energy.
BaseHadronizer(edm::ParameterSet const &ps)
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool useUserHook
Switch User Hook flag.
CLHEP::HepRandomEngine & getEngineReference()
CLHEP::HepRandomEngine * randomEngine
Definition: PYR.cc:4
unsigned int pythiaPylistVerbosity
Pythia PYLIST Verbosity flag.
ParameterCollector parameters
unsigned int maxEventsToPrint
Events to print if verbosity.
Pythia8Hadronizer::~Pythia8Hadronizer ( )

Definition at line 101 of file Pythia8Hadronizer.cc.

102 {
103 }

Member Function Documentation

const char* Pythia8Hadronizer::classname ( ) const
inline

Definition at line 58 of file Pythia8Hadronizer.cc.

58 { return "Pythia8Hadronizer"; }
bool Pythia8Hadronizer::decay ( )

Definition at line 287 of file Pythia8Hadronizer.cc.

288 {
289  return true;
290 }
bool Pythia8Hadronizer::declareSpecialSettings ( const std::vector< std::string >  )

Definition at line 240 of file Pythia8Hadronizer.cc.

241 {
242  return true;
243 }
bool Pythia8Hadronizer::declareStableParticles ( const std::vector< int > &  pdgIds)

Definition at line 219 of file Pythia8Hadronizer.cc.

References i, and pythia.

220 {
221 
222  for ( size_t i=0; i<pdgIds.size(); i++ )
223  {
224  // FIXME: need to double check if PID's are the same in Py6 & Py8,
225  // because the HepPDT translation tool is actually for **Py6**
226  //
227  int PyID = HepPID::translatePDTtoPythia( pdgIds[i] );
228  std::ostringstream pyCard ;
229  pyCard << PyID <<":mayDecay=false";
230  pythia->readString( pyCard.str() );
231  // alternative:
232  // set the 2nd input argument warn=false
233  // - this way Py8 will NOT print warnings about unknown particle code(s)
234  // pythia->readString( pyCard.str(), false )
235  }
236 
237  return true;
238 
239 }
int i
Definition: DBlmapReader.cc:9
std::auto_ptr< Pythia > pythia
void Pythia8Hadronizer::finalizeEvent ( )

Definition at line 297 of file Pythia8Hadronizer.cc.

References gather_cfg::cout, gen::BaseHadronizer::event(), gen::BaseHadronizer::eventInfo(), gen::BaseHadronizer::lheEvent(), maxEventsToPrint, pythia, pythiaHepMCVerbosity, and pythiaPylistVerbosity.

298 {
299  bool lhe = lheEvent() != 0;
300 
301  event()->set_signal_process_id(pythia->info.code());
302  event()->set_event_scale(pythia->info.pTHat()); //FIXME
303 
304  int id1 = pythia->info.id1();
305  int id2 = pythia->info.id2();
306  if (id1 == 21) id1 = 0;
307  if (id2 == 21) id2 = 0;
308  double x1 = pythia->info.x1();
309  double x2 = pythia->info.x2();
310  double Q = pythia->info.QRen();
311  double pdf1 = pythia->info.pdf1() / pythia->info.x1();
312  double pdf2 = pythia->info.pdf2() / pythia->info.x2();
313  event()->set_pdf_info(HepMC::PdfInfo(id1,id2,x1,x2,Q,pdf1,pdf2));
314 
315  event()->weights().push_back(pythia->info.weight());
316 
317  // now create the GenEventInfo product from the GenEvent and fill
318  // the missing pieces
319  eventInfo().reset( new GenEventInfoProduct( event().get() ) );
320 
321  // in pythia pthat is used to subdivide samples into different bins
322  // in LHE mode the binning is done by the external ME generator
323  // which is likely not pthat, so only filling it for Py6 internal mode
324  if (!lhe) {
325  eventInfo()->setBinningValues(std::vector<double>(1, pythia->info.pTHat()));
326  }
327 
328  //******** Verbosity ********
329 
330  if (maxEventsToPrint > 0 &&
333  if (pythiaPylistVerbosity) {
334  pythia->info.list(std::cout);
335  pythia->event.list(std::cout);
336  }
337 
338  if (pythiaHepMCVerbosity) {
339  std::cout << "Event process = "
340  << pythia->info.code() << "\n"
341  << "----------------------" << std::endl;
342  event()->print();
343  }
344  }
345 }
bool pythiaHepMCVerbosity
HepMC verbosity flag.
std::auto_ptr< Pythia > pythia
std::auto_ptr< HepMC::GenEvent > & event()
lhef::LHEEvent * lheEvent()
unsigned int pythiaPylistVerbosity
Pythia PYLIST Verbosity flag.
std::auto_ptr< GenEventInfoProduct > & eventInfo()
unsigned int maxEventsToPrint
Events to print if verbosity.
tuple cout
Definition: gather_cfg.py:41
bool Pythia8Hadronizer::generatePartonsAndHadronize ( )

Definition at line 255 of file Pythia8Hadronizer.cc.

References gen::BaseHadronizer::event(), pythia, pythiaEvent, and toHepMC.

256 {
257  if (!pythia->next())
258  return false;
259 
260  event().reset(new HepMC::GenEvent);
261  toHepMC.fill_next_event(*pythiaEvent, event().get());
262 
263  return true;
264 }
std::auto_ptr< Pythia > pythia
std::auto_ptr< HepMC::GenEvent > & event()
HepMC::I_Pythia8 toHepMC
bool Pythia8Hadronizer::hadronize ( )

Definition at line 266 of file Pythia8Hadronizer.cc.

References lhef::LHEEvent::count(), gen::BaseHadronizer::event(), lhef::LHERunInfo::kAccepted, lhaUP, gen::BaseHadronizer::lheEvent(), LHEInputFileName, pythia, pythiaEvent, and toHepMC.

267 {
268  if(LHEInputFileName == string()) {
269  //cout << "start loading event" << endl;
270  lhaUP->loadEvent(lheEvent());
271  //cout << "finish loading event" << endl;
272  }
273 
274  if (!pythia->next())
275  return false;
276 
277  // update LHE matching statistics
278  //
280 
281  event().reset(new HepMC::GenEvent);
282  toHepMC.fill_next_event(*pythiaEvent, event().get());
283 
284  return true;
285 }
std::auto_ptr< Pythia > pythia
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
Definition: LHEEvent.cc:198
std::auto_ptr< HepMC::GenEvent > & event()
std::auto_ptr< LHAupLesHouches > lhaUP
lhef::LHEEvent * lheEvent()
HepMC::I_Pythia8 toHepMC
bool Pythia8Hadronizer::initializeForExternalPartons ( )

Definition at line 151 of file Pythia8Hadronizer.cc.

References gen::ParameterCollector::begin(), gather_cfg::cout, gen::ParameterCollector::end(), lhaUP, LHEInputFileName, gen::BaseHadronizer::lheRunInfo(), geometryCSVtoXML::line, parameters, pythia, pythiaEvent, and pythiaPylistVerbosity.

152 {
153 
154  std::cout << "Initializing for external partons" << std::endl;
155 
156  RandomP8* RP8 = new RandomP8();
157 
158  pythia.reset(new Pythia);
159 
160  pythia->setRndmEnginePtr(RP8);
161 
162  pythiaEvent = &pythia->event;
163 
165  line != parameters.end(); ++line) {
166  if (line->find("Random:") != std::string::npos)
167  throw cms::Exception("PythiaError")
168  << "Attempted to set random number "
169  "using Pythia commands. Please use "
170  "the RandomNumberGeneratorService."
171  << std::endl;
172 
173  if (!pythia->readString(*line))
174  throw cms::Exception("PythiaError")
175  << "Pythia 8 did not accept \""
176  << *line << "\"." << std::endl;
177  }
178 
179  if(pythiaPylistVerbosity > 10) {
181  pythia->settings.listAll();
183  pythia->particleData.listAll();
184  }
185 
186  if(LHEInputFileName != string()) {
187 
188  cout << endl;
189  cout << "LHE Input File Name = " << LHEInputFileName << endl;
190  cout << endl;
191  pythia->init(LHEInputFileName);
192 
193  } else {
194 
195  lhaUP.reset(new LHAupLesHouches());
196  lhaUP->loadRunInfo(lheRunInfo());
197  pythia->init(lhaUP.get());
198 
199  }
200 
201  return true;
202 }
std::auto_ptr< Pythia > pythia
std::auto_ptr< LHAupLesHouches > lhaUP
unsigned int pythiaPylistVerbosity
Pythia PYLIST Verbosity flag.
lhef::LHERunInfo * lheRunInfo()
ParameterCollector parameters
const_iterator end() const
const_iterator begin() const
tuple cout
Definition: gather_cfg.py:41
bool Pythia8Hadronizer::initializeForInternalPartons ( )

Definition at line 105 of file Pythia8Hadronizer.cc.

References gen::ParameterCollector::begin(), comEnergy, gen::ParameterCollector::end(), geometryCSVtoXML::line, parameters, pythia, pythiaEvent, pythiaPylistVerbosity, and useUserHook.

106 {
107  //Old code that used Pythia8 own random engine
108  //edm::Service<edm::RandomNumberGenerator> rng;
109  //uint32_t seed = rng->mySeed();
110  //Pythia8::Rndm::init(seed);
111 
112  RandomP8* RP8 = new RandomP8();
113 
114  pythia.reset(new Pythia);
115 
116  pythia->setRndmEnginePtr(RP8);
117  if(useUserHook) pythia->setUserHooksPtr(new PtHatReweightUserHook());
118 
119  pythiaEvent = &pythia->event;
120 
122  line != parameters.end(); ++line) {
123  if (line->find("Random:") != std::string::npos)
124  throw cms::Exception("PythiaError")
125  << "Attempted to set random number "
126  "using Pythia commands. Please use "
127  "the RandomNumberGeneratorService."
128  << std::endl;
129 
130  if (!pythia->readString(*line))
131  throw cms::Exception("PythiaError")
132  << "Pythia 8 did not accept \""
133  << *line << "\"." << std::endl;
134  }
135 
136  if(pythiaPylistVerbosity > 10) {
138  pythia->settings.listAll();
140  pythia->particleData.listAll();
141  }
142 
143  pythia->init(2212, 2212, comEnergy);
144 
145  pythia->settings.listChanged();
146 
147  return true;
148 }
double comEnergy
Center-of-Mass energy.
std::auto_ptr< Pythia > pythia
bool useUserHook
Switch User Hook flag.
unsigned int pythiaPylistVerbosity
Pythia PYLIST Verbosity flag.
ParameterCollector parameters
const_iterator end() const
const_iterator begin() const
bool Pythia8Hadronizer::residualDecay ( )

Definition at line 292 of file Pythia8Hadronizer.cc.

293 {
294  return true;
295 }
void Pythia8Hadronizer::statistics ( )

Definition at line 246 of file Pythia8Hadronizer.cc.

References pythia, gen::BaseHadronizer::runInfo(), and GenRunInfoProduct::setInternalXSec().

247 {
248  pythia->statistics();
249 
250  double xsec = pythia->info.sigmaGen(); // cross section in mb
251  xsec *= 1.0e9; // translate to pb (CMS/Gen "convention" as of May 2009)
252  runInfo().setInternalXSec(xsec);
253 }
std::auto_ptr< Pythia > pythia
void setInternalXSec(const XSec &xsec)
GenRunInfoProduct & runInfo()

Member Data Documentation

double Pythia8Hadronizer::comEnergy
private

Center-of-Mass energy.

Definition at line 64 of file Pythia8Hadronizer.cc.

Referenced by initializeForInternalPartons().

std::auto_ptr<LHAupLesHouches> Pythia8Hadronizer::lhaUP
private

Definition at line 77 of file Pythia8Hadronizer.cc.

Referenced by hadronize(), and initializeForExternalPartons().

string Pythia8Hadronizer::LHEInputFileName
private

Definition at line 72 of file Pythia8Hadronizer.cc.

Referenced by hadronize(), and initializeForExternalPartons().

unsigned int Pythia8Hadronizer::maxEventsToPrint
private

Events to print if verbosity.

Definition at line 70 of file Pythia8Hadronizer.cc.

Referenced by finalizeEvent().

ParameterCollector Pythia8Hadronizer::parameters
private
std::auto_ptr<Pythia> Pythia8Hadronizer::pythia
private
Event* Pythia8Hadronizer::pythiaEvent
private
bool Pythia8Hadronizer::pythiaHepMCVerbosity
private

HepMC verbosity flag.

Definition at line 68 of file Pythia8Hadronizer.cc.

Referenced by finalizeEvent().

unsigned int Pythia8Hadronizer::pythiaPylistVerbosity
private

Pythia PYLIST Verbosity flag.

Definition at line 66 of file Pythia8Hadronizer.cc.

Referenced by finalizeEvent(), initializeForExternalPartons(), and initializeForInternalPartons().

HepMC::I_Pythia8 Pythia8Hadronizer::toHepMC
private

Definition at line 81 of file Pythia8Hadronizer.cc.

Referenced by generatePartonsAndHadronize(), and hadronize().

bool Pythia8Hadronizer::useUserHook
private

Switch User Hook flag.

Definition at line 75 of file Pythia8Hadronizer.cc.

Referenced by initializeForInternalPartons(), and Pythia8Hadronizer().