-
Notifications
You must be signed in to change notification settings - Fork 4
/
varyXS_01.cpp
167 lines (140 loc) · 4.63 KB
/
varyXS_01.cpp
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
// c++ -o varyXS_01 `root-config --glibs --cflags` -lm varyXS_01.cpp
#include "LHEF.h"
#include <iomanip>
#include <vector>
#include <map>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include "LHEF.h"
#include "TLorentzVector.h"
#include <algorithm>
#include <functional>
#include "TH1.h"
#include "TH2.h"
#include "TFile.h"
using namespace std ;
// find daughters for a particle
vector<int> daughters (const LHEF::HEPEUP & event, int PID)
{
vector<int> result ;
for (int iPart = 0 ; iPart < event.IDUP.size () ; ++iPart)
{
pair <int, int> mothers = event.MOTHUP.at (iPart) ;
if (mothers.first != mothers.second) continue ;
if (mothers.first == PID) result.push_back (iPart) ;
}
return result ;
}
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
int splitString (vector<string>& fields, const string & work, char delim, int rep = 0) {
if (!fields.empty ()) fields.clear () ; // empty vector if necessary
string buf = "" ;
int i = 0;
while (i < work.length ()) {
if (work[i] != delim)
buf += work[i] ;
else if (rep == 1) {
fields.push_back (buf) ;
buf = "";
} else if (buf.length() > 0) {
fields.push_back (buf) ;
buf = "" ;
}
i++;
}
if (!buf.empty ())
fields.push_back (buf) ;
return fields.size () ;
}
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
TLorentzVector buildP (const LHEF::HEPEUP & event, int iPart)
{
TLorentzVector dummy ;
dummy.SetPxPyPzE (
event.PUP.at (iPart).at (0), // px
event.PUP.at (iPart).at (1), // py
event.PUP.at (iPart).at (2), // pz
event.PUP.at (iPart).at (3) // E
) ;
return dummy ;
}
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
int main(int argc, char ** argv)
{
if(argc < 2)
{
cout << "Usage: " << argv[0]
<< " input.lhe" << endl ;
return -1;
}
std::ifstream ifs (argv[1]) ;
LHEF::Reader reader (ifs) ;
TH1F * h_higgsPt[7] ;
TString suffix[7] = {"1_1", "h_h", "1_h", "h_1", "1_2", "2_1", "2_2"} ;
for (int iScale = 0 ; iScale < 7 ; ++iScale)
{
TString name = "h_higgsPt_" + suffix[iScale] ;
TH1F * dummy = new TH1F (name, name, 250 , 0 , 1000 ) ;
h_higgsPt[iScale] = dummy ;
}
int counter = 0 ;
//PG loop over input events
while (reader.readEvent ())
{
if ( reader.outsideBlock.length() ) std::cout << reader.outsideBlock;
if (counter++ % 10000 == 0)
cerr << "reading event " << counter << endl ;
// cout << reader.eventComments << endl ;
vector<string> comments ;
splitString (comments, reader.eventComments, '\n') ;
// cout << comments.size () << endl ;
// cout << comments.at (1) << endl ;
vector<double> weights ;
for (int iString = 1 ; iString < comments.size () ; ++iString)
{
vector<string> words ;
splitString (words, comments.at (iString), ' ') ;
float renFact = atof (words.at (3).c_str ()) ;
float facFact = atof (words.at (4).c_str ()) ;
double weight = atof (words.at (2).c_str ()) ;
// if (renFact / facFact < 0.5 || renFact / facFact > 2) continue ;
weights.push_back (weight) ;
}
// cout << weights.size () << endl ;
if (weights.size () < 7)
{
cerr << "ERROR too few weigths: " << weights.size ()
<< " in event " << (counter - 1) << endl ;
cerr << "skipping event" << endl ;
continue ;
}
TLorentzVector momentum ;
// loop over particles in the event
for (int iPart = 0 ; iPart < reader.hepeup.IDUP.size () ; ++iPart)
{
// outgoing particles
if (reader.hepeup.ISTUP.at (iPart) == 1)
{
if (abs (reader.hepeup.IDUP.at (iPart)) == 25)
{
momentum = buildP (reader.hepeup, iPart) ;
}
} // outgoing particles
} // loop over particles in the event
for (int iScale = 0 ; iScale < 7 ; ++iScale)
{
h_higgsPt[iScale]->Fill (momentum.Pt (), weights.at (iScale)) ;
// cout << weights.at (iScale) << endl ;
}
} //PG loop over input events
cout << "CROSS SECTION " << h_higgsPt[0]->Integral () << endl ;
cout << "entries " << h_higgsPt[0]->GetEntries () << endl ;
TFile out ("varyXS_01.root", "recreate") ;
out.cd () ;
for (int iScale = 0 ; iScale < 7 ; ++iScale)
h_higgsPt[iScale]->Write () ;
out.Close () ;
return 0 ;
}