1 |
anghel |
1.1 |
#include <iostream>
|
2 |
|
|
#include <vector>
|
3 |
|
|
#include "TMath.h"
|
4 |
|
|
#include <string>
|
5 |
|
|
#include <fstream>
|
6 |
|
|
#include <iostream>
|
7 |
|
|
#include <vector>
|
8 |
|
|
#include "TFile.h"
|
9 |
|
|
#include "TH1.h"
|
10 |
|
|
#include "TH1F.h"
|
11 |
|
|
#include "TH2.h"
|
12 |
|
|
#include "TH2D.h"
|
13 |
|
|
#include "TF1.h"
|
14 |
|
|
#include "TFile.h"
|
15 |
|
|
#include "TDirectory.h"
|
16 |
|
|
#include "TCanvas.h"
|
17 |
|
|
#include "TLegend.h"
|
18 |
|
|
#include "TLatex.h"
|
19 |
|
|
|
20 |
|
|
#include "../../../Style.cc"
|
21 |
|
|
|
22 |
|
|
using namespace std;
|
23 |
|
|
|
24 |
|
|
//use simType = FastSimWinter09, FullSimSummer08
|
25 |
|
|
//use studyType = revd0cut_alld0corrBins,revd0cut_CVd0corrMax_2jetsinclusive,revd0cut_CVd0corrMax_3jetsinclusive
|
26 |
|
|
//use jetBin = all,1jet,2jet,3jet,4jet
|
27 |
|
|
void mainMMerrors(string simType, string studyType, string jetBin) {
|
28 |
|
|
Style();
|
29 |
|
|
TLatex *latex = new TLatex();
|
30 |
|
|
latex->SetNDC();
|
31 |
|
|
|
32 |
|
|
string path = "/uscms/home/omanghel/work/Top/macros/";
|
33 |
|
|
string dirName = simType;
|
34 |
|
|
string studyT = studyType;
|
35 |
|
|
string sampleFile[5] = {"inclusiveMu_none","TTjets_none","Wjets_Wbb","Wjets_Wcc","Wjets_Wjets"};
|
36 |
|
|
int Nsamples = 5;
|
37 |
|
|
|
38 |
|
|
//define the variable to store the statistical information
|
39 |
|
|
double weightf[5];
|
40 |
|
|
double d0binL[5][16];
|
41 |
|
|
double d0binT[5][16];
|
42 |
|
|
double epsd0binmix[16];
|
43 |
|
|
for (int i=0; i< Nsamples; i++) {
|
44 |
|
|
weightf[i] = 0.0;
|
45 |
|
|
for (int j=0; j!=16; j++) {
|
46 |
|
|
d0binL[i][j] = 0.0;
|
47 |
|
|
d0binT[i][j] = 0.0;
|
48 |
|
|
}
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
string fileName[5];
|
52 |
|
|
TFile *inFile[5];
|
53 |
|
|
//inFile = TFile::Open((path+"/"+dirName+"/"+fileName).c_str());
|
54 |
|
|
//inFile = TFile::Open(fileName.c_str());
|
55 |
|
|
//inFile->cd();
|
56 |
|
|
|
57 |
|
|
//define the variable to store the histograms properties
|
58 |
|
|
string sample[5] = {"inclusiveMu","TTjets","Wjets_Wbb","Wjets_Wcc","Wjets_Wjets"};
|
59 |
|
|
string histo1DType[5] = {"weight","epsBKG_error","epsBKG_loose","epsBKG_tight"};
|
60 |
|
|
string histoPlotname[2] = {"epsBKG_single_error","epsBKG_mix_error"};
|
61 |
|
|
TH1F *histoPlot0 = new TH1F(histoPlotname[0].c_str(),"",16,0.,16.);
|
62 |
|
|
TH1F *histoPlot1 = new TH1F(histoPlotname[1].c_str(),"",16,0.,16.);
|
63 |
|
|
string xlabel[2] = {"d0/d0sig","d0/d0sig"};
|
64 |
|
|
string ylabel[2] = {"#epsilon_{Bkg}","#epsilon_{Bkg} mix"};
|
65 |
|
|
string canvas1DTitle[2] = {"#epsilon_{Bkg} = Nev_{tight}/Nev_{loose} for inclusiveMu","#epsilon_{Bkg} = Nev_{tight}/Nev_{loose} for mixed sample"};
|
66 |
|
|
|
67 |
|
|
Double_t XminBin1D[2] = {0,0};
|
68 |
|
|
Double_t XmaxBin1D[2]; XmaxBin1D[2]= 16; XmaxBin1D[3] = 16;
|
69 |
|
|
Double_t YminBin1D[5] = {0,0};
|
70 |
|
|
Double_t YmaxBin1D[5] = {1.0,1.0};
|
71 |
|
|
|
72 |
|
|
int color[5] = {1,2,3,4,6}; //for the Nsamples
|
73 |
|
|
|
74 |
|
|
TH1F* histo1D[20];
|
75 |
|
|
|
76 |
|
|
for (int i=0; i!=4; i++) {
|
77 |
|
|
for (int j=0; j != Nsamples; j++) {
|
78 |
|
|
fileName[j] = simType+"/inputMM_"+sampleFile[j]+"_"+studyType+".root";
|
79 |
|
|
inFile[j] = TFile::Open(fileName[j].c_str());
|
80 |
|
|
inFile[j]->cd();
|
81 |
|
|
|
82 |
|
|
string nametmp0;
|
83 |
|
|
string nametmp1;
|
84 |
|
|
if (i==0) {
|
85 |
|
|
nametmp0 = "h_"+histo1DType[0]+"_"+sampleFile[j];
|
86 |
|
|
gDirectory->GetObject(nametmp0.c_str(),histo1D[j]);
|
87 |
|
|
double temp = histo1D[j]->GetBinContent(1);
|
88 |
|
|
weightf[j] = temp;
|
89 |
|
|
cout << "weight(" << j << ") = " << weightf[j] << endl;
|
90 |
|
|
}
|
91 |
|
|
else {
|
92 |
|
|
nametmp1 = "h_"+histo1DType[i]+"_"+jetBin+"_"+sampleFile[j];
|
93 |
|
|
cout << i*Nsamples+j << " ----> " << nametmp1 << endl;
|
94 |
|
|
gDirectory->GetObject(nametmp1.c_str(),histo1D[i*Nsamples+j]);
|
95 |
|
|
if (i==2) {for(int k=0; k!=16; k++) d0binL[j][k] = histo1D[i*Nsamples+j]->GetBinContent(k+1);}
|
96 |
|
|
if (i==3) {for(int k=0; k!=16; k++) d0binT[j][k] = histo1D[i*Nsamples+j]->GetBinContent(k+1);}
|
97 |
|
|
}
|
98 |
|
|
//inFile[j]->Close();
|
99 |
|
|
}
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
TH1F *hmixloose = new TH1F("loose","",16,0.,16.);
|
103 |
|
|
TH1F *hmixtight = new TH1F("tight","",16,0.,16.);
|
104 |
|
|
for (int k=0; k != 16; k++) {
|
105 |
|
|
//cout << "w0 = " << weightf[0] << "\t w1 = " << weightf[1] << "\t w2 = " << weightf[2] << "\t w3 = " << weightf[3] << "\t w4 = " << weightf[4] << endl;
|
106 |
|
|
//double binvalue_loose = d0binL[0][k]*weightf[0]+d0binL[1][k]*weightf[1]+d0binL[2][k]*weightf[2]+d0binL[3][k]*weightf[3]+d0binL[4][k]*weightf[4];
|
107 |
|
|
//double binvalue_tight = d0binT[0][k]*weightf[0]+d0binT[1][k]*weightf[1]+d0binT[2][k]*weightf[2]+d0binT[3][k]*weightf[3]+d0binT[4][k]*weightf[4];
|
108 |
|
|
|
109 |
|
|
//just testing...
|
110 |
|
|
double binvalue_loose = d0binL[1][k]*weightf[1]+d0binL[2][k]*weightf[2]+d0binL[3][k]*weightf[3]+d0binL[4][k]*weightf[4];
|
111 |
|
|
double binvalue_tight = d0binT[1][k]*weightf[1]+d0binT[2][k]*weightf[2]+d0binT[3][k]*weightf[3]+d0binT[4][k]*weightf[4];
|
112 |
|
|
|
113 |
|
|
hmixloose->SetBinContent(k+1,binvalue_loose);
|
114 |
|
|
hmixtight->SetBinContent(k+1,binvalue_tight);
|
115 |
|
|
|
116 |
|
|
cout << "bin = " << k << "\tloose = " << binvalue_loose << "\ttight = " << binvalue_tight << "\tepsQCD = " << binvalue_tight/binvalue_loose << endl;
|
117 |
|
|
}
|
118 |
|
|
histoPlot0 -> Sumw2();
|
119 |
|
|
histoPlot1 -> Sumw2();
|
120 |
|
|
hmixloose -> Sumw2();
|
121 |
|
|
hmixtight -> Sumw2();
|
122 |
|
|
histoPlot1 -> Divide(hmixtight,hmixloose,1.0,1.0,"B");
|
123 |
|
|
|
124 |
|
|
histoPlot1->SetLineColor(2);
|
125 |
|
|
histoPlot1->SetLineWidth(2.0);
|
126 |
|
|
histoPlot1->GetXaxis()->SetTitle(xlabel[1].c_str());
|
127 |
|
|
histoPlot1->GetYaxis()->SetTitle(ylabel[1].c_str());
|
128 |
|
|
histoPlot1->GetYaxis()->SetRangeUser(0.,0.2);
|
129 |
|
|
histoPlot1->SetStats(0);
|
130 |
|
|
|
131 |
|
|
TF1 *h1;
|
132 |
|
|
h1 = new TF1("func0","1*[0]",5.0,12.0);
|
133 |
|
|
h1->SetParameter(0,0.4);
|
134 |
|
|
histoPlot1->Fit(h1, "NR");
|
135 |
|
|
histoPlot1->Fit(h1, "NR");
|
136 |
|
|
|
137 |
|
|
cout << "parameter0 = " << h1->GetParameter(0) << endl;
|
138 |
|
|
cout << "parameter_error = " << h1->GetParError(0) << endl;
|
139 |
|
|
cout << "parameter1 = " << h1->GetParameter(1) << endl;
|
140 |
|
|
cout << "parameter2 = " << h1->GetParameter(2) << endl;
|
141 |
|
|
|
142 |
|
|
double fitvalue = h1->GetParameter(0);
|
143 |
|
|
double fiterror = h1->GetParError(0);
|
144 |
|
|
|
145 |
|
|
TF1 *h1err_up = new TF1("func0_err_up","func0+[0]+0.010",5.0,12.0);
|
146 |
|
|
h1err_up->SetParameter(0,fiterror);
|
147 |
|
|
TF1 *h1err_down = new TF1("func0_err_down","func0-[0]-0.010",5.0,12.0);
|
148 |
|
|
h1err_down->SetParameter(0,fiterror);
|
149 |
|
|
|
150 |
|
|
h1->SetLineStyle(1);
|
151 |
|
|
h1err_up->SetLineStyle(2);
|
152 |
|
|
h1err_down->SetLineStyle(2);
|
153 |
|
|
h1->SetLineWidth(1.5);
|
154 |
|
|
h1err_up->SetLineWidth(1.5);
|
155 |
|
|
h1err_down->SetLineWidth(1.5);
|
156 |
|
|
h1->SetLineColor(1);
|
157 |
|
|
h1err_up->SetLineColor(1);
|
158 |
|
|
h1err_down->SetLineColor(1);
|
159 |
|
|
|
160 |
|
|
histo1D[5]->SetLineColor(2);
|
161 |
|
|
histo1D[5]->SetLineWidth(2.0);
|
162 |
|
|
histo1D[5]->GetXaxis()->SetTitle(xlabel[0].c_str());
|
163 |
|
|
histo1D[5]->GetYaxis()->SetTitle(ylabel[0].c_str());
|
164 |
|
|
histo1D[5]->GetYaxis()->SetRangeUser(0.,0.2);
|
165 |
|
|
histo1D[5]->SetStats(0);
|
166 |
|
|
|
167 |
|
|
TCanvas *canvas1 = new TCanvas(histoPlotname[0].c_str(), "");
|
168 |
|
|
histo1D[5]->Draw("e");
|
169 |
|
|
latex->DrawLatex(0.22,0.94,canvas1DTitle[0].c_str());
|
170 |
|
|
//canvas1->SetLogy();
|
171 |
|
|
string nameCanvas1 = histoPlotname[0]+"_"+jetBin+".eps";
|
172 |
|
|
canvas1->SaveAs(nameCanvas1.c_str());
|
173 |
|
|
|
174 |
|
|
if (jetBin == "all") {
|
175 |
|
|
ofstream outfile;
|
176 |
|
|
outfile.open(("fit_"+simType+"_"+jetBin+".txt").c_str());
|
177 |
|
|
outfile << fitvalue << "\t" << fiterror << endl;
|
178 |
|
|
}
|
179 |
|
|
TF1 *hist1;
|
180 |
|
|
TF1 *hist1_up;
|
181 |
|
|
TF1 *hist1_down;
|
182 |
|
|
if (jetBin != "all") {
|
183 |
|
|
ifstream infile;
|
184 |
|
|
infile.open(("fit_"+simType+"_all.txt").c_str());
|
185 |
|
|
double a,b;
|
186 |
|
|
infile >> a >> b;
|
187 |
|
|
infile.close();
|
188 |
|
|
cout << "Parameters from fit file = " << a << "\t" << b << endl;
|
189 |
|
|
hist1 = new TF1("histofit_all","[0]",5.0,12.0);
|
190 |
|
|
hist1->SetParameter(0,a);
|
191 |
|
|
//if (jetBin == "3jet") hist1->SetParameter(0,0.03516); //FastSim
|
192 |
|
|
//if (jetBin == "4jet") hist1->SetParameter(0,0.0233325); //FastSim
|
193 |
|
|
if (jetBin == "2jet") hist1->SetParameter(0,0.05); //FullSim
|
194 |
|
|
if (jetBin == "3jet") hist1->SetParameter(0,0.04); //FullSim
|
195 |
|
|
if (jetBin == "4jet") hist1->SetParameter(0,0.03); //FullSim
|
196 |
|
|
hist1_up = new TF1("histofit_all_up","[0]+[1]+0.010",5.0,12.0);
|
197 |
|
|
hist1_up->SetParameters(a,b);
|
198 |
|
|
//if (jetBin == "3jet") hist1_up->SetParameters(0.03516,0); //FastSim
|
199 |
|
|
//if (jetBin == "3jet") hist1_up->SetParameters(0.03516,0); //FastSim
|
200 |
|
|
if (jetBin == "2jet") hist1_up->SetParameters(0.05,0); //FullSim
|
201 |
|
|
if (jetBin == "3jet") hist1_up->SetParameters(0.04,0); //FullSim
|
202 |
|
|
if (jetBin == "4jet") hist1_up->SetParameters(0.03,0); //FullSim
|
203 |
|
|
hist1_down = new TF1("histofit_all_down","[0]-[1]-0.010",5.0,12.0);
|
204 |
|
|
hist1_down->SetParameters(a,b);
|
205 |
|
|
//if (jetBin == "3jet") hist1_down->SetParameters(0.03516,0);
|
206 |
|
|
//if (jetBin == "4jet") hist1_down->SetParameters(0.0233325,0);
|
207 |
|
|
if (jetBin == "2jet") hist1_down->SetParameters(0.05,0); //FullSim
|
208 |
|
|
if (jetBin == "3jet") hist1_down->SetParameters(0.04,0); //FullSim
|
209 |
|
|
if (jetBin == "4jet") hist1_down->SetParameters(0.03,0); //FullSim
|
210 |
|
|
hist1->SetLineStyle(1);
|
211 |
|
|
hist1_up->SetLineStyle(2);
|
212 |
|
|
hist1_down->SetLineStyle(2);
|
213 |
|
|
hist1->SetLineWidth(1.5);
|
214 |
|
|
hist1_up->SetLineWidth(1.5);
|
215 |
|
|
hist1_down->SetLineWidth(1.5);
|
216 |
|
|
hist1->SetLineColor(1);
|
217 |
|
|
hist1_up->SetLineColor(1);
|
218 |
|
|
hist1_down->SetLineColor(1);
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
|
222 |
|
|
TCanvas *canvas2 = new TCanvas(histoPlotname[1].c_str(), "");
|
223 |
|
|
histoPlot1->Draw("e");
|
224 |
|
|
if (jetBin == "all") {
|
225 |
|
|
h1->Draw("same");
|
226 |
|
|
h1err_up->Draw("same");
|
227 |
|
|
h1err_down->Draw("same");
|
228 |
|
|
}
|
229 |
|
|
if (jetBin != "all") {
|
230 |
|
|
hist1->Draw("same");
|
231 |
|
|
hist1_up->Draw("same");
|
232 |
|
|
hist1_down->Draw("same");
|
233 |
|
|
}
|
234 |
|
|
latex->DrawLatex(0.22,0.94,canvas1DTitle[1].c_str());
|
235 |
|
|
//canvas2->SetLogy();
|
236 |
|
|
string nameCanvas2 = histoPlotname[1]+"_"+jetBin+".eps";
|
237 |
|
|
canvas2->SaveAs(nameCanvas2.c_str());
|
238 |
|
|
|
239 |
|
|
}
|