ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Jeng/scripts/skim.C
Revision: 1.3
Committed: Mon Apr 20 23:41:31 2009 UTC (16 years ago) by jengbou
Content type: text/plain
Branch: MAIN
Changes since 1.2: +15 -7 lines
Log Message:
update

File Contents

# User Rev Content
1 jengbou 1.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 jengbou 1.3 // Output file
19     TString fileName = "skimmed/QCDbinall_NewRelIso.root";
20 jengbou 1.2 bool FastSim = false;
21 jengbou 1.3 TString isoname = "New";
22 jengbou 1.2 // Jet bin:
23 jengbou 1.3 Int_t jbin = 0; // 1-3, 4 for >=4. Put in number less than 5; 0 for all jets
24     double binwidth = 0.01; // 0.02,0.02,0.05,0.1 for New RelIso
25 jengbou 1.1 // Histo range
26     double xMin = 0.0;
27 jengbou 1.2 double xMax = 0.0;
28 jengbou 1.1 // 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 jengbou 1.2 int nbin;
36    
37 jengbou 1.1 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 jengbou 1.2
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 jengbou 1.1 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 jengbou 1.2 AXf = 0.053; // default:0.053 ; loose:0.11
89 jengbou 1.1 }
90    
91 jengbou 1.2 // 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 jengbou 1.1
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 jengbou 1.2
145 jengbou 1.1 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 jengbou 1.3 if ( jbin == 0 ){
151     if ( top_njets > jbin ) { correctBin = true; }
152     }
153     else if ( jbin == 4 ){
154     if ( top_njets >= jbin ) { correctBin = true; }
155     }
156     else {
157     if ( top_njets == jbin ) { correctBin = true; }
158     }
159    
160 jengbou 1.1 if ( d0sig < d0sigCut ) goodD0sig = true;
161    
162 jengbou 1.2 // Counting
163 jengbou 1.1 if( correctBin && goodD0sig ) {
164 jengbou 1.2 if ( filename.Contains("TT") ) {
165 jengbou 1.1 h_RelIso_ttbar->Fill(reliso);
166     if ( signalRegion ) { Nttbar += wttbar; }
167     }
168 jengbou 1.2 if ( filename.Contains("Mu") ) {
169 jengbou 1.1 h_RelIso_qcd->Fill(reliso);
170     if ( signalRegion ) { Na += wqcd; Nqcd+= wqcd; } // QCD in signal region
171     }
172     if ( filename.Contains("WJets") ) {
173     h_RelIso_wjets->Fill(reliso);
174     if ( signalRegion ) { NWjets += wwjets; }
175     }
176     if ( filename.Contains("ZJets") ) {
177     h_RelIso_zjets->Fill(reliso);
178     if ( signalRegion ) { NZjets += wzjets; }
179     }
180     }
181     }
182     fjbin=jbin;
183     fna=Na;
184     ftree->Fill();
185     cout << "\n";
186     cout << " N ttbar = " << Nttbar << endl;
187     cout << " N qcd = " << Nqcd << endl;
188     cout << " N Wjets = " << NWjets << endl;
189     cout << " N Zjets = " << NZjets << endl << endl;
190    
191     TFile *file0 = new TFile(fileName,"RECREATE");
192     file0->mkdir("histos");
193 jengbou 1.2 file0->mkdir("hstack");
194 jengbou 1.1 file0->cd("histos");
195     TCanvas *cv1 = new TCanvas("cv1","cv1",800,600);
196     THStack *hs = new THStack("hs","RelIso (stacked)");
197    
198     // Take care of scaling
199     h_RelIso_qcd->Scale(wqcd);
200     h_RelIso_wjets->Scale(wwjets);
201     h_RelIso_zjets->Scale(wzjets);
202     h_RelIso_ttbar->Scale(wttbar);
203    
204     // Save for later use
205     h_RelIso_ttbar->Write();
206     h_RelIso_qcd->Write();
207     h_RelIso_wjets->Write();
208     h_RelIso_zjets->Write();
209    
210     h_RelIso_qcd->SetXTitle("Combined Relative Isolation");
211     h_RelIso_qcd->SetLineColor(40);
212     h_RelIso_qcd->SetFillStyle(3018);
213     h_RelIso_qcd->SetFillColor(38);
214     hs->Add(h_RelIso_qcd);
215     h_RelIso_wjets->SetMarkerColor(4);
216     h_RelIso_wjets->SetLineColor(4);
217     h_RelIso_wjets->SetFillColor(4);
218     hs->Add(h_RelIso_wjets);
219     h_RelIso_zjets->SetMarkerColor(5);
220     h_RelIso_zjets->SetLineColor(5);
221     h_RelIso_zjets->SetFillColor(5);
222     hs->Add(h_RelIso_zjets);
223     h_RelIso_ttbar->SetMarkerColor(2);
224     h_RelIso_ttbar->SetLineColor(2);
225     h_RelIso_ttbar->SetFillColor(2);
226     hs->Add(h_RelIso_ttbar);
227     hs->Draw();
228    
229     // Label histo
230     TLegend * leg0 = new TLegend(0.3,0.3,0.6,0.55);
231     leg0->AddEntry(h_RelIso_ttbar,"t#bar{t}");
232     leg0->AddEntry(h_RelIso_qcd,"QCD (MuPt15) ");
233     leg0->AddEntry(h_RelIso_wjets,"W+jets");
234     leg0->AddEntry(h_RelIso_zjets,"Z+jets");
235     leg0->Draw();
236    
237     h_RelIso_all->Add(h_RelIso_ttbar,1.);
238     h_RelIso_all->Add(h_RelIso_qcd,1.);
239     h_RelIso_all->Add(h_RelIso_wjets,1.);
240     h_RelIso_all->Add(h_RelIso_zjets,1.);
241     h_RelIso_all->Write();
242     h_RelIso_all->SetLineWidth(2);
243    
244     if( jbin == 4)
245     h_RelIso_all->SetTitle( isoname+" RelIso distribution (#geq 4 jets)");
246     else if ( jbin < 4 ) {
247     TString title = isoname+" RelIso distribution (";
248     title += jbin;
249     title += " jets)";
250     h_RelIso_all->SetTitle(title);
251     }
252     else {
253     cout<<"Don't mess around!!! jbin should be less than 5!"<<endl;
254     return;
255     }
256     h_RelIso_all->SetMinimum(0);
257 jengbou 1.2
258     file0->cd("hstack");
259     hs->Write();
260    
261 jengbou 1.1 file0->cd();
262     ftree->Write();
263     file0->Close();
264     }
265