forked from ajgilbert/EFT2Obs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LHEF.h
3407 lines (2914 loc) · 85.8 KB
/
LHEF.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- C++ -*-
#ifndef HEPMC3_LHEF_H
#define HEPMC3_LHEF_H
//
// This is the declaration of the Les Houches Event File classes,
// implementing a simple C++ parser/writer for Les Houches Event files.
// Copyright (C) 2009-2013 Leif Lonnblad
//
// The code is licenced under version 2 of the GPL, see COPYING for details.
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
//
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <stdexcept>
#include <cstdlib>
#include <cmath>
#include <limits>
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288
#endif
/**
* @brief Les Houches event file classes.
*
* The namespace containing helper classes and Reader and Writer
* classes for handling Les Houches event files.
*
* @ingroup LHEF
*/
namespace LHEF {
/**
* Helper struct for output of attributes.
*/
template <typename T>
struct OAttr {
/**
* Constructor
*/
OAttr(std::string n, const T & v): name(n), val(v) {}
/**
* The name of the attribute being printed.
*/
std::string name;
/**
* The value of the attribute being printed.
*/
T val;
};
/**
* Output manipulator for writing attributes.
*/
template <typename T>
OAttr<T> oattr(std::string name, const T & value) {
return OAttr<T>(name, value);
}
/**
* Output operator for attributes.
*/
template <typename T>
std::ostream & operator<<(std::ostream & os, const OAttr<T> & oa) {
os << " " << oa.name << "=\"" << oa.val << "\"";
return os;
}
/**
* The XMLTag struct is used to represent all information within an
* XML tag. It contains the attributes as a map, any sub-tags as a
* vector of pointers to other XMLTag objects, and any other
* information as a single string.
*/
struct XMLTag {
/**
* Convenient typdef.
*/
typedef std::string::size_type pos_t;
/**
* Convenient typdef.
*/
typedef std::map<std::string,std::string> AttributeMap;
/**
* Convenient alias for npos.
*/
static const pos_t end = std::string::npos;
/**
* Default constructor.
*/
XMLTag() {}
/**
* The destructor also destroys any sub-tags.
*/
~XMLTag() {
for ( int i = 0, N = tags.size(); i < N; ++i ) delete tags[i];
}
/**
* The name of this tag.
*/
std::string name;
/**
* The attributes of this tag.
*/
AttributeMap attr;
/**
* A vector of sub-tags.
*/
std::vector<XMLTag*> tags;
/**
* The contents of this tag.
*/
std::string contents;
/**
* Find an attribute named \a n and set the double variable \a v to
* the corresponding value. @return false if no attribute was found.
*/
bool getattr(std::string n, double & v) const {
AttributeMap::const_iterator it = attr.find(n);
if ( it == attr.end() ) return false;
v = std::atof(it->second.c_str());
return true;
}
/**
* Find an attribute named \a n and set the bool variable \a v to
* true if the corresponding value is "yes". @return false if no
* attribute was found.
*/
bool getattr(std::string n, bool & v) const {
AttributeMap::const_iterator it = attr.find(n);
if ( it == attr.end() ) return false;
if ( it->second == "yes" ) v = true;
return true;
}
/**
* Find an attribute named \a n and set the long variable \a v to
* the corresponding value. @return false if no attribute was found.
*/
bool getattr(std::string n, long & v) const {
AttributeMap::const_iterator it = attr.find(n);
if ( it == attr.end() ) return false;
v = std::atoi(it->second.c_str());
return true;
}
/**
* Find an attribute named \a n and set the long variable \a v to
* the corresponding value. @return false if no attribute was found.
*/
bool getattr(std::string n, int & v) const {
AttributeMap::const_iterator it = attr.find(n);
if ( it == attr.end() ) return false;
v = int(std::atoi(it->second.c_str()));
return true;
}
/**
* Find an attribute named \a n and set the string variable \a v to
* the corresponding value. @return false if no attribute was found.
*/
bool getattr(std::string n, std::string & v) const {
AttributeMap::const_iterator it = attr.find(n);
if ( it == attr.end() ) return false;
v = it->second;
return true;
}
/**
* Scan the given string and return all XML tags found as a vector
* of pointers to XMLTag objects. Text which does not belong to any
* tag is stored in tags without name and in the string pointed to
* by leftover (if not null).
*/
static std::vector<XMLTag*> findXMLTags(std::string str,
std::string * leftover = 0) {
std::vector<XMLTag*> tags;
pos_t curr = 0;
while ( curr != end ) {
// Find the first tag
pos_t begin = str.find("<", curr);
// Check for comments
if ( begin != end && str.find("<!--", curr) == begin ) {
pos_t endcom = str.find("-->", begin);
tags.push_back(new XMLTag());
if ( endcom == end ) {
tags.back()->contents = str.substr(curr);
if ( leftover ) *leftover += str.substr(curr);
return tags;
}
tags.back()->contents = str.substr(curr, endcom - curr);
if ( leftover ) *leftover += str.substr(curr, endcom - curr);
curr = endcom;
continue;
}
if ( begin != curr ) {
tags.push_back(new XMLTag());
tags.back()->contents = str.substr(curr, begin - curr);
if ( leftover ) *leftover += str.substr(curr, begin - curr);
}
if ( begin == end || begin > str.length() - 3 || str[begin + 1] == '/' )
return tags;
pos_t close = str.find(">", curr);
if ( close == end ) return tags;
// find the tag name.
curr = str.find_first_of(" \t\n/>", begin);
tags.push_back(new XMLTag());
tags.back()->name = str.substr(begin + 1, curr - begin - 1);
while ( true ) {
// Now skip some white space to see if we can find an attribute.
curr = str.find_first_not_of(" \t\n", curr);
if ( curr == end || curr >= close ) break;
pos_t tend = str.find_first_of("= \t\n", curr);
if ( tend == end || tend >= close ) break;
std::string name = str.substr(curr, tend - curr);
curr = str.find("=", curr) + 1;
// OK now find the beginning and end of the atribute.
curr = str.find_first_of("\"'", curr);
if ( curr == end || curr >= close ) break;
char quote = str[curr];
pos_t bega = ++curr;
curr = str.find(quote, curr);
while ( curr != end && str[curr - 1] == '\\' )
curr = str.find(quote, curr + 1);
std::string value = str.substr(bega, curr == end? end: curr - bega);
tags.back()->attr[name] = value;
++curr;
}
curr = close + 1;
if ( str[close - 1] == '/' ) continue;
pos_t endtag = str.find("</" + tags.back()->name + ">", curr);
if ( endtag == end ) {
tags.back()->contents = str.substr(curr);
curr = endtag;
} else {
tags.back()->contents = str.substr(curr, endtag - curr);
curr = endtag + tags.back()->name.length() + 3;
}
std::string leftovers;
tags.back()->tags = findXMLTags(tags.back()->contents, &leftovers);
if ( leftovers.find_first_not_of(" \t\n") == end ) leftovers="";
tags.back()->contents = leftovers;
}
return tags;
}
/**
* Delete all tags in a vector.
*/
static void deleteAll(std::vector<XMLTag*> & tags) {
while ( tags.size() && tags.back() ) {
delete tags.back();
tags.pop_back();
}
}
/**
* Print out this tag to a stream.
*/
void print(std::ostream & os) const {
if ( name.empty() ) {
os << contents;
return;
}
os << "<" << name;
for ( AttributeMap::const_iterator it = attr.begin();
it != attr.end(); ++it )
os << oattr(it->first, it->second);
if ( contents.empty() && tags.empty() ) {
os << "/>" << std::endl;
return;
}
os << ">";
for ( int i = 0, N = tags.size(); i < N; ++i )
tags[i]->print(os);
os << contents << "</" << name << ">" << std::endl;
}
};
/**
* Helper function to make sure that each line in the string \a s starts with a
* #-character and that the string ends with a new-line.
*/
inline std::string hashline(std::string s) {
std::string ret;
std::istringstream is(s);
std::string ss;
while ( getline(is, ss) ) {
if ( ss.empty() ) continue;
if ( ss.find_first_not_of(" \t") == std::string::npos ) continue;
if ( ss.find('#') == std::string::npos ||
ss.find('#') != ss.find_first_not_of(" \t") ) ss = "# " + ss;
ret += ss + '\n';
}
return ret;
}
/**
* This is the base class of all classes representing xml tags.
*/
struct TagBase {
/**
* Convenient typedef.
*/
typedef XMLTag::AttributeMap AttributeMap;
/**
* Default constructor does nothing.
*/
TagBase() {}
/**
* Main constructor stores the attributes and contents of a tag.
*/
TagBase(const AttributeMap & attr, std::string conts = std::string()): attributes(attr), contents(conts) {}
/**
* Find an attribute named \a n and set the double variable \a v to
* the corresponding value. Remove the correspondig attribute from
* the list if found and \a erase is true. @return false if no
* attribute was found.
*/
bool getattr(std::string n, double & v, bool erase = true) {
AttributeMap::iterator it = attributes.find(n);
if ( it == attributes.end() ) return false;
v = std::atof(it->second.c_str());
if ( erase) attributes.erase(it);
return true;
}
/**
* Find an attribute named \a n and set the bool variable \a v to
* true if the corresponding value is "yes". Remove the correspondig
* attribute from the list if found and \a erase is true. @return
* false if no attribute was found.
*/
bool getattr(std::string n, bool & v, bool erase = true) {
AttributeMap::iterator it = attributes.find(n);
if ( it == attributes.end() ) return false;
if ( it->second == "yes" ) v = true;
if ( erase) attributes.erase(it);
return true;
}
/**
* Find an attribute named \a n and set the long variable \a v to
* the corresponding value. Remove the correspondig attribute from
* the list if found and \a erase is true. @return false if no
* attribute was found.
*/
bool getattr(std::string n, long & v, bool erase = true) {
AttributeMap::iterator it = attributes.find(n);
if ( it == attributes.end() ) return false;
v = std::atoi(it->second.c_str());
if ( erase) attributes.erase(it);
return true;
}
/**
* Find an attribute named \a n and set the long variable \a v to
* the corresponding value. Remove the correspondig attribute from
* the list if found and \a erase is true. @return false if no
* attribute was found.
*/
bool getattr(std::string n, int & v, bool erase = true) {
AttributeMap::iterator it = attributes.find(n);
if ( it == attributes.end() ) return false;
v = int(std::atoi(it->second.c_str()));
if ( erase) attributes.erase(it);
return true;
}
/**
* Find an attribute named \a n and set the string variable \a v to
* the corresponding value. Remove the correspondig attribute from
* the list if found and \a erase is true. @return false if no
* attribute was found.
*/
bool getattr(std::string n, std::string & v, bool erase = true) {
AttributeMap::iterator it = attributes.find(n);
if ( it == attributes.end() ) return false;
v = it->second;
if ( erase) attributes.erase(it);
return true;
}
/**
* print out ' name="value"' for all unparsed attributes.
*/
void printattrs(std::ostream & file) const {
for ( AttributeMap::const_iterator it = attributes.begin();
it != attributes.end(); ++ it )
file << oattr(it->first, it->second);
}
/**
* Print out end of tag marker. Print contents if not empty else
* print simple close tag.
*/
void closetag(std::ostream & file, std::string tag) const {
if ( contents.empty() )
file << "/>\n";
else if ( contents.find('\n') != std::string::npos )
file << ">\n" << contents << "\n</" << tag << ">\n";
else
file << ">" << contents << "</" << tag << ">\n";
}
/**
* The attributes of this tag;
*/
XMLTag::AttributeMap attributes;
/**
* The contents of this tag.
*/
mutable std::string contents;
/**
* Static string token for truth values.
*/
static std::string yes() { return "yes"; }
};
/**
* The Generator class contains information about a generator used in a run.
*/
struct Generator : public TagBase {
/**
* Construct from XML tag.
*/
Generator(const XMLTag & tag)
: TagBase(tag.attr, tag.contents) {
getattr("name", name);
getattr("version", version);
}
/**
* Print the object as a generator tag.
*/
void print(std::ostream & file) const {
file << "<generator";
if ( !name.empty() ) file << oattr("name", name);
if ( !version.empty() ) file << oattr("version", version);
printattrs(file);
closetag(file, "generator");
}
/**
* The name of the generator.
*/
std::string name;
/**
* The version of the generator.
*/
std::string version;
};
/**
* The XSecInfo class contains information given in the xsecinfo tag.
*/
struct XSecInfo : public TagBase {
/**
* Intitialize default values.
*/
XSecInfo(): neve(-1), ntries(-1), totxsec(0.0), xsecerr(0.0), maxweight(1.0),
meanweight(1.0), negweights(false), varweights(false) {}
/**
* Create from XML tag
*/
XSecInfo(const XMLTag & tag)
: TagBase(tag.attr, tag.contents), neve(-1), ntries(-1),
totxsec(0.0), xsecerr(0.0), maxweight(1.0), meanweight(1.0),
negweights(false), varweights(false) {
if ( !getattr("neve", neve) )
throw std::runtime_error("Found xsecinfo tag without neve attribute "
"in Les Houches Event File.");
ntries = neve;
getattr("ntries", ntries);
if ( !getattr("totxsec", totxsec) )
throw std::runtime_error("Found xsecinfo tag without totxsec "
"attribute in Les Houches Event File.");
getattr("xsecerr", xsecerr);
getattr("weightname", weightname);
getattr("maxweight", maxweight);
getattr("meanweight", meanweight);
getattr("negweights", negweights);
getattr("varweights", varweights);
}
/**
* Print out an XML tag.
*/
void print(std::ostream & file) const {
file << "<xsecinfo" << oattr("neve", neve)
<< oattr("totxsec", totxsec);
if ( maxweight != 1.0 )
file << oattr("maxweight", maxweight)
<< oattr("meanweight", meanweight);
if ( ntries > neve ) file << oattr("ntries", ntries);
if ( xsecerr > 0.0 ) file << oattr("xsecerr", xsecerr);
if ( !weightname.empty() ) file << oattr("weightname", weightname);
if ( negweights ) file << oattr("negweights", yes());
if ( varweights ) file << oattr("varweights", yes());
printattrs(file);
closetag(file, "xsecinfo");
}
/**
* The number of events.
*/
long neve;
/**
* The number of attempte that was needed to produce the neve events.
*/
long ntries;
/**
* The total cross section in pb.
*/
double totxsec;
/**
* The estimated statistical error on totxsec.
*/
double xsecerr;
/**
* The maximum weight.
*/
double maxweight;
/**
* The average weight.
*/
double meanweight;
/**
* Does the file contain negative weights?
*/
bool negweights;
/**
* Does the file contain varying weights?
*/
bool varweights;
/**
* The named weight to which this object belongs.
*/
std::string weightname;
};
/**
* Convenient Alias.
*/
typedef std::map<std::string,XSecInfo> XSecInfos;
/**
* Simple struct to store information about separate eventfiles to be
* loaded.
*/
struct EventFile : public TagBase {
/**
* Intitialize default values.
*/
EventFile(): filename(""), neve(-1), ntries(-1) {}
/**
* Create from XML tag
*/
EventFile(const XMLTag & tag)
: TagBase(tag.attr, tag.contents), filename(""), neve(-1), ntries(-1) {
if ( !getattr("name", filename) )
throw std::runtime_error("Found eventfile tag without name attribute "
"in Les Houches Event File.");
getattr("neve", neve);
ntries = neve;
getattr("ntries", ntries);
}
/**
* Print out an XML tag.
*/
void print(std::ostream & file) const {
if ( filename.empty() ) return;
file << " <eventfile" << oattr("name", filename);
if ( neve > 0 ) file << oattr("neve", neve);
if ( ntries > neve ) file << oattr("ntries", ntries);
printattrs(file);
closetag(file, "eventfile");
}
/**
* The name of the file.
*/
std::string filename;
/**
* The number of events.
*/
long neve;
/**
* The number of attempte that was needed to produce the neve events.
*/
long ntries;
};
/**
* The Cut class represents a cut used by the Matrix Element generator.
*/
struct Cut : public TagBase {
/**
* Intitialize default values.
*/
Cut(): min(-0.99*std::numeric_limits<double>::max()),
max(0.99*std::numeric_limits<double>::max()) {}
/**
* Create from XML tag.
*/
Cut(const XMLTag & tag,
const std::map<std::string,std::set<long> >& ptypes)
: TagBase(tag.attr),
min(-0.99*std::numeric_limits<double>::max()),
max(0.99*std::numeric_limits<double>::max()) {
if ( !getattr("type", type) )
throw std::runtime_error("Found cut tag without type attribute "
"in Les Houches file");
long tmp;
if ( tag.getattr("p1", np1) ) {
if ( ptypes.find(np1) != ptypes.end() ) {
p1 = ptypes.find(np1)->second;
attributes.erase("p1");
} else {
getattr("p1", tmp);
p1.insert(tmp);
np1 = "";
}
}
if ( tag.getattr("p2", np2) ) {
if ( ptypes.find(np2) != ptypes.end() ) {
p2 = ptypes.find(np2)->second;
attributes.erase("p2");
} else {
getattr("p2", tmp);
p2.insert(tmp);
np2 = "";
}
}
std::istringstream iss(tag.contents);
iss >> min;
if ( iss >> max ) {
if ( min >= max )
min = -0.99*std::numeric_limits<double>::max();
} else
max = 0.99*std::numeric_limits<double>::max();
}
/**
* Print out an XML tag.
*/
void print(std::ostream & file) const {
file << "<cut" << oattr("type", type);
if ( !np1.empty() )
file << oattr("p1", np1);
else
if ( p1.size() == 1 ) file << oattr("p1", *p1.begin());
if ( !np2.empty() )
file << oattr("p2", np2);
else
if ( p2.size() == 1 ) file << oattr("p2", *p2.begin());
printattrs(file);
file << ">";
if ( min > -0.9*std::numeric_limits<double>::max() )
file << min;
else
file << max;
if ( max < 0.9*std::numeric_limits<double>::max() )
file << " " << max;
if ( !contents.empty() ) file << std::endl << contents << std::endl;
file << "</cut>" << std::endl;
}
/**
* Check if a \a id1 matches p1 and \a id2 matches p2. Only non-zero
* values are considered.
*/
bool match(long id1, long id2 = 0) const {
std::pair<bool,bool> ret(false, false);
if ( !id2 ) ret.second = true;
if ( !id1 ) ret.first = true;
if ( p1.find(0) != p1.end() ) ret.first = true;
if ( p1.find(id1) != p1.end() ) ret.first = true;
if ( p2.find(0) != p2.end() ) ret.second = true;
if ( p2.find(id2) != p2.end() ) ret.second = true;
return ret.first && ret.second;
}
/**
* Check if the particles given as a vector of PDG \a id numbers,
* and a vector of vectors of momentum components, \a p, will pass
* the cut defined in this event.
*/
bool passCuts(const std::vector<long> & id,
const std::vector< std::vector<double> >& p ) const {
if ( ( type == "m" && !p2.size() ) || type == "kt" || type == "eta" ||
type == "y" || type == "E" ) {
for ( int i = 0, N = id.size(); i < N; ++i )
if ( match(id[i]) ) {
if ( type == "m" ) {
double v = p[i][4]*p[i][4] - p[i][3]*p[i][3] - p[i][2]*p[i][2]
- p[i][1]*p[i][1];
v = v >= 0.0? std::sqrt(v): -std::sqrt(-v);
if ( outside(v) ) return false;
}
else if ( type == "kt" ) {
if ( outside(std::sqrt(p[i][2]*p[i][2] + p[i][1]*p[i][1])) )
return false;
}
else if ( type == "E" ) {
if ( outside(p[i][4]) ) return false;
}
else if ( type == "eta" ) {
if ( outside(eta(p[i])) ) return false;
}
else if ( type == "y" ) {
if ( outside(rap(p[i])) ) return false;
}
}
}
else if ( type == "m" || type == "deltaR" ) {
for ( int i = 1, N = id.size(); i < N; ++i )
for ( int j = 0; j < i; ++j )
if ( match(id[i], id[j]) || match(id[j], id[i]) ) {
if ( type == "m" ) {
double v = (p[i][4] + p[j][4])*(p[i][4] + p[j][4])
- (p[i][3] + p[j][3])*(p[i][3] + p[j][3])
- (p[i][2] + p[j][2])*(p[i][2] + p[j][2])
- (p[i][1] + p[j][1])*(p[i][1] + p[j][1]);
v = v >= 0.0? std::sqrt(v): -std::sqrt(-v);
if ( outside(v) ) return false;
}
else if ( type == "deltaR" ) {
if ( outside(deltaR(p[i], p[j])) ) return false;
}
}
}
else if ( type == "ETmiss" ) {
double x = 0.0;
double y = 0.0;
for ( int i = 0, N = id.size(); i < N; ++i )
if ( match(id[i]) && !match(0, id[i]) ) {
x += p[i][1];
y += p[i][2];
}
if ( outside(std::sqrt(x*x + y*y)) ) return false;
}
else if ( type == "HT" ) {
double pt = 0.0;
for ( int i = 0, N = id.size(); i < N; ++i )
if ( match(id[i]) && !match(0, id[i]) )
pt += std::sqrt(p[i][1]*p[i][1] + p[i][2]*p[i][2]);
if ( outside(pt) ) return false;
}
return true;
}
/**
* Return the pseudorapidity of a particle with momentum \a p.
*/
static double eta(const std::vector<double> & p) {
double pt2 = p[2]*p[2] + p[1]*p[1];
if ( pt2 != 0.0 ) {
double dum = std::sqrt(pt2 + p[3]*p[3]) + p[3];
if ( dum != 0.0 )
return std::log(dum/std::sqrt(pt2));
}
return p[3] < 0.0? -std::numeric_limits<double>::max():
std::numeric_limits<double>::max();
}
/**
* Return the true rapidity of a particle with momentum \a p.
*/
static double rap(const std::vector<double> & p) {
double pt2 = p[5]*p[5] + p[2]*p[2] + p[1]*p[1];
if ( pt2 != 0.0 ) {
double dum = std::sqrt(pt2 + p[3]*p[3]) + p[3];
if ( dum != 0.0 )
return std::log(dum/std::sqrt(pt2));
}
return p[3] < 0.0? -std::numeric_limits<double>::max():
std::numeric_limits<double>::max();
}
/**
* Return the delta-R of a particle pair with momenta \a p1 and \a p2.
*/
static double deltaR(const std::vector<double> & p1,
const std::vector<double> & p2) {
double deta = eta(p1) - eta(p2);
double dphi = std::atan2(p1[1], p1[2]) - std::atan2(p2[1], p2[2]);
if ( dphi > M_PI ) dphi -= 2.0*M_PI;
if ( dphi < -M_PI ) dphi += 2.0*M_PI;
return std::sqrt(dphi*dphi + deta*deta);
}
/**
* Return true if the given \a value is outside limits.
*/
bool outside(double value) const {
return value < min || value >= max;
}
/**
* The variable in which to cut.
*/
std::string type;
/**
* The first types particle types for which this cut applies.
*/
std::set<long> p1;
/**
* Symbolic name for p1.
*/
std::string np1;
/**
* The second type of particles for which this cut applies.
*/
std::set<long> p2;
/**
* Symbolic name for p1.
*/
std::string np2;
/**
* The minimum value of the variable
*/
double min;
/**
* The maximum value of the variable
*/
double max;
};
/**
* The ProcInfo class represents the information in a procinfo tag.
*/
struct ProcInfo : public TagBase {
/**
* Intitialize default values.
*/
ProcInfo(): iproc(0), loops(0), qcdorder(-1), eworder(-1) {}
/**
* Create from XML tag.
*/
ProcInfo(const XMLTag & tag)
: TagBase(tag.attr, tag.contents),
iproc(0), loops(0), qcdorder(-1), eworder(-1) {
getattr("iproc", iproc);
getattr("loops", loops);
getattr("qcdorder", qcdorder);
getattr("eworder", eworder);
getattr("rscheme", rscheme);
getattr("fscheme", fscheme);
getattr("scheme", scheme);
}
/**
* Print out an XML tag.
*/
void print(std::ostream & file) const {
file << "<procinfo" << oattr("iproc", iproc);
if ( loops >= 0 ) file << oattr("loops", loops);
if ( qcdorder >= 0 ) file << oattr("qcdorder", qcdorder);
if ( eworder >= 0 ) file<< oattr("eworder", eworder);
if ( !rscheme.empty() ) file << oattr("rscheme", rscheme);
if ( !fscheme.empty() ) file << oattr("fscheme", fscheme);
if ( !scheme.empty() ) file << oattr("scheme", scheme);
printattrs(file);
closetag(file, "procinfo");
}
/**
* The id number for the process.
*/
int iproc;
/**
* The number of loops
*/
int loops;
/**
* The number of QCD vertices.
*/
int qcdorder;
/**
* The number of electro-weak vertices.
*/
int eworder;
/**
* The factorization scheme used.
*/
std::string fscheme;
/**
* The renormalization scheme used.
*/
std::string rscheme;
/**
* The NLO scheme used.
*/
std::string scheme;
};
/**
* The MergeInfo class represents the information in a mergeinfo tag.
*/
struct MergeInfo : public TagBase {
/**
* Intitialize default values.
*/
MergeInfo(): iproc(0), mergingscale(0.0), maxmult(false) {}
/**
* Create from XML tag.