ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Jeng/scripts/ikstest.h
(Generate patch)

Comparing UserCode/Jeng/scripts/ikstest.h (file contents):
Revision 1.3 by jengbou, Wed Sep 8 04:51:35 2010 UTC vs.
Revision 1.4 by jengbou, Thu Sep 9 08:03:25 2010 UTC

# Line 9 | Line 9
9   #include <TMath.h>
10   #include <TLegend.h>
11   #include <TObject.h>
12 + #include <TStyle.h>
13   #include <iostream>
14   #include <sstream>
15   #include <fstream>
# Line 39 | Line 40 | vector<testMC> doKStest(const vector<Dou
40    Double_t Ns  = 0.0; // non-Wjets (ttbar,Zjets,single top...)
41    for (UInt_t i = 3; i < vnevt.size(); ++i)
42      Ns += vnevt[i];
43 <  //cout << "Total number of Non Wjets events = " << Ns << endl;
43 >  cout << "Total number of Non Wjets events = " << Ns << endl;
44    //KS test
45    do {
46      sf1 = (vnevt.at(0) - Ns - vnevt.at(2)*sf2)/vnevt.at(1);
# Line 75 | Line 76 | vector<testMC> doKStest(const vector<Dou
76   }
77  
78   //get the maximum KS test result
79 < testMC getMax(vector<testMC> vec) {
79 > testMC getMax(vector<testMC> & vec) {
80    testMC maxKSRes;
81    Double_t maximum = 0.0;
82 +
83 +  vector<int> posMax;
84    for (size_t i = 0; i < vec.size(); i++) {
85 <    if (maximum < vec.at(i).prob)  {
86 <      maximum = vec.at(i).prob;
87 <      maxKSRes = vec.at(i);
85 >    if (vec.at(i).prob != 1.) {
86 >      if (maximum < vec.at(i).prob)  {
87 >        maximum = vec.at(i).prob;
88 >        maxKSRes = vec.at(i);
89 >      }
90 >    }
91 >    else if (vec.at(i).prob == 1.) {
92 >      maximum = 1.;
93 >      posMax.push_back(i);
94 >    }
95 >  }
96 >
97 >  if (posMax.size() > 0) {
98 >    int tot_ = 0;
99 >    for (vector<int>::iterator iv = posMax.begin();
100 >         iv != posMax.end(); ++iv) {
101 >      tot_ += *iv;
102      }
103 +    int med_ = (int) tot_/posMax.size();
104 +    maxKSRes = vec.at(med_);
105    }
106    cout << "for maximum: " << setw(12) << maxKSRes.prob
107         << "; sb = " << setw(10) << maxKSRes.scaleF_backg
108         << "; ss = " << setw(5) << maxKSRes.scaleF_sample << endl;
109    return maxKSRes;
110   }
111 +
112 + Int_t findFirstBinAbove(Double_t threshold,TH1* f) {
113 +  Int_t nbins = f->GetNbinsX();
114 +  for (int nb = 1; nb <= nbins; nb++) {
115 +    if (f->GetBinContent(nb) > threshold) return nb;
116 +  }
117 +  return -1;
118 + }
119 +
120 + Int_t findLastBinAbove(Double_t threshold,TH1* f) {
121 +  Int_t nbins = f->GetNbinsX();
122 +  for (int nb = nbins; nb >= 1; nb--) {
123 +    if (f->GetBinContent(nb) > threshold) return nb;
124 +  }
125 +  return -1;
126 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines