ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Jeng/scripts/ikstest.h
Revision: 1.1
Committed: Fri Sep 3 05:05:19 2010 UTC (14 years, 8 months ago) by jengbou
Content type: text/plain
Branch: MAIN
Log Message:
Update: move functions to header file

File Contents

# User Rev Content
1 jengbou 1.1 #include <vector>
2     #include <TROOT.h>
3     #include <TFile.h>
4     #include <TH1.h>
5     #include <TH2.h>
6     #include <TLatex.h>
7     #include <TCanvas.h>
8     #include <TMath.h>
9     #include <TLegend.h>
10     #include <TObject.h>
11     #include <iostream>
12     #include <sstream>
13     #include <fstream>
14     #include <iomanip>
15     #include <map>
16     #include <sys/types.h>
17     #include <sys/stat.h>
18     #include <stdio.h>
19    
20     const double stepsize = 0.001;
21     //=================================
22     // Structure/Functions
23     //=================================
24    
25     struct testMC {
26     testMC(Double_t p = 0., Double_t sb = 0., Double_t ss = 0.){prob=p; scaleF_backg = sb; scaleF_sample = ss;}
27     Double_t prob;
28     Double_t scaleF_backg;
29     Double_t scaleF_sample;
30     };
31    
32     //function for doing KS test
33     vector<testMC> doKStest(Double_t NsS, Double_t Ns1, Double_t Ns2, TH1F* mixS, TH1F* s1, TH1F* s2) {
34     vector<testMC> output;
35     //define the scale factors
36     Double_t sf1 = 0.0; // QCD
37     Double_t sf2 = 0.0; // Wjets
38     //KS test
39     do {
40     sf1 = (NsS - Ns2*sf2)/Ns1;
41     if (sf1 < 0) break;
42     //cout << "..........sf1 = " << sf1 << endl;
43     int nbins = mixS->GetNbinsX();
44     double xmin = mixS->GetXaxis()->GetBinLowEdge(1);
45     double xmax = mixS->GetXaxis()->GetBinUpEdge(nbins);
46     TH1F *test = new TH1F("test", "", nbins, xmin, xmax);
47     test -> Sumw2();
48     test -> Add(s1,s2,sf1,sf2);
49     //test->Scale(1./(1.*test->Integral()));
50     Double_t probability = mixS -> KolmogorovTest(test,"");
51     testMC temp = testMC(probability,sf1,sf2);
52     output.push_back(temp);
53     // cout << "probability = " << setw(15) << temp.prob
54     // << "; sfQCD = " << setw(10) << temp.scaleF_backg
55     // << "; sfWjets = " << setw(6) << temp.scaleF_sample << endl;
56     delete test;
57     sf2 = sf2 + stepsize;
58     } while(sf1 > 0 && sf2 <= 2.0);
59     return output;
60     }
61    
62     //get the maximum KS test result
63     testMC getMax(vector<testMC> vec) {
64     testMC maxKSRes;
65     Double_t maximum = 0.0;
66     for (size_t i = 0; i < vec.size(); i++) {
67     if (maximum < vec.at(i).prob) {
68     maximum = vec.at(i).prob;
69     maxKSRes = vec.at(i);
70     }
71     }
72     cout << "for maximum: " << setw(12) << maxKSRes.prob
73     << "; sb = " << setw(10) << maxKSRes.scaleF_backg
74     << "; ss = " << setw(5) << maxKSRes.scaleF_sample << endl;
75     return maxKSRes;
76     }