ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/algomez/FourTop/TreeAnalyzer/test/Analyzer.C
Revision: 1.13
Committed: Thu Feb 9 18:34:51 2012 UTC (13 years, 3 months ago) by algomez
Content type: text/plain
Branch: MAIN
Changes since 1.12: +354 -335 lines
Log Message:
new version with JEC and BDT incorporated

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.6 hMET["Ht0"] = new TH1F("Ht0"+hname,"H_{T} [GeV]", 50, 0, 3000);
253     hMET["Ht"] = new TH1F("Ht"+hname,"H_{T} [GeV]", 50, 0, 3000);
254 algomez 1.10 hMET["Ht_1btag"] = new TH1F("Ht_1btag"+hname,"H_{T} [GeV]", 50, 0, 3000);
255 algomez 1.8 hMET["Htlep"] = new TH1F("Htlep"+hname,"H_{T,lep} [GeV]", 100, 0, 1000);
256 algomez 1.10 hMET["Stlep"] = new TH1F("Stlep"+hname,"S_{t}^{lep} [GeV]", 100, 0, 1000);
257     hMET["Stlep_1btag"] = new TH1F("Stlep_1btag"+hname,"S_{t}^{lep} [GeV]", 100, 0, 1000);
258     hMET["Stjet"] = new TH1F("Stjet"+hname,"S_{t}^{jet} [GeV]", 100, 0, 3000);
259     hMET["Stjet_1btag"] = new TH1F("Stjet_1btag"+hname,"S_{t}^{jet} [GeV]", 100, 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.13 hMET["bdtresponse"] = new TH1F("bdtresponse"+hname,"BDT response",50, -0.5, 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 //if (!fBDT){
366     //------- Store information in a Tree
367     MyStoreTree = new StoreTreeVariable();
368    
369     if(fChannel == 1){
370     MyStoreTree->SetElectronFalse();
371     //MyStoreTree->SetJetFalse();
372     MyStoreTree->SetVertexFalse();
373     MyStoreTree->SetTriggerFalse();
374     //MyStoreTree->SetMetFalse();
375     MyStoreTree->SetMuonFalse();
376     }
377    
378     MyStoreTree->InitialAll();
379     //Get the Store Tree
380     MyStoreTree->GetStoreTree()->SetDirectory(fFile);
381     MyStoreTree->GetStoreTree()->AutoSave();
382     //}
383     //////////////////////////////////////////
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.1 }
396     else
397     { //electron+jets
398     fCutLabels.push_back("Processed");
399 algomez 1.12 fCutLabels.push_back("OneIsoMu");
400 algomez 1.1 fCutLabels.push_back("LooseMuVeto");
401 algomez 1.12 fCutLabels.push_back("ElectronVeto");
402 algomez 1.13 fCutLabels.push_back("4Jet");
403 algomez 1.12 fCutLabels.push_back("Ht");
404 algomez 1.13 fCutLabels.push_back("4Jet1b");
405 algomez 1.1 }
406     hcutflow = new TH1D("cutflow","cut flow", fCutLabels.size(), 0.5, fCutLabels.size() +0.5 );
407    
408     for ( vector<string>::const_iterator ivec= fCutLabels.begin(); ivec!=fCutLabels.end(); ++ivec)
409     {
410     cutmap[ *ivec ] = 0;
411     }
412    
413 algomez 1.13 //fpu_weights_vec.assign( pu_weights, pu_weights + 35 );
414 algomez 1.1
415     // For JEC uncertainties
416 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");
417     //JetCorrectorParameters *jcp = new JetCorrectorParameters("/uscms/home/yumiceva/work/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/JEC11_V10_AK5PF_UncertaintySources.txt", "Total");
418     if (fdoJECunc)
419     {
420     JetCorrectorParameters *jcp = new JetCorrectorParameters("/uscms/home/yumiceva/work/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/JEC11_V10_AK5PF_UncertaintySources.txt", "Total");
421     fJECunc = new JetCorrectionUncertainty( *jcp );
422     }
423 algomez 1.9 // LOT for b-tagging SF
424     //bSF_table.LoadTable("/uscms/home/yumiceva/work/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/Table_CSVM_beff_SF.txt");
425     lSF_table.LoadTable("/uscms/home/yumiceva/work/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/Table_CSVM_lmistag_SF.txt");
426     leff_table.LoadTable("/uscms/home/yumiceva/work/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/Table_CSVM_lmistag_Eff.txt");
427    
428     //leff_tablebtag efficiency file and 2D histogram
429     //TString btagefffilename = "/uscms/home/weizou/work/NtupleMaker/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/BtagEff.root";
430     //btagefffile = new TFile(btagefffilename,"read");
431     //ttbar
432     //f2Dttbarbtag = (TH2D*) btagefffile->Get("ttbar_csv_btageff");
433     //f2Dttbarctag = (TH2D*) btagefffile->Get("ttbar_csv_ctageff");
434     //f2Dttbarlighttag = (TH2D*) btagefffile->Get("ttbar_csv_lighttageff");
435     //wprime
436     //f2Dwprimebtag = (TH2D*) btagefffile->Get("wprime_csv_btageff");
437     //f2Dwprimectag = (TH2D*) btagefffile->Get("wprime_csv_ctageff");
438     //f2Dwprimelighttag = (TH2D*) btagefffile->Get("wprime_csv_lighttageff");
439    
440 algomez 1.13 LumiWeights_ =
441     edm::Lumi3DReWeighting("/uscms/home/weizou/work/NtupleMaker/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/PUMC_dist.root",
442     "/uscms/home/weizou/work/NtupleMaker/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/PileUp/PUData_dist.root",
443     "pileup",
444     //"pileup","/uscms/home/weizou/work/NtupleMaker/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/Weight_3Dnew.root");
445     "pileup","/uscms/home/algomez/work/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/Weight_3Dnew.root");
446     LumiWeights_.weight3D_init( 1.08 );
447     LumiWeightsup_ =
448     edm::Lumi3DReWeighting("/uscms/home/weizou/work/NtupleMaker/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/PUMC_dist.root",
449     "/uscms/home/weizou/work/NtupleMaker/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/PileUp/PUData_dist.root",
450     "pileup",
451     //"pileup","/uscms/home/weizou/work/NtupleMaker/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/Weight_3Dup.root");
452     "pileup","/uscms/home/algomez/work/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/Weight_3Dup.root");
453     LumiWeightsup_.weight3D_init( 1.167 );//up
454     LumiWeightsdown_ =
455     edm::Lumi3DReWeighting("/uscms/home/weizou/work/NtupleMaker/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/PUMC_dist.root",
456     "/uscms/home/weizou/work/NtupleMaker/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/PileUp/PUData_dist.root",
457     "pileup",
458     //"pileup","/uscms/home/weizou/work/NtupleMaker/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/Weight_3Ddown.root");
459     "pileup","/uscms/home/algomez/work/CMSSW_4_2_4/src/Yumiceva/TreeAnalyzer/test/Weight_3Ddown.root");
460     LumiWeightsdown_.weight3D_init( 0.994 );//down
461 algomez 1.1 }
462    
463     Bool_t Analyzer::Process(Long64_t entry)
464     {
465     // The Process() function is called for each entry in the tree (or possibly
466     // keyed object in the case of PROOF) to be processed. The entry argument
467     // specifies which entry in the currently loaded tree is to be processed.
468     // It can be passed to either Analyzer::GetEntry() or TBranch::GetEntry()
469     // to read either all or the required parts of the data. When processing
470     // keyed objects with PROOF, the object is already loaded and is available
471     // via the fObject pointer.
472     //
473     // This function should contain the "body" of the analysis. It can contain
474     // simple or elaborate selection criteria, run algorithms on the data
475     // of the event and typically fill histograms.
476     //
477     // The processing can be stopped by calling Abort().
478     //
479     // Use fStatus to set the return value of TTree::Process().
480     //
481     // The return value is currently not used.
482    
483     //TString option = GetOption();
484    
485 algomez 1.13 //if ( entry % 100 == 0 )
486     //cout<< "process entry " << entry << endl;
487 algomez 1.1
488     //TString sEntry = Form("%f", float(entry) );
489     // Info("Process",
490     //"entry # %s", Form("%f", float(entry) ) );
491    
492     //fChain->GetTree()->GetEntry(entry);
493     fChain->GetEntry(entry);
494    
495     //if (entry>10) return kTRUE;
496    
497     // event info
498     //cout << "run: " << ntuple->run << " lumi: " << ntuple->lumi << endl;
499    
500     // get collections
501     vector< TopVertexEvent > primaryVertices = ntuple->vertices;
502     vector< TopMuonEvent > muons = ntuple->muons;
503 algomez 1.2 vector< TopElectronEvent > electrons = ntuple->PFelectrons; // use PF electrons (gsf collection is called "electrons")
504 algomez 1.1 vector< TopJetEvent > jets = ntuple->PFjets;
505    
506 algomez 1.2 // USE PF Isolation
507     fMuSelector.UsePFIsolation(true);
508     fEleSelector.UsePFIsolation(true);
509    
510 algomez 1.1 size_t total_pvs = primaryVertices.size();
511     size_t total_muons = muons.size();
512     size_t total_electrons = electrons.size();
513     size_t total_jets = jets.size();
514    
515     float PVz = 0.;
516     TLorentzVector p4muon, p4ele, p4lepton, p4MET;
517     TLorentzVector p4Nu, p4OtherNu;
518     TLorentzVector p4QCDmuon;
519    
520     vector< TLorentzVector > p4jets;
521 algomez 1.6 vector< TLorentzVector > p4Othermuon; // leading muon
522 algomez 1.1
523 algomez 1.13 //--------- For MVA analysis
524     const char* inputVars[] = { "Ht", "Stlep", "Stjet", "jet_number", "numBjets_csvl" };
525     std::vector<std::string> inputVarsMVA;
526     for (int i=0; i<5; ++i) inputVarsMVA.push_back( inputVars[i] );
527     ReadBDT mvaReader( inputVarsMVA );
528     float bdtresponse = 0.;
529     //////////////////////////////////////////////////
530    
531    
532     // FILTER OUT DATA events
533     int testrun = ntuple->run;
534     if ( fSample =="data" && ( testrun == 176765 || testrun == 176771 || testrun == 176795 || testrun == 176796 || testrun == 176545 || testrun == 176547 || testrun == 176928 || testrun == 176982 ) ) return kTRUE;
535     if ( fSample =="dataMissing" && ( testrun != 176765 && testrun != 176771 && testrun != 176795 && testrun != 176796 && testrun != 176545 && testrun != 176547 && testrun != 176928 && testrun != 176982 ) ) return kTRUE;
536    
537    
538 algomez 1.2 ////////////////////
539     // GENERATOR
540     ///////////////////
541 algomez 1.6 if (fIsMC && fSample.Contains("4Top") )
542 algomez 1.2 {
543     TLorentzVector p4genLepton;
544     TLorentzVector p4genNu;
545     TLorentzVector p4genb;
546     if (ntuple->gen.bLep_pt>0)
547     {
548     p4genLepton.SetPtEtaPhiE(ntuple->gen.mu_pt,ntuple->gen.mu_eta,ntuple->gen.mu_phi,ntuple->gen.mu_e);
549     p4genNu.SetPtEtaPhiE(ntuple->gen.nu_pt,ntuple->gen.nu_eta,ntuple->gen.nu_phi,ntuple->gen.nu_e);
550     p4genb.SetPtEtaPhiE(ntuple->gen.bLep_pt,ntuple->gen.bLep_eta,ntuple->gen.bLep_phi,ntuple->gen.bLep_e);
551    
552     hjets["gen_deltaR_mub"]->Fill( p4genLepton.DeltaR( p4genb ) );
553     }
554     }
555 algomez 1.1 ////////////////////////////////////
556     // PRIMARY VERTICES
557     ///////////////////////////////////
558    
559 algomez 1.6 for ( size_t ipv=0; ipv < total_pvs; ++ipv)
560     {
561     if (ipv==0) PVz = primaryVertices[ipv].vz;
562     }
563 algomez 1.1
564 algomez 1.6 //hPVs["N"]->Fill( total_pvs );
565 algomez 1.1
566     // calculate PU weight
567     double PUweight = 1.;
568    
569     if (fIsMC) {
570 algomez 1.2
571 algomez 1.13 //Int_t mc_npvminus1 = TMath::Min(ntuple->gen.Bx_minus1,34);
572     //Int_t mc_npv0 = TMath::Min(ntuple->gen.Bx_0,34);
573     //Int_t mc_npvplus1 = TMath::Min(ntuple->gen.Bx_plus1,34);
574     //PUweight = f3Dweight->GetBinContent(mc_npvminus1,mc_npv0,mc_npvplus1);
575     Int_t mc_npvminus1 = ntuple->gen.Bx_minus1;
576     Int_t mc_npv0 = ntuple->gen.Bx_0;
577     Int_t mc_npvplus1 = ntuple->gen.Bx_plus1;
578    
579     PUweight = LumiWeights_.weight3D(mc_npvminus1,mc_npv0,mc_npvplus1);
580     if ( fpu_down )
581     PUweight = LumiWeightsdown_.weight3D(mc_npvminus1,mc_npv0,mc_npvplus1);
582     if ( fpu_up )
583     PUweight = LumiWeightsup_.weight3D(mc_npvminus1,mc_npv0,mc_npvplus1);
584    
585 algomez 1.1 }
586    
587 algomez 1.5 // For 4 tops
588     if (fIsMC && fSample.Contains("4Top") ) {
589     PUweight = 1;
590     }
591    
592 algomez 1.2 /////////////
593     // HLT scale factor for MC
594     ////////////
595     double SF_hlt = 1.;
596 algomez 1.9 if (fIsMC) SF_hlt = 0.97; //0.966;
597     double SF_iso = 1.;
598     if (fIsMC) SF_iso = 0.996;
599     PUweight = PUweight*SF_hlt*SF_iso; // LETS INCLUDE THE TRIGGER SF INTO THE PU WEIGHTS
600    
601 algomez 1.13 hPVs["Nreweight"]->Fill( total_pvs, PUweight );
602    
603 algomez 1.9 //TEMP
604     //PUweight = 1.;
605 algomez 1.2
606 algomez 1.1 cutmap["Processed"] += PUweight;
607    
608     if (fVerbose) cout << "done pv" << endl;
609 algomez 1.6
610 algomez 1.1 //////////////////////////////////
611     // MUONS
612     //////////////////////////////////
613 algomez 1.2 int ngoodIDmuons = 0;
614 algomez 1.1 int nloosemuons = 0;
615     int ntightmuons = 0;
616     int nqcdmuons = 0;
617 algomez 1.9 int nmuonID[8] = {0};
618 algomez 1.1
619     double RelIso = -1.;
620     double deltaR = -1.;
621     double QCDRelIso = -1.;
622     double QCDdeltaR = -1;
623    
624     for ( size_t imu=0; imu < total_muons; ++imu) {
625    
626 algomez 1.6 TopMuonEvent muon = muons[imu];
627 algomez 1.9
628 algomez 1.6 h1test->Fill( muon.pt );
629     hmuons["pt_cut1"]->Fill( muon.pt, PUweight );
630 algomez 1.9
631     if (muon.pt > 32. && fabs(muon.eta)<2.1 && muon.IsTrackerMuon==1 ) {
632     nmuonID[0] += 1;
633     if (fabs(muon.d0)<0.02 ) {
634     nmuonID[1] += 1;
635     if (muon.trackerhits>=11 ) {
636     nmuonID[2] += 1;
637     if (muon.normchi2<10 ) {
638     nmuonID[3] +=1;
639     if (muon.muonhits>0 ) {
640     nmuonID[4] += 1;
641     if (muon.pixelhits >= 1 ) {
642     nmuonID[5] += 1;
643     if (muon.muonstations > 1 ) {
644     nmuonID[6] +=1;
645     if (fabs(muon.vz - PVz) < 1.) {
646     nmuonID[7] +=1;
647     }
648     }
649     }
650     }
651     }
652     }
653     }
654     }
655 algomez 1.6
656     if ( fMuSelector.MuonID( muon, PVz ) ) ngoodIDmuons++;
657 algomez 1.9
658 algomez 1.6 // select only good muons
659 algomez 1.9
660 algomez 1.6 if ( fMuSelector.MuonLoose( muon ) ) {
661 algomez 1.9
662 algomez 1.6 nloosemuons++;
663 algomez 1.9
664 algomez 1.12 //if ( fMuSelector.MuonTight( muon, PVz) )
665     //hmuons["pt_cut2"]->Fill( muon.pt, PUweight );
666 algomez 1.6 //hmuons["N_tisomuons"]->Fill( nloosemuons );
667     //hmuons["charge_tiso"]->Fill( muon.charge, PUweight );
668     if ( fMuSelector.MuonTightDeltaR( muon, PVz, jets) ) {
669     ntightmuons++;
670     deltaR = fMuSelector.GetDeltaR();
671     }
672 algomez 1.1
673 algomez 1.6 p4muon.SetPtEtaPhiE( muon.pt, muon.eta, muon.phi, muon.e );
674     RelIso = muon.pfreliso; //muon.reliso03;
675     p4Othermuon.push_back( p4muon ); // for leading muon
676 algomez 1.9 }
677 algomez 1.4
678 algomez 1.6 // check muon in QCD control region
679     if ( fMuSelector.MuonRelax02IsoQCD( muon, PVz, jets ) ) {
680     nqcdmuons++;
681 algomez 1.9
682 algomez 1.6 // keep the leading muon for selection
683     if (nqcdmuons==1) {
684     p4QCDmuon.SetPtEtaPhiE( muon.pt, muon.eta, muon.phi, muon.e );
685     QCDRelIso = muon.pfreliso; //muon.reliso03;
686     QCDdeltaR = fMuSelector.GetDeltaR();
687     }
688 algomez 1.1 }
689 algomez 1.6 }
690 algomez 1.1
691 algomez 1.6 if (fVerbose) cout << "done muons" << endl;
692 algomez 1.1
693     //////////////////////////////////
694     // ELECTRONS
695     //////////////////////////////////
696     int nlooseelectrons = 0;
697     int ntightelectrons = 0;
698     bool IsConversion = false;
699    
700     for ( size_t iele=0; iele < total_electrons; ++iele) {
701    
702 algomez 1.6 TopElectronEvent electron = electrons[iele];
703 algomez 1.1
704 algomez 1.6 if ( fEleSelector.ElectronLoose(electron) ) nlooseelectrons++;
705 algomez 1.1
706 algomez 1.6 if ( fEleSelector.ElectronTight(electron, PVz ) ) {
707 algomez 1.1
708 algomez 1.6 if (ntightelectrons == 0) {
709     IsConversion = electron.IsConversion;
710     p4ele.SetPtEtaPhiE( electron.pt, electron.eta, electron.phi, electron.e );
711 algomez 1.12 /*helectrons["pt_cut2"]->Fill( p4ele.Pt(), PUweight );
712 algomez 1.6 helectrons["eta_cut2"]->Fill( p4ele.Eta(), PUweight );
713 algomez 1.12 helectrons["phi_cut2"]->Fill( p4ele.Phi(), PUweight );*/
714 algomez 1.6 }
715     ntightelectrons++;
716     }
717 algomez 1.1 }
718     if (fVerbose) cout << "done electron" << endl;
719    
720 algomez 1.6 /////////////////////////////////////
721     // MUON/ELECTRON + JETS
722     /////////////////////////////////////
723 algomez 1.1
724 algomez 1.6 if ( fChannel == 1 ) {
725 algomez 1.1
726 algomez 1.6 if (fdoQCD2SideBand) {
727 algomez 1.1
728 algomez 1.6 if (nqcdmuons == 0) return kTRUE;
729     cutmap["OneIsoMu"] += PUweight;
730 algomez 1.1
731 algomez 1.6 p4lepton = p4QCDmuon;
732     RelIso = QCDRelIso;
733     deltaR = QCDdeltaR;
734     }
735     else {
736 algomez 1.9 /*
737     if (nmuonID[0] == 1) cutmap["MuID1"] += PUweight;
738     if (nmuonID[1] == 1) cutmap["MuID2"] +=PUweight;
739     if (nmuonID[2] == 1) cutmap["MuID3"] +=PUweight;
740     if (nmuonID[3] == 1) cutmap["MuID4"] +=PUweight;
741     if (nmuonID[4] == 1) cutmap["MuID5"] +=PUweight;
742     if (nmuonID[5] == 1) cutmap["MuID6"] +=PUweight;
743     if (nmuonID[6] == 1) cutmap["MuID7"] +=PUweight;
744     if (nmuonID[7] == 1) cutmap["MuID8"] +=PUweight;
745     if (ngoodIDmuons == 1) cutmap["MuID"] += PUweight;*/ // TEMP
746 algomez 1.2
747 algomez 1.6 if ( ngoodIDmuons > 0 ) hmuons["Ngood"]->Fill( total_pvs, PUweight);
748     if ( ntightmuons > 0 ) hmuons["Niso"]->Fill( total_pvs, PUweight);
749     if ( ntightmuons != 1 ) return kTRUE;
750     cutmap["OneIsoMu"] += PUweight;
751 algomez 1.2
752 algomez 1.6 if ( nloosemuons > 1 ) return kTRUE;
753     cutmap["LooseMuVeto"] += PUweight;
754 algomez 1.1
755 algomez 1.6 if ( nlooseelectrons > 0 ) return kTRUE;
756     cutmap["ElectronVeto"] += PUweight;
757 algomez 1.1
758 algomez 1.6 p4lepton = p4muon;
759     if (fVerbose) cout << "got a good lepton" << endl;
760     }
761    
762 algomez 1.12 /*
763 algomez 1.6 hmuons["pt"]->Fill( p4lepton.Pt(), PUweight );
764     hmuons["eta"]->Fill( p4lepton.Eta(), PUweight );
765     hmuons["phi"]->Fill( p4lepton.Phi(), PUweight );
766     hmuons["reliso"]->Fill( RelIso, PUweight );
767 algomez 1.12 hmuons["deltaR"]->Fill( deltaR, PUweight ); */
768 algomez 1.1
769 algomez 1.6 }
770 algomez 1.1 else // electron+jets
771     {
772     // pending ...
773     }
774    
775     if (fVerbose) cout << "done lepton selection " << endl;
776    
777     /////////////////////////////////
778 algomez 1.6 // MET + Ht
779 algomez 1.1 /////////////////////////////////
780    
781     p4MET.SetPtEtaPhiE( ntuple->PFMET,
782     0.,
783     ntuple->PFMETphi,
784     ntuple->PFMET );
785    
786     //temporal check using genMET
787     //p4MET.SetPtEtaPhiE( ntuple->gen.MET,
788     // 0.,
789     // ntuple->gen.METPhi,
790     // ntuple->gen.MET );
791    
792     if (fdoQCD1SideBand && p4MET.Et() > 20.) return kTRUE;
793     else if ( p4MET.Et() <= 20. && fdoQCD2SideBand==false ) return kTRUE;
794 algomez 1.6 if (fVerbose) cout << "pass MET cut" << endl;
795 algomez 1.1
796    
797     //cutmap["MET"] += PUweight;
798 algomez 1.6 //hMET["MET"]->Fill( p4MET.Pt(), PUweight );
799     //hMET["phi"]->Fill( p4MET.Phi(), PUweight );
800     //hMET["Ht0"]->Fill( ntuple->PFHt, PUweight );
801     //hMET["Htlep"]->Fill( ntuple->PFHt + p4lepton.Pt(), PUweight );
802    
803 algomez 1.1
804     double Wpt = p4lepton.Pt() + p4MET.Pt();
805     double Wpx = p4lepton.Px() + p4MET.Px();
806     double Wpy = p4lepton.Py() + p4MET.Py();
807     double WMt = sqrt(Wpt*Wpt-Wpx*Wpx-Wpy*Wpy);
808 algomez 1.3
809     //if ( WMt <= 40. ) return kTRUE;
810 algomez 1.12 //cutmap["MET"] += PUweight;
811 algomez 1.1
812     /////////////////////////////////
813     // JETS
814     ////////////////////////////////
815    
816 algomez 1.6 //JetCombinatorics myCombi = JetCombinatoric();
817 algomez 1.1
818     int njets = 0;
819 algomez 1.11 //double prod_bdisc =0;
820 algomez 1.8 MyStoreTree->GetJetVariable()->numjets = 0;
821 algomez 1.11 MyStoreTree->GetJetVariable()->numBjets_csvl = 0;
822 algomez 1.13 //MyStoreTree->GetJetVariable()->numBjets_csvm = 0;
823     //MyStoreTree->GetJetVariable()->numBjets_csvt = 0;
824    
825 algomez 1.1 map< string, vector<float> > bdisc;
826     map< string, vector<bool> > isTagb;
827 algomez 1.9 map< string, vector<bool> > isTagbUp;
828     map< string, vector<bool> > isTagbDown;
829 algomez 1.1 vector<int> listflavor;
830 algomez 1.13 //vector<float> bdiscriminator;
831 algomez 1.8
832 algomez 1.13 Float_t metcorpx = p4MET.Px();
833     Float_t metcorpy = p4MET.Py();
834     Float_t totJERptadd = 0.;
835     Float_t totJERptminus = 0;
836    
837     vector< TopJetEvent > tmp_corrjets;
838 algomez 1.1
839 algomez 1.6 for ( size_t ijet=0; ijet < total_jets; ++ijet) {
840 algomez 1.1
841 algomez 1.6 TopJetEvent jet = jets[ijet];
842     double SF_JEC = 1.;
843 algomez 1.13
844     //JER
845     Float_t factor = 1.0;
846     Float_t ptscale = 1.0;
847    
848 algomez 1.6 if (fdoJECunc){
849 algomez 1.13 /*fJECunc->setJetEta( jet.eta);
850     fJECunc->setJetPt( jet.pt);
851     double jec_unc = fJECunc->getUncertainty(true);
852     if (fVerbose) cout << "JEC uncertainty is " << jec_unc << endl;
853     if (fdoJECup) SF_JEC = 1.+jec_unc;
854     else SF_JEC = 1.-jec_unc; */
855    
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.13 //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.13 /*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.13 // 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     vector<double>mvaInputVal;
1287 algomez 1.9
1288 algomez 1.7 // Cuts
1289 algomez 1.6 bool passcut = true;
1290     if ( Ht <= 300. ) passcut = false;
1291    
1292     if (passcut) {
1293 algomez 1.13 //if(!fBDT){
1294 algomez 1.7 hPVs["Nreweight_2jet"]->Fill( total_pvs, PUweight );
1295     hMET["Ht"]->Fill( Ht, PUweight );
1296 algomez 1.10 hMET["MET"]->Fill( p4MET.Pt(), PUweight );
1297     hMET["Stlep"]->Fill( Stlep , PUweight );
1298     hMET["Stjet"]->Fill( Stjet , PUweight );
1299 algomez 1.6 hjets["Njets_cut1"]->Fill( njets, PUweight );
1300     hjets["1st_pt"]->Fill( p4jets[0].Pt(), PUweight );
1301     hjets["1st_eta"]->Fill( p4jets[0].Eta(), PUweight );
1302     hjets["2nd_pt"]->Fill( p4jets[1].Pt(), PUweight );
1303     hjets["2nd_eta"]->Fill( p4jets[1].Eta(), PUweight );
1304     hjets["3rd_pt"]->Fill( p4jets[2].Pt(), PUweight );
1305     hjets["4th_pt"]->Fill( p4jets[3].Pt(), PUweight );
1306 algomez 1.12 //hjets["5th_pt"]->Fill( p4jets[4].Pt(), PUweight );
1307     //hjets["6th_pt"]->Fill( p4jets[5].Pt(), PUweight );
1308     //hjets["7th_pt"]->Fill( p4jets[6].Pt(), PUweight );
1309 algomez 1.10 hjets["Dijet_deltaR"]->Fill( deltaRjj, PUweight );
1310 algomez 1.6 hmuons["N"]->Fill( total_muons, PUweight );
1311     hmuons["Nelectrons"]->Fill( nlooseelectrons, PUweight );
1312 algomez 1.10 hmuons["pt"]->Fill( p4lepton.Pt(), PUweight );
1313 algomez 1.6 hmuons["deltaR"]->Fill( deltaR, PUweight );
1314 algomez 1.7 hM["WMt_2jet"]->Fill( WMt, PUweight );
1315    
1316 algomez 1.11 // B-tagging
1317     hjets["Nbtags_CSVL"]->Fill( Nbtags_CSVL, PUweight );
1318     hjets["Nbtags_CSVM"]->Fill( Nbtags_CSVM, PUweight );
1319     hjets["Nbtags_CSVT"]->Fill( Nbtags_CSVT, PUweight );
1320    
1321 algomez 1.10 // plot bdiscriminator
1322 algomez 1.13 //if ( bdiscriminator[0] >= 0 ) { MyStoreTree->GetJetVariable()->bdisc_1st = bdiscriminator[0]; hjets["1st_bdisc"]->Fill( bdiscriminator[0], PUweight );}
1323     //if ( bdiscriminator[1] >= 0 ) { MyStoreTree->GetJetVariable()->bdisc_2nd = bdiscriminator[1]; hjets["2nd_bdisc"]->Fill( bdiscriminator[1], PUweight );}
1324     //if ( bdiscriminator[2] >= 0 ) { MyStoreTree->GetJetVariable()->bdisc_3rd = bdiscriminator[2]; hjets["3rd_bdisc"]->Fill( bdiscriminator[2], PUweight );}
1325     //if ( bdiscriminator[3] >= 0 ) { MyStoreTree->GetJetVariable()->bdisc_4th = bdiscriminator[3]; hjets["4th_bdisc"]->Fill( bdiscriminator[3], PUweight );}
1326     //prod_bdisc = bdiscriminator[0]*bdiscriminator[1]*bdiscriminator[2]*bdiscriminator[3];
1327 algomez 1.11 //hjets["prod_bdisc"]->Fill( prod_bdisc, PUweight );
1328    
1329 algomez 1.12 // Variables in 4Tree
1330 algomez 1.10 MyStoreTree->GetGeneralVariable()->PUWeight = PUweight;
1331     MyStoreTree->GetMetVariable()->Ht = Ht;
1332     MyStoreTree->GetMetVariable()->Stlep = Stlep;
1333     MyStoreTree->GetMetVariable()->Stjet = Stjet;
1334     MyStoreTree->GetJetVariable()->numjets= njets;
1335 algomez 1.11 MyStoreTree->GetJetVariable()->numBjets_csvl= Nbtags_CSVL;
1336 algomez 1.13 //MyStoreTree->GetJetVariable()->numBjets_csvm= Nbtags_CSVM;
1337     //MyStoreTree->GetJetVariable()->numBjets_csvt= Nbtags_CSVT;
1338 algomez 1.10 //////////////////////////////////////////////////////////////////////////////////
1339    
1340 algomez 1.12 cutmap["Ht"] += PUweight;
1341    
1342 algomez 1.7 if ( Nbtags_CSVM >= 1 ) {
1343 algomez 1.13 cutmap["4Jet1b"] += PUweight;
1344     //hPVs["Nreweight_2jet_1btag"]->Fill( total_pvs, PUweight );
1345     //hMET["Ht_1btag"]->Fill( Ht, PUweight );
1346     //hMET["MET_1btag"]->Fill( p4MET.Pt(), PUweight );
1347     //hMET["Stlep_1btag"]->Fill( Stlep , PUweight );
1348     //hMET["Stjet_1btag"]->Fill( Stjet , PUweight );
1349     //hjets["Njets_1btag"]->Fill(njets, PUweight*SFb_1tag );
1350     //hjets["1st_pt_1btag"]->Fill( p4jets[0].Pt(), PUweight );
1351     //hjets["1st_eta_1btag"]->Fill( p4jets[0].Eta(), PUweight );
1352     //hjets["2nd_pt_1btag"]->Fill( p4jets[1].Pt(), PUweight );
1353     //hjets["2nd_eta_1btag"]->Fill( p4jets[1].Eta(), PUweight );
1354     //hjets["3rd_pt_1btag"]->Fill( p4jets[2].Pt(), PUweight );
1355     //hjets["4th_pt_1btag"]->Fill( p4jets[3].Pt(), PUweight );
1356     //hjets["Dijet_deltaR_1btag"]->Fill( deltaRjj, PUweight );
1357     //hmuons["N_1btag"]->Fill( total_muons, PUweight );
1358     //hmuons["Nelectrons_1btag"]->Fill( nlooseelectrons, PUweight );
1359     //hmuons["pt_1btag"]->Fill( p4lepton.Pt(), PUweight );
1360     //hmuons["deltaR_1btag"]->Fill( deltaR, PUweight );
1361     //hM["WMt_2jet_1btag"]->Fill( WMt, PUweight );
1362    
1363     //////////////////////////////////////////////////////////////////////////////////
1364    
1365 algomez 1.7 }
1366 algomez 1.13
1367     //} else {
1368     if (fBDT){
1369     mvaInputVal.push_back( Ht );
1370     mvaInputVal.push_back( Stlep );
1371     mvaInputVal.push_back( Stjet );
1372     jet_number = njets;
1373     mvaInputVal.push_back( jet_number );
1374     numBjets_csvl = Nbtags_CSVL;
1375     mvaInputVal.push_back( numBjets_csvl );
1376    
1377    
1378     bdtresponse = mvaReader.GetMvaValue( mvaInputVal );
1379     hMET["bdtresponse"]->Fill( bdtresponse, PUweight );
1380     //////////////////////////////////////////////////////////////////////////////////
1381     }
1382 algomez 1.4 }
1383 algomez 1.6 }
1384 algomez 1.1
1385 algomez 1.13 //if (!fBDT){
1386 algomez 1.9 MyStoreTree->GetGeneralVariable()->Run = ntuple->run;
1387     MyStoreTree->GetGeneralVariable()->Lumi = ntuple->lumi;
1388     MyStoreTree->GetGeneralVariable()->Event = ntuple->event;
1389 algomez 1.8
1390 algomez 1.13 MyStoreTree->GetStoreTree()->Fill();
1391     //}
1392 algomez 1.1 if (fVerbose) cout << "done analysis" << endl;
1393     return kTRUE;
1394     }
1395    
1396     void Analyzer::SlaveTerminate()
1397     {
1398     // The SlaveTerminate() function is called after all entries or objects
1399     // have been processed. When running with PROOF SlaveTerminate() is called
1400     // on each slave server.
1401    
1402     // fill cutflow histogram
1403    
1404     int ibin = 1;
1405     for ( vector<string>::const_iterator ivec= fCutLabels.begin(); ivec != fCutLabels.end(); ++ivec )
1406     // for ( map<string, int >::const_iterator imap=cutmap.begin(); imap!=cutmap.end(); ++imap )
1407     {
1408     hcutflow->SetBinContent( ibin, cutmap[ *ivec ] );
1409     ibin++;
1410     }
1411 algomez 1.8
1412 algomez 1.1 // Write the ntuple to the file
1413     if (fFile) {
1414 algomez 1.8 Bool_t cleanup = kFALSE;
1415     TDirectory *savedir = gDirectory;
1416     if ( h1test->GetEntries() > 0) {
1417     fFile->cd();
1418     h1test->Write();
1419     hcutflow->Write();
1420 algomez 1.13 //if (!fBDT) MyStoreTree->GetStoreTree()->Write();
1421 algomez 1.8 MyStoreTree->GetStoreTree()->Write();
1422     //h2_pt_Wprime->Write();
1423     fFile->mkdir("muons");
1424     fFile->cd("muons");
1425     for ( map<string,TH1* >::const_iterator imap=hmuons.begin(); imap!=hmuons.end(); ++imap ) {
1426     TH1 *temp = imap->second;
1427     if ( temp->GetEntries() > 0 )
1428     temp->Write();
1429     //else cout << "Warning: empty histogram " << temp->GetName() << " will not be written to file." << endl;
1430     }
1431     fFile->cd();
1432     fFile->mkdir("PVs");
1433     fFile->cd("PVs");
1434     for ( map<string,TH1* >::const_iterator imap=hPVs.begin(); imap!=hPVs.end(); ++imap ) {
1435     TH1 *temp = imap->second;
1436     if ( temp->GetEntries() > 0 )
1437     temp->Write();
1438     //else cout << "Warning: empty histogram " << temp->GetName() << " will not be written to file." << endl;
1439     }
1440     fFile->cd();
1441     fFile->mkdir("jets");
1442     fFile->cd("jets");
1443     for ( map<string,TH1* >::const_iterator imap=hjets.begin(); imap!=hjets.end(); ++imap ) {
1444     TH1 *temp = imap->second;
1445     if ( temp->GetEntries() > 0 )
1446     temp->Write();
1447     }
1448     fFile->cd();
1449     fFile->mkdir("mass");
1450     fFile->cd("mass");
1451     for ( map<string,TH1* >::const_iterator imap=hM.begin(); imap!=hM.end(); ++imap ) {
1452     TH1 *temp = imap->second;
1453     if ( temp->GetEntries() > 0 )
1454     temp->Write();
1455     }
1456     fFile->cd();
1457     fFile->mkdir("MET");
1458     fFile->cd("MET");
1459     for ( map<string,TH1* >::const_iterator imap=hMET.begin(); imap!=hMET.end(); ++imap ) {
1460     TH1 *temp = imap->second;
1461     if ( temp->GetEntries() > 0 )
1462     temp->Write();
1463     }
1464     fFile->cd();
1465    
1466     fProofFile->Print();
1467     fOutput->Add(fProofFile);
1468     } else {
1469     cleanup = kTRUE;
1470     }
1471 algomez 1.1
1472    
1473     h1test->SetDirectory(0);
1474     hcutflow->SetDirectory(0);
1475     gDirectory = savedir;
1476     fFile->Close();
1477     // Cleanup, if needed
1478     if (cleanup) {
1479 algomez 1.8 TUrl uf(*(fFile->GetEndpointUrl()));
1480     SafeDelete(fFile);
1481     gSystem->Unlink(uf.GetFile());
1482     SafeDelete(fProofFile);
1483 algomez 1.1 }
1484     }
1485    
1486     }
1487    
1488     void Analyzer::Terminate()
1489     {
1490     // The Terminate() function is the last function to be called during
1491     // a query. It always runs on the client, it can be used to present
1492     // the results graphically or save the results to file.
1493    
1494     Info("Terminate","Analyzer done.");
1495     }