-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSignalEffData.cxx
249 lines (194 loc) · 6.88 KB
/
SignalEffData.cxx
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
#include "SignalEffData.h"
//#include <ifstream>
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
void SignalEffData::write(TString id) const {
//goal: be able to write to an ascii file all of the important data members,
//such that I can destroy the object, and recreate it later using the content of the file
//filename constructed from id
TString filename = "SignalEffData.";
filename += id;
filename +=".";
filename += SignalEffDataSuffix_;
filename.Prepend(sedfPath);
ofstream output(filename.Data());
output<<rawYield<<endl<<effCorr<<endl;
// output<<eff_derivative_b<<endl;
// output<<eff_derivative_c<<endl;
// output<<eff_derivative_l<<endl;
for (map<TString, SystInfo >::const_iterator isyst=systematics.begin(); isyst!=systematics.end(); ++isyst) {
output << isyst->first<<" ";
isyst->second.write( &output );
}
output.close();
cout<<" == done writing output file: "<<filename<<endl;
}
SignalEffData::SignalEffData(TString idtoload) :
// id(idtoload),
rawYield(0),
effCorr(1),
yield_JER(0), yield_JER_PU(0),yield_JER_PU_HLT(0)//,eff_derivative_b(0),eff_derivative_c(0),eff_derivative_l(0)
{
//filename constructed from id
TString filename = "SignalEffData.";
filename += idtoload;
filename.Prepend(sedfPath);
ifstream input(filename.Data()); //should check that this is good
input>>rawYield;
input>>effCorr;
// input>>eff_derivative_b;
// input>>eff_derivative_c;
// input>>eff_derivative_l;
TString akey;
while (input>>akey) {
//load the SystInfo from the file using the special ctor
cout<<"==loading key "<<akey<<endl; //DEBUG
systematics[akey] = SystInfo(&input);
}
input.close();
}
SignalEffData::SignalEffData() :
// id("noname"),
rawYield(0),
effCorr(1),
yield_JER(0), yield_JER_PU(0),yield_JER_PU_HLT(0)//,eff_derivative_b(0),eff_derivative_c(0),eff_derivative_l(0)
{
systematics["JES"] = SystInfo();
systematics["btag"] = SystInfo();
systematics["lftag"] = SystInfo();
systematics["PDF"] = SystInfo();
systematics["MET"] = SystInfo();
systematics["PU"] = SystInfo();
systematics["JER"] = SystInfo();
systematics["kFactor"] = SystInfo();
systematics["cleaning"] = SystInfo(1e-2,1e-2,1);
systematics["LepVeto"] = SystInfo(3e-2,3e-2,1);
systematics["trigger"] = SystInfo(); //now going to be done directly in likelihood (at least for MHT leg)
systematics["lumi"] = SystInfo(2.2e-2 , 2.2e-2,1); //final 2011 number is 2.2%
//list of signal systematics:
// JES
// btag efficiency
// PDFs (acceptance)
// (RA2 says they don't do PDF uncertainties on the cross section. so i won't either)
// unc energy (MET)
// PU
// JER
// trigger eff
// MET cleaning
// lepton veto eff
// lumi
// for mSugra, NLO cross section (k factor)
}
SignalEffData::~SignalEffData()
{
systematics.clear();
}
void SignalEffData::setFixedForScan() {
systematics["PU"].plus = 1e-2;
systematics["PU"].minus = -systematics["PU"].plus;
systematics["PU"].status = 1;
systematics["JER"].plus = 1e-2;
systematics["JER"].minus = -systematics["JER"].plus;
systematics["JER"].status = 1;
}
TString SignalEffData::translateVariation(const TString & which) {
//this is a nasty hack that i do not like
//the variations are known only by their differences in name
//these are easily human-readable but don't fit in well with the names I chose to use
//in this class SignalEffData
//for now I will just "translate" them here in a hard-coded way.
//maybe i should use .Contains() but that can be dangerous
// the b-tag ones are not needed anymore
// if (which == "BTagEff03") return "btag"; //hardcoding this 03 is a really bad idea...
// else if (which == "BTagEff04") return "btag"; //a bad idea indeed...
if (which=="JERbias") return "JER";
else if (which=="JES0") return "JES";
else if (which=="METunc0") return "MET";
else if (which =="PUunc0") return "PU";
return which;
}
void SignalEffData::set(const TString & which, float valminus, float valplus) {
TString translatedWhich= translateVariation(which);
map<TString, SystInfo >::iterator it=systematics.find(translatedWhich);
if (it==systematics.end() ) {
cout<<"ERROR -- cannot find in systematics list: "<<translatedWhich<<endl;
return;
}
it->second.minus = valminus;
it->second.plus = valplus;
it->second.status = 2;
}
float SignalEffData::symmetrize(const TString & which) {
float s=-1;
map<TString, SystInfo >::iterator it=systematics.find(which);
if (it==systematics.end() ) {
cout<<"ERROR -- cannot find in systematics list: "<<which<<endl;
}
//realizing now that i symmetrized different results differently!
//for now maintain strict consistency
else if ( it->first=="kFactor" ) { //average the 2 parts of the pair
s = 0.5* (fabs(it->second.plus) + fabs(it->second.minus));
}
else { //return the larger deviation
//for PDF uncertainties for now just store the pre-processed results
float var1= fabs( it->second.plus);
float var2= fabs( it->second.minus);
s = var2>var1? var2:var1;
}
return s;
}
float SignalEffData::symmetrizeWithSign(const TString & which) {
float s=-1;
map<TString, SystInfo >::iterator it=systematics.find(which);
if (it==systematics.end() ) {
cout<<"ERROR -- cannot find in systematics list: "<<which<<endl;
}
else {
s= (it->second.plus - it->second.minus)*0.5;
}
return s;
}
float SignalEffData::valuePlus(const TString & which) {
float s=-1;
map<TString, SystInfo >::iterator it=systematics.find(which);
if (it==systematics.end() ) {
cout<<"ERROR -- cannot find in systematics list: "<<which<<endl;
}
else { //return the larger deviation
s=it->second.plus;
}
return s;
}
float SignalEffData::valueMinus(const TString & which) {
float s=-1;
map<TString, SystInfo >::iterator it=systematics.find(which);
if (it==systematics.end() ) {
cout<<"ERROR -- cannot find in systematics list: "<<which<<endl;
}
else { //return the larger deviation
s=it->second.minus;
}
return s;
}
float SignalEffData::totalSystematic() {
float total2=0;
for (map<TString, SystInfo >::iterator isyst=systematics.begin(); isyst!=systematics.end(); ++isyst) {
if ( isyst->second.status == 0) {
cout<<"WARNING -- systematic is unset! "<<isyst->first<<endl;
}
total2 += pow( symmetrize(isyst->first),2);
}
return 100*sqrt(total2);
}
float SignalEffData::totalSystematicWithoutB() {
float total2=0;
for (map<TString, SystInfo >::iterator isyst=systematics.begin(); isyst!=systematics.end(); ++isyst) {
if ( isyst->second.status == 0) {
cout<<"WARNING -- systematic is unset! "<<isyst->first<<endl;
}
if ( isyst->first != "btag" && isyst->first != "lftag") total2 += pow( symmetrize(isyst->first),2);
}
return 100*sqrt(total2);
}