ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Jeng/scripts/skim.C
Revision: 1.2
Committed: Thu Apr 16 21:02:44 2009 UTC (16 years ago) by jengbou
Content type: text/plain
Branch: MAIN
Changes since 1.1: +53 -29 lines
Log Message:
Update

File Contents

# Content
1 #define skim_cxx
2 #include "skim.h"
3 #include <TH2.h>
4 #include <THStack.h>
5 #include <TStyle.h>
6 #include <TCanvas.h>
7 #include <TMath.h>
8 #include <TMultiGraph.h>
9 #include <TGraphErrors.h>
10 #include <TCanvas.h>
11 #include "Math/GSLIntegrator.h"
12 #include "Math/WrappedTF1.h"
13 #include <iostream>
14 #include <TLegend.h>
15 #include <TPaveStats.h>
16 #include <TTree.h>
17
18 TString fileName = "skimmed/QCDbin4_OldRelIso_rebin.root";
19 // TString fileName = "skimmed/QCDbin4_OldRelIso_FastSim.root";
20 bool FastSim = false;
21 TString isoname = "Old";
22 // Jet bin:
23 Int_t jbin = 4; // 1-3, 4 for >=4. Put in number less than 5
24 double binwidth = 0.02; // 0.02,0.02,0.05,0.1 for New RelIso
25 // Histo range
26 double xMin = 0.0;
27 double xMax = 0.0;
28 // Specify fitting function:
29 // Select New or Old reliso:
30 double d0sigCut = 3.;
31
32 Int_t fjbin;
33 Double_t fna; // Num of QCD events in signal region
34
35 int nbin;
36
37 void skim::Loop()
38 {
39 // In a ROOT session, you can do:
40 // Modify jbin, binwidth, wxmin, wxmax
41 // Root > .L skim.C++
42 // Root > skim t
43 // Root > t.GetEntry(12); // Fill t data members with entry number 12
44 // Root > t.Show(); // Show values of entry 12
45 // Root > t.Show(16); // Read and show values of entry 16
46 // Root > t.Loop(); // Loop on all entries
47
48 if ( isoname.Contains("Old") ) {
49 xMax = 1+binwidth;
50 nbin = (1.0-xMin)/binwidth+1;
51 }
52 else if ( isoname.Contains("New") ) {
53 xMax = 2.0;
54 nbin = (xMax-xMin)/binwidth;
55 }
56 else {
57 cout << "No Rel Iso defined!" << endl;
58 return;
59 }
60 cout << "nbin for histo = " << nbin << endl;
61 TTree *ftree = new TTree("myTree","myTree");
62 ftree->AutoSave();
63 ftree->Branch("jbin",&fjbin,"jbin/I");
64 ftree->Branch("na",&fna,"na/D");
65 ftree->SetBranchAddress("jbin",&fjbin);
66 ftree->SetBranchAddress("na",&fna);
67
68 TH1D *h_RelIso_ttbar = new TH1D("h_RelIso_ttbar","h_RelIso_ttbar",nbin,xMin,xMax);
69 TH1D *h_RelIso_qcd = new TH1D("h_RelIso_qcd","h_RelIso_qcd",nbin,xMin,xMax);
70 TH1D *h_RelIso_wjets = new TH1D("h_RelIso_wjets","h_RelIso_wjets",nbin,xMin,xMax);
71 TH1D *h_RelIso_zjets = new TH1D("h_RelIso_zjets","h_RelIso_zjets",nbin,xMin,xMax);
72 TH1D *h_RelIso_all = new TH1D("h_RelIso_all","h_RelIso_all",nbin,xMin,xMax);
73
74 // define fit region:
75 double AX0 = 0.;
76 double AXf = 0.;
77
78 cout<<"Use "<<isoname<<" RelIso"<<endl;
79
80 if ( isoname.Contains("Old") ) {
81 // old
82 AX0 = 0.95;
83 AXf = 1.0;
84 }
85 else if ( isoname.Contains("New") ) {
86 // new
87 AX0 = 0.0;
88 AXf = 0.053; // default:0.053 ; loose:0.11
89 }
90
91 // Weights:
92 double wttbar,wqcd,wwjets,wzjets;
93 wttbar = wqcd = wwjets = wzjets = 0.;
94 if ( ! FastSim ) {
95 cout << "Full sim sample weights used " << endl;
96 // Full Sim
97 wttbar = 0.0101;
98 wqcd = 1.3161;
99 wwjets = 0.0977;
100 wzjets = 0.078;
101 }
102 else {
103 // Fast Sim
104 cout << "Fast sim sample weights used " << endl;
105 wttbar = 0.0008;
106 wqcd = 0.676;
107 wwjets = 0.0091;
108 wzjets = 0.0094;
109 }
110
111 // Na = num of qcd in signal region
112 double Na;
113 Na = 0;
114
115 double Nttbar, NWjets, NZjets, Nqcd;
116 Nttbar = NWjets = NZjets = Nqcd = 0;
117 double reliso = 0.0;
118
119 if (fChain == 0) return;
120
121 Long64_t nentries = fChain->GetEntriesFast();
122
123 Long64_t nbytes = 0, nb = 0;
124 for (Long64_t jentry=0; jentry<nentries;jentry++) {
125 Long64_t ientry = LoadTree(jentry);
126 if (ientry < 0) break;
127 nb = fChain->GetEntry(jentry); nbytes += nb;
128 // if (Cut(ientry) < 0) continue;
129 bool signalRegion = false;
130
131 TString filename(fChain->GetCurrentFile()->GetName());
132 if (isoname.Contains("Old")) {
133 reliso = top_muon_old_reliso[0];
134 if ( reliso > AX0 ) signalRegion = true;
135 }
136 else if (isoname.Contains("New")) {
137 reliso = top_muon_new_reliso[0];
138 if ( reliso < AXf ) signalRegion = true;
139 }
140 else {
141 cout<<"No RelIso defined!!!"<<endl;
142 return;
143 }
144
145 double d0sig = TMath::Abs(top_muon_d0[0])/top_muon_d0Error[0];
146 bool correctBin = false; // jet bin condition
147 bool goodD0sig = false; // d0sig condition
148
149 if ( jbin > 4 ) {cout<<"Don't mess around!!! jbin should be less than 5!"<<endl;return;}
150 if (top_njets == jbin && jbin != 4) correctBin = true;
151 else if (top_njets >= jbin && jbin == 4) correctBin = true;
152 if ( d0sig < d0sigCut ) goodD0sig = true;
153
154 // Counting
155 if( correctBin && goodD0sig ) {
156 if ( filename.Contains("TT") ) {
157 h_RelIso_ttbar->Fill(reliso);
158 if ( signalRegion ) { Nttbar += wttbar; }
159 }
160 if ( filename.Contains("Mu") ) {
161 h_RelIso_qcd->Fill(reliso);
162 if ( signalRegion ) { Na += wqcd; Nqcd+= wqcd; } // QCD in signal region
163 }
164 if ( filename.Contains("WJets") ) {
165 h_RelIso_wjets->Fill(reliso);
166 if ( signalRegion ) { NWjets += wwjets; }
167 }
168 if ( filename.Contains("ZJets") ) {
169 h_RelIso_zjets->Fill(reliso);
170 if ( signalRegion ) { NZjets += wzjets; }
171 }
172 }
173 }
174 fjbin=jbin;
175 fna=Na;
176 ftree->Fill();
177 cout << "\n";
178 cout << " N ttbar = " << Nttbar << endl;
179 cout << " N qcd = " << Nqcd << endl;
180 cout << " N Wjets = " << NWjets << endl;
181 cout << " N Zjets = " << NZjets << endl << endl;
182
183 TFile *file0 = new TFile(fileName,"RECREATE");
184 file0->mkdir("histos");
185 file0->mkdir("hstack");
186 file0->cd("histos");
187 TCanvas *cv1 = new TCanvas("cv1","cv1",800,600);
188 THStack *hs = new THStack("hs","RelIso (stacked)");
189
190 // Take care of scaling
191 h_RelIso_qcd->Scale(wqcd);
192 h_RelIso_wjets->Scale(wwjets);
193 h_RelIso_zjets->Scale(wzjets);
194 h_RelIso_ttbar->Scale(wttbar);
195
196 // Save for later use
197 h_RelIso_ttbar->Write();
198 h_RelIso_qcd->Write();
199 h_RelIso_wjets->Write();
200 h_RelIso_zjets->Write();
201
202 h_RelIso_qcd->SetXTitle("Combined Relative Isolation");
203 h_RelIso_qcd->SetLineColor(40);
204 h_RelIso_qcd->SetFillStyle(3018);
205 h_RelIso_qcd->SetFillColor(38);
206 hs->Add(h_RelIso_qcd);
207 h_RelIso_wjets->SetMarkerColor(4);
208 h_RelIso_wjets->SetLineColor(4);
209 h_RelIso_wjets->SetFillColor(4);
210 hs->Add(h_RelIso_wjets);
211 h_RelIso_zjets->SetMarkerColor(5);
212 h_RelIso_zjets->SetLineColor(5);
213 h_RelIso_zjets->SetFillColor(5);
214 hs->Add(h_RelIso_zjets);
215 h_RelIso_ttbar->SetMarkerColor(2);
216 h_RelIso_ttbar->SetLineColor(2);
217 h_RelIso_ttbar->SetFillColor(2);
218 hs->Add(h_RelIso_ttbar);
219 hs->Draw();
220
221 // Label histo
222 TLegend * leg0 = new TLegend(0.3,0.3,0.6,0.55);
223 leg0->AddEntry(h_RelIso_ttbar,"t#bar{t}");
224 leg0->AddEntry(h_RelIso_qcd,"QCD (MuPt15) ");
225 leg0->AddEntry(h_RelIso_wjets,"W+jets");
226 leg0->AddEntry(h_RelIso_zjets,"Z+jets");
227 leg0->Draw();
228
229 h_RelIso_all->Add(h_RelIso_ttbar,1.);
230 h_RelIso_all->Add(h_RelIso_qcd,1.);
231 h_RelIso_all->Add(h_RelIso_wjets,1.);
232 h_RelIso_all->Add(h_RelIso_zjets,1.);
233 h_RelIso_all->Write();
234 h_RelIso_all->SetLineWidth(2);
235
236 if( jbin == 4)
237 h_RelIso_all->SetTitle( isoname+" RelIso distribution (#geq 4 jets)");
238 else if ( jbin < 4 ) {
239 TString title = isoname+" RelIso distribution (";
240 title += jbin;
241 title += " jets)";
242 h_RelIso_all->SetTitle(title);
243 }
244 else {
245 cout<<"Don't mess around!!! jbin should be less than 5!"<<endl;
246 return;
247 }
248 h_RelIso_all->SetMinimum(0);
249
250 file0->cd("hstack");
251 hs->Write();
252
253 file0->cd();
254 ftree->Write();
255 file0->Close();
256 }
257