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

Comparing UserCode/Jeng/scripts/ikstest.cc (file contents):
Revision 1.5 by jengbou, Tue Sep 7 03:59:59 2010 UTC vs.
Revision 1.9 by jengbou, Thu Sep 9 08:03:25 2010 UTC

# Line 1 | Line 1
1   #include "ikstest.h"
2 + #include "TopStyle/CMSTopStyle.cc"
3  
4   //=================================
5   // Program to run IKS test
# Line 19 | Line 20
20   using namespace std;
21  
22   //define the constants: 2.88/pb
23 < const double weight_[3]    = {0.0524313, //QCD
24 <                              0.0091395, //WJets
25 <                              0.000306   //TTbar
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 procttjets  = 1.0;
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 desDir = "Results_2.88pb-1/";
36 > TString baseDir      = "Results_2.88pb-1_Incl3/";
37   // User defined parameters
38 < bool useInv    = false; // whether to use n-1 QCD template
39 < bool realData  = false;
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 < TString suffix = "Sel0"; // Suffix of selection
44 < TString invNames[2] = {"RelIsogt0p1","D0gt0p02"};
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 <  TString invName;
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 <    invName = invNames[ninv];
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 += "MC/";
75 <      else desDir += "Data_MC/";
74 >      if (!realData) desDir = baseDir + "MC/";
75 >      else desDir = baseDir + "Data_MC/";
76      } else {
77 <      if (!realData) desDir += "MC_"+invName+"/";
78 <      else desDir += "Data_"+invName+"/";
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! Continues? (enter to continue; 'q' for quit)" << endl;
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;
# Line 68 | Line 90 | void ikstest() {
90          return;
91        }
92      }
93 <
94 <    ofstream outprint(TString(desDir+"Results_"+suffix+".txt"));
95 <    //open the files with histograms
96 <    map<string,TFile*> mfile;
97 <    mfile["Data"] = TFile::Open(TString("skimmed_Data_2.88pb-1/Data_"+suffix+".root"));
98 <    // n-1 cuts
99 <    if (useInv) {
100 <      if (realData)
101 <        mfile["InvSel"] = TFile::Open(TString("skimmed_Data_2.88pb-1/Data_"+suffix+"_"+invName+".root"));
102 <      else
103 <        mfile["InvSel"] = TFile::Open(TString("skimmed_MC/v5/QCD_"+suffix+"_"+invName+".root"));
104 <    }
105 <    // RefSel MC
106 <    mfile["0"] = TFile::Open(TString("skimmed_MC/v5/QCD_"+suffix+".root"));
107 <    mfile["1"] = TFile::Open(TString("skimmed_MC/v5/WJets_"+suffix+".root"));
86 <    mfile["2"] = TFile::Open(TString("skimmed_MC/v5/TTbar_"+suffix+".root"));
87 <
88 <    //define histograms and related parameters
89 <    string histoName[3] = {"h_mu_pt_calo","h_met_calo","h_mt_calo"};
90 <    string histoLabelX[3] = {"p_{T}^{#mu} [GeV/c]", "#slash{E}_{T} [GeV/c]", "M_{T}^{W} [GeV/c^{2}]"};
91 <    Int_t xbins[3] = {20,20,40};
92 <    Double_t xlow[3] = {0.,0.,0.};
93 <    Double_t xhigh[3] = {100.,100.,200.};
94 <    string sample[3] = {"QCD","Wjets","ttjets"};
95 <
96 <    TH1F* h_[9];
97 <    TH1F* mixh_[3];
98 <    TH1F* hQCD_NEW[3];
99 <    TH1F* hKSres_[3];
100 <    TH1F* hKSvalues_[3];
101 <
102 <    //load the histograms from the root files
103 <    for (int i = 0; i < 3; i++) {// 3 variables
104 <      //cout << "file[" << i << "] : " << endl;
105 <      string nameNewHisto = "mix_"+histoName[i];
106 <      string nameNewHistoSFKS = "finalSF_"+histoName[i];
107 <      string nameNewHistoKSvalues = "KSvalues_"+histoLabelX[i];
108 <
109 <      mixh_[i] = new TH1F(nameNewHisto.c_str(),"",xbins[i],xlow[i],xhigh[i]);
110 <      hKSres_[i] = new TH1F(nameNewHistoSFKS.c_str(),"",xbins[i],xlow[i],xhigh[i]);
111 <      hKSvalues_[i] = new TH1F(nameNewHistoKSvalues.c_str(),"",2./stepsize, stepsize, 2.+stepsize);
112 <
113 <      if (!useInv) {//use QCD MC sample
114 <        hQCD_NEW[i] = (TH1F*) mfile["0"]->Get(TString(histoName[i]))->Clone();
115 <        hQCD_NEW[i] -> Scale(weight_[0]);
116 <        hQCD_NEW[i] -> SetName((histoName[i]).c_str());
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 <      else {
110 <        hQCD_NEW[i] = (TH1F*) mfile["InvSel"]->Get(TString(histoName[i]));
111 <        if (!realData) hQCD_NEW[i] -> Scale(weight_[0]);
112 <        hQCD_NEW[i] -> SetName((histoName[i]).c_str());
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 <      mixh_[i] -> Sumw2();
164 <      hKSres_[i] -> Sumw2();
165 <      hKSvalues_[i] -> Sumw2();
166 <    }
167 <
168 <    for (int n = 0; n < 3; ++n) {// 3 MC samples
169 <      for (int ihisto = 0; ihisto < 3; ihisto++) {// 3 variables
170 <        //cout << "Variable[" << ihisto << "]" << endl;
171 <        string histo_name = histoName[ihisto]+sample[n];
172 <        ostringstream ss;
173 <        ss << n;
174 <        h_[n*3+ihisto] = (TH1F*) mfile[ss.str()]->Get(TString(histoName[ihisto]))->Clone();
175 <        h_[n*3+ihisto] -> Scale(weight_[n]);
176 <        h_[n*3+ihisto] -> SetName(histo_name.c_str());
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        }
139    }
181  
182 <    //create the mixed samples = "data"
183 <    TString cvsName0 = "Data";
184 <    if (useInv) {
185 <      cvsName0 += "_";
186 <      cvsName0 += invName;
146 <    }
147 <    cvs[cvsName0] = new TCanvas(cvsName0,"Data distributions",600,700);
148 <    cvs[cvsName0]->Divide(3,1);
149 <    for (int i = 0; i < 3; i++) {
150 <      cvs[cvsName0]->cd(i+1);
151 <      if (!realData) {
152 <        mixh_[i] -> Add(h_[i],h_[i+3], procQCD,procWjets);
153 <        //mixh_[i] -> Add(mixh_[i],h_[i+6], 1,procttjets);
154 <        //cout << "histo_name: " << mixh_[0]->GetNbinsX() << endl;
182 >      //create the mixed samples = "data"
183 >      TString cvsName0 = "Data";
184 >      if (useInv) {
185 >        cvsName0 += "_";
186 >        cvsName0 += invName;
187        }
188 <      else {
189 <        TH1F *htmp = (TH1F*) mfile["Data"]->Get(TString(histoName[i]));
190 <        mixh_[i] -> Add(htmp,1.);
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 <      mixh_[i]->GetXaxis()->SetTitle(histoLabelX[i].c_str());
209 <      mixh_[i]->GetYaxis()->SetTitle("Entries");
210 <      mixh_[i]->DrawClone();
211 <    }
212 <    cvs[cvsName0]->SaveAs(TString(desDir+"Data_distributions.pdf"));
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  
166    //define the weight corrections for each sample
167    double NevData                = mixh_[2]->Integral();
168    double corr_NevQCD          = h_[2]->Integral();
169    double corr_NevQCD_NEW        = hQCD_NEW[2]->Integral();
170    double corr_NevWjets        = h_[5]->Integral();
171    double corr_Nevttjets       = h_[8]->Integral();
172    double corr_Nevmix          = procQCD*corr_NevQCD+procWjets*corr_NevWjets;
173    //double corr_Nevmix            = procQCD*corr_NevQCD+procWjets*corr_NevWjets+procttjets*corr_Nevttjets;
174    if (!realData)
175      outprint << "Events mix sample    = " << corr_Nevmix << endl;
176    else
234        outprint << "Events in Data       = " << NevData << endl;
235 <    outprint << "Events QCD sample    = " << corr_NevQCD << endl;
236 <    outprint << "Events Wjets sample  = " << corr_NevWjets << endl;
180 <    outprint << "Events InvSel sample = " << corr_NevQCD_NEW << endl;
181 <
182 <    //define the containers for chosen numbers (coressponding to the max KStest result)
183 <    testMC maxProb[3];
184 <
185 <    //define the scale factors calculated using information obtained from all parameters
186 <    Double_t SFbackg = 0.0;
187 <    Double_t sumSFbackg = 0.0;
188 <    Double_t SFsample = 0.0;
189 <    Double_t sumSFsample = 0.0;
190 <    Double_t allKS = 0.0;
191 <
192 <    //do the KS test by varying the scale factors
193 <    for (int i = 0; i < 3; i++) { // 3 variables
194 <      TH1F *data = (TH1F*)mixh_[i]->Clone();
195 <      data -> SetName("dataClone");
196 <      //data -> Scale(1./data->Integral());
197 <      vector<testMC> resultsKS = doKStest((realData ? NevData : corr_Nevmix),
198 <                                          (useInv ? corr_NevQCD_NEW : corr_NevQCD),
199 <                                          corr_NevWjets,
200 <                                          data, hQCD_NEW[i], h_[i+3]);
201 <      testMC tksmax = getMax(resultsKS);
202 <      maxProb[i] = tksmax;
203 <      outprint << "\nFor the plot " << histoLabelX[i] << " the results are:"<< endl;
204 <      outprint << "\tmax Probability = " << maxProb[i].prob << endl;
205 <      outprint << "\tproc_background = " << maxProb[i].scaleF_backg << endl;
206 <      outprint << "\tproc_sample     = " << maxProb[i].scaleF_sample << endl;
207 <
208 <      outprint << "\n\tpercent_B of Data = "
209 <               << maxProb[i].scaleF_backg*corr_NevQCD_NEW*100/(realData ? NevData : corr_Nevmix) << endl;
210 <      outprint << "\tpercent_S of Data = "
211 <               << maxProb[i].scaleF_sample*corr_NevWjets*100/(realData ? NevData : corr_Nevmix) << endl;
235 >      outprint << "Events QCD sample    = " << corr_NevQCD << endl;
236 >      outprint << "Events InvSel sample = " << corr_NevQCD_NEW << endl;
237        outprint << "---------------------------" << endl;
238 <
239 <      //create the mixed samples with KS test results
240 <      sumSFbackg += maxProb[i].prob*maxProb[i].scaleF_backg;
241 <      sumSFsample += maxProb[i].prob*maxProb[i].scaleF_sample;
242 <      allKS += maxProb[i].prob;
243 <
244 <      //fill a histogram with the results from the KS test for each variable
245 <      for (int jiter = 0; jiter < resultsKS.size(); jiter++) {
246 <        if (resultsKS.at(jiter).prob == 1.)
247 <          cout << "variable [" << i << "]: prob[" << jiter << "]= " << resultsKS.at(jiter).prob << endl;
248 <        hKSvalues_[i]->SetBinContent(jiter,resultsKS.at(jiter).prob);
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        }
225      delete data;
226    }
294  
295 <    //calculate the final scale factors
296 <    SFbackg = sumSFbackg/allKS;
297 <    SFsample = sumSFsample/allKS;
298 <    outprint << "allKS = " << allKS << "\tbackground = " << SFbackg << "\tsample = " << SFsample << endl;
299 <    outprint << "==> Scale Factor for QCD MC = " << SFbackg*corr_NevQCD_NEW/corr_NevQCD << endl;
300 <    outprint << "\tcombined percent_B of Data = "
301 <             << SFbackg*corr_NevQCD_NEW*100/(realData ? NevData : corr_Nevmix) << endl;
302 <    outprint << "\tcombined percent_S of Data = "
303 <             << SFsample*corr_NevWjets*100/(realData ? NevData : corr_Nevmix) << endl;
304 <    outprint << "\n" << endl;
305 <    outprint << "=================================" << endl;
306 <    outprint << "\n" << endl;
307 <
308 <
309 <    //=================================
310 <    // Plots
311 <    //=================================
312 <    for (int i = 0; i < 3; i++) {// 3 variables
313 <      hKSres_[i] -> Add(hQCD_NEW[i],h_[i+3],SFbackg,SFsample);
314 <      outprint << "hKSres->Integral() = " << hKSres_[i]->Integral() << endl;
315 <      outprint << "Data->Integral()   = " << mixh_[i]->Integral() << endl;
316 <
317 <      mixh_[i]->Rebin(2);
318 <      hQCD_NEW[i]->Rebin(2);
319 <      h_[i]->Rebin(2);
320 <      h_[i+3]->Rebin(2);
321 <      hKSres_[i]->Rebin(2);
322 <      //hKSvalues_[i]->Rebin(2);
323 <
324 <      mixh_[i]     ->SetLineColor(1);
325 <      hQCD_NEW[i]  ->SetLineColor(2);
326 <      h_[i]        ->SetLineColor(4);
327 <      h_[i+3]      ->SetLineColor(3);
328 <      hKSres_[i]   ->SetLineColor(2);
329 <      hKSvalues_[i]->SetLineColor(i+1);
330 <
331 <      mixh_[i]     ->SetMarkerColor(1);
332 <      hQCD_NEW[i]  ->SetMarkerColor(2);
333 <      h_[i]        ->SetMarkerColor(4);
334 <      h_[i+3]      ->SetMarkerColor(3);
335 <      hKSres_[i]   ->SetMarkerColor(2);
336 <      hKSvalues_[i]->SetMarkerColor(i+1);
337 <
338 <      mixh_[i]     ->SetMarkerStyle(24);
339 <      hQCD_NEW[i]  ->SetMarkerStyle(20);
340 <      h_[i]        ->SetMarkerStyle(20);
341 <      h_[i+3]      ->SetMarkerStyle(20);
342 <      hKSres_[i]   ->SetMarkerStyle(20);
343 <      hKSvalues_[i]->SetMarkerStyle(20);
344 <
345 <      mixh_[i]     ->SetMarkerSize(1.4);
346 <      hQCD_NEW[i]  ->SetMarkerSize(1.1);
347 <      h_[i]        ->SetMarkerSize(1.1);
348 <      h_[i+3]      ->SetMarkerSize(1.1);
349 <      hKSres_[i]   ->SetMarkerSize(0.9);
350 <      hKSvalues_[i]->SetMarkerSize(1.1);
351 <
352 <      mixh_[i]     ->SetStats(0);
353 <      hQCD_NEW[i]  ->SetStats(0);
354 <      h_[i]        ->SetStats(0);
355 <      h_[i+3]      ->SetStats(0);
356 <      hKSres_[i]   ->SetStats(0);
357 <      hKSvalues_[i]->SetStats(0);
358 <
359 <      hKSres_[i]->GetXaxis()->SetTitle(histoLabelX[i].c_str());
360 <      hKSres_[i]->GetYaxis()->SetTitle("Entries");
361 <      hKSvalues_[i]->GetXaxis()->SetTitle("iteration #");
362 <      hKSvalues_[i]->GetYaxis()->SetTitle("KS test values");
363 <      h_[i]->GetXaxis()->SetTitle(histoLabelX[i].c_str());
364 <      h_[i]->GetYaxis()->SetTitle("A.U.");
365 <
366 <      TString nameCanvas1 = desDir+histoName[i]+"_QCD_"+suffix+".pdf";
367 <      TString cvsName1 = histoName[i]+"_QCD";
368 <      if(useInv) cvsName1 = cvsName1 + "_" + invName;
369 <      cvs[cvsName1] = new TCanvas(cvsName1,"",600,700);
370 <      hQCD_NEW[i] -> Scale(1./hQCD_NEW[i]->Integral());
371 <      h_[i] -> Scale(1./h_[i]->Integral());
372 <      h_[i+3] -> Scale(1./h_[i+3]->Integral());
373 <      outprint << "For " << histoName[i] << " , the KStest result btw MC_QCD/InvSel is = "
374 <               << h_[i] -> KolmogorovTest(hQCD_NEW[i],"") << endl;
375 <      h_[i]->Draw("P");
376 <      if (useInv)
377 <        hQCD_NEW[i]->Draw("sameP");
378 <      h_[i+3]->Draw("sameP");
379 <      TLegend *legend1 = new TLegend(0.7, 0.70, 0.9, 0.85);
380 <      legend1->AddEntry(h_[i], "QCD");
381 <      if (useInv)
382 <        legend1->AddEntry(hQCD_NEW[i], "QCD - InvSel");
383 <      legend1->AddEntry(h_[i+3], "W+jets");
384 <      legend1->Draw();
385 <      legend1->SetFillColor(kWhite);
386 <      //latex->DrawLatex(0.22,0.91,histoName[i].c_str());
387 <      //cvs[cvsName1]->SetLogy();
388 <      cvs[cvsName1]->SaveAs(nameCanvas1);
389 <
390 <      TString nameCanvas2 = desDir+histoName[i]+"_dataKS_"+suffix+".pdf";
391 <      TString cvsName2 = histoName[i]+"_dataKS";
392 <      if(useInv) cvsName2 = cvsName2 + "_" + invName;
393 <      cvs[cvsName2] = new TCanvas(cvsName2,"",600,700);
394 <      hKSres_[i]->Draw("P");
395 <      mixh_[i]->Draw("sameP");
396 <      TLegend *legend2 = new TLegend(0.7, 0.70, 0.9, 0.85);
397 <      legend2->AddEntry(mixh_[i], "Data");
398 <      legend2->AddEntry(hKSres_[i], "KS result");
399 <      legend2->Draw();
400 <      legend2->SetFillColor(kWhite);
401 <      //latex->DrawLatex(0.22,0.91,histoName[i].c_str());
402 <      //cvs[cvsName2]->SetLogy();
403 <      cvs[cvsName2]->SaveAs(nameCanvas2);
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 <    }
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 <    TString cvsName3 = "KStestValues";
558 <    if(useInv) cvsName3 = cvsName3 + "_" + invName;
559 <    cvs[cvsName3] = new TCanvas(cvsName3,"",600,700);
560 <    //hKSvalues_[0]->GetXaxis()->SetRangeUser(0.9,1.2);
561 <    hKSvalues_[0]->GetYaxis()->SetRangeUser(1e-36,1.2);
562 <    hKSvalues_[0]->Draw();
563 <    hKSvalues_[1]->Draw("same");
564 <    hKSvalues_[2]->Draw("same");
565 <    TLegend *legend3 = new TLegend(0.7, 0.70, 0.9, 0.85);
566 <    legend3->AddEntry(hKSvalues_[0], "muon_pT");
567 <    legend3->AddEntry(hKSvalues_[1], "MET");
568 <    legend3->AddEntry(hKSvalues_[2], "W_mT");
569 <    legend3->Draw();
570 <    legend3->SetFillColor(kWhite);
571 <    //latex->DrawLatex(0.22,0.91,"KS test values");
572 <    cvs[cvsName3]->SetLogy();
573 <    TString nameCanvas3 = desDir+"KStestValues_newQCD"+suffix+".pdf";
574 <    cvs[cvsName3]->SaveAs(nameCanvas3);
575 <  }
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   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines