64 std::ostream & operator<<(std::ostream & os, const OAttr<T> & oa) {
65 os <<
" " << oa.
name <<
"=\"" << oa.val <<
"\"";
80 typedef std::string::size_type
pos_t;
90 static const pos_t end = std::string::npos;
101 for (
int i = 0, N = tags.size(); i < N; ++i )
delete tags[i];
128 bool getattr(std::string n,
double & v)
const {
129 AttributeMap::const_iterator it = attr.find(n);
130 if ( it == attr.end() )
return false;
131 v = std::atof(it->second.c_str());
141 AttributeMap::const_iterator it = attr.find(n);
142 if ( it == attr.end() )
return false;
143 if ( it->second ==
"yes" ) v =
true;
152 AttributeMap::const_iterator it = attr.find(n);
153 if ( it == attr.end() )
return false;
154 v = std::atoi(it->second.c_str());
163 AttributeMap::const_iterator it = attr.find(n);
164 if ( it == attr.end() )
return false;
165 v = int(std::atoi(it->second.c_str()));
173 bool getattr(std::string n, std::string & v)
const {
174 AttributeMap::const_iterator it = attr.find(n);
175 if ( it == attr.end() )
return false;
187 std::string * leftover = 0) {
188 std::vector<XMLTag*> tags;
191 while ( curr != end ) {
194 pos_t begin = str.find(
"<", curr);
197 if ( begin != end && str.find(
"<!--", curr) == begin ) {
198 pos_t endcom = str.find(
"-->", begin);
199 tags.push_back(
new XMLTag());
200 if ( endcom == end ) {
201 tags.back()->contents = str.substr(curr);
202 if ( leftover ) *leftover += str.substr(curr);
205 tags.back()->contents = str.substr(curr, endcom - curr);
206 if ( leftover ) *leftover += str.substr(curr, endcom - curr);
211 if ( begin != curr ) {
212 tags.push_back(
new XMLTag());
213 tags.back()->contents = str.substr(curr, begin - curr);
214 if ( leftover ) *leftover += str.substr(curr, begin - curr);
216 if ( begin == end || begin > str.length() - 3 || str[begin + 1] ==
'/' )
219 pos_t close = str.find(
">", curr);
220 if ( close == end )
return tags;
223 curr = str.find_first_of(
" \t\n/>", begin);
224 tags.push_back(
new XMLTag());
225 tags.back()->name = str.substr(begin + 1, curr - begin - 1);
230 curr = str.find_first_not_of(
" \t\n", curr);
231 if ( curr == end || curr >= close )
break;
233 pos_t tend = str.find_first_of(
"= \t\n", curr);
234 if ( tend == end || tend >= close )
break;
236 std::string name = str.substr(curr, tend - curr);
237 curr = str.find(
"=", curr) + 1;
240 curr = str.find_first_of(
"\"'", curr);
241 if ( curr == end || curr >= close )
break;
242 char quote = str[curr];
244 curr = str.find(quote, curr);
245 while ( curr != end && str[curr - 1] ==
'\\' )
246 curr = str.find(quote, curr + 1);
248 std::string value = str.substr(bega, curr == end? end: curr - bega);
250 tags.back()->attr[
name] = value;
257 if ( str[close - 1] ==
'/' )
continue;
259 pos_t endtag = str.find(
"</" + tags.back()->name +
">", curr);
260 if ( endtag == end ) {
261 tags.back()->contents = str.substr(curr);
264 tags.back()->contents = str.substr(curr, endtag - curr);
265 curr = endtag + tags.back()->name.length() + 3;
268 std::string leftovers;
269 tags.back()->tags = findXMLTags(tags.back()->contents, &leftovers);
270 if ( leftovers.find_first_not_of(
" \t\n") == end ) leftovers=
"";
271 tags.back()->contents = leftovers;
282 while ( tags.size() && tags.back() ) {
290 void print(std::ostream & os)
const {
291 if ( name.empty() ) {
296 for ( AttributeMap::const_iterator it = attr.begin();
297 it != attr.end(); ++it )
298 os << oattr(it->first, it->second);
299 if ( contents.empty() && tags.empty() ) {
300 os <<
"/>" << std::endl;
304 for (
int i = 0, N = tags.size(); i < N; ++i )
307 os << contents <<
"</" << name <<
">" << std::endl;
316 inline std::string hashline(std::string s) {
318 std::istringstream is(s);
320 while ( getline(is, ss) ) {
321 if ( ss.empty() )
continue;
322 if ( ss.find_first_not_of(
" \t") == std::string::npos )
continue;
323 if ( ss.find(
'#') == std::string::npos ||
324 ss.find(
'#') != ss.find_first_not_of(
" \t") ) ss =
"# " + ss;
348 TagBase(
const AttributeMap & attr, std::string conts = std::string())
349 : attributes(attr), contents(conts) {}
357 bool getattr(std::string n,
double & v,
bool erase =
true) {
358 AttributeMap::iterator it = attributes.find(n);
359 if ( it == attributes.end() )
return false;
360 v = std::atof(it->second.c_str());
361 if ( erase) attributes.erase(it);
371 bool getattr(std::string n,
bool & v,
bool erase =
true) {
372 AttributeMap::iterator it = attributes.find(n);
373 if ( it == attributes.end() )
return false;
374 if ( it->second ==
"yes" ) v =
true;
375 if ( erase) attributes.erase(it);
385 bool getattr(std::string n,
long & v,
bool erase =
true) {
386 AttributeMap::iterator it = attributes.find(n);
387 if ( it == attributes.end() )
return false;
388 v = std::atoi(it->second.c_str());
389 if ( erase) attributes.erase(it);
399 bool getattr(std::string n,
int & v,
bool erase =
true) {
400 AttributeMap::iterator it = attributes.find(n);
401 if ( it == attributes.end() )
return false;
402 v = int(std::atoi(it->second.c_str()));
403 if ( erase) attributes.erase(it);
413 bool getattr(std::string n, std::string & v,
bool erase =
true) {
414 AttributeMap::iterator it = attributes.find(n);
415 if ( it == attributes.end() )
return false;
417 if ( erase) attributes.erase(it);
425 for ( AttributeMap::const_iterator it = attributes.begin();
426 it != attributes.end(); ++ it )
427 file << oattr(it->first, it->second);
434 void closetag(std::ostream & file, std::string tag)
const {
435 if ( contents.empty() )
437 else if ( contents.find(
'\n') != std::string::npos )
438 file <<
">\n" << contents <<
"\n</" << tag <<
">\n";
440 file <<
">" << contents <<
"</" << tag <<
">\n";
456 static std::string
yes() {
return "yes"; }
469 :
TagBase(tag.attr, tag.contents) {
470 getattr(
"name",
name);
471 getattr(
"version", version);
477 void print(std::ostream & file)
const {
478 file <<
"<generator";
479 if ( !
name.empty() ) file << oattr(
"name",
name);
480 if ( !version.empty() ) file << oattr(
"version", version);
482 closetag(file,
"generator");
505 XSecInfo(): neve(-1), totxsec(0.0), maxweight(1.0), meanweight(1.0),
506 negweights(false), varweights(false) {}
512 :
TagBase(tag.attr, tag.contents), neve(-1), totxsec(0.0),
513 maxweight(1.0), meanweight(1.0), negweights(false), varweights(false) {
514 if ( !getattr(
"neve", neve) )
515 throw std::runtime_error(
"Found xsecinfo tag without neve attribute " 516 "in Les Houches Event File.");
517 if ( !getattr(
"totxsec", totxsec) )
518 throw std::runtime_error(
"Found xsecinfo tag without totxsec " 519 "attribute in Les Houches Event File.");
520 getattr(
"maxweight", maxweight);
521 getattr(
"meanweight", meanweight);
522 getattr(
"negweights", negweights);
523 getattr(
"varweights", varweights);
530 void print(std::ostream & file)
const {
531 file <<
"<xsecinfo" << oattr(
"neve", neve) << oattr(
"totxsec", totxsec)
532 << oattr(
"maxweight", maxweight) << oattr(
"meanweight", meanweight);
533 if ( negweights ) file << oattr(
"negweights", yes());
534 if ( varweights ) file << oattr(
"varweights", yes());
536 closetag(file,
"xsecinfo");
580 Cut(): min(-0.99*
std::numeric_limits<double>::max()),
581 max(0.99*
std::numeric_limits<double>::max()) {}
587 const std::map<std::string,std::set<long> >& ptypes)
589 min(-0.99*
std::numeric_limits<double>::max()),
590 max(0.99*
std::numeric_limits<double>::max()) {
591 if ( !getattr(
"type", type) )
592 throw std::runtime_error(
"Found cut tag without type attribute " 593 "in Les Houches file");
595 if ( tag.
getattr(
"p1", np1) ) {
596 if ( ptypes.find(np1) != ptypes.end() ) {
597 p1 = ptypes.find(np1)->second;
598 attributes.erase(
"p1");
605 if ( tag.
getattr(
"p2", np2) ) {
606 if ( ptypes.find(np2) != ptypes.end() ) {
607 p2 = ptypes.find(np2)->second;
608 attributes.erase(
"p2");
616 std::istringstream iss(tag.
contents);
620 min = -0.99*std::numeric_limits<double>::max();
622 max = 0.99*std::numeric_limits<double>::max();
628 void print(std::ostream & file)
const {
629 file <<
"<cut" << oattr(
"type", type);
631 file << oattr(
"p1", np1);
633 if ( p1.size() == 1 ) file << oattr(
"p1", *p1.begin());
635 file << oattr(
"p2", np2);
637 if ( p2.size() == 1 ) file << oattr(
"p2", *p2.begin());
641 if ( min > -0.9*std::numeric_limits<double>::max() )
645 if ( max < 0.9*std::numeric_limits<double>::max() )
647 if ( !contents.empty() ) file << std::endl << contents << std::endl;
648 file <<
"</cut>" << std::endl;
655 bool match(
long id1,
long id2 = 0)
const {
656 std::pair<bool,bool> ret(
false,
false);
657 if ( !id2 ) ret.second =
true;
658 if ( !id1 ) ret.first =
true;
659 if ( p1.find(0) != p1.end() ) ret.first =
true;
660 if ( p1.find(id1) != p1.end() ) ret.first =
true;
661 if ( p2.find(0) != p2.end() ) ret.second =
true;
662 if ( p2.find(id2) != p2.end() ) ret.second =
true;
663 return ret.first && ret.second;
672 const std::vector< std::vector<double> >& p )
const {
673 if ( ( type ==
"m" && !p2.size() ) || type ==
"kt" || type ==
"eta" ||
674 type ==
"y" || type ==
"E" ) {
675 for (
int i = 0, N =
id.size(); i < N; ++i )
676 if ( match(
id[i]) ) {
678 double v = p[i][4]*p[i][4] - p[i][3]*p[i][3] - p[i][2]*p[i][2]
680 v = v >= 0.0? std::sqrt(v): -std::sqrt(-v);
681 if ( outside(v) )
return false;
683 else if ( type ==
"kt" ) {
684 if ( outside(std::sqrt(p[i][2]*p[i][2] + p[i][1]*p[i][1])) )
687 else if ( type ==
"E" ) {
688 if ( outside(p[i][4]) )
return false;
690 else if ( type ==
"eta" ) {
691 if ( outside(eta(p[i])) )
return false;
693 else if ( type ==
"y" ) {
694 if ( outside(rap(p[i])) )
return false;
698 else if ( type ==
"m" || type ==
"deltaR" ) {
699 for (
int i = 1, N =
id.size(); i < N; ++i )
700 for (
int j = 0; j < i; ++j )
701 if ( match(
id[i],
id[j]) || match(
id[j],
id[i]) ) {
703 double v = (p[i][4] + p[j][4])*(p[i][4] + p[j][4])
704 - (p[i][3] + p[j][3])*(p[i][3] + p[j][3])
705 - (p[i][2] + p[j][2])*(p[i][2] + p[j][2])
706 - (p[i][1] + p[j][1])*(p[i][1] + p[j][1]);
707 v = v >= 0.0? std::sqrt(v): -std::sqrt(-v);
708 if ( outside(v) )
return false;
710 else if ( type ==
"deltaR" ) {
711 if ( outside(deltaR(p[i], p[j])) )
return false;
715 else if ( type ==
"ETmiss" ) {
718 for (
int i = 0, N =
id.size(); i < N; ++i )
719 if ( match(
id[i]) && !match(0,
id[i]) ) {
723 if ( outside(std::sqrt(x*x + y*y)) )
return false;
725 else if ( type ==
"HT" ) {
727 for (
int i = 0, N =
id.size(); i < N; ++i )
728 if ( match(
id[i]) && !match(0,
id[i]) )
729 pt += std::sqrt(p[i][1]*p[i][1] + p[i][2]*p[i][2]);
730 if ( outside(pt) )
return false;
738 static double eta(
const std::vector<double> & p) {
739 double pt2 = p[2]*p[2] + p[1]*p[1];
741 double dum = std::sqrt(pt2 + p[3]*p[3]) + p[3];
743 return std::log(dum/std::sqrt(pt2));
745 return p[3] < 0.0? -std::numeric_limits<double>::max():
746 std::numeric_limits<double>::max();
752 static double rap(
const std::vector<double> & p) {
753 double pt2 = p[5]*p[5] + p[2]*p[2] + p[1]*p[1];
755 double dum = std::sqrt(pt2 + p[3]*p[3]) + p[3];
757 return std::log(dum/std::sqrt(pt2));
759 return p[3] < 0.0? -std::numeric_limits<double>::max():
760 std::numeric_limits<double>::max();
766 static double deltaR(
const std::vector<double> & p1,
767 const std::vector<double> & p2) {
768 double deta = eta(p1) - eta(p2);
769 double dphi = std::atan2(p1[1], p1[2]) - std::atan2(p2[1], p2[2]);
770 if ( dphi > M_PI ) dphi -= 2.0*M_PI;
771 if ( dphi < -M_PI ) dphi += 2.0*M_PI;
772 return std::sqrt(dphi*dphi + deta*deta);
779 return value < min || value >= max;
826 ProcInfo(): iproc(0), loops(0), qcdorder(-1), eworder(-1) {}
832 :
TagBase(tag.attr, tag.contents),
833 iproc(0), loops(0), qcdorder(-1), eworder(-1) {
834 getattr(
"iproc", iproc);
835 getattr(
"loops", loops);
836 getattr(
"qcdorder", qcdorder);
837 getattr(
"eworder", eworder);
838 getattr(
"rscheme", rscheme);
839 getattr(
"fscheme", fscheme);
840 getattr(
"scheme", scheme);
846 void print(std::ostream & file)
const {
847 file <<
"<procinfo" << oattr(
"iproc", iproc);
848 if ( loops >= 0 ) file << oattr(
"loops", loops);
849 if ( qcdorder >= 0 ) file << oattr(
"qcdorder", qcdorder);
850 if ( eworder >= 0 ) file<< oattr(
"eworder", eworder);
851 if ( !rscheme.empty() ) file << oattr(
"rscheme", rscheme);
852 if ( !fscheme.empty() ) file << oattr(
"fscheme", fscheme);
853 if ( !scheme.empty() ) file << oattr(
"scheme", scheme);
855 closetag(file,
"procinfo");
903 MergeInfo(): iproc(0), mergingscale(0.0), maxmult(false) {}
909 :
TagBase(tag.attr, tag.contents),
910 iproc(0), mergingscale(0.0), maxmult(false) {
911 getattr(
"iproc", iproc);
912 getattr(
"mergingscale", mergingscale);
913 getattr(
"maxmult", maxmult);
919 void print(std::ostream & file)
const {
920 file <<
"<mergeinfo" << oattr(
"iproc", iproc);
921 if ( mergingscale > 0.0 ) file << oattr(
"mergingscale", mergingscale);
922 if ( maxmult ) file << oattr(
"maxmult", yes());
924 closetag(file,
"mergeinfo");
954 muf(1.0), mur(1.0), pdf(0), pdf2(0) {}
960 :
TagBase(tag.attr, tag.contents),
961 inGroup(-1), isrwgt(tag.
name ==
"weight"),
962 muf(1.0), mur(1.0), pdf(0), pdf2(0) {
966 getattr(
"pdf2", pdf2);
970 getattr(
"name",
name);
976 void print(std::ostream & file)
const {
979 file <<
"<weight" << oattr(
"id",
name);
981 file <<
"<weightinfo" << oattr(
"name",
name);
982 if ( mur != 1.0 ) file << oattr(
"mur", mur);
983 if ( muf != 1.0 ) file << oattr(
"muf", muf);
984 if ( pdf != 0 ) file << oattr(
"pdf", pdf);
985 if ( pdf2 != 0 ) file << oattr(
"pdf2", pdf2);
988 closetag(file,
"weight");
990 closetag(file,
"weightinfo");
1047 getattr(
"type", type);
1048 getattr(
"combine", combine);
1049 for (
int i = 0, N = tag.
tags.size(); i < N; ++i ) {
1050 if ( tag.
tags[i]->name ==
"weight" ||
1051 tag.
tags[i]->name ==
"weightinfo" ) {
1080 Weight(): iswgt(false), born(0.0), sudakov(0.0) {}
1086 :
TagBase(tag.attr, tag.contents),
1087 iswgt(tag.
name ==
"wgt"), born(0.0), sudakov(0.0) {
1089 getattr(
"id",
name);
1091 getattr(
"name",
name);
1092 getattr(
"born", born);
1093 getattr(
"sudakov", sudakov);
1094 std::istringstream iss(tag.
contents);
1096 while ( iss >> w ) weights.push_back(w);
1097 indices.resize(weights.size(), 0.0);
1105 file <<
"<wgt" << oattr(
"id",
name);
1108 if ( !
name.empty() ) file << oattr(
"name",
name);
1110 if ( born != 0.0 ) file << oattr(
"born", born);
1111 if ( sudakov != 0.0 ) file << oattr(
"sudakov", sudakov);
1113 for (
int j = 0, M = weights.size(); j < M; ++j ) file <<
" " << weights[j];
1115 file <<
"</wgt>" << std::endl;
1117 file <<
"</weight>" << std::endl;
1161 Clus(): scale(-1.0), alphas(-1.0) {}
1167 :
TagBase(tag.attr, tag.contents), scale(-1.0), alphas(-1.0) {
1168 getattr(
"scale", scale);
1169 getattr(
"alphas", alphas);
1170 std::istringstream iss(tag.
contents);
1172 if ( !( iss >> p0 ) ) p0 = p1;
1180 if ( scale > 0.0 ) file << oattr(
"scale", scale);
1181 if ( alphas > 0.0 ) file << oattr(
"alphas", alphas);
1182 file <<
">" << p1 <<
" " << p2;
1183 if ( p1 != p0 ) file <<
" " << p0;
1184 file <<
"</clus>" << std::endl;
1224 : muf(defscale), mur(defscale), mups(defscale), SCALUP(defscale) {}
1230 :
TagBase(tag.attr, tag.contents),
1231 muf(defscale), mur(defscale), mups(defscale), SCALUP(defscale) {
1232 getattr(
"muf", muf);
1233 getattr(
"mur", mur);
1234 getattr(
"mups", mups);
1241 if ( muf == SCALUP && mur == SCALUP && mups == SCALUP )
return;
1243 if ( muf != SCALUP ) file << oattr(
"muf", muf);
1244 if ( mur != SCALUP ) file << oattr(
"mur", mur);
1245 if ( mups != SCALUP ) file << oattr(
"mups", mups);
1247 closetag(file,
"scales");
1281 PDFInfo(
double defscale = -1.0): p1(0), p2(0), x1(-1.0), x2(-1.0),
1282 xf1(-1.0), xf2(-1.0), scale(defscale), SCALUP(defscale) {}
1288 :
TagBase(tag.attr, tag.contents),
1289 p1(0), p2(0), x1(-1.0), x2(-1.0), xf1(-1.0), xf2(-1.0),
1290 scale(defscale), SCALUP(defscale) {
1291 getattr(
"scale", scale);
1302 if ( xf1 <= 0 )
return;
1304 if ( p1 != 0 ) file << oattr(
"p1", p1);
1305 if ( p2 != 0 ) file << oattr(
"p2", p2);
1306 if ( x1 > 0 ) file << oattr(
"x1", x1);
1307 if ( x2 > 0 ) file << oattr(
"x2", x2);
1308 if ( scale != SCALUP ) file << oattr(
"scale", scale);
1310 file <<
">" << xf1 <<
" " << xf2 <<
"</pdfinfo>" << std::endl;
1373 : IDWTUP(0), NPRUP(0), version(3),
1374 dprec(
std::numeric_limits<double>::digits10) {}
1410 :
TagBase(tagin.attr, tagin.contents), version(versin),
1411 dprec(
std::numeric_limits<double>::digits10) {
1413 std::vector<XMLTag*> tags = tagin.
tags;
1416 std::istringstream iss(tags[0]->contents);
1417 if ( !( iss >> IDBMUP.first >> IDBMUP.second >> EBMUP.first >> EBMUP.second
1418 >> PDFGUP.first >> PDFGUP.second >> PDFSUP.first >> PDFSUP.second
1419 >> IDWTUP >> NPRUP ) ) {
1420 throw std::runtime_error(
"Could not parse init block " 1421 "in Les Houches Event File.");
1425 for (
int i = 0; i < NPRUP; ++i ) {
1426 if ( !( iss >> XSECUP[i] >> XERRUP[i] >> XMAXUP[i] >> LPRUP[i] ) ) {
1427 throw std::runtime_error(
"Could not parse processes in init block " 1428 "in Les Houches Event File.");
1432 for (
int i = 1, N = tags.size(); i < N; ++i ) {
1433 const XMLTag & tag = *tags[i];
1437 if ( tag.
name ==
"initrwgt" ) {
1438 for (
int j = 0, M = tag.
tags.size(); j < M; ++j ) {
1439 if ( tag.
tags[j]->name ==
"weightgroup" )
1442 if ( tag.
tags[j]->name ==
"weight" )
1447 if ( tag.
name ==
"weightinfo" ) {
1450 if ( tag.
name ==
"weightgroup" ) {
1451 weightgroup.push_back(
WeightGroup(tag, weightgroup.size(),
1454 if ( tag.
name ==
"xsecinfo" ) {
1457 if ( tag.
name ==
"generator" ) {
1460 else if ( tag.
name ==
"cutsinfo" ) {
1461 for (
int j = 0, M = tag.
tags.size(); j < M; ++j ) {
1464 if ( ctag.
name ==
"ptype" ) {
1465 std::string tname = ctag.
attr[
"name"];
1467 std::istringstream isss(ctag.
contents);
1468 while ( isss >>
id ) ptypes[tname].insert(
id);
1470 else if ( ctag.
name ==
"cut" )
1471 cuts.push_back(
Cut(ctag, ptypes));
1474 else if ( tag.
name ==
"procinfo" ) {
1476 procinfo[proc.
iproc] = proc;
1478 else if ( tag.
name ==
"mergeinfo" ) {
1480 mergeinfo[merge.
iproc] = merge;
1486 for (
int i = 0, N = weightinfo.size(); i < N; ++i )
1487 weightmap[weightinfo[i].
name] = i + 1;
1505 if ( i < 0 || i >= (
int)weightinfo.size() )
return name;
1506 if ( weightinfo[i].inGroup >= 0 )
1507 name = weightgroup[weightinfo[i].inGroup].type +
"/" 1508 + weightgroup[weightinfo[i].inGroup].combine +
"/";
1509 name += weightinfo[i].name;
1520 file << std::setprecision(dprec);
1523 <<
" " << setw(8) << IDBMUP.first
1524 <<
" " << setw(8) << IDBMUP.second
1525 <<
" " << setw(14) << EBMUP.first
1526 <<
" " << setw(14) << EBMUP.second
1527 <<
" " << setw(4) << PDFGUP.first
1528 <<
" " << setw(4) << PDFGUP.second
1529 <<
" " << setw(4) << PDFSUP.first
1530 <<
" " << setw(4) << PDFSUP.second
1531 <<
" " << setw(4) << IDWTUP
1532 <<
" " << setw(4) << NPRUP << std::endl;
1534 for (
int i = 0; i < NPRUP; ++i )
1535 file <<
" " << setw(14) << XSECUP[i]
1536 <<
" " << setw(14) << XERRUP[i]
1537 <<
" " << setw(14) << XMAXUP[i]
1538 <<
" " << setw(6) << LPRUP[i] << std::endl;
1540 for (
int i = 0, N = generators.size(); i < N; ++i )
1541 generators[i].print(file);
1543 if ( xsecinfo.neve > 0 ) xsecinfo.print(file);
1545 if ( cuts.size() > 0 ) {
1546 file <<
"<cutsinfo>" << std::endl;
1548 for ( std::map<std::string, std::set<long> >::const_iterator ptit =
1549 ptypes.begin(); ptit != ptypes.end(); ++ptit ) {
1550 file <<
"<ptype" << oattr(
"name", ptit->first) <<
">";
1551 for ( std::set<long>::const_iterator it = ptit->second.begin();
1552 it != ptit->second.end(); ++it )
1554 file <<
"</ptype>" << std::endl;
1557 for (
int i = 0, N = cuts.size(); i < N; ++i )
1558 cuts[i].print(file);
1559 file <<
"</cutsinfo>" << std::endl;
1562 for ( std::map<long,ProcInfo>::const_iterator it = procinfo.begin();
1563 it != procinfo.end(); ++it )
1564 it->second.print(file);
1566 for ( std::map<long,MergeInfo>::const_iterator it = mergeinfo.begin();
1567 it != mergeinfo.end(); ++it )
1568 it->second.print(file);
1570 bool isrwgt =
false;
1572 for (
int i = 0, N = weightinfo.size(); i < N; ++i ) {
1573 if ( weightinfo[i].isrwgt ) {
1574 if ( !isrwgt ) file <<
"<initrwgt>\n";
1577 if ( isrwgt ) file <<
"</initrwgt>\n";
1580 int group = weightinfo[i].inGroup;
1581 if ( group != ingroup ) {
1582 if ( ingroup != -1 ) file <<
"</weightgroup>\n";
1583 if ( group != -1 ) {
1584 file <<
"<weightgroup" 1585 << oattr(
"type", weightgroup[group].type);
1586 if ( !weightgroup[group].combine.empty() )
1587 file << oattr(
"combine", weightgroup[group].combine);
1592 weightinfo[i].print(file);
1594 if ( ingroup != -1 ) file <<
"</weightgroup>\n";
1595 if ( isrwgt ) file <<
"</initrwgt>\n";
1598 file << hashline(junk) <<
"</init>" << std::endl;
1609 weightgroup.clear();
1631 XSECUP.resize(NPRUP);
1632 XERRUP.resize(NPRUP);
1633 XMAXUP.resize(NPRUP);
1634 LPRUP.resize(NPRUP);
1641 std::map<std::string, int>::const_iterator it = weightmap.find(name);
1642 if ( it != weightmap.end() )
return it->second;
1650 return weightmap.size() + 1;
1724 std::map<std::string, std::set<long> >
ptypes;
1803 inline void clear();
1841 : NUP(0), IDPRUP(0), XWGTUP(0.0), XPDWUP(0.0, 0.0),
1842 SCALUP(0.0), AQEDUP(0.0), AQCDUP(0.0), heprup(0), currentWeight(0),
1849 :
TagBase(x), isGroup(false) {
1911 :
TagBase(tagin.attr), NUP(0), IDPRUP(0), XWGTUP(0.0), XPDWUP(0.0, 0.0),
1912 SCALUP(0.0), AQEDUP(0.0), AQCDUP(0.0), heprup(&heprupin),
1913 currentWeight(0), isGroup(tagin.
name ==
"eventgroup") {
1915 if ( heprup->NPRUP < 0 )
1916 throw std::runtime_error(
"Tried to read events but no processes defined " 1917 "in init block of Les Houches file.");
1919 std::vector<XMLTag*> tags = tagin.
tags;
1922 getattr(
"nreal", subevents.nreal);
1923 getattr(
"ncounter", subevents.ncounter);
1924 for (
int i = 0, N = tags.size(); i < N; ++i )
1925 if ( tags[i]->
name ==
"event" )
1926 subevents.push_back(
new HEPEUP(*tags[i], heprupin));
1933 std::istringstream iss(tags[0]->contents);
1934 if ( !( iss >> NUP >> IDPRUP >> XWGTUP >> SCALUP >> AQEDUP >> AQCDUP ) )
1935 throw std::runtime_error(
"Failed to parse event in Les Houches file.");
1940 for (
int i = 0; i < NUP; ++i ) {
1941 if ( !( iss >> IDUP[i] >> ISTUP[i] >> MOTHUP[i].first >> MOTHUP[i].second
1942 >> ICOLUP[i].first >> ICOLUP[i].second
1943 >> PUP[i][0] >> PUP[i][1] >> PUP[i][2]
1944 >> PUP[i][3] >> PUP[i][4]
1945 >> VTIMUP[i] >> SPINUP[i] ) )
1946 throw std::runtime_error(
"Failed to parse event in Les Houches file.");
1951 while ( getline(iss, ss) ) junk += ss +
'\n';
1955 namedweights.clear();
1957 weights.resize(heprup->nWeights(),
1959 weights.front().first = XWGTUP;
1960 for (
int i = 1, N = weights.size(); i < N; ++i )
1961 weights[i].second = &heprup->weightinfo[i - 1];
1963 for (
int i = 1, N = tags.size(); i < N; ++i ) {
1968 if ( tag.
name ==
"weights" ) {
1969 weights.resize(heprup->nWeights(),
1971 weights.front().first = XWGTUP;
1972 for (
int ii = 1, NN = weights.size(); ii < NN; ++ii )
1973 weights[ii].second = &heprup->weightinfo[ii - 1];
1976 std::istringstream isss(tag.
contents);
1978 if ( ++iii <
int(weights.size()) )
1979 weights[iii].first = w;
1981 weights.push_back(std::make_pair(w, (
WeightInfo*)(0)));
1983 if ( tag.
name ==
"weight" ) {
1984 namedweights.push_back(
Weight(tag));
1986 if ( tag.
name ==
"rwgt" ) {
1987 for (
int j = 0, M = tag.
tags.size(); j < M; ++j ) {
1988 if ( tag.
tags[j]->name ==
"wgt" ) {
1989 namedweights.push_back(
Weight(*tag.
tags[j]));
1993 else if ( tag.
name ==
"clustering" ) {
1994 for (
int j = 0, M= tag.
tags.size(); j < M; ++j ) {
1995 if ( tag.
tags[j]->name ==
"clus" )
1996 clustering.push_back(
Clus(*tag.
tags[j]));
1999 else if ( tag.
name ==
"pdfinfo" ) {
2000 pdfinfo =
PDFInfo(tag, SCALUP);
2002 else if ( tag.
name ==
"scales" ) {
2003 scales =
Scales(tag, SCALUP);
2008 for (
int i = 0, N = namedweights.size(); i < N; ++i ) {
2009 int indx = heprup->weightIndex(namedweights[i].
name);
2011 weights[indx].first = namedweights[i].weights[0];
2012 namedweights[i].indices[0] = indx;
2014 weights.push_back(std::make_pair(namedweights[i].weights[0],
2016 namedweights[i].indices[0] = weights.size() - 1;
2018 for (
int j = 1, M = namedweights[i].weights.size(); j < M; ++j ) {
2019 weights.push_back(std::make_pair(namedweights[i].weights[j],
2021 namedweights[i].indices[j] = weights.size() - 1;
2032 file << std::setprecision(heprup->dprec);
2037 file <<
"<eventgroup";
2038 if ( subevents.nreal > 0 )
2039 file << oattr(
"nreal", subevents.nreal);
2040 if ( subevents.ncounter > 0 )
2041 file << oattr(
"ncounter", subevents.ncounter);
2044 for (
int i = 0, N = subevents.size(); i < N; ++i )
2045 subevents[i]->print(file);
2046 file <<
"</eventgroup>\n";
2053 file <<
" " << setw(4) << NUP
2054 <<
" " << setw(6) << IDPRUP
2055 <<
" " << setw(14) << XWGTUP
2056 <<
" " << setw(14) << SCALUP
2057 <<
" " << setw(14) << AQEDUP
2058 <<
" " << setw(14) << AQCDUP <<
"\n";
2060 for (
int i = 0; i < NUP; ++i )
2061 file <<
" " << setw(8) << IDUP[i]
2062 <<
" " << setw(2) << ISTUP[i]
2063 <<
" " << setw(4) << MOTHUP[i].first
2064 <<
" " << setw(4) << MOTHUP[i].second
2065 <<
" " << setw(4) << ICOLUP[i].first
2066 <<
" " << setw(4) << ICOLUP[i].second
2067 <<
" " << setw(14) << PUP[i][0]
2068 <<
" " << setw(14) << PUP[i][1]
2069 <<
" " << setw(14) << PUP[i][2]
2070 <<
" " << setw(14) << PUP[i][3]
2071 <<
" " << setw(14) << PUP[i][4]
2072 <<
" " << setw(1) << VTIMUP[i]
2073 <<
" " << setw(1) << SPINUP[i] << std::endl;
2075 if ( weights.size() > 0 ) {
2076 file <<
"<weights>";
2077 for (
int i = 1, N = weights.size(); i < N; ++i )
2078 file <<
" " << weights[i].first;
2079 file <<
"</weights>\n";
2083 for (
int i = 0, N = namedweights.size(); i < N; ++i ) {
2084 if ( namedweights[i].iswgt ) {
2085 if ( !iswgt ) file <<
"<rwgt>\n";
2088 if ( iswgt ) file <<
"</rwgt>\n";
2091 for (
int j = 0, M = namedweights[i].indices.size(); j < M; ++j )
2092 namedweights[i].weights[j] = weight(namedweights[i].indices[j]);
2093 namedweights[i].print(file);
2095 if ( iswgt ) file <<
"</rwgt>\n";
2097 if ( !clustering.empty() ) {
2098 file <<
"<clustering>" << std::endl;
2099 for (
int i = 0, N = clustering.size(); i < N; ++i )
2100 clustering[i].print(file);
2101 file <<
"</clustering>" << std::endl;
2104 pdfinfo.print(file);
2109 file << hashline(junk) <<
"</event>\n";
2146 if ( subevents.empty() )
return weight(i);
2148 for (
int ii = 0, N = subevents.size(); ii < N; ++ii )
2149 w += subevents[ii]->weight(i);
2158 return totalWeight(heprup->weightIndex(name));
2165 return weights[i].first;
2172 return weight(heprup->weightIndex(name));
2179 weights[i].first = w;
2185 int i = heprup->weightIndex(name);
2186 if ( i >=
int(weights.size()) )
return false;
2202 PUP.resize(NUP, std::vector<double>(5));
2212 if ( i >= weights.size() )
return false;
2213 if ( currentWeight ) {
2214 scales.mur /= currentWeight->mur;
2215 scales.muf /= currentWeight->muf;
2216 heprup->PDFGUP = PDFGUPsave;
2217 heprup->PDFSUP = PDFSUPsave;
2219 XWGTUP = weights[i].first;
2220 currentWeight = weights[i].second;
2221 if ( currentWeight ) {
2222 scales.mur *= currentWeight->mur;
2223 scales.muf *= currentWeight->muf;
2224 PDFGUPsave = heprup->PDFGUP;
2225 PDFSUPsave = heprup->PDFSUP;
2226 if ( currentWeight->pdf ) {
2227 heprup->PDFGUP.first = heprup->PDFGUP.second = 0;
2228 heprup->PDFSUP.first = heprup->PDFSUP.second = currentWeight->pdf;
2230 if ( currentWeight->pdf2 ) {
2231 heprup->PDFSUP.second = currentWeight->pdf2;
2243 if ( i > subevents.size() || subevents.empty() )
return false;
2246 weights = subevents[0]->weights;
2247 for (
int ii = 1, N = subevents.size(); ii < N; ++ii )
2248 for (
int j = 0, M = weights.size(); j < M; ++j )
2249 weights[j].first += subevents[ii]->weights[j].first;
2252 setEvent(*subevents[i - 1]);
2324 std::vector< std::vector<double> >
PUP;
2357 std::vector< std::pair<double, const WeightInfo *> >
weights;
2407 while ( size() > 0 ) {
2419 for (
int i = 0, N = eg.size(); i < N; ++i ) at(i) =
new HEPEUP(*eg.at(i));
2423 if ( &x ==
this )
return *
this;
2427 for (
int i = 0, N = x.size(); i < N; ++i ) push_back(
new HEPEUP(*x.at(i)));
2478 : intstream(filename.c_str()), file(intstream) {
2490 bool readingHeader =
false;
2491 bool readingInit =
false;
2495 if ( !currentFind(
"<LesHouchesEvents") )
2496 throw std::runtime_error
2497 (
"Tried to read a file which does not start with the " 2498 "LesHouchesEvents tag.");
2500 if ( currentFind(
"version=\"3" ) )
2502 else if ( currentFind(
"version=\"2" ) )
2504 else if ( !currentFind(
"version=\"1" ) )
2505 throw std::runtime_error
2506 (
"Tried to read a LesHouchesEvents file which is above version 3.");
2509 while ( getline() && !currentFind(
"</init>") ) {
2510 if ( currentFind(
"<header") ) {
2514 readingHeader =
true;
2515 headerBlock = currentLine +
"\n";
2517 else if ( currentFind(
"<init>") ) {
2520 initComments = currentLine +
"\n";
2522 else if ( currentFind(
"</header>") ) {
2525 readingHeader =
false;
2526 headerBlock += currentLine +
"\n";
2528 else if ( readingHeader ) {
2531 headerBlock += currentLine +
"\n";
2533 else if ( readingInit ) {
2535 initComments += currentLine +
"\n";
2539 outsideBlock += currentLine +
"\n";
2542 if ( !currentFind(
"</init>") )
2543 throw std::runtime_error(
"Found incomplete init tag in " 2544 "Les Houches file.");
2545 initComments += currentLine +
"\n";
2547 for (
int i = 0, N = tags.size(); i < N; ++i )
2548 if ( tags[i]->name ==
"init" ) {
2549 heprup =
HEPRUP(*tags[i], version);
2568 if ( heprup.NPRUP < 0 )
return false;
2570 std::string eventLines;
2574 while ( getline() ) {
2576 eventLines += currentLine +
"\n";
2577 if ( inEvent == 1 && currentFind(
"</event>") )
break;
2578 if ( inEvent == 2 && currentFind(
"</eventgroup>") )
break;
2580 else if ( currentFind(
"<eventgroup") ) {
2581 eventLines += currentLine +
"\n";
2584 else if ( currentFind(
"<event") ) {
2585 eventLines += currentLine +
"\n";
2589 outsideBlock += currentLine +
"\n";
2592 if ( inEvent == 1 && !currentFind(
"</event>") )
return false;
2593 if ( inEvent == 2 && !currentFind(
"</eventgroup>") )
return false;
2597 for (
int i = 0, N = tags.size(); i < N ; ++i ) {
2598 if ( tags[i]->name ==
"event" || tags[i]->name ==
"eventgroup" ) {
2599 hepeup =
HEPEUP(*tags[i], heprup);
2616 return ( (
bool)std::getline(file, currentLine) );
2623 return currentLine.find(str) != std::string::npos;
2739 : intstream(filename.c_str()), file(intstream) {}
2745 file <<
"</LesHouchesEvents>" << std::endl;
2752 return headerStream;
2776 if ( heprup.version == 3 )
2777 file <<
"<LesHouchesEvents version=\"3.0\">\n";
2778 else if ( heprup.version == 2 )
2779 file <<
"<LesHouchesEvents version=\"2.0\">\n";
2781 file <<
"<LesHouchesEvents version=\"1.0\">\n";
2784 file << std::setprecision(10);
2788 std::string headBlock = headerStream.str();
2789 if ( headBlock.length() ) {
2790 if ( headBlock.find(
"<header>") == std::string::npos )
2791 file <<
"<header>\n";
2792 if ( headBlock[headBlock.length() - 1] !=
'\n' )
2795 if ( headBlock.find(
"</header>") == std::string::npos )
2796 file <<
"</header>\n";
MergeInfo(const XMLTag &tag)
void print(std::ostream &file) const
int weightIndex(std::string name) const
std::string weightNameHepMC(int i) const
void setWeight(int i, double w)
bool getattr(std::string n, int &v) const
bool getattr(std::string n, double &v, bool erase=true)
double totalWeight(std::string name) const
void print(std::ostream &file) const
void print(std::ostream &file) const
bool getattr(std::string n, int &v, bool erase=true)
std::vector< WeightGroup > weightgroup
static void deleteAll(std::vector< XMLTag *> &tags)
bool setWeight(std::string name, double w)
Reader(std::string filename)
static std::vector< XMLTag * > findXMLTags(std::string str, std::string *leftover=0)
XSecInfo(const XMLTag &tag)
std::pair< double, double > XPDWUP
void print(std::ostream &os) const
HEPEUP & setEvent(const HEPEUP &x)
bool getattr(std::string n, std::string &v, bool erase=true)
std::ostream & eventComments()
std::vector< double > weights
std::ostringstream headerStream
Scales(double defscale=-1.0)
std::vector< WeightInfo > weightinfo
std::ostream & headerBlock()
std::ostringstream initStream
bool match(long id1, long id2=0) const
std::ostream & initComments()
bool passCuts(const std::vector< long > &id, const std::vector< std::vector< double > > &p) const
OAttr(std::string n, const T &v)
std::map< std::string, std::set< long > > ptypes
WeightGroup(const XMLTag &tag, int groupIndex, std::vector< WeightInfo > &wiv)
std::vector< Weight > namedweights
std::vector< double > XSECUP
bool getattr(std::string n, std::string &v) const
Writer(std::string filename)
std::map< long, MergeInfo > mergeinfo
Generator(const XMLTag &tag)
XMLTag::AttributeMap AttributeMap
bool getattr(std::string n, bool &v) const
PDFInfo(double defscale=-1.0)
ProcInfo(const XMLTag &tag)
void print(std::ostream &file) const
void print(std::ostream &file) const
HEPRUP(const XMLTag &tagin, int versin)
XMLTag::AttributeMap attributes
bool setSubEvent(unsigned int i)
double weight(std::string name) const
bool getattr(std::string n, long &v, bool erase=true)
std::vector< Generator > generators
std::pair< int, int > PDFSUP
std::vector< XMLTag * > tags
std::ostringstream eventStream
void print(std::ostream &file) const
std::vector< std::pair< int, int > > ICOLUP
HEPEUP(const XMLTag &tagin, HEPRUP &heprupin)
std::vector< int > indices
std::pair< long, long > IDBMUP
std::map< std::string, int > weightmap
WeightInfo(const XMLTag &tag)
std::vector< std::pair< int, int > > MOTHUP
std::vector< double > SPINUP
std::pair< int, int > PDFGUPsave
std::string::size_type pos_t
std::vector< std::vector< double > > PUP
TagBase(const AttributeMap &attr, std::string conts=std::string())
bool currentFind(std::string str) const
bool outside(double value) const
void print(std::ostream &file) const
EventGroup & operator=(const EventGroup &)
Weight(const XMLTag &tag)
void closetag(std::ostream &file, std::string tag) const
std::pair< double, double > EBMUP
Scales(const XMLTag &tag, double defscale=-1.0)
void print(std::ostream &file) const
std::string eventComments
std::vector< double > XERRUP
std::map< long, ProcInfo > procinfo
bool getattr(std::string n, bool &v, bool erase=true)
std::vector< std::pair< double, const WeightInfo * > > weights
bool setWeightInfo(unsigned int i)
PDFInfo(const XMLTag &tag, double defscale=-1.0)
void print(std::ostream &file) const
static double eta(const std::vector< double > &p)
std::vector< double > XMAXUP
void printattrs(std::ostream &file) const
const WeightInfo * currentWeight
std::vector< double > VTIMUP
Cut(const XMLTag &tag, const std::map< std::string, std::set< long > > &ptypes)
std::pair< int, int > PDFGUP
bool getattr(std::string n, long &v) const
static double deltaR(const std::vector< double > &p1, const std::vector< double > &p2)
HEPEUP & operator=(const HEPEUP &x)
static double rap(const std::vector< double > &p)
void print(std::ostream &file) const
std::vector< Clus > clustering
void print(std::ostream &file) const
std::pair< int, int > PDFSUPsave
HEPRUP & operator=(const HEPRUP &x)
double totalWeight(int i=0) const
void print(std::ostream &file) const
bool getattr(std::string n, double &v) const
double weight(int i=0) const
std::map< std::string, std::string > AttributeMap