ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/src/SFWeight.cc
Revision: 1.1
Committed: Tue Mar 12 20:43:04 2013 UTC (12 years, 2 months ago) by ahart
Content type: text/plain
Branch: MAIN
Log Message:
First commit of lepton scale factor machinery.

File Contents

# Content
1 #include "OSUT3Analysis/AnaTools/interface/SFWeight.h"
2
3 MuonSFWeight::MuonSFWeight (const string &sfFile, const string &dataOverMC)
4 {
5 TFile *fin = TFile::Open (sfFile.c_str ());
6 TGraphAsymmErrors *data = (TGraphAsymmErrors *) fin->Get (dataOverMC.c_str ());
7
8 double bins[data->GetN () + 1];
9 for (int i = 0; i < data->GetN (); i++)
10 {
11 double x, y, exl, exh;
12
13 data->GetPoint (i, x, y);
14 exl = data->GetErrorXlow (i);
15 exh = data->GetErrorXhigh (i);
16 if (i == 0)
17 bins[i] = x - exl;
18 bins[i + 1] = x + exh;
19 }
20
21 muonSFWeight_ = new TH1D ("muonSFWeight", "", data->GetN (), bins);
22 muonSFWeight_->SetDirectory (0);
23 for (int i = 0; i < data->GetN (); i++)
24 {
25 double dataX, dataY;
26
27 data->GetPoint (i, dataX, dataY);
28 muonSFWeight_->SetBinContent (i + 1, dataY);
29 }
30
31 fin->Close ();
32 delete data;
33 }
34
35 MuonSFWeight::MuonSFWeight (const string &sfFile, const string &dataEff, const string &mcEff)
36 {
37 TFile *fin = TFile::Open (sfFile.c_str ());
38 TGraphAsymmErrors *mc = (TGraphAsymmErrors *) fin->Get (mcEff.c_str ());
39 TGraphAsymmErrors *data = (TGraphAsymmErrors *) fin->Get (dataEff.c_str ());
40
41 double bins[mc->GetN () + 1];
42 for (int i = 0; i < mc->GetN (); i++)
43 {
44 double x, y, exl, exh;
45
46 mc->GetPoint (i, x, y);
47 exl = mc->GetErrorXlow (i);
48 exh = mc->GetErrorXhigh (i);
49 if (i == 0)
50 bins[i] = x - exl;
51 bins[i + 1] = x + exh;
52 }
53
54 muonSFWeight_ = new TH1D ("muonSFWeight", "", mc->GetN (), bins);
55 muonSFWeight_->SetDirectory (0);
56 for (int i = 0; i < mc->GetN (); i++)
57 {
58 double mcX, mcY, dataX, dataY;
59
60 mc->GetPoint (i, mcX, mcY);
61 data->GetPoint (i, dataX, dataY);
62 muonSFWeight_->SetBinContent (i + 1, dataY / mcY);
63 }
64
65 fin->Close ();
66 delete mc;
67 delete data;
68 }
69
70 MuonSFWeight::~MuonSFWeight ()
71 {
72 delete muonSFWeight_;
73 }
74
75 ElectronSFWeight::ElectronSFWeight (const string &cmsswRelease, const string &id) :
76 cmsswRelease_ (cmsswRelease),
77 id_ (id)
78 {
79 }
80
81 double
82 ElectronSFWeight::at (const double &eta, const double &pt)
83 {
84 if (cmsswRelease_ == "53X")
85 {
86 if (id_ == "tight")
87 {
88 if (fabs (eta) < 0.8)
89 {
90 if (pt < 15.0 && pt >= 10.0)
91 return 0.818;
92 if (pt < 20.0 && pt >= 15.0)
93 return 0.928;
94 if (pt < 30.0 && pt >= 20.0)
95 return 0.973;
96 if (pt < 40.0 && pt >= 30.0)
97 return 0.979;
98 if (pt < 50.0 && pt >= 40.0)
99 return 0.984;
100 if (pt < 200.0 && pt >= 50.0)
101 return 0.983;
102 }
103 if (fabs (eta) < 1.442 && fabs (eta) >= 0.8)
104 {
105 if (pt < 15.0 && pt >= 10.0)
106 return 0.840;
107 if (pt < 20.0 && pt >= 15.0)
108 return 0.914;
109 if (pt < 30.0 && pt >= 20.0)
110 return 0.948;
111 if (pt < 40.0 && pt >= 30.0)
112 return 0.961;
113 if (pt < 50.0 && pt >= 40.0)
114 return 0.972;
115 if (pt < 200.0 && pt >= 50.0)
116 return 0.977;
117 }
118 if (fabs (eta) < 1.556 && fabs (eta) >= 1.442)
119 {
120 if (pt < 15.0 && pt >= 10.0)
121 return 1.008;
122 if (pt < 20.0 && pt >= 15.0)
123 return 0.877;
124 if (pt < 30.0 && pt >= 20.0)
125 return 0.983;
126 if (pt < 40.0 && pt >= 30.0)
127 return 0.983;
128 if (pt < 50.0 && pt >= 40.0)
129 return 0.957;
130 if (pt < 200.0 && pt >= 50.0)
131 return 0.978;
132 }
133 if (fabs (eta) < 2.0 && fabs (eta) >= 1.556)
134 {
135 if (pt < 15.0 && pt >= 10.0)
136 return 0.906;
137 if (pt < 20.0 && pt >= 15.0)
138 return 0.907;
139 if (pt < 30.0 && pt >= 20.0)
140 return 0.957;
141 if (pt < 40.0 && pt >= 30.0)
142 return 0.962;
143 if (pt < 50.0 && pt >= 40.0)
144 return 0.985;
145 if (pt < 200.0 && pt >= 50.0)
146 return 0.986;
147 }
148 if (fabs (eta) < 2.5 && fabs (eta) >= 2.0)
149 {
150 if (pt < 15.0 && pt >= 10.0)
151 return 0.991;
152 if (pt < 20.0 && pt >= 15.0)
153 return 0.939;
154 if (pt < 30.0 && pt >= 20.0)
155 return 1.001;
156 if (pt < 40.0 && pt >= 30.0)
157 return 1.002;
158 if (pt < 50.0 && pt >= 40.0)
159 return 0.999;
160 if (pt < 200.0 && pt >= 50.0)
161 return 0.995;
162 }
163 }
164 }
165
166 return 0.0;
167 }
168
169 ElectronSFWeight::~ElectronSFWeight ()
170 {
171 }