ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/NonMCBackground/macros/plot_fakes.C
Revision: 1.2
Committed: Sat Dec 17 21:27:18 2011 UTC (13 years, 5 months ago) by dkralph
Content type: text/plain
Branch: MAIN
CVS Tags: compiled, synced_FSR_2, synced_FSR, synched, AN490, HEAD
Changes since 1.1: +13 -17 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 dkralph 1.1 #if !defined(__CINT__) || defined(__MAKECINT__)
2     #include <TROOT.h> // access to gROOT, entry point to ROOT system
3     #include <TFile.h> // file handle class
4     #include <TTree.h> // class to access ntuples
5     #include <TChain.h>
6     #include <TCanvas.h> // class for drawing
7     #include <TH1F.h> // 1D histograms
8     #include <TH2F.h> // 2D histograms
9     #include <TBenchmark.h> // class to track macro running statistics
10     #include <TVector3.h> // 3D vector class
11     #include <TRegexp.h> // 3D vector class
12     #include <vector> // STL vector class
13     #include <iostream> // standard I/O
14     #include <iomanip> // functions to format standard I/O
15     #include <fstream> // functions for file I/O
16     #include <string> // C++ string class
17     #include <sstream> // class for parsing strings
18     #include "RooHistPdf.h"
19     #include "RooGlobalFunc.h"
20     #include "RooPlot.h"
21     #include "RooRealVar.h"
22     #include "RooDataHist.h"
23     #include "RooGenericPdf.h"
24     #include "RooDataSet.h"
25     #include "RooAddPdf.h"
26     #include "RooFormulaVar.h"
27     #include "RooCurve.h"
28     #include "RooBinning.h"
29     #include "Common/CPlot.hh" // helper class for plots
30     #include "Common/MitStyleRemix.hh" // style settings for drawing
31     #include "Common/MyTools.hh" // miscellaneous helper functions
32     #include "Common/CSample.hh" // helper class for organizing input ntuple files
33    
34     #endif
35     using namespace RooFit;
36    
37     TString scheme = "bdt-medium";
38     TString lumi = "4700";
39     TCanvas *c = new TCanvas("c","c");
40     vector<TString> fnamev,labelv;
41    
42    
43     //----------------------------------------------------------------------------------------
44     class filestuff
45     {
46     public:
47     filestuff(TString nameval, TString filename);
48     TString name;
49     TChain *chain;
50     TString fname;
51     };
52     filestuff::filestuff(TString nameval, TString filename)
53     {
54     name = nameval;
55     fname = filename;
56     chain = new TChain(nameval,nameval);
57     chain->AddFile(fname,-1,"passtuple");
58     }
59     //----------------------------------------------------------------------------------------
60     TH1F* get_FR_pred(filestuff fs, TString var, TString extra, int nbins, double xmin, double xmax, double &integral, bool oneZ=false) {
61     TString hname = "hFR_"+fs.name+var;
62     TH1F* hFR = new TH1F(hname,"",nbins,xmin,xmax); hFR->Sumw2();
63     if(oneZ) fs.chain->Draw(var+">>"+hname,"w*(w!=1)"+extra); // for Z + one fake 'w' is fake weight
64     else fs.chain->Draw(var+">>"+hname,"w"+extra); //
65     integral = hFR->Integral();
66     return hFR;
67     }
68    
69     TH1F* get_Obs(filestuff fs, TString var, TString extra, int nbins, double xmin, double xmax, double &integral) {
70     TString hname = "hObs_"+fs.name+var;
71     TH1F* hObs = new TH1F(hname,"",nbins,xmin,xmax); hObs->Sumw2();
72     fs.chain->Draw(var+">>"+hname,"(w==1)"+extra);
73     integral = hObs->Integral();
74     return hObs;
75     }
76    
77     TH1F* get_MC(filestuff fs, TString var, TString extra, int nbins, double xmin, double xmax, double &integral, bool oneZ=false) {
78     TString hname = "hMC_"+fs.name+var;
79     TH1F *hMC = new TH1F(hname,"",nbins,xmin,xmax); hMC->Sumw2();
80     if(oneZ) fs.chain->Draw(var+">>"+hname,lumi+"*xswgt*npuw*(w==1)"+extra); // here 'w' is the fake weight (1 for tight events)
81     else fs.chain->Draw(var+">>"+hname,lumi+"*npuw*w*won*woff"+extra); // but in these files, 'w' is the xs weight
82     integral = hMC->Integral();
83     return hMC;
84     }
85    
86     TH1F* get_MC_FR_pred(filestuff fs, TString var, TString extra, int nbins, double xmin, double xmax, double &integral, bool oneZ=false) {
87     TString hname = "hMC_FR_pred_"+fs.name+var;
88     TH1F *hMC_FR_pred = new TH1F(hname,"",nbins,xmin,xmax); hMC_FR_pred->Sumw2();
89     if(oneZ) fs.chain->Draw(var+">>"+hname,lumi+"*w*(w!=1)*npuw*xswgt"+extra); // here 'w' is the fake weight
90     else fs.chain->Draw(var+">>"+hname,lumi+"*w*npuw*xswgt*won*woff"+extra); // (and here...)
91     integral = hMC_FR_pred->Integral();
92     return hMC_FR_pred;
93     }
94    
95     void plot_fakes()
96     {
97     CPlot::sOutDir = "~/public_html/4lfakes";
98    
99     map<TString,TTree*> treemap;
100     map<TString,TString> labelmap;
101    
102 dkralph 1.2 TString suffix("test");
103     filestuff single("single","root/ntuples/singleEle-bdt-medium-"+suffix+".root");
104     filestuff doublel("doublel","root/ntuples/doubleEle-bdt-medium-"+suffix+".root");
105     filestuff zjets_single("zjets_single","root/ntuples/singleEle-bdt-medium-zjets-"+suffix+".root");
106     filestuff zjets_double("zjets_double","root/ntuples/doubleEle-bdt-medium-zjets-"+suffix+".root");
107     filestuff zz_single("zz_single","root/ntuples/singleEle-bdt-medium-ZZ-powheg-"+suffix+".root");
108     filestuff gg2zz_single("gg2zz_single","root/ntuples/singleEle-bdt-medium-gg2zz-"+suffix+".root");
109     filestuff gg2zz_double("gg2zz_double","root/ntuples/doubleEle-bdt-medium-gg2zz-"+suffix+".root");
110     filestuff zllg_single("zllg_single","root/ntuples/singleEle-bdt-medium-zllg-"+suffix+".root");
111     filestuff zllg_double("zllg_double","root/ntuples/doubleEle-bdt-medium-zllg-"+suffix+".root");
112     filestuff wzmg_single("wzmg_single","root/ntuples/singleEle-bdt-medium-wzmg-"+suffix+".root");
113 dkralph 1.1
114     // Z + one fake
115     filestuff oneZ_data("oneZ_data","root/ntuples/oneZ-bdt-medium-iso07-new.root");
116     filestuff oneZ_zjets("oneZ_zjets","root/ntuples/oneZ-bdt-medium-zjets-iso07-new.root");
117    
118     double xmin,xmax,integral;
119     int nbins;
120     TString var,cut,extra,ylabel;
121     TH1F *htmp,*htmp2;
122     //----------------------------------------------------------------------------------------
123    
124     cut = "*(1)";
125     ylabel = "events";
126    
127     var = "m4l";
128     xmin = 0; xmax = 750; nbins = 10;
129     extra = cut;
130     CPlot plotm4l_single(var+"_single","","#bf{m4l [GeV]}",ylabel);
131     htmp = get_FR_pred(single,var,extra,nbins,xmin,xmax,integral);
132     plotm4l_single.AddHist1D(htmp,"single loop","E");
133     plotm4l_single.AddToStack(get_MC_FR_pred(wzmg_single,var,extra,nbins,xmin,xmax,integral),"wz single loop",kBlue);
134     plotm4l_single.AddToStack(get_MC_FR_pred(gg2zz_single,var,extra,nbins,xmin,xmax,integral),"ggzz single loop",kRed);
135     // plotm4l_single.AddToStack(get_MC_FR_pred(zllg_single,var,extra,nbins,xmin,xmax,integral),"zllg single loop",843);
136     plotm4l_single.AddToStack(get_MC_FR_pred(zz_single,var,extra,nbins,xmin,xmax,integral),"zz single loop",kGray);
137     plotm4l_single.AddToStack(get_MC_FR_pred(zjets_single,var,extra,nbins,xmin,xmax,integral),"z+jets single loop",kCyan-6);
138     plotm4l_single.SetYRange(0,1.4*htmp->GetMaximum());
139     plotm4l_single.Draw(c,kTRUE,"png");
140    
141     var = "m4l";
142     xmin = 0; xmax = 750; nbins = 40;
143     extra = cut;
144     CPlot plotm4l_single_dataonly(var+"_single_dataonly","","#bf{m4l [GeV]}",ylabel);
145     htmp = get_FR_pred(single,var,extra,nbins,xmin,xmax,integral);
146     plotm4l_single_dataonly.AddToStack(htmp,"FR prediction",kCyan-6);
147     plotm4l_single_dataonly.SetYRange(0,1.4*htmp->GetMaximum());
148     plotm4l_single_dataonly.Draw(c,kTRUE,"png");
149    
150     var = "met";
151     xmin = 0; xmax = 120; nbins = 10;
152     extra = cut;
153     CPlot plotmet_single(var+"_single","","#bf{met [GeV]}",ylabel);
154     htmp = get_FR_pred(single,var,extra,nbins,xmin,xmax,integral);
155     plotmet_single.AddHist1D(htmp,"single loop","E");
156     htmp2 = get_FR_pred(doublel,var,extra,nbins,xmin,xmax,integral); htmp2->Scale(2.);
157     // plotmet_single.AddHist1D(htmp2,"2*(double loop)","hist",kRed);
158     plotmet_single.AddToStack(get_MC_FR_pred(wzmg_single,var,extra,nbins,xmin,xmax,integral),"wz single loop",kBlue);
159 dkralph 1.2 // plotmet_single.AddToStack(get_MC_FR_pred(tt2l_single,var,extra,nbins,xmin,xmax,integral),"t#bar{t} single loop",kRed);
160 dkralph 1.1 // plotmet_single.AddToStack(get_MC_FR_pred(zllg_single,var,extra,nbins,xmin,xmax,integral),"zllg single loop",843);
161     plotmet_single.AddToStack(get_MC_FR_pred(zz_single,var,extra,nbins,xmin,xmax,integral),"zz single loop",kGray);
162     plotmet_single.AddToStack(get_MC_FR_pred(zjets_single,var,extra,nbins,xmin,xmax,integral),"z+jets single loop",kCyan-6);
163     plotmet_single.SetYRange(0,1.4*htmp->GetMaximum());
164     plotmet_single.Draw(c,kTRUE,"png");
165    
166     var = "mt";
167     xmin = 7; xmax = 150; nbins = 10;
168     extra = cut;
169     CPlot plotpt4_single(var+"_single","","#bf{p_{T} [GeV]}",ylabel);
170     htmp = get_FR_pred(single,var,extra,nbins,xmin,xmax,integral);
171     plotpt4_single.AddHist1D(htmp,"single loop","E");
172     htmp2 = get_FR_pred(doublel,var,extra,nbins,xmin,xmax,integral);
173     htmp2->Scale(2.);
174     // plotpt4_single.AddHist1D(htmp2,"2*(double loop)","hist",kRed);
175     plotpt4_single.AddToStack(get_MC_FR_pred(wzmg_single,var,extra,nbins,xmin,xmax,integral),"wz single loop",kBlue);
176     // plotpt4_single.AddToStack(get_MC_FR_pred(zllg_single,var,extra,nbins,xmin,xmax,integral),"zllg single loop",843);
177     plotpt4_single.AddToStack(get_MC_FR_pred(zz_single,var,extra,nbins,xmin,xmax,integral),"zz single loop",kGray);
178     plotpt4_single.AddToStack(get_MC_FR_pred(zjets_single,var,extra,nbins,xmin,xmax,integral),"z+jets single loop",kCyan-6);
179     plotpt4_single.SetYRange(0,1.4*htmp->GetMaximum());
180     plotpt4_single.Draw(c,kTRUE,"png");
181    
182     var = "m4l";
183     xmin = 0; xmax = 750; nbins = 10;
184     extra = cut;
185     CPlot plotm4l_double(var+"_double","","#bf{m4l [GeV]}",ylabel);
186     plotm4l_double.AddHist1D(get_FR_pred(doublel,var,extra,nbins,xmin,xmax,integral),"double loop","E");
187     plotm4l_double.AddToStack(get_MC_FR_pred(zjets_double,var,extra,nbins,xmin,xmax,integral),"z+jets double loop",kCyan-6);
188     htmp = get_MC_FR_pred(zjets_single,var,extra,nbins,xmin,xmax,integral);
189     htmp->Scale(1./2);
190     plotm4l_double.AddHist1D(htmp,"0.5*(z+jets single loop)","hist",kRed);
191     plotm4l_double.Draw(c,kTRUE,"png");
192    
193     var = "m3l";
194     xmin = 50; xmax = 500; nbins = 20;
195     extra = cut + "/w";
196     CPlot plotm3l(var,"","#bf{m3l [GeV]}",ylabel);
197     plotm3l.AddHist1D(get_FR_pred(single,var,extra,nbins,xmin,xmax,integral),"single loop","E");
198     plotm3l.AddToStack(get_MC_FR_pred(wzmg_single,var,extra,nbins,xmin,xmax,integral),"wz single loop",kBlue);
199     plotm3l.AddToStack(get_MC_FR_pred(zjets_single,var,extra,nbins,xmin,xmax,integral),"z+jets single loop",kCyan-6);
200     plotm3l.Draw(c,kTRUE,"png");
201    
202     //
203     // Z + one fake
204     //
205     var = "met";
206     xmin = 0; xmax = 100; nbins = 40;
207     extra = cut + "*(mZ1>0)";
208     CPlot plotOneZ_met(var+"_oneZ","","#bf{MET [GeV]}",ylabel);
209     plotOneZ_met.AddHist1D(get_Obs(oneZ_data,var,extra,nbins,xmin,xmax,integral),"Obs","E");
210     plotOneZ_met.AddHist1D(get_FR_pred(oneZ_data,var,extra,nbins,xmin,xmax,integral,true),"FR predic","hist",kBlue);
211     plotOneZ_met.AddHist1D(get_MC(oneZ_zjets,var,extra,nbins,xmin,xmax,integral,true),"z+jets","hist",kRed);
212     plotOneZ_met.AddToStack(get_MC_FR_pred(oneZ_zjets,var,extra,nbins,xmin,xmax,integral,true),"z+jets FR prediction",kCyan-6);
213     plotOneZ_met.Draw(c,kTRUE,"png");
214    
215     var = "mZ1";
216     xmin = 60; xmax = 110; nbins = 50;
217     extra = cut + "*(mZ1>0)";
218     CPlot plotOneZ_mZ1(var+"_oneZ","","#bf{mZ1 [GeV]}",ylabel);
219     plotOneZ_mZ1.AddHist1D(get_Obs(oneZ_data,var,extra,nbins,xmin,xmax,integral),"Obs","E");
220 dkralph 1.2 cout << "one Z yields: " << endl;
221 dkralph 1.1 cout << "Data obs.:\t\t" << integral << endl;
222     plotOneZ_mZ1.AddHist1D(get_FR_pred(oneZ_data,var,extra,nbins,xmin,xmax,integral,true),"FR predic","hist",kBlue);
223     cout << "Data FR predic.:\t" << integral << endl;
224     plotOneZ_mZ1.AddHist1D(get_MC(oneZ_zjets,var,extra,nbins,xmin,xmax,integral,true),"z+jets","hist",kRed);
225     cout << "z+jets obs.:\t\t" << integral << endl;
226     plotOneZ_mZ1.AddToStack(get_MC_FR_pred(oneZ_zjets,var,extra,nbins,xmin,xmax,integral,true),"z+jets FR prediction",kCyan-6);
227     cout << "z+jets FR predic.:\t" << integral << endl;
228     plotOneZ_mZ1.TransLegend(-.4,0);
229     plotOneZ_mZ1.Draw(c,kTRUE,"png");
230    
231     }