ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/algomez/FourTop/TreeAnalyzer/test/Analyzer.C
Revision: 1.14
Committed: Thu Mar 1 17:24:49 2012 UTC (13 years, 2 months ago) by algomez
Content type: text/plain
Branch: MAIN
Changes since 1.13: +96 -59 lines
Log Message:
new version, more BDT variables, less plots after BDT training

File Contents

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