ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/algomez/FourTop/TreeAnalyzer/test/Analyzer.C
Revision: 1.9
Committed: Fri Jan 6 16:22:18 2012 UTC (13 years, 4 months ago) by algomez
Content type: text/plain
Branch: MAIN
Changes since 1.8: +228 -48 lines
Log Message:
fix storing b discriminant value

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