ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Jeng/scripts/ikstest.h
Revision: 1.3
Committed: Wed Sep 8 04:51:35 2010 UTC (14 years, 7 months ago) by jengbou
Content type: text/plain
Branch: MAIN
Changes since 1.2: +25 -11 lines
Log Message:
Update to include non Wjets contributions

File Contents

# Content
1 #include <vector>
2 #include <TROOT.h>
3 #include <TFile.h>
4 #include <TH1.h>
5 #include <TH2.h>
6 #include <THStack.h>
7 #include <TLatex.h>
8 #include <TCanvas.h>
9 #include <TMath.h>
10 #include <TLegend.h>
11 #include <TObject.h>
12 #include <iostream>
13 #include <sstream>
14 #include <fstream>
15 #include <iomanip>
16 #include <map>
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <stdio.h>
20
21 const double stepsize = 0.001;
22 //=================================
23 // Structure/Functions
24 //=================================
25
26 struct testMC {
27 testMC(Double_t p = 0., Double_t sb = 0., Double_t ss = 0.){prob=p; scaleF_backg = sb; scaleF_sample = ss;}
28 Double_t prob;
29 Double_t scaleF_backg;
30 Double_t scaleF_sample;
31 };
32
33 //function for doing KS test
34 vector<testMC> doKStest(const vector<Double_t>& vnevt, map<string,TH1F*>& mhisto) {
35 vector<testMC> output;
36 //define the scale factors
37 Double_t sf1 = 0.0; // QCD
38 Double_t sf2 = 0.0; // Wjets
39 Double_t Ns = 0.0; // non-Wjets (ttbar,Zjets,single top...)
40 for (UInt_t i = 3; i < vnevt.size(); ++i)
41 Ns += vnevt[i];
42 //cout << "Total number of Non Wjets events = " << Ns << endl;
43 //KS test
44 do {
45 sf1 = (vnevt.at(0) - Ns - vnevt.at(2)*sf2)/vnevt.at(1);
46 if (sf1 < 0) break;
47 //cout << "..........sf1 = " << sf1 << endl;
48 int nbins = mhisto["Data"]->GetNbinsX();
49 double xmin = mhisto["Data"]->GetXaxis()->GetBinLowEdge(1);
50 double xmax = mhisto["Data"]->GetXaxis()->GetBinUpEdge(nbins);
51 TH1F *test = new TH1F("test", "", nbins, xmin, xmax);
52 test->Sumw2();
53 test->Add(mhisto["QCD"],mhisto["WJets"],sf1,sf2);
54 for (map<string,TH1F*>::iterator ihisto = mhisto.begin();
55 ihisto != mhisto.end(); ++ihisto) {
56 if (ihisto->first != "QCD"
57 && ihisto->first != "Data"
58 && ihisto->first != "WJets"
59 ) {
60 test->Add(ihisto->second,1.);
61 }
62 }
63
64 //test->Scale(1./(1.*test->Integral()));
65 Double_t probability = mhisto["Data"]->KolmogorovTest(test,"");
66 testMC temp = testMC(probability,sf1,sf2);
67 output.push_back(temp);
68 /* cout << "probability = " << setw(15) << temp.prob */
69 /* << "; sfQCD = " << setw(10) << temp.scaleF_backg */
70 /* << "; sfWjets = " << setw(6) << temp.scaleF_sample << endl; */
71 delete test;
72 sf2 = sf2 + stepsize;
73 } while(sf1 > 0 && sf2 <= 2.0);
74 return output;
75 }
76
77 //get the maximum KS test result
78 testMC getMax(vector<testMC> vec) {
79 testMC maxKSRes;
80 Double_t maximum = 0.0;
81 for (size_t i = 0; i < vec.size(); i++) {
82 if (maximum < vec.at(i).prob) {
83 maximum = vec.at(i).prob;
84 maxKSRes = vec.at(i);
85 }
86 }
87 cout << "for maximum: " << setw(12) << maxKSRes.prob
88 << "; sb = " << setw(10) << maxKSRes.scaleF_backg
89 << "; ss = " << setw(5) << maxKSRes.scaleF_sample << endl;
90 return maxKSRes;
91 }