1 |
#include "ikstest.h"
|
2 |
#include "TopStyle/CMSTopStyle.cc"
|
3 |
|
4 |
//=================================
|
5 |
// Program to run IKS test
|
6 |
// * Input directories:
|
7 |
// * Data: skimmed_Data_x.xxpb-1
|
8 |
// => default selection : Data_<suffix>.root
|
9 |
// => n-1 selection : Data_<suffix>_<invName>.root
|
10 |
// * MC : skimmed_MC {QCD,WJets,TTbar...}
|
11 |
// => default selection : QCD_<suffix>.root
|
12 |
// => n-1 selection : Data_<suffix>_<invName>.root
|
13 |
// * Upmost output dir specified by <desDir>
|
14 |
// subdirectory created according to <useInv> and <realData>
|
15 |
// => <desDir'><xyz><suffix>.pdf (.txt)
|
16 |
// * e.g. to do KS test on data with MC QCD shape in signal region:
|
17 |
// useInv=false; realData=true
|
18 |
//=================================
|
19 |
|
20 |
using namespace std;
|
21 |
|
22 |
//define the constants: 2.88/pb
|
23 |
const Double_t weight_[5] = {0.0524313, //QCD
|
24 |
0.0089567, //WJets
|
25 |
0.000306, //TTbar
|
26 |
0.0080911, //ZJets
|
27 |
0.000114 //STtch
|
28 |
};
|
29 |
const Double_t procQCD = 1.46;
|
30 |
const Double_t procWJets = 1.03;
|
31 |
const Double_t procTTbar = 1.;
|
32 |
const Double_t procZJets = 1.;
|
33 |
const Double_t procSTtch = 1.;
|
34 |
|
35 |
// Output directory
|
36 |
TString baseDir = "Results_2.88pb-1_Incl3/";
|
37 |
// User defined parameters
|
38 |
bool realData = true;
|
39 |
bool useInv = true; // whether to use n-1 QCD template
|
40 |
bool useInvSelShape = false; // whether to use shape from inverse selection for dataKS plots. Use when useInv is true
|
41 |
double yLowBound = 1.e-10;
|
42 |
// Ntuples to use
|
43 |
int n_sels = 5; // 5:Run all selections
|
44 |
TString suffixs[5] = {"Incl3_Sel0","Incl3_Sel1","Incl3_Sel2","Incl3_Sel3","Incl3_Sel4"}; // Suffix of selection
|
45 |
TString invNames[2] = {"RelIsogt0p1","D0gt0p02"};
|
46 |
TString invLabels[2] = {"RelIso > 0.1","d_{0} > 0.02"};
|
47 |
map<TString,TCanvas*> cvs; // map of usual histogram
|
48 |
bool debug_ = false;
|
49 |
|
50 |
//=================================
|
51 |
// Main program
|
52 |
//=================================
|
53 |
void ikstest() {
|
54 |
CMSTopStyle style;
|
55 |
gROOT->SetStyle("CMS");
|
56 |
TLatex *latex = new TLatex();
|
57 |
latex->SetNDC();
|
58 |
|
59 |
struct stat stbDir;
|
60 |
if (stat(baseDir,&stbDir)){
|
61 |
cout << "Creating folder : " << baseDir << endl;
|
62 |
if (mkdir(baseDir,0755) == -1){
|
63 |
std::cerr << "Error creating folder" << endl;
|
64 |
return;
|
65 |
}
|
66 |
}
|
67 |
|
68 |
int size_ninv = (useInv ? 2 : 1);
|
69 |
for (int ninv = 0; ninv < size_ninv; ++ninv) {
|
70 |
TString invName = invNames[ninv];
|
71 |
TString desDir;
|
72 |
// create output directory
|
73 |
if (!useInv) {
|
74 |
if (!realData) desDir = baseDir + "MC/";
|
75 |
else desDir = baseDir + "Data_MC/";
|
76 |
} else {
|
77 |
if (!realData) desDir = baseDir + "MC_"+invName+"/";
|
78 |
else desDir = baseDir + "Data_"+invName+"/";
|
79 |
}
|
80 |
struct stat stDir;
|
81 |
if (!stat(desDir,&stDir)){
|
82 |
cout << "Output folder exists! Continue to overwrite it? (enter to continue; 'q' for quit)" << endl;
|
83 |
char incmd;
|
84 |
cin.get(incmd);
|
85 |
if (incmd == 'q') return;
|
86 |
} else {
|
87 |
cout << "Creating folder : " << desDir << endl;
|
88 |
if (mkdir(desDir,0755) == -1){
|
89 |
std::cerr << "Error creating folder" << endl;
|
90 |
return;
|
91 |
}
|
92 |
}
|
93 |
|
94 |
for (int nsel = 0; nsel < n_sels; ++nsel) {
|
95 |
TString suffix = suffixs[nsel];
|
96 |
|
97 |
ofstream outprint(TString(desDir+"Results_"+suffix+".txt"));
|
98 |
//open the files with histograms
|
99 |
map<string,TFile*> mfile;
|
100 |
mfile.clear();
|
101 |
mfile["Data"] = TFile::Open(TString("skimmed_Data_2.88pb-1/Data_"+suffix+".root"));
|
102 |
// n-1 cuts
|
103 |
if (useInv) {
|
104 |
if (realData)
|
105 |
mfile["InvSel"] = TFile::Open(TString("skimmed_Data_2.88pb-1/Data_"+suffix+"_"+invName+".root"));
|
106 |
else
|
107 |
mfile["InvSel"] = TFile::Open(TString("skimmed_MC/v5/QCD_"+suffix+"_"+invName+".root"));
|
108 |
}
|
109 |
// RefSel MC
|
110 |
mfile["0"] = TFile::Open(TString("skimmed_MC/v5/QCD_"+suffix+".root"));
|
111 |
mfile["1"] = TFile::Open(TString("skimmed_MC/v5/WJets_"+suffix+".root"));
|
112 |
mfile["2"] = TFile::Open(TString("skimmed_MC/v5/TTbar_"+suffix+".root"));
|
113 |
mfile["3"] = TFile::Open(TString("skimmed_MC/v5/ZJets_"+suffix+".root"));
|
114 |
mfile["4"] = TFile::Open(TString("skimmed_MC/v5/STtch_"+suffix+".root"));
|
115 |
|
116 |
//define histograms and related parameters
|
117 |
string histoName[3] = {"h_mu_pt_calo","h_met_calo","h_mt_calo"};
|
118 |
string histoLabelX[3] = {"p_{T}^{#mu} [GeV/c]", "#slash{E}_{T} [GeV/c]", "M_{T}^{W} [GeV/c^{2}]"};
|
119 |
Int_t xbins[3] = {20,20,40};
|
120 |
Double_t xlow[3] = {0.,0.,0.};
|
121 |
Double_t xhigh[3] = {100.,100.,200.};
|
122 |
string sample[5] = {"QCD","WJets","TTbar","ZJets","STtch"};
|
123 |
|
124 |
TH1F* hMC_[5][3]; // MC histograms
|
125 |
TH1F* hData_[3]; // Data or mix MC
|
126 |
TH1F* hQCD_NEW[3]; // InvSel QCD shape
|
127 |
TH1F* hKSres_[3];
|
128 |
TH1F* hKSvalues_[3];
|
129 |
TH1F* hQCD_KS[3];
|
130 |
TH1F* hWJets_KS[3];
|
131 |
|
132 |
//load the histograms from the root files
|
133 |
for (int vi = 0; vi < 3; ++vi) {// 3 variables
|
134 |
//cout << "file[" << vi << "] : " << endl;
|
135 |
string nameNewHisto = "mix_"+histoName[vi];
|
136 |
string nameNewHistoSFKS = "finalSF_"+histoName[vi];
|
137 |
string nameNewHistoKSvalues = "KSvalues_"+histoLabelX[vi];
|
138 |
|
139 |
hData_[vi] = new TH1F(nameNewHisto.c_str(),"",xbins[vi],xlow[vi],xhigh[vi]);
|
140 |
hKSres_[vi] = new TH1F(nameNewHistoSFKS.c_str(),"",xbins[vi],xlow[vi],xhigh[vi]);
|
141 |
hKSvalues_[vi] = new TH1F(nameNewHistoKSvalues.c_str(),"",2./stepsize, stepsize, 2.+stepsize);
|
142 |
|
143 |
ostringstream ssc;
|
144 |
ssc << vi;
|
145 |
|
146 |
if (!useInv) {//use QCD MC sample
|
147 |
hQCD_NEW[vi] = (TH1F*) mfile["0"]->Get(TString(histoName[vi]))->Clone();
|
148 |
hQCD_NEW[vi] -> Scale(weight_[0]);
|
149 |
hQCD_NEW[vi] -> SetName(TString("InvSel_"+histoName[vi]+"_"+ssc.str()));
|
150 |
}
|
151 |
else {
|
152 |
hQCD_NEW[vi] = (TH1F*) mfile["InvSel"]->Get(TString(histoName[vi]))->Clone();
|
153 |
if (!realData) hQCD_NEW[vi] -> Scale(weight_[0]);
|
154 |
hQCD_NEW[vi] -> SetName(TString("InvSel_"+histoName[vi]+"_"+ssc.str()));
|
155 |
}
|
156 |
if (debug_) cout << "hQCD_NEW[" << vi << "] @ " << hQCD_NEW[vi] << endl;
|
157 |
|
158 |
hData_[vi] -> Sumw2();
|
159 |
hKSres_[vi] -> Sumw2();
|
160 |
hKSvalues_[vi] -> Sumw2();
|
161 |
}
|
162 |
|
163 |
for (int n = 0; n < 5; ++n) {// 3 MC samples
|
164 |
for (int ihisto = 0; ihisto < 3; ihisto++) {// 3 variables
|
165 |
//cout << "Variable[" << ihisto << "]" << endl;
|
166 |
string histo_name = histoName[ihisto]+sample[n];
|
167 |
ostringstream ss;
|
168 |
ss << n;
|
169 |
hMC_[n][ihisto] = (TH1F*) mfile[ss.str()]->Get(TString(histoName[ihisto]))->Clone();
|
170 |
if (debug_) {
|
171 |
cout << "File[" << n << "] @" << mfile[ss.str()]
|
172 |
<< "; histo[" << ihisto << "] @ " << mfile[ss.str()]->Get(TString(histoName[ihisto]))
|
173 |
<<"; hMC_[" << n << "][" << ihisto << "] raw evts = "
|
174 |
<< setw(12) << hMC_[n][ihisto]->Integral();
|
175 |
}
|
176 |
hMC_[n][ihisto] -> Scale(weight_[n]);
|
177 |
hMC_[n][ihisto] -> SetName(TString("MC_"+sample[n]+"_"+histoName[ihisto]));
|
178 |
if (debug_) cout << "; weighted num evts = " << setw(8) << hMC_[n][ihisto]->Integral() << endl;
|
179 |
}
|
180 |
}
|
181 |
|
182 |
//create the mixed samples = "data"
|
183 |
TString cvsName0 = "Data";
|
184 |
if (useInv) {
|
185 |
cvsName0 += "_";
|
186 |
cvsName0 += invName;
|
187 |
}
|
188 |
cvs[cvsName0] = new TCanvas(cvsName0,"Data distributions",600,700);
|
189 |
cvs[cvsName0]->Divide(3,1);
|
190 |
for (int i = 0; i < 3; i++) {
|
191 |
cvs[cvsName0]->cd(i+1);
|
192 |
if (!realData) {
|
193 |
hData_[i] -> Add(hMC_[0][i],hMC_[1][i], procQCD,procWJets);
|
194 |
hData_[i] -> Add(hMC_[2][i], procTTbar);
|
195 |
hData_[i] -> Add(hMC_[3][i], procZJets);
|
196 |
hData_[i] -> Add(hMC_[4][i], procSTtch);
|
197 |
}
|
198 |
else {
|
199 |
TH1F *htmp = (TH1F*) mfile["Data"]->Get(TString(histoName[i]));
|
200 |
hData_[i] -> Add(htmp,1.);
|
201 |
}
|
202 |
hData_[i]->GetXaxis()->SetTitle(histoLabelX[i].c_str());
|
203 |
hData_[i]->GetYaxis()->SetTitle("Events");
|
204 |
if (i == 0) // mu pT plot
|
205 |
hData_[0]->GetXaxis()->SetRangeUser(20.,xhigh[0]);
|
206 |
hData_[i]->DrawClone("hist");
|
207 |
}
|
208 |
cvs[cvsName0]->SaveAs(TString(desDir+"Data_distributions.pdf"));
|
209 |
cvs[cvsName0]->SaveAs(TString(desDir+"Data_distributions.png"));
|
210 |
|
211 |
//Calculate num of events for each sample
|
212 |
vector<double> vNev_;
|
213 |
|
214 |
double NevData = hData_[2]->Integral();
|
215 |
double corr_NevQCD = hMC_[0][2]->Integral();
|
216 |
double corr_NevQCD_NEW = hQCD_NEW[2]->Integral();
|
217 |
double corr_NevWJets = hMC_[1][2]->Integral();
|
218 |
double corr_NevTTbar = hMC_[2][2]->Integral();
|
219 |
double corr_NevZJets = hMC_[3][2]->Integral();
|
220 |
double corr_NevSTtch = hMC_[4][2]->Integral();
|
221 |
cout << "corr_NevSTtch = " << corr_NevSTtch << endl;
|
222 |
// double corr_Nevmix = procQCD*corr_NevQCD + procWJets*corr_NevWJets
|
223 |
// + procTTbar*corr_NevTTbar+procZJets*corr_NevZJets + procSTtch*corr_NevSTtch;//should equal NevData for MC
|
224 |
// store nev in a vector
|
225 |
vNev_.push_back(NevData);
|
226 |
vNev_.push_back((useInv ? corr_NevQCD_NEW : corr_NevQCD));
|
227 |
vNev_.push_back(corr_NevWJets);
|
228 |
|
229 |
// Non WJets (use MC expected values):
|
230 |
if (procTTbar > 0.) vNev_.push_back(corr_NevTTbar*procTTbar);
|
231 |
if (procZJets > 0.) vNev_.push_back(corr_NevZJets*procZJets);
|
232 |
if (procSTtch > 0.) vNev_.push_back(corr_NevSTtch*procSTtch);
|
233 |
|
234 |
outprint << "Events in Data = " << NevData << endl;
|
235 |
outprint << "Events QCD sample = " << corr_NevQCD << endl;
|
236 |
outprint << "Events InvSel sample = " << corr_NevQCD_NEW << endl;
|
237 |
outprint << "---------------------------" << endl;
|
238 |
outprint << "Events WJets sample = " << corr_NevWJets << endl;
|
239 |
outprint << "Events TTbar sample = " << corr_NevTTbar << endl;
|
240 |
outprint << "Events ZJets sample = " << corr_NevZJets << endl;
|
241 |
outprint << "Events STtch sample = " << corr_NevSTtch << endl;
|
242 |
|
243 |
//define the containers for chosen numbers (coressponding to the max KStest result)
|
244 |
testMC maxProb[3];
|
245 |
|
246 |
//define the scale factors calculated using information obtained from all parameters
|
247 |
Double_t SFbackg = 0.0;
|
248 |
Double_t sumSFbackg = 0.0;
|
249 |
Double_t SFsample = 0.0;
|
250 |
Double_t sumSFsample = 0.0;
|
251 |
Double_t allKS = 0.0;
|
252 |
|
253 |
//do the KS test by varying the scale factors
|
254 |
for (int i = 0; i < 3; i++) { // 3 variables
|
255 |
TH1F *data = (TH1F*)hData_[i]->Clone("data");
|
256 |
data -> SetName("dataClone");
|
257 |
map<string,TH1F*> mHisto_;
|
258 |
mHisto_.clear();
|
259 |
mHisto_["Data"] = data;
|
260 |
mHisto_["QCD"] = (useInv ? (TH1F*)hQCD_NEW[i]->Clone() : (TH1F*)hMC_[0][i]->Clone());
|
261 |
mHisto_["WJets"] = (TH1F*)hMC_[1][i]->Clone();//WJets
|
262 |
if (procTTbar > 0.) mHisto_["TTbar"] = (TH1F*)hMC_[2][i]->Clone();//TTbar
|
263 |
if (procZJets > 0.) mHisto_["ZJets"] = (TH1F*)hMC_[3][i]->Clone();//ZJets
|
264 |
if (procSTtch > 0.) mHisto_["STtch"] = (TH1F*)hMC_[4][i]->Clone();//STtch
|
265 |
|
266 |
//data -> Scale(1./data->Integral());
|
267 |
vector<testMC> resultsKS = doKStest(vNev_,mHisto_);
|
268 |
testMC tksmax = getMax(resultsKS);
|
269 |
maxProb[i] = tksmax;
|
270 |
outprint << "\nFor the plot " << histoLabelX[i] << " the results are:"<< endl;
|
271 |
outprint << "\tmax Probability = " << maxProb[i].prob << endl;
|
272 |
outprint << "\tproc_background = " << maxProb[i].scaleF_backg << endl;
|
273 |
outprint << "\tproc_sample = " << maxProb[i].scaleF_sample << endl;
|
274 |
|
275 |
outprint << "\n\tpercent_B of Data = "
|
276 |
<< maxProb[i].scaleF_backg*corr_NevQCD_NEW*100/NevData << endl;
|
277 |
outprint << "\tpercent_S of Data = "
|
278 |
<< maxProb[i].scaleF_sample*corr_NevWJets*100/NevData << endl;
|
279 |
outprint << "---------------------------" << endl;
|
280 |
|
281 |
//create the mixed samples with KS test results
|
282 |
sumSFbackg += maxProb[i].prob*maxProb[i].scaleF_backg;
|
283 |
sumSFsample += maxProb[i].prob*maxProb[i].scaleF_sample;
|
284 |
allKS += maxProb[i].prob;
|
285 |
|
286 |
//fill a histogram with the results from the KS test for each variable
|
287 |
for (unsigned int jiter = 0; jiter < resultsKS.size(); jiter++) {
|
288 |
if (resultsKS.at(jiter).prob == 1.)
|
289 |
cout << "variable [" << i << "]: prob[" << jiter << "]= " << resultsKS.at(jiter).prob << endl;
|
290 |
hKSvalues_[i]->SetBinContent(jiter,resultsKS.at(jiter).prob);
|
291 |
}
|
292 |
delete data;
|
293 |
}
|
294 |
|
295 |
//calculate the final scale factors
|
296 |
SFbackg = sumSFbackg/allKS;
|
297 |
SFsample = sumSFsample/allKS;
|
298 |
double SF_QCD = SFbackg*corr_NevQCD_NEW/corr_NevQCD;
|
299 |
outprint << "allKS = " << allKS << "\tbackground = " << SFbackg << "\tsample = " << SFsample << endl;
|
300 |
outprint << "==> Scale Factor for QCD MC = " << SF_QCD << endl;
|
301 |
outprint << "\tcombined percent_B of Data = "
|
302 |
<< SFbackg*corr_NevQCD_NEW*100/NevData << endl;
|
303 |
outprint << "\tcombined percent_S of Data = "
|
304 |
<< SFsample*corr_NevWJets*100/NevData << endl;
|
305 |
outprint << "\n" << endl;
|
306 |
outprint << "=================================" << endl;
|
307 |
outprint << "\n" << endl;
|
308 |
|
309 |
|
310 |
//=================================
|
311 |
// Plots
|
312 |
//=================================
|
313 |
for (int i = 0; i < 3; i++) {// 3 variables
|
314 |
gStyle->SetErrorX(0.);
|
315 |
hKSres_[i] -> Add((TH1F*)hQCD_NEW[i]->Clone(),(TH1F*)hMC_[1][i]->Clone(),SFbackg,SFsample);
|
316 |
hKSres_[i] -> Add((TH1F*)hMC_[2][i]->Clone(),procTTbar);
|
317 |
hKSres_[i] -> Add((TH1F*)hMC_[3][i]->Clone(),procZJets);
|
318 |
hKSres_[i] -> Add((TH1F*)hMC_[4][i]->Clone(),procSTtch);
|
319 |
|
320 |
outprint << "hKSres->Integral() = " << hKSres_[i]->Integral() << endl;
|
321 |
outprint << "Data->Integral() = " << hData_[i]->Integral() << endl;
|
322 |
|
323 |
hData_[i]->Rebin(2);
|
324 |
hQCD_NEW[i]->Rebin(2);
|
325 |
hMC_[0][i]->Rebin(2);
|
326 |
hMC_[1][i]->Rebin(2);
|
327 |
hKSres_[i]->Rebin(2);
|
328 |
//hKSvalues_[i]->Rebin(2);
|
329 |
|
330 |
// Stack Wjets and QCD after scaled by KS factors
|
331 |
if (useInv && useInvSelShape) {
|
332 |
hQCD_KS[i] = (TH1F*) hQCD_NEW[i]->Clone();
|
333 |
hQCD_KS[i]->Scale(SFbackg);
|
334 |
}
|
335 |
else {// Use MC QCD
|
336 |
hQCD_KS[i] = (TH1F*) hMC_[0][i]->Clone();
|
337 |
hQCD_KS[i]->Scale(SF_QCD);
|
338 |
}
|
339 |
hQCD_KS[i]->SetLineColor(style.QCDColor);
|
340 |
hQCD_KS[i]->SetFillColor(style.QCDColor);
|
341 |
hQCD_KS[i]->SetFillStyle(style.QCDFill);
|
342 |
|
343 |
hWJets_KS[i] = (TH1F*) hMC_[1][i]->Clone();
|
344 |
hWJets_KS[i]->Scale(SFsample);
|
345 |
hWJets_KS[i]->SetLineColor(style.WJetsColor);
|
346 |
hWJets_KS[i]->SetFillColor(style.WJetsColor);
|
347 |
hWJets_KS[i]->SetFillStyle(style.WJetsFill);
|
348 |
|
349 |
if (procTTbar > 0.) {
|
350 |
hMC_[2][i]->Rebin(2);
|
351 |
hMC_[2][i]->SetLineColor(style.TtbarColor);
|
352 |
hMC_[2][i]->SetFillColor(style.TtbarColor);
|
353 |
hMC_[2][i]->SetFillStyle(style.TtbarFill);
|
354 |
}
|
355 |
if (procZJets > 0.) {
|
356 |
hMC_[3][i]->Rebin(2);
|
357 |
hMC_[3][i]->SetLineColor(style.DYZJetsColor);
|
358 |
hMC_[3][i]->SetFillColor(style.DYZJetsColor);
|
359 |
hMC_[3][i]->SetFillStyle(style.DYZJetsFill);
|
360 |
}
|
361 |
if (procSTtch > 0.) {
|
362 |
hMC_[4][i]->Rebin(2);
|
363 |
hMC_[4][i]->SetLineColor(style.ST_tColor);
|
364 |
hMC_[4][i]->SetFillColor(style.ST_tColor);
|
365 |
hMC_[4][i]->SetFillStyle(style.ST_tFill);
|
366 |
}
|
367 |
|
368 |
THStack *hst = new THStack(invName,invName);
|
369 |
hst->Add((TH1F*)hQCD_KS[i]->Clone());
|
370 |
if (procSTtch > 0) hst->Add((TH1F*)hMC_[4][i]->Clone());
|
371 |
if (procZJets > 0) hst->Add((TH1F*)hMC_[3][i]->Clone());
|
372 |
hst->Add((TH1F*)hWJets_KS[i]->Clone());
|
373 |
if (procTTbar > 0) hst->Add((TH1F*)hMC_[2][i]->Clone());
|
374 |
|
375 |
// Set plotting parameters
|
376 |
hData_[i] ->SetLineColor(1);
|
377 |
hQCD_NEW[i] ->SetLineColor(2);
|
378 |
hMC_[0][i] ->SetLineColor(4);
|
379 |
hMC_[1][i] ->SetLineColor(3);
|
380 |
hKSres_[i] ->SetLineColor(9);
|
381 |
hKSvalues_[i]->SetLineColor(i+1);
|
382 |
|
383 |
hData_[i] ->SetMarkerColor(1);
|
384 |
hQCD_NEW[i] ->SetMarkerColor(2);
|
385 |
hMC_[0][i] ->SetMarkerColor(4);
|
386 |
hMC_[1][i] ->SetMarkerColor(3);
|
387 |
hKSres_[i] ->SetMarkerColor(9);
|
388 |
hKSvalues_[i]->SetMarkerColor(i+1);
|
389 |
|
390 |
hData_[i] ->SetMarkerStyle((realData ? 20 : 24));
|
391 |
hQCD_NEW[i] ->SetMarkerStyle(20);
|
392 |
hMC_[0][i] ->SetMarkerStyle(20);
|
393 |
hMC_[1][i] ->SetMarkerStyle(20);
|
394 |
hKSres_[i] ->SetMarkerStyle(20);
|
395 |
hKSvalues_[i]->SetMarkerStyle(20);
|
396 |
|
397 |
hData_[i] ->SetMarkerSize((realData ? 1.2 : 1.4));
|
398 |
hQCD_NEW[i] ->SetMarkerSize(1.1);
|
399 |
hMC_[0][i] ->SetMarkerSize(1.1);
|
400 |
hMC_[1][i] ->SetMarkerSize(1.1);
|
401 |
hKSres_[i] ->SetMarkerSize(1.18);
|
402 |
hKSvalues_[i]->SetMarkerSize(1.1);
|
403 |
|
404 |
hData_[i] ->SetStats(0);
|
405 |
hQCD_NEW[i] ->SetStats(0);
|
406 |
hMC_[0][i] ->SetStats(0);
|
407 |
hMC_[1][i] ->SetStats(0);
|
408 |
hKSres_[i] ->SetStats(0);
|
409 |
hKSvalues_[i]->SetStats(0);
|
410 |
hQCD_KS[i] ->SetStats(0);
|
411 |
hWJets_KS[i] ->SetStats(0);
|
412 |
|
413 |
hKSres_[i]->GetXaxis()->SetTitle(histoLabelX[i].c_str());
|
414 |
hKSres_[i]->GetYaxis()->SetTitle("Events");
|
415 |
hKSvalues_[i]->GetXaxis()->SetTitle("#lambda_{wjets}");
|
416 |
hKSvalues_[i]->GetYaxis()->SetTitle("KS test values");
|
417 |
hMC_[0][i]->GetXaxis()->SetTitle(histoLabelX[i].c_str());
|
418 |
hMC_[0][i]->GetYaxis()->SetTitle("A.U.");
|
419 |
|
420 |
TLatex* text1 = new TLatex(1., 1., "2.88 pb^{-1} at #sqrt{s} = 7 TeV");
|
421 |
text1->SetNDC();
|
422 |
text1->SetTextAlign(13);
|
423 |
text1->SetX(0.63);
|
424 |
text1->SetY(0.91);
|
425 |
text1->SetTextFont(42);
|
426 |
text1->SetTextSize(0.03);
|
427 |
text1->SetTextSizePixels(20);// dflt=28
|
428 |
|
429 |
// QCD shape comparison
|
430 |
TString cvsName1 = histoName[i]+"_QCD";
|
431 |
double val_Max_ = 0.;
|
432 |
|
433 |
if(useInv) cvsName1 = cvsName1 + "_" + invName;
|
434 |
cvs[cvsName1] = new TCanvas(cvsName1,"",600,700);
|
435 |
hQCD_NEW[i] -> Scale(1./hQCD_NEW[i]->Integral());
|
436 |
hMC_[0][i] -> Scale(1./hMC_[0][i]->Integral());
|
437 |
hMC_[1][i] -> Scale(1./hMC_[1][i]->Integral());
|
438 |
outprint << "For " << histoName[i] << " , the KStest result btw MC_QCD/InvSel is = "
|
439 |
<< hMC_[0][i] -> KolmogorovTest(hQCD_NEW[i],"") << endl;
|
440 |
|
441 |
hMC_[0][i]->GetXaxis()->SetLabelFont(42);
|
442 |
hMC_[0][i]->GetXaxis()->SetLabelSize(0.04);
|
443 |
hMC_[0][i]->GetXaxis()->SetTitleFont(42);
|
444 |
hMC_[0][i]->GetXaxis()->SetTitleSize(0.05);
|
445 |
hMC_[0][i]->GetXaxis()->SetTitleOffset(1.2);
|
446 |
hMC_[0][i]->GetYaxis()->SetLabelFont(42);
|
447 |
hMC_[0][i]->GetYaxis()->SetLabelSize(0.04);
|
448 |
hMC_[0][i]->GetYaxis()->SetTitleFont(42);
|
449 |
hMC_[0][i]->GetYaxis()->SetTitleSize(0.05);
|
450 |
hMC_[0][i]->GetYaxis()->SetTitleOffset(1.3);
|
451 |
// Get better Y range
|
452 |
Int_t nbMax = hMC_[0][i]->GetMaximumBin();
|
453 |
double tmpval = hMC_[0][i]->GetBinContent(nbMax) + hMC_[0][i]->GetBinError(nbMax);
|
454 |
val_Max_ = (val_Max_ > 1.2*tmpval ? val_Max_ : 1.2*tmpval);
|
455 |
|
456 |
if (useInv) {
|
457 |
nbMax = hQCD_NEW[i]->GetMaximumBin();
|
458 |
tmpval = hQCD_NEW[i]->GetBinContent(nbMax) + hQCD_NEW[i]->GetBinError(nbMax);
|
459 |
val_Max_ = (val_Max_ > 1.2*tmpval ? val_Max_ : 1.2*tmpval);
|
460 |
}
|
461 |
hMC_[0][i]->GetYaxis()->SetRangeUser(0.,(val_Max_ > 1. ? 1. : val_Max_));
|
462 |
if (i == 0) // mu pT plot
|
463 |
hMC_[0][0]->GetXaxis()->SetRangeUser(20.,xhigh[0]);
|
464 |
hMC_[0][i]->DrawCopy("histe");
|
465 |
|
466 |
if (useInv)
|
467 |
hQCD_NEW[i]->DrawCopy("samehiste");
|
468 |
|
469 |
hMC_[1][i]->DrawCopy("samehiste");
|
470 |
TLegend *legend1 = new TLegend(0.6, 0.65, 0.92, 0.9);
|
471 |
legend1->SetFillColor(0);
|
472 |
legend1->SetFillStyle(0);
|
473 |
|
474 |
legend1->AddEntry(hMC_[0][i], "QCD");
|
475 |
if (useInv)
|
476 |
if (!realData) legend1->AddEntry(hQCD_NEW[i], TString("QCD (" + invLabels[ninv] + ")"));
|
477 |
else legend1->AddEntry(hQCD_NEW[i], TString("Data (" + invLabels[ninv]) + ")");
|
478 |
|
479 |
legend1->AddEntry(hMC_[1][i], style.WJetsText);
|
480 |
legend1->Draw();
|
481 |
legend1->SetFillColor(kWhite);
|
482 |
//latex->DrawLatex(0.22,0.91,histoName[i].c_str());
|
483 |
//cvs[cvsName1]->SetLogy();
|
484 |
TString nameCanvas1 = desDir+histoName[i]+"_QCD_"+suffix;
|
485 |
cvs[cvsName1]->SaveAs(nameCanvas1+".pdf");
|
486 |
cvs[cvsName1]->SaveAs(nameCanvas1+".png");
|
487 |
|
488 |
|
489 |
// KS results vs. (pseudo) Data
|
490 |
TString cvsName2 = histoName[i]+"_dataKS";
|
491 |
if(useInv) cvsName2 = cvsName2 + "_" + invName;
|
492 |
cvs[cvsName2] = new TCanvas(cvsName2,"",600,700);
|
493 |
|
494 |
// Get better Y range
|
495 |
val_Max_ = 0.;
|
496 |
nbMax = hData_[i]->GetMaximumBin();
|
497 |
tmpval = hData_[i]->GetBinContent(nbMax) + hData_[i]->GetBinError(nbMax);
|
498 |
val_Max_ = (val_Max_ > 1.05*tmpval ? val_Max_ : 1.05*tmpval);
|
499 |
nbMax = hKSres_[i]->GetMaximumBin();
|
500 |
tmpval = hKSres_[i]->GetBinContent(nbMax) + hKSres_[i]->GetBinError(nbMax);
|
501 |
val_Max_ = (val_Max_ > 1.05*tmpval ? val_Max_ : 1.05*tmpval);
|
502 |
|
503 |
hData_[i]->GetYaxis()->SetRangeUser(0.,val_Max_);
|
504 |
|
505 |
if (i == 0) // mu pT plot
|
506 |
hData_[0]->GetXaxis()->SetRangeUser(20.,xhigh[0]);
|
507 |
hData_[i]->Draw("P");
|
508 |
hst->Draw("samehist");
|
509 |
hKSres_[i]->Draw("samehiste");
|
510 |
hData_[i]->Draw("sameP");
|
511 |
TLegend *legend2 = new TLegend(0.7, 0.64, 0.9, 0.88);
|
512 |
legend2->AddEntry(hData_[i], (realData ? "Data" : "Pseudo Data"),"p");
|
513 |
legend2->AddEntry(hKSres_[i], "KS result");
|
514 |
if (procTTbar > 0.) legend2->AddEntry(hMC_[2][i], style.TtbarText);
|
515 |
legend2->AddEntry(hWJets_KS[i], style.WJetsText);
|
516 |
if (procZJets > 0.) legend2->AddEntry(hMC_[3][i], style.DYZJetsText);
|
517 |
if (procSTtch > 0.) legend2->AddEntry(hMC_[4][i], style.ST_tText);
|
518 |
if (realData)
|
519 |
legend2->AddEntry(hQCD_KS[i], ((!useInvSelShape || !useInv) ? style.QCDText :
|
520 |
TString("#splitline{Data (" + invLabels[ninv] + ",}{Scaled by IKS)}")));
|
521 |
else
|
522 |
legend2->AddEntry(hQCD_KS[i], ((!useInvSelShape || !useInv) ? style.QCDText :
|
523 |
TString("QCD (" + invLabels[ninv] + ")")));
|
524 |
legend2->SetFillColor(0);
|
525 |
legend2->SetFillStyle(0);
|
526 |
legend2->Draw();
|
527 |
legend2->SetFillColor(kWhite);
|
528 |
//latex->DrawLatex(0.22,0.91,histoName[i].c_str());
|
529 |
//cvs[cvsName2]->SetLogy();
|
530 |
text1->Draw();
|
531 |
TString nameCanvas2 = desDir+histoName[i]+"_dataKS_"+suffix;
|
532 |
cvs[cvsName2]->SaveAs(nameCanvas2+".pdf");
|
533 |
cvs[cvsName2]->SaveAs(nameCanvas2+".png");
|
534 |
|
535 |
}
|
536 |
|
537 |
// KS fit results
|
538 |
TString cvsName3 = "KStestValues";
|
539 |
if(useInv) cvsName3 = cvsName3 + "_" + invName;
|
540 |
cvs[cvsName3] = new TCanvas(cvsName3,"",600,700);
|
541 |
// Zoom-in
|
542 |
Int_t nbins_ = hKSvalues_[0]->GetNbinsX();;
|
543 |
Int_t nbMax_ = 1;
|
544 |
Int_t nbMin_ = nbins_;
|
545 |
double val_Min_ = 1.;
|
546 |
for (int i = 0; i < 3; ++i) {
|
547 |
Int_t tmp = findFirstBinAbove(yLowBound, hKSvalues_[i]);
|
548 |
val_Min_ = (hKSvalues_[i]->GetBinContent(tmp) < 0.8*val_Min_ ?
|
549 |
hKSvalues_[i]->GetBinContent(tmp) : 0.8*val_Min_);
|
550 |
nbMin_ = (nbMin_ < tmp ? nbMin_ : tmp);
|
551 |
tmp = findLastBinAbove(0., hKSvalues_[i]);
|
552 |
nbMax_ = (nbMax_ > tmp ? nbMax_ : tmp);
|
553 |
}
|
554 |
nbMin_ -= (0.1/stepsize);
|
555 |
nbMax_ += (0.1/stepsize);
|
556 |
|
557 |
hKSvalues_[0]->GetXaxis()->SetRange(nbMin_,nbMax_);
|
558 |
hKSvalues_[0]->GetYaxis()->SetRangeUser((1e-36 < val_Min_ ? val_Min_ : 1e-36),1.1);
|
559 |
hKSvalues_[0]->Draw();
|
560 |
hKSvalues_[1]->Draw("same");
|
561 |
hKSvalues_[2]->Draw("same");
|
562 |
TLegend *legend3 = new TLegend(0.2, 0.75, 0.38, 0.93);
|
563 |
legend3->AddEntry(hKSvalues_[0], "muon_pT");
|
564 |
legend3->AddEntry(hKSvalues_[1], "MET");
|
565 |
legend3->AddEntry(hKSvalues_[2], "W_mT");
|
566 |
legend3->SetFillColor(0);
|
567 |
legend3->SetFillStyle(0);
|
568 |
legend3->Draw();
|
569 |
legend3->SetFillColor(kWhite);
|
570 |
//latex->DrawLatex(0.22,0.91,"KS test values");
|
571 |
cvs[cvsName3]->SetLogy();
|
572 |
TString nameCanvas3 = desDir+"KStestValues_newQCD_"+suffix;
|
573 |
cvs[cvsName3]->SaveAs(nameCanvas3+".pdf");
|
574 |
cvs[cvsName3]->SaveAs(nameCanvas3+".png");
|
575 |
|
576 |
} //End of nsel loop
|
577 |
} // End of ninv loop
|
578 |
}
|