29#define M_PI 3.14159265358979323846264338327950288
79 os <<
" " << oa.
name <<
"=\"" << oa.
val <<
"\"";
94 typedef std::string::size_type
pos_t;
115 for (
int i = 0, N =
tags.size(); i < N; ++i )
delete tags[i];
142 bool getattr(
const std::string & n,
double & v)
const {
143 AttributeMap::const_iterator it =
attr.find(n);
144 if ( it ==
attr.end() )
return false;
145 v = std::atof(it->second.c_str());
154 bool getattr(
const std::string & n,
bool & v)
const {
155 AttributeMap::const_iterator it =
attr.find(n);
156 if ( it ==
attr.end() )
return false;
157 if ( it->second ==
"yes" ) v =
true;
165 bool getattr(
const std::string & n,
long & v)
const {
166 AttributeMap::const_iterator it =
attr.find(n);
167 if ( it ==
attr.end() )
return false;
168 v = std::atoi(it->second.c_str());
176 bool getattr(
const std::string & n,
int & v)
const {
177 AttributeMap::const_iterator it =
attr.find(n);
178 if ( it ==
attr.end() )
return false;
179 v = int(std::atoi(it->second.c_str()));
187 bool getattr(
const std::string &n, std::string & v)
const {
188 AttributeMap::const_iterator it =
attr.find(n);
189 if ( it ==
attr.end() )
return false;
201 std::string * leftover =
nullptr) {
202 std::vector<XMLTag*>
tags;
205 while ( curr !=
end ) {
208 pos_t begin = str.find(
"<", curr);
211 if ( begin !=
end && str.find(
"<!--", curr) == begin ) {
212 pos_t endcom = str.find(
"-->", begin);
214 if ( endcom ==
end ) {
215 tags.back()->contents = str.substr(curr);
216 if ( leftover ) *leftover += str.substr(curr);
219 tags.back()->contents = str.substr(curr, endcom - curr);
220 if ( leftover ) *leftover += str.substr(curr, endcom - curr);
226 if ( begin !=
end && str.find(
"<![CDATA[", curr) == begin ) {
227 pos_t endcom = str.find(
"]]>", begin);
229 if ( endcom ==
end ) {
230 tags.back()->contents = str.substr(curr);
231 if ( leftover ) *leftover += str.substr(curr);
234 tags.back()->contents = str.substr(curr, endcom - curr);
235 if ( leftover ) *leftover += str.substr(curr, endcom - curr);
240 if ( begin != curr ) {
242 tags.back()->contents = str.substr(curr, begin - curr);
243 if ( leftover ) *leftover += str.substr(curr, begin - curr);
245 if ( begin ==
end || begin > str.length() - 3 || str[begin + 1] ==
'/' )
248 pos_t close = str.find(
">", curr);
249 if ( close ==
end )
return tags;
252 curr = str.find_first_of(
" \t\n/>", begin);
254 tags.back()->name = str.substr(begin + 1, curr - begin - 1);
259 curr = str.find_first_not_of(
" \t\n", curr);
260 if ( curr ==
end || curr >= close )
break;
262 pos_t tend = str.find_first_of(
"= \t\n", curr);
263 if ( tend ==
end || tend >= close )
break;
265 std::string namex = str.substr(curr, tend - curr);
266 curr = str.find(
"=", curr) + 1;
269 curr = str.find_first_of(
"\"'", curr);
270 if ( curr ==
end || curr >= close )
break;
271 char quote = str[curr];
273 curr = str.find(quote, curr);
274 while ( curr !=
end && str[curr - 1] ==
'\\' )
275 curr = str.find(quote, curr + 1);
277 std::string value = str.substr(bega, curr ==
end?
end: curr - bega);
279 tags.back()->attr[namex] = value;
286 if ( str[close - 1] ==
'/' )
continue;
288 pos_t endtag = str.find(
"</" +
tags.back()->name +
">", curr);
289 if ( endtag ==
end ) {
290 tags.back()->contents = str.substr(curr);
293 tags.back()->contents = str.substr(curr, endtag - curr);
294 curr = endtag +
tags.back()->name.length() + 3;
297 std::string leftovers;
299 if ( leftovers.find_first_not_of(
" \t\n") ==
end ) leftovers=
"";
300 tags.back()->contents = leftovers;
311 while (
tags.size() &&
tags.back() ) {
319 void print(std::ostream & os)
const {
320 if (
name.empty() ) {
325 for ( AttributeMap::const_iterator it =
attr.begin();
326 it !=
attr.end(); ++it )
327 os <<
oattr(it->first, it->second);
329 os <<
"/>" << std::endl;
333 for (
int i = 0, N =
tags.size(); i < N; ++i )
347 std::istringstream is(s);
349 while ( getline(is, ss) ) {
350 if ( ss.empty() )
continue;
351 if ( ss.find_first_not_of(
" \t") == std::string::npos )
continue;
352 if ( ss.find(
'#') == std::string::npos ||
353 ss.find(
'#') != ss.find_first_not_of(
" \t") ) ss =
"# " + ss;
386 bool getattr(
const std::string & n,
double & v,
bool erase =
true) {
387 AttributeMap::iterator it =
attributes.find(n);
389 v = std::atof(it->second.c_str());
400 bool getattr(
const std::string & n,
bool & v,
bool erase =
true) {
401 AttributeMap::iterator it =
attributes.find(n);
403 if ( it->second ==
"yes" ) v =
true;
414 bool getattr(
const std::string & n,
long & v,
bool erase =
true) {
415 AttributeMap::iterator it =
attributes.find(n);
417 v = std::atoi(it->second.c_str());
428 bool getattr(
const std::string & n,
int & v,
bool erase =
true) {
429 AttributeMap::iterator it =
attributes.find(n);
431 v = int(std::atoi(it->second.c_str()));
442 bool getattr(
const std::string & n, std::string & v,
bool erase =
true) {
443 AttributeMap::iterator it =
attributes.find(n);
454 for ( AttributeMap::const_iterator it =
attributes.begin();
456 file <<
oattr(it->first, it->second);
463 void closetag(std::ostream & file,
const std::string & tag)
const {
466 else if (
contents.find(
'\n') != std::string::npos )
467 file <<
">\n" <<
contents <<
"\n</" << tag <<
">\n";
469 file <<
">" <<
contents <<
"</" << tag <<
">\n";
485 static std::string
yes() {
return "yes"; }
506 void print(std::ostream & file)
const {
507 file <<
"<generator";
545 throw std::runtime_error(
"Found xsecinfo tag without neve attribute "
546 "in Les Houches Event File.");
550 throw std::runtime_error(
"Found xsecinfo tag without totxsec "
551 "attribute in Les Houches Event File.");
564 void print(std::ostream & file)
const {
565 file <<
"<xsecinfo" <<
oattr(
"neve",
neve)
648 throw std::runtime_error(
"Found eventfile tag without name attribute "
649 "in Les Houches Event File.");
658 void print(std::ostream & file)
const {
693 max(0.99*std::numeric_limits<double>::
max()) {}
699 const std::map<std::string,std::set<long> >& ptypes)
701 min(-0.99*std::numeric_limits<double>::
max()),
702 max(0.99*std::numeric_limits<double>::
max()) {
704 throw std::runtime_error(
"Found cut tag without type attribute "
705 "in Les Houches file");
708 if ( ptypes.find(np1) != ptypes.end() ) {
709 p1 = ptypes.find(np1)->second;
710 attributes.erase(
"p1");
717 if ( tag.getattr(
"p2",
np2) ) {
718 if ( ptypes.find(np2) != ptypes.end() ) {
719 p2 = ptypes.find(np2)->second;
720 attributes.erase(
"p2");
728 std::istringstream iss(tag.contents);
732 min = -0.99*std::numeric_limits<double>::max();
734 max = 0.99*std::numeric_limits<double>::max();
740 void print(std::ostream & file)
const {
745 if (
p1.size() == 1 ) file <<
oattr(
"p1", *
p1.begin());
749 if (
p2.size() == 1 ) file <<
oattr(
"p2", *
p2.begin());
753 if (
min > -0.9*std::numeric_limits<double>::max() )
757 if (
max < 0.9*std::numeric_limits<double>::max() )
760 file <<
"</cut>" << std::endl;
767 bool match(
long id1,
long id2 = 0)
const {
768 std::pair<bool,bool> ret(
false,
false);
769 if ( !id2 ) ret.second =
true;
770 if ( !id1 ) ret.first =
true;
771 if (
p1.find(0) !=
p1.end() ) ret.first =
true;
772 if (
p1.find(id1) !=
p1.end() ) ret.first =
true;
773 if (
p2.find(0) !=
p2.end() ) ret.second =
true;
774 if (
p2.find(id2) !=
p2.end() ) ret.second =
true;
775 return ret.first && ret.second;
784 const std::vector< std::vector<double> >& p )
const {
785 if ( (
type ==
"m" && !
p2.size() ) ||
type ==
"kt" ||
type ==
"eta" ||
787 for (
int i = 0, N =
id.size(); i < N; ++i )
788 if (
match(
id[i]) ) {
790 double v = p[i][4]*p[i][4] - p[i][3]*p[i][3] - p[i][2]*p[i][2]
792 v = v >= 0.0? std::sqrt(v): -std::sqrt(-v);
793 if (
outside(v) )
return false;
795 else if (
type ==
"kt" ) {
796 if (
outside(std::sqrt(p[i][2]*p[i][2] + p[i][1]*p[i][1])) )
799 else if (
type ==
"E" ) {
800 if (
outside(p[i][4]) )
return false;
802 else if (
type ==
"eta" ) {
805 else if (
type ==
"y" ) {
810 else if (
type ==
"m" ||
type ==
"deltaR" ) {
811 for (
int i = 1, N =
id.size(); i < N; ++i )
812 for (
int j = 0; j < i; ++j )
813 if (
match(
id[i],
id[j]) ||
match(
id[j],
id[i]) ) {
815 double v = (p[i][4] + p[j][4])*(p[i][4] + p[j][4])
816 - (p[i][3] + p[j][3])*(p[i][3] + p[j][3])
817 - (p[i][2] + p[j][2])*(p[i][2] + p[j][2])
818 - (p[i][1] + p[j][1])*(p[i][1] + p[j][1]);
819 v = v >= 0.0? std::sqrt(v): -std::sqrt(-v);
820 if (
outside(v) )
return false;
822 else if (
type ==
"deltaR" ) {
827 else if (
type ==
"ETmiss" ) {
830 for (
int i = 0, N =
id.size(); i < N; ++i )
835 if (
outside(std::sqrt(x*x + y*y)) )
return false;
837 else if (
type ==
"HT" ) {
839 for (
int i = 0, N =
id.size(); i < N; ++i )
841 pt += std::sqrt(p[i][1]*p[i][1] + p[i][2]*p[i][2]);
842 if (
outside(pt) )
return false;
850 static double eta(
const std::vector<double> & p) {
851 double pt2 = p[2]*p[2] + p[1]*p[1];
853 double dum = std::sqrt(pt2 + p[3]*p[3]) + p[3];
855 return std::log(dum/std::sqrt(pt2));
857 return p[3] < 0.0? -std::numeric_limits<double>::max():
858 std::numeric_limits<double>::max();
864 static double rap(
const std::vector<double> & p) {
865 double pt2 = p[5]*p[5] + p[2]*p[2] + p[1]*p[1];
867 double dum = std::sqrt(pt2 + p[3]*p[3]) + p[3];
869 return std::log(dum/std::sqrt(pt2));
871 return p[3] < 0.0? -std::numeric_limits<double>::max():
872 std::numeric_limits<double>::max();
878 static double deltaR(
const std::vector<double> &
p1,
879 const std::vector<double> &
p2) {
881 double dphi = std::atan2(
p1[1],
p1[2]) - std::atan2(
p2[1],
p2[2]);
882 if ( dphi >
M_PI ) dphi -= 2.0*
M_PI;
883 if ( dphi < -
M_PI ) dphi += 2.0*
M_PI;
884 return std::sqrt(dphi*dphi + deta*deta);
891 return value < min || value >=
max;
958 void print(std::ostream & file)
const {
1032 file <<
"<mergeinfo" <<
oattr(
"iproc",
iproc);
1093 file <<
"<weightinfo" <<
oattr(
"name",
name);
1161 for (
int i = 0, N = tag.
tags.size(); i < N; ++i ) {
1162 if ( tag.
tags[i]->name ==
"weight" ||
1163 tag.
tags[i]->name ==
"weightinfo" ) {
1206 std::istringstream iss(tag.
contents);
1208 while ( iss >> w )
weights.push_back(w);
1225 for (
int j = 0, M =
weights.size(); j < M; ++j ) file <<
" " <<
weights[j];
1227 file <<
"</wgt>" << std::endl;
1229 file <<
"</weight>" << std::endl;
1282 std::istringstream iss(tag.
contents);
1284 if ( !( iss >>
p0 ) )
p0 =
p1;
1294 file <<
">" <<
p1 <<
" " <<
p2;
1295 if (
p1 !=
p0 ) file <<
" " <<
p0;
1296 file <<
"</clus>" << std::endl;
1336 Scale(std::string st =
"veto",
int emtr = 0,
double sc = 0.0)
1345 throw std::runtime_error(
"Found scale tag without stype attribute "
1346 "in Les Houches Event File.");
1348 if (
getattr(
"pos", pattr) ) {
1349 std::istringstream pis(pattr);
1353 while ( pis >> rec )
recoilers.insert(rec);
1358 if (
getattr(
"etype", eattr) ) {
1359 if ( eattr ==
"QCD" ) eattr =
"-5 -4 -3 -2 -1 1 2 3 4 5 21";
1360 if ( eattr ==
"EW" ) eattr =
"-13 -12 -11 11 12 13 22 23 24";
1361 std::istringstream eis(eattr);
1363 while ( eis >> pdg )
emitted.insert(pdg);
1365 std::istringstream cis(tag.
contents);
1376 std::ostringstream pos;
1378 for ( std::set<int>::iterator it =
recoilers.begin();
1381 file <<
oattr(
"pos", pos.str());
1384 std::set<int>::iterator it =
emitted.begin();
1385 std::ostringstream eos;
1387 while ( ++it !=
emitted.end() ) eos <<
" " << *it;
1388 if ( eos.str() ==
"-5 -4 -3 -2 -1 1 2 3 4 5 21" )
1389 file <<
oattr(
"etype", std::string(
"QCD"));
1390 else if ( eos.str() ==
"-13 -12 -11 11 12 13 22 23 24" )
1391 file <<
oattr(
"etype", std::string(
"EW"));
1393 file <<
oattr(
"etype", eos.str());
1395 std::ostringstream os;
1439 Scales(
double defscale = -1.0,
int npart = 0)
1449 muf(defscale),
mur(defscale),
mups(defscale),
1454 for (
int i = 0, N = tag.
tags.size(); i < N; ++i )
1455 if ( tag.
tags[i]->name ==
"scale" )
1457 for (
int i = 0; i < npart; ++i ) {
1458 std::ostringstream pttag;
1459 pttag <<
"pt_start_" << i + 1;
1461 if (
getattr(pttag.str(), sc) )
1487 std::ostringstream os;
1488 for (
int i = 0, N =
scales.size(); i < N; ++i )
1507 double getScale(std::string st,
int pdgem,
int emr,
int rec)
const {
1508 for (
int i = 0, N =
scales.size(); i < N; ++i ) {
1509 if (
scales[i].emitter == emr && st ==
scales[i].stype &&
1511 scales[i].recoilers.find(rec) !=
scales[i].recoilers.end() ) &&
1512 scales[i].emitted.find(pdgem) !=
scales[i].emitted.end() )
1515 for (
int i = 0, N =
scales.size(); i < N; ++i ) {
1516 if (
scales[i].emitter == emr && st ==
scales[i].stype &&
1518 scales[i].recoilers.find(rec) !=
scales[i].recoilers.end() ) &&
1519 scales[i].emitted.empty() )
1522 if ( emr != rec )
return getScale(st, pdgem, emr, emr);
1523 if ( emr == rec )
return getScale(st, pdgem, 0, 0);
1585 if (
xf1 <= 0 )
return;
1593 file <<
">" <<
xf1 <<
" " <<
xf2 <<
"</pdfinfo>" << std::endl;
1657 dprec(std::numeric_limits<double>::digits10) {}
1674 dprec(std::numeric_limits<double>::digits10) {
1676 std::vector<XMLTag*> tags = tagin.
tags;
1679 std::istringstream iss(tags[0]->
contents);
1683 throw std::runtime_error(
"Could not parse init block "
1684 "in Les Houches Event File.");
1688 for (
int i = 0; i <
NPRUP; ++i ) {
1690 throw std::runtime_error(
"Could not parse processes in init block "
1691 "in Les Houches Event File.");
1695 for (
int i = 1, N = tags.size(); i < N; ++i ) {
1696 const XMLTag & tag = *tags[i];
1700 if ( tag.
name ==
"initrwgt" ) {
1701 for (
int j = 0, M = tag.
tags.size(); j < M; ++j ) {
1702 if ( tag.
tags[j]->name ==
"weightgroup" )
1705 if ( tag.
tags[j]->name ==
"weight" )
1710 if ( tag.
name ==
"weightinfo" ) {
1713 if ( tag.
name ==
"weightgroup" ) {
1717 if ( tag.
name ==
"eventfiles" ) {
1718 for (
int j = 0, M = tag.
tags.size(); j < M; ++j ) {
1720 if ( eftag.
name ==
"eventfile" )
1724 if ( tag.
name ==
"xsecinfo" ) {
1728 if ( tag.
name ==
"generator" ) {
1731 else if ( tag.
name ==
"cutsinfo" ) {
1732 for (
int j = 0, M = tag.
tags.size(); j < M; ++j ) {
1735 if ( ctag.
name ==
"ptype" ) {
1736 std::string tname = ctag.
attr[
"name"];
1738 std::istringstream isss(ctag.
contents);
1739 while ( isss >>
id )
ptypes[tname].insert(
id);
1741 else if ( ctag.
name ==
"cut" )
1745 else if ( tag.
name ==
"procinfo" ) {
1749 else if ( tag.
name ==
"mergeinfo" ) {
1757 for (
int i = 0, N =
weightinfo.size(); i < N; ++i )
1772 if ( i < 0 || i >=
static_cast<int>(
weightinfo.size()) )
return name;
1786 file << std::setprecision(
dprec);
1789 <<
" " << std::setw(8) <<
IDBMUP.first
1790 <<
" " << std::setw(8) <<
IDBMUP.second
1791 <<
" " << std::setw(14) <<
EBMUP.first
1792 <<
" " << std::setw(14) <<
EBMUP.second
1793 <<
" " << std::setw(4) <<
PDFGUP.first
1794 <<
" " << std::setw(4) <<
PDFGUP.second
1795 <<
" " << std::setw(4) <<
PDFSUP.first
1796 <<
" " << std::setw(4) <<
PDFSUP.second
1797 <<
" " << std::setw(4) <<
IDWTUP
1798 <<
" " << std::setw(4) <<
NPRUP << std::endl;
1800 for (
int i = 0; i <
NPRUP; ++i )
1801 file <<
" " << std::setw(14) <<
XSECUP[i]
1802 <<
" " << std::setw(14) <<
XERRUP[i]
1803 <<
" " << std::setw(14) <<
XMAXUP[i]
1804 <<
" " << std::setw(6) <<
LPRUP[i] << std::endl;
1806 for (
int i = 0, N =
generators.size(); i < N; ++i )
1810 file <<
"<eventfiles>\n";
1811 for (
int i = 0, N =
eventfiles.size(); i < N; ++i )
1813 file <<
"</eventfiles>\n";
1817 for ( XSecInfos::const_iterator it =
xsecinfos.begin();
1819 if ( it->second.neve > 0 ) it->second.print(file);
1821 if (
cuts.size() > 0 ) {
1822 file <<
"<cutsinfo>" << std::endl;
1824 for ( std::map<std::string, std::set<long> >::const_iterator ptit =
1826 file <<
"<ptype" <<
oattr(
"name", ptit->first) <<
">";
1827 for ( std::set<long>::const_iterator it = ptit->second.begin();
1828 it != ptit->second.end(); ++it )
1830 file <<
"</ptype>" << std::endl;
1833 for (
int i = 0, N =
cuts.size(); i < N; ++i )
1834 cuts[i].print(file);
1835 file <<
"</cutsinfo>" << std::endl;
1838 for ( std::map<long,ProcInfo>::const_iterator it =
procinfo.begin();
1840 it->second.print(file);
1842 for ( std::map<long,MergeInfo>::const_iterator it =
mergeinfo.begin();
1844 it->second.print(file);
1846 bool isrwgt =
false;
1848 for (
int i = 0, N =
weightinfo.size(); i < N; ++i ) {
1850 if ( !isrwgt ) file <<
"<initrwgt>\n";
1853 if ( isrwgt ) file <<
"</initrwgt>\n";
1857 if ( group != ingroup ) {
1858 if ( ingroup != -1 ) file <<
"</weightgroup>\n";
1859 if ( group != -1 ) {
1860 file <<
"<weightgroup"
1870 if ( ingroup != -1 ) file <<
"</weightgroup>\n";
1871 if ( isrwgt ) file <<
"</initrwgt>\n";
1917 std::map<std::string, int>::const_iterator it =
weightmap.find(name);
1918 if ( it !=
weightmap.end() )
return it->second;
1946 XSecInfos::const_iterator it =
xsecinfos.find(weightname);
1947 if ( it !=
xsecinfos.end() )
return it->second;
2029 std::map<std::string, std::set<long> >
ptypes;
2108 inline void clear();
2195 if ( &x ==
this )
return *
this;
2196 TagBase::operator=(x);
2224 throw std::runtime_error(
"Tried to read events but no processes defined "
2225 "in init block of Les Houches file.");
2227 std::vector<XMLTag*> tags = tagin.
tags;
2232 for (
int i = 0, N = tags.size(); i < N; ++i )
2233 if ( tags[i]->name ==
"event" )
2242 std::istringstream iss(tags[0]->
contents);
2244 throw std::runtime_error(
"Failed to parse event in Les Houches file.");
2249 for (
int i = 0; i <
NUP; ++i ) {
2253 >>
PUP[i][3] >>
PUP[i][4]
2255 throw std::runtime_error(
"Failed to parse event in Les Houches file.");
2260 while ( getline(iss, ss) )
junk += ss +
'\n';
2267 std::make_pair(
XWGTUP,
nullptr));
2269 for (
int i = 1, N =
weights.size(); i < N; ++i )
2272 for (
int i = 1, N = tags.size(); i < N; ++i ) {
2277 if ( tag.
name ==
"weights" ) {
2279 std::make_pair(
XWGTUP,
nullptr));
2281 for (
int ii = 1, NN =
weights.size(); ii < NN; ++ii )
2285 std::istringstream isss(tag.
contents);
2287 if ( ++iii <
int(
weights.size()) )
2290 weights.push_back(std::make_pair(w,
nullptr));
2292 if ( tag.
name ==
"weight" ) {
2295 if ( tag.
name ==
"rwgt" ) {
2296 for (
int j = 0, M = tag.
tags.size(); j < M; ++j ) {
2297 if ( tag.
tags[j]->name ==
"wgt" ) {
2302 else if ( tag.
name ==
"clustering" ) {
2303 for (
int j = 0, M= tag.
tags.size(); j < M; ++j ) {
2304 if ( tag.
tags[j]->name ==
"clus" )
2308 else if ( tag.
name ==
"pdfinfo" ) {
2311 else if ( tag.
name ==
"scales" ) {
2317 for (
int i = 0, N =
namedweights.size(); i < N; ++i ) {
2341 file << std::setprecision(
heprup->dprec);
2345 file <<
"<eventgroup";
2352 for (
int i = 0, N =
subevents.size(); i < N; ++i )
2354 file <<
"</eventgroup>\n";
2362 file <<
" " << std::setw(4) <<
NUP
2363 <<
" " << std::setw(6) <<
IDPRUP
2364 <<
" " << std::setw(14) <<
XWGTUP
2365 <<
" " << std::setw(14) <<
SCALUP
2366 <<
" " << std::setw(14) <<
AQEDUP
2367 <<
" " << std::setw(14) <<
AQCDUP <<
"\n";
2369 for (
int i = 0; i <
NUP; ++i )
2370 file <<
" " << std::setw(8) <<
IDUP[i]
2371 <<
" " << std::setw(2) <<
ISTUP[i]
2372 <<
" " << std::setw(4) <<
MOTHUP[i].first
2373 <<
" " << std::setw(4) <<
MOTHUP[i].second
2374 <<
" " << std::setw(4) <<
ICOLUP[i].first
2375 <<
" " << std::setw(4) <<
ICOLUP[i].second
2376 <<
" " << std::setw(14) <<
PUP[i][0]
2377 <<
" " << std::setw(14) <<
PUP[i][1]
2378 <<
" " << std::setw(14) <<
PUP[i][2]
2379 <<
" " << std::setw(14) <<
PUP[i][3]
2380 <<
" " << std::setw(14) <<
PUP[i][4]
2381 <<
" " << std::setw(1) <<
VTIMUP[i]
2382 <<
" " << std::setw(1) <<
SPINUP[i] << std::endl;
2385 file <<
"<weights>";
2386 for (
int i = 1, N =
weights.size(); i < N; ++i )
2387 file <<
" " <<
weights[i].first;
2388 file <<
"</weights>\n";
2392 for (
int i = 0, N =
namedweights.size(); i < N; ++i ) {
2394 if ( !iswgt ) file <<
"<rwgt>\n";
2397 if ( iswgt ) file <<
"</rwgt>\n";
2400 for (
int j = 0, M =
namedweights[i].indices.size(); j < M; ++j )
2404 if ( iswgt ) file <<
"</rwgt>\n";
2407 file <<
"<clustering>" << std::endl;
2408 for (
int i = 0, N =
clustering.size(); i < N; ++i )
2410 file <<
"</clustering>" << std::endl;
2455 for (
int ii = 0, N =
subevents.size(); ii < N; ++ii )
2478 double weight(
const std::string & name)
const {
2492 int i =
heprup->weightIndex(name);
2493 if ( i >=
int(
weights.size()) )
return false;
2509 PUP.resize(
NUP, std::vector<double>(5));
2519 if ( i >=
weights.size() )
return false;
2554 for (
int ii = 1, N =
subevents.size(); ii < N; ++ii )
2555 for (
int j = 0, M =
weights.size(); j < M; ++j )
2631 std::vector< std::vector<double> >
PUP;
2664 std::vector< std::pair<double, const WeightInfo *> >
weights;
2720 while ( size() > 0 ) {
2732 for (
int i = 0, N = eg.size(); i < N; ++i ) at(i) =
new HEPEUP(*eg.at(i));
2736 if ( &x ==
this )
return *
this;
2740 for (
int i = 0, N = x.size(); i < N; ++i ) push_back(
new HEPEUP(*x.at(i)));
2795 size_t slash = filename.find_last_of(
'/');
2796 if ( slash != std::string::npos )
dirpath = filename.substr(0, slash + 1);
2811 bool readingHeader =
false;
2812 bool readingInit =
false;
2817 throw std::runtime_error
2818 (
"Tried to read a file which does not start with the "
2819 "LesHouchesEvents tag.");
2826 throw std::runtime_error
2827 (
"Tried to read a LesHouchesEvents file which is above version 3.");
2835 readingHeader =
true;
2846 readingHeader =
false;
2849 else if ( readingHeader ) {
2854 else if ( readingInit ) {
2864 throw std::runtime_error(
"Found incomplete init tag in "
2865 "Les Houches file.");
2868 for (
int i = 0, N = tags.size(); i < N; ++i )
2869 if ( tags[i]->name ==
"init" ) {
2891 if (
heprup.NPRUP < 0 )
return false;
2893 std::string eventLines;
2900 if ( inEvent == 1 &&
currentFind(
"</event>") )
break;
2901 if ( inEvent == 2 &&
currentFind(
"</eventgroup>") )
break;
2915 if ( ( inEvent == 1 && !
currentFind(
"</event>") ) ||
2916 ( inEvent == 2 && !
currentFind(
"</eventgroup>") ) ) {
2917 if (
heprup.eventfiles.empty() ||
2925 for (
int i = 0, N = tags.size(); i < N ; ++i ) {
2926 if ( tags[i]->name ==
"event" || tags[i]->name ==
"eventgroup" ) {
2935 if ( !
heprup.eventfiles.empty() &&
2953 std::cerr <<
"opening file " << ifile << std::endl;
2955 std::string fname =
heprup.eventfiles[ifile].filename;
2956 if ( fname[0] !=
'/' ) fname =
dirpath + fname;
2957 efile.open(fname.c_str());
2958 if ( !
efile )
throw std::runtime_error(
"Could not open event file " +
2978 return currentLine.find(str) != std::string::npos;
3017 return std::ifstream::goodbit;
3025 return std::ifstream::goodbit;
3144 size_t slash = filename.find_last_of(
'/');
3145 if ( slash != std::string::npos )
dirpath = filename.substr(0, slash + 1);
3153 if ( !
heprup.eventfiles.empty() ) {
3160 *
file <<
"</LesHouchesEvents>" << std::endl;
3218 if (
heprup.eventfiles.empty() )
return false;
3219 if ( ifile < 0 || ifile >=
int(
heprup.eventfiles.size()) )
return false;
3223 std::cerr <<
"LHEF::Writer number of events in event file "
3224 << ef.
filename <<
" does not match the given number."
3229 std::string fname =
heprup.eventfiles[ifile].filename;
3230 if ( fname[0] !=
'/' ) fname =
dirpath + fname;
3231 efile.open(fname.c_str());
3232 if ( !
efile )
throw std::runtime_error(
"Could not open event file " +
3234 std::cerr <<
"Opened event file " << fname << std::endl;
3249 if (
heprup.version == 3 )
3250 *
file <<
"<LesHouchesEvents version=\"3.0\">\n";
3251 else if (
heprup.version == 2 )
3252 *
file <<
"<LesHouchesEvents version=\"2.0\">\n";
3254 *
file <<
"<LesHouchesEvents version=\"1.0\">\n";
3257 *
file << std::setprecision(10);
3260 if ( headBlock.length() ) {
3261 if ( headBlock.find(
"<header>") == std::string::npos )
3262 *
file <<
"<header>\n";
3263 if ( headBlock[headBlock.length() - 1] !=
'\n' )
3266 if ( headBlock.find(
"</header>") == std::string::npos )
3267 *
file <<
"</header>\n";
3279 if ( !
heprup.eventfiles.empty() ) {
#define M_PI
Definition of PI. Needed on some platforms.
std::vector< double > VTIMUP
double totalWeight(int i=0) const
void print(std::ostream &file) const
std::pair< int, int > PDFGUPsave
HEPEUP & operator=(const HEPEUP &x)
std::vector< std::pair< int, int > > MOTHUP
HEPEUP & setEvent(const HEPEUP &x)
const WeightInfo * currentWeight
std::pair< int, int > PDFSUPsave
double totalWeight(const std::string &name) const
std::vector< Clus > clustering
bool setWeightInfo(unsigned int i)
std::vector< std::pair< double, const WeightInfo * > > weights
HEPEUP(const XMLTag &tagin, HEPRUP &heprupin)
bool setSubEvent(unsigned int i)
void setWeight(int i, double w)
std::vector< Weight > namedweights
double weight(int i=0) const
std::vector< double > SPINUP
bool setWeight(const std::string &name, double w)
double weight(const std::string &name) const
std::vector< std::pair< int, int > > ICOLUP
std::pair< double, double > XPDWUP
std::vector< std::vector< double > > PUP
std::vector< double > XMAXUP
std::vector< WeightGroup > weightgroup
std::vector< Generator > generators
void print(std::ostream &file) const
XSecInfo & getXSecInfo(std::string weightname="")
HEPRUP(const HEPRUP &)=default
std::pair< double, double > EBMUP
std::vector< EventFile > eventfiles
int weightIndex(const std::string &name) const
std::pair< int, int > PDFGUP
std::map< long, MergeInfo > mergeinfo
HEPRUP & operator=(const HEPRUP &)=default
std::vector< WeightInfo > weightinfo
std::map< long, ProcInfo > procinfo
std::map< std::string, int > weightmap
HEPRUP(const XMLTag &tagin, int versin)
std::map< std::string, std::set< long > > ptypes
std::pair< int, int > PDFSUP
std::pair< long, long > IDBMUP
std::vector< double > XSECUP
const XSecInfo & getXSecInfo(std::string weightname="") const
std::vector< double > XERRUP
std::string weightNameHepMC(int i) const
std::ios_base::iostate file_rdstate() const
std::string eventComments
void openeventfile(int ifile)
bool currentFind(std::string str) const
Reader & operator=(const Reader &)
Reader(std::string filename)
std::ios_base::iostate initfile_rdstate() const
std::ostream & initComments()
void initComments(const std::string &a)
void eventComments(const std::string &a)
std::ostream & headerBlock()
std::ostringstream initStream
std::ostringstream eventStream
std::ostream & eventComments()
void headerBlock(const std::string &a)
Writer(std::string filename)
std::ostringstream headerStream
bool openeventfile(int ifile)
Writer & operator=(const Writer &)
Les Houches event file classes.
std::string hashline(std::string s)
std::map< std::string, XSecInfo > XSecInfos
OAttr< T > oattr(std::string name, const T &value)
std::ostream & operator<<(std::ostream &os, const OAttr< T > &oa)
void print(std::ostream &file) const
void print(std::ostream &file) const
bool match(long id1, long id2=0) const
Cut(const XMLTag &tag, const std::map< std::string, std::set< long > > &ptypes)
bool outside(double value) const
bool passCuts(const std::vector< long > &id, const std::vector< std::vector< double > > &p) const
static double rap(const std::vector< double > &p)
static double eta(const std::vector< double > &p)
static double deltaR(const std::vector< double > &p1, const std::vector< double > &p2)
EventFile(const XMLTag &tag)
void print(std::ostream &file) const
EventGroup & operator=(const EventGroup &)
void print(std::ostream &file) const
Generator(const XMLTag &tag)
void print(std::ostream &file) const
MergeInfo(const XMLTag &tag)
OAttr(const std::string &n, const T &v)
void print(std::ostream &file) const
PDFInfo(const XMLTag &tag, double defscale=-1.0)
PDFInfo(double defscale=-1.0)
ProcInfo(const XMLTag &tag)
void print(std::ostream &file) const
void print(std::ostream &file) const
Scale(std::string st="veto", int emtr=0, double sc=0.0)
std::set< int > recoilers
double getScale(std::string st, int pdgem, int emr, int rec) const
void print(std::ostream &file) const
Scales(double defscale=-1.0, int npart=0)
Scales(const XMLTag &tag, double defscale=-1.0, int npart=0)
std::vector< Scale > scales
bool getattr(const std::string &n, double &v, bool erase=true)
bool getattr(const std::string &n, int &v, bool erase=true)
void closetag(std::ostream &file, const std::string &tag) const
bool getattr(const std::string &n, long &v, bool erase=true)
XMLTag::AttributeMap attributes
void printattrs(std::ostream &file) const
TagBase(const AttributeMap &attr, const std::string &conts=std::string())
bool getattr(const std::string &n, bool &v, bool erase=true)
XMLTag::AttributeMap AttributeMap
bool getattr(const std::string &n, std::string &v, bool erase=true)
WeightGroup(const XMLTag &tag, int groupIndex, std::vector< WeightInfo > &wiv)
void print(std::ostream &file) const
WeightInfo(const XMLTag &tag)
Weight(const XMLTag &tag)
std::vector< int > indices
void print(std::ostream &file) const
std::vector< double > weights
bool getattr(const std::string &n, int &v) const
bool getattr(const std::string &n, double &v) const
std::map< std::string, std::string > AttributeMap
std::string::size_type pos_t
static std::vector< XMLTag * > findXMLTags(std::string str, std::string *leftover=nullptr)
static void deleteAll(std::vector< XMLTag * > &tags)
bool getattr(const std::string &n, long &v) const
void print(std::ostream &os) const
bool getattr(const std::string &n, bool &v) const
std::vector< XMLTag * > tags
bool getattr(const std::string &n, std::string &v) const
void print(std::ostream &file) const
XSecInfo(const XMLTag &tag)