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.8 by jengbou, Wed Sep 8 06:47:15 2010 UTC vs.
Revision 1.9 by jengbou, Thu Sep 9 08:03:25 2010 UTC

# Line 33 | Line 33 | const Double_t procZJets   = 1.;
33   const Double_t procSTtch   = 1.;
34  
35   // Output directory
36 < TString baseDir = "Results_2.88pb-1_NEW/";
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  
# Line 62 | Line 66 | void ikstest() {
66    }
67  
68    int size_ninv = (useInv ? 2 : 1);
69 <  for (int ninv = 0;ninv < size_ninv; ++ninv) {
69 >  for (int ninv = 0; ninv < size_ninv; ++ninv) {
70      TString invName = invNames[ninv];
71      TString desDir;
72      // create output directory
# Line 86 | 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.clear();
98 <    mfile["Data"] = TFile::Open(TString("skimmed_Data_2.88pb-1/Data_"+suffix+".root"));
99 <    // n-1 cuts
100 <    if (useInv) {
101 <      if (realData)
102 <        mfile["InvSel"] = TFile::Open(TString("skimmed_Data_2.88pb-1/Data_"+suffix+"_"+invName+".root"));
103 <      else
104 <        mfile["InvSel"] = TFile::Open(TString("skimmed_MC/v5/QCD_"+suffix+"_"+invName+".root"));
105 <    }
106 <    // RefSel MC
107 <    mfile["0"] = TFile::Open(TString("skimmed_MC/v5/QCD_"+suffix+".root"));
104 <    mfile["1"] = TFile::Open(TString("skimmed_MC/v5/WJets_"+suffix+".root"));
105 <    mfile["2"] = TFile::Open(TString("skimmed_MC/v5/TTbar_"+suffix+".root"));
106 <    mfile["3"] = TFile::Open(TString("skimmed_MC/v5/ZJets_"+suffix+".root"));
107 <    mfile["4"] = TFile::Open(TString("skimmed_MC/v5/STtch_"+suffix+".root"));
108 <
109 <    //define histograms and related parameters
110 <    string histoName[3] = {"h_mu_pt_calo","h_met_calo","h_mt_calo"};
111 <    string histoLabelX[3] = {"p_{T}^{#mu} [GeV/c]", "#slash{E}_{T} [GeV/c]", "M_{T}^{W} [GeV/c^{2}]"};
112 <    Int_t xbins[3] = {20,20,40};
113 <    Double_t xlow[3] = {0.,0.,0.};
114 <    Double_t xhigh[3] = {100.,100.,200.};
115 <    string sample[5] = {"QCD","WJets","TTbar","ZJets","STtch"};
116 <
117 <    TH1F* hMC_[5][3];   // MC histograms
118 <    TH1F* hData_[3];    // Data or mix MC
119 <    TH1F* hQCD_NEW[3];  // InvSel QCD shape
120 <    TH1F* hKSres_[3];
121 <    TH1F* hKSvalues_[3];
122 <    TH1F* hQCD_KS[3];
123 <    TH1F* hWJets_KS[3];
124 <
125 <    //load the histograms from the root files
126 <    for (int vi = 0; vi < 3; ++vi) {// 3 variables
127 <      //cout << "file[" << vi << "] : " << endl;
128 <      string nameNewHisto = "mix_"+histoName[vi];
129 <      string nameNewHistoSFKS = "finalSF_"+histoName[vi];
130 <      string nameNewHistoKSvalues = "KSvalues_"+histoLabelX[vi];
131 <
132 <      hData_[vi] = new TH1F(nameNewHisto.c_str(),"",xbins[vi],xlow[vi],xhigh[vi]);
133 <      hKSres_[vi] = new TH1F(nameNewHistoSFKS.c_str(),"",xbins[vi],xlow[vi],xhigh[vi]);
134 <      hKSvalues_[vi] = new TH1F(nameNewHistoKSvalues.c_str(),"",2./stepsize, stepsize, 2.+stepsize);
135 <
136 <      ostringstream ssc;
137 <      ssc << vi;
138 <
139 <      if (!useInv) {//use QCD MC sample
140 <        hQCD_NEW[vi] = (TH1F*) mfile["0"]->Get(TString(histoName[vi]))->Clone();
141 <        hQCD_NEW[vi] -> Scale(weight_[0]);
142 <        hQCD_NEW[vi] -> SetName(TString("InvSel_"+histoName[vi]+"_"+ssc.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[vi] = (TH1F*) mfile["InvSel"]->Get(TString(histoName[vi]))->Clone();
111 <        if (!realData) hQCD_NEW[vi] -> Scale(weight_[0]);
112 <        hQCD_NEW[vi] -> SetName(TString("InvSel_"+histoName[vi]+"_"+ssc.str()));
113 <      }
114 <      if (debug_) cout << "hQCD_NEW[" << vi << "] @ " << hQCD_NEW[vi] << endl;
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 <    }
158 >        hData_[vi] -> Sumw2();
159 >        hKSres_[vi] -> Sumw2();
160 >        hKSvalues_[vi] -> Sumw2();
161 >      }
162  
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;
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        }
173    }
181  
182 <    //create the mixed samples = "data"
183 <    TString cvsName0 = "Data";
184 <    if (useInv) {
185 <      cvsName0 += "_";
186 <      cvsName0 += invName;
180 <    }
181 <    cvs[cvsName0] = new TCanvas(cvsName0,"Data distributions",600,700);
182 <    cvs[cvsName0]->Divide(3,1);
183 <    for (int i = 0; i < 3; i++) {
184 <      cvs[cvsName0]->cd(i+1);
185 <      if (!realData) {
186 <        hData_[i] -> Add(hMC_[0][i],hMC_[1][i], procQCD,procWJets);
187 <        hData_[i] -> Add(hMC_[2][i], procTTbar);
188 <        hData_[i] -> Add(hMC_[3][i], procZJets);
189 <        hData_[i] -> Add(hMC_[4][i], procSTtch);
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 <        hData_[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 <      hData_[i]->GetXaxis()->SetTitle(histoLabelX[i].c_str());
209 <      hData_[i]->GetYaxis()->SetTitle("Entries");
197 <      hData_[i]->DrawClone();
198 <    }
199 <    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_;
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 <
234 <    outprint << "Events in Data       = " << NevData << endl;
235 <    outprint << "Events QCD sample    = " << corr_NevQCD << endl;
236 <    outprint << "Events InvSel sample = " << corr_NevQCD_NEW << endl;
227 <    outprint << "---------------------------" << endl;
228 <    outprint << "Events WJets sample  = " << corr_NevWJets << endl;
229 <    outprint << "Events TTbar sample  = " << corr_NevTTbar << endl;
230 <    outprint << "Events ZJets sample  = " << corr_NevZJets << endl;
231 <    outprint << "Events STtch sample  = " << corr_NevSTtch << endl;
232 <
233 <    //define the containers for chosen numbers (coressponding to the max KStest result)
234 <    testMC maxProb[3];
235 <
236 <    //define the scale factors calculated using information obtained from all parameters
237 <    Double_t SFbackg = 0.0;
238 <    Double_t sumSFbackg = 0.0;
239 <    Double_t SFsample = 0.0;
240 <    Double_t sumSFsample = 0.0;
241 <    Double_t allKS = 0.0;
242 <
243 <    //do the KS test by varying the scale factors
244 <    for (int i = 0; i < 3; i++) { // 3 variables
245 <      TH1F *data = (TH1F*)hData_[i]->Clone("data");
246 <      data -> SetName("dataClone");
247 <      map<string,TH1F*> mHisto_;
248 <      mHisto_.clear();
249 <      mHisto_["Data"]  = data;
250 <      mHisto_["QCD"]   = (useInv ? (TH1F*)hQCD_NEW[i]->Clone() : (TH1F*)hMC_[0][i]->Clone());
251 <      mHisto_["WJets"] = (TH1F*)hMC_[1][i]->Clone();//WJets
252 <      if (procTTbar > 0.) mHisto_["TTbar"] = (TH1F*)hMC_[2][i]->Clone();//TTbar
253 <      if (procZJets > 0.) mHisto_["ZJets"] = (TH1F*)hMC_[3][i]->Clone();//ZJets
254 <      if (procSTtch > 0.) mHisto_["STtch"] = (TH1F*)hMC_[4][i]->Clone();//STtch
255 <
256 <      //data -> Scale(1./data->Integral());
257 <      vector<testMC> resultsKS = doKStest(vNev_,mHisto_);
258 <      testMC tksmax = getMax(resultsKS);
259 <      maxProb[i] = tksmax;
260 <      outprint << "\nFor the plot " << histoLabelX[i] << " the results are:"<< endl;
261 <      outprint << "\tmax Probability = " << maxProb[i].prob << endl;
262 <      outprint << "\tproc_background = " << maxProb[i].scaleF_backg << endl;
263 <      outprint << "\tproc_sample     = " << maxProb[i].scaleF_sample << endl;
264 <
265 <      outprint << "\n\tpercent_B of Data = "
266 <               << maxProb[i].scaleF_backg*corr_NevQCD_NEW*100/NevData << endl;
267 <      outprint << "\tpercent_S of Data = "
268 <               << maxProb[i].scaleF_sample*corr_NevWJets*100/NevData << endl;
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 >
234 >      outprint << "Events in Data       = " << NevData << 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 (unsigned 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        }
282      delete data;
283    }
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/NevData << endl;
302 <    outprint << "\tcombined percent_S of Data = "
303 <             << SFsample*corr_NevWJets*100/NevData << 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((TH1F*)hQCD_NEW[i]->Clone(),(TH1F*)hMC_[1][i]->Clone(),SFbackg,SFsample);
314 <      hKSres_[i] -> Add((TH1F*)hMC_[2][i]->Clone(),procTTbar);
315 <      hKSres_[i] -> Add((TH1F*)hMC_[3][i]->Clone(),procZJets);
316 <      hKSres_[i] -> Add((TH1F*)hMC_[4][i]->Clone(),procSTtch);
317 <
318 <      outprint << "hKSres->Integral() = " << hKSres_[i]->Integral() << endl;
319 <      outprint << "Data->Integral()   = " << hData_[i]->Integral() << endl;
320 <
321 <      hData_[i]->Rebin(2);
322 <      hQCD_NEW[i]->Rebin(2);
323 <      hMC_[0][i]->Rebin(2);
324 <      hMC_[1][i]->Rebin(2);
325 <      hKSres_[i]->Rebin(2);
326 <      //hKSvalues_[i]->Rebin(2);
327 <
328 <      // Stack Wjets and QCD after scaled by KS factors
329 <      hQCD_KS[i] = (TH1F*) hQCD_NEW[i]->Clone();
330 <      hQCD_KS[i]->Scale(SFbackg);
331 <      hQCD_KS[i]->SetLineColor(style.QCDColor);
332 <      hQCD_KS[i]->SetFillColor(style.QCDColor);
333 <      hQCD_KS[i]->SetFillStyle(style.QCDFill);
334 <
335 <      hWJets_KS[i] = (TH1F*) hMC_[1][i]->Clone();
336 <      hWJets_KS[i]->Scale(SFsample);
337 <      hWJets_KS[i]->SetLineColor(style.WJetsColor);
338 <      hWJets_KS[i]->SetFillColor(style.WJetsColor);
339 <      hWJets_KS[i]->SetFillStyle(style.WJetsFill);
340 <
341 <      if (procTTbar > 0.) {
342 <        hMC_[2][i]->Rebin(2);
343 <        hMC_[2][i]->SetLineColor(style.TtbarColor);
344 <        hMC_[2][i]->SetFillColor(style.TtbarColor);
345 <        hMC_[2][i]->SetFillStyle(style.TtbarFill);
346 <      }
347 <      if (procZJets > 0.) {
348 <        hMC_[3][i]->Rebin(2);
349 <        hMC_[3][i]->SetLineColor(style.DYZJetsColor);
350 <        hMC_[3][i]->SetFillColor(style.DYZJetsColor);
351 <        hMC_[3][i]->SetFillStyle(style.DYZJetsFill);
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        }
536 <      if (procSTtch > 0.) {
537 <        hMC_[4][i]->Rebin(2);
538 <        hMC_[4][i]->SetLineColor(style.ST_t_sColor);
539 <        hMC_[4][i]->SetFillColor(style.ST_t_sColor);
540 <        hMC_[4][i]->SetFillStyle(style.ST_t_sFill);
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 <      THStack *hst = new THStack(invName,invName);
555 <      hst->Add((TH1F*)hQCD_KS[i]->Clone());
351 <      if (procSTtch > 0) hst->Add((TH1F*)hMC_[4][i]->Clone());
352 <      if (procZJets > 0) hst->Add((TH1F*)hMC_[3][i]->Clone());
353 <      hst->Add((TH1F*)hWJets_KS[i]->Clone());
354 <      if (procTTbar > 0) hst->Add((TH1F*)hMC_[2][i]->Clone());
355 <
356 <      // Set plotting parameters
357 <      hData_[i]    ->SetLineColor(1);
358 <      hQCD_NEW[i]  ->SetLineColor(2);
359 <      hMC_[0][i]   ->SetLineColor(4);
360 <      hMC_[1][i]   ->SetLineColor(3);
361 <      hKSres_[i]   ->SetLineColor(2);
362 <      hKSvalues_[i]->SetLineColor(i+1);
363 <
364 <      hData_[i]    ->SetMarkerColor(1);
365 <      hQCD_NEW[i]  ->SetMarkerColor(2);
366 <      hMC_[0][i]   ->SetMarkerColor(4);
367 <      hMC_[1][i]   ->SetMarkerColor(3);
368 <      hKSres_[i]   ->SetMarkerColor(2);
369 <      hKSvalues_[i]->SetMarkerColor(i+1);
370 <
371 <      hData_[i]    ->SetMarkerStyle(24);
372 <      hQCD_NEW[i]  ->SetMarkerStyle(20);
373 <      hMC_[0][i]   ->SetMarkerStyle(20);
374 <      hMC_[1][i]   ->SetMarkerStyle(20);
375 <      hKSres_[i]   ->SetMarkerStyle(20);
376 <      hKSvalues_[i]->SetMarkerStyle(20);
377 <
378 <      hData_[i]    ->SetMarkerSize(1.4);
379 <      hQCD_NEW[i]  ->SetMarkerSize(1.1);
380 <      hMC_[0][i]   ->SetMarkerSize(1.1);
381 <      hMC_[1][i]   ->SetMarkerSize(1.1);
382 <      hKSres_[i]   ->SetMarkerSize(0.9);
383 <      hKSvalues_[i]->SetMarkerSize(1.1);
384 <
385 <      hData_[i]    ->SetStats(0);
386 <      hQCD_NEW[i]  ->SetStats(0);
387 <      hMC_[0][i]   ->SetStats(0);
388 <      hMC_[1][i]   ->SetStats(0);
389 <      hKSres_[i]   ->SetStats(0);
390 <      hKSvalues_[i]->SetStats(0);
391 <      hQCD_KS[i]   ->SetStats(0);
392 <      hWJets_KS[i] ->SetStats(0);
393 <
394 <      hKSres_[i]->GetXaxis()->SetTitle(histoLabelX[i].c_str());
395 <      hKSres_[i]->GetYaxis()->SetTitle("Entries");
396 <      hKSvalues_[i]->GetXaxis()->SetTitle("iteration #");
397 <      hKSvalues_[i]->GetYaxis()->SetTitle("KS test values");
398 <      hMC_[0][i]->GetXaxis()->SetTitle(histoLabelX[i].c_str());
399 <      hMC_[0][i]->GetYaxis()->SetTitle("A.U.");
400 <
401 <
402 <      TString nameCanvas1 = desDir+histoName[i]+"_QCD_"+suffix+".pdf";
403 <      TString cvsName1 = histoName[i]+"_QCD";
404 <      if(useInv) cvsName1 = cvsName1 + "_" + invName;
405 <      cvs[cvsName1] = new TCanvas(cvsName1,"",600,700);
406 <      hQCD_NEW[i] -> Scale(1./hQCD_NEW[i]->Integral());
407 <      hMC_[0][i] -> Scale(1./hMC_[0][i]->Integral());
408 <      hMC_[1][i] -> Scale(1./hMC_[1][i]->Integral());
409 <      outprint << "For " << histoName[i] << " , the KStest result btw MC_QCD/InvSel is = "
410 <               << hMC_[0][i] -> KolmogorovTest(hQCD_NEW[i],"") << endl;
411 <      hMC_[0][i]->DrawCopy("P");
412 <      if (useInv)
413 <        hQCD_NEW[i]->DrawCopy("sameP");
414 <      hMC_[1][i]->DrawCopy("sameP");
415 <      TLegend *legend1 = new TLegend(0.7, 0.65, 0.9, 0.85);
416 <      legend1->AddEntry(hMC_[0][i], "QCD");
417 <      if (useInv)
418 <        legend1->AddEntry(hQCD_NEW[i], "QCD - InvSel");
419 <      legend1->AddEntry(hMC_[1][i], style.WJetsText);
420 <      legend1->Draw();
421 <      legend1->SetFillColor(kWhite);
422 <      //latex->DrawLatex(0.22,0.91,histoName[i].c_str());
423 <      //cvs[cvsName1]->SetLogy();
424 <      cvs[cvsName1]->SaveAs(nameCanvas1);
425 <
426 <
427 <      TString nameCanvas2 = desDir+histoName[i]+"_dataKS_"+suffix+".pdf";
428 <      TString cvsName2 = histoName[i]+"_dataKS";
429 <      if(useInv) cvsName2 = cvsName2 + "_" + invName;
430 <      cvs[cvsName2] = new TCanvas(cvsName2,"",600,700);
431 <      hst->Draw("hist");
432 <      hKSres_[i]->Draw("sameP");
433 <      hData_[i]->Draw("sameP");
434 <
435 <      TLegend *legend2 = new TLegend(0.7, 0.65, 0.9, 0.85);
436 <      legend2->AddEntry(hData_[i], "Data");
437 <      legend2->AddEntry(hKSres_[i], "KS result");
438 <      if (procTTbar > 0.) legend2->AddEntry(hMC_[2][i], style.TtbarText);
439 <      legend2->AddEntry(hWJets_KS[i], style.WJetsText);
440 <      if (procZJets > 0.) legend2->AddEntry(hMC_[3][i], style.DYZJetsText);
441 <      if (procSTtch > 0.) legend2->AddEntry(hMC_[4][i], style.ST_t_sText);
442 <      legend2->AddEntry(hQCD_KS[i], style.QCDText);
443 <      legend2->Draw();
444 <      legend2->SetFillColor(kWhite);
445 <      //latex->DrawLatex(0.22,0.91,histoName[i].c_str());
446 <      //cvs[cvsName2]->SetLogy();
447 <      cvs[cvsName2]->SaveAs(nameCanvas2);
554 >      nbMin_ -= (0.1/stepsize);
555 >      nbMax_ += (0.1/stepsize);
556  
557 <    }
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 <    TString cvsName3 = "KStestValues";
577 <    if(useInv) cvsName3 = cvsName3 + "_" + invName;
453 <    cvs[cvsName3] = new TCanvas(cvsName3,"",600,700);
454 <    if (!realData) hKSvalues_[0]->GetXaxis()->SetRangeUser(0.95,1.1);
455 <    hKSvalues_[0]->GetYaxis()->SetRangeUser(1e-36,1.2);
456 <    hKSvalues_[0]->Draw();
457 <    hKSvalues_[1]->Draw("same");
458 <    hKSvalues_[2]->Draw("same");
459 <    TLegend *legend3 = new TLegend(0.7, 0.70, 0.9, 0.85);
460 <    legend3->AddEntry(hKSvalues_[0], "muon_pT");
461 <    legend3->AddEntry(hKSvalues_[1], "MET");
462 <    legend3->AddEntry(hKSvalues_[2], "W_mT");
463 <    legend3->Draw();
464 <    legend3->SetFillColor(kWhite);
465 <    //latex->DrawLatex(0.22,0.91,"KS test values");
466 <    cvs[cvsName3]->SetLogy();
467 <    TString nameCanvas3 = desDir+"KStestValues_newQCD"+suffix+".pdf";
468 <    cvs[cvsName3]->SaveAs(nameCanvas3);
469 <  }
576 >    } //End of nsel loop
577 >  } // End of ninv loop
578   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines