ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/algomez/FourTop/TreeAnalyzer/test/Analyzer.C
Revision: 1.10
Committed: Wed Jan 18 18:20:03 2012 UTC (13 years, 3 months ago) by algomez
Content type: text/plain
Branch: MAIN
Changes since 1.9: +124 -73 lines
Log Message:
lastest version

File Contents

# User Rev Content
1 algomez 1.1
2     // The class definition in Analyzer.h has been generated automatically
3     // by the ROOT utility TTree::MakeSelector(). This class is derived
4     // from the ROOT class TSelector. For more information on the TSelector
5     // framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.
6    
7     // The following methods are defined in this file:
8     // Begin(): called every time a loop on the tree starts,
9     // a convenient place to create your histograms.
10     // SlaveBegin(): called after Begin(), when on PROOF called only on the
11     // slave servers.
12     // Process(): called for each event, in this function you decide what
13     // to read and fill your histograms.
14     // SlaveTerminate: called at the end of the loop on the tree, when on PROOF
15     // called only on the slave servers.
16     // Terminate(): called at the end of the loop on the tree,
17     // a convenient place to draw/fit your histograms.
18     //
19     // To use this file, try the following session on your Tree T:
20     //
21     // Root > T->Process("Analyzer.C")
22     // Root > T->Process("Analyzer.C","some options")
23     // Root > T->Process("Analyzer.C+")
24     //
25    
26     #include "Analyzer.h"
27 algomez 1.9 //#include "BTagWeight.h"
28     #include "BTagSFUtil_lite.h"
29 algomez 1.1 //#include "Yumiceva/TreeAnalyzer/interface/JetCombinatorics.h"
30    
31     #include <TStyle.h>
32     #include <TSystem.h>
33    
34     #include <iostream>
35     #include <vector>
36     #include <stdio.h>
37     #include <stdlib.h>
38 algomez 1.8 #define NMAX 100
39 algomez 1.1
40     void Analyzer::ParseInput()
41     {
42    
43     if (fMyOpt.Contains("muon"))
44     {
45     fChannel = 1;
46     }
47     if (fMyOpt.Contains("electron"))
48     {
49     fChannel = 2;
50     }
51     if (fMyOpt.Contains("verbose"))
52     {
53     fVerbose = true;
54     }
55     if (fMyOpt.Contains("JECUP")) { fdoJECunc = true; fdoJECup = true; }
56     if (fMyOpt.Contains("JECDOWN")) { fdoJECunc = true; fdoJECup = false; }
57 algomez 1.2 if (fMyOpt.Contains("PUUP")) { fpuhistogram = "WHistUp";}
58     if (fMyOpt.Contains("PUDOWN")) { fpuhistogram = "WHistDown";}
59 algomez 1.8 if (fMyOpt.Contains("QCD1")) fdoQCD1SideBand = true;//anti-isolation
60     if (fMyOpt.Contains("QCD2")) fdoQCD2SideBand = true;//MET < 20 GeV
61 algomez 1.1 if (fMyOpt.Contains("mtop")) fdoMtopCut = true;
62     if (fMyOpt.Contains("outdir")) {
63     TString tmp = fMyOpt;
64     tmp = tmp.Remove(0,fMyOpt.Index("outdir")+7);
65     fOutdir = tmp+"/";
66     Info("Begin","output files will be written to directory: %s", fOutdir.Data());
67     }
68     if (fMyOpt.Contains("sample"))
69     {
70     TString tmp = fMyOpt;
71     tmp = tmp.Remove(0,fMyOpt.Index("sample")+7);
72     fSample = tmp;
73     if (fdoJECunc && fdoJECup==true) fSample += "_JECUP";
74     if (fdoJECunc && fdoJECup==false) fSample += "_JECDOWN";
75 algomez 1.2 if (fMyOpt.Contains("PUUP")) fSample += "_PUUP";
76     if (fMyOpt.Contains("PUDOWN")) fSample += "_PUDOWN";
77 algomez 1.1
78     Info("Begin","Histogram names will have suffix: %s", fSample.Data());
79    
80     if ( fSample.Contains("data") )
81     {
82     fIsMC = false;
83     Info("Begin","This sample is treated as DATA");
84     if (fdoQCD1SideBand) fSample = "dataQCD1";
85     if (fdoQCD2SideBand) fSample = "dataQCD2";
86     }
87 algomez 1.2 else
88     {
89     Info("Begin","This sample is treated as MC");
90     Info("Begin","we will use pileup set: %s", fpuhistogram.Data());
91     }
92    
93 algomez 1.1
94     }
95     }
96    
97     void Analyzer::Begin(TTree * /*tree*/)
98     {
99     // The Begin() function is called at the start of the query.
100     // When running with PROOF Begin() is only called on the client.
101     // The tree argument is deprecated (on PROOF 0 is passed).
102    
103     TString option = GetOption();
104     fMyOpt = option;
105     ParseInput();
106    
107     Info("Begin", "starting with process option: %s", option.Data());
108    
109     }
110    
111     void Analyzer::SlaveBegin(TTree * tree)
112     {
113    
114     // The SlaveBegin() function is called after the Begin() function.
115     // When running with PROOF SlaveBegin() is called on each slave server.
116     // The tree argument is deprecated (on PROOF 0 is passed).
117    
118     TString option = GetOption();
119     fMyOpt = option;
120     ParseInput();
121    
122     Info("SlaveBegin",
123     "starting with process option: %s (tree: %p)", option.Data(), tree);
124    
125     //initialize the Tree branch addresses
126     Init(tree);
127    
128     // We may be creating a dataset or a merge file: check it
129     TNamed *nm = dynamic_cast<TNamed *>(fInput->FindObject("SimpleNtuple.root"));
130     if (nm) {
131     // Just create the object
132     UInt_t opt = TProofOutputFile::kRegister | TProofOutputFile::kOverwrite | TProofOutputFile::kVerify;
133 algomez 1.8 fProofFile = new TProofOutputFile("SimpleNtuple.root", TProofOutputFile::kDataset, opt, nm->GetTitle());
134 algomez 1.1 } else {
135     // For the ntuple, we use the automatic file merging facility
136     // Check if an output URL has been given
137     TNamed *out = (TNamed *) fInput->FindObject("PROOF_OUTPUTFILE_LOCATION");
138     Info("SlaveBegin", "PROOF_OUTPUTFILE_LOCATION: %s", (out ? out->GetTitle() : "undef"));
139     TString tmpfilename = "results";
140     if ( fSample != "" ) tmpfilename += "_"+fSample+".root";
141     else tmpfilename = "results.root";
142     fProofFile = new TProofOutputFile(tmpfilename, (out ? out->GetTitle() : "M"));
143     out = (TNamed *) fInput->FindObject("PROOF_OUTPUTFILE");
144     if (out) fProofFile->SetOutputFileName(fOutdir + out->GetTitle());
145     }
146    
147     // Open the file
148     //TDirectory *savedir = gDirectory;
149     if (!(fFile = fProofFile->OpenFile("RECREATE"))) {
150     Warning("SlaveBegin", "problems opening file: %s/%s",
151     fProofFile->GetDir(), fProofFile->GetFileName());
152     }
153    
154 algomez 1.2 // Get PU weights
155 algomez 1.8 TString weightfilename = "/uscms/home/yumiceva/work/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/Weight3Dfinebin4p7.root"; //Weight3D.root";
156 algomez 1.2 fweightfile = new TFile(weightfilename,"read");
157     f3Dweight = (TH1D*) fweightfile->Get(fpuhistogram);
158    
159 algomez 1.1 //create histograms
160     h1test = new TH1F("h1test","muon p_{T}",100,10.,400);
161     //fHist = new HistoManager(string(fSample));
162     TString hname = "_"+fSample;
163    
164 algomez 1.6 hmuons["N_cut0"] = new TH1F("N_muons_cut0"+hname,"Number of Muons",6,-0.5,5.5);
165     hmuons["N"] = new TH1F("N_muons"+hname,"Number of Muons",6,-0.5,5.5);
166 algomez 1.10 hmuons["N_1btag"] = new TH1F("N_muons_1btag"+hname,"Number of Muons",6,-0.5,5.5);
167 algomez 1.6 hmuons["Nelectrons_cut0"] = new TH1F("Nelectrons_cut0"+hname,"Number of Loose Electrons",6,-0.5,5.5);
168     hmuons["Nelectrons"] = new TH1F("Nelectrons"+hname,"Number of Loose Electrons",6,-0.5,5.5);
169 algomez 1.10 hmuons["Nelectrons_1btag"] = new TH1F("Nelectrons_1btag"+hname,"Number of Loose Electrons",6,-0.5,5.5);
170 algomez 1.1 hmuons["pt_1jet"] = new TH1F("muon_pt_1jet"+hname,"p_{T}^{#mu} [GeV/c]", 50, 0, 500);
171     hmuons["pt_2jet"] = new TH1F("muon_pt_2jet"+hname,"p_{T}^{#mu} [GeV/c]", 50, 0, 500);
172 algomez 1.2 hmuons["pt_fin"] = new TH1F("muon_pt_fin"+hname,"p_{T}^{#mu} [GeV/c]", 50, 0, 500);
173 algomez 1.1 hmuons["eta"] = new TH1F("muon_eta"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
174     hmuons["eta_1jet"] = new TH1F("muon_eta_1jet"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
175     hmuons["eta_2jet"] = new TH1F("muon_eta_2jet"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
176 algomez 1.2 hmuons["eta_fin"] = new TH1F("muon_eta_fin"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
177 algomez 1.1 hmuons["phi"] = new TH1F("muon_phi"+hname,"#phi^{#mu}", 30, -3.15, 3.15);
178     hmuons["phi_1jet"] = new TH1F("muon_phi_1jet"+hname,"#phi^{#mu}", 30, -3.15, 3.15);
179     hmuons["phi_2jet"] = new TH1F("muon_phi_2jet"+hname,"#phi^{#mu}", 30, -3.15, 3.15);
180 algomez 1.2 hmuons["phi_fin"] = new TH1F("muon_phi_fin"+hname,"#phi^{#mu}", 30, -3.15, 3.15);
181 algomez 1.1 hmuons["reliso"] = new TH1F("muon_reliso"+hname,"Relative Isolation", 40, 0, 0.2);
182 algomez 1.2 hmuons["reliso_fin"] = new TH1F("muon_reliso_fin"+hname,"Relative Isolation", 40, 0, 0.2);
183 algomez 1.1 hmuons["deltaR_cut0"] = new TH1F("deltaR_cut0"+hname,"#DeltaR(#mu,jet)",80, 0, 4);
184     hmuons["deltaR"] = new TH1F("deltaR"+hname,"#DeltaR(#mu,jet)", 80, 0, 4);
185 algomez 1.10 hmuons["deltaR_1btag"] = new TH1F("deltaR_1btag"+hname,"#DeltaR(#mu,jet)", 80, 0, 4);
186 algomez 1.1 hmuons["d0_cut1"] = new TH1F("d0_cut1"+hname,"#mu Impact Parameter [cm]",20,-0.1,0.1);
187     hmuons["pt_cut1"] = new TH1F("muon_pt_cut1"+hname,"p_{T}^{#mu} [GeV/c]", 50, 0, 500);
188     hmuons["pt_cut2"] = new TH1F("muon_pt_cut2"+hname,"p_{T}^{#mu} [GeV/c]", 50, 0, 500);
189     hmuons["pt_cut3"] = new TH1F("muon_pt_cut3"+hname,"p_{T}^{#mu} [GeV/c]", 50, 0, 500);
190     hmuons["pt"] = new TH1F("muon_pt"+hname,"p_{T}^{#mu} [GeV/c]", 50, 0, 500);
191 algomez 1.10 hmuons["pt_1btag"] = new TH1F("muon_pt_1btag"+hname,"p_{T}^{#mu} [GeV/c]", 50, 0, 500);
192 algomez 1.1 hmuons["dz"] = new TH1F("dz"+hname,"|z(#mu) - z_{PV}| [cm]", 25, 0, 1.);
193 algomez 1.2 hmuons["Niso"] = new TH1F("Niso"+hname,"Number of Primary Vertices", 25,-0.5,24.5);
194     hmuons["Ngood"] = new TH1F("Ngood"+hname,"Number of Primary Vertices",25,-0.5,24.5);
195 algomez 1.1
196     hPVs["N"] = new TH1F("NPV"+hname,"Number of PVs",25,-0.5,24.5);
197     hPVs["Nreweight"] = new TH1F("NPVreweight"+hname,"Number of PVs",25,-0.5,24.5);
198     hPVs["Nreweight_2jet"] = new TH1F("NPVreweight_2jet"+hname,"Number of PVs",25,-0.5,24.5);
199 algomez 1.10 hPVs["Nreweight_2jet_1btag"] = new TH1F("NPVreweight_2jet_1btag"+hname,"Number of PVs",25,-0.5,24.5);
200 algomez 1.1
201     helectrons["pt"] = new TH1F("electron_pt"+hname,"p_{T}^{#mu} [GeV/c]", 50, 20, 500);
202     helectrons["pt_cut2"] = new TH1F("electron_pt_cut2"+hname,"p_{T}^{#mu} [GeV/c]", 50, 20, 500);
203     helectrons["pt_1jet"] = new TH1F("electron_pt_1jet"+hname,"p_{T}^{#mu} [GeV/c]", 50, 20, 500);
204     helectrons["pt_2jet"] = new TH1F("electron_pt_2jet"+hname,"p_{T}^{#mu} [GeV/c]", 50, 20, 500);
205     helectrons["pt_3jet"] = new TH1F("electron_pt_3jet"+hname,"p_{T}^{#mu} [GeV/c]", 50, 20, 500);
206     helectrons["pt_4jet"] = new TH1F("electron_pt_4jet"+hname,"p_{T}^{#mu} [GeV/c]", 50, 20, 500);
207     helectrons["eta"] = new TH1F("electron_eta"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
208     helectrons["eta_cut2"] = new TH1F("electron_eta_cut2"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
209     helectrons["eta_1jet"] = new TH1F("electron_eta_1jet"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
210     helectrons["eta_2jet"] = new TH1F("electron_eta_2jet"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
211     helectrons["eta_3jet"] = new TH1F("electron_eta_3jet"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
212     helectrons["eta_4jet"] = new TH1F("electron_eta_4jet"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
213     helectrons["phi"] = new TH1F("electron_phi"+hname,"#phi^{#mu}", 20, 0, 3.15);
214     helectrons["phi_cut2"] = new TH1F("electron_phi_cut2"+hname,"#phi^{#mu}", 20, 0, 3.15);
215     helectrons["phi_1jet"] = new TH1F("electron_phi_1jet"+hname,"#phi^{#mu}", 20, 0, 3.15);
216     helectrons["phi_2jet"] = new TH1F("electron_phi_2jet"+hname,"#phi^{#mu}", 20, 0, 3.15);
217     helectrons["phi_3jet"] = new TH1F("electron_phi_3jet"+hname,"#phi^{#mu}", 20, 0, 3.15);
218     helectrons["phi_4jet"] = new TH1F("electron_phi_4jet"+hname,"#phi^{#mu}", 20, 0, 3.15);
219     helectrons["reliso"] = new TH1F("electron_reliso"+hname,"Relative Isolation", 40, 0, 0.2);
220     helectrons["reliso_1jet"] = new TH1F("electron_reliso_1jet"+hname,"Relative Isolation", 40, 0, 0.2);
221     helectrons["reliso_2jet"] = new TH1F("electron_reliso_2jet"+hname,"Relative Isolation", 40, 0, 0.2);
222     helectrons["reliso_3jet"] = new TH1F("electron_reliso_3jet"+hname,"Relative Isolation", 40, 0, 0.2);
223     helectrons["reliso_4jet"] = new TH1F("electron_reliso_4jet"+hname,"Relative Isolation", 40, 0, 0.2);
224     helectrons["deltaR_cut0"] = new TH1F("electron_deltaR_cut0"+hname,"#DeltaR(#mu,jet)",80, 0, 4);
225     helectrons["deltaR"] = new TH1F("electron_deltaR"+hname,"#DeltaR(#mu,jet)",80, 0, 4);
226     helectrons["d0_cut1"] = new TH1F("electron_d0_cut1"+hname,"#mu Impact Parameter [cm]",20,-0.1,0.1);
227     helectrons["dz"] = new TH1F("electron_dz"+hname,"|z(#mu) - z_{PV}| [cm]", 25, 0, 1.);
228    
229 algomez 1.6 hMET["MET"] = new TH1F("MET"+hname,"Missing Transverse Energy [GeV]", 50, 0, 500);
230 algomez 1.10 hMET["MET_1btag"] = new TH1F("MET_1btag"+hname,"Missing Transverse Energy [GeV]", 50, 0, 500);
231 algomez 1.6 hMET["MET_cut0"] = new TH1F("MET_cut0"+hname,"Missing Transverse Energy [GeV]", 50, 0, 300);
232 algomez 1.1 hMET["MET_2jet"] = new TH1F("MET_2jet"+hname,"Missing Transverse Energy [GeV]", 50, 0, 300);
233 algomez 1.2 hMET["MET_fin"] = new TH1F("MET_fin"+hname,"Missing Transverse Energy [GeV]", 50, 0, 300);
234 algomez 1.1 hMET["genMET_2jet"] = new TH1F("genMET_2jet"+hname,"Missing Transverse Energy [GeV]", 50, 0, 300);
235     hMET["deltaMET_2jet"] = new TH1F("deltaMET_2jet"+hname,"Missing Transverse Energy [GeV]", 50, -200, 200);
236     hMET["phi"] = new TH1F("MET_phi"+hname,"#phi Missing Transverse Energy [GeV]", 20, 0, 3.15);
237 algomez 1.6 hMET["Ht0"] = new TH1F("Ht0"+hname,"H_{T} [GeV]", 50, 0, 3000);
238     hMET["Ht"] = new TH1F("Ht"+hname,"H_{T} [GeV]", 50, 0, 3000);
239 algomez 1.10 hMET["Ht_1btag"] = new TH1F("Ht_1btag"+hname,"H_{T} [GeV]", 50, 0, 3000);
240 algomez 1.8 hMET["Htlep"] = new TH1F("Htlep"+hname,"H_{T,lep} [GeV]", 100, 0, 1000);
241 algomez 1.10 hMET["Stlep"] = new TH1F("Stlep"+hname,"S_{t}^{lep} [GeV]", 100, 0, 1000);
242     hMET["Stlep_1btag"] = new TH1F("Stlep_1btag"+hname,"S_{t}^{lep} [GeV]", 100, 0, 1000);
243     hMET["Stjet"] = new TH1F("Stjet"+hname,"S_{t}^{jet} [GeV]", 100, 0, 3000);
244     hMET["Stjet_1btag"] = new TH1F("Stjet_1btag"+hname,"S_{t}^{jet} [GeV]", 100, 0, 3000);
245 algomez 1.1 hMET["PzNu"] = new TH1F("PzNu"+hname,"p_{z} #nu [GeV]", 40, -300,300);
246     hMET["EtaNu"] = new TH1F("EtaNu"+hname,"#eta",50,-2.2,2.2);
247     hMET["LepWmass"] = new TH1F("LepWmass"+hname,"W#rightarrow#mu#nu Mass [GeV/c^{2}]",20, 0, 150);
248     hMET["LepWmass_topcut"] = new TH1F("LepWmass_topcut"+hname,"W#rightarrow#mu#nu Mass [GeV/c^{2}]",20, 0, 150);
249     hMET["LepWmassNoPt"]=new TH1F("LepWmassNoPt"+hname,"W#rightarrow#mu#nu Mass [GeV/c^{2}]",20, 0, 150);
250     hMET["deltaPhi"] = new TH1F("deltaPhi"+hname,"#Delta #phi(#mu,MET)",50, -3.15, 3.15);
251    
252 algomez 1.6 hM["WMt"] = new TH1F("Mt"+hname,"M_{T}(W) [GeV/c^{2}]", 50, 0, 500); // Transverse Mass sqrt(Wpt*Wpt - Wpx*Wpx - Wpy*Wpy)
253 algomez 1.1 hM["WMt_2jet"] = new TH1F("Mt_2jet"+hname,"M_{T}(W) [GeV/c^{2}]", 50, 0, 300);
254 algomez 1.10 hM["WMt_2jet_1btag"] = new TH1F("Mt_2jet_1btag"+hname,"M_{T}(W) [GeV/c^{2}]", 50, 0, 300);
255 algomez 1.2 hM["WMt_fin"] = new TH1F("Mt_fin"+hname,"M_{T}(W) [GeV/c^{2}]", 50, 0, 300);
256 algomez 1.1 hM["dijet"] = new TH1F("dijet"+hname,"(jj) mass [GeV/c^{2}]", 50, 0, 1000);
257     hM["trijet"] = new TH1F("trijet"+hname,"(jjj) mass [GeV/c^{2}]", 50, 0, 1000);
258     hM["top_1btag"] = new TH1F("top_1btag"+hname,"top mass [GeV/c^{2}]",50,0,500);
259     hM["top_2btag"] = new TH1F("top_2btag"+hname,"top mass [GeV/c^{2}]",50,0,500);
260 algomez 1.6
261 algomez 1.1 hjets["pt"] = new TH1F("jet_pt"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
262 algomez 1.2 hjets["pt_b_mc"] = new TH1F("jet_pt_b_mc"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
263     hjets["pt_c_mc"] = new TH1F("jet_pt_c_mc"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
264     hjets["pt_l_mc"] = new TH1F("jet_pt_l_mc"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
265 algomez 1.1 hjets["pt_btag"] = new TH1F("jet_pt_btag"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
266     hjets["pt_btag_b"] = new TH1F("jet_pt_btag_b"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
267     hjets["pt_btag_c"] = new TH1F("jet_pt_btag_c"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
268     hjets["pt_btag_l"] = new TH1F("jet_pt_btag_l"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
269 algomez 1.6 hjets["1st_pt_cut0"] = new TH1F("jet1_pt_cut0"+hname,"Leading jet p_{T} [GeV/c]",60, 30, 1000);
270     hjets["1st_pt"] = new TH1F("jet1_pt"+hname,"Leading jet p_{T} [GeV/c]",60, 30, 1000);
271 algomez 1.10 hjets["1st_pt_1btag"] = new TH1F("jet1_pt_1btag"+hname,"Leading jet p_{T} [GeV/c]",60, 30, 1000);
272 algomez 1.6 hjets["2nd_pt_cut0"] = new TH1F("jet2_pt_cut0"+hname,"2nd jet p_{T} [GeV/c]",60, 30, 1000);
273     hjets["2nd_pt"] = new TH1F("jet2_pt"+hname,"2nd jet p_{T} [GeV/c]",60, 30, 1000);
274 algomez 1.10 hjets["2nd_pt_1btag"] = new TH1F("jet2_pt_1btag"+hname,"2nd jet p_{T} [GeV/c]",60, 30, 1000);
275 algomez 1.6 hjets["3rd_pt_cut0"] = new TH1F("jet3_pt_cut0"+hname,"3rd jet p_{T} [GeV/c]",60, 30, 800);
276 algomez 1.1 hjets["3rd_pt"] = new TH1F("jet3_pt"+hname,"3rd jet p_{T} [GeV/c]",60, 30, 800);
277 algomez 1.10 hjets["3rd_pt_1btag"] = new TH1F("jet3_pt_1btag"+hname,"3rd jet p_{T} [GeV/c]",60, 30, 800);
278 algomez 1.6 hjets["4th_pt_cut0"] = new TH1F("jet4_pt_cut0"+hname,"4th jet p_{T} [GeV/c]",60, 30, 800);
279 algomez 1.1 hjets["4th_pt"] = new TH1F("jet4_pt"+hname,"4th jet p_{T} [GeV/c]",60, 30, 800);
280 algomez 1.10 hjets["4th_pt_1btag"] = new TH1F("jet4_pt_1btag"+hname,"4th jet p_{T} [GeV/c]",60, 30, 800);
281 algomez 1.6 hjets["5th_pt_cut0"] = new TH1F("jet5_pt_cut0"+hname,"5th jet p_{T} [GeV/c]",60, 30, 800);
282     hjets["5th_pt"] = new TH1F("jet5_pt"+hname,"5th jet p_{T} [GeV/c]",60, 30, 800);
283 algomez 1.10 hjets["5th_pt_1btag"] = new TH1F("jet5_pt_1btag"+hname,"5th jet p_{T} [GeV/c]",60, 30, 800);
284 algomez 1.6 hjets["6th_pt_cut0"] = new TH1F("jet6_pt_cut0"+hname,"6th jet p_{T} [GeV/c]",60, 30, 800);
285     hjets["6th_pt"] = new TH1F("jet6_pt"+hname,"6th jet p_{T} [GeV/c]",60, 30, 800);
286 algomez 1.10 hjets["6th_pt_1btag"] = new TH1F("jet6_pt_1btag"+hname,"6th jet p_{T} [GeV/c]",60, 30, 800);
287 algomez 1.6 hjets["7th_pt_cut0"] = new TH1F("jet7_pt_cut0"+hname,"7th jet p_{T} [GeV/c]",60, 30, 800);
288     hjets["7th_pt"] = new TH1F("jet7_pt"+hname,"7th jet p_{T} [GeV/c]",60, 30, 800);
289 algomez 1.10 hjets["7th_pt_1btag"] = new TH1F("jet7_pt_1btag"+hname,"7th jet p_{T} [GeV/c]",60, 30, 800);
290 algomez 1.2 hjets["1st_pt_fin"] = new TH1F("jet1_pt_fin"+hname,"Leading jet p_{T} [GeV/c]",60, 30, 800);
291     hjets["2nd_pt_fin"] = new TH1F("jet2_pt_fin"+hname,"2nd jet p_{T} [GeV/c]",60, 30, 800);
292 algomez 1.1 hjets["eta"] = new TH1F("jet_eta"+hname,"jet #eta",50, -2.4, 2.4);
293 algomez 1.6 hjets["1st_eta_cut0"] = new TH1F("jet1_eta_cut0"+hname,"Leading jet #eta",50, -2.4, 2.4);
294 algomez 1.1 hjets["1st_eta"] = new TH1F("jet1_eta"+hname,"Leading jet #eta",50, -2.4, 2.4);
295 algomez 1.10 hjets["1st_eta_1btag"] = new TH1F("jet1_eta_1btag"+hname,"Leading jet #eta",50, -2.4, 2.4);
296 algomez 1.6 hjets["2nd_eta_cut0"] = new TH1F("jet2_eta_cut0"+hname,"2nd jet #eta",50, -2.4, 2.4);
297 algomez 1.1 hjets["2nd_eta"] = new TH1F("jet2_eta"+hname,"2nd jet #eta",50, -2.4, 2.4);
298 algomez 1.10 hjets["2nd_eta_1btag"] = new TH1F("jet2_eta_1btag"+hname,"2nd jet #eta",50, -2.4, 2.4);
299 algomez 1.2 hjets["1st_eta_fin"] = new TH1F("jet1_eta_fin"+hname,"Leading jet #eta",50, -2.4, 2.4);
300     hjets["2nd_eta_fin"] = new TH1F("jet2_eta_fin"+hname,"2nd jet #eta",50, -2.4, 2.4);
301 algomez 1.1 hjets["phi"] = new TH1F("jet_phi"+hname,"jet #phi",50, 0, 3.15);
302 algomez 1.3 hjets["Njets"] = new TH1F("Njets"+hname,"jet multiplicity",13,-0.5,12.5);
303 algomez 1.6 hjets["Njets_cut0"] = new TH1F("Njets_cut0"+hname,"jet multiplicity",13,-0.5,12.5);
304 algomez 1.4 hjets["Njets_cut1"] = new TH1F("Njets_cut1"+hname,"jet multiplicity",13,-0.5,12.5);
305 algomez 1.10 hjets["Njets_1btag"] = new TH1F("Njets_1tag"+hname,"jet multiplicity",13,-0.5,12.5);
306     hjets["Njets_2btag"] = new TH1F("Njets_2tag"+hname,"jet multiplicity",6,0.5,6.5);
307     hjets["Nbtags_TCHPM"] = new TH1F("Nbjets_TCHPM"+hname,"Tagged b-jets",3,-0.5,2.5);
308     hjets["Nbtags_CSVM"] = new TH1F("Nbjets_CSVM"+hname,"Tagged b-jets",8,-0.5,7.5);
309 algomez 1.1 hjets["Dijet_deltaPhi"] = new TH1F("Dijet_deltaPhi"+hname,"#Delta #phi(j,j)",30,-3.15,3.15);
310 algomez 1.6 hjets["Dijet_deltaR_cut0"] = new TH1F("Dijet_deltaR_cut0"+hname,"#DeltaR(j,j)",80,0.,4.);
311     hjets["Dijet_deltaR"] = new TH1F("Dijet_deltaR"+hname,"#DeltaR(j,j)",80,0.,4.);
312 algomez 1.10 hjets["Dijet_deltaR_1btag"] = new TH1F("Dijet_deltaR_1btag"+hname,"#DeltaR(j,j)",80,0.,4.);
313 algomez 1.1 hjets["tb_deltaPhi"] = new TH1F("tb_deltaPhi"+hname,"#Delta #phi(t,b)",30,0.,3.15);
314 algomez 1.2 hjets["tb_deltaEta"] = new TH1F("tb_deltaEta"+hname,"#Delta #eta(t,b)",30,-5,5);
315     hjets["pt_top"] = new TH1F("pt_top"+hname,"top p_{T} [GeV]",60,0,1500);
316     hjets["pt_b"] = new TH1F("pt_b"+hname,"b-jet p_{T} [GeV]",60,0,1500);
317     hjets["gen_deltaR_mub"] = new TH1F("gen_deltaR_mub"+hname,"#Delta R(#mu,b)",40,0,4);
318 algomez 1.8 hjets["1st_bdisc"] = new TH1F("1st_bdisc"+hname,"b discriminator Leading jet", 50, -0.01, 1.01);
319 algomez 1.10 hjets["1st_bdisc_1btag"] = new TH1F("1st_bdisc_1btag"+hname,"b discriminator Leading jet", 50, -0.01, 1.01);
320 algomez 1.8 hjets["2nd_bdisc"] = new TH1F("2nd_bdisc"+hname,"b discriminator 2nd jet", 50, -0.01, 1.01);
321 algomez 1.10 hjets["2nd_bdisc_1btag"] = new TH1F("2nd_bdisc_1btag"+hname,"b discriminator 2nd jet", 50, -0.01, 1.01);
322 algomez 1.8 hjets["3rd_bdisc"] = new TH1F("3rd_bdisc"+hname,"b discriminator 3rd jet", 50, -0.01, 1.01);
323 algomez 1.10 hjets["3rd_bdisc_1btag"] = new TH1F("3rd_bdisc_1btag"+hname,"b discriminator 3rd jet", 50, -0.01, 1.01);
324 algomez 1.8 hjets["4th_bdisc"] = new TH1F("4th_bdisc"+hname,"b discriminator 4th jet", 50, -0.01, 1.01);
325 algomez 1.10 hjets["4th_bdisc_1btag"] = new TH1F("4th_bdisc_1btag"+hname,"b discriminator 4th jet", 50, -0.01, 1.01);
326 algomez 1.8 hjets["5th_bdisc"] = new TH1F("5th_bdisc"+hname,"b discriminator 5th jet", 50, -0.01, 1.01);
327     hjets["6th_bdisc"] = new TH1F("6th_bdisc"+hname,"b discriminator 6th jet", 50, -0.01, 1.01);
328     hjets["7th_bdisc"] = new TH1F("7th_bdisc"+hname,"b discriminator 7th jet", 50, -0.01, 1.01);
329 algomez 1.10 hjets["prod_bdisc"] = new TH1F("prod_bdisc"+hname,"discriminators product", 50, -0.01, 1.01);
330     hjets["prod_bdisc_1btag"] = new TH1F("prod_bdisc_1btag"+hname,"discriminators product", 50, -0.01, 1.01);
331 algomez 1.8
332    
333 algomez 1.1
334     map<string,TH1* > allhistos = hmuons;
335     allhistos.insert( helectrons.begin(), helectrons.end() );
336     allhistos.insert( hMET.begin(), hMET.end() );
337     allhistos.insert( hM.begin(), hM.end() );
338     allhistos.insert( hjets.begin(), hjets.end() );
339    
340     for ( map<string,TH1* >::const_iterator imap=allhistos.begin(); imap!=allhistos.end(); ++imap )
341     {
342     TH1 *temp = imap->second;
343     temp->Sumw2();
344     temp->SetXTitle( temp->GetTitle() );
345     }
346    
347     // cut flow
348     if (fChannel==1)
349     { //muon +jets
350     fCutLabels.push_back("Processed");
351     fCutLabels.push_back("OneIsoMu");
352     fCutLabels.push_back("LooseMuVeto");
353     fCutLabels.push_back("ElectronVeto");
354     fCutLabels.push_back("MET");
355     fCutLabels.push_back("1Jet");
356     fCutLabels.push_back("2Jet");
357     fCutLabels.push_back("3Jet");
358     fCutLabels.push_back("4Jet");
359     fCutLabels.push_back("2Jet1b");
360     fCutLabels.push_back("2Jet2b");
361     fCutLabels.push_back("MaxJets");
362     fCutLabels.push_back("phi");
363     fCutLabels.push_back("topmass");
364     }
365     else
366     { //electron+jets
367     fCutLabels.push_back("Processed");
368     fCutLabels.push_back("OneIsoElectron");
369     fCutLabels.push_back("LooseMuVeto");
370     fCutLabels.push_back("ZVeto");
371     fCutLabels.push_back("ConversionVeto");
372     fCutLabels.push_back("MET");
373     fCutLabels.push_back("1Jet");
374     fCutLabels.push_back("2Jet");
375     fCutLabels.push_back("3Jet");
376     fCutLabels.push_back("4Jet");
377     fCutLabels.push_back("2Jet1b");
378     fCutLabels.push_back("2Jet2b");
379     }
380     hcutflow = new TH1D("cutflow","cut flow", fCutLabels.size(), 0.5, fCutLabels.size() +0.5 );
381    
382     for ( vector<string>::const_iterator ivec= fCutLabels.begin(); ivec!=fCutLabels.end(); ++ivec)
383     {
384     cutmap[ *ivec ] = 0;
385     }
386    
387     double pu_weights[35] = {
388     0.0255506,
389     0.251923,
390     0.549605,
391     0.924918,
392     1.25977,
393     1.48142,
394     1.57923,
395     1.57799,
396     1.52152,
397     1.4414,
398     1.35889,
399     1.2841,
400     1.21927,
401     1.16125,
402     1.11244,
403     1.06446,
404     1.01666,
405     0.966989,
406     0.913378,
407     0.85774,
408     0.799258,
409     0.734225,
410     0.670242,
411     0.607641,
412     0.54542,
413     0.484084,
414     0.427491,
415     0.369787,
416     0.321454,
417     0.280706,
418     0.238499,
419     0.198961,
420     0.166742,
421     0.146428,
422     0.224425
423     };
424    
425     fpu_weights_vec.assign( pu_weights, pu_weights + 35 );
426    
427     // For JEC uncertainties
428 algomez 1.8 if (fdoJECunc) fJECunc = new JetCorrectionUncertainty("/uscms/home/yumiceva/work/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/GR_R_42_V19_AK5PF_Uncertainty.txt");
429    
430 algomez 1.9 // LOT for b-tagging SF
431     //bSF_table.LoadTable("/uscms/home/yumiceva/work/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/Table_CSVM_beff_SF.txt");
432     lSF_table.LoadTable("/uscms/home/yumiceva/work/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/Table_CSVM_lmistag_SF.txt");
433     leff_table.LoadTable("/uscms/home/yumiceva/work/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/Table_CSVM_lmistag_Eff.txt");
434    
435     //leff_tablebtag efficiency file and 2D histogram
436     //TString btagefffilename = "/uscms/home/weizou/work/NtupleMaker/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/BtagEff.root";
437     //btagefffile = new TFile(btagefffilename,"read");
438     //ttbar
439     //f2Dttbarbtag = (TH2D*) btagefffile->Get("ttbar_csv_btageff");
440     //f2Dttbarctag = (TH2D*) btagefffile->Get("ttbar_csv_ctageff");
441     //f2Dttbarlighttag = (TH2D*) btagefffile->Get("ttbar_csv_lighttageff");
442     //wprime
443     //f2Dwprimebtag = (TH2D*) btagefffile->Get("wprime_csv_btageff");
444     //f2Dwprimectag = (TH2D*) btagefffile->Get("wprime_csv_ctageff");
445     //f2Dwprimelighttag = (TH2D*) btagefffile->Get("wprime_csv_lighttageff");
446    
447    
448 algomez 1.8 //------- Store information in a Tree
449     MyStoreTree = new StoreTreeVariable();
450    
451     if(fChannel == 1){
452     MyStoreTree->SetElectronFalse();
453     //MyStoreTree->SetJetFalse();
454     MyStoreTree->SetVertexFalse();
455     MyStoreTree->SetTriggerFalse();
456 algomez 1.10 //MyStoreTree->SetMetFalse();
457 algomez 1.8 MyStoreTree->SetMuonFalse();
458     }
459    
460     if(fChannel == 2){
461    
462     MyStoreTree->SetElectronFalse();
463     //MyStoreTree->SetJetFalse();
464     MyStoreTree->SetVertexFalse();
465     MyStoreTree->SetTriggerFalse();
466 algomez 1.10 //MyStoreTree->SetMetFalse();
467 algomez 1.8 MyStoreTree->SetMuonFalse();
468     }
469    
470     MyStoreTree->InitialAll();
471     //Get the Store Tree
472     MyStoreTree->GetStoreTree()->SetDirectory(fFile);
473     MyStoreTree->GetStoreTree()->AutoSave();
474 algomez 1.9 //////////////////////////////////////////
475 algomez 1.1
476     }
477    
478     Bool_t Analyzer::Process(Long64_t entry)
479     {
480     // The Process() function is called for each entry in the tree (or possibly
481     // keyed object in the case of PROOF) to be processed. The entry argument
482     // specifies which entry in the currently loaded tree is to be processed.
483     // It can be passed to either Analyzer::GetEntry() or TBranch::GetEntry()
484     // to read either all or the required parts of the data. When processing
485     // keyed objects with PROOF, the object is already loaded and is available
486     // via the fObject pointer.
487     //
488     // This function should contain the "body" of the analysis. It can contain
489     // simple or elaborate selection criteria, run algorithms on the data
490     // of the event and typically fill histograms.
491     //
492     // The processing can be stopped by calling Abort().
493     //
494     // Use fStatus to set the return value of TTree::Process().
495     //
496     // The return value is currently not used.
497    
498     //TString option = GetOption();
499    
500 algomez 1.8 if ( entry % 100 == 0 )
501     cout<< "process entry " << entry << endl;
502 algomez 1.1
503     //TString sEntry = Form("%f", float(entry) );
504     // Info("Process",
505     //"entry # %s", Form("%f", float(entry) ) );
506    
507     //fChain->GetTree()->GetEntry(entry);
508     fChain->GetEntry(entry);
509    
510     //if (entry>10) return kTRUE;
511    
512     // event info
513     //cout << "run: " << ntuple->run << " lumi: " << ntuple->lumi << endl;
514    
515     // get collections
516     vector< TopVertexEvent > primaryVertices = ntuple->vertices;
517     vector< TopMuonEvent > muons = ntuple->muons;
518 algomez 1.2 vector< TopElectronEvent > electrons = ntuple->PFelectrons; // use PF electrons (gsf collection is called "electrons")
519 algomez 1.1 vector< TopJetEvent > jets = ntuple->PFjets;
520    
521 algomez 1.2 // USE PF Isolation
522     fMuSelector.UsePFIsolation(true);
523     fEleSelector.UsePFIsolation(true);
524    
525 algomez 1.1 size_t total_pvs = primaryVertices.size();
526     size_t total_muons = muons.size();
527     size_t total_electrons = electrons.size();
528     size_t total_jets = jets.size();
529    
530     float PVz = 0.;
531     TLorentzVector p4muon, p4ele, p4lepton, p4MET;
532     TLorentzVector p4Nu, p4OtherNu;
533     TLorentzVector p4QCDmuon;
534    
535     vector< TLorentzVector > p4jets;
536 algomez 1.6 vector< TLorentzVector > p4Othermuon; // leading muon
537 algomez 1.1
538 algomez 1.2 ////////////////////
539     // GENERATOR
540     ///////////////////
541 algomez 1.6 if (fIsMC && fSample.Contains("4Top") )
542 algomez 1.2 {
543     TLorentzVector p4genLepton;
544     TLorentzVector p4genNu;
545     TLorentzVector p4genb;
546     if (ntuple->gen.bLep_pt>0)
547     {
548     p4genLepton.SetPtEtaPhiE(ntuple->gen.mu_pt,ntuple->gen.mu_eta,ntuple->gen.mu_phi,ntuple->gen.mu_e);
549     p4genNu.SetPtEtaPhiE(ntuple->gen.nu_pt,ntuple->gen.nu_eta,ntuple->gen.nu_phi,ntuple->gen.nu_e);
550     p4genb.SetPtEtaPhiE(ntuple->gen.bLep_pt,ntuple->gen.bLep_eta,ntuple->gen.bLep_phi,ntuple->gen.bLep_e);
551    
552     hjets["gen_deltaR_mub"]->Fill( p4genLepton.DeltaR( p4genb ) );
553     }
554     }
555 algomez 1.1 ////////////////////////////////////
556     // PRIMARY VERTICES
557     ///////////////////////////////////
558    
559 algomez 1.6 for ( size_t ipv=0; ipv < total_pvs; ++ipv)
560     {
561     if (ipv==0) PVz = primaryVertices[ipv].vz;
562     }
563 algomez 1.1
564 algomez 1.6 //hPVs["N"]->Fill( total_pvs );
565 algomez 1.1
566     // calculate PU weight
567     double PUweight = 1.;
568    
569     if (fIsMC) {
570 algomez 1.2
571     Int_t mc_npvminus1 = TMath::Min(ntuple->gen.Bx_minus1,34);
572     Int_t mc_npv0 = TMath::Min(ntuple->gen.Bx_0,34);
573     Int_t mc_npvplus1 = TMath::Min(ntuple->gen.Bx_plus1,34);
574    
575     PUweight = f3Dweight->GetBinContent(mc_npvminus1,mc_npv0,mc_npvplus1);
576    
577     //int iibin = 0;
578     //for ( vector<double>::iterator ivec = fpu_weights_vec.begin(); ivec != fpu_weights_vec.end(); ++ivec )
579     // {
580     // int mc_npvs = ntuple->gen.Bx_0; // in-time pile up
581     ////int mc_npvs = (int)total_pvs;
582     //if ( mc_npvs >= iibin+1 ) PUweight = *ivec; // use the last weight for last bin
583     //if ( ( iibin <= mc_npvs ) && ( mc_npvs < iibin + 1 ) ) PUweight = *ivec;
584     //iibin++;
585     //}
586 algomez 1.1 }
587    
588 algomez 1.5 // For 4 tops
589     if (fIsMC && fSample.Contains("4Top") ) {
590     PUweight = 1;
591     }
592    
593 algomez 1.1 hPVs["Nreweight"]->Fill( total_pvs, PUweight );
594    
595 algomez 1.2 /////////////
596     // HLT scale factor for MC
597     ////////////
598     double SF_hlt = 1.;
599 algomez 1.9 if (fIsMC) SF_hlt = 0.97; //0.966;
600     double SF_iso = 1.;
601     if (fIsMC) SF_iso = 0.996;
602     PUweight = PUweight*SF_hlt*SF_iso; // LETS INCLUDE THE TRIGGER SF INTO THE PU WEIGHTS
603    
604     //TEMP
605     //PUweight = 1.;
606 algomez 1.2
607 algomez 1.1 cutmap["Processed"] += PUweight;
608    
609     if (fVerbose) cout << "done pv" << endl;
610 algomez 1.6
611 algomez 1.1 //////////////////////////////////
612     // MUONS
613     //////////////////////////////////
614 algomez 1.2 int ngoodIDmuons = 0;
615 algomez 1.1 int nloosemuons = 0;
616     int ntightmuons = 0;
617     int nqcdmuons = 0;
618 algomez 1.9 int nmuonID[8] = {0};
619 algomez 1.1
620     double RelIso = -1.;
621     double deltaR = -1.;
622     double QCDRelIso = -1.;
623     double QCDdeltaR = -1;
624    
625 algomez 1.2
626 algomez 1.1 for ( size_t imu=0; imu < total_muons; ++imu) {
627    
628 algomez 1.6 TopMuonEvent muon = muons[imu];
629 algomez 1.9
630 algomez 1.6 h1test->Fill( muon.pt );
631     hmuons["pt_cut1"]->Fill( muon.pt, PUweight );
632 algomez 1.9
633     if (muon.pt > 32. && fabs(muon.eta)<2.1 && muon.IsTrackerMuon==1 ) {
634     nmuonID[0] += 1;
635     if (fabs(muon.d0)<0.02 ) {
636     nmuonID[1] += 1;
637     if (muon.trackerhits>=11 ) {
638     nmuonID[2] += 1;
639     if (muon.normchi2<10 ) {
640     nmuonID[3] +=1;
641     if (muon.muonhits>0 ) {
642     nmuonID[4] += 1;
643     if (muon.pixelhits >= 1 ) {
644     nmuonID[5] += 1;
645     if (muon.muonstations > 1 ) {
646     nmuonID[6] +=1;
647     if (fabs(muon.vz - PVz) < 1.) {
648     nmuonID[7] +=1;
649     }
650     }
651     }
652     }
653     }
654     }
655     }
656     }
657 algomez 1.6
658     if ( fMuSelector.MuonID( muon, PVz ) ) ngoodIDmuons++;
659 algomez 1.9
660 algomez 1.6 // select only good muons
661 algomez 1.9
662 algomez 1.6 if ( fMuSelector.MuonLoose( muon ) ) {
663 algomez 1.9
664 algomez 1.6 nloosemuons++;
665 algomez 1.9
666     if ( fMuSelector.MuonTight( muon, PVz) ) hmuons["pt_cut2"]->Fill( muon.pt, PUweight );
667 algomez 1.6 //hmuons["N_tisomuons"]->Fill( nloosemuons );
668     //hmuons["charge_tiso"]->Fill( muon.charge, PUweight );
669     if ( fMuSelector.MuonTightDeltaR( muon, PVz, jets) ) {
670     ntightmuons++;
671     deltaR = fMuSelector.GetDeltaR();
672     }
673 algomez 1.1
674 algomez 1.6 p4muon.SetPtEtaPhiE( muon.pt, muon.eta, muon.phi, muon.e );
675     RelIso = muon.pfreliso; //muon.reliso03;
676     p4Othermuon.push_back( p4muon ); // for leading muon
677 algomez 1.9 }
678 algomez 1.4
679 algomez 1.6 // check muon in QCD control region
680     if ( fMuSelector.MuonRelax02IsoQCD( muon, PVz, jets ) ) {
681     nqcdmuons++;
682 algomez 1.9
683 algomez 1.6 // keep the leading muon for selection
684     if (nqcdmuons==1) {
685     p4QCDmuon.SetPtEtaPhiE( muon.pt, muon.eta, muon.phi, muon.e );
686     QCDRelIso = muon.pfreliso; //muon.reliso03;
687     QCDdeltaR = fMuSelector.GetDeltaR();
688     }
689 algomez 1.1 }
690 algomez 1.6 }
691 algomez 1.1
692 algomez 1.6 if (fVerbose) cout << "done muons" << endl;
693 algomez 1.1
694     //////////////////////////////////
695     // ELECTRONS
696     //////////////////////////////////
697     int nlooseelectrons = 0;
698     int ntightelectrons = 0;
699     bool IsConversion = false;
700    
701     for ( size_t iele=0; iele < total_electrons; ++iele) {
702    
703 algomez 1.6 TopElectronEvent electron = electrons[iele];
704 algomez 1.1
705 algomez 1.6 if ( fEleSelector.ElectronLoose(electron) ) nlooseelectrons++;
706 algomez 1.1
707 algomez 1.6 if ( fEleSelector.ElectronTight(electron, PVz ) ) {
708 algomez 1.1
709 algomez 1.6 if (ntightelectrons == 0) {
710     IsConversion = electron.IsConversion;
711     p4ele.SetPtEtaPhiE( electron.pt, electron.eta, electron.phi, electron.e );
712     helectrons["pt_cut2"]->Fill( p4ele.Pt(), PUweight );
713     helectrons["eta_cut2"]->Fill( p4ele.Eta(), PUweight );
714     helectrons["phi_cut2"]->Fill( p4ele.Phi(), PUweight );
715     }
716     ntightelectrons++;
717     }
718 algomez 1.1 }
719     if (fVerbose) cout << "done electron" << endl;
720    
721 algomez 1.6 /////////////////////////////////////
722     // MUON/ELECTRON + JETS
723     /////////////////////////////////////
724 algomez 1.1
725 algomez 1.6 if ( fChannel == 1 ) {
726 algomez 1.1
727 algomez 1.6 if (fdoQCD2SideBand) {
728 algomez 1.1
729 algomez 1.6 if (nqcdmuons == 0) return kTRUE;
730     cutmap["OneIsoMu"] += PUweight;
731 algomez 1.1
732 algomez 1.6 p4lepton = p4QCDmuon;
733     RelIso = QCDRelIso;
734     deltaR = QCDdeltaR;
735     }
736     else {
737 algomez 1.9 /*
738     if (nmuonID[0] == 1) cutmap["MuID1"] += PUweight;
739     if (nmuonID[1] == 1) cutmap["MuID2"] +=PUweight;
740     if (nmuonID[2] == 1) cutmap["MuID3"] +=PUweight;
741     if (nmuonID[3] == 1) cutmap["MuID4"] +=PUweight;
742     if (nmuonID[4] == 1) cutmap["MuID5"] +=PUweight;
743     if (nmuonID[5] == 1) cutmap["MuID6"] +=PUweight;
744     if (nmuonID[6] == 1) cutmap["MuID7"] +=PUweight;
745     if (nmuonID[7] == 1) cutmap["MuID8"] +=PUweight;
746     if (ngoodIDmuons == 1) cutmap["MuID"] += PUweight;*/ // TEMP
747 algomez 1.2
748 algomez 1.6 if ( ngoodIDmuons > 0 ) hmuons["Ngood"]->Fill( total_pvs, PUweight);
749     if ( ntightmuons > 0 ) hmuons["Niso"]->Fill( total_pvs, PUweight);
750     if ( ntightmuons != 1 ) return kTRUE;
751     cutmap["OneIsoMu"] += PUweight;
752 algomez 1.2
753 algomez 1.6 if ( nloosemuons > 1 ) return kTRUE;
754     cutmap["LooseMuVeto"] += PUweight;
755 algomez 1.1
756 algomez 1.6 if ( nlooseelectrons > 0 ) return kTRUE;
757     cutmap["ElectronVeto"] += PUweight;
758 algomez 1.1
759 algomez 1.6 p4lepton = p4muon;
760     if (fVerbose) cout << "got a good lepton" << endl;
761     }
762    
763     hmuons["pt"]->Fill( p4lepton.Pt(), PUweight );
764     hmuons["eta"]->Fill( p4lepton.Eta(), PUweight );
765     hmuons["phi"]->Fill( p4lepton.Phi(), PUweight );
766     hmuons["reliso"]->Fill( RelIso, PUweight );
767     //hmuons["deltaR"]->Fill( deltaR, PUweight );
768 algomez 1.1
769 algomez 1.6 }
770 algomez 1.1 else // electron+jets
771     {
772     // pending ...
773     }
774    
775     if (fVerbose) cout << "done lepton selection " << endl;
776    
777     /////////////////////////////////
778 algomez 1.6 // MET + Ht
779 algomez 1.1 /////////////////////////////////
780    
781     p4MET.SetPtEtaPhiE( ntuple->PFMET,
782     0.,
783     ntuple->PFMETphi,
784     ntuple->PFMET );
785    
786     //temporal check using genMET
787     //p4MET.SetPtEtaPhiE( ntuple->gen.MET,
788     // 0.,
789     // ntuple->gen.METPhi,
790     // ntuple->gen.MET );
791    
792     if (fdoQCD1SideBand && p4MET.Et() > 20.) return kTRUE;
793     else if ( p4MET.Et() <= 20. && fdoQCD2SideBand==false ) return kTRUE;
794 algomez 1.6 if (fVerbose) cout << "pass MET cut" << endl;
795 algomez 1.1
796    
797     //cutmap["MET"] += PUweight;
798 algomez 1.6 //hMET["MET"]->Fill( p4MET.Pt(), PUweight );
799     //hMET["phi"]->Fill( p4MET.Phi(), PUweight );
800     //hMET["Ht0"]->Fill( ntuple->PFHt, PUweight );
801     //hMET["Htlep"]->Fill( ntuple->PFHt + p4lepton.Pt(), PUweight );
802    
803 algomez 1.1
804     double Wpt = p4lepton.Pt() + p4MET.Pt();
805     double Wpx = p4lepton.Px() + p4MET.Px();
806     double Wpy = p4lepton.Py() + p4MET.Py();
807     double WMt = sqrt(Wpt*Wpt-Wpx*Wpx-Wpy*Wpy);
808 algomez 1.3
809     //if ( WMt <= 40. ) return kTRUE;
810 algomez 1.1 cutmap["MET"] += PUweight;
811    
812     if (fVerbose) cout << "pass W MT cut " << endl;
813    
814     /////////////////////////////////
815     // estimate Pz of neutrino
816     ////////////////////////////////
817    
818     fzCalculator.SetMET(p4MET);
819     fzCalculator.SetLepton(p4lepton);
820 algomez 1.6 if (fChannel==2) {
821     fzCalculator.SetLeptonType("electron");
822     }
823 algomez 1.9
824     double pzNu = fzCalculator.Calculate();
825     double pzOtherNu = fzCalculator.getOther();
826     if (fabs(pzNu) > fabs(pzOtherNu) ) {
827     double tmppzNu = pzNu;
828     double tmppzOtherNu = pzOtherNu;
829     pzNu = tmppzOtherNu;
830     pzOtherNu = tmppzNu;
831     }
832 algomez 1.1
833     p4Nu = TLorentzVector();
834     p4OtherNu = TLorentzVector();
835    
836     p4Nu.SetPxPyPzE(p4MET.Px(), p4MET.Py(), pzNu, sqrt(p4MET.Px()*p4MET.Px()+p4MET.Py()*p4MET.Py()+pzNu*pzNu));
837     //print "pzNu = " +str(pzNu)
838     //print "p4Nu =("+str(p4Nu.Px())+","+str(p4Nu.Py())+","+str(p4Nu.Pz())+","+str(p4Nu.E())
839     p4OtherNu.SetPxPyPzE( p4MET.Px(), p4MET.Py(),pzOtherNu,sqrt(p4MET.Px()*p4MET.Px()+p4MET.Py()*p4MET.Py()+pzOtherNu*pzOtherNu));
840    
841 algomez 1.6 //double WmassNoPt = (p4Nu+p4lepton).M();
842 algomez 1.1
843 algomez 1.6 if ( fzCalculator.IsComplex() ) {
844     double ptNu1 = fzCalculator.getPtneutrino(1);
845     double ptNu2 = fzCalculator.getPtneutrino(2);
846     TLorentzVector p4Nu1tmp;
847     TLorentzVector p4Nu2tmp;
848 algomez 1.1
849 algomez 1.6 p4Nu1tmp.SetPxPyPzE( ptNu1*p4MET.Px()/p4MET.Pt(), ptNu1*p4MET.Py()/p4MET.Pt(), pzNu, sqrt(ptNu1*ptNu1+pzNu*pzNu));
850     p4Nu2tmp.SetPxPyPzE( ptNu2*p4MET.Px()/p4MET.Pt(), ptNu2*p4MET.Py()/p4MET.Pt(), pzNu, sqrt(ptNu2*ptNu2+pzNu*pzNu));
851 algomez 1.1
852 algomez 1.6 TLorentzVector Wtmp;
853     Wtmp = p4lepton + p4Nu1tmp;
854     double Wm1 = 0;
855     double Wm2 = 0;
856     Wm1 = Wtmp.M();
857     Wtmp = p4lepton + p4Nu2tmp;
858     Wm2 = Wtmp.M();
859     if ( fabs( Wm1 - 80.) < fabs( Wm2 - 80.) ) p4Nu = p4Nu1tmp;
860     else p4Nu = p4Nu2tmp;
861 algomez 1.1
862 algomez 1.6 p4OtherNu = p4Nu; // since we chose the real part, the two solutions are the same.
863     }
864 algomez 1.1
865    
866     hMET["PzNu"]->Fill(pzNu, PUweight ); //change this to 2d with two sol and as a function of jets
867    
868     TLorentzVector p4LepW = p4lepton + p4Nu;
869     TLorentzVector p4OtherLepW = p4lepton + p4OtherNu;
870    
871     //hMET["LepWmass"]->Fill(p4LepW.M(), PUweight );
872     //if ( fzCalculator.IsComplex() ) hMET["LepWmassComplex"]->Fill( p4LepW.M(), PUweight );
873    
874    
875     /////////////////////////////////
876     // JETS
877     ////////////////////////////////
878    
879 algomez 1.6 //JetCombinatorics myCombi = JetCombinatoric();
880 algomez 1.1
881     int njets = 0;
882 algomez 1.10 double prod_bdisc =0;
883 algomez 1.8 MyStoreTree->GetJetVariable()->numjets = 0;
884 algomez 1.1 map< string, vector<float> > bdisc;
885     map< string, vector<bool> > isTagb;
886 algomez 1.9 map< string, vector<bool> > isTagbUp;
887     map< string, vector<bool> > isTagbDown;
888 algomez 1.1 vector<int> listflavor;
889 algomez 1.8 vector<float> bdiscriminator;
890    
891 algomez 1.1
892 algomez 1.6 for ( size_t ijet=0; ijet < total_jets; ++ijet) {
893 algomez 1.1
894 algomez 1.6 TopJetEvent jet = jets[ijet];
895     double SF_JEC = 1.;
896     if (fdoJECunc){
897     fJECunc->setJetEta( jet.eta);
898     fJECunc->setJetPt( jet.pt);
899     double jec_unc = fJECunc->getUncertainty(true);
900     if (fVerbose) cout << "JEC uncertainty is " << jec_unc << endl;
901     if (fdoJECup) SF_JEC = 1.+jec_unc;
902     else SF_JEC = 1.-jec_unc;
903 algomez 1.1 }
904    
905 algomez 1.7 if ( SF_JEC*jet.pt > 40. && fabs(jet.eta) < 2.4 && SF_JEC*jets[0].pt > 100. && SF_JEC*jets[1].pt > 60. ) { //first cut
906 algomez 1.6
907 algomez 1.8 //if (fVerbose) cout << " jet pt " << SF_JEC*jet.pt << endl;
908 algomez 1.6
909     //hjets["pt"]->Fill( jet.pt, PUweight );
910     //hjets["eta"]->Fill( jet.eta, PUweight );
911     //hjets["phi"]->Fill( jet.phi, PUweight );
912    
913     TLorentzVector tmpjet;
914     tmpjet.SetPtEtaPhiE(SF_JEC*jet.pt, jet.eta, jet.phi, SF_JEC*jet.e);
915     p4jets.push_back( tmpjet);
916     listflavor.push_back( jet.mc.flavor );
917 algomez 1.9 if (jet.btag_CSV > 0) bdiscriminator.push_back( jet.btag_CSV ); // for bdiscriminator
918 algomez 1.8 else bdiscriminator.push_back( 0 );
919 algomez 1.6
920     if (fVerbose) {
921     cout << "done storing njets " << njets << endl;
922 algomez 1.8 //cout << " bdisc " << jet.btag_TCHP << endl;
923 algomez 1.6 cout << " bdisc " << jet.btag_CSV << endl;
924     }
925    
926 algomez 1.8
927 algomez 1.7 // store discriminators
928 algomez 1.8 //bdisc["TCHP"].push_back( jet.btag_TCHP );
929 algomez 1.6 bdisc["CSV"].push_back( jet.btag_CSV );
930     if (fVerbose) cout << "store bdisc" << endl;
931     // TCHPL cut at 1.19
932     // check TCHPM cut at 1.93
933 algomez 1.7 //if ( jet.btag_TCHP > 1.93 ) isTagb["TCHPM"].push_back(true);
934     //else isTagb["TCHPM"].push_back(false);
935     //if (fVerbose) cout << "done tchpl" << endl;
936 algomez 1.6 // check SSVHEM cut at 1.74
937 algomez 1.9 if ( jet.btag_CSV > 0.679) {
938     isTagb["CSVM"].push_back(true);
939     isTagbUp["CSVM"].push_back(true);
940     isTagbDown["CSVM"].push_back(true);
941     } else {
942     isTagb["CSVM"].push_back(false);
943     isTagbUp["CSVM"].push_back(false);
944     isTagbDown["CSVM"].push_back(false);
945     }
946 algomez 1.6 if (fVerbose) cout << "done csvm" << endl;
947 algomez 1.7 // CSVM cut at 0.679 MEDIUM
948    
949 algomez 1.6 njets++;
950     }
951     }
952 algomez 1.1
953 algomez 1.10 // if (njets>0) {
954     // /////////// plots without cuts
955     // hM["WMt"]->Fill( WMt, PUweight );
956     // hjets["Njets"]->Fill( njets, PUweight );
957     // hMET["Ht0"]->Fill( ntuple->PFHt, PUweight );
958     // hjets["Njets_cut0"]->Fill( njets, PUweight );
959     // hjets["1st_pt_cut0"]->Fill( p4jets[0].Pt(), PUweight );
960     // hjets["1st_eta_cut0"]->Fill( p4jets[0].Eta(), PUweight );
961     // hjets["2nd_pt_cut0"]->Fill( p4jets[1].Pt(), PUweight );
962     // hjets["2nd_eta_cut0"]->Fill( p4jets[1].Eta(), PUweight );
963     // hjets["3rd_pt_cut0"]->Fill( p4jets[2].Pt(), PUweight );
964     // hjets["4th_pt_cut0"]->Fill( p4jets[3].Pt(), PUweight );
965     // hjets["5th_pt_cut0"]->Fill( p4jets[4].Pt(), PUweight );
966     // hjets["6th_pt_cut0"]->Fill( p4jets[5].Pt(), PUweight );
967     // hjets["7th_pt_cut0"]->Fill( p4jets[6].Pt(), PUweight );
968     // hmuons["N_cut0"]->Fill( total_muons, PUweight );
969     // hmuons["Nelectrons_cut0"]->Fill( nlooseelectrons, PUweight );
970     // hMET["MET_cut0"]->Fill( p4MET.Pt(), PUweight );
971     // hmuons["deltaR_cut0"]->Fill( deltaR, PUweight );
972     // //hjets["Dijet_deltaR_cut0"]->Fill( deltaRjj, PUweight );
973     // /////////////////////////////////////////////////////////////////////
974     // }
975 algomez 1.1
976     if (fVerbose) cout << "done jets" << endl;
977    
978     if (njets > 0 ) cutmap["1Jet"] += PUweight;
979     if (njets > 1 ) cutmap["2Jet"] += PUweight;
980     if (njets > 2 ) cutmap["3Jet"] += PUweight;
981     if (njets > 3 ) cutmap["4Jet"] += PUweight;
982    
983 algomez 1.10 if (njets >= 4) {
984 algomez 1.1
985 algomez 1.7 // count partons
986     int number_of_b = 0;
987     int number_of_c = 0;
988     int number_of_l = 0;
989    
990 algomez 1.6 double Ht = 0;
991 algomez 1.8 double Stlep = 0;
992     double Stjet = 0;
993 algomez 1.6 double deltaRjj = 999.;
994 algomez 1.7
995 algomez 1.8
996 algomez 1.6 for ( size_t kk=0; kk < p4jets.size(); ++kk) {
997 algomez 1.7 // Ht calculation
998 algomez 1.6 Ht += p4jets[kk].Pt();
999    
1000 algomez 1.8 // St Calculation
1001     Stlep = p4MET.Pt() + p4lepton.Pt() ;
1002     Stjet = p4MET.Pt() + p4lepton.Pt() + Ht ;
1003    
1004    
1005 algomez 1.7 // deltaR(jet,jet)
1006 algomez 1.6 for ( vector< TopJetEvent>::iterator ijet=jets.begin(); ijet != jets.end(); ++ijet) {
1007    
1008     TopJetEvent jet = *ijet;
1009     TLorentzVector tmpp4Jet;
1010     tmpp4Jet.SetPtEtaPhiE(jet.pt, jet.eta, jet.phi, jet.e );
1011     double tmpdeltaR = p4jets[kk].DeltaR(tmpp4Jet);
1012     if ( tmpdeltaR < 0.3 ) continue;
1013     if ( tmpdeltaR < deltaRjj ) deltaRjj = tmpdeltaR;
1014     }
1015 algomez 1.7
1016     // b-tag
1017     if ( abs(listflavor[kk])==5 && p4jets[kk].Pt()<=240 ) { number_of_b++; hjets["pt_b_mc"]->Fill( p4jets[kk].Pt(), PUweight );}
1018     if ( abs(listflavor[kk])==4 && p4jets[kk].Pt()<=240 ) { number_of_c++; hjets["pt_c_mc"]->Fill( p4jets[kk].Pt(), PUweight );}
1019     if ( abs(listflavor[kk])==1 || abs(listflavor[kk])==2 || abs(listflavor[kk])==3 || abs(listflavor[kk])==21 ) { number_of_l++; hjets["pt_l_mc"]->Fill( p4jets[kk].Pt(), PUweight );}
1020 algomez 1.9 //if ( abs(listflavor[kk])==5 && p4jets[kk].Pt()>240 ) { number_of_b_highpt++; hjets["pt_b_mc"]->Fill( p4jets[kk].Pt(), PUweight );}
1021     //if ( abs(listflavor[kk])==4 && p4jets[kk].Pt()>240 ) { number_of_c_highpt++; hjets["pt_c_mc"]->Fill( p4jets[kk].Pt(), PUweight );}
1022 algomez 1.8
1023 algomez 1.9
1024     hjets["pt"]->Fill( p4jets[kk].Pt(), PUweight );
1025     //float b_mc_eff = f2Dttbarbtag->GetBinContent(f2Dttbarbtag->FindBin(p4jets[kk].Pt(),fabs(p4jets[kk].Eta())));
1026     //float c_mc_eff = f2Dttbarctag->GetBinContent(f2Dttbarctag->FindBin(p4jets[kk].Pt(),fabs(p4jets[kk].Eta())));
1027     //float l_mc_eff = f2Dttbarlighttag->GetBinContent(f2Dttbarlighttag->FindBin(p4jets[kk].Pt(),fabs(p4jets[kk].Eta())));
1028     float b_data_eff = 0.705;
1029     float c_data_eff = b_data_eff/5.;
1030    
1031     float b_SF = 0.972; //bSF_table.GetValue( p4jets[kk].Pt(), fabs(p4jets[kk].Eta()) );
1032     float l_SF = lSF_table.GetValue( p4jets[kk].Pt(), fabs(p4jets[kk].Eta()) );
1033     float l_data_eff = leff_table.GetValue( p4jets[kk].Pt(), fabs(p4jets[kk].Eta()) );
1034    
1035     double seed = abs(static_cast<int>(sin(p4jets[kk].Phi()*1000000)*100000));
1036     BTagSFUtil btsfutil = BTagSFUtil( seed );
1037    
1038     if ( fIsMC && abs(listflavor[kk])==5 ) {
1039     number_of_b++; hjets["pt_b_mc"]->Fill( p4jets[kk].Pt(), PUweight );
1040     //Info("Process",TString("btag SF= ")+TString(Form("%f",b_SF)));
1041    
1042     bool tmp_IsTag = isTagb["CSVM"][kk];
1043     isTagb["CSVM"][kk] = btsfutil.modifyBTagsWithSF( tmp_IsTag, abs(listflavor[kk]), b_SF, b_data_eff, l_SF, l_data_eff);
1044    
1045     if (p4jets[kk].Pt()<=240 ) {
1046     tmp_IsTag = isTagbUp["CSVM"][kk];
1047     isTagbUp["CSVM"][kk] = btsfutil.modifyBTagsWithSF( tmp_IsTag , abs(listflavor[kk]), b_SF*1.04, b_data_eff, l_SF, l_data_eff);
1048     tmp_IsTag = isTagbDown["CSVM"][kk];
1049     isTagbDown["CSVM"][kk] = btsfutil.modifyBTagsWithSF( tmp_IsTag, abs(listflavor[kk]), b_SF*0.96, b_data_eff, l_SF, l_data_eff);
1050     } else {
1051     tmp_IsTag = isTagbUp["CSVM"][kk];
1052     isTagbUp["CSVM"][kk] = btsfutil.modifyBTagsWithSF( tmp_IsTag , abs(listflavor[kk]), b_SF*1.15, b_data_eff, l_SF, l_data_eff);
1053     tmp_IsTag = isTagbDown["CSVM"][kk];
1054     isTagbDown["CSVM"][kk] = btsfutil.modifyBTagsWithSF( tmp_IsTag, abs(listflavor[kk]), b_SF*0.85, b_data_eff, l_SF, l_data_eff);
1055     }
1056     }
1057    
1058     if ( fIsMC && abs(listflavor[kk])==4 ) {
1059     number_of_c++; hjets["pt_c_mc"]->Fill( p4jets[kk].Pt(), PUweight );
1060     bool tmp_IsTag = isTagb["CSVM"][kk];
1061     isTagb["CSVM"][kk] = btsfutil.modifyBTagsWithSF( tmp_IsTag, abs(listflavor[kk]), b_SF, c_data_eff, l_SF, l_data_eff);
1062     if (p4jets[kk].Pt()<=240 ) {
1063     tmp_IsTag = isTagbUp["CSVM"][kk];
1064     isTagbUp["CSVM"][kk] = btsfutil.modifyBTagsWithSF( tmp_IsTag , abs(listflavor[kk]), b_SF*1.08, c_data_eff, l_SF, l_data_eff);
1065     tmp_IsTag = isTagbDown["CSVM"][kk];
1066     isTagbDown["CSVM"][kk] = btsfutil.modifyBTagsWithSF( tmp_IsTag, abs(listflavor[kk]), b_SF*0.92, c_data_eff, l_SF, l_data_eff);
1067     } else {
1068     tmp_IsTag = isTagbUp["CSVM"][kk];
1069     isTagbUp["CSVM"][kk] = btsfutil.modifyBTagsWithSF( tmp_IsTag , abs(listflavor[kk]), b_SF*1.15, c_data_eff, l_SF, l_data_eff);
1070     tmp_IsTag = isTagbDown["CSVM"][kk];
1071     isTagbDown["CSVM"][kk] = btsfutil.modifyBTagsWithSF( tmp_IsTag, abs(listflavor[kk]), b_SF*0.85, c_data_eff, l_SF, l_data_eff);
1072     }
1073     }
1074    
1075     if ( fIsMC && (abs(listflavor[kk])==1 || abs(listflavor[kk])==2 || abs(listflavor[kk])==3 || abs(listflavor[kk])==21 )) {
1076     number_of_l++; hjets["pt_l_mc"]->Fill( p4jets[kk].Pt(), PUweight );
1077     bool tmp_IsTag = isTagb["CSVM"][kk];
1078     isTagb["CSVM"][kk] = btsfutil.modifyBTagsWithSF( tmp_IsTag, abs(listflavor[kk]), b_SF, b_data_eff, l_SF, l_data_eff);
1079     if (p4jets[kk].Pt()<=240 ) {
1080     tmp_IsTag = isTagbUp["CSVM"][kk];
1081     isTagbUp["CSVM"][kk] = btsfutil.modifyBTagsWithSF( tmp_IsTag , abs(listflavor[kk]), b_SF, b_data_eff, l_SF*1.13, l_data_eff);
1082     tmp_IsTag = isTagbDown["CSVM"][kk];
1083     isTagbDown["CSVM"][kk] = btsfutil.modifyBTagsWithSF( tmp_IsTag, abs(listflavor[kk]), b_SF, b_data_eff, l_SF*1.13, l_data_eff);
1084     } else {
1085     tmp_IsTag = isTagbUp["CSVM"][kk];
1086     isTagbUp["CSVM"][kk] = btsfutil.modifyBTagsWithSF( tmp_IsTag , abs(listflavor[kk]), b_SF, b_data_eff, l_SF*1.20, l_data_eff);
1087     tmp_IsTag = isTagbDown["CSVM"][kk];
1088     isTagbDown["CSVM"][kk] = btsfutil.modifyBTagsWithSF( tmp_IsTag, abs(listflavor[kk]), b_SF, b_data_eff, l_SF*1.20, l_data_eff);
1089     }
1090     }
1091    
1092     if ( isTagb["CSVM"][kk] ) {
1093     hjets["pt_btag"]->Fill( p4jets[kk].Pt(), PUweight );
1094     if ( abs(listflavor[kk])==5 ) hjets["pt_btag_b"]->Fill( p4jets[kk].Pt(), PUweight );
1095     if ( abs(listflavor[kk])==4 ) hjets["pt_btag_c"]->Fill( p4jets[kk].Pt(), PUweight );
1096     if ( abs(listflavor[kk])==1 || abs(listflavor[kk])==2 || abs(listflavor[kk])==3 || abs(listflavor[kk])==21 ) hjets["pt_btag_l"]->Fill( p4jets[kk].Pt(), PUweight );
1097     }
1098 algomez 1.1 }
1099    
1100 algomez 1.9 // W+jets h.f. corrections
1101     int FH = 2; // 0=Wbb, 1=Wcc, 2=Wqq
1102     if ( number_of_b > 0 ) FH = 0;
1103     else if ( number_of_b == 0 && number_of_c > 0 ) FH = 1;
1104     else FH = 2;
1105     float SF_W = 1.;
1106     if (fSample=="WJets") {
1107     // from TOP-11-003
1108     if ( FH == 0 ) SF_W = 1.21;
1109     if ( FH == 1 ) SF_W = 1.66;
1110     }
1111    
1112     // Split W+jets if requested
1113     if (fSample=="Wbb" && FH != 0 ) return kTRUE;
1114     if (fSample=="Wcc" && FH != 1 ) return kTRUE;
1115     if (fSample=="Wqq" && FH != 2 ) return kTRUE;
1116    
1117 algomez 1.7 // count number of b-tags
1118 algomez 1.10 int Nbtags_TCHPM = 0;
1119 algomez 1.7 int Nbtags_CSVM = 0;
1120 algomez 1.10 int NbtagsUp_CSVM = 0;
1121     int NbtagsDown_CSVM = 0;
1122     float SFb_0tag = 1.;
1123     float SFb_only1tag = 1.;
1124     float SFb_1tag = 1.;
1125     float SFb_2tag = 1.;
1126     float SFb_0tag_syst[2] = {1.}; // for systematics
1127     float SFb_1tag_syst[2] = {1.};
1128     float SFb_2tag_syst[2] = {1.};
1129    
1130 algomez 1.7 for ( size_t itag=0; itag< isTagb["CSVM"].size(); ++itag ) {
1131 algomez 1.10 if ( isTagb["TCHPM"][itag] ) Nbtags_TCHPM++;
1132 algomez 1.7 if ( isTagb["CSVM"][itag] ) Nbtags_CSVM++;
1133 algomez 1.10 if ( isTagbUp["CSVM"][itag] ) NbtagsUp_CSVM++;
1134     if ( isTagbDown["CSVM"][itag] ) NbtagsDown_CSVM++;
1135 algomez 1.7 }
1136 algomez 1.10
1137     // store b tags
1138     hjets["Nbtags_CSVM"]->Fill( Nbtags_CSVM, PUweight*SF_W );
1139 algomez 1.7
1140     // compute b-tag event weight
1141     if ( fIsMC ) {
1142 algomez 1.9 hMET["genMET_2jet"]->Fill( ntuple->gen.MET, PUweight*SF_W );
1143     hMET["deltaMET_2jet"]->Fill( p4MET.Pt() - ntuple->gen.MET, PUweight*SF_W );
1144     }
1145     /*
1146 algomez 1.7 // zeto tag
1147     BTagWeight b0(0,0); // number of tags
1148     //BTagWeight::JetInfo bj(0.63,0.91); // mean MC eff and mean SF. For TCHPM=0.91\pm0.09, CSVM=0.96\pm0.096
1149     //BTagWeight::JetInfo cj(0.15,0.91);
1150     BTagWeight::JetInfo bj(0.63,0.96);
1151     BTagWeight::JetInfo cj(0.15,0.96);
1152     double light_mceff = 0.017; //CHECK
1153     if ( 100 < p4jets[0].Pt() && p4jets[0].Pt() <= 200 ) light_mceff = 0.04;
1154     if ( 200 < p4jets[0].Pt() && p4jets[0].Pt() <= 300 ) light_mceff = 0.08;
1155     if ( 300 < p4jets[0].Pt() && p4jets[0].Pt() <= 400 ) light_mceff = 0.12;
1156     if ( 400 < p4jets[0].Pt() ) light_mceff = 0.14;
1157    
1158     //BTagWeight::JetInfo lj(light_mceff,1.22); //for TCHPM=1.22, CSVM=1.08 \pm 0.13
1159     BTagWeight::JetInfo lj(light_mceff,1.08);
1160    
1161     // b-tag systematic UP 9% for b, 18% for c
1162     // for CSVM 5% for b, and 10% for c
1163     //BTagWeight::JetInfo bjUP(0.63,0.99);
1164     //BTagWeight::JetInfo cjUP(0.15,1.07);
1165     BTagWeight::JetInfo bjUP(0.63,1.008);
1166     BTagWeight::JetInfo cjUP(0.15,1.056);
1167    
1168     // b-tag systemacit DOWN 9% for b, 18% for c
1169     //BTagWeight::JetInfo bjDOWN(0.63,0.83);
1170     //BTagWeight::JetInfo cjDOWN(0.15,0.75);
1171     BTagWeight::JetInfo bjDOWN(0.63,0.912);
1172     BTagWeight::JetInfo cjDOWN(0.15,0.864);
1173    
1174     // for high pt jets > 240 UP 50% for b and c
1175     // for CSVM
1176     //BTagWeight::JetInfo bjUPhighpt(0.63,1.36);
1177     //BTagWeight::JetInfo cjUPhighpt(0.15,1.36);
1178     BTagWeight::JetInfo bjUPhighpt(0.63,1.104);
1179     BTagWeight::JetInfo cjUPhighpt(0.15,1.104);
1180     // for high pt jets > 240 DOWN 50% for b and c
1181     //BTagWeight::JetInfo bjDOWNhighpt(0.63,0.46);
1182     //BTagWeight::JetInfo cjDOWNhighpt(0.15,0.46);
1183     BTagWeight::JetInfo bjDOWNhighpt(0.63,0.816);
1184     BTagWeight::JetInfo cjDOWNhighpt(0.15,0.816);
1185    
1186     vector<BTagWeight::JetInfo> j;
1187     for(int i=0;i<number_of_b;i++)j.push_back(bj);
1188     for(int i=0;i<number_of_b_highpt;i++)j.push_back(bj);
1189     for(int i=0;i<number_of_c;i++)j.push_back(cj);
1190     for(int i=0;i<number_of_c_highpt;i++)j.push_back(cj);
1191     for(int i=0;i<number_of_l;i++)j.push_back(lj);
1192    
1193     // changed to CSVM from TCHPM
1194     if (Nbtags_CSVM==0) {
1195     SFb_0tag = b0.weight(j,0);
1196     hjets["Nbtags_CSVM"]->Fill( Nbtags_CSVM, PUweight*SFb_0tag ); // fill bin 0
1197     }
1198    
1199     // only one tag
1200     BTagWeight b11(1,1); // number of tags
1201     if (Nbtags_CSVM==1) {
1202     SFb_only1tag = b11.weight(j,1);
1203     hjets["Nbtags_CSVM"]->Fill( Nbtags_CSVM, PUweight*SFb_only1tag ); // fill bin 1
1204     }
1205    
1206     // at least one tag
1207     BTagWeight b1(1,Nbtags_CSVM); // number of tags
1208     if (Nbtags_CSVM>=1) {
1209     SFb_1tag = b1.weight(j,1);
1210    
1211     // UP
1212     vector<BTagWeight::JetInfo> jj;
1213     for(int i=0;i<number_of_b;i++)jj.push_back(bjUP);
1214     for(int i=0;i<number_of_b_highpt;i++)jj.push_back(bjUPhighpt);
1215     for(int i=0;i<number_of_c;i++)jj.push_back(cjUP);
1216     for(int i=0;i<number_of_c_highpt;i++)jj.push_back(cjUPhighpt);
1217     for(int i=0;i<number_of_l;i++)jj.push_back(lj);
1218     SFb_1tag_syst[0] = b1.weight(jj,1);
1219    
1220     // DOWN
1221     vector<BTagWeight::JetInfo> jk;
1222     for(int i=0;i<number_of_b;i++)jk.push_back(bjDOWN);
1223     for(int i=0;i<number_of_b_highpt;i++)jk.push_back(bjDOWNhighpt);
1224     for(int i=0;i<number_of_c;i++)jk.push_back(cjDOWN);
1225     for(int i=0;i<number_of_c_highpt;i++)jk.push_back(cjDOWNhighpt);
1226     for(int i=0;i<number_of_l;i++)jk.push_back(lj);
1227     SFb_1tag_syst[1] = b1.weight(jk,1);
1228 algomez 1.8
1229 algomez 1.7 }
1230    
1231     // at least two tags
1232     BTagWeight b2(2,Nbtags_CSVM); // number of tags
1233     if (Nbtags_CSVM>=2) {
1234     SFb_2tag = b2.weight(j,2);
1235     hjets["Nbtags_CSVM"]->Fill( Nbtags_CSVM, PUweight*SFb_2tag ); // fill bin >=2
1236    
1237     // UP
1238     vector<BTagWeight::JetInfo> jj;
1239     for(int i=0;i<number_of_b;i++)jj.push_back(bjUP);
1240     for(int i=0;i<number_of_b_highpt;i++)jj.push_back(bjUPhighpt);
1241     for(int i=0;i<number_of_c;i++)jj.push_back(cjUP);
1242     for(int i=0;i<number_of_c_highpt;i++)jj.push_back(cjUPhighpt);
1243     for(int i=0;i<number_of_l;i++)jj.push_back(lj);
1244     SFb_2tag_syst[0] = b2.weight(jj,2);
1245    
1246     // DOWN
1247     vector<BTagWeight::JetInfo> jk;
1248     for(int i=0;i<number_of_b;i++)jk.push_back(bjDOWN);
1249     for(int i=0;i<number_of_b_highpt;i++)jk.push_back(bjDOWNhighpt);
1250     for(int i=0;i<number_of_c;i++)jk.push_back(cjDOWN);
1251     for(int i=0;i<number_of_c_highpt;i++)jk.push_back(cjDOWNhighpt);
1252     for(int i=0;i<number_of_l;i++)jk.push_back(lj);
1253     SFb_2tag_syst[1] = b2.weight(jk,2);
1254 algomez 1.9 }*/
1255     //else hjets["Nbtags_CSVM"]->Fill( Nbtags_CSVM );
1256 algomez 1.7
1257     //hjets["Nbtags_TCHPM"]->Fill( Nbtags_TCHPM, PUweight*SFb );
1258     //hjets["Nbtags_CSVM"]->Fill( Nbtags_CSVM, PUweight*SFb );
1259 algomez 1.6
1260 algomez 1.9
1261 algomez 1.7 // Cuts
1262 algomez 1.6 bool passcut = true;
1263     if ( Ht <= 300. ) passcut = false;
1264    
1265     if (passcut) {
1266 algomez 1.7 hPVs["Nreweight_2jet"]->Fill( total_pvs, PUweight );
1267     hMET["Ht"]->Fill( Ht, PUweight );
1268 algomez 1.10 hMET["MET"]->Fill( p4MET.Pt(), PUweight );
1269     hMET["Stlep"]->Fill( Stlep , PUweight );
1270     hMET["Stjet"]->Fill( Stjet , PUweight );
1271 algomez 1.6 hjets["Njets_cut1"]->Fill( njets, PUweight );
1272     hjets["1st_pt"]->Fill( p4jets[0].Pt(), PUweight );
1273     hjets["1st_eta"]->Fill( p4jets[0].Eta(), PUweight );
1274     hjets["2nd_pt"]->Fill( p4jets[1].Pt(), PUweight );
1275     hjets["2nd_eta"]->Fill( p4jets[1].Eta(), PUweight );
1276     hjets["3rd_pt"]->Fill( p4jets[2].Pt(), PUweight );
1277     hjets["4th_pt"]->Fill( p4jets[3].Pt(), PUweight );
1278     hjets["5th_pt"]->Fill( p4jets[4].Pt(), PUweight );
1279     hjets["6th_pt"]->Fill( p4jets[5].Pt(), PUweight );
1280     hjets["7th_pt"]->Fill( p4jets[6].Pt(), PUweight );
1281 algomez 1.10 hjets["Dijet_deltaR"]->Fill( deltaRjj, PUweight );
1282 algomez 1.6 hmuons["N"]->Fill( total_muons, PUweight );
1283     hmuons["Nelectrons"]->Fill( nlooseelectrons, PUweight );
1284 algomez 1.10 hmuons["pt"]->Fill( p4lepton.Pt(), PUweight );
1285 algomez 1.6 hmuons["deltaR"]->Fill( deltaR, PUweight );
1286 algomez 1.7 hM["WMt_2jet"]->Fill( WMt, PUweight );
1287    
1288 algomez 1.10 // plot bdiscriminator
1289     if ( bdiscriminator[0] >= 0 ) { MyStoreTree->GetJetVariable()->bdisc_1st = bdiscriminator[0]; hjets["1st_bdisc"]->Fill( bdiscriminator[0], PUweight );}
1290     if ( bdiscriminator[1] >= 0 ) { MyStoreTree->GetJetVariable()->bdisc_2nd = bdiscriminator[1]; hjets["2nd_bdisc"]->Fill( bdiscriminator[1], PUweight );}
1291     if ( bdiscriminator[2] >= 0 ) { MyStoreTree->GetJetVariable()->bdisc_3rd = bdiscriminator[2]; hjets["3rd_bdisc"]->Fill( bdiscriminator[2], PUweight );}
1292     if ( bdiscriminator[3] >= 0 ) { MyStoreTree->GetJetVariable()->bdisc_4th = bdiscriminator[3]; hjets["4th_bdisc"]->Fill( bdiscriminator[3], PUweight );}
1293     prod_bdisc = bdiscriminator[0]*bdiscriminator[1]*bdiscriminator[2]*bdiscriminator[3];
1294     hjets["prod_bdisc"]->Fill( prod_bdisc, PUweight );
1295     MyStoreTree->GetGeneralVariable()->PUWeight = PUweight;
1296     MyStoreTree->GetMetVariable()->Ht = Ht;
1297     MyStoreTree->GetMetVariable()->Stlep = Stlep;
1298     MyStoreTree->GetMetVariable()->Stjet = Stjet;
1299     MyStoreTree->GetJetVariable()->numjets= njets;
1300     //////////////////////////////////////////////////////////////////////////////////
1301    
1302 algomez 1.7 if ( Nbtags_CSVM >= 1 ) {
1303 algomez 1.10 hPVs["Nreweight_2jet_1btag"]->Fill( total_pvs, PUweight );
1304     hMET["Ht_1btag"]->Fill( Ht, PUweight );
1305     hMET["MET_1btag"]->Fill( p4MET.Pt(), PUweight );
1306     hMET["Stlep_1btag"]->Fill( Stlep , PUweight );
1307     hMET["Stjet_1btag"]->Fill( Stjet , PUweight );
1308     hjets["Njets_1btag"]->Fill(njets, PUweight*SFb_1tag );
1309     hjets["1st_pt_1btag"]->Fill( p4jets[0].Pt(), PUweight );
1310     hjets["1st_eta_1btag"]->Fill( p4jets[0].Eta(), PUweight );
1311     hjets["2nd_pt_1btag"]->Fill( p4jets[1].Pt(), PUweight );
1312     hjets["2nd_eta_1btag"]->Fill( p4jets[1].Eta(), PUweight );
1313     hjets["3rd_pt_1btag"]->Fill( p4jets[2].Pt(), PUweight );
1314     hjets["4th_pt_1btag"]->Fill( p4jets[3].Pt(), PUweight );
1315     hjets["5th_pt_1btag"]->Fill( p4jets[4].Pt(), PUweight );
1316     hjets["6th_pt_1btag"]->Fill( p4jets[5].Pt(), PUweight );
1317     hjets["7th_pt_1btag"]->Fill( p4jets[6].Pt(), PUweight );
1318     hjets["Dijet_deltaR_1btag"]->Fill( deltaRjj, PUweight );
1319     hmuons["N_1btag"]->Fill( total_muons, PUweight );
1320     hmuons["Nelectrons_1btag"]->Fill( nlooseelectrons, PUweight );
1321     hmuons["pt_1btag"]->Fill( p4lepton.Pt(), PUweight );
1322     hmuons["deltaR_1btag"]->Fill( deltaR, PUweight );
1323     hM["WMt_2jet_1btag"]->Fill( WMt, PUweight );
1324    
1325     // plot bdiscriminator
1326     //if ( bdiscriminator[0] >= 0 ) hjets["1st_bdisc"]->Fill( bdiscriminator[0], PUweight );
1327     hjets["1st_bdisc_1btag"]->Fill( bdiscriminator[0], PUweight );
1328     if ( bdiscriminator[1] >= 0 ) hjets["2nd_bdisc_1btag"]->Fill( bdiscriminator[1], PUweight );
1329     if ( bdiscriminator[2] >= 0 ) hjets["3rd_bdisc_1btag"]->Fill( bdiscriminator[2], PUweight );
1330     if ( bdiscriminator[3] >= 0 ) hjets["4th_bdisc_1btag"]->Fill( bdiscriminator[3], PUweight );
1331     hjets["prod_bdisc_1btag"]->Fill( prod_bdisc, PUweight );
1332     //////////////////////////////////////////////////////////////////////////////////
1333 algomez 1.7 }
1334 algomez 1.4 }
1335 algomez 1.6 }
1336 algomez 1.1
1337 algomez 1.9 MyStoreTree->GetGeneralVariable()->Run = ntuple->run;
1338     MyStoreTree->GetGeneralVariable()->Lumi = ntuple->lumi;
1339     MyStoreTree->GetGeneralVariable()->Event = ntuple->event;
1340 algomez 1.8
1341     MyStoreTree->GetStoreTree()->Fill();
1342 algomez 1.1 if (fVerbose) cout << "done analysis" << endl;
1343     return kTRUE;
1344     }
1345    
1346     void Analyzer::SlaveTerminate()
1347     {
1348     // The SlaveTerminate() function is called after all entries or objects
1349     // have been processed. When running with PROOF SlaveTerminate() is called
1350     // on each slave server.
1351    
1352     // fill cutflow histogram
1353    
1354     int ibin = 1;
1355     for ( vector<string>::const_iterator ivec= fCutLabels.begin(); ivec != fCutLabels.end(); ++ivec )
1356     // for ( map<string, int >::const_iterator imap=cutmap.begin(); imap!=cutmap.end(); ++imap )
1357     {
1358     hcutflow->SetBinContent( ibin, cutmap[ *ivec ] );
1359     ibin++;
1360     }
1361 algomez 1.8
1362 algomez 1.1 // Write the ntuple to the file
1363     if (fFile) {
1364 algomez 1.8 Bool_t cleanup = kFALSE;
1365     TDirectory *savedir = gDirectory;
1366     if ( h1test->GetEntries() > 0) {
1367     fFile->cd();
1368     h1test->Write();
1369     hcutflow->Write();
1370     MyStoreTree->GetStoreTree()->Write();
1371     //h2_pt_Wprime->Write();
1372     fFile->mkdir("muons");
1373     fFile->cd("muons");
1374     for ( map<string,TH1* >::const_iterator imap=hmuons.begin(); imap!=hmuons.end(); ++imap ) {
1375     TH1 *temp = imap->second;
1376     if ( temp->GetEntries() > 0 )
1377     temp->Write();
1378     //else cout << "Warning: empty histogram " << temp->GetName() << " will not be written to file." << endl;
1379     }
1380     fFile->cd();
1381     fFile->mkdir("PVs");
1382     fFile->cd("PVs");
1383     for ( map<string,TH1* >::const_iterator imap=hPVs.begin(); imap!=hPVs.end(); ++imap ) {
1384     TH1 *temp = imap->second;
1385     if ( temp->GetEntries() > 0 )
1386     temp->Write();
1387     //else cout << "Warning: empty histogram " << temp->GetName() << " will not be written to file." << endl;
1388     }
1389     fFile->cd();
1390     fFile->mkdir("jets");
1391     fFile->cd("jets");
1392     for ( map<string,TH1* >::const_iterator imap=hjets.begin(); imap!=hjets.end(); ++imap ) {
1393     TH1 *temp = imap->second;
1394     if ( temp->GetEntries() > 0 )
1395     temp->Write();
1396     }
1397     fFile->cd();
1398     fFile->mkdir("mass");
1399     fFile->cd("mass");
1400     for ( map<string,TH1* >::const_iterator imap=hM.begin(); imap!=hM.end(); ++imap ) {
1401     TH1 *temp = imap->second;
1402     if ( temp->GetEntries() > 0 )
1403     temp->Write();
1404     }
1405     fFile->cd();
1406     fFile->mkdir("MET");
1407     fFile->cd("MET");
1408     for ( map<string,TH1* >::const_iterator imap=hMET.begin(); imap!=hMET.end(); ++imap ) {
1409     TH1 *temp = imap->second;
1410     if ( temp->GetEntries() > 0 )
1411     temp->Write();
1412     }
1413     fFile->cd();
1414     // fFile->mkdir("TMVA");
1415     // fFile->cd("TMVA");
1416     // fBdisc->Write();
1417     // fBdisc->Print();
1418     // TMVA->Write();
1419     //
1420     fFile->cd();
1421    
1422     fProofFile->Print();
1423     fOutput->Add(fProofFile);
1424     } else {
1425     cleanup = kTRUE;
1426     }
1427 algomez 1.1
1428    
1429     h1test->SetDirectory(0);
1430     hcutflow->SetDirectory(0);
1431     gDirectory = savedir;
1432     fFile->Close();
1433     // Cleanup, if needed
1434     if (cleanup) {
1435 algomez 1.8 TUrl uf(*(fFile->GetEndpointUrl()));
1436     SafeDelete(fFile);
1437     gSystem->Unlink(uf.GetFile());
1438     SafeDelete(fProofFile);
1439 algomez 1.1 }
1440     }
1441    
1442     }
1443    
1444     void Analyzer::Terminate()
1445     {
1446     // The Terminate() function is the last function to be called during
1447     // a query. It always runs on the client, it can be used to present
1448     // the results graphically or save the results to file.
1449    
1450     Info("Terminate","Analyzer done.");
1451     }