11 #ifndef Pythia8_LHEF3_H 12 #define Pythia8_LHEF3_H 14 #include "Pythia8/PythiaStdlib.h" 15 #include "Pythia8/Streams.h" 30 typedef string::size_type
pos_t;
33 static const pos_t
end;
37 for (
int i = 0, N =
tags.size(); i < N; ++i )
55 bool getattr(
string n,
double & v)
const {
56 map<string,string>::const_iterator it = attr.find(n);
57 if ( it == attr.end() )
return false;
58 v = atof(it->second.c_str());
65 map<string,string>::const_iterator it = attr.find(n);
66 if ( it == attr.end() )
return false;
67 if ( it->second ==
"yes" ) v =
true;
74 map<string,string>::const_iterator it = attr.find(n);
75 if ( it == attr.end() )
return false;
76 v = atoi(it->second.c_str());
83 map<string,string>::const_iterator it = attr.find(n);
84 if ( it == attr.end() )
return false;
85 v = int(atoi(it->second.c_str()));
91 bool getattr(
string n,
string & v)
const {
92 map<string,string>::const_iterator it = attr.find(n);
93 if ( it == attr.end() )
return false;
101 string * leftover = 0) {
102 vector<XMLTag*>
tags;
105 while ( curr != end ) {
108 pos_t begin = str.find(
"<", curr);
111 pos_t lastbreak_before_begin = str.find_last_of(
"\n",begin);
112 pos_t lastpound_before_begin = str.find_last_of(
"#",begin);
117 if ( (lastbreak_before_begin < lastpound_before_begin
118 || lastbreak_before_begin == end)
119 && begin > lastpound_before_begin) {
120 pos_t endcom = str.find_first_of(
"\n",begin);
121 if ( endcom == end ) {
122 if ( leftover ) *leftover += str.substr(curr);
125 if ( leftover ) *leftover += str.substr(curr, endcom - curr);
131 if ( begin != end && str.find(
"<!--", curr) == begin ) {
132 pos_t endcom = str.find(
"-->", begin);
133 if ( endcom == end ) {
134 if ( leftover ) *leftover += str.substr(curr);
137 if ( leftover ) *leftover += str.substr(curr, endcom - curr);
148 if ( str.find(
"<![CDATA[", curr) == begin ) {
149 pos_t endcom = str.find(
"]]>", begin);
150 if ( endcom == end ) {
151 if ( leftover ) *leftover += str.substr(curr);
154 if ( leftover ) *leftover += str.substr(curr, endcom - curr);
159 if ( leftover ) *leftover += str.substr(curr, begin - curr);
160 if ( begin == end || begin > str.length() - 3 || str[begin + 1] ==
'/' )
163 pos_t close = str.find(
">", curr);
164 if ( close == end )
return tags;
167 curr = str.find_first_of(
" \t\n/>", begin);
168 tags.push_back(
new XMLTag());
169 tags.back()->name = str.substr(begin + 1, curr - begin - 1);
174 curr = str.find_first_not_of(
" \t\n", curr);
175 if ( curr == end || curr >= close )
break;
177 pos_t tend = str.find_first_of(
"= \t\n", curr);
178 if ( tend == end || tend >= close )
break;
180 string name = str.substr(curr, tend - curr);
181 curr = str.find(
"=", curr) + 1;
184 curr = str.find(
"\"", curr);
185 if ( curr == end || curr >= close )
break;
187 curr = str.find(
"\"", curr);
188 while ( curr != end && str[curr - 1] ==
'\\' )
189 curr = str.find(
"\"", curr + 1);
191 string value = str.substr(bega, curr == end? end: curr - bega);
193 tags.back()->attr[
name] = value;
200 if ( str[close - 1] ==
'/' )
continue;
202 pos_t endtag = str.find(
"</" + tags.back()->name +
">", curr);
203 if ( endtag == end ) {
204 tags.back()->contents = str.substr(curr);
207 tags.back()->contents = str.substr(curr, endtag - curr);
208 curr = endtag + tags.back()->name.length() + 3;
212 tags.back()->tags =
findXMLTags(tags.back()->contents, &leftovers);
213 if ( leftovers.find_first_not_of(
" \t\n") ==
end ) leftovers=
"";
214 tags.back()->contents = leftovers;
223 void list(ostream & os)
const {
225 for ( map<string,string>::const_iterator it = attr.begin();
226 it != attr.end(); ++it )
227 os <<
" " << it->first <<
"=\"" << it->second <<
"\"";
228 if ( contents.empty() && tags.empty() ) {
233 for (
int i = 0, N = tags.size(); i < N; ++i )
236 os <<
"````" << contents <<
"''''</" << name <<
">" << endl;
254 void list(ostream & file)
const;
273 int size()
const {
return int(weights.size()); }
285 : muf(defscale), mur(defscale), mups(defscale), SCALUP(defscale) {}
291 void list(ostream & file)
const;
335 void list(ostream & file)
const;
373 void list(ostream & file)
const;
407 void list(ostream & file)
const;
441 void list(ostream & file)
const;
459 vector<string> weightsKeys;
465 int size()
const {
return int(weights.size()); }
483 void list(ostream & file)
const;
497 vector<string> wgtsKeys;
503 int size()
const {
return int(wgts.size()); }
521 void list(ostream & file)
const;
527 weightgroups.clear();
536 vector<string> weightsKeys;
540 vector<string> weightgroupsKeys;
546 int size()
const {
return int(weights.size());}
603 XSECUP.resize(NPRUP);
604 XERRUP.resize(NPRUP);
605 XMAXUP.resize(NPRUP);
677 : NUP(0), IDPRUP(0), XWGTUP(0.0), XPDWUP(0.0, 0.0),
678 SCALUP(0.0), AQEDUP(0.0), AQCDUP(0.0), heprup(0) {}
765 vector< vector<double> >
PUP;
828 : filename(filenameIn), intstream(nullptr), file(nullptr), version() {
829 intstream =
new igzstream(filename.c_str());
835 : filename(
""), intstream(
nullptr), file(is), version() {
841 if (intstream)
delete intstream;
853 filename = filenameIn;
854 if (intstream)
delete intstream;
855 intstream =
new igzstream(filename.c_str());
871 bool readEvent(
HEPEUP * peup = 0);
878 weights_detailed_vec.resize(0);
879 weightnames_detailed_vec.resize(0);
887 if(!getline(*file, currentLine))
return false;
889 replace(currentLine.begin(),currentLine.end(),
'\'',
'\"');
923 string headerComments;
939 vector<double> weights_detailed_vector()
940 {
return weights_detailed_vec; }
941 vector<string> weightnames_detailed_vec;
942 vector<string> weightnames_detailed_vector()
943 {
return weightnames_detailed_vec; }
1005 : file(os), version(3) {}
1010 : intstream(filename.c_str()), file(intstream), version(3) {}
1017 return headerStream;
1032 file <<
"</LesHouchesEvents>" << endl;
1041 bool writeEvent(
HEPEUP * peup = 0,
int pDigits = 15);
1043 string getEventString(
HEPEUP * peup = 0);
1049 string hashline(
string s,
bool comment =
false);
istream * file
Definition: LHEF3.h:904
ostream & initComments()
Add comment lines to the init block with this stream.
Definition: LHEF3.h:1021
pair< int, int > PDFSUP
Definition: LHEF3.h:624
string name
The name of this tag.
Definition: LHEF3.h:42
ostringstream eventStream
Stream to add additional comments to be written together the next event.
Definition: LHEF3.h:1076
string contents
The contents of the tag.
Definition: LHEF3.h:270
LHAinitrwgt()
Default constructor;.
Definition: LHEF3.h:514
int NPRUP
The number of different subprocesses in this file.
Definition: LHEF3.h:632
LHArwgt rwgtSave
Contents of the LHArwgt tag (detailed format)
Definition: LHEF3.h:792
vector< XMLTag * > tags
A vector of sub-tags.
Definition: LHEF3.h:48
map< string, string > attributes
Any other attributes.
Definition: LHEF3.h:352
string currentLine
The last line read in from the stream in getline().
Definition: LHEF3.h:907
map< string, string > attributes
Any other attributes.
Definition: LHEF3.h:462
vector< double > VTIMUP
Definition: LHEF3.h:769
void clearEvent()
Reset values of all event-related members to their defaults.
Definition: LHEF3.h:874
string contents
The contents of the tag.
Definition: LHEF3.h:532
map< string, string > attributes
Any other attributes.
Definition: LHEF3.h:795
vector< pair< int, int > > MOTHUP
Definition: LHEF3.h:757
LHAinitrwgt initrwgt
Contents of the LHAinitrwgt tag.
Definition: LHEF3.h:649
Writer(string filename)
Definition: LHEF3.h:1009
double AQEDUP
The value of the QED coupling used in this event.
Definition: LHEF3.h:744
HEPRUP heprup
The standard init information.
Definition: LHEF3.h:1067
bool setup(string filenameIn)
Definition: LHEF3.h:852
void resize(int nup)
Definition: LHEF3.h:709
vector< int > LPRUP
The subprocess code for the different subprocesses.
Definition: LHEF3.h:646
LHAweights weightsSave
Contents of the LHAweights tag (compressed format)
Definition: LHEF3.h:789
vector< double > XERRUP
Definition: LHEF3.h:639
double mups
Definition: LHEF3.h:308
string id
The identification number of this weight tag.
Definition: LHEF3.h:417
string contents
The contents of the tag.
Definition: LHEF3.h:355
HEPEUP & operator=(const HEPEUP &x)
Assignment operator.
Definition: LHEF3.h:687
bool getattr(string n, double &v) const
Definition: LHEF3.h:55
void clear()
Function to reset this object.
Definition: LHEF3.h:524
pair< double, double > XPDWUP
Definition: LHEF3.h:737
vector< long > IDUP
The PDG id's for the particle entries in this event.
Definition: LHEF3.h:750
ostream & eventComments()
Add comment lines to the next event to be written out with this stream.
Definition: LHEF3.h:1026
double SCALUP
The default scale in this event.
Definition: LHEF3.h:314
Collect different scales relevant for an event.
Definition: LHEF3.h:281
string contents
The contents of the tag.
Definition: LHEF3.h:493
ostringstream initStream
Stream to add additional comments to be put in the init block.
Definition: LHEF3.h:1070
vector< int > ISTUP
The status codes for the particle entries in this event.
Definition: LHEF3.h:753
void list_end_tag()
Write out the final XML end-tag.
Definition: LHEF3.h:1031
The LHAweights struct represents the information in a weights tag.
Definition: LHEF3.h:245
HEPEUP hepeup
The standard information about the event we will write next.
Definition: LHEF3.h:1073
~HEPRUP()
Destructor.
Definition: LHEF3.h:589
void clear()
Clear the HEPEUP object.
Definition: LHEF3.h:702
LHAwgt(double defwgt=1.0)
Empty constructor.
Definition: LHEF3.h:366
vector< double > XMAXUP
Definition: LHEF3.h:643
map< string, double > weights_detailed
The weights associated with this event, as given by the LHAwgt tags.
Definition: LHEF3.h:780
string contents
The contents of the tag.
Definition: LHEF3.h:317
The LHArwgt assigns a group-name to a set of LHAwgt objects.
Definition: LHEF3.h:473
The LHAinitrwgt assigns a group-name to a set of LHAweightgroup objects.
Definition: LHEF3.h:511
Collect the wgt information.
Definition: LHEF3.h:363
HEPRUP heprup
The standard init information.
Definition: LHEF3.h:926
vector< LHAgenerator > generators
Contents of the LHAgenerator tags.
Definition: LHEF3.h:652
igzstream * intstream
Definition: LHEF3.h:900
vector< vector< double > > PUP
Definition: LHEF3.h:765
string contents
The contents of this tag.
Definition: LHEF3.h:51
pair< double, double > EBMUP
Energy of beam particles given in GeV.
Definition: LHEF3.h:616
map< string, string > attributes
Any other attributes.
Definition: LHEF3.h:500
string name
The generator name used for this file.
Definition: LHEF3.h:346
HEPEUP hepeup
The standard information about the last read event.
Definition: LHEF3.h:932
HEPRUP * heprup
A pointer to the current HEPRUP object.
Definition: LHEF3.h:777
int version
XML file version.
Definition: LHEF3.h:1079
void clear()
Function to reset this object.
Definition: LHEF3.h:444
Collect generator information for an event file.
Definition: LHEF3.h:325
string contents
The weight description associated to this tag.
Definition: LHEF3.h:423
string id
The identification number of this wgt tag.
Definition: LHEF3.h:383
double SCALUP
Definition: LHEF3.h:741
int sizeWeightGroups() const
Return number of weights.
Definition: LHEF3.h:549
map< string, string > attr
The attributes of this tag.
Definition: LHEF3.h:45
void clear()
Function to reset this object.
Definition: LHEF3.h:338
vector< double > weights_compressed
The weights associated with this event, as given by the LHAweights tags.
Definition: LHEF3.h:783
int IDPRUP
The subprocess code for this event (as given in LPRUP).
Definition: LHEF3.h:728
double muf
The factorization scale used for this event.
Definition: LHEF3.h:301
map< string, LHAweight > weights
The vector of weights.
Definition: LHEF3.h:458
bool getattr(string n, string &v) const
Definition: LHEF3.h:91
void clear()
Function to reset this object.
Definition: LHEF3.h:410
map< string, double > attributes
Any other scales reported by the matrix element generator.
Definition: LHEF3.h:311
string version
The generator version used for this file.
Definition: LHEF3.h:349
void clear()
Function to reset this object.
Definition: LHEF3.h:294
~XMLTag()
The destructor also destroys any sub-tags.
Definition: LHEF3.h:36
The LHAweightgroup assigns a group-name to a set of LHAweight objects.
Definition: LHEF3.h:431
ofstream intstream
Definition: LHEF3.h:1055
HEPRUP & operator=(const HEPRUP &x)
Assignment operator.
Definition: LHEF3.h:570
int size() const
Return number of weights.
Definition: LHEF3.h:546
bool getLine()
Used internally to read a single line from the stream.
Definition: LHEF3.h:885
vector< double > XSECUP
The cross sections for the different subprocesses in pb.
Definition: LHEF3.h:635
void clear()
Function to reset this object.
Definition: LHEF3.h:376
double weight() const
Return the main weight for this event.
Definition: LHEF3.h:715
static vector< XMLTag * > findXMLTags(string str, string *leftover=0)
Definition: LHEF3.h:100
void list(ostream &os) const
Print out this tag to a stream.
Definition: LHEF3.h:223
int version
XML file version.
Definition: LHEF3.h:915
double contents
The weight associated to this tag.
Definition: LHEF3.h:389
LHAweight(string defname="")
Empty constructor.
Definition: LHEF3.h:400
static const pos_t end
Convenient alias for npos.
Definition: LHEF3.h:33
ostream & file
Definition: LHEF3.h:1059
void resize()
Definition: LHEF3.h:602
~Reader()
Clean up.
Definition: LHEF3.h:840
Writer(ostream &os)
Definition: LHEF3.h:1004
vector< double > weights_detailed_vec
The detailed weights associated with this event, linearized to a vector.
Definition: LHEF3.h:938
LHAgenerator()
Empty constructor.
Definition: LHEF3.h:328
double mur
The renormalization scale used for this event.
Definition: LHEF3.h:304
double AQCDUP
The value of the QCD coupling used in this event.
Definition: LHEF3.h:747
map< string, LHAweight > weights
A map of the LHAweight tags, indexed by name.
Definition: LHEF3.h:658
LHArwgt()
Default constructor;.
Definition: LHEF3.h:476
int size() const
Return number of weights.
Definition: LHEF3.h:503
void clear()
Function to reset this object.
Definition: LHEF3.h:257
double XWGTUP
The weight for this event.
Definition: LHEF3.h:731
Reader(string filenameIn)
Definition: LHEF3.h:827
string contents
The contents of the tag.
Definition: LHEF3.h:452
string::size_type pos_t
Convenient typdef.
Definition: LHEF3.h:30
bool getattr(string n, long &v) const
Definition: LHEF3.h:73
LHAscales(double defscale=-1.0)
Empty constructor.
Definition: LHEF3.h:284
map< string, string > attributes
Any other attributes.
Definition: LHEF3.h:420
string outsideBlock
Definition: LHEF3.h:919
map< string, string > attributes
Any other attributes.
Definition: LHEF3.h:386
pair< int, int > PDFGUP
Definition: LHEF3.h:620
map< string, LHAwgt > wgts
The map of weights.
Definition: LHEF3.h:496
bool isGood
Save if the initialisation worked.
Definition: LHEF3.h:912
string name
The name.
Definition: LHEF3.h:455
string headerBlock
All lines from the header block.
Definition: LHEF3.h:922
string filename
Name of file-to-be-read.
Definition: LHEF3.h:896
Header for classes to set beam momentum and interaction vertex spread.
Definition: Analysis.h:20
HEPEUP()
Default constructor.
Definition: LHEF3.h:676
pair< long, long > IDBMUP
PDG id's of beam particles. (first/second is in +/-z direction).
Definition: LHEF3.h:613
LHAweights()
Initialize default values.
Definition: LHEF3.h:248
~Writer()
The destructor.
Definition: LHEF3.h:1013
vector< double > SPINUP
Definition: LHEF3.h:774
map< string, LHAweightgroup > weightgroups
A map of the LHAweightgroup tags, indexed by name.
Definition: LHEF3.h:655
vector< double > weights
The weights of this event.
Definition: LHEF3.h:264
LHAweightgroup()
Default constructor;.
Definition: LHEF3.h:434
ostringstream headerStream
Stream to add all lines in the header block.
Definition: LHEF3.h:1064
void resize(int nrup)
Definition: LHEF3.h:594
void clear()
Function to reset this object.
Definition: LHEF3.h:486
string eventComments
Additional comments found with the last read event.
Definition: LHEF3.h:935
int NUP
The number of particle entries in the current event.
Definition: LHEF3.h:725
string initComments
Additional comments found in the init block.
Definition: LHEF3.h:929
int size() const
Return number of weights.
Definition: LHEF3.h:273
map< string, string > attributes
Any other attributes.
Definition: LHEF3.h:543
~HEPEUP()
Destructor.
Definition: LHEF3.h:694
int size() const
Return number of weights.
Definition: LHEF3.h:465
vector< pair< int, int > > ICOLUP
Definition: LHEF3.h:761
map< string, LHAweightgroup > weightgroups
The vector of weightgroup's.
Definition: LHEF3.h:539
bool getattr(string n, bool &v) const
Definition: LHEF3.h:64
Collect the wgt information.
Definition: LHEF3.h:397
LHAscales scalesSave
Contents of the LHAscales tag.
Definition: LHEF3.h:786
bool getattr(string n, int &v) const
Definition: LHEF3.h:82
ostream & headerBlock()
Add header lines consisting of XML code with this stream.
Definition: LHEF3.h:1016
HEPRUP()
Default constructor.
Definition: LHEF3.h:567
int IDWTUP
Definition: LHEF3.h:629
map< string, string > attributes
Any other attributes.
Definition: LHEF3.h:267
HEPEUP(const HEPEUP &x)
Copy constructor.
Definition: LHEF3.h:681
map< string, LHAweight > weights
The vector of weight's.
Definition: LHEF3.h:535