ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Jeng/scripts/ikstest.h
Revision: 1.2
Committed: Tue Sep 7 05:18:46 2010 UTC (14 years, 8 months ago) by jengbou
Content type: text/plain
Branch: MAIN
Changes since 1.1: +1 -0 lines
Log Message:
Update

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(Double_t NsS, Double_t Ns1, Double_t Ns2, TH1F* mixS, TH1F* s1, TH1F* s2) {
35 vector<testMC> output;
36 //define the scale factors
37 Double_t sf1 = 0.0; // QCD
38 Double_t sf2 = 0.0; // Wjets
39 //KS test
40 do {
41 sf1 = (NsS - Ns2*sf2)/Ns1;
42 if (sf1 < 0) break;
43 //cout << "..........sf1 = " << sf1 << endl;
44 int nbins = mixS->GetNbinsX();
45 double xmin = mixS->GetXaxis()->GetBinLowEdge(1);
46 double xmax = mixS->GetXaxis()->GetBinUpEdge(nbins);
47 TH1F *test = new TH1F("test", "", nbins, xmin, xmax);
48 test -> Sumw2();
49 test -> Add(s1,s2,sf1,sf2);
50 //test->Scale(1./(1.*test->Integral()));
51 Double_t probability = mixS -> KolmogorovTest(test,"");
52 testMC temp = testMC(probability,sf1,sf2);
53 output.push_back(temp);
54 // cout << "probability = " << setw(15) << temp.prob
55 // << "; sfQCD = " << setw(10) << temp.scaleF_backg
56 // << "; sfWjets = " << setw(6) << temp.scaleF_sample << endl;
57 delete test;
58 sf2 = sf2 + stepsize;
59 } while(sf1 > 0 && sf2 <= 2.0);
60 return output;
61 }
62
63 //get the maximum KS test result
64 testMC getMax(vector<testMC> vec) {
65 testMC maxKSRes;
66 Double_t maximum = 0.0;
67 for (size_t i = 0; i < vec.size(); i++) {
68 if (maximum < vec.at(i).prob) {
69 maximum = vec.at(i).prob;
70 maxKSRes = vec.at(i);
71 }
72 }
73 cout << "for maximum: " << setw(12) << maxKSRes.prob
74 << "; sb = " << setw(10) << maxKSRes.scaleF_backg
75 << "; ss = " << setw(5) << maxKSRes.scaleF_sample << endl;
76 return maxKSRes;
77 }