ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/algomez/FourTop/TreeAnalyzer/test/Analyzer.C
Revision: 1.7
Committed: Mon Dec 19 18:21:42 2011 UTC (13 years, 4 months ago) by algomez
Content type: text/plain
Branch: MAIN
Changes since 1.6: +171 -13 lines
Log Message:
adding b-tagging

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     #include "BTagWeight.h"
28     //#include "Yumiceva/TreeAnalyzer/interface/JetCombinatorics.h"
29    
30     #include <TStyle.h>
31     #include <TSystem.h>
32    
33     #include <iostream>
34     #include <vector>
35     #include <stdio.h>
36     #include <stdlib.h>
37    
38     void Analyzer::ParseInput()
39     {
40    
41     if (fMyOpt.Contains("muon"))
42     {
43     fChannel = 1;
44     }
45     if (fMyOpt.Contains("electron"))
46     {
47     fChannel = 2;
48     }
49     if (fMyOpt.Contains("verbose"))
50     {
51     fVerbose = true;
52     }
53     if (fMyOpt.Contains("JECUP")) { fdoJECunc = true; fdoJECup = true; }
54     if (fMyOpt.Contains("JECDOWN")) { fdoJECunc = true; fdoJECup = false; }
55 algomez 1.2 if (fMyOpt.Contains("PUUP")) { fpuhistogram = "WHistUp";}
56     if (fMyOpt.Contains("PUDOWN")) { fpuhistogram = "WHistDown";}
57 algomez 1.1 if (fMyOpt.Contains("QCD1")) fdoQCD1SideBand = true;
58     if (fMyOpt.Contains("QCD2")) fdoQCD2SideBand = true;
59     if (fMyOpt.Contains("mtop")) fdoMtopCut = true;
60     if (fMyOpt.Contains("outdir")) {
61     TString tmp = fMyOpt;
62     tmp = tmp.Remove(0,fMyOpt.Index("outdir")+7);
63     fOutdir = tmp+"/";
64     Info("Begin","output files will be written to directory: %s", fOutdir.Data());
65     }
66     if (fMyOpt.Contains("sample"))
67     {
68     TString tmp = fMyOpt;
69     tmp = tmp.Remove(0,fMyOpt.Index("sample")+7);
70     fSample = tmp;
71     if (fdoJECunc && fdoJECup==true) fSample += "_JECUP";
72     if (fdoJECunc && fdoJECup==false) fSample += "_JECDOWN";
73 algomez 1.2 if (fMyOpt.Contains("PUUP")) fSample += "_PUUP";
74     if (fMyOpt.Contains("PUDOWN")) fSample += "_PUDOWN";
75 algomez 1.1
76     Info("Begin","Histogram names will have suffix: %s", fSample.Data());
77    
78     if ( fSample.Contains("data") )
79     {
80     fIsMC = false;
81     Info("Begin","This sample is treated as DATA");
82     if (fdoQCD1SideBand) fSample = "dataQCD1";
83     if (fdoQCD2SideBand) fSample = "dataQCD2";
84     }
85 algomez 1.2 else
86     {
87     Info("Begin","This sample is treated as MC");
88     Info("Begin","we will use pileup set: %s", fpuhistogram.Data());
89     }
90    
91 algomez 1.1
92     }
93     }
94    
95     void Analyzer::Begin(TTree * /*tree*/)
96     {
97     // The Begin() function is called at the start of the query.
98     // When running with PROOF Begin() is only called on the client.
99     // The tree argument is deprecated (on PROOF 0 is passed).
100    
101     TString option = GetOption();
102     fMyOpt = option;
103     ParseInput();
104    
105     Info("Begin", "starting with process option: %s", option.Data());
106    
107     }
108    
109     void Analyzer::SlaveBegin(TTree * tree)
110     {
111    
112     // The SlaveBegin() function is called after the Begin() function.
113     // When running with PROOF SlaveBegin() is called on each slave server.
114     // The tree argument is deprecated (on PROOF 0 is passed).
115    
116     TString option = GetOption();
117     fMyOpt = option;
118     ParseInput();
119    
120     Info("SlaveBegin",
121     "starting with process option: %s (tree: %p)", option.Data(), tree);
122    
123     //initialize the Tree branch addresses
124     Init(tree);
125    
126     // We may be creating a dataset or a merge file: check it
127     TNamed *nm = dynamic_cast<TNamed *>(fInput->FindObject("SimpleNtuple.root"));
128     if (nm) {
129     // Just create the object
130     UInt_t opt = TProofOutputFile::kRegister | TProofOutputFile::kOverwrite | TProofOutputFile::kVerify;
131     fProofFile = new TProofOutputFile("SimpleNtuple.root",
132     TProofOutputFile::kDataset, opt, nm->GetTitle());
133     } else {
134     // For the ntuple, we use the automatic file merging facility
135     // Check if an output URL has been given
136     TNamed *out = (TNamed *) fInput->FindObject("PROOF_OUTPUTFILE_LOCATION");
137     Info("SlaveBegin", "PROOF_OUTPUTFILE_LOCATION: %s", (out ? out->GetTitle() : "undef"));
138     TString tmpfilename = "results";
139     if ( fSample != "" ) tmpfilename += "_"+fSample+".root";
140     else tmpfilename = "results.root";
141     fProofFile = new TProofOutputFile(tmpfilename, (out ? out->GetTitle() : "M"));
142     out = (TNamed *) fInput->FindObject("PROOF_OUTPUTFILE");
143     if (out) fProofFile->SetOutputFileName(fOutdir + out->GetTitle());
144     }
145    
146     // Open the file
147     //TDirectory *savedir = gDirectory;
148     if (!(fFile = fProofFile->OpenFile("RECREATE"))) {
149     Warning("SlaveBegin", "problems opening file: %s/%s",
150     fProofFile->GetDir(), fProofFile->GetFileName());
151     }
152    
153 algomez 1.2 // Get PU weights
154 algomez 1.6 TString weightfilename = "/uscms/home/algomez/work/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/Weight3Dfinebin4p7.root"; //Weight3D.root";
155 algomez 1.2 fweightfile = new TFile(weightfilename,"read");
156     f3Dweight = (TH1D*) fweightfile->Get(fpuhistogram);
157    
158 algomez 1.1 //create histograms
159     h1test = new TH1F("h1test","muon p_{T}",100,10.,400);
160     //fHist = new HistoManager(string(fSample));
161     TString hname = "_"+fSample;
162    
163 algomez 1.6 hmuons["N_cut0"] = new TH1F("N_muons_cut0"+hname,"Number of Muons",6,-0.5,5.5);
164     hmuons["N"] = new TH1F("N_muons"+hname,"Number of Muons",6,-0.5,5.5);
165     hmuons["Nelectrons_cut0"] = new TH1F("Nelectrons_cut0"+hname,"Number of Loose Electrons",6,-0.5,5.5);
166     hmuons["Nelectrons"] = new TH1F("Nelectrons"+hname,"Number of Loose Electrons",6,-0.5,5.5);
167 algomez 1.1 hmuons["pt_1jet"] = new TH1F("muon_pt_1jet"+hname,"p_{T}^{#mu} [GeV/c]", 50, 0, 500);
168     hmuons["pt_2jet"] = new TH1F("muon_pt_2jet"+hname,"p_{T}^{#mu} [GeV/c]", 50, 0, 500);
169 algomez 1.2 hmuons["pt_fin"] = new TH1F("muon_pt_fin"+hname,"p_{T}^{#mu} [GeV/c]", 50, 0, 500);
170 algomez 1.1 hmuons["eta"] = new TH1F("muon_eta"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
171     hmuons["eta_1jet"] = new TH1F("muon_eta_1jet"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
172     hmuons["eta_2jet"] = new TH1F("muon_eta_2jet"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
173 algomez 1.2 hmuons["eta_fin"] = new TH1F("muon_eta_fin"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
174 algomez 1.1 hmuons["phi"] = new TH1F("muon_phi"+hname,"#phi^{#mu}", 30, -3.15, 3.15);
175     hmuons["phi_1jet"] = new TH1F("muon_phi_1jet"+hname,"#phi^{#mu}", 30, -3.15, 3.15);
176     hmuons["phi_2jet"] = new TH1F("muon_phi_2jet"+hname,"#phi^{#mu}", 30, -3.15, 3.15);
177 algomez 1.2 hmuons["phi_fin"] = new TH1F("muon_phi_fin"+hname,"#phi^{#mu}", 30, -3.15, 3.15);
178 algomez 1.1 hmuons["reliso"] = new TH1F("muon_reliso"+hname,"Relative Isolation", 40, 0, 0.2);
179 algomez 1.2 hmuons["reliso_fin"] = new TH1F("muon_reliso_fin"+hname,"Relative Isolation", 40, 0, 0.2);
180 algomez 1.1 hmuons["deltaR_cut0"] = new TH1F("deltaR_cut0"+hname,"#DeltaR(#mu,jet)",80, 0, 4);
181     hmuons["deltaR"] = new TH1F("deltaR"+hname,"#DeltaR(#mu,jet)", 80, 0, 4);
182     hmuons["d0_cut1"] = new TH1F("d0_cut1"+hname,"#mu Impact Parameter [cm]",20,-0.1,0.1);
183     hmuons["pt_cut1"] = new TH1F("muon_pt_cut1"+hname,"p_{T}^{#mu} [GeV/c]", 50, 0, 500);
184     hmuons["pt_cut2"] = new TH1F("muon_pt_cut2"+hname,"p_{T}^{#mu} [GeV/c]", 50, 0, 500);
185     hmuons["pt_cut3"] = new TH1F("muon_pt_cut3"+hname,"p_{T}^{#mu} [GeV/c]", 50, 0, 500);
186     hmuons["pt"] = new TH1F("muon_pt"+hname,"p_{T}^{#mu} [GeV/c]", 50, 0, 500);
187     hmuons["dz"] = new TH1F("dz"+hname,"|z(#mu) - z_{PV}| [cm]", 25, 0, 1.);
188 algomez 1.2 hmuons["Niso"] = new TH1F("Niso"+hname,"Number of Primary Vertices", 25,-0.5,24.5);
189     hmuons["Ngood"] = new TH1F("Ngood"+hname,"Number of Primary Vertices",25,-0.5,24.5);
190 algomez 1.1
191     hPVs["N"] = new TH1F("NPV"+hname,"Number of PVs",25,-0.5,24.5);
192     hPVs["Nreweight"] = new TH1F("NPVreweight"+hname,"Number of PVs",25,-0.5,24.5);
193     hPVs["Nreweight_2jet"] = new TH1F("NPVreweight_2jet"+hname,"Number of PVs",25,-0.5,24.5);
194    
195     helectrons["pt"] = new TH1F("electron_pt"+hname,"p_{T}^{#mu} [GeV/c]", 50, 20, 500);
196     helectrons["pt_cut2"] = new TH1F("electron_pt_cut2"+hname,"p_{T}^{#mu} [GeV/c]", 50, 20, 500);
197     helectrons["pt_1jet"] = new TH1F("electron_pt_1jet"+hname,"p_{T}^{#mu} [GeV/c]", 50, 20, 500);
198     helectrons["pt_2jet"] = new TH1F("electron_pt_2jet"+hname,"p_{T}^{#mu} [GeV/c]", 50, 20, 500);
199     helectrons["pt_3jet"] = new TH1F("electron_pt_3jet"+hname,"p_{T}^{#mu} [GeV/c]", 50, 20, 500);
200     helectrons["pt_4jet"] = new TH1F("electron_pt_4jet"+hname,"p_{T}^{#mu} [GeV/c]", 50, 20, 500);
201     helectrons["eta"] = new TH1F("electron_eta"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
202     helectrons["eta_cut2"] = new TH1F("electron_eta_cut2"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
203     helectrons["eta_1jet"] = new TH1F("electron_eta_1jet"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
204     helectrons["eta_2jet"] = new TH1F("electron_eta_2jet"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
205     helectrons["eta_3jet"] = new TH1F("electron_eta_3jet"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
206     helectrons["eta_4jet"] = new TH1F("electron_eta_4jet"+hname,"#eta^{#mu}", 20, -2.1, 2.1);
207     helectrons["phi"] = new TH1F("electron_phi"+hname,"#phi^{#mu}", 20, 0, 3.15);
208     helectrons["phi_cut2"] = new TH1F("electron_phi_cut2"+hname,"#phi^{#mu}", 20, 0, 3.15);
209     helectrons["phi_1jet"] = new TH1F("electron_phi_1jet"+hname,"#phi^{#mu}", 20, 0, 3.15);
210     helectrons["phi_2jet"] = new TH1F("electron_phi_2jet"+hname,"#phi^{#mu}", 20, 0, 3.15);
211     helectrons["phi_3jet"] = new TH1F("electron_phi_3jet"+hname,"#phi^{#mu}", 20, 0, 3.15);
212     helectrons["phi_4jet"] = new TH1F("electron_phi_4jet"+hname,"#phi^{#mu}", 20, 0, 3.15);
213     helectrons["reliso"] = new TH1F("electron_reliso"+hname,"Relative Isolation", 40, 0, 0.2);
214     helectrons["reliso_1jet"] = new TH1F("electron_reliso_1jet"+hname,"Relative Isolation", 40, 0, 0.2);
215     helectrons["reliso_2jet"] = new TH1F("electron_reliso_2jet"+hname,"Relative Isolation", 40, 0, 0.2);
216     helectrons["reliso_3jet"] = new TH1F("electron_reliso_3jet"+hname,"Relative Isolation", 40, 0, 0.2);
217     helectrons["reliso_4jet"] = new TH1F("electron_reliso_4jet"+hname,"Relative Isolation", 40, 0, 0.2);
218     helectrons["deltaR_cut0"] = new TH1F("electron_deltaR_cut0"+hname,"#DeltaR(#mu,jet)",80, 0, 4);
219     helectrons["deltaR"] = new TH1F("electron_deltaR"+hname,"#DeltaR(#mu,jet)",80, 0, 4);
220     helectrons["d0_cut1"] = new TH1F("electron_d0_cut1"+hname,"#mu Impact Parameter [cm]",20,-0.1,0.1);
221     helectrons["dz"] = new TH1F("electron_dz"+hname,"|z(#mu) - z_{PV}| [cm]", 25, 0, 1.);
222    
223 algomez 1.6 hMET["MET"] = new TH1F("MET"+hname,"Missing Transverse Energy [GeV]", 50, 0, 500);
224     hMET["MET_cut0"] = new TH1F("MET_cut0"+hname,"Missing Transverse Energy [GeV]", 50, 0, 300);
225 algomez 1.1 hMET["MET_2jet"] = new TH1F("MET_2jet"+hname,"Missing Transverse Energy [GeV]", 50, 0, 300);
226 algomez 1.2 hMET["MET_fin"] = new TH1F("MET_fin"+hname,"Missing Transverse Energy [GeV]", 50, 0, 300);
227 algomez 1.1 hMET["genMET_2jet"] = new TH1F("genMET_2jet"+hname,"Missing Transverse Energy [GeV]", 50, 0, 300);
228     hMET["deltaMET_2jet"] = new TH1F("deltaMET_2jet"+hname,"Missing Transverse Energy [GeV]", 50, -200, 200);
229     hMET["phi"] = new TH1F("MET_phi"+hname,"#phi Missing Transverse Energy [GeV]", 20, 0, 3.15);
230 algomez 1.6 hMET["Ht0"] = new TH1F("Ht0"+hname,"H_{T} [GeV]", 50, 0, 3000);
231     hMET["Ht"] = new TH1F("Ht"+hname,"H_{T} [GeV]", 50, 0, 3000);
232 algomez 1.1 hMET["Htlep"] = new TH1F("Htlep"+hname,"H_{T,lep} [GeV]", 50, 0, 1000);
233     hMET["PzNu"] = new TH1F("PzNu"+hname,"p_{z} #nu [GeV]", 40, -300,300);
234     hMET["EtaNu"] = new TH1F("EtaNu"+hname,"#eta",50,-2.2,2.2);
235     hMET["LepWmass"] = new TH1F("LepWmass"+hname,"W#rightarrow#mu#nu Mass [GeV/c^{2}]",20, 0, 150);
236     hMET["LepWmass_topcut"] = new TH1F("LepWmass_topcut"+hname,"W#rightarrow#mu#nu Mass [GeV/c^{2}]",20, 0, 150);
237     hMET["LepWmassNoPt"]=new TH1F("LepWmassNoPt"+hname,"W#rightarrow#mu#nu Mass [GeV/c^{2}]",20, 0, 150);
238     hMET["deltaPhi"] = new TH1F("deltaPhi"+hname,"#Delta #phi(#mu,MET)",50, -3.15, 3.15);
239    
240 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)
241 algomez 1.1 hM["WMt_2jet"] = new TH1F("Mt_2jet"+hname,"M_{T}(W) [GeV/c^{2}]", 50, 0, 300);
242 algomez 1.2 hM["WMt_fin"] = new TH1F("Mt_fin"+hname,"M_{T}(W) [GeV/c^{2}]", 50, 0, 300);
243 algomez 1.1 hM["dijet"] = new TH1F("dijet"+hname,"(jj) mass [GeV/c^{2}]", 50, 0, 1000);
244     hM["trijet"] = new TH1F("trijet"+hname,"(jjj) mass [GeV/c^{2}]", 50, 0, 1000);
245     hM["top_1btag"] = new TH1F("top_1btag"+hname,"top mass [GeV/c^{2}]",50,0,500);
246     hM["top_2btag"] = new TH1F("top_2btag"+hname,"top mass [GeV/c^{2}]",50,0,500);
247 algomez 1.6
248 algomez 1.1 hjets["pt"] = new TH1F("jet_pt"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
249 algomez 1.2 hjets["pt_b_mc"] = new TH1F("jet_pt_b_mc"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
250     hjets["pt_c_mc"] = new TH1F("jet_pt_c_mc"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
251     hjets["pt_l_mc"] = new TH1F("jet_pt_l_mc"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
252 algomez 1.1 hjets["pt_btag"] = new TH1F("jet_pt_btag"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
253     hjets["pt_btag_b"] = new TH1F("jet_pt_btag_b"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
254     hjets["pt_btag_c"] = new TH1F("jet_pt_btag_c"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
255     hjets["pt_btag_l"] = new TH1F("jet_pt_btag_l"+hname,"jet p_{T} [GeV/c]", 60, 30, 800);
256 algomez 1.6 hjets["1st_pt_cut0"] = new TH1F("jet1_pt_cut0"+hname,"Leading jet p_{T} [GeV/c]",60, 30, 1000);
257     hjets["1st_pt"] = new TH1F("jet1_pt"+hname,"Leading jet p_{T} [GeV/c]",60, 30, 1000);
258     hjets["2nd_pt_cut0"] = new TH1F("jet2_pt_cut0"+hname,"2nd jet p_{T} [GeV/c]",60, 30, 1000);
259     hjets["2nd_pt"] = new TH1F("jet2_pt"+hname,"2nd jet p_{T} [GeV/c]",60, 30, 1000);
260     hjets["3rd_pt_cut0"] = new TH1F("jet3_pt_cut0"+hname,"3rd jet p_{T} [GeV/c]",60, 30, 800);
261 algomez 1.1 hjets["3rd_pt"] = new TH1F("jet3_pt"+hname,"3rd jet p_{T} [GeV/c]",60, 30, 800);
262 algomez 1.6 hjets["4th_pt_cut0"] = new TH1F("jet4_pt_cut0"+hname,"4th jet p_{T} [GeV/c]",60, 30, 800);
263 algomez 1.1 hjets["4th_pt"] = new TH1F("jet4_pt"+hname,"4th jet p_{T} [GeV/c]",60, 30, 800);
264 algomez 1.6 hjets["5th_pt_cut0"] = new TH1F("jet5_pt_cut0"+hname,"5th jet p_{T} [GeV/c]",60, 30, 800);
265     hjets["5th_pt"] = new TH1F("jet5_pt"+hname,"5th jet p_{T} [GeV/c]",60, 30, 800);
266     hjets["6th_pt_cut0"] = new TH1F("jet6_pt_cut0"+hname,"6th jet p_{T} [GeV/c]",60, 30, 800);
267     hjets["6th_pt"] = new TH1F("jet6_pt"+hname,"6th jet p_{T} [GeV/c]",60, 30, 800);
268     hjets["7th_pt_cut0"] = new TH1F("jet7_pt_cut0"+hname,"7th jet p_{T} [GeV/c]",60, 30, 800);
269     hjets["7th_pt"] = new TH1F("jet7_pt"+hname,"7th jet p_{T} [GeV/c]",60, 30, 800);
270 algomez 1.2 hjets["1st_pt_fin"] = new TH1F("jet1_pt_fin"+hname,"Leading jet p_{T} [GeV/c]",60, 30, 800);
271     hjets["2nd_pt_fin"] = new TH1F("jet2_pt_fin"+hname,"2nd jet p_{T} [GeV/c]",60, 30, 800);
272 algomez 1.1 hjets["eta"] = new TH1F("jet_eta"+hname,"jet #eta",50, -2.4, 2.4);
273 algomez 1.6 hjets["1st_eta_cut0"] = new TH1F("jet1_eta_cut0"+hname,"Leading jet #eta",50, -2.4, 2.4);
274 algomez 1.1 hjets["1st_eta"] = new TH1F("jet1_eta"+hname,"Leading jet #eta",50, -2.4, 2.4);
275 algomez 1.6 hjets["2nd_eta_cut0"] = new TH1F("jet2_eta_cut0"+hname,"2nd jet #eta",50, -2.4, 2.4);
276 algomez 1.1 hjets["2nd_eta"] = new TH1F("jet2_eta"+hname,"2nd jet #eta",50, -2.4, 2.4);
277 algomez 1.2 hjets["1st_eta_fin"] = new TH1F("jet1_eta_fin"+hname,"Leading jet #eta",50, -2.4, 2.4);
278     hjets["2nd_eta_fin"] = new TH1F("jet2_eta_fin"+hname,"2nd jet #eta",50, -2.4, 2.4);
279 algomez 1.1 hjets["phi"] = new TH1F("jet_phi"+hname,"jet #phi",50, 0, 3.15);
280 algomez 1.3 hjets["Njets"] = new TH1F("Njets"+hname,"jet multiplicity",13,-0.5,12.5);
281 algomez 1.6 hjets["Njets_cut0"] = new TH1F("Njets_cut0"+hname,"jet multiplicity",13,-0.5,12.5);
282 algomez 1.4 hjets["Njets_cut1"] = new TH1F("Njets_cut1"+hname,"jet multiplicity",13,-0.5,12.5);
283 algomez 1.7 hjets["Njets_1tag"] = new TH1F("Njets_1tag"+hname,"jet multiplicity",13,-0.5,12.5);
284 algomez 1.1 hjets["Njets_2tag"] = new TH1F("Njets_2tag"+hname,"jet multiplicity",6,0.5,6.5);
285     hjets["Nbtags_TCHPM"] = new TH1F("Nbjets_TCHPM_N2j"+hname,"Tagged b-jets",3,-0.5,2.5);
286 algomez 1.7 hjets["Nbtags_CSVM"] = new TH1F("Nbjets_CSVM_N2j"+hname,"Tagged b-jets",4,-0.5,3.5);
287 algomez 1.1 hjets["Dijet_deltaPhi"] = new TH1F("Dijet_deltaPhi"+hname,"#Delta #phi(j,j)",30,-3.15,3.15);
288 algomez 1.6 hjets["Dijet_deltaR_cut0"] = new TH1F("Dijet_deltaR_cut0"+hname,"#DeltaR(j,j)",80,0.,4.);
289     hjets["Dijet_deltaR"] = new TH1F("Dijet_deltaR"+hname,"#DeltaR(j,j)",80,0.,4.);
290 algomez 1.1 hjets["tb_deltaPhi"] = new TH1F("tb_deltaPhi"+hname,"#Delta #phi(t,b)",30,0.,3.15);
291 algomez 1.2 hjets["tb_deltaEta"] = new TH1F("tb_deltaEta"+hname,"#Delta #eta(t,b)",30,-5,5);
292     hjets["pt_top"] = new TH1F("pt_top"+hname,"top p_{T} [GeV]",60,0,1500);
293     hjets["pt_b"] = new TH1F("pt_b"+hname,"b-jet p_{T} [GeV]",60,0,1500);
294     hjets["gen_deltaR_mub"] = new TH1F("gen_deltaR_mub"+hname,"#Delta R(#mu,b)",40,0,4);
295 algomez 1.1
296     map<string,TH1* > allhistos = hmuons;
297     allhistos.insert( helectrons.begin(), helectrons.end() );
298     allhistos.insert( hMET.begin(), hMET.end() );
299     allhistos.insert( hM.begin(), hM.end() );
300     allhistos.insert( hjets.begin(), hjets.end() );
301    
302     for ( map<string,TH1* >::const_iterator imap=allhistos.begin(); imap!=allhistos.end(); ++imap )
303     {
304     TH1 *temp = imap->second;
305     temp->Sumw2();
306     temp->SetXTitle( temp->GetTitle() );
307     }
308    
309     // cut flow
310     if (fChannel==1)
311     { //muon +jets
312     fCutLabels.push_back("Processed");
313     fCutLabels.push_back("OneIsoMu");
314     fCutLabels.push_back("LooseMuVeto");
315     fCutLabels.push_back("ElectronVeto");
316     fCutLabels.push_back("MET");
317     fCutLabels.push_back("1Jet");
318     fCutLabels.push_back("2Jet");
319     fCutLabels.push_back("3Jet");
320     fCutLabels.push_back("4Jet");
321     fCutLabels.push_back("2Jet1b");
322     fCutLabels.push_back("2Jet2b");
323     fCutLabels.push_back("MaxJets");
324     fCutLabels.push_back("phi");
325     fCutLabels.push_back("topmass");
326     }
327     else
328     { //electron+jets
329     fCutLabels.push_back("Processed");
330     fCutLabels.push_back("OneIsoElectron");
331     fCutLabels.push_back("LooseMuVeto");
332     fCutLabels.push_back("ZVeto");
333     fCutLabels.push_back("ConversionVeto");
334     fCutLabels.push_back("MET");
335     fCutLabels.push_back("1Jet");
336     fCutLabels.push_back("2Jet");
337     fCutLabels.push_back("3Jet");
338     fCutLabels.push_back("4Jet");
339     fCutLabels.push_back("2Jet1b");
340     fCutLabels.push_back("2Jet2b");
341     }
342     hcutflow = new TH1D("cutflow","cut flow", fCutLabels.size(), 0.5, fCutLabels.size() +0.5 );
343    
344     for ( vector<string>::const_iterator ivec= fCutLabels.begin(); ivec!=fCutLabels.end(); ++ivec)
345     {
346     cutmap[ *ivec ] = 0;
347     }
348    
349     double pu_weights[35] = {
350     0.0255506,
351     0.251923,
352     0.549605,
353     0.924918,
354     1.25977,
355     1.48142,
356     1.57923,
357     1.57799,
358     1.52152,
359     1.4414,
360     1.35889,
361     1.2841,
362     1.21927,
363     1.16125,
364     1.11244,
365     1.06446,
366     1.01666,
367     0.966989,
368     0.913378,
369     0.85774,
370     0.799258,
371     0.734225,
372     0.670242,
373     0.607641,
374     0.54542,
375     0.484084,
376     0.427491,
377     0.369787,
378     0.321454,
379     0.280706,
380     0.238499,
381     0.198961,
382     0.166742,
383     0.146428,
384     0.224425
385     };
386    
387     fpu_weights_vec.assign( pu_weights, pu_weights + 35 );
388    
389     // For JEC uncertainties
390 algomez 1.2 if (fdoJECunc) fJECunc = new JetCorrectionUncertainty("/uscms/home/algomez/work/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/GR_R_42_V19_AK5PF_Uncertainty.txt");
391 algomez 1.1
392     }
393    
394     Bool_t Analyzer::Process(Long64_t entry)
395     {
396     // The Process() function is called for each entry in the tree (or possibly
397     // keyed object in the case of PROOF) to be processed. The entry argument
398     // specifies which entry in the currently loaded tree is to be processed.
399     // It can be passed to either Analyzer::GetEntry() or TBranch::GetEntry()
400     // to read either all or the required parts of the data. When processing
401     // keyed objects with PROOF, the object is already loaded and is available
402     // via the fObject pointer.
403     //
404     // This function should contain the "body" of the analysis. It can contain
405     // simple or elaborate selection criteria, run algorithms on the data
406     // of the event and typically fill histograms.
407     //
408     // The processing can be stopped by calling Abort().
409     //
410     // Use fStatus to set the return value of TTree::Process().
411     //
412     // The return value is currently not used.
413    
414     //TString option = GetOption();
415    
416     //if ( entry % 100 == 0 )
417     //cout<< "process entry " << entry << endl;
418    
419     //TString sEntry = Form("%f", float(entry) );
420     // Info("Process",
421     //"entry # %s", Form("%f", float(entry) ) );
422    
423     //fChain->GetTree()->GetEntry(entry);
424     fChain->GetEntry(entry);
425    
426     //if (entry>10) return kTRUE;
427    
428     // event info
429     //cout << "run: " << ntuple->run << " lumi: " << ntuple->lumi << endl;
430    
431     // get collections
432     vector< TopVertexEvent > primaryVertices = ntuple->vertices;
433     vector< TopMuonEvent > muons = ntuple->muons;
434 algomez 1.2 vector< TopElectronEvent > electrons = ntuple->PFelectrons; // use PF electrons (gsf collection is called "electrons")
435 algomez 1.1 vector< TopJetEvent > jets = ntuple->PFjets;
436    
437 algomez 1.2 // USE PF Isolation
438     fMuSelector.UsePFIsolation(true);
439     fEleSelector.UsePFIsolation(true);
440    
441 algomez 1.1 size_t total_pvs = primaryVertices.size();
442     size_t total_muons = muons.size();
443     size_t total_electrons = electrons.size();
444     size_t total_jets = jets.size();
445    
446     float PVz = 0.;
447     TLorentzVector p4muon, p4ele, p4lepton, p4MET;
448     TLorentzVector p4Nu, p4OtherNu;
449     TLorentzVector p4QCDmuon;
450    
451     vector< TLorentzVector > p4jets;
452 algomez 1.6 vector< TLorentzVector > p4Othermuon; // leading muon
453 algomez 1.1
454 algomez 1.2 ////////////////////
455     // GENERATOR
456     ///////////////////
457 algomez 1.6 if (fIsMC && fSample.Contains("4Top") )
458 algomez 1.2 {
459     TLorentzVector p4genLepton;
460     TLorentzVector p4genNu;
461     TLorentzVector p4genb;
462     if (ntuple->gen.bLep_pt>0)
463     {
464     p4genLepton.SetPtEtaPhiE(ntuple->gen.mu_pt,ntuple->gen.mu_eta,ntuple->gen.mu_phi,ntuple->gen.mu_e);
465     p4genNu.SetPtEtaPhiE(ntuple->gen.nu_pt,ntuple->gen.nu_eta,ntuple->gen.nu_phi,ntuple->gen.nu_e);
466     p4genb.SetPtEtaPhiE(ntuple->gen.bLep_pt,ntuple->gen.bLep_eta,ntuple->gen.bLep_phi,ntuple->gen.bLep_e);
467    
468     hjets["gen_deltaR_mub"]->Fill( p4genLepton.DeltaR( p4genb ) );
469     }
470     }
471 algomez 1.1 ////////////////////////////////////
472     // PRIMARY VERTICES
473     ///////////////////////////////////
474    
475 algomez 1.6 for ( size_t ipv=0; ipv < total_pvs; ++ipv)
476     {
477     if (ipv==0) PVz = primaryVertices[ipv].vz;
478     }
479 algomez 1.1
480 algomez 1.6 //hPVs["N"]->Fill( total_pvs );
481 algomez 1.1
482     // calculate PU weight
483     double PUweight = 1.;
484    
485     if (fIsMC) {
486 algomez 1.2
487     Int_t mc_npvminus1 = TMath::Min(ntuple->gen.Bx_minus1,34);
488     Int_t mc_npv0 = TMath::Min(ntuple->gen.Bx_0,34);
489     Int_t mc_npvplus1 = TMath::Min(ntuple->gen.Bx_plus1,34);
490    
491     PUweight = f3Dweight->GetBinContent(mc_npvminus1,mc_npv0,mc_npvplus1);
492    
493     //int iibin = 0;
494     //for ( vector<double>::iterator ivec = fpu_weights_vec.begin(); ivec != fpu_weights_vec.end(); ++ivec )
495     // {
496     // int mc_npvs = ntuple->gen.Bx_0; // in-time pile up
497     ////int mc_npvs = (int)total_pvs;
498     //if ( mc_npvs >= iibin+1 ) PUweight = *ivec; // use the last weight for last bin
499     //if ( ( iibin <= mc_npvs ) && ( mc_npvs < iibin + 1 ) ) PUweight = *ivec;
500     //iibin++;
501     //}
502 algomez 1.1 }
503    
504 algomez 1.5 // For 4 tops
505     if (fIsMC && fSample.Contains("4Top") ) {
506     PUweight = 1;
507     }
508    
509 algomez 1.1 hPVs["Nreweight"]->Fill( total_pvs, PUweight );
510    
511 algomez 1.2 /////////////
512     // HLT scale factor for MC
513     ////////////
514     double SF_hlt = 1.;
515     if (fIsMC) SF_hlt = 0.966;
516    
517 algomez 1.6 PUweight = PUweight*SF_hlt; // LETS INCLUDE THE TRIGGER SF INTO THE PU WEIGHTS
518 algomez 1.2
519 algomez 1.1 cutmap["Processed"] += PUweight;
520    
521     if (fVerbose) cout << "done pv" << endl;
522 algomez 1.6
523 algomez 1.1 //////////////////////////////////
524     // MUONS
525     //////////////////////////////////
526 algomez 1.2 int ngoodIDmuons = 0;
527 algomez 1.1 int nloosemuons = 0;
528     int ntightmuons = 0;
529     int nqcdmuons = 0;
530    
531     double RelIso = -1.;
532     double deltaR = -1.;
533     double QCDRelIso = -1.;
534     double QCDdeltaR = -1;
535    
536 algomez 1.2
537 algomez 1.1 for ( size_t imu=0; imu < total_muons; ++imu) {
538    
539 algomez 1.6 TopMuonEvent muon = muons[imu];
540 algomez 1.2
541 algomez 1.6 h1test->Fill( muon.pt );
542     //hmuons["N_muons"]->Fill( total_muons );
543     hmuons["pt_cut1"]->Fill( muon.pt, PUweight );
544    
545     if ( fMuSelector.MuonID( muon, PVz ) ) ngoodIDmuons++;
546    
547     // select only good muons
548     if ( fMuSelector.MuonLoose( muon ) ) {
549     nloosemuons++;
550    
551     if ( fMuSelector.MuonTight( muon, PVz) ) {
552     //hmuons["N_tisomuons"]->Fill( nloosemuons );
553     //hmuons["charge_tiso"]->Fill( muon.charge, PUweight );
554     hmuons["pt_cut2"]->Fill( muon.pt, PUweight );
555     }
556    
557     if ( fMuSelector.MuonTightDeltaR( muon, PVz, jets) ) {
558     ntightmuons++;
559     deltaR = fMuSelector.GetDeltaR();
560     }
561 algomez 1.1
562 algomez 1.6 p4muon.SetPtEtaPhiE( muon.pt, muon.eta, muon.phi, muon.e );
563     RelIso = muon.pfreliso; //muon.reliso03;
564 algomez 1.1
565 algomez 1.6 p4Othermuon.push_back( p4muon ); // for leading muon
566 algomez 1.1 }
567 algomez 1.4
568 algomez 1.6 // check muon in QCD control region
569     if ( fMuSelector.MuonRelax02IsoQCD( muon, PVz, jets ) ) {
570     nqcdmuons++;
571     // keep the leading muon for selection
572     if (nqcdmuons==1) {
573     p4QCDmuon.SetPtEtaPhiE( muon.pt, muon.eta, muon.phi, muon.e );
574     QCDRelIso = muon.pfreliso; //muon.reliso03;
575     QCDdeltaR = fMuSelector.GetDeltaR();
576     }
577 algomez 1.1 }
578 algomez 1.6 }
579 algomez 1.1
580 algomez 1.6 if (fVerbose) cout << "done muons" << endl;
581 algomez 1.1
582     //////////////////////////////////
583     // ELECTRONS
584     //////////////////////////////////
585     int nlooseelectrons = 0;
586     int ntightelectrons = 0;
587     bool IsConversion = false;
588    
589     for ( size_t iele=0; iele < total_electrons; ++iele) {
590    
591 algomez 1.6 TopElectronEvent electron = electrons[iele];
592 algomez 1.1
593 algomez 1.6 if ( fEleSelector.ElectronLoose(electron) ) nlooseelectrons++;
594 algomez 1.1
595 algomez 1.6 if ( fEleSelector.ElectronTight(electron, PVz ) ) {
596 algomez 1.1
597 algomez 1.6 if (ntightelectrons == 0) {
598     IsConversion = electron.IsConversion;
599     p4ele.SetPtEtaPhiE( electron.pt, electron.eta, electron.phi, electron.e );
600     helectrons["pt_cut2"]->Fill( p4ele.Pt(), PUweight );
601     helectrons["eta_cut2"]->Fill( p4ele.Eta(), PUweight );
602     helectrons["phi_cut2"]->Fill( p4ele.Phi(), PUweight );
603     }
604     ntightelectrons++;
605     }
606 algomez 1.1 }
607     if (fVerbose) cout << "done electron" << endl;
608    
609 algomez 1.6 /////////////////////////////////////
610     // MUON/ELECTRON + JETS
611     /////////////////////////////////////
612 algomez 1.1
613 algomez 1.6 if ( fChannel == 1 ) {
614 algomez 1.1
615 algomez 1.6 if (fdoQCD2SideBand) {
616 algomez 1.1
617 algomez 1.6 if (nqcdmuons == 0) return kTRUE;
618     cutmap["OneIsoMu"] += PUweight;
619 algomez 1.1
620 algomez 1.6 p4lepton = p4QCDmuon;
621     RelIso = QCDRelIso;
622     deltaR = QCDdeltaR;
623     }
624     else {
625 algomez 1.2
626 algomez 1.6 if ( ngoodIDmuons > 0 ) hmuons["Ngood"]->Fill( total_pvs, PUweight);
627     if ( ntightmuons > 0 ) hmuons["Niso"]->Fill( total_pvs, PUweight);
628     if ( ntightmuons != 1 ) return kTRUE;
629     cutmap["OneIsoMu"] += PUweight;
630 algomez 1.2
631 algomez 1.6 if ( nloosemuons > 1 ) return kTRUE;
632     cutmap["LooseMuVeto"] += PUweight;
633 algomez 1.1
634 algomez 1.6 if ( nlooseelectrons > 0 ) return kTRUE;
635     cutmap["ElectronVeto"] += PUweight;
636 algomez 1.1
637 algomez 1.6 p4lepton = p4muon;
638     if (fVerbose) cout << "got a good lepton" << endl;
639     }
640    
641     hmuons["pt"]->Fill( p4lepton.Pt(), PUweight );
642     hmuons["eta"]->Fill( p4lepton.Eta(), PUweight );
643     hmuons["phi"]->Fill( p4lepton.Phi(), PUweight );
644     hmuons["reliso"]->Fill( RelIso, PUweight );
645     //hmuons["deltaR"]->Fill( deltaR, PUweight );
646 algomez 1.1
647 algomez 1.6 }
648 algomez 1.1 else // electron+jets
649     {
650     // pending ...
651     }
652    
653     if (fVerbose) cout << "done lepton selection " << endl;
654    
655     /////////////////////////////////
656 algomez 1.6 // MET + Ht
657 algomez 1.1 /////////////////////////////////
658    
659     p4MET.SetPtEtaPhiE( ntuple->PFMET,
660     0.,
661     ntuple->PFMETphi,
662     ntuple->PFMET );
663    
664     //temporal check using genMET
665     //p4MET.SetPtEtaPhiE( ntuple->gen.MET,
666     // 0.,
667     // ntuple->gen.METPhi,
668     // ntuple->gen.MET );
669    
670     if (fdoQCD1SideBand && p4MET.Et() > 20.) return kTRUE;
671     else if ( p4MET.Et() <= 20. && fdoQCD2SideBand==false ) return kTRUE;
672 algomez 1.6 if (fVerbose) cout << "pass MET cut" << endl;
673 algomez 1.1
674    
675     //cutmap["MET"] += PUweight;
676 algomez 1.6 //hMET["MET"]->Fill( p4MET.Pt(), PUweight );
677     //hMET["phi"]->Fill( p4MET.Phi(), PUweight );
678     //hMET["Ht0"]->Fill( ntuple->PFHt, PUweight );
679     //hMET["Htlep"]->Fill( ntuple->PFHt + p4lepton.Pt(), PUweight );
680    
681 algomez 1.1
682     double Wpt = p4lepton.Pt() + p4MET.Pt();
683     double Wpx = p4lepton.Px() + p4MET.Px();
684     double Wpy = p4lepton.Py() + p4MET.Py();
685     double WMt = sqrt(Wpt*Wpt-Wpx*Wpx-Wpy*Wpy);
686 algomez 1.3
687     //if ( WMt <= 40. ) return kTRUE;
688 algomez 1.1 cutmap["MET"] += PUweight;
689    
690     if (fVerbose) cout << "pass W MT cut " << endl;
691    
692     /////////////////////////////////
693     // estimate Pz of neutrino
694     ////////////////////////////////
695    
696     fzCalculator.SetMET(p4MET);
697     fzCalculator.SetLepton(p4lepton);
698 algomez 1.6 if (fChannel==2) {
699     fzCalculator.SetLeptonType("electron");
700     }
701 algomez 1.1
702     double pzNu = fzCalculator.Calculate();
703     p4Nu = TLorentzVector();
704     p4OtherNu = TLorentzVector();
705    
706     p4Nu.SetPxPyPzE(p4MET.Px(), p4MET.Py(), pzNu, sqrt(p4MET.Px()*p4MET.Px()+p4MET.Py()*p4MET.Py()+pzNu*pzNu));
707     //print "pzNu = " +str(pzNu)
708     //print "p4Nu =("+str(p4Nu.Px())+","+str(p4Nu.Py())+","+str(p4Nu.Pz())+","+str(p4Nu.E())
709     double pzOtherNu = fzCalculator.getOther();
710     p4OtherNu.SetPxPyPzE( p4MET.Px(), p4MET.Py(),pzOtherNu,sqrt(p4MET.Px()*p4MET.Px()+p4MET.Py()*p4MET.Py()+pzOtherNu*pzOtherNu));
711    
712 algomez 1.6 //double WmassNoPt = (p4Nu+p4lepton).M();
713 algomez 1.1
714 algomez 1.6 if ( fzCalculator.IsComplex() ) {
715     double ptNu1 = fzCalculator.getPtneutrino(1);
716     double ptNu2 = fzCalculator.getPtneutrino(2);
717     TLorentzVector p4Nu1tmp;
718     TLorentzVector p4Nu2tmp;
719 algomez 1.1
720 algomez 1.6 p4Nu1tmp.SetPxPyPzE( ptNu1*p4MET.Px()/p4MET.Pt(), ptNu1*p4MET.Py()/p4MET.Pt(), pzNu, sqrt(ptNu1*ptNu1+pzNu*pzNu));
721     p4Nu2tmp.SetPxPyPzE( ptNu2*p4MET.Px()/p4MET.Pt(), ptNu2*p4MET.Py()/p4MET.Pt(), pzNu, sqrt(ptNu2*ptNu2+pzNu*pzNu));
722 algomez 1.1
723 algomez 1.6 TLorentzVector Wtmp;
724     Wtmp = p4lepton + p4Nu1tmp;
725     double Wm1 = 0;
726     double Wm2 = 0;
727     Wm1 = Wtmp.M();
728     Wtmp = p4lepton + p4Nu2tmp;
729     Wm2 = Wtmp.M();
730     if ( fabs( Wm1 - 80.) < fabs( Wm2 - 80.) ) p4Nu = p4Nu1tmp;
731     else p4Nu = p4Nu2tmp;
732 algomez 1.1
733 algomez 1.6 p4OtherNu = p4Nu; // since we chose the real part, the two solutions are the same.
734     }
735 algomez 1.1
736    
737     hMET["PzNu"]->Fill(pzNu, PUweight ); //change this to 2d with two sol and as a function of jets
738    
739     TLorentzVector p4LepW = p4lepton + p4Nu;
740     TLorentzVector p4OtherLepW = p4lepton + p4OtherNu;
741    
742     //hMET["LepWmass"]->Fill(p4LepW.M(), PUweight );
743     //if ( fzCalculator.IsComplex() ) hMET["LepWmassComplex"]->Fill( p4LepW.M(), PUweight );
744    
745    
746     /////////////////////////////////
747     // JETS
748     ////////////////////////////////
749    
750 algomez 1.6 //JetCombinatorics myCombi = JetCombinatoric();
751 algomez 1.1
752     int njets = 0;
753     map< string, vector<float> > bdisc;
754     map< string, vector<bool> > isTagb;
755     vector<int> listflavor;
756    
757 algomez 1.6 for ( size_t ijet=0; ijet < total_jets; ++ijet) {
758 algomez 1.1
759 algomez 1.6 TopJetEvent jet = jets[ijet];
760     double SF_JEC = 1.;
761     if (fdoJECunc){
762     fJECunc->setJetEta( jet.eta);
763     fJECunc->setJetPt( jet.pt);
764     double jec_unc = fJECunc->getUncertainty(true);
765     if (fVerbose) cout << "JEC uncertainty is " << jec_unc << endl;
766     if (fdoJECup) SF_JEC = 1.+jec_unc;
767     else SF_JEC = 1.-jec_unc;
768 algomez 1.1 }
769    
770    
771 algomez 1.7 //if ( SF_JEC*jet.pt > 35. && fabs(jet.eta) < 2.4 && SF_JEC*jets[0].pt > 120. ) {
772     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
773 algomez 1.6
774     if (fVerbose) cout << " jet pt " << SF_JEC*jet.pt << endl;
775    
776     //hjets["pt"]->Fill( jet.pt, PUweight );
777     //hjets["eta"]->Fill( jet.eta, PUweight );
778     //hjets["phi"]->Fill( jet.phi, PUweight );
779    
780     TLorentzVector tmpjet;
781     tmpjet.SetPtEtaPhiE(SF_JEC*jet.pt, jet.eta, jet.phi, SF_JEC*jet.e);
782     p4jets.push_back( tmpjet);
783     listflavor.push_back( jet.mc.flavor );
784    
785     if (fVerbose) {
786     cout << "done storing njets " << njets << endl;
787     cout << " bdisc " << jet.btag_TCHP << endl;
788     cout << " bdisc " << jet.btag_CSV << endl;
789     }
790    
791 algomez 1.7 // store discriminators
792 algomez 1.6 bdisc["TCHP"].push_back( jet.btag_TCHP );
793     bdisc["CSV"].push_back( jet.btag_CSV );
794     if (fVerbose) cout << "store bdisc" << endl;
795     // TCHPL cut at 1.19
796     // check TCHPM cut at 1.93
797 algomez 1.7 //if ( jet.btag_TCHP > 1.93 ) isTagb["TCHPM"].push_back(true);
798     //else isTagb["TCHPM"].push_back(false);
799     //if (fVerbose) cout << "done tchpl" << endl;
800 algomez 1.6 // check SSVHEM cut at 1.74
801     if ( jet.btag_CSV > 0.679) isTagb["CSVM"].push_back(true);
802     else isTagb["CSVM"].push_back(false);
803     if (fVerbose) cout << "done csvm" << endl;
804 algomez 1.7 // CSVM cut at 0.679 MEDIUM
805    
806 algomez 1.6 njets++;
807     }
808     }
809 algomez 1.1
810 algomez 1.6 if (njets>0) {
811     hM["WMt"]->Fill( WMt, PUweight );
812     hjets["Njets"]->Fill( njets, PUweight );
813     }
814 algomez 1.1
815     if (fVerbose) cout << "done jets" << endl;
816    
817     if (njets > 0 ) cutmap["1Jet"] += PUweight;
818     if (njets > 1 ) cutmap["2Jet"] += PUweight;
819     if (njets > 2 ) cutmap["3Jet"] += PUweight;
820     if (njets > 3 ) cutmap["4Jet"] += PUweight;
821    
822 algomez 1.6 if (njets >= 2) {
823 algomez 1.1
824 algomez 1.7 // count partons
825     int number_of_b = 0;
826     int number_of_c = 0;
827     int number_of_l = 0;
828     int number_of_b_highpt = 0;
829     int number_of_c_highpt = 0;
830     float SFb_0tag = 1.;
831     float SFb_only1tag = 1.;
832     float SFb_1tag = 1.;
833     float SFb_2tag = 1.;
834     //float SFb_0tag_syst[2] = {1.}; // for systematics
835     float SFb_1tag_syst[2] = {1.};
836     float SFb_2tag_syst[2] = {1.};
837     //float SFb_1tag_systhighpt[2] = {1.};
838    
839 algomez 1.6 double Ht = 0;
840     double deltaRjj = 999.;
841 algomez 1.7
842 algomez 1.6 for ( size_t kk=0; kk < p4jets.size(); ++kk) {
843 algomez 1.7 // Ht calculation
844 algomez 1.6 Ht += p4jets[kk].Pt();
845    
846 algomez 1.7 // deltaR(jet,jet)
847 algomez 1.6 for ( vector< TopJetEvent>::iterator ijet=jets.begin(); ijet != jets.end(); ++ijet) {
848    
849     TopJetEvent jet = *ijet;
850     TLorentzVector tmpp4Jet;
851     tmpp4Jet.SetPtEtaPhiE(jet.pt, jet.eta, jet.phi, jet.e );
852     double tmpdeltaR = p4jets[kk].DeltaR(tmpp4Jet);
853     if ( tmpdeltaR < 0.3 ) continue;
854     if ( tmpdeltaR < deltaRjj ) deltaRjj = tmpdeltaR;
855     }
856 algomez 1.7
857     // b-tag
858     if ( abs(listflavor[kk])==5 && p4jets[kk].Pt()<=240 ) { number_of_b++; hjets["pt_b_mc"]->Fill( p4jets[kk].Pt(), PUweight );}
859     if ( abs(listflavor[kk])==4 && p4jets[kk].Pt()<=240 ) { number_of_c++; hjets["pt_c_mc"]->Fill( p4jets[kk].Pt(), PUweight );}
860     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 );}
861     if ( abs(listflavor[kk])==5 && p4jets[kk].Pt()>240 ) { number_of_b_highpt++; hjets["pt_b_mc"]->Fill( p4jets[kk].Pt(), PUweight );}
862     if ( abs(listflavor[kk])==4 && p4jets[kk].Pt()>240 ) { number_of_c_highpt++; hjets["pt_c_mc"]->Fill( p4jets[kk].Pt(), PUweight );}
863 algomez 1.1 }
864    
865 algomez 1.7 /////////// plots without cuts
866 algomez 1.6 hMET["Ht0"]->Fill( ntuple->PFHt, PUweight );
867     hjets["Njets_cut0"]->Fill( njets, PUweight );
868     hjets["1st_pt_cut0"]->Fill( p4jets[0].Pt(), PUweight );
869     hjets["1st_eta_cut0"]->Fill( p4jets[0].Eta(), PUweight );
870     hjets["2nd_pt_cut0"]->Fill( p4jets[1].Pt(), PUweight );
871     hjets["2nd_eta_cut0"]->Fill( p4jets[1].Eta(), PUweight );
872     hjets["3rd_pt_cut0"]->Fill( p4jets[2].Pt(), PUweight );
873     hjets["4th_pt_cut0"]->Fill( p4jets[3].Pt(), PUweight );
874     hjets["5th_pt_cut0"]->Fill( p4jets[4].Pt(), PUweight );
875     hjets["6th_pt_cut0"]->Fill( p4jets[5].Pt(), PUweight );
876     hjets["7th_pt_cut0"]->Fill( p4jets[6].Pt(), PUweight );
877     hmuons["N_cut0"]->Fill( total_muons, PUweight );
878     hmuons["Nelectrons_cut0"]->Fill( nlooseelectrons, PUweight );
879     hMET["MET_cut0"]->Fill( p4MET.Pt(), PUweight );
880     hmuons["deltaR_cut0"]->Fill( deltaR, PUweight );
881     hjets["Dijet_deltaR_cut0"]->Fill( deltaRjj, PUweight );
882 algomez 1.7 /////////////////////////////////////////////////////////////////////
883    
884     // count number of b-tags
885     //int Nbtags_TCHPM = 0;
886     int Nbtags_CSVM = 0;
887     //for ( size_t itag=0; itag< isTagb["TCHPM"].size(); ++itag ) {
888     for ( size_t itag=0; itag< isTagb["CSVM"].size(); ++itag ) {
889     //if ( isTagb["TCHPM"][itag] ) Nbtags_TCHPM++;
890     if ( isTagb["CSVM"][itag] ) Nbtags_CSVM++;
891     }
892    
893     // compute b-tag event weight
894     if ( fIsMC ) {
895    
896     // zeto tag
897     BTagWeight b0(0,0); // number of tags
898     //BTagWeight::JetInfo bj(0.63,0.91); // mean MC eff and mean SF. For TCHPM=0.91\pm0.09, CSVM=0.96\pm0.096
899     //BTagWeight::JetInfo cj(0.15,0.91);
900     BTagWeight::JetInfo bj(0.63,0.96);
901     BTagWeight::JetInfo cj(0.15,0.96);
902     double light_mceff = 0.017; //CHECK
903     if ( 100 < p4jets[0].Pt() && p4jets[0].Pt() <= 200 ) light_mceff = 0.04;
904     if ( 200 < p4jets[0].Pt() && p4jets[0].Pt() <= 300 ) light_mceff = 0.08;
905     if ( 300 < p4jets[0].Pt() && p4jets[0].Pt() <= 400 ) light_mceff = 0.12;
906     if ( 400 < p4jets[0].Pt() ) light_mceff = 0.14;
907    
908     //BTagWeight::JetInfo lj(light_mceff,1.22); //for TCHPM=1.22, CSVM=1.08 \pm 0.13
909     BTagWeight::JetInfo lj(light_mceff,1.08);
910    
911     // b-tag systematic UP 9% for b, 18% for c
912     // for CSVM 5% for b, and 10% for c
913     //BTagWeight::JetInfo bjUP(0.63,0.99);
914     //BTagWeight::JetInfo cjUP(0.15,1.07);
915     BTagWeight::JetInfo bjUP(0.63,1.008);
916     BTagWeight::JetInfo cjUP(0.15,1.056);
917    
918     // b-tag systemacit DOWN 9% for b, 18% for c
919     //BTagWeight::JetInfo bjDOWN(0.63,0.83);
920     //BTagWeight::JetInfo cjDOWN(0.15,0.75);
921     BTagWeight::JetInfo bjDOWN(0.63,0.912);
922     BTagWeight::JetInfo cjDOWN(0.15,0.864);
923    
924     // for high pt jets > 240 UP 50% for b and c
925     // for CSVM
926     //BTagWeight::JetInfo bjUPhighpt(0.63,1.36);
927     //BTagWeight::JetInfo cjUPhighpt(0.15,1.36);
928     BTagWeight::JetInfo bjUPhighpt(0.63,1.104);
929     BTagWeight::JetInfo cjUPhighpt(0.15,1.104);
930     // for high pt jets > 240 DOWN 50% for b and c
931     //BTagWeight::JetInfo bjDOWNhighpt(0.63,0.46);
932     //BTagWeight::JetInfo cjDOWNhighpt(0.15,0.46);
933     BTagWeight::JetInfo bjDOWNhighpt(0.63,0.816);
934     BTagWeight::JetInfo cjDOWNhighpt(0.15,0.816);
935    
936     vector<BTagWeight::JetInfo> j;
937     for(int i=0;i<number_of_b;i++)j.push_back(bj);
938     for(int i=0;i<number_of_b_highpt;i++)j.push_back(bj);
939     for(int i=0;i<number_of_c;i++)j.push_back(cj);
940     for(int i=0;i<number_of_c_highpt;i++)j.push_back(cj);
941     for(int i=0;i<number_of_l;i++)j.push_back(lj);
942    
943     // changed to CSVM from TCHPM
944     if (Nbtags_CSVM==0) {
945     SFb_0tag = b0.weight(j,0);
946     hjets["Nbtags_CSVM"]->Fill( Nbtags_CSVM, PUweight*SFb_0tag ); // fill bin 0
947     }
948    
949     // only one tag
950     BTagWeight b11(1,1); // number of tags
951     if (Nbtags_CSVM==1) {
952     SFb_only1tag = b11.weight(j,1);
953     hjets["Nbtags_CSVM"]->Fill( Nbtags_CSVM, PUweight*SFb_only1tag ); // fill bin 1
954     }
955    
956     // at least one tag
957     BTagWeight b1(1,Nbtags_CSVM); // number of tags
958     if (Nbtags_CSVM>=1) {
959     SFb_1tag = b1.weight(j,1);
960    
961     // UP
962     vector<BTagWeight::JetInfo> jj;
963     for(int i=0;i<number_of_b;i++)jj.push_back(bjUP);
964     for(int i=0;i<number_of_b_highpt;i++)jj.push_back(bjUPhighpt);
965     for(int i=0;i<number_of_c;i++)jj.push_back(cjUP);
966     for(int i=0;i<number_of_c_highpt;i++)jj.push_back(cjUPhighpt);
967     for(int i=0;i<number_of_l;i++)jj.push_back(lj);
968     SFb_1tag_syst[0] = b1.weight(jj,1);
969    
970     // DOWN
971     vector<BTagWeight::JetInfo> jk;
972     for(int i=0;i<number_of_b;i++)jk.push_back(bjDOWN);
973     for(int i=0;i<number_of_b_highpt;i++)jk.push_back(bjDOWNhighpt);
974     for(int i=0;i<number_of_c;i++)jk.push_back(cjDOWN);
975     for(int i=0;i<number_of_c_highpt;i++)jk.push_back(cjDOWNhighpt);
976     for(int i=0;i<number_of_l;i++)jk.push_back(lj);
977     SFb_1tag_syst[1] = b1.weight(jk,1);
978     }
979    
980     // at least two tags
981     BTagWeight b2(2,Nbtags_CSVM); // number of tags
982     if (Nbtags_CSVM>=2) {
983     SFb_2tag = b2.weight(j,2);
984     hjets["Nbtags_CSVM"]->Fill( Nbtags_CSVM, PUweight*SFb_2tag ); // fill bin >=2
985    
986     // UP
987     vector<BTagWeight::JetInfo> jj;
988     for(int i=0;i<number_of_b;i++)jj.push_back(bjUP);
989     for(int i=0;i<number_of_b_highpt;i++)jj.push_back(bjUPhighpt);
990     for(int i=0;i<number_of_c;i++)jj.push_back(cjUP);
991     for(int i=0;i<number_of_c_highpt;i++)jj.push_back(cjUPhighpt);
992     for(int i=0;i<number_of_l;i++)jj.push_back(lj);
993     SFb_2tag_syst[0] = b2.weight(jj,2);
994    
995     // DOWN
996     vector<BTagWeight::JetInfo> jk;
997     for(int i=0;i<number_of_b;i++)jk.push_back(bjDOWN);
998     for(int i=0;i<number_of_b_highpt;i++)jk.push_back(bjDOWNhighpt);
999     for(int i=0;i<number_of_c;i++)jk.push_back(cjDOWN);
1000     for(int i=0;i<number_of_c_highpt;i++)jk.push_back(cjDOWNhighpt);
1001     for(int i=0;i<number_of_l;i++)jk.push_back(lj);
1002     SFb_2tag_syst[1] = b2.weight(jk,2);
1003     }
1004     }
1005     else hjets["Nbtags_CSVM"]->Fill( Nbtags_CSVM );
1006    
1007     //hjets["Nbtags_TCHPM"]->Fill( Nbtags_TCHPM, PUweight*SFb );
1008     //hjets["Nbtags_CSVM"]->Fill( Nbtags_CSVM, PUweight*SFb );
1009 algomez 1.6
1010 algomez 1.7 // Cuts
1011 algomez 1.6 bool passcut = true;
1012     if ( Ht <= 300. ) passcut = false;
1013    
1014     if (passcut) {
1015 algomez 1.7 hPVs["Nreweight_2jet"]->Fill( total_pvs, PUweight );
1016     hMET["Ht"]->Fill( Ht, PUweight );
1017 algomez 1.6 hjets["Njets_cut1"]->Fill( njets, PUweight );
1018     hjets["1st_pt"]->Fill( p4jets[0].Pt(), PUweight );
1019     hjets["1st_eta"]->Fill( p4jets[0].Eta(), PUweight );
1020     hjets["2nd_pt"]->Fill( p4jets[1].Pt(), PUweight );
1021     hjets["2nd_eta"]->Fill( p4jets[1].Eta(), PUweight );
1022     hjets["3rd_pt"]->Fill( p4jets[2].Pt(), PUweight );
1023     hjets["4th_pt"]->Fill( p4jets[3].Pt(), PUweight );
1024     hjets["5th_pt"]->Fill( p4jets[4].Pt(), PUweight );
1025     hjets["6th_pt"]->Fill( p4jets[5].Pt(), PUweight );
1026     hjets["7th_pt"]->Fill( p4jets[6].Pt(), PUweight );
1027     hmuons["N"]->Fill( total_muons, PUweight );
1028     hmuons["Nelectrons"]->Fill( nlooseelectrons, PUweight );
1029     hMET["MET"]->Fill( p4MET.Pt(), PUweight );
1030     hmuons["deltaR"]->Fill( deltaR, PUweight );
1031     hjets["Dijet_deltaR"]->Fill( deltaRjj, PUweight );
1032 algomez 1.7 hM["WMt_2jet"]->Fill( WMt, PUweight );
1033    
1034     if ( Nbtags_CSVM >= 1 ) {
1035     hjets["Njets_1tag"]->Fill(njets, PUweight*SFb_1tag );
1036     }
1037 algomez 1.4 }
1038 algomez 1.6 }
1039 algomez 1.1
1040     if (fVerbose) cout << "done analysis" << endl;
1041     return kTRUE;
1042     }
1043    
1044     void Analyzer::SlaveTerminate()
1045     {
1046     // The SlaveTerminate() function is called after all entries or objects
1047     // have been processed. When running with PROOF SlaveTerminate() is called
1048     // on each slave server.
1049    
1050     // fill cutflow histogram
1051    
1052     int ibin = 1;
1053     for ( vector<string>::const_iterator ivec= fCutLabels.begin(); ivec != fCutLabels.end(); ++ivec )
1054     // for ( map<string, int >::const_iterator imap=cutmap.begin(); imap!=cutmap.end(); ++imap )
1055     {
1056     hcutflow->SetBinContent( ibin, cutmap[ *ivec ] );
1057     ibin++;
1058     }
1059     // Write the ntuple to the file
1060     if (fFile) {
1061     Bool_t cleanup = kFALSE;
1062     TDirectory *savedir = gDirectory;
1063     if ( h1test->GetEntries() > 0) {
1064     fFile->cd();
1065     h1test->Write();
1066     hcutflow->Write();
1067 algomez 1.3 //h2_pt_Wprime->Write();
1068 algomez 1.1 fFile->mkdir("muons");
1069     fFile->cd("muons");
1070     for ( map<string,TH1* >::const_iterator imap=hmuons.begin(); imap!=hmuons.end(); ++imap )
1071     {
1072     TH1 *temp = imap->second;
1073     if ( temp->GetEntries() > 0 )
1074     temp->Write();
1075     //else cout << "Warning: empty histogram " << temp->GetName() << " will not be written to file." << endl;
1076     }
1077     fFile->cd();
1078     fFile->mkdir("PVs");
1079     fFile->cd("PVs");
1080     for ( map<string,TH1* >::const_iterator imap=hPVs.begin(); imap!=hPVs.end(); ++imap )
1081     {
1082     TH1 *temp = imap->second;
1083     if ( temp->GetEntries() > 0 )
1084     temp->Write();
1085     //else cout << "Warning: empty histogram " << temp->GetName() << " will not be written to file." << endl;
1086     }
1087     fFile->cd();
1088     fFile->mkdir("jets");
1089     fFile->cd("jets");
1090     for ( map<string,TH1* >::const_iterator imap=hjets.begin(); imap!=hjets.end(); ++imap )
1091     {
1092     TH1 *temp = imap->second;
1093     if ( temp->GetEntries() > 0 )
1094     temp->Write();
1095     }
1096     fFile->cd();
1097     fFile->mkdir("mass");
1098     fFile->cd("mass");
1099     for ( map<string,TH1* >::const_iterator imap=hM.begin(); imap!=hM.end(); ++imap )
1100     {
1101     TH1 *temp = imap->second;
1102     if ( temp->GetEntries() > 0 )
1103     temp->Write();
1104     }
1105     fFile->cd();
1106     fFile->mkdir("MET");
1107     fFile->cd("MET");
1108     for ( map<string,TH1* >::const_iterator imap=hMET.begin(); imap!=hMET.end(); ++imap )
1109     {
1110     TH1 *temp = imap->second;
1111     if ( temp->GetEntries() > 0 )
1112     temp->Write();
1113     }
1114    
1115     fFile->cd();
1116    
1117     fProofFile->Print();
1118     fOutput->Add(fProofFile);
1119     } else {
1120     cleanup = kTRUE;
1121     }
1122    
1123    
1124     h1test->SetDirectory(0);
1125     hcutflow->SetDirectory(0);
1126     gDirectory = savedir;
1127     fFile->Close();
1128     // Cleanup, if needed
1129     if (cleanup) {
1130     TUrl uf(*(fFile->GetEndpointUrl()));
1131     SafeDelete(fFile);
1132     gSystem->Unlink(uf.GetFile());
1133     SafeDelete(fProofFile);
1134     }
1135     }
1136    
1137     }
1138    
1139     void Analyzer::Terminate()
1140     {
1141     // The Terminate() function is the last function to be called during
1142     // a query. It always runs on the client, it can be used to present
1143     // the results graphically or save the results to file.
1144    
1145     Info("Terminate","Analyzer done.");
1146     }