CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LHAupLesHouches.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 
11 
12 
13 using namespace Pythia8;
14 
15 
17 {
18  if (!runInfo) return false;
19  const lhef::HEPRUP &heprup = *runInfo->getHEPRUP();
20 
21  setBeamA(heprup.IDBMUP.first, heprup.EBMUP.first,
22  heprup.PDFGUP.first, heprup.PDFSUP.first);
23  setBeamB(heprup.IDBMUP.second, heprup.EBMUP.second,
24  heprup.PDFGUP.second, heprup.PDFSUP.second);
25  setStrategy(heprup.IDWTUP);
26 
27  for(int i = 0; i < heprup.NPRUP; i++)
28  addProcess(heprup.LPRUP[i], heprup.XSECUP[i],
29  heprup.XERRUP[i], heprup.XMAXUP[i]);
30 
31  //hadronisation->onInit().emit();
32 
33  //runInfo.reset();
34 
35  //fill SLHA header information if available
36  std::vector<std::string> slha = runInfo->findHeader("slha");
37  if (!slha.empty()) {
38  std::string slhaheader;
39  for(std::vector<std::string>::const_iterator iter = slha.begin(); iter != slha.end(); ++iter) {
40  slhaheader.append(*iter);
41  }
42  infoPtr->setHeader("slha",slhaheader);
43  }
44 
45  //work around missing initialization inside pythia8
46  infoPtr->eventAttributes = new std::map<std::string, std::string >;
47 
48 
49  return true;
50 }
51 
52 
53 bool LHAupLesHouches::setEvent(int inProcId, double mRecalculate)
54 {
55  if (!event) return false;
56 
57  if ( event->getReadAttempts() > 0 ) return false; // record already tried
58 
59  const lhef::HEPEUP &hepeup = *event->getHEPEUP();
60 
61  if ( !hepeup.NUP ) return false;
62 
63  setProcess(hepeup.IDPRUP, hepeup.XWGTUP, hepeup.SCALUP,
64  hepeup.AQEDUP, hepeup.AQCDUP);
65 
66  const std::vector<float> &scales = event->scales();
67 
68  bool doRecalculate = (mRecalculate > 0.);
69 
70  unsigned int iscale = 0;
71  for(int i = 0; i < hepeup.NUP; i++) {
72  //retrieve scale corresponding to each particle
73  double scalein = -1.;
74 
75  //handle clustering scales if present,
76  //applies to outgoing partons only
77  if (scales.size()>0 && hepeup.ISTUP[i]==1) {
78  if (iscale>=scales.size()) {
79  edm::LogError("InvalidLHEInput") << "Pythia8 requires"
80  << "cluster scales for all outgoing partons or for none"
81  << std::endl;
82  }
83  scalein = scales[iscale];
84  ++iscale;
85  }
86 
87  double energy = hepeup.PUP[i][3];
88  double mass = hepeup.PUP[i][4];
89 
90  // Optionally recalculate mass from four-momentum.
91  if (doRecalculate && mass > mRecalculate) {
92  mass = sqrtpos( energy*energy - hepeup.PUP[i][0]*hepeup.PUP[i][0] - hepeup.PUP[i][1]*hepeup.PUP[i][1] - hepeup.PUP[i][2]*hepeup.PUP[i][2]);
93  }
94  // If not, recalculate energy from three-momentum and mass.
95  else {
96  energy = sqrt( hepeup.PUP[i][0]*hepeup.PUP[i][0] + hepeup.PUP[i][1]*hepeup.PUP[i][1] + hepeup.PUP[i][2]*hepeup.PUP[i][2] + mass*mass);
97  }
98 
99  addParticle(hepeup.IDUP[i], hepeup.ISTUP[i],
100  hepeup.MOTHUP[i].first, hepeup.MOTHUP[i].second,
101  hepeup.ICOLUP[i].first, hepeup.ICOLUP[i].second,
102  hepeup.PUP[i][0], hepeup.PUP[i][1],
103  hepeup.PUP[i][2], energy,
104  mass, hepeup.VTIMUP[i],
105  hepeup.SPINUP[i],scalein);
106  }
107 
108  infoPtr->eventAttributes->clear();
109 
110  //fill parton multiplicities if available
111  int npLO = event->npLO();
112  int npNLO = event->npNLO();
113 
114  //default value of -99 indicates tags were not present in the original LHE file
115  //don't pass to pythia in this case to emulate pythia internal lhe reader behaviour
116  if (npLO!=-99) {
117  char buffer [100];
118  snprintf( buffer, 100, "%i",npLO);
119  (*infoPtr->eventAttributes)["npLO"] = buffer;
120  }
121  if (npNLO!=-99) {
122  char buffer [100];
123  snprintf( buffer, 100, "%i",npNLO);
124  (*infoPtr->eventAttributes)["npNLO"] = buffer;
125  }
126 
127  const lhef::LHEEvent::PDF *pdf = event->getPDF();
128  if (pdf) {
129  this->setPdf(pdf->id.first, pdf->id.second,
130  pdf->x.first, pdf->x.second,
131  pdf->scalePDF,
132  pdf->xPDF.first, pdf->xPDF.second, true);
133  }
134  else {
135  this->setPdf(hepeup.IDUP[0], hepeup.IDUP[1],
136  hepeup.PUP[0][3] / runInfo->getHEPRUP()->EBMUP.first,
137  hepeup.PUP[1][3] / runInfo->getHEPRUP()->EBMUP.second,
138  0., 0., 0., false);
139  }
140 
141  //hadronisation->onBeforeHadronisation().emit();
142 
143  //event.reset();
144 
145  event->attempted();
146 
147  return true;
148 }
int i
Definition: DBlmapReader.cc:9
std::pair< double, double > EBMUP
Definition: LesHouches.h:78
std::pair< double, double > x
Definition: PdfInfo.h:11
std::vector< double > VTIMUP
Definition: LesHouches.h:254
std::pair< int, int > IDBMUP
Definition: LesHouches.h:73
std::pair< double, double > xPDF
Definition: PdfInfo.h:12
std::pair< int, int > PDFGUP
Definition: LesHouches.h:84
bool setEvent(int idProcIn, double mRecalculate=-1.)
std::vector< std::pair< int, int > > MOTHUP
Definition: LesHouches.h:236
T sqrt(T t)
Definition: SSEVec.h:48
std::vector< FiveVector > PUP
Definition: LesHouches.h:248
std::vector< double > SPINUP
Definition: LesHouches.h:261
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
std::pair< int, int > PDFSUP
Definition: LesHouches.h:90
double AQEDUP
Definition: LesHouches.h:215
std::vector< double > XSECUP
Definition: LesHouches.h:108
double XWGTUP
Definition: LesHouches.h:196
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