@@ -6,31 +6,34 @@ def print_header(fout):
6
6
fout .write ('#ifndef PUWEIGHT_H\n ' )
7
7
fout .write ('#define PUWEIGHT_H\n ' )
8
8
fout .write ('\n ' )
9
- fout .write ('#include<vector>\n ' )
10
- fout .write ('#include<iostream>\n ' )
11
- fout .write ('#include<string>\n ' )
9
+ fout .write ('#include <iostream>\n ' )
10
+ fout .write ('#include <TString.h>\n ' )
12
11
fout .write ('\n ' )
13
- fout .write ('std::vector<double> puweight_central_2016nonAPV = { };\n ' )
14
- fout .write ('std::vector<double> puweight_central_2016APV = { };\n ' )
15
- fout .write ('std::vector<double> puweight_central_2017 = { };\n ' )
16
- fout .write ('std::vector<double> puweight_central_2018 = { };\n ' )
17
- fout .write ('std::vector<double> puweight_central_2018B = { };\n ' )
18
- fout .write ('std::vector<double> puweight_up_2016nonAPV = { };\n ' )
19
- fout .write ('std::vector<double> puweight_up_2016APV = { };\n ' )
20
- fout .write ('std::vector<double> puweight_up_2017 = { };\n ' )
21
- fout .write ('std::vector<double> puweight_up_2018 = { };\n ' )
22
- fout .write ('std::vector<double> puweight_up_2018B = { };\n ' )
23
- fout .write ('std::vector<double> puweight_down_2016nonAPV = { };\n ' )
24
- fout .write ('std::vector<double> puweight_down_2016APV = { };\n ' )
25
- fout .write ('std::vector<double> puweight_down_2017 = { };\n ' )
26
- fout .write ('std::vector<double> puweight_down_2018 = { };\n ' )
27
- fout .write ('std::vector<double> puweight_down_2018B = { };\n ' )
12
+ fout .write ('#define nPUbins 99\n ' )
13
+ fout .write ('\n ' )
14
+ fout .write ('using namespace std;\n ' )
15
+ fout .write ('\n ' )
16
+ fout .write ('double *puweight_central_2016nonAPV = new double[nPUbins];\n ' )
17
+ fout .write ('double *puweight_central_2016APV = new double[nPUbins];\n ' )
18
+ fout .write ('double *puweight_central_2017 = new double[nPUbins];\n ' )
19
+ fout .write ('double *puweight_central_2018 = new double[nPUbins];\n ' )
20
+ fout .write ('double *puweight_central_2018B = new double[nPUbins];\n ' )
21
+ fout .write ('double *puweight_up_2016nonAPV = new double[nPUbins];\n ' )
22
+ fout .write ('double *puweight_up_2016APV = new double[nPUbins];\n ' )
23
+ fout .write ('double *puweight_up_2017 = new double[nPUbins];\n ' )
24
+ fout .write ('double *puweight_up_2018 = new double[nPUbins];\n ' )
25
+ fout .write ('double *puweight_up_2018B = new double[nPUbins];\n ' )
26
+ fout .write ('double *puweight_down_2016nonAPV = new double[nPUbins];\n ' )
27
+ fout .write ('double *puweight_down_2016APV = new double[nPUbins];\n ' )
28
+ fout .write ('double *puweight_down_2017 = new double[nPUbins];\n ' )
29
+ fout .write ('double *puweight_down_2018 = new double[nPUbins];\n ' )
30
+ fout .write ('double *puweight_down_2018B = new double[nPUbins];\n ' )
28
31
fout .write ('\n ' )
29
32
30
33
def print_function_h (fout ):
31
- fout .write ('double get_puWeight(const unsigned int nTrueInt, const std::string year, const std::string var);\n ' )
34
+ fout .write ('double get_puWeight(const unsigned int nTrueInt, const TString year, const TString var);\n ' )
32
35
fout .write ('\n ' )
33
- fout .write ('inline void setWeights () {\n ' )
36
+ fout .write ('inline void set_puWeights () {\n ' )
34
37
35
38
def print_footer (fout ):
36
39
fout .write ('}\n ' )
@@ -40,40 +43,39 @@ def print_footer(fout):
40
43
def print_cc (fout ,fname ):
41
44
fout .write ('#include "%s.h"\n ' % fname )
42
45
fout .write ('\n ' )
43
- fout .write ('double get_puWeight(const unsigned int nTrueInt, const std::string year, const std::string var="central")\n ' )
46
+ fout .write ('double get_puWeight(const unsigned int nTrueInt, const TString year, const TString var="central")\n ' )
44
47
fout .write ('{\n ' )
45
- fout .write ('\t setWeights();\n ' )
46
48
fout .write ('\t unsigned int npu = nTrueInt;\n ' )
47
49
fout .write ('\t if ( npu < 0 ) npu = 0;\n ' )
48
- fout .write ('\t if ( npu >= puweight_central_2018.size() ) npu = puweight_central_2018.size() -1;\n ' )
49
- fout .write ('\t if ( var.compare( "central")==0 ) {\n ' )
50
- fout .write ('\t \t if ( year.compare( "2016nonAPV")==0 ) return puweight_central_2016nonAPV.at( npu) ;\n ' )
51
- fout .write ('\t \t else if ( year.compare( "2016APV")==0 ) return puweight_central_2016APV.at( npu) ;\n ' )
52
- fout .write ('\t \t else if ( year.compare( "2017")==0 ) return puweight_central_2017.at( npu) ;\n ' )
53
- fout .write ('\t \t else if ( year.compare( "2018")==0 ) return puweight_central_2018.at( npu) ;\n ' )
54
- fout .write ('\t \t else if ( year.compare( "2018B")==0 ) return puweight_central_2018B.at( npu) ;\n ' )
50
+ fout .write ('\t if ( npu >= nPUbins ) npu = nPUbins -1;\n ' )
51
+ fout .write ('\t if ( var== "central" ) {\n ' )
52
+ fout .write ('\t \t if ( year== "2016nonAPV" ) return puweight_central_2016nonAPV[ npu] ;\n ' )
53
+ fout .write ('\t \t else if ( year== "2016APV" ) return puweight_central_2016APV[ npu] ;\n ' )
54
+ fout .write ('\t \t else if ( year== "2017" ) return puweight_central_2017[ npu] ;\n ' )
55
+ fout .write ('\t \t else if ( year== "2018" ) return puweight_central_2018[ npu] ;\n ' )
56
+ fout .write ('\t \t else if ( year== "2018B" ) return puweight_central_2018B[ npu] ;\n ' )
55
57
fout .write ('\t \t else {\n ' )
56
58
fout .write ('\t \t \t std::cout << "WARNING: unknown year, returning unity piluep weight!" << std::endl;\n ' )
57
59
fout .write ('\t \t \t return 1.0;\n ' )
58
60
fout .write ('\t \t }\n ' )
59
61
fout .write ('\t }\n ' )
60
- fout .write ('\t else if ( var.compare( "up")==0 ) {\n ' )
61
- fout .write ('\t \t if ( year.compare( "2016nonAPV")==0 ) return puweight_up_2016nonAPV.at( npu) ;\n ' )
62
- fout .write ('\t \t else if ( year.compare( "2016APV")==0 ) return puweight_up_2016APV.at( npu) ;\n ' )
63
- fout .write ('\t \t else if ( year.compare( "2017")==0 ) return puweight_up_2017.at( npu) ;\n ' )
64
- fout .write ('\t \t else if ( year.compare( "2018")==0 ) return puweight_up_2018.at( npu) ;\n ' )
65
- fout .write ('\t \t else if ( year.compare( "2018B")==0 ) return puweight_up_2018B.at( npu) ;\n ' )
62
+ fout .write ('\t else if ( var== "up" ) {\n ' )
63
+ fout .write ('\t \t if ( year== "2016nonAPV" ) return puweight_up_2016nonAPV[ npu] ;\n ' )
64
+ fout .write ('\t \t else if ( year== "2016APV" ) return puweight_up_2016APV[ npu] ;\n ' )
65
+ fout .write ('\t \t else if ( year== "2017" ) return puweight_up_2017[ npu] ;\n ' )
66
+ fout .write ('\t \t else if ( year== "2018" ) return puweight_up_2018[ npu] ;\n ' )
67
+ fout .write ('\t \t else if ( year== "2018B" ) return puweight_up_2018B[ npu] ;\n ' )
66
68
fout .write ('\t \t else {\n ' )
67
69
fout .write ('\t \t \t std::cout << "WARNING: unknown year, returning unity piluep weight!" << std::endl;\n ' )
68
70
fout .write ('\t \t \t return 1.0;\n ' )
69
71
fout .write ('\t \t }\n ' )
70
72
fout .write ('\t }\n ' )
71
- fout .write ('\t else if ( var.compare( "down")==0 ) {\n ' )
72
- fout .write ('\t \t if ( year.compare( "2016nonAPV")==0 ) return puweight_down_2016nonAPV.at( npu) ;\n ' )
73
- fout .write ('\t \t else if ( year.compare( "2016APV")==0 ) return puweight_down_2016APV.at( npu) ;\n ' )
74
- fout .write ('\t \t else if ( year.compare( "2017")==0 ) return puweight_down_2017.at( npu) ;\n ' )
75
- fout .write ('\t \t else if ( year.compare( "2018")==0 ) return puweight_down_2018.at( npu) ;\n ' )
76
- fout .write ('\t \t else if ( year.compare( "2018B")==0 ) return puweight_down_2018B.at( npu) ;\n ' )
73
+ fout .write ('\t else if ( var== "down" ) {\n ' )
74
+ fout .write ('\t \t if ( year== "2016nonAPV" ) return puweight_down_2016nonAPV[ npu] ;\n ' )
75
+ fout .write ('\t \t else if ( year== "2016APV" ) return puweight_down_2016APV[ npu] ;\n ' )
76
+ fout .write ('\t \t else if ( year== "2017" ) return puweight_down_2017[ npu] ;\n ' )
77
+ fout .write ('\t \t else if ( year== "2018" ) return puweight_down_2018[ npu] ;\n ' )
78
+ fout .write ('\t \t else if ( year== "2018B" ) return puweight_down_2018B[ npu] ;\n ' )
77
79
fout .write ('\t \t else {\n ' )
78
80
fout .write ('\t \t \t std::cout << "WARNING: unknown year, returning unity piluep weight!" << std::endl;\n ' )
79
81
fout .write ('\t \t \t return 1.0;\n ' )
@@ -116,7 +118,7 @@ def get_weights(fout, year = "2018", var = "central", mcsample="ttbar"):
116
118
117
119
for b in range (1 , hdata .GetNbinsX ()+ 1 ):
118
120
tw = hdata .GetBinContent (b );
119
- fout .write ("\t " + wname + ".push_back(" + str (tw )+ ") ;\n " )
121
+ fout .write ("\t " + wname + "[" + str ( b - 1 ) + "] = " + str (tw )+ ";\n " )
120
122
fout .write ("\n " )
121
123
122
124
indir = "./data/"
0 commit comments