27 #define M_PI 3.14159265358979323846264338327950288
76 std::ostream & operator<<(std::ostream & os, const OAttr<T> & oa) {
77 os <<
" " << oa.
name <<
"=\"" << oa.val <<
"\"";
92 typedef std::string::size_type
pos_t;
113 for (
int i = 0, N =
tags.size(); i < N; ++i )
delete tags[i];
140 bool getattr(std::string n,
double & v)
const {
141 AttributeMap::const_iterator it =
attr.find(n);
142 if ( it ==
attr.end() )
return false;
143 v = std::atof(it->second.c_str());
153 AttributeMap::const_iterator it =
attr.find(n);
154 if ( it ==
attr.end() )
return false;
155 if ( it->second ==
"yes" ) v =
true;
164 AttributeMap::const_iterator it =
attr.find(n);
165 if ( it ==
attr.end() )
return false;
166 v = std::atoi(it->second.c_str());
175 AttributeMap::const_iterator it =
attr.find(n);
176 if ( it ==
attr.end() )
return false;
177 v = int(std::atoi(it->second.c_str()));
185 bool getattr(std::string n, std::string & v)
const {
186 AttributeMap::const_iterator it =
attr.find(n);
187 if ( it ==
attr.end() )
return false;
199 std::string * leftover = 0) {
200 std::vector<XMLTag*>
tags;
203 while ( curr !=
end ) {
206 pos_t begin = str.find(
"<", curr);
209 if ( begin !=
end && str.find(
"<!--", curr) == begin ) {
210 pos_t endcom = str.find(
"-->", begin);
211 tags.push_back(
new XMLTag());
212 if ( endcom ==
end ) {
213 tags.back()->contents = str.substr(curr);
214 if ( leftover ) *leftover += str.substr(curr);
217 tags.back()->contents = str.substr(curr, endcom - curr);
218 if ( leftover ) *leftover += str.substr(curr, endcom - curr);
223 if ( begin != curr ) {
224 tags.push_back(
new XMLTag());
225 tags.back()->contents = str.substr(curr, begin - curr);
226 if ( leftover ) *leftover += str.substr(curr, begin - curr);
228 if ( begin ==
end || begin > str.length() - 3 || str[begin + 1] ==
'/' )
231 pos_t close = str.find(
">", curr);
232 if ( close ==
end )
return tags;
235 curr = str.find_first_of(
" \t\n/>", begin);
236 tags.push_back(
new XMLTag());
237 tags.back()->name = str.substr(begin + 1, curr - begin - 1);
242 curr = str.find_first_not_of(
" \t\n", curr);
243 if ( curr ==
end || curr >= close )
break;
245 pos_t tend = str.find_first_of(
"= \t\n", curr);
246 if ( tend ==
end || tend >= close )
break;
248 std::string
name = str.substr(curr, tend - curr);
249 curr = str.find(
"=", curr) + 1;
252 curr = str.find_first_of(
"\"'", curr);
253 if ( curr ==
end || curr >= close )
break;
254 char quote = str[curr];
256 curr = str.find(quote, curr);
257 while ( curr !=
end && str[curr - 1] ==
'\\' )
258 curr = str.find(quote, curr + 1);
260 std::string value = str.substr(bega, curr ==
end?
end: curr - bega);
262 tags.back()->attr[
name] = value;
269 if ( str[close - 1] ==
'/' )
continue;
271 pos_t endtag = str.find(
"</" + tags.back()->name +
">", curr);
272 if ( endtag ==
end ) {
273 tags.back()->contents = str.substr(curr);
276 tags.back()->contents = str.substr(curr, endtag - curr);
277 curr = endtag + tags.back()->name.length() + 3;
280 std::string leftovers;
281 tags.back()->tags =
findXMLTags(tags.back()->contents, &leftovers);
282 if ( leftovers.find_first_not_of(
" \t\n") ==
end ) leftovers=
"";
283 tags.back()->contents = leftovers;
294 while ( tags.size() && tags.back() ) {
302 void print(std::ostream & os)
const {
303 if (
name.empty() ) {
308 for ( AttributeMap::const_iterator it =
attr.begin();
309 it !=
attr.end(); ++it )
310 os <<
oattr(it->first, it->second);
312 os <<
"/>" << std::endl;
316 for (
int i = 0, N =
tags.size(); i < N; ++i )
319 os <<
contents <<
"</" << name <<
">" << std::endl;
330 std::istringstream is(s);
332 while ( getline(is, ss) ) {
333 if ( ss.empty() )
continue;
334 if ( ss.find_first_not_of(
" \t") == std::string::npos )
continue;
335 if ( ss.find(
'#') == std::string::npos ||
336 ss.find(
'#') != ss.find_first_not_of(
" \t") ) ss =
"# " + ss;
369 bool getattr(std::string n,
double & v,
bool erase =
true) {
370 AttributeMap::iterator it =
attributes.find(n);
372 v = std::atof(it->second.c_str());
383 bool getattr(std::string n,
bool & v,
bool erase =
true) {
384 AttributeMap::iterator it =
attributes.find(n);
386 if ( it->second ==
"yes" ) v =
true;
397 bool getattr(std::string n,
long & v,
bool erase =
true) {
398 AttributeMap::iterator it =
attributes.find(n);
400 v = std::atoi(it->second.c_str());
411 bool getattr(std::string n,
int & v,
bool erase =
true) {
412 AttributeMap::iterator it =
attributes.find(n);
414 v = int(std::atoi(it->second.c_str()));
425 bool getattr(std::string n, std::string & v,
bool erase =
true) {
426 AttributeMap::iterator it =
attributes.find(n);
437 for ( AttributeMap::const_iterator it =
attributes.begin();
439 file <<
oattr(it->first, it->second);
446 void closetag(std::ostream & file, std::string tag)
const {
449 else if (
contents.find(
'\n') != std::string::npos )
450 file <<
">\n" <<
contents <<
"\n</" << tag <<
">\n";
452 file <<
">" <<
contents <<
"</" << tag <<
">\n";
468 static std::string
yes() {
return "yes"; }
489 void print(std::ostream & file)
const {
490 file <<
"<generator";
528 throw std::runtime_error(
"Found xsecinfo tag without neve attribute "
529 "in Les Houches Event File.");
533 throw std::runtime_error(
"Found xsecinfo tag without totxsec "
534 "attribute in Les Houches Event File.");
547 void print(std::ostream & file)
const {
548 file <<
"<xsecinfo" <<
oattr(
"neve",
neve)
631 throw std::runtime_error(
"Found eventfile tag without name attribute "
632 "in Les Houches Event File.");
641 void print(std::ostream & file)
const {
676 max(0.99*std::numeric_limits<double>::
max()) {}
682 const std::map<std::string,std::set<long> >& ptypes)
684 min(-0.99*std::numeric_limits<double>::
max()),
685 max(0.99*std::numeric_limits<double>::
max()) {
687 throw std::runtime_error(
"Found cut tag without type attribute "
688 "in Les Houches file");
691 if ( ptypes.find(
np1) != ptypes.end() ) {
692 p1 = ptypes.find(
np1)->second;
701 if ( ptypes.find(
np2) != ptypes.end() ) {
702 p2 = ptypes.find(
np2)->second;
711 std::istringstream iss(tag.
contents);
715 min = -0.99*std::numeric_limits<double>::max();
717 max = 0.99*std::numeric_limits<double>::max();
723 void print(std::ostream & file)
const {
728 if (
p1.size() == 1 ) file <<
oattr(
"p1", *
p1.begin());
732 if (
p2.size() == 1 ) file <<
oattr(
"p2", *
p2.begin());
736 if (
min > -0.9*std::numeric_limits<double>::max() )
740 if ( max < 0.9*std::numeric_limits<double>::max() )
743 file <<
"</cut>" << std::endl;
750 bool match(
long id1,
long id2 = 0)
const {
751 std::pair<bool,bool> ret(
false,
false);
752 if ( !id2 ) ret.second =
true;
753 if ( !id1 ) ret.first =
true;
754 if (
p1.find(0) !=
p1.end() ) ret.first =
true;
755 if (
p1.find(id1) !=
p1.end() ) ret.first =
true;
756 if (
p2.find(0) !=
p2.end() ) ret.second =
true;
757 if (
p2.find(id2) !=
p2.end() ) ret.second =
true;
758 return ret.first && ret.second;
767 const std::vector< std::vector<double> >& p )
const {
768 if ( (
type ==
"m" && !
p2.size() ) ||
type ==
"kt" ||
type ==
"eta" ||
770 for (
int i = 0, N =
id.size(); i < N; ++i )
771 if (
match(
id[i]) ) {
773 double v = p[i][4]*p[i][4] - p[i][3]*p[i][3] - p[i][2]*p[i][2]
775 v = v >= 0.0? std::sqrt(v): -std::sqrt(-v);
776 if (
outside(v) )
return false;
778 else if (
type ==
"kt" ) {
779 if (
outside(std::sqrt(p[i][2]*p[i][2] + p[i][1]*p[i][1])) )
782 else if (
type ==
"E" ) {
783 if (
outside(p[i][4]) )
return false;
785 else if (
type ==
"eta" ) {
788 else if (
type ==
"y" ) {
793 else if (
type ==
"m" ||
type ==
"deltaR" ) {
794 for (
int i = 1, N =
id.size(); i < N; ++i )
795 for (
int j = 0; j < i; ++j )
796 if (
match(
id[i],
id[j]) ||
match(
id[j],
id[i]) ) {
798 double v = (p[i][4] + p[j][4])*(p[i][4] + p[j][4])
799 - (p[i][3] + p[j][3])*(p[i][3] + p[j][3])
800 - (p[i][2] + p[j][2])*(p[i][2] + p[j][2])
801 - (p[i][1] + p[j][1])*(p[i][1] + p[j][1]);
802 v = v >= 0.0? std::sqrt(v): -std::sqrt(-v);
803 if (
outside(v) )
return false;
805 else if (
type ==
"deltaR" ) {
810 else if (
type ==
"ETmiss" ) {
813 for (
int i = 0, N =
id.size(); i < N; ++i )
818 if (
outside(std::sqrt(x*x + y*y)) )
return false;
820 else if (
type ==
"HT" ) {
822 for (
int i = 0, N =
id.size(); i < N; ++i )
824 pt += std::sqrt(p[i][1]*p[i][1] + p[i][2]*p[i][2]);
825 if (
outside(pt) )
return false;
833 static double eta(
const std::vector<double> & p) {
834 double pt2 = p[2]*p[2] + p[1]*p[1];
836 double dum = std::sqrt(pt2 + p[3]*p[3]) + p[3];
838 return std::log(dum/std::sqrt(pt2));
840 return p[3] < 0.0? -std::numeric_limits<double>::max():
841 std::numeric_limits<double>::max();
847 static double rap(
const std::vector<double> & p) {
848 double pt2 = p[5]*p[5] + p[2]*p[2] + p[1]*p[1];
850 double dum = std::sqrt(pt2 + p[3]*p[3]) + p[3];
852 return std::log(dum/std::sqrt(pt2));
854 return p[3] < 0.0? -std::numeric_limits<double>::max():
855 std::numeric_limits<double>::max();
861 static double deltaR(
const std::vector<double> &
p1,
862 const std::vector<double> &
p2) {
863 double deta =
eta(p1) -
eta(p2);
864 double dphi = std::atan2(p1[1], p1[2]) - std::atan2(p2[1], p2[2]);
865 if ( dphi > M_PI ) dphi -= 2.0*M_PI;
866 if ( dphi < -M_PI ) dphi += 2.0*M_PI;
867 return std::sqrt(dphi*dphi + deta*deta);
874 return value < min || value >=
max;
941 void print(std::ostream & file)
const {
1015 file <<
"<mergeinfo" <<
oattr(
"iproc",
iproc);
1076 file <<
"<weightinfo" <<
oattr(
"name",
name);
1144 for (
int i = 0, N = tag.
tags.size(); i < N; ++i ) {
1145 if ( tag.
tags[i]->name ==
"weight" ||
1146 tag.
tags[i]->name ==
"weightinfo" ) {
1189 std::istringstream iss(tag.
contents);
1191 while ( iss >> w )
weights.push_back(w);
1208 for (
int j = 0, M =
weights.size(); j < M; ++j ) file <<
" " <<
weights[j];
1210 file <<
"</wgt>" << std::endl;
1212 file <<
"</weight>" << std::endl;
1265 std::istringstream iss(tag.
contents);
1267 if ( !( iss >>
p0 ) )
p0 =
p1;
1277 file <<
">" <<
p1 <<
" " <<
p2;
1278 if (
p1 !=
p0 ) file <<
" " <<
p0;
1279 file <<
"</clus>" << std::endl;
1319 Scale(
string st =
"veto",
int emtr = 0,
double sc = 0.0)
1328 throw std::runtime_error(
"Found scale tag without stype attribute "
1329 "in Les Houches Event File.");
1331 if (
getattr(
"pos", pattr) ) {
1332 std::istringstream pis(pattr);
1336 while ( pis >> rec )
recoilers.insert(rec);
1341 if (
getattr(
"etype", eattr) ) {
1342 if ( eattr ==
"QCD" ) eattr =
"-5 -4 -3 -2 -1 1 2 3 4 5 21";
1343 if ( eattr ==
"EW" ) eattr =
"-13 -12 -11 11 12 13 22 23 24";
1344 std::istringstream eis(eattr);
1346 while ( eis >> pdg )
emitted.insert(pdg);
1348 std::istringstream cis(tag.
contents);
1359 std::ostringstream pos;
1361 for ( std::set<int>::iterator it =
recoilers.begin();
1364 file <<
oattr(
"pos", pos.str());
1367 std::set<int>::iterator it =
emitted.begin();
1368 std::ostringstream eos;
1370 while ( ++it !=
emitted.end() ) eos <<
" " << *it;
1371 if ( eos.str() ==
"-5 -4 -3 -2 -1 1 2 3 4 5 21" )
1372 file <<
oattr(
"etype",
string(
"QCD"));
1373 else if ( eos.str() ==
"-13 -12 -11 11 12 13 22 23 24" )
1374 file <<
oattr(
"etype",
string(
"EW"));
1376 file <<
oattr(
"etype", eos.str());
1378 std::ostringstream os;
1422 Scales(
double defscale = -1.0,
int npart = 0)
1431 muf(defscale),
mur(defscale),
mups(defscale),
1436 for (
int i = 0, N = tag.
tags.size(); i < N; ++i )
1437 if ( tag.
tags[i]->name ==
"scale" )
1439 for (
int i = 0; i < npart; ++i ) {
1440 std::ostringstream pttag;
1441 pttag <<
"pt_start_" << i + 1;
1443 if (
getattr(pttag.str(), sc) )
1469 std::ostringstream os;
1470 for (
int i = 0, N =
scales.size(); i < N; ++i )
1489 double getScale(std::string st,
int pdgem,
int emr,
int rec)
const {
1490 for (
int i = 0, N =
scales.size(); i < N; ++i ) {
1491 if (
scales[i].emitter == emr && st ==
scales[i].stype &&
1493 scales[i].recoilers.find(rec) !=
scales[i].recoilers.end() ) &&
1494 scales[i].emitted.find(pdgem) !=
scales[i].emitted.end() )
1497 for (
int i = 0, N =
scales.size(); i < N; ++i ) {
1498 if (
scales[i].emitter == emr && st ==
scales[i].stype &&
1500 scales[i].recoilers.find(rec) !=
scales[i].recoilers.end() ) &&
1501 scales[i].emitted.empty() )
1504 if ( emr != rec )
return getScale(st, pdgem, emr, emr);
1505 if ( emr == rec )
return getScale(st, pdgem, 0, 0);
1566 if (
xf1 <= 0 )
return;
1574 file <<
">" <<
xf1 <<
" " <<
xf2 <<
"</pdfinfo>" << std::endl;
1638 dprec(std::numeric_limits<double>::digits10) {}
1676 dprec(std::numeric_limits<double>::digits10) {
1678 std::vector<XMLTag*> tags = tagin.
tags;
1681 std::istringstream iss(tags[0]->
contents);
1685 throw std::runtime_error(
"Could not parse init block "
1686 "in Les Houches Event File.");
1690 for (
int i = 0; i <
NPRUP; ++i ) {
1692 throw std::runtime_error(
"Could not parse processes in init block "
1693 "in Les Houches Event File.");
1697 for (
int i = 1, N = tags.size(); i < N; ++i ) {
1698 const XMLTag & tag = *tags[i];
1702 if ( tag.
name ==
"initrwgt" ) {
1703 for (
int j = 0, M = tag.
tags.size(); j < M; ++j ) {
1704 if ( tag.
tags[j]->name ==
"weightgroup" )
1707 if ( tag.
tags[j]->name ==
"weight" )
1712 if ( tag.
name ==
"weightinfo" ) {
1715 if ( tag.
name ==
"weightgroup" ) {
1719 if ( tag.
name ==
"eventfiles" ) {
1720 for (
int j = 0, M = tag.
tags.size(); j < M; ++j ) {
1722 if ( eftag.
name ==
"eventfile" )
1726 if ( tag.
name ==
"xsecinfo" ) {
1730 if ( tag.
name ==
"generator" ) {
1733 else if ( tag.
name ==
"cutsinfo" ) {
1734 for (
int j = 0, M = tag.
tags.size(); j < M; ++j ) {
1737 if ( ctag.
name ==
"ptype" ) {
1738 std::string tname = ctag.
attr[
"name"];
1740 std::istringstream isss(ctag.
contents);
1741 while ( isss >>
id )
ptypes[tname].insert(
id);
1743 else if ( ctag.
name ==
"cut" )
1747 else if ( tag.
name ==
"procinfo" ) {
1751 else if ( tag.
name ==
"mergeinfo" ) {
1759 for (
int i = 0, N =
weightinfo.size(); i < N; ++i )
1778 if ( i < 0 || i >= (
int)
weightinfo.size() )
return name;
1793 file << std::setprecision(
dprec);
1796 <<
" " << setw(8) <<
IDBMUP.first
1797 <<
" " << setw(8) <<
IDBMUP.second
1798 <<
" " << setw(14) <<
EBMUP.first
1799 <<
" " << setw(14) <<
EBMUP.second
1800 <<
" " << setw(4) <<
PDFGUP.first
1801 <<
" " << setw(4) <<
PDFGUP.second
1802 <<
" " << setw(4) <<
PDFSUP.first
1803 <<
" " << setw(4) <<
PDFSUP.second
1804 <<
" " << setw(4) <<
IDWTUP
1805 <<
" " << setw(4) <<
NPRUP << std::endl;
1807 for (
int i = 0; i <
NPRUP; ++i )
1808 file <<
" " << setw(14) <<
XSECUP[i]
1809 <<
" " << setw(14) <<
XERRUP[i]
1810 <<
" " << setw(14) <<
XMAXUP[i]
1811 <<
" " << setw(6) <<
LPRUP[i] << std::endl;
1813 for (
int i = 0, N =
generators.size(); i < N; ++i )
1817 file <<
"<eventfiles>\n";
1818 for (
int i = 0, N =
eventfiles.size(); i < N; ++i )
1820 file <<
"</eventfiles>\n";
1823 for ( XSecInfos::const_iterator it =
xsecinfos.begin();
1825 if ( it->second.neve > 0 ) it->second.print(file);
1827 if (
cuts.size() > 0 ) {
1828 file <<
"<cutsinfo>" << std::endl;
1830 for ( std::map<std::string, std::set<long> >::const_iterator ptit =
1832 file <<
"<ptype" <<
oattr(
"name", ptit->first) <<
">";
1833 for ( std::set<long>::const_iterator it = ptit->second.begin();
1834 it != ptit->second.end(); ++it )
1836 file <<
"</ptype>" << std::endl;
1839 for (
int i = 0, N =
cuts.size(); i < N; ++i )
1841 file <<
"</cutsinfo>" << std::endl;
1844 for ( std::map<long,ProcInfo>::const_iterator it =
procinfo.begin();
1846 it->second.print(file);
1848 for ( std::map<long,MergeInfo>::const_iterator it =
mergeinfo.begin();
1850 it->second.print(file);
1852 bool isrwgt =
false;
1854 for (
int i = 0, N =
weightinfo.size(); i < N; ++i ) {
1856 if ( !isrwgt ) file <<
"<initrwgt>\n";
1859 if ( isrwgt ) file <<
"</initrwgt>\n";
1863 if ( group != ingroup ) {
1864 if ( ingroup != -1 ) file <<
"</weightgroup>\n";
1865 if ( group != -1 ) {
1866 file <<
"<weightgroup"
1876 if ( ingroup != -1 ) file <<
"</weightgroup>\n";
1877 if ( isrwgt ) file <<
"</initrwgt>\n";
1923 std::map<std::string, int>::const_iterator it =
weightmap.find(name);
1924 if ( it !=
weightmap.end() )
return it->second;
1952 XSecInfos::const_iterator it =
xsecinfos.find(weightname);
1953 if ( it !=
xsecinfos.end() )
return it->second;
2035 std::map<std::string, std::set<long> >
ptypes;
2114 inline void clear();
2228 throw std::runtime_error(
"Tried to read events but no processes defined "
2229 "in init block of Les Houches file.");
2231 std::vector<XMLTag*> tags = tagin.
tags;
2236 for (
int i = 0, N = tags.size(); i < N; ++i )
2237 if ( tags[i]->name ==
"event" )
2246 std::istringstream iss(tags[0]->
contents);
2248 throw std::runtime_error(
"Failed to parse event in Les Houches file.");
2253 for (
int i = 0; i <
NUP; ++i ) {
2257 >>
PUP[i][3] >>
PUP[i][4]
2259 throw std::runtime_error(
"Failed to parse event in Les Houches file.");
2264 while ( getline(iss, ss) )
junk += ss +
'\n';
2273 for (
int i = 1, N =
weights.size(); i < N; ++i )
2276 for (
int i = 1, N = tags.size(); i < N; ++i ) {
2281 if ( tag.
name ==
"weights" ) {
2285 for (
int ii = 1, NN =
weights.size(); ii < NN; ++ii )
2289 std::istringstream isss(tag.
contents);
2291 if ( ++iii <
int(
weights.size()) )
2296 if ( tag.
name ==
"weight" ) {
2299 if ( tag.
name ==
"rwgt" ) {
2300 for (
int j = 0, M = tag.
tags.size(); j < M; ++j ) {
2301 if ( tag.
tags[j]->name ==
"wgt" ) {
2306 else if ( tag.
name ==
"clustering" ) {
2307 for (
int j = 0, M= tag.
tags.size(); j < M; ++j ) {
2308 if ( tag.
tags[j]->name ==
"clus" )
2312 else if ( tag.
name ==
"pdfinfo" ) {
2315 else if ( tag.
name ==
"scales" ) {
2321 for (
int i = 0, N =
namedweights.size(); i < N; ++i ) {
2350 file <<
"<eventgroup";
2357 for (
int i = 0, N =
subevents.size(); i < N; ++i )
2359 file <<
"</eventgroup>\n";
2367 file <<
" " << setw(4) <<
NUP
2368 <<
" " << setw(6) <<
IDPRUP
2369 <<
" " << setw(14) <<
XWGTUP
2370 <<
" " << setw(14) <<
SCALUP
2371 <<
" " << setw(14) <<
AQEDUP
2372 <<
" " << setw(14) <<
AQCDUP <<
"\n";
2374 for (
int i = 0; i <
NUP; ++i )
2375 file <<
" " << setw(8) <<
IDUP[i]
2376 <<
" " << setw(2) <<
ISTUP[i]
2377 <<
" " << setw(4) <<
MOTHUP[i].first
2378 <<
" " << setw(4) <<
MOTHUP[i].second
2379 <<
" " << setw(4) <<
ICOLUP[i].first
2380 <<
" " << setw(4) <<
ICOLUP[i].second
2381 <<
" " << setw(14) <<
PUP[i][0]
2382 <<
" " << setw(14) <<
PUP[i][1]
2383 <<
" " << setw(14) <<
PUP[i][2]
2384 <<
" " << setw(14) <<
PUP[i][3]
2385 <<
" " << setw(14) <<
PUP[i][4]
2386 <<
" " << setw(1) <<
VTIMUP[i]
2387 <<
" " << setw(1) <<
SPINUP[i] << std::endl;
2390 file <<
"<weights>";
2391 for (
int i = 1, N =
weights.size(); i < N; ++i )
2392 file <<
" " <<
weights[i].first;
2393 file <<
"</weights>\n";
2397 for (
int i = 0, N =
namedweights.size(); i < N; ++i ) {
2399 if ( !iswgt ) file <<
"<rwgt>\n";
2402 if ( iswgt ) file <<
"</rwgt>\n";
2405 for (
int j = 0, M =
namedweights[i].indices.size(); j < M; ++j )
2409 if ( iswgt ) file <<
"</rwgt>\n";
2412 file <<
"<clustering>" << std::endl;
2413 for (
int i = 0, N =
clustering.size(); i < N; ++i )
2415 file <<
"</clustering>" << std::endl;
2460 for (
int ii = 0, N =
subevents.size(); ii < N; ++ii )
2498 if ( i >=
int(
weights.size()) )
return false;
2514 PUP.resize(
NUP, std::vector<double>(5));
2524 if ( i >=
weights.size() )
return false;
2559 for (
int ii = 1, N =
subevents.size(); ii < N; ++ii )
2560 for (
int j = 0, M =
weights.size(); j < M; ++j )
2636 std::vector< std::vector<double> >
PUP;
2669 std::vector< std::pair<double, const WeightInfo *> >
weights;
2725 while ( size() > 0 ) {
2736 : std::vector<
HEPEUP*>(eg.size()) {
2737 for (
int i = 0, N = eg.size(); i < N; ++i ) at(i) =
new HEPEUP(*eg.at(i));
2741 if ( &x ==
this )
return *
this;
2745 for (
int i = 0, N = x.size(); i < N; ++i ) push_back(
new HEPEUP(*x.at(i)));
2800 size_t slash = filename.find_last_of(
'/');
2801 if ( slash != std::string::npos )
dirpath = filename.substr(0, slash + 1);
2816 bool readingHeader =
false;
2817 bool readingInit =
false;
2822 throw std::runtime_error
2823 (
"Tried to read a file which does not start with the "
2824 "LesHouchesEvents tag.");
2831 throw std::runtime_error
2832 (
"Tried to read a LesHouchesEvents file which is above version 3.");
2840 readingHeader =
true;
2851 readingHeader =
false;
2854 else if ( readingHeader ) {
2859 else if ( readingInit ) {
2869 throw std::runtime_error(
"Found incomplete init tag in "
2870 "Les Houches file.");
2873 for (
int i = 0, N = tags.size(); i < N; ++i )
2874 if ( tags[i]->name ==
"init" ) {
2898 std::string eventLines;
2905 if ( inEvent == 1 &&
currentFind(
"</event>") )
break;
2906 if ( inEvent == 2 &&
currentFind(
"</eventgroup>") )
break;
2920 if ( ( inEvent == 1 && !
currentFind(
"</event>") ) ||
2921 ( inEvent == 2 && !
currentFind(
"</eventgroup>") ) ) {
2930 for (
int i = 0, N = tags.size(); i < N ; ++i ) {
2931 if ( tags[i]->name ==
"event" || tags[i]->name ==
"eventgroup" ) {
2957 std::cerr <<
"opening file " << ifile << std::endl;
2960 if ( fname[0] !=
'/' ) fname =
dirpath + fname;
2961 efile.open(fname.c_str());
2962 if ( !
efile )
throw std::runtime_error(
"Could not open event file " +
2982 return currentLine.find(str) != std::string::npos;
3132 size_t slash = filename.find_last_of(
'/');
3133 if ( slash != std::string::npos )
dirpath = filename.substr(0, slash + 1);
3148 *
file <<
"</LesHouchesEvents>" << std::endl;
3191 std::cerr <<
"LHEF::Writer number of events in event file "
3192 << ef.
filename <<
" does not match the given number."
3198 if ( fname[0] !=
'/' ) fname =
dirpath + fname;
3199 efile.open(fname.c_str());
3200 if ( !
efile )
throw std::runtime_error(
"Could not open event file " +
3202 std::cerr <<
"Opened event file " << fname << std::endl;
3218 *
file <<
"<LesHouchesEvents version=\"3.0\">\n";
3220 *
file <<
"<LesHouchesEvents version=\"2.0\">\n";
3222 *
file <<
"<LesHouchesEvents version=\"1.0\">\n";
3225 *
file << std::setprecision(10);
3230 if ( headBlock.length() ) {
3231 if ( headBlock.find(
"<header>") == std::string::npos )
3232 *
file <<
"<header>\n";
3233 if ( headBlock[headBlock.length() - 1] !=
'\n' )
3236 if ( headBlock.find(
"</header>") == std::string::npos )
3237 *
file <<
"</header>\n";
XSecInfo & getXSecInfo(std::string weightname="")
MergeInfo(const XMLTag &tag)
std::vector< XMLTag * > tags
void setWeight(int i, double w)
std::vector< double > VTIMUP
bool getattr(std::string n, double &v, bool erase=true)
Scales(const XMLTag &tag, double defscale=-1.0, int npart=0)
static void deleteAll(std::vector< XMLTag * > &tags)
bool getattr(std::string n, int &v, bool erase=true)
void print(std::ostream &file) const
std::pair< int, int > PDFGUPsave
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)
void print(std::ostream &os) const
HEPEUP & setEvent(const HEPEUP &x)
bool getattr(std::string n, std::string &v, bool erase=true)
int weightIndex(std::string name) const
void print(std::ostream &file) const
std::string hashline(std::string s)
std::ostream & eventComments()
std::ostringstream headerStream
double weight(std::string name) const
void printattrs(std::ostream &file) const
std::vector< EventFile > eventfiles
double weight(int i=0) const
std::ostream & headerBlock()
std::vector< Scale > scales
Reader & operator=(const Reader &)
std::vector< std::pair< int, int > > MOTHUP
std::pair< double, double > EBMUP
void print(std::ostream &file) const
std::ostringstream initStream
std::map< long, ProcInfo > procinfo
void print(std::ostream &file) const
std::vector< double > XERRUP
OAttr< T > oattr(std::string name, const T &value)
std::ostream & initComments()
std::pair< double, double > XPDWUP
OAttr(std::string n, const T &v)
WeightGroup(const XMLTag &tag, int groupIndex, std::vector< WeightInfo > &wiv)
std::map< std::string, XSecInfo > XSecInfos
std::pair< int, int > PDFSUPsave
Writer(std::string filename)
double totalWeight(int i=0) const
Generator(const XMLTag &tag)
XMLTag::AttributeMap AttributeMap
void print(std::ostream &file) const
void closetag(std::ostream &file, std::string tag) const
PDFInfo(double defscale=-1.0)
ProcInfo(const XMLTag &tag)
void print(std::ostream &file) const
bool match(long id1, long id2=0) const
EventFile(const XMLTag &tag)
HEPRUP(const XMLTag &tagin, int versin)
XMLTag::AttributeMap attributes
bool setSubEvent(unsigned int i)
bool currentFind(std::string str) const
bool getattr(std::string n, long &v, bool erase=true)
std::pair< int, int > PDFGUP
const WeightInfo * currentWeight
double getScale(std::string st, int pdgem, int emr, int rec) const
bool getattr(std::string n, std::string &v) const
std::ostringstream eventStream
HEPEUP(const XMLTag &tagin, HEPRUP &heprupin)
WeightInfo(const XMLTag &tag)
std::vector< std::pair< double, const WeightInfo * > > weights
std::string::size_type pos_t
void print(std::ostream &file) const
std::set< int > recoilers
std::vector< Generator > generators
void openeventfile(int ifile)
void print(std::ostream &file) const
std::vector< std::vector< double > > PUP
Scale(string st="veto", int emtr=0, double sc=0.0)
std::map< long, MergeInfo > mergeinfo
std::vector< WeightGroup > weightgroup
void print(std::ostream &file) const
std::vector< Weight > namedweights
EventGroup & operator=(const EventGroup &)
Weight(const XMLTag &tag)
std::vector< double > SPINUP
std::string eventComments
const XSecInfo & getXSecInfo(std::string weightname="") const
bool getattr(std::string n, bool &v, bool erase=true)
std::map< std::string, std::set< long > > ptypes
std::string weightNameHepMC(int i) const
bool getattr(std::string n, double &v) const
bool getattr(std::string n, long &v) const
bool setWeightInfo(unsigned int i)
PDFInfo(const XMLTag &tag, double defscale=-1.0)
bool passCuts(const std::vector< long > &id, const std::vector< std::vector< double > > &p) const
bool openeventfile(int ifile)
double totalWeight(std::string name) const
static double eta(const std::vector< double > &p)
Writer & operator=(const Writer &)
bool getattr(std::string n, bool &v) const
std::vector< double > XMAXUP
std::vector< WeightInfo > weightinfo
void print(std::ostream &file) const
void print(std::ostream &file) const
std::vector< int > indices
Cut(const XMLTag &tag, const std::map< std::string, std::set< long > > &ptypes)
std::vector< Clus > clustering
bool outside(double value) const
void print(std::ostream &file) const
std::vector< std::pair< int, int > > ICOLUP
std::map< std::string, int > weightmap
static double deltaR(const std::vector< double > &p1, const std::vector< double > &p2)
HEPEUP & operator=(const HEPEUP &x)
std::vector< double > weights
void print(std::ostream &file) const
static double rap(const std::vector< double > &p)
std::vector< double > XSECUP
bool getattr(std::string n, int &v) const
Scales(double defscale=-1.0, int npart=0)
HEPRUP & operator=(const HEPRUP &x)
std::pair< int, int > PDFSUP
void print(std::ostream &file) const
std::pair< long, long > IDBMUP
std::map< std::string, std::string > AttributeMap