CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Pythia8Hadronisation.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <iostream>
3 #include <iterator>
4 #include <sstream>
5 #include <string>
6 #include <memory>
7 #include <assert.h>
8 
9 #include <boost/shared_ptr.hpp>
10 
11 #include <HepMC/GenEvent.h>
12 #include <HepMC/GenParticle.h>
13 
14 #include <Pythia.h>
15 #include <LesHouches.h>
16 #include <HepMCInterface.h>
17 
22 
27 
28 using namespace Pythia8;
29 
30 namespace lhef {
31 
33  public:
36 
37  private:
38  void doInit();
39  std::auto_ptr<HepMC::GenEvent> doHadronisation();
40  void newRunInfo(const boost::shared_ptr<LHERunInfo> &runInfo);
41 
44  std::vector<std::string> paramLines;
45 
47 
48  std::auto_ptr<Pythia> pythia;
49  std::auto_ptr<LHAupLesHouches> lhaUP;
50  std::auto_ptr<HepMC::I_Pythia8> conv;
51 };
52 
54  public:
55  LHAupLesHouches(Hadronisation *hadronisation) :
56  hadronisation(hadronisation) {}
57 
58  void loadRunInfo(const boost::shared_ptr<LHERunInfo> &runInfo)
59  { this->runInfo = runInfo; }
60 
61  void loadEvent(const boost::shared_ptr<LHEEvent> &event)
62  { this->event = event; }
63 
64  private:
65 
66  bool setInit();
67  bool setEvent(int idProcIn);
68 
70  boost::shared_ptr<LHERunInfo> runInfo;
71  boost::shared_ptr<LHEEvent> event;
72 };
73 
74 bool Pythia8Hadronisation::LHAupLesHouches::setInit()
75 {
76  if (!runInfo)
77  return false;
78  const HEPRUP &heprup = *runInfo->getHEPRUP();
79 
80  setBeamA(heprup.IDBMUP.first, heprup.EBMUP.first,
81  heprup.PDFGUP.first, heprup.PDFSUP.first);
82  setBeamB(heprup.IDBMUP.second, heprup.EBMUP.second,
83  heprup.PDFGUP.second, heprup.PDFSUP.second);
84  setStrategy(heprup.IDWTUP);
85 
86  for(int i = 0; i < heprup.NPRUP; i++)
87  addProcess(heprup.LPRUP[i], heprup.XSECUP[i],
88  heprup.XERRUP[i], heprup.XMAXUP[i]);
89 
90  hadronisation->onInit().emit();
91 
92  runInfo.reset();
93  return true;
94 }
95 
96 bool Pythia8Hadronisation::LHAupLesHouches::setEvent(int inProcId)
97 {
98  if (!event)
99  return false;
100  const HEPEUP &hepeup = *event->getHEPEUP();
101 
102  setProcess(hepeup.IDPRUP, hepeup.XWGTUP, hepeup.SCALUP,
103  hepeup.AQEDUP, hepeup.AQCDUP);
104 
105  for(int i = 0; i < hepeup.NUP; i++)
106  addParticle(hepeup.IDUP[i], hepeup.ISTUP[i],
107  hepeup.MOTHUP[i].first, hepeup.MOTHUP[i].second,
108  hepeup.ICOLUP[i].first, hepeup.ICOLUP[i].second,
109  hepeup.PUP[i][0], hepeup.PUP[i][1],
110  hepeup.PUP[i][2], hepeup.PUP[i][3],
111  hepeup.PUP[i][4], hepeup.VTIMUP[i],
112  hepeup.SPINUP[i]);
113 
114  const LHEEvent::PDF *pdf = event->getPDF();
115  if (pdf)
116  this->setPdf(pdf->id.first, pdf->id.second,
117  pdf->x.first, pdf->x.second,
118  pdf->scalePDF,
119  pdf->xPDF.first, pdf->xPDF.second, true);
120 
121  hadronisation->onBeforeHadronisation().emit();
122 
123  event.reset();
124  return true;
125 }
126 
127 Pythia8Hadronisation::Pythia8Hadronisation(const edm::ParameterSet &params) :
128  Hadronisation(params),
129  pythiaPylistVerbosity(params.getUntrackedParameter<int>("pythiaPylistVerbosity", 0)),
130  maxEventsToPrint(params.getUntrackedParameter<int>("maxEventsToPrint", 0))
131 {
132  std::vector<std::string> setNames =
133  params.getParameter<std::vector<std::string> >("parameterSets");
134 
135  for(std::vector<std::string>::const_iterator iter = setNames.begin();
136  iter != setNames.end(); ++iter) {
137  std::vector<std::string> lines =
138  params.getParameter< std::vector<std::string> >(*iter);
139 
140  for(std::vector<std::string>::const_iterator line = lines.begin();
141  line != lines.end(); ++line )
142  if (line->substr(0, 14) == "Random:setSeed" ||
143  line->substr(0, 11) == "Random:seed")
144  throw cms::Exception("PythiaError")
145  << "Attempted to set random number"
146  " using Pythia command 'MRPY(1)'."
147  " Please use the"
148  " RandomNumberGeneratorService."
149  << std::endl;
150 
151  std::copy(lines.begin(), lines.end(),
152  std::back_inserter(paramLines));
153  }
154 }
155 
157 {
158 }
159 
161 {
162  pythia.reset(new Pythia);
163  lhaUP.reset(new LHAupLesHouches(this));
164  conv.reset(new HepMC::I_Pythia8);
165 
166  for(std::vector<std::string>::const_iterator iter = paramLines.begin();
167  iter != paramLines.end(); ++iter)
168  if (!pythia->readString(*iter))
169  throw cms::Exception("PythiaError")
170  << "Pythia did not accept \""
171  << *iter << "\"." << std::endl;
172 
174  std::ostringstream ss;
175  ss << "Random:seed = " << rng->mySeed();
176  pythia->readString(ss.str());
177  pythia->readString("Random:setSeed = on");
178 }
179 
180 // naive Pythia8 HepMC status fixup
181 static int getStatus(const HepMC::GenParticle *p)
182 {
183  int status = p->status();
184  if (status > 0)
185  return status;
186  else if (status > -30 && status < 0)
187  return 3;
188  else
189  return 2;
190 }
191 
192 std::auto_ptr<HepMC::GenEvent> Pythia8Hadronisation::doHadronisation()
193 {
194  lhaUP->loadEvent(getRawEvent());
195  if (!pythia->next())
196  throw cms::Exception("PythiaError")
197  << "Pythia did not want to process event."
198  << std::endl;
199 
200  std::auto_ptr<HepMC::GenEvent> event(new HepMC::GenEvent);
201  conv->fill_next_event(pythia->event, event.get());
202 
203  for(HepMC::GenEvent::particle_iterator iter = event->particles_begin();
204  iter != event->particles_end(); iter++)
205  (*iter)->set_status(getStatus(*iter));
206 
207  event->set_signal_process_id(pythia->info.code());
208  event->set_event_scale(pythia->info.pTHat());
209 
210  if (maxEventsToPrint > 0) {
213  pythia->event.list(std::cout);
214  }
215 
216  return event;
217 }
218 
220  const boost::shared_ptr<LHERunInfo> &runInfo)
221 {
222  lhaUP->loadRunInfo(runInfo);
223  pythia->init(lhaUP.get());
224 }
225 
227 
228 } // namespace lhef
std::vector< std::string > paramLines
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::auto_ptr< Pythia > pythia
std::pair< double, double > EBMUP
Definition: LesHouches.h:78
std::pair< double, double > x
Definition: PdfInfo.h:11
DEFINE_LHE_HADRONISATION_PLUGIN(Pythia8Hadronisation)
void loadRunInfo(const boost::shared_ptr< LHERunInfo > &runInfo)
std::vector< double > VTIMUP
Definition: LesHouches.h:254
std::pair< int, int > IDBMUP
Definition: LesHouches.h:73
void newRunInfo(const boost::shared_ptr< LHERunInfo > &runInfo)
std::auto_ptr< LHAupLesHouches > lhaUP
static int getStatus(const HepMC::GenParticle *p)
std::pair< double, double > xPDF
Definition: PdfInfo.h:12
std::pair< int, int > PDFGUP
Definition: LesHouches.h:84
std::vector< std::pair< int, int > > MOTHUP
Definition: LesHouches.h:236
const boost::shared_ptr< LHEEvent > & getRawEvent() const
Definition: Hadronisation.h:59
void loadEvent(const boost::shared_ptr< LHEEvent > &event)
std::vector< FiveVector > PUP
Definition: LesHouches.h:248
std::vector< double > SPINUP
Definition: LesHouches.h:261
tuple pythiaPylistVerbosity
std::vector< int > ISTUP
Definition: LesHouches.h:230
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::vector< int > IDUP
Definition: LesHouches.h:225
std::vector< double > XERRUP
Definition: LesHouches.h:114
std::pair< int, int > id
Definition: PdfInfo.h:10
std::vector< double > XMAXUP
Definition: LesHouches.h:119
double AQCDUP
Definition: LesHouches.h:220
tuple maxEventsToPrint
std::auto_ptr< HepMC::I_Pythia8 > conv
std::pair< int, int > PDFSUP
Definition: LesHouches.h:90
tuple cout
Definition: gather_cfg.py:121
double AQEDUP
Definition: LesHouches.h:215
std::auto_ptr< HepMC::GenEvent > doHadronisation()
std::vector< double > XSECUP
Definition: LesHouches.h:108
tuple status
Definition: ntuplemaker.py:245
double XWGTUP
Definition: LesHouches.h:196
virtual uint32_t mySeed() const =0
Exists for backward compatibility.
double scalePDF
Definition: PdfInfo.h:13
std::vector< std::pair< int, int > > ICOLUP
Definition: LesHouches.h:242
std::vector< int > LPRUP
Definition: LesHouches.h:124
double SCALUP
Definition: LesHouches.h:210