From 2cd8f5d81c6a346c1091c5ca6fd42e5c6e0e8bb5 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 21 Aug 2013 03:29:29 -0500 Subject: [PATCH 001/192] added muon fake rates --- wh/FakeRatesEM.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/wh/FakeRatesEM.py b/wh/FakeRatesEM.py index 3597fa16..95b9039d 100644 --- a/wh/FakeRatesEM.py +++ b/wh/FakeRatesEM.py @@ -71,7 +71,7 @@ def begin(self): denom_histos['electronInfo'] = self.book( os.path.join(region, denom), 'electronInfo', "electronInfo", - 'electronPt:electronJetPt:weight:'+':'.join(self.lepIds), + 'electronPt:electronJetPt:electronJetCSVBtag:numJets20:numJets40:weight:'+':'.join(self.lepIds), type=ROOT.TNtuple) for numerator in self.lepIds: @@ -109,7 +109,7 @@ def book_histo(name, *args, **kwargs): denom_histos['muonInfo'] = self.book( os.path.join(region, denom), 'muonInfo', "muonInfo", - 'muonPt:muonJetPt:muonJetBtag:weight:'+':'.join(self.muon_lepIds), + 'muonPt:muonJetPt:muonJetCSVBtag:numJets20:numJets40:weight:'+':'.join(self.muon_lepIds), type=ROOT.TNtuple) for numerator in self.muon_lepIds: @@ -147,7 +147,8 @@ def preselection(row): if not selections.muSelection(row, 'm'): return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag) if not selections.eSelection(row, 'e'): return False #applies basic selection (eta, pt > 10, DZ, missingHits, jetBTag, HasConversion and chargedIdTight) if not row.eChargeIdTight: return False - if not (row.jetVeto40_DR05 >= 1): return False + #if not (row.jetVeto40_DR05 >= 1): return False + if not (row.jetVeto20 >= 1): return False if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes return True #if self.is7TeV: @@ -171,11 +172,12 @@ def fill(the_histos, row, fillNtuple=False): the_histos['eJetptDvseJetPt'].Fill(max(row.eJetPt, row.ePt),row.eJetptD) if fillNtuple: id_iso_vals = [ float( selections.lepton_id_iso(row, 'e', label) ) for label in self.lepIds] - the_histos['electronInfo'].Fill( array("f", [row.ePt, row.eJetPt, weight]+id_iso_vals) ) + the_histos['electronInfo'].Fill( array("f", [row.ePt, row.eJetPt, max(0, row.eJetCSVBtag), + row.jetVeto20, row.jetVeto40_DR05, weight]+id_iso_vals) ) def fill_muon(the_histos, row, fillNtuple=False): - weight = 1 + weight = 1. if row.run == 1: weight = self.pucorrector(row.nTruePU) *\ mcCorrectors.correct_mueg_mu(row.mPt, row.mAbsEta) * \ @@ -190,11 +192,16 @@ def fill_muon(the_histos, row, fillNtuple=False): pfidiso02 = float( row.mPFIDTight and row.mRelPFIsoDB < 0.2) h2taucuts = float( row.mPFIDTight and ((row.mRelPFIsoDB < 0.15 and row.mAbsEta < 1.479) or row.mRelPFIsoDB < 0.1 )) h2taucuts020 = float( row.mPFIDTight and ((row.mRelPFIsoDB < 0.20 and row.mAbsEta < 1.479) or row.mRelPFIsoDB < 0.15)) - the_histos['muonInfo'].Fill( array("f", [row.mPt, row.mJetPt, row.mJetBtag, weight, pfidiso02, h2taucuts, h2taucuts020] ) ) + + the_histos['muonInfo'].Fill( array("f", [row.mPt, row.mJetPt, max(0, row.mJetCSVBtag), + row.jetVeto20, row.jetVeto40_DR05, weight, + pfidiso02, h2taucuts, h2taucuts020] ) ) def fill_region(region,pt_cut): + if region is None: + return None fill(histos[(region, pt_cut)], row, True) for idlabel, idfcn in selections.electronIds.iteritems(): @@ -211,6 +218,8 @@ def fill_region(region,pt_cut): fill(histos[(region, pt_cut, idlabel+'_h2taucuts020')], row) def fill_muon_region(region, tag): + if region is None: + return None # This is a QCD or Wjets fill_muon(histos[(region, tag)], row, True) @@ -230,9 +239,8 @@ def fill_muon_region(region, tag): if not preselection(row): continue region = control_region(row) - if region is None: - continue - # This is a QCD or Wjets + muon_region = control_region_muon(row) + is7TeV = bool('7TeV' in os.environ['jobid']) use_iso_trigger = not is7TeV mu17e8 = (row.mu17ele8isoPass and row.mPt >= 20) if use_iso_trigger else (row.mu17ele8Pass and row.mPt >= 20) @@ -241,7 +249,6 @@ def fill_muon_region(region, tag): fill_region(region,'pt10') if mu8e17: fill_region(region,'pt20') - muon_region = control_region_muon(row) if muon_region: fill_muon_region(muon_region, 'pt10') if row.mPt > 20: From 5b4d82889fa9b4e1a9688d5253c2aa57b375ee16 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 30 Aug 2013 03:09:21 -0500 Subject: [PATCH 002/192] moved 40GeV jet veto to 20, added #jets in training ntuple --- wh/FakeRatesEE.py | 8 +++++--- wh/FakeRatesEM.py | 2 +- wh/FakeRatesMM.py | 9 ++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/wh/FakeRatesEE.py b/wh/FakeRatesEE.py index abfc4f04..131263c4 100755 --- a/wh/FakeRatesEE.py +++ b/wh/FakeRatesEE.py @@ -57,7 +57,7 @@ def begin(self): denom_histos['electronInfo'] = self.book( os.path.join(region, denom), 'electronInfo', "electronInfo", - 'electronPt:electronJetPt:weight:'+':'.join(self.lepIds), + 'electronPt:electronJetPt:electronJetCSVBtag:numJets20:numJets40:weight:'+':'.join(self.lepIds), type=ROOT.TNtuple) for numerator in self.lepIds: @@ -103,7 +103,8 @@ def preselection(row): if not selections.eSelection(row, 'e1'): return False if not row.e1MVAIDH2TauWP: return False if not selections.eSelection(row, 'e2'): return False - if not (row.jetVeto40_DR05 >= 1): return False + #if not (row.jetVeto40_DR05 >= 1): return False + if not (row.jetVeto20 > 1): return False if not selections.vetos(row): return False return True @@ -135,7 +136,8 @@ def fill(the_histos, row, fillNtuple=False): #print id_iso_vals #print self.lepIds id_iso_vals = [float( i ) for i in id_iso_vals ] - the_histos['electronInfo'].Fill( array("f", [row.e2Pt, row.e2JetPt, weight]+id_iso_vals) ) + the_histos['electronInfo'].Fill( array("f", [row.e2Pt, row.e2JetPt, max(0, row.e2JetCSVBtag), + row.jetVeto20, row.jetVeto40_DR05, weight]+id_iso_vals) ) histos = self.histograms diff --git a/wh/FakeRatesEM.py b/wh/FakeRatesEM.py index 95b9039d..836ae88a 100644 --- a/wh/FakeRatesEM.py +++ b/wh/FakeRatesEM.py @@ -148,7 +148,7 @@ def preselection(row): if not selections.eSelection(row, 'e'): return False #applies basic selection (eta, pt > 10, DZ, missingHits, jetBTag, HasConversion and chargedIdTight) if not row.eChargeIdTight: return False #if not (row.jetVeto40_DR05 >= 1): return False - if not (row.jetVeto20 >= 1): return False + if not (row.jetVeto20 > 1): return False if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes return True #if self.is7TeV: diff --git a/wh/FakeRatesMM.py b/wh/FakeRatesMM.py index 86808db5..ff67891d 100755 --- a/wh/FakeRatesMM.py +++ b/wh/FakeRatesMM.py @@ -57,7 +57,7 @@ def begin(self): denom_histos['muonInfo'] = self.book( os.path.join(region, denom), 'muonInfo', "muonInfo", - 'muonPt:muonJetPt:muonJetCSVBtag:muonPVDXY:weight:'+':'.join(self.lepIds), + 'muonPt:muonJetPt:muonAbsEta:muonJetCSVBtag:muonPVDXY:numJets20:numJets40:weight:'+':'.join(self.lepIds), type=ROOT.TNtuple) for numerator in self.lepIds: @@ -116,7 +116,8 @@ def preselection(row): if not selections.muSelection(row, 'm1'): return False if not selections.muSelection(row, 'm2'): return False if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes - if not (row.jetVeto40_DR05 >= 1): return False + #if not (row.jetVeto40_DR05 >= 1): return False + if not (row.jetVeto20 > 0): return False return True def fill(the_histos, row, fillNtuple=False): @@ -145,7 +146,9 @@ def fill(the_histos, row, fillNtuple=False): pfidiso02 = float( row.m2PFIDTight and row.m2RelPFIsoDB < 0.2) h2taucuts = float( row.m2PFIDTight and ((row.m2RelPFIsoDB < 0.15 and row.m2AbsEta < 1.479) or row.m2RelPFIsoDB < 0.1 )) h2taucuts020 = float( row.m2PFIDTight and ((row.m2RelPFIsoDB < 0.20 and row.m2AbsEta < 1.479) or row.m2RelPFIsoDB < 0.15)) - the_histos['muonInfo'].Fill( array("f", [row.m2Pt, row.m2JetPt, max(0, row.m2JetCSVBtag), abs(row.m2PVDXY), weight, pfidiso02, h2taucuts, h2taucuts020] ) ) + the_histos['muonInfo'].Fill( array("f", [row.m2Pt, row.m2JetPt, row.m2AbsEta, max(0, row.m2JetCSVBtag), + abs(row.m2PVDXY), row.jetVeto20, row.jetVeto40_DR05, weight, + pfidiso02, h2taucuts, h2taucuts020] ) ) histos = self.histograms for row in self.tree: From 7d26ebc74210c4d9eb3d7b7fedb5b79b1a116401 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 30 Aug 2013 03:11:33 -0500 Subject: [PATCH 003/192] added muon fr from EM data, copy pulls in the plots dir --- wh/Rakefile | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/wh/Rakefile b/wh/Rakefile index 7b4e87cd..0c041a1a 100755 --- a/wh/Rakefile +++ b/wh/Rakefile @@ -188,23 +188,23 @@ def make_kNN(chan, datas) ] end -iso_points = ['idiso02', 'h2taucuts', 'h2taucuts020'] -electronIds = ['eid12Loose', 'eid12Medium', 'eid12Tight'] #, 'eid13Loose', 'eid13Tight'] +iso_points = ['h2taucuts', 'h2taucuts020'] #'idiso02', +electronIds = ['eid12Medium', 'eid12Tight'] #, 'eid13Loose', 'eid12Loose', 'eid13Tight'] elewps = electronIds.product(iso_points) elewps = elewps.map{|x,y| "#{x}_#{y}"} pt_regions = ['pt10', 'pt20'] -muonwps = ['h2taucuts', 'h2taucuts020', 'pfidiso02'] +muonwps = ['h2taucuts', 'h2taucuts020'] #, 'pfidiso02'] fr_fits = Hash.new kNN_trains = Hash.new -muon_kNN_vars= ['muonJetPt', 'muonPt', 'muonJetCSVBtag'] #'muonPVDXY'] -electron_kNN_vars= ['electronJetPt', 'electronPt'] +muon_kNN_vars= ['muonJetPt', 'muonPt', 'numJets20'] +electron_kNN_vars= ['electronJetPt', 'electronPt', 'numJets20'] ############# # EM datas ############# emcrs = ['qcd', 'wjets'] -elewps.each do |ele_wp| +elewps.select{|x| x.start_with?('eid12Medium')}.each do |ele_wp| emcrs.each do |cr| pt_regions.each do |ptr| key = "e_#{cr}_#{ptr}_#{ele_wp}_eJetPt" @@ -218,16 +218,16 @@ elewps.each do |ele_wp| end #muon fakes from em -#mmcrs = ['qcd', 'wjets'] -#muonwps.each do |mu_wp| -# mmcrs.each do |cr| -# pt_regions.each do |ptr| -# key = "m_M#{cr}_#{ptr}_#{mu_wp}_muonInfo" -# kNN_trains[key] = make_kNN('em', 'em') -# kNN_trains[key]['vars'] = muon_kNN_vars -# end -# end -#end +mmcrs = ['qcd', 'wjets'] +muonwps.each do |mu_wp| + mmcrs.each do |cr| + pt_regions.each do |ptr| + key = "m_M#{cr}_#{ptr}_#{mu_wp}_muonInfo" + kNN_trains[key] = make_kNN('em', 'em') + kNN_trains[key]['vars'] = muon_kNN_vars + end + end +end ############# @@ -254,6 +254,7 @@ end ############# # MM datas ############# +muon_kNN_vars= ['muonJetPt', 'muonPt', 'numJets20'] mmcrs = ['qcd', 'wjets'] muonwps.each do |mu_wp| mmcrs.each do |cr| @@ -387,7 +388,7 @@ kNN_trains.each do |kNN, info| file knn_output => subsamples_inputs_result_list + [info['analyzer'] + '.py',] do |t| sh "mkdir -p #{$frfit_dir}" - sh "train_kNN.py --files #{subsample_input_list} --outputfile #{knn_output} --tree #{tree_path} --cut #{cut} --variables #{vars_str} --makePlots 0" + sh "train_kNN.py --files #{subsample_input_list} --outputfile #{knn_output} --tree #{tree_path} --cut #{cut} --variables #{vars_str} --makePlots 1" end task :kNN => knn_output kNN_files << knn_output @@ -673,6 +674,7 @@ def make_unc_vals_task(channel, opttag='') Dir.glob("results/#{$jobid}/plots/#{channel}/#{channel}#{opttag}_shapes_*_statshapes.txt").each do |list| category = list.split('/')[-1].split('_')[-2] sh "cat #{list} | xargs -n 1 -I {} echo '#{category} fakes {} 1.0' >> #{t.name}" + #sh "python get_fake_systematic.py #{carddir_channel}/shapes.root #{$categories_map[channel].join(',')} CMS_vhtt_#{category}_fakes_#{$period} >> #{t.name}" end sh "python get_fake_systematic.py #{carddir_channel}/shapes.root #{$categories_map[channel].join(',')} CMS_vhtt_#{channel}_fakes_#{$period} >> #{t.name}" end @@ -1036,6 +1038,7 @@ def make_f3_postfit_plots_task(channel) sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{category} -e 'WH*' -o #{resultdir}/#{category}.png -x #{$xlabels_map[channel]}" sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{category} -e 'WH*' -o #{resultdir}/#{category}.pdf -x #{$xlabels_map[channel]}" end + sh "cp -v #{$carddir}/#{channel}/#{channel}.pulls* #{resultdir}/." sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{$categories_map[channel].join(' ')} -e 'WH*' -o #{resultdir}/#{channel}_categories_summed.png -x #{$xlabels_map[channel]}" sh "touch #{t.name}" end From 8fe93ce844305dbad19bf44155142ef14b66f854 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 30 Aug 2013 03:13:28 -0500 Subject: [PATCH 004/192] added better memory handling, added njets to kNN --- wh/WHAnalyzeEET.py | 20 ++++-- wh/WHAnalyzeEMT.py | 156 +++++++++++++++++++++++++-------------------- wh/WHAnalyzeMMT.py | 149 ++++++++++++++++++++++++------------------- 3 files changed, 186 insertions(+), 139 deletions(-) diff --git a/wh/WHAnalyzeEET.py b/wh/WHAnalyzeEET.py index 7dc5a081..6ea9af94 100755 --- a/wh/WHAnalyzeEET.py +++ b/wh/WHAnalyzeEET.py @@ -17,6 +17,18 @@ from chargeflipcuts import charge_flip_funcs from FinalStateAnalysis.PlotTools.decorators import memo_last +#initialize FRFits +optimizer_keys = [ i for i in optimizer.grid_search.keys() if i.startswith('EET') ] +grid_search = {} +if len(optimizer_keys) > 1: + grid_search[key] = optimizer.grid_search[key] + +for key in optimizer_keys: + frfits.highpt_ee_fr.__activate__(optimizer.grid_search[key]['leading_iso']) + frfits.highpt_ee_qcd_fr.__activate__(optimizer.grid_search[key]['leading_iso']) + frfits.lowpt_ee_fr.__activate__(optimizer.grid_search[key]['subleading_iso']) + frfits.lowpt_ee_qcd_fr.__activate__(optimizer.grid_search[key]['subleading_iso']) + #mtr = frfits.mt_likelihood_ratio ################################################################################ #### Analysis logic ############################################################ @@ -340,19 +352,19 @@ def event_weight(self, row): def obj1_weight(self, row, leadleptonId='eid13Looseh2taucuts', subleadleptonId=None): - return frfits.highpt_ee_fr[leadleptonId](electronJetPt=max(row.e1JetPt, row.e1Pt), electronPt=row.e1Pt) + return frfits.highpt_ee_fr[leadleptonId](electronJetPt=max(row.e1JetPt, row.e1Pt), electronPt=row.e1Pt, numJets20=row.jetVeto20+1) def obj2_weight(self, row, leadleptonId=None, subleadleptonId='eid13Looseh2taucuts'): - return frfits.lowpt_ee_fr[subleadleptonId](electronJetPt=max(row.e2JetPt, row.e2Pt), electronPt=row.e2Pt) + return frfits.lowpt_ee_fr[subleadleptonId](electronJetPt=max(row.e2JetPt, row.e2Pt), electronPt=row.e2Pt, numJets20=row.jetVeto20+1) def obj3_weight(self, row, notUsed1=None, notUsed2=None): return frfits.tau_fr(row.tPt) def obj1_qcd_weight(self, row, leadleptonId='eid13Looseh2taucuts', subleadleptonId=None): - return frfits.highpt_ee_qcd_fr[leadleptonId](electronJetPt=max(row.e1JetPt, row.e1Pt), electronPt=row.e1Pt) + return frfits.highpt_ee_qcd_fr[leadleptonId](electronJetPt=max(row.e1JetPt, row.e1Pt), electronPt=row.e1Pt, numJets20=row.jetVeto20+1) def obj2_qcd_weight(self, row, leadleptonId=None, subleadleptonId='eid13Looseh2taucuts'): - return frfits.lowpt_ee_qcd_fr[subleadleptonId](electronJetPt=max(row.e2JetPt, row.e2Pt), electronPt=row.e2Pt) + return frfits.lowpt_ee_qcd_fr[subleadleptonId](electronJetPt=max(row.e2JetPt, row.e2Pt), electronPt=row.e2Pt, numJets20=row.jetVeto20+1) def obj3_qcd_weight(self, row, notUsed1=None, notUsed2=None): return frfits.tau_qcd_fr(row.tPt) diff --git a/wh/WHAnalyzeEMT.py b/wh/WHAnalyzeEMT.py index 9705b06d..515514d7 100644 --- a/wh/WHAnalyzeEMT.py +++ b/wh/WHAnalyzeEMT.py @@ -12,11 +12,36 @@ import mcCorrectors import baseSelections as selections import fakerate_functions as frfits +from array import array import ROOT import math import optimizer from FinalStateAnalysis.PlotTools.decorators import memo_last +#def make_bins(n, xlow, xhigh): +# step = float(xhigh - xlow) / float(n) +# ret = [] +# for i in xrange(n): +# ret.append(xlow + step*i) +# ret.append(xhigh) +# return array('d', ret) + +#initialize FRFits +optimizer_keys = [ i for i in optimizer.grid_search.keys() if i.startswith('EMT') ] +grid_search = {} +if len(optimizer_keys) > 1: + grid_search[key] = optimizer.grid_search[key] + +for key in optimizer_keys: + frfits.highpt_mu_fr[optimizer.grid_search[key]['leading_iso']] + frfits.highpt_mu_qcd_fr[optimizer.grid_search[key]['leading_iso']] + frfits.lowpt_mu_fr[optimizer.grid_search[key]['leading_iso']] + frfits.lowpt_mu_qcd_fr[optimizer.grid_search[key]['leading_iso']] + frfits.highpt_e_fr[optimizer.grid_search[key]['subleading_iso']] + frfits.highpt_e_qcd_fr[optimizer.grid_search[key]['subleading_iso']] + frfits.lowpt_e_fr[optimizer.grid_search[key]['subleading_iso']] + frfits.lowpt_e_qcd_fr[optimizer.grid_search[key]['subleading_iso']] + ################################################################################ #### Analysis logic ############################################################ ################################################################################ @@ -58,27 +83,27 @@ def sub_mass(row, weight): lead_iso = self.grid_search['']['leading_iso'] sublead_iso = self.grid_search['']['subleading_iso'] - def f_prob(row, weight): - p_m = ( self.obj1_weight(row, lead_iso, sublead_iso) + \ - self.obj1_qcd_weight(row, lead_iso, sublead_iso))/2 - p_e = ( self.obj2_weight(row, lead_iso, sublead_iso) + \ - self.obj2_qcd_weight(row, lead_iso, sublead_iso))/2 - p_t = frfits.tau_fr(row.tPt) - return ((p_m + p_e*(1 - p_m) + p_t*(1 - p_m)*(1 - p_e)), weight) - - def log_prob(row, weight): - prob, weight = f_prob(row, weight) - return math.log(prob), weight + #def f_prob(row, weight): + # p_m = ( self.obj1_weight(row, lead_iso, sublead_iso) + \ + # self.obj1_qcd_weight(row, lead_iso, sublead_iso))/2 + # p_e = ( self.obj2_weight(row, lead_iso, sublead_iso) + \ + # self.obj2_qcd_weight(row, lead_iso, sublead_iso))/2 + # p_t = frfits.tau_fr(row.tPt) + # return ((p_m + p_e*(1 - p_m) + p_t*(1 - p_m)*(1 - p_e)), weight) + # + #def log_prob(row, weight): + # prob, weight = f_prob(row, weight) + # return math.log(prob), weight - self.hfunc['faking_prob'] = f_prob - self.hfunc['log_prob'] = log_prob - self.hfunc["subMass#faking_prob"] = merge_functions( sub_mass, f_prob ) - self.hfunc["subMass#log_prob" ] = merge_functions( sub_mass, log_prob) + #self.hfunc['faking_prob'] = f_prob + #self.hfunc['log_prob'] = log_prob + #self.hfunc["subMass#faking_prob"] = merge_functions( sub_mass, f_prob ) + #self.hfunc["subMass#log_prob" ] = merge_functions( sub_mass, log_prob) self.hfunc["subMass#LT" ] = merge_functions( sub_mass, attr_getter('LT')) self.hfunc["subMass#tPt"] = merge_functions( sub_mass, attr_getter('tPt')) - self.hfunc["subMass*#faking_prob"] = merge_functions( mass_scaler( sub_mass ), f_prob ) - self.hfunc["subMass*#log_prob" ] = merge_functions( mass_scaler( sub_mass ), log_prob) + #self.hfunc["subMass*#faking_prob"] = merge_functions( mass_scaler( sub_mass ), f_prob ) + #self.hfunc["subMass*#log_prob" ] = merge_functions( mass_scaler( sub_mass ), log_prob) self.hfunc["subMass*#LT" ] = merge_functions( mass_scaler( sub_mass ), attr_getter('LT')) self.hfunc["subMass*#tPt"] = merge_functions( mass_scaler( sub_mass ), attr_getter('tPt')) @@ -102,74 +127,73 @@ def log_prob(row, weight): def book_histos(self, folder): for key in self.grid_search: prefix = key+'$' if key else '' - self.book(folder, prefix+"subMass", "Subleading Mass", 200, 0, 200) + #self.book(folder, prefix+"subMass", "Subleading Mass", 200, 0, 200) self.book(folder, prefix+"LT", "L_T", 100, 0, 300) #Charge mis-id special histograms - if 'c2' in folder: - self.book(folder, prefix+"subMass*", "Subleading Mass", 200, 0, 200) + #if 'c2' in folder: + # self.book(folder, prefix+"subMass*", "Subleading Mass", 200, 0, 200) if len(self.grid_search.keys()) == 1: + LTBinning = array('d',[0, 80, 130, 600]) + nLTBins = len(LTBinning) -1 if 'c2' in folder: self.book(folder, "e*_t_Mass", "Electron-Tau Mass", 200, 0, 200) self.book(folder, "e*_m_Mass", "Electron-Muon Mass", 200, 0, 200) #self.book(folder, "subMass*#faking_prob", '', 200, 0, 200, 220, 0., 1.1, type=ROOT.TH2F) #self.book(folder, "subMass*#log_prob" , '', 200, 0, 200, 200, -2, 1, type=ROOT.TH2F) - self.book(folder, "subMass*#LT" , '', 200, 0, 200, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, "subMass*#tPt" , '', 200, 0, 200, 200, 0, 200, type=ROOT.TH2F) - + self.book(folder, "subMass*#LT" , '', 200, 0, 200, nLTBins, LTBinning, type=ROOT.TH2F) - self.book(folder, prefix+"subMass#LT" , "subleadingMass", 200, 0, 200, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"subMass#tPt", "subleadingMass", 200, 0, 200, 200, 0, 200, type=ROOT.TH2F) + self.book(folder, prefix+"subMass#LT" , "subleadingMass", 200, 0, 200, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "e_m_Mass#LT", "Electron-Muon Mass", 200, 0, 200, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "m_t_Mass#LT", "Electron-Muon Mass", 200, 0, 200, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "e_t_Mass#LT", "Electron-Tau Mass" , 200, 0, 200, nLTBins, LTBinning, type=ROOT.TH2F) #Pt - self.book(folder, prefix+"mPt#LT" , "subleadingMass", 150, 0, 150, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"ePt#LT" , "subleadingMass", 150, 0, 150, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"tPt#LT" , "subleadingMass", 150, 0, 150, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"mJetPt#LT" , "subleadingMass", 150, 0, 150, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"eJetPt#LT" , "subleadingMass", 150, 0, 150, 120, 0, 600, type=ROOT.TH2F) + self.book(folder, prefix+"mPt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, prefix+"ePt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, prefix+"tPt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, prefix+"mJetPt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, prefix+"eJetPt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) #eta - self.book(folder, prefix+"mAbsEta#LT" , "subleadingMass", 100, 0, 2.5, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"eAbsEta#LT" , "subleadingMass", 100, 0, 2.5, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"tAbsEta#LT" , "subleadingMass", 100, 0, 2.5, 120, 0, 600, type=ROOT.TH2F) + self.book(folder, prefix+"mAbsEta#LT" , "subleadingMass", 100, 0, 2.5, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, prefix+"eAbsEta#LT" , "subleadingMass", 100, 0, 2.5, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, prefix+"tAbsEta#LT" , "subleadingMass", 100, 0, 2.5, nLTBins, LTBinning, type=ROOT.TH2F) #DR - self.book(folder, prefix+"m_t_DR#LT" , "subleadingMass", 100, 0, 10, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"e_t_DR#LT" , "subleadingMass", 100, 0, 10, 120, 0, 600, type=ROOT.TH2F) + self.book(folder, prefix+"m_t_DR#LT" , "subleadingMass", 100, 0, 10, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, prefix+"e_t_DR#LT" , "subleadingMass", 100, 0, 10, nLTBins, LTBinning, type=ROOT.TH2F) #Jet BTag - self.book(folder, "mJetBtag#LT", "Muon 2 Pt", 30, -10, 5, 60, 0, 600, type=ROOT.TH2F) - self.book(folder, "eJetBtag#LT", "Muon 2 Pt", 30, -10, 5, 60, 0, 600, type=ROOT.TH2F) + self.book(folder, "mJetBtag#LT", "Muon 2 Pt", 30, -10, 5, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "eJetBtag#LT", "Muon 2 Pt", 30, -10, 5, nLTBins, LTBinning, type=ROOT.TH2F) self.book(folder, "subPt" , "SubLeading Pt", 100, 0, 100) self.book(folder, "leadPt" , "Leading Pt" , 100, 0, 100) self.book(folder, "subJetPt" , "SubLeading Pt", 100, 0, 100) self.book(folder, "leadJetPt" , "Leading Pt" , 100, 0, 100) - self.book(folder, "e_m_Mass", "Electron-Muon Mass", 200, 0, 200) - self.book(folder, "m_t_Mass", "Electron-Muon Mass", 200, 0, 200) - self.book(folder, "e_t_Mass", "Electron-Tau Mass", 200, 0, 200) self.book(folder, "nTruePU", "NPU", 62, -1.5, 60.5) - self.book(folder, "mPt", "Muon Pt", 100, 0, 100) - self.book(folder, "ePt", "Electron Pt", 100, 0, 100) - self.book(folder, "mJetPt", "Muon Pt", 100, 0, 100) - self.book(folder, "eJetPt", "Electron Pt", 100, 0, 100) - self.book(folder, "tPt", "Tau Pt", 100, 0, 100) - self.book(folder, "mAbsEta", "Muon AbsEta", 100, 0, 2.4) - self.book(folder, "eAbsEta", "Electron AbsEta", 100, 0, 2.5) - self.book(folder, "tAbsEta", "Tau AbsEta", 100, 0, 2.3) + #self.book(folder, "mPt", "Muon Pt", 100, 0, 100) + #self.book(folder, "ePt", "Electron Pt", 100, 0, 100) + #self.book(folder, "mJetPt", "Muon Pt", 100, 0, 100) + #self.book(folder, "eJetPt", "Electron Pt", 100, 0, 100) + #self.book(folder, "tPt", "Tau Pt", 100, 0, 100) + #self.book(folder, "mAbsEta", "Muon AbsEta", 100, 0, 2.4) + #self.book(folder, "eAbsEta", "Electron AbsEta", 100, 0, 2.5) + #self.book(folder, "tAbsEta", "Tau AbsEta", 100, 0, 2.3) self.book(folder, "eChargeIdTight", "Elec charge ID tight", 2, -0.5, 1.5) self.book(folder, "tLeadDR", "DR between leading lepton and tau", 100, 0, 5) self.book(folder, "tSubDR", "DR between subleading lepton and tau", 100, 0, 5) self.book(folder, "e_m_DR", "", 200, 0, 5) - self.book(folder, "m_t_DR", "", 200, 0, 5) - self.book(folder, "e_t_DR", "", 200, 0, 5) + #self.book(folder, "m_t_DR", "", 200, 0, 5) + #self.book(folder, "e_t_DR", "", 200, 0, 5) #let's look for osme other possible selections - self.book(folder, "Mass" , "mass" , 800, 0, 800 ) - self.book(folder, "pt_ratio" , "pt_ratio" , 100, 0, 1) - self.book(folder, "tToMETDPhi" , "tToMETDPhi" , 100, 0, 4) - self.book(folder, "type1_pfMetEt" , "metEt" , 300, 0, 2000) + #self.book(folder, "Mass" , "mass" , 800, 0, 800 ) + #self.book(folder, "pt_ratio" , "pt_ratio" , 100, 0, 1) + #self.book(folder, "tToMETDPhi" , "tToMETDPhi" , 100, 0, 4) + #self.book(folder, "type1_pfMetEt" , "metEt" , 300, 0, 2000) #There is no call to self, so just promote it to statucmethod, to allow usage by other dedicated analyzers @@ -238,7 +262,7 @@ def preselection( self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr if not row.eChargeIdTight: return False #cut_flow_trk.Fill('ChargeIdTight') - if e_m_Mass < 20: return False + if row.e_m_Mass < 20: return False cut_flow_trk.Fill('charge_fakes') #no charge fakes here #FIXME: ONLY FOR CUT-FLOW PRODUCTION @@ -306,16 +330,16 @@ def event_weight(self, row): def obj1_weight(self, row, ledleptonId='h2taucuts', subledleptonId='h2taucuts'): mu17e8 = (row.mu17ele8isoPass and row.mPt >= 20) if use_iso_trigger else (row.mu17ele8Pass and row.mPt >= 20) if mu17e8: - return frfits.highpt_mu_fr[ledleptonId](muonJetPt=max(row.mJetPt, row.mPt), muonPt=row.mPt, muonJetCSVBtag=max(0, row.mJetCSVBtag)) + return frfits.highpt_mue_fr[ledleptonId](muonJetPt=max(row.mJetPt, row.mPt), muonPt=row.mPt, numJets20=row.jetVeto20+1) # else: - return frfits.lowpt_mu_fr[ledleptonId](muonJetPt=max(row.mJetPt, row.mPt), muonPt=row.mPt, muonJetCSVBtag=max(0, row.mJetCSVBtag)) + return frfits.lowpt_mue_fr[ledleptonId](muonJetPt=max(row.mJetPt, row.mPt), muonPt=row.mPt, numJets20=row.jetVeto20+1) # def obj2_weight(self, row, ledleptonId='h2taucuts', subledleptonId='h2taucuts'): mu17e8 = (row.mu17ele8isoPass and row.mPt >= 20) if use_iso_trigger else (row.mu17ele8Pass and row.mPt >= 20) if mu17e8: - return frfits.lowpt_e_fr[subledleptonId](electronJetPt=max(row.eJetPt, row.ePt), electronPt=row.ePt) + return frfits.lowpt_e_fr[subledleptonId](electronJetPt=max(row.eJetPt, row.ePt), electronPt=row.ePt, numJets20=row.jetVeto20+1) else: - return frfits.highpt_e_fr[subledleptonId](electronJetPt=max(row.eJetPt, row.ePt), electronPt=row.ePt) + return frfits.highpt_e_fr[subledleptonId](electronJetPt=max(row.eJetPt, row.ePt), electronPt=row.ePt, numJets20=row.jetVeto20+1) def obj3_weight(self, row, notUsed1=None, notUsed2=None): return frfits.tau_fr(row.tPt) @@ -323,16 +347,16 @@ def obj3_weight(self, row, notUsed1=None, notUsed2=None): def obj1_qcd_weight(self, row, ledleptonId='h2taucuts', subledleptonId='h2taucuts'): mu17e8 = (row.mu17ele8isoPass and row.mPt >= 20) if use_iso_trigger else (row.mu17ele8Pass and row.mPt >= 20) if mu17e8: - return frfits.highpt_mu_qcd_fr[ledleptonId](muonJetPt=max(row.mJetPt, row.mPt), muonPt=row.mPt, muonJetCSVBtag=max(0, row.mJetCSVBtag)) + return frfits.highpt_mue_qcd_fr[ledleptonId](muonJetPt=max(row.mJetPt, row.mPt), muonPt=row.mPt, numJets20=row.jetVeto20+1) # else: - return frfits.lowpt_mu_qcd_fr[ledleptonId](muonJetPt=max(row.mJetPt, row.mPt), muonPt=row.mPt, muonJetCSVBtag=max(0, row.mJetCSVBtag)) + return frfits.lowpt_mue_qcd_fr[ledleptonId](muonJetPt=max(row.mJetPt, row.mPt), muonPt=row.mPt, numJets20=row.jetVeto20+1) # def obj2_qcd_weight(self, row, ledleptonId='h2taucuts', subledleptonId='h2taucuts'): mu17e8 = (row.mu17ele8isoPass and row.mPt >= 20) if use_iso_trigger else (row.mu17ele8Pass and row.mPt >= 20) if mu17e8: - return frfits.lowpt_e_qcd_fr[subledleptonId](electronJetPt=max(row.eJetPt, row.ePt), electronPt=row.ePt) + return frfits.lowpt_e_qcd_fr[subledleptonId](electronJetPt=max(row.eJetPt, row.ePt), electronPt=row.ePt, numJets20=row.jetVeto20+1) else: - return frfits.highpt_e_qcd_fr[subledleptonId](electronJetPt=max(row.eJetPt, row.ePt), electronPt=row.ePt) + return frfits.highpt_e_qcd_fr[subledleptonId](electronJetPt=max(row.eJetPt, row.ePt), electronPt=row.ePt, numJets20=row.jetVeto20+1) def obj3_qcd_weight(self, row, notUsed1=None, notUsed2=None): return frfits.tau_qcd_fr(row.tPt) @@ -346,17 +370,11 @@ def obj1_obj3_SS(self, row): ## return 0 def obj2_charge_flip(self, row, ledleptonId='h2taucuts', subledleptonId='h2taucuts'): - if ledleptonId.startswith('lead4muon_'): - ledleptonId = subledleptonId - subledleptonId = subledleptonId return frfits.e_charge_flip[ledleptonId](row.eAbsEta,row.ePt) \ if row.ePt > row.mPt else \ frfits.e_charge_flip[subledleptonId](row.eAbsEta,row.ePt) def obj2_charge_flip_sysup(self, row, ledleptonId='h2taucuts', subledleptonId='h2taucuts'): - if ledleptonId.startswith('lead4muon_'): - ledleptonId = subledleptonId - subledleptonId = subledleptonId return frfits.e_charge_flip_up[ledleptonId](row.eAbsEta,row.ePt) \ if row.ePt > row.mPt else \ frfits.e_charge_flip_up[subledleptonId](row.eAbsEta,row.ePt) \ diff --git a/wh/WHAnalyzeMMT.py b/wh/WHAnalyzeMMT.py index 64272203..50f5b22e 100755 --- a/wh/WHAnalyzeMMT.py +++ b/wh/WHAnalyzeMMT.py @@ -12,8 +12,25 @@ import baseSelections as selections import fakerate_functions as frfits import math +from array import array from FinalStateAnalysis.PlotTools.decorators import memo_last import optimizer + +#initialize FRFits +optimizer_keys = [ i for i in optimizer.grid_search.keys() if i.startswith('MMT') ] +print optimizer_keys +grid_search = {} +if len(optimizer_keys) > 1: + grid_search[key] = optimizer.grid_search[key] + +for key in optimizer_keys: + frfits.highpt_mu_fr.__activate__(optimizer.grid_search[key]['leading_iso']) + frfits.highpt_mu_qcd_fr.__activate__(optimizer.grid_search[key]['leading_iso']) + frfits.lowpt_mu_fr.__activate__(optimizer.grid_search[key]['subleading_iso']) + frfits.lowpt_mu_qcd_fr.__activate__(optimizer.grid_search[key]['subleading_iso']) + + + ################################################################################ #### Analysis logic ############################################################ ################################################################################ @@ -40,31 +57,31 @@ def f(row, weight): lead_iso = self.grid_search['']['leading_iso'] sublead_iso = self.grid_search['']['subleading_iso'] - @memo_last - def f_par_prob(m1Pt, m1JetPt, - m2Pt, m2JetPt, - tPt): - p_m1 = (( frfits.highpt_mu_fr[lead_iso](muonJetPt=max(m1JetPt, m1Pt), muonPt=m1Pt) +\ - frfits.highpt_mu_qcd_fr[lead_iso](muonJetPt=max(m1JetPt, m1Pt), muonPt=m1Pt) )/2) - p_m2 = (( frfits.lowpt_mu_fr[sublead_iso](muonJetPt=max(m2JetPt, m2Pt), muonPt=m2Pt) + \ - frfits.lowpt_mu_qcd_fr[sublead_iso](muonJetPt=max(m2JetPt, m2Pt), muonPt=m2Pt))/2) - p_t = frfits.tau_fr(tPt) - return (p_m1 + p_m2*(1 - p_m1) + p_t*(1 - p_m1)*(1 - p_m2)) - - def f_prob(row, weight): - val = f_par_prob(row.m1Pt, row.m1JetPt, - row.m2Pt, row.m2JetPt, - row.tPt) - return val, weight - - def log_prob(row, weight): - prob, weight = f_prob(row, weight) - return ROOT.TMath.Log10(prob), weight + #@memo_last + #def f_par_prob(m1Pt, m1JetPt, + # m2Pt, m2JetPt, + # tPt): + # p_m1 = (( frfits.highpt_mu_fr[lead_iso](muonJetPt=max(m1JetPt, m1Pt), muonPt=m1Pt) +\ + # frfits.highpt_mu_qcd_fr[lead_iso](muonJetPt=max(m1JetPt, m1Pt), muonPt=m1Pt) )/2) + # p_m2 = (( frfits.lowpt_mu_fr[sublead_iso](muonJetPt=max(m2JetPt, m2Pt), muonPt=m2Pt) + \ + # frfits.lowpt_mu_qcd_fr[sublead_iso](muonJetPt=max(m2JetPt, m2Pt), muonPt=m2Pt))/2) + # p_t = frfits.tau_fr(tPt) + # return (p_m1 + p_m2*(1 - p_m1) + p_t*(1 - p_m1)*(1 - p_m2)) + # + #def f_prob(row, weight): + # val = f_par_prob(row.m1Pt, row.m1JetPt, + # row.m2Pt, row.m2JetPt, + # row.tPt) + # return val, weight + # + #def log_prob(row, weight): + # prob, weight = f_prob(row, weight) + # return ROOT.TMath.Log10(prob), weight - self.hfunc['faking_prob'] = f_prob - self.hfunc['log_prob'] = log_prob - self.hfunc["m2_t_Mass#faking_prob"] = merge_functions( attr_getter('m2_t_Mass'), f_prob ) - self.hfunc["m2_t_Mass#log_prob" ] = merge_functions( attr_getter('m2_t_Mass'), log_prob) + #self.hfunc['faking_prob'] = f_prob + #self.hfunc['log_prob'] = log_prob + #self.hfunc["m2_t_Mass#faking_prob"] = merge_functions( attr_getter('m2_t_Mass'), f_prob ) + #self.hfunc["m2_t_Mass#log_prob" ] = merge_functions( attr_getter('m2_t_Mass'), log_prob) self.hfunc['subMTMass'] = lambda row, weight: (row.m2_t_Mass, weight) if row.m1MtToMET > row.m2MtToMET else (row.m1_t_Mass, weight) #maps the name of non-trivial histograms to a function to get the proper value, the function MUST have two args (evt and weight). Used in WHAnalyzerBase.fill_histos later self.hfunc['pt_ratio' ] = lambda row, weight: (row.m2Pt/row.m1Pt, weight) @@ -72,66 +89,63 @@ def log_prob(row, weight): self.pucorrector = mcCorrectors.make_puCorrector('doublemu') def book_histos(self, folder): + LTBinning = array('d',[0, 80, 130, 600]) + nLTBins = len(LTBinning) -1 for key in self.grid_search: prefix = key+'$' if key else '' - self.book(folder, prefix+"m2_t_Mass", "subleadingMass", 200, 0, 200) + #self.book(folder, prefix+"m2_t_Mass", "subleadingMass", 200, 0, 200) self.book(folder, prefix+"LT" , "LT" , 100, 0., 500) self.book(folder, prefix+"m2_t_Pt", "subleadingPt", 400, 0, 400) if len(self.grid_search.keys()) == 1: self.book(folder, "m2_t_Mass#LT" , "subleadingMass", 200, 0, 200, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, "m2_t_Mass#tPt", "subleadingMass", 200, 0, 200, 200, 0, 200, type=ROOT.TH2F) - #self.book(folder, "m2_t_Mass#faking_prob" , "subleadingMass", 200, 0, 200, 1100, 0., 1.1, type=ROOT.TH2F) - #self.book(folder, "m2_t_Mass#log_prob" , "subleadingMass", 200, 0, 200, 1000, -10, 1, type=ROOT.TH2F) - #self.book(folder, 'faking_prob' , "", 1100, 0., 1.1) - #self.book(folder, 'log_prob' , "", 1000, -10, 1) #Pt - self.book(folder, "m1Pt#LT" , "subleadingMass", 150, 0, 150, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, "tPt#LT" , "subleadingMass", 150, 0, 150, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, "m2Pt#LT" , "subleadingMass", 150, 0, 150, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, "m1JetPt#LT" , "subleadingMass", 150, 0, 150, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, "m2JetPt#LT" , "subleadingMass", 150, 0, 150, 120, 0, 600, type=ROOT.TH2F) + self.book(folder, "m1Pt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "tPt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "m2Pt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "m1JetPt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "m2JetPt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) #eta - self.book(folder, "m1AbsEta#LT" , "subleadingMass", 100, 0, 2.5, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, "m2AbsEta#LT" , "subleadingMass", 100, 0, 2.5, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, "tAbsEta#LT" , "subleadingMass", 100, 0, 2.5, 120, 0, 600, type=ROOT.TH2F) + self.book(folder, "m1AbsEta#LT" , "subleadingMass", 100, 0, 2.5, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "m2AbsEta#LT" , "subleadingMass", 100, 0, 2.5, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "tAbsEta#LT" , "subleadingMass", 100, 0, 2.5, nLTBins, LTBinning, type=ROOT.TH2F) #DR - self.book(folder, "m1_t_DR#LT" , "subleadingMass", 100, 0, 10, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, "m2_t_DR#LT" , "subleadingMass", 100, 0, 10, 120, 0, 600, type=ROOT.TH2F) - + self.book(folder, "m1_t_DR#LT" , "subleadingMass", 100, 0, 10, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "m2_t_DR#LT" , "subleadingMass", 100, 0, 10, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "m1_m2_DR#LT", "subleadingMass", 100, 0, 10, nLTBins, LTBinning, type=ROOT.TH2F) + #Jet BTag - self.book(folder, "m2JetBtag#LT", "Muon 2 Pt", 100, -100, 100, 60, 0, 600, type=ROOT.TH2F) - self.book(folder, "m1JetBtag#LT", "Muon 2 Pt", 100, -100, 100, 60, 0, 600, type=ROOT.TH2F) - self.book(folder, "m1JetCSVBtag#LT", "Muon 2 Pt", 120, -5, 1, 60, 0, 600, type=ROOT.TH2F) - self.book(folder, "m2JetCSVBtag#LT", "Muon 2 Pt", 120, -5, 1, 60, 0, 600, type=ROOT.TH2F) - + self.book(folder, "m2JetBtag#LT", "Muon 2 Pt", 100, -100, 100, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "m1JetBtag#LT", "Muon 2 Pt", 100, -100, 100, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "m1JetCSVBtag#LT", "Muon 2 Pt", 120, -5, 1 , nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "m2JetCSVBtag#LT", "Muon 2 Pt", 120, -5, 1 , nLTBins, LTBinning, type=ROOT.TH2F) #Mt To MET - self.book(folder, "m1MtToMET#LT", "Muon 2 Pt", 150, 0, 150, 60, 0, 600, type=ROOT.TH2F) - self.book(folder, "m2MtToMET#LT", "Muon 2 Pt", 150, 0, 150, 60, 0, 600, type=ROOT.TH2F) + self.book(folder, "m1MtToMET#LT", "Muon 2 Pt", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "m2MtToMET#LT", "Muon 2 Pt", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) self.book(folder, "m2RelPFIsoDB", "m2Iso", 100, 0, 0.3) self.book(folder, "m1_t_Mass", "leadingMass", 200, 0, 200) self.book(folder, "m1_m2_Mass", "Muon 1-2 Mass", 120, 0, 120) - self.book(folder, "m2_t_DR", "m2_t_DR", 100, 0, 5) - self.book(folder, "m1_t_DR", "m1_t_DR", 100, 0, 5) + #self.book(folder, "m2_t_DR", "m2_t_DR", 100, 0, 5) + #self.book(folder, "m1_t_DR", "m1_t_DR", 100, 0, 5) - self.book(folder, "m1JetPt", "Muon 1 Jet Pt", 100, 0, 200) - self.book(folder, "m2JetPt", "Muon 2 Jet Pt", 100, 0, 200) + #self.book(folder, "m1JetPt", "Muon 1 Jet Pt", 100, 0, 200) + #self.book(folder, "m2JetPt", "Muon 2 Jet Pt", 100, 0, 200) # Rank muons by less MT to MET, for WZ control region self.book(folder, "weight", "Event weight", 100, 0, 5) self.book(folder, "rho", "Fastjet #rho", 100, 0, 25) self.book(folder, "nvtx", "Number of vertices", 31, -0.5, 30.5) - self.book(folder, "m1Pt", "Muon 1 Pt", 100, 0, 100) - self.book(folder, "m2Pt", "Muon 2 Pt", 100, 0, 100) - self.book(folder, "m1AbsEta", "Muon 1 AbsEta", 100, 0, 2.4) - self.book(folder, "m2AbsEta", "Muon 2 AbsEta", 100, 0, 2.4) - self.book(folder, "tPt", "Tau Pt", 100, 0, 100) - self.book(folder, "tAbsEta", "Tau AbsEta", 100, 0, 2.3) + #self.book(folder, "m1Pt", "Muon 1 Pt", 100, 0, 100) + #self.book(folder, "m2Pt", "Muon 2 Pt", 100, 0, 100) + #self.book(folder, "m1AbsEta", "Muon 1 AbsEta", 100, 0, 2.4) + #self.book(folder, "m2AbsEta", "Muon 2 AbsEta", 100, 0, 2.4) + #self.book(folder, "tPt", "Tau Pt", 100, 0, 100) + #self.book(folder, "tAbsEta", "Tau AbsEta", 100, 0, 2.3) self.book(folder, "subMTMass", "subMTMass", 200, 0, 200) #self.book(folder, "tDecayMode", "Tau AbsEta", 15, -0.5, 14.5) self.book(folder, "nTruePU", "NPU", 62, -1.5, 60.5) @@ -141,10 +155,10 @@ def book_histos(self, folder): self.book(folder, "doubleMuPrescale", "HLT prescale", 26, -5.5, 20.5) #let's look for osme other possible selections - self.book(folder, "pt_ratio" , "pt_ratio" , 100, 0, 1) - self.book(folder, "tToMETDPhi" , "tToMETDPhi" , 100, 0, 4) - self.book(folder, "Mass" , "mass" , 800, 0, 800 ) - self.book(folder, "type1_pfMetEt" , "metEt" , 300, 0, 2000) + #self.book(folder, "pt_ratio" , "pt_ratio" , 100, 0, 1) + #self.book(folder, "tToMETDPhi" , "tToMETDPhi" , 100, 0, 4) + #self.book(folder, "Mass" , "mass" , 800, 0, 800 ) + #self.book(folder, "type1_pfMetEt" , "metEt" , 300, 0, 2000) def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = 0.): ''' Preselection applied to events. @@ -160,6 +174,9 @@ def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = if not ( double_mu_pass or double_muTrk_pass ): return False cut_flow_trk.Fill('trigger') + #TEST + if row.m2_t_DR < 1: return False + if row.m1Pt < row.m2Pt: return False if row.m1Pt < 20: return False if not selections.muSelection(row, 'm1'): return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag) @@ -244,19 +261,19 @@ def event_weight(self, row): mcCorrectors.double_muon_trigger(row,'m1','m2') def obj1_weight(self, row, ledleptonId='h2taucuts', subledleptonId=None): - return frfits.highpt_mu_fr[ledleptonId](muonJetPt=max(row.m1JetPt, row.m1Pt), muonPt=row.m1Pt, muonJetCSVBtag=max(0, row.m1JetCSVBtag)) #muonPVDXY=row.m1PVDXY) #, muonJetBtag=row.m1JetBtag) + return frfits.highpt_mu_fr[ledleptonId](muonJetPt=max(row.m1JetPt, row.m1Pt), muonPt=row.m1Pt, numJets20=row.jetVeto20+1) # def obj2_weight(self, row, ledleptonId=None, subledleptonId='h2taucuts'): - return frfits.lowpt_mu_fr[subledleptonId](muonJetPt=max(row.m2JetPt, row.m2Pt), muonPt=row.m2Pt, muonJetCSVBtag=max(0, row.m2JetCSVBtag)) #, muonPVDXY=row.m2PVDXY) #, muonJetBtag=row.m2JetBtag) + return frfits.lowpt_mu_fr[subledleptonId](muonJetPt=max(row.m2JetPt, row.m2Pt), muonPt=row.m2Pt, numJets20=row.jetVeto20+1) # def obj3_weight(self, row, notUsed1=None, notUsed2=None): return frfits.tau_fr(row.tPt) def obj1_qcd_weight(self, row, ledleptonId='h2taucuts', subledleptonId=None): - return frfits.highpt_mu_qcd_fr[ledleptonId](muonJetPt=max(row.m1JetPt, row.m1Pt), muonPt=row.m1Pt, muonJetCSVBtag=max(0, row.m1JetCSVBtag)) #, muonPVDXY=row.m1PVDXY) #, muonJetBtag=row.m1JetBtag) + return frfits.highpt_mu_qcd_fr[ledleptonId](muonJetPt=max(row.m1JetPt, row.m1Pt), muonPt=row.m1Pt, numJets20=row.jetVeto20+1) # def obj2_qcd_weight(self, row, ledleptonId=None, subledleptonId='h2taucuts'): - return frfits.lowpt_mu_qcd_fr[subledleptonId](muonJetPt=max(row.m2JetPt, row.m2Pt), muonPt=row.m2Pt, muonJetCSVBtag=max(0, row.m2JetCSVBtag)) #, muonPVDXY=row.m2PVDXY) #, muonJetBtag=row.m2JetBtag) + return frfits.lowpt_mu_qcd_fr[subledleptonId](muonJetPt=max(row.m2JetPt, row.m2Pt), muonPt=row.m2Pt, numJets20=row.jetVeto20+1) # def obj3_qcd_weight(self, row, notUsed1=None, notUsed2=None): return frfits.tau_qcd_fr(row.tPt) From fff50cf21b25e533374040f64bd88b322e97a6fc Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 30 Aug 2013 03:14:02 -0500 Subject: [PATCH 005/192] added differential plots --- wh/WHPlotterBase.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wh/WHPlotterBase.py b/wh/WHPlotterBase.py index 4e29d70b..869f6e59 100644 --- a/wh/WHPlotterBase.py +++ b/wh/WHPlotterBase.py @@ -19,6 +19,7 @@ from FinalStateAnalysis.PlotTools.MedianView import MedianView from FinalStateAnalysis.PlotTools.ProjectionView import ProjectionView from FinalStateAnalysis.PlotTools.FixedIntegralView import FixedIntegralView +from FinalStateAnalysis.PlotTools.DifferentialView import DifferentialView from FinalStateAnalysis.PlotTools.RebinView import RebinView from FinalStateAnalysis.MetaData.data_styles import data_styles, colors from FinalStateAnalysis.PlotTools.decorators import memo @@ -721,7 +722,7 @@ def plot_final(self, variable, rebin=1, xaxis='', maxy=24, show_error=False, qcd_correction=False, stack_higgs=True, qcd_weight_fraction=0.5, x_range=None, show_charge_fakes=False, leftside_legend=False, higgs_xsec_multiplier=5, project=None, - project_axis=None, **kwargs): + project_axis=None, differential=False, **kwargs): ''' Plot the final output - with bkg. estimation ''' show_charge_fakes = show_charge_fakes if 'show_charge_fakes' not in self.defaults else self.defaults['show_charge_fakes'] sig_view = self.make_signal_views(unblinded=(not self.blind), @@ -729,6 +730,9 @@ def plot_final(self, variable, rebin=1, xaxis='', maxy=24, if project and project_axis: sig_view = self.apply_to_dict( sig_view, ProjectionView, project_axis, project ) sig_view = self.apply_to_dict( sig_view, RebinView, rebin ) #Rebin + + if differential: + sig_view = self.apply_to_dict(sig_view, DifferentialView) vh_10x = views.TitleView( views.StyleView( @@ -833,7 +837,7 @@ def plot_final_f3(self, variable, rebin=1, xaxis='', maxy=None, show_error=True, qcd_correction=False, qcd_weight_fraction=0.5, x_range=None, #): show_chi2=False,project=None, - project_axis=None, **kwargs): + project_axis=None, differential=False, **kwargs): ''' Plot the final F3 control region - with bkg. estimation ''' sig_view = self.make_obj3_fail_cr_views( @@ -841,6 +845,8 @@ def plot_final_f3(self, variable, rebin=1, xaxis='', maxy=None, if project and project_axis: sig_view = self.apply_to_dict( sig_view, ProjectionView, project_axis, project ) sig_view = self.apply_to_dict( sig_view, RebinView, rebin ) #Rebin + if differential: + sig_view = self.apply_to_dict(sig_view, DifferentialView) charge_fakes_view = MedianView(highv=sig_view['charge_fakes']['sys_up'], centv=sig_view['charge_fakes']['central']) From ee6c41e866310b784a439f7f4006aae06d8de6c2 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 30 Aug 2013 03:14:19 -0500 Subject: [PATCH 006/192] added differential plots, more plots --- wh/WHPlotterEET.py | 75 ++++++++++---- wh/WHPlotterEMT.py | 239 ++++++++++++++++++++++++--------------------- wh/WHPlotterMMT.py | 216 ++++++++++++++++++++-------------------- 3 files changed, 292 insertions(+), 238 deletions(-) diff --git a/wh/WHPlotterEET.py b/wh/WHPlotterEET.py index 87a25111..81049443 100755 --- a/wh/WHPlotterEET.py +++ b/wh/WHPlotterEET.py @@ -130,16 +130,67 @@ def __init__(self): ########################################################################### plotter.set_subdir('') rebin_slim = [0,20]+range(30, 81, 10)+[100, 200] + categories = { + 'LTCut' : [80, 650], + 'LTLow' : [0, 100], + 'LTHigh': [100, 650], + } + + for label, proj_range in categories.iteritems(): + factor = 1.5 if label == 'LTHigh' else 1 + plotter.set_subdir('%s' % label) + plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s' % label) + + plotter.plot_final('e2_t_Mass#LT', 200, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) + + #pt + plotter.plot_final("e1Pt#LT" , int(factor*10), xaxis='p_{Te_{1}} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e1Pt-%s' % label) + + plotter.plot_final("e2Pt#LT" , int(factor*10), xaxis='p_{Te_{2}} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e2Pt-%s' % label) + + plotter.plot_final("e1JetPt#LT" , int(factor*10), xaxis='p_{T Jet e_{1}} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e1JetPt-%s' % label) + + plotter.plot_final("e2JetPt#LT" , int(factor*10), xaxis='p_{T Jet e_{2}} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e2JetPt-%s' % label) + + #eta + plotter.plot_final("e1AbsEta#LT", 10, xaxis='|#eta_{e_{1}}|', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e1AbsEta-%s' % label) + + plotter.plot_final("e2AbsEta#LT", 10, xaxis='|#eta_{e_{2}}|' , maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e2AbsEta-%s' % label) + + #DR + plotter.plot_final("e1_t_DR#LT", 10, xaxis='#DeltaR_{e_{1}#tau}', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e1_t_DR-%s' % label) + + plotter.plot_final("e2_t_DR#LT", 10, xaxis='#DeltaR_{e_{2}#tau}' , maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e2_t_DR-%s' % label) - plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=[0, 130], project_axis='X') + plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=[0, 130], project_axis='X', differential=True) plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-LTLow') - plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=[130, 650], project_axis='X') + plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=[130, 650], project_axis='X', differential=True) plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-LTHigh') - plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=[80, 650], project_axis='X') + plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=[80, 650], project_axis='X', differential=True) plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-LTCut') @@ -199,31 +250,19 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-LT') - plotter.plot_final('e2_t_Mass#LT', 20, xaxis='subleading mass from projection', maxy=None, project=[0, 600], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMassProj') - - plotter.plot_final('e2_t_Mass#LT', 20, xaxis='M_{e_{2}#tau} (GeV)', maxy=None, project=[0, 70], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTLo') - - plotter.plot_final('e2_t_Mass#LT', 20, xaxis='M_{e_{2}#tau} (GeV)', maxy=None, project=[70, 600], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTHi') - ########################################################################### ## f3 region plots ################################################ ########################################################################### categories = { 'LTCut' : [80, 650], - 'LTLow' : [0, 130], - 'LTHigh': [130, 650], + 'LTLow' : [0, 100], + 'LTHigh': [100, 650], } for label, proj_range in categories.iteritems(): factor = 1.5 if label == 'LTHigh' else 1 plotter.set_subdir('f3/%s' % label) - plotter.plot_final_f3('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final_f3('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X', differential=True) plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-%s' % label) diff --git a/wh/WHPlotterEMT.py b/wh/WHPlotterEMT.py index 1d6787d3..86fb4fb1 100644 --- a/wh/WHPlotterEMT.py +++ b/wh/WHPlotterEMT.py @@ -105,100 +105,133 @@ def __init__(self): ## FR sideband MC-vs-Data ################################################ ########################################################################### - plotter.plot_mc_vs_data('ss/p1f2p3', 'mPt', 5, '#mu_{1} p_{T}', leftside=False) - plotter.save('mcdata-ss-p1f2p3-mPt') - - plotter.plot_mc_vs_data('ss/p1f2p3', 'subMass', 20, 'Subleading mass (GeV)', leftside=False) - plotter.save('mcdata-ss-p1f2p3-subMass') - - plotter.plot_mc_vs_data('ss/p1p2f3', 'subMass', 20, 'Subleading mass (GeV)', leftside=False) - plotter.save('mcdata-ss-p1p2f3-subMass') - - plotter.plot_mc_vs_data('ss/f1p2p3', 'subMass', 20, 'Subleading mass (GeV)', leftside=False) - plotter.save('mcdata-ss-f1p2p3-subMass') - - plotter.plot_mc_vs_data('ss/p1f2p3/w2', 'mPt', 5, '#mu_{1} p_{T}', leftside=False) - plotter.save('mcdata-ss-p1f2p3-w2-mPt') - - plotter.plot_mc_vs_data('ss/p1f2p3', 'ePt', 5, 'Electron p_{T}', leftside=False) - plotter.save('mcdata-ss-p1f2p3-ePt') - - plotter.plot_mc_vs_data('ss/p1f2p3/w2', 'ePt', 5, 'Electron p_{T}', leftside=False) - plotter.save('mcdata-ss-p1f2p3-w2-ePt') - - plotter.plot_mc_vs_data('ss/f1p2p3', 'ePt', 5, 'Electron p_{T}', leftside=False) - plotter.save('mcdata-ss-f1p2p3-ePt') - - plotter.plot_mc_vs_data('ss/f1p2p3/w1', 'ePt', 5, 'Electron p_{T}', leftside=False) - plotter.save('mcdata-ss-f1p2p3-w2-ePt') + #plotter.plot_mc_vs_data('ss/p1f2p3', 'mPt', 5, '#mu_{1} p_{T}', leftside=False) + #plotter.save('mcdata-ss-p1f2p3-mPt') + + #plotter.plot_mc_vs_data('ss/p1f2p3', 'subMass', 20, 'Subleading mass (GeV)', leftside=False) + #plotter.save('mcdata-ss-p1f2p3-subMass') + # + #plotter.plot_mc_vs_data('ss/p1p2f3', 'subMass', 20, 'Subleading mass (GeV)', leftside=False) + #plotter.save('mcdata-ss-p1p2f3-subMass') + # + #plotter.plot_mc_vs_data('ss/f1p2p3', 'subMass', 20, 'Subleading mass (GeV)', leftside=False) + #plotter.save('mcdata-ss-f1p2p3-subMass') + # + #plotter.plot_mc_vs_data('ss/p1f2p3/w2', 'mPt', 5, '#mu_{1} p_{T}', leftside=False) + #plotter.save('mcdata-ss-p1f2p3-w2-mPt') + # + #plotter.plot_mc_vs_data('ss/p1f2p3', 'ePt', 5, 'Electron p_{T}', leftside=False) + #plotter.save('mcdata-ss-p1f2p3-ePt') + # + #plotter.plot_mc_vs_data('ss/p1f2p3/w2', 'ePt', 5, 'Electron p_{T}', leftside=False) + #plotter.save('mcdata-ss-p1f2p3-w2-ePt') + # + #plotter.plot_mc_vs_data('ss/f1p2p3', 'ePt', 5, 'Electron p_{T}', leftside=False) + #plotter.save('mcdata-ss-f1p2p3-ePt') + # + #plotter.plot_mc_vs_data('ss/f1p2p3/w1', 'ePt', 5, 'Electron p_{T}', leftside=False) + #plotter.save('mcdata-ss-f1p2p3-w2-ePt') ########################################################################### ## Signal region plots ################################################ ########################################################################### plotter.set_subdir('') rebin_slim = [0,20]+range(30, 81, 10)+[100,130,200] + categories = { + 'LTCut' : [80, 650], + 'LTLow' : [0, 130], + 'LTHigh': [130, 650], + } - plotter.plot_final('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=[0, 130], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTLow') + for label, proj_range in categories.iteritems(): + plotter.set_subdir('%s' % label) + plotter.plot_final('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X', differential=True) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s' % label) - plotter.plot_final('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTHigh') + plotter.plot_final('subMass#LT', 200, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) - plotter.plot_final('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=[80, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTCut') + #pt + plotter.plot_final("mPt#LT" , 10, xaxis='p_{T#mu} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-mPt-%s' % label) - plotter.plot_final('subMass#LT', 20, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=[80, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTCut-flatbin') + plotter.plot_final("ePt#LT" , 10, xaxis='p_{Te} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-ePt-%s' % label) - plotter.plot_final('LT', 5, xaxis='LT (GeV)', maxy=15) - plotter.add_cms_blurb(sqrts) - plotter.save('final-LT') + plotter.plot_final("mJetPt#LT" , 10, xaxis='p_{T Jet#mu} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-mJetPt-%s' % label) - plotter.plot_final('mPt', 10) - plotter.save('final-mPt') + plotter.plot_final("eJetPt#LT" , 10, xaxis='p_{T Jet e} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-eJetPt-%s' % label) - plotter.plot_final('ePt', 10) - plotter.save('final-ePt') + plotter.plot_final("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-tPt-%s' % label) - plotter.plot_final('tPt', 10) - plotter.save('final-tPt') + #eta + plotter.plot_final("mAbsEta#LT", 10, xaxis='|#eta_{#mu}|', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-mAbsEta-%s' % label) - plotter.plot_final('mAbsEta', 10) - plotter.save('final-mAbsEta') + plotter.plot_final("eAbsEta#LT", 10, xaxis='|#eta_{e}|' , maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-eAbsEta-%s' % label) - plotter.plot_final('eAbsEta', 10) - plotter.save('final-eAbsEta') + plotter.plot_final("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-tAbsEta-%s' % label) - plotter.plot_final('tAbsEta', 10) - plotter.save('final-tAbsEta') + #DR + plotter.plot_final("m_t_DR#LT", 10, xaxis='#DeltaR_{#mu#tau}', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-m_t_DR-%s' % label) - plotter.plot_final('subMass', 20, xaxis='m_{l_{2}#tau} (GeV)') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass') + plotter.plot_final("e_t_DR#LT", 10, xaxis='#DeltaR_{e#tau}' , maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-e_t_DR-%s' % label) - plotter.plot_final('subMass', 20, xaxis='m_{l_{2}#tau} (GeV)', qcd_weight_fraction=0.5) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-qweight05') - plotter.canvas.SetLogy(True) - plotter.save('final-subMass-qweight05-logscale') + #Jet BTag + plotter.plot_final("eJetBtag#LT", 2, xaxis='e Jet Btag' , maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-eJetBtag-%s' % label) + plotter.plot_final("mJetBtag#LT", 2, xaxis='#mu Jet Btag' , maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-mJetBtag-%s' % label) - plotter.plot_final('subMass', 20, xaxis='m_{l_{2}#tau} (GeV)', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-werror') - # Shape only - plotter.plot_final('subMass', 20, xaxis='m_{l_{2}#tau} (GeV)', show_error=True, - fake_error=0, wz_error=0, zz_error=0) + plotter.plot_final('LT', 5, xaxis='LT (GeV)', maxy=15) plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-wshapeerror') + plotter.save('final-LT') + + #plotter.plot_final('mPt', 10) + #plotter.save('final-mPt') + # + #plotter.plot_final('ePt', 10) + #plotter.save('final-ePt') + # + #plotter.plot_final('tPt', 10) + #plotter.save('final-tPt') + # + #plotter.plot_final('mAbsEta', 10) + #plotter.save('final-mAbsEta') + # + #plotter.plot_final('eAbsEta', 10) + #plotter.save('final-eAbsEta') + # + #plotter.plot_final('tAbsEta', 10) + #plotter.save('final-tAbsEta') + + #plotter.plot_final('subMass', 20, xaxis='m_{l_{2}#tau} (GeV)') + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-subMass') - ## plotter.plot_final('metSig', 5) - ## plotter.save('final-metSig') plotter.plot_final('tLeadDR', 10) plotter.save('final-tLeadDR') plotter.plot_final('tSubDR', 10) @@ -207,18 +240,6 @@ def __init__(self): plotter.plot_final('e_t_Mass', 10) plotter.save('final-etMass') - plotter.plot_final('subMass#LT', 20, xaxis='subleading mass from projection', maxy=None, project=[0, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMassProj') - - plotter.plot_final('subMass#LT', 20, xaxis='M_{l_{2}#tau} (GeV)', maxy=None, project=[0, 90], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTLo') - - plotter.plot_final('subMass#LT', 20, xaxis='M_{l_{2}#tau} (GeV)', maxy=None, project=[90, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTHi') - ########################################################################### ## WZ enhanced region plots ########################################### ########################################################################### @@ -228,9 +249,9 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-wz-etMass') - plotter.plot_final_wz('mPt', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', maxy=20) - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-mPt') + #plotter.plot_final_wz('mPt', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', maxy=20) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-wz-mPt') #plotter.plot_final_wz('mJetPt', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') #plotter.add_cms_blurb(sqrts) @@ -240,16 +261,10 @@ def __init__(self): ## F3 enhanced region plots ########################################### ########################################################################### plotter.set_subdir('f3') - - categories = { - 'LTCut' : [80, 650], - 'LTLow' : [0, 130], - 'LTHigh': [130, 650], - } for label, proj_range in categories.iteritems(): plotter.set_subdir('f3/%s' % label) - plotter.plot_final_f3('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final_f3('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X', differential=True) plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-%s' % label) @@ -314,19 +329,19 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-f3-LT') - plotter.plot_final_f3('subMass', 20, xaxis='m_{l_{2}#tau_{#mu}} (GeV)', qcd_weight_fraction=0.5, show_error=True) + plotter.plot_final_f3('subMass#LT', 20, xaxis='m_{l_{2}#tau_{#mu}} (GeV)', qcd_weight_fraction=0.5, show_error=True, project=[0, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass') - plotter.plot_final_f3('subMass', 200, xaxis='m_{l_{2}#tau_{#mu}} (GeV)', qcd_weight_fraction=0.5, show_error=True) + plotter.plot_final_f3('subMass#LT', 200, xaxis='m_{l_{2}#tau_{#mu}} (GeV)', qcd_weight_fraction=0.5, show_error=True, project=[0, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-counting-like', dotc=True, dotroot=True) - plotter.plot_final_f3('subMass', 20, xaxis='m_{l_{2}#tau_{#mu}} (GeV)', qcd_weight_fraction=1, show_error=True) + plotter.plot_final_f3('subMass#LT', 20, xaxis='m_{l_{2}#tau_{#mu}} (GeV)', qcd_weight_fraction=1, show_error=True, project=[0, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-qcdfake-subMass') - plotter.plot_final_f3('subMass', 20, xaxis='m_{l_{2}#tau_{#mu}} (GeV)', qcd_weight_fraction=0, show_error=True) + plotter.plot_final_f3('subMass#LT', 20, xaxis='m_{l_{2}#tau_{#mu}} (GeV)', qcd_weight_fraction=0, show_error=True, project=[0, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-wjetfake-subMass') @@ -351,15 +366,15 @@ def __init__(self): #plotter.add_cms_blurb(sqrts) #plotter.save('final-f3-emMass') - plotter.plot_final_f3('mPt', 10, xaxis='p_{T#mu} (GeV)', qcd_weight_fraction=0.5, show_error=True) + plotter.plot_final_f3('mPt#LT', 10, xaxis='p_{T#mu} (GeV)', qcd_weight_fraction=0.5, show_error=True, project=[0, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-mPt') - plotter.plot_final_f3('ePt', 10, xaxis='p_{Te} (GeV)', qcd_weight_fraction=0.5, show_error=True) + plotter.plot_final_f3('ePt#LT', 10, xaxis='p_{Te} (GeV)', qcd_weight_fraction=0.5, show_error=True, project=[0, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-ePt') - plotter.plot_final_f3('tPt', 10, xaxis='p_{T#tau} (GeV)', qcd_weight_fraction=0.5, show_error=True) + plotter.plot_final_f3('tPt#LT', 10, xaxis='p_{T#tau} (GeV)', qcd_weight_fraction=0.5, show_error=True, project=[0, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-tPt') @@ -371,13 +386,13 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-f3-tLeadDR') - plotter.plot_final_f3('e_t_DR', 10, xaxis='#DeltaR_{e#tau}', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-etDR') - - plotter.plot_final_f3('m_t_DR', 10, xaxis='#DeltaR_{#mu#tau}', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-mtDR') + #plotter.plot_final_f3('e_t_DR', 10, xaxis='#DeltaR_{e#tau}', show_error=True) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-etDR') + # + #plotter.plot_final_f3('m_t_DR', 10, xaxis='#DeltaR_{#mu#tau}', show_error=True) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-mtDR') plotter.plot_final_f3('subPt', 10, xaxis='p_{Tl_{2}} (GeV)', show_error=True) plotter.add_cms_blurb(sqrts) @@ -422,13 +437,13 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('study-%s-LT-qweight05' % shape_prefix) - plotter.plot_final(prefix+'subMass', 20, xaxis='m_{#l_{2}#tau} (GeV)', qcd_weight_fraction=0.5) - plotter.add_cms_blurb(sqrts) - plotter.save('study-%s-subMass-qweight05' % shape_prefix) + #plotter.plot_final(prefix+'subMass', 20, xaxis='m_{#l_{2}#tau} (GeV)', qcd_weight_fraction=0.5) + #plotter.add_cms_blurb(sqrts) + #plotter.save('study-%s-subMass-qweight05' % shape_prefix) - plotter.plot_final_f3(prefix+'subMass', 20, xaxis='m_{l_{1}#tau_{#mu}} (GeV)', qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('study-%s-f3-qweight05-werror-subMass' % shape_prefix) + #plotter.plot_final_f3(prefix+'subMass', 20, xaxis='m_{l_{1}#tau_{#mu}} (GeV)', qcd_weight_fraction=0.5, show_error=True) + #plotter.add_cms_blurb(sqrts) + #plotter.save('study-%s-f3-qweight05-werror-subMass' % shape_prefix) shape_file = ROOT.TFile( os.path.join(plotter.outputdir, 'LTCut_emt_shapes_%s.root' % ( plotter.period) ), 'RECREATE') diff --git a/wh/WHPlotterMMT.py b/wh/WHPlotterMMT.py index da48fe38..7aa13ee1 100644 --- a/wh/WHPlotterMMT.py +++ b/wh/WHPlotterMMT.py @@ -41,9 +41,9 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('mcdata-os-p1p2p3-m1m2Mass') - plotter.plot_mc_vs_data('ss/p1p2p3_enhance_wz', 'm2_t_Mass', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=10) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1p2p3-enhance_wz-subMass') + #plotter.plot_mc_vs_data('ss/p1p2p3_enhance_wz', 'm2_t_Mass', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=10) + #plotter.add_cms_blurb(sqrts) + #plotter.save('mcdata-ss-p1p2p3-enhance_wz-subMass') plotter.plot_mc_vs_data('ss/p1p2p3_enhance_wz', 'm1_t_Mass', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=10) plotter.add_cms_blurb(sqrts) @@ -61,9 +61,9 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('mcdata-ss-p1p2p3-enhance_wz-subMTMass') - plotter.plot_mc_vs_data('ss/p1p2p3_enhance_wz', 'm2Pt', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=5) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1p2p3-enhance_wz-m2Pt') + #plotter.plot_mc_vs_data('ss/p1p2p3_enhance_wz', 'm2Pt', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=5) + #plotter.add_cms_blurb(sqrts) + #plotter.save('mcdata-ss-p1p2p3-enhance_wz-m2Pt') plotter.compare_shapes('Zjets_M50', 'data', 'os/p1p2f3/nvtx') plotter.save('z-vs-data-nvtx-shape') @@ -93,17 +93,17 @@ def __init__(self): # Make Z->mumu + tau jet control - antiiso_m2JetPt = plotter.plot('data', 'ss/p1f2p3/m2JetPt', 'hist', styler=make_styler(2, 'hist'), xrange=(0, 120), rebin=10) - antiiso_m2JetPt.SetTitle("Anti-iso CR yield") - antiiso_m2JetPt.legendstyle='l' - antiiso_m2JetPt.GetXaxis().SetTitle("#mu_{2} Jet Pt") - plotter.save('data-p1f2p3-m2JetPt') + #antiiso_m2JetPt = plotter.plot('data', 'ss/p1f2p3/m2JetPt', 'hist', styler=make_styler(2, 'hist'), xrange=(0, 120), rebin=10) + #antiiso_m2JetPt.SetTitle("Anti-iso CR yield") + #antiiso_m2JetPt.legendstyle='l' + #antiiso_m2JetPt.GetXaxis().SetTitle("#mu_{2} Jet Pt") + #plotter.save('data-p1f2p3-m2JetPt') - antiiso_m1JetPt = plotter.plot('data', 'ss/f1p2p3/m1JetPt', 'hist', styler=make_styler(2, 'hist'), xrange=(0, 120), rebin=10) - antiiso_m1JetPt.SetTitle("Anti-iso CR yield") - antiiso_m1JetPt.legendstyle='l' - antiiso_m1JetPt.GetXaxis().SetTitle("#mu_{1} Jet Pt") - plotter.save('data-f1p2p3-m1JetPt') + #antiiso_m1JetPt = plotter.plot('data', 'ss/f1p2p3/m1JetPt', 'hist', styler=make_styler(2, 'hist'), xrange=(0, 120), rebin=10) + #antiiso_m1JetPt.SetTitle("Anti-iso CR yield") + #antiiso_m1JetPt.legendstyle='l' + #antiiso_m1JetPt.GetXaxis().SetTitle("#mu_{1} Jet Pt") + #plotter.save('data-f1p2p3-m1JetPt') zmm_weighted = plotter.plot('data', 'os/p1p2f3/w3/m1_m2_Mass', 'hist', styler=make_styler(2, 'hist'), xrange=(60, 120)) zmm_weighted.SetTitle("Z#mu#mu + fake #tau_{h} est.") @@ -136,34 +136,33 @@ def __init__(self): ## FR sideband MC-vs-Data ################################################ ########################################################################### - plotter.plot_mc_vs_data('ss/p1f2p3', 'm1Pt', rebin=10, xaxis='#mu_{1} p_{T} (GeV)', leftside=False) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1f2p3-m1Pt') - - plotter.plot_mc_vs_data('ss/p1f2p3', 'm2_t_Mass', rebin=10, xaxis='m_{#mu2#tau} (GeV)', leftside=False) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1f2p3-subMass') - - plotter.plot_mc_vs_data('ss/p1f2p3/w2', 'm1Pt', rebin=10, xaxis='#mu_{1} p_{T}', leftside=False) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1f2p3-w2-m1Pt') - - plotter.plot_mc_vs_data('ss/f1p2p3', 'm2_t_Mass', rebin=20, xaxis='m_{#mu2#tau} (GeV)', leftside=False) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-f1p2p3-subMass') - - plotter.plot_mc_vs_data('ss/f1p2p3/w1', 'm2_t_Mass', rebin=20, xaxis='m_{#mu2#tau} (GeV)', leftside=False) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-f1p2p3-w1-subMass') - - plotter.plot_mc_vs_data('ss/p1f2f3', 'm2AbsEta', rebin=10, xaxis='m_{#mu2#tau} (GeV)', leftside=False) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1f2f3-m2AbsEta') - - plotter.plot_mc_vs_data('ss/p1f2p3', 'm2AbsEta', rebin=10, xaxis='m_{#mu2#tau} (GeV)', leftside=False) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1f2p3-m2AbsEta') - + #plotter.plot_mc_vs_data('ss/p1f2p3', 'm1Pt', rebin=10, xaxis='#mu_{1} p_{T} (GeV)', leftside=False) + #plotter.add_cms_blurb(sqrts) + #plotter.save('mcdata-ss-p1f2p3-m1Pt') + + #plotter.plot_mc_vs_data('ss/p1f2p3', 'm2_t_Mass', rebin=10, xaxis='m_{#mu2#tau} (GeV)', leftside=False) + #plotter.add_cms_blurb(sqrts) + #plotter.save('mcdata-ss-p1f2p3-subMass') + # + #plotter.plot_mc_vs_data('ss/p1f2p3/w2', 'm1Pt', rebin=10, xaxis='#mu_{1} p_{T}', leftside=False) + #plotter.add_cms_blurb(sqrts) + #plotter.save('mcdata-ss-p1f2p3-w2-m1Pt') + # + #plotter.plot_mc_vs_data('ss/f1p2p3', 'm2_t_Mass', rebin=20, xaxis='m_{#mu2#tau} (GeV)', leftside=False) + #plotter.add_cms_blurb(sqrts) + #plotter.save('mcdata-ss-f1p2p3-subMass') + # + #plotter.plot_mc_vs_data('ss/f1p2p3/w1', 'm2_t_Mass', rebin=20, xaxis='m_{#mu2#tau} (GeV)', leftside=False) + #plotter.add_cms_blurb(sqrts) + #plotter.save('mcdata-ss-f1p2p3-w1-subMass') + # + #plotter.plot_mc_vs_data('ss/p1f2f3', 'm2AbsEta', rebin=10, xaxis='m_{#mu2#tau} (GeV)', leftside=False) + #plotter.add_cms_blurb(sqrts) + #plotter.save('mcdata-ss-p1f2f3-m2AbsEta') + # + #plotter.plot_mc_vs_data('ss/p1f2p3', 'm2AbsEta', rebin=10, xaxis='m_{#mu2#tau} (GeV)', leftside=False) + #plotter.add_cms_blurb(sqrts) + #plotter.save('mcdata-ss-p1f2p3-m2AbsEta') ########################################################################### @@ -179,7 +178,7 @@ def __init__(self): for label, proj_range in categories.iteritems(): plotter.set_subdir('%s' % label) - plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X', differential=True) plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-%s' % label) @@ -252,19 +251,19 @@ def __init__(self): #from pdb import set_trace; set_trace() - plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=[0, 130], project_axis='X') + plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=[0, 130], project_axis='X', differential=True) plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-LTLow') - plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=[130, 650], project_axis='X') + plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=[130, 650], project_axis='X', differential=True) plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-LTHigh') - plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=[80, 650], project_axis='X') + plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=[80, 650], project_axis='X', differential=True) plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-LTCut') - plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=[80, 650], project_axis='X') + plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=[80, 650], project_axis='X', differential=True) plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-LTCut-flatbin') @@ -272,48 +271,49 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-LT') - plotter.plot_final('m1Pt', 10) + plotter.plot_final('m1Pt#LT', 10, project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-m1Pt') - plotter.plot_final('m2Pt', 10) + plotter.plot_final('m2Pt#LT', 10, project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-m2Pt') - plotter.plot_final('m2Pt', 10) + plotter.plot_final('m2Pt#LT', 10, project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-m2Pt') - plotter.plot_final('m1AbsEta', 10) + plotter.plot_final('m1AbsEta#LT', 10, project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-m1AbsEta') - plotter.plot_final('m2AbsEta', 10) + plotter.plot_final('m2AbsEta#LT', 10, project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-m2AbsEta') - plotter.plot_final('m2AbsEta', 10) + plotter.plot_final('m2AbsEta#LT', 10, project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-m2AbsEta') - plotter.plot_final('m2_t_Mass', 20, xaxis='m_{#mu_{2}#tau} (GeV)') + plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-subMass') - plotter.plot_final('m2_t_Mass', 20, xaxis='m_{#mu_{2}#tau} (GeV)', qcd_weight_fraction=1) + plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', qcd_weight_fraction=1, project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-qweight-subMass') - plotter.plot_final('m2_t_Mass', 20, xaxis='m_{#mu_{2}#tau} (GeV)', qcd_weight_fraction=0.5) + plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', qcd_weight_fraction=0.5, project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-qweight05-subMass') - plotter.plot_final('m2_t_Mass', 20, xaxis='m_{#mu_{2}#tau} (GeV)', show_error=True) + plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', show_error=True, project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-werror') - plotter.plot_final('m2_t_Mass', 20, xaxis='m_{#mu_{2}#tau} (GeV)', - show_error=True, fake_error=0, wz_error=0, zz_error=0) + plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', + show_error=True, fake_error=0, wz_error=0, zz_error=0 + , project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-wshapeerror') @@ -330,13 +330,13 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-wz-leadMass') - plotter.plot_final_wz('m2Pt', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-m2Pt') - - plotter.plot_final_wz('m2JetPt', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-m2JetPt') + #plotter.plot_final_wz('m2Pt', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-wz-m2Pt') + # + #plotter.plot_final_wz('m2JetPt', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-wz-m2JetPt') ########################################################################### ## F3 enhanced region plots ########################################### @@ -349,7 +349,7 @@ def __init__(self): for label, proj_range in categories.iteritems(): plotter.set_subdir('f3/%s' % label) - plotter.plot_final_f3('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final_f3('m2_t_Mass#LT', [0,10,20]+range(30, 91, 10)+[110,200], xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X', differential=True) plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-%s' % label) @@ -392,11 +392,11 @@ def __init__(self): plotter.save('final-f3-tAbsEta-%s' % label) #DR - plotter.plot_final_f3("m1_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{1}#tau}', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final_f3("m1_t_DR#LT", 5, xaxis='#DeltaR_{#mu_{1}#tau}', maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-m1_t_DR-%s' % label) - plotter.plot_final_f3("m2_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, project=proj_range, project_axis='X') + plotter.plot_final_f3("m2_t_DR#LT", 5, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-m2_t_DR-%s' % label) @@ -429,11 +429,11 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-f3-leadMass') - plotter.plot_final_f3('m2_t_Mass', 20, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=0, show_error=True) + plotter.plot_final_f3('m2_t_Mass#LT', 20, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=0, show_error=True, project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-wjetfake-subMass') - plotter.plot_final_f3('m2_t_Mass', 20, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=1, show_error=True) + plotter.plot_final_f3('m2_t_Mass#LT', 20, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=1, show_error=True, project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-qcdfake-subMass') @@ -445,47 +445,47 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-f3-m1JetBtag') - plotter.plot_final_f3('m2_t_Mass', 20, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=0.5, show_error=True) + plotter.plot_final_f3('m2_t_Mass#LT', 20, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=0.5, show_error=True, project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass') - plotter.plot_final_f3('m2_t_Mass', 200, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=0.5, show_error=True) + plotter.plot_final_f3('m2_t_Mass#LT', 200, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=0.5, show_error=True, project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-counting-like', dotc=True, dotroot=True) - plotter.plot_final_f3_split('m2_t_Mass', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-split-subMass') + #plotter.plot_final_f3_split('m2_t_Mass#LT', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', project=[130, 650], project_axis='X') + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-split-subMass') - plotter.plot_final_f3('m1Pt', 5, xaxis='p_{T#mu_{1}} (GeV)') + plotter.plot_final_f3('m1Pt#LT', 5, xaxis='p_{T#mu_{1}} (GeV)', project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-m1Pt') - plotter.plot_final_f3('m1JetPt', 5, xaxis='p_{TJet#mu_{1}} (GeV)') + plotter.plot_final_f3('m1JetPt#LT', 5, xaxis='p_{TJet#mu_{1}} (GeV)', project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-m1JetPt') - plotter.plot_final_f3('m1AbsEta', 10, xaxis='|#eta_{#mu_{1}}| (GeV)') + plotter.plot_final_f3('m1AbsEta#LT', 10, xaxis='|#eta_{#mu_{1}}| (GeV)', project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-m1AbsEta') - plotter.plot_final_f3('m2Pt', 5, xaxis='p_{T#mu_{2}} (GeV)') + plotter.plot_final_f3('m2Pt#LT', 5, xaxis='p_{T#mu_{2}} (GeV)', project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-m2Pt') - plotter.plot_final_f3('m2JetPt', 5, xaxis='p_{TJet#mu_{2}} (GeV)') + plotter.plot_final_f3('m2JetPt#LT', 5, xaxis='p_{TJet#mu_{2}} (GeV)', project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-m2JetPt') - plotter.plot_final_f3('m2AbsEta', 10, xaxis='|#eta_{#mu_{2}}| (GeV)') + plotter.plot_final_f3('m2AbsEta#LT', 10, xaxis='|#eta_{#mu_{2}}| (GeV)', project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-m2AbsEta') - plotter.plot_final_f3('m1_t_DR', 5, xaxis='#DeltaR_{#mu_{1}#tau}') + plotter.plot_final_f3('m1_t_DR#LT', 5, xaxis='#DeltaR_{#mu_{1}#tau}', project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-m1_t_DR') - plotter.plot_final_f3('m2_t_DR', 5, xaxis='#DeltaR_{#mu_{2}#tau}') + plotter.plot_final_f3('m2_t_DR#LT', 5, xaxis='#DeltaR_{#mu_{2}#tau}', project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-m2_t_DR') @@ -494,21 +494,21 @@ def __init__(self): ########################################################################### plotter.set_subdir('qcd_contamination') - plotter.plot_qcd_contamination('m2_t_Mass', 2, 10) - plotter.add_cms_blurb(sqrts) - plotter.save('final-qcd2-subMass') - - plotter.plot_qcd_contamination('m2_t_Mass', 1, 20) - plotter.add_cms_blurb(sqrts) - plotter.save('final-qcd1-subMass') - - plotter.plot_qcd_contamination('m2JetPt', 2, 10) - plotter.add_cms_blurb(sqrts) - plotter.save('final-qcd2-m2JetPt') - - plotter.plot_qcd_contamination('m1JetPt', 1, 20) - plotter.add_cms_blurb(sqrts) - plotter.save('final-qcd1-m1JetPt') + #plotter.plot_qcd_contamination('m2_t_Mass', 2, 10) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-qcd2-subMass') + # + #plotter.plot_qcd_contamination('m2_t_Mass', 1, 20) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-qcd1-subMass') + # + #plotter.plot_qcd_contamination('m2JetPt', 2, 10) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-qcd2-m2JetPt') + # + #plotter.plot_qcd_contamination('m1JetPt', 1, 20) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-qcd1-m1JetPt') #END OF if not options.dry_run: ########################################################################### @@ -518,13 +518,13 @@ def __init__(self): prefixes = [options.prefix+'$'] if options.prefix else [''] prefixes = [i+'$' for i in options.prefixes.split(',') if i] if options.prefixes else prefixes for prefix in prefixes: - plotter.plot_final(prefix+'m2_t_Mass', 20, xaxis='m_{#mu_{2}#tau} (GeV)', qcd_weight_fraction=0.5) - plotter.add_cms_blurb(sqrts) - plotter.save('final-%s-qweight05-subMass' % options.prefix) - - plotter.plot_final_f3(prefix+'m2_t_Mass', 20, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-%s-f3-qweight05-subMass' % options.prefix) + #plotter.plot_final(prefix+'m2_t_Mass', 20, xaxis='m_{#mu_{2}#tau} (GeV)', qcd_weight_fraction=0.5) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-%s-qweight05-subMass' % options.prefix) + # + #plotter.plot_final_f3(prefix+'m2_t_Mass', 20, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=0.5, show_error=True) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-%s-f3-qweight05-subMass' % options.prefix) shape_prefix = prefix if len(prefixes) > 1 else '' shape_prefix = shape_prefix.replace(':','_').replace('$','_') From 9c234c3ff05d0cfab17b1d616bb9fb7c421bbea9 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 30 Aug 2013 03:16:04 -0500 Subject: [PATCH 007/192] added more kNN variables and more, added muon fr from EM data --- wh/fakerate_functions.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/wh/fakerate_functions.py b/wh/fakerate_functions.py index aa9db0e8..6dddf1f3 100755 --- a/wh/fakerate_functions.py +++ b/wh/fakerate_functions.py @@ -96,6 +96,18 @@ def make_mva_functor_dict(template, variables, mapper=None): ) return ret +def null(*args, **kwargs): + return 0. + +def make_null_dict(template, variables, mapper=None): + ret = {} + for i in optimizer.lep_id: + lepid = i + if mapper: + lepid = mapper(lepid) + ret[i] = null + return ret + ################## ## 1D Muon Func ## @@ -103,19 +115,26 @@ def make_mva_functor_dict(template, variables, mapper=None): #no changes in muonID in 2013 mapper = {'eid1[0-9][A-Z][a-z]+_':'', 'idiso02' : 'pfidiso02'} -variables = ['muonJetPt', 'muonPt', 'muonJetCSVBtag'] #'muonPVDXY']#, 'muonJetBtag'] +variables = ['muonJetPt', 'muonPt', 'numJets20'] #, 'muonJetCSVBtag'] highpt_mu_fr = make_mva_functor_dict(frfit_dir + '/m_wjets_pt20_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) lowpt_mu_fr = make_mva_functor_dict(frfit_dir + '/m_wjets_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) highpt_mu_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_qcd_pt20_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) lowpt_mu_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_qcd_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +variables = ['muonJetPt', 'muonPt', 'numJets20'] +highpt_mue_fr = make_mva_functor_dict(frfit_dir + '/m_Mwjets_pt20_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +lowpt_mue_fr = make_mva_functor_dict(frfit_dir + '/m_Mwjets_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) + +highpt_mue_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_Mqcd_pt20_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +lowpt_mue_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_Mqcd_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) + ####################### ## 1D Electrons Func ## ####################### -variables = ['electronJetPt', 'electronPt'] +variables = ['electronJetPt', 'electronPt', 'numJets20'] #EMT highpt_e_fr = make_mva_functor_dict(frfit_dir + '/e_wjets_pt20_%s_electronInfo.kNN.weights.xml', variables) lowpt_e_fr = make_mva_functor_dict(frfit_dir + '/e_wjets_pt10_%s_electronInfo.kNN.weights.xml', variables) @@ -124,6 +143,7 @@ def make_mva_functor_dict(template, variables, mapper=None): lowpt_e_qcd_fr = make_mva_functor_dict(frfit_dir + '/e_qcd_pt10_%s_electronInfo.kNN.weights.xml', variables) #EET +variables = ['electronJetPt', 'electronPt', 'numJets20'] highpt_ee_fr = make_mva_functor_dict(frfit_dir + '/ee_wjetsNoZmass_pt20_%s_electronInfo.kNN.weights.xml', variables) lowpt_ee_fr = make_mva_functor_dict(frfit_dir + '/ee_wjetsNoZmass_pt10_%s_electronInfo.kNN.weights.xml', variables) @@ -150,10 +170,10 @@ def make_mva_functor_dict(template, variables, mapper=None): default_scaler = mass_scaler[mass_scaler.keys()[0]] -e1_charge_flip = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e1_%s.root", "efficiency_map") -e1_charge_flip_up = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e1_%s.root", "efficiency_map_statUp") -e1_charge_flip_down = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e1_%s.root", "efficiency_map_statDown") - -e2_charge_flip = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e2_%s.root", "efficiency_map") -e2_charge_flip_up = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e2_%s.root", "efficiency_map_statUp") -e2_charge_flip_down = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e2_%s.root", "efficiency_map_statDown") +#e1_charge_flip = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e1_%s.root", "efficiency_map") +#e1_charge_flip_up = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e1_%s.root", "efficiency_map_statUp") +#e1_charge_flip_down = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e1_%s.root", "efficiency_map_statDown") +# +#e2_charge_flip = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e2_%s.root", "efficiency_map") +#e2_charge_flip_up = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e2_%s.root", "efficiency_map_statUp") +#e2_charge_flip_down = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e2_%s.root", "efficiency_map_statDown") From f83a35ed99ab5ca15553892d87c9e455016926e7 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 30 Aug 2013 03:16:42 -0500 Subject: [PATCH 008/192] minimal error is 1% --- wh/get_fake_systematic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wh/get_fake_systematic.py b/wh/get_fake_systematic.py index 7b39c2fa..acb51ceb 100755 --- a/wh/get_fake_systematic.py +++ b/wh/get_fake_systematic.py @@ -26,4 +26,5 @@ nom = nom_view.Get('fakes').Integral() qcd = qcd_view.Get('fakes').Integral() -print "%s fakes %s %0.2f" % (','.join(base_dirs), syst_name, 1 + abs(nom - qcd) / nom) +minimalerror = max(abs(nom - qcd)/nom, 0.01) +print "%s fakes %s %0.2f" % (','.join(base_dirs), syst_name, 1 + minimalerror) From fc821ccff1c220395e1c8dc1778d828a7aa28933 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 30 Aug 2013 03:17:25 -0500 Subject: [PATCH 009/192] reduce number of unused isopoints --- wh/optimizer.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/wh/optimizer.py b/wh/optimizer.py index bb786e02..be16d9f1 100644 --- a/wh/optimizer.py +++ b/wh/optimizer.py @@ -6,23 +6,17 @@ RUN_OPTIMIZATION = ('RUN_OPTIMIZATION' in os.environ) and eval(os.environ['RUN_OPTIMIZATION']) lep_id = [ - 'eid12Tight_idiso02', 'eid12Tight_h2taucuts', 'eid12Tight_h2taucuts020', - 'eid12Loose_idiso02', - 'eid12Loose_h2taucuts', - 'eid12Loose_h2taucuts020', - 'eid12Medium_idiso02', + #'eid12Loose_h2taucuts', + #'eid12Loose_h2taucuts020', 'eid12Medium_h2taucuts', 'eid12Medium_h2taucuts020' ] \ if RUN_OPTIMIZATION else \ [ - 'eid12Medium_idiso02', - 'eid12Loose_idiso02', - 'eid12Tight_idiso02', - 'eid12Loose_h2taucuts', - 'eid12Loose_h2taucuts020', + #'eid12Loose_h2taucuts', + #'eid12Loose_h2taucuts020', 'eid12Tight_h2taucuts', 'eid12Medium_h2taucuts020', 'eid12Medium_h2taucuts' @@ -81,8 +75,8 @@ } else: grid_search['MMT'] = { - 'leading_iso' : 'eid12Loose_h2taucuts', - 'subleading_iso' : 'eid12Loose_h2taucuts020', + 'leading_iso' : 'eid12Medium_h2taucuts', + 'subleading_iso' : 'eid12Medium_h2taucuts020', 'LT' : 50, 'tauID' : None, 'tauPT' : 0, From daa569578b614051f02695aa2bdb94a24b644952 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Sep 2013 08:16:42 -0500 Subject: [PATCH 010/192] work in progress --- wh/Rakefile | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/wh/Rakefile b/wh/Rakefile index 0c041a1a..ed7a8b2e 100755 --- a/wh/Rakefile +++ b/wh/Rakefile @@ -33,7 +33,7 @@ end #puts get_sample_names('data_DoubleMu') samples = Hash[ - "ewk" => Array['Zjets_M50', 'WplusJets_madgraph', 'TTplusJets_madgraph'] + get_sample_names('WZ') + get_sample_names('WWJet')+ get_sample_names('ZZ'), #'ZZJetsTo4L_pythia', + "ewk" => Array['Zjets_M50', 'WplusJets_madgraph'] + get_sample_names('TTplusJets') + get_sample_names('WZ') + get_sample_names('WWJet')+ get_sample_names('ZZ'), #'ZZJetsTo4L_pythia', "wjets" => Array['WplusJets_madgraph'], "zjets" => Array['Zjets_M50'], "diboson" => get_sample_names('ZZ')+get_sample_names('WZ') + get_sample_names('WWJet'), @@ -605,8 +605,12 @@ task :eet_shapes => eet_shape_file $carddir = "results/#{$jobid}/cards" cardmasses = get_sample_names('VH') #get all the VH samples available -cardmasses = cardmasses.select{|x| x.include? "H2Tau"} #get only the H2Tau, to avid repetition -cardmasses = cardmasses.map{|x| x.sub("VH_H2Tau_M-","")} #remove trailing name, the leftover is the mass (as a string) +cardmasses = cardmasses.select{|x| not x.include? "HWW"} #get only the H2Tau, to avid repetition +if $period == '8TeV' + cardmasses = cardmasses.map{|x| x.sub("VH_H2Tau_M-","")} #remove trailing name, the leftover is the mass (as a string) +else + cardmasses = cardmasses.map{|x| x.sub("VH_","")} #remove trailing name, the leftover is the mass (as a string) +end cardmasses = cardmasses.map{|x| Integer(x)} #maps to integers (don't know if it's really needed but can't harm) cardmasses = cardmasses.select{|x| x <= 140} #FIXME! to be removed! #puts cardmasses @@ -618,7 +622,7 @@ def make_morphing_task(channel, shapefile) file ret => [shapefile] do |t| sh "mkdir -p `dirname #{t.name}`" sh "cp #{t.prerequisites[0]} #{t.name}" - sh "horizontal-morphing.py --categories='#{$categories_map[channel].join(',')}' --samples='WH_hww{MASS}' --uncerts='' --masses='110,120,130,140' --step-size=5 -i #{t.name}"# --extrapolate=#{$to_extrapolate.join(",")} #{t.name}" #FIXME! to be removed! + #sh "horizontal-morphing.py --categories='#{$categories_map[channel].join(',')}' --samples='WH_hww{MASS}' --uncerts='' --masses='110,120,130,140' --step-size=5 -i #{t.name}"# --extrapolate=#{$to_extrapolate.join(",")} #{t.name}" #FIXME! to be removed! end return ret end @@ -730,11 +734,13 @@ def make_timestamp_task(cardmasses, channel) make_unc_vals_task(channel) make_cgs_conf_task(channel) file timestamp => cardmasses.map{|x| make_datacard_task(x, channel)} do |t| + sh "mkdir -p `dirname #{t.name}`" sh "touch #{t.name}" end end file "#{$carddir}/llt/.creation_timestamp" => cardmasses.map{|x| combine_channels(x)} do |t| + sh "mkdir -p `dirname #{t.name}`" sh "touch #{t.name}" end @@ -872,6 +878,15 @@ def copy_file(source, target) return target end +def copy_and_trim_file(source, target) + file target => [source] do |t| + sh "mkdir -p `dirname #{t.name}`" + sh "grep -v -E 'CMS_vhtt_.*_bin_[0-9]+' #{source} > #{t.name}" + end + return target +end + + def copy_configs(channel, vhtt_number) dir = "#{$carddir}/#{channel}" htt_id = "sm-#{$period}-#{vhtt_number}" @@ -880,10 +895,10 @@ def copy_configs(channel, vhtt_number) copy_file("#{dir}/cgs.conf", "#{$httcombodir}/cgs-#{htt_id}.conf") #copies unc.conf - copy_file("#{dir}/unc.conf", "#{$httcombodir}/unc-#{htt_id}.conf") + copy_and_trim_file("#{dir}/unc.conf", "#{$httcombodir}/unc-#{htt_id}.conf") #copies unc.vals - copy_file("#{dir}/unc.vals", "#{$httcombodir}/unc-#{htt_id}.vals") + copy_and_trim_file("#{dir}/unc.vals", "#{$httcombodir}/unc-#{htt_id}.vals") return ["#{$httcombodir}/cgs-#{htt_id}.conf", "#{$httcombodir}/unc-#{htt_id}.conf", "#{$httcombodir}/unc-#{htt_id}.vals"] end @@ -1035,11 +1050,11 @@ def make_f3_postfit_plots_task(channel) file plot_timestamp => shape_file do |t| sh "mkdir -p `dirname #{t.name}`" $categories_map[channel].each do |category| - sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{category} -e 'WH*' -o #{resultdir}/#{category}.png -x #{$xlabels_map[channel]}" - sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{category} -e 'WH*' -o #{resultdir}/#{category}.pdf -x #{$xlabels_map[channel]}" + sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{category} -e 'WH*' -o #{resultdir}/#{category}.png -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV'" + sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{category} -e 'WH*' -o #{resultdir}/#{category}.pdf -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV'" end sh "cp -v #{$carddir}/#{channel}/#{channel}.pulls* #{resultdir}/." - sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{$categories_map[channel].join(' ')} -e 'WH*' -o #{resultdir}/#{channel}_categories_summed.png -x #{$xlabels_map[channel]}" + sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{$categories_map[channel].join(' ')} -e 'WH*' -o #{resultdir}/#{channel}_categories_summed.png -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV'" sh "touch #{t.name}" end return plot_timestamp From d4cb248b6708e58ca1fd03b6e69fb9bf3de5bb37 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 08:52:13 -0500 Subject: [PATCH 011/192] easier to read, added 7TeV triggers for EM --- wh/FakeRatesEE.py | 2 +- wh/FakeRatesEM.py | 7 +++---- wh/FakeRatesMM.py | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/wh/FakeRatesEE.py b/wh/FakeRatesEE.py index 131263c4..9c92c14a 100755 --- a/wh/FakeRatesEE.py +++ b/wh/FakeRatesEE.py @@ -136,7 +136,7 @@ def fill(the_histos, row, fillNtuple=False): #print id_iso_vals #print self.lepIds id_iso_vals = [float( i ) for i in id_iso_vals ] - the_histos['electronInfo'].Fill( array("f", [row.e2Pt, row.e2JetPt, max(0, row.e2JetCSVBtag), + the_histos['electronInfo'].Fill( array("f", [row.e2Pt, max(row.e2Pt, row.e2JetPt), max(0, row.e2JetCSVBtag), row.jetVeto20, row.jetVeto40_DR05, weight]+id_iso_vals) ) diff --git a/wh/FakeRatesEM.py b/wh/FakeRatesEM.py index 836ae88a..3a8328b2 100644 --- a/wh/FakeRatesEM.py +++ b/wh/FakeRatesEM.py @@ -172,7 +172,7 @@ def fill(the_histos, row, fillNtuple=False): the_histos['eJetptDvseJetPt'].Fill(max(row.eJetPt, row.ePt),row.eJetptD) if fillNtuple: id_iso_vals = [ float( selections.lepton_id_iso(row, 'e', label) ) for label in self.lepIds] - the_histos['electronInfo'].Fill( array("f", [row.ePt, row.eJetPt, max(0, row.eJetCSVBtag), + the_histos['electronInfo'].Fill( array("f", [row.ePt, max(row.eJetPt, row.ePt), max(0, row.eJetCSVBtag), row.jetVeto20, row.jetVeto40_DR05, weight]+id_iso_vals) ) @@ -192,8 +192,7 @@ def fill_muon(the_histos, row, fillNtuple=False): pfidiso02 = float( row.mPFIDTight and row.mRelPFIsoDB < 0.2) h2taucuts = float( row.mPFIDTight and ((row.mRelPFIsoDB < 0.15 and row.mAbsEta < 1.479) or row.mRelPFIsoDB < 0.1 )) h2taucuts020 = float( row.mPFIDTight and ((row.mRelPFIsoDB < 0.20 and row.mAbsEta < 1.479) or row.mRelPFIsoDB < 0.15)) - - the_histos['muonInfo'].Fill( array("f", [row.mPt, row.mJetPt, max(0, row.mJetCSVBtag), + the_histos['muonInfo'].Fill( array("f", [row.mPt, max(row.mJetPt, row.mPt), max(0, row.mJetCSVBtag), row.jetVeto20, row.jetVeto40_DR05, weight, pfidiso02, h2taucuts, h2taucuts020] ) ) @@ -244,7 +243,7 @@ def fill_muon_region(region, tag): is7TeV = bool('7TeV' in os.environ['jobid']) use_iso_trigger = not is7TeV mu17e8 = (row.mu17ele8isoPass and row.mPt >= 20) if use_iso_trigger else (row.mu17ele8Pass and row.mPt >= 20) - mu8e17 = (row.mu8ele17isoPass and row.ePt >= 20) #if use_iso_trigger else (row.mu17ele8Pass and row.mPt < 20) + mu8e17 = (row.mu8ele17isoPass and row.ePt >= 20) if use_iso_trigger else (row.mu8ele17Pass and row.ePt >= 20) if mu17e8: fill_region(region,'pt10') if mu8e17: diff --git a/wh/FakeRatesMM.py b/wh/FakeRatesMM.py index ff67891d..68783250 100755 --- a/wh/FakeRatesMM.py +++ b/wh/FakeRatesMM.py @@ -146,7 +146,7 @@ def fill(the_histos, row, fillNtuple=False): pfidiso02 = float( row.m2PFIDTight and row.m2RelPFIsoDB < 0.2) h2taucuts = float( row.m2PFIDTight and ((row.m2RelPFIsoDB < 0.15 and row.m2AbsEta < 1.479) or row.m2RelPFIsoDB < 0.1 )) h2taucuts020 = float( row.m2PFIDTight and ((row.m2RelPFIsoDB < 0.20 and row.m2AbsEta < 1.479) or row.m2RelPFIsoDB < 0.15)) - the_histos['muonInfo'].Fill( array("f", [row.m2Pt, row.m2JetPt, row.m2AbsEta, max(0, row.m2JetCSVBtag), + the_histos['muonInfo'].Fill( array("f", [row.m2Pt, max(row.m2JetPt, row.m2Pt), row.m2AbsEta, max(0, row.m2JetCSVBtag), abs(row.m2PVDXY), row.jetVeto20, row.jetVeto40_DR05, weight, pfidiso02, h2taucuts, h2taucuts020] ) ) From f8d8b446031276372b642a8c05d312e6ce51e7ca Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 08:53:29 -0500 Subject: [PATCH 012/192] implemented fake yield uncertainty from f3 region fit --- wh/Rakefile | 474 ++++++++++++++++++++++++++++------------------------ 1 file changed, 254 insertions(+), 220 deletions(-) diff --git a/wh/Rakefile b/wh/Rakefile index ed7a8b2e..58960e11 100755 --- a/wh/Rakefile +++ b/wh/Rakefile @@ -524,6 +524,7 @@ file "#{$zeedir}/.plot_timestamp" => Array["PlotControlZEE.py"]+get_analyzer_res end task :plot_zee => "#{$zeedir}/.plot_timestamp" + ################################################################################ # Recipes to make signal plots # targets: @@ -556,15 +557,14 @@ file "#{$eetdir}/eet_shapes_#{$period}.root" => ['WHPlotterEET.py', 'WHPlotterBa end task :plot_eet => "#{$eetdir}/eet_shapes_#{$period}.root" -################################################################################ -# Recipes to make data cards (plots come for free) -# targets: -# mmt_shapes -# emt_shapes -# eet_shapes -# cards -# copycards -> move cards to official HTT CVS area -################################################################################ + +################################################################################# +#### +#### HELPER FUNCTIONS TO COMPUTE LIMITS +#### +################################################################################# +$carddir = "FIXME" #TO BE CHANGED BY THE DIFFERENT PARTS + #categories $categories_map = Hash[ @@ -573,6 +573,7 @@ $categories_map = Hash[ 'mmt' => File.open("card_config/cgs.conf.mmt.#{$period}").select {|x| x.start_with? 'categories'}[0].split(':')[1].split(',').map{|x| x.strip}, ] + # Recipes for adding stat. error shapes. Makes a new file task: # input_file_stat_errors.root => input_file.root def add_fake_errors(input_file, channel, prefix) @@ -584,59 +585,6 @@ def add_fake_errors(input_file, channel, prefix) return output_file end -mmt_shape_file = "#{$mmtdir}/mmt_shapes_#{$period}.root" -$categories_map['mmt'].each do |category| - mmt_shape_file = add_fake_errors(mmt_shape_file, "mmt", category) -end -task :mmt_shapes => mmt_shape_file - -emt_shape_file = "#{$emtdir}/emt_shapes_#{$period}.root" -$categories_map['emt'].each do |category| - emt_shape_file = add_fake_errors(emt_shape_file, "emt", category) -end -task :emt_shapes => emt_shape_file - -eet_shape_file = "#{$eetdir}/eet_shapes_#{$period}.root" -$categories_map['eet'].each do |category| - eet_shape_file = add_fake_errors(eet_shape_file, "eet", category) -end -task :eet_shapes => eet_shape_file - -$carddir = "results/#{$jobid}/cards" - -cardmasses = get_sample_names('VH') #get all the VH samples available -cardmasses = cardmasses.select{|x| not x.include? "HWW"} #get only the H2Tau, to avid repetition -if $period == '8TeV' - cardmasses = cardmasses.map{|x| x.sub("VH_H2Tau_M-","")} #remove trailing name, the leftover is the mass (as a string) -else - cardmasses = cardmasses.map{|x| x.sub("VH_","")} #remove trailing name, the leftover is the mass (as a string) -end -cardmasses = cardmasses.map{|x| Integer(x)} #maps to integers (don't know if it's really needed but can't harm) -cardmasses = cardmasses.select{|x| x <= 140} #FIXME! to be removed! -#puts cardmasses - -$to_extrapolate = cardmasses.select{|x| x > 140} - -def make_morphing_task(channel, shapefile) - ret = "#{$carddir}/#{channel}/shapes.root" - file ret => [shapefile] do |t| - sh "mkdir -p `dirname #{t.name}`" - sh "cp #{t.prerequisites[0]} #{t.name}" - #sh "horizontal-morphing.py --categories='#{$categories_map[channel].join(',')}' --samples='WH_hww{MASS}' --uncerts='' --masses='110,120,130,140' --step-size=5 -i #{t.name}"# --extrapolate=#{$to_extrapolate.join(",")} #{t.name}" #FIXME! to be removed! - end - return ret -end - -mmt_morphed_shape_file = make_morphing_task('mmt', mmt_shape_file) -task :mmt_morphed_shapes => mmt_morphed_shape_file - -emt_morphed_shape_file = make_morphing_task('emt', emt_shape_file) -task :emt_morphed_shapes => emt_morphed_shape_file - -eet_morphed_shape_file = make_morphing_task('eet', eet_shape_file) -task :eet_morphed_shapes => eet_morphed_shape_file - - def make_cgs_conf_task(channel) ret = "#{$carddir}/#{channel}/cgs.conf" file ret => ["card_config/cgs.conf.#{channel}.#{$period}"] do |t| @@ -664,10 +612,11 @@ def make_unc_conf_task(channel, opttag='') return ret end -def make_unc_vals_task(channel, opttag='') +def make_unc_vals_task(channel, opttag='', use_postfit=false) ret = "#{$carddir}/#{channel}/unc.vals" + additional = Array[] file ret => ["card_config/unc.vals.#{channel}.#{$period}", - "#{$carddir}/#{channel}/shapes.root"] do |t| #+ Dir.glob("results/#{$jobid}/plots/#{channel}/*_statshapes.root") shapes.root depends on statshapes, so are redundant + "#{$carddir}/#{channel}/shapes.root"] do |t| #+ Dir.glob("results/#{$jobid}/plots/#{channel}/*_statshapes.root") shapes.root depends on statshapes, so are redundant # Copy the basic template carddir_channel = File.dirname(t.name) sh "mkdir -p #{carddir_channel}" @@ -680,7 +629,11 @@ def make_unc_vals_task(channel, opttag='') sh "cat #{list} | xargs -n 1 -I {} echo '#{category} fakes {} 1.0' >> #{t.name}" #sh "python get_fake_systematic.py #{carddir_channel}/shapes.root #{$categories_map[channel].join(',')} CMS_vhtt_#{category}_fakes_#{$period} >> #{t.name}" end - sh "python get_fake_systematic.py #{carddir_channel}/shapes.root #{$categories_map[channel].join(',')} CMS_vhtt_#{channel}_fakes_#{$period} >> #{t.name}" + if !use_postfit + sh "echo #{$categories_map[channel].join(',')} fakes CMS_vhtt_#{channel}_fakes_#{$period} 1.50 >> #{t.name}" + else + sh "./get_fake_systematic.py results/#{$jobid}/plots/#{channel}/f3/postfit/#{channel}.pulls.all.raw_txt CMS_vhtt_#{channel}_fakes_#{$period} 1.50 '#{$categories_map[channel].join(',')} fakes' >> #{t.name}" + end end end @@ -727,6 +680,242 @@ def combine_channels(mass) return card end +def copy_file(source, target) + file target => [source] do |t| + sh "mkdir -p `dirname #{t.name}`" + sh "cp -v #{t.prerequisites[0]} #{t.name}" + end + return target +end + + + +################################################################################# +#### Background-only f3 pulls, to convince yourself and the others ############# +#### (but mostly the others) that the background estimation is fine ############# +################################################################################# + +$carddir = "results/#{$jobid}/bkg-only-pulls" #change global var so we can reuse the functions + +mmt_f3_shape_file = "#{$mmtdir}/mmt_f3_shapes_#{$period}.root" +$categories_map['mmt'].each do |category| + mmt_f3_shape_file = add_fake_errors(mmt_f3_shape_file, "mmt_f3", category) +end +task :mmt_f3_shapes => mmt_f3_shape_file + +emt_f3_shape_file = "#{$emtdir}/emt_f3_shapes_#{$period}.root" +$categories_map['emt'].each do |category| + emt_f3_shape_file = add_fake_errors(emt_f3_shape_file, "emt_f3", category) +end +task :emt_f3_shapes => emt_f3_shape_file + +eet_f3_shape_file = "#{$eetdir}/eet_f3_shapes_#{$period}.root" +$categories_map['eet'].each do |category| + eet_f3_shape_file = add_fake_errors(eet_f3_shape_file, "eet_f3", category) +end +task :eet_f3_shapes => eet_f3_shape_file + +def make_copy_task(channel, shapefile) + ret = "#{$carddir}/#{channel}/shapes.root" + file ret => [shapefile] do |t| + sh "mkdir -p `dirname #{t.name}`" + sh "cp #{t.prerequisites[0]} #{t.name}" + end + return ret +end + +task :mmt_copied_f3_shapes => copy_file(mmt_f3_shape_file, "#{$carddir}/mmt/shapes.root") +task :emt_copied_f3_shapes => copy_file(emt_f3_shape_file, "#{$carddir}/emt/shapes.root") +task :eet_copied_f3_shapes => copy_file(eet_f3_shape_file, "#{$carddir}/eet/shapes.root") + +def make_f3_timestamp_task(channel) + timestamp = "#{$carddir}/#{channel}/.creation_timestamp" + #creates the tasks + make_unc_conf_task(channel, '_f3') + make_unc_vals_task(channel, '_f3') + make_cgs_conf_task(channel) + file timestamp => make_datacard_task(120, channel) do |t| + sh "touch #{t.name}" + end +end + +file "#{$carddir}/llt/.creation_timestamp" => combine_channels(120) do |t| + sh "touch #{t.name}" +end + + +task :f3_cards_mmt => make_f3_timestamp_task('mmt') +task :f3_cards_emt => make_f3_timestamp_task('emt') +task :f3_cards_eet => make_f3_timestamp_task('eet') +task :f3_cards_llt => "#{$carddir}/llt/.creation_timestamp" + +task :f3_cards => [:f3_cards_mmt, + :f3_cards_emt, + :f3_cards_eet, + :f3_cards_llt + ] + + +def make_pulls_task(channel) + pulls_timestamp = "#{$carddir}/#{channel}/.pulls_computed" + carddir = $carddir #makes a copy so that if $cardir changes this does not + file pulls_timestamp => "#{$carddir}/#{channel}/.creation_timestamp" do |t| + chdir("#{carddir}/#{channel}") do + sh "limit.py --max-likelihood --stable --rMin 0 --rMax 0 120" + sh "python $CMSSW_BASE/src/HiggsAnalysis/CombinedLimit/test/diffNuisances.py 120/out/mlfit.root -f html > #{channel}.pulls.html" + sh "python $CMSSW_BASE/src/HiggsAnalysis/CombinedLimit/test/diffNuisances.py 120/out/mlfit.root -a -f html > #{channel}.pulls.all.html" + sh "python $CMSSW_BASE/src/HiggsAnalysis/CombinedLimit/test/diffNuisances.py 120/out/mlfit.root -a -f txt > #{channel}.pulls.all.raw_txt" + end + sh "touch #{t.name}" + end + return pulls_timestamp +end + +task :f3_pulls_mmt => make_pulls_task('mmt') +task :f3_pulls_emt => make_pulls_task('emt') +task :f3_pulls_eet => make_pulls_task('eet') +task :f3_pulls_llt => make_pulls_task('llt') +task :f3_pulls => Array[:f3_pulls_mmt, + :f3_pulls_emt, + :f3_pulls_eet, + :f3_pulls_llt] + + + + + +################################################################################# +#### Background-only f3 post-fit plots, to convince yourself and the ###### +#### others (but mostly the others) that the background estimation is fine ###### +################################################################################# + +def make_f3_postfit_shapes_task(channel) + shape_file = "results/#{$jobid}/plots/#{channel}/f3/postfit/#{channel}_f3_postfit_shapes.root" + carddir = $carddir #makes a copy so that if $cardir changes this does not + file shape_file => "#{carddir}/#{channel}/.pulls_computed" do |t| + sh "mkdir -p `dirname #{t.name}`" + sh "cp #{carddir}/#{channel}/shapes.root #{t.name}" #FIXME this may create to rake some problems if next command fails! + sh "#{ENV['CMSSW_BASE']}/src/HiggsAnalysis/HiggsToTauTau/test/postfit.py #{t.name} #{carddir}/#{channel}/120/vhtt_#{channel}.txt --verbose --bins #{$categories_map[channel].join(' ')} --fitresults #{carddir}/#{channel}/120/out/mlfit.txt" + end + return shape_file +end + +task :f3_postfit_shapes_mmt => make_f3_postfit_shapes_task('mmt') +task :f3_postfit_shapes_emt => make_f3_postfit_shapes_task('emt') +task :f3_postfit_shapes_eet => make_f3_postfit_shapes_task('eet') +#task :f3_postfit_shapes_llt => make_f3_postfit_shapes_task('llt') +task :f3_postfit_shapes => Array[:f3_postfit_shapes_mmt, + :f3_postfit_shapes_emt, + :f3_postfit_shapes_eet] + + +#categories +$xlabels_map = Hash[ + 'eet' => '"M_{e_{2}#tau} (GeV)"', + 'emt' => '"M_{l_{2}#tau} (GeV)"', + 'mmt' => '"M_{#mu_{2}#tau} (GeV)"', +] + + +def make_f3_postfit_plots_task(channel) + resultdir = "results/#{$jobid}/plots/#{channel}/f3/postfit" + shape_file = "#{resultdir}/#{channel}_f3_postfit_shapes.root" + plot_timestamp = "#{resultdir}/.postfit_plots_timestamp" + carddir = $carddir #makes a copy so that if $cardir changes this does not + file plot_timestamp => shape_file do |t| + sh "mkdir -p `dirname #{t.name}`" + $categories_map[channel].each do |category| + sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{category} -e 'WH*' -o #{resultdir}/#{category}.png -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV'" + sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{category} -e 'WH*' -o #{resultdir}/#{category}.pdf -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV'" + end + sh "cp -v #{carddir}/#{channel}/#{channel}.pulls* #{resultdir}/." + sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{$categories_map[channel].join(' ')} -e 'WH*' -o #{resultdir}/#{channel}_categories_summed.png -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV'" + sh "touch #{t.name}" + end + return plot_timestamp +end + +task :f3_postfit_plots_mmt => make_f3_postfit_plots_task('mmt') +task :f3_postfit_plots_emt => make_f3_postfit_plots_task('emt') +task :f3_postfit_plots_eet => make_f3_postfit_plots_task('eet') +#task :f3_postfit_plots_llt => make_f3_postfit_plots_task('llt') +task :f3_postfit_plots => Array[:f3_postfit_plots_mmt, + :f3_postfit_plots_emt, + :f3_postfit_plots_eet] + + + + + + + + +################################################################################ +# Recipes to make data cards (plots come for free) +# targets: +# mmt_shapes +# emt_shapes +# eet_shapes +# cards +# copycards -> move cards to official HTT CVS area +################################################################################ + +$carddir = "results/#{$jobid}/cards" + +mmt_shape_file = "#{$mmtdir}/mmt_shapes_#{$period}.root" +$categories_map['mmt'].each do |category| + mmt_shape_file = add_fake_errors(mmt_shape_file, "mmt", category) +end +task :mmt_shapes => mmt_shape_file + +emt_shape_file = "#{$emtdir}/emt_shapes_#{$period}.root" +$categories_map['emt'].each do |category| + emt_shape_file = add_fake_errors(emt_shape_file, "emt", category) +end +task :emt_shapes => emt_shape_file + +eet_shape_file = "#{$eetdir}/eet_shapes_#{$period}.root" +$categories_map['eet'].each do |category| + eet_shape_file = add_fake_errors(eet_shape_file, "eet", category) +end +task :eet_shapes => eet_shape_file + +$carddir = "results/#{$jobid}/cards" + +cardmasses = get_sample_names('VH') #get all the VH samples available +cardmasses = cardmasses.select{|x| not x.include? "HWW"} #get only the H2Tau, to avid repetition +if $period == '8TeV' + cardmasses = cardmasses.map{|x| x.sub("VH_H2Tau_M-","")} #remove trailing name, the leftover is the mass (as a string) +else + cardmasses = cardmasses.map{|x| x.sub("VH_","")} #remove trailing name, the leftover is the mass (as a string) +end +cardmasses = cardmasses.map{|x| Integer(x)} #maps to integers (don't know if it's really needed but can't harm) +cardmasses = cardmasses.select{|x| x <= 140} #FIXME! to be removed! +#puts cardmasses + +$to_extrapolate = cardmasses.select{|x| x > 140} + +def make_morphing_task(channel, shapefile) + ret = "#{$carddir}/#{channel}/shapes.root" + file ret => [shapefile] do |t| + sh "mkdir -p `dirname #{t.name}`" + sh "cp #{t.prerequisites[0]} #{t.name}" + sh "horizontal-morphing.py --categories='#{$categories_map[channel].join(',')}' --samples='WH_hww{MASS}' --uncerts='' --masses='110,120,130,140' --step-size=5 -i #{t.name}"# --extrapolate=#{$to_extrapolate.join(",")} #{t.name}" #FIXME! to be removed! + end + return ret +end + +mmt_morphed_shape_file = make_morphing_task('mmt', mmt_shape_file) +task :mmt_morphed_shapes => mmt_morphed_shape_file + +emt_morphed_shape_file = make_morphing_task('emt', emt_shape_file) +task :emt_morphed_shapes => emt_morphed_shape_file + +eet_morphed_shape_file = make_morphing_task('eet', eet_shape_file) +task :eet_morphed_shapes => eet_morphed_shape_file + + + def make_timestamp_task(cardmasses, channel) timestamp = "#{$carddir}/#{channel}/.creation_timestamp" #creates the tasks @@ -870,14 +1059,6 @@ end $httcombodir = "#{ENV['CMSSW_BASE']}/src/HiggsAnalysis/HiggsToTauTau/setup/vhtt/" $auxdir = "#{ENV['CMSSW_BASE']}/src/auxiliaries/datacards/collected/vhtt/" -def copy_file(source, target) - file target => [source] do |t| - sh "mkdir -p `dirname #{t.name}`" - sh "cp -v #{t.prerequisites[0]} #{t.name}" - end - return target -end - def copy_and_trim_file(source, target) file target => [source] do |t| sh "mkdir -p `dirname #{t.name}`" @@ -920,150 +1101,3 @@ task :copycards => ["#{$auxdir}/vhtt_llt.inputs-sm-#{$period}.root"] + end -################################################################################# -#### Background-only f3 pulls, to convince yourself and the others ############# -#### (but mostly the others) that the background estimation is fine ############# -################################################################################# - -$carddir = "results/#{$jobid}/bkg-only-pulls" #change global var so we can reuse the functions - -mmt_f3_shape_file = "#{$mmtdir}/mmt_f3_shapes_#{$period}.root" -$categories_map['mmt'].each do |category| - mmt_f3_shape_file = add_fake_errors(mmt_f3_shape_file, "mmt_f3", category) -end -task :mmt_f3_shapes => mmt_f3_shape_file - -emt_f3_shape_file = "#{$emtdir}/emt_f3_shapes_#{$period}.root" -$categories_map['emt'].each do |category| - emt_f3_shape_file = add_fake_errors(emt_f3_shape_file, "emt_f3", category) -end -task :emt_f3_shapes => emt_f3_shape_file - -eet_f3_shape_file = "#{$eetdir}/eet_f3_shapes_#{$period}.root" -$categories_map['eet'].each do |category| - eet_f3_shape_file = add_fake_errors(eet_f3_shape_file, "eet_f3", category) -end -task :eet_f3_shapes => eet_f3_shape_file - -def make_copy_task(channel, shapefile) - ret = "#{$carddir}/#{channel}/shapes.root" - file ret => [shapefile] do |t| - sh "mkdir -p `dirname #{t.name}`" - sh "cp #{t.prerequisites[0]} #{t.name}" - end - return ret -end - -task :mmt_copied_f3_shapes => copy_file(mmt_f3_shape_file, "#{$carddir}/mmt/shapes.root") -task :emt_copied_f3_shapes => copy_file(emt_f3_shape_file, "#{$carddir}/emt/shapes.root") -task :eet_copied_f3_shapes => copy_file(eet_f3_shape_file, "#{$carddir}/eet/shapes.root") - -def make_f3_timestamp_task(cardmasses, channel) - timestamp = "#{$carddir}/#{channel}/.creation_timestamp" - #creates the tasks - make_unc_conf_task(channel, '_f3') - make_unc_vals_task(channel, '_f3') - make_cgs_conf_task(channel) - file timestamp => cardmasses.map{|x| make_datacard_task(x, channel)} do |t| - sh "touch #{t.name}" - end -end - -file "#{$carddir}/llt/.creation_timestamp" => combine_channels(120) do |t| - sh "touch #{t.name}" -end - - -task :f3_cards_mmt => make_f3_timestamp_task([120], 'mmt') -task :f3_cards_emt => make_f3_timestamp_task([120], 'emt') -task :f3_cards_eet => make_f3_timestamp_task([120], 'eet') -task :f3_cards_llt => "#{$carddir}/llt/.creation_timestamp" - -task :f3_cards => [:f3_cards_mmt, - :f3_cards_emt, - :f3_cards_eet, - :f3_cards_llt - ] - - -def make_pulls_task(channel) - pulls_timestamp = "#{$carddir}/#{channel}/.pulls_computed" - carddir = $carddir #makes a copy so that if $cardir changes this does not - file pulls_timestamp => "#{$carddir}/#{channel}/.creation_timestamp" do |t| - chdir("#{carddir}/#{channel}") do - sh "limit.py --max-likelihood --stable --rMin 0 --rMax 0 120" - sh "python $CMSSW_BASE/src/HiggsAnalysis/CombinedLimit/test/diffNuisances.py 120/out/mlfit.root -f html > #{channel}.pulls.html" - sh "python $CMSSW_BASE/src/HiggsAnalysis/CombinedLimit/test/diffNuisances.py 120/out/mlfit.root -a -f html > #{channel}.pulls.all.html" - sh "python $CMSSW_BASE/src/HiggsAnalysis/CombinedLimit/test/diffNuisances.py 120/out/mlfit.root -a -f txt > #{channel}.pulls.all.raw_txt" - end - sh "touch #{t.name}" - end - return pulls_timestamp -end - -task :f3_pulls_mmt => make_pulls_task('mmt') -task :f3_pulls_emt => make_pulls_task('emt') -task :f3_pulls_eet => make_pulls_task('eet') -task :f3_pulls_llt => make_pulls_task('llt') -task :f3_pulls => Array[:f3_pulls_mmt, - :f3_pulls_emt, - :f3_pulls_eet, - :f3_pulls_llt] - -################################################################################# -#### Background-only f3 post-fit plots, to convince yourself and the ###### -#### others (but mostly the others) that the background estimation is fine ###### -################################################################################# - -def make_f3_postfit_shapes_task(channel) - shape_file = "results/#{$jobid}/plots/#{channel}/f3/postfit/#{channel}_f3_postfit_shapes.root" - carddir = $carddir #makes a copy so that if $cardir changes this does not - file shape_file => "#{$carddir}/#{channel}/.pulls_computed" do |t| - sh "mkdir -p `dirname #{t.name}`" - sh "cp #{carddir}/#{channel}/shapes.root #{t.name}" #FIXME this may create to rake some problems if next command fails! - sh "#{ENV['CMSSW_BASE']}/src/HiggsAnalysis/HiggsToTauTau/test/postfit.py #{t.name} #{$carddir}/#{channel}/120/vhtt_#{channel}.txt --verbose --bins #{$categories_map[channel].join(' ')} --fitresults #{$carddir}/#{channel}/120/out/mlfit.txt" - end - return shape_file -end - -task :f3_postfit_shapes_mmt => make_f3_postfit_shapes_task('mmt') -task :f3_postfit_shapes_emt => make_f3_postfit_shapes_task('emt') -task :f3_postfit_shapes_eet => make_f3_postfit_shapes_task('eet') -#task :f3_postfit_shapes_llt => make_f3_postfit_shapes_task('llt') -task :f3_postfit_shapes => Array[:f3_postfit_shapes_mmt, - :f3_postfit_shapes_emt, - :f3_postfit_shapes_eet] - - -#categories -$xlabels_map = Hash[ - 'eet' => '"M_{e_{2}#tau} (GeV)"', - 'emt' => '"M_{l_{2}#tau} (GeV)"', - 'mmt' => '"M_{#mu_{2}#tau} (GeV)"', -] - - -def make_f3_postfit_plots_task(channel) - resultdir = "results/#{$jobid}/plots/#{channel}/f3/postfit" - shape_file = "#{resultdir}/#{channel}_f3_postfit_shapes.root" - plot_timestamp = "#{resultdir}/.postfit_plots_timestamp" - file plot_timestamp => shape_file do |t| - sh "mkdir -p `dirname #{t.name}`" - $categories_map[channel].each do |category| - sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{category} -e 'WH*' -o #{resultdir}/#{category}.png -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV'" - sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{category} -e 'WH*' -o #{resultdir}/#{category}.pdf -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV'" - end - sh "cp -v #{$carddir}/#{channel}/#{channel}.pulls* #{resultdir}/." - sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{$categories_map[channel].join(' ')} -e 'WH*' -o #{resultdir}/#{channel}_categories_summed.png -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV'" - sh "touch #{t.name}" - end - return plot_timestamp -end - -task :f3_postfit_plots_mmt => make_f3_postfit_plots_task('mmt') -task :f3_postfit_plots_emt => make_f3_postfit_plots_task('emt') -task :f3_postfit_plots_eet => make_f3_postfit_plots_task('eet') -#task :f3_postfit_plots_llt => make_f3_postfit_plots_task('llt') -task :f3_postfit_plots => Array[:f3_postfit_plots_mmt, - :f3_postfit_plots_emt, - :f3_postfit_plots_eet] From 93077efb87e25bbcd3c498d544379fc90bddadf1 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 08:54:46 -0500 Subject: [PATCH 013/192] updated mass range, WZ rejection, and some binning --- wh/WHAnalyzeEET.py | 32 ++++++++++++++++---------------- wh/WHAnalyzeEMT.py | 11 +++++++---- wh/WHAnalyzeMMT.py | 2 +- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/wh/WHAnalyzeEET.py b/wh/WHAnalyzeEET.py index 6ea9af94..f57ce89a 100755 --- a/wh/WHAnalyzeEET.py +++ b/wh/WHAnalyzeEET.py @@ -139,14 +139,16 @@ def anti_charge_flip(row, rejection_power=80): def book_histos(self, folder): #PLOTS TO FILL IN ANY CASE + LTBinning = array('d',[0, 80, 130, 600]) + nLTBins = len(LTBinning) -1 for key in self.grid_search: prefix = key+'$' if key else '' self.book(folder, prefix+"LT", "L_T", 100, 0, 300) - self.book(folder, prefix+"e2_t_Mass", "subleadingMass", 200, 0, 200) + self.book(folder, prefix+"e2_t_Mass", "subleadingMass", 300, 0, 300) self.book(folder, prefix+"e2_t_Pt", "subleadingPt", 400, 0, 400) #Charge mis-id special histograms if 'c2' in folder: - self.book(folder, prefix+"e*2_t_Mass", "subleadingMass with misid sclaing correction", 200, 0, 200) + self.book(folder, prefix+"e*2_t_Mass", "subleadingMass with misid sclaing correction", 300, 0, 300) if len(self.grid_search.keys()) == 1: if 'c1' in folder: @@ -156,28 +158,26 @@ def book_histos(self, folder): self.book(folder, "e1_e*2_Mass", "E 1-2 Mass with misid sclaing correction", 120, 0, 120) #self.book(folder, "e*2_t_Mass#faking_prob", '', 200, 0, 200, 1100, 0., 1.1, type=ROOT.TH2F) #self.book(folder, "e*2_t_Mass#log_prob" , '', 200, 0, 200, 1000, -10, 1, type=ROOT.TH2F) - self.book(folder, "e*2_t_Mass#LT" , '', 200, 0, 200, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, "e*2_t_Mass#tPt" , '', 200, 0, 200, 200, 0, 200, type=ROOT.TH2F) + self.book(folder, "e*2_t_Mass#LT" , '', 300, 0, 300, nLTBins, LTBinning, type=ROOT.TH2F) - self.book(folder, prefix+"e2_t_Mass#LT" , "subleadingMass", 200, 0, 200, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"e2_t_Mass#tPt", "subleadingMass", 200, 0, 200, 200, 0, 200, type=ROOT.TH2F) + self.book(folder, prefix+"e2_t_Mass#LT" , "subleadingMass", 300, 0, 300, nLTBins, LTBinning, type=ROOT.TH2F) #Pt - self.book(folder, prefix+"e1Pt#LT" , "subleadingMass", 150, 0, 150, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"e2Pt#LT" , "subleadingMass", 150, 0, 150, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"tPt#LT" , "subleadingMass", 150, 0, 150, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"e1JetPt#LT" , "subleadingMass", 150, 0, 150, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"e2JetPt#LT" , "subleadingMass", 150, 0, 150, 120, 0, 600, type=ROOT.TH2F) + self.book(folder, prefix+"e1Pt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, prefix+"e2Pt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, prefix+"tPt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, prefix+"e1JetPt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, prefix+"e2JetPt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) #eta - self.book(folder, prefix+"e1AbsEta#LT" , "subleadingMass", 100, 0, 2.5, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"e2AbsEta#LT" , "subleadingMass", 100, 0, 2.5, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"tAbsEta#LT" , "subleadingMass", 100, 0, 2.5, 120, 0, 600, type=ROOT.TH2F) + self.book(folder, prefix+"e1AbsEta#LT" , "subleadingMass", 100, 0, 2.5, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, prefix+"e2AbsEta#LT" , "subleadingMass", 100, 0, 2.5, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, prefix+"tAbsEta#LT" , "subleadingMass", 100, 0, 2.5, nLTBins, LTBinning, type=ROOT.TH2F) #DR - self.book(folder, prefix+"e1_t_DR#LT" , "subleadingMass", 100, 0, 10, 120, 0, 600, type=ROOT.TH2F) - self.book(folder, prefix+"e2_t_DR#LT" , "subleadingMass", 100, 0, 10, 120, 0, 600, type=ROOT.TH2F) + self.book(folder, prefix+"e1_t_DR#LT" , "subleadingMass", 100, 0, 10, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, prefix+"e2_t_DR#LT" , "subleadingMass", 100, 0, 10, nLTBins, LTBinning, type=ROOT.TH2F) #Jet BTag self.book(folder, "e1JetBtag#LT", "Muon 2 Pt", 30, -10, 5, 60, 0, 600, type=ROOT.TH2F) diff --git a/wh/WHAnalyzeEMT.py b/wh/WHAnalyzeEMT.py index 515514d7..007cce49 100644 --- a/wh/WHAnalyzeEMT.py +++ b/wh/WHAnalyzeEMT.py @@ -141,9 +141,9 @@ def book_histos(self, folder): self.book(folder, "e*_m_Mass", "Electron-Muon Mass", 200, 0, 200) #self.book(folder, "subMass*#faking_prob", '', 200, 0, 200, 220, 0., 1.1, type=ROOT.TH2F) #self.book(folder, "subMass*#log_prob" , '', 200, 0, 200, 200, -2, 1, type=ROOT.TH2F) - self.book(folder, "subMass*#LT" , '', 200, 0, 200, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "subMass*#LT" , '', 300, 0, 300, nLTBins, LTBinning, type=ROOT.TH2F) - self.book(folder, prefix+"subMass#LT" , "subleadingMass", 200, 0, 200, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, prefix+"subMass#LT" , "subleadingMass", 300, 0, 300, nLTBins, LTBinning, type=ROOT.TH2F) self.book(folder, "e_m_Mass#LT", "Electron-Muon Mass", 200, 0, 200, nLTBins, LTBinning, type=ROOT.TH2F) self.book(folder, "m_t_Mass#LT", "Electron-Muon Mass", 200, 0, 200, nLTBins, LTBinning, type=ROOT.TH2F) self.book(folder, "e_t_Mass#LT", "Electron-Tau Mass" , 200, 0, 200, nLTBins, LTBinning, type=ROOT.TH2F) @@ -248,8 +248,8 @@ def preselection( self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr if not selections.tauSelection(row, 't'): return False #applies basic selection (eta, pt > 20, DZ) if row.tPt < taupt_thr: return False - if row.tMuOverlap: return False - if not row.tAntiMuonTight: return False + #if row.tMuOverlap: return False + if not row.tAntiMuonLoose: return False cut_flow_trk.Fill('obj3 Presel') if row.LT < LT_threshold: return False @@ -311,6 +311,9 @@ def anti_wz( row): return False elif not row.tAntiElectronMVA3Loose: return False + elif row.m_t_Zcompat < 20: + if not row.tAntiMuonTight: + return False return True def enhance_wz(self, row): diff --git a/wh/WHAnalyzeMMT.py b/wh/WHAnalyzeMMT.py index 50f5b22e..e349b742 100755 --- a/wh/WHAnalyzeMMT.py +++ b/wh/WHAnalyzeMMT.py @@ -99,7 +99,7 @@ def book_histos(self, folder): if len(self.grid_search.keys()) == 1: - self.book(folder, "m2_t_Mass#LT" , "subleadingMass", 200, 0, 200, 120, 0, 600, type=ROOT.TH2F) + self.book(folder, "m2_t_Mass#LT" , "subleadingMass", 300, 0, 300, nLTBins, LTBinning, type=ROOT.TH2F) #Pt self.book(folder, "m1Pt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) From c61b4dbaeeb13e7e7fc7ece88668034f46241ce7 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:03:02 -0500 Subject: [PATCH 014/192] automatically excludes missing signal samples --- wh/WHPlotterBase.py | 91 ++++++++++++++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 31 deletions(-) diff --git a/wh/WHPlotterBase.py b/wh/WHPlotterBase.py index 869f6e59..851c33b9 100644 --- a/wh/WHPlotterBase.py +++ b/wh/WHPlotterBase.py @@ -200,7 +200,7 @@ def __init__(self, channel, obj1_charge_mapper={}, obj2_charge_mapper={}): 'ZZ*', 'VH*', 'WW*', - 'TTplusJets_madgraph', + #'TTplusJets_madgraph', "data_*", ] @@ -228,6 +228,7 @@ def __init__(self, channel, obj1_charge_mapper={}, obj2_charge_mapper={}): super(WHPlotterBase, self).__init__(files, lumifiles, self.outputdir, blinder) self.defaults = {} #allows to set some options and avoid repeating them each function call + self.mc_samples = filter(lambda x: x.startswith('data'), samples) os.chdir( cwd ) #create a fake wiew summing up all HWW self.views['VH_hww_sum'] = { @@ -244,6 +245,8 @@ def apply_to_dict(self, dictionary, viewtype, *args, **kwargs): #project, projec for key, val in dictionary.iteritems(): if isinstance(val, dict): ret[key] = self.apply_to_dict(val, viewtype, *args, **kwargs) #project, project_axis, rebin) + elif val is None: + ret[key] = None else: ret[key] = viewtype(val, *args, **kwargs) # self.rebin_view( ProjectionView(val, project_axis, project), rebin ) return ret @@ -256,8 +259,9 @@ def make_signal_views(self, unblinded=False, qcd_weight_fraction=0): self.get_view('WZJetsTo3LNu*ZToTauTau*'), 'ss/p1p2p3/' ) + tomatch = 'WZJetsTo3LNu' if self.sqrts == 7 else 'WZJetsTo3LNu_pythia' wz_view_3l = views.SubdirectoryView( - self.get_view('WZJetsTo3LNu_pythia'), + self.get_view(tomatch), 'ss/p1p2p3/' ) zz_view = views.SubdirectoryView( @@ -371,20 +375,29 @@ def make_fakes_view(weight_type, scale): # Add signal data_total_lumi = self.views['data']['intlumi'] - for mass in range(110, 165, 5): - vh_view = views.SubdirectoryView( - self.get_view('VH_*%i' % mass), - 'ss/p1p2p3/' - ) - output['vh%i' % mass] = vh_view + for mass in range(100, 165, 5): + try: + vh_view = views.SubdirectoryView( + self.get_view('VH_*%i' % mass), + 'ss/p1p2p3/' + ) + output['vh%i' % mass] = vh_view + except KeyError: + logging.warning('No sample found matching VH_*%i' % mass) + continue + if mass % 10 == 0 and mass < 150: # Only have 10 GeV steps for WW - ww_view = views.SubdirectoryView( - self.get_view('VH_%i_HWW*' % mass), - 'ss/p1p2p3/' - ) + try: + ww_view = views.SubdirectoryView( + self.get_view('VH_%i_HWW*' % mass), + 'ss/p1p2p3/' + ) + except KeyError: + logging.warning('No sample found matching VH_%i_HWW*' % mass) + ww_view = None output['vh%i_hww' % mass] = ww_view - output['signal%i' % mass] = views.SumView(ww_view, vh_view) + output['signal%i' % mass] = views.SumView(ww_view, vh_view) if ww_view else vh_view return output @@ -428,8 +441,9 @@ def make_obj3_fail_cr_views(self, qcd_correction=False, self.get_view('WZJetsTo3LNu*ZToTauTau*'), 'ss/p1p2f3/' ) + tomatch = 'WZJetsTo3LNu' if self.sqrts == 7 else 'WZJetsTo3LNu_pythia' wz_view_3l = views.SubdirectoryView( - self.get_view('WZJetsTo3LNu_pythia'), + self.get_view(tomatch), 'ss/p1p2f3/' ) zz_view = views.SubdirectoryView( @@ -546,12 +560,16 @@ def make_fakes_view(weight_type, scale): 'ss/p1p2f3/' ) output['vh%i' % mass] = vh_view - ww_view = views.SubdirectoryView( - self.get_view('VH_%i_HWW*' % mass), - 'ss/p1p2f3/' - ) + try: + ww_view = views.SubdirectoryView( + self.get_view('VH_%i_HWW*' % mass), + 'ss/p1p2f3/' + ) + except KeyError: + logging.warning('No sample found matching VH_%i_HWW*' % mass) + ww_view = None output['vh%i_hww' % mass] = ww_view - output['signal%i' % mass] = views.SumView(ww_view, vh_view) + output['signal%i' % mass] = views.SumView(ww_view, vh_view) if ww_view else vh_view return output @@ -633,15 +651,21 @@ def write_shapes(self, variable, rebin, outdir, fakes.SetName('fakes') #for mass in [110, 115, 120, 125, 130, 135, 140]: - for mass in range(110, 165, 5): - vh = sig_view['vh%i' % mass].Get(variable) - vh.SetName('WH%i' % mass) - vh.Write() + for mass in range(100, 165, 5): + try: + vh = sig_view['vh%i' % mass].Get(variable) + vh.SetName('WH%i' % mass) + vh.Write() + except KeyError: + logging.warning('No sample found matching VH_*%i' % mass) + continue + if mass % 10 == 0 and mass < 150: # Only have 10 GeV steps for WW - ww = sig_view['vh%i_hww' % mass].Get(variable) - ww.SetName('WH_hww%i' % mass) - ww.Write() + if sig_view['vh%i_hww' % mass]: + ww = sig_view['vh%i_hww' % mass].Get(variable) + ww.SetName('WH_hww%i' % mass) + ww.Write() wz.Write() zz.Write() @@ -701,9 +725,10 @@ def write_f3_shapes(self, variable, rebin, outdir, vh.SetName('WH%i' % mass) vh.Write() # Only have 10 GeV steps for WW - ww = sig_view['vh%i_hww' % mass].Get(variable) - ww.SetName('WH_hww%i' % mass) - ww.Write() + if sig_view['vh%i_hww' % mass]: + ww = sig_view['vh%i_hww' % mass].Get(variable) + ww.SetName('WH_hww125') + ww.Write() #charge_fakes_CMS_vhtt_emt_chargeFlip_8TeVUpx if show_charge_fakes: @@ -722,7 +747,7 @@ def plot_final(self, variable, rebin=1, xaxis='', maxy=24, show_error=False, qcd_correction=False, stack_higgs=True, qcd_weight_fraction=0.5, x_range=None, show_charge_fakes=False, leftside_legend=False, higgs_xsec_multiplier=5, project=None, - project_axis=None, differential=False, **kwargs): + project_axis=None, differential=False, yaxis='Events', **kwargs): ''' Plot the final output - with bkg. estimation ''' show_charge_fakes = show_charge_fakes if 'show_charge_fakes' not in self.defaults else self.defaults['show_charge_fakes'] sig_view = self.make_signal_views(unblinded=(not self.blind), @@ -754,6 +779,8 @@ def plot_final(self, variable, rebin=1, xaxis='', maxy=24, histo.Draw() histo.GetHistogram().GetXaxis().SetTitle(xaxis) + histo.GetHistogram().GetYaxis().SetTitle(yaxis) + if x_range: histo.GetHistogram().GetXaxis().SetRangeUser(x_range[0], x_range[1]) if isinstance(maxy, (int, long, float)): @@ -837,7 +864,7 @@ def plot_final_f3(self, variable, rebin=1, xaxis='', maxy=None, show_error=True, qcd_correction=False, qcd_weight_fraction=0.5, x_range=None, #): show_chi2=False,project=None, - project_axis=None, differential=False, **kwargs): + project_axis=None, differential=False, yaxis='Events', **kwargs): ''' Plot the final F3 control region - with bkg. estimation ''' sig_view = self.make_obj3_fail_cr_views( @@ -860,6 +887,8 @@ def plot_final_f3(self, variable, rebin=1, xaxis='', maxy=None, histo = stack.Get(variable) histo.Draw() histo.GetHistogram().GetXaxis().SetTitle(xaxis) + histo.GetHistogram().GetYaxis().SetTitle(yaxis) + if x_range: histo.GetHistogram().GetXaxis().SetRangeUser(x_range[0], x_range[1]) From e3d5566b3da270883bbe4e3cdf56c1e3ff90d6dc Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:03:49 -0500 Subject: [PATCH 015/192] work in progress --- wh/WHPlotterEMT.py | 106 ++++++++++++++++++++++++++++++--------------- 1 file changed, 71 insertions(+), 35 deletions(-) diff --git a/wh/WHPlotterEMT.py b/wh/WHPlotterEMT.py index 86fb4fb1..85b58355 100644 --- a/wh/WHPlotterEMT.py +++ b/wh/WHPlotterEMT.py @@ -40,9 +40,9 @@ def __init__(self): plotter.set_subdir('mc_data') # Control Z->tautau + jet region - plotter.plot_mc_vs_data('os/p1p2f3', 'e_m_Mass', rebin=10, xaxis='m_{e#mu} (GeV)', leftside=False) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-os-p1p2f3-emMass') + #plotter.plot_mc_vs_data('os/p1p2f3', 'e_m_Mass', rebin=10, xaxis='m_{e#mu} (GeV)', leftside=False) + #plotter.add_cms_blurb(sqrts) + #plotter.save('mcdata-os-p1p2f3-emMass') plotter.plot_mc_vs_data('os/p1p2f3', 'nTruePU', rebin=1, xaxis='True PU') plotter.add_cms_blurb(sqrts) @@ -56,14 +56,14 @@ def __init__(self): ## plotter.add_cms_blurb(sqrts) ## plotter.save('mcdata-os-p1p2f3-bveto') - plotter.plot_mc_vs_data('os/p1p2f3/w3', 'e_m_Mass', 10) - plotter.save('mcdata-os-p1p2f3-w3-emMass') - - plotter.plot_mc_vs_data('os/p1f2p3', 'e_m_Mass', 10) - plotter.save('mcdata-os-p1f2p3-emMass') - - plotter.plot_mc_vs_data('os/f1p2p3', 'e_m_Mass', 10) - plotter.save('mcdata-os-p1f2p3-emMass') + #plotter.plot_mc_vs_data('os/p1p2f3/w3', 'e_m_Mass', 10) + #plotter.save('mcdata-os-p1p2f3-w3-emMass') + # + #plotter.plot_mc_vs_data('os/p1f2p3', 'e_m_Mass', 10) + #plotter.save('mcdata-os-p1f2p3-emMass') + # + #plotter.plot_mc_vs_data('os/f1p2p3', 'e_m_Mass', 10) + #plotter.save('mcdata-os-p1f2p3-emMass') # Check PU variables #plotter.plot_mc_vs_data('os/p1p2f3', 'rho') @@ -81,15 +81,15 @@ def __init__(self): # Make Z->mumu + tau jet control - weighted = plotter.plot('data', 'os/p1p2f3/w3/e_m_Mass', 'hist', rebin=20, styler=make_styler(2, 'hist'), xaxis='m_{e#mu} (GeV)') - unweighted = plotter.plot('data', 'os/p1p2p3/e_m_Mass', 'same', rebin=20, styler=make_styler(1), xaxis='m_{e#mu} (GeV)') - weighted.SetTitle('e^{+}#mu^{-} + fake #tau_{h} est.') - weighted.legendstyle = 'l' - unweighted.SetTitle('e^{+}#mu^{-} + fake #tau_{h} obs.') - unweighted.legendstyle = 'pe' - plotter.add_legend([weighted, unweighted]) - plotter.add_cms_blurb(sqrts) - plotter.save('ztt-os-fr-control') + #weighted = plotter.plot('data', 'os/p1p2f3/w3/e_m_Mass', 'hist', rebin=20, styler=make_styler(2, 'hist'), xaxis='m_{e#mu} (GeV)') + #unweighted = plotter.plot('data', 'os/p1p2p3/e_m_Mass', 'same', rebin=20, styler=make_styler(1), xaxis='m_{e#mu} (GeV)') + #weighted.SetTitle('e^{+}#mu^{-} + fake #tau_{h} est.') + #weighted.legendstyle = 'l' + #unweighted.SetTitle('e^{+}#mu^{-} + fake #tau_{h} obs.') + #unweighted.legendstyle = 'pe' + #plotter.add_legend([weighted, unweighted]) + #plotter.add_cms_blurb(sqrts) + #plotter.save('ztt-os-fr-control') #plotter.plot('data', 'os/p1p2p3/prescale', styler=make_styler(1)) #plotter.save('ztt-os-prescale-check') @@ -136,19 +136,33 @@ def __init__(self): ## Signal region plots ################################################ ########################################################################### plotter.set_subdir('') - rebin_slim = [0,20]+range(30, 81, 10)+[100,130,200] + rebin_slim = [20]+range(30, 81, 10)+[100,130,300] categories = { 'LTCut' : [80, 650], 'LTLow' : [0, 130], 'LTHigh': [130, 650], + 'Full' : [0, 650], } for label, proj_range in categories.iteritems(): plotter.set_subdir('%s' % label) - plotter.plot_final('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X', differential=True) + plotter.plot_final('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, yaxis='Events / GeV') plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-%s' % label) + plotter.plot_final("e_m_Mass#LT", 20, xaxis='m_{e#mu} (GeV)' , maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-e_m_Mass-%s' % label) + + plotter.plot_final("m_t_Mass#LT", 20, xaxis='m_{#mu#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-m_t_Mass-%s' % label) + + plotter.plot_final("e_t_Mass#LT", 20, xaxis='m_{e#tau} (GeV)' , maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-e_t_Mass-%s' % label) + plotter.plot_final('subMass#LT', 200, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) @@ -237,17 +251,17 @@ def __init__(self): plotter.plot_final('tSubDR', 10) plotter.save('final-tSubDR') - plotter.plot_final('e_t_Mass', 10) - plotter.save('final-etMass') + #plotter.plot_final('e_t_Mass', 10) + #plotter.save('final-etMass') ########################################################################### ## WZ enhanced region plots ########################################### ########################################################################### plotter.set_subdir('WZ_enhanced') - plotter.plot_final_wz('e_t_Mass', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-etMass') + #plotter.plot_final_wz('e_t_Mass', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-wz-etMass') #plotter.plot_final_wz('mPt', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', maxy=20) #plotter.add_cms_blurb(sqrts) @@ -264,10 +278,32 @@ def __init__(self): for label, proj_range in categories.iteritems(): plotter.set_subdir('f3/%s' % label) - plotter.plot_final_f3('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X', differential=True) + plotter.plot_final_f3('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, yaxis='Events / GeV') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-%s' % label) + plotter.plot_final_f3('subMass#LT', [20, 40, 120, 200], xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, yaxis='Events / GeV') + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-widebin-%s' % label) + + plotter.plot_final_f3('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s-notDifferential' % label) + + plotter.plot_final_f3("e_m_Mass#LT", 20, xaxis='m_{e#mu} (GeV)' , maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-e_m_Mass-%s' % label) + + plotter.plot_final_f3("m_t_Mass#LT", 20, xaxis='m_{#mu#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-m_t_Mass-%s' % label) + + plotter.plot_final_f3("e_t_Mass#LT", 20, xaxis='m_{e#tau} (GeV)' , maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-e_t_Mass-%s' % label) + plotter.plot_final_f3('subMass#LT', 200, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) @@ -354,13 +390,13 @@ def __init__(self): plotter.save('final-f3-mJetBtag') - plotter.plot_final_f3('e_t_Mass', 20, xaxis='m_{e#tau_{#mu}} (GeV)', qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-etMass') - - plotter.plot_final_f3('e_m_Mass', 20, xaxis='m_{e#mu} (GeV)', qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-emMass') + #plotter.plot_final_f3('e_t_Mass', 20, xaxis='m_{e#tau_{#mu}} (GeV)', qcd_weight_fraction=0.5, show_error=True) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-etMass') + # + #plotter.plot_final_f3('e_m_Mass', 20, xaxis='m_{e#mu} (GeV)', qcd_weight_fraction=0.5, show_error=True) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-emMass') #plotter.plot_final_f3('m_t_Mass', 20, xaxis='m_{#mu#tau} (GeV)', qcd_weight_fraction=0.5, show_error=True) #plotter.add_cms_blurb(sqrts) From c67bcc3e511d347347a8bdcfa031e39bca9c973c Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:21:43 -0500 Subject: [PATCH 016/192] moved HWW125 from signal to background --- wh/card_config/cgs.conf.eet.8TeV | 6 +++--- wh/card_config/cgs.conf.emt.8TeV | 6 +++--- wh/card_config/cgs.conf.mmt.8TeV | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/wh/card_config/cgs.conf.eet.8TeV b/wh/card_config/cgs.conf.eet.8TeV index 317982bb..c70fa4f5 100644 --- a/wh/card_config/cgs.conf.eet.8TeV +++ b/wh/card_config/cgs.conf.eet.8TeV @@ -7,9 +7,9 @@ #backgrounds: background #data: data_obs -$ GROUP signal WH,WH_hww -$ GROUP all_background wz,zz,fakes,charge_fakes -$ GROUP simulated WH,wz,zz,WH_hww +$ GROUP signal WH +$ GROUP all_background wz,zz,fakes,charge_fakes,WH_hww125 +$ GROUP simulated WH,wz,zz,WH_hww125 categories: eetCatHigh,eetCatLow signals: signal diff --git a/wh/card_config/cgs.conf.emt.8TeV b/wh/card_config/cgs.conf.emt.8TeV index 7a41f0a7..07e64400 100644 --- a/wh/card_config/cgs.conf.emt.8TeV +++ b/wh/card_config/cgs.conf.emt.8TeV @@ -7,9 +7,9 @@ #backgrounds: background #data: data_obs -$ GROUP signal WH,WH_hww -$ GROUP all_background wz,zz,fakes,charge_fakes -$ GROUP simulated WH,wz,zz,WH_hww +$ GROUP signal WH +$ GROUP all_background wz,zz,fakes,charge_fakes,WH_hww125 +$ GROUP simulated WH,wz,zz,WH_hww125 categories: emtCatHigh,emtCatLow signals: signal diff --git a/wh/card_config/cgs.conf.mmt.8TeV b/wh/card_config/cgs.conf.mmt.8TeV index bad4fb30..aa3d1bf9 100644 --- a/wh/card_config/cgs.conf.mmt.8TeV +++ b/wh/card_config/cgs.conf.mmt.8TeV @@ -7,9 +7,9 @@ #backgrounds: background #data: data_obs -$ GROUP signal WH,WH_hww -$ GROUP background wz,zz,fakes -$ GROUP simulated WH,wz,zz,WH_hww +$ GROUP signal WH +$ GROUP background wz,zz,fakes,WH_hww125 +$ GROUP simulated WH,wz,zz,WH_hww125 categories: mmtCatHigh,mmtCatLow signals: signal From e6d9e4414a1214fc71bd9e3fe7e8ec742fbed0e7 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:22:33 -0500 Subject: [PATCH 017/192] cleanup added trigger uncertainties --- wh/card_config/unc.conf.eet.8TeV | 7 ++----- wh/card_config/unc.conf.emt.8TeV | 2 ++ wh/card_config/unc.conf.mmt.8TeV | 6 ++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/wh/card_config/unc.conf.eet.8TeV b/wh/card_config/unc.conf.eet.8TeV index 944955bc..7c64358b 100644 --- a/wh/card_config/unc.conf.eet.8TeV +++ b/wh/card_config/unc.conf.eet.8TeV @@ -6,6 +6,8 @@ lumi_8TeV lnN +CMS_trigger_e lnN + CMS_eff_e lnN CMS_eff_t lnN @@ -14,9 +16,6 @@ CMS_fake_b_8TeV lnN CMS_scale_t lnN CMS_vhtt_eet_fakes_8TeV lnN -#CMS_vhtt_eet_fakes_8TeV lnN -#CMS_vhtt_eetCatLow_fakes_8TeV lnN -#CMS_vhtt_eetCatHigh_fakes_8TeV lnN CMS_vhtt_eet_chargeFlip_8TeV shape @@ -24,5 +23,3 @@ pdf_qqbar lnN QCDscale_VH lnN QCDscale_VV lnN -# Only for testing. -#CMS_vhtt_llt_fakes lnN diff --git a/wh/card_config/unc.conf.emt.8TeV b/wh/card_config/unc.conf.emt.8TeV index e071e1a5..a448dd44 100644 --- a/wh/card_config/unc.conf.emt.8TeV +++ b/wh/card_config/unc.conf.emt.8TeV @@ -6,6 +6,8 @@ lumi_8TeV lnN +CMS_trigger_em lnN + CMS_eff_e lnN CMS_eff_m lnN CMS_eff_t lnN diff --git a/wh/card_config/unc.conf.mmt.8TeV b/wh/card_config/unc.conf.mmt.8TeV index be49adf7..6f1268f3 100644 --- a/wh/card_config/unc.conf.mmt.8TeV +++ b/wh/card_config/unc.conf.mmt.8TeV @@ -6,6 +6,8 @@ lumi_8TeV lnN +CMS_trigger_m lnN + CMS_eff_m lnN CMS_eff_t lnN @@ -14,12 +16,8 @@ CMS_fake_b_8TeV lnN CMS_scale_t lnN CMS_vhtt_mmt_fakes_8TeV lnN -#CMS_vhtt_mmtCatHigh_fakes_8TeV lnN -#CMS_vhtt_mmtCatLow_fakes_8TeV lnN pdf_qqbar lnN QCDscale_VH lnN QCDscale_VV lnN -# Only for testing. -#CMS_vhtt_llt_fakes lnN From ae32581dfde2271463051ab570d833564b3829fe Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:23:18 -0500 Subject: [PATCH 018/192] updated values --- wh/card_config/unc.vals.eet.8TeV | 13 ++++++++----- wh/card_config/unc.vals.emt.8TeV | 13 ++++++++----- wh/card_config/unc.vals.mmt.8TeV | 13 ++++++++----- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/wh/card_config/unc.vals.eet.8TeV b/wh/card_config/unc.vals.eet.8TeV index 79f1e01d..515bfc51 100644 --- a/wh/card_config/unc.vals.eet.8TeV +++ b/wh/card_config/unc.vals.eet.8TeV @@ -3,11 +3,14 @@ # Example: # emu_vbf,emu_novbf,emu_boost signal,EWK lumi 1.045 -eetCatLow,eetCatHigh simulated lumi_8TeV 1.042 +eetCatLow,eetCatHigh simulated lumi_8TeV 1.026 + +# Trigger uncertainties +eetCatLow,eetCatHigh simulated CMS_trigger_e 1.01 # Efficiency uncertainties -eetCatLow,eetCatHigh simulated CMS_eff_e 1.02 -eetCatLow,eetCatHigh simulated CMS_eff_t 1.08 +eetCatLow,eetCatHigh simulated CMS_eff_e 1.04 +eetCatLow,eetCatHigh simulated CMS_eff_t 1.06 # Scale uncertainties eetCatLow,eetCatHigh simulated CMS_scale_t 1.03 @@ -22,8 +25,8 @@ eetCatLow,eetCatHigh zz QCDscale_VV 1.023 eetCatLow,eetCatHigh wz pdf_qqbar 1.04 eetCatLow,eetCatHigh wz QCDscale_VV 1.04 -eetCatLow,eetCatHigh signal pdf_qqbar 1.034 -eetCatLow,eetCatHigh signal QCDscale_VH 1.004 +eetCatLow,eetCatHigh signal pdf_qqbar 1.023 +eetCatLow,eetCatHigh signal QCDscale_VH 1.01 #charge flip uncertainty eetCatLow,eetCatHigh charge_fakes CMS_vhtt_eet_chargeFlip_8TeV 1.0 \ No newline at end of file diff --git a/wh/card_config/unc.vals.emt.8TeV b/wh/card_config/unc.vals.emt.8TeV index d42a8ab1..15590606 100644 --- a/wh/card_config/unc.vals.emt.8TeV +++ b/wh/card_config/unc.vals.emt.8TeV @@ -3,12 +3,15 @@ # Example: # emu_vbf,emu_novbf,emu_boost signal,EWK lumi 1.045 -emtCatHigh,emtCatLow simulated lumi_8TeV 1.042 +emtCatHigh,emtCatLow simulated lumi_8TeV 1.026 + +# Trigger uncertainties +emtCatHigh,emtCatLow simulated CMS_trigger_em 1.01 # Efficiency uncertainties emtCatHigh,emtCatLow simulated CMS_eff_e 1.02 -emtCatHigh,emtCatLow simulated CMS_eff_m 1.01 -emtCatHigh,emtCatLow simulated CMS_eff_t 1.08 +emtCatHigh,emtCatLow simulated CMS_eff_m 1.02 +emtCatHigh,emtCatLow simulated CMS_eff_t 1.06 # Scale uncertainties emtCatHigh,emtCatLow simulated CMS_scale_t 1.03 @@ -23,8 +26,8 @@ emtCatHigh,emtCatLow zz QCDscale_VV 1.023 emtCatHigh,emtCatLow wz pdf_qqbar 1.04 emtCatHigh,emtCatLow wz QCDscale_VV 1.04 -emtCatHigh,emtCatLow signal pdf_qqbar 1.034 -emtCatHigh,emtCatLow signal QCDscale_VH 1.004 +emtCatHigh,emtCatLow signal pdf_qqbar 1.023 +emtCatHigh,emtCatLow signal QCDscale_VH 1.01 #charge flip uncertainty emtCatHigh,emtCatLow charge_fakes CMS_vhtt_emt_chargeFlip_8TeV 1.0 diff --git a/wh/card_config/unc.vals.mmt.8TeV b/wh/card_config/unc.vals.mmt.8TeV index b3630604..915c37bb 100644 --- a/wh/card_config/unc.vals.mmt.8TeV +++ b/wh/card_config/unc.vals.mmt.8TeV @@ -3,11 +3,14 @@ # Example: # emu_vbf,emu_novbf,emu_boost signal,EWK lumi 1.045 -mmtCatHigh,mmtCatLow simulated lumi_8TeV 1.042 +mmtCatHigh,mmtCatLow simulated lumi_8TeV 1.026 + +# Trigger uncertainties +mmtCatHigh,mmtCatLow simulated CMS_trigger_m 1.01 # Efficiency uncertainties -mmtCatHigh,mmtCatLow simulated CMS_eff_m 1.02 -mmtCatHigh,mmtCatLow simulated CMS_eff_t 1.08 +mmtCatHigh,mmtCatLow simulated CMS_eff_m 1.04 +mmtCatHigh,mmtCatLow simulated CMS_eff_t 1.06 # Scale uncertainties mmtCatHigh,mmtCatLow simulated CMS_scale_t 1.03 @@ -22,6 +25,6 @@ mmtCatHigh,mmtCatLow zz QCDscale_VV 1.023 mmtCatHigh,mmtCatLow wz pdf_qqbar 1.04 mmtCatHigh,mmtCatLow wz QCDscale_VV 1.04 -mmtCatHigh,mmtCatLow signal pdf_qqbar 1.034 -mmtCatHigh,mmtCatLow signal QCDscale_VH 1.004 +mmtCatHigh,mmtCatLow signal pdf_qqbar 1.023 +mmtCatHigh,mmtCatLow signal QCDscale_VH 1.01 From 90347760594bdc3382622ae620ad24d526a1bf2c Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:23:49 -0500 Subject: [PATCH 019/192] work in progress --- wh/fakerate_functions.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/wh/fakerate_functions.py b/wh/fakerate_functions.py index 6dddf1f3..f1fffac2 100755 --- a/wh/fakerate_functions.py +++ b/wh/fakerate_functions.py @@ -116,17 +116,17 @@ def make_null_dict(template, variables, mapper=None): #no changes in muonID in 2013 mapper = {'eid1[0-9][A-Z][a-z]+_':'', 'idiso02' : 'pfidiso02'} variables = ['muonJetPt', 'muonPt', 'numJets20'] #, 'muonJetCSVBtag'] -highpt_mu_fr = make_mva_functor_dict(frfit_dir + '/m_wjets_pt20_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +highpt_mu_fr = make_mva_functor_dict(frfit_dir + '/m_wjets_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) lowpt_mu_fr = make_mva_functor_dict(frfit_dir + '/m_wjets_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) -highpt_mu_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_qcd_pt20_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +highpt_mu_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_qcd_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) lowpt_mu_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_qcd_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) variables = ['muonJetPt', 'muonPt', 'numJets20'] -highpt_mue_fr = make_mva_functor_dict(frfit_dir + '/m_Mwjets_pt20_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +highpt_mue_fr = make_mva_functor_dict(frfit_dir + '/m_Mwjets_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) lowpt_mue_fr = make_mva_functor_dict(frfit_dir + '/m_Mwjets_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) -highpt_mue_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_Mqcd_pt20_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +highpt_mue_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_Mqcd_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) lowpt_mue_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_Mqcd_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) @@ -136,18 +136,18 @@ def make_null_dict(template, variables, mapper=None): variables = ['electronJetPt', 'electronPt', 'numJets20'] #EMT -highpt_e_fr = make_mva_functor_dict(frfit_dir + '/e_wjets_pt20_%s_electronInfo.kNN.weights.xml', variables) +highpt_e_fr = make_mva_functor_dict(frfit_dir + '/e_wjets_pt10_%s_electronInfo.kNN.weights.xml', variables) lowpt_e_fr = make_mva_functor_dict(frfit_dir + '/e_wjets_pt10_%s_electronInfo.kNN.weights.xml', variables) -highpt_e_qcd_fr = make_mva_functor_dict(frfit_dir + '/e_qcd_pt20_%s_electronInfo.kNN.weights.xml', variables) +highpt_e_qcd_fr = make_mva_functor_dict(frfit_dir + '/e_qcd_pt10_%s_electronInfo.kNN.weights.xml', variables) lowpt_e_qcd_fr = make_mva_functor_dict(frfit_dir + '/e_qcd_pt10_%s_electronInfo.kNN.weights.xml', variables) #EET variables = ['electronJetPt', 'electronPt', 'numJets20'] -highpt_ee_fr = make_mva_functor_dict(frfit_dir + '/ee_wjetsNoZmass_pt20_%s_electronInfo.kNN.weights.xml', variables) +highpt_ee_fr = make_mva_functor_dict(frfit_dir + '/ee_wjetsNoZmass_pt10_%s_electronInfo.kNN.weights.xml', variables) lowpt_ee_fr = make_mva_functor_dict(frfit_dir + '/ee_wjetsNoZmass_pt10_%s_electronInfo.kNN.weights.xml', variables) -highpt_ee_qcd_fr = make_mva_functor_dict(frfit_dir + '/ee_qcd_pt20_%s_electronInfo.kNN.weights.xml', variables) +highpt_ee_qcd_fr = make_mva_functor_dict(frfit_dir + '/ee_qcd_pt10_%s_electronInfo.kNN.weights.xml', variables) lowpt_ee_qcd_fr = make_mva_functor_dict(frfit_dir + '/ee_qcd_pt10_%s_electronInfo.kNN.weights.xml', variables) From 8c00453b80d63d8078171bfe91f00c2ca7ac58a1 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:24:46 -0500 Subject: [PATCH 020/192] take yield systematics from f3 region fit --- wh/get_fake_systematic.py | 57 ++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/wh/get_fake_systematic.py b/wh/get_fake_systematic.py index acb51ceb..9b12d4bc 100755 --- a/wh/get_fake_systematic.py +++ b/wh/get_fake_systematic.py @@ -1,30 +1,31 @@ -#!/usr/bin/env python +#! /bin/env python -''' - -Get fake systematic. - -''' - -from rootpy import io -import rootpy.plotting.views as views import sys - -the_filename = sys.argv[1] -base_dirs = sys.argv[2].split(',') -syst_name = sys.argv[3] - -the_file = io.open(the_filename, 'READ') -nom_view = views.SumView( - *[ views.SubdirectoryView( the_file, dirname ) for dirname in base_dirs] -) - -qcd_view = views.SumView( - *[ views.SubdirectoryView( the_file, dirname+'_q' ) for dirname in base_dirs] -) - -nom = nom_view.Get('fakes').Integral() -qcd = qcd_view.Get('fakes').Integral() - -minimalerror = max(abs(nom - qcd)/nom, 0.01) -print "%s fakes %s %0.2f" % (','.join(base_dirs), syst_name, 1 + minimalerror) +import os +import re + +"Usage pull files get_unc_val_from_pull.py pulls.txt nuisance initial_value header" + +header = sys.argv[-1] +prefit = float(sys.argv[-2]) +nuisance = sys.argv[-3] +filename = sys.argv[-4] + +if not os.path.isfile(filename): + print "%s not found!" % filename + sys.exit(1) + +lines = open(filename).readlines() +parser = re.compile(r'(?P\w+)\s+(?P(?:[\*\!] )?[\-+]\d+\.\d+)\,\s(?P\d+\.\d+)') + +for line in lines: + match = parser.match(line) + if match: + if match.group('nuisance') != nuisance: + continue + pull = float(match.group('pull').replace('* ','').replace('! ','')) + constraint = float(match.group('constraint')) + max_dev = max(abs(pull), abs(constraint)) + new_dev = abs(1-prefit)*max_dev + 1 + print '%s %s %.2f' % (header, nuisance, new_dev) + From 29d6bbab9e0a5792149ada71c6077b3c76835a86 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:25:00 -0500 Subject: [PATCH 021/192] updates --- wh/jobid.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wh/jobid.sh b/wh/jobid.sh index 9a98b4dc..fab0f77a 100644 --- a/wh/jobid.sh +++ b/wh/jobid.sh @@ -1,4 +1,5 @@ # Central definition of current job IDs -export jobid7='2013-Jul-04-7TeV' +export jobid7='2013-Sept-02-7TeV' +#export jobid7='2013-Sept-02' export jobid8='2013-Jul-03-8TeV' From 953f887aec2fc92194d94283b680c8f096797ca8 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:26:26 -0500 Subject: [PATCH 022/192] cleanup, run f3 fits first --- wh/limits.sh | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/wh/limits.sh b/wh/limits.sh index 21c72f49..b36e2571 100755 --- a/wh/limits.sh +++ b/wh/limits.sh @@ -6,16 +6,10 @@ set -o nounset set -o errexit source jobid.sh -#export jobid=$jobid7 -#rake cards -#rake limits -#rake harvest_limits -#rake plot_limits -#rake compare_limits +export jobid=$jobid7 +rake f3_postfit_plots +rake compare_limits -export jobid=$jobid8 -rake cards -rake limits -rake harvest_limits -rake plot_limits -rake compare_limits \ No newline at end of file +export jobid=$jobid8 #'2013-Jun-30-8TeV' # +rake f3_postfit_plots +rake compare_limits From 2c2e89644f30f4e2e5a52eaecff190e537671bcc Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:32:46 -0500 Subject: [PATCH 023/192] added different file for each channels --- wh/card_config/cgs.conf.eet.7TeV | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 wh/card_config/cgs.conf.eet.7TeV diff --git a/wh/card_config/cgs.conf.eet.7TeV b/wh/card_config/cgs.conf.eet.7TeV new file mode 100644 index 00000000..32f2fff9 --- /dev/null +++ b/wh/card_config/cgs.conf.eet.7TeV @@ -0,0 +1,19 @@ +# cgs.config: Specification of groups, categories, and samples + +#$ GROUP signal Higgs_vtth_sm_120,Higgs_gf_sm_120,Higgs_vbf_sm_120 +#$ GROUP background Ztt,ttbar,EWK,Fakes +#categories: emu_vbf +#signals: signal +#backgrounds: background +#data: data_obs + +$ GROUP signal WH +#,WH_hww +$ GROUP background wz,zz,fakes,WH_hww125 +$ GROUP simulated WH,wz,zz,WH_hww125 +#,WH_hww + +categories: eetCatHigh,eetCatLow +signals: signal +backgrounds: background +data: data_obs From bfcba59469862adb07286c71e6b56c5946fff955 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:32:47 -0500 Subject: [PATCH 024/192] added different file for each channels --- wh/card_config/cgs.conf.emt.7TeV | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 wh/card_config/cgs.conf.emt.7TeV diff --git a/wh/card_config/cgs.conf.emt.7TeV b/wh/card_config/cgs.conf.emt.7TeV new file mode 100644 index 00000000..381f2a15 --- /dev/null +++ b/wh/card_config/cgs.conf.emt.7TeV @@ -0,0 +1,19 @@ +# cgs.config: Specification of groups, categories, and samples + +#$ GROUP signal Higgs_vtth_sm_120,Higgs_gf_sm_120,Higgs_vbf_sm_120 +#$ GROUP background Ztt,ttbar,EWK,Fakes +#categories: emu_vbf +#signals: signal +#backgrounds: background +#data: data_obs + +$ GROUP signal WH +# +$ GROUP background wz,zz,fakes,WH_hww125 +$ GROUP simulated WH,wz,zz,WH_hww125 +#,WH_hww + +categories: emtCatHigh,emtCatLow +signals: signal +backgrounds: background +data: data_obs From 664b2369e11191009ee770f31fbe15ab03b89b1d Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:32:47 -0500 Subject: [PATCH 025/192] added different file for each channels --- wh/card_config/cgs.conf.mmt.7TeV | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 wh/card_config/cgs.conf.mmt.7TeV diff --git a/wh/card_config/cgs.conf.mmt.7TeV b/wh/card_config/cgs.conf.mmt.7TeV new file mode 100644 index 00000000..d64b07c8 --- /dev/null +++ b/wh/card_config/cgs.conf.mmt.7TeV @@ -0,0 +1,19 @@ +# cgs.config: Specification of groups, categories, and samples + +#$ GROUP signal Higgs_vtth_sm_120,Higgs_gf_sm_120,Higgs_vbf_sm_120 +#$ GROUP background Ztt,ttbar,EWK,Fakes +#categories: emu_vbf +#signals: signal +#backgrounds: background +#data: data_obs + +$ GROUP signal WH +#, +$ GROUP background wz,zz,fakes,WH_hww125 +$ GROUP simulated WH,wz,zz,WH_hww125 +#,WH_hww + +categories: mmtCatHigh,mmtCatLow +signals: signal +backgrounds: background +data: data_obs From bd26230ae1aed243165f41a349b6bdd0a6494c80 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:32:47 -0500 Subject: [PATCH 026/192] added different file for each channels --- wh/card_config/unc.conf.eet.7TeV | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 wh/card_config/unc.conf.eet.7TeV diff --git a/wh/card_config/unc.conf.eet.7TeV b/wh/card_config/unc.conf.eet.7TeV new file mode 100644 index 00000000..06257e08 --- /dev/null +++ b/wh/card_config/unc.conf.eet.7TeV @@ -0,0 +1,23 @@ +# unc.config: Specification of uncertainty parameter names and types +# Example: +# lumi lnN +# some_sb_parameter gmN 1000 +# some_shape_parameter shape + +lumi_7TeV lnN + +CMS_trigger_e lnN + +CMS_eff_e lnN +CMS_eff_t lnN + +CMS_fake_b_7TeV lnN + +CMS_scale_t lnN + +CMS_vhtt_eet_fakes_7TeV lnN +CMS_vhtt_eet_chargeFlip_7TeV shape + +pdf_qqbar lnN +QCDscale_VH lnN +QCDscale_VV lnN From 2e8d8738a8711f7fdd41788a50b71efd3f0979b5 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:32:47 -0500 Subject: [PATCH 027/192] added different file for each channels --- wh/card_config/unc.conf.emt.7TeV | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 wh/card_config/unc.conf.emt.7TeV diff --git a/wh/card_config/unc.conf.emt.7TeV b/wh/card_config/unc.conf.emt.7TeV new file mode 100644 index 00000000..2809be5f --- /dev/null +++ b/wh/card_config/unc.conf.emt.7TeV @@ -0,0 +1,27 @@ +# unc.config: Specification of uncertainty parameter names and types +# Example: +# lumi lnN +# some_sb_parameter gmN 1000 +# some_shape_parameter shape + +lumi_7TeV lnN + +CMS_trigger_em lnN + +CMS_eff_e lnN +CMS_eff_m lnN +CMS_eff_t lnN + +CMS_fake_b_7TeV lnN + +CMS_scale_t lnN + +CMS_vhtt_emt_fakes_7TeV lnN +CMS_vhtt_emt_chargeFlip_7TeV shape + +pdf_qqbar lnN +QCDscale_VH lnN +QCDscale_VV lnN + +# Only for testing. +CMS_vhtt_llt_fakes lnN From e06725426612a5f8b5d9c386952ecdba8d07cc0c Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:32:48 -0500 Subject: [PATCH 028/192] added different file for each channels --- wh/card_config/unc.conf.mmt.7TeV | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 wh/card_config/unc.conf.mmt.7TeV diff --git a/wh/card_config/unc.conf.mmt.7TeV b/wh/card_config/unc.conf.mmt.7TeV new file mode 100644 index 00000000..e9dc8834 --- /dev/null +++ b/wh/card_config/unc.conf.mmt.7TeV @@ -0,0 +1,23 @@ +# unc.config: Specification of uncertainty parameter names and types +# Example: +# lumi lnN +# some_sb_parameter gmN 1000 +# some_shape_parameter shape + +lumi_7TeV lnN + +CMS_trigger_m lnN + +CMS_eff_m lnN +CMS_eff_t lnN + +CMS_fake_b_7TeV lnN + +CMS_scale_t lnN + +CMS_vhtt_mmt_fakes_7TeV lnN + +pdf_qqbar lnN +QCDscale_VH lnN +QCDscale_VV lnN + From 561df8026f65c8078eee6ee051c8d91e4ed754b5 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:32:48 -0500 Subject: [PATCH 029/192] added different file for each channels --- wh/card_config/unc.vals.eet.7TeV | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 wh/card_config/unc.vals.eet.7TeV diff --git a/wh/card_config/unc.vals.eet.7TeV b/wh/card_config/unc.vals.eet.7TeV new file mode 100644 index 00000000..9f6e0ec6 --- /dev/null +++ b/wh/card_config/unc.vals.eet.7TeV @@ -0,0 +1,32 @@ +########################################################################### +# unc.vals: specification of uncertainty values by category, sample, and uncertainty name +# Example: +# emu_vbf,emu_novbf,emu_boost signal,EWK lumi 1.045 + +eetCatLow,eetCatHigh simulated lumi_7TeV 1.022 + +# Trigger uncertainties +eetCatLow,eetCatHigh simulated CMS_trigger_e 1.01 + +# Efficiency uncertainties +eetCatLow,eetCatHigh simulated CMS_eff_e 1.04 +eetCatLow,eetCatHigh simulated CMS_eff_t 1.06 + +# Scale uncertainties +eetCatLow,eetCatHigh simulated CMS_scale_t 1.03 + +# Efficiency of b-jet veto +eetCatLow,eetCatHigh simulated CMS_fake_b_7TeV 1.01 + +# Background uncertainties - due to the theoretical unc. on the xsection +eetCatLow,eetCatHigh zz pdf_qqbar 1.033 +eetCatLow,eetCatHigh zz QCDscale_VV 1.023 + +eetCatLow,eetCatHigh wz pdf_qqbar 1.04 +eetCatLow,eetCatHigh wz QCDscale_VV 1.04 + +eetCatLow,eetCatHigh signal pdf_qqbar 1.026 +eetCatLow,eetCatHigh signal QCDscale_VH 1.009 + +#charge flip uncertainty +eetCatLow,eetCatHigh charge_fakes CMS_vhtt_eet_chargeFlip_7TeV 1.0 \ No newline at end of file From 43392f64be3c390ba27818a8ab4081e234444b9a Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:32:48 -0500 Subject: [PATCH 030/192] added different file for each channels --- wh/card_config/unc.vals.emt.7TeV | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 wh/card_config/unc.vals.emt.7TeV diff --git a/wh/card_config/unc.vals.emt.7TeV b/wh/card_config/unc.vals.emt.7TeV new file mode 100644 index 00000000..581895ff --- /dev/null +++ b/wh/card_config/unc.vals.emt.7TeV @@ -0,0 +1,33 @@ +########################################################################### +# unc.vals: specification of uncertainty values by category, sample, and uncertainty name +# Example: +# emu_vbf,emu_novbf,emu_boost signal,EWK lumi 1.045 + +emtCatHigh,emtCatLow simulated lumi_7TeV 1.022 + +# Trigger uncertainties +emtCatHigh,emtCatLow simulated CMS_trigger_em 1.01 + +# Efficiency uncertainties +emtCatHigh,emtCatLow simulated CMS_eff_e 1.02 +emtCatHigh,emtCatLow simulated CMS_eff_m 1.02 +emtCatHigh,emtCatLow simulated CMS_eff_t 1.08 + +# Scale uncertainties +emtCatHigh,emtCatLow simulated CMS_scale_t 1.03 + +# Efficiency of b-jet veto +emtCatHigh,emtCatLow simulated CMS_fake_b_7TeV 1.01 + +# Background uncertainties - due to the theoretical unc. on the xsection +emtCatHigh,emtCatLow zz pdf_qqbar 1.033 +emtCatHigh,emtCatLow zz QCDscale_VV 1.023 + +emtCatHigh,emtCatLow wz pdf_qqbar 1.04 +emtCatHigh,emtCatLow wz QCDscale_VV 1.04 + +emtCatHigh,emtCatLow signal pdf_qqbar 1.026 +emtCatHigh,emtCatLow signal QCDscale_VH 1.009 + +#charge flip uncertainty +emtCatHigh,emtCatLow charge_fakes CMS_vhtt_emt_chargeFlip_7TeV 1.0 From 7f39ca870da4c12f52881cc7a238cb271da22786 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:32:48 -0500 Subject: [PATCH 031/192] added different file for each channels --- wh/card_config/unc.vals.mmt.7TeV | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 wh/card_config/unc.vals.mmt.7TeV diff --git a/wh/card_config/unc.vals.mmt.7TeV b/wh/card_config/unc.vals.mmt.7TeV new file mode 100644 index 00000000..b82af8cc --- /dev/null +++ b/wh/card_config/unc.vals.mmt.7TeV @@ -0,0 +1,29 @@ +########################################################################### +# unc.vals: specification of uncertainty values by category, sample, and uncertainty name +# Example: +# emu_vbf,emu_novbf,emu_boost signal,EWK lumi 1.045 + +mmtCatHigh,mmtCatLow simulated lumi_7TeV 1.022 + +# Trigger uncertainties +mmtCatHigh,mmtCatLow simulated CMS_trigger_m 1.01 + +# Efficiency uncertainties +mmtCatHigh,mmtCatLow simulated CMS_eff_m 1.04 +mmtCatHigh,mmtCatLow simulated CMS_eff_t 1.06 + +# Scale uncertainties +mmtCatHigh,mmtCatLow simulated CMS_scale_t 1.03 + +# Efficiency of b-jet veto +mmtCatHigh,mmtCatLow simulated CMS_fake_b_7TeV 1.01 + +# Background uncertainties - due to the theoretical unc. on the xsection +mmtCatHigh,mmtCatLow zz pdf_qqbar 1.033 +mmtCatHigh,mmtCatLow zz QCDscale_VV 1.023 + +mmtCatHigh,mmtCatLow wz pdf_qqbar 1.04 +mmtCatHigh,mmtCatLow wz QCDscale_VV 1.04 + +mmtCatHigh,mmtCatLow signal pdf_qqbar 1.026 +mmtCatHigh,mmtCatLow signal QCDscale_VH 1.009 From 9e1c62382387a4fad8a8a867d2cfe7849ebdf623 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:33:42 -0500 Subject: [PATCH 032/192] checks that the shapes for the limit are looking good --- wh/check_shapes.py | 214 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100755 wh/check_shapes.py diff --git a/wh/check_shapes.py b/wh/check_shapes.py new file mode 100755 index 00000000..55537656 --- /dev/null +++ b/wh/check_shapes.py @@ -0,0 +1,214 @@ +#! /bin/env python + +import ROOT +import fnmatch +from optparse import OptionParser +import os +import re +import logging +import sys + +__author__ = "Mauro Verzetti (mauro.verzetti@cern.ch)" +__doc__ = """checks that the shapes for the limit are looking good""" + +parser = OptionParser(description=__doc__) +parser.add_option('--fakes', '-f', type=str, default = '*fakes*', + help='pattern to match to fakes',dest='fakes') +parser.add_option('--exclude', '-e', type=str, default = '*_?', + help='pattern of dirs to exclude',dest='exclude') +parser.add_option('--signal', '-s', type=str, default = 'WH*', + help='pattern of plots to be recognised as signals',dest='signal') +parser.add_option('--shape-unc-matcher', default='*CMS_*', + dest='shapematch', + help='Shell glob-style matcher for shape errors. These shapes arent shown.') +parser.add_option('--level', '-l', type=str, default = 'INFO', + help='pattern of dirs to excludelogging level', dest='level') + +args, shapes_filenames = parser.parse_args() + +logging.basicConfig(stream=sys.stderr, level=getattr(logging, args.level)) + +ROOT.gROOT.SetBatch(True) +ROOT.gStyle.SetOptStat('111111111') + +def walk(inputdir): + ''' Recursive function which generates (path, subdirs, histos) ''' + directories = [] + histos = [] + for key in inputdir.GetListOfKeys(): + # Keep track of stuff we find in this directory + name = key.GetName() + classname = key.GetClassName() + if classname.startswith('TDirectory'): + directories.append(name) + elif isinstance(inputdir.Get(name), ROOT.TH1): + histos.append(name) + path = inputdir.GetPath().split(':')[1] + # Yield the stuff in this directory + yield (path, tuple(directories), tuple(histos)) + # Now get the stuff in sub directories + for directory in directories: + for subresult in walk(inputdir.Get(directory)): + yield subresult + +def seperate_histos(histo_list, signal_pattern, err_pattern, fakes_pattern): + ''' Separate histogram lists into backgrounds, shape_uncs, and signals ''' + signals = [] + shapes = [] + bkgs = [] + fakes = [] + for x in histo_list: + if 'obs' in x: + continue + if fnmatch.fnmatch(x, signal_pattern): + signals.append(x) + elif fnmatch.fnmatch(x, err_pattern): + shapes.append(x) + elif fnmatch.fnmatch(x, fakes_pattern): + fakes.append(x) + else: + bkgs.append(x) + return (tuple(signals), tuple(shapes), tuple(fakes), tuple(bkgs)) + +def count_holes(histo): + nbins_x = histo.GetNbinsX() + last_filled = 0 + first_filled = nbins_x + for i in xrange(nbins_x, 1, -1): + if histo.GetBinContent(i): + last_filled = i + break + for i in xrange(1, nbins_x+1): + if histo.GetBinContent(i): + first_filled = i + break + + if last_filled < first_filled: + return -1 + #raise Exception("Error in count_holes") + + holes = sum( + 1 for i in xrange(first_filled, last_filled) + if not histo.GetBinContent(i) + ) + return holes + +def count_negatives(histo): + nbins_x = histo.GetNbinsX() + negatives = sum( + 1 for i in xrange(1, nbins_x+1) + if (histo.GetBinContent(i) + histo.GetBinError(i)) < 0 + ) + return negatives + +def check_empty(histo): + return histo.Integral() == 0 + +def check_sig_bkg(signals, backgrounds): + nbins_x = signals[0].GetNbinsX() #same as + bins = 0 + for ibin in xrange(1, nbins_x+1): + bkg_sum = sum( + h.GetBinContent(ibin) for h in backgrounds + if h.GetBinContent(ibin) >= 0 + ) + if not bkg_sum: #in background is empty + #check signals + bins += int( + any( + h.GetBinContent(ibin) > 0 + for h in signals + ) + ) + return bins + +def pair_signals(signals): + regex = re.compile("[a-zA-Z_]+(?P\d+)") + pairs = {} + for name in signals: + logging.debug(name) + mass = regex.match(name).group('mass') + pairs[mass] = pairs.get(mass,[]) + [name] + return pairs + + +good_shapes = [] +bad_shapes = [] +ugly_shapes = [] #not used + +for shape_filename in shapes_filenames: + logging.info( "Inspecting %s" % shape_filename) + shape_file = ROOT.TFile.Open(shape_filename) + + info = {} + for path, subdirs, histos in walk(shape_file): + if not histos or fnmatch.fnmatch(path, args.exclude): + continue + + h_dict = {} + for h in histos: + h_dict[h] = shape_file.Get(os.path.join(path, h)) + + logging.debug('%s, %s, %s' % (path.__repr__(), subdirs.__repr__(), histos.__repr__())) + signals, unc, fakes, bkgs = seperate_histos( + histos, args.signal, args.shapematch, args.fakes) + + paired_signals = pair_signals(signals) + logging.debug('paired signals: %s' % paired_signals) + signals = [] + for mass, names in paired_signals.iteritems(): + if len(names) == 1: + signals += names + if len(names) == 2: + h_dict[names[0]].Add(h_dict[names[1]]) + signals.append(names[0]) + + logging.debug('new signals: %s' % signals) + signals = tuple(signals) + #count holes + for h in fakes+bkgs: + hpath = os.path.join(path, h) + info[hpath] = {} + info[hpath]['holes'] = count_holes(h_dict[h]) + + for h in signals: + info[hpath]['empty'] = check_empty(h_dict[h]) + + #count negatives + for h in fakes: + hpath = os.path.join(path, h) + info[hpath]['negatives'] = count_negatives(h_dict[h]) + + h_sigs = [ h_dict[h] for h in signals ] + h_bkgs = [ h_dict[h] for h in fakes+bkgs ] + info[path] = { + 'signal_only' : check_sig_bkg(h_sigs, h_bkgs) + } + + has_errors = False + for path, values in info.iteritems(): + if values.get('holes') or values.get('negatives'): + has_errors = True + logging.info( '%s found with %i holes and %i negative bins!' % (path, values['holes'], values.get('negatives', 0)) ) + if values.get('empty'): + has_errors = True + logging.info( '%s found to be empty!' % path ) + if values.get('signal_only'): + has_errors = True + logging.info('category %s has %i bins with signal-only contribution!' % (path, values['signal_only'])) + if has_errors: + bad_shapes.append(shape_filename) + logging.warning('%s has errors!' % shape_filename) + else: + good_shapes.append(shape_filename) + logging.info( "\n\n\n") + shape_file.Close() + + + +print '\n\nBAD SHAPE FILES:\n\n' +print '\n'.join( bad_shapes ) + + +print '\n\nGOOD SHAPE FILES:\n\n' +print '\n'.join( good_shapes ) From f3362228e84e3d436c195c6f625ffa3fa045f3f8 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:34:42 -0500 Subject: [PATCH 033/192] dumps and compares the luminosity of two jobids --- wh/dump_lumis.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 wh/dump_lumis.py diff --git a/wh/dump_lumis.py b/wh/dump_lumis.py new file mode 100644 index 00000000..16e72136 --- /dev/null +++ b/wh/dump_lumis.py @@ -0,0 +1,43 @@ +import glob +import os +from FinalStateAnalysis.MetaData.data_views import extract_sample, read_lumi +import re +#from pudb import set_trace; set_trace() + +paths = { + #os.environ['current'], + 'current' : 'inputs/%s/' % os.environ['jobid'], + 'previous' : 'inputs/2013-Jun-30-8TeV/', +} + + +for dataset in ['DoubleMu', 'DoubleElectron', 'MuEG']: + lumi_dict = {} + for jobid, path in paths.iteritems(): + lumi_dict[jobid] = {} + for lumifile in glob.glob(path+'/data_'+dataset+'*.lumicalc.sum'): + lumi_dict[jobid][extract_sample(lumifile)] = read_lumi(lumifile) + + print dataset + print '%60s%20s%20s' % ('', 'current', 'previous') + keys = [] + for i in lumi_dict.values(): + keys += i.keys() + keys = list(set(keys)) + + total_lumis = dict([(i, {'current' : 0., 'previous' : 0.}) for i in ['2012A', '2012B', '2012C', '2012D', 'TOTAL',]]) + + for sample in keys: + curr_l = lumi_dict['current'][sample] if sample in lumi_dict['current'] else 0. + total_lumis['TOTAL']['current'] += curr_l + previous_l = lumi_dict['previous'][sample] if sample in lumi_dict['previous'] else 0. + total_lumis['TOTAL']['previous'] += previous_l + for key in total_lumis: + if key in sample: + total_lumis[key]['previous'] += previous_l + total_lumis[key]['current'] += curr_l + print '%60s%20s%20s' % (sample, '%.1f' % curr_l, '%.1f' % previous_l) + + for key, val in total_lumis.iteritems(): + print '%60s%20s%20s' % (key, '%.1f' % val['current'], '%.1f' % val['previous']) + print '\n\n' From d181a7388291158109b8f06a4d8f5506f9b1e890 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Sep 2013 09:40:26 -0500 Subject: [PATCH 034/192] fancy plots of fake rates --- wh/plots_for_prepp_kNN.py | 217 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 wh/plots_for_prepp_kNN.py diff --git a/wh/plots_for_prepp_kNN.py b/wh/plots_for_prepp_kNN.py new file mode 100644 index 00000000..7338e83f --- /dev/null +++ b/wh/plots_for_prepp_kNN.py @@ -0,0 +1,217 @@ +from FinalStateAnalysis.Utilities.rootbindings import ROOT +import os +from rootpy.utils import asrootpy +from FinalStateAnalysis.PlotTools.RebinView import RebinView +import rootpy.plotting as plotting +import logging +import sys + +logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) + +def round_to_ints(histo): + new = histo.Clone() + new.Reset() + for bin in range(histo.GetNbinsX()+1): + nentries = ROOT.TMath.Nint(histo.GetBinContent(bin)) \ + if histo.GetBinContent(bin) >= 0 else 0 + centerx = histo.GetXaxis().GetBinCenter(bin) + for _ in range(nentries): + new.Fill(centerx) + return new + + +ROOT.gROOT.SetBatch(True) +ROOT.gROOT.SetStyle("Plain") +ROOT.gStyle.SetOptTitle(0) +ROOT.gStyle.SetOptStat(0) + +jobid = os.environ['jobid'] + +rebinPt = ( + [10,12,15,20,25,30,35,40,45,50,60,70,100], #,150,200], + range(0,50,5)+range(50,110,10), + ) + +rebinJet = ( + [0,1,2,3,4,6,9,12], + range(13), + ) + +axes = { + 'muonPt' : 'muon p_{T} (GeV)', + 'muonJetPt' : 'muon p_{T}^{Jet} (GeV)', + 'numJets20' : '# Jets', + 'electronPt' : 'electron p_{T} (GeV)', + 'electronJetPt' : 'electron p_{T}^{Jet} (GeV)', +} + +sources = { + ##MMT + 'm_mmt_pt10_h2taucuts020_kNN' : { + 'vars' : {'muonPt':rebinPt, 'muonJetPt':rebinPt, 'numJets20':rebinJet}, + 'wjets' : 'results/%s/fakerate_fits/m_wjets_pt10_h2taucuts020_muonInfo.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/m_qcd_pt10_h2taucuts020_muonInfo.kNN.root' % jobid, + }, + 'm_mmt_pt20_h2taucuts_kNN' : { + 'vars' : {'muonPt':rebinPt, 'muonJetPt':rebinPt, 'numJets20':rebinJet}, + 'wjets' : 'results/%s/fakerate_fits/m_wjets_pt20_h2taucuts_muonInfo.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/m_qcd_pt20_h2taucuts_muonInfo.kNN.root' % jobid, + }, + + #EMT + 'm_emt_pt10_h2taucuts_kNN' : { + 'vars' : {'muonPt':rebinPt, 'muonJetPt':rebinPt, 'numJets20':rebinJet}, + 'wjets' : 'results/%s/fakerate_fits/m_Mwjets_pt10_h2taucuts_muonInfo.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/m_Mqcd_pt10_h2taucuts_muonInfo.kNN.root' % jobid, + }, + 'm_emt_pt20_h2taucuts_kNN' : { + 'vars' : {'muonPt':rebinPt, 'muonJetPt':rebinPt, 'numJets20':rebinJet}, + 'wjets' : 'results/%s/fakerate_fits/m_Mwjets_pt20_h2taucuts_muonInfo.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/m_Mqcd_pt20_h2taucuts_muonInfo.kNN.root' % jobid, + }, + + + 'e_emt_pt10_h2taucuts_kNN' : { + 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, + 'wjets' : 'results/%s/fakerate_fits/e_wjets_pt10_eid12Medium_h2taucuts_electronInfo.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/e_qcd_pt10_eid12Medium_h2taucuts_electronInfo.kNN.root' % jobid, + }, + 'e_emt_pt20_h2taucuts_kNN' : { + 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, + 'wjets' : 'results/%s/fakerate_fits/e_wjets_pt20_eid12Medium_h2taucuts_electronInfo.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/e_qcd_pt20_eid12Medium_h2taucuts_electronInfo.kNN.root' % jobid, + }, + + #EET + 'e_eet_pt10_h2taucuts_kNN' : { + 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, + 'wjets' : 'results/%s/fakerate_fits/ee_wjetsNoZmass_pt10_eid12Tight_h2taucuts_electronInfo.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/ee_qcd_pt10_eid12Tight_h2taucuts_electronInfo.kNN.root' % jobid, + }, + 'e_eet_pt20_h2taucuts_kNN' : { + 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, + 'wjets' : 'results/%s/fakerate_fits/ee_wjetsNoZmass_pt20_eid12Medium_h2taucuts020_electronInfo.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/ee_qcd_pt20_eid12Medium_h2taucuts020_electronInfo.kNN.root' % jobid, + }, +} + +canvas = plotting.Canvas(800, 800, name='adsf', title='asdf') +canvas.SetLogy(True) + +#from pdb import set_trace; set_trace() +for output, info in sources.iteritems(): + logging.info("analyzing %s" % output) + wjets_name = info['wjets'] + qcd_name = info['qcd'] + variables = info['vars'] + + wjets_file = ROOT.TFile.Open(wjets_name) + logging.debug('filename: %s instance: %s' % (wjets_name, wjets_file.__repr__())) + qcd_file = ROOT.TFile.Open(qcd_name) + logging.debug('filename: %s instance: %s' % (qcd_name, qcd_file.__repr__())) + + for var, rebins in variables.iteritems(): + logging.debug('variable %s' % var) + ##### + #WJets fake rate + ##### + wjets_view = RebinView(wjets_file, rebins[0]) + wjets_eff = asrootpy( + ROOT.TGraphAsymmErrors( + round_to_ints( wjets_view.Get('%s_pass' % var)), + round_to_ints( wjets_view.Get('%s_all' % var)) + ) + ) + wjets_eff.SetTitle('WJets fake rate') + wjets_eff.markerstyle = 20 + wjets_eff.markercolor = ROOT.EColor.kBlue + + ##### + #QCD fake rate + ##### + qcd_view = RebinView(qcd_file, rebins[0]) + qcd_eff = asrootpy( + ROOT.TGraphAsymmErrors( + round_to_ints(qcd_view.Get('%s_pass' % var)), + round_to_ints(qcd_view.Get('%s_all' % var)) + ) + ) + qcd_eff.SetTitle('QCD fake rate') + qcd_eff.markerstyle = 20 + qcd_eff.markercolor = ROOT.EColor.kRed + + + ##### + #WJets kNN output + ##### + wjets_view = RebinView(wjets_file, rebins[1]) + wjets_estimate = asrootpy( + wjets_view.Get('%s_estimate' % var) + ) + wjets_estimate_denom = asrootpy( + wjets_view.Get('%s_estimate_all' % var) + ) + wjets_estimate.Divide(wjets_estimate_denom) + wjets_estimate.SetTitle('WJets kNN output') + wjets_estimate.linecolor = ROOT.kBlue + wjets_estimate.linewidth = 2 + wjets_estimate.legendstyle = 'l' + wjets_estimate.fillstyle = 0 + wjets_estimate.drawstyle = 'hist' + + ##### + #QCD kNN output + ##### + qcd_view = RebinView(qcd_file, rebins[1]) + qcd_estimate = asrootpy( + qcd_view.Get('%s_estimate' % var) + ) + qcd_estimate_denom = asrootpy( + qcd_view.Get('%s_estimate_all' % var) + ) + qcd_estimate.Divide(qcd_estimate_denom) + qcd_estimate.SetTitle('QCD kNN output') + qcd_estimate.linecolor = ROOT.kRed + qcd_estimate.linewidth = 2 + qcd_estimate.fillstyle = 0 + qcd_estimate.legendstyle = 'l' + qcd_estimate.drawstyle = 'hist' + + canvas.SetGrid() + + wjets_estimate.GetXaxis().SetTitle(axes[var]) + wjets_estimate.GetYaxis().SetTitle('fake rate') + wjets_estimate.GetYaxis().SetRangeUser(10**-2,1.) + for axis in [wjets_estimate.GetXaxis(), wjets_estimate.GetYaxis()]: + axis.SetLabelSize( axis.GetLabelSize()*0.6 ) + axis.SetTitleSize( axis.GetTitleSize()*0.6 ) + #axis.SetTitleOffset( axis.GetTitleOffset()*0.6 ) + + wjets_estimate.Draw() + qcd_estimate.Draw('same') + + wjets_eff.Draw('P SAME') + qcd_eff.Draw('P SAME') + + ##### + #Legend + ##### + legend = plotting.Legend(4, rightmargin=0.02, topmargin=0.05, leftmargin=0.45) + legend.AddEntry(wjets_estimate) + legend.AddEntry(qcd_estimate) + legend.AddEntry(wjets_eff) + legend.AddEntry(qcd_eff) + legend.SetTextSize(0.5*legend.GetTextSize()) + legend.SetEntrySeparation(0.0) + legend.SetMargin(0.35) + legend.Draw() + + canvas.Update() + canvas.SetLogy(True) + print "saving results/%s/fakerate_fits/%s_%s.pdf(png)" % (jobid, output, var) + canvas.SaveAs('results/%s/fakerate_fits/%s_%s.pdf' % (jobid, output, var)) + canvas.SaveAs('results/%s/fakerate_fits/%s_%s.png' % (jobid, output, var)) + + + wjets_file.Close() + qcd_file.Close() From 50581925f164fe1e9200a9519083440da4e313fa Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 13 Sep 2013 09:46:14 -0500 Subject: [PATCH 035/192] update fake rates variables --- wh/ControlEM.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wh/ControlEM.py b/wh/ControlEM.py index 65c4a8de..b83237b4 100644 --- a/wh/ControlEM.py +++ b/wh/ControlEM.py @@ -145,9 +145,9 @@ def obj2_weight(self, row): mu17e8 = (row.mu17ele8isoPass and row.mPt >= 20) if use_iso_trigger else (row.mu17ele8Pass and row.mPt >= 20) fr = 0. if mu17e8: - fr = frfits.lowpt_e_fr[subleptonId](electronJetPt=max(row.eJetPt, row.ePt), electronPt=row.ePt) + fr = frfits.lowpt_e_fr[subleptonId](electronJetPt=max(row.eJetPt, row.ePt), electronPt=row.ePt, numJets20=row.jetVeto20) else: - fr = frfits.highpt_e_fr[subleptonId](electronJetPt=max(row.eJetPt, row.ePt),electronPt=row.ePt) + fr = frfits.highpt_e_fr[subleptonId](electronJetPt=max(row.eJetPt, row.ePt), electronPt=row.ePt, numJets20=row.jetVeto20) return fr / (1. - fr) def process(self): From e0f6f7cbe1309564af75f1a8939c3a47d3f308cf Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 13 Sep 2013 09:46:33 -0500 Subject: [PATCH 036/192] update fake rates variables --- wh/ControlZEE.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wh/ControlZEE.py b/wh/ControlZEE.py index 9aca6433..0cb5a814 100644 --- a/wh/ControlZEE.py +++ b/wh/ControlZEE.py @@ -65,9 +65,10 @@ def assign_id_weight(dir_, row): return 1 leading_fr = leading_e_fr_wjets if 'wjet_w' in dir_ else leading_e_fr_qcd sublead_fr = subleading_e_fr_wjets if 'wjet_w' in dir_ else subleading_e_fr_qcd - if "f1f2" in dir_: return leading_fr( electronJetPt=max(row.e1JetPt, row.e1Pt), electronPt=row.e1Pt) * sublead_fr( electronJetPt=max(row.e2JetPt, row.e2Pt), electronPt=row.e2Pt ) - if "f2" in dir_: return sublead_fr( electronJetPt=max(row.e2JetPt, row.e2Pt), electronPt=row.e2Pt) - if "f1" in dir_: return leading_fr( electronJetPt=max(row.e1JetPt, row.e1Pt), electronPt=row.e1Pt) + if "f1f2" in dir_: return leading_fr( electronJetPt=max(row.e1JetPt, row.e1Pt), electronPt=row.e1Pt, numJets20=row.jetVeto20) *\ + sublead_fr( electronJetPt=max(row.e2JetPt, row.e2Pt), electronPt=row.e2Pt, numJets20=row.jetVeto20) + if "f2" in dir_: return sublead_fr( electronJetPt=max(row.e2JetPt, row.e2Pt), electronPt=row.e2Pt, numJets20=row.jetVeto20) + if "f1" in dir_: return leading_fr( electronJetPt=max(row.e1JetPt, row.e1Pt), electronPt=row.e1Pt, numJets20=row.jetVeto20) class ControlZEE(MegaBase): tree = 'ee/final/Ntuple' From 4dbb23bbcedec3dcdfb3d4424cf26947dae957ee Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 13 Sep 2013 09:47:52 -0500 Subject: [PATCH 037/192] allow multiple neighbors training, update horizontal_morphing to new requirements --- wh/Rakefile | 86 ++++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/wh/Rakefile b/wh/Rakefile index 58960e11..9b68c8ad 100755 --- a/wh/Rakefile +++ b/wh/Rakefile @@ -185,6 +185,7 @@ def make_kNN(chan, datas) "samples" => Array["diboson", "data_#{datas.downcase}"], "analyzer" => "FakeRates#{chan.upcase}", 'fitter' => 'train_kNN.py', + #'neighbors' => neighbors, ] end @@ -192,13 +193,13 @@ iso_points = ['h2taucuts', 'h2taucuts020'] #'idiso02', electronIds = ['eid12Medium', 'eid12Tight'] #, 'eid13Loose', 'eid12Loose', 'eid13Tight'] elewps = electronIds.product(iso_points) elewps = elewps.map{|x,y| "#{x}_#{y}"} -pt_regions = ['pt10', 'pt20'] +pt_regions = ['pt10']#, 'pt20'] muonwps = ['h2taucuts', 'h2taucuts020'] #, 'pfidiso02'] fr_fits = Hash.new kNN_trains = Hash.new muon_kNN_vars= ['muonJetPt', 'muonPt', 'numJets20'] electron_kNN_vars= ['electronJetPt', 'electronPt', 'numJets20'] - +neighbors = ['100'] #, '50'] ############# # EM datas @@ -206,13 +207,15 @@ electron_kNN_vars= ['electronJetPt', 'electronPt', 'numJets20'] emcrs = ['qcd', 'wjets'] elewps.select{|x| x.start_with?('eid12Medium')}.each do |ele_wp| emcrs.each do |cr| - pt_regions.each do |ptr| - key = "e_#{cr}_#{ptr}_#{ele_wp}_eJetPt" - #fr_fits[key] = make_exponential('em', 'em') #fit EVERYTHING with exponential, in case change afterwards - - key = "e_#{cr}_#{ptr}_#{ele_wp}_electronInfo" - kNN_trains[key] = make_kNN('em', 'em') - kNN_trains[key]['vars'] = electron_kNN_vars + neighbors.each do |k| + pt_regions.each do |ptr| + key = "e_#{cr}_#{ptr}_#{ele_wp}_eJetPt" + #fr_fits[key] = make_exponential('em', 'em') #fit EVERYTHING with exponential, in case change afterwards + + key = "e_#{cr}_#{ptr}_#{ele_wp}_electronInfo_k#{k}" + kNN_trains[key] = make_kNN('em', 'em') + kNN_trains[key]['vars'] = electron_kNN_vars + end end end end @@ -221,10 +224,12 @@ end mmcrs = ['qcd', 'wjets'] muonwps.each do |mu_wp| mmcrs.each do |cr| - pt_regions.each do |ptr| - key = "m_M#{cr}_#{ptr}_#{mu_wp}_muonInfo" - kNN_trains[key] = make_kNN('em', 'em') - kNN_trains[key]['vars'] = muon_kNN_vars + neighbors.each do |k| + pt_regions.each do |ptr| + key = "m_M#{cr}_#{ptr}_#{mu_wp}_muonInfo_k#{k}" + kNN_trains[key] = make_kNN('em', 'em') + kNN_trains[key]['vars'] = muon_kNN_vars + end end end end @@ -235,18 +240,17 @@ end ############# eecrs = ['qcd', 'wjetsNoZmass'] elewps.each do |ele_wp| - eecrs.each do |cr| - key = "ee_#{cr}_pt10_#{ele_wp}_electronJetPt" - #fr_fits[key] = make_landau('ee', 'ee') #fit pt10 with landau - key = "ee_#{cr}_pt20_#{ele_wp}_electronJetPt" - #fr_fits[key] = make_exponential('ee', 'ee') #fit pt20 with expo - - key = "ee_#{cr}_pt10_#{ele_wp}_electronInfo" - kNN_trains[key] = make_kNN('ee', 'ee') - kNN_trains[key]['vars'] = electron_kNN_vars - key = "ee_#{cr}_pt20_#{ele_wp}_electronInfo" - kNN_trains[key] = make_kNN('ee', 'ee') - kNN_trains[key]['vars'] = electron_kNN_vars + neighbors.each do |k| + eecrs.each do |cr| + pt_regions.each do |ptr| + key = "ee_#{cr}_#{ptr}_#{ele_wp}_electronJetPt" + #fr_fits[key] = make_landau('ee', 'ee') #fit pt10 with landau + + key = "ee_#{cr}_#{ptr}_#{ele_wp}_electronInfo_k#{k}" + kNN_trains[key] = make_kNN('ee', 'ee') + kNN_trains[key]['vars'] = electron_kNN_vars + end + end end end #fr_fits["ee_wjetsNoZmass_pt10_eid12Medium_h2taucuts020_electronJetPt"] = make_constant('ee', 'ee') @@ -258,18 +262,18 @@ muon_kNN_vars= ['muonJetPt', 'muonPt', 'numJets20'] mmcrs = ['qcd', 'wjets'] muonwps.each do |mu_wp| mmcrs.each do |cr| - pt_regions.each do |ptr| - key = "m_#{cr}_#{ptr}_#{mu_wp}_muonJetPt" - #fr_fits[key] = make_landau('mm', 'mm') - - key = "m_#{cr}_#{ptr}_#{mu_wp}_muonInfo" - kNN_trains[key] = make_kNN('mm', 'mm') - kNN_trains[key]['vars'] = muon_kNN_vars + neighbors.each do |k| + pt_regions.each do |ptr| + key = "m_#{cr}_#{ptr}_#{mu_wp}_muonJetPt" + #fr_fits[key] = make_landau('mm', 'mm') + + key = "m_#{cr}_#{ptr}_#{mu_wp}_muonInfo_k#{k}" + kNN_trains[key] = make_kNN('mm', 'mm') + kNN_trains[key]['vars'] = muon_kNN_vars + end end end end -#fr_fits["m_qcd_pt20_h2taucuts_muonJetPt"] = make_cruijff('mm', 'mm') -#fr_fits["m_qcd_pt20_h2taucuts020_muonJetPt"] = make_cruijff('mm', 'mm') #Tau stuff (by hand, they are just 2) @@ -360,16 +364,18 @@ kNN_trains.each do |kNN, info| cut = '' var = '' - if kNN_configuration.size() == 6 #check if we have an idIso with _ separation + if kNN_configuration.size() == 7 #check if we have an idIso with _ separation region = kNN_configuration[1] denom = kNN_configuration[2] cut = "#{kNN_configuration[3]}_#{kNN_configuration[4]}" var = kNN_configuration[5] + neigh = kNN_configuration[6].sub('k','') else #otherwise as usual region = kNN_configuration[1] denom = kNN_configuration[2] cut = kNN_configuration[3] var = kNN_configuration[4] + neigh = kNN_configuration[5].sub('k','') end knn_output = $frfit_dir + "/#{kNN}.kNN.root" @@ -388,7 +394,7 @@ kNN_trains.each do |kNN, info| file knn_output => subsamples_inputs_result_list + [info['analyzer'] + '.py',] do |t| sh "mkdir -p #{$frfit_dir}" - sh "train_kNN.py --files #{subsample_input_list} --outputfile #{knn_output} --tree #{tree_path} --cut #{cut} --variables #{vars_str} --makePlots 1" + sh "train_kNN.py --files #{subsample_input_list} --outputfile #{knn_output} --tree #{tree_path} --cut #{cut} --variables #{vars_str} --makePlots 1 --neighbors #{neigh}" end task :kNN => knn_output kNN_files << knn_output @@ -825,11 +831,11 @@ def make_f3_postfit_plots_task(channel) file plot_timestamp => shape_file do |t| sh "mkdir -p `dirname #{t.name}`" $categories_map[channel].each do |category| - sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{category} -e 'WH*' -o #{resultdir}/#{category}.png -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV'" - sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{category} -e 'WH*' -o #{resultdir}/#{category}.pdf -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV'" + sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{category} -e 'WH*' -o #{resultdir}/#{category}.png -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV' --show-errors" + sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{category} -e 'WH*' -o #{resultdir}/#{category}.pdf -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV' --show-errors" end sh "cp -v #{carddir}/#{channel}/#{channel}.pulls* #{resultdir}/." - sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{$categories_map[channel].join(' ')} -e 'WH*' -o #{resultdir}/#{channel}_categories_summed.png -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV'" + sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{$categories_map[channel].join(' ')} -e 'WH*' -o #{resultdir}/#{channel}_categories_summed.png -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV' --show-errors" sh "touch #{t.name}" end return plot_timestamp @@ -900,7 +906,7 @@ def make_morphing_task(channel, shapefile) file ret => [shapefile] do |t| sh "mkdir -p `dirname #{t.name}`" sh "cp #{t.prerequisites[0]} #{t.name}" - sh "horizontal-morphing.py --categories='#{$categories_map[channel].join(',')}' --samples='WH_hww{MASS}' --uncerts='' --masses='110,120,130,140' --step-size=5 -i #{t.name}"# --extrapolate=#{$to_extrapolate.join(",")} #{t.name}" #FIXME! to be removed! + sh "horizontal-morphing.py --categories='#{$categories_map[channel].join(',')}' --samples='WH_hww{MASS}' --uncerts='' --masses='110,120,130,140' --step-size=5 #{t.name}"# --extrapolate=#{$to_extrapolate.join(",")} #{t.name}" #FIXME! to be removed! end return ret end From 676da869b5f6f5a5b30f5fd65f49d6e745508951 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 13 Sep 2013 09:48:25 -0500 Subject: [PATCH 038/192] bugfix --- wh/WHAnalyzeEET.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wh/WHAnalyzeEET.py b/wh/WHAnalyzeEET.py index f57ce89a..b59c31ba 100755 --- a/wh/WHAnalyzeEET.py +++ b/wh/WHAnalyzeEET.py @@ -13,7 +13,7 @@ import fakerate_functions as frfits import optimizer import math -import array +from array import array from chargeflipcuts import charge_flip_funcs from FinalStateAnalysis.PlotTools.decorators import memo_last From 66d7ba3032f2f7c717d303dcd64cbd66d9f637fa Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 13 Sep 2013 09:49:10 -0500 Subject: [PATCH 039/192] HWW treated as bkg, work in progress --- wh/WHPlotterBase.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/wh/WHPlotterBase.py b/wh/WHPlotterBase.py index 851c33b9..acf74a87 100644 --- a/wh/WHPlotterBase.py +++ b/wh/WHPlotterBase.py @@ -184,7 +184,7 @@ def unsuck(x): class WHPlotterBase(Plotter): def __init__(self, channel, obj1_charge_mapper={}, obj2_charge_mapper={}): cwd = os.getcwd() - os.chdir( os.path.dirname(__file__) ) + #os.chdir( os.path.dirname(__file__) ) self.channel = channel jobid = os.environ['jobid'] print "\nPlotting %s for %s\n" % (channel, jobid) @@ -229,7 +229,7 @@ def __init__(self, channel, obj1_charge_mapper={}, obj2_charge_mapper={}): blinder) self.defaults = {} #allows to set some options and avoid repeating them each function call self.mc_samples = filter(lambda x: x.startswith('data'), samples) - os.chdir( cwd ) + #os.chdir( cwd ) #create a fake wiew summing up all HWW self.views['VH_hww_sum'] = { 'unweighted_view' : views.SumView( @@ -761,7 +761,7 @@ def plot_final(self, variable, rebin=1, xaxis='', maxy=24, vh_10x = views.TitleView( views.StyleView( - views.ScaleView(sig_view['signal120'], higgs_xsec_multiplier), + views.ScaleView(sig_view['vh125'], higgs_xsec_multiplier), **remove_name_entry(data_styles['VH*']) ), "(%i#times) m_{H} = 125" % higgs_xsec_multiplier @@ -769,11 +769,16 @@ def plot_final(self, variable, rebin=1, xaxis='', maxy=24, charge_fakes_view = MedianView(highv=sig_view['charge_fakes']['sys_up'], centv=sig_view['charge_fakes']['central']) # Fudge factor to go from 120->125 - change in xsec*BR - vh_10x = views.ScaleView(vh_10x, .783) + #vh_10x = views.ScaleView(vh_10x), .783) tostack = [sig_view['wz_3l'], sig_view['zz'], sig_view['wz'], sig_view['fakes'], vh_10x] if stack_higgs else \ [sig_view['wz_3l'], sig_view['zz'], sig_view['wz'], sig_view['fakes']] if show_charge_fakes: tostack = tostack[:2]+[charge_fakes_view]+tostack[2:] + + vh_hww = views.ScaleView(sig_view['vh120_hww'], .783) if 'vh120_hww' in sig_view else None + if vh_hww: + tostack = tostack + [vh_hww] + stack = views.StackView( *tostack ) histo = stack.Get(variable) From 9e2e430b1db67825243031ca0ec966fee6729438 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 13 Sep 2013 09:49:43 -0500 Subject: [PATCH 040/192] more plots, better naming --- wh/WHPlotterEET.py | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/wh/WHPlotterEET.py b/wh/WHPlotterEET.py index 81049443..da96c548 100755 --- a/wh/WHPlotterEET.py +++ b/wh/WHPlotterEET.py @@ -129,7 +129,7 @@ def __init__(self): ## Signal region plots ################################################ ########################################################################### plotter.set_subdir('') - rebin_slim = [0,20]+range(30, 81, 10)+[100, 200] + rebin_slim = range(20, 81, 10)+[100, 130, 300] categories = { 'LTCut' : [80, 650], 'LTLow' : [0, 100], @@ -139,48 +139,57 @@ def __init__(self): for label, proj_range in categories.iteritems(): factor = 1.5 if label == 'LTHigh' else 1 plotter.set_subdir('%s' % label) - plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', + maxy=None, project=proj_range, project_axis='X', + differential=True, yaxis='Events / GeV', show_error=True) plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s' % label) + plotter.save('final-subMass-%s' % label) - plotter.plot_final('e2_t_Mass#LT', 200, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', + maxy=None, project=proj_range, project_axis='X', + differential=True, yaxis='Events / GeV', show_error=True) plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) + plotter.canvas.SetLogy(True) + plotter.save('final-subMass-logscale-%s' % label) + + plotter.plot_final('e2_t_Mass#LT', 300, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) #pt plotter.plot_final("e1Pt#LT" , int(factor*10), xaxis='p_{Te_{1}} (GeV)', maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1Pt-%s' % label) + plotter.save('final-e1Pt-%s' % label) plotter.plot_final("e2Pt#LT" , int(factor*10), xaxis='p_{Te_{2}} (GeV)', maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2Pt-%s' % label) + plotter.save('final-e2Pt-%s' % label) plotter.plot_final("e1JetPt#LT" , int(factor*10), xaxis='p_{T Jet e_{1}} (GeV)', maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1JetPt-%s' % label) + plotter.save('final-e1JetPt-%s' % label) plotter.plot_final("e2JetPt#LT" , int(factor*10), xaxis='p_{T Jet e_{2}} (GeV)', maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2JetPt-%s' % label) + plotter.save('final-e2JetPt-%s' % label) #eta plotter.plot_final("e1AbsEta#LT", 10, xaxis='|#eta_{e_{1}}|', maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1AbsEta-%s' % label) + plotter.save('final-e1AbsEta-%s' % label) plotter.plot_final("e2AbsEta#LT", 10, xaxis='|#eta_{e_{2}}|' , maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2AbsEta-%s' % label) + plotter.save('final-e2AbsEta-%s' % label) #DR plotter.plot_final("e1_t_DR#LT", 10, xaxis='#DeltaR_{e_{1}#tau}', maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1_t_DR-%s' % label) + plotter.save('final-e1_t_DR-%s' % label) plotter.plot_final("e2_t_DR#LT", 10, xaxis='#DeltaR_{e_{2}#tau}' , maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2_t_DR-%s' % label) + plotter.save('final-e2_t_DR-%s' % label) plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=[0, 130], project_axis='X', differential=True) plotter.add_cms_blurb(sqrts) @@ -262,11 +271,12 @@ def __init__(self): for label, proj_range in categories.iteritems(): factor = 1.5 if label == 'LTHigh' else 1 plotter.set_subdir('f3/%s' % label) - plotter.plot_final_f3('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X', differential=True) + plotter.plot_final_f3('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, yaxis='Events / GeV') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-%s' % label) - plotter.plot_final_f3('e2_t_Mass#LT', 200, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final_f3('e2_t_Mass#LT', 300, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) @@ -312,7 +322,7 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass') - plotter.plot_final_f3('e2_t_Mass', 200, xaxis='m_{e_{2}#tau} (GeV)', qcd_weight_fraction=0.5, show_error=True) + plotter.plot_final_f3('e2_t_Mass', 300, xaxis='m_{e_{2}#tau} (GeV)', qcd_weight_fraction=0.5, show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-counting-like', dotc=True, dotroot=True) From 865f7da28823e6640a1429b6e1c535cb026eef5f Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 13 Sep 2013 09:50:14 -0500 Subject: [PATCH 041/192] mass range limit put to 300 --- wh/WHPlotterEMT.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/wh/WHPlotterEMT.py b/wh/WHPlotterEMT.py index 85b58355..b33643d4 100644 --- a/wh/WHPlotterEMT.py +++ b/wh/WHPlotterEMT.py @@ -147,7 +147,8 @@ def __init__(self): for label, proj_range in categories.iteritems(): plotter.set_subdir('%s' % label) plotter.plot_final('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', differential=True, yaxis='Events / GeV') + project=proj_range, project_axis='X', differential=True, + yaxis='Events / GeV', show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-%s' % label) @@ -163,7 +164,7 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-e_t_Mass-%s' % label) - plotter.plot_final('subMass#LT', 200, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final('subMass#LT', 300, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) @@ -283,7 +284,7 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-%s' % label) - plotter.plot_final_f3('subMass#LT', [20, 40, 120, 200], xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + plotter.plot_final_f3('subMass#LT', [20, 40, 120, 300], xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X', differential=True, yaxis='Events / GeV') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-widebin-%s' % label) @@ -304,7 +305,7 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-e_t_Mass-%s' % label) - plotter.plot_final_f3('subMass#LT', 200, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final_f3('subMass#LT', 300, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) @@ -369,7 +370,7 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass') - plotter.plot_final_f3('subMass#LT', 200, xaxis='m_{l_{2}#tau_{#mu}} (GeV)', qcd_weight_fraction=0.5, show_error=True, project=[0, 650], project_axis='X') + plotter.plot_final_f3('subMass#LT', 300, xaxis='m_{l_{2}#tau_{#mu}} (GeV)', qcd_weight_fraction=0.5, show_error=True, project=[0, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-counting-like', dotc=True, dotroot=True) From 22b7b677dea692934b70caaf46e01c82da0f9359 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 13 Sep 2013 09:50:44 -0500 Subject: [PATCH 042/192] break lines, mass range limit put to 300 --- wh/WHPlotterMMT.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/wh/WHPlotterMMT.py b/wh/WHPlotterMMT.py index 7aa13ee1..0bee4631 100644 --- a/wh/WHPlotterMMT.py +++ b/wh/WHPlotterMMT.py @@ -169,7 +169,8 @@ def __init__(self): ## Signal region plots ################################################ ########################################################################### plotter.set_subdir('') - rebin_slim = [0,20]+range(30, 91, 10)+[110,200] + #rebin_slim = range(20, 91, 10)+[110,200] + rebin_slim = range(20, 81, 10)+[100, 130, 300] categories = { 'LTCut' : [80, 650], 'LTLow' : [0, 130], @@ -178,11 +179,12 @@ def __init__(self): for label, proj_range in categories.iteritems(): plotter.set_subdir('%s' % label) - plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X', differential=True) + plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, yaxis='Events / GeV') plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-%s' % label) - plotter.plot_final('m2_t_Mass#LT', 200, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final('m2_t_Mass#LT', 300, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) @@ -251,7 +253,8 @@ def __init__(self): #from pdb import set_trace; set_trace() - plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=[0, 130], project_axis='X', differential=True) + plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, + project=[0, 130], project_axis='X', differential=True, yaxis='Events / GeV') plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-LTLow') @@ -349,11 +352,13 @@ def __init__(self): for label, proj_range in categories.iteritems(): plotter.set_subdir('f3/%s' % label) - plotter.plot_final_f3('m2_t_Mass#LT', [0,10,20]+range(30, 91, 10)+[110,200], xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X', differential=True) + plotter.plot_final_f3('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', + maxy=None, project=proj_range, project_axis='X', differential=True, + show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-%s' % label) - plotter.plot_final_f3('m2_t_Mass#LT', 200, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final_f3('m2_t_Mass#LT', 300, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) @@ -449,7 +454,7 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass') - plotter.plot_final_f3('m2_t_Mass#LT', 200, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=0.5, show_error=True, project=[130, 650], project_axis='X') + plotter.plot_final_f3('m2_t_Mass#LT', 300, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=0.5, show_error=True, project=[130, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-counting-like', dotc=True, dotroot=True) @@ -539,7 +544,7 @@ def __init__(self): plotter.write_shapes(prefix+'m2_t_Mass#LT', 20, shape_dir, qcd_fraction=1.0, project=[80, 650], project_axis='X') shape_file.Close() - + #rebin_slim = range(20, 91, 10)+[110,200] shape_file = ROOT.TFile( os.path.join(plotter.outputdir, '%smmt_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') From 50db7e44ab71181e36302afe7067ed9f8349ff80 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 13 Sep 2013 09:51:10 -0500 Subject: [PATCH 043/192] use only pt10 FR --- wh/fakerate_functions.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/wh/fakerate_functions.py b/wh/fakerate_functions.py index f1fffac2..7e5d3d56 100755 --- a/wh/fakerate_functions.py +++ b/wh/fakerate_functions.py @@ -116,18 +116,18 @@ def make_null_dict(template, variables, mapper=None): #no changes in muonID in 2013 mapper = {'eid1[0-9][A-Z][a-z]+_':'', 'idiso02' : 'pfidiso02'} variables = ['muonJetPt', 'muonPt', 'numJets20'] #, 'muonJetCSVBtag'] -highpt_mu_fr = make_mva_functor_dict(frfit_dir + '/m_wjets_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) -lowpt_mu_fr = make_mva_functor_dict(frfit_dir + '/m_wjets_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +lowpt_mu_fr = make_mva_functor_dict(frfit_dir + '/m_wjets_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +highpt_mu_fr = lowpt_mu_fr -highpt_mu_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_qcd_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) -lowpt_mu_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_qcd_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +lowpt_mu_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_qcd_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +highpt_mu_qcd_fr = lowpt_mu_qcd_fr variables = ['muonJetPt', 'muonPt', 'numJets20'] -highpt_mue_fr = make_mva_functor_dict(frfit_dir + '/m_Mwjets_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) -lowpt_mue_fr = make_mva_functor_dict(frfit_dir + '/m_Mwjets_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +lowpt_mue_fr = make_mva_functor_dict(frfit_dir + '/m_Mwjets_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +highpt_mue_fr = lowpt_mue_fr -highpt_mue_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_Mqcd_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) -lowpt_mue_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_Mqcd_pt10_%s_muonInfo.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +lowpt_mue_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_Mqcd_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +highpt_mue_qcd_fr = lowpt_mue_qcd_fr ####################### @@ -136,19 +136,19 @@ def make_null_dict(template, variables, mapper=None): variables = ['electronJetPt', 'electronPt', 'numJets20'] #EMT -highpt_e_fr = make_mva_functor_dict(frfit_dir + '/e_wjets_pt10_%s_electronInfo.kNN.weights.xml', variables) -lowpt_e_fr = make_mva_functor_dict(frfit_dir + '/e_wjets_pt10_%s_electronInfo.kNN.weights.xml', variables) +lowpt_e_fr = make_mva_functor_dict(frfit_dir + '/e_wjets_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) +highpt_e_fr = lowpt_e_fr -highpt_e_qcd_fr = make_mva_functor_dict(frfit_dir + '/e_qcd_pt10_%s_electronInfo.kNN.weights.xml', variables) -lowpt_e_qcd_fr = make_mva_functor_dict(frfit_dir + '/e_qcd_pt10_%s_electronInfo.kNN.weights.xml', variables) +lowpt_e_qcd_fr = make_mva_functor_dict(frfit_dir + '/e_qcd_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) +highpt_e_qcd_fr = lowpt_e_qcd_fr #EET variables = ['electronJetPt', 'electronPt', 'numJets20'] -highpt_ee_fr = make_mva_functor_dict(frfit_dir + '/ee_wjetsNoZmass_pt10_%s_electronInfo.kNN.weights.xml', variables) -lowpt_ee_fr = make_mva_functor_dict(frfit_dir + '/ee_wjetsNoZmass_pt10_%s_electronInfo.kNN.weights.xml', variables) +lowpt_ee_fr = make_mva_functor_dict(frfit_dir + '/ee_wjetsNoZmass_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) +highpt_ee_fr = lowpt_ee_fr -highpt_ee_qcd_fr = make_mva_functor_dict(frfit_dir + '/ee_qcd_pt10_%s_electronInfo.kNN.weights.xml', variables) -lowpt_ee_qcd_fr = make_mva_functor_dict(frfit_dir + '/ee_qcd_pt10_%s_electronInfo.kNN.weights.xml', variables) +lowpt_ee_qcd_fr = make_mva_functor_dict(frfit_dir + '/ee_qcd_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) +highpt_ee_qcd_fr = lowpt_ee_qcd_fr ################## From 55ce9d26f62ccfe577fb5f871030270d83448d5f Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 13 Sep 2013 09:51:46 -0500 Subject: [PATCH 044/192] better naming, use only pt10 FR --- wh/plots_for_prepp_kNN.py | 41 ++++++++++++++------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/wh/plots_for_prepp_kNN.py b/wh/plots_for_prepp_kNN.py index 7338e83f..ad96a47a 100644 --- a/wh/plots_for_prepp_kNN.py +++ b/wh/plots_for_prepp_kNN.py @@ -29,12 +29,13 @@ def round_to_ints(histo): rebinPt = ( [10,12,15,20,25,30,35,40,45,50,60,70,100], #,150,200], - range(0,50,5)+range(50,110,10), + [10,12,15,20,25,30,35,40,45,50,60,70,100], #range(0,50,5)+range(50,110,10), ) rebinJet = ( [0,1,2,3,4,6,9,12], - range(13), + [0,1,2,3,4,6,9,12], + #range(13), ) axes = { @@ -47,51 +48,39 @@ def round_to_ints(histo): sources = { ##MMT - 'm_mmt_pt10_h2taucuts020_kNN' : { + 'm_mmt_subleading_kNN' : { 'vars' : {'muonPt':rebinPt, 'muonJetPt':rebinPt, 'numJets20':rebinJet}, 'wjets' : 'results/%s/fakerate_fits/m_wjets_pt10_h2taucuts020_muonInfo.kNN.root' % jobid, 'qcd' : 'results/%s/fakerate_fits/m_qcd_pt10_h2taucuts020_muonInfo.kNN.root' % jobid, }, - 'm_mmt_pt20_h2taucuts_kNN' : { + 'm_mmt_leading_kNN' : { 'vars' : {'muonPt':rebinPt, 'muonJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/m_wjets_pt20_h2taucuts_muonInfo.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/m_qcd_pt20_h2taucuts_muonInfo.kNN.root' % jobid, + 'wjets' : 'results/%s/fakerate_fits/m_wjets_pt10_h2taucuts_muonInfo.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/m_qcd_pt10_h2taucuts_muonInfo.kNN.root' % jobid, }, #EMT - 'm_emt_pt10_h2taucuts_kNN' : { + 'm_emt_kNN' : { 'vars' : {'muonPt':rebinPt, 'muonJetPt':rebinPt, 'numJets20':rebinJet}, 'wjets' : 'results/%s/fakerate_fits/m_Mwjets_pt10_h2taucuts_muonInfo.kNN.root' % jobid, 'qcd' : 'results/%s/fakerate_fits/m_Mqcd_pt10_h2taucuts_muonInfo.kNN.root' % jobid, }, - 'm_emt_pt20_h2taucuts_kNN' : { - 'vars' : {'muonPt':rebinPt, 'muonJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/m_Mwjets_pt20_h2taucuts_muonInfo.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/m_Mqcd_pt20_h2taucuts_muonInfo.kNN.root' % jobid, - }, - - - 'e_emt_pt10_h2taucuts_kNN' : { + 'e_emt_kNN' : { 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, 'wjets' : 'results/%s/fakerate_fits/e_wjets_pt10_eid12Medium_h2taucuts_electronInfo.kNN.root' % jobid, 'qcd' : 'results/%s/fakerate_fits/e_qcd_pt10_eid12Medium_h2taucuts_electronInfo.kNN.root' % jobid, }, - 'e_emt_pt20_h2taucuts_kNN' : { - 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/e_wjets_pt20_eid12Medium_h2taucuts_electronInfo.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/e_qcd_pt20_eid12Medium_h2taucuts_electronInfo.kNN.root' % jobid, - }, #EET - 'e_eet_pt10_h2taucuts_kNN' : { + 'e_eet_subleading_kNN' : { 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/ee_wjetsNoZmass_pt10_eid12Tight_h2taucuts_electronInfo.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/ee_qcd_pt10_eid12Tight_h2taucuts_electronInfo.kNN.root' % jobid, + 'wjets' : 'results/%s/fakerate_fits/ee_wjetsNoZmass_pt10_eid12Medium_h2taucuts020_electronInfo.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/ee_qcd_pt10_eid12Medium_h2taucuts020_electronInfo.kNN.root' % jobid, }, - 'e_eet_pt20_h2taucuts_kNN' : { + 'e_eet_leading_kNN' : { 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/ee_wjetsNoZmass_pt20_eid12Medium_h2taucuts020_electronInfo.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/ee_qcd_pt20_eid12Medium_h2taucuts020_electronInfo.kNN.root' % jobid, + 'wjets' : 'results/%s/fakerate_fits/ee_wjetsNoZmass_pt20_eid12Tight_h2taucuts_electronInfo.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/ee_qcd_pt20_eid12Tight_h2taucuts_electronInfo.kNN.root' % jobid, }, } From 7dea56bc72910fbe7a383ad5470792588b2259ae Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 16 Sep 2013 10:55:48 -0500 Subject: [PATCH 045/192] added logging workflow control --- wh/PlotControlEM.py | 4 +++- wh/PlotControlZMM.py | 13 ++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/wh/PlotControlEM.py b/wh/PlotControlEM.py index c4ef81c1..47af5dc3 100644 --- a/wh/PlotControlEM.py +++ b/wh/PlotControlEM.py @@ -8,6 +8,9 @@ import glob from FinalStateAnalysis.PlotTools.Plotter import Plotter from FinalStateAnalysis.MetaData.data_styles import data_styles +import logging +import sys +logging.basicConfig(stream=sys.stderr, level=logging.INFO) jobid = os.environ['jobid'] @@ -92,7 +95,6 @@ def correct_for_contrib_in_fakes(x, fudge_factor=1.0): 0.95 if sqrts == 7 else 1.0) } -print plotter.views.keys() ww_name = 'WWJetsTo2L2Nu' if sqrts == 7 else 'WWJetsTo2L2Nu_TuneZ2_8TeV' plotter.views['WWJetsTo2L2Nu-no-fakes'] = { 'view': correct_for_contrib_in_fakes(plotter.views[ww_name]['view']) diff --git a/wh/PlotControlZMM.py b/wh/PlotControlZMM.py index 237004e3..a4097d08 100644 --- a/wh/PlotControlZMM.py +++ b/wh/PlotControlZMM.py @@ -7,6 +7,9 @@ import os import glob from FinalStateAnalysis.PlotTools.Plotter import Plotter +import logging +import sys +logging.basicConfig(stream=sys.stderr, level=logging.INFO) jobid = os.environ['jobid'] @@ -14,11 +17,11 @@ samples = [ 'Zjets_M50', - #'WZ*', - #'ZZ*', - #'WW*', + 'WZ*', + 'ZZ*', + 'WW*', 'TT*', - #'WplusJets*', + 'WplusJets*', "data_DoubleMu*", ] @@ -30,7 +33,7 @@ lumifiles.extend(glob.glob('inputs/%s/%s.lumicalc.sum' % (jobid, x))) plotter = Plotter(files, lumifiles, output_dir) -plotter.mc_samples = ['Zjets_M50'] +plotter.mc_samples = filter(lambda x: 'data' not in x.lower(), samples) #['Zjets_M50'] sqrts = 7 if '7TeV' in jobid else 8 From 3ed8c2d9474988f04d9dcece139061f54b399eb2 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 16 Sep 2013 10:56:04 -0500 Subject: [PATCH 046/192] added logging workflow control, and Zee control plots --- wh/PlotControlZEE.py | 59 ++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/wh/PlotControlZEE.py b/wh/PlotControlZEE.py index b758adae..97a888ef 100644 --- a/wh/PlotControlZEE.py +++ b/wh/PlotControlZEE.py @@ -12,6 +12,9 @@ from FinalStateAnalysis.PlotTools.HistToTGRaphErrors import HistStackToTGRaphErrors from FinalStateAnalysis.MetaData.data_styles import data_styles, colors import ROOT +import logging +import sys +logging.basicConfig(stream=sys.stderr, level=logging.INFO) ROOT.gROOT.SetBatch(True) @@ -22,11 +25,11 @@ def __init__(self): self.output_dir = os.path.join('results', self.jobid, 'plots', 'zee') samples = [ 'Zjets_M50', - #'WZ*', - #'ZZ*', - #'WW*', + 'WZ*', + 'ZZ*', + 'WW*', 'TT*', - #'WplusJets*', + 'WplusJets*', "data_DoubleE*", ] files = [] @@ -66,23 +69,6 @@ def make_fakes_view(sign, weight_type): ss_fakes_est = views.SumView(ss_fakes_1, ss_fakes_2, ss_fakes_12) ss_fakes_est = views.TitleView( views.StyleView(ss_fakes_est, **data_styles['Zjets*']), 'Fakes;%s' % xaxis) - ## os_f1p2_qcd_views, os_p1f2_qcd_views, os_f1f2_qcd_views = zip(make_fakes_view('os', 'qcd_w/charge_weightSysUp'), make_fakes_view('os', 'qcd_w/charge_weightSysDwn')) - ## os_f1p2_wje_views, os_p1f2_wje_views, os_f1f2_wje_views = zip(make_fakes_view('os', 'wjet_w/charge_weightSysUp'),make_fakes_view('os', 'wjet_w/charge_weightSysDwn')) - - ## os_f1p2_qcd_view = MedianView( *os_f1p2_qcd_views ) - ## os_p1f2_qcd_view = MedianView( *os_p1f2_qcd_views ) - ## os_f1f2_qcd_view = MedianView( *os_f1f2_qcd_views ) - - ## os_f1p2_wje_view = MedianView( *os_f1p2_wje_views ) - ## os_p1f2_wje_view = MedianView( *os_p1f2_wje_views ) - ## os_f1f2_wje_view = MedianView( *os_f1f2_wje_views ) - - ## os_fakes_1 = MedianView(os_f1p2_qcd_view, os_f1p2_wje_view) - ## os_fakes_2 = MedianView(os_p1f2_qcd_view, os_p1f2_wje_view) - ## os_fakes_12 = MedianView(os_f1f2_qcd_view, os_f1f2_wje_view) - ## os_fakes_est = views.SumView(os_fakes_1, os_fakes_2, os_fakes_12) - ## neg_os_fakes = views.ScaleView(os_fakes_est, -1) - os_flip_est_up = views.SubdirectoryView( data_view, 'os/p1p2/charge_weightSysUp') os_flip_est = views.SubdirectoryView( data_view, 'os/p1p2/charge_weight') os_flip_est = MedianView(highv=os_flip_est_up, centv=os_flip_est) @@ -176,3 +162,34 @@ def make_charge_flip_control_plot(self, variable, xaxis='', rebin=1, legend_on_t plotter.make_charge_flip_control_plot('ePt','electron p_{T}',2,x_range=[0,200], data_type='Zjets_M50') plotter.save('EE_Charge_Flip_closure_ePt') + +# +# DATA/MC control plots +# + +plotter.plot_mc_vs_data('os/p1p2/', 'TrkMass', rebin=2, xaxis='m_{#mu#mu} (GeV)') +plotter.add_cms_blurb(plotter.sqrts) +plotter.save('mass') + +plotter.plot_mc_vs_data('os/p1p2/', 'TrkMass', rebin=10, xaxis='m_{#mu#mu} (GeV)') +plotter.add_cms_blurb(plotter.sqrts) +plotter.save('mass_rebin') + +plotter.plot_mc_vs_data('os/p1p2/', 'e1Pt') +plotter.save('e1Pt') +plotter.plot_mc_vs_data('os/p1p2/', 'e1Pt', 5) +plotter.save('e1Pt_rebin') +plotter.plot_mc_vs_data('os/p1p2/', 'e2Pt') +plotter.save('e2Pt') +plotter.plot_mc_vs_data('os/p1p2/', 'e2Pt', 5) +plotter.save('e2Pt_rebin') + +plotter.plot_mc_vs_data('os/p1p2/', 'e1AbsEta') +plotter.save('e1AbsEta') +plotter.plot_mc_vs_data('os/p1p2/', 'e2AbsEta') +plotter.save('e2AbsEta') + +plotter.plot_mc_vs_data('os/p1p2/', 'e1AbsEta', 5) +plotter.save('e1AbsEta_rebin') +plotter.plot_mc_vs_data('os/p1p2/', 'e2AbsEta', 5) +plotter.save('e2AbsEta_rebin') From 7eda92dce1ca50ce6cf6b6f2a0253bfbbbac7ea8 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 16 Sep 2013 10:56:24 -0500 Subject: [PATCH 047/192] bugfix --- wh/Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wh/Rakefile b/wh/Rakefile index 9b68c8ad..8cb8425d 100755 --- a/wh/Rakefile +++ b/wh/Rakefile @@ -926,7 +926,7 @@ def make_timestamp_task(cardmasses, channel) timestamp = "#{$carddir}/#{channel}/.creation_timestamp" #creates the tasks make_unc_conf_task(channel) - make_unc_vals_task(channel) + make_unc_vals_task(channel, '', true) make_cgs_conf_task(channel) file timestamp => cardmasses.map{|x| make_datacard_task(x, channel)} do |t| sh "mkdir -p `dirname #{t.name}`" From 238caa9a7d3bd460502c7000601add460f2dc2b1 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 16 Sep 2013 10:57:02 -0500 Subject: [PATCH 048/192] better treatment of low stat bins in FR, removes empty bins --- wh/WHPlotterBase.py | 103 ++++++++++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 36 deletions(-) diff --git a/wh/WHPlotterBase.py b/wh/WHPlotterBase.py index acf74a87..ec169975 100644 --- a/wh/WHPlotterBase.py +++ b/wh/WHPlotterBase.py @@ -69,6 +69,28 @@ def _f(path): def remove_name_entry(dictionary): return dict( [ i for i in dictionary.iteritems() if i[0] != 'name'] ) +def fake_rate_estimate(histograms): #always, ALWAYS give as 1,2,0 + cat1 = histograms.next() + cat2 = histograms.next() + cat0 = histograms.next() + ret = cat0.Clone() + ret.Reset() + for i in range(ret.GetNbinsX() + 2): + c1 = cat1.GetBinContent(i) + c2 = cat2.GetBinContent(i) + c0 = cat0.GetBinContent(i) + e1 = cat1.GetBinError(i) + e2 = cat2.GetBinError(i) + e0 = cat0.GetBinError(i) + if c1 == 0 and c2 == 0: + ret.SetBinContent(i,c0) + ret.SetBinError(i,e0) + else: + ret.SetBinContent(i,c1+c2-c0) + ret.SetBinError(i,quad(e1,e2,e0)) + return ret + + class BackgroundErrorView(object): ''' Compute the total background error in each bin. ''' def __init__(self, fakes, wz, zz, charge_fake, wz_error=0.1, zz_error=0.04, @@ -251,27 +273,43 @@ def apply_to_dict(self, dictionary, viewtype, *args, **kwargs): #project, projec ret[key] = viewtype(val, *args, **kwargs) # self.rebin_view( ProjectionView(val, project_axis, project), rebin ) return ret - @memo - def make_signal_views(self, unblinded=False, qcd_weight_fraction=0): + def make_signal_views(self, unblinded=False, qcd_weight_fraction=0, #MARK + rebin=1, project=None, project_axis=None ): ''' Make signal views with FR background estimation ''' - wz_view_tautau = views.SubdirectoryView( - self.get_view('WZJetsTo3LNu*ZToTauTau*'), - 'ss/p1p2p3/' + def preprocess(view): + ret = view + if project and project_axis: + ret = ProjectionView(ret, project_axis, project) + return RebinView( ret, rebin ) + + wz_view_tautau = preprocess( + views.SubdirectoryView( + self.get_view('WZJetsTo3LNu*ZToTauTau*'), + 'ss/p1p2p3/' + ) ) + tomatch = 'WZJetsTo3LNu' if self.sqrts == 7 else 'WZJetsTo3LNu_pythia' - wz_view_3l = views.SubdirectoryView( - self.get_view(tomatch), - 'ss/p1p2p3/' + wz_view_3l = preprocess( + views.SubdirectoryView( + self.get_view(tomatch), + 'ss/p1p2p3/' + ) ) - zz_view = views.SubdirectoryView( - self.get_view('ZZJetsTo4L*'), - 'ss/p1p2p3/' + + zz_view = preprocess( + views.SubdirectoryView( + self.get_view('ZZJetsTo4L*'), + 'ss/p1p2p3/' + ) ) + all_data_view = self.get_view('data') if unblinded: all_data_view = self.get_view('data', 'unblinded_view') - + all_data_view = preprocess(all_data_view) + data_view = views.SubdirectoryView(all_data_view, 'ss/p1p2p3/') def make_fakes(qcd_fraction): @@ -298,20 +336,18 @@ def make_fakes_view(weight_type, scale): views.StyleView(obj12_view, **remove_name_entry(data_styles['WW*'])), 'Reducible bkg. 12') - subtract_obj12_view = views.ScaleView(obj12_view, -1) - return obj1_view, obj2_view, obj12_view, subtract_obj12_view + return obj1_view, obj2_view, obj12_view - qcd1, qcd2, qcd12, negqcd12 = make_fakes_view('q', qcd_fraction) - wjet1, wjet2, wjet12, negwjet12 = make_fakes_view( + qcd1, qcd2, qcd12 = make_fakes_view('q', qcd_fraction) + wjet1, wjet2, wjet12 = make_fakes_view( 'w', 1 - qcd_fraction) obj1_view = views.SumView(qcd1, wjet1) obj2_view = views.SumView(qcd2, wjet2) obj12_view = views.SumView(qcd12, wjet12) - subtract_obj12_view = views.SumView(negqcd12, negwjet12) # Corrected fake view - fakes_view = views.SumView(obj1_view, obj2_view, subtract_obj12_view) + fakes_view = views.MultiFunctorView(fake_rate_estimate, obj1_view, obj2_view, obj12_view) fakes_view = views.TitleView( views.StyleView(fakes_view, **remove_name_entry(data_styles['Zjets*'])), 'Reducible bkg.') return obj1_view, obj2_view, obj12_view, fakes_view @@ -381,9 +417,9 @@ def make_fakes_view(weight_type, scale): self.get_view('VH_*%i' % mass), 'ss/p1p2p3/' ) - output['vh%i' % mass] = vh_view + output['vh%i' % mass] = preprocess(vh_view) except KeyError: - logging.warning('No sample found matching VH_*%i' % mass) + #logging.warning('No sample found matching VH_*%i' % mass) continue if mass % 10 == 0 and mass < 150: @@ -393,11 +429,11 @@ def make_fakes_view(weight_type, scale): self.get_view('VH_%i_HWW*' % mass), 'ss/p1p2p3/' ) + output['vh%i_hww' % mass] = preprocess(ww_view) except KeyError: - logging.warning('No sample found matching VH_%i_HWW*' % mass) - ww_view = None - output['vh%i_hww' % mass] = ww_view - output['signal%i' % mass] = views.SumView(ww_view, vh_view) if ww_view else vh_view + #logging.warning('No sample found matching VH_%i_HWW*' % mass) + continue + #output['signal%i' % mass] = views.SumView(ww_view, vh_view) if ww_view else vh_view return output @@ -633,12 +669,9 @@ def write_shapes(self, variable, rebin, outdir, ''' Write final shapes for [variable] into a TDirectory [outputdir] ''' show_charge_fakes = show_charge_fakes if 'show_charge_fakes' not in self.defaults else self.defaults['show_charge_fakes'] sig_view = self.make_signal_views(unblinded=(not self.blind), - qcd_weight_fraction=qcd_fraction) + qcd_weight_fraction=qcd_fraction, + rebin=rebin, project=project, project_axis=project_axis) - if project and project_axis: - sig_view = self.apply_to_dict( sig_view, ProjectionView, project_axis, project ) - sig_view = self.apply_to_dict( sig_view, RebinView, rebin ) - outdir.cd() wz = views.SumView(sig_view['wz'], sig_view['wz_3l']).Get(variable) zz = sig_view['zz'].Get(variable) @@ -662,7 +695,7 @@ def write_shapes(self, variable, rebin, outdir, if mass % 10 == 0 and mass < 150: # Only have 10 GeV steps for WW - if sig_view['vh%i_hww' % mass]: + if 'vh%i_hww' % mass in sig_view: ww = sig_view['vh%i_hww' % mass].Get(variable) ww.SetName('WH_hww%i' % mass) ww.Write() @@ -751,11 +784,9 @@ def plot_final(self, variable, rebin=1, xaxis='', maxy=24, ''' Plot the final output - with bkg. estimation ''' show_charge_fakes = show_charge_fakes if 'show_charge_fakes' not in self.defaults else self.defaults['show_charge_fakes'] sig_view = self.make_signal_views(unblinded=(not self.blind), - qcd_weight_fraction=qcd_weight_fraction) - if project and project_axis: - sig_view = self.apply_to_dict( sig_view, ProjectionView, project_axis, project ) - sig_view = self.apply_to_dict( sig_view, RebinView, rebin ) #Rebin - + qcd_weight_fraction=qcd_weight_fraction, + rebin=rebin, project=project, project_axis=project_axis) + if differential: sig_view = self.apply_to_dict(sig_view, DifferentialView) @@ -777,7 +808,7 @@ def plot_final(self, variable, rebin=1, xaxis='', maxy=24, vh_hww = views.ScaleView(sig_view['vh120_hww'], .783) if 'vh120_hww' in sig_view else None if vh_hww: - tostack = tostack + [vh_hww] + tostack = tostack[:-1] + [vh_hww] + tostack[-1:] stack = views.StackView( *tostack ) histo = stack.Get(variable) From 34c5bf7a791beb0c07f7d12a1d04ddded7c81945 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 16 Sep 2013 10:57:55 -0500 Subject: [PATCH 049/192] define vars in the proper place --- wh/WHPlotterMMT.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/wh/WHPlotterMMT.py b/wh/WHPlotterMMT.py index 0bee4631..1932c1e8 100644 --- a/wh/WHPlotterMMT.py +++ b/wh/WHPlotterMMT.py @@ -22,6 +22,14 @@ class WHPlotterMMT(WHPlotterBase.WHPlotterBase): def __init__(self): super(WHPlotterMMT, self).__init__('MMT') +rebin_slim = range(20, 81, 10)+[100, 130, 300] +categories = { + 'LTCut' : [80, 650], + 'LTLow' : [0, 130], + 'LTHigh': [130, 650], +} + + if __name__ == "__main__": plotter = WHPlotterMMT() sqrts = plotter.sqrts @@ -170,12 +178,6 @@ def __init__(self): ########################################################################### plotter.set_subdir('') #rebin_slim = range(20, 91, 10)+[110,200] - rebin_slim = range(20, 81, 10)+[100, 130, 300] - categories = { - 'LTCut' : [80, 650], - 'LTLow' : [0, 130], - 'LTHigh': [130, 650], - } for label, proj_range in categories.iteritems(): plotter.set_subdir('%s' % label) From 41a81ee2e85e6545287b411d5234f275035704da Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 16 Sep 2013 10:59:10 -0500 Subject: [PATCH 050/192] update --- wh/plot.sh | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/wh/plot.sh b/wh/plot.sh index 2ab705df..43a0b0ac 100755 --- a/wh/plot.sh +++ b/wh/plot.sh @@ -5,24 +5,27 @@ set -o nounset set -o errexit source jobid.sh -#export jobid=$jobid7 -#rake plot_zee -#rake plot_eet -# -#rake plot_em -#rake plot_emt -# -#rake plot_zmm -#rake plot_mmt -#python plots_for_prepp.py -# +export jobid=$jobid7 +echo $jobid +python WHPlotterMMT.py +python WHPlotterEMT.py +python WHPlotterEET.py + +python PlotControlZMM.py +python PlotControlEM.py +python PlotControlZEE.py + +python plots_for_prepp_kNN.py + export jobid=$jobid8 -#rake plot_zee -rake plot_eet -# -#rake plot_em -rake plot_emt -# -#rake plot_zmm -rake plot_mmt -python plots_for_prepp.py +echo $jobid +python WHPlotterMMT.py +python WHPlotterEMT.py +python WHPlotterEET.py + +python PlotControlZMM.py +python PlotControlEM.py +python PlotControlZEE.py + +python plots_for_prepp_kNN.py + From e13f901e58a84e5ca105d7aad7e0b5c2a693d1cd Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 16 Sep 2013 10:59:51 -0500 Subject: [PATCH 051/192] update names --- wh/plots_for_prepp_kNN.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/wh/plots_for_prepp_kNN.py b/wh/plots_for_prepp_kNN.py index ad96a47a..c4660c53 100644 --- a/wh/plots_for_prepp_kNN.py +++ b/wh/plots_for_prepp_kNN.py @@ -50,37 +50,37 @@ def round_to_ints(histo): ##MMT 'm_mmt_subleading_kNN' : { 'vars' : {'muonPt':rebinPt, 'muonJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/m_wjets_pt10_h2taucuts020_muonInfo.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/m_qcd_pt10_h2taucuts020_muonInfo.kNN.root' % jobid, + 'wjets' : 'results/%s/fakerate_fits/m_wjets_pt10_h2taucuts020_muonInfo_k100.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/m_qcd_pt10_h2taucuts020_muonInfo_k100.kNN.root' % jobid, }, 'm_mmt_leading_kNN' : { 'vars' : {'muonPt':rebinPt, 'muonJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/m_wjets_pt10_h2taucuts_muonInfo.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/m_qcd_pt10_h2taucuts_muonInfo.kNN.root' % jobid, + 'wjets' : 'results/%s/fakerate_fits/m_wjets_pt10_h2taucuts_muonInfo_k100.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/m_qcd_pt10_h2taucuts_muonInfo_k100.kNN.root' % jobid, }, #EMT 'm_emt_kNN' : { 'vars' : {'muonPt':rebinPt, 'muonJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/m_Mwjets_pt10_h2taucuts_muonInfo.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/m_Mqcd_pt10_h2taucuts_muonInfo.kNN.root' % jobid, + 'wjets' : 'results/%s/fakerate_fits/m_Mwjets_pt10_h2taucuts_muonInfo_k100.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/m_Mqcd_pt10_h2taucuts_muonInfo_k100.kNN.root' % jobid, }, 'e_emt_kNN' : { 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/e_wjets_pt10_eid12Medium_h2taucuts_electronInfo.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/e_qcd_pt10_eid12Medium_h2taucuts_electronInfo.kNN.root' % jobid, + 'wjets' : 'results/%s/fakerate_fits/e_wjets_pt10_eid12Medium_h2taucuts_electronInfo_k100.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/e_qcd_pt10_eid12Medium_h2taucuts_electronInfo_k100.kNN.root' % jobid, }, #EET 'e_eet_subleading_kNN' : { 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/ee_wjetsNoZmass_pt10_eid12Medium_h2taucuts020_electronInfo.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/ee_qcd_pt10_eid12Medium_h2taucuts020_electronInfo.kNN.root' % jobid, + 'wjets' : 'results/%s/fakerate_fits/ee_wjetsNoZmass_pt10_eid12Medium_h2taucuts020_electronInfo_k100.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/ee_qcd_pt10_eid12Medium_h2taucuts020_electronInfo_k100.kNN.root' % jobid, }, 'e_eet_leading_kNN' : { 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/ee_wjetsNoZmass_pt20_eid12Tight_h2taucuts_electronInfo.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/ee_qcd_pt20_eid12Tight_h2taucuts_electronInfo.kNN.root' % jobid, + 'wjets' : 'results/%s/fakerate_fits/ee_wjetsNoZmass_pt10_eid12Tight_h2taucuts_electronInfo_k100.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/ee_qcd_pt10_eid12Tight_h2taucuts_electronInfo_k100.kNN.root' % jobid, }, } From d14e78f6ab841c3bdab70d267bbc309a73280f92 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 16 Sep 2013 11:00:44 -0500 Subject: [PATCH 052/192] update --- wh/run.sh | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/wh/run.sh b/wh/run.sh index 0b0ba5e8..7ef7c979 100755 --- a/wh/run.sh +++ b/wh/run.sh @@ -8,25 +8,27 @@ source jobid.sh export jobid=$jobid8 rake fakerates -rake fits - -#rake mmcontrol -#rake emcontrol -rake eecontrol +rake charge_fakes +rake kNN rake mmt rake emt rake eet -#export jobid=$jobid7 -#rake fakerates -#rake fits +rake mmcontrol +rake emcontrol +rake eecontrol -#rake mmcontrol -#rake emcontrol -#rake eecontrol +export jobid=$jobid7 +rake fakerates +rake charge_fakes +rake kNN +#rake fits -#rake mmt -#rake emt -#rake eet +rake mmt +rake emt +rake eet +rake mmcontrol +rake emcontrol +rake eecontrol From 4fd0a64c4b0001fda796e33c1ad05aa4be72830c Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 27 Sep 2013 07:31:13 -0500 Subject: [PATCH 053/192] added trig scale factor --- wh/ChargeFlipProbabilityEE.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wh/ChargeFlipProbabilityEE.py b/wh/ChargeFlipProbabilityEE.py index 2eb0d82e..8ad26532 100755 --- a/wh/ChargeFlipProbabilityEE.py +++ b/wh/ChargeFlipProbabilityEE.py @@ -100,8 +100,8 @@ def preselection(row): continue evt_weight = pucorrector(row.nTruePU) * \ - mcCorrectors.get_electron_corrections(row,'e1','e2') - + mcCorrectors.get_electron_corrections(row,'e1','e2') *\ + mcCorrectors.double_electron_trigger(row) for iso_label in lep_id: if not selections.lepton_id_iso(row, 'e1', iso_label): continue From 2d88feb540124cf30c03234bcfdcd1d748df9164 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 27 Sep 2013 07:32:45 -0500 Subject: [PATCH 054/192] more plots, added 7TeV trigger --- wh/ControlEM.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/wh/ControlEM.py b/wh/ControlEM.py index b83237b4..893bac98 100644 --- a/wh/ControlEM.py +++ b/wh/ControlEM.py @@ -74,6 +74,11 @@ def begin(self): 5, -0.5, 4.5) self.book('em' + folder, 'eVetoCicTightIso', 'Number of extra CiC tight electrons', 5, -0.5, 4.5) + self.book('em' + folder, "trig_weight" , "mva_metEt", 200, 0, 2) + self.book('em' + folder, "PU_weight" , "mva_metEt", 200, 0, 2) + self.book('em' + folder, "idIso_weight", "mva_metEt", 200, 0, 2) + self.book('em' + folder, "emMass_noweight", "m_{e#mu} (GeV)", 240, 0, 240) + def correction(self, row): return self.pucorrector(row.nTruePU) * \ @@ -100,12 +105,20 @@ def fill_folder(x, w): histos[x + '/eJetBtag'].Fill(row.eJetBtag, w) histos[x + '/mJetBtag'].Fill(row.mJetBtag, w) histos[x + '/emMass'].Fill(row.e_m_Mass, w) + histos[x + '/emMass_noweight'].Fill(row.e_m_Mass) histos[x + '/bjetVeto'].Fill(row.bjetVeto, w) histos[x + '/bjetCSVVeto'].Fill(row.bjetCSVVeto, w) histos[x + '/muVetoPt5'].Fill(row.muVetoPt5, w) histos[x + '/tauVetoPt20'].Fill(row.tauVetoPt20, w) histos[x + '/eVetoCicTightIso'].Fill(row.eVetoCicTightIso, w) + if row.run < 2: + histos[x + "/trig_weight" ].Fill(mcCorrectors.correct_mueg_mu(row.mPt, row.mAbsEta)* + mcCorrectors.correct_mueg_e(row.ePt, row.eAbsEta) ) + histos[x + "/PU_weight" ].Fill(self.pucorrector(row.nTruePU)) + histos[x + "/idIso_weight"].Fill(mcCorrectors.get_muon_corrections(row,'m') * + mcCorrectors.get_electron_corrections(row,'e') ) + passes_e_id_iso = self.obj2_id(row) if row.e_m_SS and passes_e_id_iso: @@ -122,7 +135,7 @@ def preselection(self, row): Excludes FR object IDs and sign cut. ''' mu17e8 = (row.mu17ele8isoPass and row.mPt >= 20) if use_iso_trigger else (row.mu17ele8Pass and row.mPt >= 20) - mu8e17 = (row.mu8ele17isoPass and row.ePt >= 20) #if use_iso_trigger else (row.mu17ele8Pass and row.mPt < 20) + mu8e17 = (row.mu8ele17isoPass and row.ePt >= 20) if use_iso_trigger else (row.mu8ele17Pass and row.mPt < 20) if not (mu17e8 or mu8e17): return False if not selections.muSelection(row, 'm'): return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag) if not selections.eSelection(row, 'e'): return False #applies basic selection (eta, pt > 10, DZ, missingHits, jetBTag, HasConversion and chargedIdTight) From 556302180d8e2c7ae68f897947915aef0b68095e Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 27 Sep 2013 07:33:51 -0500 Subject: [PATCH 055/192] more plots, bugfix, added trig scale factors --- wh/ControlZEE.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/wh/ControlZEE.py b/wh/ControlZEE.py index 0cb5a814..822291db 100644 --- a/wh/ControlZEE.py +++ b/wh/ControlZEE.py @@ -19,8 +19,8 @@ from functools import wraps math = ROOT.TMath -leading_iso = optimizer.grid_search['EET']['leading_iso'] -subleading_iso = optimizer.grid_search['EET']['subleading_iso'] +leading_iso = 'eid12Medium_h2taucuts' #optimizer.grid_search['EET']['leading_iso'] +subleading_iso = 'eid12Medium_h2taucuts' #optimizer.grid_search['EET']['subleading_iso'] def sc_inv_mass(row): @@ -89,6 +89,7 @@ def book_(dirname): self.book(dirname, 'SCEnergy', 'electron Super Cluster energy', 500, 0, 1000) self.book(dirname, 'SCDPhi' , 'electron Super Cluster DeltaPhi', 180, 0, math.Pi()) self.book(dirname, 'TrkMass' , 'Dielectrons invariant mass; M_{ee} [GeV];counts', 110, 40, 150) + self.book(dirname, 'TrkMass_NoWeight', 'Dielectrons invariant mass; M_{ee} [GeV];counts', 110, 40, 150) self.book(dirname, 'TrkMass_NOSCALE' , 'Dielectrons invariant mass; M_{ee} [GeV];counts', 110, 40, 150) self.book(dirname, 'SCMass' , 'Dielectrons Super Cluster invariant mass; M_{ee} [GeV];counts', 110, 40, 150) self.book(dirname, "e1Pt" , "electron 1 Pt", 400, 0, 800) @@ -97,6 +98,10 @@ def book_(dirname): self.book(dirname, "e2AbsEta", "electron 2 abseta", 100, 0., 2.5) self.book(dirname, "type1_pfMetEt", "metEt" , 300, 0, 300) self.book(dirname, "mva_metEt", "mva_metEt", 300, 0, 300) + self.book(dirname, "trig_weight" , "mva_metEt", 200, 0, 2) + self.book(dirname, "PU_weight" , "mva_metEt", 200, 0, 2) + self.book(dirname, "idIso_weight", "mva_metEt", 200, 0, 2) + self.dirs = ['/'.join([sign,id_,weight,ch_weight]) for sign in ['os','ss'] for id_ in [h+k for h in ['p1','f1'] for k in ['p2','f2'] ] @@ -119,14 +124,6 @@ def book_(dirname): self.dir_based_histograms[location] = {} self.dir_based_histograms[location][name] = hist - def evt_weight(self, row): - if row.run > 2: - return 1. - else: - return self.pucorrector(row.nTruePU) * \ - mcCorrectors.get_electron_corrections(row,'e1','e2') - - def preselection(self, row): ''' Preselection applied to events. @@ -144,7 +141,7 @@ def preselection(self, row): return True def obj1_id(self, row): - return selections.lepton_id_iso(row, 'e1', subleading_iso) + return selections.lepton_id_iso(row, 'e1', leading_iso) def obj2_id(self, row): return selections.lepton_id_iso(row, 'e2', subleading_iso) @@ -152,8 +149,10 @@ def obj2_id(self, row): def mc_weight(self, row): if row.run > 2: return 1. - return self.pucorrector(row.nTruePU) * \ - mcCorrectors.get_electron_corrections(row,'e1','e2') + else: + return self.pucorrector(row.nTruePU) * \ + mcCorrectors.get_electron_corrections(row,'e1','e2') *\ + mcCorrectors.double_electron_trigger(row) def process(self): @@ -174,8 +173,13 @@ def fill_histos(dirname, row, weight): histos[dirname]["e1AbsEta"].Fill(row.e1AbsEta,weight) histos[dirname]["e2AbsEta"].Fill(row.e2AbsEta,weight) histos[dirname]['TrkMass_NOSCALE'].Fill(row.e1_e2_Mass, weight) + histos[dirname]['TrkMass_NoWeight'].Fill(row.e1_e2_Mass) histos[dirname]['type1_pfMetEt'].Fill(row.type1_pfMetEt, weight) histos[dirname]['mva_metEt'].Fill(row.mva_metEt, weight) + if row.run < 2: + histos[dirname]["trig_weight" ].Fill( self.pucorrector(row.nTruePU) ) + histos[dirname]["PU_weight" ].Fill( mcCorrectors.get_electron_corrections(row,'e1','e2') ) + histos[dirname]["idIso_weight"].Fill( mcCorrectors.double_electron_trigger(row) ) for row in self.tree: if not self.preselection(row): From 18a9f0ddb914160ebb717d523f3b2bf6629792d1 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 27 Sep 2013 07:34:32 -0500 Subject: [PATCH 056/192] more plots, added ratio under the main pad --- wh/PlotControlEM.py | 19 ++++++++++--------- wh/PlotControlZEE.py | 38 +++++++++++++++++++++++++++----------- wh/PlotControlZMM.py | 22 +++++++++++----------- 3 files changed, 48 insertions(+), 31 deletions(-) diff --git a/wh/PlotControlEM.py b/wh/PlotControlEM.py index 47af5dc3..b1ed1fd5 100644 --- a/wh/PlotControlEM.py +++ b/wh/PlotControlEM.py @@ -131,31 +131,32 @@ def correct_for_contrib_in_fakes(x, fudge_factor=1.0): for suffix, samples in [('', os_ss_samples), ('-fakes', fakes_samples)]: plotter.mc_samples = samples + #from pdb import set_trace; set_trace() plotter.plot_mc_vs_data('em', 'emMass', rebin=5, leftside=False, - xaxis='m_{e#mu} (GeV)') + xaxis='m_{e#mu} (GeV)', show_ratio=True) plotter.add_cms_blurb(sqrts) plotter.save('mass' + suffix) plotter.plot_mc_vs_data('em', 'emMass', rebin=10, leftside=False, - xaxis='m_{e#mu} (GeV)') + xaxis='m_{e#mu} (GeV)', show_ratio=True) plotter.add_cms_blurb(sqrts) plotter.save('mass_rebin' + suffix) - plotter.plot_mc_vs_data('em', 'mPt', rebin=10) + plotter.plot_mc_vs_data('em', 'mPt', rebin=10, show_ratio=True) plotter.save('mPt' + suffix) - plotter.plot_mc_vs_data('em', 'ePt', rebin=10) + plotter.plot_mc_vs_data('em', 'ePt', rebin=10, show_ratio=True) plotter.save('ePt' + suffix) - plotter.plot_mc_vs_data('em', 'mAbsEta', rebin=5) + plotter.plot_mc_vs_data('em', 'mAbsEta', rebin=5, show_ratio=True) plotter.save('mAbsEta' + suffix) - plotter.plot_mc_vs_data('em', 'eAbsEta', rebin=5) + plotter.plot_mc_vs_data('em', 'eAbsEta', rebin=5, show_ratio=True) plotter.save('eAbsEta' + suffix) - plotter.plot_mc_vs_data('em', 'nvtx') + plotter.plot_mc_vs_data('em', 'nvtx', show_ratio=True) plotter.save('nvtx' + suffix) - plotter.plot_mc_vs_data('em', 'bjetCSVVeto') + plotter.plot_mc_vs_data('em', 'bjetCSVVeto', show_ratio=True) plotter.save('bjetCSVVeto' + suffix) - plotter.plot_mc_vs_data('em', 'bjetVeto') + plotter.plot_mc_vs_data('em', 'bjetVeto', show_ratio=True) plotter.save('bjetVeto' + suffix) diff --git a/wh/PlotControlZEE.py b/wh/PlotControlZEE.py index 97a888ef..b9c5fc59 100644 --- a/wh/PlotControlZEE.py +++ b/wh/PlotControlZEE.py @@ -39,7 +39,7 @@ def __init__(self): files.extend(glob.glob('results/%s/ControlZEE/%s.root' % (self.jobid, x))) lumifiles.extend(glob.glob('inputs/%s/%s.lumicalc.sum' % (self.jobid, x))) super(ControlZEEPlotter, self).__init__(files, lumifiles, self.output_dir) - self.mc_samples = ['Zjets_M50'] + self.mc_samples = filter(lambda x: 'data' not in x, samples) def get_flip_data(self, rebin=1, xaxis='', data_type='data'): data_view = self.get_view(data_type) @@ -167,29 +167,45 @@ def make_charge_flip_control_plot(self, variable, xaxis='', rebin=1, legend_on_t # DATA/MC control plots # -plotter.plot_mc_vs_data('os/p1p2/', 'TrkMass', rebin=2, xaxis='m_{#mu#mu} (GeV)') +plotter.plot_mc_vs_data('os/p1p2/', 'TrkMass', rebin=2, xaxis='m_{#mu#mu} (GeV)', + leftside=False, show_ratio=True) plotter.add_cms_blurb(plotter.sqrts) plotter.save('mass') -plotter.plot_mc_vs_data('os/p1p2/', 'TrkMass', rebin=10, xaxis='m_{#mu#mu} (GeV)') +plotter.plot_mc_vs_data('os/p1p2/', 'TrkMass', rebin=10, xaxis='m_{#mu#mu} (GeV)', + leftside=False, show_ratio=True) plotter.add_cms_blurb(plotter.sqrts) plotter.save('mass_rebin') -plotter.plot_mc_vs_data('os/p1p2/', 'e1Pt') +plotter.plot_mc_vs_data('os/p1p2/', 'e1Pt', leftside=False, show_ratio=True) plotter.save('e1Pt') -plotter.plot_mc_vs_data('os/p1p2/', 'e1Pt', 5) +plotter.plot_mc_vs_data('os/p1p2/', 'e1Pt', 5, leftside=False, show_ratio=True) plotter.save('e1Pt_rebin') -plotter.plot_mc_vs_data('os/p1p2/', 'e2Pt') +plotter.plot_mc_vs_data('os/p1p2/', 'e2Pt', leftside=False, show_ratio=True) plotter.save('e2Pt') -plotter.plot_mc_vs_data('os/p1p2/', 'e2Pt', 5) +plotter.plot_mc_vs_data('os/p1p2/', 'e2Pt', 5, leftside=False, show_ratio=True) plotter.save('e2Pt_rebin') -plotter.plot_mc_vs_data('os/p1p2/', 'e1AbsEta') +plotter.plot_mc_vs_data('os/p1p2/', 'e1AbsEta', leftside=False, show_ratio=True) plotter.save('e1AbsEta') -plotter.plot_mc_vs_data('os/p1p2/', 'e2AbsEta') +plotter.plot_mc_vs_data('os/p1p2/', 'e2AbsEta', leftside=False, show_ratio=True) plotter.save('e2AbsEta') -plotter.plot_mc_vs_data('os/p1p2/', 'e1AbsEta', 5) +plotter.plot_mc_vs_data('os/p1p2/', 'e1AbsEta', 5, leftside=False, show_ratio=True) plotter.save('e1AbsEta_rebin') -plotter.plot_mc_vs_data('os/p1p2/', 'e2AbsEta', 5) +plotter.plot_mc_vs_data('os/p1p2/', 'e2AbsEta', 5, leftside=False, show_ratio=True) plotter.save('e2AbsEta_rebin') + + +plotter.plot_mc_vs_data('os/p1p2/', "trig_weight" , 5, leftside=False, show_ratio=True) +plotter.save('trig_weight') + +plotter.plot_mc_vs_data('os/p1p2/', "PU_weight" , 5, leftside=False, show_ratio=True) +plotter.save('PU_weight') + +plotter.plot_mc_vs_data('os/p1p2/', "idIso_weight", 5, leftside=False, show_ratio=True) +plotter.save('idIso_weight') + + +#plotter.plot_mc_vs_data('os/p1p2/', 'nvtx', show_ratio=True) +#plotter.save('nvtx') diff --git a/wh/PlotControlZMM.py b/wh/PlotControlZMM.py index a4097d08..b59ed872 100644 --- a/wh/PlotControlZMM.py +++ b/wh/PlotControlZMM.py @@ -37,32 +37,32 @@ sqrts = 7 if '7TeV' in jobid else 8 -plotter.plot_mc_vs_data('zmm', 'm1m2Mass', rebin=2, xaxis='m_{#mu#mu} (GeV)') +plotter.plot_mc_vs_data('zmm', 'm1m2Mass', rebin=2, xaxis='m_{#mu#mu} (GeV)', show_ratio=True) plotter.add_cms_blurb(sqrts) plotter.save('mass') -plotter.plot_mc_vs_data('zmm', 'm1m2Mass', rebin=6, xaxis='m_{#mu#mu} (GeV)') +plotter.plot_mc_vs_data('zmm', 'm1m2Mass', rebin=6, xaxis='m_{#mu#mu} (GeV)', show_ratio=True) plotter.add_cms_blurb(sqrts) plotter.save('mass_rebin') -plotter.plot_mc_vs_data('zmm', 'm1Pt') +plotter.plot_mc_vs_data('zmm', 'm1Pt', show_ratio=True) plotter.save('m1Pt') -plotter.plot_mc_vs_data('zmm', 'm1Pt', 5) +plotter.plot_mc_vs_data('zmm', 'm1Pt', 5, show_ratio=True) plotter.save('m1Pt_rebin') -plotter.plot_mc_vs_data('zmm', 'm2Pt') +plotter.plot_mc_vs_data('zmm', 'm2Pt', show_ratio=True) plotter.save('m2Pt') -plotter.plot_mc_vs_data('zmm', 'm2Pt', 5) +plotter.plot_mc_vs_data('zmm', 'm2Pt', 5, show_ratio=True) plotter.save('m2Pt_rebin') -plotter.plot_mc_vs_data('zmm', 'm1AbsEta') +plotter.plot_mc_vs_data('zmm', 'm1AbsEta', show_ratio=True) plotter.save('m1AbsEta') -plotter.plot_mc_vs_data('zmm', 'm2AbsEta') +plotter.plot_mc_vs_data('zmm', 'm2AbsEta', show_ratio=True) plotter.save('m2AbsEta') -plotter.plot_mc_vs_data('zmm', 'm1AbsEta', 5) +plotter.plot_mc_vs_data('zmm', 'm1AbsEta', 5, show_ratio=True) plotter.save('m1AbsEta_rebin') -plotter.plot_mc_vs_data('zmm', 'm2AbsEta', 5) +plotter.plot_mc_vs_data('zmm', 'm2AbsEta', 5, show_ratio=True) plotter.save('m2AbsEta_rebin') -plotter.plot_mc_vs_data('zmm', 'nvtx') +plotter.plot_mc_vs_data('zmm', 'nvtx', show_ratio=True) plotter.save('nvtx') From b982c7e22d1aec89aba9fa1732a7e788c2781a97 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 27 Sep 2013 07:49:01 -0500 Subject: [PATCH 057/192] added trigger scale factors --- wh/WHAnalyzeEET.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wh/WHAnalyzeEET.py b/wh/WHAnalyzeEET.py index b59c31ba..76d51c15 100755 --- a/wh/WHAnalyzeEET.py +++ b/wh/WHAnalyzeEET.py @@ -348,8 +348,8 @@ def event_weight(self, row): if row.run > 2: return 1. return self.pucorrector(row.nTruePU) * \ - mcCorrectors.get_electron_corrections(row,'e1','e2') - + mcCorrectors.get_electron_corrections(row,'e1','e2') *\ + mcCorrectors.double_electron_trigger(row) def obj1_weight(self, row, leadleptonId='eid13Looseh2taucuts', subleadleptonId=None): return frfits.highpt_ee_fr[leadleptonId](electronJetPt=max(row.e1JetPt, row.e1Pt), electronPt=row.e1Pt, numJets20=row.jetVeto20+1) From a6a8761162c94a307e773d8b67fa4394d03df870 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 27 Sep 2013 07:50:15 -0500 Subject: [PATCH 058/192] many changes, sorry for not having split it before --- wh/WHPlotterBase.py | 57 ++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/wh/WHPlotterBase.py b/wh/WHPlotterBase.py index ec169975..7b7b7803 100644 --- a/wh/WHPlotterBase.py +++ b/wh/WHPlotterBase.py @@ -41,6 +41,8 @@ parser.add_option('--prefixes', metavar='label', type=str, dest='prefixes', default = '', help='prefix to eppend before histogram name o be used to make the shapes' ) +project_x = lambda x: ProjectionView(x, 'X', [0, 650]) + def get_chi_square(hdata, hexp): chi2 = 0. nbins = 0. @@ -250,14 +252,14 @@ def __init__(self, channel, obj1_charge_mapper={}, obj2_charge_mapper={}): super(WHPlotterBase, self).__init__(files, lumifiles, self.outputdir, blinder) self.defaults = {} #allows to set some options and avoid repeating them each function call - self.mc_samples = filter(lambda x: x.startswith('data'), samples) + self.mc_samples = filter(lambda x: not x.startswith('data'), samples) #os.chdir( cwd ) #create a fake wiew summing up all HWW - self.views['VH_hww_sum'] = { - 'unweighted_view' : views.SumView( - *[item['unweighted_view'] for name, item in self.views.iteritems() if fnmatch(name, 'VH_*_HWW*')] - ) - } + #self.views['VH_hww_sum'] = { + # 'unweighted_view' : views.SumView( + # *[item['unweighted_view'] for name, item in self.views.iteritems() if fnmatch(name, 'VH_*_HWW*')] + # ) + #} def set_subdir(self, folder): self.outputdir = '/'.join([self.base_out_dir, folder]) @@ -306,8 +308,8 @@ def preprocess(view): ) all_data_view = self.get_view('data') - if unblinded: - all_data_view = self.get_view('data', 'unblinded_view') + #if unblinded: + # all_data_view = self.get_view('data', 'unblinded_view') all_data_view = preprocess(all_data_view) data_view = views.SubdirectoryView(all_data_view, 'ss/p1p2p3/') @@ -779,7 +781,7 @@ def write_f3_shapes(self, variable, rebin, outdir, def plot_final(self, variable, rebin=1, xaxis='', maxy=24, show_error=False, qcd_correction=False, stack_higgs=True, qcd_weight_fraction=0.5, x_range=None, show_charge_fakes=False, - leftside_legend=False, higgs_xsec_multiplier=5, project=None, + leftside_legend=False, higgs_xsec_multiplier=1, project=None, project_axis=None, differential=False, yaxis='Events', **kwargs): ''' Plot the final output - with bkg. estimation ''' show_charge_fakes = show_charge_fakes if 'show_charge_fakes' not in self.defaults else self.defaults['show_charge_fakes'] @@ -828,7 +830,10 @@ def plot_final(self, variable, rebin=1, xaxis='', maxy=24, self.keep.append(histo) # Add legend - legend = self.add_legend(histo, leftside=leftside_legend, entries=4) + entries = len(tostack)+1 + if show_error: + entries += 1 + legend = self.add_legend(histo, leftside=leftside_legend, entries=entries) if show_error: correct_qcd_view = None @@ -857,7 +862,7 @@ def plot_final(self, variable, rebin=1, xaxis='', maxy=24, legend.AddEntry(bkg_error) # Use poisson error bars on the data - sig_view['data'] = PoissonView(sig_view['data'], x_err=False) + sig_view['data'] = sig_view['data'] #PoissonView(, x_err=False) data = sig_view['data'].Get(variable) if not self.blind: @@ -902,7 +907,7 @@ def plot_final_f3(self, variable, rebin=1, xaxis='', maxy=None, show_chi2=False,project=None, project_axis=None, differential=False, yaxis='Events', **kwargs): ''' Plot the final F3 control region - with bkg. estimation ''' - + show_chi2 = False #broken sig_view = self.make_obj3_fail_cr_views( qcd_correction, qcd_weight_fraction) if project and project_axis: @@ -932,10 +937,10 @@ def plot_final_f3(self, variable, rebin=1, xaxis='', maxy=None, # Add legend legend = self.add_legend(histo, leftside=False, entries=4) - latex = ROOT.TLatex(0.01, 0.9, "") - pad = ROOT.TPad('da','fuq',0.1,0.8,0.5,0.9) - self.canvas.cd() - latexit = '' + #latex = ROOT.TLatex(0.01, 0.9, "") + #pad = ROOT.TPad('da','fuq',0.1,0.8,0.5,0.9) + #self.canvas.cd() + #latexit = '' if show_error: correct_qcd_view = None if qcd_weight_fraction == 0: @@ -961,9 +966,9 @@ def plot_final_f3(self, variable, rebin=1, xaxis='', maxy=None, self.keep.append(bkg_error) bkg_error.Draw('pe2,same') legend.AddEntry(bkg_error) - if show_chi2: - chival = get_chi_square(data, bkg_error) - latexit = '#chi^{2}/#bins = %.2f / %i' % chival + #if show_chi2: + # chival = get_chi_square(data, bkg_error) + # latexit = '#chi^{2}/#bins = %.2f / %i' % chival data.Draw('same') if isinstance(maxy, (int, long, float)): @@ -974,13 +979,13 @@ def plot_final_f3(self, variable, rebin=1, xaxis='', maxy=None, histo.SetMaximum(2 * max(data.GetMaximum(), histo.GetMaximum())) self.keep.append(data) self.keep.append(histo) - if latexit: - pad.cd() - latex.DrawLatex(0.01, 0.01, latexit) - self.canvas.cd() - pad.Draw() - self.keep.append(latex) - self.keep.append(pad) + #if latexit: + # pad.cd() + # latex.DrawLatex(0.01, 0.01, latexit) + # self.canvas.cd() + # pad.Draw() + #self.keep.append(latex) + #self.keep.append(pad) #legend.AddEntry(data) legend.Draw() From 841df19190185e026d0d8f4bd427d49ea4a953ee Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 27 Sep 2013 07:51:30 -0500 Subject: [PATCH 059/192] more plots, new shape file with 4 categories (2 f3 ones) --- wh/WHPlotterEET.py | 44 ++++++++++++++++++++++++++-- wh/WHPlotterEMT.py | 48 ++++++++++++++++++++++++++----- wh/WHPlotterMMT.py | 71 +++++++++++++++++++++++++++++++++++++--------- 3 files changed, 141 insertions(+), 22 deletions(-) diff --git a/wh/WHPlotterEET.py b/wh/WHPlotterEET.py index da96c548..708231d3 100755 --- a/wh/WHPlotterEET.py +++ b/wh/WHPlotterEET.py @@ -12,7 +12,7 @@ import ROOT import sys import WHPlotterBase -from WHPlotterBase import make_styler, remove_name_entry, parser +from WHPlotterBase import make_styler, remove_name_entry, parser, project_x import rootpy.plotting.views as views from FinalStateAnalysis.MetaData.data_styles import data_styles, colors #from pudb import set_trace; set_trace() @@ -117,7 +117,8 @@ def __init__(self): ## ## FR sideband MC-vs-Data ################################################ ## ########################################################################### - plotter.plot_mc_vs_data('ss/p1f2p3', 'e2_t_Mass', rebin=10, xaxis='m_{e2#tau} (GeV)', leftside=False) + plotter.plot_mc_vs_data('ss/p1f2p3', 'e2_t_Mass#LT', rebin=10, xaxis='m_{e2#tau} (GeV)', + leftside=False, preprocess=project_x) plotter.add_cms_blurb(sqrts) plotter.save('mcdata-ss-p1f2p3-subMass') @@ -125,6 +126,11 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('mcdata-ss-p1f2p3-LT') + plotter.plot_mc_vs_data('ss/f1p2p3', 'e2_t_Mass#LT', rebin=10, xaxis='m_{e2#tau} (GeV)', + leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-ss-f1p2p3-subMass') + ########################################################################### ## Signal region plots ################################################ ########################################################################### @@ -492,3 +498,37 @@ def __init__(self): logging.warning('shape file %s created' % shape_file.GetName()) shape_file.Close() + + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, '%seet_f3_all_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') + + shape_dir = shape_file.mkdir('eetCatLow') + plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('eetCatLow_w') + plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('eetCatLow_q') + plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + + shape_dir = shape_file.mkdir('eetCatHigh') + plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('eetCatHigh_w') + plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('eetCatHigh_q') + plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + + shape_dir = shape_file.mkdir('eetCatLowf3') + plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('eetCatLowf3_w') + plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('eetCatLowf3_q') + plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + + shape_dir = shape_file.mkdir('eetCatHighf3') + plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('eetCatHighf3_w') + plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('eetCatHighf3_q') + plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() diff --git a/wh/WHPlotterEMT.py b/wh/WHPlotterEMT.py index b33643d4..540499f3 100644 --- a/wh/WHPlotterEMT.py +++ b/wh/WHPlotterEMT.py @@ -12,7 +12,7 @@ import ROOT import sys import WHPlotterBase -from WHPlotterBase import make_styler, parser +from WHPlotterBase import make_styler, parser, project_x import rootpy.plotting.views as views from FinalStateAnalysis.MetaData.data_styles import data_styles, colors @@ -108,15 +108,15 @@ def __init__(self): #plotter.plot_mc_vs_data('ss/p1f2p3', 'mPt', 5, '#mu_{1} p_{T}', leftside=False) #plotter.save('mcdata-ss-p1f2p3-mPt') - #plotter.plot_mc_vs_data('ss/p1f2p3', 'subMass', 20, 'Subleading mass (GeV)', leftside=False) - #plotter.save('mcdata-ss-p1f2p3-subMass') - # + plotter.plot_mc_vs_data('ss/p1f2p3', 'subMass#LT', 20, 'Subleading mass (GeV)', leftside=False, preprocess=project_x) + plotter.save('mcdata-ss-p1f2p3-subMass') + #plotter.plot_mc_vs_data('ss/p1p2f3', 'subMass', 20, 'Subleading mass (GeV)', leftside=False) #plotter.save('mcdata-ss-p1p2f3-subMass') # - #plotter.plot_mc_vs_data('ss/f1p2p3', 'subMass', 20, 'Subleading mass (GeV)', leftside=False) - #plotter.save('mcdata-ss-f1p2p3-subMass') - # + plotter.plot_mc_vs_data('ss/f1p2p3', 'subMass#LT', 20, 'Subleading mass (GeV)', leftside=False, preprocess=project_x) + plotter.save('mcdata-ss-f1p2p3-subMass') + #plotter.plot_mc_vs_data('ss/p1f2p3/w2', 'mPt', 5, '#mu_{1} p_{T}', leftside=False) #plotter.save('mcdata-ss-p1f2p3-w2-mPt') # @@ -532,3 +532,37 @@ def __init__(self): logging.warning('shape file %s created' % shape_file.GetName()) shape_file.Close() + + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, '%semt_f3_all_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') + + shape_dir = shape_file.mkdir('emtCatLow') + plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('emtCatLow_w') + plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('emtCatLow_q') + plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + + shape_dir = shape_file.mkdir('emtCatHigh') + plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('emtCatHigh_w') + plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('emtCatHigh_q') + plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + + shape_dir = shape_file.mkdir('emtCatLowf3') + plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('emtCatLowf3_w') + plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('emtCatLowf3_q') + plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + + shape_dir = shape_file.mkdir('emtCatHighf3') + plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('emtCatHighf3_w') + plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('emtCatHighf3_q') + plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() diff --git a/wh/WHPlotterMMT.py b/wh/WHPlotterMMT.py index 1932c1e8..e9f58ea1 100644 --- a/wh/WHPlotterMMT.py +++ b/wh/WHPlotterMMT.py @@ -12,7 +12,7 @@ import ROOT import sys import WHPlotterBase -from WHPlotterBase import make_styler, parser +from WHPlotterBase import make_styler, parser, project_x import rootpy.plotting.views as views from FinalStateAnalysis.MetaData.data_styles import data_styles, colors @@ -30,6 +30,7 @@ def __init__(self): } + if __name__ == "__main__": plotter = WHPlotterMMT() sqrts = plotter.sqrts @@ -148,18 +149,27 @@ def __init__(self): #plotter.add_cms_blurb(sqrts) #plotter.save('mcdata-ss-p1f2p3-m1Pt') - #plotter.plot_mc_vs_data('ss/p1f2p3', 'm2_t_Mass', rebin=10, xaxis='m_{#mu2#tau} (GeV)', leftside=False) - #plotter.add_cms_blurb(sqrts) - #plotter.save('mcdata-ss-p1f2p3-subMass') - # - #plotter.plot_mc_vs_data('ss/p1f2p3/w2', 'm1Pt', rebin=10, xaxis='#mu_{1} p_{T}', leftside=False) - #plotter.add_cms_blurb(sqrts) - #plotter.save('mcdata-ss-p1f2p3-w2-m1Pt') - # - #plotter.plot_mc_vs_data('ss/f1p2p3', 'm2_t_Mass', rebin=20, xaxis='m_{#mu2#tau} (GeV)', leftside=False) - #plotter.add_cms_blurb(sqrts) - #plotter.save('mcdata-ss-f1p2p3-subMass') + plotter.plot_mc_vs_data('ss/p1f2p3', 'm2_t_Mass#LT', rebin=10, xaxis='m_{#mu2#tau} (GeV)', + leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-ss-p1f2p3-subMass') + + plotter.plot_mc_vs_data('os/p1p2f3', 'nvtx') + plotter.save('mcdata-os-p1p2f3-nvtx') + + plotter.plot_mc_vs_data('os/p1p2f3', 'm1_m2_Mass', rebin=10) + plotter.save('mcdata-os-p1p2f3-m1_m2_Mass') + + plotter.plot_mc_vs_data('os/p1p2f3', 'm2_t_Mass#LT', rebin=10, xaxis='m_{#mu1#mu2} (GeV)', + leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-os-p1p2f3-m1m2Mass') # + plotter.plot_mc_vs_data('ss/f1p2p3', 'm2_t_Mass#LT', rebin=20, xaxis='m_{#mu2#tau} (GeV)', + leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-ss-f1p2p3-subMass') + #plotter.plot_mc_vs_data('ss/f1p2p3/w1', 'm2_t_Mass', rebin=20, xaxis='m_{#mu2#tau} (GeV)', leftside=False) #plotter.add_cms_blurb(sqrts) #plotter.save('mcdata-ss-f1p2p3-w1-subMass') @@ -182,7 +192,8 @@ def __init__(self): for label, proj_range in categories.iteritems(): plotter.set_subdir('%s' % label) plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', differential=True, yaxis='Events / GeV') + project=proj_range, project_axis='X', differential=True, + yaxis='Events / GeV', show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-%s' % label) @@ -589,5 +600,39 @@ def __init__(self): logging.warning('shape file %s created' % shape_file.GetName()) shape_file.Close() + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, '%smmt_f3_all_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') + + shape_dir = shape_file.mkdir('mmtCatLow') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatLow_w') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatLow_q') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + + shape_dir = shape_file.mkdir('mmtCatHigh') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatHigh_w') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatHigh_q') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + + shape_dir = shape_file.mkdir('mmtCatLowf3') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatLowf3_w') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatLowf3_q') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + + shape_dir = shape_file.mkdir('mmtCatHighf3') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatHighf3_w') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatHighf3_q') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() + From e8b4b1d70ebf1aab4ab84b608bcdfd3c3028b2b5 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 27 Sep 2013 07:55:30 -0500 Subject: [PATCH 060/192] updated scale factors --- wh/mcCorrectors.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/wh/mcCorrectors.py b/wh/mcCorrectors.py index 9f29d16b..13fde937 100644 --- a/wh/mcCorrectors.py +++ b/wh/mcCorrectors.py @@ -31,12 +31,15 @@ muon_pog_Mu17Mu8_2011 = MuonPOGCorrections.muon_pog_Mu17Mu8_eta_eta_2011 muon_pog_Mu17Mu8_Mu17_2012 = MuonPOGCorrections.make_muon_pog_Mu17Mu8_Mu17_2012() muon_pog_Mu17Mu8_Mu8_2012 = MuonPOGCorrections.make_muon_pog_Mu17Mu8_Mu8_2012() +muon_h2tau_Mu17Mu8_2012 = H2TauCorrections.correct_double_muon_trg_2012 + #Scale factors for mueg triggers, that's better correct_mueg_mu = H2TauCorrections.correct_mueg_mu_2011 if is7TeV else H2TauCorrections.correct_mu_idiso_2012 correct_mueg_e = H2TauCorrections.correct_mueg_e_2011 if is7TeV else H2TauCorrections.correct_mueg_e_2012 -#Double electrons does NOT need scale factors +#Double electrons scale factors +correct_double_electron = H2TauCorrections.correct_double_electron_trg_2011 if is7TeV else H2TauCorrections.correct_double_electron_trg_2012 def make_puCorrector(dataset, kind=None): 'makes PU reweighting according to the pu distribution of the reference data and the MC, MC distribution can be forced' @@ -74,7 +77,7 @@ def double_muon_trigger(row,m1,m2): if is7TeV: return muon_pog_Mu17Mu8_2011(getattr(row, '%sEta' % m1), getattr(row, '%sEta' % m2) ) else: - f1 = muon_pog_Mu17Mu8_Mu17_2012(getattr(row, '%sPt' % m1), getattr(row, '%sEta' % m1)) - f2 = muon_pog_Mu17Mu8_Mu8_2012(getattr(row, '%sPt' % m2), getattr(row, '%sEta' % m2)) - return f1*f2 + return muon_h2tau_Mu17Mu8_2012(getattr(row, '%sPt' % m1), getattr(row, '%sEta' % m1), getattr(row, '%sPt' % m2), getattr(row, '%sEta' % m2)) +def double_electron_trigger(row): + return correct_double_electron( row.e1Pt, row.e1Eta, row.e2Pt, row.e2Eta ) From f900cc15db1f742098c54cded3e9790dda26b184 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Tue, 1 Oct 2013 07:39:08 -0500 Subject: [PATCH 061/192] changed dirs --- wh/Rakefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wh/Rakefile b/wh/Rakefile index 8cb8425d..17e9dbd8 100755 --- a/wh/Rakefile +++ b/wh/Rakefile @@ -836,6 +836,7 @@ def make_f3_postfit_plots_task(channel) end sh "cp -v #{carddir}/#{channel}/#{channel}.pulls* #{resultdir}/." sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{$categories_map[channel].join(' ')} -e 'WH*' -o #{resultdir}/#{channel}_categories_summed.png -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV' --show-errors" + sh "shapes2hist.py #{resultdir}/#{channel}_f3_postfit_shapes.root #{$categories_map[channel].join(' ')} -e 'WH*' -o #{resultdir}/#{channel}_categories_summed.pdf -x #{$xlabels_map[channel]} -d 1 -y 'Events / GeV' --show-errors" sh "touch #{t.name}" end return plot_timestamp @@ -846,8 +847,8 @@ task :f3_postfit_plots_emt => make_f3_postfit_plots_task('emt') task :f3_postfit_plots_eet => make_f3_postfit_plots_task('eet') #task :f3_postfit_plots_llt => make_f3_postfit_plots_task('llt') task :f3_postfit_plots => Array[:f3_postfit_plots_mmt, - :f3_postfit_plots_emt, - :f3_postfit_plots_eet] + :f3_postfit_plots_emt, + :f3_postfit_plots_eet] @@ -1063,7 +1064,7 @@ end #### Copying card configuration to official place ############################### ################################################################################# $httcombodir = "#{ENV['CMSSW_BASE']}/src/HiggsAnalysis/HiggsToTauTau/setup/vhtt/" -$auxdir = "#{ENV['CMSSW_BASE']}/src/auxiliaries/datacards/collected/vhtt/" +$auxdir = "#{ENV['CMSSW_BASE']}/src/auxiliaries/shapes/VHTT/" def copy_and_trim_file(source, target) file target => [source] do |t| From e43353ddb2b660c45875b0154928fb3b5390ecd9 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Tue, 1 Oct 2013 07:39:38 -0500 Subject: [PATCH 062/192] small cosmetics, no real change --- wh/WHAnalyzeMMT.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/wh/WHAnalyzeMMT.py b/wh/WHAnalyzeMMT.py index e349b742..c8217c20 100755 --- a/wh/WHAnalyzeMMT.py +++ b/wh/WHAnalyzeMMT.py @@ -100,7 +100,7 @@ def book_histos(self, folder): if len(self.grid_search.keys()) == 1: self.book(folder, "m2_t_Mass#LT" , "subleadingMass", 300, 0, 300, nLTBins, LTBinning, type=ROOT.TH2F) - + self.book(folder, "Event_ID", "Event ID", 'run:lumi:evt1:evt2', type=ROOT.TNtuple) #Pt self.book(folder, "m1Pt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) self.book(folder, "tPt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) @@ -165,6 +165,7 @@ def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = Excludes FR object IDs and sign cut. ''' + double_mu_pass = row.doubleMuPass and \ row.m1MatchesDoubleMuPaths > 0 and \ row.m2MatchesDoubleMuPaths > 0 @@ -202,7 +203,7 @@ def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = cut_flow_trk.Fill('vetos') #cut_flow_trk.Fill('ChargeIdTight') cut_flow_trk.Fill('charge_fakes') #no charge fakes here - + #FIXME: ONLY FOR CUT-FLOW PRODUCTION #if not row.m1PFIDTight: return False #cut_flow_trk.Fill('obj1 ID') @@ -232,10 +233,12 @@ def obj2_id(row, leadleptonId=None, subleadleptonId='h2taucuts'): @staticmethod def obj3_id(row, tauId=None, LT_threshold = 80., taupt_thr = 0.): + retval = False if row.LT >= LT_threshold and row.tPt >= taupt_thr: - return bool(row.tLooseIso3Hits) + retval = bool(row.tLooseIso3Hits) else: - return bool( getattr(row, tauId) ) + retval = bool( getattr(row, tauId) ) + return retval @staticmethod def anti_wz(row): From 538dc5e3f4c54bc74890dd1aaf3ffb83ed7106f8 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Tue, 1 Oct 2013 07:40:27 -0500 Subject: [PATCH 063/192] added debugging (commented) --- wh/WHAnalyzerBase.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/wh/WHAnalyzerBase.py b/wh/WHAnalyzerBase.py index d176cb88..36b9d966 100644 --- a/wh/WHAnalyzerBase.py +++ b/wh/WHAnalyzerBase.py @@ -58,6 +58,7 @@ import ROOT import math import itertools +import array from FinalStateAnalysis.PlotTools.decorators import memo from FinalStateAnalysis.Utilities.struct import struct @@ -365,6 +366,9 @@ def process(self): if row.processID != 26: continue + #if row.lumi == 2348 and row.evt == 704038: + # print 'preselection', preselection(row, cut_flow_trk, cut_settings['LT'] if lt_tpt_in_presel else 0., cut_settings['tauPT'] if lt_tpt_in_presel else 0.) + cut_flow_trk.Fill('WH Event') lt_tpt_in_presel = not bool(cut_settings['tauID']) if not preselection(row, cut_flow_trk, cut_settings['LT'] if lt_tpt_in_presel else 0., cut_settings['tauPT'] if lt_tpt_in_presel else 0.): @@ -384,6 +388,14 @@ def process(self): to_fill = ('',) \ if not anti_charge_flip_cut else \ ('','charge_flip_CR/') if anti_charge_flip else ('charge_flip_CR/',) + + #if row.lumi == 2348 and row.evt == 704038: + # print 'sign_result ', sign_result + # print 'obj1_id_result', obj1_id_result + # print 'obj2_id_result', obj2_id_result + # print 'obj3_id_result', obj3_id_result + # print 'anti_wz ', anti_wz + # #from pdb import set_trace; set_trace() #if not cut_flow_trk.disabled: if obj1_id_result: @@ -407,6 +419,9 @@ def process(self): if anti_wz: base_folder, weights = region_result + #if base_folder == ('ss', 'p1p2f3'): + # print row.run, row.lumi, row.evt + base_folder = joinDirs(*base_folder) # Fill the un-fr-weighted histograms for i in to_fill: From 61c71381855d52c02aec2956e90f11f6ae16f685 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Tue, 1 Oct 2013 07:41:17 -0500 Subject: [PATCH 064/192] even more plots --- wh/WHPlotterMMT.py | 67 +++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/wh/WHPlotterMMT.py b/wh/WHPlotterMMT.py index e9f58ea1..dfc7962b 100644 --- a/wh/WHPlotterMMT.py +++ b/wh/WHPlotterMMT.py @@ -197,74 +197,105 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-%s' % label) - plotter.plot_final('m2_t_Mass#LT', 300, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', + project=proj_range, project_axis='X', + yaxis='Events', show_error=True, x_range=[0,199], maxy=15.6) plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) + plotter.save('final-subMass-const_bin-%s' % label, verbose=True) + + data_view = plotter.make_signal_views(unblinded=(not plotter.blind), + qcd_weight_fraction=0.5, + rebin=20, project=proj_range, project_axis='X')['data'] + data_hist = data_view.Get('m2_t_Mass#LT') + data_hist.GetXaxis().SetRangeUser(0,200) + data_hist.GetXaxis().SetRangeUser(0,15.6) + data_hist.SetMarkerColor(2) + data_hist.Draw() + plotter.add_cms_blurb(sqrts) + plotter.save('bareData-subMass-const_bin-%s' % label) + + plotter.plot_final('m2_t_Mass#LT', 300, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', show_error=True) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s-counting' % label) #, dotc=True, dotroot=True) #pt - plotter.plot_final("m1Pt#LT" , 10, xaxis='p_{T#mu_{1}} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("m1Pt#LT" , 10, xaxis='p_{T#mu_{1}} (GeV)', + maxy=None, project=proj_range, project_axis='X', show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-m1Pt-%s' % label) - plotter.plot_final("m2Pt#LT" , 10, xaxis='p_{T#mu_{2}} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("m2Pt#LT" , 10, xaxis='p_{T#mu_{2}} (GeV)', maxy=None, + project=proj_range, project_axis='X', show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-m2Pt-%s' % label) - plotter.plot_final("m1JetPt#LT" , 10, xaxis='p_{T Jet #mu_{1}} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("m1JetPt#LT" , 10, xaxis='p_{T Jet #mu_{1}} (GeV)', maxy=None, + project=proj_range, project_axis='X', show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-m1JetPt-%s' % label) - plotter.plot_final("m2JetPt#LT" , 10, xaxis='p_{T Jet #mu_{2}} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("m2JetPt#LT" , 10, xaxis='p_{T Jet #mu_{2}} (GeV)', maxy=None, + project=proj_range, project_axis='X', show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-m2JetPt-%s' % label) - plotter.plot_final("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-tPt-%s' % label) #eta - plotter.plot_final("m1AbsEta#LT", 10, xaxis='|#eta_{#mu_{1}}|', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("m1AbsEta#LT", 10, xaxis='|#eta_{#mu_{1}}|', maxy=None, + project=proj_range, project_axis='X', show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-m1AbsEta-%s' % label) - plotter.plot_final("m2AbsEta#LT", 10, xaxis='|#eta_{#mu_{2}}|' , maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("m2AbsEta#LT", 10, xaxis='|#eta_{#mu_{2}}|' , maxy=None, + project=proj_range, project_axis='X', show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-m2AbsEta-%s' % label) - plotter.plot_final("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, + project=proj_range, project_axis='X', show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-tAbsEta-%s' % label) #DR - plotter.plot_final("m1_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{1}#tau}', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("m1_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{1}#tau}', maxy=None, + project=proj_range, project_axis='X', show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-m1_t_DR-%s' % label) - plotter.plot_final("m2_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("m2_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, + project=proj_range, project_axis='X', show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-m2_t_DR-%s' % label) #Jet BTag #from pdb import set_trace; set_trace() - plotter.plot_final("m2JetBtag#LT", [-100, -40, 20, 100], xaxis='#mu_{2} Jet Btag' , maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("m2JetBtag#LT", [-100, -40, 20, 100], xaxis='#mu_{2} Jet Btag' , + maxy=None, project=proj_range, project_axis='X', show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-m2JetBtag-%s' % label, dotroot=True) - plotter.plot_final("m1JetBtag#LT", 1, xaxis='#mu_{1} Jet Btag' , maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("m1JetBtag#LT", 1, xaxis='#mu_{1} Jet Btag' , maxy=None, + project=proj_range, project_axis='X', show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-m1JetBtag-%s' % label) - plotter.plot_final("m2JetCSVBtag#LT", 1, xaxis='#mu_{2} Jet CSV Btag' , maxy=None, project=proj_range, project_axis='X', x_range=[0,1]) + plotter.plot_final("m2JetCSVBtag#LT", 1, xaxis='#mu_{2} Jet CSV Btag' , maxy=None, + project=proj_range, project_axis='X', x_range=[0,1], show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-m2JetCSVBtag-%s' % label, dotroot=True) - plotter.plot_final("m1JetCSVBtag#LT", 1, xaxis='#mu_{1} Jet CSV Btag' , maxy=None, project=proj_range, project_axis='X', x_range=[0,1]) + plotter.plot_final("m1JetCSVBtag#LT", 1, xaxis='#mu_{1} Jet CSV Btag' , maxy=None, + project=proj_range, project_axis='X', x_range=[0,1], show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-m1JetCSVBtag-%s' % label) - - + raise ValueError #from pdb import set_trace; set_trace() plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=[0, 130], project_axis='X', differential=True, yaxis='Events / GeV') From 91e24c8eba68395f2ec38496dc2363a10f85634e Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 4 Oct 2013 10:42:23 -0500 Subject: [PATCH 065/192] removed bjet veto --- wh/ControlEM.py | 6 +++++- wh/ControlZEE.py | 14 +++++++++----- wh/ControlZMM.py | 3 +++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/wh/ControlEM.py b/wh/ControlEM.py index 893bac98..48d734c6 100644 --- a/wh/ControlEM.py +++ b/wh/ControlEM.py @@ -139,7 +139,11 @@ def preselection(self, row): if not (mu17e8 or mu8e17): return False if not selections.muSelection(row, 'm'): return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag) if not selections.eSelection(row, 'e'): return False #applies basic selection (eta, pt > 10, DZ, missingHits, jetBTag, HasConversion and chargedIdTight) - if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes + #if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes + if row.muVetoPt5IsoIdVtx: return False + if row.eVetoMVAIsoVtx: return False + if row.tauVetoPt20Loose3HitsVtx: return False + return True def obj1_id(self, row): diff --git a/wh/ControlZEE.py b/wh/ControlZEE.py index 822291db..3a60b228 100644 --- a/wh/ControlZEE.py +++ b/wh/ControlZEE.py @@ -19,8 +19,8 @@ from functools import wraps math = ROOT.TMath -leading_iso = 'eid12Medium_h2taucuts' #optimizer.grid_search['EET']['leading_iso'] -subleading_iso = 'eid12Medium_h2taucuts' #optimizer.grid_search['EET']['subleading_iso'] +leading_iso = optimizer.grid_search['EET']['leading_iso'] +subleading_iso = optimizer.grid_search['EET']['subleading_iso'] def sc_inv_mass(row): @@ -135,7 +135,10 @@ def preselection(self, row): if row.e1Pt < 20: return False if not selections.eSelection(row, 'e1'): return False if not selections.eSelection(row, 'e2'): return False - if not selections.vetos(row): return False + if row.muVetoPt5IsoIdVtx: return False + if row.eVetoMVAIsoVtx: return False + if row.tauVetoPt20Loose3HitsVtx: return False + #if not selections.vetos(row): return False if row.e1_e2_Mass < 40: return False if not (row.jetVeto40 >= 1): return False return True @@ -151,9 +154,10 @@ def mc_weight(self, row): return 1. else: return self.pucorrector(row.nTruePU) * \ - mcCorrectors.get_electron_corrections(row,'e1','e2') *\ + mcCorrectors.get_electron_corrections(row,'e2') *\ + mcCorrectors.electron_tight_corrections(row.e1Pt, row.e1AbsEta) *\ mcCorrectors.double_electron_trigger(row) - + #'e1', def process(self): histos = self.dir_based_histograms diff --git a/wh/ControlZMM.py b/wh/ControlZMM.py index b7afea45..d2d9b706 100644 --- a/wh/ControlZMM.py +++ b/wh/ControlZMM.py @@ -112,6 +112,9 @@ def preselection(self, row): if row.m1_m2_Mass > 120: return False if not selections.muSelection(row, 'm1'): return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag) if not selections.muSelection(row, 'm2'): return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag) + if row.muVetoPt5IsoIdVtx: return False + if row.eVetoMVAIsoVtx: return False + if row.tauVetoPt20Loose3HitsVtx: return False return True def obj1_id(self, row): From 841692a6a9ca65ce9dde108e773b799bc498d8ca Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 4 Oct 2013 10:43:10 -0500 Subject: [PATCH 066/192] refactor the code. Make ZEE control plots with fake estimation from data --- wh/PlotControlZEE.py | 209 ++++++++++++++++++++++++++++++++----------- 1 file changed, 159 insertions(+), 50 deletions(-) diff --git a/wh/PlotControlZEE.py b/wh/PlotControlZEE.py index b9c5fc59..f11d989e 100644 --- a/wh/PlotControlZEE.py +++ b/wh/PlotControlZEE.py @@ -41,6 +41,18 @@ def __init__(self): super(ControlZEEPlotter, self).__init__(files, lumifiles, self.output_dir) self.mc_samples = filter(lambda x: 'data' not in x, samples) + def make_fakes_view(self, data_view, sign, weight_type): + # View of weighted obj1-fails data + obj1_view = views.SubdirectoryView(data_view, '%s/f1p2/%s' % (sign, weight_type)) + # View of weighted obj2-fails data + obj2_view = views.SubdirectoryView(data_view, '%s/p1f2/%s' % (sign, weight_type)) + # View of weighted obj1&2-fails data + obj12_view = views.SubdirectoryView(data_view, '%s/f1f2/%s' % (sign, weight_type)) + # Give the individual object views nice colors + subtract_obj12_view = views.ScaleView(obj12_view, -1) + return obj1_view, obj2_view, subtract_obj12_view + + def get_flip_data(self, rebin=1, xaxis='', data_type='data'): data_view = self.get_view(data_type) data_view = self.rebin_view(data_view, rebin) if rebin != 1 else data_view @@ -48,24 +60,24 @@ def get_flip_data(self, rebin=1, xaxis='', data_type='data'): ss_p1p2_view = views.SubdirectoryView( data_view, 'ss/p1p2') ss_p1p2_view = views.TitleView( views.StyleView(ss_p1p2_view, **data_styles['data*']), 'observed;%s' % xaxis) - def make_fakes_view(sign, weight_type): - # View of weighted obj1-fails data - obj1_view = views.SubdirectoryView(data_view, '%s/f1p2/%s' % (sign, weight_type)) - # View of weighted obj2-fails data - obj2_view = views.SubdirectoryView(data_view, '%s/p1f2/%s' % (sign, weight_type)) - # View of weighted obj1&2-fails data - obj12_view = views.SubdirectoryView(data_view, '%s/f1f2/%s' % (sign, weight_type)) - # Give the individual object views nice colors - subtract_obj12_view = views.ScaleView(obj12_view, -1) - return obj1_view, obj2_view, subtract_obj12_view + #def make_fakes_view(sign, weight_type): + # # View of weighted obj1-fails data + # obj1_view = views.SubdirectoryView(data_view, '%s/f1p2/%s' % (sign, weight_type)) + # # View of weighted obj2-fails data + # obj2_view = views.SubdirectoryView(data_view, '%s/p1f2/%s' % (sign, weight_type)) + # # View of weighted obj1&2-fails data + # obj12_view = views.SubdirectoryView(data_view, '%s/f1f2/%s' % (sign, weight_type)) + # # Give the individual object views nice colors + # subtract_obj12_view = views.ScaleView(obj12_view, -1) + # return obj1_view, obj2_view, subtract_obj12_view #Get fakes according to WJets or QCD - ss_f1p2_qcd_view, ss_p1f2_qcd_view, ss_f1f2_qcd_view = make_fakes_view('ss','qcd_w') - ss_f1p2_wje_view, ss_p1f2_wje_view, ss_f1f2_wje_view = make_fakes_view('ss','wjet_w') + ss_f1p2_qcd_view, ss_p1f2_qcd_view, ss_f1f2_qcd_view = self.make_fakes_view(data_view, 'ss','qcd_w') + ss_f1p2_wje_view, ss_p1f2_wje_view, ss_f1f2_wje_view = self.make_fakes_view(data_view, 'ss','wjet_w') - ss_fakes_1 = MedianView(ss_f1p2_qcd_view, ss_f1p2_wje_view) - ss_fakes_2 = MedianView(ss_p1f2_qcd_view, ss_p1f2_wje_view) - ss_fakes_12 = MedianView(ss_f1f2_qcd_view, ss_f1f2_wje_view) + ss_fakes_1 = MedianView(lowv=ss_f1p2_qcd_view, highv=ss_f1p2_wje_view) + ss_fakes_2 = MedianView(lowv=ss_p1f2_qcd_view, highv=ss_p1f2_wje_view) + ss_fakes_12 = MedianView(lowv=ss_f1f2_qcd_view, highv=ss_f1f2_wje_view) ss_fakes_est = views.SumView(ss_fakes_1, ss_fakes_2, ss_fakes_12) ss_fakes_est = views.TitleView( views.StyleView(ss_fakes_est, **data_styles['Zjets*']), 'Fakes;%s' % xaxis) @@ -113,11 +125,65 @@ def make_charge_flip_control_plot(self, variable, xaxis='', rebin=1, legend_on_t #legend.AddEntry(estimate_error,'f') legend.Draw() self.add_cms_blurb(self.sqrts) + + def plot_zee_control(self, variable, xaxis='', rebin=1, legend_on_the_left=False, + x_range=None, show_ratio=False, logscale=False): + data_view = self.get_view('data') + data_view = self.rebin_view(data_view, rebin) if rebin != 1 else data_view + mc_views = [self.get_view(i) for i in [ 'ZZ*', 'WZ*', 'WW*', 'TT*', 'Zjets_M50' ] ] + if rebin != 1: + mc_views = [self.rebin_view(i, rebin) for i in mc_views] + + zee_data = views.SubdirectoryView( data_view, 'os/p1p2/') + zee_mcs = [ views.SubdirectoryView( i, 'os/p1p2/') for i in mc_views] + + os_f1p2_qcd_view, os_p1f2_qcd_view, os_f1f2_qcd_view = self.make_fakes_view(data_view, 'os','qcd_w') + os_f1p2_wje_view, os_p1f2_wje_view, os_f1f2_wje_view = self.make_fakes_view(data_view, 'os','wjet_w') + os_fakes_1 = MedianView(lowv=os_f1p2_qcd_view, highv=os_f1p2_wje_view) + os_fakes_2 = MedianView(lowv=os_p1f2_qcd_view, highv=os_p1f2_wje_view) + os_fakes_12 = MedianView(lowv=os_f1f2_qcd_view, highv=os_f1f2_wje_view) + os_fakes_est = views.SumView(os_fakes_1, os_fakes_2, os_fakes_12) + os_fakes_est = views.TitleView( views.StyleView(os_fakes_est, **data_styles['WplusJets*']), 'Fakes;%s' % xaxis) + + zee_mcs = zee_mcs[:-1]+[os_fakes_est]+zee_mcs[-1:] + events_estimate = views.StackView( *zee_mcs) + estimate_hist = events_estimate.Get(variable) + obs_hist = zee_data.Get(variable) + hmax = max( [ estimate_hist.GetMaximum(), max(list(obs_hist)) ] ) + if logscale: + obs_hist.GetYaxis().SetRangeUser(10**-2,hmax*10**4) + self.pad.SetLogy(True) + else: + obs_hist.GetYaxis().SetRangeUser(0.,hmax*1.3) + + if x_range: + obs_hist.GetXaxis().SetRangeUser(x_range[0],x_range[1]) + + obs_hist.Draw() + estimate_hist.Draw('same') + obs_hist.Draw('same') + self.canvas.Update() + self.keep.extend([ + estimate_hist, + obs_hist + ]) + + legend = self.add_legend([obs_hist], leftside=legend_on_the_left, entries=len(zee_mcs)+1) + legend.AddEntry(estimate_hist,'f') + #legend.AddEntry(estimate_error,'f') + legend.Draw() + if show_ratio: + self.add_ratio_plot(obs_hist, estimate_hist, x_range, ratio_range=0.2) + self.add_cms_blurb(self.sqrts) plotter = ControlZEEPlotter() +########################################################################### +## CHARGE FLIP CONTROL PLOTS ######################################### +########################################################################### + #Charge flip control plots plotter.make_charge_flip_control_plot('TrkMass','Tracker Inv Mass (GeV)',2) plotter.save('EE_Charge_Flip_xcheck_trk_invMass') @@ -163,49 +229,92 @@ def make_charge_flip_control_plot(self, variable, xaxis='', rebin=1, legend_on_t plotter.make_charge_flip_control_plot('ePt','electron p_{T}',2,x_range=[0,200], data_type='Zjets_M50') plotter.save('EE_Charge_Flip_closure_ePt') +########################################################################### +## DATA/MC PLOTS ######################################### +########################################################################### + +#plotter.plot_mc_vs_data('os/p1p2/', 'TrkMass', rebin=2, xaxis='m_{#mu#mu} (GeV)', +# leftside=False, show_ratio=True) +#plotter.add_cms_blurb(plotter.sqrts) +#for obj in plotter.keep: +# if obj.ClassName().startswith('TH1F'): +# print obj.GetTitle(), obj.Integral() +# if obj.ClassName().startswith('THStack'): +# for histo in obj.GetHists(): +# print histo.GetTitle(), histo.Integral() # -# DATA/MC control plots +#plotter.save('mass') # +# +#plotter.plot_mc_vs_data('os/p1p2/', 'TrkMass', rebin=2, xaxis='m_{#mu#mu} (GeV)', +# leftside=False, show_ratio=True) +#plotter.add_cms_blurb(plotter.sqrts) +#plotter.pad.SetLogy(True) +#plotter.save('mass_log') +# +#plotter.plot_mc_vs_data('os/p1p2/', 'TrkMass', rebin=10, xaxis='m_{#mu#mu} (GeV)', +# leftside=False, show_ratio=True) +#plotter.add_cms_blurb(plotter.sqrts) +#plotter.save('mass_rebin') +# +#plotter.plot_mc_vs_data('os/p1p2/', 'e1Pt', leftside=False, show_ratio=True) +#plotter.save('e1Pt') +#plotter.plot_mc_vs_data('os/p1p2/', 'e1Pt', 5, leftside=False, show_ratio=True) +#plotter.save('e1Pt_rebin') +#plotter.plot_mc_vs_data('os/p1p2/', 'e2Pt', leftside=False, show_ratio=True) +#plotter.save('e2Pt') +#plotter.plot_mc_vs_data('os/p1p2/', 'e2Pt', 5, leftside=False, show_ratio=True) +#plotter.save('e2Pt_rebin') +# +#plotter.plot_mc_vs_data('os/p1p2/', 'e1AbsEta', leftside=False, show_ratio=True) +#plotter.save('e1AbsEta') +#plotter.plot_mc_vs_data('os/p1p2/', 'e2AbsEta', leftside=False, show_ratio=True) +#plotter.save('e2AbsEta') +# +#plotter.plot_mc_vs_data('os/p1p2/', 'e1AbsEta', 5, leftside=False, show_ratio=True) +#plotter.save('e1AbsEta_rebin') +#plotter.plot_mc_vs_data('os/p1p2/', 'e2AbsEta', 5, leftside=False, show_ratio=True) +#plotter.save('e2AbsEta_rebin') +# +# +#plotter.plot_mc_vs_data('os/p1p2/', "trig_weight" , 5, leftside=False, show_ratio=True) +#plotter.save('trig_weight') +# +#plotter.plot_mc_vs_data('os/p1p2/', "PU_weight" , 5, leftside=False, show_ratio=True) +#plotter.save('PU_weight') +# +#plotter.plot_mc_vs_data('os/p1p2/', "idIso_weight", 5, leftside=False, show_ratio=True) +#plotter.save('idIso_weight') -plotter.plot_mc_vs_data('os/p1p2/', 'TrkMass', rebin=2, xaxis='m_{#mu#mu} (GeV)', - leftside=False, show_ratio=True) -plotter.add_cms_blurb(plotter.sqrts) -plotter.save('mass') - -plotter.plot_mc_vs_data('os/p1p2/', 'TrkMass', rebin=10, xaxis='m_{#mu#mu} (GeV)', - leftside=False, show_ratio=True) -plotter.add_cms_blurb(plotter.sqrts) -plotter.save('mass_rebin') - -plotter.plot_mc_vs_data('os/p1p2/', 'e1Pt', leftside=False, show_ratio=True) -plotter.save('e1Pt') -plotter.plot_mc_vs_data('os/p1p2/', 'e1Pt', 5, leftside=False, show_ratio=True) -plotter.save('e1Pt_rebin') -plotter.plot_mc_vs_data('os/p1p2/', 'e2Pt', leftside=False, show_ratio=True) -plotter.save('e2Pt') -plotter.plot_mc_vs_data('os/p1p2/', 'e2Pt', 5, leftside=False, show_ratio=True) -plotter.save('e2Pt_rebin') -plotter.plot_mc_vs_data('os/p1p2/', 'e1AbsEta', leftside=False, show_ratio=True) -plotter.save('e1AbsEta') -plotter.plot_mc_vs_data('os/p1p2/', 'e2AbsEta', leftside=False, show_ratio=True) -plotter.save('e2AbsEta') +#plotter.plot_mc_vs_data('os/p1p2/', 'nvtx', show_ratio=True) +#plotter.save('nvtx') -plotter.plot_mc_vs_data('os/p1p2/', 'e1AbsEta', 5, leftside=False, show_ratio=True) -plotter.save('e1AbsEta_rebin') -plotter.plot_mc_vs_data('os/p1p2/', 'e2AbsEta', 5, leftside=False, show_ratio=True) -plotter.save('e2AbsEta_rebin') +########################################################################### +## DATA/MC+FAKES PLOTS ######################################### +########################################################################### +plotter.plot_zee_control('TrkMass', rebin=2, xaxis='m_{#mu#mu} (GeV)', + legend_on_the_left=False, show_ratio=True, logscale=True) +plotter.save('mass_wfakes_log') -plotter.plot_mc_vs_data('os/p1p2/', "trig_weight" , 5, leftside=False, show_ratio=True) -plotter.save('trig_weight') +#print data_styles.keys() +plotter.plot_zee_control('TrkMass', rebin=2, xaxis='m_{#mu#mu} (GeV)', + legend_on_the_left=False, show_ratio=True) +plotter.save('mass_wfakes') -plotter.plot_mc_vs_data('os/p1p2/', "PU_weight" , 5, leftside=False, show_ratio=True) -plotter.save('PU_weight') +plotter.plot_zee_control('e1Pt', rebin=5, xaxis='p_{T}^{#mu1} (GeV)', + legend_on_the_left=False, show_ratio=True, x_range=[0,200]) +plotter.save('e1Pt_wfakes') -plotter.plot_mc_vs_data('os/p1p2/', "idIso_weight", 5, leftside=False, show_ratio=True) -plotter.save('idIso_weight') +plotter.plot_zee_control('e2Pt', rebin=5, xaxis='p_{T}^{#mu2} (GeV)', + legend_on_the_left=False, show_ratio=True, x_range=[0,200]) +plotter.save('e2Pt_wfakes') +plotter.plot_zee_control('e1AbsEta', rebin=5, xaxis='|#eta|^{#mu1}', + legend_on_the_left=False, show_ratio=True) +plotter.save('e1AbsEta_wfakes') -#plotter.plot_mc_vs_data('os/p1p2/', 'nvtx', show_ratio=True) -#plotter.save('nvtx') +plotter.plot_zee_control('e2AbsEta', rebin=5, xaxis='|#eta|^{#mu2}', + legend_on_the_left=False, show_ratio=True) +plotter.save('e2AbsEta_wfakes') From a4000e19f6ccb9617d6cd8ef474b56edb4d80bf7 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 4 Oct 2013 10:44:13 -0500 Subject: [PATCH 067/192] be complieant with new code structure. Change in enhance_wz --- wh/WHAnalyzeEET.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/wh/WHAnalyzeEET.py b/wh/WHAnalyzeEET.py index 76d51c15..f0635cb7 100755 --- a/wh/WHAnalyzeEET.py +++ b/wh/WHAnalyzeEET.py @@ -274,7 +274,7 @@ def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = if row.LT < LT_threshold: return False cut_flow_trk.Fill('LT') - if row.e1_e2_SS and row.e1_t_SS: return False #remove three SS leptons + #if row.e1_e2_SS and row.e1_t_SS: return False #remove three SS leptons if row.e1_e2_Mass < 20: return False if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes cut_flow_trk.Fill('vetos') @@ -306,6 +306,11 @@ def sign_cut(row): ''' Returns true if muons are SS ''' return bool(row.e1_e2_SS) + @staticmethod + def tau_sign_cut(row): + ''' Returns true if muons are SS ''' + return not bool(row.e1_t_SS) + #There is no call to self, so just promote it to statucmethod, to allow usage by other dedicated analyzers @staticmethod def obj1_id(row, leadleptonId='eid13Looseh2taucuts', subleadleptonId=None): @@ -338,11 +343,7 @@ def anti_wz(row): def enhance_wz(self, row): # Require the "tau" to be a electron, and require the third electron # to have M_Z +- 20 - if self.anti_wz(row): - return False - # Make sure any Z is from e1 - e2_good_Z = bool(71 < row.e2_t_Mass < 111) - return not e2_good_Z + return row.tCiCTightElecOverlap def event_weight(self, row): if row.run > 2: From 0b505b45510425b712e40fcaeef5bae25181addd Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 4 Oct 2013 10:44:18 -0500 Subject: [PATCH 068/192] be complieant with new code structure. Change in enhance_wz --- wh/WHAnalyzeEMT.py | 9 +++++++-- wh/WHAnalyzeMMT.py | 12 +++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/wh/WHAnalyzeEMT.py b/wh/WHAnalyzeEMT.py index 007cce49..27adface 100644 --- a/wh/WHAnalyzeEMT.py +++ b/wh/WHAnalyzeEMT.py @@ -255,7 +255,7 @@ def preselection( self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr if row.LT < LT_threshold: return False cut_flow_trk.Fill('LT') - if row.e_m_SS and row.e_t_SS: return False #remove three SS leptons + #if row.e_m_SS and row.e_t_SS: return False #remove three SS leptons if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes cut_flow_trk.Fill('vetos') #FIXME @@ -285,6 +285,11 @@ def sign_cut( row): ''' Returns true if muons are SS ''' return bool(row.e_m_SS) + @staticmethod + def tau_sign_cut(row): + ''' Returns true if muons are SS ''' + return not bool(row.m_t_SS) + #There is no call to self, so just promote it to statucmethod, to allow usage by other dedicated analyzers @staticmethod def obj1_id( row, ledleptonId='h2taucuts', subledleptonId='h2taucuts'): @@ -317,7 +322,7 @@ def anti_wz( row): return True def enhance_wz(self, row): - if row.e_t_Zcompat < 15 and not row.tAntiElectronMVA: + if row.e_t_Zcompat < 15 and row.tCiCTightElecOverlap: return True return False diff --git a/wh/WHAnalyzeMMT.py b/wh/WHAnalyzeMMT.py index c8217c20..cdb1fca6 100755 --- a/wh/WHAnalyzeMMT.py +++ b/wh/WHAnalyzeMMT.py @@ -197,7 +197,7 @@ def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = if row.LT < LT_threshold: return False cut_flow_trk.Fill('LT') - if row.m1_m2_SS and row.m1_t_SS: return False #remove three SS leptons + #if row.m1_m2_SS and row.m1_t_SS: return False #remove three SS leptons if row.m1_m2_Mass < 20: return False if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes cut_flow_trk.Fill('vetos') @@ -218,6 +218,11 @@ def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = return True + @staticmethod + def tau_sign_cut(row): + ''' Returns true if muons are SS ''' + return not bool(row.m1_t_SS) + @staticmethod def sign_cut(row): ''' Returns true if muons are SS ''' @@ -247,14 +252,11 @@ def anti_wz(row): def enhance_wz(self, row): # Require the "tau" to be a muon, and require the third muon # to have M_Z +- 20 - if self.anti_wz(row): - return False # Cut on m2 PT > 20 #if row.m2Pt < 20: #return False # Make sure any Z is from m1 - m2_good_Z = bool(71 < row.m2_t_Mass < 111) - return not m2_good_Z + return row.tMuOverlap def event_weight(self, row): if row.run > 2: From e69c9d40c547b7e71a719731cd8a70934edd1393 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 4 Oct 2013 10:45:42 -0500 Subject: [PATCH 069/192] change in code structure, allow 3SS objects in a dedicated region --- wh/WHAnalyzerBase.py | 169 ++++++++++++++++++++++--------------------- 1 file changed, 85 insertions(+), 84 deletions(-) diff --git a/wh/WHAnalyzerBase.py b/wh/WHAnalyzerBase.py index 36b9d966..0c13713f 100644 --- a/wh/WHAnalyzerBase.py +++ b/wh/WHAnalyzerBase.py @@ -141,65 +141,68 @@ def build_wh_folder_structure(): #folders = [] flag_map = {} for sign in ['ss', 'os']: - for failing_objs in [(), (1,), (2,), (3,), (1,3), (2, 3), (1,2), (1,2,3)]: - cut_key = [sign == 'ss'] - region_label = '' - for i in range(1,4): - if i in failing_objs: - region_label += 'f' + str(i) - cut_key.append(False) - else: - region_label += 'p' + str(i) - cut_key.append(True) - # Figure out which objects to weight for FR - weights_to_apply = [] - # Single fake - if len(failing_objs) == 1: - weights_to_apply.append( - (failing_objs, "w%i" % failing_objs)) - # A version using the QCD fake rate - weights_to_apply.append( - (failing_objs, "q%i" % failing_objs)) - if len(failing_objs) == 2: - # in the 1-2 case, apply both. Otherwise, just apply the - # first (a light lepton) - if 3 not in failing_objs: - weights_to_apply.append( - (failing_objs, "w%i%i" % failing_objs)) - # Using QCD rate - weights_to_apply.append( - (failing_objs, "q%i%i" % failing_objs)) - else: + for tau_sign in ['tau_ss', 'tau_os']: + for failing_objs in [(), (1,), (2,), (3,), (1,3), (2, 3), (1,2), (1,2,3)]: + cut_key = [sign == 'ss'] + tau_sign_key = (tau_sign == 'tau_os') + cut_key.append( tau_sign_key ) + region_label = '' + for i in range(1,4): + if i in failing_objs: + region_label += 'f' + str(i) + cut_key.append(False) + else: + region_label += 'p' + str(i) + cut_key.append(True) + # Figure out which objects to weight for FR + weights_to_apply = [] + # Single fake + if len(failing_objs) == 1: weights_to_apply.append( - (failing_objs, "w%i" % failing_objs[0])) - # Using QCD rate + (failing_objs, "w%i" % failing_objs)) + # A version using the QCD fake rate weights_to_apply.append( - (failing_objs, "q%i" % failing_objs[0])) - - if len(failing_objs) == 3: - weights_to_apply.append( ((3,), "w3") ) - weights_to_apply.append( ((1,3,), "w13") ) - weights_to_apply.append( ((2,3,), "w23") ) - # QCD weight versions - weights_to_apply.append( ((1,3,), "q13") ) - weights_to_apply.append( ((2,3,), "q23") ) - # Needed for f3 CR - weights_to_apply.append( ((1,2), "w12")) - weights_to_apply.append( ((1,), "w1")) - weights_to_apply.append( ((2,), "w2")) - weights_to_apply.append( ((1,2), "q12")) - weights_to_apply.append( ((1,), "q1")) - weights_to_apply.append( ((2,), "q2")) - - #folders_to_add = [ (sign, region_label) ] - # Which objects to weight for each region - weights_to_add = [] - for failing_objs, weight_to_apply in weights_to_apply: - #folders_to_add.append( (sign, region_label, weight_to_apply) ) - weights_to_add.append(weight_to_apply) - - flag_map[tuple(cut_key)] = ((sign, region_label), tuple(weights_to_add)) - #folders.extend(folders_to_add) + (failing_objs, "q%i" % failing_objs)) + if len(failing_objs) == 2: + # in the 1-2 case, apply both. Otherwise, just apply the + # first (a light lepton) + if 3 not in failing_objs: + weights_to_apply.append( + (failing_objs, "w%i%i" % failing_objs)) + # Using QCD rate + weights_to_apply.append( + (failing_objs, "q%i%i" % failing_objs)) + else: + weights_to_apply.append( + (failing_objs, "w%i" % failing_objs[0])) + # Using QCD rate + weights_to_apply.append( + (failing_objs, "q%i" % failing_objs[0])) + + if len(failing_objs) == 3: + weights_to_apply.append( ((3,), "w3") ) + weights_to_apply.append( ((1,3,), "w13") ) + weights_to_apply.append( ((2,3,), "w23") ) + # QCD weight versions + weights_to_apply.append( ((1,3,), "q13") ) + weights_to_apply.append( ((2,3,), "q23") ) + # Needed for f3 CR + weights_to_apply.append( ((1,2), "w12")) + weights_to_apply.append( ((1,), "w1")) + weights_to_apply.append( ((2,), "w2")) + weights_to_apply.append( ((1,2), "q12")) + weights_to_apply.append( ((1,), "q1")) + weights_to_apply.append( ((2,), "q2")) + + #folders_to_add = [ (sign, region_label) ] + # Which objects to weight for each region + weights_to_add = [] + for failing_objs, weight_to_apply in weights_to_apply: + #folders_to_add.append( (sign, region_label, weight_to_apply) ) + weights_to_add.append(weight_to_apply) + + flag_map[tuple(cut_key)] = ((sign, tau_sign, region_label), tuple(weights_to_add)) + #folders.extend(folders_to_add) return flag_map @@ -254,16 +257,16 @@ def begin(self): self.book_histos(hfolder+'/charge_flip_CR') # Add WZ control region - self.book_histos('ss/p1p2p3_enhance_wz') + self.book_histos('ss/tau_os/p1p2p3_enhance_wz') # Where second light lepton fails - self.book_histos('ss/p1f2p3_enhance_wz') - self.book_histos('ss/p1f2p3_enhance_wz/w2') + self.book_histos('ss/tau_os/p1f2p3_enhance_wz') + self.book_histos('ss/tau_os/p1f2p3_enhance_wz/w2') # Add charge-fake control region - probability that obj1 will flip into # ss/p1p2p3 - for i in itertools.product(['p3','f3'],['c1','c2','c1_sysup','c2_sysup']): - self.book_histos('os/p1p2%s/%s' % i) - self.book_histos('os/p1p2%s/%s/charge_flip_CR' % i) + for i in itertools.product(['tau_os','tau_ss'],['p3','f3'],['c1','c2','c1_sysup','c2_sysup']): + self.book_histos('os/%s/p1p2%s/%s' % i) + self.book_histos('os/%s/p1p2%s/%s/charge_flip_CR' % i) for key in self.histograms: charpos = key.rfind('/') @@ -309,6 +312,7 @@ def process(self): histos = self.histograms preselection = self.preselection sign_cut = self.sign_cut + tau_sign_cut = self.tau_sign_cut obj1_id = self.obj1_id obj2_id = self.obj2_id obj3_id = self.obj3_id @@ -378,6 +382,7 @@ def process(self): # Get the cuts that define the region sign_result = sign_cut(row) + tau_sign_result = tau_sign_cut(row) obj1_id_result = obj1_id(row, cut_settings['leading_iso'], cut_settings['subleading_iso']) obj2_id_result = obj2_id(row, cut_settings['leading_iso'], cut_settings['subleading_iso']) obj3_id_result = obj3_id(row, cut_settings['tauID'], cut_settings['LT'], cut_settings['tauPT']) @@ -396,7 +401,7 @@ def process(self): # print 'obj3_id_result', obj3_id_result # print 'anti_wz ', anti_wz # #from pdb import set_trace; set_trace() - + #from pdb import set_trace; set_trace() #if not cut_flow_trk.disabled: if obj1_id_result: cut_flow_trk.Fill('obj1 IDIso') @@ -411,7 +416,7 @@ def process(self): # Figure out which folder/region we are in region_result = cut_region_map.get( - (sign_result, obj1_id_result, obj2_id_result, obj3_id_result)) + (sign_result, tau_sign_result, obj1_id_result, obj2_id_result, obj3_id_result)) # Ignore stupid regions we don't care about if region_result is None: @@ -445,32 +450,28 @@ def process(self): if not sign_result and obj1_id_result and obj2_id_result: # Object 1 can only flip if it is OS with the tau obj1_obj3_SS = self.obj1_obj3_SS(row) - if (obj1_obj3_SS and obj1_charge_flip) \ - or ( not obj1_obj3_SS and obj2_charge_flip): #there is the function --> we have to compute it, otherwise skip and save some precious filling time! - charge_flip_prob = obj1_charge_flip(row, cut_settings['leading_iso'], cut_settings['subleading_iso']) \ - if obj1_obj3_SS else \ - obj2_charge_flip(row, cut_settings['leading_iso'], cut_settings['subleading_iso']) - charge_flip_sysu = obj1_charge_flip_sysup(row, cut_settings['leading_iso'], cut_settings['subleading_iso']) \ - if obj1_obj3_SS else \ - obj2_charge_flip_sysup(row, cut_settings['leading_iso'], cut_settings['subleading_iso']) - directory = joinDirs(base_folder,'c1' if obj1_obj3_SS else 'c2') - directory_up = joinDirs(base_folder,'c1_sysup' if obj1_obj3_SS else 'c2_sysup') - charge_flip_prob = charge_flip_prob/(1. - charge_flip_prob) - for i in to_fill: - fill_histos(histos, joinDirs(directory,i), row, event_weight*charge_flip_prob, cut_label) - fill_histos(histos, joinDirs(directory_up,i), row, event_weight*charge_flip_sysu, cut_label) - - elif sign_result and obj1_id_result and obj3_id_result: + for flipfunc, flipfunc_sysup, dirname in [(obj1_charge_flip, obj1_charge_flip_sysup, 'c1'), (obj2_charge_flip, obj2_charge_flip_sysup, 'c2')]: + if flipfunc: + charge_flip_prob = flipfunc(row, cut_settings['leading_iso'], cut_settings['subleading_iso']) + charge_flip_sysu = flipfunc_sysup(row, cut_settings['leading_iso'], cut_settings['subleading_iso']) + directory = joinDirs(base_folder, dirname) + directory_up = joinDirs(base_folder, '%s_sysup' % dirname) + charge_flip_prob = charge_flip_prob/(1. - charge_flip_prob) + for i in to_fill: + fill_histos(histos, joinDirs(directory,i), row, event_weight*charge_flip_prob, cut_label) + fill_histos(histos, joinDirs(directory_up,i), row, event_weight*charge_flip_sysu, cut_label) + + elif sign_result and obj1_id_result and obj3_id_result and tau_sign_result: # WZ object topology fails. Check if we are in signal region. if self.enhance_wz(row): # Signal region if obj2_id_result: - fill_histos(histos, 'ss/p1p2p3_enhance_wz/', row, event_weight, cut_label) + fill_histos(histos, 'ss/tau_os/p1p2p3_enhance_wz/', row, event_weight, cut_label) else: - fill_histos(histos, 'ss/p1f2p3_enhance_wz/', row, event_weight, cut_label) + fill_histos(histos, 'ss/tau_os/p1f2p3_enhance_wz/', row, event_weight, cut_label) fake_rate_obj2 = self.obj2_weight(row, cut_settings['leading_iso'], cut_settings['subleading_iso']) fake_weight = fake_rate_obj2/(1.-fake_rate_obj2) - fill_histos(histos, 'ss/p1f2p3_enhance_wz/w2/', row, event_weight*fake_weight, cut_label) + fill_histos(histos, 'ss/tau_os/p1f2p3_enhance_wz/w2/', row, event_weight*fake_weight, cut_label) cut_flow_trk.flush() def finish(self): From 3255caaaf27e78ebfb8e3c200714b93f4c9444ef Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 4 Oct 2013 10:47:24 -0500 Subject: [PATCH 070/192] allow to plot 3SS region. Update WZ CR plotting to match current samples --- wh/WHPlotterBase.py | 187 +++++++++++++++++++++++--------------------- 1 file changed, 100 insertions(+), 87 deletions(-) diff --git a/wh/WHPlotterBase.py b/wh/WHPlotterBase.py index 7b7b7803..73d85dce 100644 --- a/wh/WHPlotterBase.py +++ b/wh/WHPlotterBase.py @@ -248,7 +248,7 @@ def __init__(self, channel, obj1_charge_mapper={}, obj2_charge_mapper={}): self.obj2_charge_mapper=obj2_charge_mapper #maps scaled charge flip histograms to the ones of the normal categories if blind: # Don't look at the SS all pass region - blinder = lambda x: BlindView(x, "ss/p1p2p3/.*") + blinder = lambda x: BlindView(x, "ss/tau_os/p1p2p3/.*") super(WHPlotterBase, self).__init__(files, lumifiles, self.outputdir, blinder) self.defaults = {} #allows to set some options and avoid repeating them each function call @@ -276,8 +276,9 @@ def apply_to_dict(self, dictionary, viewtype, *args, **kwargs): #project, projec return ret def make_signal_views(self, unblinded=False, qcd_weight_fraction=0, #MARK - rebin=1, project=None, project_axis=None ): + rebin=1, project=None, project_axis=None, tau_charge='tau_os' ): ''' Make signal views with FR background estimation ''' + other_tau_sign = 'tau_os' if tau_charge == 'tau_ss' else 'tau_ss' def preprocess(view): ret = view @@ -288,7 +289,7 @@ def preprocess(view): wz_view_tautau = preprocess( views.SubdirectoryView( self.get_view('WZJetsTo3LNu*ZToTauTau*'), - 'ss/p1p2p3/' + 'ss/%s/p1p2p3/' % tau_charge ) ) @@ -296,14 +297,14 @@ def preprocess(view): wz_view_3l = preprocess( views.SubdirectoryView( self.get_view(tomatch), - 'ss/p1p2p3/' + 'ss/%s/p1p2p3/' % tau_charge ) ) zz_view = preprocess( views.SubdirectoryView( self.get_view('ZZJetsTo4L*'), - 'ss/p1p2p3/' + 'ss/%s/p1p2p3/' % tau_charge ) ) @@ -312,20 +313,20 @@ def preprocess(view): # all_data_view = self.get_view('data', 'unblinded_view') all_data_view = preprocess(all_data_view) - data_view = views.SubdirectoryView(all_data_view, 'ss/p1p2p3/') + data_view = views.SubdirectoryView(all_data_view, 'ss/%s/p1p2p3/' % tau_charge) def make_fakes(qcd_fraction): def make_fakes_view(weight_type, scale): scaled_data = views.ScaleView(all_data_view, scale) # View of weighted obj1-fails data obj1_view = views.SubdirectoryView( - scaled_data, 'ss/f1p2p3/%s1' % weight_type) + scaled_data, 'ss/%s/f1p2p3/%s1' % (tau_charge, weight_type)) # View of weighted obj2-fails data obj2_view = views.SubdirectoryView( - scaled_data, 'ss/p1f2p3/%s2' % weight_type) + scaled_data, 'ss/%s/p1f2p3/%s2' % (tau_charge, weight_type)) # View of weighted obj1&2-fails data obj12_view = views.SubdirectoryView( - scaled_data, 'ss/f1f2p3/%s12' % weight_type) + scaled_data, 'ss/%s/f1f2p3/%s12' % (tau_charge, weight_type)) # Give the individual object views nice colors obj1_view = views.TitleView( @@ -363,11 +364,11 @@ def make_fakes_view(weight_type, scale): views.StyleView( views.SumView( views.PathModifierView( - views.SubdirectoryView(all_data_view, 'os/p1p2p3/c1'), + views.SubdirectoryView(all_data_view, 'os/%s/p1p2p3/c1' % other_tau_sign), #FIXME: needs to be fixed for charge 3 region create_mapper(self.obj1_charge_mapper) ), views.PathModifierView( - views.SubdirectoryView(all_data_view, 'os/p1p2p3/c2'), + views.SubdirectoryView(all_data_view, 'os/%s/p1p2p3/c2' % tau_charge), create_mapper(self.obj2_charge_mapper) ), ), @@ -378,11 +379,11 @@ def make_fakes_view(weight_type, scale): views.StyleView( views.SumView( views.PathModifierView( - views.SubdirectoryView(all_data_view, 'os/p1p2p3/c1_sysup'), + views.SubdirectoryView(all_data_view, 'os/%s/p1p2p3/c1_sysup' % other_tau_sign), create_mapper(self.obj1_charge_mapper) ), views.PathModifierView( - views.SubdirectoryView(all_data_view, 'os/p1p2p3/c2_sysup'), + views.SubdirectoryView(all_data_view, 'os/%s/p1p2p3/c2_sysup' % tau_charge), create_mapper(self.obj2_charge_mapper) ), ), @@ -417,7 +418,7 @@ def make_fakes_view(weight_type, scale): try: vh_view = views.SubdirectoryView( self.get_view('VH_*%i' % mass), - 'ss/p1p2p3/' + 'ss/%s/p1p2p3/' % tau_charge ) output['vh%i' % mass] = preprocess(vh_view) except KeyError: @@ -429,7 +430,7 @@ def make_fakes_view(weight_type, scale): try: ww_view = views.SubdirectoryView( self.get_view('VH_%i_HWW*' % mass), - 'ss/p1p2p3/' + 'ss/%s/p1p2p3/' % tau_charge ) output['vh%i_hww' % mass] = preprocess(ww_view) except KeyError: @@ -448,12 +449,12 @@ def make_qcd_proj_views(self, control_region, rebin): mapping = { 1: { - 'obs': 'ss/f1p2p3', - 'qcd': 'ss/f1f2f3/w23', + 'obs': 'ss/tau_os/f1p2p3', + 'qcd': 'ss/tau_os/f1f2f3/w23', }, 2: { - 'obs': 'ss/p1f2p3', - 'qcd': 'ss/f1f2f3/w13', + 'obs': 'ss/tau_os/p1f2p3', + 'qcd': 'ss/tau_os/f1f2f3/w13', }, } @@ -472,37 +473,39 @@ def make_qcd_proj_views(self, control_region, rebin): @memo def make_obj3_fail_cr_views(self, qcd_correction=False, - qcd_weight_fraction=0): + qcd_weight_fraction=0, tau_charge='tau_os'): ''' Make views when obj3 fails, estimating the bkg in obj1 pass using f1p2f3 ''' + other_tau_sign = 'tau_os' if tau_charge == 'tau_ss' else 'tau_ss' + wz_view = views.SubdirectoryView( self.get_view('WZJetsTo3LNu*ZToTauTau*'), - 'ss/p1p2f3/' + 'ss/%s/p1p2f3/' % tau_charge ) tomatch = 'WZJetsTo3LNu' if self.sqrts == 7 else 'WZJetsTo3LNu_pythia' wz_view_3l = views.SubdirectoryView( self.get_view(tomatch), - 'ss/p1p2f3/' + 'ss/%s/p1p2f3/' % tau_charge ) zz_view = views.SubdirectoryView( self.get_view('ZZJetsTo4L*'), - 'ss/p1p2f3/' + 'ss/%s/p1p2f3/' % tau_charge ) all_data_view = self.get_view('data') - data_view = views.SubdirectoryView(all_data_view, 'ss/p1p2f3/') + data_view = views.SubdirectoryView(all_data_view, 'ss/%s/p1p2f3/' % tau_charge) def make_fakes(qcd_fraction): def make_fakes_view(weight_type, scale): scaled_data = views.ScaleView(all_data_view, scale) # View of weighted obj1-fails data obj1_view = views.SubdirectoryView( - scaled_data, 'ss/f1p2f3/%s1' % weight_type) + scaled_data, 'ss/%s/f1p2f3/%s1' % (tau_charge, weight_type)) # View of weighted obj2-fails data obj2_view = views.SubdirectoryView( - scaled_data, 'ss/p1f2f3/%s2' % weight_type) + scaled_data, 'ss/%s/p1f2f3/%s2' % (tau_charge, weight_type)) # View of weighted obj1&2-fails data obj12_view = views.SubdirectoryView( - scaled_data, 'ss/f1f2f3/%s12' % weight_type) + scaled_data, 'ss/%s/f1f2f3/%s12' % (tau_charge, weight_type)) # Give the individual object views nice colors obj1_view = views.TitleView( @@ -539,15 +542,15 @@ def make_fakes_view(weight_type, scale): fakes_view_1 = make_fakes(1)[-1] style_dict_no_name = remove_name_entry(data_styles['TT*']) - charge_fakes = views.TitleView( + charge_fakes = views.TitleView( #FIXME views.StyleView( views.SumView( views.PathModifierView( - views.SubdirectoryView(all_data_view, 'os/p1p2f3/c1'), + views.SubdirectoryView(all_data_view, 'os/%s/p1p2f3/c1' % other_tau_sign), create_mapper(self.obj1_charge_mapper) ), views.PathModifierView( - views.SubdirectoryView(all_data_view, 'os/p1p2f3/c2'), + views.SubdirectoryView(all_data_view, 'os/%s/p1p2f3/c2' % tau_charge), create_mapper(self.obj2_charge_mapper) ), ), @@ -558,11 +561,11 @@ def make_fakes_view(weight_type, scale): views.StyleView( views.SumView( views.PathModifierView( - views.SubdirectoryView(all_data_view, 'os/p1p2f3/c1_sysup'), + views.SubdirectoryView(all_data_view, 'os/%s/p1p2f3/c1_sysup' % other_tau_sign), create_mapper(self.obj1_charge_mapper) ), views.PathModifierView( - views.SubdirectoryView(all_data_view, 'os/p1p2f3/c2_sysup'), + views.SubdirectoryView(all_data_view, 'os/%s/p1p2f3/c2_sysup' % tau_charge), create_mapper(self.obj2_charge_mapper) ), ), @@ -595,13 +598,13 @@ def make_fakes_view(weight_type, scale): mass = 120 vh_view = views.SubdirectoryView( self.get_view('VH_*%i' % mass), - 'ss/p1p2f3/' + 'ss/tau_os/p1p2f3/' ) output['vh%i' % mass] = vh_view try: ww_view = views.SubdirectoryView( self.get_view('VH_%i_HWW*' % mass), - 'ss/p1p2f3/' + 'ss/tau_os/p1p2f3/' ) except KeyError: logging.warning('No sample found matching VH_%i_HWW*' % mass) @@ -611,59 +614,62 @@ def make_fakes_view(weight_type, scale): return output - def make_wz_cr_views(self, rebin): + def make_wz_cr_views(self, rebin=1, project=None, project_axis=None): ''' Make WZ control region views with FR background estimation ''' - wz_view = views.SubdirectoryView( - self.rebin_view(self.get_view('WZJetsTo3LNu*'), rebin), - 'ss/p1p2p3_enhance_wz/' - ) - zz_view = views.SubdirectoryView( - self.rebin_view(self.get_view('ZZJetsTo4L*'), rebin), - 'ss/p1p2p3_enhance_wz/' - ) - all_data_view = self.rebin_view(self.get_view('data'), rebin) + def preprocess(view): + ret = view + if project and project_axis: + ret = ProjectionView(ret, project_axis, project) + return RebinView( ret, rebin ) + + wz_view_tautau_all = preprocess( self.get_view('WZJetsTo3LNu*ZToTauTau*') ) + wz_view_tautau = views.SubdirectoryView(wz_view_tautau_all, 'ss/tau_os/p1p2p3_enhance_wz/') + + tomatch = 'WZJetsTo3LNu' if self.sqrts == 7 else 'WZJetsTo3LNu_pythia' + wz_view_3l_all = preprocess( self.get_view(tomatch) ) + wz_view_3l = views.SubdirectoryView(wz_view_3l_all, 'ss/tau_os/p1p2p3_enhance_wz/') + wz_view_all = views.SumView(wz_view_tautau_all, wz_view_3l_all) + + zz_view_all = preprocess( self.get_view('ZZJetsTo4L*') ) + zz_view = views.SubdirectoryView(zz_view_all, 'ss/tau_os/p1p2p3_enhance_wz/') + + all_data_view = preprocess( self.get_view('data') ) data_view = views.SubdirectoryView( - all_data_view, 'ss/p1p2p3_enhance_wz/') + all_data_view, 'ss/tau_os/p1p2p3_enhance_wz/') # View of weighted obj2-fails data fakes_view = views.SubdirectoryView( - all_data_view, 'ss/p1f2p3_enhance_wz/w2') + all_data_view, 'ss/tau_os/p1f2p3_enhance_wz/w2') fakes_view = views.StyleView(fakes_view, **remove_name_entry(data_styles['Zjets*'])) # Correct - wz_in_fakes_view = views.SubdirectoryView( - self.rebin_view(self.get_view('WZJetsTo3LNu*'), rebin), - 'ss/p1f2p3_enhance_wz/w2' - ) - zz_in_fakes_view = views.SubdirectoryView( - self.rebin_view(self.get_view('ZZJetsTo4L*'), rebin), - 'ss/p1f2p3_enhance_wz/w2' - ) + wz_in_fakes_view = views.SubdirectoryView(wz_view_all, 'ss/tau_os/p1f2p3_enhance_wz/w2') + zz_in_fakes_view = views.SubdirectoryView(zz_view_all, 'ss/tau_os/p1f2p3_enhance_wz/w2') diboson_view = views.SumView(wz_in_fakes_view, zz_in_fakes_view) inverted_diboson_view = views.ScaleView(diboson_view, -1) fakes_view = views.SumView(fakes_view, inverted_diboson_view) - fakes_view = views.TitleView(fakes_view, 'Reducible bkg.') output = { - 'wz': wz_view, - 'zz': zz_view, - 'data': data_view, - 'fakes': fakes_view + 'wz_ztt': wz_view_tautau, + 'wz_3l' : wz_view_3l, + 'zz' : zz_view, + 'data' : data_view, + 'fakes' : fakes_view } - - # Add signal - for mass in [110, 120, 130, 140]: - vh_view = views.SubdirectoryView( - self.rebin_view(self.get_view('VH_*%i' % mass, 'unweighted_view'), rebin), - 'ss/p1p2p3/' - ) - output['vh%i' % mass] = vh_view - return output + # Add signal + #for mass in [110, 120, 130, 140]: + # vh_view = views.SubdirectoryView( + # self.rebin_view(self.get_view('VH_*%i' % mass, 'unweighted_view'), rebin), + # 'ss/tau_os/p1p2p3/' + # ) + # output['vh%i' % mass] = vh_view + # + #return output def write_shapes(self, variable, rebin, outdir, qcd_fraction=0, show_charge_fakes=False, @@ -782,12 +788,13 @@ def plot_final(self, variable, rebin=1, xaxis='', maxy=24, show_error=False, qcd_correction=False, stack_higgs=True, qcd_weight_fraction=0.5, x_range=None, show_charge_fakes=False, leftside_legend=False, higgs_xsec_multiplier=1, project=None, - project_axis=None, differential=False, yaxis='Events', **kwargs): + project_axis=None, differential=False, yaxis='Events', tau_charge='tau_os', **kwargs): ''' Plot the final output - with bkg. estimation ''' show_charge_fakes = show_charge_fakes if 'show_charge_fakes' not in self.defaults else self.defaults['show_charge_fakes'] sig_view = self.make_signal_views(unblinded=(not self.blind), qcd_weight_fraction=qcd_weight_fraction, - rebin=rebin, project=project, project_axis=project_axis) + rebin=rebin, project=project, + project_axis=project_axis, tau_charge=tau_charge) if differential: sig_view = self.apply_to_dict(sig_view, DifferentialView) @@ -821,12 +828,6 @@ def plot_final(self, variable, rebin=1, xaxis='', maxy=24, if x_range: histo.GetHistogram().GetXaxis().SetRangeUser(x_range[0], x_range[1]) - if isinstance(maxy, (int, long, float)): - #print "setting maxy to %s" % maxy - histo.SetMaximum(maxy) - self.canvas.Update() - else: - histo.SetMaximum(sum(histo.GetHists()).GetMaximum()*1.2) self.keep.append(histo) # Add legend @@ -862,29 +863,40 @@ def plot_final(self, variable, rebin=1, xaxis='', maxy=24, legend.AddEntry(bkg_error) # Use poisson error bars on the data - sig_view['data'] = sig_view['data'] #PoissonView(, x_err=False) + sig_view['data'] = PoissonView(sig_view['data'], x_err=False, is_scaled=differential) #PoissonView(, x_err=False) data = sig_view['data'].Get(variable) - if not self.blind: + ymax = histo.GetMaximum() + if not self.blind or tau_charge != 'tau_os': + #print "drawing", data.Integral() data.Draw('pe,same') + legend.AddEntry(data) + ymax = max(ymax, data.GetMaximum()) self.keep.append(data) + if isinstance(maxy, (int, long, float)): + #print "setting maxy to %s" % maxy + histo.SetMaximum(maxy) + self.canvas.Update() + else: + histo.SetMaximum(ymax*1.2) + if not stack_higgs: higgs_plot = vh_10x.Get(variable) higgs_plot.Draw('same') self.keep.append(higgs_plot) - #legend.AddEntry(data) legend.Draw() - def plot_final_wz(self, variable, rebin=1, xaxis='', maxy=None): + def plot_final_wz(self, variable, rebin=1, xaxis='', maxy=None, project=None, project_axis=None): ''' Plot the final WZ control region - with bkg. estimation ''' - sig_view = self.make_wz_cr_views(rebin) - + sig_view = self.make_wz_cr_views(rebin, project, project_axis) + stack = views.StackView( - sig_view['fakes'], - sig_view['wz'], + sig_view['wz_ztt'], sig_view['zz'], + sig_view['fakes'], + sig_view['wz_3l'] ) histo = stack.Get(variable) histo.Draw() @@ -899,17 +911,18 @@ def plot_final_wz(self, variable, rebin=1, xaxis='', maxy=None): self.keep.append(histo) # Add legend - self.add_legend(histo, leftside=False, entries=4) + self.add_legend(histo, leftside=False, entries=len(histo)) def plot_final_f3(self, variable, rebin=1, xaxis='', maxy=None, show_error=True, qcd_correction=False, qcd_weight_fraction=0.5, x_range=None, #): show_chi2=False,project=None, - project_axis=None, differential=False, yaxis='Events', **kwargs): + project_axis=None, differential=False, + yaxis='Events', tau_charge='tau_os', **kwargs): ''' Plot the final F3 control region - with bkg. estimation ''' show_chi2 = False #broken sig_view = self.make_obj3_fail_cr_views( - qcd_correction, qcd_weight_fraction) + qcd_correction, qcd_weight_fraction, tau_charge) if project and project_axis: sig_view = self.apply_to_dict( sig_view, ProjectionView, project_axis, project ) sig_view = self.apply_to_dict( sig_view, RebinView, rebin ) #Rebin From 23459dffb37f831e7675797ccbfc94e7b5d9b80a Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 4 Oct 2013 10:48:18 -0500 Subject: [PATCH 071/192] code clean-up and add data-mc, WZ CR and 3SS plots --- wh/WHPlotterEET.py | 298 ++++++++++++++++++++++++--------------------- 1 file changed, 156 insertions(+), 142 deletions(-) diff --git a/wh/WHPlotterEET.py b/wh/WHPlotterEET.py index 708231d3..afbc661b 100755 --- a/wh/WHPlotterEET.py +++ b/wh/WHPlotterEET.py @@ -33,6 +33,14 @@ def __init__(self): super(WHPlotterEET, self).__init__('EET', obj1_charge_mapper, obj2_charge_mapper) +rebin_slim = range(20, 81, 10)+[100, 130, 300] +categories = { + 'LTCut' : [80, 650], + 'LTLow' : [0, 100], + 'LTHigh': [100, 650], + 'Full' : [0, 650], +} + if __name__ == "__main__": plotter = WHPlotterEET() sqrts = plotter.sqrts @@ -41,159 +49,154 @@ def __init__(self): if not options.dry_run: ########################################################################### - ## Zmm control plots ##################################################### + ## Zee control plots ##################################################### ########################################################################### - plotter.set_subdir('mc_data') - ## # Control Z->mumu + jet region - ## plotter.plot_mc_vs_data('os/p1p2f3', 'e1_e2_Mass', xaxis='m_{ee} (GeV)', xrange=(60, 120)) - ## plotter.add_cms_blurb(sqrts) - ## plotter.save('mcdata-os-p1p2f3-e1e2Mass') - - ## plotter.plot_mc_vs_data('os/p1p2f3/w3', 'e1_e2_Mass') - ## plotter.save('mcdata-os-p1p2f3-w3-e1e2Mass') - - ## plotter.plot_mc_vs_data('os/p1f2p3', 'e1_e2_Mass', xaxis='m_{ee} (GeV)', xrange=(60, 120)) - ## plotter.add_cms_blurb(sqrts) - ## plotter.save('mcdata-os-p1f2p3-e1e2Mass') - - ## # Check PU variables - ## plotter.plot_mc_vs_data('os/p1p2f3', 'rho') - ## plotter.save('mcdata-os-p1p2f3-rho') - - ## plotter.plot_mc_vs_data('os/p1p2f3', 'nvtx') - ## plotter.save('mcdata-os-p1p2f3-nvtx') - - ## # Lower stat but closer to signal region - ## plotter.plot_mc_vs_data('os/p1p2p3', 'rho') - ## plotter.save('mcdata-os-p1p2p3-rho') - - ## plotter.plot_mc_vs_data('os/p1p2p3', 'nvtx') - ## plotter.save('mcdata-os-p1p2p3-nvtx') - - ## # Make Z->mumu + tau jet control - - ## # - ## # Makes Tau fr control plot - ## # - ## zmm_weighted = plotter.plot('data', 'os/p1p2f3/w3/e1_e2_Mass', 'hist', styler=make_styler(2, 'hist'), xrange=(60, 120)) - ## zmm_weighted.SetTitle("Zee + fake #tau_{h} est.") - ## zmm_weighted.legendstyle='l' - ## zmm_weighted.GetXaxis().SetTitle("m_{ee} (GeV)") - - ## zmm_unweighted = plotter.plot('data', 'os/p1p2p3/e1_e2_Mass', 'same', styler=make_styler(1), xrange=(60, 120)) - ## zmm_unweighted.SetTitle("Zee observed") - ## zmm_unweighted.SetTitle("Zee + fake #tau_{h} obs.") - ## zmm_unweighted.legendstyle='pe' - - ## plotter.add_legend([zmm_weighted, zmm_unweighted]) - ## plotter.add_cms_blurb(sqrts) - ## plotter.save('zmm-os-fr-control') + ## # Control Z->ee + jet region + plotter.set_subdir('mc_data/zee') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e1_e2_Mass', rebin=10, + xaxis='m_{#mu#mu} (GeV)', leftside=False) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-Zee-e1e2Mass') - ## # - ## # Makes charge fr control plot - ## # + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e1Pt#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-Zee-e1Pt') - ## zeet_os_weighted = plotter.plot('data', 'os/p1p2f3/c1/e1_e2_Mass', 'hist', styler=make_styler(2, 'hist'), xrange=(60, 120)) - ## zeet_os_weighted.SetTitle("Ze^{#pm}e^{#mp} + fake #tau_{h} charge flip est.") - ## zeet_os_weighted.legendstyle='l' - ## zeet_os_weighted.GetXaxis().SetTitle("M_{ee} (GeV)") + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e2Pt#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-Zee-e2Pt') - ## zee_ss_unweighted = plotter.plot('data', 'ss/p1p2f3/e1_e2_Mass', 'same', styler=make_styler(1), xrange=(60, 120)) - ## zee_ss_unweighted.SetTitle("Ze^{#pm}e^{#pm} + fake #tau_{h} obs.") - ## zee_ss_unweighted.legendstyle='pe' + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e1AbsEta#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-Zee-e1AbsEta') - ## plotter.add_legend([zeet_os_weighted, zee_ss_unweighted]) - ## plotter.add_cms_blurb(sqrts) - ## plotter.save('zee-os-ss-charge-flip-control') + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e2AbsEta#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-Zee-e2AbsEta') - ## plotter.plot('Zjets_M50', 'os/p1p2f3/weight') - ## plotter.save('zee-mc-event-weights') - ## # Check MC weights - ## ## plotter.plot('Zjets_M50', 'os/p1p2f3/weight_nopu') - ## ## plotter.save('zee-mc-event-weight_nopu') + # Check PU variables + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'rho') + plotter.save('mcdata-Zee-rho') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'nvtx') + plotter.save('mcdata-Zee-nvtx') - ## ########################################################################### - ## ## FR sideband MC-vs-Data ################################################ - ## ########################################################################### + ########################################################################### + ## WZ control plots ##################################################### + ########################################################################### + plotter.set_subdir('mc_data/wz_enhanced') + + plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'e2_t_Mass#LT', xaxis='m_{#mu#mu} (GeV)', + xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-ss-p1p2p3-enhance_wz-subMass') + + plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'e1_t_Mass', xaxis='m_{#mu#mu} (GeV)', + xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-ss-p1p2p3-enhance_wz-leadMass') + + plotter.set_subdir('WZ_enhanced') - plotter.plot_mc_vs_data('ss/p1f2p3', 'e2_t_Mass#LT', rebin=10, xaxis='m_{e2#tau} (GeV)', - leftside=False, preprocess=project_x) + plotter.plot_final_wz('e1_t_Mass', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1f2p3-subMass') + plotter.save('final-wz-leadMass') - plotter.plot_mc_vs_data('ss/p1f2p3', 'LT', rebin=10, xaxis='LT (GeV)', leftside=False) + plotter.plot_final_wz('e2_t_Mass#LT', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1f2p3-LT') + plotter.save('final-wz-subMass') - plotter.plot_mc_vs_data('ss/f1p2p3', 'e2_t_Mass#LT', rebin=10, xaxis='m_{e2#tau} (GeV)', - leftside=False, preprocess=project_x) + plotter.plot_final_wz('e2Pt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-e2Pt') + + plotter.plot_final_wz('e2JetPt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-f1p2p3-subMass') + plotter.save('final-wz-e2JetPt') ########################################################################### ## Signal region plots ################################################ ########################################################################### plotter.set_subdir('') - rebin_slim = range(20, 81, 10)+[100, 130, 300] - categories = { - 'LTCut' : [80, 650], - 'LTLow' : [0, 100], - 'LTHigh': [100, 650], - } for label, proj_range in categories.iteritems(): factor = 1.5 if label == 'LTHigh' else 1 - plotter.set_subdir('%s' % label) + for tau_charge in ['tau_os', 'tau_ss']: + if tau_charge == 'tau_os': + plotter.set_subdir('%s' % label) + else: + plotter.set_subdir('%s_charge3' % label) + plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X', - differential=True, yaxis='Events / GeV', show_error=True) + differential=True, yaxis='Events / GeV', show_error=True, + tau_charge=tau_charge) plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-%s' % label) plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X', - differential=True, yaxis='Events / GeV', show_error=True) + differential=True, yaxis='Events / GeV', show_error=True, + tau_charge=tau_charge) plotter.add_cms_blurb(sqrts) plotter.canvas.SetLogy(True) plotter.save('final-subMass-logscale-%s' % label) - plotter.plot_final('e2_t_Mass#LT', 300, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final('e2_t_Mass#LT', 300, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) #pt - plotter.plot_final("e1Pt#LT" , int(factor*10), xaxis='p_{Te_{1}} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("e1Pt#LT" , int(factor*10), xaxis='p_{Te_{1}} (GeV)', + maxy=None, project=proj_range, project_axis='X', + tau_charge=tau_charge) plotter.add_cms_blurb(sqrts) plotter.save('final-e1Pt-%s' % label) - plotter.plot_final("e2Pt#LT" , int(factor*10), xaxis='p_{Te_{2}} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("e2Pt#LT", int(factor*10), xaxis='p_{Te_{2}} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) plotter.add_cms_blurb(sqrts) plotter.save('final-e2Pt-%s' % label) - plotter.plot_final("e1JetPt#LT" , int(factor*10), xaxis='p_{T Jet e_{1}} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("e1JetPt#LT", int(factor*10), xaxis='p_{T Jet e_{1}} (GeV)', + maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) plotter.add_cms_blurb(sqrts) plotter.save('final-e1JetPt-%s' % label) - plotter.plot_final("e2JetPt#LT" , int(factor*10), xaxis='p_{T Jet e_{2}} (GeV)', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("e2JetPt#LT", int(factor*10), xaxis='p_{T Jet e_{2}} (GeV)', + maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) plotter.add_cms_blurb(sqrts) plotter.save('final-e2JetPt-%s' % label) #eta - plotter.plot_final("e1AbsEta#LT", 10, xaxis='|#eta_{e_{1}}|', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("e1AbsEta#LT", 10, xaxis='|#eta_{e_{1}}|', maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) plotter.add_cms_blurb(sqrts) plotter.save('final-e1AbsEta-%s' % label) - plotter.plot_final("e2AbsEta#LT", 10, xaxis='|#eta_{e_{2}}|' , maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("e2AbsEta#LT", 10, xaxis='|#eta_{e_{2}}|', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) plotter.add_cms_blurb(sqrts) plotter.save('final-e2AbsEta-%s' % label) #DR - plotter.plot_final("e1_t_DR#LT", 10, xaxis='#DeltaR_{e_{1}#tau}', maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("e1_t_DR#LT", 10, xaxis='#DeltaR_{e_{1}#tau}', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) plotter.add_cms_blurb(sqrts) plotter.save('final-e1_t_DR-%s' % label) - plotter.plot_final("e2_t_DR#LT", 10, xaxis='#DeltaR_{e_{2}#tau}' , maxy=None, project=proj_range, project_axis='X') + plotter.plot_final("e2_t_DR#LT", 10, xaxis='#DeltaR_{e_{2}#tau}', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) plotter.add_cms_blurb(sqrts) plotter.save('final-e2_t_DR-%s' % label) @@ -265,61 +268,72 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-LT') + ########################################################################### ## f3 region plots ################################################ ########################################################################### - categories = { - 'LTCut' : [80, 650], - 'LTLow' : [0, 100], - 'LTHigh': [100, 650], - } for label, proj_range in categories.iteritems(): factor = 1.5 if label == 'LTHigh' else 1 - plotter.set_subdir('f3/%s' % label) - plotter.plot_final_f3('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', differential=True, yaxis='Events / GeV') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s' % label) - - plotter.plot_final_f3('e2_t_Mass#LT', 300, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) - - #pt - plotter.plot_final_f3("e1Pt#LT" , int(factor*10), xaxis='p_{Te_{1}} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1Pt-%s' % label) - - plotter.plot_final_f3("e2Pt#LT" , int(factor*10), xaxis='p_{Te_{2}} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2Pt-%s' % label) - - plotter.plot_final_f3("e1JetPt#LT" , int(factor*10), xaxis='p_{T Jet e_{1}} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1JetPt-%s' % label) - - plotter.plot_final_f3("e2JetPt#LT" , int(factor*10), xaxis='p_{T Jet e_{2}} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2JetPt-%s' % label) - - #eta - plotter.plot_final_f3("e1AbsEta#LT", 10, xaxis='|#eta_{e_{1}}|', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1AbsEta-%s' % label) - - plotter.plot_final_f3("e2AbsEta#LT", 10, xaxis='|#eta_{e_{2}}|' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2AbsEta-%s' % label) - - #DR - plotter.plot_final_f3("e1_t_DR#LT", 10, xaxis='#DeltaR_{e_{1}#tau}', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1_t_DR-%s' % label) - - plotter.plot_final_f3("e2_t_DR#LT", 10, xaxis='#DeltaR_{e_{2}#tau}' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2_t_DR-%s' % label) + for tau_charge in ['tau_os', 'tau_ss']: + if tau_charge == 'tau_os': + plotter.set_subdir('f3/%s' % label) + else: + plotter.set_subdir('f3/%s_charge3' % label) + + plotter.plot_final_f3('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, + yaxis='Events / GeV', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s' % label) + + plotter.plot_final_f3('e2_t_Mass#LT', 300, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) + + #pt + plotter.plot_final_f3("e1Pt#LT", int(factor*10), xaxis='p_{Te_{1}} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e1Pt-%s' % label) + + plotter.plot_final_f3("e2Pt#LT", int(factor*10), xaxis='p_{Te_{2}} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e2Pt-%s' % label) + + plotter.plot_final_f3("e1JetPt#LT", int(factor*10), xaxis='p_{T Jet e_{1}} (GeV)', + maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e1JetPt-%s' % label) + + plotter.plot_final_f3("e2JetPt#LT" , int(factor*10), xaxis='p_{T Jet e_{2}} (GeV)', + maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e2JetPt-%s' % label) + + #eta + plotter.plot_final_f3("e1AbsEta#LT", 10, xaxis='|#eta_{e_{1}}|', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e1AbsEta-%s' % label) + + plotter.plot_final_f3("e2AbsEta#LT", 10, xaxis='|#eta_{e_{2}}|', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e2AbsEta-%s' % label) + + #DR + plotter.plot_final_f3("e1_t_DR#LT", 10, xaxis='#DeltaR_{e_{1}#tau}', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e1_t_DR-%s' % label) + + plotter.plot_final_f3("e2_t_DR#LT", 10, xaxis='#DeltaR_{e_{2}#tau}', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e2_t_DR-%s' % label) From d9baf706a1e215037811ecaa5eada8f7ecad5858 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 4 Oct 2013 10:48:22 -0500 Subject: [PATCH 072/192] code clean-up and add data-mc, WZ CR and 3SS plots --- wh/WHPlotterEMT.py | 578 ++++++++++++++++++++----------------------- wh/WHPlotterMMT.py | 604 +++++++++++++++++++++------------------------ 2 files changed, 545 insertions(+), 637 deletions(-) diff --git a/wh/WHPlotterEMT.py b/wh/WHPlotterEMT.py index 540499f3..b01ae424 100644 --- a/wh/WHPlotterEMT.py +++ b/wh/WHPlotterEMT.py @@ -28,6 +28,13 @@ def __init__(self): "subMass" : "subMass*" ,} super(WHPlotterEMT, self).__init__('EMT', {}, obj2_charge_mapper) +categories = { + 'LTCut' : [80, 650], + 'LTLow' : [0, 130], + 'LTHigh': [130, 650], + 'Full' : [0, 650], +} + if __name__ == "__main__": plotter = WHPlotterEMT() sqrts = plotter.sqrts @@ -35,331 +42,301 @@ def __init__(self): options,NOTUSED = parser.parse_args() if not options.dry_run: ########################################################################### - ## Zmm control plots ##################################################### + ## Ztt control plots ##################################################### ########################################################################### - plotter.set_subdir('mc_data') + plotter.set_subdir('mc_data/em') # Control Z->tautau + jet region - #plotter.plot_mc_vs_data('os/p1p2f3', 'e_m_Mass', rebin=10, xaxis='m_{e#mu} (GeV)', leftside=False) - #plotter.add_cms_blurb(sqrts) - #plotter.save('mcdata-os-p1p2f3-emMass') - - plotter.plot_mc_vs_data('os/p1p2f3', 'nTruePU', rebin=1, xaxis='True PU') + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e_m_Mass#LT', rebin=10, xaxis='m_{e#mu} (GeV)', + leftside=False, preprocess=project_x) plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-os-p1p2f3-nTruePU') - - plotter.plot('Zjets_M50', 'os/p1p2f3/nTruePU', 'nTruePU', rebin=1, xaxis='True PU') - plotter.save('zjets-os-p1p2f3-nTruePU') - - - ## plotter.plot_mc_vs_data('os/p1p2f3', 'bCSVVeto', rebin=1, xaxis='bveto') - ## plotter.add_cms_blurb(sqrts) - ## plotter.save('mcdata-os-p1p2f3-bveto') - - #plotter.plot_mc_vs_data('os/p1p2f3/w3', 'e_m_Mass', 10) - #plotter.save('mcdata-os-p1p2f3-w3-emMass') - # - #plotter.plot_mc_vs_data('os/p1f2p3', 'e_m_Mass', 10) - #plotter.save('mcdata-os-p1f2p3-emMass') - # - #plotter.plot_mc_vs_data('os/f1p2p3', 'e_m_Mass', 10) - #plotter.save('mcdata-os-p1f2p3-emMass') + plotter.save('mcdata-em-emMass') - # Check PU variables - #plotter.plot_mc_vs_data('os/p1p2f3', 'rho') - #plotter.save('mcdata-os-p1p2f3-rho') - #plotter.plot_mc_vs_data('os/p1p2f3', 'nvtx') - #plotter.save('mcdata-os-p1p2f3-nvtx') - - # Lower stat but closer to signal region - #plotter.plot_mc_vs_data('os/p1p2p3', 'rho') - #plotter.save('mcdata-os-p1p2p3-rho') - - #plotter.plot_mc_vs_data('os/p1p2p3', 'nvtx') - #plotter.save('mcdata-os-p1p2p3-nvtx') - - # Make Z->mumu + tau jet control + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'mPt#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-em-mPt') - #weighted = plotter.plot('data', 'os/p1p2f3/w3/e_m_Mass', 'hist', rebin=20, styler=make_styler(2, 'hist'), xaxis='m_{e#mu} (GeV)') - #unweighted = plotter.plot('data', 'os/p1p2p3/e_m_Mass', 'same', rebin=20, styler=make_styler(1), xaxis='m_{e#mu} (GeV)') - #weighted.SetTitle('e^{+}#mu^{-} + fake #tau_{h} est.') - #weighted.legendstyle = 'l' - #unweighted.SetTitle('e^{+}#mu^{-} + fake #tau_{h} obs.') - #unweighted.legendstyle = 'pe' - #plotter.add_legend([weighted, unweighted]) - #plotter.add_cms_blurb(sqrts) - #plotter.save('ztt-os-fr-control') + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'ePt#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-em-ePt') - #plotter.plot('data', 'os/p1p2p3/prescale', styler=make_styler(1)) - #plotter.save('ztt-os-prescale-check') + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'mAbsEta#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-em-mAbsEta') - #plotter.plot('Zjets_M50', 'os/p1p2f3/weight') - #plotter.save('ztt-mc-event-weights') - ## Check MC weights - #plotter.plot('Zjets_M50', 'os/p1p2f3/weight_nopu') - #plotter.save('ztt-mc-event-weight_nopu') + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'eAbsEta#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-em-eAbsEta') ########################################################################### - ## FR sideband MC-vs-Data ################################################ + ## WZ control plots ##################################################### ########################################################################### + plotter.set_subdir('mc_data/wz_enhanced') + + plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'e_t_Mass#LT', xaxis='m_{e#tau} (GeV)', + xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-ss-p1p2p3-enhance_wz-e_t_Mass') + + plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'm_t_Mass#LT', xaxis='m_{#mu#tau} (GeV)', + xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-ss-p1p2p3-enhance_wz-leadMass') + + plotter.set_subdir('WZ_enhanced') - #plotter.plot_mc_vs_data('ss/p1f2p3', 'mPt', 5, '#mu_{1} p_{T}', leftside=False) - #plotter.save('mcdata-ss-p1f2p3-mPt') + plotter.plot_final_wz('e_t_Mass#LT', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-e_t_Mass') - plotter.plot_mc_vs_data('ss/p1f2p3', 'subMass#LT', 20, 'Subleading mass (GeV)', leftside=False, preprocess=project_x) - plotter.save('mcdata-ss-p1f2p3-subMass') - - #plotter.plot_mc_vs_data('ss/p1p2f3', 'subMass', 20, 'Subleading mass (GeV)', leftside=False) - #plotter.save('mcdata-ss-p1p2f3-subMass') - # - plotter.plot_mc_vs_data('ss/f1p2p3', 'subMass#LT', 20, 'Subleading mass (GeV)', leftside=False, preprocess=project_x) - plotter.save('mcdata-ss-f1p2p3-subMass') + plotter.plot_final_wz('m_t_Mass#LT', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-m_t_Mass') + + plotter.plot_final_wz('ePt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-ePt') - #plotter.plot_mc_vs_data('ss/p1f2p3/w2', 'mPt', 5, '#mu_{1} p_{T}', leftside=False) - #plotter.save('mcdata-ss-p1f2p3-w2-mPt') - # - #plotter.plot_mc_vs_data('ss/p1f2p3', 'ePt', 5, 'Electron p_{T}', leftside=False) - #plotter.save('mcdata-ss-p1f2p3-ePt') - # - #plotter.plot_mc_vs_data('ss/p1f2p3/w2', 'ePt', 5, 'Electron p_{T}', leftside=False) - #plotter.save('mcdata-ss-p1f2p3-w2-ePt') - # - #plotter.plot_mc_vs_data('ss/f1p2p3', 'ePt', 5, 'Electron p_{T}', leftside=False) - #plotter.save('mcdata-ss-f1p2p3-ePt') - # - #plotter.plot_mc_vs_data('ss/f1p2p3/w1', 'ePt', 5, 'Electron p_{T}', leftside=False) - #plotter.save('mcdata-ss-f1p2p3-w2-ePt') + plotter.plot_final_wz('eJetPt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-eJetPt') + ########################################################################### ## Signal region plots ################################################ ########################################################################### plotter.set_subdir('') rebin_slim = [20]+range(30, 81, 10)+[100,130,300] - categories = { - 'LTCut' : [80, 650], - 'LTLow' : [0, 130], - 'LTHigh': [130, 650], - 'Full' : [0, 650], - } for label, proj_range in categories.iteritems(): - plotter.set_subdir('%s' % label) - plotter.plot_final('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', differential=True, - yaxis='Events / GeV', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-%s' % label) - - plotter.plot_final("e_m_Mass#LT", 20, xaxis='m_{e#mu} (GeV)' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-e_m_Mass-%s' % label) - - plotter.plot_final("m_t_Mass#LT", 20, xaxis='m_{#mu#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-m_t_Mass-%s' % label) - - plotter.plot_final("e_t_Mass#LT", 20, xaxis='m_{e#tau} (GeV)' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-e_t_Mass-%s' % label) - - plotter.plot_final('subMass#LT', 300, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) - - #pt - plotter.plot_final("mPt#LT" , 10, xaxis='p_{T#mu} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-mPt-%s' % label) - - plotter.plot_final("ePt#LT" , 10, xaxis='p_{Te} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-ePt-%s' % label) - - plotter.plot_final("mJetPt#LT" , 10, xaxis='p_{T Jet#mu} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-mJetPt-%s' % label) - - plotter.plot_final("eJetPt#LT" , 10, xaxis='p_{T Jet e} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-eJetPt-%s' % label) - - plotter.plot_final("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-tPt-%s' % label) - - #eta - plotter.plot_final("mAbsEta#LT", 10, xaxis='|#eta_{#mu}|', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-mAbsEta-%s' % label) - - plotter.plot_final("eAbsEta#LT", 10, xaxis='|#eta_{e}|' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-eAbsEta-%s' % label) - - plotter.plot_final("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-tAbsEta-%s' % label) - - #DR - plotter.plot_final("m_t_DR#LT", 10, xaxis='#DeltaR_{#mu#tau}', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-m_t_DR-%s' % label) - - plotter.plot_final("e_t_DR#LT", 10, xaxis='#DeltaR_{e#tau}' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-e_t_DR-%s' % label) - - #Jet BTag - plotter.plot_final("eJetBtag#LT", 2, xaxis='e Jet Btag' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-eJetBtag-%s' % label) - - plotter.plot_final("mJetBtag#LT", 2, xaxis='#mu Jet Btag' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-mJetBtag-%s' % label) + for tau_charge in ['tau_os', 'tau_ss']: + if tau_charge == 'tau_os': + plotter.set_subdir('%s' % label) + else: + plotter.set_subdir('%s_charge3' % label) + + plotter.plot_final('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, + yaxis='Events / GeV', show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s' % label) + + plotter.plot_final("e_m_Mass#LT", 20, xaxis='m_{e#mu} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e_m_Mass-%s' % label) + + plotter.plot_final("m_t_Mass#LT", 20, xaxis='m_{#mu#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m_t_Mass-%s' % label) + + plotter.plot_final("e_t_Mass#LT", 20, xaxis='m_{e#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e_t_Mass-%s' % label) + + plotter.plot_final('subMass#LT', 300, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) + + #pt + plotter.plot_final("mPt#LT" , 10, xaxis='p_{T#mu} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-mPt-%s' % label) + + plotter.plot_final("ePt#LT" , 10, xaxis='p_{Te} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-ePt-%s' % label) + + plotter.plot_final("mJetPt#LT" , 10, xaxis='p_{T Jet#mu} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-mJetPt-%s' % label) + + plotter.plot_final("eJetPt#LT" , 10, xaxis='p_{T Jet e} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-eJetPt-%s' % label) + + plotter.plot_final("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-tPt-%s' % label) + + #eta + plotter.plot_final("mAbsEta#LT", 10, xaxis='|#eta_{#mu}|', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-mAbsEta-%s' % label) + + plotter.plot_final("eAbsEta#LT", 10, xaxis='|#eta_{e}|' , maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-eAbsEta-%s' % label) + + plotter.plot_final("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-tAbsEta-%s' % label) + + #DR + plotter.plot_final("m_t_DR#LT", 10, xaxis='#DeltaR_{#mu#tau}', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m_t_DR-%s' % label) + + plotter.plot_final("e_t_DR#LT", 10, xaxis='#DeltaR_{e#tau}' , maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e_t_DR-%s' % label) + + #Jet BTag + plotter.plot_final("eJetBtag#LT", 2, xaxis='e Jet Btag' , maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-eJetBtag-%s' % label) + + plotter.plot_final("mJetBtag#LT", 2, xaxis='#mu Jet Btag' , maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-mJetBtag-%s' % label) plotter.plot_final('LT', 5, xaxis='LT (GeV)', maxy=15) plotter.add_cms_blurb(sqrts) plotter.save('final-LT') - #plotter.plot_final('mPt', 10) - #plotter.save('final-mPt') - # - #plotter.plot_final('ePt', 10) - #plotter.save('final-ePt') - # - #plotter.plot_final('tPt', 10) - #plotter.save('final-tPt') - # - #plotter.plot_final('mAbsEta', 10) - #plotter.save('final-mAbsEta') - # - #plotter.plot_final('eAbsEta', 10) - #plotter.save('final-eAbsEta') - # - #plotter.plot_final('tAbsEta', 10) - #plotter.save('final-tAbsEta') - - #plotter.plot_final('subMass', 20, xaxis='m_{l_{2}#tau} (GeV)') - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-subMass') - plotter.plot_final('tLeadDR', 10) plotter.save('final-tLeadDR') plotter.plot_final('tSubDR', 10) plotter.save('final-tSubDR') - #plotter.plot_final('e_t_Mass', 10) - #plotter.save('final-etMass') - - ########################################################################### - ## WZ enhanced region plots ########################################### - ########################################################################### - plotter.set_subdir('WZ_enhanced') - - #plotter.plot_final_wz('e_t_Mass', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-wz-etMass') - - #plotter.plot_final_wz('mPt', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', maxy=20) - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-wz-mPt') - - #plotter.plot_final_wz('mJetPt', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-wz-mJetPt') - ########################################################################### ## F3 enhanced region plots ########################################### ########################################################################### plotter.set_subdir('f3') for label, proj_range in categories.iteritems(): - plotter.set_subdir('f3/%s' % label) - plotter.plot_final_f3('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', differential=True, yaxis='Events / GeV') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s' % label) - - plotter.plot_final_f3('subMass#LT', [20, 40, 120, 300], xaxis='m_{l_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', differential=True, yaxis='Events / GeV') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-widebin-%s' % label) - - plotter.plot_final_f3('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s-notDifferential' % label) - - plotter.plot_final_f3("e_m_Mass#LT", 20, xaxis='m_{e#mu} (GeV)' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-e_m_Mass-%s' % label) - - plotter.plot_final_f3("m_t_Mass#LT", 20, xaxis='m_{#mu#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-m_t_Mass-%s' % label) - - plotter.plot_final_f3("e_t_Mass#LT", 20, xaxis='m_{e#tau} (GeV)' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-e_t_Mass-%s' % label) - - plotter.plot_final_f3('subMass#LT', 300, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) - - #pt - plotter.plot_final_f3("mPt#LT" , 10, xaxis='p_{T#mu} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-mPt-%s' % label) - - plotter.plot_final_f3("ePt#LT" , 10, xaxis='p_{Te} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-ePt-%s' % label) - - plotter.plot_final_f3("mJetPt#LT" , 10, xaxis='p_{T Jet#mu} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-mJetPt-%s' % label) - - plotter.plot_final_f3("eJetPt#LT" , 10, xaxis='p_{T Jet e} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-eJetPt-%s' % label) - - plotter.plot_final_f3("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tPt-%s' % label) - - #eta - plotter.plot_final_f3("mAbsEta#LT", 10, xaxis='|#eta_{#mu}|', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-mAbsEta-%s' % label) - - plotter.plot_final_f3("eAbsEta#LT", 10, xaxis='|#eta_{e}|' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-eAbsEta-%s' % label) - - plotter.plot_final_f3("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tAbsEta-%s' % label) - - #DR - plotter.plot_final_f3("m_t_DR#LT", 10, xaxis='#DeltaR_{#mu#tau}', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m_t_DR-%s' % label) - - plotter.plot_final_f3("e_t_DR#LT", 10, xaxis='#DeltaR_{e#tau}' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e_t_DR-%s' % label) - - #Jet BTag - plotter.plot_final_f3("eJetBtag#LT", 2, xaxis='e Jet Btag' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-eJetBtag-%s' % label) - - plotter.plot_final_f3("mJetBtag#LT", 2, xaxis='#mu Jet Btag' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-mJetBtag-%s' % label) + for tau_charge in ['tau_os', 'tau_ss']: + if tau_charge == 'tau_os': + plotter.set_subdir('f3/%s' % label) + else: + plotter.set_subdir('f3/%s_charge3' % label) + + plotter.plot_final_f3('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, + yaxis='Events / GeV', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s' % label) + + plotter.plot_final_f3('subMass#LT', [20, 40, 120, 300], xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, + yaxis='Events / GeV', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-widebin-%s' % label) + + plotter.plot_final_f3('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s-notDifferential' % label) + + plotter.plot_final_f3("e_m_Mass#LT", 20, xaxis='m_{e#mu} (GeV)', maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e_m_Mass-%s' % label) + + plotter.plot_final_f3("m_t_Mass#LT", 20, xaxis='m_{#mu#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m_t_Mass-%s' % label) + + plotter.plot_final_f3("e_t_Mass#LT", 20, xaxis='m_{e#tau} (GeV)' , maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e_t_Mass-%s' % label) + + plotter.plot_final_f3('subMass#LT', 300, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) + + #pt + plotter.plot_final_f3("mPt#LT" , 10, xaxis='p_{T#mu} (GeV)', maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-mPt-%s' % label) + + plotter.plot_final_f3("ePt#LT" , 10, xaxis='p_{Te} (GeV)', maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-ePt-%s' % label) + + plotter.plot_final_f3("mJetPt#LT" , 10, xaxis='p_{T Jet#mu} (GeV)', maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-mJetPt-%s' % label) + + plotter.plot_final_f3("eJetPt#LT" , 10, xaxis='p_{T Jet e} (GeV)', maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-eJetPt-%s' % label) + + plotter.plot_final_f3("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-tPt-%s' % label) + + #eta + plotter.plot_final_f3("mAbsEta#LT", 10, xaxis='|#eta_{#mu}|', maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-mAbsEta-%s' % label) + + plotter.plot_final_f3("eAbsEta#LT", 10, xaxis='|#eta_{e}|' , maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-eAbsEta-%s' % label) + + plotter.plot_final_f3("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-tAbsEta-%s' % label) + + #DR + plotter.plot_final_f3("m_t_DR#LT", 10, xaxis='#DeltaR_{#mu#tau}', maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m_t_DR-%s' % label) + + plotter.plot_final_f3("e_t_DR#LT", 10, xaxis='#DeltaR_{e#tau}' , maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e_t_DR-%s' % label) + + #Jet BTag + plotter.plot_final_f3("eJetBtag#LT", 2, xaxis='e Jet Btag' , maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-eJetBtag-%s' % label) + + plotter.plot_final_f3("mJetBtag#LT", 2, xaxis='#mu Jet Btag' , maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-mJetBtag-%s' % label) plotter.set_subdir('f3') plotter.plot_final_f3('LT', 5, xaxis='LT (GeV)', qcd_weight_fraction=0.5, show_error=True) @@ -390,19 +367,6 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-f3-mJetBtag') - - #plotter.plot_final_f3('e_t_Mass', 20, xaxis='m_{e#tau_{#mu}} (GeV)', qcd_weight_fraction=0.5, show_error=True) - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-f3-etMass') - # - #plotter.plot_final_f3('e_m_Mass', 20, xaxis='m_{e#mu} (GeV)', qcd_weight_fraction=0.5, show_error=True) - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-f3-emMass') - - #plotter.plot_final_f3('m_t_Mass', 20, xaxis='m_{#mu#tau} (GeV)', qcd_weight_fraction=0.5, show_error=True) - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-f3-emMass') - plotter.plot_final_f3('mPt#LT', 10, xaxis='p_{T#mu} (GeV)', qcd_weight_fraction=0.5, show_error=True, project=[0, 650], project_axis='X') plotter.add_cms_blurb(sqrts) plotter.save('final-f3-mPt') @@ -423,14 +387,6 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-f3-tLeadDR') - #plotter.plot_final_f3('e_t_DR', 10, xaxis='#DeltaR_{e#tau}', show_error=True) - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-f3-etDR') - # - #plotter.plot_final_f3('m_t_DR', 10, xaxis='#DeltaR_{#mu#tau}', show_error=True) - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-f3-mtDR') - plotter.plot_final_f3('subPt', 10, xaxis='p_{Tl_{2}} (GeV)', show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subPt') @@ -447,18 +403,6 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-f3-eChargeIdTight') - plotter.plot_final_f3('subMass#LT', 20, xaxis='subleading mass from projection', maxy=None, project=[0, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMassProj') - - plotter.plot_final_f3('subMass#LT', 20, xaxis='M_{l_{2}#tau} (GeV)', maxy=None, project=[0, 90], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-LTLo') - - plotter.plot_final_f3('subMass#LT', 20, xaxis='M_{l_{2}#tau} (GeV)', maxy=None, project=[90, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-LTHi') - #END OF if not options.dry_run: ########################################################################### ## Making shape file ################################################# diff --git a/wh/WHPlotterMMT.py b/wh/WHPlotterMMT.py index dfc7962b..55cf54c2 100644 --- a/wh/WHPlotterMMT.py +++ b/wh/WHPlotterMMT.py @@ -25,7 +25,8 @@ def __init__(self): rebin_slim = range(20, 81, 10)+[100, 130, 300] categories = { 'LTCut' : [80, 650], - 'LTLow' : [0, 130], + 'Full' : [0, 650], + 'LTLow' : [0, 130], 'LTHigh': [130, 650], } @@ -39,148 +40,88 @@ def __init__(self): ########################################################################### ## Zmm control plots ##################################################### ########################################################################### - plotter.set_subdir('mc_data') + plotter.set_subdir('mc_data/zmm') - # Control Z->mumu + jet region - plotter.plot_mc_vs_data('os/p1p2f3', 'm1_m2_Mass', xaxis='m_{#mu#mu} (GeV)', xrange=(60, 120)) + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'm1_m2_Mass', rebin=10, + xaxis='m_{#mu#mu} (GeV)', leftside=False) plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-os-p1p2f3-m1m2Mass') - - plotter.plot_mc_vs_data('os/p1p2p3', 'm1_m2_Mass', xaxis='m_{#mu#mu} (GeV)', xrange=(60, 120)) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-os-p1p2p3-m1m2Mass') - - #plotter.plot_mc_vs_data('ss/p1p2p3_enhance_wz', 'm2_t_Mass', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=10) - #plotter.add_cms_blurb(sqrts) - #plotter.save('mcdata-ss-p1p2p3-enhance_wz-subMass') - - plotter.plot_mc_vs_data('ss/p1p2p3_enhance_wz', 'm1_t_Mass', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=10) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1p2p3-enhance_wz-leadMass') - - plotter.plot_mc_vs_data('ss/p1f2p3_enhance_wz', 'm1_t_Mass', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=10) + plotter.save('mcdata-Zmm-m1m2Mass') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'm1Pt#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1f2p3-enhance_wz-leadMass') - - plotter.plot_mc_vs_data('ss/p1f2p3_enhance_wz/w2', 'm1_t_Mass', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=10) + plotter.save('mcdata-Zmm-m1Pt') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'm2Pt#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1f2p3-w2-enhance_wz-leadMass') - - plotter.plot_mc_vs_data('ss/p1p2p3_enhance_wz', 'subMTMass', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=10) + plotter.save('mcdata-Zmm-m2Pt') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'm1AbsEta#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1p2p3-enhance_wz-subMTMass') - - #plotter.plot_mc_vs_data('ss/p1p2p3_enhance_wz', 'm2Pt', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=5) - #plotter.add_cms_blurb(sqrts) - #plotter.save('mcdata-ss-p1p2p3-enhance_wz-m2Pt') - - plotter.compare_shapes('Zjets_M50', 'data', 'os/p1p2f3/nvtx') - plotter.save('z-vs-data-nvtx-shape') - plotter.compare_shapes('Zjets_M50', 'data', 'os/p1p2f3/rho') - plotter.save('z-vs-data-rho-shape') - - plotter.plot_mc_vs_data('os/p1p2f3/w3', 'm1_m2_Mass') - plotter.save('mcdata-os-p1p2f3-w3-m1m2Mass') - - plotter.plot_mc_vs_data('os/p1f2p3', 'm1_m2_Mass', xaxis='m_{#mu#mu} (GeV)', xrange=(60, 120)) + plotter.save('mcdata-Zmm-m1AbsEta') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'm2AbsEta#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-os-p1f2p3-m1m2Mass') - + plotter.save('mcdata-Zmm-m2AbsEta') + # Check PU variables - plotter.plot_mc_vs_data('os/p1p2f3', 'rho') - plotter.save('mcdata-os-p1p2f3-rho') + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'rho') + plotter.save('mcdata-Zmm-rho') - plotter.plot_mc_vs_data('os/p1p2f3', 'nvtx') - plotter.save('mcdata-os-p1p2f3-nvtx') - - # Lower stat but closer to signal region - plotter.plot_mc_vs_data('os/p1p2p3', 'rho') - plotter.save('mcdata-os-p1p2p3-rho') - - plotter.plot_mc_vs_data('os/p1p2p3', 'nvtx') - plotter.save('mcdata-os-p1p2p3-nvtx') - - # Make Z->mumu + tau jet control - - #antiiso_m2JetPt = plotter.plot('data', 'ss/p1f2p3/m2JetPt', 'hist', styler=make_styler(2, 'hist'), xrange=(0, 120), rebin=10) - #antiiso_m2JetPt.SetTitle("Anti-iso CR yield") - #antiiso_m2JetPt.legendstyle='l' - #antiiso_m2JetPt.GetXaxis().SetTitle("#mu_{2} Jet Pt") - #plotter.save('data-p1f2p3-m2JetPt') - - #antiiso_m1JetPt = plotter.plot('data', 'ss/f1p2p3/m1JetPt', 'hist', styler=make_styler(2, 'hist'), xrange=(0, 120), rebin=10) - #antiiso_m1JetPt.SetTitle("Anti-iso CR yield") - #antiiso_m1JetPt.legendstyle='l' - #antiiso_m1JetPt.GetXaxis().SetTitle("#mu_{1} Jet Pt") - #plotter.save('data-f1p2p3-m1JetPt') - - zmm_weighted = plotter.plot('data', 'os/p1p2f3/w3/m1_m2_Mass', 'hist', styler=make_styler(2, 'hist'), xrange=(60, 120)) - zmm_weighted.SetTitle("Z#mu#mu + fake #tau_{h} est.") - zmm_weighted.legendstyle='l' - zmm_weighted.GetXaxis().SetTitle("m_{#mu#mu} (GeV)") - - zmm_unweighted = plotter.plot('data', 'os/p1p2p3/m1_m2_Mass', 'same', styler=make_styler(1), xrange=(60, 120)) - zmm_unweighted.SetTitle("Z#mu#mu observed") - zmm_unweighted.SetTitle("Z#mu#mu + fake #tau_{h} obs.") - zmm_unweighted.legendstyle='pe' - - plotter.add_legend([zmm_weighted, zmm_unweighted]) - plotter.add_cms_blurb(sqrts) - plotter.save('zmm-os-fr-control') - - ## plotter.plot('data', 'os/p1p2p3/prescale', styler=make_styler(1)) - ## plotter.save('zmm-os-prescale-check') - - plotter.plot('Zjets_M50', 'os/p1p2f3/weight') - plotter.save('zmm-mc-event-weights') - # Check MC weights - ## plotter.plot('Zjets_M50', 'os/p1p2f3/weight_nopu') - ## plotter.save('zmm-mc-event-weight_nopu') - - plotter.plot('Zjets_M50', 'os/p1p2f3/nTruePU', 'nTruePU', rebin=1, xaxis='True PU') - plotter.save('zjets-os-p1p2f3-nTruePU') + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'nvtx') + plotter.save('mcdata-Zmm-nvtx') ########################################################################### - ## FR sideband MC-vs-Data ################################################ + ## WZ control plots ##################################################### ########################################################################### - - #plotter.plot_mc_vs_data('ss/p1f2p3', 'm1Pt', rebin=10, xaxis='#mu_{1} p_{T} (GeV)', leftside=False) - #plotter.add_cms_blurb(sqrts) - #plotter.save('mcdata-ss-p1f2p3-m1Pt') + plotter.set_subdir('mc_data/wz_enhanced') - plotter.plot_mc_vs_data('ss/p1f2p3', 'm2_t_Mass#LT', rebin=10, xaxis='m_{#mu2#tau} (GeV)', - leftside=False, preprocess=project_x) + plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'm2_t_Mass#LT', xaxis='m_{#mu#mu} (GeV)', + xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1f2p3-subMass') - - plotter.plot_mc_vs_data('os/p1p2f3', 'nvtx') - plotter.save('mcdata-os-p1p2f3-nvtx') - - plotter.plot_mc_vs_data('os/p1p2f3', 'm1_m2_Mass', rebin=10) - plotter.save('mcdata-os-p1p2f3-m1_m2_Mass') + plotter.save('mcdata-ss-p1p2p3-enhance_wz-subMass') - plotter.plot_mc_vs_data('os/p1p2f3', 'm2_t_Mass#LT', rebin=10, xaxis='m_{#mu1#mu2} (GeV)', - leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-os-p1p2f3-m1m2Mass') - # - plotter.plot_mc_vs_data('ss/f1p2p3', 'm2_t_Mass#LT', rebin=20, xaxis='m_{#mu2#tau} (GeV)', - leftside=False, preprocess=project_x) + plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'm1_t_Mass', xaxis='m_{#mu#mu} (GeV)', + xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-f1p2p3-subMass') + plotter.save('mcdata-ss-p1p2p3-enhance_wz-leadMass') - #plotter.plot_mc_vs_data('ss/f1p2p3/w1', 'm2_t_Mass', rebin=20, xaxis='m_{#mu2#tau} (GeV)', leftside=False) + #plotter.plot_mc_vs_data('ss/p1f2p3_enhance_wz', 'm1_t_Mass', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=10) #plotter.add_cms_blurb(sqrts) - #plotter.save('mcdata-ss-f1p2p3-w1-subMass') + #plotter.save('mcdata-ss-p1f2p3-enhance_wz-leadMass') # - #plotter.plot_mc_vs_data('ss/p1f2f3', 'm2AbsEta', rebin=10, xaxis='m_{#mu2#tau} (GeV)', leftside=False) + #plotter.plot_mc_vs_data('ss/p1f2p3_enhance_wz/w2', 'm1_t_Mass', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=10) #plotter.add_cms_blurb(sqrts) - #plotter.save('mcdata-ss-p1f2f3-m2AbsEta') + #plotter.save('mcdata-ss-p1f2p3-w2-enhance_wz-leadMass') # - #plotter.plot_mc_vs_data('ss/p1f2p3', 'm2AbsEta', rebin=10, xaxis='m_{#mu2#tau} (GeV)', leftside=False) + #plotter.plot_mc_vs_data('ss/p1p2p3_enhance_wz', 'subMTMass', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=10) #plotter.add_cms_blurb(sqrts) - #plotter.save('mcdata-ss-p1f2p3-m2AbsEta') + #plotter.save('mcdata-ss-p1p2p3-enhance_wz-subMTMass') + + plotter.set_subdir('WZ_enhanced') + + plotter.plot_final_wz('m1_t_Mass', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-leadMass') + + plotter.plot_final_wz('m2_t_Mass#LT', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-subMass') + + plotter.plot_final_wz('m2Pt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-m2Pt') + + plotter.plot_final_wz('m2JetPt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-m2JetPt') ########################################################################### @@ -190,112 +131,131 @@ def __init__(self): #rebin_slim = range(20, 91, 10)+[110,200] for label, proj_range in categories.iteritems(): - plotter.set_subdir('%s' % label) - plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', differential=True, - yaxis='Events / GeV', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-%s' % label) - - plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', - project=proj_range, project_axis='X', - yaxis='Events', show_error=True, x_range=[0,199], maxy=15.6) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-const_bin-%s' % label, verbose=True) - - data_view = plotter.make_signal_views(unblinded=(not plotter.blind), - qcd_weight_fraction=0.5, - rebin=20, project=proj_range, project_axis='X')['data'] - data_hist = data_view.Get('m2_t_Mass#LT') - data_hist.GetXaxis().SetRangeUser(0,200) - data_hist.GetXaxis().SetRangeUser(0,15.6) - data_hist.SetMarkerColor(2) - data_hist.Draw() - plotter.add_cms_blurb(sqrts) - plotter.save('bareData-subMass-const_bin-%s' % label) - - plotter.plot_final('m2_t_Mass#LT', 300, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-%s-counting' % label) #, dotc=True, dotroot=True) - - #pt - plotter.plot_final("m1Pt#LT" , 10, xaxis='p_{T#mu_{1}} (GeV)', - maxy=None, project=proj_range, project_axis='X', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1Pt-%s' % label) - - plotter.plot_final("m2Pt#LT" , 10, xaxis='p_{T#mu_{2}} (GeV)', maxy=None, - project=proj_range, project_axis='X', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2Pt-%s' % label) - - plotter.plot_final("m1JetPt#LT" , 10, xaxis='p_{T Jet #mu_{1}} (GeV)', maxy=None, - project=proj_range, project_axis='X', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1JetPt-%s' % label) - - plotter.plot_final("m2JetPt#LT" , 10, xaxis='p_{T Jet #mu_{2}} (GeV)', maxy=None, - project=proj_range, project_axis='X', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2JetPt-%s' % label) - - plotter.plot_final("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-tPt-%s' % label) - - #eta - plotter.plot_final("m1AbsEta#LT", 10, xaxis='|#eta_{#mu_{1}}|', maxy=None, - project=proj_range, project_axis='X', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1AbsEta-%s' % label) - - plotter.plot_final("m2AbsEta#LT", 10, xaxis='|#eta_{#mu_{2}}|' , maxy=None, - project=proj_range, project_axis='X', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2AbsEta-%s' % label) - - plotter.plot_final("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, - project=proj_range, project_axis='X', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-tAbsEta-%s' % label) - - #DR - plotter.plot_final("m1_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{1}#tau}', maxy=None, - project=proj_range, project_axis='X', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1_t_DR-%s' % label) - - plotter.plot_final("m2_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, - project=proj_range, project_axis='X', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2_t_DR-%s' % label) - - #Jet BTag - - #from pdb import set_trace; set_trace() - plotter.plot_final("m2JetBtag#LT", [-100, -40, 20, 100], xaxis='#mu_{2} Jet Btag' , - maxy=None, project=proj_range, project_axis='X', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2JetBtag-%s' % label, dotroot=True) - - plotter.plot_final("m1JetBtag#LT", 1, xaxis='#mu_{1} Jet Btag' , maxy=None, - project=proj_range, project_axis='X', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1JetBtag-%s' % label) - - plotter.plot_final("m2JetCSVBtag#LT", 1, xaxis='#mu_{2} Jet CSV Btag' , maxy=None, - project=proj_range, project_axis='X', x_range=[0,1], show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2JetCSVBtag-%s' % label, dotroot=True) - - plotter.plot_final("m1JetCSVBtag#LT", 1, xaxis='#mu_{1} Jet CSV Btag' , maxy=None, - project=proj_range, project_axis='X', x_range=[0,1], show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1JetCSVBtag-%s' % label) - - raise ValueError + for tau_charge in ['tau_os', 'tau_ss']: + if tau_charge == 'tau_os': + plotter.set_subdir('%s' % label) + else: + plotter.set_subdir('%s_charge3' % label) + + plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, + yaxis='Events / GeV', show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s' % label) + + plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', + project=proj_range, project_axis='X', + yaxis='Events', show_error=True, x_range=[0,199], + maxy=15.6, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-const_bin-%s' % label, verbose=True) + + #data_view = plotter.make_signal_views(unblinded=(not plotter.blind), + # qcd_weight_fraction=0.5, + # rebin=20, project=proj_range, project_axis='X')['data'] + #data_hist = data_view.Get('m2_t_Mass#LT') + #data_hist.GetXaxis().SetRangeUser(0,200) + #data_hist.GetXaxis().SetRangeUser(0,15.6) + #data_hist.SetMarkerColor(2) + #data_hist.Draw() + #plotter.add_cms_blurb(sqrts) + #plotter.save('bareData-subMass-const_bin-%s' % label) + + plotter.plot_final('m2_t_Mass#LT', 300, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s-counting' % label) #, dotc=True, dotroot=True) + + #pt + plotter.plot_final("m1Pt#LT" , 10, xaxis='p_{T#mu_{1}} (GeV)', + maxy=None, project=proj_range, project_axis='X', + show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m1Pt-%s' % label) + + plotter.plot_final("m2Pt#LT" , 10, xaxis='p_{T#mu_{2}} (GeV)', maxy=None, + project=proj_range, project_axis='X', + show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m2Pt-%s' % label) + + plotter.plot_final("m1JetPt#LT" , 10, xaxis='p_{T Jet #mu_{1}} (GeV)', + maxy=None, project=proj_range, project_axis='X', + show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m1JetPt-%s' % label) + + plotter.plot_final("m2JetPt#LT" , 10, xaxis='p_{T Jet #mu_{2}} (GeV)', + maxy=None, project=proj_range, project_axis='X', + show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m2JetPt-%s' % label) + + plotter.plot_final("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-tPt-%s' % label) + + #eta + plotter.plot_final("m1AbsEta#LT", 10, xaxis='|#eta_{#mu_{1}}|', maxy=None, + project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m1AbsEta-%s' % label) + + plotter.plot_final("m2AbsEta#LT", 10, xaxis='|#eta_{#mu_{2}}|' , maxy=None, + project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m2AbsEta-%s' % label) + + plotter.plot_final("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, + project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-tAbsEta-%s' % label) + + #DR + plotter.plot_final("m1_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{1}#tau}', maxy=None, + project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m1_t_DR-%s' % label) + + plotter.plot_final("m2_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, + project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m2_t_DR-%s' % label) + + #Jet BTag + + #from pdb import set_trace; set_trace() + plotter.plot_final("m2JetBtag#LT", [-100, -40, 20, 100], xaxis='#mu_{2} Jet Btag' , + maxy=None, project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m2JetBtag-%s' % label, dotroot=True) + + plotter.plot_final("m1JetBtag#LT", 1, xaxis='#mu_{1} Jet Btag' , maxy=None, + project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m1JetBtag-%s' % label) + + plotter.plot_final("m2JetCSVBtag#LT", 1, xaxis='#mu_{2} Jet CSV Btag' , maxy=None, + project=proj_range, project_axis='X', x_range=[0,1], show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m2JetCSVBtag-%s' % label, dotroot=True) + + plotter.plot_final("m1JetCSVBtag#LT", 1, xaxis='#mu_{1} Jet CSV Btag' , maxy=None, + project=proj_range, project_axis='X', x_range=[0,1], show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m1JetCSVBtag-%s' % label) + #from pdb import set_trace; set_trace() plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=[0, 130], project_axis='X', differential=True, yaxis='Events / GeV') @@ -368,105 +328,109 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-m2Iso') - ########################################################################### - ## WZ enhanced region plots ########################################### - ########################################################################### - plotter.set_subdir('WZ_enhanced') - - plotter.plot_final_wz('m1_t_Mass', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-leadMass') - - #plotter.plot_final_wz('m2Pt', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-wz-m2Pt') - # - #plotter.plot_final_wz('m2JetPt', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-wz-m2JetPt') - ########################################################################### ## F3 enhanced region plots ########################################### ########################################################################### - categories = { - 'LTCut' : [80, 650], - 'LTLow' : [0, 130], - 'LTHigh': [130, 650], - } for label, proj_range in categories.iteritems(): - plotter.set_subdir('f3/%s' % label) - plotter.plot_final_f3('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', - maxy=None, project=proj_range, project_axis='X', differential=True, - show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s' % label) - - plotter.plot_final_f3('m2_t_Mass#LT', 300, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) - - #pt - plotter.plot_final_f3("m1Pt#LT" , 10, xaxis='p_{T#mu_{1}} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1Pt-%s' % label) - - plotter.plot_final_f3("m2Pt#LT" , 10, xaxis='p_{T#mu_{2}} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2Pt-%s' % label) - - plotter.plot_final_f3("m1JetPt#LT" , 10, xaxis='p_{T Jet #mu_{1}} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1JetPt-%s' % label) - - plotter.plot_final_f3("m2JetPt#LT" , 10, xaxis='p_{T Jet #mu_{2}} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2JetPt-%s' % label) - - plotter.plot_final_f3("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tPt-%s' % label) - - #eta - plotter.plot_final_f3("m1AbsEta#LT", 10, xaxis='|#eta_{#mu_{1}}|', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1AbsEta-%s' % label) - - plotter.plot_final_f3("m2AbsEta#LT", 10, xaxis='|#eta_{#mu_{2}}|' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2AbsEta-%s' % label) - - plotter.plot_final_f3("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tAbsEta-%s' % label) - - #DR - plotter.plot_final_f3("m1_t_DR#LT", 5, xaxis='#DeltaR_{#mu_{1}#tau}', maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1_t_DR-%s' % label) - - plotter.plot_final_f3("m2_t_DR#LT", 5, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2_t_DR-%s' % label) - - #Jet BTag + for tau_charge in ['tau_os', 'tau_ss']: + if tau_charge == 'tau_os': + plotter.set_subdir('f3/%s' % label) + else: + plotter.set_subdir('f3/%s_charge3' % label) + plotter.plot_final_f3('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', + maxy=None, project=proj_range, project_axis='X', differential=True, + show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s' % label) + + plotter.plot_final_f3('m2_t_Mass#LT', 300, xaxis='m_{#mu_{2}#tau} (GeV)', + maxy=None, project=proj_range, project_axis='X', + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) + + #pt + plotter.plot_final_f3("m1Pt#LT" , 10, xaxis='p_{T#mu_{1}} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m1Pt-%s' % label) + + plotter.plot_final_f3("m2Pt#LT" , 10, xaxis='p_{T#mu_{2}} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m2Pt-%s' % label) + + plotter.plot_final_f3("m1JetPt#LT" , 10, xaxis='p_{T Jet #mu_{1}} (GeV)', + maxy=None, project=proj_range, project_axis='X', + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m1JetPt-%s' % label) + + plotter.plot_final_f3("m2JetPt#LT" , 10, xaxis='p_{T Jet #mu_{2}} (GeV)', + maxy=None, project=proj_range, project_axis='X', + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m2JetPt-%s' % label) + + plotter.plot_final_f3("tPt#LT", 10, xaxis='p_{T#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-tPt-%s' % label) + + #eta + plotter.plot_final_f3("m1AbsEta#LT", 10, xaxis='|#eta_{#mu_{1}}|', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m1AbsEta-%s' % label) + + plotter.plot_final_f3("m2AbsEta#LT", 10, xaxis='|#eta_{#mu_{2}}|', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m2AbsEta-%s' % label) + + plotter.plot_final_f3("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-tAbsEta-%s' % label) + + #DR + plotter.plot_final_f3("m1_t_DR#LT", 5, xaxis='#DeltaR_{#mu_{1}#tau}', + maxy=None, project=proj_range, project_axis='X', + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m1_t_DR-%s' % label) + + plotter.plot_final_f3("m2_t_DR#LT", 5, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m2_t_DR-%s' % label) + + #Jet BTag - #from pdb import set_trace; set_trace() - plotter.plot_final_f3("m2JetBtag#LT", [-100, -40, 20, 100], xaxis='#mu_{2} Jet Btag' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2JetBtag-%s' % label, dotroot=True) - - plotter.plot_final_f3("m1JetBtag#LT", 1, xaxis='#mu_{1} Jet Btag' , maxy=None, project=proj_range, project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1JetBtag-%s' % label) - - plotter.plot_final_f3("m2JetCSVBtag#LT", 1, xaxis='#mu_{2} Jet CSV Btag' , maxy=None, project=proj_range, project_axis='X', x_range=[0,1]) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2JetCSVBtag-%s' % label, dotroot=True) - - plotter.plot_final_f3("m1JetCSVBtag#LT", 1, xaxis='#mu_{1} Jet CSV Btag' , maxy=None, project=proj_range, project_axis='X', x_range=[0,1]) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1JetCSVBtag-%s' % label) + #from pdb import set_trace; set_trace() + plotter.plot_final_f3("m2JetBtag#LT", [-100, -40, 20, 100], xaxis='#mu_{2} Jet Btag', + maxy=None, project=proj_range, project_axis='X', + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m2JetBtag-%s' % label, dotroot=True) + + plotter.plot_final_f3("m1JetBtag#LT", 1, xaxis='#mu_{1} Jet Btag' , maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m1JetBtag-%s' % label) + + plotter.plot_final_f3("m2JetCSVBtag#LT", 1, xaxis='#mu_{2} Jet CSV Btag', maxy=None, + project=proj_range, project_axis='X', x_range=[0,1], + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m2JetCSVBtag-%s' % label, dotroot=True) + + plotter.plot_final_f3("m1JetCSVBtag#LT", 1, xaxis='#mu_{1} Jet CSV Btag', maxy=None, + project=proj_range, project_axis='X', x_range=[0,1], + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m1JetCSVBtag-%s' % label) plotter.set_subdir('f3') From 8f746602b9c081495fd9c6fd3fbaac4d6500d81b Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 4 Oct 2013 10:49:09 -0500 Subject: [PATCH 073/192] bugfix and reshuffle the code to make it easier to understand --- wh/mcCorrectors.py | 87 +++++++++++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 31 deletions(-) diff --git a/wh/mcCorrectors.py b/wh/mcCorrectors.py index 13fde937..483b42e5 100644 --- a/wh/mcCorrectors.py +++ b/wh/mcCorrectors.py @@ -8,6 +8,13 @@ is7TeV = bool('7TeV' in os.environ['jobid']) print "Is 7TeV:", is7TeV + +######################################################################## +## +## PILE UP CORRECTIONS +## +######################################################################## + # Make PU corrector from expected data PU distribution # PU corrections .root files from pileupCalc.py pu_distributions = { @@ -20,27 +27,6 @@ print "Using S6_600bins PU weights for HWW3l" mc_pu_tag = 'S6_600bins' -#Makes appropriate correction function for electrons or muons according to run period -mu_pog_2011_id = MuonPOGCorrections.make_muon_pog_PFTight_2011() -mu_pog_2011_iso = MuonPOGCorrections.make_muon_pog_PFRelIsoDB02_2011() -muon_pog_IsoID = (lambda pt, eta: mu_pog_2011_id(pt,eta)*mu_pog_2011_iso(pt,eta)) if is7TeV else H2TauCorrections.correct_mu_idiso_2012 -electron_corrections = H2TauCorrections.correct_e_idiso_2011 if is7TeV else H2TauCorrections.correct_e_idiso_2012 - -#scale factors for double muon trigger, too messy to make only in one line, the function will take care of this -# takes etas of muons -muon_pog_Mu17Mu8_2011 = MuonPOGCorrections.muon_pog_Mu17Mu8_eta_eta_2011 -muon_pog_Mu17Mu8_Mu17_2012 = MuonPOGCorrections.make_muon_pog_Mu17Mu8_Mu17_2012() -muon_pog_Mu17Mu8_Mu8_2012 = MuonPOGCorrections.make_muon_pog_Mu17Mu8_Mu8_2012() -muon_h2tau_Mu17Mu8_2012 = H2TauCorrections.correct_double_muon_trg_2012 - - -#Scale factors for mueg triggers, that's better -correct_mueg_mu = H2TauCorrections.correct_mueg_mu_2011 if is7TeV else H2TauCorrections.correct_mu_idiso_2012 -correct_mueg_e = H2TauCorrections.correct_mueg_e_2011 if is7TeV else H2TauCorrections.correct_mueg_e_2012 - -#Double electrons scale factors -correct_double_electron = H2TauCorrections.correct_double_electron_trg_2011 if is7TeV else H2TauCorrections.correct_double_electron_trg_2012 - def make_puCorrector(dataset, kind=None): 'makes PU reweighting according to the pu distribution of the reference data and the MC, MC distribution can be forced' if not kind: @@ -51,7 +37,55 @@ def make_puCorrector(dataset, kind=None): raise KeyError('dataset not present. Please check the spelling or add it to mcCorrectors.py') ## def force_pu_distribution(kind): ## pu_corrector = PileupWeight.PileupWeight( kind, *pu_distributions) - + + + +######################################################################## +## +## TRIGGER +## +######################################################################## + +#DOUBLE MU +muon_pog_Mu17Mu8_2011 = MuonPOGCorrections.muon_pog_Mu17Mu8_eta_eta_2011 +#muon_pog_Mu17Mu8_Mu17_2012 = MuonPOGCorrections.make_muon_pog_Mu17Mu8_Mu17_2012() +#muon_pog_Mu17Mu8_Mu8_2012 = MuonPOGCorrections.make_muon_pog_Mu17Mu8_Mu8_2012() +muon_h2tau_Mu17Mu8_2012 = H2TauCorrections.correct_double_muon_trg_2012 + +def double_muon_trigger(row,m1,m2): + 'makes scale factor for double mu trigger' + if is7TeV: + return muon_pog_Mu17Mu8_2011(getattr(row, '%sEta' % m1), getattr(row, '%sEta' % m2) ) + else: + return muon_h2tau_Mu17Mu8_2012(getattr(row, '%sPt' % m1), getattr(row, '%sEta' % m1), getattr(row, '%sPt' % m2), getattr(row, '%sEta' % m2)) + + +#MUEG +correct_mueg_mu = H2TauCorrections.correct_mueg_mu_2011 if is7TeV else H2TauCorrections.correct_mueg_mu_2012 +correct_mueg_e = H2TauCorrections.correct_mueg_e_2011 if is7TeV else H2TauCorrections.correct_mueg_e_2012 + +#Double electrons scale factors +correct_double_electron = H2TauCorrections.correct_double_electron_trg_2011 if is7TeV else H2TauCorrections.correct_double_electron_trg_2012 + +def double_electron_trigger(row): + return correct_double_electron( row.e1Pt, row.e1Eta, row.e2Pt, row.e2Eta ) + + + +######################################################################## +## +## ID/ISO +## +######################################################################## + + +#Makes appropriate correction function for electrons or muons according to run period +mu_pog_2011_id = MuonPOGCorrections.make_muon_pog_PFTight_2011() +mu_pog_2011_iso = MuonPOGCorrections.make_muon_pog_PFRelIsoDB02_2011() +muon_pog_IsoID = (lambda pt, eta: mu_pog_2011_id(pt,eta)*mu_pog_2011_iso(pt,eta)) if is7TeV else H2TauCorrections.correct_mu_idiso_2012 +electron_corrections = H2TauCorrections.correct_e_idiso_2011 if is7TeV else H2TauCorrections.correct_e_idiso_2012 +electron_tight_corrections = H2TauCorrections.correct_e_TIGHTidiso_2011 if is7TeV else H2TauCorrections.correct_e_TIGHTidiso_2012 + def get_muon_corrections(row,*args): 'makes corrections to iso and id of muons' @@ -72,12 +106,3 @@ def get_electron_corrections(row,*args): ret *= electron_corrections(pt,abseta) return ret -def double_muon_trigger(row,m1,m2): - 'makes scale factor for double mu trigger' - if is7TeV: - return muon_pog_Mu17Mu8_2011(getattr(row, '%sEta' % m1), getattr(row, '%sEta' % m2) ) - else: - return muon_h2tau_Mu17Mu8_2012(getattr(row, '%sPt' % m1), getattr(row, '%sEta' % m1), getattr(row, '%sPt' % m2), getattr(row, '%sEta' % m2)) - -def double_electron_trigger(row): - return correct_double_electron( row.e1Pt, row.e1Eta, row.e2Pt, row.e2Eta ) From ac309297f9b5fa175d7094b1d2d8cf50893fdd6a Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 30 Oct 2013 04:13:03 -0500 Subject: [PATCH 074/192] post sync commit. Added DR requirement, new trigger matching and AntiMuon tight patch --- wh/WHAnalyzeMMT.py | 81 ++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 50 deletions(-) diff --git a/wh/WHAnalyzeMMT.py b/wh/WHAnalyzeMMT.py index cdb1fca6..a9cc9b47 100755 --- a/wh/WHAnalyzeMMT.py +++ b/wh/WHAnalyzeMMT.py @@ -23,20 +23,23 @@ if len(optimizer_keys) > 1: grid_search[key] = optimizer.grid_search[key] -for key in optimizer_keys: - frfits.highpt_mu_fr.__activate__(optimizer.grid_search[key]['leading_iso']) - frfits.highpt_mu_qcd_fr.__activate__(optimizer.grid_search[key]['leading_iso']) - frfits.lowpt_mu_fr.__activate__(optimizer.grid_search[key]['subleading_iso']) - frfits.lowpt_mu_qcd_fr.__activate__(optimizer.grid_search[key]['subleading_iso']) +NO_HISTO_FILL = ('NO_HISTO_FILL' in os.environ) and eval(os.environ['NO_HISTO_FILL']) +if not NO_HISTO_FILL: + for key in optimizer_keys: + frfits.highpt_mu_fr.__activate__(optimizer.grid_search[key]['leading_iso']) + frfits.highpt_mu_qcd_fr.__activate__(optimizer.grid_search[key]['leading_iso']) + frfits.lowpt_mu_fr.__activate__(optimizer.grid_search[key]['subleading_iso']) + frfits.lowpt_mu_qcd_fr.__activate__(optimizer.grid_search[key]['subleading_iso']) +SYNC = ('SYNC' in os.environ) and eval(os.environ['SYNC']) ################################################################################ #### Analysis logic ############################################################ ################################################################################ class WHAnalyzeMMT(WHAnalyzerBase): - tree = 'mmt/final/Ntuple' + tree = 'mmt/final/Ntuple' if not SYNC else 'Ntuple' def __init__(self, tree, outfile, **kwargs): self.channel = 'MMT' super(WHAnalyzeMMT, self).__init__(tree, outfile, MuMuTauTree, **kwargs) @@ -85,6 +88,7 @@ def f(row, weight): self.hfunc['subMTMass'] = lambda row, weight: (row.m2_t_Mass, weight) if row.m1MtToMET > row.m2MtToMET else (row.m1_t_Mass, weight) #maps the name of non-trivial histograms to a function to get the proper value, the function MUST have two args (evt and weight). Used in WHAnalyzerBase.fill_histos later self.hfunc['pt_ratio' ] = lambda row, weight: (row.m2Pt/row.m1Pt, weight) + self.hfunc['DEBUG'] = lambda row, weight: (array("f", [row.run, row.lumi, row.m2_t_Mass, row.LT, row.m1Pt, row.m2Pt, row.tPt] ), None) self.pucorrector = mcCorrectors.make_puCorrector('doublemu') @@ -100,7 +104,8 @@ def book_histos(self, folder): if len(self.grid_search.keys()) == 1: self.book(folder, "m2_t_Mass#LT" , "subleadingMass", 300, 0, 300, nLTBins, LTBinning, type=ROOT.TH2F) - self.book(folder, "Event_ID", "Event ID", 'run:lumi:evt1:evt2', type=ROOT.TNtuple) + #self.book(folder, "Event_ID", "Event ID", 'run:lumi:evt1:evt2', type=ROOT.TNtuple) + self.book(folder, "DEBUG", "DEBUG", 'run:lumi:m2_t_Mass:LT:m1Pt:m2Pt:tPt', type=ROOT.TNtuple) #Pt self.book(folder, "m1Pt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) self.book(folder, "tPt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) @@ -128,66 +133,56 @@ def book_histos(self, folder): self.book(folder, "m1MtToMET#LT", "Muon 2 Pt", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) self.book(folder, "m2MtToMET#LT", "Muon 2 Pt", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) + #tau ISO + self.book(folder, "tRawIso3Hits#LT", "Muon 2 Pt", 200, 0, 200, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "tRawIsoMVA2#LT", "Muon 2 Pt" , 200, -1, -1, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "m2RelPFIsoDB", "m2Iso", 100, 0, 0.3) self.book(folder, "m1_t_Mass", "leadingMass", 200, 0, 200) self.book(folder, "m1_m2_Mass", "Muon 1-2 Mass", 120, 0, 120) - #self.book(folder, "m2_t_DR", "m2_t_DR", 100, 0, 5) - #self.book(folder, "m1_t_DR", "m1_t_DR", 100, 0, 5) - #self.book(folder, "m1JetPt", "Muon 1 Jet Pt", 100, 0, 200) - #self.book(folder, "m2JetPt", "Muon 2 Jet Pt", 100, 0, 200) # Rank muons by less MT to MET, for WZ control region self.book(folder, "weight", "Event weight", 100, 0, 5) self.book(folder, "rho", "Fastjet #rho", 100, 0, 25) self.book(folder, "nvtx", "Number of vertices", 31, -0.5, 30.5) - #self.book(folder, "m1Pt", "Muon 1 Pt", 100, 0, 100) - #self.book(folder, "m2Pt", "Muon 2 Pt", 100, 0, 100) - #self.book(folder, "m1AbsEta", "Muon 1 AbsEta", 100, 0, 2.4) - #self.book(folder, "m2AbsEta", "Muon 2 AbsEta", 100, 0, 2.4) - #self.book(folder, "tPt", "Tau Pt", 100, 0, 100) - #self.book(folder, "tAbsEta", "Tau AbsEta", 100, 0, 2.3) self.book(folder, "subMTMass", "subMTMass", 200, 0, 200) - #self.book(folder, "tDecayMode", "Tau AbsEta", 15, -0.5, 14.5) self.book(folder, "nTruePU", "NPU", 62, -1.5, 60.5) self.book(folder, "m1DZ", "m1DZ", 100, 0., 1) self.book(folder, "m2DZ", "m2DZ", 100, 0., 1) self.book(folder, "tDZ" , "tDZ" , 100, 0., 1) self.book(folder, "doubleMuPrescale", "HLT prescale", 26, -5.5, 20.5) - #let's look for osme other possible selections - #self.book(folder, "pt_ratio" , "pt_ratio" , 100, 0, 1) - #self.book(folder, "tToMETDPhi" , "tToMETDPhi" , 100, 0, 4) - #self.book(folder, "Mass" , "mass" , 800, 0, 800 ) - #self.book(folder, "type1_pfMetEt" , "metEt" , 300, 0, 2000) - def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = 0.): ''' Preselection applied to events. Excludes FR object IDs and sign cut. ''' + # + # NEW EXPLICIT CUT, BEFORE IT WAS IMPLICIT AND MADE WHILE PLOTTING! + # + if row.m1_t_DR < 0.5 or row.m2_t_DR < 0.5 or row.m1_m2_DR < 0.5: return False + cut_flow_trk.Fill('DR separation') + + if row.m2_t_Mass < 20: return False + cut_flow_trk.Fill('sub mass cut') + double_mu_pass = row.doubleMuPass and \ row.m1MatchesDoubleMuPaths > 0 and \ row.m2MatchesDoubleMuPaths > 0 double_muTrk_pass = row.doubleMuTrkPass and \ - row.m1MatchesDoubleMuTrkPaths > 0 and \ - row.m2MatchesDoubleMuTrkPaths > 0 + row.m1MatchesMu17TrkMu8Path > 0 and \ + row.m2MatchesMu17TrkMu8Path > 0 if not ( double_mu_pass or double_muTrk_pass ): return False cut_flow_trk.Fill('trigger') - #TEST - if row.m2_t_DR < 1: return False - if row.m1Pt < row.m2Pt: return False if row.m1Pt < 20: return False if not selections.muSelection(row, 'm1'): return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag) cut_flow_trk.Fill('obj1 Presel') - #cut_flow_trk.Fill('pt requirements 1', 'eta requirements 1', 'MissingHits 1', 'HasConversion 1', 'JetBtag 1', 'DZ 1',) - if not selections.muSelection(row, 'm2'): return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag) cut_flow_trk.Fill('obj2 Presel') - #cut_flow_trk.Fill('pt requirements 2', 'eta requirements 2', 'MissingHits 2', 'HasConversion 2', 'JetBtag 2', 'DZ 2',) if not selections.tauSelection(row, 't'): return False #applies basic selection (eta, pt > 20, DZ) if not row.tAntiElectronMVA3Loose: return False @@ -197,24 +192,10 @@ def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = if row.LT < LT_threshold: return False cut_flow_trk.Fill('LT') - #if row.m1_m2_SS and row.m1_t_SS: return False #remove three SS leptons if row.m1_m2_Mass < 20: return False - if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes - cut_flow_trk.Fill('vetos') - #cut_flow_trk.Fill('ChargeIdTight') - cut_flow_trk.Fill('charge_fakes') #no charge fakes here - - #FIXME: ONLY FOR CUT-FLOW PRODUCTION - #if not row.m1PFIDTight: return False - #cut_flow_trk.Fill('obj1 ID') - #if not selections.lepton_id_iso(row, 'm1', 'h2taucuts'): return False - #cut_flow_trk.Fill('obj1 Iso') - #if not row.m2PFIDTight: return False - #cut_flow_trk.Fill('obj2 ID') - #if not selections.lepton_id_iso(row, 'm2', 'h2taucuts'): return False - #cut_flow_trk.Fill('obj2 Iso') - #if not row.tLooseIso3Hits: return False - #cut_flow_trk.Fill('obj3 IDIso') + cut_flow_trk.Fill('dilepton mass cut') + + if not selections.vetos(row, cut_flow_trk): return False #applies mu bjet e additional tau vetoes return True @@ -247,7 +228,7 @@ def obj3_id(row, tauId=None, LT_threshold = 80., taupt_thr = 0.): @staticmethod def anti_wz(row): - return row.tAntiMuonTight # and not row.tMuOverlap + return bool(row.tAntiMuonTight and (( row.tDecayMode == 0 and row.tLeadChargeCandEMFraction > 0.2 ) or row.tDecayMode <> 0)) # and not row.tMuOverlap def enhance_wz(self, row): # Require the "tau" to be a muon, and require the third muon From a632b44f8bc1a901d2a4baa86ff075fa2778d7bd Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 30 Oct 2013 04:14:56 -0500 Subject: [PATCH 075/192] half-sync commit. Added stuff to make sync easier, clened up the code. Added DR cut and AntiMuon tight patch --- wh/WHAnalyzeEET.py | 88 ++++++++++++------------------------- wh/WHAnalyzeEMT.py | 107 ++++++++++++++++----------------------------- 2 files changed, 64 insertions(+), 131 deletions(-) diff --git a/wh/WHAnalyzeEET.py b/wh/WHAnalyzeEET.py index f0635cb7..28c035bd 100755 --- a/wh/WHAnalyzeEET.py +++ b/wh/WHAnalyzeEET.py @@ -23,11 +23,16 @@ if len(optimizer_keys) > 1: grid_search[key] = optimizer.grid_search[key] -for key in optimizer_keys: - frfits.highpt_ee_fr.__activate__(optimizer.grid_search[key]['leading_iso']) - frfits.highpt_ee_qcd_fr.__activate__(optimizer.grid_search[key]['leading_iso']) - frfits.lowpt_ee_fr.__activate__(optimizer.grid_search[key]['subleading_iso']) - frfits.lowpt_ee_qcd_fr.__activate__(optimizer.grid_search[key]['subleading_iso']) +NO_HISTO_FILL = ('NO_HISTO_FILL' in os.environ) and eval(os.environ['NO_HISTO_FILL']) + +if not NO_HISTO_FILL: + for key in optimizer_keys: + frfits.highpt_ee_fr.__activate__(optimizer.grid_search[key]['leading_iso']) + frfits.highpt_ee_qcd_fr.__activate__(optimizer.grid_search[key]['leading_iso']) + frfits.lowpt_ee_fr.__activate__(optimizer.grid_search[key]['subleading_iso']) + frfits.lowpt_ee_qcd_fr.__activate__(optimizer.grid_search[key]['subleading_iso']) + +SYNC = ('SYNC' in os.environ) and eval(os.environ['SYNC']) #mtr = frfits.mt_likelihood_ratio ################################################################################ @@ -35,7 +40,7 @@ ################################################################################ class WHAnalyzeEET(WHAnalyzerBase): - tree = 'eet/final/Ntuple' + tree = 'eet/final/Ntuple' if not SYNC else 'Ntuple' def __init__(self, tree, outfile, **kwargs): self.channel = 'EET' super(WHAnalyzeEET, self).__init__(tree, outfile, EETauTree, **kwargs) @@ -183,11 +188,9 @@ def book_histos(self, folder): self.book(folder, "e1JetBtag#LT", "Muon 2 Pt", 30, -10, 5, 60, 0, 600, type=ROOT.TH2F) self.book(folder, "e2JetBtag#LT", "Muon 2 Pt", 30, -10, 5, 60, 0, 600, type=ROOT.TH2F) - #self.book(folder, prefix+"e2_t_Mass#faking_prob" , "subleadingMass", 200, 0, 200, 1100, 0., 1.1, type=ROOT.TH2F) - #self.book(folder, prefix+"e2_t_Mass#log_prob" , "subleadingMass", 200, 0, 200, 1000, -10, 1, type=ROOT.TH2F) - # - #self.book(folder, prefix+'faking_prob' , "", 1100, 0., 1.1) - #self.book(folder, prefix+'log_prob' , "", 1000, -10, 1) + #tau ISO + self.book(folder, "tRawIso3Hits#LT", "Muon 2 Pt", 200, 0, 200, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "tRawIsoMVA2#LT", "Muon 2 Pt" , 200, -1, -1, nLTBins, LTBinning, type=ROOT.TH2F) self.book(folder, "e2RelPFIsoDB", "e2RelPFIsoDB", 30, 0, 0.3) self.book(folder, "e1RelPFIsoDB", "e1RelPFIsoDB", 30, 0, 0.3) @@ -228,6 +231,12 @@ def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = Excludes FR object IDs and sign cut. ''' + if row.e1_t_DR < 0.5 or row.e2_t_DR < 0.5 or row.e1_e2_DR < 0.5: return False + cut_flow_trk.Fill('DR separation') + + if row.e2_t_Mass < 20: return False + cut_flow_trk.Fill('sub mass cut') + if not row.doubleEPass: return False if not (row.e1MatchesDoubleEPath > 0 and \ row.e2MatchesDoubleEPath > 0): return False @@ -236,35 +245,9 @@ def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = if row.e1Pt < 20: return False if not selections.eSelection(row, 'e1'): return False cut_flow_trk.Fill('obj1 Presel') - #FIXME - #if row.e1Pt < 20: return False - #cut_flow_trk.Fill('pt requirements 1') - #if row.e1AbsEta > 2.5: return False - #cut_flow_trk.Fill('eta requirements 1') - #if row.e1MissingHits: return False - #cut_flow_trk.Fill('MissingHits 1') - #if row.e1HasConversion: return False - #cut_flow_trk.Fill('HasConversion 1') - #if row.e1JetBtag > 3.3: return False - #cut_flow_trk.Fill('JetBtag 1') - #if abs(row.e1DZ) > 0.2: return False - #cut_flow_trk.Fill('DZ 1') if not selections.eSelection(row, 'e2'): return False cut_flow_trk.Fill('obj2 Presel') - #FIXME - #if row.e2Pt < 10: return False - #cut_flow_trk.Fill('pt requirements 2') - #if row.e2AbsEta > 2.5: return False - #cut_flow_trk.Fill('eta requirements 2') - #if row.e2MissingHits: return False - #cut_flow_trk.Fill('MissingHits 2') - #if row.e2HasConversion: return False - #cut_flow_trk.Fill('HasConversion 2') - #if row.e2JetBtag > 3.3: return False - #cut_flow_trk.Fill('JetBtag 2') - #if abs(row.e2DZ) > 0.2: return False - #cut_flow_trk.Fill('DZ 2') if not selections.tauSelection(row, 't'): return False if row.tPt < taupt_thr: return False @@ -276,27 +259,9 @@ def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = #if row.e1_e2_SS and row.e1_t_SS: return False #remove three SS leptons if row.e1_e2_Mass < 20: return False - if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes - cut_flow_trk.Fill('vetos') - - #REMOVE CHARGE FAKES! - #FIXME - #if not row.e1ChargeIdLoose: return False - #if not row.e2ChargeIdLoose: return False - #cut_flow_trk.Fill('ChargeIdLoose') - #cut_flow_trk.Fill('charge_fakes') - - #FIXME: ONLY FOR CUT-FLOW PRODUCTION - #if not selections.summer_2013_eid(row, 'e1'): return False - #cut_flow_trk.Fill('obj1 ID') - #if not selections.lepton_id_iso(row, 'e1', 'eid13Looseh2taucuts'): return False - #cut_flow_trk.Fill('obj1 Iso') - #if not selections.summer_2013_eid(row, 'e2'): return False - #cut_flow_trk.Fill('obj2 ID') - #if not selections.lepton_id_iso(row, 'e2', 'eid13Looseh2taucuts'): return False - #cut_flow_trk.Fill('obj2 Iso') - #if not row.tLooseIso3Hits: return False - #cut_flow_trk.Fill('obj3 IDIso') + cut_flow_trk.Fill('dilepton mass cut') + + if not selections.vetos(row, cut_flow_trk): return False #applies mu bjet e additional tau vetoes return True @@ -346,11 +311,12 @@ def enhance_wz(self, row): return row.tCiCTightElecOverlap def event_weight(self, row): - if row.run > 2: + if row.run > 2: #FIXME! add tight ID correction return 1. return self.pucorrector(row.nTruePU) * \ - mcCorrectors.get_electron_corrections(row,'e1','e2') *\ - mcCorrectors.double_electron_trigger(row) + mcCorrectors.get_electron_corrections(row,'e2') *\ + mcCorrectors.electron_tight_corrections(row.e1Pt, row.e1AbsEta) *\ + mcCorrectors.double_electron_trigger(row) def obj1_weight(self, row, leadleptonId='eid13Looseh2taucuts', subleadleptonId=None): return frfits.highpt_ee_fr[leadleptonId](electronJetPt=max(row.e1JetPt, row.e1Pt), electronPt=row.e1Pt, numJets20=row.jetVeto20+1) diff --git a/wh/WHAnalyzeEMT.py b/wh/WHAnalyzeEMT.py index 27adface..9cc20912 100644 --- a/wh/WHAnalyzeEMT.py +++ b/wh/WHAnalyzeEMT.py @@ -32,15 +32,21 @@ if len(optimizer_keys) > 1: grid_search[key] = optimizer.grid_search[key] -for key in optimizer_keys: - frfits.highpt_mu_fr[optimizer.grid_search[key]['leading_iso']] - frfits.highpt_mu_qcd_fr[optimizer.grid_search[key]['leading_iso']] - frfits.lowpt_mu_fr[optimizer.grid_search[key]['leading_iso']] - frfits.lowpt_mu_qcd_fr[optimizer.grid_search[key]['leading_iso']] - frfits.highpt_e_fr[optimizer.grid_search[key]['subleading_iso']] - frfits.highpt_e_qcd_fr[optimizer.grid_search[key]['subleading_iso']] - frfits.lowpt_e_fr[optimizer.grid_search[key]['subleading_iso']] - frfits.lowpt_e_qcd_fr[optimizer.grid_search[key]['subleading_iso']] +NO_HISTO_FILL = ('NO_HISTO_FILL' in os.environ) and eval(os.environ['NO_HISTO_FILL']) + +if not NO_HISTO_FILL: + for key in optimizer_keys: + frfits.highpt_mue_fr[optimizer.grid_search[key]['leading_iso']] + frfits.highpt_mue_qcd_fr[optimizer.grid_search[key]['leading_iso']] + frfits.lowpt_mue_fr[optimizer.grid_search[key]['leading_iso']] + frfits.lowpt_mue_qcd_fr[optimizer.grid_search[key]['leading_iso']] + frfits.highpt_e_fr[optimizer.grid_search[key]['subleading_iso']] + frfits.highpt_e_qcd_fr[optimizer.grid_search[key]['subleading_iso']] + frfits.lowpt_e_fr[optimizer.grid_search[key]['subleading_iso']] + frfits.lowpt_e_qcd_fr[optimizer.grid_search[key]['subleading_iso']] + +SYNC = ('SYNC' in os.environ) and eval(os.environ['SYNC']) + ################################################################################ #### Analysis logic ############################################################ @@ -49,7 +55,7 @@ use_iso_trigger = not is7TeV class WHAnalyzeEMT(WHAnalyzerBase): - tree = 'emt/final/Ntuple' + tree = 'emt/final/Ntuple' if not SYNC else 'Ntuple' def __init__(self, tree, outfile, **kwargs): self.channel = 'EMT' @@ -168,32 +174,19 @@ def book_histos(self, folder): self.book(folder, "mJetBtag#LT", "Muon 2 Pt", 30, -10, 5, nLTBins, LTBinning, type=ROOT.TH2F) self.book(folder, "eJetBtag#LT", "Muon 2 Pt", 30, -10, 5, nLTBins, LTBinning, type=ROOT.TH2F) + #tau ISO + self.book(folder, "tRawIso3Hits#LT", "Muon 2 Pt", 200, 0, 200, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "tRawIsoMVA2#LT", "Muon 2 Pt" , 200, -1, -1, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, "subPt" , "SubLeading Pt", 100, 0, 100) self.book(folder, "leadPt" , "Leading Pt" , 100, 0, 100) self.book(folder, "subJetPt" , "SubLeading Pt", 100, 0, 100) self.book(folder, "leadJetPt" , "Leading Pt" , 100, 0, 100) self.book(folder, "nTruePU", "NPU", 62, -1.5, 60.5) - #self.book(folder, "mPt", "Muon Pt", 100, 0, 100) - #self.book(folder, "ePt", "Electron Pt", 100, 0, 100) - #self.book(folder, "mJetPt", "Muon Pt", 100, 0, 100) - #self.book(folder, "eJetPt", "Electron Pt", 100, 0, 100) - #self.book(folder, "tPt", "Tau Pt", 100, 0, 100) - #self.book(folder, "mAbsEta", "Muon AbsEta", 100, 0, 2.4) - #self.book(folder, "eAbsEta", "Electron AbsEta", 100, 0, 2.5) - #self.book(folder, "tAbsEta", "Tau AbsEta", 100, 0, 2.3) self.book(folder, "eChargeIdTight", "Elec charge ID tight", 2, -0.5, 1.5) self.book(folder, "tLeadDR", "DR between leading lepton and tau", 100, 0, 5) self.book(folder, "tSubDR", "DR between subleading lepton and tau", 100, 0, 5) self.book(folder, "e_m_DR", "", 200, 0, 5) - #self.book(folder, "m_t_DR", "", 200, 0, 5) - #self.book(folder, "e_t_DR", "", 200, 0, 5) - - - #let's look for osme other possible selections - #self.book(folder, "Mass" , "mass" , 800, 0, 800 ) - #self.book(folder, "pt_ratio" , "pt_ratio" , 100, 0, 1) - #self.book(folder, "tToMETDPhi" , "tToMETDPhi" , 100, 0, 4) - #self.book(folder, "type1_pfMetEt" , "metEt" , 300, 0, 2000) #There is no call to self, so just promote it to statucmethod, to allow usage by other dedicated analyzers @@ -202,6 +195,12 @@ def preselection( self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr Excludes FR object IDs and sign cut. ''' + if row.e_t_DR < 0.5 or row.m_t_DR < 0.5 or row.e_m_DR < 0.5: return False + cut_flow_trk.Fill('DR separation') + + if self.hfunc['subMass'](row, 1)[0] < 20: return False + cut_flow_trk.Fill('sub mass cut') + mu17e8, mu8e17 = False, False if use_iso_trigger: mu17e8 = row.mu17ele8isoPass and \ @@ -226,56 +225,24 @@ def preselection( self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr cut_flow_trk.Fill('trigger') if not selections.muSelection(row, 'm'): return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag) - #cut_flow_trk.Fill('pt requirements 1', 'eta requirements 1', 'MissingHits 1', 'HasConversion 1', 'JetBtag 1', 'DZ 1',) cut_flow_trk.Fill('obj1 Presel') if not selections.eSelection(row, 'e'): return False #applies basic selection (eta, pt > 10, DZ, missingHits, jetBTag, HasConversion and chargedIdTight) cut_flow_trk.Fill('obj2 Presel') - #FIXME - #if row.ePt < 10: return False - #cut_flow_trk.Fill('pt requirements 2') - #if row.eAbsEta > 2.5: return False - #cut_flow_trk.Fill('eta requirements 2') - #if row.eMissingHits: return False - #cut_flow_trk.Fill('MissingHits 2') - #if row.eHasConversion: return False - #cut_flow_trk.Fill('HasConversion 2') - #if row.eJetBtag > 3.3: return False - #cut_flow_trk.Fill('JetBtag 2') - #if abs(row.eDZ) > 0.2: return False - #cut_flow_trk.Fill('DZ 2') - if not selections.tauSelection(row, 't'): return False #applies basic selection (eta, pt > 20, DZ) if row.tPt < taupt_thr: return False - #if row.tMuOverlap: return False - if not row.tAntiMuonLoose: return False cut_flow_trk.Fill('obj3 Presel') if row.LT < LT_threshold: return False cut_flow_trk.Fill('LT') - #if row.e_m_SS and row.e_t_SS: return False #remove three SS leptons - if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes - cut_flow_trk.Fill('vetos') - #FIXME - if not row.eChargeIdTight: return False - #cut_flow_trk.Fill('ChargeIdTight') - if row.e_m_Mass < 20: return False - cut_flow_trk.Fill('charge_fakes') #no charge fakes here + cut_flow_trk.Fill('dilepton mass cut') - #FIXME: ONLY FOR CUT-FLOW PRODUCTION - #if not row.mPFIDTight: return False - #cut_flow_trk.Fill('obj1 ID') - #if not selections.lepton_id_iso(row, 'm', 'h2taucuts'): return False - #cut_flow_trk.Fill('obj1 Iso') - #if not selections.summer_2013_eid(row, 'e'): return False - #cut_flow_trk.Fill('obj2 ID') - #if not selections.lepton_id_iso(row, 'e', 'h2taucuts'): return False - #cut_flow_trk.Fill('obj2 Iso') - #if not row.tLooseIso3Hits: return False - #cut_flow_trk.Fill('obj3 IDIso') + if not selections.vetos(row, cut_flow_trk): return False #applies mu bjet e additional tau vetoes + + cut_flow_trk.Fill('charge_fakes') #no charge fakes here return True @@ -311,14 +278,14 @@ def obj3_id(row, tauId=None, LT_threshold = 80., taupt_thr = 0.): #There is no call to self, so just promote it to statucmethod, to allow usage by other dedicated analyzers @staticmethod def anti_wz( row): - if row.e_t_Zcompat < 20: - if not row.tAntiElectronMVA3Medium: - return False - elif not row.tAntiElectronMVA3Loose: + if not row.tAntiMuonLoose or not row.tAntiElectronMVA3Loose: + return False + if row.e_t_Zcompat < 20 and (not row.tAntiElectronMVA3Medium): return False - elif row.m_t_Zcompat < 20: - if not row.tAntiMuonTight: - return False + if row.m_t_Zcompat < 20 and not (row.tAntiMuonTight and \ + (( row.tDecayMode == 0 and row.tLeadChargeCandEMFraction > 0.2 ) \ + or row.tDecayMode <> 0)): + return False return True def enhance_wz(self, row): From d8cb35655945840f1e55d4c049390f03614ddc67 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 30 Oct 2013 04:16:14 -0500 Subject: [PATCH 076/192] few changes to make the three channels independent to run --- wh/Rakefile | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/wh/Rakefile b/wh/Rakefile index 17e9dbd8..fa79981a 100755 --- a/wh/Rakefile +++ b/wh/Rakefile @@ -12,7 +12,8 @@ if $jobid.include? '7TeV' $period = '7TeV' end -check_luminosity(['data_DoubleElectron', 'data_DoubleMu', 'data_MuEG'], $period, $jobid) +#check_luminosity(['data_DoubleElectron', 'data_DoubleMu', 'data_MuEG'], $period, $jobid) +check_luminosity(['data_DoubleMu'], $period, $jobid) task :getlumi, [:sample] do |t, args| puts get_lumi(args.sample, $jobid) @@ -209,10 +210,10 @@ elewps.select{|x| x.start_with?('eid12Medium')}.each do |ele_wp| emcrs.each do |cr| neighbors.each do |k| pt_regions.each do |ptr| - key = "e_#{cr}_#{ptr}_#{ele_wp}_eJetPt" + key = "em_#{cr}_#{ptr}_#{ele_wp}_eJetPt" #fr_fits[key] = make_exponential('em', 'em') #fit EVERYTHING with exponential, in case change afterwards - key = "e_#{cr}_#{ptr}_#{ele_wp}_electronInfo_k#{k}" + key = "em_#{cr}_#{ptr}_#{ele_wp}_electronInfo_k#{k}" kNN_trains[key] = make_kNN('em', 'em') kNN_trains[key]['vars'] = electron_kNN_vars end @@ -226,7 +227,7 @@ muonwps.each do |mu_wp| mmcrs.each do |cr| neighbors.each do |k| pt_regions.each do |ptr| - key = "m_M#{cr}_#{ptr}_#{mu_wp}_muonInfo_k#{k}" + key = "em_M#{cr}_#{ptr}_#{mu_wp}_muonInfo_k#{k}" kNN_trains[key] = make_kNN('em', 'em') kNN_trains[key]['vars'] = muon_kNN_vars end @@ -264,10 +265,10 @@ muonwps.each do |mu_wp| mmcrs.each do |cr| neighbors.each do |k| pt_regions.each do |ptr| - key = "m_#{cr}_#{ptr}_#{mu_wp}_muonJetPt" + key = "mm_#{cr}_#{ptr}_#{mu_wp}_muonJetPt" #fr_fits[key] = make_landau('mm', 'mm') - key = "m_#{cr}_#{ptr}_#{mu_wp}_muonInfo_k#{k}" + key = "mm_#{cr}_#{ptr}_#{mu_wp}_muonInfo_k#{k}" kNN_trains[key] = make_kNN('mm', 'mm') kNN_trains[key]['vars'] = muon_kNN_vars end @@ -430,17 +431,18 @@ task :fits => :charge_fakes fake_rate_files = fr_fits.keys.map{|x| "#{$frfit_dir}/#{x}.root"} # IF the FR fits change, make sure we re-run the analyses -file "WHAnalyzeEMT.py" => kNN_files.select{|x| x.start_with?("#{$frfit_dir}/e_")} + \ - kNN_files.select{|x| x.start_with?("#{$frfit_dir}/m_")} + \ +file "WHAnalyzeEMT.py" => kNN_files.select{|x| x.start_with?("#{$frfit_dir}/em_")} + \ + #kNN_files.select{|x| x.start_with?("#{$frfit_dir}/m_")} + \ fake_rate_files.select{|x| x.start_with?("#{$frfit_dir}/t_")} + \ Array["optimizer.py", 'WHAnalyzerBase.py', "fakerate_functions.py", "mcCorrectors.py"] do |t| + puts t.investigation sh "touch #{t.name}" end -file "WHAnalyzeMMT.py" => kNN_files.select{|x| x.start_with?("#{$frfit_dir}/m_")} + \ +file "WHAnalyzeMMT.py" => kNN_files.select{|x| x.start_with?("#{$frfit_dir}/mm_")} + \ fake_rate_files.select{|x| x.start_with?("#{$frfit_dir}/t_")} + \ ["optimizer.py", 'WHAnalyzerBase.py', @@ -459,7 +461,7 @@ file "WHAnalyzeEET.py" => kNN_files.select{|x| x.start_with?( "#{$frfit_dir}/ee_ sh "touch #{t.name}" end -mmt_results = get_analyzer_results("WHAnalyzeMMT.py", samples['ewk'] + samples['data_mm'] + samples['signal']) +mmt_results = get_analyzer_results("WHAnalyzeMMT.py", samples['diboson'] + samples['data_mm'] + samples['signal']) emt_results = get_analyzer_results("WHAnalyzeEMT.py", samples['ewk'] + samples['data_em'] + samples['signal']) eet_results = get_analyzer_results("WHAnalyzeEET.py", samples['ewk'] + samples['data_ee'] + samples['signal']) @@ -474,7 +476,7 @@ task :eet => eet_results task :mmcontrol => get_analyzer_results("ControlZMM.py", samples['ewk'] + samples['data_mm']) task :emcontrol => get_analyzer_results("ControlEM.py", samples['ewk'] + samples['data_em']) -task :eecontrol => get_analyzer_results("ControlZEE.py", samples['data_ee'] + samples["zjets"]) + Dir.glob("#{$frfit_dir}/ee*h2taucuts_electronJetPt.root") #samples['ewk'] + +task :eecontrol => get_analyzer_results("ControlZEE.py", samples['data_ee'] + samples["ewk"]) + Dir.glob("#{$frfit_dir}/ee*h2taucuts_electronJetPt.root") #samples['ewk'] + task :mmt_signal => get_analyzer_results("WHAnalyzeMMT.py", samples['signal']) task :emt_signal => get_analyzer_results("WHAnalyzeEMT.py", samples['signal']) @@ -940,6 +942,10 @@ file "#{$carddir}/llt/.creation_timestamp" => cardmasses.map{|x| combine_channel sh "touch #{t.name}" end +task :cards_mmt => make_timestamp_task(cardmasses, 'mmt') +task :cards_emt => make_timestamp_task(cardmasses, 'emt') +task :cards_eet => make_timestamp_task(cardmasses, 'eet') + task :cards => [make_timestamp_task(cardmasses, 'mmt'), make_timestamp_task(cardmasses, 'emt'), make_timestamp_task(cardmasses, 'eet'), From 1c01c087f52bac05282dce68a605609c08d293d7 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 30 Oct 2013 04:17:54 -0500 Subject: [PATCH 077/192] Added DR cut and new trig matching for MM --- wh/FakeRatesEE.py | 1 + wh/FakeRatesEM.py | 1 + wh/FakeRatesMM.py | 10 ++++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/wh/FakeRatesEE.py b/wh/FakeRatesEE.py index 9c92c14a..16bdc526 100755 --- a/wh/FakeRatesEE.py +++ b/wh/FakeRatesEE.py @@ -100,6 +100,7 @@ def preselection(row): if not (row.e1MatchesDoubleEPath > 0 and \ row.e2MatchesDoubleEPath > 0): return False if not row.e1Pt > 20: return False + if row.e1_e2_DR < 0.5: return False if not selections.eSelection(row, 'e1'): return False if not row.e1MVAIDH2TauWP: return False if not selections.eSelection(row, 'e2'): return False diff --git a/wh/FakeRatesEM.py b/wh/FakeRatesEM.py index 3a8328b2..024d89f3 100644 --- a/wh/FakeRatesEM.py +++ b/wh/FakeRatesEM.py @@ -147,6 +147,7 @@ def preselection(row): if not selections.muSelection(row, 'm'): return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag) if not selections.eSelection(row, 'e'): return False #applies basic selection (eta, pt > 10, DZ, missingHits, jetBTag, HasConversion and chargedIdTight) if not row.eChargeIdTight: return False + if row.e_m_DR < 0.5: return False #if not (row.jetVeto40_DR05 >= 1): return False if not (row.jetVeto20 > 1): return False if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes diff --git a/wh/FakeRatesMM.py b/wh/FakeRatesMM.py index 68783250..2b70fadd 100755 --- a/wh/FakeRatesMM.py +++ b/wh/FakeRatesMM.py @@ -32,6 +32,7 @@ def control_region(row): else: return None +region_for_event_list = os.environ.get('EVTLIST_REGION','') class FakeRatesMM(MegaBase): tree = 'mm/final/Ntuple' @@ -104,11 +105,12 @@ def preselection(row): row.m1MatchesDoubleMuPaths > 0 and \ row.m2MatchesDoubleMuPaths > 0 double_muTrk_pass = row.doubleMuTrkPass and \ - row.m1MatchesDoubleMuTrkPaths > 0 and \ - row.m2MatchesDoubleMuTrkPaths > 0 + row.m1MatchesMu17TrkMu8Path > 0 and \ + row.m2MatchesMu17TrkMu8Path > 0 if not ( double_mu_pass or double_muTrk_pass ): return False if not row.m1_m2_SS: return False + if row.m1_m2_DR < 0.5: return False if row.m2Pt > row.m1Pt: return False if row.m1_m2_Mass < 20: return False if not row.m1Pt > 20: return False @@ -158,6 +160,10 @@ def fill(the_histos, row, fillNtuple=False): if region is None: continue + if region_for_event_list and region == region_for_event_list: + print '%i:%i:%i' % (row.run, row.lumi, row.evt) + continue + def fill_region(region, tag): # This is a QCD or Wjets fill(histos[(region, tag)], row, True) From b017a692d1a6b855f6c4ab75dbaa5ab61386cb52 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 30 Oct 2013 04:18:25 -0500 Subject: [PATCH 078/192] reshuffled the code, made sync easier --- wh/WHAnalyzerBase.py | 157 ++++++++++++++++++++++++------------------- 1 file changed, 88 insertions(+), 69 deletions(-) diff --git a/wh/WHAnalyzerBase.py b/wh/WHAnalyzerBase.py index 0c13713f..bfdb7fbd 100644 --- a/wh/WHAnalyzerBase.py +++ b/wh/WHAnalyzerBase.py @@ -62,6 +62,18 @@ from FinalStateAnalysis.PlotTools.decorators import memo from FinalStateAnalysis.Utilities.struct import struct +#Makes the cut flow histogram +cut_flow_step = ['bare', 'WH Event', + #'obj1 GenMatching', 'obj2 GenMatching', 'obj3 GenMatching', + 'DR separation', 'sub mass cut', 'trigger', + 'obj1 Presel', 'obj2 Presel', 'obj3 Presel', + 'LT', 'dilepton mass cut', 'muon veto', 'bjet veto', 'electron veto', + 'tau veto', 'sign cut', 'tau sign', + 'obj1 IDIso', 'obj2 IDIso', 'obj3 IDIso', + 'anti WZ', 'anti charge flip', +] + + @memo def joinDirs(*args): return '/'.join(args) @@ -82,9 +94,8 @@ def __init__(self, hist): self.cut_flow = dict([ (i, False) for i in self.labels]) self.hist = hist self.evt_info = [-1, -1, -1] - self.disabled = True #'CutFlow' not in os.environ - if not self.disabled: - print "running cut flow" + self.disabled = 'CutFlow' not in os.environ + self.sync_mode = 'SYNC' in os.environ def fill(self, label): self.cut_flow[label] = True @@ -98,11 +109,20 @@ def Fill(self, *labels): def flush(self): if self.disabled: return + final_i = -1 for i, label in enumerate(self.labels): val = self.cut_flow[label] if val: self.hist.Fill(i+0.5) - + final_i = i + if self.sync_mode: + fails = '' + try: + fails = 'fails %s' % (self.labels[final_i+1]) + except IndexError: + fails = 'passes the selection' #if len(self.labels) == final_i else 'passes the selection' + print 'Event %i:%i:%i ' % tuple(self.evt_info) + fails + def new_row(self, *args): if self.disabled: return @@ -243,57 +263,43 @@ def fill_histos(self, histos, folder_str, row, weight, filter_label = ''): def begin(self): # Loop over regions, book histograms, book the minimal amount book_charge_flip_cr = hasattr(self, 'anti_charge_flip') - for _, folders in self.build_wh_folder_structure().iteritems(): - base_folder, weight_folders = folders - folder = "/".join(base_folder) - self.book_histos(folder) # in subclass - if book_charge_flip_cr: - self.book_histos(folder+'/charge_flip_CR') - # Each of the weight subfolders - for weight_folder in weight_folders: - hfolder = "/".join(base_folder + (weight_folder,)) - self.book_histos(hfolder) + no_histo_fill = ('NO_HISTO_FILL' in os.environ) and eval(os.environ['NO_HISTO_FILL']) + if not no_histo_fill: + for _, folders in self.build_wh_folder_structure().iteritems(): + base_folder, weight_folders = folders + folder = "/".join(base_folder) + self.book_histos(folder) # in subclass if book_charge_flip_cr: - self.book_histos(hfolder+'/charge_flip_CR') - - # Add WZ control region - self.book_histos('ss/tau_os/p1p2p3_enhance_wz') - # Where second light lepton fails - self.book_histos('ss/tau_os/p1f2p3_enhance_wz') - self.book_histos('ss/tau_os/p1f2p3_enhance_wz/w2') - - # Add charge-fake control region - probability that obj1 will flip into - # ss/p1p2p3 - for i in itertools.product(['tau_os','tau_ss'],['p3','f3'],['c1','c2','c1_sysup','c2_sysup']): - self.book_histos('os/%s/p1p2%s/%s' % i) - self.book_histos('os/%s/p1p2%s/%s/charge_flip_CR' % i) - - for key in self.histograms: - charpos = key.rfind('/') - location = key[ : charpos]+'/' - name = key[ charpos + 1 :] - if location in self.histo_locations: - self.histo_locations[location].append(name) - else: - self.histo_locations[location] = [name] - - #Makes the cut flow histogram - cut_flow_step = ['bare', 'WH Event', - #'obj1 GenMatching', 'obj2 GenMatching', 'obj3 GenMatching', - 'trigger', - 'obj1 Presel', 'obj2 Presel', -## 'pt requirements 1', 'eta requirements 1', -## 'MissingHits 1', 'HasConversion 1', 'JetBtag 1', 'DZ 1', -## 'pt requirements 2', 'eta requirements 2', -## 'MissingHits 2', 'HasConversion 2', 'JetBtag 2', 'DZ 2', - 'obj3 Presel', - 'LT', 'vetos', -## 'ChargeIdLoose', -## 'charge_fakes', - #'obj1 ID', 'obj1 Iso', 'obj2 ID', 'obj2 Iso', - 'obj1 IDIso', 'obj2 IDIso', 'obj3 IDIso', - 'sign cut', 'anti WZ', - ] + self.book_histos(folder+'/charge_flip_CR') + # Each of the weight subfolders + for weight_folder in weight_folders: + hfolder = "/".join(base_folder + (weight_folder,)) + self.book_histos(hfolder) + if book_charge_flip_cr: + self.book_histos(hfolder+'/charge_flip_CR') + + # Add WZ control region + self.book_histos('ss/tau_os/p1p2p3_enhance_wz') + # Where second light lepton fails + self.book_histos('ss/tau_os/p1f2p3_enhance_wz') + self.book_histos('ss/tau_os/p1f2p3_enhance_wz/w2') + + # Add charge-fake control region - probability that obj1 will flip into + # ss/p1p2p3 + for i in itertools.product(['tau_os','tau_ss'],['p3','f3'],['c1','c2','c1_sysup','c2_sysup']): + self.book_histos('os/%s/p1p2%s/%s' % i) + self.book_histos('os/%s/p1p2%s/%s/charge_flip_CR' % i) + + for key in self.histograms: + charpos = key.rfind('/') + location = key[ : charpos]+'/' + name = key[ charpos + 1 :] + if location in self.histo_locations: + self.histo_locations[location].append(name) + else: + self.histo_locations[location] = [name] + #END if not no_histo_fill: + self.book('ss', "CUT_FLOW", "Cut Flow", len(cut_flow_step), 0, len(cut_flow_step)) xaxis = self.histograms['ss/CUT_FLOW'].GetXaxis() self.cut_flow_histo = self.histograms['ss/CUT_FLOW'] @@ -307,6 +313,8 @@ def process(self): # string using a dictionary # key = (sign, obj1, obj2, obj3) cut_region_map = self.build_wh_folder_structure() + region_for_event_list = os.environ.get('EVTLIST_REGION','') + no_histo_fill = ('NO_HISTO_FILL' in os.environ) and eval(os.environ['NO_HISTO_FILL']) # Reduce number of self lookups and get the derived functions here histos = self.histograms @@ -366,9 +374,9 @@ def process(self): cut_flow_trk.Fill('bare') # Apply basic preselection # - if not cut_flow_trk.disabled: - if row.processID != 26: - continue + #if not cut_flow_trk.disabled: + # if row.processID != 26: + # continue #if row.lumi == 2348 and row.evt == 704038: # print 'preselection', preselection(row, cut_flow_trk, cut_settings['LT'] if lt_tpt_in_presel else 0., cut_settings['tauPT'] if lt_tpt_in_presel else 0.) @@ -403,16 +411,21 @@ def process(self): # #from pdb import set_trace; set_trace() #from pdb import set_trace; set_trace() #if not cut_flow_trk.disabled: - if obj1_id_result: - cut_flow_trk.Fill('obj1 IDIso') - if obj2_id_result: - cut_flow_trk.Fill('obj2 IDIso') - if obj3_id_result: - cut_flow_trk.Fill('obj3 IDIso') - if sign_result: - cut_flow_trk.Fill('sign cut') - if anti_wz : - cut_flow_trk.Fill('anti WZ') + if sign_result: + cut_flow_trk.Fill('sign cut') + if tau_sign_result: + cut_flow_trk.Fill('tau sign') + if obj1_id_result: + cut_flow_trk.Fill('obj1 IDIso') + if obj2_id_result: + cut_flow_trk.Fill('obj2 IDIso') + if obj3_id_result: + cut_flow_trk.Fill('obj3 IDIso') + if anti_wz : + cut_flow_trk.Fill('anti WZ') + if anti_charge_flip: + cut_flow_trk.Fill('anti charge flip') + # Figure out which folder/region we are in region_result = cut_region_map.get( @@ -424,10 +437,13 @@ def process(self): if anti_wz: base_folder, weights = region_result - #if base_folder == ('ss', 'p1p2f3'): - # print row.run, row.lumi, row.evt base_folder = joinDirs(*base_folder) + if region_for_event_list and base_folder == region_for_event_list: + print '%i:%i:%i' % (row.run, row.lumi, row.evt) + if no_histo_fill: + continue + # Fill the un-fr-weighted histograms for i in to_fill: folder = joinDirs(base_folder,i) @@ -462,6 +478,9 @@ def process(self): fill_histos(histos, joinDirs(directory_up,i), row, event_weight*charge_flip_sysu, cut_label) elif sign_result and obj1_id_result and obj3_id_result and tau_sign_result: + if no_histo_fill: + continue + # WZ object topology fails. Check if we are in signal region. if self.enhance_wz(row): # Signal region From e3144071c7db9f93826925b6df15e5558f8c1756 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 30 Oct 2013 04:19:13 -0500 Subject: [PATCH 079/192] added options to draw ratios and stuff --- wh/WHPlotterBase.py | 109 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 88 insertions(+), 21 deletions(-) diff --git a/wh/WHPlotterBase.py b/wh/WHPlotterBase.py index 73d85dce..110ba092 100644 --- a/wh/WHPlotterBase.py +++ b/wh/WHPlotterBase.py @@ -24,6 +24,8 @@ from FinalStateAnalysis.MetaData.data_styles import data_styles, colors from FinalStateAnalysis.PlotTools.decorators import memo from FinalStateAnalysis.MetaData.datacommon import br_w_leptons, br_z_leptons +from FinalStateAnalysis.Utilities.floatformatting import smart_float_format +from pdb import set_trace from optparse import OptionParser import os import ROOT @@ -36,6 +38,13 @@ parser = OptionParser(description=__doc__) parser.add_option('--dry-run', action='store_true', dest='dry_run', default = False, help='produces only shape file and minimal histograms') + +parser.add_option('--no-mc-data', action='store_true', dest='no_mc_data', default = False) +parser.add_option('--no-wz', action='store_true', dest='no_wz', default = False) +parser.add_option('--no-signal', action='store_true', dest='no_signal', default = False) +parser.add_option('--no-f3', action='store_true', dest='no_f3', default = False) +parser.add_option('--no-shapes', action='store_true', dest='no_shapes', default = False) + parser.add_option('--prefix', metavar='label', type=str, dest='prefix', default = '', help='prefix to eppend before histogram name o be used to make the shapes' ) parser.add_option('--prefixes', metavar='label', type=str, dest='prefixes', default = '', @@ -93,6 +102,37 @@ def fake_rate_estimate(histograms): #always, ALWAYS give as 1,2,0 return ret +class MultyErrorView(object): #FIXME + '''takes a StackView and adds systematics''' + def __init__(self, stackview, systematics_map): + self.stack_view = stackview + self.systematics_map = systematics_map + + def Get(self, path): + stack_components = self.stack_view.Get(path).GetHists() + stack_sum = sum(stack_components) + + for bin in range(1, stack_sum.GetNbinsX() + 1): + #sys_errors = [ sum(hist.GetBinContent(bin)*value for hist in stack_components if fnmatch(hist.GetTitle(), key)) for key, value in self.systematics_map ] + sys_errors = [] + for key, value in self.systematics_map.iteritems(): + it = 0 + for hist in stack_components: + if fnmatch(hist.GetTitle(), key): + print '%s matches %s' % (hist.GetTitle(), key) + it += hist.GetBinContent(bin)*value + sys_errors.append(it) + + error = quad( stack_sum.GetBinError(bin), *sys_errors ) + stack_sum.SetBinError(bin, error) + + stack_sum.SetMarkerSize(0) + stack_sum.SetFillColor(1) + stack_sum.SetFillStyle(3013) + stack_sum.legendstyle = 'f' + return stack_sum + + class BackgroundErrorView(object): ''' Compute the total background error in each bin. ''' def __init__(self, fakes, wz, zz, charge_fake, wz_error=0.1, zz_error=0.04, @@ -286,20 +326,19 @@ def preprocess(view): ret = ProjectionView(ret, project_axis, project) return RebinView( ret, rebin ) - wz_view_tautau = preprocess( - views.SubdirectoryView( - self.get_view('WZJetsTo3LNu*ZToTauTau*'), + all_wz_view_tautau = preprocess( self.get_view('WZJetsTo3LNu*ZToTauTau*') ) + wz_view_tautau = views.SubdirectoryView( + all_wz_view_tautau, 'ss/%s/p1p2p3/' % tau_charge - ) ) tomatch = 'WZJetsTo3LNu' if self.sqrts == 7 else 'WZJetsTo3LNu_pythia' - wz_view_3l = preprocess( - views.SubdirectoryView( - self.get_view(tomatch), + all_wz_view_3l = preprocess( self.get_view(tomatch) ) + wz_view_3l = views.SubdirectoryView( + all_wz_view_3l, 'ss/%s/p1p2p3/' % tau_charge - ) ) + all_wz_view = views.SumView(all_wz_view_tautau, all_wz_view_3l) zz_view = preprocess( views.SubdirectoryView( @@ -317,7 +356,10 @@ def preprocess(view): def make_fakes(qcd_fraction): def make_fakes_view(weight_type, scale): - scaled_data = views.ScaleView(all_data_view, scale) + scaled_bare_data = views.ScaleView(all_data_view, scale) + scaled_wz_data = views.ScaleView(all_wz_view, -1*scale) + scaled_data = views.SumView(scaled_bare_data, scaled_wz_data) + # View of weighted obj1-fails data obj1_view = views.SubdirectoryView( scaled_data, 'ss/%s/f1p2p3/%s1' % (tau_charge, weight_type)) @@ -478,15 +520,21 @@ def make_obj3_fail_cr_views(self, qcd_correction=False, f1p2f3 ''' other_tau_sign = 'tau_os' if tau_charge == 'tau_ss' else 'tau_ss' + all_wz_ztt_view = self.get_view('WZJetsTo3LNu*ZToTauTau*') wz_view = views.SubdirectoryView( - self.get_view('WZJetsTo3LNu*ZToTauTau*'), + all_wz_ztt_view, 'ss/%s/p1p2f3/' % tau_charge ) + tomatch = 'WZJetsTo3LNu' if self.sqrts == 7 else 'WZJetsTo3LNu_pythia' + all_wz_3l_view = self.get_view(tomatch) wz_view_3l = views.SubdirectoryView( - self.get_view(tomatch), + all_wz_3l_view, 'ss/%s/p1p2f3/' % tau_charge ) + + all_wz_view = views.SumView(all_wz_ztt_view, all_wz_3l_view) + zz_view = views.SubdirectoryView( self.get_view('ZZJetsTo4L*'), 'ss/%s/p1p2f3/' % tau_charge @@ -496,7 +544,9 @@ def make_obj3_fail_cr_views(self, qcd_correction=False, def make_fakes(qcd_fraction): def make_fakes_view(weight_type, scale): - scaled_data = views.ScaleView(all_data_view, scale) + scaled_bare_data = views.ScaleView(all_data_view, scale) + wz_data = views.ScaleView(all_wz_view, -1*scale) + scaled_data = views.SumView(scaled_bare_data, wz_data) # View of weighted obj1-fails data obj1_view = views.SubdirectoryView( scaled_data, 'ss/%s/f1p2f3/%s1' % (tau_charge, weight_type)) @@ -918,7 +968,8 @@ def plot_final_f3(self, variable, rebin=1, xaxis='', maxy=None, qcd_weight_fraction=0.5, x_range=None, #): show_chi2=False,project=None, project_axis=None, differential=False, - yaxis='Events', tau_charge='tau_os', **kwargs): + yaxis='Events', tau_charge='tau_os', show_ratio=False, + ratio_range=None, fit=None, **kwargs): ''' Plot the final F3 control region - with bkg. estimation ''' show_chi2 = False #broken sig_view = self.make_obj3_fail_cr_views( @@ -954,6 +1005,7 @@ def plot_final_f3(self, variable, rebin=1, xaxis='', maxy=None, #pad = ROOT.TPad('da','fuq',0.1,0.8,0.5,0.9) #self.canvas.cd() #latexit = '' + bkg_error = None if show_error: correct_qcd_view = None if qcd_weight_fraction == 0: @@ -992,15 +1044,30 @@ def plot_final_f3(self, variable, rebin=1, xaxis='', maxy=None, histo.SetMaximum(2 * max(data.GetMaximum(), histo.GetMaximum())) self.keep.append(data) self.keep.append(histo) - #if latexit: - # pad.cd() - # latex.DrawLatex(0.01, 0.01, latexit) - # self.canvas.cd() - # pad.Draw() - #self.keep.append(latex) - #self.keep.append(pad) - #legend.AddEntry(data) legend.Draw() + if show_ratio: + ratio_plot = self.add_ratio_plot(data, bkg_error, x_range, ratio_range=ratio_range) + if fit: + #set_trace() + fitrange = fit.get('range', False) + if not fitrange: + nbins = ratio_plot.GetNbinsX() + fitrange = x_range if x_range else [ ratio_plot.GetBinLowEdge(1), + ratio_plot.GetBinLowEdge(nbins)+ratio_plot.GetBinWidth(nbins)] + self.lower_pad.cd() + function = self.fit_shape(ratio_plot, fit['model'], fitrange, fit.get('options','IRMENS')) + toprint = '#chi^{2} / DoF = %.2f / %i\n' % (function.GetChisquare() , function.GetNDF()) + for i in range(function.GetNpar()): + name = function.GetParName(i) + value = function.GetParameter(i) + error = function.GetParError(i) + toprint += '%s = %s\n' % (name, smart_float_format((value, error))) #%f #pm %f + + stat_box = self.make_text_box(toprint[:-1],fit.get('stat position','bottom-left')) + stat_box.Draw() + self.keep.append(stat_box) + #print toprint + self.pad.cd() def plot_final_f3_split(self, variable, rebin=1, xaxis='', maxy=None): ''' Plot the final F3 control region - with bkg. estimation ''' From 67a982345775b430305a2327720fe00da8c11b5a Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 30 Oct 2013 04:20:05 -0500 Subject: [PATCH 080/192] cleanup --- wh/WHPlotterEET.py | 127 +++--- wh/WHPlotterEMT.py | 5 +- wh/WHPlotterMMT.py | 1058 ++++++++++++++++++++------------------------ 3 files changed, 549 insertions(+), 641 deletions(-) diff --git a/wh/WHPlotterEET.py b/wh/WHPlotterEET.py index afbc661b..ed4688e3 100755 --- a/wh/WHPlotterEET.py +++ b/wh/WHPlotterEET.py @@ -136,69 +136,70 @@ def __init__(self): else: plotter.set_subdir('%s_charge3' % label) - plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', - maxy=None, project=proj_range, project_axis='X', - differential=True, yaxis='Events / GeV', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-%s' % label) - - plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', - maxy=None, project=proj_range, project_axis='X', - differential=True, yaxis='Events / GeV', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.canvas.SetLogy(True) - plotter.save('final-subMass-logscale-%s' % label) - - plotter.plot_final('e2_t_Mass#LT', 300, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) - - #pt - plotter.plot_final("e1Pt#LT" , int(factor*10), xaxis='p_{Te_{1}} (GeV)', - maxy=None, project=proj_range, project_axis='X', - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e1Pt-%s' % label) - - plotter.plot_final("e2Pt#LT", int(factor*10), xaxis='p_{Te_{2}} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e2Pt-%s' % label) - - plotter.plot_final("e1JetPt#LT", int(factor*10), xaxis='p_{T Jet e_{1}} (GeV)', - maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e1JetPt-%s' % label) - - plotter.plot_final("e2JetPt#LT", int(factor*10), xaxis='p_{T Jet e_{2}} (GeV)', - maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e2JetPt-%s' % label) - - #eta - plotter.plot_final("e1AbsEta#LT", 10, xaxis='|#eta_{e_{1}}|', maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e1AbsEta-%s' % label) - - plotter.plot_final("e2AbsEta#LT", 10, xaxis='|#eta_{e_{2}}|', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e2AbsEta-%s' % label) - - #DR - plotter.plot_final("e1_t_DR#LT", 10, xaxis='#DeltaR_{e_{1}#tau}', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e1_t_DR-%s' % label) - - plotter.plot_final("e2_t_DR#LT", 10, xaxis='#DeltaR_{e_{2}#tau}', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e2_t_DR-%s' % label) + plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', + maxy=None, project=proj_range, project_axis='X', + differential=True, yaxis='Events / GeV', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s' % label) + + plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', + maxy=None, project=proj_range, project_axis='X', + differential=True, yaxis='Events / GeV', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.canvas.SetLogy(True) + plotter.save('final-subMass-logscale-%s' % label) + + plotter.plot_final('e2_t_Mass#LT', 300, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge, + show_error=True) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) + + #pt + plotter.plot_final("e1Pt#LT" , int(factor*10), xaxis='p_{Te_{1}} (GeV)', + maxy=None, project=proj_range, project_axis='X', + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e1Pt-%s' % label) + + plotter.plot_final("e2Pt#LT", int(factor*10), xaxis='p_{Te_{2}} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e2Pt-%s' % label) + + plotter.plot_final("e1JetPt#LT", int(factor*10), xaxis='p_{T Jet e_{1}} (GeV)', + maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e1JetPt-%s' % label) + + plotter.plot_final("e2JetPt#LT", int(factor*10), xaxis='p_{T Jet e_{2}} (GeV)', + maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e2JetPt-%s' % label) + + #eta + plotter.plot_final("e1AbsEta#LT", 10, xaxis='|#eta_{e_{1}}|', maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e1AbsEta-%s' % label) + + plotter.plot_final("e2AbsEta#LT", 10, xaxis='|#eta_{e_{2}}|', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e2AbsEta-%s' % label) + + #DR + plotter.plot_final("e1_t_DR#LT", 10, xaxis='#DeltaR_{e_{1}#tau}', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e1_t_DR-%s' % label) + + plotter.plot_final("e2_t_DR#LT", 10, xaxis='#DeltaR_{e_{2}#tau}', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e2_t_DR-%s' % label) plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=[0, 130], project_axis='X', differential=True) plotter.add_cms_blurb(sqrts) diff --git a/wh/WHPlotterEMT.py b/wh/WHPlotterEMT.py index b01ae424..aec4f2e7 100644 --- a/wh/WHPlotterEMT.py +++ b/wh/WHPlotterEMT.py @@ -34,6 +34,7 @@ def __init__(self): 'LTHigh': [130, 650], 'Full' : [0, 650], } +rebin_slim = [20]+range(30, 81, 10)+[100,130,300] if __name__ == "__main__": plotter = WHPlotterEMT() @@ -116,7 +117,6 @@ def __init__(self): ## Signal region plots ################################################ ########################################################################### plotter.set_subdir('') - rebin_slim = [20]+range(30, 81, 10)+[100,130,300] for label, proj_range in categories.iteritems(): for tau_charge in ['tau_os', 'tau_ss']: @@ -147,7 +147,8 @@ def __init__(self): plotter.save('final-e_t_Mass-%s' % label) plotter.plot_final('subMass#LT', 300, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) + project=proj_range, project_axis='X', tau_charge=tau_charge, + show_error=True) plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) diff --git a/wh/WHPlotterMMT.py b/wh/WHPlotterMMT.py index 55cf54c2..fd7c4e4b 100644 --- a/wh/WHPlotterMMT.py +++ b/wh/WHPlotterMMT.py @@ -37,597 +37,503 @@ def __init__(self): sqrts = plotter.sqrts options,NOTUSED = parser.parse_args() if not options.dry_run: - ########################################################################### - ## Zmm control plots ##################################################### - ########################################################################### - plotter.set_subdir('mc_data/zmm') - - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'm1_m2_Mass', rebin=10, - xaxis='m_{#mu#mu} (GeV)', leftside=False) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-Zmm-m1m2Mass') - - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'm1Pt#LT', rebin=10, - xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-Zmm-m1Pt') - - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'm2Pt#LT', rebin=10, - xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-Zmm-m2Pt') - - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'm1AbsEta#LT', rebin=10, - xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-Zmm-m1AbsEta') - - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'm2AbsEta#LT', rebin=10, - xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-Zmm-m2AbsEta') - - # Check PU variables - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'rho') - plotter.save('mcdata-Zmm-rho') - - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'nvtx') - plotter.save('mcdata-Zmm-nvtx') - - - ########################################################################### - ## WZ control plots ##################################################### - ########################################################################### - plotter.set_subdir('mc_data/wz_enhanced') + if not options.no_mc_data: + ########################################################################### + ## Zmm control plots ##################################################### + ########################################################################### + plotter.set_subdir('mc_data/zmm') - plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'm2_t_Mass#LT', xaxis='m_{#mu#mu} (GeV)', - xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1p2p3-enhance_wz-subMass') + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'm1_m2_Mass', rebin=10, + xaxis='m_{#mu#mu} (GeV)', leftside=False) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-Zmm-m1m2Mass') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'm1Pt#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-Zmm-m1Pt') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'm2Pt#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-Zmm-m2Pt') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'm1AbsEta#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-Zmm-m1AbsEta') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'm2AbsEta#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-Zmm-m2AbsEta') + + # Check PU variables + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'rho') + plotter.save('mcdata-Zmm-rho') - plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'm1_t_Mass', xaxis='m_{#mu#mu} (GeV)', - xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1p2p3-enhance_wz-leadMass') + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'nvtx') + plotter.save('mcdata-Zmm-nvtx') + + if not options.no_wz: + ########################################################################### + ## WZ control plots ##################################################### + ########################################################################### + plotter.set_subdir('mc_data/wz_enhanced') - #plotter.plot_mc_vs_data('ss/p1f2p3_enhance_wz', 'm1_t_Mass', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=10) - #plotter.add_cms_blurb(sqrts) - #plotter.save('mcdata-ss-p1f2p3-enhance_wz-leadMass') - # - #plotter.plot_mc_vs_data('ss/p1f2p3_enhance_wz/w2', 'm1_t_Mass', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=10) - #plotter.add_cms_blurb(sqrts) - #plotter.save('mcdata-ss-p1f2p3-w2-enhance_wz-leadMass') - # - #plotter.plot_mc_vs_data('ss/p1p2p3_enhance_wz', 'subMTMass', xaxis='m_{#mu#mu} (GeV)', xrange=(0, 120), rebin=10) - #plotter.add_cms_blurb(sqrts) - #plotter.save('mcdata-ss-p1p2p3-enhance_wz-subMTMass') + plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'm2_t_Mass#LT', xaxis='m_{#mu#mu} (GeV)', + xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-ss-p1p2p3-enhance_wz-subMass') - plotter.set_subdir('WZ_enhanced') - - plotter.plot_final_wz('m1_t_Mass', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-leadMass') - - plotter.plot_final_wz('m2_t_Mass#LT', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', - project=[0,650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-subMass') - - plotter.plot_final_wz('m2Pt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', - project=[0,650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-m2Pt') + plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'm1_t_Mass', xaxis='m_{#mu#mu} (GeV)', + xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-ss-p1p2p3-enhance_wz-leadMass') + + plotter.set_subdir('WZ_enhanced') + + plotter.plot_final_wz('m1_t_Mass', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-leadMass') + + plotter.plot_final_wz('m2_t_Mass#LT', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-subMass') + + plotter.plot_final_wz('m2Pt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-m2Pt') - plotter.plot_final_wz('m2JetPt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', - project=[0,650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-m2JetPt') + plotter.plot_final_wz('m2JetPt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-m2JetPt') + + if not options.no_signal: + ########################################################################### + ## Signal region plots ################################################ + ########################################################################### + plotter.set_subdir('') + #rebin_slim = range(20, 91, 10)+[110,200] + + for label, proj_range in categories.iteritems(): + for tau_charge in ['tau_os', 'tau_ss']: + if tau_charge == 'tau_os': + plotter.set_subdir('%s' % label) + else: + plotter.set_subdir('%s_charge3' % label) + + plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, + yaxis='Events / GeV', show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s' % label) + + plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', + project=proj_range, project_axis='X', + yaxis='Events', show_error=True, x_range=[0,199], + maxy=15.6, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-const_bin-%s' % label, verbose=True) + + #data_view = plotter.make_signal_views(unblinded=(not plotter.blind), + # qcd_weight_fraction=0.5, + # rebin=20, project=proj_range, project_axis='X')['data'] + #data_hist = data_view.Get('m2_t_Mass#LT') + #data_hist.GetXaxis().SetRangeUser(0,200) + #data_hist.GetXaxis().SetRangeUser(0,15.6) + #data_hist.SetMarkerColor(2) + #data_hist.Draw() + #plotter.add_cms_blurb(sqrts) + #plotter.save('bareData-subMass-const_bin-%s' % label) + + plotter.plot_final('m2_t_Mass#LT', 300, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s-counting' % label, json=True) #, dotc=True, dotroot=True) + + #pt + plotter.plot_final("m1Pt#LT" , 10, xaxis='p_{T#mu_{1}} (GeV)', + maxy=None, project=proj_range, project_axis='X', + show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m1Pt-%s' % label) + + plotter.plot_final("m2Pt#LT" , 10, xaxis='p_{T#mu_{2}} (GeV)', maxy=None, + project=proj_range, project_axis='X', + show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m2Pt-%s' % label) + + plotter.plot_final("m1JetPt#LT" , 10, xaxis='p_{T Jet #mu_{1}} (GeV)', + maxy=None, project=proj_range, project_axis='X', + show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m1JetPt-%s' % label) + + plotter.plot_final("m2JetPt#LT" , 10, xaxis='p_{T Jet #mu_{2}} (GeV)', + maxy=None, project=proj_range, project_axis='X', + show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m2JetPt-%s' % label) + + plotter.plot_final("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-tPt-%s' % label) + + #eta + plotter.plot_final("m1AbsEta#LT", 10, xaxis='|#eta_{#mu_{1}}|', maxy=None, + project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m1AbsEta-%s' % label) + + plotter.plot_final("m2AbsEta#LT", 10, xaxis='|#eta_{#mu_{2}}|' , maxy=None, + project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m2AbsEta-%s' % label) + + plotter.plot_final("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, + project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-tAbsEta-%s' % label) + + #DR + plotter.plot_final("m1_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{1}#tau}', maxy=None, + project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m1_t_DR-%s' % label) + + plotter.plot_final("m2_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, + project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m2_t_DR-%s' % label) + + #Jet BTag + + #from pdb import set_trace; set_trace() + plotter.plot_final("m2JetBtag#LT", [-100, -40, 20, 100], xaxis='#mu_{2} Jet Btag' , + maxy=None, project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m2JetBtag-%s' % label, dotroot=True) + + plotter.plot_final("m1JetBtag#LT", 1, xaxis='#mu_{1} Jet Btag' , maxy=None, + project=proj_range, project_axis='X', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m1JetBtag-%s' % label) + + plotter.plot_final("m2JetCSVBtag#LT", 1, xaxis='#mu_{2} Jet CSV Btag' , maxy=None, + project=proj_range, project_axis='X', x_range=[0,1], show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m2JetCSVBtag-%s' % label, dotroot=True) + + plotter.plot_final("m1JetCSVBtag#LT", 1, xaxis='#mu_{1} Jet CSV Btag' , maxy=None, + project=proj_range, project_axis='X', x_range=[0,1], show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-m1JetCSVBtag-%s' % label) + + plotter.set_subdir('') + plotter.plot_final('LT', 10, xaxis='LT (GeV)', maxy=15) + plotter.add_cms_blurb(sqrts) + plotter.save('final-LT') + + if not options.no_f3: + ########################################################################### + ## F3 enhanced region plots ########################################### + ########################################################################### + plotter.set_subdir('f3') + plotter.plot_final_f3('LT', [0, 50, 75, 100, 125, 150, 200, 300, 500], xaxis='LT (GeV)', maxy=None, + show_ratio=True, fit = { 'model' : ("slope*x + offset", "offset[0, -1, 1], slope[0,-1,1]"), + 'range' : [50, 500], 'options' : 'QIRMENS', + 'stat position' : 'bottom-left'}) + plotter.add_cms_blurb(sqrts) + plotter.save('final-LT-tauOS-chi2', verbose=True) + + plotter.plot_final_f3('LT', [0, 50, 75, 100, 125, 150, 200, 300, 500], xaxis='LT (GeV)', maxy=None, + show_ratio=True, fit = { 'model' : ("slope*x + offset", "offset[0, -1, 1], slope[0,-1,1]"), + 'range' : [50, 500], 'options' : 'WLQIRMENS', + 'stat position' : 'bottom-left'}) + plotter.add_cms_blurb(sqrts) + plotter.save('final-LT-tauOS-likelihood') + + plotter.plot_final_f3('LT', [0, 50, 130, 500], xaxis='LT (GeV)', maxy=None, show_ratio=True) + plotter.add_cms_blurb(sqrts) + plotter.save('final-LT-tauOS-2categories') + + plotter.plot_final_f3('LT', [0, 50, 75, 100, 125, 150, 200, 300, 500], xaxis='LT (GeV)', tau_charge='tau_ss', + maxy=None, show_ratio=True, + fit = {'range' : [50, 500], 'model' : ("slope*x + offset", "offset[0, -1, 1], slope[0,-1,1]")}) + plotter.add_cms_blurb(sqrts) + plotter.save('final-LT-tauSS') + + plotter.plot_final_f3('LT', [0, 50, 130, 500], xaxis='LT (GeV)', tau_charge='tau_ss', maxy=None, show_ratio=True) + plotter.add_cms_blurb(sqrts) + plotter.save('final-LT-tauSS-2categories') + + for label, proj_range in categories.iteritems(): + for tau_charge in ['tau_os', 'tau_ss']: + if tau_charge == 'tau_os': + plotter.set_subdir('f3/%s' % label) + else: + plotter.set_subdir('f3/%s_charge3' % label) + + plotter.plot_final_f3('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', + maxy=None, project=proj_range, project_axis='X', differential=True, + show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s' % label) + + plotter.plot_final_f3('m2_t_Mass#LT', 300, xaxis='m_{#mu_{2}#tau} (GeV)', + maxy=None, project=proj_range, project_axis='X', + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s-counting' % label, json=True, verbose=True) + + #pt + plotter.plot_final_f3("m1Pt#LT" , 10, xaxis='p_{T#mu_{1}} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m1Pt-%s' % label) + + plotter.plot_final_f3("m2Pt#LT" , 10, xaxis='p_{T#mu_{2}} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m2Pt-%s' % label) + + plotter.plot_final_f3("m1JetPt#LT" , 10, xaxis='p_{T Jet #mu_{1}} (GeV)', + maxy=None, project=proj_range, project_axis='X', + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m1JetPt-%s' % label) + + plotter.plot_final_f3("m2JetPt#LT" , 10, xaxis='p_{T Jet #mu_{2}} (GeV)', + maxy=None, project=proj_range, project_axis='X', + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m2JetPt-%s' % label) + + plotter.plot_final_f3("tPt#LT", 10, xaxis='p_{T#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-tPt-%s' % label) + + #eta + plotter.plot_final_f3("m1AbsEta#LT", 10, xaxis='|#eta_{#mu_{1}}|', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m1AbsEta-%s' % label) + + plotter.plot_final_f3("m2AbsEta#LT", 10, xaxis='|#eta_{#mu_{2}}|', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m2AbsEta-%s' % label) + + plotter.plot_final_f3("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-tAbsEta-%s' % label) + + #DR + plotter.plot_final_f3("m1_t_DR#LT", 5, xaxis='#DeltaR_{#mu_{1}#tau}', + maxy=None, project=proj_range, project_axis='X', + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m1_t_DR-%s' % label) + + plotter.plot_final_f3("m2_t_DR#LT", 5, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m2_t_DR-%s' % label) + + #Jet BTag + + #from pdb import set_trace; set_trace() + plotter.plot_final_f3("m2JetBtag#LT", [-100, -40, 20, 100], xaxis='#mu_{2} Jet Btag', + maxy=None, project=proj_range, project_axis='X', + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m2JetBtag-%s' % label, dotroot=True) + + plotter.plot_final_f3("m1JetBtag#LT", 1, xaxis='#mu_{1} Jet Btag' , maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m1JetBtag-%s' % label) + + plotter.plot_final_f3("m2JetCSVBtag#LT", 1, xaxis='#mu_{2} Jet CSV Btag', maxy=None, + project=proj_range, project_axis='X', x_range=[0,1], + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m2JetCSVBtag-%s' % label, dotroot=True) + + plotter.plot_final_f3("m1JetCSVBtag#LT", 1, xaxis='#mu_{1} Jet CSV Btag', maxy=None, + project=proj_range, project_axis='X', x_range=[0,1], + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-m1JetCSVBtag-%s' % label) + + #TAU ISO + plotter.plot_final_f3("tRawIso3Hits#LT", [0,5,10,15,20,25,30,35,40,50,60,120,200], + xaxis='#tau 3Hits Raw Iso', maxy=None, + project=proj_range, project_axis='X', + tau_charge=tau_charge, show_ratio=True, + fit = { 'model' : ("slope*x + offset", "offset[0, -1, 1], slope[0,-1,1]"), + 'options' : 'WLQIRMENS', + 'stat position' : 'bottom-right'}) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-tRawIso3Hits-Likelihood-%s' % label) + + plotter.plot_final_f3("tRawIso3Hits#LT", [0,5,10,15,20,25,30,35,40,50,60,120,200], + xaxis='#tau 3Hits Raw Iso', maxy=None, + project=proj_range, project_axis='X', + tau_charge=tau_charge, show_ratio=True, + fit = { 'model' : ("slope*x + offset", "offset[0, -1, 1], slope[0,-1,1]"), + 'options' : 'QIRMENS', + 'stat position' : 'bottom-right'}) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-tRawIso3Hits-chi2-%s' % label) + + plotter.plot_final_f3("tRawIso3Hits#LT", [0,5,10,15,20,25,30,35,40,50,60,120,200], + xaxis='#tau 3Hits Raw Iso', maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge, show_ratio=True, + wz_error=0., zz_error =0.) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-tRawIso3Hits-noDibosonErr-%s' % label) + #END OF if not options.dry_run: + if not options.no_shapes: ########################################################################### - ## Signal region plots ################################################ + ## Making shape file ################################################# ########################################################################### plotter.set_subdir('') - #rebin_slim = range(20, 91, 10)+[110,200] - - for label, proj_range in categories.iteritems(): - for tau_charge in ['tau_os', 'tau_ss']: - if tau_charge == 'tau_os': - plotter.set_subdir('%s' % label) - else: - plotter.set_subdir('%s_charge3' % label) - - plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', differential=True, - yaxis='Events / GeV', show_error=True, tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-%s' % label) - - plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', - project=proj_range, project_axis='X', - yaxis='Events', show_error=True, x_range=[0,199], - maxy=15.6, tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-const_bin-%s' % label, verbose=True) - - #data_view = plotter.make_signal_views(unblinded=(not plotter.blind), - # qcd_weight_fraction=0.5, - # rebin=20, project=proj_range, project_axis='X')['data'] - #data_hist = data_view.Get('m2_t_Mass#LT') - #data_hist.GetXaxis().SetRangeUser(0,200) - #data_hist.GetXaxis().SetRangeUser(0,15.6) - #data_hist.SetMarkerColor(2) - #data_hist.Draw() - #plotter.add_cms_blurb(sqrts) - #plotter.save('bareData-subMass-const_bin-%s' % label) - - plotter.plot_final('m2_t_Mass#LT', 300, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', show_error=True, tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-%s-counting' % label) #, dotc=True, dotroot=True) - - #pt - plotter.plot_final("m1Pt#LT" , 10, xaxis='p_{T#mu_{1}} (GeV)', - maxy=None, project=proj_range, project_axis='X', - show_error=True, tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1Pt-%s' % label) - - plotter.plot_final("m2Pt#LT" , 10, xaxis='p_{T#mu_{2}} (GeV)', maxy=None, - project=proj_range, project_axis='X', - show_error=True, tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2Pt-%s' % label) - - plotter.plot_final("m1JetPt#LT" , 10, xaxis='p_{T Jet #mu_{1}} (GeV)', - maxy=None, project=proj_range, project_axis='X', - show_error=True, tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1JetPt-%s' % label) - - plotter.plot_final("m2JetPt#LT" , 10, xaxis='p_{T Jet #mu_{2}} (GeV)', - maxy=None, project=proj_range, project_axis='X', - show_error=True, tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2JetPt-%s' % label) - - plotter.plot_final("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-tPt-%s' % label) - - #eta - plotter.plot_final("m1AbsEta#LT", 10, xaxis='|#eta_{#mu_{1}}|', maxy=None, - project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1AbsEta-%s' % label) - - plotter.plot_final("m2AbsEta#LT", 10, xaxis='|#eta_{#mu_{2}}|' , maxy=None, - project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2AbsEta-%s' % label) - - plotter.plot_final("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, - project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-tAbsEta-%s' % label) - - #DR - plotter.plot_final("m1_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{1}#tau}', maxy=None, - project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1_t_DR-%s' % label) - - plotter.plot_final("m2_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, - project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2_t_DR-%s' % label) - - #Jet BTag - - #from pdb import set_trace; set_trace() - plotter.plot_final("m2JetBtag#LT", [-100, -40, 20, 100], xaxis='#mu_{2} Jet Btag' , - maxy=None, project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2JetBtag-%s' % label, dotroot=True) - - plotter.plot_final("m1JetBtag#LT", 1, xaxis='#mu_{1} Jet Btag' , maxy=None, - project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1JetBtag-%s' % label) - - plotter.plot_final("m2JetCSVBtag#LT", 1, xaxis='#mu_{2} Jet CSV Btag' , maxy=None, - project=proj_range, project_axis='X', x_range=[0,1], show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2JetCSVBtag-%s' % label, dotroot=True) - - plotter.plot_final("m1JetCSVBtag#LT", 1, xaxis='#mu_{1} Jet CSV Btag' , maxy=None, - project=proj_range, project_axis='X', x_range=[0,1], show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1JetCSVBtag-%s' % label) - - #from pdb import set_trace; set_trace() - plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, - project=[0, 130], project_axis='X', differential=True, yaxis='Events / GeV') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTLow') - - plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=[130, 650], project_axis='X', differential=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTHigh') - - plotter.plot_final('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=[80, 650], project_axis='X', differential=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTCut') - - plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=[80, 650], project_axis='X', differential=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTCut-flatbin') - - plotter.plot_final('LT', 5, xaxis='LT (GeV)', maxy=15) - plotter.add_cms_blurb(sqrts) - plotter.save('final-LT') - - plotter.plot_final('m1Pt#LT', 10, project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1Pt') - - plotter.plot_final('m2Pt#LT', 10, project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2Pt') - - plotter.plot_final('m2Pt#LT', 10, project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2Pt') - - plotter.plot_final('m1AbsEta#LT', 10, project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1AbsEta') - - plotter.plot_final('m2AbsEta#LT', 10, project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2AbsEta') - - plotter.plot_final('m2AbsEta#LT', 10, project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2AbsEta') - - plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass') - - plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', qcd_weight_fraction=1, project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-qweight-subMass') - - plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', qcd_weight_fraction=0.5, project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-qweight05-subMass') - - plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', show_error=True, project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-werror') - - plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', - show_error=True, fake_error=0, wz_error=0, zz_error=0 - , project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-wshapeerror') - - plotter.plot_final('m2RelPFIsoDB', 10) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2Iso') - - ########################################################################### - ## F3 enhanced region plots ########################################### - ########################################################################### - - for label, proj_range in categories.iteritems(): - for tau_charge in ['tau_os', 'tau_ss']: - if tau_charge == 'tau_os': - plotter.set_subdir('f3/%s' % label) - else: - plotter.set_subdir('f3/%s_charge3' % label) - plotter.plot_final_f3('m2_t_Mass#LT', rebin_slim, xaxis='m_{#mu_{2}#tau} (GeV)', - maxy=None, project=proj_range, project_axis='X', differential=True, - show_error=True, tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s' % label) - - plotter.plot_final_f3('m2_t_Mass#LT', 300, xaxis='m_{#mu_{2}#tau} (GeV)', - maxy=None, project=proj_range, project_axis='X', - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) - - #pt - plotter.plot_final_f3("m1Pt#LT" , 10, xaxis='p_{T#mu_{1}} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1Pt-%s' % label) - - plotter.plot_final_f3("m2Pt#LT" , 10, xaxis='p_{T#mu_{2}} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2Pt-%s' % label) - - plotter.plot_final_f3("m1JetPt#LT" , 10, xaxis='p_{T Jet #mu_{1}} (GeV)', - maxy=None, project=proj_range, project_axis='X', - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1JetPt-%s' % label) - - plotter.plot_final_f3("m2JetPt#LT" , 10, xaxis='p_{T Jet #mu_{2}} (GeV)', - maxy=None, project=proj_range, project_axis='X', - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2JetPt-%s' % label) - - plotter.plot_final_f3("tPt#LT", 10, xaxis='p_{T#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tPt-%s' % label) - - #eta - plotter.plot_final_f3("m1AbsEta#LT", 10, xaxis='|#eta_{#mu_{1}}|', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1AbsEta-%s' % label) - - plotter.plot_final_f3("m2AbsEta#LT", 10, xaxis='|#eta_{#mu_{2}}|', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2AbsEta-%s' % label) - - plotter.plot_final_f3("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tAbsEta-%s' % label) - - #DR - plotter.plot_final_f3("m1_t_DR#LT", 5, xaxis='#DeltaR_{#mu_{1}#tau}', - maxy=None, project=proj_range, project_axis='X', - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1_t_DR-%s' % label) - - plotter.plot_final_f3("m2_t_DR#LT", 5, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2_t_DR-%s' % label) - - #Jet BTag + prefixes = [options.prefix+'$'] if options.prefix else [''] + prefixes = [i+'$' for i in options.prefixes.split(',') if i] if options.prefixes else prefixes + for prefix in prefixes: + #plotter.plot_final(prefix+'m2_t_Mass', 20, xaxis='m_{#mu_{2}#tau} (GeV)', qcd_weight_fraction=0.5) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-%s-qweight05-subMass' % options.prefix) + # + #plotter.plot_final_f3(prefix+'m2_t_Mass', 20, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=0.5, show_error=True) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-%s-f3-qweight05-subMass' % options.prefix) + + shape_prefix = prefix if len(prefixes) > 1 else '' + shape_prefix = shape_prefix.replace(':','_').replace('$','_') - #from pdb import set_trace; set_trace() - plotter.plot_final_f3("m2JetBtag#LT", [-100, -40, 20, 100], xaxis='#mu_{2} Jet Btag', - maxy=None, project=proj_range, project_axis='X', - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2JetBtag-%s' % label, dotroot=True) - - plotter.plot_final_f3("m1JetBtag#LT", 1, xaxis='#mu_{1} Jet Btag' , maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1JetBtag-%s' % label) - - plotter.plot_final_f3("m2JetCSVBtag#LT", 1, xaxis='#mu_{2} Jet CSV Btag', maxy=None, - project=proj_range, project_axis='X', x_range=[0,1], - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2JetCSVBtag-%s' % label, dotroot=True) - - plotter.plot_final_f3("m1JetCSVBtag#LT", 1, xaxis='#mu_{1} Jet CSV Btag', maxy=None, - project=proj_range, project_axis='X', x_range=[0,1], - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1JetCSVBtag-%s' % label) - - - plotter.set_subdir('f3') - plotter.plot_final_f3('LT', 5, xaxis='LT (GeV)', qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-LT') - - plotter.plot_final_f3('m1_t_Mass', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-leadMass') - - plotter.plot_final_f3('m2_t_Mass#LT', 20, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=0, show_error=True, project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-wjetfake-subMass') - - plotter.plot_final_f3('m2_t_Mass#LT', 20, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=1, show_error=True, project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-qcdfake-subMass') - - plotter.plot_final_f3("m2JetBtag#LT", 4, xaxis='#mu_{2} Jet Btag' , maxy=None, project=[0, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2JetBtag') - - plotter.plot_final_f3("m1JetBtag#LT", 4, xaxis='#mu_{1} Jet Btag' , maxy=None, project=[0, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1JetBtag') - - plotter.plot_final_f3('m2_t_Mass#LT', 20, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=0.5, show_error=True, project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass') - - plotter.plot_final_f3('m2_t_Mass#LT', 300, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=0.5, show_error=True, project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-counting-like', dotc=True, dotroot=True) - - #plotter.plot_final_f3_split('m2_t_Mass#LT', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', project=[130, 650], project_axis='X') - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-f3-split-subMass') - - plotter.plot_final_f3('m1Pt#LT', 5, xaxis='p_{T#mu_{1}} (GeV)', project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1Pt') - - plotter.plot_final_f3('m1JetPt#LT', 5, xaxis='p_{TJet#mu_{1}} (GeV)', project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1JetPt') - - plotter.plot_final_f3('m1AbsEta#LT', 10, xaxis='|#eta_{#mu_{1}}| (GeV)', project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1AbsEta') - - plotter.plot_final_f3('m2Pt#LT', 5, xaxis='p_{T#mu_{2}} (GeV)', project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2Pt') - - plotter.plot_final_f3('m2JetPt#LT', 5, xaxis='p_{TJet#mu_{2}} (GeV)', project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2JetPt') - - plotter.plot_final_f3('m2AbsEta#LT', 10, xaxis='|#eta_{#mu_{2}}| (GeV)', project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2AbsEta') - - plotter.plot_final_f3('m1_t_DR#LT', 5, xaxis='#DeltaR_{#mu_{1}#tau}', project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1_t_DR') - - plotter.plot_final_f3('m2_t_DR#LT', 5, xaxis='#DeltaR_{#mu_{2}#tau}', project=[130, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2_t_DR') - - ########################################################################### - ## Check QCD contamination in control regions ############################ - ########################################################################### - plotter.set_subdir('qcd_contamination') - - #plotter.plot_qcd_contamination('m2_t_Mass', 2, 10) - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-qcd2-subMass') - # - #plotter.plot_qcd_contamination('m2_t_Mass', 1, 20) - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-qcd1-subMass') - # - #plotter.plot_qcd_contamination('m2JetPt', 2, 10) - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-qcd2-m2JetPt') - # - #plotter.plot_qcd_contamination('m1JetPt', 1, 20) - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-qcd1-m1JetPt') - - #END OF if not options.dry_run: - ########################################################################### - ## Making shape file ################################################# - ########################################################################### - plotter.set_subdir('') - prefixes = [options.prefix+'$'] if options.prefix else [''] - prefixes = [i+'$' for i in options.prefixes.split(',') if i] if options.prefixes else prefixes - for prefix in prefixes: - #plotter.plot_final(prefix+'m2_t_Mass', 20, xaxis='m_{#mu_{2}#tau} (GeV)', qcd_weight_fraction=0.5) - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-%s-qweight05-subMass' % options.prefix) - # - #plotter.plot_final_f3(prefix+'m2_t_Mass', 20, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', qcd_correction=False, qcd_weight_fraction=0.5, show_error=True) - #plotter.add_cms_blurb(sqrts) - #plotter.save('final-%s-f3-qweight05-subMass' % options.prefix) - - shape_prefix = prefix if len(prefixes) > 1 else '' - shape_prefix = shape_prefix.replace(':','_').replace('$','_') - - shape_file = ROOT.TFile( - os.path.join(plotter.outputdir, 'LTCut_mmt_shapes_%s.root' % ( plotter.period) ), 'RECREATE') - shape_dir = shape_file.mkdir('mmtCatHigh') - plotter.write_shapes(prefix+'m2_t_Mass#LT', 20, shape_dir, qcd_fraction=0.5, project=[80, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_w') - plotter.write_shapes(prefix+'m2_t_Mass#LT', 20, shape_dir, qcd_fraction=0.0, project=[80, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_q') - plotter.write_shapes(prefix+'m2_t_Mass#LT', 20, shape_dir, qcd_fraction=1.0, project=[80, 650], project_axis='X') - shape_file.Close() - - #rebin_slim = range(20, 91, 10)+[110,200] - shape_file = ROOT.TFile( - os.path.join(plotter.outputdir, '%smmt_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') - - shape_dir = shape_file.mkdir('mmtCatLow') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLow_w') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLow_q') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') - - shape_dir = shape_file.mkdir('mmtCatHigh') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_w') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_q') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') - - logging.warning('shape file %s created' % shape_file.GetName()) - shape_file.Close() + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, 'LTCut_mmt_shapes_%s.root' % ( plotter.period) ), 'RECREATE') + shape_dir = shape_file.mkdir('mmtCatHigh') + plotter.write_shapes(prefix+'m2_t_Mass#LT', 20, shape_dir, qcd_fraction=0.5, project=[80, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatHigh_w') + plotter.write_shapes(prefix+'m2_t_Mass#LT', 20, shape_dir, qcd_fraction=0.0, project=[80, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatHigh_q') + plotter.write_shapes(prefix+'m2_t_Mass#LT', 20, shape_dir, qcd_fraction=1.0, project=[80, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() + + + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, 'LTAll_mmt_shapes_%s.root' % ( plotter.period) ), 'RECREATE') + shape_dir = shape_file.mkdir('mmt') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmt_w') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmt_q') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() + + #rebin_slim = range(20, 91, 10)+[110,200] + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, '%smmt_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') + + shape_dir = shape_file.mkdir('mmtCatLow') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatLow_w') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatLow_q') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + + shape_dir = shape_file.mkdir('mmtCatHigh') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatHigh_w') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatHigh_q') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() - shape_file = ROOT.TFile( - os.path.join(plotter.outputdir, '%smmt_f3_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') - - shape_dir = shape_file.mkdir('mmtCatLow') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLow_w') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLow_q') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') - - shape_dir = shape_file.mkdir('mmtCatHigh') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_w') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_q') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') - - logging.warning('shape file %s created' % shape_file.GetName()) - shape_file.Close() + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, '%smmt_f3_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') + + shape_dir = shape_file.mkdir('mmtCatLow') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatLow_w') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatLow_q') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + + shape_dir = shape_file.mkdir('mmtCatHigh') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatHigh_w') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatHigh_q') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() - shape_file = ROOT.TFile( - os.path.join(plotter.outputdir, '%smmt_f3_all_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') - - shape_dir = shape_file.mkdir('mmtCatLow') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLow_w') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLow_q') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') - - shape_dir = shape_file.mkdir('mmtCatHigh') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_w') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_q') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') - - shape_dir = shape_file.mkdir('mmtCatLowf3') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLowf3_w') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLowf3_q') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') - - shape_dir = shape_file.mkdir('mmtCatHighf3') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHighf3_w') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHighf3_q') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') - - logging.warning('shape file %s created' % shape_file.GetName()) - shape_file.Close() + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, '%smmt_f3_all_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') + + shape_dir = shape_file.mkdir('mmtCatLow') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatLow_w') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatLow_q') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + + shape_dir = shape_file.mkdir('mmtCatHigh') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatHigh_w') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatHigh_q') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + + shape_dir = shape_file.mkdir('mmtCatLowf3') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatLowf3_w') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatLowf3_q') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + + shape_dir = shape_file.mkdir('mmtCatHighf3') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatHighf3_w') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmtCatHighf3_q') + plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() From dc8ee93acb31b52be656b00a7baa697411850587 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 30 Oct 2013 04:20:30 -0500 Subject: [PATCH 081/192] bugfix and sync improvements --- wh/baseSelections.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/wh/baseSelections.py b/wh/baseSelections.py index 2e16cf93..6f485474 100755 --- a/wh/baseSelections.py +++ b/wh/baseSelections.py @@ -16,7 +16,6 @@ def muSelection(row, name): if getattr( row, getVar(name,'AbsEta')) > 2.4: return False if not getattr( row, getVar(name,'PixHits')): return False if getattr( row, getVar(name,'JetCSVBtag')) > 0.8: return False - #if getattr( row, getVar(name,'JetBtag')) > 3.3: return False #was 3.3 if abs(getattr( row, getVar(name,'DZ'))) > 0.2: return False return True @@ -24,10 +23,9 @@ def eSelection(row, name): if getattr( row, getVar(name,'Pt')) < 10: return False if getattr( row, getVar(name,'AbsEta')) > 2.5: return False if getattr( row, getVar(name,'MissingHits')): return False - if getattr( row, getVar(name,'HasConversion')): return False + if getattr( row, getVar(name,'HasMatchedConversion')): return False if not getattr( row, getVar(name,'ChargeIdTight')): return False if getattr( row, getVar(name,'JetCSVBtag')) > 0.8: return False - #if getattr( row, getVar(name,'JetBtag')) > 3.3: return False if abs(getattr( row, getVar(name,'DZ'))) > 0.2: return False return True @@ -39,12 +37,18 @@ def tauSelection(row, name): #VETOS -def vetos(row): +def vetos(row, tracker=None): if row.muVetoPt5IsoIdVtx: return False + if tracker: tracker.Fill('muon veto') + if row.bjetCSVVetoZHLike: return False - #if row.bjetCSVVeto: return False + if tracker: tracker.Fill('bjet veto') + if row.eVetoMVAIsoVtx: return False + if tracker: tracker.Fill('electron veto') + if row.tauVetoPt20Loose3HitsVtx: return False + if tracker: tracker.Fill('tau veto') return True def lepton_id_iso(row, name, label): #label in the format eidtype_isotype From 2af281ab4f4f2c96e5da008aa9c52a88d1b7ed54 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 30 Oct 2013 04:21:24 -0500 Subject: [PATCH 082/192] new naming to make channels completely independent. cluenup --- wh/fakerate_functions.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/wh/fakerate_functions.py b/wh/fakerate_functions.py index 7e5d3d56..6505b944 100755 --- a/wh/fakerate_functions.py +++ b/wh/fakerate_functions.py @@ -116,17 +116,17 @@ def make_null_dict(template, variables, mapper=None): #no changes in muonID in 2013 mapper = {'eid1[0-9][A-Z][a-z]+_':'', 'idiso02' : 'pfidiso02'} variables = ['muonJetPt', 'muonPt', 'numJets20'] #, 'muonJetCSVBtag'] -lowpt_mu_fr = make_mva_functor_dict(frfit_dir + '/m_wjets_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +lowpt_mu_fr = make_mva_functor_dict(frfit_dir + '/mm_wjets_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) highpt_mu_fr = lowpt_mu_fr -lowpt_mu_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_qcd_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +lowpt_mu_qcd_fr = make_mva_functor_dict(frfit_dir + '/mm_qcd_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) highpt_mu_qcd_fr = lowpt_mu_qcd_fr variables = ['muonJetPt', 'muonPt', 'numJets20'] -lowpt_mue_fr = make_mva_functor_dict(frfit_dir + '/m_Mwjets_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +lowpt_mue_fr = make_mva_functor_dict(frfit_dir + '/em_Mwjets_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) highpt_mue_fr = lowpt_mue_fr -lowpt_mue_qcd_fr = make_mva_functor_dict(frfit_dir + '/m_Mqcd_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) +lowpt_mue_qcd_fr = make_mva_functor_dict(frfit_dir + '/em_Mqcd_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) highpt_mue_qcd_fr = lowpt_mue_qcd_fr @@ -136,10 +136,10 @@ def make_null_dict(template, variables, mapper=None): variables = ['electronJetPt', 'electronPt', 'numJets20'] #EMT -lowpt_e_fr = make_mva_functor_dict(frfit_dir + '/e_wjets_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) +lowpt_e_fr = make_mva_functor_dict(frfit_dir + '/em_wjets_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) highpt_e_fr = lowpt_e_fr -lowpt_e_qcd_fr = make_mva_functor_dict(frfit_dir + '/e_qcd_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) +lowpt_e_qcd_fr = make_mva_functor_dict(frfit_dir + '/em_qcd_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) highpt_e_qcd_fr = lowpt_e_qcd_fr #EET @@ -168,12 +168,3 @@ def make_null_dict(template, variables, mapper=None): e_charge_flip_down = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_%s.root", "efficiency_map_statDown") mass_scaler = make_scaler_dict(frfit_dir+"/charge_flip_prob_map_%s.root", 'mass_scale') default_scaler = mass_scaler[mass_scaler.keys()[0]] - - -#e1_charge_flip = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e1_%s.root", "efficiency_map") -#e1_charge_flip_up = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e1_%s.root", "efficiency_map_statUp") -#e1_charge_flip_down = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e1_%s.root", "efficiency_map_statDown") -# -#e2_charge_flip = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e2_%s.root", "efficiency_map") -#e2_charge_flip_up = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e2_%s.root", "efficiency_map_statUp") -#e2_charge_flip_down = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_e2_%s.root", "efficiency_map_statDown") From a8ab7eb1fbdd8bd299e9aafef288e896af27d695 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 30 Oct 2013 04:21:53 -0500 Subject: [PATCH 083/192] added mc matching functions --- wh/mcCorrectors.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/wh/mcCorrectors.py b/wh/mcCorrectors.py index 483b42e5..c49e5939 100644 --- a/wh/mcCorrectors.py +++ b/wh/mcCorrectors.py @@ -106,3 +106,35 @@ def get_electron_corrections(row,*args): ret *= electron_corrections(pt,abseta) return ret + + + + +######################################################################## +## +## MC MATCHING +## +######################################################################## + + +from FinalStateAnalysis.PlotTools.decorators import memo + +@memo +def getVar(name, var): + return name+var + +def match_mc_object(row, obj_name): + '''check that muons are real muons, electrons are real electrons, + had taus are real had taus and little furry creatures from alpha + centauri are real little furry creatures form alpha centauri''' + if obj_name[0] == 'm': + return (abs( getattr(row, getVar(obj_name, 'GenPdgId')) ) == 13) + elif obj_name[0] == 'e': + return (abs( getattr(row, getVar(obj_name, 'GenPdgId')) ) == 11) + elif obj_name[0] == 't': + return ( getattr(row, getVar(obj_name, 'GenDecayMode')) > -1) + return False + +def mc_matching(row, *args): + 'matches object to the gen-level object' + return all( match_mc_object(row, i) for i in args ) From 2f7c9e25bb8b839de02e8f0118e8fdf788ef7cb5 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Dec 2013 04:55:14 -0600 Subject: [PATCH 084/192] test charge flip shape unc --- wh/ControlZEE.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/wh/ControlZEE.py b/wh/ControlZEE.py index 3a60b228..a5a83d1f 100644 --- a/wh/ControlZEE.py +++ b/wh/ControlZEE.py @@ -47,9 +47,9 @@ def f_(*args,**kargs): leading_e_fr_wjets = make_weight(frfits.highpt_ee_fr[leading_iso] ) -leading_e_fr_qcd = make_weight(frfits.highpt_ee_qcd_fr[leading_iso] ) +leading_e_fr_qcd = None #make_weight(frfits.highpt_ee_qcd_fr[leading_iso] ) subleading_e_fr_wjets = make_weight(frfits.lowpt_ee_fr[subleading_iso] ) -subleading_e_fr_qcd = make_weight(frfits.lowpt_ee_qcd_fr[subleading_iso] ) +subleading_e_fr_qcd = None #make_weight(frfits.lowpt_ee_qcd_fr[subleading_iso] ) def assign_charge_weight_one_maps(dir_, row): if "charge_weightSysUp" in dir_: return charge_flip_up_lead(row.e1AbsEta,row.e1Pt) + charge_flip_up_sub(row.e2AbsEta,row.e2Pt) @@ -89,6 +89,8 @@ def book_(dirname): self.book(dirname, 'SCEnergy', 'electron Super Cluster energy', 500, 0, 1000) self.book(dirname, 'SCDPhi' , 'electron Super Cluster DeltaPhi', 180, 0, math.Pi()) self.book(dirname, 'TrkMass' , 'Dielectrons invariant mass; M_{ee} [GeV];counts', 110, 40, 150) + self.book(dirname, 'TrkMass_low' , 'Dielectrons invariant mass; M_{ee} [GeV];counts', 110, 40, 150) + self.book(dirname, 'TrkMass_high', 'Dielectrons invariant mass; M_{ee} [GeV];counts', 110, 40, 150) self.book(dirname, 'TrkMass_NoWeight', 'Dielectrons invariant mass; M_{ee} [GeV];counts', 110, 40, 150) self.book(dirname, 'TrkMass_NOSCALE' , 'Dielectrons invariant mass; M_{ee} [GeV];counts', 110, 40, 150) self.book(dirname, 'SCMass' , 'Dielectrons Super Cluster invariant mass; M_{ee} [GeV];counts', 110, 40, 150) @@ -105,7 +107,7 @@ def book_(dirname): self.dirs = ['/'.join([sign,id_,weight,ch_weight]) for sign in ['os','ss'] for id_ in [h+k for h in ['p1','f1'] for k in ['p2','f2'] ] - for weight in ['','wjet_w','qcd_w'] + for weight in ['','wjet_w'] #,'qcd_w'] for ch_weight in ["","charge_weight","charge_weightSysUp","charge_weightSysDwn"] if 'f' in id_ or weight == '' if ch_weight == '' or sign == 'os' @@ -163,7 +165,10 @@ def process(self): histos = self.dir_based_histograms mc_weight = self.mc_weight def fill_histos(dirname, row, weight): - mass = frfits.mass_scaler[leading_iso](row.e1_e2_Mass) if "charge_weight" in dirname else row.e1_e2_Mass + mass = frfits.default_scaler(row.e1_e2_Mass) if "charge_weight" in dirname else row.e1_e2_Mass + mass_up = frfits.default_scaler_up(row.e1_e2_Mass) if "charge_weight" in dirname else row.e1_e2_Mass + mass_dw = frfits.default_scaler_down(row.e1_e2_Mass) if "charge_weight" in dirname else row.e1_e2_Mass + histos[dirname]['ePt' ].Fill(row.e1Pt,weight) histos[dirname]['eAbsEta' ].Fill(row.e1AbsEta,weight) histos[dirname]['SCEnergy'].Fill(row.e1SCEnergy,weight) @@ -171,6 +176,8 @@ def fill_histos(dirname, row, weight): histos[dirname]['eAbsEta' ].Fill(row.e2AbsEta,weight) histos[dirname]['SCEnergy'].Fill(row.e2SCEnergy,weight) histos[dirname]['TrkMass' ].Fill(mass, weight) + histos[dirname]['TrkMass_low' ].Fill(mass_dw, weight) + histos[dirname]['TrkMass_high' ].Fill(mass_up, weight) #histos[dirname]['SCMass' ].Fill(sc_inv_mass(row),weight) histos[dirname]["e1Pt" ].Fill(row.e1Pt,weight) histos[dirname]["e2Pt" ].Fill(row.e2Pt,weight) From d9d8f35da2b7b8bbfee88d4a2d81c01b33743dcd Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Dec 2013 04:56:35 -0600 Subject: [PATCH 085/192] added sync tools --- wh/FakeRatesEE.py | 93 +++++++++++++++++++++++++++---- wh/FakeRatesEM.py | 139 ++++++++++++++++++++++++++++++++++++++++------ wh/FakeRatesMM.py | 116 +++++++++++++++++++++++++++----------- 3 files changed, 289 insertions(+), 59 deletions(-) diff --git a/wh/FakeRatesEE.py b/wh/FakeRatesEE.py index 16bdc526..05199c66 100755 --- a/wh/FakeRatesEE.py +++ b/wh/FakeRatesEE.py @@ -28,9 +28,32 @@ from array import array from pprint import pprint import ROOT - +import FinalStateAnalysis.PlotTools.pytree as pytree +from cutflowtracker import cut_flow_tracker +import math + +def inv_mass(pt1,eta1,phi1,pt2,eta2,phi2): + return math.sqrt( + 2*pt1*pt2*(math.cosh(eta1 - eta2) - math.cos(phi1 - phi2)) + ) + +cut_flow_step = ['bare', 'trigger', 'e1_e2_DR', + 'e1 presel', 'e2 presel', 'jet requirement', + 'muon veto', 'bjet veto', 'electron veto', 'tau veto', + 'region assignment', +] + + +region_for_event_list = os.environ.get('EVTLIST_REGION','') +zMassCut = 'NoZmass' in region_for_event_list +if zMassCut: + cut_flow_step.append('zMassCut') +region_for_event_list = region_for_event_list.replace('NoZmass','') +SYNC = ('SYNC' in os.environ) and eval(os.environ['SYNC']) +print region_for_event_list + class FakeRatesEE(MegaBase): - tree = 'ee/final/Ntuple' + tree = 'ee/final/Ntuple' if not SYNC else 'Ntuple' def __init__(self, tree, outfile, **kwargs): super(FakeRatesEE, self).__init__(tree, outfile, **kwargs) # Use the cython wrapper @@ -47,7 +70,13 @@ def __init__(self, tree, outfile, **kwargs): for j in self.iso_points] def begin(self): - for region in ['wjets', 'qcd', 'wjetsNoZmass', 'qcdNoZmass']: + self.book('', "CUT_FLOW", "Cut Flow", len(cut_flow_step), 0, len(cut_flow_step)) + xaxis = self.histograms['CUT_FLOW'].GetXaxis() + self.cut_flow_histo = self.histograms['CUT_FLOW'] + for i, name in enumerate(cut_flow_step): + xaxis.SetBinLabel(i+1, name) + + for region in ['wjetsLtLow', 'qcd', 'wjetsNoZmass', 'wjetsLtLowNoZmass', 'qcdNoZmass']: for denom in ['pt10', 'pt20']: denom_key = (region, denom) denom_histos = {} @@ -57,9 +86,17 @@ def begin(self): denom_histos['electronInfo'] = self.book( os.path.join(region, denom), 'electronInfo', "electronInfo", - 'electronPt:electronJetPt:electronJetCSVBtag:numJets20:numJets40:weight:'+':'.join(self.lepIds), + 'electronPt:electronJetPt:electronJetCSVBtag:electronJetMass:numJets20:numJets40:weight:'+':'.join(self.lepIds), type=ROOT.TNtuple) + denom_histos['evtInfo'] = self.book( + os.path.join(region, denom), + 'evtInfo', 'evtInfo', + 'run/l:lumi/l:evt/l:e1Pt/D:e1Eta/D:e1Phi/D:e2Pt/D:e2Eta/D:e2Phi/D:e1ChargeIdTight/D' +\ + ':e2ChargeIdTight/D:e2RelPFIsoDB/D:e2MtToMET/D:e1MtToMET/D:bjetCSVVetoZHLike/D'+\ + ':e1RelPFIsoDB/D:e2MVAIDH2TauWP/D:e1MVAIDH2TauWP/D:e1_e2_SS/D:e1MVANonTrig/D:e2MVANonTrig/D', + type=pytree.PyTree) + for numerator in self.lepIds: num_key = (region, denom, numerator) num_histos = {} @@ -94,19 +131,32 @@ def book_histo(name, *args, **kwargs): def process(self): + cut_flow_histo = self.cut_flow_histo + cut_flow_trk = cut_flow_tracker(cut_flow_histo) - def preselection(row): + def preselection(row, cut_flow_trk): if not row.doubleEPass: return False if not (row.e1MatchesDoubleEPath > 0 and \ row.e2MatchesDoubleEPath > 0): return False - if not row.e1Pt > 20: return False + cut_flow_trk.Fill('trigger') + if row.e1_e2_DR < 0.5: return False + cut_flow_trk.Fill('e1_e2_DR') + + if not row.e1Pt > 20: return False if not selections.eSelection(row, 'e1'): return False if not row.e1MVAIDH2TauWP: return False + cut_flow_trk.Fill('e1 presel') + if not selections.eSelection(row, 'e2'): return False + cut_flow_trk.Fill('e2 presel') + #if not (row.jetVeto40_DR05 >= 1): return False - if not (row.jetVeto20 > 1): return False - if not selections.vetos(row): return False + if row.jetVeto20 == 0: return False + cut_flow_trk.Fill('jet requirement') + + if not selections.vetos(row, cut_flow_trk): return False + return True def fill(the_histos, row, fillNtuple=False): @@ -137,14 +187,20 @@ def fill(the_histos, row, fillNtuple=False): #print id_iso_vals #print self.lepIds id_iso_vals = [float( i ) for i in id_iso_vals ] + electron_jet_mass = -1 #inv_mass(row.e2Pt, row.e2Eta, row.e2Phi, row.leadingJetPt, row.leadingJetEta, row.leadingJetPhi) + the_histos['electronInfo'].Fill( array("f", [row.e2Pt, max(row.e2Pt, row.e2JetPt), max(0, row.e2JetCSVBtag), - row.jetVeto20, row.jetVeto40_DR05, weight]+id_iso_vals) ) + electron_jet_mass, row.jetVeto20, row.jetVeto40_DR05, weight]+id_iso_vals) ) + the_histos['evtInfo'].Fill( row ) histos = self.histograms #pprint( histos) for row in self.tree: - if not preselection(row): + cut_flow_trk.new_row(row.run,row.lumi,row.evt) + cut_flow_trk.Fill('bare') + + if not preselection(row, cut_flow_trk): continue region = selections.control_region_ee(row) @@ -153,7 +209,18 @@ def fill(the_histos, row, fillNtuple=False): if region == 'zee': continue + + if region_for_event_list and region == region_for_event_list: + cut_flow_trk.Fill('region assignment') + if zMassCut and not (60 < row.e1_e2_Mass < 120): + cut_flow_trk.Fill('zMassCut') + # This is a QCD or Wjets + if region_for_event_list and region == region_for_event_list\ + and (not zMassCut or not (60 < row.e1_e2_Mass < 120)) \ + and not SYNC: + print '%i:%i:%i' % (row.run, row.lumi, row.evt) + continue def make_region_plots(full_region): fill(histos[full_region], row, True) @@ -172,11 +239,15 @@ def make_region_plots(full_region): make_region_plots((region, 'pt10')) if not (row.e1_e2_Mass > 60 and row.e1_e2_Mass < 120): make_region_plots((region+'NoZmass', 'pt10')) - + if region == 'wjetsLtLow' and row.e1MtToMET > 55: + make_region_plots(('wjetsNoZmass', 'pt10')) + if row.e2Pt > 20: make_region_plots((region, 'pt20')) if not (row.e1_e2_Mass > 60 and row.e1_e2_Mass < 120): make_region_plots((region+'NoZmass', 'pt20')) + if region == 'wjetsLtLow' and row.e1MtToMET > 55: + make_region_plots(('wjetsNoZmass', 'pt20')) def finish(self): diff --git a/wh/FakeRatesEM.py b/wh/FakeRatesEM.py index 024d89f3..90038564 100644 --- a/wh/FakeRatesEM.py +++ b/wh/FakeRatesEM.py @@ -21,11 +21,32 @@ import mcCorrectors import os from array import array +import FinalStateAnalysis.PlotTools.pytree as pytree +from cutflowtracker import cut_flow_tracker +import math + +def inv_mass(pt1,eta1,phi1,pt2,eta2,phi2): + return math.sqrt( + 2*pt1*pt2*(math.cosh(eta1 - eta2) - math.cos(phi1 - phi2)) + ) + +cut_flow_step = ['bare', #'trigger', + 'e_m_SS', 'e_m_DR', #'e_m_Mass', + 'mu presel', 'e presel', 'jet presence', + 'muon veto', 'bjet veto', 'electron veto', 'tau veto', + 'trigger', 'tag ID ISO', 'tag MT', 'probe MT' +] + +REGION = os.environ['REGION'] if ('REGION' in os.environ) else '' +env_lepton = REGION[0] if REGION else '' +env_region = REGION[1:] if REGION else '' def control_region(row): # Figure out what control region we are in. - if row.mPFIDTight and row.mRelPFIsoDB < 0.15 and row.mMtToMET > 35 and row.eMtToMET < 35: - return 'wjets' + if row.mPFIDTight and row.mRelPFIsoDB < 0.15 and row.mMtToMET > 35 and row.eMtToMET < 35 and row.bjetCSVVetoZHLike == 0: + return 'wjetsLtLow' + elif row.mPFIDTight and row.mRelPFIsoDB < 0.15 and row.mMtToMET > 35 and row.eMtToMET < 35 and row.bjetCSVVetoZHLike > 0: + return 'ttbar' elif row.mPFIDTight and row.mRelPFIsoDB > 0.3 and row.type1_pfMetEt < 25: return 'qcd' else: @@ -33,8 +54,10 @@ def control_region(row): def control_region_muon(row): # Figure out what control region we are in. - if selections.lepton_id_iso(row, 'e', 'eid12Medium_h2taucuts') and row.eMtToMET > 35 and row.mMtToMET < 35: - return 'Mwjets' + if selections.lepton_id_iso(row, 'e', 'eid12Medium_h2taucuts') and row.eMtToMET > 35 and row.mMtToMET < 35 and row.bjetCSVVetoZHLike == 0: + return 'MwjetsLtLow' + elif selections.lepton_id_iso(row, 'e', 'eid12Medium_h2taucuts') and row.eMtToMET > 35 and row.mMtToMET < 35 and row.bjetCSVVetoZHLike > 0: + return 'Mttbar' elif row.eRelPFIsoDB > 0.3 and row.type1_pfMetEt < 25: # selections.electronIds['eid12Medium'](row, 'e') and return 'Mqcd' else: @@ -42,11 +65,11 @@ def control_region_muon(row): class FakeRatesEM(MegaBase): - tree = 'em/final/Ntuple' + tree = 'em/final/Ntuple' if 'SYNC' not in os.environ else 'Ntuple' def __init__(self, tree, outfile, **kwargs): super(FakeRatesEM, self).__init__(tree, outfile, **kwargs) # Use the cython wrapper - self.tree = EMuTree.EMuTree(tree) + self.tree = tree #EMuTree.EMuTree(tree) self.out = outfile # Histograms for each category self.histograms = {} @@ -61,7 +84,13 @@ def __init__(self, tree, outfile, **kwargs): def begin(self): #Electron Fake Rates - for region in ['wjets', 'qcd']: + self.book('', "CUT_FLOW", "Cut Flow", len(cut_flow_step), 0, len(cut_flow_step)) + xaxis = self.histograms['CUT_FLOW'].GetXaxis() + self.cut_flow_histo = self.histograms['CUT_FLOW'] + for i, name in enumerate(cut_flow_step): + xaxis.SetBinLabel(i+1, name) + + for region in ['wjets', 'wjetsLtLow', 'qcd', 'ttbar']: for denom in ['pt10','pt20']: denom_key = (region, denom) denom_histos = {} @@ -71,9 +100,20 @@ def begin(self): denom_histos['electronInfo'] = self.book( os.path.join(region, denom), 'electronInfo', "electronInfo", - 'electronPt:electronJetPt:electronJetCSVBtag:numJets20:numJets40:weight:'+':'.join(self.lepIds), + 'electronPt:electronJetPt:electronJetCSVBtag:electronJetMass:numJets20:numJets40:weight:'+':'.join(self.lepIds), type=ROOT.TNtuple) + denom_histos['evtInfo'] = self.book( + os.path.join(region, denom), + 'evtInfo', 'evtInfo', + 'run/l:lumi/l:evt/l' +\ + ':ePt/D:eEta/D:ePhi/D:mPt/D:mEta/D:mPhi/D' +\ + ':eChargeIdTight/D:mPFIDTight/D:mRelPFIsoDB/D' +\ + ':mMtToMET/D:eMtToMET/D:bjetCSVVetoZHLike/D' +\ + ':eRelPFIsoDB/D:eMVAIDH2TauWP/D:e_m_SS/D', + type=pytree.PyTree) + + for numerator in self.lepIds: num_key = (region, denom, numerator) num_histos = {} @@ -99,8 +139,8 @@ def book_histo(name, *args, **kwargs): book_histo('eJetptDvseJetPt', '' , 200, 0, 200, 200, 0, 1,type=ROOT.TH2F) #Muon Fake Rates - for region in ['Mwjets', 'Mqcd']: - for denom in ['pt10', 'pt20']: #, 'pt10b', 'pt10t', 'pt10f']: + for region in ['Mwjets', 'MwjetsLtLow', 'Mqcd', 'Mttbar']: + for denom in ['pt10', 'pt20']: denom_key = (region, denom) denom_histos = {} self.histograms[denom_key] = denom_histos @@ -109,9 +149,20 @@ def book_histo(name, *args, **kwargs): denom_histos['muonInfo'] = self.book( os.path.join(region, denom), 'muonInfo', "muonInfo", - 'muonPt:muonJetPt:muonJetCSVBtag:numJets20:numJets40:weight:'+':'.join(self.muon_lepIds), + 'muonPt:muonJetPt:muonJetCSVBtag:muonJetMass:numJets20:numJets40:weight:'+':'.join(self.muon_lepIds), type=ROOT.TNtuple) + denom_histos['evtInfo'] = self.book( + os.path.join(region, denom), + 'evtInfo', 'evtInfo', + 'run/l:lumi/l:evt/l' +\ + ':ePt/D:eEta/D:ePhi/D' +\ + ':mPt/D:mEta/D:mPhi/D' +\ + ':eChargeIdTight/D:mPFIDTight/D:mRelPFIsoDB/D' +\ + ':mMtToMET/D:eMtToMET/D:bjetCSVVetoZHLike/D' +\ + ':eRelPFIsoDB/D:eMVAIDH2TauWP/D:e_m_SS/D', + type=pytree.PyTree) + for numerator in self.muon_lepIds: num_key = (region, denom, numerator) num_histos = {} @@ -138,19 +189,34 @@ def book_histo(name, *args, **kwargs): book_histo('muonAbsEta', 'Muon Abs Eta', 100, -2.5, 2.5) book_histo('muonPtRatio', 'Muon Pt', 100, 0., 1.) book_histo('muonPtDiff', 'Muon Pt', 200, 0., 200.) + book_histo('eMtToMET', 'e MT', 100, 0, 200) + def process(self): + cut_flow_histo = self.cut_flow_histo + cut_flow_trk = cut_flow_tracker(cut_flow_histo) def preselection(row): if not row.e_m_SS: return False + cut_flow_trk.Fill('e_m_SS') + + if row.e_m_DR < 0.5: return False + cut_flow_trk.Fill('e_m_DR') + if not selections.muSelection(row, 'm'): return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag) + cut_flow_trk.Fill('mu presel') + if not selections.eSelection(row, 'e'): return False #applies basic selection (eta, pt > 10, DZ, missingHits, jetBTag, HasConversion and chargedIdTight) if not row.eChargeIdTight: return False - if row.e_m_DR < 0.5: return False + cut_flow_trk.Fill('e presel') + #if not (row.jetVeto40_DR05 >= 1): return False - if not (row.jetVeto20 > 1): return False - if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes + if row.jetVeto20 == 0: return False + cut_flow_trk.Fill('jet presence') + + if not selections.vetos(row, cut_flow_trk, False): return False #applies mu bjet e additional tau vetoes + #DO NOT APPLY BJet veto. It is used for ttbar CR return True #if self.is7TeV: #base_selection = 'mu17ele8Pass && ' + base_selection @@ -173,9 +239,12 @@ def fill(the_histos, row, fillNtuple=False): the_histos['eJetptDvseJetPt'].Fill(max(row.eJetPt, row.ePt),row.eJetptD) if fillNtuple: id_iso_vals = [ float( selections.lepton_id_iso(row, 'e', label) ) for label in self.lepIds] + electron_jet_mass = -1. #inv_mass(row.ePt, row.eEta, row.ePhi, row.leadingJetPt, row.leadingJetEta, row.leadingJetPhi) + the_histos['electronInfo'].Fill( array("f", [row.ePt, max(row.eJetPt, row.ePt), max(0, row.eJetCSVBtag), - row.jetVeto20, row.jetVeto40_DR05, weight]+id_iso_vals) ) + electron_jet_mass, row.jetVeto20, row.jetVeto40_DR05, weight]+id_iso_vals) ) + the_histos['evtInfo'].Fill(row) def fill_muon(the_histos, row, fillNtuple=False): weight = 1. @@ -185,6 +254,7 @@ def fill_muon(the_histos, row, fillNtuple=False): mcCorrectors.correct_mueg_e(row.ePt, row.eAbsEta) the_histos['muonPt'].Fill(row.mPt, weight) + the_histos['eMtToMET'].Fill(row.eMtToMET) the_histos['muonJetPt'].Fill(max(row.mJetPt, row.mPt), weight) the_histos['muonAbsEta'].Fill(row.mAbsEta, weight) the_histos['muonPtRatio'].Fill(row.mPt/max(row.mJetPt, row.mPt), weight) @@ -193,11 +263,13 @@ def fill_muon(the_histos, row, fillNtuple=False): pfidiso02 = float( row.mPFIDTight and row.mRelPFIsoDB < 0.2) h2taucuts = float( row.mPFIDTight and ((row.mRelPFIsoDB < 0.15 and row.mAbsEta < 1.479) or row.mRelPFIsoDB < 0.1 )) h2taucuts020 = float( row.mPFIDTight and ((row.mRelPFIsoDB < 0.20 and row.mAbsEta < 1.479) or row.mRelPFIsoDB < 0.15)) + muon_jet_mass = -1. #inv_mass(row.mPt, row.mEta, row.mPhi, row.leadingJetPt, row.leadingJetEta, row.leadingJetPhi) + the_histos['muonInfo'].Fill( array("f", [row.mPt, max(row.mJetPt, row.mPt), max(0, row.mJetCSVBtag), - row.jetVeto20, row.jetVeto40_DR05, weight, + muon_jet_mass, row.jetVeto20, row.jetVeto40_DR05, weight, pfidiso02, h2taucuts, h2taucuts020] ) ) - + the_histos['evtInfo'].Fill(row) def fill_region(region,pt_cut): if region is None: @@ -236,6 +308,8 @@ def fill_muon_region(region, tag): histos = self.histograms for row in self.tree: + cut_flow_trk.new_row(row.run,row.lumi,row.evt) + cut_flow_trk.Fill('bare') if not preselection(row): continue region = control_region(row) @@ -245,14 +319,45 @@ def fill_muon_region(region, tag): use_iso_trigger = not is7TeV mu17e8 = (row.mu17ele8isoPass and row.mPt >= 20) if use_iso_trigger else (row.mu17ele8Pass and row.mPt >= 20) mu8e17 = (row.mu8ele17isoPass and row.ePt >= 20) if use_iso_trigger else (row.mu8ele17Pass and row.ePt >= 20) + + if env_lepton and env_lepton == 'e': + if mu17e8: + cut_flow_trk.Fill('trigger') + if row.mPFIDTight and row.mRelPFIsoDB < 0.15: + cut_flow_trk.Fill('tag ID ISO') + if row.mMtToMET > 35: + cut_flow_trk.Fill('tag MT') + if row.eMtToMET < 35: + cut_flow_trk.Fill('probe MT') + + elif env_lepton and env_lepton == 'm': + if mu8e17: + cut_flow_trk.Fill('trigger') + if selections.lepton_id_iso(row, 'e', 'eid12Medium_h2taucuts'): + cut_flow_trk.Fill('tag ID ISO') + if row.eMtToMET > 35: + cut_flow_trk.Fill('tag MT') + if row.mMtToMET < 35: + cut_flow_trk.Fill('probe MT') + + cut_flow_trk.flush() + if mu17e8: fill_region(region,'pt10') + if region == 'wjetsLtLow' and row.mMtToMET > 55: + fill_region('wjets', 'pt10') if mu8e17: fill_region(region,'pt20') + if region == 'wjetsLtLow' and row.mMtToMET > 55: + fill_region('wjets', 'pt20') if muon_region: fill_muon_region(muon_region, 'pt10') + if muon_region == 'MwjetsLtLow' and row.eMtToMET > 55: + fill_muon_region('Mwjets', 'pt10') if row.mPt > 20: fill_muon_region(muon_region, 'pt20') + if muon_region == 'MwjetsLtLow' and row.eMtToMET > 55: + fill_muon_region('Mwjets', 'pt20') def finish(self): self.write_histos() diff --git a/wh/FakeRatesMM.py b/wh/FakeRatesMM.py index 2b70fadd..3846c97c 100755 --- a/wh/FakeRatesMM.py +++ b/wh/FakeRatesMM.py @@ -22,20 +22,39 @@ import baseSelections as selections import os import ROOT +from cutflowtracker import cut_flow_tracker +import math + +def inv_mass(pt1,eta1,phi1,pt2,eta2,phi2): + return math.sqrt( + 2*pt1*pt2*(math.cosh(eta1 - eta2) - math.cos(phi1 - phi2)) + ) + +#Makes the cut flow histogram +cut_flow_step = ['bare', 'trigger', + 'm1_m2_SS', 'm1_m2_DR', 'm1_m2_Mass', + 'muon Pt', 'muon AbsEta', 'muon PixHits', + 'muon JetCSVBtag', 'muon DZ', #'lead mu preselection', + 'lead mu pt', 'm1PFIDTight', 'sublead mu preselection', + 'muon veto', 'bjet veto', 'electron veto', + 'Jet presence', 'muon isolation', 'MET', 'region assignment' +] + def control_region(row): # Figure out what control region we are in. if row.m1RelPFIsoDB < 0.15 and row.m1MtToMET > 35 and row.m2MtToMET < 35: - return 'wjets' + return 'wjetsLtLow' elif row.m1RelPFIsoDB > 0.3 and row.type1_pfMetEt < 25: return 'qcd' else: return None region_for_event_list = os.environ.get('EVTLIST_REGION','') +SYNC = ('SYNC' in os.environ) and eval(os.environ['SYNC']) class FakeRatesMM(MegaBase): - tree = 'mm/final/Ntuple' + tree = 'mm/final/Ntuple' if not SYNC else 'Ntuple' def __init__(self, tree, outfile, **kwargs): super(FakeRatesMM, self).__init__(tree, outfile, **kwargs) # Use the cython wrapper @@ -48,8 +67,14 @@ def __init__(self, tree, outfile, **kwargs): self.pucorrector = mcCorrectors.make_puCorrector('doublemu') def begin(self): - for region in ['wjets', 'qcd']:#, 'all']: - for denom in ['pt10', 'pt20']: #, 'pt10b', 'pt10t', 'pt10f']: + self.book('', "CUT_FLOW", "Cut Flow", len(cut_flow_step), 0, len(cut_flow_step)) + xaxis = self.histograms['CUT_FLOW'].GetXaxis() + self.cut_flow_histo = self.histograms['CUT_FLOW'] + for i, name in enumerate(cut_flow_step): + xaxis.SetBinLabel(i+1, name) + + for region in ['wjets', 'wjetsLtLow', 'qcd']:#, 'all']: + for denom in ['pt10', 'pt20']: denom_key = (region, denom) denom_histos = {} self.histograms[denom_key] = denom_histos @@ -58,7 +83,7 @@ def begin(self): denom_histos['muonInfo'] = self.book( os.path.join(region, denom), 'muonInfo', "muonInfo", - 'muonPt:muonJetPt:muonAbsEta:muonJetCSVBtag:muonPVDXY:numJets20:numJets40:weight:'+':'.join(self.lepIds), + 'muonPt:muonJetPt:muonAbsEta:muonJetCSVBtag:muonPVDXY:muonJetMass:numJets20:numJets40:weight:'+':'.join(self.lepIds), type=ROOT.TNtuple) for numerator in self.lepIds: @@ -100,7 +125,11 @@ def book_histo(name, *args, **kwargs): def process(self): - def preselection(row): + cut_flow_histo = self.cut_flow_histo + cut_flow_trk = cut_flow_tracker(cut_flow_histo) + cut_flow_trk.Fill('bare') + + def preselection(row, cut_flow_trk): double_mu_pass = row.doubleMuPass and \ row.m1MatchesDoubleMuPaths > 0 and \ row.m2MatchesDoubleMuPaths > 0 @@ -108,18 +137,33 @@ def preselection(row): row.m1MatchesMu17TrkMu8Path > 0 and \ row.m2MatchesMu17TrkMu8Path > 0 if not ( double_mu_pass or double_muTrk_pass ): return False + cut_flow_trk.Fill('trigger') if not row.m1_m2_SS: return False + cut_flow_trk.Fill('m1_m2_SS') + if row.m1_m2_DR < 0.5: return False + cut_flow_trk.Fill('m1_m2_DR') + if row.m2Pt > row.m1Pt: return False if row.m1_m2_Mass < 20: return False + cut_flow_trk.Fill('m1_m2_Mass') + + if not selections.muSelection(row, 'm1', cut_flow_trk): return False if not row.m1Pt > 20: return False + cut_flow_trk.Fill('lead mu pt') if not row.m1PFIDTight: return False - if not selections.muSelection(row, 'm1'): return False + cut_flow_trk.Fill('m1PFIDTight') + #cut_flow_trk.Fill('lead mu preselection') + if not selections.muSelection(row, 'm2'): return False - if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes + cut_flow_trk.Fill('sublead mu preselection') + + if not selections.vetos(row, cut_flow_trk): return False #applies mu bjet e additional tau vetoes #if not (row.jetVeto40_DR05 >= 1): return False - if not (row.jetVeto20 > 0): return False + if row.jetVeto20 == 0: return False + cut_flow_trk.Fill('Jet presence') + return True def fill(the_histos, row, fillNtuple=False): @@ -148,45 +192,55 @@ def fill(the_histos, row, fillNtuple=False): pfidiso02 = float( row.m2PFIDTight and row.m2RelPFIsoDB < 0.2) h2taucuts = float( row.m2PFIDTight and ((row.m2RelPFIsoDB < 0.15 and row.m2AbsEta < 1.479) or row.m2RelPFIsoDB < 0.1 )) h2taucuts020 = float( row.m2PFIDTight and ((row.m2RelPFIsoDB < 0.20 and row.m2AbsEta < 1.479) or row.m2RelPFIsoDB < 0.15)) + muon_jet_mass = -1. #inv_mass(row.m1Pt, row.m1Eta, row.m1Phi, row.leadingJetPt, row.leadingJetEta, row.leadingJetPhi) + the_histos['muonInfo'].Fill( array("f", [row.m2Pt, max(row.m2JetPt, row.m2Pt), row.m2AbsEta, max(0, row.m2JetCSVBtag), - abs(row.m2PVDXY), row.jetVeto20, row.jetVeto40_DR05, weight, + abs(row.m2PVDXY), muon_jet_mass, row.jetVeto20, row.jetVeto40_DR05, weight, pfidiso02, h2taucuts, h2taucuts020] ) ) - + + def fill_region(region, tag): + # This is a QCD or Wjets + fill(histos[(region, tag)], row, True) + + if row.m2PFIDTight: + if row.m2RelPFIsoDB < 0.2: + fill(histos[(region, tag, 'pfidiso02')], row) + + if (row.m2RelPFIsoDB < 0.15 and row.m2AbsEta < 1.479) or row.m2RelPFIsoDB < 0.1: + fill(histos[(region, tag, 'h2taucuts')], row) + + if (row.m2RelPFIsoDB < 0.20 and row.m2AbsEta < 1.479) or row.m2RelPFIsoDB < 0.15: + fill(histos[(region, tag, 'h2taucuts020')], row) + histos = self.histograms for row in self.tree: - if not preselection(row): + cut_flow_trk.new_row(row.run,row.lumi,row.evt) + cut_flow_trk.Fill('bare') + if not preselection(row, cut_flow_trk): continue + region = control_region(row) + if row.m1RelPFIsoDB > 0.3: + cut_flow_trk.Fill('muon isolation') + if row.type1_pfMetEt < 25: + cut_flow_trk.Fill('MET') + if region is None: continue + cut_flow_trk.Fill('region assignment') if region_for_event_list and region == region_for_event_list: print '%i:%i:%i' % (row.run, row.lumi, row.evt) continue - def fill_region(region, tag): - # This is a QCD or Wjets - fill(histos[(region, tag)], row, True) - - if row.m2PFIDTight: - if row.m2RelPFIsoDB < 0.2: - fill(histos[(region, tag, 'pfidiso02')], row) - - if (row.m2RelPFIsoDB < 0.15 and row.m2AbsEta < 1.479) or row.m2RelPFIsoDB < 0.1: - fill(histos[(region, tag, 'h2taucuts')], row) - - if (row.m2RelPFIsoDB < 0.20 and row.m2AbsEta < 1.479) or row.m2RelPFIsoDB < 0.15: - fill(histos[(region, tag, 'h2taucuts020')], row) - - #if (row.m2RelPFIsoDB < 0.25 and row.m2AbsEta < 1.479) or row.m2RelPFIsoDB < 0.20: - # fill(histos[(region, tag, 'h2taucuts025')], row) - fill_region(region, 'pt10') - #fill_region('all', 'pt10') + if region == 'wjetsLtLow' and row.m1MtToMET > 55: + fill_region('wjets', 'pt10') if row.m2Pt > 20: fill_region(region, 'pt20') - #fill_region('all', 'pt20') + if region == 'wjetsLtLow' and row.m1MtToMET > 55: + fill_region('wjets', 'pt20') def finish(self): self.write_histos() From 6c2798fcb27a4b99191aa70e54677e30d04eeadf Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Dec 2013 04:56:58 -0600 Subject: [PATCH 086/192] update plots --- wh/PlotControlEM.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wh/PlotControlEM.py b/wh/PlotControlEM.py index b1ed1fd5..78901e67 100644 --- a/wh/PlotControlEM.py +++ b/wh/PlotControlEM.py @@ -133,12 +133,12 @@ def correct_for_contrib_in_fakes(x, fudge_factor=1.0): #from pdb import set_trace; set_trace() plotter.plot_mc_vs_data('em', 'emMass', rebin=5, leftside=False, - xaxis='m_{e#mu} (GeV)', show_ratio=True) + xaxis='m_{e#mu} (GeV)')#, show_ratio=True) plotter.add_cms_blurb(sqrts) plotter.save('mass' + suffix) plotter.plot_mc_vs_data('em', 'emMass', rebin=10, leftside=False, - xaxis='m_{e#mu} (GeV)', show_ratio=True) + xaxis='m_{e#mu} (GeV)')#, show_ratio=True) plotter.add_cms_blurb(sqrts) plotter.save('mass_rebin' + suffix) From e4c00471330976df9ca92fe54576b3a8d348614c Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Dec 2013 04:57:36 -0600 Subject: [PATCH 087/192] charge flip shape unc experiment --- wh/PlotControlZEE.py | 56 ++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/wh/PlotControlZEE.py b/wh/PlotControlZEE.py index f11d989e..54c1feeb 100644 --- a/wh/PlotControlZEE.py +++ b/wh/PlotControlZEE.py @@ -8,7 +8,9 @@ import glob from FinalStateAnalysis.PlotTools.Plotter import Plotter from FinalStateAnalysis.PlotTools.MedianView import MedianView +from FinalStateAnalysis.PlotTools.DifferentialView import DifferentialView import rootpy.plotting.views as views +import rootpy.plotting as plotting from FinalStateAnalysis.PlotTools.HistToTGRaphErrors import HistStackToTGRaphErrors from FinalStateAnalysis.MetaData.data_styles import data_styles, colors import ROOT @@ -17,7 +19,8 @@ logging.basicConfig(stream=sys.stderr, level=logging.INFO) ROOT.gROOT.SetBatch(True) - +ROOT.gStyle.SetOptStat(0) +ROOT.gStyle.SetOptTitle(0) class ControlZEEPlotter(Plotter): def __init__(self): @@ -72,28 +75,42 @@ def get_flip_data(self, rebin=1, xaxis='', data_type='data'): # return obj1_view, obj2_view, subtract_obj12_view #Get fakes according to WJets or QCD - ss_f1p2_qcd_view, ss_p1f2_qcd_view, ss_f1f2_qcd_view = self.make_fakes_view(data_view, 'ss','qcd_w') + #ss_f1p2_qcd_view, ss_p1f2_qcd_view, ss_f1f2_qcd_view = self.make_fakes_view(data_view, 'ss','qcd_w') ss_f1p2_wje_view, ss_p1f2_wje_view, ss_f1f2_wje_view = self.make_fakes_view(data_view, 'ss','wjet_w') - ss_fakes_1 = MedianView(lowv=ss_f1p2_qcd_view, highv=ss_f1p2_wje_view) - ss_fakes_2 = MedianView(lowv=ss_p1f2_qcd_view, highv=ss_p1f2_wje_view) - ss_fakes_12 = MedianView(lowv=ss_f1f2_qcd_view, highv=ss_f1f2_wje_view) + ss_fakes_1 = ss_f1p2_wje_view #MedianView(lowv=ss_f1p2_qcd_view, highv=ss_f1p2_wje_view) + ss_fakes_2 = ss_p1f2_wje_view #MedianView(lowv=ss_p1f2_qcd_view, highv=ss_p1f2_wje_view) + ss_fakes_12 = ss_f1f2_wje_view #MedianView(lowv=ss_f1f2_qcd_view, highv=ss_f1f2_wje_view) ss_fakes_est = views.SumView(ss_fakes_1, ss_fakes_2, ss_fakes_12) ss_fakes_est = views.TitleView( views.StyleView(ss_fakes_est, **data_styles['Zjets*']), 'Fakes;%s' % xaxis) os_flip_est_up = views.SubdirectoryView( data_view, 'os/p1p2/charge_weightSysUp') os_flip_est = views.SubdirectoryView( data_view, 'os/p1p2/charge_weight') - os_flip_est = MedianView(highv=os_flip_est_up, centv=os_flip_est) + #os_flip_est = MedianView(highv=os_flip_est_up, centv=os_flip_est) os_flip_est_nofake = os_flip_est#views.SumView(os_flip_est, neg_os_fakes) os_flip_est_nofake = views.TitleView( views.StyleView(os_flip_est_nofake, **data_styles['WZ*']), 'charge-fakes;%s' % xaxis) return ss_p1p2_view, ss_fakes_est, os_flip_est_nofake - def make_charge_flip_control_plot(self, variable, xaxis='', rebin=1, legend_on_the_left=False, data_type='data', x_range=None): - ss_p1p2_view, ss_fakes_est, os_flip_est_nofake = self.get_flip_data(rebin,xaxis,data_type) - events_estimate = views.StackView( ss_fakes_est,os_flip_est_nofake) + def make_charge_flip_control_plot(self, variable, xaxis='', rebin=1, legend_on_the_left=False, + data_type='data', x_range=None, apply_scale='', show_ratio=False, + differential=False): + ss_p1p2_view, ss_fakes_est, os_flip_est_nofake = self.get_flip_data(rebin, xaxis, data_type) + + if differential: + ss_p1p2_view = DifferentialView(ss_p1p2_view ) + ss_fakes_est = DifferentialView(ss_fakes_est ) + os_flip_est_nofake = DifferentialView(os_flip_est_nofake) + + fakes_hist = ss_fakes_est.Get(variable) + flip_hist = os_flip_est_nofake.Get(variable) + if apply_scale: + flip_hist = MedianView.apply_view(flip_hist, os_flip_est_nofake.Get(variable+apply_scale)) obs_hist = ss_p1p2_view.Get(variable) - estimate_hist = events_estimate.Get(variable) + estimate_hist = plotting.HistStack() + estimate_hist.Add(fakes_hist) + estimate_hist.Add(flip_hist) + estimate_error = HistStackToTGRaphErrors( estimate_hist ) estimate_error.SetFillStyle(3013) estimate_error.SetFillColor(ROOT.EColor.kBlack) @@ -125,6 +142,9 @@ def make_charge_flip_control_plot(self, variable, xaxis='', rebin=1, legend_on_t #legend.AddEntry(estimate_error,'f') legend.Draw() self.add_cms_blurb(self.sqrts) + if show_ratio: + self.add_ratio_plot(obs_hist, estimate_hist, x_range, ratio_range=0.2) + def plot_zee_control(self, variable, xaxis='', rebin=1, legend_on_the_left=False, x_range=None, show_ratio=False, logscale=False): @@ -137,11 +157,11 @@ def plot_zee_control(self, variable, xaxis='', rebin=1, legend_on_the_left=False zee_data = views.SubdirectoryView( data_view, 'os/p1p2/') zee_mcs = [ views.SubdirectoryView( i, 'os/p1p2/') for i in mc_views] - os_f1p2_qcd_view, os_p1f2_qcd_view, os_f1f2_qcd_view = self.make_fakes_view(data_view, 'os','qcd_w') + #os_f1p2_qcd_view, os_p1f2_qcd_view, os_f1f2_qcd_view = self.make_fakes_view(data_view, 'os','qcd_w') os_f1p2_wje_view, os_p1f2_wje_view, os_f1f2_wje_view = self.make_fakes_view(data_view, 'os','wjet_w') - os_fakes_1 = MedianView(lowv=os_f1p2_qcd_view, highv=os_f1p2_wje_view) - os_fakes_2 = MedianView(lowv=os_p1f2_qcd_view, highv=os_p1f2_wje_view) - os_fakes_12 = MedianView(lowv=os_f1f2_qcd_view, highv=os_f1f2_wje_view) + os_fakes_1 = os_f1p2_wje_view #MedianView(lowv=os_f1p2_qcd_view, highv=os_f1p2_wje_view) + os_fakes_2 = os_p1f2_wje_view #MedianView(lowv=os_p1f2_qcd_view, highv=os_p1f2_wje_view) + os_fakes_12 = os_f1f2_wje_view #MedianView(lowv=os_f1f2_qcd_view, highv=os_f1f2_wje_view) os_fakes_est = views.SumView(os_fakes_1, os_fakes_2, os_fakes_12) os_fakes_est = views.TitleView( views.StyleView(os_fakes_est, **data_styles['WplusJets*']), 'Fakes;%s' % xaxis) @@ -185,11 +205,17 @@ def plot_zee_control(self, variable, xaxis='', rebin=1, legend_on_the_left=False ########################################################################### #Charge flip control plots -plotter.make_charge_flip_control_plot('TrkMass','Tracker Inv Mass (GeV)',2) +plotter.make_charge_flip_control_plot('TrkMass','Tracker Inv Mass (GeV)', + [40,50,60,70,75,80]+[80+i for i in range(1,21,2)]+[105,110,120,130,140], + apply_scale='_high', show_ratio=True, differential=True) plotter.save('EE_Charge_Flip_xcheck_trk_invMass') plotter.canvas.SaveAs('test.root') #plotter.save('EE_Charge_Flip_xcheck_trk_invMass_log') +plotter.make_charge_flip_control_plot('TrkMass','Tracker Inv Mass (GeV)',[40, 150],apply_scale='_high', + show_ratio=True) +plotter.save('EE_Charge_Flip_xcheck_trk_invMass_counting') + plotter.make_charge_flip_control_plot('TrkMass_NOSCALE','Tracker Inv Mass (GeV)',2) plotter.save('EE_Charge_Flip_xcheck_trk_invMass_NoScale') From fbc4de8163b6d2bef935f9a37067b511f02d3c3c Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Dec 2013 04:57:46 -0600 Subject: [PATCH 088/192] updated plots --- wh/PlotControlZMM.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wh/PlotControlZMM.py b/wh/PlotControlZMM.py index b59ed872..a9affcf7 100644 --- a/wh/PlotControlZMM.py +++ b/wh/PlotControlZMM.py @@ -37,11 +37,11 @@ sqrts = 7 if '7TeV' in jobid else 8 -plotter.plot_mc_vs_data('zmm', 'm1m2Mass', rebin=2, xaxis='m_{#mu#mu} (GeV)', show_ratio=True) +plotter.plot_mc_vs_data('zmm', 'm1m2Mass', rebin=2, xaxis='m_{#mu#mu} (GeV)')#, show_ratio=True) plotter.add_cms_blurb(sqrts) plotter.save('mass') -plotter.plot_mc_vs_data('zmm', 'm1m2Mass', rebin=6, xaxis='m_{#mu#mu} (GeV)', show_ratio=True) +plotter.plot_mc_vs_data('zmm', 'm1m2Mass', rebin=6, xaxis='m_{#mu#mu} (GeV)')#, show_ratio=True) plotter.add_cms_blurb(sqrts) plotter.save('mass_rebin') From 21ced83d7965fef6c9dc090c11d513b557e190af Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Dec 2013 04:59:00 -0600 Subject: [PATCH 089/192] added new sample definitions and changed fake rates regions according to the new prescriptions --- wh/Rakefile | 89 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 19 deletions(-) diff --git a/wh/Rakefile b/wh/Rakefile index fa79981a..190bcaff 100755 --- a/wh/Rakefile +++ b/wh/Rakefile @@ -2,6 +2,7 @@ recipes = ENV['CMSSW_BASE'] + '/src/FinalStateAnalysis/PlotTools/rake/recipes.rake' import recipes require ENV['CMSSW_BASE'] + '/src/FinalStateAnalysis/PlotTools/rake/tools.rb' +require 'pathname' $jobid = ENV['jobid'] $blind = ENV['blind'] @@ -36,8 +37,11 @@ end samples = Hash[ "ewk" => Array['Zjets_M50', 'WplusJets_madgraph'] + get_sample_names('TTplusJets') + get_sample_names('WZ') + get_sample_names('WWJet')+ get_sample_names('ZZ'), #'ZZJetsTo4L_pythia', "wjets" => Array['WplusJets_madgraph'], + "ttbar" => get_sample_names('TTplusJets'), "zjets" => Array['Zjets_M50'], "diboson" => get_sample_names('ZZ')+get_sample_names('WZ') + get_sample_names('WWJet'), + "diboson4fakes" => get_sample_names('ZZ')+get_sample_names('WZJetsTo3LNu_ZToTauTau'), + "WZ" => get_sample_names('WZJetsTo3LNu_ZToTauTau'), "signal" => get_sample_names('VH') + get_sample_names('WH'), # Automagically figure out what data samples we have "data_m" => get_sample_names("data_SingleMu"), @@ -183,7 +187,7 @@ end def make_kNN(chan, datas) return Hash[ - "samples" => Array["diboson", "data_#{datas.downcase}"], + "samples" => Array["diboson4fakes", "data_#{datas.downcase}"], "analyzer" => "FakeRates#{chan.upcase}", 'fitter' => 'train_kNN.py', #'neighbors' => neighbors, @@ -194,19 +198,23 @@ iso_points = ['h2taucuts', 'h2taucuts020'] #'idiso02', electronIds = ['eid12Medium', 'eid12Tight'] #, 'eid13Loose', 'eid12Loose', 'eid13Tight'] elewps = electronIds.product(iso_points) elewps = elewps.map{|x,y| "#{x}_#{y}"} +ee_wps = ['eid12Medium_h2taucuts020', 'eid12Tight_h2taucuts'] +em_wps = ['eid12Medium_h2taucuts'] + pt_regions = ['pt10']#, 'pt20'] muonwps = ['h2taucuts', 'h2taucuts020'] #, 'pfidiso02'] fr_fits = Hash.new kNN_trains = Hash.new muon_kNN_vars= ['muonJetPt', 'muonPt', 'numJets20'] electron_kNN_vars= ['electronJetPt', 'electronPt', 'numJets20'] -neighbors = ['100'] #, '50'] +neighbors = ['50'] # '100'] #, ] ############# # EM datas ############# -emcrs = ['qcd', 'wjets'] -elewps.select{|x| x.start_with?('eid12Medium')}.each do |ele_wp| +emcrs = [ 'wjets', 'ttbar']#'qcd', +#elewps.select{|x| x.start_with?('eid12Medium')}.each do |ele_wp| +em_wps.each do |ele_wp| emcrs.each do |cr| neighbors.each do |k| pt_regions.each do |ptr| @@ -216,20 +224,29 @@ elewps.select{|x| x.start_with?('eid12Medium')}.each do |ele_wp| key = "em_#{cr}_#{ptr}_#{ele_wp}_electronInfo_k#{k}" kNN_trains[key] = make_kNN('em', 'em') kNN_trains[key]['vars'] = electron_kNN_vars + + if cr == 'ttbar' + kNN_trains[key]['samples'] = Array['data_em'] + end end end end end #muon fakes from em -mmcrs = ['qcd', 'wjets'] -muonwps.each do |mu_wp| +mmcrs = [ 'wjets', 'ttbar']#'qcd', +#muonwps.each do |mu_wp| +['h2taucuts'].each do |mu_wp| mmcrs.each do |cr| neighbors.each do |k| pt_regions.each do |ptr| key = "em_M#{cr}_#{ptr}_#{mu_wp}_muonInfo_k#{k}" kNN_trains[key] = make_kNN('em', 'em') kNN_trains[key]['vars'] = muon_kNN_vars + + if cr == 'ttbar' + kNN_trains[key]['samples'] = Array['data_em'] + end end end end @@ -239,8 +256,9 @@ end ############# # EE datas ############# -eecrs = ['qcd', 'wjetsNoZmass'] -elewps.each do |ele_wp| +eecrs = [ 'wjetsNoZmass'] #['qcd', +#elewps.each do |ele_wp| +ee_wps.each do |ele_wp| neighbors.each do |k| eecrs.each do |cr| pt_regions.each do |ptr| @@ -250,6 +268,12 @@ elewps.each do |ele_wp| key = "ee_#{cr}_#{ptr}_#{ele_wp}_electronInfo_k#{k}" kNN_trains[key] = make_kNN('ee', 'ee') kNN_trains[key]['vars'] = electron_kNN_vars + #if ele_wp == 'eid12Tight_h2taucuts': + # kNN_trains[key]['samples'] = Array["WZ", 'data_ee'] + #end + if cr == 'qcd' + kNN_trains[key]['samples'] = Array['data_ee'] + end end end end @@ -260,7 +284,7 @@ end # MM datas ############# muon_kNN_vars= ['muonJetPt', 'muonPt', 'numJets20'] -mmcrs = ['qcd', 'wjets'] +mmcrs = [ 'wjets']#'qcd', muonwps.each do |mu_wp| mmcrs.each do |cr| neighbors.each do |k| @@ -271,6 +295,10 @@ muonwps.each do |mu_wp| key = "mm_#{cr}_#{ptr}_#{mu_wp}_muonInfo_k#{k}" kNN_trains[key] = make_kNN('mm', 'mm') kNN_trains[key]['vars'] = muon_kNN_vars + + if cr == 'qcd' + kNN_trains[key]['samples'] = Array['data_mm'] + end end end end @@ -379,7 +407,6 @@ kNN_trains.each do |kNN, info| neigh = kNN_configuration[5].sub('k','') end - knn_output = $frfit_dir + "/#{kNN}.kNN.root" # Expand sample list subsample_inputs = [] @@ -387,18 +414,42 @@ kNN_trains.each do |kNN, info| subsample_inputs += samples[sample] end subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/#{info['analyzer']}/#{x}.root"} - subsample_input_list = subsamples_inputs_result_list.join(" ") + + data_list = subsamples_inputs_result_list.select{|x| x.include? 'data_'} + mc_list = subsamples_inputs_result_list.select{|x| not x.include? 'data_'} + #subsample_input_list = subsamples_inputs_result_list.join(" ") # Path to tree in root files tree_path = Array[region, denom, var].join("/") vars_str = info['vars'].join(" ") - file knn_output => subsamples_inputs_result_list + [info['analyzer'] + '.py',] do |t| + + knn_all_output = $frfit_dir + "/#{kNN}.ALL.kNN.root" + file knn_all_output => data_list + [info['analyzer'] + '.py',] do |t| + sh "mkdir -p #{$frfit_dir}" + sh "train_kNN.py --files #{data_list.join(' ')} #{mc_list.join(' ')} --outputfile #{t.name} --tree #{tree_path} --cut #{cut} --variables #{vars_str} --makePlots 1 --neighbors 100" #{neigh}" + end + task :kNN => knn_all_output + kNN_files << knn_all_output + + knn_data_output = $frfit_dir + "/#{kNN}.data.kNN.root" + file $frfit_dir + "/#{kNN}.data.kNN.root" => data_list + [info['analyzer'] + '.py',] do |t| sh "mkdir -p #{$frfit_dir}" - sh "train_kNN.py --files #{subsample_input_list} --outputfile #{knn_output} --tree #{tree_path} --cut #{cut} --variables #{vars_str} --makePlots 1 --neighbors #{neigh}" + sh "train_kNN.py --files #{data_list.join(' ')} --outputfile #{t.name} --tree #{tree_path} --cut #{cut} --variables #{vars_str} --makePlots 1 --neighbors #{neigh}" + end + task :kNN => knn_data_output + kNN_files << knn_data_output + + mc_list.each do |mc_input| + base = Pathname.new(mc_input).basename.sub('.root','') + kNN_mc_output = $frfit_dir + "/#{kNN}.#{base}.kNN.root" + file kNN_mc_output => [mc_input] + [info['analyzer'] + '.py',] do |t| + sh "mkdir -p #{$frfit_dir}" + sh "train_kNN.py --files #{mc_input} --outputfile #{t.name} --tree #{tree_path} --cut #{cut} --variables #{vars_str} --makePlots 0 --neighbors #{neigh} --forceLumi -1" + end + task :kNN => kNN_mc_output + kNN_files << kNN_mc_output end - task :kNN => knn_output - kNN_files << knn_output end #Rake.application.tasks.each do |t| @@ -461,9 +512,9 @@ file "WHAnalyzeEET.py" => kNN_files.select{|x| x.start_with?( "#{$frfit_dir}/ee_ sh "touch #{t.name}" end -mmt_results = get_analyzer_results("WHAnalyzeMMT.py", samples['diboson'] + samples['data_mm'] + samples['signal']) -emt_results = get_analyzer_results("WHAnalyzeEMT.py", samples['ewk'] + samples['data_em'] + samples['signal']) -eet_results = get_analyzer_results("WHAnalyzeEET.py", samples['ewk'] + samples['data_ee'] + samples['signal']) +mmt_results = get_analyzer_results("WHAnalyzeMMT.py", samples['diboson'] + samples['data_mm'] + samples['signal'] + samples["ttbar"] + samples['zjets']) +emt_results = get_analyzer_results("WHAnalyzeEMT.py", samples['diboson'] + samples['data_em'] + samples['signal'] + samples["ttbar"] + samples['zjets']) +eet_results = get_analyzer_results("WHAnalyzeEET.py", samples['diboson'] + samples['data_ee'] + samples['signal'] + samples["ttbar"] + samples['zjets']) mmt_debug = get_analyzer_results("WHAnalyzeMMT.py", Array['Zjets_M50'] ) task :mmt_dbg => mmt_debug @@ -892,7 +943,7 @@ task :eet_shapes => eet_shape_file $carddir = "results/#{$jobid}/cards" cardmasses = get_sample_names('VH') #get all the VH samples available -cardmasses = cardmasses.select{|x| not x.include? "HWW"} #get only the H2Tau, to avid repetition +cardmasses = cardmasses.select{|x| (not x.include? "HWW") and (not x.include? "lepdecay")} #get only the H2Tau, to avid repetition if $period == '8TeV' cardmasses = cardmasses.map{|x| x.sub("VH_H2Tau_M-","")} #remove trailing name, the leftover is the mass (as a string) else From 190f264a434a40f05c4527a8ea9de5fec221ec21 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Dec 2013 05:00:11 -0600 Subject: [PATCH 090/192] added new sync tools, added structure to perform second background estimation --- wh/WHAnalyzeMMT.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/wh/WHAnalyzeMMT.py b/wh/WHAnalyzeMMT.py index a9cc9b47..613b7825 100755 --- a/wh/WHAnalyzeMMT.py +++ b/wh/WHAnalyzeMMT.py @@ -15,6 +15,7 @@ from array import array from FinalStateAnalysis.PlotTools.decorators import memo_last import optimizer +import FinalStateAnalysis.PlotTools.pytree as pytree #initialize FRFits optimizer_keys = [ i for i in optimizer.grid_search.keys() if i.startswith('MMT') ] @@ -88,7 +89,7 @@ def f(row, weight): self.hfunc['subMTMass'] = lambda row, weight: (row.m2_t_Mass, weight) if row.m1MtToMET > row.m2MtToMET else (row.m1_t_Mass, weight) #maps the name of non-trivial histograms to a function to get the proper value, the function MUST have two args (evt and weight). Used in WHAnalyzerBase.fill_histos later self.hfunc['pt_ratio' ] = lambda row, weight: (row.m2Pt/row.m1Pt, weight) - self.hfunc['DEBUG'] = lambda row, weight: (array("f", [row.run, row.lumi, row.m2_t_Mass, row.LT, row.m1Pt, row.m2Pt, row.tPt] ), None) + self.hfunc['SYNC'] = lambda row, weight: (row, None)#((row.run, row.lumi, row.evt, row.m1Pt, row.m1Eta, row.m1Phi, row.m2Pt, row.m2Eta, row.m2Phi, row.tPt, row.tEta, row.tPhi, weight), None) self.pucorrector = mcCorrectors.make_puCorrector('doublemu') @@ -103,9 +104,17 @@ def book_histos(self, folder): if len(self.grid_search.keys()) == 1: + self.book(folder, 'SYNC', 'SYNC', + 'run/l:lumi/l:evt/l' +\ + ':m1Pt/D:m1Eta/D:m1Phi/D:m1PFIDTight/D:m1RelPFIsoDB/D' +\ + ':m2Pt/D:m2Eta/D:m2Phi/D:m2PFIDTight/D:m2RelPFIsoDB/D' +\ + ':tPt/D:tEta/D:tPhi/D:tAntiMuonTight/D:tDecayMode/D:tLooseIso3Hits/D:tAntiElectronMVA3Loose/D' +\ + ':m1_m2_Mass/D:m2_t_Mass/D:LT/D:m1_m2_SS/D:m1_t_SS/D', + type=pytree.PyTree) + self.book(folder, "m2_t_Mass#LT" , "subleadingMass", 300, 0, 300, nLTBins, LTBinning, type=ROOT.TH2F) #self.book(folder, "Event_ID", "Event ID", 'run:lumi:evt1:evt2', type=ROOT.TNtuple) - self.book(folder, "DEBUG", "DEBUG", 'run:lumi:m2_t_Mass:LT:m1Pt:m2Pt:tPt', type=ROOT.TNtuple) + #self.book(folder, "DEBUG", "DEBUG", 'run:lumi:m2_t_Mass:LT:m1Pt:m2Pt:tPt', type=ROOT.TNtuple) #Pt self.book(folder, "m1Pt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) self.book(folder, "tPt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) @@ -225,6 +234,18 @@ def obj3_id(row, tauId=None, LT_threshold = 80., taupt_thr = 0.): else: retval = bool( getattr(row, tauId) ) return retval + + @staticmethod + def obj1_matches_gen(row): + return row.m1GenPdgId == -1*row.m1Charge*13 + + @staticmethod + def obj2_matches_gen(row): + return row.m2GenPdgId == -1*row.m2Charge*13 + + @staticmethod + def obj3_matches_gen(row): + return t.genDecayMode != -2 @staticmethod def anti_wz(row): @@ -253,7 +274,7 @@ def obj2_weight(self, row, ledleptonId=None, subledleptonId='h2taucuts'): return frfits.lowpt_mu_fr[subledleptonId](muonJetPt=max(row.m2JetPt, row.m2Pt), muonPt=row.m2Pt, numJets20=row.jetVeto20+1) # def obj3_weight(self, row, notUsed1=None, notUsed2=None): - return frfits.tau_fr(row.tPt) + return frfits.tau_fr(row.tPt, row.tAbsEta) def obj1_qcd_weight(self, row, ledleptonId='h2taucuts', subledleptonId=None): return frfits.highpt_mu_qcd_fr[ledleptonId](muonJetPt=max(row.m1JetPt, row.m1Pt), muonPt=row.m1Pt, numJets20=row.jetVeto20+1) # @@ -262,7 +283,7 @@ def obj2_qcd_weight(self, row, ledleptonId=None, subledleptonId='h2taucuts'): return frfits.lowpt_mu_qcd_fr[subledleptonId](muonJetPt=max(row.m2JetPt, row.m2Pt), muonPt=row.m2Pt, numJets20=row.jetVeto20+1) # def obj3_qcd_weight(self, row, notUsed1=None, notUsed2=None): - return frfits.tau_qcd_fr(row.tPt) + return frfits.tau_qcd_fr(row.tPt, row.tAbsEta) # For measuring charge flip probability # Not really used in this channel From 56a5cb016b30ee61a257e3ebcb0a930194347e41 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Dec 2013 05:00:18 -0600 Subject: [PATCH 091/192] added new sync tools, added structure to perform second background estimation --- wh/WHAnalyzeEET.py | 29 ++++++++++++++++++++++++++--- wh/WHAnalyzeEMT.py | 30 ++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/wh/WHAnalyzeEET.py b/wh/WHAnalyzeEET.py index 28c035bd..dd61b453 100755 --- a/wh/WHAnalyzeEET.py +++ b/wh/WHAnalyzeEET.py @@ -16,6 +16,7 @@ from array import array from chargeflipcuts import charge_flip_funcs from FinalStateAnalysis.PlotTools.decorators import memo_last +import FinalStateAnalysis.PlotTools.pytree as pytree #initialize FRFits optimizer_keys = [ i for i in optimizer.grid_search.keys() if i.startswith('EET') ] @@ -133,6 +134,7 @@ def log_prob(row, weight): self.hfunc["e*1_t_Mass" ] = mass_scaler( attr_getter('e1_t_Mass')) self.hfunc["e1_e*2_Mass"] = mass_scaler( attr_getter('e1_e2_Mass')) self.hfunc["e*2_t_Mass" ] = mass_scaler( attr_getter('e2_t_Mass')) + self.hfunc['SYNC'] = lambda row, weight: (row, None) #((row.run, row.lumi, row.evt, row.e1Pt, row.e1Eta, row.e1Phi, row.e2Pt, row.e2Eta, row.e2Phi, row.tPt, row.tEta, row.tPhi, weight), None) #self.hfunc['evt_info'] = lambda row, weight: (array.array("f", [row.e1Pt, row.e2Pt, row.tPt, row.LT, weight] ), None) self.pucorrector = mcCorrectors.make_puCorrector('doublee') @@ -144,7 +146,7 @@ def anti_charge_flip(row, rejection_power=80): def book_histos(self, folder): #PLOTS TO FILL IN ANY CASE - LTBinning = array('d',[0, 80, 130, 600]) + LTBinning = array('d',[0, 80, 100, 600]) nLTBins = len(LTBinning) -1 for key in self.grid_search: prefix = key+'$' if key else '' @@ -168,6 +170,15 @@ def book_histos(self, folder): self.book(folder, prefix+"e2_t_Mass#LT" , "subleadingMass", 300, 0, 300, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, 'SYNC', 'SYNC', + 'run/l:lumi/l:evt/l' +\ + ':e1Pt/D:e1Eta/D:e1Phi/D:e1RelPFIsoDB/D:e1MVANonTrig/D' +\ + ':e2Pt/D:e2Eta/D:e2Phi/D:e2RelPFIsoDB/D:e2MVANonTrig/D' +\ + ':tPt/D:tEta/D:tPhi/D:tAntiMuonTight/D:tDecayMode/D:tLooseIso3Hits/D:tAntiElectronMVA3Loose/D' +\ + ':tAntiMuonLoose/D:tAntiElectronMVA3Medium/D:tAntiElectronMVA3Tight/D' +\ + ':e1_e2_Mass/D:e2_t_Mass/D:LT/D:e1_e2_SS/D:e1_t_SS/D', + type=pytree.PyTree) + #Pt self.book(folder, prefix+"e1Pt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) self.book(folder, prefix+"e2Pt#LT" , "subleadingMass", 150, 0, 150, nLTBins, LTBinning, type=ROOT.TH2F) @@ -294,6 +305,18 @@ def obj3_id(row, tauId=None, LT_threshold = 80., taupt_thr = 0.): else: return bool( getattr(row, tauId) ) + @staticmethod + def obj1_matches_gen(row): + return row.e1GenPdgId == -1*row.e1Charge*11 + + @staticmethod + def obj2_matches_gen(row): + return row.e2GenPdgId == -1*row.e2Charge*11 + + @staticmethod + def obj3_matches_gen(row): + return t.genDecayMode != -2 + #There is no call to self, so just promote it to statucmethod, to allow usage by other dedicated analyzers @staticmethod def anti_wz(row): @@ -325,7 +348,7 @@ def obj2_weight(self, row, leadleptonId=None, subleadleptonId='eid13Looseh2taucu return frfits.lowpt_ee_fr[subleadleptonId](electronJetPt=max(row.e2JetPt, row.e2Pt), electronPt=row.e2Pt, numJets20=row.jetVeto20+1) def obj3_weight(self, row, notUsed1=None, notUsed2=None): - return frfits.tau_fr(row.tPt) + return frfits.tau_fr(row.tPt, row.tAbsEta) def obj1_qcd_weight(self, row, leadleptonId='eid13Looseh2taucuts', subleadleptonId=None): return frfits.highpt_ee_qcd_fr[leadleptonId](electronJetPt=max(row.e1JetPt, row.e1Pt), electronPt=row.e1Pt, numJets20=row.jetVeto20+1) @@ -334,7 +357,7 @@ def obj2_qcd_weight(self, row, leadleptonId=None, subleadleptonId='eid13Looseh2t return frfits.lowpt_ee_qcd_fr[subleadleptonId](electronJetPt=max(row.e2JetPt, row.e2Pt), electronPt=row.e2Pt, numJets20=row.jetVeto20+1) def obj3_qcd_weight(self, row, notUsed1=None, notUsed2=None): - return frfits.tau_qcd_fr(row.tPt) + return frfits.tau_qcd_fr(row.tPt, row.tAbsEta) # For measuring charge flip probability # Not really used in this channel diff --git a/wh/WHAnalyzeEMT.py b/wh/WHAnalyzeEMT.py index 9cc20912..fe0f9032 100644 --- a/wh/WHAnalyzeEMT.py +++ b/wh/WHAnalyzeEMT.py @@ -16,6 +16,7 @@ import ROOT import math import optimizer +import FinalStateAnalysis.PlotTools.pytree as pytree from FinalStateAnalysis.PlotTools.decorators import memo_last #def make_bins(n, xlow, xhigh): @@ -53,6 +54,7 @@ ################################################################################ is7TeV = bool('7TeV' in os.environ['jobid']) use_iso_trigger = not is7TeV +region_for_event_list = os.environ.get('EVTLIST_REGION','') class WHAnalyzeEMT(WHAnalyzerBase): tree = 'emt/final/Ntuple' if not SYNC else 'Ntuple' @@ -127,10 +129,13 @@ def sub_mass(row, weight): self.hfunc["subMass*" ] = mass_scaler( sub_mass ) self.hfunc["_recoilDaught" ] = lambda row, weight: (math.sqrt(row.recoilDaught) , weight) self.hfunc["_recoilWithMet"] = lambda row, weight: (math.sqrt(row.recoilWithMet), weight) + self.hfunc['SYNC'] = lambda row, weight: (row, None) #((row.run, row.lumi, row.evt, row.mPt, row.mEta, row.mPhi, row.ePt, row.eEta, row.ePhi, row.tPt, row.tEta, row.tPhi, weight), None ) self.pucorrector = mcCorrectors.make_puCorrector('mueg') def book_histos(self, folder): + if region_for_event_list and region_for_event_list != folder: + return for key in self.grid_search: prefix = key+'$' if key else '' #self.book(folder, prefix+"subMass", "Subleading Mass", 200, 0, 200) @@ -149,6 +154,15 @@ def book_histos(self, folder): #self.book(folder, "subMass*#log_prob" , '', 200, 0, 200, 200, -2, 1, type=ROOT.TH2F) self.book(folder, "subMass*#LT" , '', 300, 0, 300, nLTBins, LTBinning, type=ROOT.TH2F) + self.book(folder, 'SYNC', 'SYNC', + 'run/l:lumi/l:evt/l' +\ + ':mPt/D:mEta/D:mPhi/D:mPFIDTight/D:mRelPFIsoDB/D' +\ + ':ePt/D:eEta/D:ePhi/D:eRelPFIsoDB/D:eMVANonTrig/D' +\ + ':tPt/D:tEta/D:tPhi/D:tAntiMuonTight/D:tDecayMode/D:tLooseIso3Hits/D:tAntiElectronMVA3Loose/D' +\ + ':tAntiMuonLoose/D:tAntiElectronMVA3Medium/D' +\ + ':e_m_Mass/D:m_t_Mass/D:e_t_Mass/D:LT/D:e_m_SS/D:m_t_SS/D', + type=pytree.PyTree) + self.book(folder, prefix+"subMass#LT" , "subleadingMass", 300, 0, 300, nLTBins, LTBinning, type=ROOT.TH2F) self.book(folder, "e_m_Mass#LT", "Electron-Muon Mass", 200, 0, 200, nLTBins, LTBinning, type=ROOT.TH2F) self.book(folder, "m_t_Mass#LT", "Electron-Muon Mass", 200, 0, 200, nLTBins, LTBinning, type=ROOT.TH2F) @@ -275,6 +289,18 @@ def obj3_id(row, tauId=None, LT_threshold = 80., taupt_thr = 0.): else: return bool( getattr(row, tauId) ) + @staticmethod + def obj1_matches_gen(row): + return row.mGenPdgId == -1*row.mCharge*13 + + @staticmethod + def obj2_matches_gen(row): + return row.eGenPdgId == -1*row.eCharge*11 + + @staticmethod + def obj3_matches_gen(row): + return t.genDecayMode != -2 + #There is no call to self, so just promote it to statucmethod, to allow usage by other dedicated analyzers @staticmethod def anti_wz( row): @@ -317,7 +343,7 @@ def obj2_weight(self, row, ledleptonId='h2taucuts', subledleptonId='h2taucuts'): return frfits.highpt_e_fr[subledleptonId](electronJetPt=max(row.eJetPt, row.ePt), electronPt=row.ePt, numJets20=row.jetVeto20+1) def obj3_weight(self, row, notUsed1=None, notUsed2=None): - return frfits.tau_fr(row.tPt) + return frfits.tau_fr(row.tPt, row.tAbsEta) def obj1_qcd_weight(self, row, ledleptonId='h2taucuts', subledleptonId='h2taucuts'): mu17e8 = (row.mu17ele8isoPass and row.mPt >= 20) if use_iso_trigger else (row.mu17ele8Pass and row.mPt >= 20) @@ -334,7 +360,7 @@ def obj2_qcd_weight(self, row, ledleptonId='h2taucuts', subledleptonId='h2taucut return frfits.highpt_e_qcd_fr[subledleptonId](electronJetPt=max(row.eJetPt, row.ePt), electronPt=row.ePt, numJets20=row.jetVeto20+1) def obj3_qcd_weight(self, row, notUsed1=None, notUsed2=None): - return frfits.tau_qcd_fr(row.tPt) + return frfits.tau_qcd_fr(row.tPt, row.tAbsEta) # For measuring charge flip probability # Not really used in this channel From da463dfcc1b939e104525ff3ea3b9e7ce4c2505b Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Dec 2013 05:02:07 -0600 Subject: [PATCH 092/192] moved cut_flow_tracker to a different location, added more debug options. added infrastructure to run the fake tau reducible background estimation method --- wh/WHAnalyzerBase.py | 112 ++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 66 deletions(-) diff --git a/wh/WHAnalyzerBase.py b/wh/WHAnalyzerBase.py index bfdb7fbd..f3d10b4a 100644 --- a/wh/WHAnalyzerBase.py +++ b/wh/WHAnalyzerBase.py @@ -57,20 +57,21 @@ import os import ROOT import math +from pdb import set_trace import itertools import array from FinalStateAnalysis.PlotTools.decorators import memo from FinalStateAnalysis.Utilities.struct import struct - +from cutflowtracker import cut_flow_tracker #Makes the cut flow histogram cut_flow_step = ['bare', 'WH Event', #'obj1 GenMatching', 'obj2 GenMatching', 'obj3 GenMatching', 'DR separation', 'sub mass cut', 'trigger', 'obj1 Presel', 'obj2 Presel', 'obj3 Presel', 'LT', 'dilepton mass cut', 'muon veto', 'bjet veto', 'electron veto', - 'tau veto', 'sign cut', 'tau sign', + 'tau veto', 'sign cut', 'tau sign', 'anti WZ', 'obj1 IDIso', 'obj2 IDIso', 'obj3 IDIso', - 'anti WZ', 'anti charge flip', + 'anti charge flip', ] @@ -88,48 +89,6 @@ def inv_mass(*args): v.SetPtEtaPhiM(*i) return sum(lorentz_vecs,ROOT.TLorentzVector()).M() #We need to give the staring point otherwise it starts from an int and it does not work -class cut_flow_tracker(object): - def __init__(self, hist): - self.labels = [hist.GetXaxis().GetBinLabel(i+1) for i in range(hist.GetNbinsX())] - self.cut_flow = dict([ (i, False) for i in self.labels]) - self.hist = hist - self.evt_info = [-1, -1, -1] - self.disabled = 'CutFlow' not in os.environ - self.sync_mode = 'SYNC' in os.environ - - def fill(self, label): - self.cut_flow[label] = True - - def Fill(self, *labels): - if self.disabled: - return - for label in labels: - self.fill(label) - - def flush(self): - if self.disabled: - return - final_i = -1 - for i, label in enumerate(self.labels): - val = self.cut_flow[label] - if val: - self.hist.Fill(i+0.5) - final_i = i - if self.sync_mode: - fails = '' - try: - fails = 'fails %s' % (self.labels[final_i+1]) - except IndexError: - fails = 'passes the selection' #if len(self.labels) == final_i else 'passes the selection' - print 'Event %i:%i:%i ' % tuple(self.evt_info) + fails - - def new_row(self, *args): - if self.disabled: - return - if self.evt_info != list(args): - self.flush() - self.evt_info = list(args) - self.cut_flow = dict([ (i, False) for i in self.labels]) class WHAnalyzerBase(MegaBase): def __init__(self, tree, outfile, wrapper, **kwargs): @@ -231,6 +190,8 @@ def fill_histos(self, histos, folder_str, row, weight, filter_label = ''): #find all keys matching for attr in self.histo_locations[folder_str]: name = attr + #if attr=='DEBUG': + # set_trace() if filter_label: if not attr.startswith(filter_label+'$'): continue @@ -315,6 +276,8 @@ def process(self): cut_region_map = self.build_wh_folder_structure() region_for_event_list = os.environ.get('EVTLIST_REGION','') no_histo_fill = ('NO_HISTO_FILL' in os.environ) and eval(os.environ['NO_HISTO_FILL']) + print_region = ('PRINT_REGION' in os.environ) and eval(os.environ['PRINT_REGION']) + debug_mode = ('DEBUG_MODE' in os.environ) and eval(os.environ['DEBUG_MODE']) # Reduce number of self lookups and get the derived functions here histos = self.histograms @@ -324,6 +287,9 @@ def process(self): obj1_id = self.obj1_id obj2_id = self.obj2_id obj3_id = self.obj3_id + obj1_matches_gen = self.obj1_matches_gen + obj2_matches_gen = self.obj2_matches_gen + obj3_matches_gen = self.obj3_matches_gen fill_histos = self.fill_histos anti_wz_cut = self.anti_wz anti_charge_flip_cut = self.anti_charge_flip if hasattr(self,'anti_charge_flip') else None @@ -385,6 +351,10 @@ def process(self): lt_tpt_in_presel = not bool(cut_settings['tauID']) if not preselection(row, cut_flow_trk, cut_settings['LT'] if lt_tpt_in_presel else 0., cut_settings['tauPT'] if lt_tpt_in_presel else 0.): continue + + if os.environ['megatarget'].startswith('Zjets') and not obj3_matches_gen(row): + continue + # Get the generic event weight event_weight = weight_func(row) @@ -402,35 +372,36 @@ def process(self): if not anti_charge_flip_cut else \ ('','charge_flip_CR/') if anti_charge_flip else ('charge_flip_CR/',) - #if row.lumi == 2348 and row.evt == 704038: - # print 'sign_result ', sign_result - # print 'obj1_id_result', obj1_id_result - # print 'obj2_id_result', obj2_id_result - # print 'obj3_id_result', obj3_id_result - # print 'anti_wz ', anti_wz - # #from pdb import set_trace; set_trace() - #from pdb import set_trace; set_trace() - #if not cut_flow_trk.disabled: if sign_result: cut_flow_trk.Fill('sign cut') if tau_sign_result: cut_flow_trk.Fill('tau sign') - if obj1_id_result: - cut_flow_trk.Fill('obj1 IDIso') - if obj2_id_result: - cut_flow_trk.Fill('obj2 IDIso') - if obj3_id_result: - cut_flow_trk.Fill('obj3 IDIso') - if anti_wz : - cut_flow_trk.Fill('anti WZ') + if anti_wz : + cut_flow_trk.Fill('anti WZ') + if obj1_id_result: + cut_flow_trk.Fill('obj1 IDIso') + if obj2_id_result: + cut_flow_trk.Fill('obj2 IDIso') + if obj3_id_result: + cut_flow_trk.Fill('obj3 IDIso') if anti_charge_flip: cut_flow_trk.Fill('anti charge flip') + if os.environ['megatarget'].startswith('Zjets'): + #remove matched but not id/Iso leptons + if obj1_matches_gen(row) and not obj1_id_result: + continue + if obj2_matches_gen(row) and not obj2_id_result: + continue + # Figure out which folder/region we are in region_result = cut_region_map.get( (sign_result, tau_sign_result, obj1_id_result, obj2_id_result, obj3_id_result)) + if debug_mode: + set_trace() + # Ignore stupid regions we don't care about if region_result is None: continue @@ -439,9 +410,18 @@ def process(self): base_folder, weights = region_result base_folder = joinDirs(*base_folder) - if region_for_event_list and base_folder == region_for_event_list: - print '%i:%i:%i' % (row.run, row.lumi, row.evt) - if no_histo_fill: + if print_region: + print 'event %i:%i:%i assigned to region(s) %s' % \ + (row.run, row.lumi, row.evt, \ + ', '.join( joinDirs(base_folder,i) for i in to_fill) ) + if region_for_event_list: + if base_folder == region_for_event_list and \ + '' in to_fill: + print '%i:%i:%i' % (row.run, row.lumi, row.evt) + else: + continue + if no_histo_fill: # and region_for_event_list and \ + #base_folder == region_for_event_list: continue # Fill the un-fr-weighted histograms @@ -478,7 +458,7 @@ def process(self): fill_histos(histos, joinDirs(directory_up,i), row, event_weight*charge_flip_sysu, cut_label) elif sign_result and obj1_id_result and obj3_id_result and tau_sign_result: - if no_histo_fill: + if no_histo_fill or region_for_event_list: continue # WZ object topology fails. Check if we are in signal region. From 6995a660154fa6e0f6b9d5364162fa9183aface9 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Dec 2013 05:03:24 -0600 Subject: [PATCH 093/192] Fixed bugs in empty bing removal, added infrastructure to plots the fake tau reducible background estimation method --- wh/WHPlotterBase.py | 181 ++++++++++++++++++++++++++++++++------------ 1 file changed, 134 insertions(+), 47 deletions(-) diff --git a/wh/WHPlotterBase.py b/wh/WHPlotterBase.py index 110ba092..e591b3d3 100644 --- a/wh/WHPlotterBase.py +++ b/wh/WHPlotterBase.py @@ -20,6 +20,7 @@ from FinalStateAnalysis.PlotTools.ProjectionView import ProjectionView from FinalStateAnalysis.PlotTools.FixedIntegralView import FixedIntegralView from FinalStateAnalysis.PlotTools.DifferentialView import DifferentialView +from FinalStateAnalysis.PlotTools.SubtractionView import SubtractionView, PositiveView from FinalStateAnalysis.PlotTools.RebinView import RebinView from FinalStateAnalysis.MetaData.data_styles import data_styles, colors from FinalStateAnalysis.PlotTools.decorators import memo @@ -33,7 +34,9 @@ import math import logging from fnmatch import fnmatch -from yellowhiggs import xs, br, xsbr + +ROOT.gStyle.SetOptTitle(0) +#ROOT.gROOT.SetStyle('Plain') parser = OptionParser(description=__doc__) parser.add_option('--dry-run', action='store_true', dest='dry_run', default = False, @@ -86,6 +89,10 @@ def fake_rate_estimate(histograms): #always, ALWAYS give as 1,2,0 cat0 = histograms.next() ret = cat0.Clone() ret.Reset() + integral = sum( i.Integral() for i in [cat0, cat1, cat2]) + entries = sum( i.GetEntries() for i in [cat0, cat1, cat2]) + weight = integral / float(entries) + for i in range(ret.GetNbinsX() + 2): c1 = cat1.GetBinContent(i) c2 = cat2.GetBinContent(i) @@ -93,14 +100,32 @@ def fake_rate_estimate(histograms): #always, ALWAYS give as 1,2,0 e1 = cat1.GetBinError(i) e2 = cat2.GetBinError(i) e0 = cat0.GetBinError(i) - if c1 == 0 and c2 == 0: + content = c1+c2-c0 + #if content <= 0: + # print "bin [%.1f, %.1f]" % (cat0.GetBinLowEdge(i), cat0.GetBinLowEdge(i)+cat0.GetBinWidth(i)) + # print "content %s c0: %s c1: %s c2: %s" % (content, c0, c1, c2) + if content <= 0 and c0 > 0: + #print "setting content to %s +/- %s" % (c0, e0) ret.SetBinContent(i,c0) ret.SetBinError(i,e0) + elif content <= 0: + #print "setting content to 10**-5 +/- %s" % (1.8*weight) + ret.SetBinContent(i,10**-5) + ret.SetBinError(i,1.8*weight) else: ret.SetBinContent(i,c1+c2-c0) ret.SetBinError(i,quad(e1,e2,e0)) return ret - + +def make_empty_bin_remover(weight): + def mc_empty_bin_remover(histogram): + ret = histogram.Clone() + for i in range(ret.GetNbinsX() + 2): + if ret.GetBinContent(i) <= 0: + ret.SetBinContent(i, 0.9200*weight) #MEAN WEIGHT + ret.SetBinError(i, 1.8*weight) + return ret + return mc_empty_bin_remover class MultyErrorView(object): #FIXME '''takes a StackView and adds systematics''' @@ -315,6 +340,31 @@ def apply_to_dict(self, dictionary, viewtype, *args, **kwargs): #project, projec ret[key] = viewtype(val, *args, **kwargs) # self.rebin_view( ProjectionView(val, project_axis, project), rebin ) return ret + def make_additional_fakes_view(self, unblinded=False, rebin=1, + project=None, project_axis=None, tau_charge='tau_os' ): + other_tau_sign = 'tau_os' if tau_charge == 'tau_ss' else 'tau_ss' + def preprocess(view): + ret = view + if project and project_axis: + ret = ProjectionView(ret, project_axis, project) + return RebinView( ret, rebin ) + + zjets_view = preprocess( self.get_view('Zjets*') ) + all_data_view = preprocess( self.get_view('data') ) + zjets_fakes = views.SumView( + views.SubdirectoryView( zjets_view, 'ss/%s/f1p2p3/w1/' % tau_charge ), + views.SubdirectoryView( zjets_view, 'ss/%s/p1f2p3/w2/' % tau_charge ) + #,views.SubdirectoryView( zjets_view, 'ss/%s/f1f2p3/w12/' % tau_charge ) #FIXME: check that effect is small + ) + tau_fakes = views.SubdirectoryView(all_data_view, 'ss/%s/p1p2f3/w3/' % tau_charge) + full_fakes = views.SumView(tau_fakes, zjets_fakes) + + return { + 'fakes' : full_fakes, + 'zjet_fakes' : zjets_fakes, + 'tau_fakes' : tau_fakes, + } + def make_signal_views(self, unblinded=False, qcd_weight_fraction=0, #MARK rebin=1, project=None, project_axis=None, tau_charge='tau_os' ): ''' Make signal views with FR background estimation ''' @@ -357,8 +407,8 @@ def preprocess(view): def make_fakes(qcd_fraction): def make_fakes_view(weight_type, scale): scaled_bare_data = views.ScaleView(all_data_view, scale) - scaled_wz_data = views.ScaleView(all_wz_view, -1*scale) - scaled_data = views.SumView(scaled_bare_data, scaled_wz_data) + scaled_wz_data = views.ScaleView(all_wz_view, scale) + scaled_data = SubtractionView(scaled_bare_data, scaled_wz_data, restrict_positive=True) # View of weighted obj1-fails data obj1_view = views.SubdirectoryView( @@ -456,10 +506,17 @@ def make_fakes_view(weight_type, scale): # Add signal data_total_lumi = self.views['data']['intlumi'] - for mass in range(100, 165, 5): + for mass in range(90, 165, 5): try: + vh_base_name = 'VH_%s' % mass if self.sqrts == 7 else 'VH_H2Tau_M-%s' % mass + vh_base_name = 'VHtautau_lepdecay_%s' % mass \ + if 'VHtautau_lepdecay_%s' % mass in self.views else \ + vh_base_name + #print 'using %s' % vh_base_name + vh_base_view = self.views[vh_base_name]['view'] + vh_view = views.SubdirectoryView( - self.get_view('VH_*%i' % mass), + vh_base_view, #self.get_view('VH_*%i' % mass), 'ss/%s/p1p2p3/' % tau_charge ) output['vh%i' % mass] = preprocess(vh_view) @@ -545,8 +602,8 @@ def make_obj3_fail_cr_views(self, qcd_correction=False, def make_fakes(qcd_fraction): def make_fakes_view(weight_type, scale): scaled_bare_data = views.ScaleView(all_data_view, scale) - wz_data = views.ScaleView(all_wz_view, -1*scale) - scaled_data = views.SumView(scaled_bare_data, wz_data) + scaled_wz_data = views.ScaleView(all_wz_view, scale) + scaled_data = SubtractionView(scaled_bare_data, scaled_wz_data, restrict_positive=True) # View of weighted obj1-fails data obj1_view = views.SubdirectoryView( scaled_data, 'ss/%s/f1p2f3/%s1' % (tau_charge, weight_type)) @@ -657,7 +714,7 @@ def make_fakes_view(weight_type, scale): 'ss/tau_os/p1p2f3/' ) except KeyError: - logging.warning('No sample found matching VH_%i_HWW*' % mass) + #logging.warning('No sample found matching VH_%i_HWW*' % mass) ww_view = None output['vh%i_hww' % mass] = ww_view output['signal%i' % mass] = views.SumView(ww_view, vh_view) if ww_view else vh_view @@ -722,33 +779,59 @@ def preprocess(view): #return output def write_shapes(self, variable, rebin, outdir, - qcd_fraction=0, show_charge_fakes=False, - project=None, project_axis=None): + qcd_fraction=0., #[1., 0., -1.], + show_charge_fakes=False, + project=None, project_axis=None, different_fakes=False): ''' Write final shapes for [variable] into a TDirectory [outputdir] ''' show_charge_fakes = show_charge_fakes if 'show_charge_fakes' not in self.defaults else self.defaults['show_charge_fakes'] sig_view = self.make_signal_views(unblinded=(not self.blind), qcd_weight_fraction=qcd_fraction, rebin=rebin, project=project, project_axis=project_axis) + + different_fakes_views = self.make_additional_fakes_view( unblinded=(not self.blind), rebin=rebin, + project=project, project_axis=project_axis) + outdir.cd() - wz = views.SumView(sig_view['wz'], sig_view['wz_3l']).Get(variable) - zz = sig_view['zz'].Get(variable) + wz_weight = self.get_view('WZJetsTo3LNu*ZToTauTau*', 'weight') + zz_weight = self.get_view('ZZJetsTo4L*', 'weight') + print "wz_weight: %s" % wz_weight + print "zz_weight: %s" % zz_weight + + wz = views.FunctorView( views.SumView(sig_view['wz'], sig_view['wz_3l']), make_empty_bin_remover(wz_weight)).Get(variable) + zz = views.FunctorView( sig_view['zz'], make_empty_bin_remover(zz_weight)).Get(variable) obs = sig_view['data'].Get(variable) - fakes = sig_view['fakes'].Get(variable) + fakes = sig_view['fakes'].Get(variable) if not different_fakes else different_fakes_views['fakes'].Get(variable) + + fakes_down = different_fakes_views['fakes'].Get(variable) + fakes_up = PositiveView( + views.SumView( views.ScaleView(sig_view['fakes'], 2.), + views.ScaleView(different_fakes_views['fakes'], -1.) + ) + ).Get(variable) wz.SetName('wz') zz.SetName('zz') obs.SetName('data_obs') fakes.SetName('fakes') - + fakes_down.SetName('fakes_CMS_vhtt_%s_fakeshape_%sTeVDown' % (outdir.GetName(), self.sqrts)) + fakes_up.SetName('fakes_CMS_vhtt_%s_fakeshape_%sTeVUp' % (outdir.GetName(), self.sqrts)) #for mass in [110, 115, 120, 125, 130, 135, 140]: - for mass in range(100, 165, 5): + #set_trace() + for mass in range(90, 165, 5): try: - vh = sig_view['vh%i' % mass].Get(variable) + vh = None + if mass == 90 and self.sqrts == 8: + vh = views.ScaleView(sig_view['vh100'], 1.3719).Get(variable) + elif mass == 95 and self.sqrts == 8: + vh = views.ScaleView(sig_view['vh100'], 1.1717).Get(variable) + else: + vh = sig_view['vh%i' % mass].Get(variable) vh.SetName('WH%i' % mass) + vh.SetLineColor(0) vh.Write() except KeyError: - logging.warning('No sample found matching VH_*%i' % mass) + #logging.warning('No sample found matching VH_*%i' % mass) continue if mass % 10 == 0 and mass < 150: @@ -762,6 +845,8 @@ def write_shapes(self, variable, rebin, outdir, zz.Write() obs.Write() fakes.Write() + fakes_down.Write() + fakes_up.Write() #charge_fakes_CMS_vhtt_emt_chargeFlip_8TeVUpx if show_charge_fakes: logging.info('adding charge fakes shape errors') @@ -836,7 +921,7 @@ def write_f3_shapes(self, variable, rebin, outdir, def plot_final(self, variable, rebin=1, xaxis='', maxy=24, show_error=False, qcd_correction=False, stack_higgs=True, - qcd_weight_fraction=0.5, x_range=None, show_charge_fakes=False, + qcd_weight_fraction=0., x_range=None, show_charge_fakes=False, leftside_legend=False, higgs_xsec_multiplier=1, project=None, project_axis=None, differential=False, yaxis='Events', tau_charge='tau_os', **kwargs): ''' Plot the final output - with bkg. estimation ''' @@ -887,24 +972,25 @@ def plot_final(self, variable, rebin=1, xaxis='', maxy=24, legend = self.add_legend(histo, leftside=leftside_legend, entries=entries) if show_error: - correct_qcd_view = None - if qcd_weight_fraction == 0: - fakes05 = sig_view['weighted_fakes'][0.5] - correct_qcd_view = MedianView(highv=fakes05, centv=sig_view['fakes']) - - elif qcd_weight_fraction == 0.5: - fakes1 = sig_view['weighted_fakes'][1.] - correct_qcd_view = MedianView(highv=fakes1, centv=sig_view['fakes']) - - elif qcd_weight_fraction == 1: - fakes05 = sig_view['weighted_fakes'][0.5] - correct_qcd_view = MedianView(lowv=fakes05, centv=sig_view['fakes']) + #correct_qcd_view = None + #if qcd_weight_fraction == 0: + # fakes05 = sig_view['weighted_fakes'][1.] + # correct_qcd_view = MedianView(lowv=fakes05, centv=sig_view['fakes']) + # + #elif qcd_weight_fraction == 0.5: + # fakes1 = sig_view['weighted_fakes'][1.] + # correct_qcd_view = MedianView(highv=fakes1, centv=sig_view['fakes']) + # + #elif qcd_weight_fraction == 1: + # fakes05 = sig_view['weighted_fakes'][0.5] + # correct_qcd_view = MedianView(lowv=fakes05, centv=sig_view['fakes']) bkg_error_view = BackgroundErrorView( - correct_qcd_view, #sig_view['fakes'], + sig_view['fakes'], #correct_qcd_view, #sig_view['fakes'], views.SumView( sig_view['wz'], sig_view['wz_3l']), sig_view['zz'], charge_fakes_view, + fake_error=0.3, **kwargs ) bkg_error = bkg_error_view.Get(variable) @@ -965,7 +1051,7 @@ def plot_final_wz(self, variable, rebin=1, xaxis='', maxy=None, project=None, pr def plot_final_f3(self, variable, rebin=1, xaxis='', maxy=None, show_error=True, qcd_correction=False, - qcd_weight_fraction=0.5, x_range=None, #): + qcd_weight_fraction=0., x_range=None, #): show_chi2=False,project=None, project_axis=None, differential=False, yaxis='Events', tau_charge='tau_os', show_ratio=False, @@ -1007,24 +1093,25 @@ def plot_final_f3(self, variable, rebin=1, xaxis='', maxy=None, #latexit = '' bkg_error = None if show_error: - correct_qcd_view = None - if qcd_weight_fraction == 0: - fakes05 = sig_view['weighted_fakes'][0.5] - correct_qcd_view = MedianView(highv=fakes05, centv=sig_view['fakes']) - - elif qcd_weight_fraction == 0.5: - fakes1 = sig_view['weighted_fakes'][1.] - correct_qcd_view = MedianView(highv=fakes1, centv=sig_view['fakes']) - - elif qcd_weight_fraction == 1: - fakes05 = sig_view['weighted_fakes'][0.5] - correct_qcd_view = MedianView(lowv=fakes05, centv=sig_view['fakes']) + #correct_qcd_view = None + #if qcd_weight_fraction == 0: + # fakes05 = sig_view['weighted_fakes'][1.] + # correct_qcd_view = MedianView(lowv=fakes05, centv=sig_view['fakes']) + # + #elif qcd_weight_fraction == 0.5: + # fakes1 = sig_view['weighted_fakes'][1.] + # correct_qcd_view = MedianView(highv=fakes1, centv=sig_view['fakes']) + # + #elif qcd_weight_fraction == 1: + # fakes05 = sig_view['weighted_fakes'][0.5] + # correct_qcd_view = MedianView(lowv=fakes05, centv=sig_view['fakes']) bkg_error_view = BackgroundErrorView( - correct_qcd_view, #sig_view['fakes'], + sig_view['fakes'], #correct_qcd_view, views.SumView(sig_view['wz'], sig_view['wz_3l']), sig_view['zz'], charge_fakes_view, + fake_error=0.3, **kwargs ) bkg_error = bkg_error_view.Get(variable) From e69d96a035a5f9b26b683527a9993b4915deae5e Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Dec 2013 05:05:23 -0600 Subject: [PATCH 094/192] Removed unused plots, added more control flows to make fewer plots faster --- wh/WHPlotterEET.py | 900 ++++++++++++++++++++------------------------ wh/WHPlotterEMT.py | 916 ++++++++++++++++++++++----------------------- wh/WHPlotterMMT.py | 571 ++++++++++++++-------------- 3 files changed, 1150 insertions(+), 1237 deletions(-) diff --git a/wh/WHPlotterEET.py b/wh/WHPlotterEET.py index ed4688e3..6a37348d 100755 --- a/wh/WHPlotterEET.py +++ b/wh/WHPlotterEET.py @@ -48,502 +48,420 @@ def __init__(self): options,NOTUSED = parser.parse_args() if not options.dry_run: - ########################################################################### - ## Zee control plots ##################################################### - ########################################################################### - ## # Control Z->ee + jet region - plotter.set_subdir('mc_data/zee') + if not options.no_mc_data: + ########################################################################### + ## Zee control plots ##################################################### + ########################################################################### + ## # Control Z->ee + jet region + plotter.set_subdir('mc_data/zee') - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e1_e2_Mass', rebin=10, - xaxis='m_{#mu#mu} (GeV)', leftside=False) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-Zee-e1e2Mass') - - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e1Pt#LT', rebin=10, - xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-Zee-e1Pt') - - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e2Pt#LT', rebin=10, - xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-Zee-e2Pt') - - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e1AbsEta#LT', rebin=10, - xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-Zee-e1AbsEta') - - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e2AbsEta#LT', rebin=10, - xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-Zee-e2AbsEta') - - # Check PU variables - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'rho') - plotter.save('mcdata-Zee-rho') + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e1_e2_Mass', rebin=10, + xaxis='m_{#mu#mu} (GeV)', leftside=False) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-Zee-e1e2Mass') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e1Pt#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-Zee-e1Pt') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e2Pt#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-Zee-e2Pt') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e1AbsEta#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-Zee-e1AbsEta') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e2AbsEta#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-Zee-e2AbsEta') + + # Check PU variables + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'rho') + plotter.save('mcdata-Zee-rho') - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'nvtx') - plotter.save('mcdata-Zee-nvtx') - - - ########################################################################### - ## WZ control plots ##################################################### - ########################################################################### - plotter.set_subdir('mc_data/wz_enhanced') + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'nvtx') + plotter.save('mcdata-Zee-nvtx') + + if not options.no_wz: + ########################################################################### + ## WZ control plots ##################################################### + ########################################################################### + plotter.set_subdir('mc_data/wz_enhanced') - plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'e2_t_Mass#LT', xaxis='m_{#mu#mu} (GeV)', - xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1p2p3-enhance_wz-subMass') + plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'e2_t_Mass#LT', xaxis='m_{#mu#mu} (GeV)', + xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-ss-p1p2p3-enhance_wz-subMass') - plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'e1_t_Mass', xaxis='m_{#mu#mu} (GeV)', - xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1p2p3-enhance_wz-leadMass') - - plotter.set_subdir('WZ_enhanced') - - plotter.plot_final_wz('e1_t_Mass', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-leadMass') - - plotter.plot_final_wz('e2_t_Mass#LT', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', - project=[0,650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-subMass') - - plotter.plot_final_wz('e2Pt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', - project=[0,650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-e2Pt') + plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'e1_t_Mass', xaxis='m_{#mu#mu} (GeV)', + xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-ss-p1p2p3-enhance_wz-leadMass') + + plotter.set_subdir('WZ_enhanced') + + plotter.plot_final_wz('e1_t_Mass', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-leadMass') + + plotter.plot_final_wz('e2_t_Mass#LT', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-subMass') + + plotter.plot_final_wz('e2Pt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-e2Pt') - plotter.plot_final_wz('e2JetPt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', - project=[0,650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-e2JetPt') - + plotter.plot_final_wz('e2JetPt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-e2JetPt') + + if not options.no_signal: + ########################################################################### + ## Signal region plots ################################################ + ########################################################################### + plotter.set_subdir('') + + for label, proj_range in categories.iteritems(): + factor = 1.5 if label == 'LTHigh' else 1 + for tau_charge in ['tau_os', 'tau_ss']: + if tau_charge == 'tau_os': + plotter.set_subdir('%s' % label) + else: + plotter.set_subdir('%s_charge3' % label) + + plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', + maxy=None, project=proj_range, project_axis='X', + differential=True, yaxis='Events / GeV', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s' % label) + + plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', + maxy=None, project=proj_range, project_axis='X', + differential=True, yaxis='Events / GeV', show_error=True, + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.canvas.SetLogy(True) + plotter.save('final-subMass-logscale-%s' % label) + + plotter.plot_final('e2_t_Mass#LT', 300, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge, + show_error=True) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) + + #pt + plotter.plot_final("e1Pt#LT" , int(factor*10), xaxis='p_{Te_{1}} (GeV)', + maxy=None, project=proj_range, project_axis='X', + tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e1Pt-%s' % label) + + plotter.plot_final("e2Pt#LT", int(factor*10), xaxis='p_{Te_{2}} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e2Pt-%s' % label) + + plotter.plot_final("tPt#LT", int(factor*10), xaxis='p_{T#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-tPt-%s' % label) + + #plotter.plot_final("e1JetPt#LT", int(factor*10), xaxis='p_{T Jet e_{1}} (GeV)', + # maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-e1JetPt-%s' % label) + # + #plotter.plot_final("e2JetPt#LT", int(factor*10), xaxis='p_{T Jet e_{2}} (GeV)', + # maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-e2JetPt-%s' % label) + + #eta + plotter.plot_final("e1AbsEta#LT", 10, xaxis='|#eta_{e_{1}}|', maxy=None, project=proj_range, + project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e1AbsEta-%s' % label) + + plotter.plot_final("e2AbsEta#LT", 10, xaxis='|#eta_{e_{2}}|', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-e2AbsEta-%s' % label) + + #DR + #plotter.plot_final("e1_t_DR#LT", 10, xaxis='#DeltaR_{e_{1}#tau}', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-e1_t_DR-%s' % label) + # + #plotter.plot_final("e2_t_DR#LT", 10, xaxis='#DeltaR_{e_{2}#tau}', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-e2_t_DR-%s' % label) + + #plotter.plot_final('e2RelPFIsoDB', 10, maxy='auto') + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-e2Iso') + + ## plotter.plot_final('metSignificance', 5) + ## plotter.add_cms_blurb(sqrts) + ## plotter.save('final-metSig') + + plotter.plot_final('LT', 10, maxy='auto', xaxis='m_{e_{1}#tau} (GeV)') + plotter.add_cms_blurb(sqrts) + plotter.save('final-LT') + + if not options.no_f3: + ########################################################################### + ## f3 region plots ################################################ + ########################################################################### + + for label, proj_range in categories.iteritems(): + factor = 1.5 if label == 'LTHigh' else 1 + for tau_charge in ['tau_os', 'tau_ss']: + if tau_charge == 'tau_os': + plotter.set_subdir('f3/%s' % label) + else: + plotter.set_subdir('f3/%s_charge3' % label) + + plotter.plot_final_f3('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, + yaxis='Events / GeV', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s' % label) + + plotter.plot_final_f3('e2_t_Mass#LT', 300, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) + + #pt + plotter.plot_final_f3("e1Pt#LT", int(factor*10), xaxis='p_{Te_{1}} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e1Pt-%s' % label) + + plotter.plot_final_f3("e2Pt#LT", int(factor*10), xaxis='p_{Te_{2}} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e2Pt-%s' % label) + + plotter.plot_final_f3("tPt#LT", int(factor*10), xaxis='p_{T#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-tPt-%s' % label) + + #plotter.plot_final_f3("e1JetPt#LT", int(factor*10), xaxis='p_{T Jet e_{1}} (GeV)', + # maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-e1JetPt-%s' % label) + # + #plotter.plot_final_f3("e2JetPt#LT" , int(factor*10), xaxis='p_{T Jet e_{2}} (GeV)', + # maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-e2JetPt-%s' % label) + + #eta + plotter.plot_final_f3("e1AbsEta#LT", 10, xaxis='|#eta_{e_{1}}|', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e1AbsEta-%s' % label) + + plotter.plot_final_f3("e2AbsEta#LT", 10, xaxis='|#eta_{e_{2}}|', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-e2AbsEta-%s' % label) + + #DR + #plotter.plot_final_f3("e1_t_DR#LT", 10, xaxis='#DeltaR_{e_{1}#tau}', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-e1_t_DR-%s' % label) + # + #plotter.plot_final_f3("e2_t_DR#LT", 10, xaxis='#DeltaR_{e_{2}#tau}', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-e2_t_DR-%s' % label) + + + + plotter.set_subdir('f3') + + plotter.plot_final_f3('LT', 5, show_error=True) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-LT') + + ########################################################################### + ## charge flip region plots ####################################### + ########################################################################### + #plotter.set_subdir('charge_flip_CR_f3') + # + #plotter.plot_final_f3('charge_flip_CR/e2_t_Mass', 20, xaxis='m_{e_{2}#tau} (GeV)', show_error=True) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-chargeFlip-subMass') + # + #plotter.plot_final_f3('charge_flip_CR/e1_t_Mass', 20, xaxis='m_{e_{1}#tau} (GeV)', show_error=True) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-chargeFlip-e1tMass') + # + #plotter.plot_final_f3('charge_flip_CR/e1_e2_Mass', 5, xaxis='m_{ee} (GeV)', show_error=True) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-chargeFlip-e1e2Mass') + + #END OF if not options.dry_run: + if not options.no_shapes: ########################################################################### - ## Signal region plots ################################################ + ## Making shape file ################################################# ########################################################################### plotter.set_subdir('') - - for label, proj_range in categories.iteritems(): - factor = 1.5 if label == 'LTHigh' else 1 - for tau_charge in ['tau_os', 'tau_ss']: - if tau_charge == 'tau_os': - plotter.set_subdir('%s' % label) - else: - plotter.set_subdir('%s_charge3' % label) - - plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', - maxy=None, project=proj_range, project_axis='X', - differential=True, yaxis='Events / GeV', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-%s' % label) - - plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', - maxy=None, project=proj_range, project_axis='X', - differential=True, yaxis='Events / GeV', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.canvas.SetLogy(True) - plotter.save('final-subMass-logscale-%s' % label) - - plotter.plot_final('e2_t_Mass#LT', 300, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge, - show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) - - #pt - plotter.plot_final("e1Pt#LT" , int(factor*10), xaxis='p_{Te_{1}} (GeV)', - maxy=None, project=proj_range, project_axis='X', - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e1Pt-%s' % label) - - plotter.plot_final("e2Pt#LT", int(factor*10), xaxis='p_{Te_{2}} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e2Pt-%s' % label) - - plotter.plot_final("e1JetPt#LT", int(factor*10), xaxis='p_{T Jet e_{1}} (GeV)', - maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e1JetPt-%s' % label) - - plotter.plot_final("e2JetPt#LT", int(factor*10), xaxis='p_{T Jet e_{2}} (GeV)', - maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e2JetPt-%s' % label) - - #eta - plotter.plot_final("e1AbsEta#LT", 10, xaxis='|#eta_{e_{1}}|', maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e1AbsEta-%s' % label) - - plotter.plot_final("e2AbsEta#LT", 10, xaxis='|#eta_{e_{2}}|', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e2AbsEta-%s' % label) - - #DR - plotter.plot_final("e1_t_DR#LT", 10, xaxis='#DeltaR_{e_{1}#tau}', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e1_t_DR-%s' % label) - - plotter.plot_final("e2_t_DR#LT", 10, xaxis='#DeltaR_{e_{2}#tau}', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e2_t_DR-%s' % label) - - plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=[0, 130], project_axis='X', differential=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTLow') - - plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=[130, 650], project_axis='X', differential=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTHigh') - - plotter.plot_final('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=[80, 650], project_axis='X', differential=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTCut') - - plotter.plot_final('e2_t_Mass#LT', 20, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, project=[80, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-LTCut-flatbin') - - plotter.plot_final('e1Pt', 10, maxy='auto') - plotter.add_cms_blurb(sqrts) - plotter.save('final-e1Pt') - - plotter.plot_final('e2Pt', 10, maxy='auto') - plotter.add_cms_blurb(sqrts) - plotter.save('final-e2Pt') - - plotter.plot_final('tPt', 10, maxy='auto') - plotter.add_cms_blurb(sqrts) - plotter.save('final-tPt') - - plotter.plot_final('e1AbsEta', 10, maxy='auto') - plotter.add_cms_blurb(sqrts) - plotter.save('final-e1AbsEta') - - plotter.plot_final('e2AbsEta', 10, maxy='auto') - plotter.add_cms_blurb(sqrts) - plotter.save('final-e2AbsEta') - - plotter.plot_final('tAbsEta', 10, maxy='auto') - plotter.add_cms_blurb(sqrts) - plotter.save('final-tAbsEta') - - plotter.plot_final('e2_t_Mass', 20, xaxis='m_{e_{2}#tau} (GeV)', maxy='auto') - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass') - - plotter.plot_final('e1_t_Mass', 20, xaxis='m_{e_{1}#tau} (GeV)', maxy='auto') - plotter.add_cms_blurb(sqrts) - plotter.save('final-e1tMass') - - plotter.plot_final('e1_e2_Mass', 20, xaxis='m_{ee} (GeV)', maxy='auto') - plotter.add_cms_blurb(sqrts) - plotter.save('final-e1e2Mass') - - plotter.plot_final('tAbsEta', 5, xaxis='|#eta_#tau|', maxy='auto') - plotter.add_cms_blurb(sqrts) - plotter.save('final-tAbsEta') - - plotter.plot_final('e2RelPFIsoDB', 10, maxy='auto') - plotter.add_cms_blurb(sqrts) - plotter.save('final-e2Iso') - - ## plotter.plot_final('metSignificance', 5) - ## plotter.add_cms_blurb(sqrts) - ## plotter.save('final-metSig') - - plotter.plot_final('LT', 10, maxy='auto', xaxis='m_{e_{1}#tau} (GeV)') - plotter.add_cms_blurb(sqrts) - plotter.save('final-LT') - - - ########################################################################### - ## f3 region plots ################################################ - ########################################################################### - - for label, proj_range in categories.iteritems(): - factor = 1.5 if label == 'LTHigh' else 1 - for tau_charge in ['tau_os', 'tau_ss']: - if tau_charge == 'tau_os': - plotter.set_subdir('f3/%s' % label) - else: - plotter.set_subdir('f3/%s_charge3' % label) - - plotter.plot_final_f3('e2_t_Mass#LT', rebin_slim, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', differential=True, - yaxis='Events / GeV', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s' % label) - - plotter.plot_final_f3('e2_t_Mass#LT', 300, xaxis='m_{e_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) - - #pt - plotter.plot_final_f3("e1Pt#LT", int(factor*10), xaxis='p_{Te_{1}} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1Pt-%s' % label) - - plotter.plot_final_f3("e2Pt#LT", int(factor*10), xaxis='p_{Te_{2}} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2Pt-%s' % label) - - plotter.plot_final_f3("e1JetPt#LT", int(factor*10), xaxis='p_{T Jet e_{1}} (GeV)', - maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1JetPt-%s' % label) - - plotter.plot_final_f3("e2JetPt#LT" , int(factor*10), xaxis='p_{T Jet e_{2}} (GeV)', - maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2JetPt-%s' % label) - - #eta - plotter.plot_final_f3("e1AbsEta#LT", 10, xaxis='|#eta_{e_{1}}|', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1AbsEta-%s' % label) - - plotter.plot_final_f3("e2AbsEta#LT", 10, xaxis='|#eta_{e_{2}}|', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2AbsEta-%s' % label) - - #DR - plotter.plot_final_f3("e1_t_DR#LT", 10, xaxis='#DeltaR_{e_{1}#tau}', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1_t_DR-%s' % label) - - plotter.plot_final_f3("e2_t_DR#LT", 10, xaxis='#DeltaR_{e_{2}#tau}', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2_t_DR-%s' % label) - - - - plotter.set_subdir('f3') - plotter.plot_final_f3('e2_t_Mass', 20, xaxis='m_{e_{2}#tau} (GeV)', qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass') - - plotter.plot_final_f3('e2_t_Mass', 300, xaxis='m_{e_{2}#tau} (GeV)', qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-counting-like', dotc=True, dotroot=True) - - plotter.plot_final_f3('e2_t_Mass', 20, xaxis='m_{e_{2}#tau} (GeV)', qcd_weight_fraction=0, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-wjetfake-subMass') - - plotter.plot_final_f3('e2_t_Mass', 20, xaxis='m_{e_{2}#tau} (GeV)', qcd_weight_fraction=1, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-qcdfake-subMass') - - plotter.plot_final_f3('e1_t_Mass', 20, xaxis='m_{e_{1}#tau} (GeV)', qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1tMass') - - plotter.plot_final_f3('e1_e2_Mass', 20, xaxis='m_{ee} (GeV)', qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1e2Mass') - - plotter.plot_final_f3('e1Pt', 10, qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1Pt') - - plotter.plot_final_f3('e2Pt', 10, qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2Pt') - - plotter.plot_final_f3('e2JetPt', 10, qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2JetPt') - - plotter.plot_final_f3('tPt', 10, qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tPt') - - plotter.plot_final_f3('e1AbsEta', 10, qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1AbsEta') - - plotter.plot_final_f3('e2AbsEta', 10, qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2AbsEta') - - plotter.plot_final_f3('tAbsEta', 10, qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tAbsEta') - - plotter.plot_final_f3('LT', 5, qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-LT') - - plotter.plot_final_f3('e1_t_DR', 20, xaxis='#DeltaR_{e_{1}#tau}', x_range=[0,5]) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e1_t_DR') - - plotter.plot_final_f3('e2_t_DR', 20, xaxis='#DeltaR_{e_{2}#tau}', x_range=[0,5]) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e2_t_DR') - - plotter.plot_final_f3('e2_t_Mass#LT', 20, xaxis='subleading mass from projection', maxy=None, project=[0, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMassProj') - - plotter.plot_final_f3('e2_t_Mass#LT', 20, xaxis='M_{e_{2}#tau} (GeV)', maxy=None, project=[0, 70], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-LTLo') - - plotter.plot_final_f3('e2_t_Mass#LT', 20, xaxis='M_{e_{2}#tau} (GeV)', maxy=None, project=[70, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-LTHi') - - ########################################################################### - ## charge flip region plots ####################################### - ########################################################################### - plotter.set_subdir('charge_flip_CR_f3') - - plotter.plot_final_f3('charge_flip_CR/e2_t_Mass', 20, xaxis='m_{e_{2}#tau} (GeV)', qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-chargeFlip-subMass') - - plotter.plot_final_f3('charge_flip_CR/e1_t_Mass', 20, xaxis='m_{e_{1}#tau} (GeV)', qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-chargeFlip-e1tMass') - - plotter.plot_final_f3('charge_flip_CR/e1_e2_Mass', 5, xaxis='m_{ee} (GeV)', qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-chargeFlip-e1e2Mass') - - #END OF if not options.dry_run: - ########################################################################### - ## Making shape file ################################################# - ########################################################################### - plotter.set_subdir('') - prefixes = [options.prefix+'$'] if options.prefix else [''] - prefixes = [i+'$' for i in options.prefixes.split(',') if i] if options.prefixes else prefixes - for prefix in prefixes: - shape_prefix = prefix if len(prefixes) > 1 else '' - shape_prefix = shape_prefix.replace(':','_').replace('$','_') - - plotter.plot_final_f3(prefix+'e2_t_Mass', 20, qcd_weight_fraction=0.5, xaxis='m_{e_{2}#tau} (GeV)', show_error=True, maxy='auto') - plotter.add_cms_blurb(sqrts) - plotter.canvas.SetGridx() - plotter.canvas.SetGridy() - plotter.save('final-%s-f3-subMass' % shape_prefix) - - plotter.plot_final(prefix+'e2_t_Mass', 20, qcd_weight_fraction=0.5, xaxis='m_{e_{2}#tau} (GeV)', maxy='auto') - plotter.add_cms_blurb(sqrts) - plotter.canvas.SetGridx() - plotter.canvas.SetGridy() - plotter.save('final-%s-subMass' % shape_prefix) - - plotter.plot_final(prefix+'LT', 10, qcd_weight_fraction=0.5, xaxis='m_{e_{2}#tau} (GeV)', maxy='auto') - plotter.add_cms_blurb(sqrts) - plotter.canvas.SetGridx() - plotter.canvas.SetGridy() - plotter.save('final-%s-LT' % shape_prefix) - - shape_file = ROOT.TFile( - os.path.join(plotter.outputdir, 'LTCut_eet_shapes_%s.root' % ( plotter.period) ), 'RECREATE') - shape_dir = shape_file.mkdir('eetCatHigh') - plotter.write_shapes(prefix+'e2_t_Mass#LT', 20, shape_dir, qcd_fraction=0.5, project=[80, 650], project_axis='X') - shape_dir = shape_file.mkdir('eetCatHigh_w') - plotter.write_shapes(prefix+'e2_t_Mass#LT', 20, shape_dir, qcd_fraction=0.0, project=[80, 650], project_axis='X') - shape_dir = shape_file.mkdir('eetCatHigh_q') - plotter.write_shapes(prefix+'e2_t_Mass#LT', 20, shape_dir, qcd_fraction=1.0, project=[80, 650], project_axis='X') - logging.warning('shape file %s created' % shape_file.GetName()) - shape_file.Close() - - - shape_file = ROOT.TFile( - os.path.join(plotter.outputdir, '%seet_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') - - shape_dir = shape_file.mkdir('eetCatLow') - plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0, 100], project_axis='X') - shape_dir = shape_file.mkdir('eetCatLow_w') - plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0, 100], project_axis='X') - shape_dir = shape_file.mkdir('eetCatLow_q') - plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0, 100], project_axis='X') - - shape_dir = shape_file.mkdir('eetCatHigh') - plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[100, 650], project_axis='X') - shape_dir = shape_file.mkdir('eetCatHigh_w') - plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[100, 650], project_axis='X') - shape_dir = shape_file.mkdir('eetCatHigh_q') - plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[100, 650], project_axis='X') - - logging.warning('shape file %s created' % shape_file.GetName()) - shape_file.Close() - - - shape_file = ROOT.TFile( - os.path.join(plotter.outputdir, '%seet_f3_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') - - shape_dir = shape_file.mkdir('eetCatLow') - plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('eetCatLow_w') - plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('eetCatLow_q') - plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') - - shape_dir = shape_file.mkdir('eetCatHigh') - plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('eetCatHigh_w') - plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('eetCatHigh_q') - plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') - - logging.warning('shape file %s created' % shape_file.GetName()) - shape_file.Close() - - shape_file = ROOT.TFile( - os.path.join(plotter.outputdir, '%seet_f3_all_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') - - shape_dir = shape_file.mkdir('eetCatLow') - plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('eetCatLow_w') - plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('eetCatLow_q') - plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') - - shape_dir = shape_file.mkdir('eetCatHigh') - plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('eetCatHigh_w') - plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('eetCatHigh_q') - plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') - - shape_dir = shape_file.mkdir('eetCatLowf3') - plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('eetCatLowf3_w') - plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('eetCatLowf3_q') - plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') - - shape_dir = shape_file.mkdir('eetCatHighf3') - plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('eetCatHighf3_w') - plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('eetCatHighf3_q') - plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') - - logging.warning('shape file %s created' % shape_file.GetName()) - shape_file.Close() + prefixes = [options.prefix+'$'] if options.prefix else [''] + prefixes = [i+'$' for i in options.prefixes.split(',') if i] if options.prefixes else prefixes + for prefix in prefixes: + shape_prefix = prefix if len(prefixes) > 1 else '' + shape_prefix = shape_prefix.replace(':','_').replace('$','_') + binning_7TeV = [0,40,80,120,200] + + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, 'LTCut_eet_shapes_%s.root' % ( plotter.period) ), 'RECREATE') + shape_dir = shape_file.mkdir('eetCatHigh') + plotter.write_shapes(prefix+'e2_t_Mass#LT', binning_7TeV, shape_dir, qcd_fraction=0., project=[80, 650], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatHigh_w') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', 20, shape_dir, qcd_fraction=0.0, project=[80, 650], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatHigh_q') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', 20, shape_dir, qcd_fraction=1.0, project=[80, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() + + + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, 'LTCut_eet_shapes_%s_different_fakes.root' % ( plotter.period) ), 'RECREATE') + shape_dir = shape_file.mkdir('eetCatHigh') + plotter.write_shapes(prefix+'e2_t_Mass#LT', binning_7TeV, shape_dir, qcd_fraction=0., project=[80, 650], project_axis='X', different_fakes=True) + #shape_dir = shape_file.mkdir('eetCatHigh_w') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', 20, shape_dir, qcd_fraction=0.0, project=[80, 650], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatHigh_q') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', 20, shape_dir, qcd_fraction=1.0, project=[80, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() + + + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, 'LTAll_eet_shapes_%s.root' % ( plotter.period) ), 'RECREATE') + shape_dir = shape_file.mkdir('eet') + plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0., project=[0, 650], project_axis='X') + #shape_dir = shape_file.mkdir('eet_w') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0, 650], project_axis='X') + #shape_dir = shape_file.mkdir('eet_q') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() + + + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, '%seet_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') + + shape_dir = shape_file.mkdir('eetCatLow') + plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0., project=[0, 100], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatLow_w') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0, 100], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatLow_q') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0, 100], project_axis='X') + + shape_dir = shape_file.mkdir('eetCatHigh') + plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0., project=[100, 650], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatHigh_w') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[100, 650], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatHigh_q') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[100, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() + + + + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, '%seet_shapes_%s_different_fakes.root' % (shape_prefix, plotter.period) ), 'RECREATE') + + shape_dir = shape_file.mkdir('eetCatLow') + plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0., project=[0, 100], project_axis='X', different_fakes=True) + #shape_dir = shape_file.mkdir('eetCatLow_w') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0, 100], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatLow_q') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0, 100], project_axis='X') + + shape_dir = shape_file.mkdir('eetCatHigh') + plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0., project=[100, 650], project_axis='X', different_fakes=True) + #shape_dir = shape_file.mkdir('eetCatHigh_w') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[100, 650], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatHigh_q') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[100, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() + + + #shape_file = ROOT.TFile( + # os.path.join(plotter.outputdir, '%seet_f3_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') + # + #shape_dir = shape_file.mkdir('eetCatLow') + #plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + ##shape_dir = shape_file.mkdir('eetCatLow_w') + ##plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + ##shape_dir = shape_file.mkdir('eetCatLow_q') + ##plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + # + #shape_dir = shape_file.mkdir('eetCatHigh') + #plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + ##shape_dir = shape_file.mkdir('eetCatHigh_w') + ##plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + ##shape_dir = shape_file.mkdir('eetCatHigh_q') + ##plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + # + #logging.warning('shape file %s created' % shape_file.GetName()) + #shape_file.Close() + # + #shape_file = ROOT.TFile( + # os.path.join(plotter.outputdir, '%seet_f3_all_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') + # + #shape_dir = shape_file.mkdir('eetCatLow') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatLow_w') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatLow_q') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + # + #shape_dir = shape_file.mkdir('eetCatHigh') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatHigh_w') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatHigh_q') + #plotter.write_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + # + #shape_dir = shape_file.mkdir('eetCatLowf3') + #plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatLowf3_w') + #plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatLowf3_q') + #plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + # + #shape_dir = shape_file.mkdir('eetCatHighf3') + #plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatHighf3_w') + #plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('eetCatHighf3_q') + #plotter.write_f3_shapes(prefix+'e2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + # + #logging.warning('shape file %s created' % shape_file.GetName()) + #shape_file.Close() diff --git a/wh/WHPlotterEMT.py b/wh/WHPlotterEMT.py index aec4f2e7..f1e0b7c3 100644 --- a/wh/WHPlotterEMT.py +++ b/wh/WHPlotterEMT.py @@ -34,7 +34,8 @@ def __init__(self): 'LTHigh': [130, 650], 'Full' : [0, 650], } -rebin_slim = [20]+range(30, 81, 10)+[100,130,300] +rebin_slim = [20]+range(30, 81, 10)+[100,130,200] +binning_7TeV = [0,40,80,120,200] if __name__ == "__main__": plotter = WHPlotterEMT() @@ -42,472 +43,463 @@ def __init__(self): plotter.defaults['show_charge_fakes'] = True options,NOTUSED = parser.parse_args() if not options.dry_run: - ########################################################################### - ## Ztt control plots ##################################################### - ########################################################################### - plotter.set_subdir('mc_data/em') - - # Control Z->tautau + jet region - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e_m_Mass#LT', rebin=10, xaxis='m_{e#mu} (GeV)', - leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-em-emMass') - - - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'mPt#LT', rebin=10, - xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-em-mPt') - - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'ePt#LT', rebin=10, - xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-em-ePt') - - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'mAbsEta#LT', rebin=10, - xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-em-mAbsEta') - - plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'eAbsEta#LT', rebin=10, - xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-em-eAbsEta') - - - ########################################################################### - ## WZ control plots ##################################################### - ########################################################################### - plotter.set_subdir('mc_data/wz_enhanced') + if not options.no_mc_data: + ########################################################################### + ## Ztt control plots ##################################################### + ########################################################################### + plotter.set_subdir('mc_data/em') + + # Control Z->tautau + jet region + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'e_m_Mass#LT', rebin=10, xaxis='m_{e#mu} (GeV)', + leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-em-emMass') + + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'mPt#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-em-mPt') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'ePt#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-em-ePt') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'mAbsEta#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-em-mAbsEta') + + plotter.plot_mc_vs_data('os/tau_?s/p1p2?3', 'eAbsEta#LT', rebin=10, + xaxis='p_{T}^{#mu1} (GeV)', leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-em-eAbsEta') + + if not options.no_wz: + ########################################################################### + ## WZ control plots ##################################################### + ########################################################################### + plotter.set_subdir('mc_data/wz_enhanced') - plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'e_t_Mass#LT', xaxis='m_{e#tau} (GeV)', - xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1p2p3-enhance_wz-e_t_Mass') + plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'e_t_Mass#LT', xaxis='m_{e#tau} (GeV)', + xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-ss-p1p2p3-enhance_wz-e_t_Mass') - plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'm_t_Mass#LT', xaxis='m_{#mu#tau} (GeV)', - xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) - plotter.add_cms_blurb(sqrts) - plotter.save('mcdata-ss-p1p2p3-enhance_wz-leadMass') - - plotter.set_subdir('WZ_enhanced') - - plotter.plot_final_wz('e_t_Mass#LT', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', - project=[0,650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-e_t_Mass') - - plotter.plot_final_wz('m_t_Mass#LT', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', - project=[0,650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-m_t_Mass') - - plotter.plot_final_wz('ePt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', - project=[0,650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-ePt') + plotter.plot_mc_vs_data('ss/tau_os/p1p2p3_enhance_wz', 'm_t_Mass#LT', xaxis='m_{#mu#tau} (GeV)', + xrange=(0, 120), rebin=10, leftside=False, preprocess=project_x) + plotter.add_cms_blurb(sqrts) + plotter.save('mcdata-ss-p1p2p3-enhance_wz-leadMass') + + plotter.set_subdir('WZ_enhanced') + + plotter.plot_final_wz('e_t_Mass#LT', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-e_t_Mass') + + plotter.plot_final_wz('m_t_Mass#LT', 10, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-m_t_Mass') + + plotter.plot_final_wz('ePt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-ePt') - plotter.plot_final_wz('eJetPt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', - project=[0,650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-wz-eJetPt') + plotter.plot_final_wz('eJetPt#LT', 5, xaxis='m_{#mu_{1}#tau_{#mu}} (GeV)', + project=[0,650], project_axis='X') + plotter.add_cms_blurb(sqrts) + plotter.save('final-wz-eJetPt') + + if not options.no_signal: + ########################################################################### + ## Signal region plots ################################################ + ########################################################################### + plotter.set_subdir('') + + for label, proj_range in categories.iteritems(): + for tau_charge in ['tau_os', 'tau_ss']: + if tau_charge == 'tau_os': + plotter.set_subdir('%s' % label) + else: + plotter.set_subdir('%s_charge3' % label) + + plotter.plot_final('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, + yaxis='Events / GeV', show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s' % label) + + plotter.plot_final('subMass#LT', binning_7TeV, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, + yaxis='Events / GeV', show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-7TeVBin-%s' % label) + + + #plotter.plot_final("e_m_Mass#LT", 20, xaxis='m_{e#mu} (GeV)', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-e_m_Mass-%s' % label) + # + #plotter.plot_final("m_t_Mass#LT", 20, xaxis='m_{#mu#tau} (GeV)', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-m_t_Mass-%s' % label) + # + #plotter.plot_final("e_t_Mass#LT", 20, xaxis='m_{e#tau} (GeV)', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-e_t_Mass-%s' % label) + + plotter.plot_final('subMass#LT', 300, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge, + show_error=True) + plotter.add_cms_blurb(sqrts) + plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) + + #pt + #plotter.plot_final("mPt#LT" , 10, xaxis='p_{T#mu} (GeV)', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-mPt-%s' % label) + # + #plotter.plot_final("ePt#LT" , 10, xaxis='p_{Te} (GeV)', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-ePt-%s' % label) + # + #plotter.plot_final("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-tPt-%s' % label) + + #plotter.plot_final("mJetPt#LT" , 10, xaxis='p_{T Jet#mu} (GeV)', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-mJetPt-%s' % label) + # + #plotter.plot_final("eJetPt#LT" , 10, xaxis='p_{T Jet e} (GeV)', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-eJetPt-%s' % label) + + #eta + #plotter.plot_final("mAbsEta#LT", 10, xaxis='|#eta_{#mu}|', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-mAbsEta-%s' % label) + # + #plotter.plot_final("eAbsEta#LT", 10, xaxis='|#eta_{e}|' , maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-eAbsEta-%s' % label) + # + #plotter.plot_final("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-tAbsEta-%s' % label) + + #DR + #plotter.plot_final("m_t_DR#LT", 10, xaxis='#DeltaR_{#mu#tau}', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-m_t_DR-%s' % label) + # + #plotter.plot_final("e_t_DR#LT", 10, xaxis='#DeltaR_{e#tau}' , maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-e_t_DR-%s' % label) + + #Jet BTag + #plotter.plot_final("eJetBtag#LT", 2, xaxis='e Jet Btag' , maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-eJetBtag-%s' % label) + # + #plotter.plot_final("mJetBtag#LT", 2, xaxis='#mu Jet Btag' , maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-mJetBtag-%s' % label) + + + plotter.plot_final('LT', 5, xaxis='LT (GeV)', maxy=15) + plotter.add_cms_blurb(sqrts) + plotter.save('final-LT') + + if not options.no_f3: + ########################################################################### + ## F3 enhanced region plots ########################################### + ########################################################################### + plotter.set_subdir('f3') + + for label, proj_range in categories.iteritems(): + for tau_charge in ['tau_os', 'tau_ss']: + if tau_charge == 'tau_os': + plotter.set_subdir('f3/%s' % label) + else: + plotter.set_subdir('f3/%s_charge3' % label) + + plotter.plot_final_f3('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, + yaxis='Events / GeV', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s' % label) + + plotter.plot_final_f3('subMass#LT', binning_7TeV, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', differential=True, + yaxis='Events / GeV', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-7TeVBin-%s' % label) + + #plotter.plot_final_f3('subMass#LT', [20, 40, 120, 300], xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + # project=proj_range, project_axis='X', differential=True, + # yaxis='Events / GeV', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-subMass-widebin-%s' % label) + # + #plotter.plot_final_f3('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-subMass-%s-notDifferential' % label) + + #plotter.plot_final_f3("e_m_Mass#LT", 20, xaxis='m_{e#mu} (GeV)', maxy=None, project=proj_range, + # project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-e_m_Mass-%s' % label) + # + #plotter.plot_final_f3("m_t_Mass#LT", 20, xaxis='m_{#mu#tau} (GeV)', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-m_t_Mass-%s' % label) + # + #plotter.plot_final_f3("e_t_Mass#LT", 20, xaxis='m_{e#tau} (GeV)' , maxy=None, project=proj_range, + # project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-e_t_Mass-%s' % label) + + plotter.plot_final_f3('subMass#LT', 300, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, + project=proj_range, project_axis='X', tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) + + #pt + #plotter.plot_final_f3("mPt#LT" , 10, xaxis='p_{T#mu} (GeV)', maxy=None, project=proj_range, + # project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-mPt-%s' % label) + # + #plotter.plot_final_f3("ePt#LT" , 10, xaxis='p_{Te} (GeV)', maxy=None, project=proj_range, + # project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-ePt-%s' % label) + # + #plotter.plot_final_f3("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, project=proj_range, + # project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-tPt-%s' % label) + + #plotter.plot_final_f3("mJetPt#LT" , 10, xaxis='p_{T Jet#mu} (GeV)', maxy=None, project=proj_range, + # project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-mJetPt-%s' % label) + # + #plotter.plot_final_f3("eJetPt#LT" , 10, xaxis='p_{T Jet e} (GeV)', maxy=None, project=proj_range, + # project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-eJetPt-%s' % label) + + #eta + #plotter.plot_final_f3("mAbsEta#LT", 10, xaxis='|#eta_{#mu}|', maxy=None, project=proj_range, + # project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-mAbsEta-%s' % label) + # + #plotter.plot_final_f3("eAbsEta#LT", 10, xaxis='|#eta_{e}|' , maxy=None, project=proj_range, + # project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-eAbsEta-%s' % label) + # + #plotter.plot_final_f3("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, project=proj_range, + # project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-tAbsEta-%s' % label) + + #DR + #plotter.plot_final_f3("m_t_DR#LT", 10, xaxis='#DeltaR_{#mu#tau}', maxy=None, project=proj_range, + # project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-m_t_DR-%s' % label) + # + #plotter.plot_final_f3("e_t_DR#LT", 10, xaxis='#DeltaR_{e#tau}' , maxy=None, project=proj_range, + # project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-e_t_DR-%s' % label) + + #Jet BTag + #plotter.plot_final_f3("eJetBtag#LT", 2, xaxis='e Jet Btag' , maxy=None, project=proj_range, + # project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-eJetBtag-%s' % label) + # + #plotter.plot_final_f3("mJetBtag#LT", 2, xaxis='#mu Jet Btag' , maxy=None, project=proj_range, + # project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-mJetBtag-%s' % label) + + plotter.set_subdir('f3') + plotter.plot_final_f3('LT', 5, xaxis='LT (GeV)', show_error=True) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-LT') + #END OF if not options.dry_run: + if not options.no_shapes: ########################################################################### - ## Signal region plots ################################################ + ## Making shape file ################################################# ########################################################################### plotter.set_subdir('') - - for label, proj_range in categories.iteritems(): - for tau_charge in ['tau_os', 'tau_ss']: - if tau_charge == 'tau_os': - plotter.set_subdir('%s' % label) - else: - plotter.set_subdir('%s_charge3' % label) - - plotter.plot_final('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', differential=True, - yaxis='Events / GeV', show_error=True, tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-%s' % label) - - plotter.plot_final("e_m_Mass#LT", 20, xaxis='m_{e#mu} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e_m_Mass-%s' % label) - - plotter.plot_final("m_t_Mass#LT", 20, xaxis='m_{#mu#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m_t_Mass-%s' % label) - - plotter.plot_final("e_t_Mass#LT", 20, xaxis='m_{e#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e_t_Mass-%s' % label) - - plotter.plot_final('subMass#LT', 300, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge, - show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-%s-counting' % label, dotc=True, dotroot=True) - - #pt - plotter.plot_final("mPt#LT" , 10, xaxis='p_{T#mu} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-mPt-%s' % label) - - plotter.plot_final("ePt#LT" , 10, xaxis='p_{Te} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-ePt-%s' % label) - - plotter.plot_final("mJetPt#LT" , 10, xaxis='p_{T Jet#mu} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-mJetPt-%s' % label) - - plotter.plot_final("eJetPt#LT" , 10, xaxis='p_{T Jet e} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-eJetPt-%s' % label) - - plotter.plot_final("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-tPt-%s' % label) - - #eta - plotter.plot_final("mAbsEta#LT", 10, xaxis='|#eta_{#mu}|', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-mAbsEta-%s' % label) - - plotter.plot_final("eAbsEta#LT", 10, xaxis='|#eta_{e}|' , maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-eAbsEta-%s' % label) - - plotter.plot_final("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-tAbsEta-%s' % label) - - #DR - plotter.plot_final("m_t_DR#LT", 10, xaxis='#DeltaR_{#mu#tau}', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m_t_DR-%s' % label) - - plotter.plot_final("e_t_DR#LT", 10, xaxis='#DeltaR_{e#tau}' , maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e_t_DR-%s' % label) - - #Jet BTag - plotter.plot_final("eJetBtag#LT", 2, xaxis='e Jet Btag' , maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-eJetBtag-%s' % label) - - plotter.plot_final("mJetBtag#LT", 2, xaxis='#mu Jet Btag' , maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-mJetBtag-%s' % label) - - - plotter.plot_final('LT', 5, xaxis='LT (GeV)', maxy=15) - plotter.add_cms_blurb(sqrts) - plotter.save('final-LT') - - plotter.plot_final('tLeadDR', 10) - plotter.save('final-tLeadDR') - plotter.plot_final('tSubDR', 10) - plotter.save('final-tSubDR') - - ########################################################################### - ## F3 enhanced region plots ########################################### - ########################################################################### - plotter.set_subdir('f3') - - for label, proj_range in categories.iteritems(): - for tau_charge in ['tau_os', 'tau_ss']: - if tau_charge == 'tau_os': - plotter.set_subdir('f3/%s' % label) - else: - plotter.set_subdir('f3/%s_charge3' % label) - - plotter.plot_final_f3('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', differential=True, - yaxis='Events / GeV', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s' % label) - - plotter.plot_final_f3('subMass#LT', [20, 40, 120, 300], xaxis='m_{l_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', differential=True, - yaxis='Events / GeV', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-widebin-%s' % label) - - plotter.plot_final_f3('subMass#LT', rebin_slim, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s-notDifferential' % label) - - plotter.plot_final_f3("e_m_Mass#LT", 20, xaxis='m_{e#mu} (GeV)', maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e_m_Mass-%s' % label) - - plotter.plot_final_f3("m_t_Mass#LT", 20, xaxis='m_{#mu#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m_t_Mass-%s' % label) - - plotter.plot_final_f3("e_t_Mass#LT", 20, xaxis='m_{e#tau} (GeV)' , maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-e_t_Mass-%s' % label) - - plotter.plot_final_f3('subMass#LT', 300, xaxis='m_{l_{2}#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-%s-counting' % label, dotc=True, dotroot=True) - - #pt - plotter.plot_final_f3("mPt#LT" , 10, xaxis='p_{T#mu} (GeV)', maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-mPt-%s' % label) - - plotter.plot_final_f3("ePt#LT" , 10, xaxis='p_{Te} (GeV)', maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-ePt-%s' % label) - - plotter.plot_final_f3("mJetPt#LT" , 10, xaxis='p_{T Jet#mu} (GeV)', maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-mJetPt-%s' % label) - - plotter.plot_final_f3("eJetPt#LT" , 10, xaxis='p_{T Jet e} (GeV)', maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-eJetPt-%s' % label) - - plotter.plot_final_f3("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tPt-%s' % label) - - #eta - plotter.plot_final_f3("mAbsEta#LT", 10, xaxis='|#eta_{#mu}|', maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-mAbsEta-%s' % label) - - plotter.plot_final_f3("eAbsEta#LT", 10, xaxis='|#eta_{e}|' , maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-eAbsEta-%s' % label) - - plotter.plot_final_f3("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tAbsEta-%s' % label) - - #DR - plotter.plot_final_f3("m_t_DR#LT", 10, xaxis='#DeltaR_{#mu#tau}', maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m_t_DR-%s' % label) - - plotter.plot_final_f3("e_t_DR#LT", 10, xaxis='#DeltaR_{e#tau}' , maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-e_t_DR-%s' % label) - - #Jet BTag - plotter.plot_final_f3("eJetBtag#LT", 2, xaxis='e Jet Btag' , maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-eJetBtag-%s' % label) - - plotter.plot_final_f3("mJetBtag#LT", 2, xaxis='#mu Jet Btag' , maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-mJetBtag-%s' % label) - - plotter.set_subdir('f3') - plotter.plot_final_f3('LT', 5, xaxis='LT (GeV)', qcd_weight_fraction=0.5, show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-LT') - - plotter.plot_final_f3('subMass#LT', 20, xaxis='m_{l_{2}#tau_{#mu}} (GeV)', qcd_weight_fraction=0.5, show_error=True, project=[0, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass') - - plotter.plot_final_f3('subMass#LT', 300, xaxis='m_{l_{2}#tau_{#mu}} (GeV)', qcd_weight_fraction=0.5, show_error=True, project=[0, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subMass-counting-like', dotc=True, dotroot=True) - - plotter.plot_final_f3('subMass#LT', 20, xaxis='m_{l_{2}#tau_{#mu}} (GeV)', qcd_weight_fraction=1, show_error=True, project=[0, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-qcdfake-subMass') - - plotter.plot_final_f3('subMass#LT', 20, xaxis='m_{l_{2}#tau_{#mu}} (GeV)', qcd_weight_fraction=0, show_error=True, project=[0, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-wjetfake-subMass') - - plotter.plot_final_f3("eJetBtag#LT", 2, xaxis='e Jet Btag' , maxy=None, project=[0, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-eJetBtag') - - plotter.plot_final_f3("mJetBtag#LT", 2, xaxis='#mu Jet Btag' , maxy=None, project=[0, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-mJetBtag') - - plotter.plot_final_f3('mPt#LT', 10, xaxis='p_{T#mu} (GeV)', qcd_weight_fraction=0.5, show_error=True, project=[0, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-mPt') - - plotter.plot_final_f3('ePt#LT', 10, xaxis='p_{Te} (GeV)', qcd_weight_fraction=0.5, show_error=True, project=[0, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-ePt') - - plotter.plot_final_f3('tPt#LT', 10, xaxis='p_{T#tau} (GeV)', qcd_weight_fraction=0.5, show_error=True, project=[0, 650], project_axis='X') - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tPt') - - plotter.plot_final_f3('tSubDR', 10, xaxis='#DeltaR_{l_{2}#tau}', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tSubDR') - - plotter.plot_final_f3('tLeadDR', 10, xaxis='#DeltaR_{l_{1}#tau}', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tLeadDR') - - plotter.plot_final_f3('subPt', 10, xaxis='p_{Tl_{2}} (GeV)', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subPt') - - plotter.plot_final_f3('subJetPt', 10, xaxis='p_{TJetl_{2}} (GeV)', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-subJetPt') - - plotter.plot_final_f3('leadPt', 10, xaxis='p_{Tl_{1}} (GeV)', show_error=True) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-leadPt') - - plotter.plot_final_f3('eChargeIdTight', 1, xaxis='Charge ID Tight', maxy=None) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-eChargeIdTight') - - #END OF if not options.dry_run: - ########################################################################### - ## Making shape file ################################################# - ########################################################################### - plotter.set_subdir('') - prefixes = [options.prefix+'$'] if options.prefix else [''] - prefixes = [i+'$' for i in options.prefixes.split(',') if i] if options.prefixes else prefixes - for prefix in prefixes: - shape_prefix = prefix if len(prefixes) > 1 else '' - shape_prefix = shape_prefix.replace(':','_').replace('$','_') - - plotter.plot_final(prefix+'LT', 5, xaxis='LT (GeV)', qcd_weight_fraction=0.5) - plotter.add_cms_blurb(sqrts) - plotter.save('study-%s-LT-qweight05' % shape_prefix) - - #plotter.plot_final(prefix+'subMass', 20, xaxis='m_{#l_{2}#tau} (GeV)', qcd_weight_fraction=0.5) - #plotter.add_cms_blurb(sqrts) - #plotter.save('study-%s-subMass-qweight05' % shape_prefix) - - #plotter.plot_final_f3(prefix+'subMass', 20, xaxis='m_{l_{1}#tau_{#mu}} (GeV)', qcd_weight_fraction=0.5, show_error=True) - #plotter.add_cms_blurb(sqrts) - #plotter.save('study-%s-f3-qweight05-werror-subMass' % shape_prefix) - - shape_file = ROOT.TFile( - os.path.join(plotter.outputdir, 'LTCut_emt_shapes_%s.root' % ( plotter.period) ), 'RECREATE') - shape_dir = shape_file.mkdir('emtCatHigh') - plotter.write_shapes(prefix+'subMass#LT', 20, shape_dir, qcd_fraction=0.5, project=[80, 650], project_axis='X') - shape_dir = shape_file.mkdir('emtCatHigh_w') - plotter.write_shapes(prefix+'subMass#LT', 20, shape_dir, qcd_fraction=0.0, project=[80, 650], project_axis='X') - shape_dir = shape_file.mkdir('emtCatHigh_q') - plotter.write_shapes(prefix+'subMass#LT', 20, shape_dir, qcd_fraction=1.0, project=[80, 650], project_axis='X') - shape_file.Close() - - shape_file = ROOT.TFile( - os.path.join(plotter.outputdir, '%semt_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') - - shape_dir = shape_file.mkdir('emtCatLow') - plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0, 130], project_axis='X') - shape_dir = shape_file.mkdir('emtCatLow_w') - plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0, 130], project_axis='X') - shape_dir = shape_file.mkdir('emtCatLow_q') - plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0, 130], project_axis='X') - - shape_dir = shape_file.mkdir('emtCatHigh') - plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('emtCatHigh_w') - plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('emtCatHigh_q') - plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') - - logging.warning('shape file %s created' % shape_file.GetName()) - shape_file.Close() - - - shape_file = ROOT.TFile( - os.path.join(plotter.outputdir, '%semt_f3_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') - - shape_dir = shape_file.mkdir('emtCatLow') - plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('emtCatLow_w') - plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('emtCatLow_q') - plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') - - shape_dir = shape_file.mkdir('emtCatHigh') - plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('emtCatHigh_w') - plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('emtCatHigh_q') - plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') - - logging.warning('shape file %s created' % shape_file.GetName()) - shape_file.Close() - - shape_file = ROOT.TFile( - os.path.join(plotter.outputdir, '%semt_f3_all_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') - - shape_dir = shape_file.mkdir('emtCatLow') - plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('emtCatLow_w') - plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('emtCatLow_q') - plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') - - shape_dir = shape_file.mkdir('emtCatHigh') - plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('emtCatHigh_w') - plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('emtCatHigh_q') - plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') - - shape_dir = shape_file.mkdir('emtCatLowf3') - plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('emtCatLowf3_w') - plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('emtCatLowf3_q') - plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') - - shape_dir = shape_file.mkdir('emtCatHighf3') - plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('emtCatHighf3_w') - plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('emtCatHighf3_q') - plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') - - logging.warning('shape file %s created' % shape_file.GetName()) - shape_file.Close() + prefixes = [options.prefix+'$'] if options.prefix else [''] + prefixes = [i+'$' for i in options.prefixes.split(',') if i] if options.prefixes else prefixes + for prefix in prefixes: + shape_prefix = prefix if len(prefixes) > 1 else '' + shape_prefix = shape_prefix.replace(':','_').replace('$','_') + binning_7TeV = [0,40,80,120,200] + + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, 'LTAll_emt_shapes_%s.root' % ( plotter.period) ), 'RECREATE') + shape_dir = shape_file.mkdir('emt') + plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0., project=[0, 650], project_axis='X') + #shape_dir = shape_file.mkdir('emt_w') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0, 650], project_axis='X') + #shape_dir = shape_file.mkdir('emt_q') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() + + + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, 'LTCut_emt_shapes_%s.root' % ( plotter.period) ), 'RECREATE') + shape_dir = shape_file.mkdir('emt') + plotter.write_shapes(prefix+'subMass#LT', binning_7TeV, shape_dir, qcd_fraction=0., project=[80, 650], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatHigh_w') + #plotter.write_shapes(prefix+'subMass#LT', 20, shape_dir, qcd_fraction=0.0, project=[80, 650], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatHigh_q') + #plotter.write_shapes(prefix+'subMass#LT', 20, shape_dir, qcd_fraction=1.0, project=[80, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() + + + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, 'LTCut_emt_shapes_%s_different_fakes.root' % ( plotter.period) ), 'RECREATE') + shape_dir = shape_file.mkdir('emt') + plotter.write_shapes(prefix+'subMass#LT', binning_7TeV, shape_dir, qcd_fraction=0., project=[80, 650], project_axis='X', different_fakes=True) + #shape_dir = shape_file.mkdir('emtCatHigh_w') + #plotter.write_shapes(prefix+'subMass#LT', 20, shape_dir, qcd_fraction=0.0, project=[80, 650], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatHigh_q') + #plotter.write_shapes(prefix+'subMass#LT', 20, shape_dir, qcd_fraction=1.0, project=[80, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() + + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, '%semt_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') + + shape_dir = shape_file.mkdir('emtCatLow') + plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0., project=[0, 130], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatLow_w') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0, 130], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatLow_q') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0, 130], project_axis='X') + + shape_dir = shape_file.mkdir('emtCatHigh') + plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0., project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatHigh_w') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatHigh_q') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() + + + + shape_file = ROOT.TFile( + os.path.join(plotter.outputdir, '%semt_shapes_%s_different_fakes.root' % (shape_prefix, plotter.period) ), 'RECREATE') + + shape_dir = shape_file.mkdir('emtCatLow') + plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0., project=[0, 130], project_axis='X', different_fakes=True) + #shape_dir = shape_file.mkdir('emtCatLow_w') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0, 130], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatLow_q') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0, 130], project_axis='X') + + shape_dir = shape_file.mkdir('emtCatHigh') + plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0., project=[130, 650], project_axis='X', different_fakes=True) + #shape_dir = shape_file.mkdir('emtCatHigh_w') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatHigh_q') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + + logging.warning('shape file %s created' % shape_file.GetName()) + shape_file.Close() + + + #shape_file = ROOT.TFile( + # os.path.join(plotter.outputdir, '%semt_f3_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') + # + #shape_dir = shape_file.mkdir('emtCatLow') + #plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatLow_w') + #plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatLow_q') + #plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + # + #shape_dir = shape_file.mkdir('emtCatHigh') + #plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatHigh_w') + #plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatHigh_q') + #plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + # + #logging.warning('shape file %s created' % shape_file.GetName()) + #shape_file.Close() + # + #shape_file = ROOT.TFile( + # os.path.join(plotter.outputdir, '%semt_f3_all_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') + # + #shape_dir = shape_file.mkdir('emtCatLow') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatLow_w') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatLow_q') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + # + #shape_dir = shape_file.mkdir('emtCatHigh') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatHigh_w') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatHigh_q') + #plotter.write_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + # + #shape_dir = shape_file.mkdir('emtCatLowf3') + #plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatLowf3_w') + #plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatLowf3_q') + #plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + # + #shape_dir = shape_file.mkdir('emtCatHighf3') + #plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatHighf3_w') + #plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('emtCatHighf3_q') + #plotter.write_f3_shapes(prefix+'subMass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + # + #logging.warning('shape file %s created' % shape_file.GetName()) + #shape_file.Close() diff --git a/wh/WHPlotterMMT.py b/wh/WHPlotterMMT.py index fd7c4e4b..571a7d9d 100644 --- a/wh/WHPlotterMMT.py +++ b/wh/WHPlotterMMT.py @@ -17,12 +17,15 @@ from FinalStateAnalysis.MetaData.data_styles import data_styles, colors logging.basicConfig(stream=sys.stderr, level=logging.INFO) +ROOT.gStyle.SetOptTitle(0) +#ROOT.gROOT.SetStyle('Plain') class WHPlotterMMT(WHPlotterBase.WHPlotterBase): def __init__(self): super(WHPlotterMMT, self).__init__('MMT') -rebin_slim = range(20, 81, 10)+[100, 130, 300] +rebin_slim = range(20, 81, 10)+[100, 130, 200] +binning_7TeV = [0,40,80,120,200] categories = { 'LTCut' : [80, 650], 'Full' : [0, 650], @@ -132,23 +135,12 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-subMass-%s' % label) - plotter.plot_final('m2_t_Mass#LT', 20, xaxis='m_{#mu_{2}#tau} (GeV)', + plotter.plot_final('m2_t_Mass#LT', binning_7TeV, xaxis='m_{#mu_{2}#tau} (GeV)', project=proj_range, project_axis='X', yaxis='Events', show_error=True, x_range=[0,199], maxy=15.6, tau_charge=tau_charge) plotter.add_cms_blurb(sqrts) - plotter.save('final-subMass-const_bin-%s' % label, verbose=True) - - #data_view = plotter.make_signal_views(unblinded=(not plotter.blind), - # qcd_weight_fraction=0.5, - # rebin=20, project=proj_range, project_axis='X')['data'] - #data_hist = data_view.Get('m2_t_Mass#LT') - #data_hist.GetXaxis().SetRangeUser(0,200) - #data_hist.GetXaxis().SetRangeUser(0,15.6) - #data_hist.SetMarkerColor(2) - #data_hist.Draw() - #plotter.add_cms_blurb(sqrts) - #plotter.save('bareData-subMass-const_bin-%s' % label) + plotter.save('final-subMass-7TeVBin-%s' % label, verbose=True) plotter.plot_final('m2_t_Mass#LT', 300, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X', show_error=True, tau_charge=tau_charge) @@ -156,94 +148,100 @@ def __init__(self): plotter.save('final-subMass-%s-counting' % label, json=True) #, dotc=True, dotroot=True) #pt - plotter.plot_final("m1Pt#LT" , 10, xaxis='p_{T#mu_{1}} (GeV)', - maxy=None, project=proj_range, project_axis='X', - show_error=True, tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1Pt-%s' % label) - - plotter.plot_final("m2Pt#LT" , 10, xaxis='p_{T#mu_{2}} (GeV)', maxy=None, - project=proj_range, project_axis='X', - show_error=True, tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2Pt-%s' % label) - - plotter.plot_final("m1JetPt#LT" , 10, xaxis='p_{T Jet #mu_{1}} (GeV)', - maxy=None, project=proj_range, project_axis='X', - show_error=True, tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1JetPt-%s' % label) - - plotter.plot_final("m2JetPt#LT" , 10, xaxis='p_{T Jet #mu_{2}} (GeV)', - maxy=None, project=proj_range, project_axis='X', - show_error=True, tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2JetPt-%s' % label) + #plotter.plot_final("m1Pt#LT" , 10, xaxis='p_{T#mu_{1}} (GeV)', + # maxy=None, project=proj_range, project_axis='X', + # show_error=True, tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-m1Pt-%s' % label) + # + #plotter.plot_final("m2Pt#LT" , 10, xaxis='p_{T#mu_{2}} (GeV)', maxy=None, + # project=proj_range, project_axis='X', + # show_error=True, tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-m2Pt-%s' % label) + # + #plotter.plot_final("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, + # project=proj_range, project_axis='X', + # show_error=True, tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-tPt-%s' % label) - plotter.plot_final("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-tPt-%s' % label) + #plotter.plot_final("m1JetPt#LT" , 10, xaxis='p_{T Jet #mu_{1}} (GeV)', + # maxy=None, project=proj_range, project_axis='X', + # show_error=True, tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-m1JetPt-%s' % label) + # + #plotter.plot_final("m2JetPt#LT" , 10, xaxis='p_{T Jet #mu_{2}} (GeV)', + # maxy=None, project=proj_range, project_axis='X', + # show_error=True, tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-m2JetPt-%s' % label) + # + #plotter.plot_final("tPt#LT" , 10, xaxis='p_{T#tau} (GeV)', maxy=None, + # project=proj_range, project_axis='X', show_error=True, + # tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-tPt-%s' % label) #eta - plotter.plot_final("m1AbsEta#LT", 10, xaxis='|#eta_{#mu_{1}}|', maxy=None, - project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1AbsEta-%s' % label) - - plotter.plot_final("m2AbsEta#LT", 10, xaxis='|#eta_{#mu_{2}}|' , maxy=None, - project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2AbsEta-%s' % label) - - plotter.plot_final("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, - project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-tAbsEta-%s' % label) + #plotter.plot_final("m1AbsEta#LT", 10, xaxis='|#eta_{#mu_{1}}|', maxy=None, + # project=proj_range, project_axis='X', show_error=True, + # tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-m1AbsEta-%s' % label) + # + #plotter.plot_final("m2AbsEta#LT", 10, xaxis='|#eta_{#mu_{2}}|' , maxy=None, + # project=proj_range, project_axis='X', show_error=True, + # tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-m2AbsEta-%s' % label) + # + #plotter.plot_final("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, + # project=proj_range, project_axis='X', show_error=True, + # tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-tAbsEta-%s' % label) #DR - plotter.plot_final("m1_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{1}#tau}', maxy=None, - project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1_t_DR-%s' % label) - - plotter.plot_final("m2_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, - project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2_t_DR-%s' % label) + #plotter.plot_final("m1_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{1}#tau}', maxy=None, + # project=proj_range, project_axis='X', show_error=True, + # tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-m1_t_DR-%s' % label) + # + #plotter.plot_final("m2_t_DR#LT", 10, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, + # project=proj_range, project_axis='X', show_error=True, + # tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-m2_t_DR-%s' % label) #Jet BTag #from pdb import set_trace; set_trace() - plotter.plot_final("m2JetBtag#LT", [-100, -40, 20, 100], xaxis='#mu_{2} Jet Btag' , - maxy=None, project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2JetBtag-%s' % label, dotroot=True) - - plotter.plot_final("m1JetBtag#LT", 1, xaxis='#mu_{1} Jet Btag' , maxy=None, - project=proj_range, project_axis='X', show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1JetBtag-%s' % label) - - plotter.plot_final("m2JetCSVBtag#LT", 1, xaxis='#mu_{2} Jet CSV Btag' , maxy=None, - project=proj_range, project_axis='X', x_range=[0,1], show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m2JetCSVBtag-%s' % label, dotroot=True) - - plotter.plot_final("m1JetCSVBtag#LT", 1, xaxis='#mu_{1} Jet CSV Btag' , maxy=None, - project=proj_range, project_axis='X', x_range=[0,1], show_error=True, - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-m1JetCSVBtag-%s' % label) + #plotter.plot_final("m2JetBtag#LT", [-100, -40, 20, 100], xaxis='#mu_{2} Jet Btag' , + # maxy=None, project=proj_range, project_axis='X', show_error=True, + # tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-m2JetBtag-%s' % label, dotroot=True) + # + #plotter.plot_final("m1JetBtag#LT", 1, xaxis='#mu_{1} Jet Btag' , maxy=None, + # project=proj_range, project_axis='X', show_error=True, + # tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-m1JetBtag-%s' % label) + # + #plotter.plot_final("m2JetCSVBtag#LT", 1, xaxis='#mu_{2} Jet CSV Btag' , maxy=None, + # project=proj_range, project_axis='X', x_range=[0,1], show_error=True, + # tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-m2JetCSVBtag-%s' % label, dotroot=True) + # + #plotter.plot_final("m1JetCSVBtag#LT", 1, xaxis='#mu_{1} Jet CSV Btag' , maxy=None, + # project=proj_range, project_axis='X', x_range=[0,1], show_error=True, + # tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-m1JetCSVBtag-%s' % label) plotter.set_subdir('') plotter.plot_final('LT', 10, xaxis='LT (GeV)', maxy=15) @@ -255,12 +253,12 @@ def __init__(self): ## F3 enhanced region plots ########################################### ########################################################################### plotter.set_subdir('f3') - plotter.plot_final_f3('LT', [0, 50, 75, 100, 125, 150, 200, 300, 500], xaxis='LT (GeV)', maxy=None, - show_ratio=True, fit = { 'model' : ("slope*x + offset", "offset[0, -1, 1], slope[0,-1,1]"), - 'range' : [50, 500], 'options' : 'QIRMENS', - 'stat position' : 'bottom-left'}) - plotter.add_cms_blurb(sqrts) - plotter.save('final-LT-tauOS-chi2', verbose=True) + #plotter.plot_final_f3('LT', [0, 50, 75, 100, 125, 150, 200, 300, 500], xaxis='LT (GeV)', maxy=None, + # show_ratio=True, fit = { 'model' : ("slope*x + offset", "offset[0, -1, 1], slope[0,-1,1]"), + # 'range' : [50, 500], 'options' : 'QIRMENS', + # 'stat position' : 'bottom-left'}) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-LT-tauOS-chi2', verbose=True) plotter.plot_final_f3('LT', [0, 50, 75, 100, 125, 150, 200, 300, 500], xaxis='LT (GeV)', maxy=None, show_ratio=True, fit = { 'model' : ("slope*x + offset", "offset[0, -1, 1], slope[0,-1,1]"), @@ -273,11 +271,11 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-LT-tauOS-2categories') - plotter.plot_final_f3('LT', [0, 50, 75, 100, 125, 150, 200, 300, 500], xaxis='LT (GeV)', tau_charge='tau_ss', - maxy=None, show_ratio=True, - fit = {'range' : [50, 500], 'model' : ("slope*x + offset", "offset[0, -1, 1], slope[0,-1,1]")}) - plotter.add_cms_blurb(sqrts) - plotter.save('final-LT-tauSS') + #plotter.plot_final_f3('LT', [0, 50, 75, 100, 125, 150, 200, 300, 500], xaxis='LT (GeV)', tau_charge='tau_ss', + # maxy=None, show_ratio=True, + # fit = {'range' : [50, 500], 'model' : ("slope*x + offset", "offset[0, -1, 1], slope[0,-1,1]")}) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-LT-tauSS') plotter.plot_final_f3('LT', [0, 50, 130, 500], xaxis='LT (GeV)', tau_charge='tau_ss', maxy=None, show_ratio=True) plotter.add_cms_blurb(sqrts) @@ -296,6 +294,12 @@ def __init__(self): plotter.add_cms_blurb(sqrts) plotter.save('final-f3-subMass-%s' % label) + plotter.plot_final_f3('m2_t_Mass#LT', binning_7TeV, xaxis='m_{#mu_{2}#tau} (GeV)', + maxy=None, project=proj_range, project_axis='X', differential=True, + show_error=True, tau_charge=tau_charge) + plotter.add_cms_blurb(sqrts) + plotter.save('final-f3-subMass-7TeVBin-%s' % label) + plotter.plot_final_f3('m2_t_Mass#LT', 300, xaxis='m_{#mu_{2}#tau} (GeV)', maxy=None, project=proj_range, project_axis='X', tau_charge=tau_charge) @@ -303,114 +307,114 @@ def __init__(self): plotter.save('final-f3-subMass-%s-counting' % label, json=True, verbose=True) #pt - plotter.plot_final_f3("m1Pt#LT" , 10, xaxis='p_{T#mu_{1}} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1Pt-%s' % label) - - plotter.plot_final_f3("m2Pt#LT" , 10, xaxis='p_{T#mu_{2}} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2Pt-%s' % label) - - plotter.plot_final_f3("m1JetPt#LT" , 10, xaxis='p_{T Jet #mu_{1}} (GeV)', - maxy=None, project=proj_range, project_axis='X', - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1JetPt-%s' % label) - - plotter.plot_final_f3("m2JetPt#LT" , 10, xaxis='p_{T Jet #mu_{2}} (GeV)', - maxy=None, project=proj_range, project_axis='X', - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2JetPt-%s' % label) - - plotter.plot_final_f3("tPt#LT", 10, xaxis='p_{T#tau} (GeV)', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tPt-%s' % label) - - #eta - plotter.plot_final_f3("m1AbsEta#LT", 10, xaxis='|#eta_{#mu_{1}}|', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1AbsEta-%s' % label) - - plotter.plot_final_f3("m2AbsEta#LT", 10, xaxis='|#eta_{#mu_{2}}|', maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2AbsEta-%s' % label) - - plotter.plot_final_f3("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tAbsEta-%s' % label) + #plotter.plot_final_f3("m1Pt#LT" , 10, xaxis='p_{T#mu_{1}} (GeV)', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-m1Pt-%s' % label) + # + #plotter.plot_final_f3("m2Pt#LT" , 10, xaxis='p_{T#mu_{2}} (GeV)', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-m2Pt-%s' % label) + # + #plotter.plot_final_f3("tPt#LT", 10, xaxis='p_{T#tau} (GeV)', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-tPt-%s' % label) + # + ##plotter.plot_final_f3("m1JetPt#LT" , 10, xaxis='p_{T Jet #mu_{1}} (GeV)', + ## maxy=None, project=proj_range, project_axis='X', + ## tau_charge=tau_charge) + ##plotter.add_cms_blurb(sqrts) + ##plotter.save('final-f3-m1JetPt-%s' % label) + ## + ##plotter.plot_final_f3("m2JetPt#LT" , 10, xaxis='p_{T Jet #mu_{2}} (GeV)', + ## maxy=None, project=proj_range, project_axis='X', + ## tau_charge=tau_charge) + ##plotter.add_cms_blurb(sqrts) + ##plotter.save('final-f3-m2JetPt-%s' % label) + # + ##eta + #plotter.plot_final_f3("m1AbsEta#LT", 10, xaxis='|#eta_{#mu_{1}}|', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-m1AbsEta-%s' % label) + # + #plotter.plot_final_f3("m2AbsEta#LT", 10, xaxis='|#eta_{#mu_{2}}|', maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-m2AbsEta-%s' % label) + # + #plotter.plot_final_f3("tAbsEta#LT", 10, xaxis='|#eta_{#tau}|' , maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-tAbsEta-%s' % label) #DR - plotter.plot_final_f3("m1_t_DR#LT", 5, xaxis='#DeltaR_{#mu_{1}#tau}', - maxy=None, project=proj_range, project_axis='X', - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1_t_DR-%s' % label) - - plotter.plot_final_f3("m2_t_DR#LT", 5, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2_t_DR-%s' % label) + #plotter.plot_final_f3("m1_t_DR#LT", 5, xaxis='#DeltaR_{#mu_{1}#tau}', + # maxy=None, project=proj_range, project_axis='X', + # tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-m1_t_DR-%s' % label) + # + #plotter.plot_final_f3("m2_t_DR#LT", 5, xaxis='#DeltaR_{#mu_{2}#tau}' , maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-m2_t_DR-%s' % label) #Jet BTag #from pdb import set_trace; set_trace() - plotter.plot_final_f3("m2JetBtag#LT", [-100, -40, 20, 100], xaxis='#mu_{2} Jet Btag', - maxy=None, project=proj_range, project_axis='X', - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2JetBtag-%s' % label, dotroot=True) - - plotter.plot_final_f3("m1JetBtag#LT", 1, xaxis='#mu_{1} Jet Btag' , maxy=None, - project=proj_range, project_axis='X', tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1JetBtag-%s' % label) - - plotter.plot_final_f3("m2JetCSVBtag#LT", 1, xaxis='#mu_{2} Jet CSV Btag', maxy=None, - project=proj_range, project_axis='X', x_range=[0,1], - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m2JetCSVBtag-%s' % label, dotroot=True) - - plotter.plot_final_f3("m1JetCSVBtag#LT", 1, xaxis='#mu_{1} Jet CSV Btag', maxy=None, - project=proj_range, project_axis='X', x_range=[0,1], - tau_charge=tau_charge) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-m1JetCSVBtag-%s' % label) + #plotter.plot_final_f3("m2JetBtag#LT", [-100, -40, 20, 100], xaxis='#mu_{2} Jet Btag', + # maxy=None, project=proj_range, project_axis='X', + # tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-m2JetBtag-%s' % label, dotroot=True) + # + #plotter.plot_final_f3("m1JetBtag#LT", 1, xaxis='#mu_{1} Jet Btag' , maxy=None, + # project=proj_range, project_axis='X', tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-m1JetBtag-%s' % label) + # + #plotter.plot_final_f3("m2JetCSVBtag#LT", 1, xaxis='#mu_{2} Jet CSV Btag', maxy=None, + # project=proj_range, project_axis='X', x_range=[0,1], + # tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-m2JetCSVBtag-%s' % label, dotroot=True) + # + #plotter.plot_final_f3("m1JetCSVBtag#LT", 1, xaxis='#mu_{1} Jet CSV Btag', maxy=None, + # project=proj_range, project_axis='X', x_range=[0,1], + # tau_charge=tau_charge) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-m1JetCSVBtag-%s' % label) #TAU ISO - plotter.plot_final_f3("tRawIso3Hits#LT", [0,5,10,15,20,25,30,35,40,50,60,120,200], - xaxis='#tau 3Hits Raw Iso', maxy=None, - project=proj_range, project_axis='X', - tau_charge=tau_charge, show_ratio=True, - fit = { 'model' : ("slope*x + offset", "offset[0, -1, 1], slope[0,-1,1]"), - 'options' : 'WLQIRMENS', - 'stat position' : 'bottom-right'}) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tRawIso3Hits-Likelihood-%s' % label) - - plotter.plot_final_f3("tRawIso3Hits#LT", [0,5,10,15,20,25,30,35,40,50,60,120,200], - xaxis='#tau 3Hits Raw Iso', maxy=None, - project=proj_range, project_axis='X', - tau_charge=tau_charge, show_ratio=True, - fit = { 'model' : ("slope*x + offset", "offset[0, -1, 1], slope[0,-1,1]"), - 'options' : 'QIRMENS', - 'stat position' : 'bottom-right'}) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tRawIso3Hits-chi2-%s' % label) - - plotter.plot_final_f3("tRawIso3Hits#LT", [0,5,10,15,20,25,30,35,40,50,60,120,200], - xaxis='#tau 3Hits Raw Iso', maxy=None, project=proj_range, - project_axis='X', tau_charge=tau_charge, show_ratio=True, - wz_error=0., zz_error =0.) - plotter.add_cms_blurb(sqrts) - plotter.save('final-f3-tRawIso3Hits-noDibosonErr-%s' % label) + #plotter.plot_final_f3("tRawIso3Hits#LT", [0,5,10,15,20,25,30,35,40,50,60,120,200], + # xaxis='#tau 3Hits Raw Iso', maxy=None, + # project=proj_range, project_axis='X', + # tau_charge=tau_charge, show_ratio=True, + # fit = { 'model' : ("slope*x + offset", "offset[0, -1, 1], slope[0,-1,1]"), + # 'options' : 'WLQIRMENS', + # 'stat position' : 'bottom-right'}) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-tRawIso3Hits-Likelihood-%s' % label) + # + #plotter.plot_final_f3("tRawIso3Hits#LT", [0,5,10,15,20,25,30,35,40,50,60,120,200], + # xaxis='#tau 3Hits Raw Iso', maxy=None, + # project=proj_range, project_axis='X', + # tau_charge=tau_charge, show_ratio=True, + # fit = { 'model' : ("slope*x + offset", "offset[0, -1, 1], slope[0,-1,1]"), + # 'options' : 'QIRMENS', + # 'stat position' : 'bottom-right'}) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-tRawIso3Hits-chi2-%s' % label) + # + #plotter.plot_final_f3("tRawIso3Hits#LT", [0,5,10,15,20,25,30,35,40,50,60,120,200], + # xaxis='#tau 3Hits Raw Iso', maxy=None, project=proj_range, + # project_axis='X', tau_charge=tau_charge, show_ratio=True, + # wz_error=0., zz_error =0.) + #plotter.add_cms_blurb(sqrts) + #plotter.save('final-f3-tRawIso3Hits-noDibosonErr-%s' % label) #END OF if not options.dry_run: @@ -432,108 +436,107 @@ def __init__(self): shape_prefix = prefix if len(prefixes) > 1 else '' shape_prefix = shape_prefix.replace(':','_').replace('$','_') + binning_7TeV = [0,40,80,120,200] shape_file = ROOT.TFile( os.path.join(plotter.outputdir, 'LTCut_mmt_shapes_%s.root' % ( plotter.period) ), 'RECREATE') - shape_dir = shape_file.mkdir('mmtCatHigh') - plotter.write_shapes(prefix+'m2_t_Mass#LT', 20, shape_dir, qcd_fraction=0.5, project=[80, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_w') - plotter.write_shapes(prefix+'m2_t_Mass#LT', 20, shape_dir, qcd_fraction=0.0, project=[80, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_q') - plotter.write_shapes(prefix+'m2_t_Mass#LT', 20, shape_dir, qcd_fraction=1.0, project=[80, 650], project_axis='X') + shape_dir = shape_file.mkdir('mmt') + plotter.write_shapes(prefix+'m2_t_Mass#LT', binning_7TeV, shape_dir, qcd_fraction=0., project=[80, 650], project_axis='X') + #shape_dir = shape_file.mkdir('mmtCatHigh_w') + #plotter.write_shapes(prefix+'m2_t_Mass#LT', 20, shape_dir, qcd_fraction=-1., project=[80, 650], project_axis='X') + #shape_dir = shape_file.mkdir('mmtCatHigh_q') + #plotter.write_shapes(prefix+'m2_t_Mass#LT', 20, shape_dir, qcd_fraction=1.0, project=[80, 650], project_axis='X') logging.warning('shape file %s created' % shape_file.GetName()) - shape_file.Close() - - + shape_file.Close() + shape_file = ROOT.TFile( os.path.join(plotter.outputdir, 'LTAll_mmt_shapes_%s.root' % ( plotter.period) ), 'RECREATE') shape_dir = shape_file.mkdir('mmt') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmt_w') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmt_q') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0, 650], project_axis='X') - + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0., project=[0, 650], project_axis='X') + #shape_dir = shape_file.mkdir('mmt_w') + #plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=-1., project=[0, 650], project_axis='X') + #shape_dir = shape_file.mkdir('mmt_q') + #plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0, 650], project_axis='X') + logging.warning('shape file %s created' % shape_file.GetName()) shape_file.Close() - + #rebin_slim = range(20, 91, 10)+[110,200] shape_file = ROOT.TFile( os.path.join(plotter.outputdir, '%smmt_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') shape_dir = shape_file.mkdir('mmtCatLow') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLow_w') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLow_q') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0., project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('mmtCatLow_w') + #plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=-1., project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('mmtCatLow_q') + #plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') shape_dir = shape_file.mkdir('mmtCatHigh') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_w') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_q') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0., project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('mmtCatHigh_w') + #plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=-1., project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('mmtCatHigh_q') + #plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') logging.warning('shape file %s created' % shape_file.GetName()) shape_file.Close() - - shape_file = ROOT.TFile( - os.path.join(plotter.outputdir, '%smmt_f3_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') - - shape_dir = shape_file.mkdir('mmtCatLow') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLow_w') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLow_q') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') - - shape_dir = shape_file.mkdir('mmtCatHigh') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_w') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_q') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') - - logging.warning('shape file %s created' % shape_file.GetName()) - shape_file.Close() - - shape_file = ROOT.TFile( - os.path.join(plotter.outputdir, '%smmt_f3_all_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') - - shape_dir = shape_file.mkdir('mmtCatLow') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLow_w') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLow_q') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') - - shape_dir = shape_file.mkdir('mmtCatHigh') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_w') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHigh_q') - plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') - - shape_dir = shape_file.mkdir('mmtCatLowf3') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLowf3_w') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatLowf3_q') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') - - shape_dir = shape_file.mkdir('mmtCatHighf3') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.5, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHighf3_w') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') - shape_dir = shape_file.mkdir('mmtCatHighf3_q') - plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') - - logging.warning('shape file %s created' % shape_file.GetName()) - shape_file.Close() + #shape_file = ROOT.TFile( + # os.path.join(plotter.outputdir, '%smmt_f3_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') + # + #shape_dir = shape_file.mkdir('mmtCatLow') + #plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + ##shape_dir = shape_file.mkdir('mmtCatLow_w') + ##plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=-1., project=[0., 130], project_axis='X') + ##shape_dir = shape_file.mkdir('mmtCatLow_q') + ##plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + # + #shape_dir = shape_file.mkdir('mmtCatHigh') + #plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + ##shape_dir = shape_file.mkdir('mmtCatHigh_w') + ##plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=-1., project=[130, 650], project_axis='X') + ##shape_dir = shape_file.mkdir('mmtCatHigh_q') + ##plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + # + #logging.warning('shape file %s created' % shape_file.GetName()) + #shape_file.Close() + # + #shape_file = ROOT.TFile( + # os.path.join(plotter.outputdir, '%smmt_f3_all_shapes_%s.root' % (shape_prefix, plotter.period) ), 'RECREATE') + # + #shape_dir = shape_file.mkdir('mmtCatLow') + #plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('mmtCatLow_w') + #plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=-1., project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('mmtCatLow_q') + #plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + # + #shape_dir = shape_file.mkdir('mmtCatHigh') + #plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('mmtCatHigh_w') + #plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=-1., project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('mmtCatHigh_q') + #plotter.write_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + # + #shape_dir = shape_file.mkdir('mmtCatLowf3') + #plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('mmtCatLowf3_w') + #plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=-1., project=[0., 130], project_axis='X') + #shape_dir = shape_file.mkdir('mmtCatLowf3_q') + #plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[0., 130], project_axis='X') + # + #shape_dir = shape_file.mkdir('mmtCatHighf3') + #plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=0.0, project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('mmtCatHighf3_w') + #plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=-1., project=[130, 650], project_axis='X') + #shape_dir = shape_file.mkdir('mmtCatHighf3_q') + #plotter.write_f3_shapes(prefix+'m2_t_Mass#LT', rebin_slim, shape_dir, qcd_fraction=1.0, project=[130, 650], project_axis='X') + # + #logging.warning('shape file %s created' % shape_file.GetName()) + #shape_file.Close() From 5cfebd1f3729e6217e7676c26d6f497fdd9d15cf Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Dec 2013 05:07:17 -0600 Subject: [PATCH 095/192] added bug tracking tools, changed WJets MT threshold --- wh/baseSelections.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/wh/baseSelections.py b/wh/baseSelections.py index 6f485474..fac2065f 100755 --- a/wh/baseSelections.py +++ b/wh/baseSelections.py @@ -11,12 +11,22 @@ def splitEid(label): return label.split('_')[-1], label.split('_')[0] #OBJECT SELECTION -def muSelection(row, name): +def muSelection(row, name, tracker=None): if getattr( row, getVar(name,'Pt')) < 10: return False + if tracker: tracker.Fill('muon Pt') + if getattr( row, getVar(name,'AbsEta')) > 2.4: return False + if tracker: tracker.Fill('muon AbsEta') + if not getattr( row, getVar(name,'PixHits')): return False + if tracker: tracker.Fill('muon PixHits') + if getattr( row, getVar(name,'JetCSVBtag')) > 0.8: return False + if tracker: tracker.Fill('muon JetCSVBtag') + if abs(getattr( row, getVar(name,'DZ'))) > 0.2: return False + if tracker: tracker.Fill('muon DZ') + return True def eSelection(row, name): @@ -33,16 +43,21 @@ def tauSelection(row, name): if getattr( row, getVar(name,'Pt')) < 20: return False if getattr( row, getVar(name,'AbsEta')) > 2.3: return False if abs(getattr( row, getVar(name,'DZ'))) > 0.2: return False + if getattr( row, + getVar( name, + 'ElectronPt10IdIsoVtxOverlap') + ): return False return True #VETOS -def vetos(row, tracker=None): +def vetos(row, tracker=None, bveto=True): if row.muVetoPt5IsoIdVtx: return False if tracker: tracker.Fill('muon veto') - if row.bjetCSVVetoZHLike: return False - if tracker: tracker.Fill('bjet veto') + if bveto: + if row.bjetCSVVetoZHLike: return False + if tracker: tracker.Fill('bjet veto') if row.eVetoMVAIsoVtx: return False if tracker: tracker.Fill('electron veto') @@ -72,8 +87,8 @@ def lepton_id_iso(row, name, label): #label in the format eidtype_isotype def control_region_ee(row): '''Figure out what control region we are in. Shared among two codes, to avoid mismatching copied here''' - if row.e1_e2_SS and lepton_id_iso(row, 'e1', 'eid12Medium_h2taucuts') and row.e1MtToMET > 30: - return 'wjets' + if row.e1_e2_SS and lepton_id_iso(row, 'e1', 'eid12Medium_h2taucuts') and row.e1MtToMET > 35: + return 'wjetsLtLow' elif row.e1_e2_SS and row.e1RelPFIsoDB > 0.3 and row.type1_pfMetEt < 25: #and row.metSignificance < 3: # return 'qcd' elif lepton_id_iso(row,'e1', 'eid12Medium_h2taucuts') and lepton_id_iso(row,'e2', 'eid12Medium_h2taucuts') \ From 5643ac3a29fd337297ed9fd97137865f15810200 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Dec 2013 05:08:17 -0600 Subject: [PATCH 096/192] new diboson sunbtraction plus some fancy stuff to avoid crashes in case of patial analyses --- wh/fakerate_functions.py | 267 ++++++++++++++++++++++++++++++++------- 1 file changed, 224 insertions(+), 43 deletions(-) diff --git a/wh/fakerate_functions.py b/wh/fakerate_functions.py index 6505b944..2728b37a 100755 --- a/wh/fakerate_functions.py +++ b/wh/fakerate_functions.py @@ -1,10 +1,14 @@ import os -from FinalStateAnalysis.StatTools.RooFunctorFromWS import build_roofunctor, make_corrector_from_th2, build_uncorr_2Droofunctor, FunctorFromMVA +from FinalStateAnalysis.StatTools.RooFunctorFromWS import build_roofunctor, make_corrector_from_th2,\ + build_uncorr_2Droofunctor, FunctorFromMVA, MultiFunctorFromMVA, MultiFunctorFromTF1 from FinalStateAnalysis.StatTools.VariableScaler import make_scaler from FinalStateAnalysis.Utilities.smartdict import SmartDict +from FinalStateAnalysis.MetaData.data_views import read_lumi import itertools import optimizer import re +import glob +from fnmatch import fnmatch #from optimizer import leading_lepton_iso_tag, subleading_lepton_iso_tag ################################################################################ @@ -12,7 +16,27 @@ ################################################################################ # Get fitted fake rate functions -frfit_dir = os.path.join('results', os.environ['jobid'], 'fakerate_fits') +frfit_dir = os.path.join('results', os.environ['jobid'], 'fakerate_fits')+'/' +is7TeV = '7TeV' in os.environ['jobid'] + +def get_lumis(pattern): + lumi_files = glob.glob( os.path.join('inputs', os.environ['jobid'], '*.lumicalc.sum') ) + ret = 0. + #print pattern + for lumi_file in lumi_files: + sample_name = os.path.basename(lumi_file).split('.')[0] + #print lumi_file, sample_name + if fnmatch(sample_name, pattern): + #print 'Matches!' + ret += read_lumi(lumi_file) + return ret + +double_e_lumi = get_lumis('data_DoubleElectron*') +double_mu_lumi = get_lumis('data_DoubleMu*') +mueg_lumi = get_lumis('data_MuEG*') +wz_lumi = get_lumis('WZ*ZToTauTau*') +zz_lumi = get_lumis('ZZ*') + def make_simple_mapper(tomap): def f_(string): @@ -77,10 +101,10 @@ def make_corrector_dict(filename, mapname, mapper=None): ret[i] = make_corrector_from_th2(filename % lepid, mapname) return ret -def make_scaler_dict(filename, mapname): +def make_scaler_dict(filename, mapname, **kwargs): ret = {} for i in optimizer.lep_id: - ret[i] = make_scaler(filename % i, 'mass_scale') + ret[i] = make_scaler(filename % i, 'mass_scale', **kwargs) return ret def make_mva_functor_dict(template, variables, mapper=None): @@ -108,63 +132,220 @@ def make_null_dict(template, variables, mapper=None): ret[i] = null return ret +SKIP_MMT=eval( os.environ.get('SKIP_MMT','False') ) +SKIP_EMT=eval( os.environ.get('SKIP_EMT','False') ) +SKIP_EET=eval( os.environ.get('SKIP_EET','False') ) + +################### +## MMT FUNCTIONS ## +################### + +wz_sample = 'WZJetsTo3LNu_ZToTauTau_pythia' if '8TeV' in os.environ['jobid'] else 'WZJetsTo3LNu_ZToTauTau' + +if not SKIP_MMT: + #no changes in muonID in 2013 + mapper = {'eid1[0-9][A-Z][a-z]+_':'', 'idiso02' : 'pfidiso02'} + variables = ['muonJetPt', 'muonPt', 'numJets20'] #, 'muonJetCSVBtag'] + lowpt_mu_fr = SmartDict() + lowpt_mu_fr.book( 'eid12Medium_h2taucuts020', + MultiFunctorFromMVA, + 'lowpt_mu_fr', + (frfit_dir + 'mm_wjets_pt10_h2taucuts020_muonInfo_k50.data.kNN.weights.xml', double_mu_lumi), + [ (frfit_dir + 'mm_wjets_pt10_h2taucuts020_muonInfo_k50.%s.kNN.weights.xml' % wz_sample, wz_lumi), + (frfit_dir + 'mm_wjets_pt10_h2taucuts020_muonInfo_k50.ZZJetsTo4L_pythia.kNN.weights.xml', zz_lumi)], + *variables) + + highpt_mu_fr = SmartDict() + highpt_mu_fr.book( 'eid12Medium_h2taucuts', + MultiFunctorFromMVA, + 'highpt_mu_fr', + (frfit_dir + 'mm_wjets_pt10_h2taucuts_muonInfo_k50.data.kNN.weights.xml', double_mu_lumi), + [ (frfit_dir + 'mm_wjets_pt10_h2taucuts_muonInfo_k50.%s.kNN.weights.xml' % wz_sample, wz_lumi), + (frfit_dir + 'mm_wjets_pt10_h2taucuts_muonInfo_k50.ZZJetsTo4L_pythia.kNN.weights.xml', zz_lumi)], + *variables, + phase_space='muonPt > 20' + ) + + lowpt_mu_qcd_fr = SmartDict() + lowpt_mu_qcd_fr.book( 'eid12Medium_h2taucuts020', + FunctorFromMVA, + 'lowpt_mu_qcd_fr', + frfit_dir + 'mm_qcd_pt10_h2taucuts020_muonInfo_k50.data.kNN.weights.xml', + *variables) + + highpt_mu_qcd_fr = SmartDict() + highpt_mu_qcd_fr.book( 'eid12Medium_h2taucuts', + FunctorFromMVA, + 'highpt_mu_qcd_fr', + frfit_dir + 'mm_qcd_pt10_h2taucuts_muonInfo_k50.data.kNN.weights.xml', + *variables) + -################## -## 1D Muon Func ## -################## -#no changes in muonID in 2013 -mapper = {'eid1[0-9][A-Z][a-z]+_':'', 'idiso02' : 'pfidiso02'} -variables = ['muonJetPt', 'muonPt', 'numJets20'] #, 'muonJetCSVBtag'] -lowpt_mu_fr = make_mva_functor_dict(frfit_dir + '/mm_wjets_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) -highpt_mu_fr = lowpt_mu_fr + #lowpt_mu_fr = make_mva_functor_dict(frfit_dir + '/mm_wjets_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) + #highpt_mu_fr = lowpt_mu_fr + # + #lowpt_mu_qcd_fr = make_mva_functor_dict(frfit_dir + '/mm_qcd_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) + #highpt_mu_qcd_fr = lowpt_mu_qcd_fr + +################### +## EMT FUNCTIONS ## +################### + +if not SKIP_EMT: + variables = ['muonJetPt', 'muonPt', 'numJets20'] + + lowpt_mue_fr = SmartDict() + lowpt_mue_fr.book( 'eid12Medium_h2taucuts', + MultiFunctorFromMVA, + 'lowpt_mue_fr', + (frfit_dir + 'em_Mwjets_pt10_h2taucuts_muonInfo_k50.data.kNN.weights.xml', mueg_lumi), + [ (frfit_dir + 'em_Mwjets_pt10_h2taucuts_muonInfo_k50.%s.kNN.weights.xml' % wz_sample, wz_lumi), + (frfit_dir + 'em_Mwjets_pt10_h2taucuts_muonInfo_k50.ZZJetsTo4L_pythia.kNN.weights.xml', zz_lumi)], + *variables) + + highpt_mue_fr = SmartDict() + highpt_mue_fr.book( 'eid12Medium_h2taucuts', + MultiFunctorFromMVA, + 'lowpt_mue_fr', + (frfit_dir + 'em_Mwjets_pt10_h2taucuts_muonInfo_k50.data.kNN.weights.xml', mueg_lumi), + [ (frfit_dir + 'em_Mwjets_pt10_h2taucuts_muonInfo_k50.%s.kNN.weights.xml' % wz_sample, wz_lumi), + (frfit_dir + 'em_Mwjets_pt10_h2taucuts_muonInfo_k50.ZZJetsTo4L_pythia.kNN.weights.xml', zz_lumi)], + *variables, + phase_space='muonPt > 20' + ) -lowpt_mu_qcd_fr = make_mva_functor_dict(frfit_dir + '/mm_qcd_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) -highpt_mu_qcd_fr = lowpt_mu_qcd_fr -variables = ['muonJetPt', 'muonPt', 'numJets20'] -lowpt_mue_fr = make_mva_functor_dict(frfit_dir + '/em_Mwjets_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) -highpt_mue_fr = lowpt_mue_fr + lowpt_mue_qcd_fr = SmartDict() + lowpt_mue_qcd_fr.book( 'eid12Medium_h2taucuts', + FunctorFromMVA, + 'lowpt_mue_qcd_fr', + frfit_dir + 'em_Mqcd_pt10_h2taucuts_muonInfo_k50.data.kNN.weights.xml', + *variables ) + highpt_mue_qcd_fr = lowpt_mue_qcd_fr -lowpt_mue_qcd_fr = make_mva_functor_dict(frfit_dir + '/em_Mqcd_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) -highpt_mue_qcd_fr = lowpt_mue_qcd_fr + variables = ['electronJetPt', 'electronPt', 'numJets20'] + lowpt_e_fr = SmartDict() + lowpt_e_fr.book( 'eid12Medium_h2taucuts', + MultiFunctorFromMVA, + 'lowpt_e_fr', + (frfit_dir + 'em_wjets_pt10_eid12Medium_h2taucuts_electronInfo_k50.data.kNN.weights.xml', mueg_lumi), + [ (frfit_dir + 'em_wjets_pt10_eid12Medium_h2taucuts_electronInfo_k50.%s.kNN.weights.xml' % wz_sample, wz_lumi), + (frfit_dir + 'em_wjets_pt10_eid12Medium_h2taucuts_electronInfo_k50.ZZJetsTo4L_pythia.kNN.weights.xml', zz_lumi)], + *variables) + + highpt_e_fr = SmartDict() + highpt_e_fr.book( 'eid12Medium_h2taucuts', + MultiFunctorFromMVA, + 'lowpt_e_fr', + (frfit_dir + 'em_wjets_pt10_eid12Medium_h2taucuts_electronInfo_k50.data.kNN.weights.xml', mueg_lumi), + [ (frfit_dir + 'em_wjets_pt10_eid12Medium_h2taucuts_electronInfo_k50.%s.kNN.weights.xml' % wz_sample, wz_lumi), + (frfit_dir + 'em_wjets_pt10_eid12Medium_h2taucuts_electronInfo_k50.ZZJetsTo4L_pythia.kNN.weights.xml', zz_lumi)], + *variables, + phase_space='electronPt > 20' + ) + + lowpt_e_qcd_fr = SmartDict() + lowpt_e_qcd_fr.book( 'eid12Medium_h2taucuts', + FunctorFromMVA, + 'lowpt_e_qcd_fr', + frfit_dir + 'em_qcd_pt10_eid12Medium_h2taucuts_electronInfo_k50.data.kNN.weights.xml', + *variables ) + highpt_e_qcd_fr = lowpt_e_qcd_fr + + + #lowpt_mue_fr = make_mva_functor_dict(frfit_dir + '/em_Mwjets_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) + #highpt_mue_fr = lowpt_mue_fr + # + #lowpt_mue_qcd_fr = make_mva_functor_dict(frfit_dir + '/em_Mqcd_pt10_%s_muonInfo_k100.kNN.weights.xml', variables, mapper=make_regex_mapper(mapper)) + #highpt_mue_qcd_fr = lowpt_mue_qcd_fr + # + #variables = ['electronJetPt', 'electronPt', 'numJets20'] + #lowpt_e_fr = make_mva_functor_dict(frfit_dir + '/em_wjets_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) + #highpt_e_fr = lowpt_e_fr + # + #lowpt_e_qcd_fr = make_mva_functor_dict(frfit_dir + '/em_qcd_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) + #highpt_e_qcd_fr = lowpt_e_qcd_fr -####################### -## 1D Electrons Func ## -####################### -variables = ['electronJetPt', 'electronPt', 'numJets20'] -#EMT -lowpt_e_fr = make_mva_functor_dict(frfit_dir + '/em_wjets_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) -highpt_e_fr = lowpt_e_fr +################### +## EET FUNCTIONS ## +################### -lowpt_e_qcd_fr = make_mva_functor_dict(frfit_dir + '/em_qcd_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) -highpt_e_qcd_fr = lowpt_e_qcd_fr +if not SKIP_EET: + variables = ['electronJetPt', 'electronPt', 'numJets20'] + lowpt_ee_fr = SmartDict() + lowpt_ee_fr.book( 'eid12Medium_h2taucuts020', + MultiFunctorFromMVA, + 'lowpt_ee_fr', + (frfit_dir + 'ee_wjetsNoZmass_pt10_eid12Medium_h2taucuts020_electronInfo_k50.data.kNN.weights.xml', double_e_lumi), + [ (frfit_dir + 'ee_wjetsNoZmass_pt10_eid12Medium_h2taucuts020_electronInfo_k50.%s.kNN.weights.xml' % wz_sample, wz_lumi), + (frfit_dir + 'ee_wjetsNoZmass_pt10_eid12Medium_h2taucuts020_electronInfo_k50.ZZJetsTo4L_pythia.kNN.weights.xml', zz_lumi)], + *variables) + + highpt_ee_fr = SmartDict() + highpt_ee_fr.book( 'eid12Tight_h2taucuts', + MultiFunctorFromMVA, + 'highpt_ee_fr', + (frfit_dir + 'ee_wjetsNoZmass_pt10_eid12Tight_h2taucuts_electronInfo_k50.data.kNN.weights.xml', double_e_lumi), + [ (frfit_dir + 'ee_wjetsNoZmass_pt10_eid12Tight_h2taucuts_electronInfo_k50.%s.kNN.weights.xml' % wz_sample, wz_lumi), + (frfit_dir + 'ee_wjetsNoZmass_pt10_eid12Tight_h2taucuts_electronInfo_k50.ZZJetsTo4L_pythia.kNN.weights.xml', zz_lumi)], + *variables, + phase_space='electronPt > 20' + ) -#EET -variables = ['electronJetPt', 'electronPt', 'numJets20'] -lowpt_ee_fr = make_mva_functor_dict(frfit_dir + '/ee_wjetsNoZmass_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) -highpt_ee_fr = lowpt_ee_fr -lowpt_ee_qcd_fr = make_mva_functor_dict(frfit_dir + '/ee_qcd_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) -highpt_ee_qcd_fr = lowpt_ee_qcd_fr + lowpt_ee_qcd_fr = SmartDict() + lowpt_ee_qcd_fr.book( 'eid12Medium_h2taucuts020', + FunctorFromMVA, + 'lowpt_ee_qcd_fr', + frfit_dir + 'ee_qcd_pt10_eid12Medium_h2taucuts020_electronInfo_k50.data.kNN.weights.xml', + *variables) + + highpt_ee_qcd_fr = SmartDict() + highpt_ee_qcd_fr.book( 'eid12Tight_h2taucuts', + FunctorFromMVA, + 'highpt_ee_qcd_fr', + frfit_dir + 'ee_qcd_pt10_eid12Tight_h2taucuts_electronInfo_k50.data.kNN.weights.xml', + *variables) + + + + + #lowpt_ee_fr = make_mva_functor_dict(frfit_dir + '/ee_wjetsNoZmass_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) + #highpt_ee_fr = lowpt_ee_fr + # + #lowpt_ee_qcd_fr = make_mva_functor_dict(frfit_dir + '/ee_qcd_pt10_%s_electronInfo_k100.kNN.weights.xml', variables) + #highpt_ee_qcd_fr = lowpt_ee_qcd_fr ################## ## 1D Taus Func ## ################## -tau_fr = build_roofunctor( - frfit_dir + '/t_ztt_pt20_mvaloose_tauPt.root', - 'fit_efficiency', # workspace name - 'efficiency' +filename = '2011.root' if is7TeV else '2012.root' +date = '2011' if is7TeV else '2012' +tau_fr = MultiFunctorFromTF1( + 'external/%s' % filename, + [('%s_wmuJetsAll_electronLooseMVA3_muonTight_lepTauOS_fakeable_combinedIsolationLoose3Hits_byEta_projX_barrel/landau' % date, [-1, 0.8]), + ('%s_wmuJetsAll_electronLooseMVA3_muonTight_lepTauOS_fakeable_combinedIsolationLoose3Hits_byEta_projX_transition/landau' % date, [0.8, 1.6]), + ('%s_wmuJetsAll_electronLooseMVA3_muonTight_lepTauOS_fakeable_combinedIsolationLoose3Hits_byEta_projX_forward/landau' % date, [1.6, 100])] ) tau_qcd_fr = tau_fr -e_charge_flip = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_%s.root", "efficiency_map") -e_charge_flip_up = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_%s.root", "efficiency_map_statUp") -e_charge_flip_down = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_%s.root", "efficiency_map_statDown") -mass_scaler = make_scaler_dict(frfit_dir+"/charge_flip_prob_map_%s.root", 'mass_scale') -default_scaler = mass_scaler[mass_scaler.keys()[0]] +############################ +## CHARGE FLIP FUNCTIONS ## +############################ + +if not (SKIP_EMT or SKIP_EET): + e_charge_flip = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_%s.root", "efficiency_map") + e_charge_flip_up = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_%s.root", "efficiency_map_statUp") + e_charge_flip_down = make_corrector_dict(frfit_dir+"/charge_flip_prob_map_%s.root", "efficiency_map_statDown") + mass_scaler = make_scaler_dict(frfit_dir+"/charge_flip_prob_map_%s.root", 'mass_scale') + mass_scaler_up = make_scaler_dict(frfit_dir+"/charge_flip_prob_map_%s.root", 'mass_scale', error_scale=1 ) + mass_scaler_down = make_scaler_dict(frfit_dir+"/charge_flip_prob_map_%s.root", 'mass_scale', error_scale=-1) + default_scaler = mass_scaler[ mass_scaler.keys()[0]] + default_scaler_up = mass_scaler_up[ mass_scaler.keys()[0]] + default_scaler_down = mass_scaler_down[mass_scaler.keys()[0]] From e8c2e4648150e24d86f4bf214669fca02364b15b Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Dec 2013 05:09:01 -0600 Subject: [PATCH 097/192] compliant to new fake rate prescriptions --- wh/plots_for_prepp_kNN.py | 104 +++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/wh/plots_for_prepp_kNN.py b/wh/plots_for_prepp_kNN.py index c4660c53..b7d44d8f 100644 --- a/wh/plots_for_prepp_kNN.py +++ b/wh/plots_for_prepp_kNN.py @@ -1,6 +1,6 @@ +from rootpy.utils import asrootpy from FinalStateAnalysis.Utilities.rootbindings import ROOT import os -from rootpy.utils import asrootpy from FinalStateAnalysis.PlotTools.RebinView import RebinView import rootpy.plotting as plotting import logging @@ -50,38 +50,38 @@ def round_to_ints(histo): ##MMT 'm_mmt_subleading_kNN' : { 'vars' : {'muonPt':rebinPt, 'muonJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/m_wjets_pt10_h2taucuts020_muonInfo_k100.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/m_qcd_pt10_h2taucuts020_muonInfo_k100.kNN.root' % jobid, + 'wjets' : 'results/%s/fakerate_fits/mm_wjets_pt10_h2taucuts020_muonInfo_k50.data.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/mm_qcd_pt10_h2taucuts020_muonInfo_k50.data.kNN.root' % jobid, }, 'm_mmt_leading_kNN' : { 'vars' : {'muonPt':rebinPt, 'muonJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/m_wjets_pt10_h2taucuts_muonInfo_k100.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/m_qcd_pt10_h2taucuts_muonInfo_k100.kNN.root' % jobid, + 'wjets' : 'results/%s/fakerate_fits/mm_wjets_pt10_h2taucuts_muonInfo_k50.data.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/mm_qcd_pt10_h2taucuts_muonInfo_k50.data.kNN.root' % jobid, }, #EMT 'm_emt_kNN' : { 'vars' : {'muonPt':rebinPt, 'muonJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/m_Mwjets_pt10_h2taucuts_muonInfo_k100.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/m_Mqcd_pt10_h2taucuts_muonInfo_k100.kNN.root' % jobid, + 'wjets' : 'results/%s/fakerate_fits/em_Mwjets_pt10_h2taucuts_muonInfo_k50.data.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/em_Mqcd_pt10_h2taucuts_muonInfo_k50.data.kNN.root' % jobid, }, 'e_emt_kNN' : { 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/e_wjets_pt10_eid12Medium_h2taucuts_electronInfo_k100.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/e_qcd_pt10_eid12Medium_h2taucuts_electronInfo_k100.kNN.root' % jobid, + 'wjets' : 'results/%s/fakerate_fits/em_wjets_pt10_eid12Medium_h2taucuts_electronInfo_k50.data.kNN.root' % jobid, + 'qcd' : 'results/%s/fakerate_fits/em_qcd_pt10_eid12Medium_h2taucuts_electronInfo_k50.data.kNN.root' % jobid, }, #EET - 'e_eet_subleading_kNN' : { - 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/ee_wjetsNoZmass_pt10_eid12Medium_h2taucuts020_electronInfo_k100.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/ee_qcd_pt10_eid12Medium_h2taucuts020_electronInfo_k100.kNN.root' % jobid, - }, - 'e_eet_leading_kNN' : { - 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, - 'wjets' : 'results/%s/fakerate_fits/ee_wjetsNoZmass_pt10_eid12Tight_h2taucuts_electronInfo_k100.kNN.root' % jobid, - 'qcd' : 'results/%s/fakerate_fits/ee_qcd_pt10_eid12Tight_h2taucuts_electronInfo_k100.kNN.root' % jobid, - }, + #'e_eet_subleading_kNN' : { + # 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, + # 'wjets' : 'results/%s/fakerate_fits/ee_wjetsNoZmass_pt10_eid12Medium_h2taucuts020_electronInfo_k50.kNN.root' % jobid, + # 'qcd' : 'results/%s/fakerate_fits/ee_qcd_pt10_eid12Medium_h2taucuts020_electronInfo_k50.kNN.root' % jobid, + # }, + #'e_eet_leading_kNN' : { + # 'vars' : {'electronPt':rebinPt, 'electronJetPt':rebinPt, 'numJets20':rebinJet}, + # 'wjets' : 'results/%s/fakerate_fits/ee_wjetsNoZmass_pt10_eid12Tight_h2taucuts_electronInfo_k50.kNN.root' % jobid, + # 'qcd' : 'results/%s/fakerate_fits/ee_qcd_pt10_eid12Tight_h2taucuts_electronInfo_k50.kNN.root' % jobid, + # }, } canvas = plotting.Canvas(800, 800, name='adsf', title='asdf') @@ -91,13 +91,13 @@ def round_to_ints(histo): for output, info in sources.iteritems(): logging.info("analyzing %s" % output) wjets_name = info['wjets'] - qcd_name = info['qcd'] + #qcd_name = info['qcd'] variables = info['vars'] wjets_file = ROOT.TFile.Open(wjets_name) logging.debug('filename: %s instance: %s' % (wjets_name, wjets_file.__repr__())) - qcd_file = ROOT.TFile.Open(qcd_name) - logging.debug('filename: %s instance: %s' % (qcd_name, qcd_file.__repr__())) + #qcd_file = ROOT.TFile.Open(qcd_name) + #logging.debug('filename: %s instance: %s' % (qcd_name, qcd_file.__repr__())) for var, rebins in variables.iteritems(): logging.debug('variable %s' % var) @@ -118,16 +118,16 @@ def round_to_ints(histo): ##### #QCD fake rate ##### - qcd_view = RebinView(qcd_file, rebins[0]) - qcd_eff = asrootpy( - ROOT.TGraphAsymmErrors( - round_to_ints(qcd_view.Get('%s_pass' % var)), - round_to_ints(qcd_view.Get('%s_all' % var)) - ) - ) - qcd_eff.SetTitle('QCD fake rate') - qcd_eff.markerstyle = 20 - qcd_eff.markercolor = ROOT.EColor.kRed + #qcd_view = RebinView(qcd_file, rebins[0]) + #qcd_eff = asrootpy( + # ROOT.TGraphAsymmErrors( + # round_to_ints(qcd_view.Get('%s_pass' % var)), + # round_to_ints(qcd_view.Get('%s_all' % var)) + # ) + #) + #qcd_eff.SetTitle('QCD fake rate') + #qcd_eff.markerstyle = 20 + #qcd_eff.markercolor = ROOT.EColor.kRed ##### @@ -151,20 +151,20 @@ def round_to_ints(histo): ##### #QCD kNN output ##### - qcd_view = RebinView(qcd_file, rebins[1]) - qcd_estimate = asrootpy( - qcd_view.Get('%s_estimate' % var) - ) - qcd_estimate_denom = asrootpy( - qcd_view.Get('%s_estimate_all' % var) - ) - qcd_estimate.Divide(qcd_estimate_denom) - qcd_estimate.SetTitle('QCD kNN output') - qcd_estimate.linecolor = ROOT.kRed - qcd_estimate.linewidth = 2 - qcd_estimate.fillstyle = 0 - qcd_estimate.legendstyle = 'l' - qcd_estimate.drawstyle = 'hist' + #qcd_view = RebinView(qcd_file, rebins[1]) + #qcd_estimate = asrootpy( + # qcd_view.Get('%s_estimate' % var) + #) + #qcd_estimate_denom = asrootpy( + # qcd_view.Get('%s_estimate_all' % var) + #) + #qcd_estimate.Divide(qcd_estimate_denom) + #qcd_estimate.SetTitle('QCD kNN output') + #qcd_estimate.linecolor = ROOT.kRed + #qcd_estimate.linewidth = 2 + #qcd_estimate.fillstyle = 0 + #qcd_estimate.legendstyle = 'l' + #qcd_estimate.drawstyle = 'hist' canvas.SetGrid() @@ -177,19 +177,19 @@ def round_to_ints(histo): #axis.SetTitleOffset( axis.GetTitleOffset()*0.6 ) wjets_estimate.Draw() - qcd_estimate.Draw('same') + #qcd_estimate.Draw('same') wjets_eff.Draw('P SAME') - qcd_eff.Draw('P SAME') + #qcd_eff.Draw('P SAME') ##### #Legend ##### - legend = plotting.Legend(4, rightmargin=0.02, topmargin=0.05, leftmargin=0.45) + legend = plotting.Legend(2, rightmargin=0.02, topmargin=0.05, leftmargin=0.45) legend.AddEntry(wjets_estimate) - legend.AddEntry(qcd_estimate) + #legend.AddEntry(qcd_estimate) legend.AddEntry(wjets_eff) - legend.AddEntry(qcd_eff) + #legend.AddEntry(qcd_eff) legend.SetTextSize(0.5*legend.GetTextSize()) legend.SetEntrySeparation(0.0) legend.SetMargin(0.35) @@ -203,4 +203,4 @@ def round_to_ints(histo): wjets_file.Close() - qcd_file.Close() + #qcd_file.Close() From 20e85e6b5c644a04103d614ed62e8ae58b943ef5 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 6 Dec 2013 05:09:46 -0600 Subject: [PATCH 098/192] allows using different meta trees for different samples --- wh/setup.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wh/setup.sh b/wh/setup.sh index 3c60d84a..5aabb3e8 100755 --- a/wh/setup.sh +++ b/wh/setup.sh @@ -1,6 +1,9 @@ #!/bin/bash # Setup the cython proxies, find input ntuple files, and compute luminosity. +export OVERRIDE_META_TREE_data_DoubleElectron='ee/metaInfo' +export OVERRIDE_META_TREE_data_MuEG='em/metaInfo' +export IGNORE_LUMI_ERRORS=1 source jobid.sh export jobid=$jobid7 @@ -19,7 +22,7 @@ for file in $(ls inputs/$jobid/WZJetsTo3LNu*); do done export jobid=$jobid8 -export datasrc=$(ls -d /scratch/*/data/$jobid | awk -F$jobid '{print $1}') +export datasrc=/hdfs/store/user/$USER/$jobid #$(ls -d /scratch/*/data/$jobid | awk -F$jobid '{print $1}') #./make_proxies.sh for dir in $datasrc; do echo $dir @@ -33,6 +36,10 @@ for file in $(ls inputs/$jobid/WZJetsTo3LNu*); do cp -uv $file $newname done +unset OVERRIDE_META_TREE_data_DoubleElectron +unset OVERRIDE_META_TREE_data_MuEG +unset IGNORE_LUMI_ERRORS + # Use the 7TeV WH samples for 8TeV #pushd inputs/$jobid/ # Symlink the list of input files and the counts of the number of events. From 9a975d1e63825d199e29908cd4083963d434195d Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Dec 2013 04:09:38 -0600 Subject: [PATCH 099/192] changed env vars --- environment.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/environment.sh b/environment.sh index 455d25ae..b88c1d5b 100644 --- a/environment.sh +++ b/environment.sh @@ -12,9 +12,11 @@ if [ -z $CONDOR_ID ]; then fi #Is the analysis blinded? -export blind='YES' +export blind='NO' #'YES' export TARGET_LUMI_8TeV=19.4 export TARGET_LUMI_7TeV=4.9 +export MEGAPATH='/scratch/mverzett/data':$hdfs + #check if dev area is up to date check_git_updates.sh From c92b2c18428f941accc8a433279e3d0233d875e8 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Dec 2013 04:21:20 -0600 Subject: [PATCH 100/192] tool for keep track of the cut flow in mega scripts --- wh/cutflowtracker.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 wh/cutflowtracker.py diff --git a/wh/cutflowtracker.py b/wh/cutflowtracker.py new file mode 100644 index 00000000..7963ac08 --- /dev/null +++ b/wh/cutflowtracker.py @@ -0,0 +1,44 @@ +import os + +class cut_flow_tracker(object): + def __init__(self, hist): + self.labels = [hist.GetXaxis().GetBinLabel(i+1) for i in range(hist.GetNbinsX())] + self.cut_flow = dict([ (i, False) for i in self.labels]) + self.hist = hist + self.evt_info = [-1, -1, -1] + self.disabled = 'CutFlow' not in os.environ + self.sync_mode = 'SYNC' in os.environ + + def fill(self, label): + self.cut_flow[label] = True + + def Fill(self, *labels): + if self.disabled: + return + for label in labels: + self.fill(label) + + def flush(self): + if self.disabled: + return + final_i = -1 + for i, label in enumerate(self.labels): + val = self.cut_flow[label] + if val: + self.hist.Fill(i+0.5) + final_i = i + if self.sync_mode: + fails = '' + try: + fails = 'fails %s' % (self.labels[final_i+1]) + except IndexError: + fails = 'passes the selection' #if len(self.labels) == final_i else 'passes the selection' + print 'Event %i:%i:%i ' % tuple(self.evt_info) + fails + + def new_row(self, *args): + if self.disabled: + return + if self.evt_info != list(args): + self.flush() + self.evt_info = list(args) + self.cut_flow = dict([ (i, False) for i in self.labels]) From 8f003f0142506aee3bdc92f052fa53870414bc28 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Dec 2013 04:22:22 -0600 Subject: [PATCH 101/192] dumps used xsections from the input files --- wh/dump_xsecs.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 wh/dump_xsecs.py diff --git a/wh/dump_xsecs.py b/wh/dump_xsecs.py new file mode 100644 index 00000000..876a79c2 --- /dev/null +++ b/wh/dump_xsecs.py @@ -0,0 +1,29 @@ +import FinalStateAnalysis.Utilities.prettyjson as prettyjson +import os +import glob +from pdb import set_trace + +def dump_xsec(jobid): + json_files = [i for i in glob.glob('inputs/%s/*.json' % jobid) if 'data_' not in i] + lumi_files = [i for i in glob.glob('inputs/%s/*.sum' % jobid) if 'data_' not in i] + + datasets = {} + for json_file in json_files: + dname = json_file.split('/')[-1].split('.')[0] + datasets[dname] = {} + datasets[dname]['numevts'] = prettyjson.loads(open(json_file).read())['n_evts'] + + for lumi_file in lumi_files: + dname = lumi_file.split('/')[-1].split('.')[0] + datasets[dname]['lumi'] = float( open(lumi_file).read().strip() ) + + out_format = '%30s'+'%15s'*3 + print out_format % ('dataset', '# evts', 'lumi [/pb]', 'xsec [pb]') + for dataset, info in datasets.iteritems(): + print out_format % (dataset, '%.3f' % info['numevts'], '%.3f' % info['lumi'], '%.5f' % (info['numevts']/info['lumi']) ) + +print '\n\n%s\n' % os.environ['jobid7'] +dump_xsec(os.environ['jobid7']) + +print '\n\n%s\n' % os.environ['jobid8'] +dump_xsec(os.environ['jobid8']) From a5fe4e5390c141e2b1ff0b5c390916dc2711722b Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 9 Dec 2013 04:35:05 -0600 Subject: [PATCH 102/192] prints an events list out of a tree --- wh/print_evt_list.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 wh/print_evt_list.py diff --git a/wh/print_evt_list.py b/wh/print_evt_list.py new file mode 100755 index 00000000..6fd69361 --- /dev/null +++ b/wh/print_evt_list.py @@ -0,0 +1,15 @@ +#! /bin/env python + +import ROOT +import sys + +tfile_path = sys.argv[-2] +tree_path = sys.argv[-1] + +tfile = ROOT.TFile.Open(tfile_path) +tree = tfile.Get(tree_path) + +for row in tree: + print '%i:%i:%i' % (row.run, row.lumi, row.evt) + + From 3e2c5b5de5265bb4e6bd182c92fc6d5497a5b408 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Fri, 10 Oct 2014 07:58:12 -0500 Subject: [PATCH 103/192] first LFVHetau analysis --- lfvetau/BasePlotter.py | 705 ++++++++++++++++++++++++++++++ lfvetau/CorrectFakeRateData.py | 168 +++++++ lfvetau/EEAnalyzerMVA.py | 453 +++++++++++++++++++ lfvetau/LFVHETauAnalyzerMVA.py | 485 ++++++++++++++++++++ lfvetau/Rakefile | 270 ++++++++++++ lfvetau/TauFakeRateAnalyzerMVA.py | 340 ++++++++++++++ lfvetau/baseSelections.py | 108 +++++ lfvetau/cutflowtracker.py | 46 ++ lfvetau/dump_xsec.py | 29 ++ lfvetau/electronids.py | 118 +++++ lfvetau/fakerate_functions.py | 85 ++++ lfvetau/jobid.sh | 8 + lfvetau/make_proxies.sh | 35 ++ lfvetau/mcCorrections.py | 153 +++++++ lfvetau/myNewPlotterReco.py | 158 +++++++ lfvetau/optimizer.py | 107 +++++ lfvetau/plotControlEE_MVA.py | 204 +++++++++ lfvetau/plotControlFakeMVA.py | 171 ++++++++ lfvetau/plotRecoQuantitiesMVA.py | 186 ++++++++ lfvetau/plotTauFakeRateMVA.py | 190 ++++++++ lfvetau/readNtuple.py | 37 ++ lfvetau/run.sh | 27 ++ lfvetau/setup.sh | 27 ++ 23 files changed, 4110 insertions(+) create mode 100644 lfvetau/BasePlotter.py create mode 100644 lfvetau/CorrectFakeRateData.py create mode 100644 lfvetau/EEAnalyzerMVA.py create mode 100644 lfvetau/LFVHETauAnalyzerMVA.py create mode 100644 lfvetau/Rakefile create mode 100644 lfvetau/TauFakeRateAnalyzerMVA.py create mode 100755 lfvetau/baseSelections.py create mode 100644 lfvetau/cutflowtracker.py create mode 100644 lfvetau/dump_xsec.py create mode 100644 lfvetau/electronids.py create mode 100644 lfvetau/fakerate_functions.py create mode 100644 lfvetau/jobid.sh create mode 100755 lfvetau/make_proxies.sh create mode 100755 lfvetau/mcCorrections.py create mode 100644 lfvetau/myNewPlotterReco.py create mode 100644 lfvetau/optimizer.py create mode 100644 lfvetau/plotControlEE_MVA.py create mode 100644 lfvetau/plotControlFakeMVA.py create mode 100644 lfvetau/plotRecoQuantitiesMVA.py create mode 100644 lfvetau/plotTauFakeRateMVA.py create mode 100644 lfvetau/readNtuple.py create mode 100755 lfvetau/run.sh create mode 100755 lfvetau/setup.sh diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py new file mode 100644 index 00000000..a55e8ca0 --- /dev/null +++ b/lfvetau/BasePlotter.py @@ -0,0 +1,705 @@ +''' + +Base class which makes nice plots. + +Author: Evan K. Friis, UW + +''' + +import fnmatch +import re +import os +import math +import rootpy.plotting.views as views +from rootpy.plotting.hist import HistStack +import rootpy.plotting as plotting +from FinalStateAnalysis.MetaData.data_views import data_views +from FinalStateAnalysis.PlotTools.RebinView import RebinView +from FinalStateAnalysis.PlotTools.BlindView import BlindView, blind_in_range +from FinalStateAnalysis.Utilities.struct import struct +import FinalStateAnalysis.Utilities.prettyjson as prettyjson +from FinalStateAnalysis.MetaData.data_styles import data_styles +from FinalStateAnalysis.PlotTools.Plotter import Plotter +from FinalStateAnalysis.PlotTools.SubtractionView import SubtractionView, PositiveView + +import ROOT +import glob +from pdb import set_trace + +def create_mapper(mapping): + def _f(path): + for key, out in mapping.iteritems(): + if key == path: + path = path.replace(key,out) + print 'path', path + return path + return _f + + +class BasePlotter(Plotter): + def __init__ (self, channel, files, lumifiles, outputdir,forceLumi=-1): + cwd = os.getcwd() + self.channel = channel + jobid = os.environ['jobid'] + period = '7TeV' if '7TeV' in jobid else '8TeV' + self.period = period + self.sqrts = 7 if '7TeV' in jobid else 8 + self.mc_samples = [ + 'ggHiggsToETau', + 'vbfHiggsToETau', + 'GluGluToHToTauTau_M-125_8TeV-powheg-pythia6', + 'VBF_HToTauTau_M-125_8TeV-powheg-pythia6', + #'Zjets_M50', + 'Zjets_M50_skimmedLL', + 'Z1jets_M50_skimmedLL', + 'Z2jets_M50_skimmedLL', + 'Z3jets_M50_skimmedLL', + 'Z4jets_M50_skimmedLL', + 'Zjets_M50_skimmedTT', + 'Z1jets_M50_skimmedTT', + 'Z2jets_M50_skimmedTT', + 'Z3jets_M50_skimmedTT', + 'Z4jets_M50_skimmedTT', + 'TTJets*', + 'T_t*', + 'Tbar_t*', + 'WplusJets_madgraph_skimmed', + 'Wplus1Jets_madgraph', + # 'Wplus1Jets_madgraph_tapas', + 'Wplus2Jets_madgraph', + # 'Wplus2Jets_madgraph_tapas', + 'Wplus3Jets_madgraph', + 'Wplus4Jets_madgraph', + 'WWJets*', + 'WZJets*', + 'ZZJets*', + 'Fake*', + 'data*', + + ] + +## files = [] +## lumifiles = [] +## +## for x in mc_samples: +## files.extend(glob.glob('results/%s/LFVHETauAnalyzerMVA/%s.root' % (jobid, x))) +## lumifiles.extend(glob.glob('inputs/%s/%s.lumicalc.sum' % (jobid, x))) +## self.outputdir = 'plots/%s/LFVHETauAnalyzerMVA/%s' % (jobid, channel) +## self.base_out_dir = self.outputdir +## if not os.path.exists(self.outputdir): +## os.makedirs(self.outputdir) +## + self.blindstart=100 + self.blindend=150 + + blinder = None + blind = 'blind' not in os.environ or os.environ['blind'] == 'YES' + print '\n\nRunning Blind: %s\n\n' % blind + self.blind = blind + + if blind: + # Don't look at the SS all pass region + blinder = lambda x: BlindView(x, "os/.*",blind_in_range(100, 150)) + super(BasePlotter, self).__init__(files, lumifiles, outputdir, blinder) + def simpleplot_mc(self, folder, signal, variable, rebin=1, xaxis='', + leftside=True, xrange=None, preprocess=None, sort=True,forceLumi=-1): + ''' Compare Monte Carlo signal to bkg ''' + #path = os.path.join(folder, variable) + #is_not_signal = lambda x: x is not signame + #set_trace() + + mc_stack_view = self.make_stack(rebin, preprocess, folder) + mc_stack=mc_stack_view.Get(variable) + + #self.canvas.SetLogy(False) + mc_stack.SetTitle('') + mc_stack.Draw() + + mc_stack.GetHistogram().GetXaxis().SetTitle(xaxis) + + if xrange: + mc_stack.GetXaxis().SetRangeUser(xrange[0], xrange[1]) + mc_stack.Draw() + + signalview=[] + mymax=0 + for sig in signal: + signal_view=self.get_view(sig) + if preprocess: + signal_view=preprocess(signal_view) + signal_view=self.get_wild_dir( + self.rebin_view(signal_view,rebin),folder) + signal=signal_view.Get(variable) + signalview.append(signal) + signal.Draw("SAME") + if signal.GetBinContent(signal.GetMaximumBin()) > mymax: + mymax = signal.GetBinContent(signal.GetMaximumBin()) + + self.keep.append(signal) + if mymax > mc_stack.GetMaximum(): + mc_stack.SetMaximum(mymax*1.2) + + self.keep.append(mc_stack) + + all_var=[] + all_var.extend([mc_stack]) + all_var.extend(signalview) + + self.add_legend(all_var, leftside, entries=len(mc_stack)+len(signalview)) + + def plot_data(self, folder, variable, rebin=1, xaxis='', + leftside=True, xrange=None, preprocess=None): + ''' Compare Monte Carlo signal to bkg ''' + #path = os.path.join(folder, variable) + #is_not_signal = lambda x: x is not signame + #set_trace() + data_view = self.get_view('data') + if preprocess: + data_view = preprocess( data_view ) + data_view = self.get_wild_dir( + self.rebin_view(data_view, rebin), + folder + ) + data = data_view.Get(variable) + data.Draw() + + + data.GetXaxis().SetTitle(xaxis) + + if xrange: + data.GetXaxis().SetRangeUser(xrange[0], xrange[1]) + data.Draw() + self.keep.append(data) + + + + def compare_data(self, folder, variable, folder2, rebin=1, xaxis='', + leftside=True, xrange=None, preprocess=None, show_ratio=False, ratio_range=0.2,rescale=1. ): + ''' Compare Monte Carlo signal to bkg ''' + #path = os.path.join(folder, variable) + #is_not_signal = lambda x: x is not signame + #set_trace() + data_view = self.get_view('data') + data_view2 = self.get_view('data') + if preprocess: + data_view = preprocess( data_view ) + data_view = self.get_wild_dir( + self.rebin_view(data_view, rebin), + folder + ) + data_view2 = self.get_wild_dir( + self.rebin_view(data_view2, rebin), + folder2 + ) + data = data_view.Get(variable) + data2 = data_view2.Get(variable) + + data.GetXaxis().SetTitle(xaxis) + #if (data.Integral()!=0 and data2.Integral()!=0) : + # data.Scale(1./data.Integral()) + # data2.Scale(1./data2.Integral()) + data.Draw() + data.GetYaxis().SetRangeUser(0, data.GetBinContent(data.GetMaximumBin())*1.2) + if xrange: + data.GetXaxis().SetRangeUser(xrange[0], xrange[1]) + data.Draw() + + data2.Draw("SAME") + data2.SetMarkerColor(2) + data2.Draw("SAME") + + + if show_ratio: + self.add_sn_ratio_plot(data2, data, xrange, ratio_range) + + self.keep.append(data) + self.keep.append(data2) + + + def add_ratio_bandplot(self, data_hist, mc_stack, err_hist, x_range=None, ratio_range=0.2): + #resize the canvas and the pad to fit the second pad + self.canvas.SetCanvasSize( self.canvas.GetWw(), int(self.canvas.GetWh()*1.3) ) + self.canvas.cd() + self.pad.SetPad(0, 0.33, 1., 1.) + self.pad.Draw() + self.canvas.cd() + #create lower pad + self.lower_pad = plotting.Pad('low', 'low', 0, 0., 1., 0.33) + self.lower_pad.Draw() + self.lower_pad.cd() + + + mc_hist = None + if isinstance(mc_stack, plotting.HistStack): + mc_hist = sum(mc_stack.GetHists()) + else: + mc_hist = mc_stack + data_clone = data_hist.Clone() + data_clone.Divide(mc_hist) + + band = err_hist.Clone() + + err = [] + ibin =1 + while ibin < band.GetXaxis().GetNbins()+1: + if mc_hist.GetBinContent(ibin) <> 0 : + err.append((ibin, band.GetBinError(ibin)/band.GetBinContent(ibin))) + ibin+=1 + + band.Divide(mc_hist.Clone()) + #print err + for ibin in err: + band.SetBinError(ibin[0], ibin[1]) + + if not x_range: + nbins = data_clone.GetNbinsX() + x_range = (data_clone.GetBinLowEdge(1), + data_clone.GetBinLowEdge(nbins)+data_clone.GetBinWidth(nbins)) + else: + data_clone.GetXaxis().SetRangeUser(*x_range) + + + ref_function = ROOT.TF1('f', "1.", *x_range) + ref_function.SetLineWidth(2) + ref_function.SetLineStyle(2) + + data_clone.Draw() + + if ratio_range: + data_clone.GetYaxis().SetRangeUser(1-ratio_range, 1+ratio_range) + ref_function.Draw('same') + band.SetMarkerStyle(0) + band.SetLineColor(1) + band.SetFillStyle(3001) + band.SetFillColor(1) + + band.Draw('samee2') + + self.keep.append(data_clone) + self.keep.append(band) + self.keep.append(ref_function) + self.pad.cd() + return data_clone + + + + def get_isoid_unc (self, folder, variable, rebin, preprocess, obj=['e1', 'e2']): + # 'e1idp1s/','e1idm1s/', 'e1isop1s/','e1isom1s/','e2idp1s/','e2idm1s/', 'e2isop1s/','e2isom1s/' + unc_list = [] + for n, lep in enumerate(obj): + + bkg_lep_iso_p1s_stack_view = self.make_stack(rebin, preprocess, lep+'isop1s/'+folder) + bkg_lep_iso_p1s_stack= bkg_lep_iso_p1s_stack_view.Get(variable) + histo_lep_iso_p1s = bkg_lep_iso_p1s_stack.GetStack().Last().Clone() + + bkg_lep_iso_m1s_stack_view = self.make_stack(rebin, preprocess, lep+'isom1s/'+folder) + bkg_lep_iso_m1s_stack=bkg_lep_iso_m1s_stack_view.Get(variable) + histo_lep_iso_m1s = bkg_lep_iso_m1s_stack.GetStack().Last().Clone() + + bkg_lep_id_p1s_stack_view = self.make_stack(rebin, preprocess, lep+'idp1s/'+folder) + bkg_lep_id_p1s_stack= bkg_lep_id_p1s_stack_view.Get(variable) + histo_lep_id_p1s = bkg_lep_id_p1s_stack.GetStack().Last().Clone() + + bkg_lep_id_m1s_stack_view = self.make_stack(rebin, preprocess, lep+'idm1s/'+folder) + bkg_lep_id_m1s_stack=bkg_lep_id_m1s_stack_view.Get(variable) + histo_lep_id_m1s = bkg_lep_id_m1s_stack.GetStack().Last().Clone() + + #bkg_obj2_iso_p1s_stack_view = self.make_stack(rebin, preprocess, obj2+'isop1s/'+folder) + #bkg_obj2_iso_p1s_stack= bkg_obj2_iso_p1s_stack_view.Get(variable) + #histo_obj2_iso_p1s = bkg_obj2_iso_p1s_stack.GetStack().Last().Clone() + + #bkg_obj2_iso_m1s_stack_view = self.make_stack(rebin, preprocess, obj2+'isom1s/'+folder) + #bkg_obj2_iso_m1s_stack=bkg_obj2_iso_m1s_stack_view.Get(variable) + #histo_obj2_iso_m1s = bkg_obj2_iso_m1s_stack.GetStack().Last().Clone() + + #bkg_obj2_id_p1s_stack_view = self.make_stack(rebin, preprocess, obj2+'idp1s/'+folder) + #bkg_obj2_id_p1s_stack= bkg_obj2_id_p1s_stack_view.Get(variable) + #histo_obj2_id_p1s = bkg_obj2_id_p1s_stack.GetStack().Last().Clone() + + #bkg_obj2_id_m1s_stack_view = self.make_stack(rebin, preprocess, obj2+'idm1s/'+folder) + #bkg_obj2_id_m1s_stack=bkg_obj2_id_m1s_stack_view.Get(variable) + #histo_obj2_id_m1s = bkg_obj2_id_m1s_stack.GetStack().Last().Clone() + + self.keep.append(histo_lep_iso_p1s) + self.keep.append(histo_lep_iso_m1s) + self.keep.append(histo_lep_id_p1s) + self.keep.append(histo_lep_id_m1s) + #self.keep.append(histo_obj2_iso_p1s) + #self.keep.append(histo_obj2_iso_m1s) + #self.keep.append(histo_obj2_id_p1s) + #self.keep.append(histo_obj2_id_m1s) + + unc_list.extend([(histo_lep_iso_p1s, histo_lep_iso_m1s), (histo_lep_id_p1s, histo_lep_id_m1s)]) + return unc_list +#[(histo_obj1_iso_p1s, histo_obj1_iso_m1s), (histo_obj1_id_p1s, histo_obj1_id_m1s), (histo_obj2_iso_p1s, histo_obj2_iso_m1s), (histo_obj2_id_p1s, histo_obj2_id_m1s)] + def add_ratio_diff(self, data_hist, mc_stack, err_hist, x_range=None, ratio_range=0.2): + #resize the canvas and the pad to fit the second pad + self.canvas.SetCanvasSize( self.canvas.GetWw(), int(self.canvas.GetWh()*1.3) ) + self.canvas.cd() + self.pad.SetPad(0, 0.33, 1., 1.) + self.pad.Draw() + self.canvas.cd() + #create lower pad + self.lower_pad = plotting.Pad('low', 'low', 0, 0., 1., 0.33) + self.lower_pad.Draw() + self.lower_pad.cd() + + + mc_hist = None + if isinstance(mc_stack, plotting.HistStack): + mc_hist = sum(mc_stack.GetHists()) + else: + mc_hist = mc_stack + data_clone = data_hist.Clone() + data_clone.Sumw2() + data_clone.Add(mc_hist, -1) + data_clone.Divide(mc_hist) + + band = err_hist.Clone() + + err = [] + ibin =1 + while ibin < band.GetXaxis().GetNbins()+1: + if mc_hist.GetBinContent(ibin) <> 0 : + err.append((ibin, band.GetBinError(ibin)/band.GetBinContent(ibin))) + + ibin+=1 + + band.Divide(mc_hist.Clone()) + #print err + for ibin in err: + band.SetBinError(ibin[0], ibin[1]) + blind=None + blind = 'blind' not in os.environ or os.environ['blind'] == 'YES' + if blind<>None: + for ibin in err: + if ibin>=band.FindBin(self.blindstart) and ibin <= band.FindBin(self.blindend): + band.SetBinError(ibin, 10) + + if not x_range: + nbins = data_clone.GetNbinsX() + x_range = (data_clone.GetBinLowEdge(1), + data_clone.GetBinLowEdge(nbins)+data_clone.GetBinWidth(nbins)) + else: + data_clone.GetXaxis().SetRangeUser(*x_range) + + + ref_function = ROOT.TF1('f', "0.", *x_range) + ref_function.SetLineWidth(2) + ref_function.SetLineStyle(2) + + data_clone.Draw() + + if ratio_range: + data_clone.GetYaxis().SetRangeUser(-ratio_range, +ratio_range) + ref_function.Draw('same') + band.SetMarkerStyle(0) + band.SetLineColor(1) + band.SetFillStyle(3001) + band.SetFillColor(1) + + band.Draw('samee2') + + self.keep.append(data_clone) + self.keep.append(band) + self.keep.append(ref_function) + self.pad.cd() + return data_clone + + def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', + leftside=True, xrange=None, preprocess=None, + show_ratio=False, ratio_range=0.2, sort=True, obj=['e1', 'e2']): + + + + mc_stack_view = self.make_stack(rebin, preprocess, folder, sort) + + mc_stack = mc_stack_view.Get(variable) + mc_stack.Draw() + + self.canvas.SetLogy(True) + mc_stack.GetHistogram().GetXaxis().SetTitle(xaxis) + if xrange: + mc_stack.GetXaxis().SetRangeUser(xrange[0], xrange[1]) + mc_stack.Draw() + self.keep.append(mc_stack) + + + finalhisto= mc_stack.GetStack().Last().Clone() + finalhisto.Sumw2() + + histlist = mc_stack.GetHists(); + bkg_stack = mc_stack_view.Get(variable) + bkg_stack.GetStack().RemoveLast()## mettere il check se c'e` il fake altirmenti histo=mc_stack.GetStack().Last().Clone() + histo=bkg_stack.GetStack().Last().Clone() + histo.Sumw2() + + fake_p1s_histo=None + + if not folder.startswith('tLoose'): + ##if folder.startswith('os'): + ## newfolder=folder#.replace('os','ss') + ## print 'newfolder', newfolder + ## #tau fake error + ## + ##fake_stack_view = self.make_stack(rebin, preprocess, 'tLoose/'+newfolder, sort) + ## fake_p1s_stack_view = self.make_stack(rebin, preprocess, 'tLooseUp/'+newfolder, sort) + ## fake_m1s_stack_view = self.make_stack(rebin, preprocess, 'tLooseDown/'+newfolder, sort) + ## + ## #if (type(fake_stack_view)==ROOT.THStack): + ## #print 'adding tau fakerate uncertainty' + ## + ## try: + ##fake_stack = fake_stack_view.Get(variable) + ##fakehisto = fake_stack.GetStack().Last().Clone() + ## + ## fake_p1s_stack = fake_p1s_stack_view.Get(variable) + ## fake_p1s_histo = fake_p1s_stack.GetStack().Last().Clone() + ## fake_m1s_stack = fake_m1s_stack_view.Get(variable) + ## fake_m1s_histo = fake_m1s_stack.GetStack().Last().Clone() + ## + ## except: + ## print 'no fake taus' + ## fake_diffup = 0 + ## fake_diffdown = 0 + + + print folder + print self.mc_samples + isFakesIn= False + if 'Fakes' in self.mc_samples: + self.mc_samples.remove('Fakes') + self.mc_samples.remove('finalDYLL') + isFakesIn=True + + bkg_p1s_stack_view = self.make_stack(rebin, preprocess, 'p1s/'+folder, sort) + bkg_p1s_stack=bkg_p1s_stack_view.Get(variable) + histo_p1s = bkg_p1s_stack.GetStack().Last().Clone() + + bkg_m1s_stack_view = self.make_stack(rebin, preprocess, 'm1s/'+folder, sort) + bkg_m1s_stack=bkg_m1s_stack_view.Get(variable) + histo_m1s = bkg_m1s_stack.GetStack().Last().Clone() + + tr_p1s_stack_view = self.make_stack(rebin, preprocess, 'trp1s/'+folder, sort) + tr_p1s_stack=tr_p1s_stack_view.Get(variable) + histotr_p1s = tr_p1s_stack.GetStack().Last().Clone() + + tr_m1s_stack_view = self.make_stack(rebin, preprocess, 'trm1s/'+folder, sort) + tr_m1s_stack=tr_m1s_stack_view.Get(variable) + histotr_m1s = tr_m1s_stack.GetStack().Last().Clone() + #if os.path.exists(folder+'tLoose/') : + # fr_tau_stack_view = self.make_stack(rebin, preprocess, 'tLoose/'+folder, sort) + # fr_tau_stack=fr_tau_stack_view.Get(variable) + # histofr_tau = fr_tau_stack.GetStack().Last().Clone() + # histofr_tau.SetTitle('Fakes') + + xsec_unc_mapper = { + 'EWK Dibosons': 0.056, + 'SM Higgs': 0.0, #still to add + 't#bar{t}' : 0.026, + 'Single Top' : 0.041, + 'DY (#rightarrow #tau#tau) + jets' : 0., + 'DY (#rightarrow ll) + jets' : 0.032, + 'W + jets': 0.035, + 'QCD' : 0.0, + 'Fakes' :0.0, + } + + ibin =1 + + iso_id_unc = self.get_isoid_unc( folder, variable, rebin, preprocess, obj) + if isFakesIn: + self.mc_samples.append('Fakes') + self.mc_samples.append('finalDYLL') + + met_histos=[] + if 'Met' in variable or 'MET' in variable: + if not 'mva' in variable or not 'MVA' in variable: + if 'type1_' in variable or '_Ty1' in variable: + ##print variable + newMetName=variable.replace('type1_', '') if 'type1_' in variable else variable.replace('_Ty', '') + met_histos.extend([mc_stack_view.Get(newMetName+'_jes'),mc_stack_view.Get(newMetName+'_mes'),mc_stack_view.Get(newMetName+'_tes'),mc_stack_view.Get(newMetName+'_ues'), mc_stack_view.Get(newMetName+'_ees') ]) ##add the ees + else: + met_histos.extend([mc_stack_view.Get(variable+'_jes'),mc_stack_view.Get(variable+'_mes'),mc_stack_view.Get(variable+'_tes'),mc_stack_view.Get(variable+'_ues'),mc_stack_view.Get(variable+'_ees')]) ##add the ees + + while ibin < histo.GetXaxis().GetNbins()+1: + ##print ibin,histo.GetXaxis().GetNbins() + err2=0 + + #if isFakesIn: + #diff_fake_up= abs(fakehisto.GetBinContent(ibin)-fake_p1s_histo.GetBinContent(ibin)) + #diff_fake_down= abs(fakehisto.GetBinContent(ibin)-fake_m1s_histo.GetBinContent(ibin)) + #print ibin, fakehisto.GetBinContent(ibin), fake_p1s_histo.GetBinContent(ibin), fake_m1s_histo.GetBinContent(ibin) + #diff_fake = diff_fake_up if diff_fake_up > diff_fake_down else diff_fake_down + + #err2+= pow(diff_fake,2) + ##err2+=pow(fakehisto.GetBinContent(ibin) * 0.3) + #print 'TAU SYSTEMATICS:', fakehisto.GetBinContent(ibin), diff_fake + + for h in histlist: + err2 += h.GetBinError(ibin)**2 + + err2 += h.GetBinContent(ibin)*xsec_unc_mapper[h.GetTitle()] + + + + #tau fake rake, I approximate with 5%. Redo it in the correct way + #diff_fake = abs(histo.GetBinContent(ibin) - finalhisto.GetBinContent(ibin)) + #err2 += pow(diff_fake*0.05,2) + + #why is not working? + #diff_fake = abs(fake_diffup.GetBinContent(ibin)) if abs(fake_diffup.GetBinContent(ibin)) > abs(fake_diffdown.GetBinContent(ibin)) else abs(fake_diffdown.GetBinContent(ibin)) + + if not folder.startswith('tLoose'): + diff_p = abs(histo.GetBinContent(ibin) - histo_p1s.GetBinContent(ibin)) + diff_m = abs(histo.GetBinContent(ibin) - histo_m1s.GetBinContent(ibin)) + err2 += diff_p**2 if diff_p > diff_m else diff_m**2 + diff_tr_p = abs(histo.GetBinContent(ibin) - histotr_p1s.GetBinContent(ibin)) + diff_tr_m = abs(histo.GetBinContent(ibin) - histotr_m1s.GetBinContent(ibin)) + err2 += diff_tr_p**2 if diff_tr_p > diff_tr_m else diff_tr_m**2 + err2 += (0.026*h.GetBinContent(ibin))**2 #lumi error + + + for h in iso_id_unc : + diff_isoid_p = abs(histo.GetBinContent(ibin) - h[0].GetBinContent(ibin)) + diff_isoid_m = abs(histo.GetBinContent(ibin) - h[1].GetBinContent(ibin)) + err2 += diff_isoid_p**2 if diff_isoid_p > diff_isoid_m else diff_isoid_m**2 + + #add met unc https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuidePATTools#MET_Systematics_Tools only to met plots (no cut on the met) + if 'Met' in variable or 'MET' in variable: + if not 'mva' in variable or not 'MVA' in variable: + if not '_jes' in variable and not '_mes' in variable and not '_tes' in variable \ + and not '_ees' in variable and not '_ues' in variable: + if not 'type1_' in variable and not '_Ty1' in variable: + for h in met_histos: + diff = abs(histo.GetBinContent(ibin) - h.GetStack().Last().GetBinContent(ibin)) + ##print variable, diff, histo.GetBinContent(ibin), h.GetStack().Last().GetBinContent(ibin), h.GetName() + err2+=diff**2 + else: + myh = mc_stack_view.Get(variable.replace('type1_', '')) if 'type1_' in variable else variable.replace('_Ty', '') + for h in met_histos: + diff = abs(h.GetStack().Last().GetBinContent(ibin) - myh.GetStack().Last().GetBinContent(ibin)) + err2+=diff**2 + + #histo.SetBinError(ibin, math.sqrt(err2)) + #finalhisto.SetBinError(ibin, math.sqrt(err2)) + + + + ibin+=1 + + + finalhisto.Draw('samee2') + finalhisto.SetMarkerStyle(0) + finalhisto.SetLineColor(1) + finalhisto.SetFillStyle(3001) + finalhisto.SetFillColor(1) + + + self.keep.append(finalhisto) + # Draw data + data_view = self.get_view('data') + if preprocess: + data_view = preprocess( data_view ) + data_view = self.get_wild_dir( + self.rebin_view(data_view, rebin), + folder + ) + data = data_view.Get(variable) + data.Draw('same') + print 'data', data.Integral() + self.keep.append(data) + ## Make sure we can see everything + if data.GetMaximum() > mc_stack.GetMaximum(): + mc_stack.SetMaximum(1.2*data.GetMaximum()) + #mc_stack.SetMinimum(0.00001*data.GetMaximum()) + + # # Ad legend + #allentries = [data] + #allentries.append( x for x in mc_stack.GetHists() ) + self.add_legend([data, mc_stack], leftside, entries=len(mc_stack.GetHists())+1) + if show_ratio: + self.add_ratio_diff(data, mc_stack, finalhisto, xrange, ratio_range) + +##----- + + def plot_without_uncert (self, folder, variable, rebin=1, xaxis='', + leftside=True, xrange=None, preprocess=None, + show_ratio=False, ratio_range=0.2, sort=True, obj=['e1', 'e2']): + + + + mc_stack_view = self.make_stack(rebin, preprocess, folder, sort) + + mc_stack = mc_stack_view.Get(variable) + mc_stack.Draw() + + self.canvas.SetLogy(True) + mc_stack.GetHistogram().GetXaxis().SetTitle(xaxis) + if xrange: + mc_stack.GetXaxis().SetRangeUser(xrange[0], xrange[1]) + mc_stack.Draw() + self.keep.append(mc_stack) + + + finalhisto= mc_stack.GetStack().Last().Clone() + finalhisto.Sumw2() + + histlist = mc_stack.GetHists(); + bkg_stack = mc_stack_view.Get(variable) + bkg_stack.GetStack().RemoveLast()## mettere il check se c'e` il fake altirmenti histo=mc_stack.GetStack().Last().Clone() + histo=bkg_stack.GetStack().Last().Clone() + histo.Sumw2() + + fake_p1s_histo=None + + if not folder.startswith('tLoose'): + isFakesIn= False + if 'Fakes' in self.mc_samples: + self.mc_samples.remove('Fakes') + self.mc_samples.remove('finalDYLL') + isFakesIn=True + + + ibin =1 + + if isFakesIn: + self.mc_samples.append('Fakes') + self.mc_samples.append('finalDYLL') + + + + finalhisto.Draw('samee2') + finalhisto.SetMarkerStyle(0) + finalhisto.SetLineColor(1) + finalhisto.SetFillStyle(3001) + finalhisto.SetFillColor(1) + + + self.keep.append(finalhisto) + # Draw data + data_view = self.get_view('data') + if preprocess: + data_view = preprocess( data_view ) + data_view = self.get_wild_dir( + self.rebin_view(data_view, rebin), + folder + ) + data = data_view.Get(variable) + data.Draw('same') + print 'data', data.Integral() + self.keep.append(data) + ## Make sure we can see everything + if data.GetMaximum() > mc_stack.GetMaximum(): + mc_stack.SetMaximum(1.2*data.GetMaximum()) + + # # Add legend + self.add_legend([data, mc_stack], leftside, entries=len(mc_stack.GetHists())+1) + if show_ratio: + self.add_ratio_diff(data, mc_stack, finalhisto, xrange, ratio_range) + + + + + + diff --git a/lfvetau/CorrectFakeRateData.py b/lfvetau/CorrectFakeRateData.py new file mode 100644 index 00000000..0a4db484 --- /dev/null +++ b/lfvetau/CorrectFakeRateData.py @@ -0,0 +1,168 @@ +#! /bin/env python +''' + +Subtract expected WZ and ZZ contamination from FR numerator and denominators. + +Author: Evan K. Frii + +''' + +import logging +import sys +logging.basicConfig(stream=sys.stderr, level=logging.INFO) +from RecoLuminosity.LumiDB import argparse +import fnmatch +from FinalStateAnalysis.PlotTools.RebinView import RebinView +from FinalStateAnalysis.PlotTools.SubtractionView import SubtractionView +import glob +import os + +log = logging.getLogger("CorrectFakeRateData") +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('--files', nargs='+') + parser.add_argument('--lumifiles', nargs='+') + parser.add_argument('--outputfile', required=True) + parser.add_argument('--denom', required=True, help='Path to denom') + parser.add_argument('--numerator', required=True, help='Path to numerator') + parser.add_argument('--rebin', type=str, default="1") + + args = parser.parse_args() + + from rootpy import io + import ROOT + import rootpy.plotting.views as views + import rootpy.plotting as plotting + from FinalStateAnalysis.MetaData.data_views import data_views + + files = [] + for pattern in args.files: + files.extend(glob.glob(pattern)) + + log.info("Loading data from %i files", len(files)) + + lumifiles = [] + for pattern in args.lumifiles: + lumifiles.extend(glob.glob(pattern)) + + the_views = data_views(files, lumifiles) + + outputdir = os.path.dirname(args.outputfile) + if outputdir and not os.path.exists(outputdir): + os.makedirs(outputdir) + + log.info("Rebinning with factor %s", args.rebin) + def rebin_view(x): + ''' Make a view which rebins histograms ''' + binning = None + binning = eval(args.rebin) + return RebinView(x, binning) + + def round_to_ints(x): + new = x.Clone() + new.Reset() + for bin in range(x.GetNbinsX()+1): + binsy = range(x.GetNbinsY()+1) if isinstance(x, ROOT.TH2) else [-1] + for biny in binsy: + nentries = ROOT.TMath.Nint(x.GetBinContent(bin, biny)) \ + if isinstance(x, ROOT.TH2) else \ + ROOT.TMath.Nint(x.GetBinContent(bin)) + centerx = x.GetXaxis().GetBinCenter(bin) + centery = x.GetYaxis().GetBinCenter(biny) \ + if isinstance(x, ROOT.TH2) else \ + 0. + for _ in range(nentries): + if isinstance(x, ROOT.TH2): + new.Fill(centerx, centery) + else: + new.Fill(centerx) + return new + + def int_view(x): + return views.FunctorView(x, round_to_ints) + + def get_view(sample_pattern): + for sample, sample_info in the_views.iteritems(): + if fnmatch.fnmatch(sample, sample_pattern): + return rebin_view(sample_info['view']) + raise KeyError("I can't find a view that matches %s, I have: %s" % ( + sample_pattern, " ".join(the_views.keys()))) + + #from pdb import set_trace; set_trace() + wz_view = get_view('WZ*') + zz_view = get_view('ZZ*') + data = rebin_view(the_views['data']['view']) + + corrected_view = int_view( + SubtractionView(data, wz_view, zz_view, restrict_positive=True)) + + log.debug('creating output file') + output = io.open(args.outputfile, 'RECREATE') + output.cd() + + log.debug('getting from corrected view') + corr_numerator = corrected_view.Get(args.numerator) + corr_denominator = corrected_view.Get(args.denom) + + log.info("Corrected: %0.2f/%0.2f = %0.1f%%", + corr_numerator.Integral(), + corr_denominator.Integral(), + 100*corr_numerator.Integral()/corr_denominator.Integral() + if corr_denominator.Integral() else 0 + ) + + uncorr_numerator = data.Get(args.numerator) + uncorr_denominator = data.Get(args.denom) + + wz_integral = wz_view.Get(args.numerator).Integral() + zz_integral = zz_view.Get(args.numerator).Integral() + + log.info("Numerator integrals data: %.2f WZ: %.2f, ZZ: %.2f. Corrected numerator: %.2f", + uncorr_numerator.Integral(), + wz_integral, + zz_integral, + corr_numerator.Integral() + ) + + log.info("Uncorrected: %0.2f/%0.2f = %0.1f%%", + uncorr_numerator.Integral(), + uncorr_denominator.Integral(), + 100*uncorr_numerator.Integral()/uncorr_denominator.Integral() + if uncorr_denominator.Integral() else 0 + ) + + + corr_numerator.SetName('numerator') + corr_denominator.SetName('denominator') + + uncorr_numerator.SetName('numerator_uncorr') + uncorr_denominator.SetName('denominator_uncorr') + + corr_numerator.Write() + corr_denominator.Write() + uncorr_numerator.Write() + uncorr_denominator.Write() + + #make the unbinned plots + args.rebin = '1' + wz_view = get_view('WZ*') + zz_view = get_view('ZZ*') + data = the_views['data']['view'] + + corrected_view = int_view( + SubtractionView(data, wz_view, zz_view, restrict_positive=True)) + + corr_numerator_unrebinned = corrected_view.Get(args.numerator) + corr_denominator_unrebinned = corrected_view.Get(args.denom) + uncorr_numerator_unrebinned = data.Get(args.numerator) + uncorr_denominator_unrebinned = data.Get(args.denom) + + corr_numerator_unrebinned.SetName('numerator_unrebinned') + corr_denominator_unrebinned.SetName('denominator_unrebinned') + uncorr_numerator_unrebinned.SetName('numerator_uncorr_unrebinned') + uncorr_denominator_unrebinned.SetName('denominator_uncorr_unrebinned') + + corr_numerator_unrebinned.Write() + corr_denominator_unrebinned.Write() + uncorr_numerator_unrebinned.Write() + uncorr_denominator_unrebinned.Write() diff --git a/lfvetau/EEAnalyzerMVA.py b/lfvetau/EEAnalyzerMVA.py new file mode 100644 index 00000000..10d38024 --- /dev/null +++ b/lfvetau/EEAnalyzerMVA.py @@ -0,0 +1,453 @@ +##Correction Factor still to add +from EETree import EETree +import os +import ROOT +import math +from pdb import set_trace +import glob +import array +import baseSelections as selections +import mcCorrections +import FinalStateAnalysis.PlotTools.pytree as pytree +from FinalStateAnalysis.PlotTools.decorators import memo_last +from FinalStateAnalysis.PlotTools.MegaBase import MegaBase +from math import sqrt, pi, sin, cos, acos, sinh + +def Z(row): + e1p=ROOT.TVector3(row.e1Pt*cos(row.e1Phi),row.e1Pt*sin(row.e1Phi),row.e1Pt*sinh(row.e1Eta)) + e2p=ROOT.TVector3(row.e2Pt*cos(row.e2Phi),row.e2Pt*sin(row.e2Phi),row.e2Pt*sinh(row.e2Eta)) + e1FourVector= ROOT.TLorentzVector(e1p, sqrt(e1p.Mag2()+row.e1Mass*row.e1Mass)) + e2FourVector= ROOT.TLorentzVector(e2p, sqrt(e2p.Mag2()+row.e2Mass*row.e2Mass)) + zFourVector = e1FourVector+e2FourVector + return zFourVector + +def zPhi(pt1, eta1, phi1, pt2, eta2, phi2): + px1 = pt1*cos(phi1) + py1 = pt1*sin(phi1) + pz1 = pt1*sinh(eta1) + px2 = pt2*cos(phi2) + py2 = pt2*sin(phi2) + pz2 = pt2*sinh(eta2) + + px = px1+px2 + py = py1+py2 + pt = sqrt(px*px+py*py) + phi = acos(px/pt) + return phi + +def deltaPhi(phi1, phi2): + PHI = abs(phi1-phi2) + if PHI<=pi: + return PHI + else: + return 2*pi-PHI +def deltaR(phi1, ph2, eta1, eta2): + deta = eta1 - eta2 + dphi = abs(phi1-phi2) + if (dphi>pi) : dphi = 2*pi-dphi + return sqrt(deta*deta + dphi*dphi); + +class EEAnalyzerMVA(MegaBase): + tree = 'ee/final/Ntuple' + def __init__(self, tree, outfile, **kwargs): + self.channel='EE' + super(EEAnalyzerMVA, self).__init__(tree, outfile, **kwargs) + self.tree = EETree(tree) + self.out=outfile + self.histograms = {} + self.pucorrector = mcCorrections.make_puCorrector('singlee') + self.pucorrectorUp = mcCorrections.make_puCorrectorUp('singlee') + self.pucorrectorDown = mcCorrections.make_puCorrectorDown('singlee') + + + def event_weight(self, row): + if row.run > 2: #FIXME! add tight ID correction + return [1.] + + etrig = 'e1' + if row.e2Pt > row.e1Pt : etrig = 'e2' + if bool(row.e1MatchesSingleE27WP80) and not bool(row.e2MatchesSingleE27WP80) : etrig = 'e1' + if not bool(row.e1MatchesSingleE27WP80) and bool(row.e2MatchesSingleE27WP80) : etrig = 'e2' + + allmcCorrections= mcCorrections.get_electronId_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronId_corrections13_MVA(row, 'e2') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e2') * mcCorrections.get_trigger_corrections_MVA(row, etrig) + + + trUp_mcCorrections = mcCorrections.get_electronId_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronId_corrections13_MVA(row, 'e2') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e2') * mcCorrections.get_trigger_corrections_p1s_MVA(row, etrig) + trDown_mcCorrections = mcCorrections.get_electronId_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronId_corrections13_MVA(row, 'e2') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e2') * mcCorrections.get_trigger_corrections_m1s_MVA(row, etrig) + + e1idUp_mcCorrections= mcCorrections.get_electronId_corrections13_p1s_MVA(row, 'e1') *\ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronId_corrections13_MVA(row, 'e2') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e2') * mcCorrections.get_trigger_corrections_MVA(row, etrig) + e1idDown_mcCorrections= mcCorrections.get_electronId_corrections13_m1s_MVA(row, 'e1') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronId_corrections13_MVA(row, 'e2') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e2') * mcCorrections.get_trigger_corrections_MVA(row, etrig) + e2idUp_mcCorrections= mcCorrections.get_electronId_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronId_corrections13_p1s_MVA(row, 'e2') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e2') * mcCorrections.get_trigger_corrections_MVA(row, etrig) + e2idDown_mcCorrections= mcCorrections.get_electronId_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronId_corrections13_m1s_MVA(row, 'e2') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e2') * mcCorrections.get_trigger_corrections_MVA(row, etrig) + + e1isoUp_mcCorrections= mcCorrections.get_electronId_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronIso_corrections13_p1s_MVA(row, 'e1') * \ + mcCorrections.get_electronId_corrections13_MVA(row, 'e2') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e2') * mcCorrections.get_trigger_corrections_MVA(row, etrig) + e1isoDown_mcCorrections= mcCorrections.get_electronId_corrections13_m1s_MVA(row, 'e1') * \ + mcCorrections.get_electronIso_corrections13_p1s_MVA(row, 'e1') * \ + mcCorrections.get_electronId_corrections13_MVA(row, 'e2') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e2') * mcCorrections.get_trigger_corrections_MVA(row, etrig) + e2isoUp_mcCorrections= mcCorrections.get_electronId_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronId_corrections13_MVA(row, 'e2') * \ + mcCorrections.get_electronIso_corrections13_p1s_MVA(row, 'e2') * mcCorrections.get_trigger_corrections_MVA(row, etrig) + e2isoDown_mcCorrections= mcCorrections.get_electronId_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronId_corrections13_MVA(row, 'e2') * \ + mcCorrections.get_electronIso_corrections13_m1s_MVA(row, 'e2') * mcCorrections.get_trigger_corrections_MVA(row, etrig) + + + #pucorrlist = self.pucorrector(row.nTruePU) + + weight = self.pucorrector(row.nTruePU) *\ + allmcCorrections + weight_up = self.pucorrectorUp(row.nTruePU) *\ + allmcCorrections + weight_down = self.pucorrectorDown(row.nTruePU) *\ + allmcCorrections + + weight_tr_up = self.pucorrector(row.nTruePU) *\ + trUp_mcCorrections + weight_tr_down = self.pucorrector(row.nTruePU) *\ + trDown_mcCorrections + + + weight_e1id_up = self.pucorrector(row.nTruePU) *\ + e1idUp_mcCorrections + weight_e2id_up = self.pucorrector(row.nTruePU) *\ + e2idUp_mcCorrections + weight_e1id_down = self.pucorrector(row.nTruePU) *\ + e1idDown_mcCorrections + weight_e2id_down = self.pucorrector(row.nTruePU) *\ + e2idDown_mcCorrections + weight_e1iso_up = self.pucorrector(row.nTruePU) *\ + e1isoUp_mcCorrections + weight_e2iso_up = self.pucorrector(row.nTruePU) *\ + e2isoUp_mcCorrections + weight_e1iso_down = self.pucorrector(row.nTruePU) *\ + e1isoDown_mcCorrections + weight_e2iso_down = self.pucorrector(row.nTruePU) *\ + e2isoDown_mcCorrections + + return [weight, weight_up, weight_down, weight_tr_up, weight_tr_down, weight_e1id_up, weight_e1id_down, weight_e1iso_up, weight_e1iso_down, weight_e2id_up, weight_e2id_down, weight_e2iso_up, weight_e2iso_down] + + + +## + def begin(self): + sign=['os', 'ss'] + jets = [0,1,2,3] + folder=[] + pudir = ['','p1s/', 'm1s/','trp1s/', 'trm1s/', 'e1idp1s/','e1idm1s/', 'e1isop1s/','e1isom1s/','e2idp1s/','e2idm1s/', 'e2isop1s/','e2isom1s/'] + + + for d in pudir : + for i in sign: + folder.append(d+i) + for j in jets: + folder.append(d+i+'/'+str(j)) + + #self.book('jobInfo', "jobInfo", "jobInfo", "inputfilename/C:events/l", type=pytree.PyTree) + + + + for f in folder: + #print f, f.startswith('os'), f.startswith('ss') + if f.startswith('os') or f.startswith('ss') : + self.book(f, "evtInfo", "evtInfo", "run/l:lumi/l:evt/l", type=pytree.PyTree) + + self.book(f,"e1Pt", "e1 p_{T}", 200, 0, 200) + self.book(f,"e1Phi", "e1 phi", 100, -3.2, 3.2) + self.book(f,"e1Eta", "e1 eta", 50, -2.5, 2.5) + self.book(f,"e2Pt", "e2 p_{T}", 200, 0, 200) + self.book(f,"e2Phi", "e2 phi", 100, -3.2, 3.2) + self.book(f,"e2Eta", "e2 eta", 50, -2.5, 2.5) + + self.book(f, "e1e2_DeltaPhi", "e1-e2 DeltaPhi" , 50, 0, 3.2) + self.book(f, "e1e2_DeltaR", "e1-e2 DeltaR" , 50, 0, 3.2) + + self.book(f, "e1e2Mass", "e1e2 Inv Mass", 320, 0, 320) + + self.book(f, "pfMetEt", "pfMetEt", 50, 0, 100) + self.book(f, "type1_pfMetEt", "type1_pfMetEt", 50, 0, 100) + self.book(f, "mvaMetEt", "mvaMetEt", 50, 0, 100) + self.book(f, "pfMetPhi", "pfMetPhi", 100, -3.2, 3.2) + self.book(f, "type1_pfMetPhi", "type1_pfMetPhi", 100, -3.2, 3.2) + self.book(f, "mvaMetPhi", "mvaMetPhi", 100, -3.2, 3.2) + + self.book(f, "type1_pfMetEt_par", "type1_pfMetEt_par", 100, -100, 100) + self.book(f, "type1_pfMetEt_perp", "type1_pfMetEt_perp", 50, 0, 100) + self.book(f, "pfMetEt_par", "pfMetEt_par", 100, -100, 100) + self.book(f, "pfMetEt_perp", "pfMetEt_perp", 50, 0, 100) + self.book(f, "mvaMetEt_par", "mvaMetEt_par", 100, -100, 100) + self.book(f, "mvaMetEt_perp", "mvaMetEt_perp", 50, 0, 100) + + + self.book(f, "e1PFMET_DeltaPhi_Ty1", "e1-type1PFMET DeltaPhi" , 50, 0, 3.2) + self.book(f, "e1PFMET_Mt_Ty1", "e1-type1PFMET M_{T}" , 200, 0, 200) + self.book(f, "e1PFMET_DeltaPhi", "e1-PFMET DeltaPhi" , 50, 0, 3.2) + self.book(f, "e1PFMET_Mt", "e1-PFMET M_{T}" , 200, 0, 200) + self.book(f, "e1MVAMET_DeltaPhi", "e1-MVAMET DeltaPhi" , 50, 0, 3.2) + self.book(f, "e1MVAMET_Mt", "e1-MVAMET M_{T}" , 200, 0, 200) + + self.book(f, "e2PFMET_DeltaPhi_Ty1", "e2-type1PFMET DeltaPhi" , 50, 0, 3.2) + self.book(f, "e2PFMET_Mt_Ty1", "e2-type1PFMET M_{T}" , 200, 0, 200) + self.book(f, "e2PFMET_DeltaPhi", "e2-PFMET DeltaPhi" , 50, 0, 3.2) + self.book(f, "e2PFMET_Mt", "e2-PFMET M_{T}" , 200, 0, 200) + self.book(f, "e2MVAMET_DeltaPhi", "e2-MVAMET DeltaPhi" , 50, 0, 3.2) + self.book(f, "e2MVAMET_Mt", "e2-MVAMET M_{T}" , 200, 0, 200) + + + self.book(f,"pfMetEt_jes","pfMetEt_jes", 50, 0, 100) + self.book(f,"pfMetPhi_jes","pfMetPhi_jes", 100, -3.2, 3.2) + self.book(f,"pfMetEt_mes","pfMetEt_mes",50, 0, 100 ) + self.book(f,"pfMetPhi_mes","pfMetPhi_mes", 100, -3.2, 3.2) + self.book(f,"pfMetEt_tes","pfMetEt_tes", 50, 0, 100) + self.book(f,"pfMetPhi_tes","pfMetPhi_tes", 100, -3.2, 3.2) + self.book(f,"pfMetEt_ees","pfMetEt_ees", 50, 0, 100) + self.book(f,"pfMetPhi_ees","pfMetPhi_ees", 100, -3.2, 3.2) + self.book(f,"pfMetEt_ues","pfMetEt_ues", 50, 0, 100) + self.book(f,"pfMetPhi_ues", "pfMetPhi_ues", 100, -3.2, 3.2) + + self.book(f,"pfMetEt_perp_jes","pfMetEt_perp_jes", 50, 0, 100) + self.book(f,"pfMetEt_perp_mes","pfMetEt_perp_mes", 50, 0, 100 ) + self.book(f,"pfMetEt_perp_tes","pfMetEt_perp_tes", 50, 0, 100) + self.book(f,"pfMetEt_perp_ees","pfMetEt_perp_ees", 50, 0, 100) + self.book(f,"pfMetEt_perp_ues","pfMetEt_perp_ues", 50, 0, 100) + + self.book(f,"pfMetEt_par_jes","pfMetEt_par_jes", 100, -100, 100) + self.book(f,"pfMetEt_par_mes","pfMetEt_par_mes",100, -100, 100 ) + self.book(f,"pfMetEt_par_tes","pfMetEt_par_tes", 100, -100, 100) + self.book(f,"pfMetEt_par_ees","pfMetEt_par_ees", 100, -100, 100) + self.book(f,"pfMetEt_par_ues","pfMetEt_par_ues", 100, -100, 100) + + self.book(f,"e2PFMET_Mt_jes","e2PFMET_Mt_jes", 200, 0, 200 ) + self.book(f,"e2PFMET_Mt_mes","e2PFMET_Mt_mes", 200, 0, 200 ) + self.book(f,"e2PFMET_Mt_ees","e2PFMET_Mt_ees", 200, 0, 200 ) + self.book(f,"e2PFMET_Mt_tes","e2PFMET_Mt_tes", 200, 0, 200 ) + self.book(f,"e2PFMET_Mt_ues","e2PFMET_Mt_ues", 200, 0, 200 ) + + + self.book(f,"e1PFMET_Mt_jes","e1PFMET_Mt_jes", 200, 0, 200 ) + self.book(f,"e1PFMET_Mt_mes","e1PFMET_Mt_mes", 200, 0, 200 ) + self.book(f,"e1PFMET_Mt_ees","e1PFMET_Mt_ees", 200, 0, 200 ) + self.book(f,"e1PFMET_Mt_tes","e1PFMET_Mt_tes", 200, 0, 200 ) + self.book(f,"e1PFMET_Mt_ues","e1PFMET_Mt_ues", 200, 0, 200 ) + + self.book(f,"e2PFMET_DeltaPhi_jes","e2PFMET_DeltaPhi_jes", 50, 0, 3.2 ) + self.book(f,"e2PFMET_DeltaPhi_mes","e2PFMET_DeltaPhi_mes", 50, 0, 3.2 ) + self.book(f,"e2PFMET_DeltaPhi_ees","e2PFMET_DeltaPhi_ees", 50, 0, 3.2 ) + self.book(f,"e2PFMET_DeltaPhi_tes","e2PFMET_DeltaPhi_tes", 50, 0, 3.2 ) + self.book(f,"e2PFMET_DeltaPhi_ues","e2PFMET_DeltaPhi_ues", 50, 0, 3.2 ) + + + + self.book(f,"e1PFMET_DeltaPhi_jes","e1PFMET_DeltaPhi_jes", 50, 0, 3.2 ) + self.book(f,"e1PFMET_DeltaPhi_mes","e1PFMET_DeltaPhi_mes", 50, 0, 3.2 ) + self.book(f,"e1PFMET_DeltaPhi_ees","e1PFMET_DeltaPhi_ees", 50, 0, 3.2 ) + self.book(f,"e1PFMET_DeltaPhi_tes","e1PFMET_DeltaPhi_tes", 50, 0, 3.2 ) + self.book(f,"e1PFMET_DeltaPhi_ues","e1PFMET_DeltaPhi_ues", 50, 0, 3.2 ) + + + self.book(f, "nPV", "N of vertices", 100, 0, 100) + self.book(f, "nPV_unweighted", "unweighted N of vertices", 100, 0, 100) + + def fill_histos(self, row, f='os', fakeRate = False): + + weight = self.event_weight(row) # pu central, +1 sigma, -1sigma + + histos = self.histograms + pudir =[''] + if row.run < 2: pudir.extend( ['p1s/', 'm1s/', 'trp1s/', 'trm1s/', 'e1idp1s/','e1idm1s/', 'e1isop1s/','e1isom1s/','e2idp1s/','e2idm1s/', 'e2isop1s/','e2isom1s/' ]) + + for n,d in enumerate(pudir) : + + folder = d+f + + histos[folder+'/e1Pt'].Fill(row.e1Pt, weight[n]) + histos[folder+'/e1Eta'].Fill(row.e1Eta, weight[n]) + histos[folder+'/e1Phi'].Fill(row.e1Phi, weight[n]) + + histos[folder+'/e2Pt'].Fill(row.e2Pt, weight[n]) + histos[folder+'/e2Eta'].Fill(row.e2Eta, weight[n]) + histos[folder+'/e2Phi'].Fill(row.e2Phi, weight[n]) + + histos[folder+'/e1e2_DeltaPhi'].Fill(deltaPhi(row.e1Phi, row.e2Phi), weight[n]) + histos[folder+'/e1e2_DeltaR'].Fill(row.e1_e2_DR, weight[n]) + + histos[folder+'/e1e2Mass'].Fill(row.e1_e2_Mass, weight[n]) + + histos[folder+'/e1PFMET_DeltaPhi'].Fill(deltaPhi(row.e1Phi, row.pfMetPhi), weight[n]) + histos[folder+'/e1MVAMET_DeltaPhi'].Fill(deltaPhi(row.e1Phi, row.mva_metPhi), weight[n]) + histos[folder+'/e1PFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.e1Phi, row.type1_pfMetPhi), weight[n]) + histos[folder+'/e1PFMET_Mt'].Fill(row.e1MtToPFMET, weight[n]) + histos[folder+'/e1MVAMET_Mt'].Fill(row.e1MtToMVAMET, weight[n]) + histos[folder+'/e1PFMET_Mt_Ty1'].Fill(row.e1MtToPfMet_Ty1, weight[n]) + + histos[folder+'/type1_pfMetEt'].Fill(row.type1_pfMetEt, weight[n]) + histos[folder+'/pfMetEt'].Fill(row.pfMetEt, weight[n]) + histos[folder+'/mvaMetEt'].Fill(row.mva_metEt, weight[n]) + + histos[folder+'/type1_pfMetPhi'].Fill(row.type1_pfMetPhi, weight[n]) + histos[folder+'/pfMetPhi'].Fill(row.pfMetPhi, weight[n]) + histos[folder+'/mvaMetPhi'].Fill(row.mva_metPhi, weight[n]) + + zphi = Z(row).Phi() + histos[folder+'/type1_pfMetEt_par'].Fill(row.pfMetEt*cos(deltaPhi(zphi, row.type1_pfMetPhi)), weight[n]) + histos[folder+'/type1_pfMetEt_perp'].Fill(row.pfMetEt*sin(deltaPhi(zphi, row.type1_pfMetPhi)), weight[n]) + histos[folder+'/pfMetEt_par'].Fill(row.pfMetEt*cos(deltaPhi(zphi, row.pfMetPhi)), weight[n]) + histos[folder+'/pfMetEt_perp'].Fill(row.pfMetEt*sin(deltaPhi(zphi, row.pfMetPhi)), weight[n]) + histos[folder+'/mvaMetEt_par'].Fill(row.mva_metEt*cos(deltaPhi(zphi, row.mva_metPhi)), weight[n]) + histos[folder+'/mvaMetEt_perp'].Fill(row.mva_metEt*sin(deltaPhi(zphi, row.mva_metPhi)), weight[n]) + + histos[folder+'/e2PFMET_DeltaPhi'].Fill(deltaPhi(row.e2Phi, row.pfMetPhi), weight[n]) + histos[folder+'/e2MVAMET_DeltaPhi'].Fill(deltaPhi(row.e2Phi, row.mva_metPhi), weight[n]) + histos[folder+'/e2PFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.e2Phi, row.type1_pfMetPhi), weight[n]) + histos[folder+'/e2PFMET_Mt'].Fill(row.e2MtToPFMET, weight[n]) + histos[folder+'/e2PFMET_Mt_Ty1'].Fill(row.e2MtToPfMet_Ty1, weight[n]) + histos[folder+'/e2MVAMET_Mt'].Fill(row.e2MtToMVAMET, weight[n]) + + histos[folder+'/pfMetEt_jes'].Fill(row.pfMet_jes_Et, weight[n]) + histos[folder+'/pfMetPhi_jes'].Fill(row.pfMet_jes_Phi, weight[n]) + histos[folder+'/pfMetEt_mes'].Fill(row.pfMet_mes_Et, weight[n]) + histos[folder+'/pfMetPhi_mes'].Fill(row.pfMet_mes_Phi, weight[n]) + histos[folder+'/pfMetEt_tes'].Fill(row.pfMet_tes_Et, weight[n]) + histos[folder+'/pfMetPhi_tes'].Fill(row.pfMet_tes_Phi, weight[n]) + histos[folder+'/pfMetEt_ees'].Fill(row.pfMet_ees_Et, weight[n]) + histos[folder+'/pfMetPhi_ees'].Fill(row.pfMet_ees_Phi, weight[n]) + histos[folder+'/pfMetEt_ues'].Fill(row.pfMet_ues_Et, weight[n]) + histos[folder+'/pfMetPhi_ues'].Fill(row.pfMet_ues_Phi, weight[n]) + + histos[folder+'/pfMetEt_par_jes'].Fill(row.pfMet_jes_Et*cos(deltaPhi(zphi, row.pfMet_jes_Phi)), weight[n]) + histos[folder+'/pfMetEt_par_mes'].Fill(row.pfMet_mes_Et*cos(deltaPhi(zphi, row.pfMet_mes_Phi)), weight[n]) + histos[folder+'/pfMetEt_par_tes'].Fill(row.pfMet_tes_Et*cos(deltaPhi(zphi, row.pfMet_tes_Phi)), weight[n]) + histos[folder+'/pfMetEt_par_ees'].Fill(row.pfMet_ees_Et*cos(deltaPhi(zphi, row.pfMet_ees_Phi)), weight[n]) + histos[folder+'/pfMetEt_par_ues'].Fill(row.pfMet_ues_Et*cos(deltaPhi(zphi, row.pfMet_ues_Phi)), weight[n]) + + histos[folder+'/pfMetEt_perp_jes'].Fill(row.pfMet_jes_Et*sin(deltaPhi(zphi, row.pfMet_jes_Phi)), weight[n]) + histos[folder+'/pfMetEt_perp_mes'].Fill(row.pfMet_mes_Et*sin(deltaPhi(zphi, row.pfMet_mes_Phi)), weight[n]) + histos[folder+'/pfMetEt_perp_tes'].Fill(row.pfMet_tes_Et*sin(deltaPhi(zphi, row.pfMet_tes_Phi)), weight[n]) + histos[folder+'/pfMetEt_perp_ees'].Fill(row.pfMet_ees_Et*sin(deltaPhi(zphi, row.pfMet_ees_Phi)), weight[n]) + histos[folder+'/pfMetEt_perp_ues'].Fill(row.pfMet_ues_Et*sin(deltaPhi(zphi, row.pfMet_ues_Phi)), weight[n]) + + + histos[folder+'/e2PFMET_Mt_jes'].Fill(row.e2MtToPfMet_jes, weight[n]) + histos[folder+'/e2PFMET_Mt_mes'].Fill(row.e2MtToPfMet_mes, weight[n]) + histos[folder+'/e2PFMET_Mt_ees'].Fill(row.e2MtToPfMet_ees, weight[n]) + histos[folder+'/e2PFMET_Mt_tes'].Fill(row.e2MtToPfMet_tes, weight[n]) + histos[folder+'/e2PFMET_Mt_ues'].Fill(row.e2MtToPfMet_ues, weight[n]) + + histos[folder+'/e1PFMET_Mt_jes'].Fill(row.e1MtToPfMet_jes, weight[n]) + histos[folder+'/e1PFMET_Mt_mes'].Fill(row.e1MtToPfMet_mes, weight[n]) + histos[folder+'/e1PFMET_Mt_ees'].Fill(row.e1MtToPfMet_ees, weight[n]) + histos[folder+'/e1PFMET_Mt_tes'].Fill(row.e1MtToPfMet_tes, weight[n]) + histos[folder+'/e1PFMET_Mt_ues'].Fill(row.e1MtToPfMet_ues, weight[n]) + + histos[folder+'/e2PFMET_DeltaPhi_jes'].Fill(deltaPhi(row.e2Phi, row.pfMet_jes_Phi), weight[n]) + histos[folder+'/e2PFMET_DeltaPhi_mes'].Fill(deltaPhi(row.e2Phi, row.pfMet_mes_Phi), weight[n]) + histos[folder+'/e2PFMET_DeltaPhi_ees'].Fill(deltaPhi(row.e2Phi, row.pfMet_ees_Phi), weight[n]) + histos[folder+'/e2PFMET_DeltaPhi_tes'].Fill(deltaPhi(row.e2Phi, row.pfMet_tes_Phi), weight[n]) + histos[folder+'/e2PFMET_DeltaPhi_ues'].Fill(deltaPhi(row.e2Phi, row.pfMet_ues_Phi), weight[n]) + + histos[folder+'/e1PFMET_DeltaPhi_jes'].Fill(deltaPhi(row.e1Phi, row.pfMet_jes_Phi), weight[n]) + histos[folder+'/e1PFMET_DeltaPhi_mes'].Fill(deltaPhi(row.e1Phi, row.pfMet_mes_Phi), weight[n]) + histos[folder+'/e1PFMET_DeltaPhi_ees'].Fill(deltaPhi(row.e1Phi, row.pfMet_ees_Phi), weight[n]) + histos[folder+'/e1PFMET_DeltaPhi_tes'].Fill(deltaPhi(row.e1Phi, row.pfMet_tes_Phi), weight[n]) + histos[folder+'/e1PFMET_DeltaPhi_ues'].Fill(deltaPhi(row.e1Phi, row.pfMet_ues_Phi), weight[n]) + +## still some type1 met histos missing + + histos[folder+'/nPV'].Fill(row.nvtx, weight[n]) + histos[folder+'/nPV_unweighted'].Fill(row.nvtx) + + + + + + + def process(self): + event = () + filename = 'unnamed' + evts_processed = 0 + #set_trace() + for row in self.tree: + #for i, row in enumerate(self.tree): + # if i >= 100: + # return + + #current_file = self.tree.inputfilename + #if filename != 'unnamed' and current_file <> filename: + # self.histograms['jobInfo/jobInfo'].Fill([[i for i in filename], evts_processed]) + #if not filename == 'unnamed' or current_file <> filename: + # filename = current_file + evts_processed += 1 + #self.histograms[folder+'/jobInfo'].Fill(row) + + + jn = row.jetVeto30 + if jn > 3 : jn = 3 + sign = 'ss' if row.e1_e2_SS else 'os' + #if row.run > 2 : #apply the trigger to data only (MC triggers enter in the scale factors) + if not bool(row.singleE27WP80Pass) : continue + if not bool(row.e1MatchesSingleE27WP80) and not bool(row.e1MatchesSingleE27WP80) : continue + + if jn != 0 and row.bjetCSVVeto30!=0 : continue + + if row.e1Pt < 30 : continue + if row.e2Pt < 30 : continue + if not abs(row.e1_e2_Mass-91.2) < 20: continue + + if not selections.eSelection(row, 'e1'): continue + if not selections.lepton_id_iso(row, 'e1', 'eid13Tight_etauiso01'): continue + if abs(row.e1Eta) > 1.4442 and abs(row.e1Eta) < 1.566 : continue + + if not selections.eSelection(row, 'e2'): continue + if not selections.lepton_id_iso(row, 'e2', 'eid13Tight_etauiso01'): continue + if abs(row.e2Eta) > 1.4442 and abs(row.e2Eta) < 1.566 : continue + + + #if not selections.vetos(row) : continue + if row.muVetoPt5IsoIdVtx : continue + if row.eVetoCicLooseIso : continue # change it with Loose + if row.tauVetoPt20EleTight3MuLoose : continue +# if row.tauHpsVetoPt20 : continue + + + folder = sign + self.histograms[folder+'/evtInfo'].Fill(row) + new_event = (row.run, row.lumi, row.evt) + if event != new_event : + event = new_event + self.fill_histos(row, folder) + folder = sign+'/'+str(int(jn)) + self.fill_histos(row, folder) + + if filename != 'unnamed': + self.histograms['jobInfo/jobInfo'].Fill([[i for i in filename], evts_processed]) + + def finish(self): + self.write_histos() + + diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py new file mode 100644 index 00000000..35a1af8f --- /dev/null +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -0,0 +1,485 @@ +from ETauTree import ETauTree +import os +import ROOT +import math +import glob +import array +import mcCorrections +import baseSelections as selections +import FinalStateAnalysis.PlotTools.pytree as pytree +from FinalStateAnalysis.PlotTools.decorators import memo_last +from FinalStateAnalysis.PlotTools.MegaBase import MegaBase +from math import sqrt, pi, cos +from fakerate_functions import fakerate_central_histogram, fakerate_p1s_histogram, fakerate_m1s_histogram + + + + +def collmass(row, met, metPhi): + ptnu =abs(met*cos(deltaPhi(metPhi, row.tPhi))) + visfrac = row.tPt/(row.tPt+ptnu) + #print met, cos(deltaPhi(metPhi, row.tPhi)), ptnu, visfrac + return (row.e_t_Mass / sqrt(visfrac)) + +def deltaPhi(phi1, phi2): + PHI = abs(phi1-phi2) + if PHI<=pi: + return PHI + else: + return 2*pi-PHI +def deltaR(phi1, ph2, eta1, eta2): + deta = eta1 - eta2 + dphi = abs(phi1-phi2) + if (dphi>pi) : dphi = 2*pi-dphi + return sqrt(deta*deta + dphi*dphi); + +class LFVHETauAnalyzerMVA(MegaBase): + tree = 'et/final/Ntuple' + def __init__(self, tree, outfile, **kwargs): + self.channel='ET' + super(LFVHETauAnalyzerMVA, self).__init__(tree, outfile, **kwargs) + self.tree = ETauTree(tree) + self.out=outfile + self.histograms = {} + self.pucorrector = mcCorrections.make_puCorrector('singlee') + self.pucorrectorUp = mcCorrections.make_puCorrectorUp('singlee') + self.pucorrectorDown = mcCorrections.make_puCorrectorDown('singlee') + + + @staticmethod + def tau_veto(row): + if not row.tAntiMuonLoose2 or not row.tAntiElectronMVA5Tight or not row.tDecayFinding : + return False + + @staticmethod + def obj1_matches_gen(row): + return row.eGenPdgId == -1*row.eCharge*11 + @staticmethod + def obj3_matches_gen(row): + return t.genDecayMode != -2 + + + def event_weight(self, row): + if row.run > 2: #FIXME! add tight ID correction + return [1.] + allmcCorrections= mcCorrections.get_electronId_corrections13_MVA(row, 'e') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e') * mcCorrections.get_trigger_corrections_MVA(row,'e') + + + trUp_mcCorrections = mcCorrections.get_electronId_corrections13_MVA(row, 'e') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e') * mcCorrections.get_trigger_corrections_p1s_MVA(row,'e') + trDown_mcCorrections = mcCorrections.get_electronId_corrections13_MVA(row, 'e') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e') * mcCorrections.get_trigger_corrections_m1s_MVA(row,'e') + + eidUp_mcCorrections= mcCorrections.get_electronId_corrections13_p1s_MVA(row, 'e') *\ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e') * mcCorrections.get_trigger_corrections_MVA(row,'e') + eidDown_mcCorrections= mcCorrections.get_electronId_corrections13_m1s_MVA(row, 'e') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e') * mcCorrections.get_trigger_corrections_MVA(row,'e') + eisoUp_mcCorrections= mcCorrections.get_electronId_corrections13_MVA(row, 'e') * \ + mcCorrections.get_electronIso_corrections13_p1s_MVA(row, 'e') * mcCorrections.get_trigger_corrections_MVA(row,'e') + eisoDown_mcCorrections= mcCorrections.get_electronId_corrections13_m1s_MVA(row, 'e') * \ + mcCorrections.get_electronIso_corrections13_p1s_MVA(row, 'e') * mcCorrections.get_trigger_corrections_MVA(row,'e') + + #pucorrlist = self.pucorrector(row.nTruePU) + + weight = self.pucorrector(row.nTruePU) *\ + allmcCorrections + weight_up = self.pucorrectorUp(row.nTruePU) *\ + allmcCorrections + weight_down = self.pucorrectorDown(row.nTruePU) *\ + allmcCorrections + + weight_tr_up = self.pucorrector(row.nTruePU) *\ + trUp_mcCorrections + weight_tr_down = self.pucorrector(row.nTruePU) *\ + trDown_mcCorrections + + + weight_eid_up = self.pucorrector(row.nTruePU) *\ + eidUp_mcCorrections + weight_eid_down = self.pucorrector(row.nTruePU) *\ + eidDown_mcCorrections + weight_eiso_up = self.pucorrector(row.nTruePU) *\ + eisoUp_mcCorrections + weight_eiso_down = self.pucorrector(row.nTruePU) *\ + eisoDown_mcCorrections + + return [weight, weight_up, weight_down, weight_tr_up, weight_tr_down, weight_eid_up, weight_eid_down, weight_eiso_up, weight_eiso_down,] + +## + def begin(self): + + processtype=['gg'] + threshold=['ept30'] + sign=['os', 'ss'] + jetN = [0, 1, 2, 3] + folder=[] + pudir = ['','p1s/', 'm1s/','trp1s/', 'trm1s/', 'eidp1s/','eidm1s/', 'eisop1s/','eisom1s/', 'tLoose/','tLooseUp/','tLooseDown/', 'tLooseUnweight/' ] + + for d in pudir : + for i in sign: + for j in processtype: + for k in threshold: + folder.append(d+i+'/'+j+'/'+k) + for jn in jetN: + + folder.append(d+i+'/'+j+'/'+k +'/'+str(jn)) + folder.append(d+i+'/'+j+'/'+k +'/'+str(jn)+'/selected') + + for f in folder: + self.book(f,"tPt", "tau p_{T}", 200, 0, 200) + self.book(f,"tPhi", "tau phi", 100, -3.2, 3.2) + self.book(f,"tEta", "tau eta", 50, -2.5, 2.5) + + self.book(f,"ePt", "e p_{T}", 200, 0, 200) + self.book(f,"ePhi", "e phi", 100, -3.2, 3.2) + self.book(f,"eEta", "e eta", 50, -2.5, 2.5) + + self.book(f, "et_DeltaPhi", "e-tau DeltaPhi" , 50, 0, 3.2) + self.book(f, "et_DeltaR", "e-tau DeltaR" , 50, 0, 3.2) + + self.book(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320) + self.book(f, "h_collmass_mvamet", "h_collmass_mvamet", 32, 0, 320) + self.book(f, "h_collmass_pfmet_Ty1", "h_collmass_pfmet_Ty1", 32, 0, 320) + self.book(f, "h_collmass_pfmet_jes", "h_collmass_pfmet_jes", 50, 0, 100) + self.book(f, "h_collmass_pfmet_mes", "h_collmass_pfmet_mes", 50, 0, 100 ) + self.book(f, "h_collmass_pfmet_tes", "h_collmass_pfmet_tes", 50, 0, 100) + self.book(f, "h_collmass_pfmet_ees", "h_collmass_pfmet_ees", 50, 0, 100) + self.book(f, "h_collmass_pfmet_ues", "h_collmass_pfmet_ues", 50, 0, 100) + + + + self.book(f, "h_collmassSpread_pfmet", "h_collmassSpread_pfmet", 40, -100, 100) + self.book(f, "h_collmassSpread_mvamet", "h_collmassSpread_mvamet", 40, -100, 100) + self.book(f, "h_collmassSpread_lowPhi_pfmet", "h_collmassSpread_lowPhi_pfmet", 40, -100, 100) + self.book(f, "h_collmassSpread_lowPhi_mvamet", "h_collmassSpread_lowPhi_mvamet", 40, -100, 100) + self.book(f, "h_collmassSpread_highPhi_pfmet", "h_collmassSpread_highPhi_pfmet", 40, -100, 100) + self.book(f, "h_collmassSpread_highPhi_mvamet", "h_collmassSpread_highPhi_mvamet", 40, -100, 100) + self.book(f, "h_collmass_lowPhi_pfmet", "h_collmass_lowPhi_pfmet", 32, 0, 320) + self.book(f, "h_collmass_lowPhi_mvamet", "h_collmass_lowPhi_mvamet", 32, 0, 320) + self.book(f, "h_collmass_highPhi_pfmet", "h_collmass_highPhi_pfmet", 32, 0, 320) + self.book(f, "h_collmass_highPhi_mvamet", "h_collmass_highPhi_mvamet", 32, 0, 320) + self.book(f, "h_collmass_vs_dPhi_pfmet", "h_collmass_vs_dPhi_pfmet", 50, 0, 3.2, 32, 0, 320, type=ROOT.TH2F) + self.book(f, "h_collmass_vs_dPhi_mvamet", "h_collmass_vs_dPhi_mvamet", 50, 0, 3.2, 32, 0, 320, type=ROOT.TH2F) + self.book(f, "h_collmassSpread_vs_dPhi_pfmet", "h_collmassSpread_vs_dPhi_pfmet", 50, 0, 3.2, 20, -100, 100, type=ROOT.TH2F) + self.book(f, "h_collmassSpread_vs_dPhi_mvamet", "h_collmassSpread_vs_dPhi_mvamet", 50, 0, 3.2, 20, -100, 100, type=ROOT.TH2F) + + self.book(f, "h_vismass", "h_vismass", 32, 0, 320) + + self.book(f, "type1_pfMetEt_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 50, 0, 3.2, 64, 0, 320, type=ROOT.TH2F) + self.book(f, "mvaMetEt_vs_dPhi", "MVAMet vs #Delta#phi(#tau,MVAMet)", 50, 0, 3.2, 64, 0, 320, type=ROOT.TH2F) + + self.book(f, "tPFMET_DeltaPhi", "tau-PFMET DeltaPhi" , 50, 0, 3.2) + self.book(f, "tPFMET_Mt", "tau-PFMET M_{T}" , 200, 0, 200) + self.book(f, "tPFMET_DeltaPhi_Ty1", "tau-type1PFMET DeltaPhi" , 50, 0, 3.2) + self.book(f, "tPFMET_Mt_Ty1", "tau-type1PFMET M_{T}" , 200, 0, 200) + self.book(f, 'tPFMET_Mt_jes', "tau-MVAMET M_{T} JES" , 200, 0, 200) + self.book(f, 'tPFMET_Mt_mes', "tau-MVAMET M_{T} JES" , 200, 0, 200) + self.book(f, 'tPFMET_Mt_ees', "tau-MVAMET M_{T} JES" , 200, 0, 200) + self.book(f, 'tPFMET_Mt_tes', "tau-MVAMET M_{T} JES" , 200, 0, 200) + self.book(f, 'tPFMET_Mt_ues', "tau-MVAMET M_{T} JES" , 200, 0, 200) + + self.book(f, "tMVAMET_DeltaPhi", "tau-MVAMET DeltaPhi" , 50, 0, 3.2) + self.book(f, "tMVAMET_Mt", "tau-MVAMET M_{T}" , 200, 0, 200) + + self.book(f, "ePFMET_DeltaPhi_Ty1", "e-type1PFMET DeltaPhi" , 50, 0, 3.2) + self.book(f, "ePFMET_Mt_Ty1", "e-type1PFMET M_{T}" , 200, 0, 200) + self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 50, 0, 3.2) + self.book(f, "ePFMET_Mt", "e-PFMET M_{T}" , 200, 0, 200) + self.book(f, 'ePFMET_Mt_jes', "e-MVAMET M_{T} JES" , 200, 0, 200) + self.book(f, 'ePFMET_Mt_mes', "e-MVAMET M_{T} JES" , 200, 0, 200) + self.book(f, 'ePFMET_Mt_ees', "e-MVAMET M_{T} JES" , 200, 0, 200) + self.book(f, 'ePFMET_Mt_tes', "e-MVAMET M_{T} JES" , 200, 0, 200) + self.book(f, 'ePFMET_Mt_ues', "e-MVAMET M_{T} JES" , 200, 0, 200) + #self.book(f, "ePFMET_Mt_Ty1_ues_minus", "e-type1PFMET M_{T} ues_minus" , 200, 0, 200) + #self.book(f, "ePFMET_Mt_Ty1_ues_plus", "e-type1PFMET M_{T} ues_plus" , 200, 0, 200) + self.book(f, 'ePFMET_Mt_jes_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) + self.book(f, 'ePFMET_Mt_mes_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) + self.book(f, 'ePFMET_Mt_ees_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) + self.book(f, 'ePFMET_Mt_tes_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) + self.book(f, 'ePFMET_Mt_ues_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) + self.book(f, 'ePFMET_Mt_jes_plus', "e-MVAMET M_{T} JES_plus" , 200, 0, 200) + self.book(f, 'ePFMET_Mt_mes_plus', "e-MVAMET M_{T} JES_plus" , 200, 0, 200) + self.book(f, 'ePFMET_Mt_ees_plus', "e-MVAMET M_{T} JES_plus" , 200, 0, 200) + self.book(f, 'ePFMET_Mt_tes_plus', "e-MVAMET M_{T} JES_plus" , 200, 0, 200) + self.book(f, 'ePFMET_Mt_ues_plus', "e-MVAMET M_{T} JES_plus" , 200, 0, 200) + + self.book(f, "eMVAMET_DeltaPhi", "e-MVAMET DeltaPhi" , 50, 0, 3.2) + self.book(f, "eMVAMET_Mt", "e-MVAMET M_{T}" , 200, 0, 200) + + self.book(f, "jetN_20", "Number of jets, p_{T}>20", 10, -0.5, 9.5) + self.book(f, "jetN_30", "Number of jets, p_{T}>30", 10, -0.5, 9.5) + + def fakerate_weights(self, tEta, central_weights, p1s_weights, m1s_weights): + frweight=[1.,1.,1.] + + #central_weights = fakerate_central_histogram(25,0, 2.5) + #p1s_weights = fakerate_central_histogram(25,0, 2.5) + #m1s_weights = fakerate_central_histogram(25,0, 2.5) + + for n,w in enumerate( central_weights ): + if abs(tEta) < w[1]: + break + frweight[0] = w[0] + frweight[1] = p1s_weights[n][0] + frweight[2] = m1s_weights[n][0] + + + return frweight; + + + + def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): + weight = self.event_weight(row) + histos = self.histograms + pudir =[''] + if row.run < 2: pudir.extend( ['p1s/', 'm1s/', 'trp1s/', 'trm1s/', 'eidp1s/','eidm1s/', 'eisop1s/','eisom1s/']) + looseList = ['tLoose/', 'tLooseUp/', 'tLooseDown/', 'tLooseUnweight/'] + + + + if bool(isTauTight) == False: + #print 'isTauTigh? ', isTauTight, ' in ', f + frweight_bv = frw[0]/(1.-frw[0]) + #print fakerate, frw[0], frweight + #err = abs(frw[0] - frw[1])* abs(frw[0]/((1-frw[0])*(1-frw[0])) + 1/(1-frw[0])) + err = 0.3/pow(1-frw[0], 2) #tau pog told to mu-tau group to use 30% uncertainty on tau fake rate. + frweight_p1s = frweight_bv*(1+err) + frweight_m1s = frweight_bv*(1-err) + + fr_weights = [frweight_bv, frweight_p1s, frweight_m1s] + #print frweight_bv, frw[0], row.tPt, row.tEta + for n, l in enumerate(looseList) : + frweight = weight[0]*fr_weights[n] if n < len(looseList)-1 else weight[0] + folder = l+f + #print folder , frweight, fr_weights[n], frw[0] + histos[folder+'/tPt'].Fill(row.tPt, frweight) + histos[folder+'/tEta'].Fill(row.tEta, frweight) + histos[folder+'/tPhi'].Fill(row.tPhi, frweight) + histos[folder+'/ePt'].Fill(row.ePt, frweight) + histos[folder+'/eEta'].Fill(row.eEta, frweight) + histos[folder+'/ePhi'].Fill(row.ePhi, frweight) + histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), frweight) + histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, frweight) + histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : + histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : + histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : + histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : + histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), frweight) + histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.pfMetPhi), frweight) + histos[folder+'/h_collmass_pfmet_jes'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_Phi), frweight) + histos[folder+'/h_collmass_pfmet_mes'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), frweight) + histos[folder+'/h_collmass_pfmet_tes'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), frweight) + histos[folder+'/h_collmass_pfmet_ees'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), frweight) + histos[folder+'/h_collmass_pfmet_ues'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), frweight) + + + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, frweight) + histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, frweight) + histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, frweight) + + histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.pfMetPhi), frweight) + histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), frweight) + histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), frweight) + histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, frweight) + histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, frweight) + histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, frweight) + #histos[folder+'/ePFMET_Mt_Ty1_ues_minus'].Fill(row.eMtToPfMet_Ty1_ues_minus, frweight) + #histos[folder+'/ePFMET_Mt_Ty1_ues_plus'].Fill(row.eMtToPfMet_Ty1_ues_plus, frweight) + histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, frweight) + histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, frweight) + histos[folder+'/ePFMET_Mt_jes'].Fill(row.eMtToPfMet_jes, frweight) + histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus, frweight) + histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, frweight) + histos[folder+'/ePFMET_Mt_mes'].Fill(row.eMtToPfMet_mes, frweight) + histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus, frweight) + histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, frweight) + histos[folder+'/ePFMET_Mt_ees'].Fill(row.eMtToPfMet_ees, frweight) + histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus, frweight) + histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, frweight) + histos[folder+'/ePFMET_Mt_tes'].Fill(row.eMtToPfMet_tes, frweight) + histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus, frweight) + histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, frweight) + histos[folder+'/ePFMET_Mt_ues'].Fill(row.eMtToPfMet_ues, frweight) + + + + histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), frweight) + histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), frweight) + histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), frweight) + histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, frweight) + histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, frweight) + histos[folder+'/tPFMET_Mt_jes'].Fill(row.tMtToPfMet_jes, frweight) + histos[folder+'/tPFMET_Mt_mes'].Fill(row.tMtToPfMet_mes, frweight) + histos[folder+'/tPFMET_Mt_ees'].Fill(row.tMtToPfMet_ees, frweight) + histos[folder+'/tPFMET_Mt_tes'].Fill(row.tMtToPfMet_tes, frweight) + histos[folder+'/tPFMET_Mt_ues'].Fill(row.tMtToPfMet_ues, frweight) + + histos[folder+'/jetN_20'].Fill(row.jetVeto20, frweight) + histos[folder+'/jetN_30'].Fill(row.jetVeto30, frweight) + + else: + for n,d in enumerate(pudir) : + + folder = d+f + histos[folder+'/tPt'].Fill(row.tPt, weight[n]) + histos[folder+'/tEta'].Fill(row.tEta, weight[n]) + histos[folder+'/tPhi'].Fill(row.tPhi, weight[n]) + histos[folder+'/ePt'].Fill(row.ePt, weight[n]) + histos[folder+'/eEta'].Fill(row.eEta, weight[n]) + histos[folder+'/ePhi'].Fill(row.ePhi, weight[n]) + histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), weight[n]) + histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, weight[n]) + histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : + histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : + histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : + histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : + histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, weight[n]) + histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, weight[n]) + histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, weight[n]) + histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) + histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), weight[n]) + histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, weight[n]) + histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, weight[n]) + histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), weight[n]) + histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), weight[n]) + histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, weight[n]) + histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, weight[n]) + histos[folder+'/jetN_20'].Fill(row.jetVeto20, weight[n]) + histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight[n]) + + + + + + def process(self): + + + central_weights = fakerate_central_histogram(25,0, 2.5) + + p1s_weights = fakerate_p1s_histogram(25,0, 2.5)#fakerate_p1s_histogram(25,0, 2.5) + + m1s_weights = fakerate_m1s_histogram(25,0, 2.5)#fakerate_m1s_histogram(25,0, 2.5) + + + + frw = [] + myevent =() + for row in self.tree: + sign = 'ss' if row.e_t_SS else 'os' + processtype = '' ## use a line as for sign when the vbf when selections are defined + ptthreshold = [30] + processtype ='gg'##changed from 20 + jn = row.jetVeto30 + if jn > 3 : jn = 3 + #if row.run > 2 : #apply the trigger to data only (MC triggers enter in the scale factors) + if not bool(row.singleE27WP80Pass) : continue + + + if not bool(row.eMatchesSingleE27WP80): continue + + if not selections.eSelection(row, 'e'): continue + + if not selections.lepton_id_iso(row, 'e', 'eid13Tight_etauiso01'): continue + + if abs(row.eEta) > 1.4442 and abs(row.eEta) < 1.566 : continue + if not selections.tauSelection(row, 't'): continue + + if row.bjetCSVVeto30!=0 : continue + if row.ePt < 30 : continue + #if row.eMtToPFMET <40 : continue + + if not row.tAntiElectronMVA5Tight : continue + if not row.tAntiMuon2Loose : continue + + if not row.tLooseIso3Hits : continue + + #isTauTight = False + frw=self.fakerate_weights(row.tEta, central_weights, p1s_weights, m1s_weights ) + + #print bool(row.tTightIso3Hits) + + if row.tauVetoPt20EleTight3MuLoose : continue + #if row.tauHpsVetoPt20 : continue + if row.muVetoPt5IsoIdVtx : continue + if row.eVetoCicLooseIso : continue # change it with Loose + + for j in ptthreshold: + folder = sign+'/'+processtype+'/ept'+str(j)+'/'+str(int(jn)) + + #if (row.run, row.lumi, row.evt, row.ePt, row.tPt)==myevent: continue + if (row.run, row.lumi, row.evt)==myevent: continue + + if myevent!=() and (row.run, row.lumi, row.evt)==(myevent[0], myevent[1], myevent[2]): print row.ePt, row.tPt + #myevent=(row.run, row.lumi, row.evt, row.ePt, row.tPt) + myevent=(row.run, row.lumi, row.evt) + isTauTight = bool(row.tTightIso3Hits) + #print row.tLooseIso3Hits, row.tTightIso3Hits, isTauTight + + if row.ePt < j : continue + + self.fill_histos(row, folder,isTauTight, frw) + + #print row.run, row.lumi, row.evt, row.ePt, row.tPt, row.tMtToPFMET, row.eEta, row.tEta, row.ePhi, row.tPhi + #print 'histo filled' + #selections + if jn == 0 : + + if row.tPt < 35: continue + if row.ePt < 40 : continue + if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue + if row.tMtToPFMET > 50 : continue + + + if jn == 1 : + if row.tPt < 40: continue + if row.ePt < 35 : continue + if row.tMtToPFMET > 35 : continue + if jn == 2 : + if row.tPt < 40: continue + if row.ePt < 30 : continue # no cut as only electrons with pt>30 are in the ntuples + if row.tMtToPFMET > 35 : continue + if row.vbfMass < 550 : continue + if row.vbfDeta < 3.5 : continue + folder = sign+'/'+processtype+'/ept'+str(j)+'/'+str(int(jn))+'/selected' + self.fill_histos(row, folder, isTauTight,frw) + + + + + + def finish(self): + self.write_histos() + + diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile new file mode 100644 index 00000000..5d5274e1 --- /dev/null +++ b/lfvetau/Rakefile @@ -0,0 +1,270 @@ +# Get common recipes +recipes = ENV['fsa'] + '/PlotTools/rake/recipes.rake' +import recipes + +require ENV['CMSSW_BASE'] + '/src/FinalStateAnalysis/PlotTools/rake/tools.rb' +require 'pathname' + +$jobid = ENV['jobid'] + +$blind = ENV['blind'] +# Figure out what run period we are in +$period = '8TeV' +PU = ENV['PU'] +#if $jobid.include? '8TeV' +# $period = '8TeV' +#end + + +################################################################################ +## Sample names ################################################################ +################################################################################ +# +# Get sample names containing a substring +def get_sample_names(substring) + inputs = Dir.glob("inputs/#{$jobid}/*.txt").select {|x| x.include? substring} + inputs = inputs.map{|x| File.basename(x).sub(".txt", "")} + return inputs +end +# +samples = Hash[ + "ttbar" => get_sample_names('TTJets'), + "singlet" => get_sample_names('T_t'), + "singletbar" => get_sample_names('Tbar_t'), + "wjets" => get_sample_names('Wplus'), + "wwjets" => get_sample_names('WWJets'), + "wzjets" => get_sample_names('WZJets'), + "zzjets" => get_sample_names('ZZJets'), + "zjets" => get_sample_names('jets_M50'), + "zjets_skimmedLL" => get_sample_names('jets_M50_skimmedLL'), + "zjets_skimmedTT" => get_sample_names('jets_M50_skimmedTT'), + "diboson" =>get_sample_names('WWJets')+get_sample_names('WZJets')+get_sample_names('ZZJets'), + "extra" => Array['T_tW-channel-DR_TuneZ2star_8TeV-powheg-tauola','Tbar_tW-channel-DR_TuneZ2star_8TeV-powheg-tauola','Tbar_t-channel','T_t-channel'], + "ewk" => Array['Zjets_M50', + 'WWJetsTo2L2Nu_TuneZ2_8TeV', + 'TTJets_FullLeptMGDecays_8TeV-madgraph-tauola','TTJets_SemiLeptMGDecays_8TeV-madgraph-tauola'], + # Maria's version + + + "signalMCgg" => get_sample_names('ggHiggsToETau'), + "signalMCvbf" => get_sample_names('vbfHiggsToETau'), + "signalMCMuTaugg" => get_sample_names('ggHiggsToMuTau'), + "signalMCMuTauvbf" => get_sample_names('vbfHiggsToMuTau'), + "ggHiggsTo2Taus" => get_sample_names('GluGluToHToTauTau_M-125_8TeV-powheg-pythia6'), + "vbfHiggsTo2Taus" => get_sample_names('VBF_HToTauTau_M-125_8TeV-powheg-pythia6'), + "dataSingleE" => get_sample_names('data_SingleElectron_Run2012') + +] + + + +# Function to get the .root files for an analyzer and samples +def get_analyzer_results(analyzer, the_samples) + output = Array.new + analyzer_base = analyzer.sub('.py', '') + the_samples.each do |sample| + output << "results/#{$jobid}/#{analyzer_base}/#{sample}.root" + end + return output +end +def get_plotter_results(analyzer) + output = Array.new + analyzer_base = analyzer.sub('.py', '') +end + + +$frfit_dir = "results/#{$jobid}/fakerate_fits" +directory $frfit_dir +exponential = "scale*TMath::Exp(x*decay)+offset" +exponential_vars = "scale[4., 0, 10],decay[-1e-2, -1, -1e-4],offset[1e-2, 0, 0.5]" +exponentialpol1 = "scale*TMath::Exp(x*decay)+offset+slope*x" +exponentialpol1_vars = "scale[4., 0, 10],decay[-1e-2, -1, -1e-4],offset[1e-2, 0, 0.5],slope[1e-1, 1, 1]" +landau = "scale*TMath::Landau(x,mu,sigma,0)+offset" +landau_vars = "scale[0.5, 0, 15],mu[5, 0, 30],sigma[1.9, 0.1, 20],offset[1e-2, 0, 0.5]" + +pol0 = "const" +pol0_vars = "const[ 0.01, 0, 1]" +pol1 = "p0+p1*x" +pol1_vars = "p0[ 0.5, 0, 1], p1[ -0.001, -1, 1]" +pol2 = "p0+p1*x+p2*x*x" +pol2_vars = "p0[ 0.05, 0, 1], p1[ -0.005, -1, 1], p2[ 0.005, 0, 1]" + +erf = "scale*TMath::Erf((x-shift)*steep)+offset" +erf_vars = "scale[0.1, 0, 10],shift[1., 0.8, 1.2],steep[100.], offset[1e-2, 0, 0.5]" + + +#$fr_sample = "\"wzjets\", \"wwjets\", \"zzjets\", \"datasingleE\"" +#$fr_sample = "dataSingleE" + +#$fr_binning = "30,35,40,45,50,55,60,70,80,90,100,120,140,160,180,200" +#$fr_binning = "30,40,50,60,70,80,100,120,140,160,200" +$fr_binning = "30,40,50,60,70,80,100,120,150,200" +#$fr_binning = "30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200" +$fr_analyzer = "TauFakeRateAnalyzerMVA" #was TauFakeRateAnalyzer +fr_fits = Hash.new +# Fake rate fit configurations + +#mysamples = [ "zjets_skimmedLL", "zjets_skimmedTT"] +#for s in mysamples + +fr_fits["t_os_tNoCuts_tTigh_tPt"] = Hash[ + "samples" => Array["diboson", "dataSingleE"], + "analyzer" => $fr_analyzer, + "function" => pol0, + "variables" => pol0_vars, + #"rebin" => 1, + "rebin" => $fr_binning, + "range" => "30 200", + "title" => "#tau p_{T} (GeV)", + "min"=>"0", + "max"=>"0.1" + ] +fr_fits["t_os_tLoose_tTigh_tPt"] = Hash[ + "samples" => Array["diboson", "dataSingleE"], + "analyzer" => $fr_analyzer, + #"function" => exponential, + #"variables" => exponential_vars, + "function" => pol0, + "variables"=>pol0_vars, + #"rebin" => 1, + "rebin" => $fr_binning, + "range" => "30 200", + "title" => "#tau p_{T} (GeV)", + "min"=>"0", + "max"=>"1" + ] + +fr_fits["t_os_tNoCuts_tTigh_tAbsEta"] = Hash[ + "samples" => Array["diboson", "dataSingleE"], + "analyzer" => $fr_analyzer, + "function" => pol2, + "variables" => pol2_vars, + "rebin" => 1, + #"range" => "-2.3 2.3", + "range" => "0 2.3", + "title" => "#tau #eta", + "min"=>"0", + "max"=>"0.1" + ] +fr_fits["t_os_tLoose_tTigh_tAbsEta"] = Hash[ + "samples" => Array["diboson", "dataSingleE"], + "analyzer" => $fr_analyzer, + "function" => pol2, + "variables" => pol2_vars, + "rebin" => 1, + "range" => "0 2.3", + #"range" => "-2.3 2.3", + "title" => "#tau #eta", + "min"=>"0", + "max"=>"1" + ] + + + + +task :fits => [] + +fr_fits.each do |fit, fit_info| + fit_configuration = fit.split("_") + sign = fit_configuration[1] + denom = fit_configuration[2] + num = fit_configuration[3] + var = fit_configuration[4] + + subsample_inputs = [] + fit_info['samples'].each do |sample| + subsample_inputs += samples[sample] + end + + + fit_output = $frfit_dir + "/#{fit}.root" + subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/#{fit_info['analyzer']}/#{x}.root"} + # subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/TauFakeRateAnalyzerMVA_eTight/#{x}.root"} + subsample_input_list = subsamples_inputs_result_list.join(" ") + + # Path to histograms in root files + denom_path = Array[sign, denom,var].join("/") + num_path = Array[sign, num, var].join("/") + + corrected_file = fit_output.sub('.root', '.corrected_inputs.root') + file corrected_file => subsamples_inputs_result_list + [fit_info['analyzer'] + '.py', "CorrectFakeRateData.py"] do |t| + sh "mkdir -p #{$frfit_dir}" + sh "python CorrectFakeRateData.py --files #{subsample_input_list} --lumifiles inputs/#{$jobid}/*sum --outputfile #{t.name} --numerator '#{num_path}' --denom '#{denom_path}' --rebin #{fit_info['rebin']}" + puts "" + end + + file fit_output => corrected_file do |t| + sh "fit_efficiency_chi2.py #{fit_output} numerator denominator \'#{fit_info['function']}\' \'#{fit_info['variables']}\' #{corrected_file} --plot --xrange #{fit_info['range']} --xtitle \'#{fit_info['title']}\' --min \'#{fit_info['min']}\' --max \'#{fit_info['max']}\' --show-error " + puts "" + end + + # file fit_output do |t| + # sh "mkdir -p #{$frfit_dir}" + # sh "fit_efficiency_chi2.py --rebin #{fit_info['rebin']} #{fit_output} #{num_path} #{denom_path} \'#{fit_info['function']}\' \'#{fit_info['variables']}\' #{subsample_input_list} --plot --xrange #{fit_info['range']} --xtitle \'#{fit_info['title']}\'" + # puts "" + # end + + task :fits => fit_output + +end +#end + + + +################################################################################ +## Recipes to analyze the GG channel of the LFV HToMuTau analysis +## targets: +## mt +################################################################################ + +task :genkin => get_analyzer_results("LFVHAnalyzeGEN.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] ) + + +task :genkinMuTau => get_analyzer_results("LFVHAnalyzeGENMuTau.py", samples['signalMCMuTaugg'] + samples['signalMCMuTauvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus']) + +task :genkinMuTauSIGNAL => get_analyzer_results("LFVHAnalyzeGENMuTau.py", samples['signalMCMuTaugg']) + +task :genkinEMu => get_analyzer_results("LFVHAnalyzeGENEMu.py", samples['signalMCMuTaugg'] + samples['signalMCMuTauvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus']) + + +task :recoplots => get_analyzer_results("LFVHETauAnalyzer.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'])# + samples['dataSingleE'] ) + +task :recoplotsMVA => get_analyzer_results("LFVHETauAnalyzerMVA.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + + samples['dataSingleE'] ) + +task :recoplotsMVAeMtcut => get_analyzer_results("LFVHETauAnalyzerMVA_eMTCut.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + + samples['dataSingleE'] ) + + +task :recoplotsMuTau => get_analyzer_results("LFVHMuTauAnalyzer.py", samples['signalMCMuTaugg'] + samples['signalMCMuTauvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] ) + +task :controlplots => get_analyzer_results("EEAnalyzer.py",samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + samples['dataSingleE']) + +task :controlplotsMVA => get_analyzer_results("EEAnalyzerMVA.py", #samples['signalMCvbf'] )#samples['zjets']) + samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + samples['dataSingleE']) + + +task :fakeeet => get_analyzer_results("TauFakeRateAnalyzer.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + + samples['wwjets'] + samples['zzjets'] + + samples['wzjets'] + + samples['zjets'] + samples['dataSingleE']) + +task :fakeeetMVA => get_analyzer_results("TauFakeRateAnalyzerMVA.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + + samples['wwjets'] + samples['zzjets'] + + samples['wzjets'] + + samples['zjets'] + samples['dataSingleE']) + + +$etdir = "plots/#{$jobid}/LFVHETauAnalyzer/et/" +directory $etdir +file "#{$emtdir}/plot#{$period}.root" do |t| + sh "echo $jobid" + sh "python myNewPlotterReco.py" + +end + + +task :drawTauFakeRate => get_plotter_results("plotTauFakeRate.py") + +task :drawplots => "#{$emtdir}/plot#{$period}.root" + diff --git a/lfvetau/TauFakeRateAnalyzerMVA.py b/lfvetau/TauFakeRateAnalyzerMVA.py new file mode 100644 index 00000000..5d6a4f54 --- /dev/null +++ b/lfvetau/TauFakeRateAnalyzerMVA.py @@ -0,0 +1,340 @@ +##Correction Factor still to add +from EETauTree import EETauTree +import os +import ROOT +import math +import optimizer +import glob +import array +import mcCorrections +import baseSelections as selections +import FinalStateAnalysis.PlotTools.pytree as pytree +from FinalStateAnalysis.PlotTools.decorators import memo_last +from FinalStateAnalysis.PlotTools.MegaBase import MegaBase +from math import sqrt, pi, sin, cos, acos, sinh +from cutflowtracker import cut_flow_tracker +#Makes the cut flow histogram +cut_flow_step = ['allEvents', 'e1sel', 'e1IDiso', 'e2sel', 'e2IDiso', 'ZMass', 'tsel', 'tAntiMuon', 'tAntiEle', 'MtToMet', 'tRawIso10','tRawIso5', 'tLooseIso', 'tTightIso' +] + +from inspect import currentframe + +def get_linenumber(): + cf = currentframe() + return cf.f_back.f_lineno + +def deltaPhi(phi1, phi2): + PHI = abs(phi1-phi2) + if PHI<=pi: + return PHI + else: + return 2*pi-PHI +def deltaR(phi1, phi2, eta1, eta2): + deta = eta1 - eta2 + dphi = abs(phi1-phi2) + if (dphi>pi) : dphi = 2*pi-dphi + return sqrt(deta*deta + dphi*dphi); + +def etDR(row): + return row.e1_t_DR if row.e1_t_DR < row.e2_t_DR else row.e2_t_DR + +def etDPhi(row): + e1tDPhi=deltaPhi(row.e1Phi, row.tPhi) + e2tDPhi=deltaPhi(row.e2Phi, row.tPhi) + return e1tDPhi if e1tDPhi < e2tDPhi else e2tDPhi + +def Z(row): + e1p=ROOT.TVector3(row.e1Pt*cos(row.e1Phi),row.e1Pt*sin(row.e1Phi),row.e1Pt*sinh(row.e1Eta)) + e2p=ROOT.TVector3(row.e2Pt*cos(row.e2Phi),row.e2Pt*sin(row.e2Phi),row.e2Pt*sinh(row.e2Eta)) + e1FourVector= ROOT.TLorentzVector(e1p, sqrt(e1p.Mag2()+row.e1Mass*row.e1Mass)) + e2FourVector= ROOT.TLorentzVector(e2p, sqrt(e2p.Mag2()+row.e2Mass*row.e2Mass)) + zFourVector = e1FourVector+e2FourVector + return zFourVector + + +class TauFakeRateAnalyzerMVA(MegaBase): + tree = 'eet/final/Ntuple' + def __init__(self, tree, outfile, **kwargs): + self.channel='EET' + super(TauFakeRateAnalyzerMVA, self).__init__(tree, outfile, **kwargs) + self.tree = EETauTree(tree) + self.out=outfile + self.histograms = {} + self.pucorrector = mcCorrections.make_puCorrector('singlee') + + optimizer_keys = [ i for i in optimizer.grid_search.keys() if i.startswith(self.channel) ] + self.grid_search = {} + if len(optimizer_keys) > 1: + for key in optimizer_keys: + self.grid_search[key] = optimizer.grid_search[key] + else: + self.grid_search[''] = optimizer.grid_search[optimizer_keys[0]] + + + def event_weight(self, row): + if row.run > 2: #FIXME! add tight ID correction + return 1. + + etrig = 'e1' + if row.e2Pt > row.e1Pt : etrig = 'e2' + if bool(row.e1MatchesSingleE27WP80) and not bool(row.e2MatchesSingleE27WP80) : etrig = 'e1' + if not bool(row.e1MatchesSingleE27WP80) and bool(row.e2MatchesSingleE27WP80) : etrig = 'e2' + + #if bool(row.e1MatchesEle27WP80) and not bool(row.e2MatchesEle27WP80) : etrig = 'e1' + #if not bool(row.e1MatchesEle27WP80) and bool(row.e2MatchesEle27WP80) : etrig = 'e2' + return self.pucorrector(row.nTruePU) * \ + mcCorrections.get_electronId_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronId_corrections13_MVA(row, 'e2') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e2')* mcCorrections.get_trigger_corrections_MVA(row, etrig) +##add the trigger correction + + def begin(self): + + tauiso = ['tNoCuts', 'tSuperSuperLoose', 'tSuperLoose', 'tLoose', 'tTigh'] + folder = [] + sign = ['ss','os'] + for iso in tauiso: + for s in sign: + folder.append(s+'/'+iso) + folder.append(s+'/'+iso+'/tptregion') + j=0 + while j < 4 : + folder.append(s+'/'+iso+'/'+str(j)) + folder.append(s+'/'+iso+'/'+str(j)+'/tptregion') + j+=1 + + for f in folder: + + self.book(f,"e1Pt", "e1 p_{T}", 200, 0, 200) + self.book(f,"e1Phi", "e1 phi", 100, -3.2, 3.2) + self.book(f,"e1Eta", "e1 eta", 50, -2.5, 2.5) + + self.book(f,"e2Pt", "e2 p_{T}", 200, 0, 200) + self.book(f,"e2Phi", "e2 phi", 100, -3.2, 3.2) + self.book(f,"e2Eta", "e2 eta", 50, -2.5, 2.5) + + self.book(f, "e1e2Mass", "e1e2 Inv Mass", 32, 0, 320) + + self.book(f, "tMtToPFMET", "#tau Met MT", 100, 0, 100) + + self.book(f,"tRawIso3Hits", "tRawIso3Hits", 500, 0, 100) + self.book(f,"tPt", "t p_{T}", 200, 0, 200) + self.book(f,"tPtbarrel", "t p_{T} barrel", 200, 0, 200) + self.book(f,"tPtendcap", "t p_{T} endcap", 200, 0, 200) + self.book(f,"tPhi", "t phi", 100, -3.2, 3.2) + self.book(f,"tEta", "t eta", 50, -2.5, 2.5) + self.book(f,"tAbsEta", "t abs eta", 50, -2.5, 2.5) + + self.book(f,"etDR", "e t DR", 50, 0, 10) + self.book(f,"etDPhi", "e t DPhi", 32, 0, 3.2) + + self.book(f,"ztDR", "Z #tau DR", 50, 0, 10) + self.book(f,"ztDPhi", "Z #tau DPhi", 32, 0, 3.2) + self.book(f,"Zpt", "Z p_{T}", 200, 0, 200) + + + + self.book(f, "type1_pfMetEt", "type1_pfMetEt",200, 0, 200) + self.book(f, "jetN_30", "Number of jets, p_{T}>30", 10, -0.5, 9.5) + self.book(f, "bjetCSVVeto30", "number of bjets", 10, -0.5, 9.5) + + for s in sign: + self.book(s+'/tNoCuts', "CUT_FLOW", "Cut Flow", len(cut_flow_step), 0, len(cut_flow_step)) + + xaxis = self.histograms[s+'/tNoCuts/CUT_FLOW'].GetXaxis() + self.cut_flow_histo = self.histograms[s+'/tNoCuts/CUT_FLOW'] + self.cut_flow_map = {} + for i, name in enumerate(cut_flow_step): + xaxis.SetBinLabel(i+1, name) + self.cut_flow_map[name] = i+0.5 + + def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): + weight = self.event_weight(row) + histos = self.histograms + + histos[folder+'/e1Pt'].Fill(row.e1Pt, weight) + histos[folder+'/e1Eta'].Fill(row.e1Eta, weight) + histos[folder+'/e1Phi'].Fill(row.e1Phi, weight) + + histos[folder+'/e2Pt'].Fill(row.e2Pt, weight) + histos[folder+'/e2Eta'].Fill(row.e2Eta, weight) + histos[folder+'/e2Phi'].Fill(row.e2Phi, weight) + + histos[folder+'/e1e2Mass'].Fill(row.e1_e2_Mass, weight) + histos[folder+'/tMtToPFMET'].Fill(row.tMtToPFMET,weight) + + #histos[folder+'/tRawIso3Hits'].Fill(row.tRawIso3Hits, weight) + histos[folder+'/tPt'].Fill(row.tPt, weight) + if abs(row.tEta) < 1.5 : histos[folder+'/tPtbarrel'].Fill(row.tPt, weight) + if abs(row.tEta) > 1.5 : histos[folder+'/tPtendcap'].Fill(row.tPt, weight) + histos[folder+'/tEta'].Fill(row.tEta, weight) + histos[folder+'/tAbsEta'].Fill(abs(row.tEta), weight) + histos[folder+'/tPhi'].Fill(row.tPhi, weight) + + histos[folder+'/type1_pfMetEt'].Fill(row.type1_pfMetEt) + histos[folder+'/etDR'].Fill(etDR(row)) + histos[folder+'/etDPhi'].Fill(etDPhi(row)) + histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight) + histos[folder+'/bjetCSVVeto30'].Fill(row.bjetCSVVeto30, weight) + + histos[folder+'/ztDR'].Fill(deltaR(Z(row).Phi(), row.tPhi, Z(row).Eta(), row.tEta)) + histos[folder+'/ztDPhi'].Fill(deltaPhi(Z(row).Phi(), row.tPhi)) + histos[folder+'/Zpt'].Fill(Z(row).Pt()) + + + def process(self): + + print 'LINE', get_linenumber() + cut_flow_histo = self.cut_flow_histo + cut_flow_trk = cut_flow_tracker(cut_flow_histo) + myevent =() + #print self.tree.inputfilename + for row in self.tree: + jn = row.jetVeto30 + if jn > 3 : jn = 3 + + print 'LINE', get_linenumber() + #if row.run > 2: + if not bool(row.singleE27WP80Pass) : continue + print 'LINE', get_linenumber() + # if hasattr(self.tree, 'row.e1MatchesEle27WP80') and hasattr(self.tree, 'row.e2MatchesEle27WP80') : + #if not bool(row.e1MatchesEle27WP80) and not bool(row.e2MatchesEle27WP80) : continue + print 'LINE', get_linenumber() + + #else : + if not bool(row.e1MatchesSingleE27WP80) and not bool(row.e2MatchesSingleE27WP80) : continue + #if not bool(row.singleEPass) : continue + #if not bool(row.e1MatchesSingleE) and not bool(row.e2MatchesSingleE) : continue + print 'LINE', get_linenumber() + if row.bjetCSVVeto30!=0 : continue + if row.e1Pt < 30 : continue + if row.e2Pt < 30 : continue + print 'LINE', get_linenumber() + +# for i, row in enumerate(self.tree): +# if i >= 100: +# return + # print bool(cut_flow_trk.disabled) + cut_flow_trk.new_row(row.run,row.lumi,row.evt) + #print row.run,row.lumi,row.evt + cut_flow_trk.Fill('allEvents') + if not selections.eSelection(row, 'e1'): continue + cut_flow_trk.Fill('e1sel') + if not selections.lepton_id_iso(row, 'e1', 'eid13Tight_etauiso01'): continue + if abs(row.e1Eta) > 1.4442 and abs(row.e1Eta < 1.566) : continue + + print 'LINE', get_linenumber() + + cut_flow_trk.Fill('e1IDiso') + if not selections.eSelection(row, 'e2'): continue + cut_flow_trk.Fill('e2sel') + if not selections.lepton_id_iso(row, 'e2', 'eid13Tight_etauiso01'): continue + if abs(row.e2Eta) > 1.4442 and abs(row.e2Eta) < 1.566 : continue + + cut_flow_trk.Fill('e2IDiso') + if not abs(row.e1_e2_Mass-91.2) < 20: continue + cut_flow_trk.Fill('ZMass') + if not selections.tauSelection(row, 't'): continue + cut_flow_trk.Fill('tsel') + + if not row.tAntiMuon2Loose: continue + cut_flow_trk.Fill('tAntiMuon') + if not row.tAntiElectronMVA5Tight: continue #was 3 + cut_flow_trk.Fill('tAntiEle') + + if row.tauVetoPt20EleTight3MuLoose : continue + #if row.tauHpsVetoPt20 : continue + if row.muVetoPt5IsoIdVtx : continue + if row.eVetoCicLooseIso : continue # change it with Loose + print 'LINE', get_linenumber() + + if not row.tMtToMET < 50: continue + cut_flow_trk.Fill('MtToMet') + + # if etDR(row) < 1. : continue + if (row.run, row.lumi, row.evt, row.e1Pt, row.e2Pt)==myevent: continue + myevent=(row.run, row.lumi, row.evt, row.e1Pt, row.e2Pt) + + tauiso = 'tNoCuts' + sign = 'ss' if row.e1_e2_SS else 'os' + folder = sign+'/'+tauiso + + print 'LINE', get_linenumber() + self.fill_histos(row, folder) + folder=folder+'/'+str(int(jn)) + self.fill_histos(row, folder) + + print 'LINE', get_linenumber() + + if row.tPt < 90 and row.tPt>65 : + folder = folder+'/tptregion' + self.fill_histos(row, folder) + folder = sign+'/'+tauiso+'/tptregion' + self.fill_histos(row, folder) + + if not row.tRawIso3Hits < 10 : continue + cut_flow_trk.Fill('tRawIso10') + tauiso = 'tSuperSuperLoose' + folder = sign+'/'+tauiso + self.fill_histos(row, folder) + folder=folder+'/'+str(int(jn)) + self.fill_histos(row, folder) + if row.tPt < 90 and row.tPt>65 : + folder = folder+'/tptregion' + self.fill_histos(row, folder) + folder = sign+'/'+tauiso+'/tptregion' + self.fill_histos(row, folder) + + if not row.tRawIso3Hits < 5 : continue + cut_flow_trk.Fill('tRawIso5') + tauiso = 'tSuperLoose' + folder = sign+'/'+tauiso + self.fill_histos(row, folder) + folder=folder+'/'+str(int(jn)) + self.fill_histos(row, folder) + if row.tPt < 90 and row.tPt>65 : + folder = folder+'/tptregion' + self.fill_histos(row, folder) + folder = sign+'/'+tauiso+'/tptregion' + self.fill_histos(row, folder) + + print 'LINE', get_linenumber() + + + if row.tLooseIso3Hits : + tauiso = 'tLoose' + folder = sign+'/'+tauiso + self.fill_histos(row, folder) + cut_flow_trk.Fill('tLooseIso') + folder=folder+'/'+str(int(jn)) + self.fill_histos(row, folder) + if row.tPt < 90 and row.tPt>65 : + folder = folder+'/tptregion' + self.fill_histos(row, folder) + folder = sign+'/'+tauiso+'/tptregion' + self.fill_histos(row, folder) + + if row.tTightIso3Hits : + tauiso = 'tTigh' + folder = sign+'/'+tauiso + self.fill_histos(row, folder) + cut_flow_trk.Fill('tTightIso') + folder=folder+'/'+str(int(jn)) + self.fill_histos(row, folder) + if row.tPt < 90 and row.tPt>65 : + folder = folder+'/tptregion' + self.fill_histos(row, folder) + folder = sign+'/'+tauiso+'/tptregion' + self.fill_histos(row, folder) + + + + cut_flow_trk.flush() + + + + def finish(self): + self.write_histos() + + diff --git a/lfvetau/baseSelections.py b/lfvetau/baseSelections.py new file mode 100755 index 00000000..2aa603b4 --- /dev/null +++ b/lfvetau/baseSelections.py @@ -0,0 +1,108 @@ +from FinalStateAnalysis.PlotTools.decorators import memo +from FinalStateAnalysis.Utilities.struct import struct +from electronids import electronIds + +@memo +def getVar(name, var): + return name+var + +@memo +def splitEid(label): + return label.split('_')[-1], label.split('_')[0] + +#OBJECT SELECTION +def muSelection(row, name): + if getattr( row, getVar(name,'Pt')) < 30: return False + if getattr( row, getVar(name,'AbsEta')) > 2.1: return False + if not getattr( row, getVar(name,'PixHits')): return False + if getattr( row, getVar(name,'JetCSVBtag')) > 0.8: return False + #if getattr( row, getVar(name,'JetBtag')) > 3.3: return False #was 3.3 + if abs(getattr( row, getVar(name,'DZ'))) > 0.2: return False + return True + +def eSelection(row, name): + if getattr( row, getVar(name,'Pt')) < 20: return False #was 20 + if getattr( row, getVar(name,'AbsEta')) > 2.1: return False#as in H->tau_etau_h # was 2.3 + if getattr( row, getVar(name,'MissingHits')): return False + if getattr( row, getVar(name,'HasConversion')): return False +# if not getattr( row, getVar(name,'ChargeIdTight')): return False + if not getattr( row, getVar(name,'ChargeIdLoose')): return False + if getattr( row, getVar(name,'JetCSVBtag')) > 0.8: return False + ###if getattr( row, getVar(name,'JetBtag')) > 3.3: return False + if abs(getattr( row, getVar(name,'DZ'))) > 0.2: return False + return True + +def tauSelection(row, name): + if getattr( row, getVar(name,'Pt')) < 30: return False + if getattr( row, getVar(name,'AbsEta')) > 2.3: return False + if abs(getattr( row, getVar(name,'DZ'))) > 0.2: return False + return True + + +#VETOS +def vetos(row): + if row.muVetoPt5IsoIdVtx: return False + if row.eVetoMVAIsoVtx: return False + if row.eVetoCicTightIso: return False # change it to loose + if row.tauVetoPt20: return False + + return True + +def lepton_id_iso(row, name, label): #label in the format eidtype_isotype + 'One function to rule them all' + LEPTON_ID = False + isolabel, eidlabel = splitEid(label) #memoizes to be faster! + if name[0] == 'e': + LEPTON_ID = electronIds[eidlabel](row, name) + else: + LEPTON_ID = getattr(row, getVar(name, 'PFIDTight')) + if not LEPTON_ID: + return False + RelPFIsoDB = getattr(row, getVar(name, 'RelPFIsoDB')) + AbsEta = getattr(row, getVar(name, 'AbsEta')) + if isolabel == 'h2taucuts': + return bool( RelPFIsoDB < 0.1 or (RelPFIsoDB < 0.15 and AbsEta < 1.479)) + if isolabel == 'h2taucuts020': + return bool( RelPFIsoDB < 0.15 or (RelPFIsoDB < 0.20 and AbsEta < 1.479)) + if isolabel == 'idiso02': + return bool( RelPFIsoDB < 0.20 ) + if isolabel == 'etauiso012' or isolabel == 'mutauiso012': + return bool( RelPFIsoDB < 0.12 ) + if isolabel == 'etauiso01' or isolabel == 'mutauiso01': + return bool( RelPFIsoDB < 0.1 ) + ##put the new iso + if isolabel == 'mvaLoose' : + if AbsEta < 0.8: + return bool( RelPFIsoDB < 0.426 ) + if AbsEta > 0.8 and AbsEta < 1.479 : + return bool(RelPFIsoDB < 0.481) + if AbsEta > 1.479 and AbsEta < 2.5: + return bool(RelPFIsoDB < 0.390) + return False + if isolabel == 'mvaTight': + if AbsEta < 0.8: + return bool( RelPFIsoDB < 0.105 ) + if AbsEta > 0.8 and AbsEta < 1.479 : + return bool(RelPFIsoDB < 0.178) + if AbsEta > 1.479 and AbsEta < 2.5: + return bool(RelPFIsoDB < 0.150) + return False + + + +def control_region_ee(row): + '''Figure out what control region we are in. Shared among two codes, to avoid mismatching copied here''' + if row.e1_e2_SS and lepton_id_iso(row, 'e1', 'eid12Medium_h2taucuts') and row.e1MtToMET > 30: + return 'wjets' + elif row.e1_e2_SS and row.e1RelPFIsoDB > 0.3 and row.type1_pfMetEt < 25: #and row.metSignificance < 3: # + return 'qcd' + elif lepton_id_iso(row,'e1', 'eid12Medium_h2taucuts') and lepton_id_iso(row,'e2', 'eid12Medium_h2taucuts') \ + and not any([ row.muVetoPt5IsoIdVtx, + row.tauVetoPt20Loose3HitsVtx, + row.eVetoMVAIsoVtx, + ]): + return 'zee' + else: + return None + + diff --git a/lfvetau/cutflowtracker.py b/lfvetau/cutflowtracker.py new file mode 100644 index 00000000..18795e71 --- /dev/null +++ b/lfvetau/cutflowtracker.py @@ -0,0 +1,46 @@ +##author Mauro Verzetti + +import os + +class cut_flow_tracker(object): + def __init__(self, hist): + self.labels = [hist.GetXaxis().GetBinLabel(i+1) for i in range(hist.GetNbinsX())] + self.cut_flow = dict([ (i, False) for i in self.labels]) + self.hist = hist + self.evt_info = [-1, -1, -1] + self.disabled = 'CutFlow' not in os.environ + self.sync_mode = 'SYNC' in os.environ + + def fill(self, label): + self.cut_flow[label] = True + + def Fill(self, *labels): + if self.disabled: + return + for label in labels: + self.fill(label) + + def flush(self): + if self.disabled: + return + final_i = -1 + for i, label in enumerate(self.labels): + val = self.cut_flow[label] + if val: + self.hist.Fill(i+0.5) + final_i = i + if self.sync_mode: + fails = '' + try: + fails = 'fails %s' % (self.labels[final_i+1]) + except IndexError: + fails = 'passes the selection' #if len(self.labels) == final_i else 'passes the selection' + print 'Event %i:%i:%i ' % tuple(self.evt_info) + fails + + def new_row(self, *args): + if self.disabled: + return + if self.evt_info != list(args): + self.flush() + self.evt_info = list(args) + self.cut_flow = dict([ (i, False) for i in self.labels]) diff --git a/lfvetau/dump_xsec.py b/lfvetau/dump_xsec.py new file mode 100644 index 00000000..984e81aa --- /dev/null +++ b/lfvetau/dump_xsec.py @@ -0,0 +1,29 @@ +import FinalStateAnalysis.Utilities.prettyjson as prettyjson +import os +import glob +from pdb import set_trace + +def dump_xsec(jobid): + json_files = [i for i in glob.glob('inputs/%s/*.json' % jobid) if 'data_' not in i] + lumi_files = [i for i in glob.glob('inputs/%s/*.sum' % jobid) if 'data_' not in i] + + datasets = {} + for json_file in json_files: + dname = json_file.split('/')[-1].split('.')[0] + datasets[dname] = {} + datasets[dname]['numevts'] = prettyjson.loads(open(json_file).read())['n_evts'] + + for lumi_file in lumi_files: + dname = lumi_file.split('/')[-1].split('.')[0] + datasets[dname]['lumi'] = float( open(lumi_file).read().strip() ) + + out_format = '%60s'+'%15s'*3 + print out_format % ('dataset', '# evts', 'lumi [/pb]', 'xsec [pb]') + for dataset, info in datasets.iteritems(): + print out_format % (dataset, '%.3f' % info['numevts'], '%.3f' % info['lumi'], '%.5f' % (info['numevts']/info['lumi']) ) + +#print '\n\n%s\n' % os.environ['jobid7'] +#dump_xsec(os.environ['jobid7']) + +print '\n\n%s\n' % os.environ['jobid'] +dump_xsec(os.environ['jobid8']) diff --git a/lfvetau/electronids.py b/lfvetau/electronids.py new file mode 100644 index 00000000..279e39c8 --- /dev/null +++ b/lfvetau/electronids.py @@ -0,0 +1,118 @@ +#This module provides additional electron ID's starting from MVA's raw values +from FinalStateAnalysis.PlotTools.decorators import memo +@memo +def getVar(name, var): + return name+var + +def h2etau_looseId(row, name): + return bool(getattr(row, getVar(name, 'CBID_LOOSE'))) +def h2etau_tightId(row, name): + return bool(getattr(row, getVar(name, 'CBID_TIGHT'))) + +def zh_loose_2012eid(row, name): + value = getattr(row, getVar(name, 'MVANonTrig')) + pt = getattr(row, getVar(name, 'Pt')) + fabseta = getattr(row, getVar(name, 'AbsEta')) + if pt > 10. and fabseta < 0.8: + return (value > 0.5) + elif pt > 10. and fabseta >=0.8 and fabseta < 1.479: + return (value > 0.12) + elif pt > 10. and fabseta >= 1.479: + return (value > 0.6) + return False + +def h2tau_2012_LooseId(row, name): + return bool( getattr(row, getVar(name, 'MVAIDH2TauWP'))) + + +def h2tau_2012_tightId(row, name): + mva_output = getattr(row, getVar(name, 'MVANonTrig')) + pT = getattr(row, getVar(name, 'Pt')) + abseta = getattr(row, getVar(name, 'AbsEta')) + if pT > 20 and abseta < 0.8: + return ( mva_output > 0.925 ) + elif pT > 20 and 0.8 < abseta < 1.479: + return ( mva_output > 0.975 ) + elif pT > 20 and abseta > 1.479: + return ( mva_output > 0.985 ) + return False + + +#LEPTON ID-ISO +def summer_2013_eid(row, name): + mva_output = getattr(row, getVar(name, 'MVANonTrig')) #was eMVATrigNoIP + pT = getattr(row, getVar(name, 'Pt')) + abseta= getattr(row, getVar(name, 'AbsEta')) + if pT < 20 and abseta < 0.8: + return ( mva_output > 0.925 ) + elif pT < 20 and 0.8 < abseta < 1.479: + return ( mva_output > 0.915 ) + elif pT < 20 and abseta > 1.479: + return ( mva_output > 0.965 ) + elif pT > 20 and abseta < 0.8: + return ( mva_output > 0.905 ) + elif pT > 20 and 0.8 < abseta < 1.479: + return ( mva_output > 0.955 ) + elif pT > 20 and abseta > 1.479: + return ( mva_output > 0.975 ) + return False + +def summer_2013_eid_tight(row, name): + mva_output = getattr(row, getVar(name, 'MVANonTrig')) + pT = getattr(row, getVar(name, 'Pt')) + abseta= getattr(row, getVar(name, 'AbsEta')) + if pT > 20 and abseta < 0.8: + return ( mva_output > 0.925) + elif pT > 20 and 0.8 < abseta < 1.479: + return ( mva_output > 0.975 ) + elif pT > 20 and abseta > 1.479: + return ( mva_output > 0.985 ) + return False + +#add electron id from AN 2012_463 +def hWW_eid_tight(row, name): + mva_output = getattr(row, getVar(name,'MVATrig')) #check if it is correct + pT = getattr(row, getVar(name, 'Pt')) + abseta= getattr(row, getVar(name, 'AbsEta')) + if pT>20: + if abseta <0.8: + if mva_output >= 0.914 : return True + if abseta <1.479 and abseta > 0.8 : + if mva_output >=0.964 : return True + if abseta <2.5 and abseta > 1.479: + if mva_output >=0.899 : return True + + return False + +def hWW_eid_loose(row, name): + mva_output = getattr(row, getVar(name,'MVATrig')) #check if correct + pT = getattr(row, getVar(name, 'Pt')) + abseta= getattr(row, getVar(name, 'AbsEta')) + if pT>20: + if abseta <0.8: + if mva_output >= 0.877 : return True + if abseta <1.479 and abseta > 0.8 : + if mva_output >=0.811 : return True + if abseta <2.5 and abseta > 1.479: + if mva_output >=0.707 : return True + + return False + + + +#ID MVA cut value (tight lepton) 0.913 0.964 0.899 +#Isolation cut value (tight lepton) 0.105 0.178 0.150 +#ID MVA cut value (loose lepton) 0.877 0.811 0.707 +#Isolation cut value (loose lepton) 0.426 0.481 0.390 + +electronIds = { + 'eidCBLoose' : h2etau_looseId, + 'eidCBTight' : h2etau_tightId, + 'eid12Loose' : zh_loose_2012eid, + 'eid12Medium': h2tau_2012_LooseId, + 'eid12Tight' : h2tau_2012_tightId, + 'eid14Loose' : hWW_eid_loose, + 'eid14Tight' : hWW_eid_tight, + 'eid13Loose' : summer_2013_eid, + 'eid13Tight' : summer_2013_eid_tight, +} diff --git a/lfvetau/fakerate_functions.py b/lfvetau/fakerate_functions.py new file mode 100644 index 00000000..4849d733 --- /dev/null +++ b/lfvetau/fakerate_functions.py @@ -0,0 +1,85 @@ +import os +import re +import glob +import ROOT +from math import sqrt + + +def fakerate_central_histogram(nbin, xmin, xmax ): + + + + frfit_dir = os.path.join('results', os.environ['jobid'], 'fakerate_fits')+'/' + + + myfile = ROOT.TFile (frfit_dir+'t_os_tLoose_tTigh_tAbsEta.root') + myWS = myfile.Get('fit_efficiency') + efficiency_x = myWS.var('x') + efficiency_func = myWS.function("efficiency") + frhisto = efficiency_func.createHistogram("efficiency_x", efficiency_x) + results = myWS.genobj("fitresult_chi2_efficiency_xy_data") + parameters=results.floatParsFinal() + weight = [] + + for n in range(1, nbin) : + + eta = (n -0.5)* (xmax - xmin)/nbin + etamin = (n-1)* (xmax - xmin)/nbin + + weight.append((parameters[0].getVal()+parameters[1].getVal()*eta+parameters[2].getVal()*eta*eta, etamin)) + + return weight + +def fakerate_p1s_histogram(nbin, xmin, xmax) : + + frfit_dir = os.path.join('results', os.environ['jobid'], 'fakerate_fits')+'/' + + myfile = ROOT.TFile (frfit_dir+'t_os_tLoose_tTigh_tAbsEta.root') + myWS = myfile.Get('fit_efficiency') + efficiency_x = myWS.var('x') + efficiency_func = myWS.function("efficiency") + frhisto = efficiency_func.createHistogram("efficiency_x", efficiency_x) + results = myWS.genobj("fitresult_chi2_efficiency_xy_data") + parameters=results.floatParsFinal() + covMatrix = results.covarianceMatrix() + weight = [] + + for n in range(1, nbin) : + + eta = (n -0.5)* (xmax - xmin)/nbin + etamin = (n-1)* (xmax - xmin)/nbin + + err2= covMatrix(0,0) + covMatrix(1,1) * eta*eta + covMatrix(2,2) *eta*eta*eta*eta + 2*eta*covMatrix(0,1) + 2*eta*eta*covMatrix(0,2) + 2*eta*eta*eta*covMatrix(1,2) + myweight = (parameters[0].getVal()+parameters[1].getVal()*eta+parameters[2].getVal()*eta*eta)+ sqrt(err2) + + weight.append((myweight, etamin)) + + return weight + +def fakerate_m1s_histogram(nbin, xmin, xmax) : + + frfit_dir = os.path.join('results', os.environ['jobid'], 'fakerate_fits')+'/' + + myfile = ROOT.TFile (frfit_dir+'t_os_tLoose_tTigh_tAbsEta.root') + myWS = myfile.Get('fit_efficiency') + efficiency_x = myWS.var('x') + efficiency_func = myWS.function("efficiency") + frhisto = efficiency_func.createHistogram("efficiency_x", efficiency_x) + results = myWS.genobj("fitresult_chi2_efficiency_xy_data") + parameters=results.floatParsFinal() + covMatrix = results.covarianceMatrix() + + weight = [] + + for n in range(1, nbin) : + + eta = (n -0.5)* (xmax - xmin)/nbin + etamin = (n-1)* (xmax - xmin)/nbin + + err2= covMatrix(0,0) + covMatrix(1,1) * eta*eta + covMatrix(2,2) *eta*eta*eta*eta + 2*eta*covMatrix(0,1) + 2*eta*eta*covMatrix(0,2) + 2*eta*eta*eta*covMatrix(1,2) + myweight = (parameters[0].getVal()+parameters[1].getVal()*eta+parameters[2].getVal()*eta*eta) - sqrt(err2) + + weight.append((myweight, etamin)) + + return weight + diff --git a/lfvetau/jobid.sh b/lfvetau/jobid.sh new file mode 100644 index 00000000..7e32420f --- /dev/null +++ b/lfvetau/jobid.sh @@ -0,0 +1,8 @@ +#export jobid8='MCntuples_25March' +#export jobid8='MCntuples_otherCh2' +#export jobid8='MCntuples_14April' +#export jobid8='MCntuples_13May' +#export jobid8='newNtuple_3JuneLfvHnoteXsec' +#export jobid8='newNtuple_2Sept' +export jobid8='newNtuple_1Oct' +export jobidmt='MCntuples_8April' diff --git a/lfvetau/make_proxies.sh b/lfvetau/make_proxies.sh new file mode 100755 index 00000000..13c671b5 --- /dev/null +++ b/lfvetau/make_proxies.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Generate the cython proxies used in the analyses + +source jobid.sh + +#export jobid=$jobid8 +export jobid="newNtuple_9Oct" +export datasrc=/hdfs/store/user/$USER/$jobid +#export datasrc=`ls -d /nfs_scratch/taroni/$jobid | head -n 1` + +if [ -z $1 ]; then + export afile=`find $datasrc/ | grep root | head -n 1` +else + export afile=$1 +fi + +echo "Building cython wrappers from file: $afile" + +rake "make_wrapper[$afile, ee/final/Ntuple, EETree]" +rake "make_wrapper[$afile, eet/final/Ntuple, EETauTree]" +rake "make_wrapper[$afile, et/final/Ntuple, ETauTree]" +ls *pyx | sed "s|pyx|so|" | xargs -n 1 -P 10 rake + +#export jobid=$jobidmt +#export datasrc=/hdfs/store/user/$USER/$jobid +# +#if [ -z $1 ]; then +# export afile=`find $datasrc/ | grep root | head -n 1` +#else +# export afile=$1 +#fi +# +#rake "make_wrapper[$afile, mt/final/Ntuple, MuTauTree]" +#ls *pyx | sed "s|pyx|so|" | xargs -n 1 -P 10 rake diff --git a/lfvetau/mcCorrections.py b/lfvetau/mcCorrections.py new file mode 100755 index 00000000..9a6c64a5 --- /dev/null +++ b/lfvetau/mcCorrections.py @@ -0,0 +1,153 @@ +import os +import glob +import FinalStateAnalysis.TagAndProbe.HetauCorrection as HetauCorrection +import FinalStateAnalysis.TagAndProbe.PileupWeight as PileupWeight + +is7TeV = bool('7TeV' in os.environ['jobid']) +pu_distributions = { + 'singlee' : glob.glob(os.path.join( 'inputs', os.environ['jobid'], 'data_SingleElectron*pu.root'))} +pu_distributionsUp = { + 'singlee' : glob.glob(os.path.join( 'inputs', os.environ['jobid'], 'data_SingleElectron*pu_up.root'))} +pu_distributionsDown = { + 'singlee' : glob.glob(os.path.join( 'inputs', os.environ['jobid'], 'data_SingleElectron*pu_down.root'))} +mc_pu_tag = 'S6' if is7TeV else 'S10' + + +def make_puCorrector(dataset, kind=None): + 'makes PU reweighting according to the pu distribution of the reference data and the MC, MC distribution can be forced' + if not kind: + kind = mc_pu_tag + weights = [] + if dataset in pu_distributions:# and dataset in pu_distributionsUp and dataset in pu_distributionsDown: + return PileupWeight.PileupWeight( 'S6' if is7TeV else 'S10', *(pu_distributions[dataset])) +# weights = (PileupWeight.PileupWeight( 'S6' if is7TeV else 'S10', *(pu_distributions[dataset])), PileupWeight.PileupWeight( 'S6' if is7TeV else 'S10', *(pu_distributionsUp[dataset])), PileupWeight.PileupWeight( 'S6' if is7TeV else 'S10', *(pu_distributionsDown[dataset]))) +# return weights + else: + raise KeyError('dataset not present. Please check the spelling or add it to mcCorrectors.py') +def make_puCorrectorUp(dataset, kind=None): + 'makes PU reweighting according to the pu distribution of the reference data and the MC, MC distribution can be forced' + if not kind: + kind = mc_pu_tag + if dataset in pu_distributions: + return PileupWeight.PileupWeight( 'S6' if is7TeV else 'S10', *(pu_distributionsUp[dataset])) + else: + raise KeyError('dataset not present. Please check the spelling or add it to mcCorrectors.py') +def make_puCorrectorDown(dataset, kind=None): + 'makes PU reweighting according to the pu distribution of the reference data and the MC, MC distribution can be forced' + if not kind: + kind = mc_pu_tag + if dataset in pu_distributions: + return PileupWeight.PileupWeight( 'S6' if is7TeV else 'S10', *(pu_distributionsDown[dataset])) + else: + raise KeyError('dataset not present. Please check the spelling or add it to mcCorrectors.py') + +##put here the trigger correction as in https://github.com/mverzett/UWHiggs/blob/WH_At_Paper/wh/mcCorrectors.py + +correct_e = HetauCorrection.correct_hamburg_e +correct_eid13_mva = HetauCorrection.correct_eid13_mva +correct_eiso13_mva = HetauCorrection.correct_eiso13_mva +correct_eid13_p1s_mva = HetauCorrection.correct_eid13_p1s_mva +correct_eiso13_p1s_mva = HetauCorrection.correct_eiso13_p1s_mva +correct_eid13_m1s_mva = HetauCorrection.correct_eid13_m1s_mva +correct_eiso13_m1s_mva = HetauCorrection.correct_eiso13_m1s_mva +correct_eid_mva = HetauCorrection.scale_eleId_hww +correct_eReco_mva = HetauCorrection.scale_elereco_hww +correct_eIso_mva = HetauCorrection.scale_eleIso_hww +correct_trigger_mva = HetauCorrection.single_ele_mva + +def get_electron_corrections(row,*args): + 'makes corrections to iso and id of electrons' + ret = 1. + for arg in args: + abseta = abs(getattr(row, '%sEta' % arg)) + pt = getattr(row, '%sPt' % arg) + ret *= correct_e(pt,abseta) + return ret + +def get_electronId_corrections_MVA(row, *args): + ret = 1. + for arg in args: + eta = getattr(row, '%sEta' % arg) + pt = getattr(row, '%sPt' % arg) + ret *= correct_eid_mva(pt,eta)[0] + return ret +def get_electronReco_corrections_MVA(row, *args): + ret = 1. + for arg in args: + eta = getattr(row, '%sEta' % arg) + pt = getattr(row, '%sPt' % arg) + ret *= correct_eReco_mva(pt,eta)[0] + return ret +def get_electronIso_corrections_MVA(row, *args): + ret = 1. + for arg in args: + eta = getattr(row, '%sEta' % arg) + pt = getattr(row, '%sPt' % arg) + ret *= correct_eIso_mva(pt,eta)[0] + return ret + +def get_trigger_corrections_MVA(row, *args): + ret = 1. + for arg in args: + eta = getattr(row, '%sEta' % arg) + pt = getattr(row, '%sPt' % arg) + ret *= correct_trigger_mva(pt,eta)[0] + return ret +def get_trigger_corrections_p1s_MVA(row, *args): + ret = 1. + for arg in args: + eta = getattr(row, '%sEta' % arg) + pt = getattr(row, '%sPt' % arg) + ret *= correct_trigger_mva(pt,eta)[0]+correct_trigger_mva(pt,eta)[1] + return ret +def get_trigger_corrections_m1s_MVA(row, *args): + ret = 1. + for arg in args: + eta = getattr(row, '%sEta' % arg) + pt = getattr(row, '%sPt' % arg) + ret *= correct_trigger_mva(pt,eta)[0]-correct_trigger_mva(pt,eta)[1] + + return ret + +def get_electronId_corrections13_MVA(row, *args): + ret = 1. + for arg in args: + eta = getattr(row, '%sEta' % arg) + pt = getattr(row, '%sPt' % arg) + ret *= correct_eid13_mva(pt,eta) + return ret +def get_electronIso_corrections13_MVA(row, *args): + ret = 1. + for arg in args: + eta = getattr(row, '%sEta' % arg) + pt = getattr(row, '%sPt' % arg) + ret *= correct_eiso13_mva(pt,eta) + return ret +def get_electronId_corrections13_p1s_MVA(row, *args): + ret = 1. + for arg in args: + eta = getattr(row, '%sEta' % arg) + pt = getattr(row, '%sPt' % arg) + ret *= correct_eid13_p1s_mva(pt,eta) + return ret +def get_electronIso_corrections13_p1s_MVA(row, *args): + ret = 1. + for arg in args: + eta = getattr(row, '%sEta' % arg) + pt = getattr(row, '%sPt' % arg) + ret *= correct_eiso13_p1s_mva(pt,eta) + return ret +def get_electronId_corrections13_m1s_MVA(row, *args): + ret = 1. + for arg in args: + eta = getattr(row, '%sEta' % arg) + pt = getattr(row, '%sPt' % arg) + ret *= correct_eid13_m1s_mva(pt,eta) + return ret +def get_electronIso_corrections13_m1s_MVA(row, *args): + ret = 1. + for arg in args: + eta = getattr(row, '%sEta' % arg) + pt = getattr(row, '%sPt' % arg) + ret *= correct_eiso13_m1s_mva(pt,eta) + return ret diff --git a/lfvetau/myNewPlotterReco.py b/lfvetau/myNewPlotterReco.py new file mode 100644 index 00000000..cc1b4461 --- /dev/null +++ b/lfvetau/myNewPlotterReco.py @@ -0,0 +1,158 @@ +import rootpy.plotting.views as views +from FinalStateAnalysis.PlotTools.SimplePlotter import SimplePlotter +from FinalStateAnalysis.PlotTools.Plotter import Plotter +from FinalStateAnalysis.PlotTools.BlindView import BlindView +from FinalStateAnalysis.PlotTools.PoissonView import PoissonView +from FinalStateAnalysis.PlotTools.MedianView import MedianView +from FinalStateAnalysis.PlotTools.ProjectionView import ProjectionView +#from FinalStateAnalysis.PlotTools.FixedIntegralView import FixedIntegralView +from FinalStateAnalysis.PlotTools.RebinView import RebinView +from FinalStateAnalysis.MetaData.data_styles import data_styles, colors +from FinalStateAnalysis.PlotTools.decorators import memo +from FinalStateAnalysis.MetaData.datacommon import br_w_leptons, br_z_leptons +from optparse import OptionParser +import os +import ROOT +import glob +import math +import logging +from fnmatch import fnmatch +from yellowhiggs import xs, br, xsbr + +ROOT.gROOT.SetBatch() +ROOT.gStyle.SetOptStat(0) +jobid = os.environ['jobid'] + +print jobid +mc_samples = [ + 'ggHiggsToETau', + 'vbfHiggsToETau', + 'GluGluToHToTauTau_M-125_8TeV-powheg-pythia6', + 'VBF_HToTauTau_M-125_8TeV-powheg-pythia6', + 'Zjets_M50_skimmedLL', + 'Z1jets_M50_skimmedLL', + 'Z2jets_M50_skimmedLL', + 'Z3jets_M50_skimmedLL', + 'Z4jets_M50_skimmedLL', + 'Zjets_M50_skimmedTT', + 'Z1jets_M50_skimmedTT', + 'Z2jets_M50_skimmedTT', + 'Z3jets_M50_skimmedTT', + 'Z4jets_M50_skimmedTT', + 'TTJets*', + 'T_t*', + 'Tbar_t*', + 'WplusJets_madgraph_skimmed', + 'Wplus1Jets_madgraph', + 'Wplus1Jets_madgraph_tapas', + 'Wplus2Jets_madgraph', + 'Wplus2Jets_madgraph_tapas', + 'Wplus3Jets_madgraph', + 'Wplus4Jets_madgraph', + 'WWJets*', + 'WZJets*', + 'ZZJets*' +] + +files = [] +lumifiles = [] +channel = 'et' +for x in mc_samples: + files.extend(glob.glob('results/%s/LFVHETauAnalyzer/%s.root' % (jobid, x))) + lumifiles.extend(glob.glob('inputs/%s/%s.lumicalc.sum' % (jobid, x))) + + + +period = '8TeV' +sqrts = 7 if '7TeV' in jobid else 8 + +def remove_name_entry(dictionary): + return dict( [ i for i in dictionary.iteritems() if i[0] != 'name'] ) + + +#sign = ['os', 'ss'] +process = ['gg'] +#ptcut = [0, 40] +njets= [0,1,2,3] +sign = ['os'] + +ptcut = [0] #was 0 + + + +outputdir = 'plots/%s/LFVHETauAnalyzer/%s/' % (jobid, channel) +if not os.path.exists(outputdir): + os.makedirs(outputdir) + +plotter = Plotter(files, lumifiles, outputdir, None, forceLumi=19800) +#plotter = SimplePlotter(files, lumifiles, outputdir) + + + + +EWKDiboson = views.StyleView( + views.SumView( + *[ plotter.get_view(regex) for regex in \ + filter(lambda x : x.startswith('WW') or x.startswith('WZ') or x.startswith('ZZ') or x.startswith('WG'), mc_samples )] + ), **remove_name_entry(data_styles['WW*'#,'WZ*', 'WG*', 'ZZ*' +]) +) +Wplus = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('Wplus'), mc_samples )]), **remove_name_entry(data_styles['Wplus*Jets*'])) +DYLL = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('skimmedLL'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*LL'])) +DYTT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedTT'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*TT'])) +singleT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('T_') or x.startswith('Tbar_'), mc_samples)]), **remove_name_entry(data_styles['T*_t*'])) + +SMH = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : 'HToTauTau' in x , mc_samples)]), **remove_name_entry(data_styles['GluGluToHToTauTau*'])) + + +plotter.views['EWKDiboson']={'view' : EWKDiboson } +plotter.views['Wplus']={'view' : Wplus } +plotter.views['DYLL']={'view' : DYLL } +plotter.views['DYTT']={'view' : DYTT } +plotter.views['singleT']={'view' : singleT } +plotter.views['SMH']={'view' : SMH } + + +new_mc_samples = filter( lambda x : not x.startswith('T_') and not x.startswith('Tbar_') and not x.endswith('jets_M50_skimmedLL') and not x.endswith('jets_M50_skimmedTT') and not x.startswith('Wplus') and not x.startswith('WW') and not x.startswith('WZ') and not x.startswith('ZZ') and not x.startswith('WG') and not x.endswith('HiggsToETau') and not 'HToTauTau' in x, mc_samples) + +new_sigsamples= filter(lambda x: x.endswith('HiggsToETau'), mc_samples) + +print new_sigsamples +new_mc_samples.extend(['EWKDiboson', 'SMH', 'singleT','Wplus', 'DYLL', 'DYTT' +]) +print new_mc_samples + +histoname = [('tPt','#tau p_{T} (GeV)',5), ('tPhi','#tau #phi',5), ('tEta','#tau #eta',2), + ('ePt', 'e p_{T} (GeV)', 5), ('ePhi','e #phi', 5), ('eEta','e #eta',2), + ('et_DeltaPhi','e-#tau #Delta#phi',1), ('et_DeltaR','e-#tau #DeltaR',1), ('tPFMET_DeltaPhi','#tau-PFMET #Delta#phi',2) , + ('tPFMET_Mt','#tau-PFMET M_{T} (GeV)',5), ('tMVAMET_DeltaPhi','#tau-MVAMET #Delta#phi',2), ('tMVAMET_Mt','#tau-MVAMET M_{T} (GeV)',5), + ('ePFMET_DeltaPhi','e-PFMET #Delta#phi',2), ('ePFMET_Mt','e-PFMET M_{T} (GeV)',5), ('eMVAMET_DeltaPhi','e-MVAMET #Delta#phi',2), + ('eMVAMET_Mt','e-MVAMET #M_{T} (GeV)',5), ('jetN_20','Number of jets',1), ('jetN_30','Number of jets',1), + ('h_collmass_pfmet','M_{e#tau}coll (GeV)',1), ('h_collmass_mvamet','M_{e#tau}coll (GeV)',1), ('h_vismass','M_{e#tau} vis (GeV)',1) ] + +plotter.mc_samples = new_mc_samples +#plotter.mc_samples = mc_samples +for i in sign : + for j in process: + for k in ptcut : + for nj in njets: + + + for n,h in enumerate(histoname) : + foldername = i+'/'+j+'/ept'+str(int(k))+'/'+str(int(nj)) + + #plotter.canvas.SetLogy(True) + plotter.plot_mc(foldername, ['ggHiggsToETau','vbfHiggToETau'],h[0], rebin=h[2], xaxis=h[1], leftside=False, show_ratio=False, ratio_range=1.5, rescale=10) + #plotter.simpleplot_mc(foldername,h[0], rebin=h[2], xaxis= h[1], leftside=False) + if not os.path.exists(outputdir+foldername): + os.makedirs(outputdir+foldername) + + plotter.save(foldername+'/mc_'+h) + + foldername = i+'/'+j+'/ept'+str(k)+'/'+str(nj)+'/selected' + #plotter.canvas.SetLogy(True) + plotter.plot_mc(foldername, ['ggHiggsToETau','vbfHiggsToETau'],h[0], rebin=h[2], xaxis= h[1], leftside=False, show_ratio=False,ratio_range=3, rescale=10) + if not os.path.exists(outputdir+foldername): + os.makedirs(outputdir+foldername) + + plotter.save(foldername+'/mc_'+h[0]) diff --git a/lfvetau/optimizer.py b/lfvetau/optimizer.py new file mode 100644 index 00000000..1becd2eb --- /dev/null +++ b/lfvetau/optimizer.py @@ -0,0 +1,107 @@ +#author Mauro Verzetti +'small interface module to deal with optimizization' + +import os +import itertools + +RUN_OPTIMIZATION = ('RUN_OPTIMIZATION' in os.environ) and eval(os.environ['RUN_OPTIMIZATION']) + +lep_id = [ + 'eid12Tight_h2taucuts', + 'eid12Tight_h2taucuts020', + #'eid12Loose_h2taucuts', + #'eid12Loose_h2taucuts020', + 'eid12Medium_h2taucuts', + 'eid12Medium_h2taucuts020' + ] \ + if RUN_OPTIMIZATION else \ + [ + #'eid12Loose_h2taucuts', + #'eid12Loose_h2taucuts020', + 'eid12Tight_h2taucuts', + 'eid12Medium_h2taucuts020', + 'eid12Medium_h2taucuts' + ] + +LT_cut = [ + 0, + 80, + 110, + 140, + 170, + 200, + 3000 + ] + +tauIDs = [ + 'tMediumIso3Hits', + None + ] + +tauPTs = [ + 0, + 30, + 40, + 60 + ] + +charge_fakes = [ + 80, + ] + +grid_search = {} +counter_1, counter_2, counter_3, counter_4 = 0, 0, 0, 0 +if RUN_OPTIMIZATION: + for lead_id, sublead_id, lt_thr, tauID, tauPT, charge_fakes in \ + itertools.product(lep_id, lep_id, LT_cut, tauIDs, tauPTs, charge_fakes): + cut_name = '%s:%s:%s:%s:%s:%s' % (lead_id, sublead_id, lt_thr, tauID, tauPT, charge_fakes) + counter_1 += 1 + if (lead_id.startswith('eid13Loose') or sublead_id.startswith('eid13Loose')) and \ + not (lead_id.startswith('eid13Loose') and sublead_id.startswith('eid13Loose')): + continue + counter_2 += 1 + if tauPT > 0 and lt_thr > 0: + continue + counter_3 += 1 + ## if lt_thr and not tauID: + ## continue + ## counter_4 += 1 + grid_search[cut_name] = { + 'leading_iso' : lead_id, + 'subleading_iso' : sublead_id, + 'LT' : lt_thr, + 'tauID': tauID, + 'tauPT': tauPT, + 'charge_fakes' : charge_fakes, + } +else: + grid_search['MMT'] = { + 'leading_iso' : 'eid12Medium_h2taucuts', + 'subleading_iso' : 'eid12Medium_h2taucuts020', + 'LT' : 50, + 'tauID' : None, + 'tauPT' : 0, + 'charge_fakes' : 80, + } + grid_search['EMT'] = { + 'leading_iso' : 'eid12Medium_h2taucuts', + 'subleading_iso' : 'eid12Medium_h2taucuts', + 'LT' : 50, + 'tauID' : None, + 'tauPT' : 0, + 'charge_fakes' : 80, + } + grid_search['EET'] = { + 'leading_iso' : 'eid12Tight_h2taucuts', + 'subleading_iso' : 'eid12Medium_h2taucuts020', + 'LT' : 50, + 'tauID' : None, + 'tauPT' : 0, + 'charge_fakes' : 100, + } + + +if __name__ == "__main__": + print '\n'.join(grid_search.keys()) +else: + print "Running optimization: %s" % RUN_OPTIMIZATION diff --git a/lfvetau/plotControlEE_MVA.py b/lfvetau/plotControlEE_MVA.py new file mode 100644 index 00000000..d023c28d --- /dev/null +++ b/lfvetau/plotControlEE_MVA.py @@ -0,0 +1,204 @@ +import rootpy.plotting.views as views +from FinalStateAnalysis.PlotTools.Plotter import Plotter +from FinalStateAnalysis.PlotTools.BlindView import BlindView +from FinalStateAnalysis.PlotTools.PoissonView import PoissonView +from FinalStateAnalysis.PlotTools.MedianView import MedianView +from FinalStateAnalysis.PlotTools.ProjectionView import ProjectionView +#from FinalStateAnalysis.PlotTools.FixedIntegralView import FixedIntegralView +from FinalStateAnalysis.PlotTools.RebinView import RebinView +from FinalStateAnalysis.MetaData.data_styles import data_styles, colors +from FinalStateAnalysis.PlotTools.decorators import memo +from FinalStateAnalysis.MetaData.datacommon import br_w_leptons, br_z_leptons +from FinalStateAnalysis.PlotTools.SubtractionView import SubtractionView, PositiveView +from optparse import OptionParser +import os +import ROOT +import glob +import math +import logging +import pdb +import array +from fnmatch import fnmatch +from yellowhiggs import xs, br, xsbr + +from BasePlotter import BasePlotter + + +ROOT.gROOT.SetBatch() +ROOT.gStyle.SetOptStat(0) +jobid = os.environ['jobid'] + +print jobid +mc_samples = [ + 'ggHiggsToETau', + 'vbfHiggsToETau', + 'GluGluToHToTauTau_M-125_8TeV-powheg-pythia6', + 'VBF_HToTauTau_M-125_8TeV-powheg-pythia6', + #'Zjets_M50', + 'Zjets_M50_skimmedLL', + 'Z1jets_M50_skimmedLL', + 'Z2jets_M50_skimmedLL', + 'Z3jets_M50_skimmedLL', + 'Z4jets_M50_skimmedLL', + 'Zjets_M50_skimmedTT', + 'Z1jets_M50_skimmedTT', + 'Z2jets_M50_skimmedTT', + 'Z3jets_M50_skimmedTT', + 'Z4jets_M50_skimmedTT', + 'TTJets*', + 'T_t*', + 'Tbar_t*', + 'WplusJets_madgraph_skimmed', + 'Wplus1Jets_madgraph', + # 'Wplus1Jets_madgraph_tapas', + 'Wplus2Jets_madgraph', + # 'Wplus2Jets_madgraph_tapas', + 'Wplus3Jets_madgraph', + 'Wplus4Jets_madgraph', + 'WWJets*', + 'WZJets*', + 'ZZJets*', + 'data*' +] + +files = [] +lumifiles = [] +channel = 'ee' +for x in mc_samples: +# files.extend(glob.glob('results/%s/EEAnalyzerMVA/%s.root' % (jobid, x))) + files.extend(glob.glob('results/%s/EEAnalyzerMVA_noTrCorr/%s.root' % (jobid, x))) + lumifiles.extend(glob.glob('inputs/%s/%s.lumicalc.sum' % (jobid, x))) + + + +period = '8TeV' +sqrts = 7 if '7TeV' in jobid else 8 + +def remove_name_entry(dictionary): + return dict( [ i for i in dictionary.iteritems() if i[0] != 'name'] ) + + +sign = ['os'] +jets = [0, 1, 2, 3] +#outputdir = 'plots/%s/EEAnalyzerMVA/%s/' % (jobid, channel) +outputdir = 'plots/%s/EEAnalyzerMVA_noTrCorr/%s/' % (jobid, channel) +if not os.path.exists(outputdir): + os.makedirs(outputdir) + +plotter = BasePlotter(files, lumifiles, outputdir) + + + + +EWKDiboson = views.StyleView( + views.SumView( + *[ plotter.get_view(regex) for regex in \ + filter(lambda x : x.startswith('WW') or x.startswith('WZ') or x.startswith('ZZ') or x.startswith('WG'), mc_samples )] + ), **remove_name_entry(data_styles['WW*'#,'WZ*', 'WG*', 'ZZ*' +]) +) +Wplus = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('Wplus'), mc_samples )]), **remove_name_entry(data_styles['Wplus*Jets*'])) +DYLL = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('skimmedLL'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*LL'])) +DYTT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedTT'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*TT'])) +TT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('TT') , mc_samples)]), **remove_name_entry(data_styles['TTJets*'])) +singleT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('T_') or x.startswith('Tbar_'), mc_samples)]), **remove_name_entry(data_styles['T*_t*'])) +SMH = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : 'HToTauTau' in x , mc_samples)]), **remove_name_entry(data_styles['GluGluToHToTauTau*'])) + +plotter.views['EWKDiboson']={'view' : EWKDiboson } +plotter.views['Wplus']={'view' : Wplus } +plotter.views['DYLL']={'view' : DYLL } +plotter.views['DYTT']={'view' : DYTT } +plotter.views['singleT']={'view' : singleT } +plotter.views['SMH']={'view' : SMH } +plotter.views['TT']={'view' : TT } +#plotter.views['DY']={'view' : DY } +new_mc_samples =[] + +new_mc_samples.extend(['EWKDiboson', 'SMH', 'singleT','Wplus', 'TT', + 'DYLL', 'DYTT' +]) +print new_mc_samples + +binx = array.array('l', [5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,100, 120, 140, 160,200 ]) + +histoname = [('e1Pt', 'e1 p_{T} (GeV)', 5), ('e1Phi','e1 #phi',5) ,('e1Eta','e1 #eta',2), + ('e2Pt','e2 p_{T} (GeV)',5) ,('e2Phi','e2 #phi',5), ('e2Eta','e2 #eta',2), + ('e1e2_DeltaPhi','e1-e2 #Delta#phi',2), ('e1e2_DeltaR','e1-e2 #DeltaR',2), ('e1e2Mass', 'e1-e2 Inv Mass (GeV)',5), + ('type1_pfMetEt', 'type1PF MET (GeV)', 2) , ('pfMetEt', 'PF MET (GeV)', 2), + ('type1_pfMetPhi','type1 PF MET #phi', 5), ('pfMetPhi','PF MET #phi',5), + ('pfMetEt_par','PF MET parallel (GeV)',2), ('pfMetEt_perp','PF MET perpendicular (GeV)',2), + ('type1_pfMetEt_par', 'type1PF MET parallel (GeV)', 2),('type1_pfMetEt_perp', 'type1PF MET perpendicular (GeV)',2), + ('e1PFMET_DeltaPhi','e1-type1PFMET #Delta#phi',2), ('e1PFMET_Mt','e1-type1PFMET M_{T} (GeV) ',5), + ('e2PFMET_DeltaPhi','e2-type1PFMET #Delta#phi',2),('e2PFMET_Mt','e2-type1PFMET M_{T} (GeV)',5), + ('nPV_unweighted', 'unweighted N of vertices', 1), ('nPV', 'number of vertices', 1) +] + + +plotter.mc_samples = new_mc_samples +foldernames = [] +for i in sign : + foldernames.append(i) + for j in jets : + foldernames.append(i+'/'+str(int(j))) + +def create_mapper(mapping): + def _f(path): + for key, out in mapping.iteritems(): + if key == path: + path = path.replace(key,out) + print 'path', path + return path + return _f + +def get_ss(x): + return x.replace('os/', 'ss/') + +print foldernames +mymapper = {"os/": "ss/", + "os/0/": "ss/0/", + "os/1": "ss/1", + "os/2": "ss/2", + "os/3": "ss/3" +} +QCD = views.TitleView(views.StyleView(SubtractionView( + views.PathModifierView( plotter.data, get_ss), + views.PathModifierView( TT, get_ss), + views.PathModifierView( singleT, get_ss), + views.PathModifierView( SMH, get_ss ), + views.PathModifierView( DYTT, get_ss ), + views.PathModifierView( DYLL, get_ss ), + views.PathModifierView( Wplus, get_ss ), + views.PathModifierView( EWKDiboson, get_ss )) + ,**data_styles['QCD*']), 'QCD') + + +plotter.views['QCD']= {'view': QCD} +plotter.mc_samples.extend(['QCD']) + + +for foldername in foldernames: + if foldername.startswith("ss") and bool('QCD' in plotter.mc_samples)==True: + plotter.mc_samples.remove('QCD') + if foldername.startswith("os") and bool('QCD' in plotter.mc_samples)==False: + plotter.mc_samples.extend(['QCD']) + + for n,h in enumerate(histoname) : + + + plotter.pad.SetLogy(True) + #plotter.plot('QCD', foldername+'/'+h[0], 'hist') + print foldername + #plotter.plot_mc_vs_data(foldername, h[0], rebin=h[2], xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.2, sorted=True) + + plotter.plot_with_bkg_uncert(foldername,h[0], rebin=h[2], xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.5, sort=True, obj1='e1', obj2='e2') + + + + + if not os.path.exists(outputdir+foldername): + os.makedirs(outputdir+foldername) + + plotter.save(foldername+'/'+h[0]) + + + diff --git a/lfvetau/plotControlFakeMVA.py b/lfvetau/plotControlFakeMVA.py new file mode 100644 index 00000000..ea69bc41 --- /dev/null +++ b/lfvetau/plotControlFakeMVA.py @@ -0,0 +1,171 @@ +#from mauro plotters +import os +from sys import argv, stdout, stderr +import ROOT +import sys +from FinalStateAnalysis.PlotTools.MegaBase import make_dirs +from FinalStateAnalysis.MetaData.data_styles import data_styles +from FinalStateAnalysis.PlotTools.BlindView import BlindView, blind_in_range +import glob +import logging +import sys +from BasePlotter import BasePlotter + +jobid = os.environ['jobid'] +#jobid = 'MCntuples_3March' +channel = 'et' +import rootpy.plotting.views as views + +ROOT.gROOT.SetStyle("Plain") +ROOT.gROOT.SetBatch(True) +ROOT.gStyle.SetOptStat(0) + +print "\nPlotting %s for %s\n" % (channel, jobid) + + + +mc_samples = [ + 'ggHiggsToETau', + 'vbfHiggsToETau', + 'GluGluToHToTauTau_M-125_8TeV-powheg-pythia6', + 'VBF_HToTauTau_M-125_8TeV-powheg-pythia6', + #'Zjets_M50', + 'Zjets_M50_skimmedLL', + 'Z1jets_M50_skimmedLL', + 'Z2jets_M50_skimmedLL', + 'Z3jets_M50_skimmedLL', + 'Z4jets_M50_skimmedLL', + 'Zjets_M50_skimmedTT', + 'Z1jets_M50_skimmedTT', + 'Z2jets_M50_skimmedTT', + 'Z3jets_M50_skimmedTT', + 'Z4jets_M50_skimmedTT', + 'TTJets*', + 'T_t*', + 'Tbar_t*', + #'WplusJets_madgraph_skimmed', + 'Wplus1Jets_madgraph*', + #'Wplus1Jets_madgraph_tapas', + 'Wplus2Jets_madgraph*', + #'Wplus2Jets_madgraph_tapas', + 'Wplus3Jets_madgraph', + 'Wplus4Jets_madgraph', + 'WWJets*', + 'WZJets*', + 'ZZJets*', + 'Fake*', + 'data*' +] + + +files = [] +lumifiles = [] + +for x in mc_samples: + files.extend(glob.glob('results/%s/LFVHETauAnalyzerMVA/%s.root' % (jobid, x))) + lumifiles.extend(glob.glob('inputs/%s/%s.lumicalc.sum' % (jobid, x))) + +sign = ['ss'] +jets = [0, 1, 2, 3] +processtype=['gg'] +threshold=['ept30'] + +outputdir = 'plots/%s/ControlFakeTau/%s/' % (jobid, channel) +if not os.path.exists(outputdir): + os.makedirs(outputdir) + + + +def remove_name_entry(dictionary): + return dict( [ i for i in dictionary.iteritems() if i[0] != 'name'] ) + + +plotter = BasePlotter(channel,files, lumifiles, outputdir) + +EWKDiboson = views.StyleView( + views.SumView( + *[ plotter.get_view(regex) for regex in \ + filter(lambda x : x.startswith('WW') or x.startswith('WZ') or x.startswith('ZZ') or x.startswith('WG'), mc_samples )] + ), **remove_name_entry(data_styles['WW*'#,'WZ*', 'WG*', 'ZZ*' +]) +) +Wplus = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('Wplus'), mc_samples )]), **remove_name_entry(data_styles['Wplus*Jets*'])) +DYLL = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('skimmedLL'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*LL'])) +DYTT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedTT'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*TT'])) +TT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('TT') , mc_samples)]), **remove_name_entry(data_styles['TTJets*'])) +singleT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('T_') or x.startswith('Tbar_'), mc_samples)]), **remove_name_entry(data_styles['T*_t*'])) +SMH = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : 'HToTauTau' in x , mc_samples)]), **remove_name_entry(data_styles['GluGluToHToTauTau*'])) + + +plotter.views['EWKDiboson']={'view' : EWKDiboson } +plotter.views['Wplus']={'view' : Wplus } +plotter.views['DYLL']={'view' : DYLL } +plotter.views['DYTT']={'view' : DYTT } +plotter.views['singleT']={'view' : singleT } +plotter.views['SMH']={'view' : SMH } +plotter.views['TT']={'view' : TT } +#plotter.views['DY']={'view' : DY } +new_mc_samples =[] + +new_mc_samples.extend(['EWKDiboson', + 'SMH', 'singleT',#'Wplus', + 'TT'#, + #'DYLL', #'DYTT' +]) +def get_fakeTaus(x): + y=x + if x.startswith('os') or x.startswith('ss'): + y = x.replace('.*s/', 'tLoose/*s/') + + return y + +print mc_samples + +#myFake = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('data'), mc_samples)]),**remove_name_entry(data_styles['Fakes*'])), 'Fakes') + +Fakes = views.SubdirectoryView(views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : 'Fake*' in x, mc_samples)]), **remove_name_entry(data_styles['Fakes*'])),'Fakes'), 'tLoose/') + + +plotter.views['Fakes']= {'view': Fakes} +new_mc_samples.extend(['Fakes']) + +print new_mc_samples + +histoname = [('tPt', 'p_T(#tau) (GeV)', 5), ('tEta', '#eta(#tau)', 2), ('tPhi', '#phi(#tau)', 5), + ('ePt', 'p_T(e) (GeV)', 5), ('eEta', '#eta(e)', 2), ('ePhi', '#phi(e)', 5), + ('et_DeltaPhi', 'e#tau #Delta#phi', 1.), ('et_DeltaR', 'e#tau #Delta{R}', 1.), + ('h_collmass_pfmet', 'M_{coll}(e#tau) (GeV)', 1.), ('h_vismass', 'M_{vis} (GeV)', 1.), + ('jetN_30', 'number of jets (p_T > 30 GeV)', 1.) ] + + +plotter.mc_samples = new_mc_samples +foldernames = [] +for i in sign: + for j in processtype: + for k in threshold: + #foldernames.append(i+'/'+j+'/'+k) + for jn in jets: + + foldernames.append(i+'/'+j+'/'+k +'/'+str(jn)) + #foldernames.append(i+'/'+j+'/'+k +'/'+str(jn)+'/selected') + + + +for foldername in foldernames: + for n,h in enumerate(histoname) : + + + plotter.pad.SetLogy(False) + #print foldername + + plotter.plot_with_bkg_uncert(foldername,h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=True, ratio_range=1., sort=True, obj=['e']) + #plotter.plot_mc_vs_data(foldername, h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=False, ratio_range=0.2) + + + + if not os.path.exists(outputdir+foldername): + os.makedirs(outputdir+foldername) + + plotter.save(foldername+'/'+h[0]) + + diff --git a/lfvetau/plotRecoQuantitiesMVA.py b/lfvetau/plotRecoQuantitiesMVA.py new file mode 100644 index 00000000..f7078209 --- /dev/null +++ b/lfvetau/plotRecoQuantitiesMVA.py @@ -0,0 +1,186 @@ +#from mauro plotters +import os +from sys import argv, stdout, stderr +import ROOT +import sys +from FinalStateAnalysis.PlotTools.MegaBase import make_dirs +from FinalStateAnalysis.MetaData.data_styles import data_styles +from FinalStateAnalysis.PlotTools.BlindView import BlindView, blind_in_range +from FinalStateAnalysis.PlotTools.SubtractionView import SubtractionView, PositiveView + +import glob +import logging +import sys +from BasePlotter import BasePlotter + +jobid = os.environ['jobid'] +#jobid = 'MCntuples_3March' +channel = 'et' +import rootpy.plotting.views as views + +ROOT.gROOT.SetStyle("Plain") +ROOT.gROOT.SetBatch(True) +ROOT.gStyle.SetOptStat(0) + +print "\nPlotting %s for %s\n" % (channel, jobid) + +mc_samples = [ + 'ggHiggsToETau', + 'vbfHiggsToETau', + 'GluGluToHToTauTau_M-125_8TeV-powheg-pythia6', + 'VBF_HToTauTau_M-125_8TeV-powheg-pythia6', + #'Zjets_M50', + 'Zjets_M50_skimmedLL', + 'Z1jets_M50_skimmedLL', + 'Z2jets_M50_skimmedLL', + 'Z3jets_M50_skimmedLL', + 'Z4jets_M50_skimmedLL', + 'Zjets_M50_skimmedTT', + 'Z1jets_M50_skimmedTT', + 'Z2jets_M50_skimmedTT', + 'Z3jets_M50_skimmedTT', + 'Z4jets_M50_skimmedTT', + 'TTJets*', + 'T_t*', + 'Tbar_t*', + #'WplusJets_madgraph_skimmed', + 'Wplus1Jets_madgraph*', + #'Wplus1Jets_madgraph_tapas', + 'Wplus2Jets_madgraph*', + #'Wplus2Jets_madgraph_tapas', + 'Wplus3Jets_madgraph', + 'Wplus4Jets_madgraph', + 'WWJets*', + 'WZJets*', + 'ZZJets*', + 'Fake*', + 'data*' +] + + +files = [] +lumifiles = [] + +for x in mc_samples: + files.extend(glob.glob('results/%s/LFVHETauAnalyzerMVA_noOverlap/%s.root' % (jobid, x))) + lumifiles.extend(glob.glob('inputs/%s/%s.lumicalc.sum' % (jobid, x))) + +sign = ['os', 'ss'] +jets = [0, 1, 2] +processtype=['gg'] +threshold=['ept30'] + +outputdir = 'plots/%s/LFVHETauAnalyzerMVA/%s/' % (jobid, channel) +if not os.path.exists(outputdir): + os.makedirs(outputdir) + + + +def remove_name_entry(dictionary): + return dict( [ i for i in dictionary.iteritems() if i[0] != 'name'] ) + + + + +plotter = BasePlotter(channel,files, lumifiles, outputdir, forceLumi=19800) + +ggMCSignal =views.ScaleView( views.TitleView(views.StyleView(plotter.get_view('ggHiggsToETau'), **remove_name_entry(data_styles['ggHiggsToETau*'])), 'LFV gg Higgs, BR = 1.'),1.) +vbfMCSignal = views.ScaleView(views.TitleView(views.StyleView(plotter.get_view('vbfHiggsToETau'), **remove_name_entry(data_styles['vbfHiggsToETau*'])), 'LFV vbf Higgs, BR = 1.'),1.) + +plotter.views['ggMCSignal']= {'view': ggMCSignal} +plotter.views['vbfMCSignal']= {'view': vbfMCSignal} + +EWKDiboson = views.TitleView(views.StyleView( + views.SumView( + *[ plotter.get_view(regex) for regex in \ + filter(lambda x : x.startswith('WW') or x.startswith('WZ') or x.startswith('ZZ') or x.startswith('WG'), mc_samples )] + ), **remove_name_entry(data_styles['WW*'#,'WZ*', 'WG*', 'ZZ*' +]) +), 'EWK Dibosons') +Wplus = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('Wplus'), mc_samples )]), **remove_name_entry(data_styles['Wplus*Jets*'])), 'W + jets') +DYLL = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('skimmedLL'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*LL'])), 'DY (#rightarrow ll) + jets') +DYLLfake = views.SubdirectoryView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedLL'), mc_samples )]), 'tLoose') + +DYTT = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedTT'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*TT'])), +'DY (#rightarrow #tau#tau) + jets') +TT = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('TT') , mc_samples)]), **remove_name_entry(data_styles['TTJets*'])), 't#bar{t}') +singleT = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('T_') or x.startswith('Tbar_'), mc_samples)]), **remove_name_entry(data_styles['T*_t*'])), 'Single Top') +SMH = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : 'HToTauTau' in x , mc_samples)]), **remove_name_entry(data_styles['GluGluToHToTauTau*'])), 'SM Higgs') + + +plotter.views['EWKDiboson']={'view' : EWKDiboson } +plotter.views['Wplus']={'view' : Wplus } +#plotter.views['DYLL']={'view' : DYLL } +plotter.views['DYTT']={'view' : DYTT } +plotter.views['singleT']={'view' : singleT } +plotter.views['SMH']={'view' : SMH } +plotter.views['TT']={'view' : TT } +#plotter.views['DY']={'view' : DY } +new_mc_samples =[] + +#DYLL = views.TitleView(views.StyleView(views.SubtractionView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedTT'), mc_samples )]), views.SubdirectoryView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedLL'), mc_samples )]), 'tLoose')), **remove_name_entry(data_styles['Z*jets*LL'])), 'DY (#rightarrow ll) + jets') +finalDYLL = SubtractionView(DYLL,DYLLfake) +plotter.views['finalDYLL']={'view' : finalDYLL } + +new_mc_samples.extend(['EWKDiboson', + 'SMH', 'singleT',#'Wplus', + 'TT', + 'finalDYLL', 'DYTT'#, 'ggMCSignal', 'vbfMCSignal' +]) +def get_fakeTaus(x): + y=x + if x.startswith('os') or x.startswith('ss'): + y = x.replace('.*s/', 'tLoose/*s/') + + return y + +#myFake = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('Fake'), mc_samples)]),**data_styles['Fakes*']), 'Fakes') + +Fakes = views.SubdirectoryView(views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : 'Fake*' in x, mc_samples)]), **remove_name_entry(data_styles['Fakes*'])),'Fakes'), 'tLoose/') + +#SumView(views.PathModifierView( views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('Fake'), mc_samples)]), get_fakeTaus)),**remove_name_entry(data_styles['Fakes*'])), 'Fakes') +plotter.views['Fakes']= {'view': Fakes} +new_mc_samples.extend(['Fakes']) + +print new_mc_samples + +histoname = [('tPt', 'p_{T}(#tau) (GeV)', 5), ('tEta', '#eta(#tau)', 2), ('tPhi', '#phi(#tau)', 5), + ('ePt', 'p_{T}(e) (GeV)', 5), ('eEta', '#eta(e)', 2), ('ePhi', '#phi(e)', 5), + ('et_DeltaPhi', 'e#tau #Delta#phi', 1.), ('et_DeltaR', 'e#tau #Delta R', 1.), + ('h_collmass_pfmet', 'M_{coll}(e#tau) (GeV)', 1.), ('h_vismass', 'M_{vis} (GeV)', 1.), + ('jetN_30', 'number of jets (p_{T} > 30 GeV)', 1.) , ('ePFMET_Mt', 'M_{T} e-PFMET', 5), + ('tPFMET_Mt', 'M_{T} #tau-PFMET', 5) ] + + +plotter.mc_samples = new_mc_samples +foldernames = [] +for i in sign: + for j in processtype: + for k in threshold: + for jn in jets: + + foldernames.append(i+'/'+j+'/'+k +'/'+str(jn)) + foldernames.append(i+'/'+j+'/'+k +'/'+str(jn)+'/selected') + + + +for foldername in foldernames: + for n,h in enumerate(histoname) : + + + plotter.pad.SetLogy(False) + #print foldername + + #plotter.simpleplot_mc(foldername,['ggMCSignal','vbfMCSignal'], h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, forceLumi=19800) + #plotter.plot_with_bkg_uncert(foldername,h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.5, sort=True, obj=['e']) + plotter.plot_without_uncert(foldername,h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.5, sort=True, obj=['e']) + #plotter.plot_mc_vs_data(foldername, h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=False, ratio_range=0.2) + + + + if not os.path.exists(outputdir+foldername): + os.makedirs(outputdir+foldername) + + plotter.save(foldername+'/'+h[0]) + + diff --git a/lfvetau/plotTauFakeRateMVA.py b/lfvetau/plotTauFakeRateMVA.py new file mode 100644 index 00000000..d59f2a69 --- /dev/null +++ b/lfvetau/plotTauFakeRateMVA.py @@ -0,0 +1,190 @@ +import rootpy.plotting.views as views +#from FinalStateAnalysis.PlotTools.SimplePlotter import SimplePlotter +from FinalStateAnalysis.PlotTools.Plotter import Plotter +from FinalStateAnalysis.PlotTools.BlindView import BlindView +from FinalStateAnalysis.PlotTools.PoissonView import PoissonView +from FinalStateAnalysis.PlotTools.MedianView import MedianView +from FinalStateAnalysis.PlotTools.ProjectionView import ProjectionView +#from FinalStateAnalysis.PlotTools.FixedIntegralView import FixedIntegralView +from FinalStateAnalysis.PlotTools.RebinView import RebinView +from FinalStateAnalysis.MetaData.data_styles import data_styles, colors +from FinalStateAnalysis.PlotTools.decorators import memo +from FinalStateAnalysis.MetaData.datacommon import br_w_leptons, br_z_leptons +from optparse import OptionParser +import os +import ROOT +import glob +import math +import logging +from fnmatch import fnmatch +from yellowhiggs import xs, br, xsbr + +ROOT.gROOT.SetBatch() +ROOT.gStyle.SetOptStat(0) + +jobid = os.environ['jobid'] + +print jobid +mc_samples = [ + 'ggHiggsToETau', + 'vbfHiggsToETau', + 'GluGluToHToTauTau_M-125_8TeV-powheg-pythia6', + 'VBF_HToTauTau_M-125_8TeV-powheg-pythia6', + 'Zjets_M50_skimmedLL', + 'Z1jets_M50_skimmedLL', + 'Z2jets_M50_skimmedLL', + 'Z3jets_M50_skimmedLL', + 'Z4jets_M50_skimmedLL', + 'Zjets_M50_skimmedTT', + 'Z1jets_M50_skimmedTT', + 'Z2jets_M50_skimmedTT', + 'Z3jets_M50_skimmedTT', + 'Z4jets_M50_skimmedTT', + 'TTJets*', + 'T_t*', + 'Tbar_t*', + 'WplusJets_madgraph_skimmed', + 'Wplus1Jets_madgraph', + 'Wplus1Jets_madgraph_tapas', + 'Wplus2Jets_madgraph', + 'Wplus2Jets_madgraph_tapas', + 'Wplus3Jets_madgraph', + 'Wplus4Jets_madgraph', + 'WWJets*', + 'WZJets*', + 'ZZJets*', + 'data*' +] + +files = [] +lumifiles = [] +channel = 'eet' +for x in mc_samples: + #print x + files.extend(glob.glob('results/%s/TauFakeRateAnalyzerMVA/%s.root' % (jobid, x))) + lumifiles.extend(glob.glob('inputs/%s/%s.lumicalc.sum' % (jobid, x))) + + + +period = '8TeV' +sqrts = 7 if '7TeV' in jobid else 8 + +def remove_name_entry(dictionary): + return dict( [ i for i in dictionary.iteritems() if i[0] != 'name'] ) + + +#sign = ['ss','os'] +sign = ['os'] +tauiso = ['tNoCuts', 'tSuperSuperLoose', 'tSuperLoose', 'tLoose', 'tTigh'] +#sign = ['os'] +#tauiso=['tTigh'] +outputdir = 'plots/%s/TauFakeRateAnalyzerMVA/%s/' % (jobid, channel) +if not os.path.exists(outputdir): + os.makedirs(outputdir) + +plotter = Plotter(files, lumifiles, outputdir) + + + + +EWKDiboson = views.StyleView( + views.SumView( + *[ plotter.get_view(regex) for regex in \ + filter(lambda x : x.startswith('WW') or x.startswith('WZ') or x.startswith('ZZ') or x.startswith('WG'), mc_samples )] +# filter(lambda x : x.startswith('WZ') , mc_samples )] + ), **remove_name_entry(data_styles['WW*'#,'WZ*', 'WG*', 'ZZ*' +]) +) +Wplus = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('Wplus'), mc_samples )]), **remove_name_entry(data_styles['Wplus*Jets*'])) +DYLL = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('skimmedLL'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*LL'])) +DYTT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedTT'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*TT'])) +singleT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('T_') or x.startswith('Tbar_'), mc_samples)]), **remove_name_entry(data_styles['T*_t*'])) + +SMH = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : 'HToTauTau' in x , mc_samples)]), **remove_name_entry(data_styles['GluGluToHToTauTau*'])) + + +plotter.views['EWKDiboson']={'view' : EWKDiboson } +plotter.views['Wplus']={'view' : Wplus } +plotter.views['DYLL']={'view' : DYLL } +plotter.views['DYTT']={'view' : DYTT } +plotter.views['singleT']={'view' : singleT } +plotter.views['SMH']={'view' : SMH } + + +new_mc_samples = filter( lambda x : x.startswith('TTJets') , mc_samples) +#new_mc_samples = [] +#new_sigsamples= filter(lambda x: x.endswith('HiggsToETau'), mc_samples) + +#print new_sigsamples +new_mc_samples.extend(['EWKDiboson', 'SMH', 'singleT','Wplus', 'DYLL', 'DYTT' , +]) +#new_mc_samples.extend(['EWKDiboson','DYLL', 'DYTT']) +print new_mc_samples + + +#histoname = ['e1Pt','e1Phi','e1Eta','e2Pt','e2Phi','e2Eta', +# 'e1e2Mass', 'tPt','tPhi','tEta'] +#axistitle = ['e1 p_{T} (GeV)','e1 #phi','e1 #eta', 'e2 p_{T} (GeV)','e2 #phi','e2 #eta', 'e1-e2 Inv Mass (GeV)','#tau p_{T} (GeV)','#tau #phi','#tau #eta'] + +histoname = [('e1Pt','e1 p_{T} (GeV)', 2),('e1Phi','e1 #phi',4),('e1Eta','e1 #eta',2),('e2Pt','e2 p_{T} (GeV)',2),('e2Phi','e2 #phi',4),('e2Eta','e2 #eta',2), + ('e1e2Mass', 'e1-e2 Inv Mass (GeV)',1), ('tPt','#tau p_{T} (GeV)',2), ('tPhi','#tau #phi',4),('tEta','#tau #eta',2),('tAbsEta','#tau |#eta|',2), + ('etDR', 'e #tau dR', 2), ('etDPhi', 'e #tau #Delta#phi', 2), ('ztDR', 'Z #tau dR', 2), ('ztDPhi', 'Z #tau #Delta#phi', 2), ('type1_pfMetEt', 'type1_pfMet', 2), ( 'jetN_30', 'Number of jets, p_{T}>30', 1), ('bjetCSVVeto30', 'Number of b-jets',1) , ('tRawIso3Hits', 'tRawIso3Hits', 1) +] + +#rebins = [5, 5, 2, 5, 5, 2, 1, 5, 5, 2, 1] +#rebins = [] +#for n in histoname : +# rebins.append(1) + + +plotter.mc_samples = new_mc_samples + +print plotter.mc_samples + +for i in tauiso : + for s in sign : + #for histo, axis in zip(histoname, axistitle): +# for n,h in enumerate(histoname) : + foldername = s+'/'+i + if not os.path.exists(outputdir+foldername): + os.makedirs(outputdir+foldername) + + if i == 'tNoCuts': + plotter.plot_mc_vs_data(foldername,'CUT_FLOW', rebin=1, xaxis='CUT_FLOW', leftside=False, show_ratio=False, ratio_range=1.5, sorted=True) + plotter.save(foldername+'/CUT_FLOW') + + foldername = s+'/'+i + for h in histoname: + #plotter.canvas.SetLogy(True) + #plotter.plot_data(foldername, h, rebin=rebins[n], xaxis= axistitle[n], leftside=False) + #plotter.plot_mc_vs_data(foldername,h, rebin=rebins[n], xaxis= axistitle[n], leftside=False, show_ratio=True, ratio_range=1.5, sort=True) + + plotter.plot_mc_vs_data(foldername,h[0], rebin=h[2], xaxis=h[1], leftside=False, show_ratio=True, ratio_range=1.5, sorted=True) + plotter.save(foldername+'/'+h[0]) + + +# foldername = s+'/'+i+'/tptregion' +# if not os.path.exists(outputdir+foldername): +# os.makedirs(outputdir+foldername) + +# for h in histoname: +# plotter.plot_mc_vs_data(foldername,h[0], rebin=h[2], xaxis=h[1], leftside=False, show_ratio=True, ratio_range=1.5, sorted=True) +# plotter.save(foldername+'/'+h[0]) + + + jets=0 + while jets < 4 : + foldername = s+'/'+i+'/'+str(int(jets)) + if not os.path.exists(outputdir+foldername): + os.makedirs(outputdir+foldername) + for h in histoname: + plotter.plot_mc_vs_data(foldername,h[0], rebin=h[2], xaxis=h[1], leftside=False, show_ratio=True, ratio_range=1.5, sorted=True) + plotter.save(foldername+'/'+h[0]) + # foldername = s+'/'+i+'/'+str(int(jets))+'/tptregion' + # if not os.path.exists(outputdir+foldername): + # os.makedirs(outputdir+foldername) + # for h in histoname: + # plotter.plot_mc_vs_data(foldername,h[0], rebin=h[2], xaxis=h[1], leftside=False, show_ratio=True, ratio_range=1.5, sorted=True) + # plotter.save(foldername+'/'+h[0]) + jets+=1 + diff --git a/lfvetau/readNtuple.py b/lfvetau/readNtuple.py new file mode 100644 index 00000000..6db52736 --- /dev/null +++ b/lfvetau/readNtuple.py @@ -0,0 +1,37 @@ +import ROOT +import os +from sys import argv, stdout, stderr +import sys +import glob +import logging + +#jobid = os.environ['jobid'] +jobid = 'newNtuple_2Sept_old' +from os import listdir +from os.path import isfile, join + +ROOT.gROOT.SetBatch(True) +ROOT.gStyle.SetPadGridY(True) +ROOT.gStyle.SetPadGridX(True) + +from ETauTree import ETauTree +import math + +##oldntuple +#f=ROOT.TFile("/hdfs/store/user/taroni/newNtuple_3June/data_SingleElectron_Run2012B_22Jan2013_v1/make_ntuples_cfg-patTuple_cfg-00FB7F10-C77D-E211-B334-003048CF9B4E.root") +##newNtuple +#f = ROOT.TFile("/hdfs/store/user/taroni/newNtuple_2Sept/data_SingleElectron_Run2012B_22Jan2013_v1/make_ntuples_cfg-patTuple_cfg-00FB7F10-C77D-E211-B334-003048CF9B4E.root") +##mc +#f= ROOT.TFile("/hdfs/store/user/taroni/newNtuple_2Sept/Zjets_M50_skimmedLL/make_ntuples_cfg-patTuple_cfg-00037C53-AAD1-E111-B1BE-003048D45F38.root") +#more trees in ntuple +#f= ROOT.TFile("/hdfs/store/user/taroni/testneNtupleMoreTrees/Zjets_M50/make_ntuples_cfg-patTuple_cfg-00037C53-AAD1-E111-B1BE-003048D45F38.root") +#one tree only +#f= ROOT.TFile("/hdfs/store/user/taroni/testneNtuple/Zjets_M50/make_ntuples_cfg-patTuple_cfg-00037C53-AAD1-E111-B1BE-003048D45F38.root") + + +f.ls() +mytree = f.Get("et/final/Ntuple") + +for n, event in enumerate(mytree) : + if n > 100 : break + print event.run, event.lumi, event.evt, event.tPhi, event.ePhi, event.tEta, event.eEta, event.tPt, event.ePt diff --git a/lfvetau/run.sh b/lfvetau/run.sh new file mode 100755 index 00000000..96ac7086 --- /dev/null +++ b/lfvetau/run.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Run all of the analysis + +set -o nounset +set -o errexit + +export MEGAPATH=/hdfs/store/user/taroni/ +source jobid.sh +#export jobid=$jobid8 +export jobid='newNtuple_9Oct' +#export jobid='newNtuple_11June' +#export jobid='newNtuple_3JuneOldWXJetsXsec' +#rake genkin +#rake recoplots +rake recoplotsMVA +#rake recoplotsMVAeMtcut +#rake controlplots +#rake controlplotsMVA +#rake fakeeet +#rake fakeeetMVA +#rake fits +#rake drawTauFakeRate +#export jobid=$jobidmt +#rake recoplotsMuTau +#rake drawplots +#rake genkinEMu +#rake genkinMuTau diff --git a/lfvetau/setup.sh b/lfvetau/setup.sh new file mode 100755 index 00000000..32b8641e --- /dev/null +++ b/lfvetau/setup.sh @@ -0,0 +1,27 @@ +#!/bin/bash +export OVERRIDE_META_TREE_data_ET='et/metaInfo' + +export IGNORE_LUMI_ERRORS=1 + +source jobid.sh +#export jobid=$jobid8 + +export jobid='newNtuple_9Oct' +echo $jobid +export datasrc=/hdfs/store/user/$USER/ #$(ls -d /scratch/*/data/$jobid | awk -F$jobid '{print $1}') +#export datasrc=/nfs_scratch/taroni/data +export MEGAPATH=/hdfs/store/user/$USER +#export MEGAPATH=/nfs_scratch/taroni/data +./make_proxies.sh +rake "meta:getinputs[$jobid, $datasrc,et/metaInfo]" +rake "meta:getmeta[inputs/$jobid, et/metaInfo, 8]" +#export jobid=$jobidmt +#./make_proxies.sh +#rake "meta:getinputs[$jobid, $datasrc,em/metaInfo]" +#rake "meta:getmeta[inputs/$jobid, em/metaInfo, 8]" +#rake "meta:getinputs[$jobid, $datasrc,mt/metaInfo]" +#rake "meta:getmeta[inputs/$jobid, mt/metaInfo, 8]" + + +unset OVERRIDE_META_TREE_data_ET +unset IGNORE_LUMI_ERRORS From ef8eb29a6160306ea0af83bbccbf1ee509c91612 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Thu, 16 Oct 2014 08:15:59 -0500 Subject: [PATCH 104/192] adding old plotters --- lfvetau/plotControlEE.py | 146 +++++++++++++ lfvetau/plotControlEE_MVAcorrected.py | 203 ++++++++++++++++++ lfvetau/plotGenQuantities.py | 130 ++++++++++++ lfvetau/plotMyReco.py | 286 ++++++++++++++++++++++++++ lfvetau/plotMyRecoMuTau.py | 245 ++++++++++++++++++++++ lfvetau/plotRecoQuantities.py | 123 +++++++++++ lfvetau/plotRecoQuantitiesMVA.py | 15 +- lfvetau/setupBatch.sh | 6 + 8 files changed, 1150 insertions(+), 4 deletions(-) create mode 100644 lfvetau/plotControlEE.py create mode 100644 lfvetau/plotControlEE_MVAcorrected.py create mode 100644 lfvetau/plotGenQuantities.py create mode 100644 lfvetau/plotMyReco.py create mode 100644 lfvetau/plotMyRecoMuTau.py create mode 100644 lfvetau/plotRecoQuantities.py create mode 100644 lfvetau/setupBatch.sh diff --git a/lfvetau/plotControlEE.py b/lfvetau/plotControlEE.py new file mode 100644 index 00000000..45a75c23 --- /dev/null +++ b/lfvetau/plotControlEE.py @@ -0,0 +1,146 @@ +import rootpy.plotting.views as views +from FinalStateAnalysis.PlotTools.Plotter import Plotter +from FinalStateAnalysis.PlotTools.BlindView import BlindView +from FinalStateAnalysis.PlotTools.PoissonView import PoissonView +from FinalStateAnalysis.PlotTools.MedianView import MedianView +from FinalStateAnalysis.PlotTools.ProjectionView import ProjectionView +#from FinalStateAnalysis.PlotTools.FixedIntegralView import FixedIntegralView +from FinalStateAnalysis.PlotTools.RebinView import RebinView +from FinalStateAnalysis.MetaData.data_styles import data_styles, colors +from FinalStateAnalysis.PlotTools.decorators import memo +from FinalStateAnalysis.MetaData.datacommon import br_w_leptons, br_z_leptons +from optparse import OptionParser +import os +import ROOT +import glob +import math +import logging +from fnmatch import fnmatch +from yellowhiggs import xs, br, xsbr + +ROOT.gROOT.SetBatch() +ROOT.gStyle.SetOptStat(0) +jobid = os.environ['jobid'] + +print jobid +mc_samples = [ + 'ggHiggsToETau', + 'vbfHiggsToETau', + 'GluGluToHToTauTau_M-125_8TeV-powheg-pythia6', + 'VBF_HToTauTau_M-125_8TeV-powheg-pythia6', + 'Zjets_M50_skimmedLL', + 'Z1jets_M50_skimmedLL', + 'Z2jets_M50_skimmedLL', + 'Z3jets_M50_skimmedLL', + 'Z4jets_M50_skimmedLL', + 'Zjets_M50_skimmedTT', + 'Z1jets_M50_skimmedTT', + 'Z2jets_M50_skimmedTT', + 'Z3jets_M50_skimmedTT', + 'Z4jets_M50_skimmedTT', + 'TTJets*', + 'T_t*', + 'Tbar_t*', + 'WplusJets_madgraph_skimmed', + 'Wplus1Jets_madgraph', + # 'Wplus1Jets_madgraph_tapas', + 'Wplus2Jets_madgraph', + # 'Wplus2Jets_madgraph_tapas', + 'Wplus3Jets_madgraph', + 'Wplus4Jets_madgraph', + 'WWJets*', + 'WZJets*', + 'ZZJets*', + 'data*' +] + +files = [] +lumifiles = [] +channel = 'ee' +for x in mc_samples: + files.extend(glob.glob('results/%s/EEAnalyzer/%s.root' % (jobid, x))) + lumifiles.extend(glob.glob('inputs/%s/%s.lumicalc.sum' % (jobid, x))) + + + +period = '8TeV' +sqrts = 7 if '7TeV' in jobid else 8 + +def remove_name_entry(dictionary): + return dict( [ i for i in dictionary.iteritems() if i[0] != 'name'] ) + + +sign = ['os', 'ss'] + +outputdir = 'plots/%s/EEAnalyzer/%s/' % (jobid, channel) +if not os.path.exists(outputdir): + os.makedirs(outputdir) + +plotter = Plotter(files, lumifiles, outputdir) + + + + +EWKDiboson = views.StyleView( + views.SumView( + *[ plotter.get_view(regex) for regex in \ + filter(lambda x : x.startswith('WW') or x.startswith('WZ') or x.startswith('ZZ') or x.startswith('WG'), mc_samples )] + ), **remove_name_entry(data_styles['WW*'#,'WZ*', 'WG*', 'ZZ*' +]) +) +Wplus = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('Wplus'), mc_samples )]), **remove_name_entry(data_styles['Wplus*Jets*'])) +DYLL = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('skimmedLL'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*LL'])) +DYTT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedTT'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*TT'])) +TT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('TT') , mc_samples)]), **remove_name_entry(data_styles['TTJets*'])) +singleT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('T_') or x.startswith('Tbar_'), mc_samples)]), **remove_name_entry(data_styles['T*_t*'])) +SMH = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : 'HToTauTau' in x , mc_samples)]), **remove_name_entry(data_styles['GluGluToHToTauTau*'])) + + +plotter.views['EWKDiboson']={'view' : EWKDiboson } +plotter.views['Wplus']={'view' : Wplus } +plotter.views['DYLL']={'view' : DYLL } +plotter.views['DYTT']={'view' : DYTT } +plotter.views['singleT']={'view' : singleT } +plotter.views['SMH']={'view' : SMH } +plotter.views['TT']={'view' : TT } + + +new_mc_samples = filter( lambda x : not x.startswith('T_') and not x.startswith('Tbar_') and not x.endswith('jets_M50_skimmedLL') and not x.endswith('jets_M50_skimmedTT') and not x.startswith('Wplus') and not x.startswith('WW') and not x.startswith('WZ') and not x.startswith('ZZ') and not x.startswith('WG') and not x.endswith('HiggsToETau') and not 'HToTauTau' and not x.startswith('data') in x, mc_samples) +#new_sigsamples= filter(lambda x: x.endswith('HiggsToETau'), mc_samples) + +#print new_sigsamples +new_mc_samples.extend(['EWKDiboson', 'SMH', 'singleT','Wplus', 'DYLL', 'DYTT' , 'TT' +]) +print new_mc_samples + +histoname = ['e1Pt','e1Phi','e1Eta','e2Pt','e2Phi','e2Eta', + 'e1e2_DeltaPhi','e1e2_DeltaR', 'e1e2Mass', + 'type1_pfMetEt', 'pfMetEt', 'type1_pfMetPhi','pfMetPhi', 'mvaMetEt', 'mvaMetPhi', + 'pfMetEt_par','pfMetEt_perp', 'type1_pfMetEt_par','type1_pfMetEt_perp', 'mvaMetEt_par','mvaMetEt_perp', + 'e1PFMET_DeltaPhi','e1PFMET_Mt','e1MVAMET_DeltaPhi','e1MVAMET_Mt','e2PFMET_DeltaPhi','e2PFMET_Mt','e2MVAMET_DeltaPhi','e2MVAMET_Mt'] +axistitle = ['e1 p_{T} (GeV)','e1 #phi','e1 #eta', 'e2 p_{T} (GeV)','e2 #phi','e2 #eta','e1-e2 #Delta#phi','e1-e2 #DeltaR', 'e1-e2 Inv Mass (GeV)', 'type1PF MET (GeV)', 'PF MET (GeV)', 'type1 PF MET #phi', 'PF MET #phi', 'MVA MET (GeV)', 'MVA MET #phi', 'PF MET parallel (GeV)', 'PF MET perpendicular (GeV)', 'type1PF MET parallel (GeV)', 'type1PF MET perpendicular (GeV)', 'MVA MET parallel (GeV)', 'MVA MET perpendicular (GeV)', +'e1-type1PFMET #Delta#phi','e1-type1PFMET M_{T} (GeV) ','e1-MVAMET #Delta#phi','e1-MVAMET M_{T} (GeV)','e2-type1PFMET #Delta#phi','e2-type1PFMET M_{T} (GeV)','e2-MVAMET #Delta#phi','e2-MVAMET #M_{T} (GeV)'] + +#rebins = [5, 5, 2, 5, 5, 2, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 5, 1, 5, 1, 5, 1, 5] +rebins = [] +for n in histoname : + rebins.append(1) + + +plotter.mc_samples = new_mc_samples +#plotter.mc_samples = mc_samples +for i in sign : + for n,h in enumerate(histoname) : + foldername = i + #plotter.pad.SetLogy(True) + +# plotter.plot_mc(foldername, ['ggHiggsToETau','vbfHiggsToETau'],h, rebin=rebins[n], xaxis= axistitle[n], leftside=False, show_ratio=False, ratio_range=1.5, rescale=10) + plotter.plot_mc_vs_data(foldername,h, rebin=rebins[n], xaxis= axistitle[n], leftside=False, show_ratio=True, ratio_range=1.5, sort=True) + + + if not os.path.exists(outputdir+foldername): + os.makedirs(outputdir+foldername) + + plotter.save(foldername+'/'+h) + + diff --git a/lfvetau/plotControlEE_MVAcorrected.py b/lfvetau/plotControlEE_MVAcorrected.py new file mode 100644 index 00000000..3ee27075 --- /dev/null +++ b/lfvetau/plotControlEE_MVAcorrected.py @@ -0,0 +1,203 @@ +import rootpy.plotting.views as views +from FinalStateAnalysis.PlotTools.Plotter import Plotter +from FinalStateAnalysis.PlotTools.BlindView import BlindView +from FinalStateAnalysis.PlotTools.PoissonView import PoissonView +from FinalStateAnalysis.PlotTools.MedianView import MedianView +from FinalStateAnalysis.PlotTools.ProjectionView import ProjectionView +#from FinalStateAnalysis.PlotTools.FixedIntegralView import FixedIntegralView +from FinalStateAnalysis.PlotTools.RebinView import RebinView +from FinalStateAnalysis.MetaData.data_styles import data_styles, colors +from FinalStateAnalysis.PlotTools.decorators import memo +from FinalStateAnalysis.MetaData.datacommon import br_w_leptons, br_z_leptons +from FinalStateAnalysis.PlotTools.SubtractionView import SubtractionView, PositiveView +from optparse import OptionParser +import os +import ROOT +import glob +import math +import logging +import pdb +import array +from fnmatch import fnmatch +from yellowhiggs import xs, br, xsbr + +from BasePlotter import BasePlotter + + +ROOT.gROOT.SetBatch() +ROOT.gStyle.SetOptStat(0) +jobid = os.environ['jobid'] + +print jobid +mc_samples = [ + 'ggHiggsToETau', + 'vbfHiggsToETau', + 'GluGluToHToTauTau_M-125_8TeV-powheg-pythia6', + 'VBF_HToTauTau_M-125_8TeV-powheg-pythia6', + #'Zjets_M50', + 'Zjets_M50_skimmedLL', + 'Z1jets_M50_skimmedLL', + 'Z2jets_M50_skimmedLL', + 'Z3jets_M50_skimmedLL', + 'Z4jets_M50_skimmedLL', + 'Zjets_M50_skimmedTT', + 'Z1jets_M50_skimmedTT', + 'Z2jets_M50_skimmedTT', + 'Z3jets_M50_skimmedTT', + 'Z4jets_M50_skimmedTT', + 'TTJets*', + 'T_t*', + 'Tbar_t*', + 'WplusJets_madgraph_skimmed', + 'Wplus1Jets_madgraph', + # 'Wplus1Jets_madgraph_tapas', + 'Wplus2Jets_madgraph', + # 'Wplus2Jets_madgraph_tapas', + 'Wplus3Jets_madgraph', + 'Wplus4Jets_madgraph', + 'WWJets*', + 'WZJets*', + 'ZZJets*', + 'data*' +] + +files = [] +lumifiles = [] +channel = 'ee' +for x in mc_samples: + files.extend(glob.glob('results/%s/EEAnalyzerMVA/%s.root' % (jobid, x))) + lumifiles.extend(glob.glob('inputs/%s/%s.lumicalc.sum' % (jobid, x))) + + + +period = '8TeV' +sqrts = 7 if '7TeV' in jobid else 8 + +def remove_name_entry(dictionary): + return dict( [ i for i in dictionary.iteritems() if i[0] != 'name'] ) + + +sign = ['os'] +jets = [0, 1, 2, 3] +outputdir = 'plots/%s/EEAnalyzerMVA/%s/' % (jobid, channel) +if not os.path.exists(outputdir): + os.makedirs(outputdir) + +plotter = BasePlotter(files, lumifiles, outputdir) + + + + +EWKDiboson = views.StyleView( + views.SumView( + *[ plotter.get_view(regex) for regex in \ + filter(lambda x : x.startswith('WW') or x.startswith('WZ') or x.startswith('ZZ') or x.startswith('WG'), mc_samples )] + ), **remove_name_entry(data_styles['WW*'#,'WZ*', 'WG*', 'ZZ*' +]) +) +Wplus = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('Wplus'), mc_samples )]), **remove_name_entry(data_styles['Wplus*Jets*'])) +DYLL = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('skimmedLL'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*LL'])) +DYTT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedTT'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*TT'])) +TT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('TT') , mc_samples)]), **remove_name_entry(data_styles['TTJets*'])) +singleT = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('T_') or x.startswith('Tbar_'), mc_samples)]), **remove_name_entry(data_styles['T*_t*'])) +SMH = views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : 'HToTauTau' in x , mc_samples)]), **remove_name_entry(data_styles['GluGluToHToTauTau*'])) + +plotter.views['EWKDiboson']={'view' : EWKDiboson } +plotter.views['Wplus']={'view' : Wplus } +plotter.views['DYLL']={'view' : DYLL } +plotter.views['DYTT']={'view' : DYTT } +plotter.views['singleT']={'view' : singleT } +plotter.views['SMH']={'view' : SMH } +plotter.views['TT']={'view' : TT } +#plotter.views['DY']={'view' : DY } +new_mc_samples =[] + +new_mc_samples.extend(['EWKDiboson', 'SMH', 'singleT','Wplus', 'TT', + 'DYLL', 'DYTT' +]) +print new_mc_samples + +binx = array.array('l', [5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,100, 120, 140, 160,200 ]) + +histoname = [('e1Pt', 'e1 p_{T} (GeV)', 5), ('e1Phi','e1 #phi',5) ,('e1Eta','e1 #eta',2), + ('e2Pt','e2 p_{T} (GeV)',5) ,('e2Phi','e2 #phi',5), ('e2Eta','e2 #eta',2), + ('e1e2_DeltaPhi','e1-e2 #Delta#phi',2), ('e1e2_DeltaR','e1-e2 #DeltaR',2), ('e1e2Mass', 'e1-e2 Inv Mass (GeV)',5), + ('type1_pfMetEt', 'type1PF MET (GeV)', 2) , ('pfMetEt', 'PF MET (GeV)', 2), + ('type1_pfMetPhi','type1 PF MET #phi', 5), ('pfMetPhi','PF MET #phi',5), + ('pfMetEt_par','PF MET parallel (GeV)',2), ('pfMetEt_perp','PF MET perpendicular (GeV)',2), + ('type1_pfMetEt_par', 'type1PF MET parallel (GeV)', 2),('type1_pfMetEt_perp', 'type1PF MET perpendicular (GeV)',2), + ('e1PFMET_DeltaPhi','e1-type1PFMET #Delta#phi',2), ('e1PFMET_Mt','e1-type1PFMET M_{T} (GeV) ',5), + ('e2PFMET_DeltaPhi','e2-type1PFMET #Delta#phi',2),('e2PFMET_Mt','e2-type1PFMET M_{T} (GeV)',5), + #('nPV_unweighted', 'unweighted N of vertices', 1), + ('nPV', 'number of vertices', 1) +] + + +plotter.mc_samples = new_mc_samples +foldernames = [] +for i in sign : + foldernames.append(i) + for j in jets : + foldernames.append(i+'/'+str(int(j))) + +def create_mapper(mapping): + def _f(path): + for key, out in mapping.iteritems(): + if key == path: + path = path.replace(key,out) + print 'path', path + return path + return _f + +def get_ss(x): + return x.replace('os/', 'ss/') + +print foldernames +mymapper = {"os/": "ss/", + "os/0/": "ss/0/", + "os/1": "ss/1", + "os/2": "ss/2", + "os/3": "ss/3" +} +QCD = views.TitleView(views.StyleView(SubtractionView( + views.PathModifierView( plotter.data, get_ss), + views.PathModifierView( TT, get_ss), + views.PathModifierView( singleT, get_ss), + views.PathModifierView( SMH, get_ss ), + views.PathModifierView( DYTT, get_ss ), + views.PathModifierView( DYLL, get_ss ), + views.PathModifierView( Wplus, get_ss ), + views.PathModifierView( EWKDiboson, get_ss )) + ,**data_styles['QCD*']), 'QCD') + + +plotter.views['QCD']= {'view': QCD} +plotter.mc_samples.extend(['QCD']) + + +for foldername in foldernames: + if foldername.startswith("ss") and bool('QCD' in plotter.mc_samples)==True: + plotter.mc_samples.remove('QCD') + if foldername.startswith("os") and bool('QCD' in plotter.mc_samples)==False: + plotter.mc_samples.extend(['QCD']) + + for n,h in enumerate(histoname) : + + + plotter.pad.SetLogy(True) + #plotter.plot('QCD', foldername+'/'+h[0], 'hist') + print foldername + #plotter.plot_mc_vs_data(foldername, h[0], rebin=h[2], xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.2, sorted=True) + + plotter.plot_with_bkg_uncert(foldername,h[0], rebin=h[2], xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.5, sort=True, obj1='e1', obj2='e2') + + + + + if not os.path.exists(outputdir+foldername): + os.makedirs(outputdir+foldername) + + plotter.save(foldername+'/'+h[0]) + + + diff --git a/lfvetau/plotGenQuantities.py b/lfvetau/plotGenQuantities.py new file mode 100644 index 00000000..cf9de9f9 --- /dev/null +++ b/lfvetau/plotGenQuantities.py @@ -0,0 +1,130 @@ +#from lfvmutau plotter +import os +from sys import argv, stdout, stderr +import ROOT +import sys +from FinalStateAnalysis.PlotTools.MegaBase import make_dirs + +ROOT.gROOT.SetStyle("Plain") +ROOT.gROOT.SetBatch(True) +ROOT.gStyle.SetOptStat(0) + +shape_norm = True +if shape_norm == False: + ynormlabel = "Normalized to Data " +else: + ynormlabel = "Normalized to 1 " + +canvas = ROOT.TCanvas("canvas","canvas",800,800) +LFVStack = ROOT.THStack("stack","") + +#lfvfilelist = ['results/MCntuples25Feb/LFVHAnalyzeGEN/ggHiggsToETau.root', 'results/MCntuples25Feb/LFVHAnalyzeGEN/vbfHiggsToETau.root'] +#smfilelist = ['results/MCntuples25Feb/LFVHAnalyzeGEN/GluGluToHToTauTau_M-125_8TeV-powheg-pythia6.root', 'results/MCntuples25Feb/LFVHAnalyzeGEN/VBF_HToTauTau_M-125_8TeV-powheg-pythia6.root'] + +lfvfilelist = ['results/MCntuples_otherCh2/LFVHAnalyzeGENEMu/ggHiggsToMuTau.root', 'results/MCntuples_otherCh2/LFVHAnalyzeGENEMu/vbfHiggsToMuTau.root','results/MCntuples_otherCh2/LFVHAnalyzeGENMuTau/ggHiggsToMuTau.root', 'results/MCntuples_otherCh2/LFVHAnalyzeGENMuTau/vbfHiggsToMuTau.root'] +smfilelist = ['results/MCntuples_otherCh2/LFVHAnalyzeGENEMu/GluGluToHToTauTau_M-125_8TeV-powheg-pythia6.root', 'results/MCntuples_otherCh2/LFVHAnalyzeGENEMu/VBF_HToTauTau_M-125_8TeV-powheg-pythia6.root','results/MCntuples_otherCh2/LFVHAnalyzeGENMuTau/GluGluToHToTauTau_M-125_8TeV-powheg-pythia6.root', 'results/MCntuples_otherCh2/LFVHAnalyzeGENMuTau/VBF_HToTauTau_M-125_8TeV-powheg-pythia6.root'] + +for n, file in enumerate(lfvfilelist): + + ETaufile = ROOT.TFile(file) + SMHTauTaufile = ROOT.TFile(smfilelist[n]) + + gendir = ETaufile.Get('gen') + hlist = gendir.GetListOfKeys() + + iter = ROOT.TIter(hlist) + + filepath = 'plots/'+ETaufile.GetName()[8 : len(ETaufile.GetName()) -5] + print filepath + startingdir = os.getcwd() + print startingdir + dirs = filepath.split('/') + print dirs + thechannel = 'e #tau_{h}' + for d in dirs: + currentdir = os.getcwd() + dirlist = os.listdir(currentdir) + + if d in dirlist: + os.chdir(d) + else: + os.makedirs(d) + os.chdir(d) + if d == "LFVHAnalyzeGENEMu" : + thechannel='#mu #tau_{e}' + thesmchannel = "#tau_{#mu}#tau_{e}" + if d == "LFVHAnalyzeGENMuTau" : + thechannel='#mu #tau_{h}' + thesmchannel = "#tau_{#mu}#tau_{h}" + + os.chdir(startingdir) + + for i in iter: + lfv_histo = ETaufile.Get('gen/'+i.GetName()) + sm_histo = SMHTauTaufile.Get('gen/'+i.GetName()) + + if lfv_histo.Integral() != 0 and sm_histo.Integral() != 0 : + lfv_histo.Scale(1./lfv_histo.Integral()) + sm_histo.Scale(1./sm_histo.Integral()) + + p = sm_histo.GetName()[0:1] + if p == 't' : p = '#tau' + if p == 'h' : + lfv_histo.Draw("E") + else: + + sm_histo.Draw("E") + lfv_histo.Draw("ESAME") + + lfv_histo.SetLineWidth(2) + sm_histo.SetLineColor(2) + sm_histo.SetLineWidth(2) + + + canvas.SetLogy(0) + variable='' + if sm_histo.GetName()[4:7] == "Phi" : variable = "#phi" + if sm_histo.GetName()[4:7] == "Eta" : variable = "#eta" + if sm_histo.GetName()[4:10] == "Energy" : + variable = "energy (GeV)" + canvas.SetLogy(1) + if sm_histo.GetName()[4:6] == "Pt" : + variable = "p_{T} (GeV)" + canvas.SetLogy(1) + if sm_histo.GetName()[9:17] == "DeltaPhi" : + variable = "#Delta#phi" + p = 'e#tau' + canvas.SetLogy(1) + if sm_histo.GetName() == "higgsPt" : + variable = "p_{T} (GeV)" + canvas.SetLogy(1) + axislabel = p+" "+variable + if variable != '' : lfv_histo.GetXaxis().SetTitle(axislabel) + + maxlfv = lfv_histo.GetBinContent(lfv_histo.GetMaximumBin()) + maxsm = sm_histo.GetBinContent(sm_histo.GetMaximumBin()) + if canvas.GetLogy()==0 : + if maxlfv > maxsm : + lfv_histo.GetYaxis().SetRangeUser(0, maxlfv*1.3) + else : + lfv_histo.GetYaxis().SetRangeUser(0, maxsm*1.3) + + if sm_histo.GetName()[4:13] == 'DecayMode': + legend = ROOT.TLegend(0.6,0.75,0.8,0.85) + else : + legend = ROOT.TLegend(0.38,0.15,0.62,0.25) + + legend.SetFillColor(0) + if thechannel == 'e #tau_{h}' : + legend.AddEntry(sm_histo, "H #rightarrow #tau_{e}#tau_{h} ") + legend.AddEntry(lfv_histo, "H #rightarrow e#tau_{h} ") + else: + legend.AddEntry(sm_histo, "H #rightarrow " +thesmchannel) + legend.AddEntry(lfv_histo, "H #rightarrow "+ thechannel) + + if p != 'h' : + legend.Draw() + + canvas.Update() + canvas.SaveAs(filepath+'/gen_'+i.GetName()+'.png') + diff --git a/lfvetau/plotMyReco.py b/lfvetau/plotMyReco.py new file mode 100644 index 00000000..644c2a26 --- /dev/null +++ b/lfvetau/plotMyReco.py @@ -0,0 +1,286 @@ +#from lfvmutau plotter +import os +from sys import argv, stdout, stderr +import ROOT +import sys +from FinalStateAnalysis.PlotTools.MegaBase import make_dirs +from math import sqrt + +ROOT.gROOT.SetStyle("Plain") +ROOT.gROOT.SetBatch(True) +ROOT.gStyle.SetOptStat(0) + +shape_norm = True +if shape_norm == False: + ynormlabel = "Normalized to Data " +else: + ynormlabel = "Normalized to 1 " + +#jobid = os.environ['jobid'] +jobid = 'MCntuples_14April' +import inspect + +def lineno(): + """Returns the current line number in our program.""" + return inspect.currentframe().f_back.f_lineno + +lfvfilelist = [] +legendlist = [] + +if jobid!='MCntuples_14April': + lfvfilelist = ['ggHiggsToETau','vbfHiggsToETau', + ['Zjets_M50'], + ['WplusJets_madgraph'], + ['WZJetsTo3LNu_TuneZ2_8TeV-madgraph-tauola', 'WZJetsTo2L2Q_TuneZ2star_8TeV-madgraph-tauola', 'WWJetsTo2L2Nu_TuneZ2star_8TeV-madgraph-tauola', 'ZZJetsTo4L_TuneZ2star_8TeV-madgraph-tauola','ZZJetsTo2L2Q_TuneZ2star_8TeV-madgraph-tauola'], + ['TTJetsFullLepMGDecays', 'TTJetsSemiLepMGDecays'], + ['T_t-channel_TuneZ2star_8TeV-powheg-tauola','T_tW-channel-DR_TuneZ2star_8TeV-powheg-tauola','Tbar_t-channel_TuneZ2star_8TeV-powheg-tauola','Tbar_tW-channel-DR_TuneZ2star_8TeV-powheg-tauola'], ['GluGluToHToTauTau_M-125_8TeV-powheg-pythia6', 'VBF_HToTauTau_M-125_8TeV-powheg-pythia6'] + ] + + legendlist = ['LFV GG Higgs', 'LFV VBF Higgs', 'DY + jets', 'W + jets', 'EWK Dibosons', 'ttbar', 'single Top', 'SM Higgs'] + +else: + lfvfilelist = ['ggHiggsToETau','vbfHiggsToETau', + ['Zjets_M50'], + #['Zjets_M50_skimmedLL', 'Z1jets_M50_skimmedLL', 'Z2jets_M50_skimmedLL', 'Z3jets_M50_skimmedLL'], + #['Zjets_M50_skimmedTT', 'Z1jets_M50_skimmedTT', 'Z2jets_M50_skimmedTT', 'Z3jets_M50_skimmedTT','Z4jets_M50_skimmedTT'], + ['WplusJets_madgraph_skimmed','Wplus4Jets_madgraph','Wplus2Jets_madgraph_tapas', 'Wplus2Jets_madgraph', 'Wplus1Jets_madgraph_tapas', 'Wplus3Jets_madgraph', 'Wplus1Jets_madgraph'], + ['WZJetsTo3LNu_TuneZ2_8TeV-madgraph-tauola', 'WZJetsTo2L2Q_TuneZ2star_8TeV-madgraph-tauola', 'WWJetsTo2L2Nu_TuneZ2star_8TeV-madgraph-tauola', 'ZZJetsTo4L_TuneZ2star_8TeV-madgraph-tauola','ZZJetsTo2L2Q_TuneZ2star_8TeV-madgraph-tauola'], + #['TTJetsFullLepMGDecays', 'TTJetsSemiLepMGDecays'], + ['TTJetsSemiLepMGDecays'], + ['T_t-channel_TuneZ2star_8TeV-powheg-tauola','T_tW-channel-DR_TuneZ2star_8TeV-powheg-tauola','Tbar_t-channel_TuneZ2star_8TeV-powheg-tauola','Tbar_tW-channel-DR_TuneZ2star_8TeV-powheg-tauola'], ['GluGluToHToTauTau_M-125_8TeV-powheg-pythia6', 'VBF_HToTauTau_M-125_8TeV-powheg-pythia6'] + ] + + legendlist = ['LFV GG Higgs', 'LFV VBF Higgs', 'Z/#gamma* #rightarrow ll + jets', #'Z/#gamma* #rightarrow #tau#tau + jets', + 'W + jets', 'EWK Dibosons', 'ttbar', 'single Top', 'SM Higgs'] + + + +sourcepath = 'results/'+jobid+'/LFVHETauAnalyzer/' +sign = ['os', 'ss'] +process = ['gg']#['gg','vbf'] +ptcut = [0]#[0, 40] +jetN = [0]#[0,1,2,3] +legend = ROOT.TLegend(0.58,0.15,0.82,0.35) +legend.SetFillColor(0) + + +histolist = ['tPt', 'tPhi', 'tEta', +'ePt', 'ePhi', 'eEta', +'et_DeltaPhi', 'et_DeltaR', +'tPFMET_DeltaPhi', 'tPFMET_Mt', 'tMVAMET_DeltaPhi', 'tMVAMET_Mt', +'ePFMET_DeltaPhi','ePFMET_Mt', 'eMVAMET_DeltaPhi', 'eMVAMET_Mt', +'jetN_20', 'jetN_30', +'h_collmass_pfmet', 'h_collmass_mvamet', 'h_vismass' +] +rebins = [5,5,2,5,5,2,1, 1, 2, 5, 2, 5, 2, 5, 2, 5,1,1,1,1,1] +axistitle = ['#tau p_{T} (GeV)','#tau #phi','#tau #eta', +'e p_{T} (GeV)','e #phi','e #eta', +'e-#tau #Delta#phi','e-#tau #DeltaR', +'#tau-PFMET #Delta#phi','#tau-PFMET M_{T} (GeV) ','#tau-MVAMET #Delta#phi','#tau-MVAMET M_{T} (GeV)', +'e-PFMET #Delta#phi','e-PFMET M_{T} (GeV)','e-MVAMET #Delta#phi','e-MVAMET #M_{T} (GeV)', +'Number of jets (p_{T}>20)','Number of jets (p_{T}>30)', +'M_{e#tau}coll (GeV)','M_{e#tau}coll (GeV)','M_{e#tau} vis (GeV)' +] + +scalefactors=[] +for myfile in lfvfilelist: + if type(myfile) is list: + for subfile in myfile : + lumifile = 'inputs/'+jobid+'/'+subfile[:(len(subfile))]+'.lumicalc.sum' + f = open(lumifile, 'r') + lumistring = f.readline() + #print lumistring + intlumi = float(lumistring) + f.close() + scalefactor = 19800./intlumi + scalefactors.append(scalefactor) + else : + lumifile = 'inputs/'+jobid+'/'+myfile[:(len(myfile))]+'.lumicalc.sum' + f = open(lumifile, 'r') + lumistring = f.readline() + #print lumistring + intlumi = float(lumistring) + f.close() + scalefactor = 19800./intlumi + scalefactors.append(scalefactor) +canvas = ROOT.TCanvas("canvas","canvas",800,800) +canvas.Draw() + +for s in sign : + outfile = ROOT.TFile("outfile"+s+".root", "RECREATE") + #print lineno() + for pr in process: + #print lineno() + for c in ptcut: + for jn in jetN: + #print lineno() + filepath = 'plots/'+jobid+'/LFVHETauAnalyzer/et/'+s+'/'+pr+'/ept'+str(c)+'/'+str(jn) + + startingdir = os.getcwd() + dirs = filepath.split('/') + thechannel = 'e #tau_{h}' + for d in dirs: + currentdir = os.getcwd() + dirlist = os.listdir(currentdir) + + if d in dirlist: + os.chdir(d) + else: + os.makedirs(d) + os.chdir(d) + if d == "LFVHAnalyzeGENEMu" : + thechannel='#mu #tau_{e}' + thesmchannel = "#tau_{#mu}#tau_{e}" + if d == "LFVHAnalyzeGENMuTau" : + thechannel='#mu #tau_{h}' + thesmchannel = "#tau_{#mu}#tau_{h}" + + os.chdir(startingdir) + + + for nhisto, i in enumerate(histolist): + #outfile = ROOT.TFile(filepath+'/'+i+".root","RECREATE") + outfile.cd() + legend.Clear() + LFVStack = ROOT.THStack("stack"+i,"") + histos = [] #fare vector di histo e clonare quello che leggo + ETaufiles = [] + nfile=-1 + newhistos =[] + for n, file in enumerate(lfvfilelist): + nfile+=1 + if type(file) is not list and file.endswith('HiggsToETau') : continue + #print n, " " , file + nn = n-2 + if type(file) is list : + + file0=ROOT.TFile(sourcepath+file[0]+'.root') + h0 = file0.Get(s+'/'+pr+'/ept'+str(c)+'/'+str(jn)+'/'+i).Clone() + h0.Scale(scalefactors[nfile]) + newhisto=h0.Clone() + outfile.cd() + newhistos.append(file0.Get(s+'/'+pr+'/ept'+str(c)+'/'+str(jn)+'/'+i).Clone()) + newhistos[nn].Scale(scalefactors[nfile]) + newhistos[nn].SetName('h'+str(n)) + for isub, subfile in enumerate(file) : + #print sourcepath+subfile+'.root' + if isub ==0 : continue + nfile +=1 + newFile = ROOT.TFile(sourcepath+subfile+'.root') + outfile.cd() + newhistos[nn].Add(newFile.Get(s+'/'+pr+'/ept'+str(c)+'/'+str(jn)+'/'+i).Clone(),scalefactors[nfile]) + + #print lineno() , nfile + newFile.Close() + + histos.append(newhistos[nn]) + histos[nn].Rebin(rebins[nhisto]) + histos[nn].SetLineColor(n+1) + histos[nn].SetFillColor(n+1) + histos[nn].SetMarkerColor(n+1) + # LFVStack.Add(histos[nn]) + #legend.AddEntry(histos[nn], legendlist[n]) + file0.Close() + + #else: + + #ETaufiles.append(ROOT.TFile(sourcepath+file+'.root')) + #histos.append(ETaufiles[nn].Get(s+'/'+pr+'/ept'+str(c)+'/'+str(jn)+'/'+i).Clone()) + #histos[nn].SetName('h'+str(n)) + #histos[nn].Scale(scalefactors[nfile]) + #histos[nn].Rebin(rebins[nhisto]) + #histos[nn].SetLineWidth(1) + #histos[nn].SetLineColor(n+1) + #histos[nn].SetFillColor(n+1) + #histos[nn].SetMarkerColor(n+1) + + #LFVStack.Add(histos[nn]) + #legend.AddEntry(histos[nn], legendlist[n]) + + legend.Clear() + LFVStack.Add(histos[4]) + LFVStack.Add(histos[5]) + LFVStack.Add(histos[2]) + LFVStack.Add(histos[3]) + LFVStack.Add(histos[1]) + LFVStack.Add(histos[0]) + legend.AddEntry(histos[4],legendlist[6]) + legend.AddEntry(histos[5],legendlist[7]) + legend.AddEntry(histos[2],legendlist[4]) + legend.AddEntry(histos[3],legendlist[5]) + legend.AddEntry(histos[0],legendlist[2]) + legend.AddEntry(histos[1],legendlist[3]) + # print histos + canvas.cd() + canvas.Clear() + #LFVStack.Print() + #newStack=LFVStack.Clone() + #newStack.RecursiveRemove() + #newStacl.Add(LFVStack.GetHists() ) + + LFVStack.Draw('hist') + + LFVStack.GetXaxis().SetTitle(axistitle[nhisto]) + + ggLFVHfile = ROOT.TFile(sourcepath+lfvfilelist[0]+'.root') + vbfLFVHfile = ROOT.TFile(sourcepath+lfvfilelist[1]+'.root') + ggLFVHhisto= ggLFVHfile.Get(s+'/'+pr+'/ept'+str(c)+'/'+str(jn)+'/'+i).Clone() + vbfLFVHhisto= vbfLFVHfile.Get(s+'/'+pr+'/ept'+str(c)+'/'+str(jn)+'/'+i).Clone() + ggLFVHhisto.Rebin(rebins[nhisto]) + vbfLFVHhisto.Rebin(rebins[nhisto]) + + ggLFVHhisto.SetLineColor(1) + ggLFVHhisto.SetLineStyle(1) + ggLFVHhisto.SetLineWidth(2) + vbfLFVHhisto.SetLineColor(1) + vbfLFVHhisto.SetLineStyle(2) + vbfLFVHhisto.SetLineWidth(2) + outfile.cd() + ibin=0 + snhisto = ggLFVHhisto.Clone() + + snhisto.SetName("significance_vs_"+i) + snhisto.SetTitle("significance_vs_"+i) + + while ibin<=LFVStack.GetXaxis().GetNbins(): + ibin+=1 + bkg = 0 + for h in histos: + bkg+=h.GetBinContent(ibin) + sig = ggLFVHhisto.GetBinContent(ibin) + vbfLFVHhisto.GetBinContent(ibin) + + if sig+bkg> 0: + sn = sig/sqrt(sig+bkg) + snhisto.SetBinContent(ibin, sn) + err = sqrt(sig/(2*sqrt(sig+bkg))) + snhisto.SetBinError(ibin, err) + #print bkg, sig, sn, err + snhisto.GetXaxis().SetTitle(axistitle[nhisto]) + snhisto.GetYaxis().SetTitle("S/#sqrt{S+B}") + + ggLFVHhisto.Scale(10*scalefactors[0]) + vbfLFVHhisto.Scale(10*scalefactors[1]) + mymax = max (ggLFVHhisto.GetBinContent(ggLFVHhisto.GetMaximumBin()), vbfLFVHhisto.GetBinContent(vbfLFVHhisto.GetMaximumBin())) + if mymax > LFVStack.GetMaximum() : LFVStack.SetMaximum( 1.2*mymax ) + + ggLFVHhisto.Draw('SAMEHIST') + vbfLFVHhisto.Draw('SAMEHIST') + legend.AddEntry(ggLFVHhisto, 'LFV GG Higgs x 10') + legend.AddEntry(vbfLFVHhisto, 'LFV VBF Higgs x 10') + legend.Draw() + canvas.SetLogy(0) + if i.endswith('Pt') : canvas.SetLogy(1) + canvas.Update() + canvas.SaveAs(filepath+'/mc_'+i+'.png') + #outfile.cd() + + #canvas.Clear() + snhisto.Draw() + canvas.SaveAs(filepath+'/mc_significance_vs_'+i+'.png') + #canvas.Write() + + + + outfile.Close() + os.system("rm outfile"+s+".root") + diff --git a/lfvetau/plotMyRecoMuTau.py b/lfvetau/plotMyRecoMuTau.py new file mode 100644 index 00000000..372716c6 --- /dev/null +++ b/lfvetau/plotMyRecoMuTau.py @@ -0,0 +1,245 @@ +#from lfvmutau plotter +import os +from sys import argv, stdout, stderr +import ROOT +import sys +from FinalStateAnalysis.PlotTools.MegaBase import make_dirs + +ROOT.gROOT.SetStyle("Plain") +ROOT.gROOT.SetBatch(True) +ROOT.gStyle.SetOptStat(0) + +shape_norm = True +if shape_norm == False: + ynormlabel = "Normalized to Data " +else: + ynormlabel = "Normalized to 1 " + + +import inspect + +def lineno(): + """Returns the current line number in our program.""" + return inspect.currentframe().f_back.f_lineno + + +lfvfilelist = ['ggHiggsToMuTau', 'vbfHiggsToMuTau', +'Zjets_M50', +'WplusJets_madgraph', +#'Wplus4Jets_madgraph.root', +#'Wplus2Jets_madgraph_tapas.root', +#'Wplus2Jets_madgraph.root', +#'Wplus1Jets_madgraph_tapas.root', +#'Wplus3Jets_madgraph.root', +#'Wplus1Jets_madgraph.root', +['WZJetsTo3LNu_TuneZ2_8TeV-madgraph-tauola', 'WZJetsTo2L2Q_TuneZ2star_8TeV-madgraph-tauola', 'WWJetsTo2L2Nu_TuneZ2star_8TeV-madgraph-tauola', 'ZZJetsTo4L_TuneZ2star_8TeV-madgraph-tauola','ZZJetsTo2L2Q_TuneZ2star_8TeV-madgraph-tauola'], +['TTJetsFullLepMGDecays', 'TTJetsSemiLepMGDecays'], +['T_t-channel_TuneZ2star_8TeV-powheg-tauola','T_tW-channel-DR_TuneZ2star_8TeV-powheg-tauola','Tbar_t-channel_TuneZ2star_8TeV-powheg-tauola','Tbar_tW-channel-DR_TuneZ2star_8TeV-powheg-tauola'], ['GluGluToHToTauTau_M-125_8TeV-powheg-pythia6', 'VBF_HToTauTau_M-125_8TeV-powheg-pythia6'] +] + + + +legendlist = ['LFV GG Higgs', 'LFV VBF Higgs', 'DY + jets', 'W + jets', 'EWK Dibosons', 'ttbar', 'single Top', 'SM Higgs' +] +#print 'lfvfilelist ', len(lfvfilelist), ' legendlist ' , len(legendlist) +sourcepath = 'results/MCntuples_8April/LFVHMuTauAnalyzer/' +sign = ['os', 'ss'] +process = ['gg','vbf'] +ptcut = [0, 40] +jetN = [0,1,2,3] +legend = ROOT.TLegend(0.58,0.15,0.82,0.35) +legend.SetFillColor(0) + + +histolist = ['tPt', 'tPhi', 'tEta', +'mPt', 'mPhi', 'mEta', +'mt_DeltaPhi', 'mt_DeltaR', +'tPFMET_DeltaPhi', 'tPFMET_Mt', 'tMVAMET_DeltaPhi', 'tMVAMET_Mt', +'mPFMET_DeltaPhi','mPFMET_Mt', 'mMVAMET_DeltaPhi', 'mMVAMET_Mt', +'jetN_20', 'jetN_30', +'h_collmass_pfmet', 'h_collmass_mvamet', 'h_vismass' +] +rebins = [5,5,2,5,5,2,1, 1, 2, 5, 2, 5, 2, 5, 2, 5,1,1,1,1,1] +axistitle = ['#tau p_{T} (GeV)','#tau #phi','#tau #eta', +'#mu p_{T} (GeV)','#mu #phi','#mu #eta', +'#mu-#tau #Delta#phi','#mu-#tau #DeltaR', +'#tau-PFMET #Delta#phi','#tau-PFMET M_{T} (GeV) ','#tau-MVAMET #Delta#phi','#tau-MVAMET M_{T} (GeV)', +'#mu-PFMET #Delta#phi','#mu-PFMET M_{T} (GeV)','#mu-MVAMET #Delta#phi','#mu-MVAMET #M_{T} (GeV)', +'Number of jets (p_{T}>20)','Number of jets (p_{T}>30)', +'M_{#mu#tau}coll (GeV)','M_{#mu#tau}coll (GeV)','M_{#mu#tau} vis (GeV)' +] + +scalefactors=[] +for myfile in lfvfilelist: + if type(myfile) is list: + for subfile in myfile : + lumifile = 'inputs/MCntuples_8April/'+subfile[:(len(subfile))]+'.lumicalc.sum' + f = open(lumifile, 'r') + lumistring = f.readline() + #print lumistring + intlumi = float(lumistring) + f.close() + scalefactor = 19800./intlumi + scalefactors.append(scalefactor) + else : + lumifile = 'inputs/MCntuples_8April/'+myfile[:(len(myfile))]+'.lumicalc.sum' + f = open(lumifile, 'r') + lumistring = f.readline() + #print lumistring + intlumi = float(lumistring) + f.close() + scalefactor = 19800./intlumi + scalefactors.append(scalefactor) +canvas = ROOT.TCanvas("canvas","canvas",800,800) +canvas.Draw() + +for s in sign : + #print lineno() + for pr in process: + #print lineno() + for c in ptcut: + for jn in jetN: + #print lineno() + filepath = 'plots/MCntuples_8April/LFVHETauAnalyzer/mt/'+s+'/'+pr+'/mpt'+str(c)+'/'+str(jn) + + startingdir = os.getcwd() + dirs = filepath.split('/') + thechannel = '#mu #tau_{h}' + for d in dirs: + currentdir = os.getcwd() + dirlist = os.listdir(currentdir) + + if d in dirlist: + os.chdir(d) + else: + os.makedirs(d) + os.chdir(d) + if d == "LFVHAnalyzeGENEMu" : + thechannel='#mu #tau_{e}' + thesmchannel = "#tau_{#mu}#tau_{e}" + if d == "LFVHAnalyzeGENMuTau" : + thechannel='#mu #tau_{h}' + thesmchannel = "#tau_{#mu}#tau_{h}" + + os.chdir(startingdir) + + + for nhisto, i in enumerate(histolist): + outfile = ROOT.TFile(filepath+'/'+i+".root","RECREATE") + legend.Clear() + LFVStack = ROOT.THStack("stack"+i,"") + histos = [] #fare vector di histo e clonare quello che leggo + ETaufiles = [] + nfile=-1 + newhistos =[] + for n, file in enumerate(lfvfilelist): + nfile+=1 + if type(file) is not list and file.endswith('HiggsToMuTau') : continue + #print n, " " , file + nn = n-2 + if type(file) is list : + + file0=ROOT.TFile(sourcepath+file[0]+'.root') + h0 = file0.Get(s+'/'+pr+'/mpt'+str(c)+'/'+str(jn)+'/'+i).Clone() + h0.Scale(scalefactors[nfile]) + newhisto=h0.Clone() + outfile.cd() + newhistos.append(file0.Get(s+'/'+pr+'/mpt'+str(c)+'/'+str(jn)+'/'+i).Clone()) + newhistos[n-4].Scale(scalefactors[nfile]) + + newhistos[n-4].SetName('h'+str(n)) + for isub, subfile in enumerate(file) : + #print sourcepath+subfile+'.root' + if isub ==0 : continue + nfile +=1 + newFile = ROOT.TFile(sourcepath+subfile+'.root') + outfile.cd() + newhistos[n-4].Add(newFile.Get(s+'/'+pr+'/mpt'+str(c)+'/'+str(jn)+'/'+i).Clone(),scalefactors[nfile]) + #newhistos[n-4].Scale() + #print lineno() , nfile + newFile.Close() + + histos.append(newhistos[n-4]) + histos[nn].Rebin(rebins[nhisto]) + histos[nn].SetLineColor(n+1) + histos[nn].SetFillColor(n+1) + histos[nn].SetMarkerColor(n+1) + # LFVStack.Add(histos[nn]) + #legend.AddEntry(histos[nn], legendlist[n]) + file0.Close() + + else: + + ETaufiles.append(ROOT.TFile(sourcepath+file+'.root')) + + histos.append(ETaufiles[nn].Get(s+'/'+pr+'/mpt'+str(c)+'/'+str(jn)+'/'+i).Clone()) + histos[nn].Scale(scalefactors[nfile]) + histos[nn].SetName('h'+str(n)) + + histos[nn].Rebin(rebins[nhisto]) + histos[nn].SetLineWidth(1) + histos[nn].SetLineColor(n+1) + histos[nn].SetFillColor(n+1) + histos[nn].SetMarkerColor(n+1) + + #LFVStack.Add(histos[nn]) + #legend.AddEntry(histos[nn], legendlist[n]) + + legend.Clear() + LFVStack.Add(histos[4]) + LFVStack.Add(histos[5]) + LFVStack.Add(histos[2]) + LFVStack.Add(histos[3]) + LFVStack.Add(histos[1]) + LFVStack.Add(histos[0]) + legend.AddEntry(histos[4],legendlist[6]) + legend.AddEntry(histos[5],legendlist[7]) + legend.AddEntry(histos[2],legendlist[4]) + legend.AddEntry(histos[3],legendlist[5]) + legend.AddEntry(histos[0],legendlist[2]) + legend.AddEntry(histos[1],legendlist[3]) + # print histos + canvas.cd() + canvas.Clear() + #LFVStack.Print() + #newStack=LFVStack.Clone() + #newStack.RecursiveRemove() + #newStacl.Add(LFVStack.GetHists() ) + + LFVStack.Draw('hist') + + LFVStack.GetXaxis().SetTitle(axistitle[nhisto]) + ggLFVHfile = ROOT.TFile(sourcepath+lfvfilelist[0]+'.root') + vbfLFVHfile = ROOT.TFile(sourcepath+lfvfilelist[1]+'.root') + ggLFVHhisto= ggLFVHfile.Get(s+'/'+pr+'/mpt'+str(c)+'/'+str(jn)+'/'+i).Clone() + vbfLFVHhisto= vbfLFVHfile.Get(s+'/'+pr+'/mpt'+str(c)+'/'+str(jn)+'/'+i).Clone() + ggLFVHhisto.Rebin(rebins[nhisto]) + vbfLFVHhisto.Rebin(rebins[nhisto]) + + ggLFVHhisto.SetLineColor(1) + ggLFVHhisto.SetLineStyle(1) + ggLFVHhisto.SetLineWidth(2) + vbfLFVHhisto.SetLineColor(1) + vbfLFVHhisto.SetLineStyle(2) + vbfLFVHhisto.SetLineWidth(2) + ggLFVHhisto.Scale(10*scalefactors[0]) + vbfLFVHhisto.Scale(10*scalefactors[1]) + mymax = max(ggLFVHhisto.GetBinContent(ggLFVHhisto.GetMaximumBin()), vbfLFVHhisto.GetBinContent(vbfLFVHhisto.GetMaximumBin())) + if mymax > LFVStack.GetMaximum() : + LFVStack.SetMaximum(1.2*mymax ) + print mymax, LFVStack.GetMaximum() + #LFVStack.Draw('hist') + ggLFVHhisto.Draw('SAMEHIST') + vbfLFVHhisto.Draw('SAMEHIST') + legend.AddEntry(ggLFVHhisto, 'LFV GG Higgs x 10') + legend.AddEntry(vbfLFVHhisto, 'LFV VBF Higgs x 10') + legend.Draw() + canvas.SetLogy(0) + if i.endswith('Pt') : canvas.SetLogy(1) + canvas.Update() + canvas.SaveAs(filepath+'/mc_'+i+'.png') + outfile.cd() + canvas.Write() + outfile.Close() + + os.system("rm "+filepath+'/'+i+".root") diff --git a/lfvetau/plotRecoQuantities.py b/lfvetau/plotRecoQuantities.py new file mode 100644 index 00000000..23b3f896 --- /dev/null +++ b/lfvetau/plotRecoQuantities.py @@ -0,0 +1,123 @@ +#from mauro plotters +import os +from sys import argv, stdout, stderr +import ROOT +import sys +from FinalStateAnalysis.PlotTools.MegaBase import make_dirs +import glob +import logging +import sys + +#jobid = os.environ['jobid'] +jobid = 'MCntuples_3March' +channel = 'et' + +print "\nPlotting %s for %s\n" % (channel, jobid) + +mcsamples = [ + 'ggHiggsToETau', + 'vbfHiggsToETau', + 'GluGluToHToTauTau_M-125_8TeV-powheg-pythia6', + 'VBF_HToTauTau_M-125_8TeV-powheg-pythia6', + # 'TTJets*', + # 'T_t*', + # 'Tbar_t', + # 'Wplus*', + # 'WWJets*', + # 'WZJets*', + # 'ZZJets*', + # 'Z*jets_M50' +] + +files = [] +lumifiles = [] + +for x in mcsamples: + files.extend(glob.glob('results/%s/LFVHETauAnalyzer/%s.root' % (jobid, x))) + lumifiles.extend(glob.glob('inputs/%s/%s.lumicalc.sum' % (jobid, x))) + outputdir = 'plots/%s/LFVHETauAnalyzer/%s' % (jobid, channel) + base_out_dir = outputdir + if not os.path.exists(outputdir): + os.makedirs(outputdir) + +# blinder = None +# blind = 'blind' not in os.environ or os.environ['blind'] == 'YES' +# print '\n\nRunning Blind: %s\n\n' % blind + + +#if blind: + # Don't look at the SS all pass region +# blinder = lambda x: BlindView(x, "ss/tau_os/p1p2p3/.*") + + + +import rootpy.plotting.views as views + +ROOT.gROOT.SetStyle("Plain") +ROOT.gROOT.SetBatch(True) +ROOT.gStyle.SetOptStat(0) + +canvas = ROOT.TCanvas("canvas","canvas",800,800) +LFVStack = ROOT.THStack("stack","") + +file0 = ROOT.TFile('results/%s/LFVHETauAnalyzer/ggHiggsToETau.root' % (jobid) ) + + +dir = file0.Get('os/gg/ept0') +hlist = dir.GetListOfKeys() +iter = ROOT.TIter(hlist) +for i in iter: + print i.GetName() + histo0 = file0.Get('%s/%s' % ('os/gg/ept0', i.GetName())) + if histo0.Integral() != 0 : + histo0.Scale(1./histo0.Integral()) + histo0.Draw("E") + histo0.SetLineWidth(2) + histo0.SetLineColor(1) + variable='' + if histo0.GetName()[4:7] == "Phi" : variable = "#phi" + if histo0.GetName()[4:7] == "Eta" : variable = "#eta" + if histo0.GetName()[4:10] == "Energy" : + variable = "energy (GeV)" + canvas.SetLogy(1) + if histo0.GetName()[4:6] == "Pt" : + variable = "p_{T} (GeV)" + canvas.SetLogy(1) + if histo0.GetName()[9:17] == "DeltaPhi" : + variable = "#Delta#phi" + p = 'e#tau' + canvas.SetLogy(1) +# axislabel = p+" "+variable + axislabel = variable + if variable != '' : histo0.GetXaxis().SetTitle(axislabel) + maxy = histo0.GetBinContent(histo0.GetMaximumBin()) + legend = ROOT.TLegend(0.7,0.85,0.88,0.75) + legend.SetFillColor(0) + legend.AddEntry(histo0, "ggHigsToETau") + + for n, sample in enumerate(mcsamples) : + if n == 0 : continue + file = ROOT.TFile("results/%s/LFVHETauAnalyzer/%s.root" %(jobid, sample)) + histo=file.Get('%s/%s' % ('os/gg/ept0', i.GetName())) + + + if histo.Integral() != 0 : + histo.Scale(1./histo.Integral()) + + p = histo.GetName()[0:1] + if p == 't' : p = '#tau' + histo.Draw("ESAME") + + histo.SetLineColor(n) + histo.SetLineWidth(2) + + canvas.SetLogy(0) + if maxy < histo.GetBinContent(histo.GetMaximumBin()) : maxy = histo.GetBinContent(histo.GetMaximumBin()) + legend.AddEntry(histo, "mcsamples") + + if canvas.GetLogy()==0 : + histo0.GetYaxis().SetRangeUser(0, maxy*1.3) + + canvas.Update() + canvas.SaveAs(outputdir+'/os_ept0_'+i.GetName()+'.png') + diff --git a/lfvetau/plotRecoQuantitiesMVA.py b/lfvetau/plotRecoQuantitiesMVA.py index f7078209..1caae976 100644 --- a/lfvetau/plotRecoQuantitiesMVA.py +++ b/lfvetau/plotRecoQuantitiesMVA.py @@ -54,7 +54,8 @@ 'WZJets*', 'ZZJets*', 'Fake*', - 'data*' + 'data_Zetau*', + 'data_Single*' ] @@ -62,7 +63,7 @@ lumifiles = [] for x in mc_samples: - files.extend(glob.glob('results/%s/LFVHETauAnalyzerMVA_noOverlap/%s.root' % (jobid, x))) + files.extend(glob.glob('results/%s/LFVHETauAnalyzerMVA/%s.root' % (jobid, x))) lumifiles.extend(glob.glob('inputs/%s/%s.lumicalc.sum' % (jobid, x))) sign = ['os', 'ss'] @@ -103,6 +104,8 @@ def remove_name_entry(dictionary): DYTT = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedTT'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*TT'])), 'DY (#rightarrow #tau#tau) + jets') +DYTTfake =views.SubdirectoryView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('data_Zetau'), mc_samples )]), 'tLoose') + TT = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('TT') , mc_samples)]), **remove_name_entry(data_styles['TTJets*'])), 't#bar{t}') singleT = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('T_') or x.startswith('Tbar_'), mc_samples)]), **remove_name_entry(data_styles['T*_t*'])), 'Single Top') SMH = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : 'HToTauTau' in x , mc_samples)]), **remove_name_entry(data_styles['GluGluToHToTauTau*'])), 'SM Higgs') @@ -111,16 +114,20 @@ def remove_name_entry(dictionary): plotter.views['EWKDiboson']={'view' : EWKDiboson } plotter.views['Wplus']={'view' : Wplus } #plotter.views['DYLL']={'view' : DYLL } -plotter.views['DYTT']={'view' : DYTT } +#plotter.views['DYTT']={'view' : DYTT } plotter.views['singleT']={'view' : singleT } plotter.views['SMH']={'view' : SMH } plotter.views['TT']={'view' : TT } #plotter.views['DY']={'view' : DY } new_mc_samples =[] - +plotter.views['DYTT']={'view' : DYTTfake } #DYLL = views.TitleView(views.StyleView(views.SubtractionView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedTT'), mc_samples )]), views.SubdirectoryView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedLL'), mc_samples )]), 'tLoose')), **remove_name_entry(data_styles['Z*jets*LL'])), 'DY (#rightarrow ll) + jets') finalDYLL = SubtractionView(DYLL,DYLLfake) plotter.views['finalDYLL']={'view' : finalDYLL } +finalDYTT = SubtractionView(DYTT,DYTTfake) +plotter.views['finalDYTT']={'view' : finalDYTT } + + new_mc_samples.extend(['EWKDiboson', 'SMH', 'singleT',#'Wplus', diff --git a/lfvetau/setupBatch.sh b/lfvetau/setupBatch.sh new file mode 100644 index 00000000..73e99b35 --- /dev/null +++ b/lfvetau/setupBatch.sh @@ -0,0 +1,6 @@ +export MEGAPATH=/hdfs/store/user/taroni +export farmout=1 +export dryrun=1 +export CutFlow=1 +source jobid.sh +export jobid=$jobid8 From 969d2563b56c42d7cdd4265fe0c4bc1d925f87a6 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Thu, 16 Oct 2014 08:17:00 -0500 Subject: [PATCH 105/192] update --- lfvetau/BasePlotter.py | 3 +- lfvetau/LFVHETauAnalyzerMVA.py | 517 ++++++++++++++++++------------ lfvetau/Rakefile | 9 +- lfvetau/TauFakeRateAnalyzerMVA.py | 27 +- lfvetau/jobid.sh | 4 +- lfvetau/make_proxies.sh | 16 +- lfvetau/run.sh | 4 +- lfvetau/setup.sh | 20 +- 8 files changed, 365 insertions(+), 235 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index a55e8ca0..5beae993 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -74,7 +74,8 @@ def __init__ (self, channel, files, lumifiles, outputdir,forceLumi=-1): 'WZJets*', 'ZZJets*', 'Fake*', - 'data*', + 'data_Zetau*', + 'data_Single*' ] diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 35a1af8f..c08e9c22 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -112,19 +112,24 @@ def begin(self): processtype=['gg'] threshold=['ept30'] sign=['os', 'ss'] - jetN = [0, 1, 2, 3] + jetN = ['0','0_jes_plus','0_jes_minus', '1','1_jes_plus','1_jes_minus', '2','2_jes_plus','2_jes_minus', '3','3_jes_plus','3_jes_minus'] folder=[] - pudir = ['','p1s/', 'm1s/','trp1s/', 'trm1s/', 'eidp1s/','eidm1s/', 'eisop1s/','eisom1s/', 'tLoose/','tLooseUp/','tLooseDown/', 'tLooseUnweight/' ] + pudir = ['','p1s/', 'm1s/','trp1s/', 'trm1s/', 'eidp1s/','eidm1s/', 'eisop1s/','eisom1s/', 'mVetoUp/', 'mVetoDown/', 'eVetoUp/', 'eVetoDown/', 'tVetoUp/', 'tVetoDown/', 'tLoose/','tLooseUp/','tLooseDown/', 'tLooseUnweight/'] for d in pudir : for i in sign: for j in processtype: for k in threshold: - folder.append(d+i+'/'+j+'/'+k) + #folder.append(d+i+'/'+j+'/'+k) for jn in jetN: - folder.append(d+i+'/'+j+'/'+k +'/'+str(jn)) - folder.append(d+i+'/'+j+'/'+k +'/'+str(jn)+'/selected') + folder.append(d+i+'/'+j+'/'+k +'/'+jn) + folder.append(d+i+'/'+j+'/'+k +'/'+jn+'/selected') + + self.book('os/gg/ept30/', "h_collmass_pfmet" , "h_collmass_pfmet", 32, 0, 320) + self.book('os/gg/ept30/', "h_vismass", "h_vismass", 32, 0, 320) + + for f in folder: self.book(f,"tPt", "tau p_{T}", 200, 0, 200) @@ -141,13 +146,18 @@ def begin(self): self.book(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320) self.book(f, "h_collmass_mvamet", "h_collmass_mvamet", 32, 0, 320) self.book(f, "h_collmass_pfmet_Ty1", "h_collmass_pfmet_Ty1", 32, 0, 320) - self.book(f, "h_collmass_pfmet_jes", "h_collmass_pfmet_jes", 50, 0, 100) - self.book(f, "h_collmass_pfmet_mes", "h_collmass_pfmet_mes", 50, 0, 100 ) - self.book(f, "h_collmass_pfmet_tes", "h_collmass_pfmet_tes", 50, 0, 100) - self.book(f, "h_collmass_pfmet_ees", "h_collmass_pfmet_ees", 50, 0, 100) - self.book(f, "h_collmass_pfmet_ues", "h_collmass_pfmet_ues", 50, 0, 100) + self.book(f, "h_collmass_pfmet_jes_plus", "h_collmass_pfmet_jes_plus", 50, 0, 100) + self.book(f, "h_collmass_pfmet_mes_plus", "h_collmass_pfmet_mes_plus", 50, 0, 100 ) + self.book(f, "h_collmass_pfmet_tes_plus", "h_collmass_pfmet_tes_plus", 50, 0, 100) + self.book(f, "h_collmass_pfmet_ees_plus", "h_collmass_pfmet_ees_plus", 50, 0, 100) + self.book(f, "h_collmass_pfmet_ues_plus", "h_collmass_pfmet_ues_plus", 50, 0, 100) + self.book(f, "h_collmass_pfmet_jes_minus", "h_collmass_pfmet_jes_minus", 50, 0, 100) + self.book(f, "h_collmass_pfmet_mes_minus", "h_collmass_pfmet_mes_minus", 50, 0, 100 ) + self.book(f, "h_collmass_pfmet_tes_minus", "h_collmass_pfmet_tes_minus", 50, 0, 100) + self.book(f, "h_collmass_pfmet_ees_minus", "h_collmass_pfmet_ees_minus", 50, 0, 100) + self.book(f, "h_collmass_pfmet_ues_minus", "h_collmass_pfmet_ues_minus", 50, 0, 100) self.book(f, "h_collmassSpread_pfmet", "h_collmassSpread_pfmet", 40, -100, 100) self.book(f, "h_collmassSpread_mvamet", "h_collmassSpread_mvamet", 40, -100, 100) @@ -173,11 +183,17 @@ def begin(self): self.book(f, "tPFMET_Mt", "tau-PFMET M_{T}" , 200, 0, 200) self.book(f, "tPFMET_DeltaPhi_Ty1", "tau-type1PFMET DeltaPhi" , 50, 0, 3.2) self.book(f, "tPFMET_Mt_Ty1", "tau-type1PFMET M_{T}" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_jes', "tau-MVAMET M_{T} JES" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_mes', "tau-MVAMET M_{T} JES" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_ees', "tau-MVAMET M_{T} JES" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_tes', "tau-MVAMET M_{T} JES" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_ues', "tau-MVAMET M_{T} JES" , 200, 0, 200) + self.book(f, 'tPFMET_Mt_jes_plus', "tau-MVAMET M_{T} JES_plus" , 200, 0, 200) + self.book(f, 'tPFMET_Mt_mes_plus', "tau-MVAMET M_{T} JES_plus" , 200, 0, 200) + self.book(f, 'tPFMET_Mt_ees_plus', "tau-MVAMET M_{T} JES_plus" , 200, 0, 200) + self.book(f, 'tPFMET_Mt_tes_plus', "tau-MVAMET M_{T} JES_plus" , 200, 0, 200) + self.book(f, 'tPFMET_Mt_ues_plus', "tau-MVAMET M_{T} JES_plus" , 200, 0, 200) + + self.book(f, 'tPFMET_Mt_jes_minus', "tau-MVAMET M_{T} JES_minus" , 200, 0, 200) + self.book(f, 'tPFMET_Mt_mes_minus', "tau-MVAMET M_{T} JES_minus" , 200, 0, 200) + self.book(f, 'tPFMET_Mt_ees_minus', "tau-MVAMET M_{T} JES_minus" , 200, 0, 200) + self.book(f, 'tPFMET_Mt_tes_minus', "tau-MVAMET M_{T} JES_minus" , 200, 0, 200) + self.book(f, 'tPFMET_Mt_ues_minus', "tau-MVAMET M_{T} JES_minus" , 200, 0, 200) self.book(f, "tMVAMET_DeltaPhi", "tau-MVAMET DeltaPhi" , 50, 0, 3.2) self.book(f, "tMVAMET_Mt", "tau-MVAMET M_{T}" , 200, 0, 200) @@ -186,11 +202,11 @@ def begin(self): self.book(f, "ePFMET_Mt_Ty1", "e-type1PFMET M_{T}" , 200, 0, 200) self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 50, 0, 3.2) self.book(f, "ePFMET_Mt", "e-PFMET M_{T}" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_jes', "e-MVAMET M_{T} JES" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_mes', "e-MVAMET M_{T} JES" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_ees', "e-MVAMET M_{T} JES" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_tes', "e-MVAMET M_{T} JES" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_ues', "e-MVAMET M_{T} JES" , 200, 0, 200) + #self.book(f, 'ePFMET_Mt_jes', "e-MVAMET M_{T} JES" , 200, 0, 200) + #self.book(f, 'ePFMET_Mt_mes', "e-MVAMET M_{T} JES" , 200, 0, 200) + #self.book(f, 'ePFMET_Mt_ees', "e-MVAMET M_{T} JES" , 200, 0, 200) + #self.book(f, 'ePFMET_Mt_tes', "e-MVAMET M_{T} JES" , 200, 0, 200) + #self.book(f, 'ePFMET_Mt_ues', "e-MVAMET M_{T} JES" , 200, 0, 200) #self.book(f, "ePFMET_Mt_Ty1_ues_minus", "e-type1PFMET M_{T} ues_minus" , 200, 0, 200) #self.book(f, "ePFMET_Mt_Ty1_ues_plus", "e-type1PFMET M_{T} ues_plus" , 200, 0, 200) self.book(f, 'ePFMET_Mt_jes_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) @@ -235,153 +251,218 @@ def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): pudir =[''] if row.run < 2: pudir.extend( ['p1s/', 'm1s/', 'trp1s/', 'trm1s/', 'eidp1s/','eidm1s/', 'eisop1s/','eisom1s/']) looseList = ['tLoose/', 'tLooseUp/', 'tLooseDown/', 'tLooseUnweight/'] + + if f=='os/gg/ept30' : + if bool(isTauTight)==True: + histos[f+'/h_collmass_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[0]) + histos[f+'/h_vismass'].Fill(row.e_t_Mass, weight[0]) + else: + if bool(isTauTight) == False: + if f.startswith('os') or f.startswith('ss') : + frweight_bv = frw[0]/(1.-frw[0]) + err = 0.3/pow(1-frw[0], 2) #tau pog told to mu-tau group to use 30% uncertainty on tau fake rate. + frweight_p1s = frweight_bv*(1+err) + frweight_m1s = frweight_bv*(1-err) + fr_weights = [frweight_bv, frweight_p1s, frweight_m1s] + + for n, l in enumerate(looseList) : + frweight = weight[0]*fr_weights[n] if n < len(looseList)-1 else weight[0] + folder = l+f + histos[folder+'/tPt'].Fill(row.tPt, frweight) + histos[folder+'/tEta'].Fill(row.tEta, frweight) + histos[folder+'/tPhi'].Fill(row.tPhi, frweight) + histos[folder+'/ePt'].Fill(row.ePt, frweight) + histos[folder+'/eEta'].Fill(row.eEta, frweight) + histos[folder+'/ePhi'].Fill(row.ePhi, frweight) + histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), frweight) + histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, frweight) + histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : + histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : + histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : + histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : + histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + + histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), frweight) + histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + + #histos[folder+'/h_collmass_pfmet_jes'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_Phi), frweight) + #histos[folder+'/h_collmass_pfmet_mes'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), frweight) + #histos[folder+'/h_collmass_pfmet_tes'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), frweight) + #histos[folder+'/h_collmass_pfmet_ees'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), frweight) + #histos[folder+'/h_collmass_pfmet_ues'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), frweight) + + + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, frweight) + histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, frweight) + histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, frweight) + + histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.pfMetPhi), frweight) + histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), frweight) + histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), frweight) + histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, frweight) + histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, frweight) + histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, frweight) + ##histos[folder+'/ePFMET_Mt_Ty1_ues_minus'].Fill(row.eMtToPfMet_Ty1_ues_minus, frweight) + ##histos[folder+'/ePFMET_Mt_Ty1_ues_plus'].Fill(row.eMtToPfMet_Ty1_ues_plus, frweight) + #histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, frweight) + #histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, frweight) + #histos[folder+'/ePFMET_Mt_jes'].Fill(row.eMtToPfMet_jes, frweight) + #histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus, frweight) + #histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, frweight) + #histos[folder+'/ePFMET_Mt_mes'].Fill(row.eMtToPfMet_mes, frweight) + #histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus, frweight) + #histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, frweight) + #histos[folder+'/ePFMET_Mt_ees'].Fill(row.eMtToPfMet_ees, frweight) + #histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus, frweight) + #histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, frweight) + #histos[folder+'/ePFMET_Mt_tes'].Fill(row.eMtToPfMet_tes, frweight) + #histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus, frweight) + #histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, frweight) + #histos[folder+'/ePFMET_Mt_ues'].Fill(row.eMtToPfMet_ues, frweight) - if bool(isTauTight) == False: - #print 'isTauTigh? ', isTauTight, ' in ', f - frweight_bv = frw[0]/(1.-frw[0]) - #print fakerate, frw[0], frweight - #err = abs(frw[0] - frw[1])* abs(frw[0]/((1-frw[0])*(1-frw[0])) + 1/(1-frw[0])) - err = 0.3/pow(1-frw[0], 2) #tau pog told to mu-tau group to use 30% uncertainty on tau fake rate. - frweight_p1s = frweight_bv*(1+err) - frweight_m1s = frweight_bv*(1-err) - - fr_weights = [frweight_bv, frweight_p1s, frweight_m1s] - #print frweight_bv, frw[0], row.tPt, row.tEta - for n, l in enumerate(looseList) : - frweight = weight[0]*fr_weights[n] if n < len(looseList)-1 else weight[0] - folder = l+f - #print folder , frweight, fr_weights[n], frw[0] - histos[folder+'/tPt'].Fill(row.tPt, frweight) - histos[folder+'/tEta'].Fill(row.tEta, frweight) - histos[folder+'/tPhi'].Fill(row.tPhi, frweight) - histos[folder+'/ePt'].Fill(row.ePt, frweight) - histos[folder+'/eEta'].Fill(row.eEta, frweight) - histos[folder+'/ePhi'].Fill(row.ePhi, frweight) - histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), frweight) - histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, frweight) - histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), frweight) - histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.pfMetPhi), frweight) - histos[folder+'/h_collmass_pfmet_jes'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_Phi), frweight) - histos[folder+'/h_collmass_pfmet_mes'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), frweight) - histos[folder+'/h_collmass_pfmet_tes'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), frweight) - histos[folder+'/h_collmass_pfmet_ees'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), frweight) - histos[folder+'/h_collmass_pfmet_ues'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), frweight) - - - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, frweight) - histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, frweight) - histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, frweight) - - histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.pfMetPhi), frweight) - histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), frweight) - histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), frweight) - histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, frweight) - histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, frweight) - histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, frweight) - #histos[folder+'/ePFMET_Mt_Ty1_ues_minus'].Fill(row.eMtToPfMet_Ty1_ues_minus, frweight) - #histos[folder+'/ePFMET_Mt_Ty1_ues_plus'].Fill(row.eMtToPfMet_Ty1_ues_plus, frweight) - histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, frweight) - histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, frweight) - histos[folder+'/ePFMET_Mt_jes'].Fill(row.eMtToPfMet_jes, frweight) - histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus, frweight) - histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, frweight) - histos[folder+'/ePFMET_Mt_mes'].Fill(row.eMtToPfMet_mes, frweight) - histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus, frweight) - histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, frweight) - histos[folder+'/ePFMET_Mt_ees'].Fill(row.eMtToPfMet_ees, frweight) - histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus, frweight) - histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, frweight) - histos[folder+'/ePFMET_Mt_tes'].Fill(row.eMtToPfMet_tes, frweight) - histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus, frweight) - histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, frweight) - histos[folder+'/ePFMET_Mt_ues'].Fill(row.eMtToPfMet_ues, frweight) - - - - histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), frweight) - histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), frweight) - histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), frweight) - histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, frweight) - histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, frweight) - histos[folder+'/tPFMET_Mt_jes'].Fill(row.tMtToPfMet_jes, frweight) - histos[folder+'/tPFMET_Mt_mes'].Fill(row.tMtToPfMet_mes, frweight) - histos[folder+'/tPFMET_Mt_ees'].Fill(row.tMtToPfMet_ees, frweight) - histos[folder+'/tPFMET_Mt_tes'].Fill(row.tMtToPfMet_tes, frweight) - histos[folder+'/tPFMET_Mt_ues'].Fill(row.tMtToPfMet_ues, frweight) - - histos[folder+'/jetN_20'].Fill(row.jetVeto20, frweight) - histos[folder+'/jetN_30'].Fill(row.jetVeto30, frweight) + + histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), frweight) + histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), frweight) + histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), frweight) + histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, frweight) + histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, frweight) + #histos[folder+'/tPFMET_Mt_jes'].Fill(row.tMtToPfMet_jes, frweight) + #histos[folder+'/tPFMET_Mt_mes'].Fill(row.tMtToPfMet_mes, frweight) + #histos[folder+'/tPFMET_Mt_ees'].Fill(row.tMtToPfMet_ees, frweight) + #histos[folder+'/tPFMET_Mt_tes'].Fill(row.tMtToPfMet_tes, frweight) + #histos[folder+'/tPFMET_Mt_ues'].Fill(row.tMtToPfMet_ues, frweight) + + histos[folder+'/jetN_20'].Fill(row.jetVeto20, frweight) + histos[folder+'/jetN_30'].Fill(row.jetVeto30, frweight) + + else: # if it is TauTight + if not f.startswith('os') and not f.startswith('ss') : # if the dir name start with mVeto, eVeto or tVeto I don't want the different weight of MC corrections + pudir = [''] + + for n,d in enumerate(pudir) : + if 'minus' in f or 'plus' in f : + if n >0 : break + + folder = d+f + print folder + + histos[folder+'/tPt'].Fill(row.tPt, weight[n]) + histos[folder+'/tEta'].Fill(row.tEta, weight[n]) + histos[folder+'/tPhi'].Fill(row.tPhi, weight[n]) + histos[folder+'/ePt'].Fill(row.ePt, weight[n]) + histos[folder+'/eEta'].Fill(row.eEta, weight[n]) + histos[folder+'/ePhi'].Fill(row.ePhi, weight[n]) + histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), weight[n]) + histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, weight[n]) + + histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : + histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : + histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : + histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : + histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + + + histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), weight[n]) + histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + + + + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, weight[n]) + + histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, weight[n]) + histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, weight[n]) + + histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) + histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) + histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), weight[n]) + + histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, weight[n]) + histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, weight[n]) + histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, weight[n]) + + histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), weight[n]) + histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), weight[n]) + histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), weight[n]) + + histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, weight[n]) + histos[folder+'/tPFMET_Mt_Ty1'].Fill(row.tMtToPfMet_Ty1, weight[n]) + histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, weight[n]) + + histos[folder+'/jetN_20'].Fill(row.jetVeto20, weight[n]) + histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight[n]) + + + if n == 0: # if I'm in the dir starting with os or ss I want also the energy scale uncertainties + histos[folder+'/h_collmass_pfmet_jes_plus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_plus_Phi), weight[n]) + histos[folder+'/h_collmass_pfmet_jes_minus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_minus_Phi), weight[n]) + ### add the minus in the ntuple. + #histos[folder+'/h_collmass_pfmet_mes_plus'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), weight[n]) + #histos[folder+'/h_collmass_pfmet_tes_plus'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), weight[n]) + #histos[folder+'/h_collmass_pfmet_ees_plus'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), weight[n]) + #histos[folder+'/h_collmass_pfmet_ues_plus'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), weight[n]) + + + histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, weight[n]) + histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, weight[n]) + + histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus,weight[n]) + histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, weight[n]) + + histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus,weight[n]) + histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, weight[n]) + + histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus,weight[n]) + histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, weight[n]) + + histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus,weight[n]) + histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, weight[n]) + + histos[folder+'/tPFMET_Mt_jes_plus'].Fill(row.tMtToPfMet_jes_plus,weight[n]) + histos[folder+'/tPFMET_Mt_mes_plus'].Fill(row.tMtToPfMet_mes_plus,weight[n]) + histos[folder+'/tPFMET_Mt_ees_plus'].Fill(row.tMtToPfMet_ees_plus,weight[n]) + histos[folder+'/tPFMET_Mt_tes_plus'].Fill(row.tMtToPfMet_tes_plus,weight[n]) + histos[folder+'/tPFMET_Mt_ues_plus'].Fill(row.tMtToPfMet_ues_plus,weight[n]) + histos[folder+'/tPFMET_Mt_jes_minus'].Fill(row.tMtToPfMet_jes_minus,weight[n]) + histos[folder+'/tPFMET_Mt_mes_minus'].Fill(row.tMtToPfMet_mes_minus,weight[n]) + histos[folder+'/tPFMET_Mt_ees_minus'].Fill(row.tMtToPfMet_ees_minus,weight[n]) + histos[folder+'/tPFMET_Mt_tes_minus'].Fill(row.tMtToPfMet_tes_minus,weight[n]) + histos[folder+'/tPFMET_Mt_ues_minus'].Fill(row.tMtToPfMet_ues_minus,weight[n]) - else: - for n,d in enumerate(pudir) : - - folder = d+f - histos[folder+'/tPt'].Fill(row.tPt, weight[n]) - histos[folder+'/tEta'].Fill(row.tEta, weight[n]) - histos[folder+'/tPhi'].Fill(row.tPhi, weight[n]) - histos[folder+'/ePt'].Fill(row.ePt, weight[n]) - histos[folder+'/eEta'].Fill(row.eEta, weight[n]) - histos[folder+'/ePhi'].Fill(row.ePhi, weight[n]) - histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), weight[n]) - histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, weight[n]) - histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, weight[n]) - histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, weight[n]) - histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, weight[n]) - histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) - histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), weight[n]) - histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, weight[n]) - histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, weight[n]) - histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), weight[n]) - histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), weight[n]) - histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, weight[n]) - histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, weight[n]) - histos[folder+'/jetN_20'].Fill(row.jetVeto20, weight[n]) - histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight[n]) + + - def process(self): @@ -397,16 +478,23 @@ def process(self): frw = [] myevent =() for row in self.tree: + #for n, row in enumerate(self.tree): + sign = 'ss' if row.e_t_SS else 'os' processtype = '' ## use a line as for sign when the vbf when selections are defined ptthreshold = [30] processtype ='gg'##changed from 20 jn = row.jetVeto30 if jn > 3 : jn = 3 + jn_jes_plus = row.jetVeto30jes_plus + jn_jes_minus = row.jetVeto30jes_minus + + if jn_jes_plus >3 : jn_jes_plus=3 + if jn_jes_minus >3 : jn_jes_minus=3 + #if row.run > 2 : #apply the trigger to data only (MC triggers enter in the scale factors) if not bool(row.singleE27WP80Pass) : continue - if not bool(row.eMatchesSingleE27WP80): continue if not selections.eSelection(row, 'e'): continue @@ -422,7 +510,6 @@ def process(self): if not row.tAntiElectronMVA5Tight : continue if not row.tAntiMuon2Loose : continue - if not row.tLooseIso3Hits : continue #isTauTight = False @@ -430,50 +517,78 @@ def process(self): #print bool(row.tTightIso3Hits) - if row.tauVetoPt20EleTight3MuLoose : continue - #if row.tauHpsVetoPt20 : continue - if row.muVetoPt5IsoIdVtx : continue - if row.eVetoCicLooseIso : continue # change it with Loose - - for j in ptthreshold: - folder = sign+'/'+processtype+'/ept'+str(j)+'/'+str(int(jn)) - #if (row.run, row.lumi, row.evt, row.ePt, row.tPt)==myevent: continue - if (row.run, row.lumi, row.evt)==myevent: continue - - if myevent!=() and (row.run, row.lumi, row.evt)==(myevent[0], myevent[1], myevent[2]): print row.ePt, row.tPt - #myevent=(row.run, row.lumi, row.evt, row.ePt, row.tPt) - myevent=(row.run, row.lumi, row.evt) - isTauTight = bool(row.tTightIso3Hits) - #print row.tLooseIso3Hits, row.tTightIso3Hits, isTauTight + #if row.tauVetoPt20EleTight3MuLoose : continue + #if row.muVetoPt5IsoIdVtx : continue + #if row.eVetoCicLooseIso : continue # change it with Loose + + if row.tauVetoPt20EleTight3MuLoose and row.tauVetoPt20EleTight3MuLoose_tes_minus and row.tauVetoPt20EleTight3MuLoose_tes_plus: continue + if row.muVetoPt5IsoIdVtx and row.muVetoPt5IsoIdVtx_mes_minus and row.muVetoPt5IsoIdVtx_mes_plus : continue + if row.eVetoCicLooseIso and row.eVetoCicLooseIso_ees_minus and row.eVetoCicLooseIso_ees_plus : continue + + standardSelection=True + tesminus =True + tesplus =True + mesminus =True + mesplus =True + eesminus =True + eesplus =True + + if row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx or row.eVetoCicLooseIso : standardSelection = False + + if row.tauVetoPt20EleTight3MuLoose_tes_minus or row.muVetoPt5IsoIdVtx or row.eVetoCicLooseIso : tesminus = False + if row.tauVetoPt20EleTight3MuLoose_tes_plus or row.muVetoPt5IsoIdVtx or row.eVetoCicLooseIso : tesplus = False + if row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx_mes_minus or row.eVetoCicLooseIso : mesminus = False + if row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx_mes_plus or row.eVetoCicLooseIso : mesplus = False + if row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx or row.eVetoCicLooseIso_ees_minus : eesminus = False + if row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx or row.eVetoCicLooseIso_ees_plus : eesplus = False + + dirpaths = [(standardSelection, sign+'/'+processtype), (mesplus, 'mVetoUp/'+sign+'/'+processtype), (mesminus, 'mVetoDown/'+sign+'/'+processtype), \ + (eesplus, 'eVetoUp/'+sign+'/'+processtype), (eesminus, 'eVetoDown/'+sign+'/'+processtype), \ + (tesplus, 'tVetoUp/'+sign+'/'+processtype), (tesminus, 'tVetoDown/'+sign+'/'+processtype)] - if row.ePt < j : continue + + + if (row.run, row.lumi, row.evt)==myevent: continue + if myevent!=() and (row.run, row.lumi, row.evt)==(myevent[0], myevent[1], myevent[2]): print row.ePt, row.tPt + + myevent=(row.run, row.lumi, row.evt) + isTauTight = bool(row.tTightIso3Hits) + folder = dirpaths[0][1]+'/ept30' + if dirpaths[0][0] == True and sign=='os': self.fill_histos(row, folder,isTauTight, frw) + + for n,dirpath in enumerate(dirpaths): + jetlist = [(int(jn), str(int(jn)))] + if dirpath[0]==False : continue + if n==0: + jetlist.extend([(int(jn_jes_plus), str(int(jn_jes_plus))+'_jes_plus'), (int(jn_jes_minus), str(int(jn_jes_plus))+'_jes_minus')]) + for jet in jetlist: + #for j in ptthreshold: + folder = dirpath[1]+'/ept30/'+jet[1] + + #print row.tLooseIso3Hits, row.tTightIso3Hits, isTauTight + + self.fill_histos(row, folder,isTauTight, frw) - #print row.run, row.lumi, row.evt, row.ePt, row.tPt, row.tMtToPFMET, row.eEta, row.tEta, row.ePhi, row.tPhi - #print 'histo filled' - #selections - if jn == 0 : - - if row.tPt < 35: continue - if row.ePt < 40 : continue - if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue - if row.tMtToPFMET > 50 : continue - - - if jn == 1 : - if row.tPt < 40: continue - if row.ePt < 35 : continue - if row.tMtToPFMET > 35 : continue - if jn == 2 : - if row.tPt < 40: continue - if row.ePt < 30 : continue # no cut as only electrons with pt>30 are in the ntuples - if row.tMtToPFMET > 35 : continue - if row.vbfMass < 550 : continue - if row.vbfDeta < 3.5 : continue - folder = sign+'/'+processtype+'/ept'+str(j)+'/'+str(int(jn))+'/selected' - self.fill_histos(row, folder, isTauTight,frw) + if jet[0] == 0 : + if row.tPt < 35: continue + if row.ePt < 40 : continue + if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue + if row.tMtToPFMET > 50 : continue + if jet[0] == 1 : + if row.tPt < 40: continue + if row.ePt < 35 : continue + if row.tMtToPFMET > 35 : continue + if jet[0] == 2 : + if row.tPt < 40: continue + if row.ePt < 30 : continue # no cut as only electrons with pt>30 are in the ntuples + if row.tMtToPFMET > 35 : continue + if row.vbfMass < 550 : continue + if row.vbfDeta < 3.5 : continue + folder = dirpath[1]+'/ept30/'+jet[1]+'/selected' + self.fill_histos(row, folder, isTauTight,frw) diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index 5d5274e1..2963dd77 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -52,6 +52,7 @@ samples = Hash[ "signalMCMuTauvbf" => get_sample_names('vbfHiggsToMuTau'), "ggHiggsTo2Taus" => get_sample_names('GluGluToHToTauTau_M-125_8TeV-powheg-pythia6'), "vbfHiggsTo2Taus" => get_sample_names('VBF_HToTauTau_M-125_8TeV-powheg-pythia6'), + "Zembedded" => get_sample_names('ZetauEmbedded'), "dataSingleE" => get_sample_names('data_SingleElectron_Run2012') ] @@ -229,7 +230,7 @@ task :genkinEMu => get_analyzer_results("LFVHAnalyzeGENEMu.py", samples['signalM task :recoplots => get_analyzer_results("LFVHETauAnalyzer.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'])# + samples['dataSingleE'] ) -task :recoplotsMVA => get_analyzer_results("LFVHETauAnalyzerMVA.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + +task :recoplotsMVA => get_analyzer_results("LFVHETauAnalyzerMVA.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + samples['Zembedded']+ samples['dataSingleE'] ) task :recoplotsMVAeMtcut => get_analyzer_results("LFVHETauAnalyzerMVA_eMTCut.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + @@ -241,18 +242,18 @@ task :recoplotsMuTau => get_analyzer_results("LFVHMuTauAnalyzer.py", samples['si task :controlplots => get_analyzer_results("EEAnalyzer.py",samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + samples['dataSingleE']) task :controlplotsMVA => get_analyzer_results("EEAnalyzerMVA.py", #samples['signalMCvbf'] )#samples['zjets']) - samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + samples['dataSingleE']) + samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + samples['Zembedded']+ samples['dataSingleE']) task :fakeeet => get_analyzer_results("TauFakeRateAnalyzer.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['zzjets'] + samples['wzjets'] + - samples['zjets'] + samples['dataSingleE']) + samples['zjets'] + samples['Zembedded']+samples['dataSingleE']) task :fakeeetMVA => get_analyzer_results("TauFakeRateAnalyzerMVA.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['zzjets'] + samples['wzjets'] + - samples['zjets'] + samples['dataSingleE']) + samples['zjets'] + samples['Zembedded']+samples['dataSingleE']) $etdir = "plots/#{$jobid}/LFVHETauAnalyzer/et/" diff --git a/lfvetau/TauFakeRateAnalyzerMVA.py b/lfvetau/TauFakeRateAnalyzerMVA.py index 5d6a4f54..d02c2ca6 100644 --- a/lfvetau/TauFakeRateAnalyzerMVA.py +++ b/lfvetau/TauFakeRateAnalyzerMVA.py @@ -185,7 +185,6 @@ def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): def process(self): - print 'LINE', get_linenumber() cut_flow_histo = self.cut_flow_histo cut_flow_trk = cut_flow_tracker(cut_flow_histo) myevent =() @@ -194,24 +193,20 @@ def process(self): jn = row.jetVeto30 if jn > 3 : jn = 3 - print 'LINE', get_linenumber() - #if row.run > 2: + #if row.run > 2: if not bool(row.singleE27WP80Pass) : continue - print 'LINE', get_linenumber() # if hasattr(self.tree, 'row.e1MatchesEle27WP80') and hasattr(self.tree, 'row.e2MatchesEle27WP80') : #if not bool(row.e1MatchesEle27WP80) and not bool(row.e2MatchesEle27WP80) : continue - print 'LINE', get_linenumber() - + #else : if not bool(row.e1MatchesSingleE27WP80) and not bool(row.e2MatchesSingleE27WP80) : continue #if not bool(row.singleEPass) : continue #if not bool(row.e1MatchesSingleE) and not bool(row.e2MatchesSingleE) : continue - print 'LINE', get_linenumber() + if row.bjetCSVVeto30!=0 : continue if row.e1Pt < 30 : continue if row.e2Pt < 30 : continue - print 'LINE', get_linenumber() - + # for i, row in enumerate(self.tree): # if i >= 100: # return @@ -224,8 +219,7 @@ def process(self): if not selections.lepton_id_iso(row, 'e1', 'eid13Tight_etauiso01'): continue if abs(row.e1Eta) > 1.4442 and abs(row.e1Eta < 1.566) : continue - print 'LINE', get_linenumber() - + cut_flow_trk.Fill('e1IDiso') if not selections.eSelection(row, 'e2'): continue cut_flow_trk.Fill('e2sel') @@ -247,8 +241,7 @@ def process(self): #if row.tauHpsVetoPt20 : continue if row.muVetoPt5IsoIdVtx : continue if row.eVetoCicLooseIso : continue # change it with Loose - print 'LINE', get_linenumber() - + if not row.tMtToMET < 50: continue cut_flow_trk.Fill('MtToMet') @@ -260,13 +253,11 @@ def process(self): sign = 'ss' if row.e1_e2_SS else 'os' folder = sign+'/'+tauiso - print 'LINE', get_linenumber() self.fill_histos(row, folder) folder=folder+'/'+str(int(jn)) self.fill_histos(row, folder) - print 'LINE', get_linenumber() - + if row.tPt < 90 and row.tPt>65 : folder = folder+'/tptregion' self.fill_histos(row, folder) @@ -299,9 +290,7 @@ def process(self): folder = sign+'/'+tauiso+'/tptregion' self.fill_histos(row, folder) - print 'LINE', get_linenumber() - - + if row.tLooseIso3Hits : tauiso = 'tLoose' folder = sign+'/'+tauiso diff --git a/lfvetau/jobid.sh b/lfvetau/jobid.sh index 7e32420f..adca46df 100644 --- a/lfvetau/jobid.sh +++ b/lfvetau/jobid.sh @@ -4,5 +4,7 @@ #export jobid8='MCntuples_13May' #export jobid8='newNtuple_3JuneLfvHnoteXsec' #export jobid8='newNtuple_2Sept' -export jobid8='newNtuple_1Oct' +#export jobid8='newNtuple_1Oct' export jobidmt='MCntuples_8April' +export jobid8='newNtuple_10Oct' +export jobidSync='newNtuple_Sync' diff --git a/lfvetau/make_proxies.sh b/lfvetau/make_proxies.sh index 13c671b5..f7700080 100755 --- a/lfvetau/make_proxies.sh +++ b/lfvetau/make_proxies.sh @@ -4,8 +4,9 @@ source jobid.sh -#export jobid=$jobid8 -export jobid="newNtuple_9Oct" +export jobid=$jobid8 +#export jobid="newNtuple_9Oct" + export datasrc=/hdfs/store/user/$USER/$jobid #export datasrc=`ls -d /nfs_scratch/taroni/$jobid | head -n 1` @@ -22,6 +23,17 @@ rake "make_wrapper[$afile, eet/final/Ntuple, EETauTree]" rake "make_wrapper[$afile, et/final/Ntuple, ETauTree]" ls *pyx | sed "s|pyx|so|" | xargs -n 1 -P 10 rake +export jobid=$jobidSync +export datasrc=/hdfs/store/user/$USER/$jobid +if [ -z $1 ]; then + export afile=`find $datasrc/ | grep root | head -n 1` +else + export afile=$1 +fi + +rake "make_wrapper[$afile, eg/final/Ntuple, EGTree]" +ls *pyx | sed "s|pyx|so|" | xargs -n 1 -P 10 rake + #export jobid=$jobidmt #export datasrc=/hdfs/store/user/$USER/$jobid # diff --git a/lfvetau/run.sh b/lfvetau/run.sh index 96ac7086..608bc3b8 100755 --- a/lfvetau/run.sh +++ b/lfvetau/run.sh @@ -6,8 +6,8 @@ set -o errexit export MEGAPATH=/hdfs/store/user/taroni/ source jobid.sh -#export jobid=$jobid8 -export jobid='newNtuple_9Oct' +export jobid=$jobid8 +#export jobid='newNtuple_9Oct' #export jobid='newNtuple_11June' #export jobid='newNtuple_3JuneOldWXJetsXsec' #rake genkin diff --git a/lfvetau/setup.sh b/lfvetau/setup.sh index 32b8641e..8ac918c1 100755 --- a/lfvetau/setup.sh +++ b/lfvetau/setup.sh @@ -4,17 +4,27 @@ export OVERRIDE_META_TREE_data_ET='et/metaInfo' export IGNORE_LUMI_ERRORS=1 source jobid.sh -#export jobid=$jobid8 -export jobid='newNtuple_9Oct' +./make_proxies.sh +export datasrc=/hdfs/store/user/$USER/ #$(ls -d /scratch/*/data/$jobid | awk -F +export MEGAPATH=/hdfs/store/user/$USER + +export jobid=$jobidSync +rake "meta:getinputs[$jobid, $datasrc,eg/metaInfo]" +rake "meta:getmeta[inputs/$jobid, eg/metaInfo, 8]" + + +#export jobid='newNtuple_10Oct' echo $jobid -export datasrc=/hdfs/store/user/$USER/ #$(ls -d /scratch/*/data/$jobid | awk -F$jobid '{print $1}') +$jobid '{print $1}') #export datasrc=/nfs_scratch/taroni/data -export MEGAPATH=/hdfs/store/user/$USER #export MEGAPATH=/nfs_scratch/taroni/data -./make_proxies.sh + +export jobid=$jobid8 rake "meta:getinputs[$jobid, $datasrc,et/metaInfo]" rake "meta:getmeta[inputs/$jobid, et/metaInfo, 8]" + + #export jobid=$jobidmt #./make_proxies.sh #rake "meta:getinputs[$jobid, $datasrc,em/metaInfo]" From 80ba400a0ae4abddc19b7578b88b02338a3fdcc2 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Thu, 16 Oct 2014 08:17:31 -0500 Subject: [PATCH 106/192] adding branches --- dependencies/FinalStateAnalysis | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 160000 => 120000 dependencies/FinalStateAnalysis diff --git a/dependencies/FinalStateAnalysis b/dependencies/FinalStateAnalysis deleted file mode 160000 index 6334928c..00000000 --- a/dependencies/FinalStateAnalysis +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6334928c5c20c98f4f8cca36ed36628a5342ee3f diff --git a/dependencies/FinalStateAnalysis b/dependencies/FinalStateAnalysis new file mode 120000 index 00000000..344025ae --- /dev/null +++ b/dependencies/FinalStateAnalysis @@ -0,0 +1 @@ +../../FinalStateAnalysis \ No newline at end of file From 7d3a7edba6c052674140d23c84e2540ac3743ec4 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Thu, 16 Oct 2014 09:17:09 -0500 Subject: [PATCH 107/192] adding (first and raw attempt) EleFakeRateAnalyzer --- lfvetau/EleFakeRateAnalyzerMVA.py | 276 ++++++++++++++++++++++++++++++ lfvetau/Rakefile | 13 +- lfvetau/TauFakeRateAnalyzerMVA.py | 2 +- lfvetau/make_proxies.sh | 1 + lfvetau/run.sh | 3 +- 5 files changed, 289 insertions(+), 6 deletions(-) create mode 100644 lfvetau/EleFakeRateAnalyzerMVA.py diff --git a/lfvetau/EleFakeRateAnalyzerMVA.py b/lfvetau/EleFakeRateAnalyzerMVA.py new file mode 100644 index 00000000..8c157d0c --- /dev/null +++ b/lfvetau/EleFakeRateAnalyzerMVA.py @@ -0,0 +1,276 @@ +##Correction Factor still to add +from EEETree import EEETree +import os +import ROOT +import math +import optimizer +import glob +import array +import mcCorrections +import baseSelections as selections +import FinalStateAnalysis.PlotTools.pytree as pytree +from FinalStateAnalysis.PlotTools.decorators import memo_last +from FinalStateAnalysis.PlotTools.MegaBase import MegaBase +from math import sqrt, pi, sin, cos, acos, sinh +from cutflowtracker import cut_flow_tracker +#Makes the cut flow histogram +cut_flow_step = ['allEvents', 'e1sel', 'e1IDiso', 'e2sel', 'e2IDiso', 'ZMass', 'tsel', 'tAntiMuon', 'tAntiEle', 'MtToMet', 'tRawIso10','tRawIso5', 'tLooseIso', 'tTightIso' +] + +from inspect import currentframe + +def get_linenumber(): + cf = currentframe() + return cf.f_back.f_lineno + +def deltaPhi(phi1, phi2): + PHI = abs(phi1-phi2) + if PHI<=pi: + return PHI + else: + return 2*pi-PHI +def deltaR(phi1, phi2, eta1, eta2): + deta = eta1 - eta2 + dphi = abs(phi1-phi2) + if (dphi>pi) : dphi = 2*pi-dphi + return sqrt(deta*deta + dphi*dphi); + +def etDR(row): + return row.e1_e3_DR if row.e1_e3_DR < row.e2_e3_DR else row.e2_e3_DR + +def etDPhi(row): + e1tDPhi=deltaPhi(row.e1Phi, row.e3Phi) + e2tDPhi=deltaPhi(row.e2Phi, row.e3Phi) + return e1tDPhi if e1tDPhi < e2tDPhi else e2tDPhi + +def Z(row): + e1p=ROOT.TVector3(row.e1Pt*cos(row.e1Phi),row.e1Pt*sin(row.e1Phi),row.e1Pt*sinh(row.e1Eta)) + e2p=ROOT.TVector3(row.e2Pt*cos(row.e2Phi),row.e2Pt*sin(row.e2Phi),row.e2Pt*sinh(row.e2Eta)) + e1FourVector= ROOT.TLorentzVector(e1p, sqrt(e1p.Mag2()+row.e1Mass*row.e1Mass)) + e2FourVector= ROOT.TLorentzVector(e2p, sqrt(e2p.Mag2()+row.e2Mass*row.e2Mass)) + zFourVector = e1FourVector+e2FourVector + return zFourVector + + +class EleFakeRateAnalyzerMVA(MegaBase): + tree = 'eee/final/Ntuple' + def __init__(self, tree, outfile, **kwargs): + self.channel='EET' + super(EleFakeRateAnalyzerMVA, self).__init__(tree, outfile, **kwargs) + self.tree = EEETree(tree) + self.out=outfile + self.histograms = {} + self.pucorrector = mcCorrections.make_puCorrector('singlee') + + optimizer_keys = [ i for i in optimizer.grid_search.keys() if i.startswith(self.channel) ] + self.grid_search = {} + if len(optimizer_keys) > 1: + for key in optimizer_keys: + self.grid_search[key] = optimizer.grid_search[key] + else: + self.grid_search[''] = optimizer.grid_search[optimizer_keys[0]] + + + def event_weight(self, row): + if row.run > 2: #FIXME! add tight ID correction + return 1. + + etrig = 'e1' + if row.e2Pt > row.e1Pt : etrig = 'e2' + if bool(row.e1MatchesSingleE27WP80) and not bool(row.e2MatchesSingleE27WP80) : etrig = 'e1' + if not bool(row.e1MatchesSingleE27WP80) and bool(row.e2MatchesSingleE27WP80) : etrig = 'e2' + + if bool(row.e3MatchesSingleE27WP80) and not bool(row.e1MatchesSingleE27WP80) and not bool(row.e2MatchesSingleE27WP80) : etrig ='e3' + + + #if bool(row.e1MatchesEle27WP80) and not bool(row.e2MatchesEle27WP80) : etrig = 'e1' + #if not bool(row.e1MatchesEle27WP80) and bool(row.e2MatchesEle27WP80) : etrig = 'e2' + return self.pucorrector(row.nTruePU) * \ + mcCorrections.get_electronId_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e1') * \ + mcCorrections.get_electronId_corrections13_MVA(row, 'e2') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e2')* \ + mcCorrections.get_electronId_corrections13_MVA(row, 'e3') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e3') * \ + mcCorrections.get_trigger_corrections_MVA(row, etrig) +##add the trigger correction + + def begin(self): + + eiso = ['eLoose', 'eTigh'] + folder = [] + sign = ['ss','os'] + for iso in eiso: + for s in sign: + folder.append(s+'/'+iso) + j=0 + while j < 4 : + folder.append(s+'/'+iso+'/'+str(j)) + j+=1 + + for f in folder: + + self.book(f,"e1Pt", "e1 p_{T}", 200, 0, 200) + self.book(f,"e1Phi", "e1 phi", 100, -3.2, 3.2) + self.book(f,"e1Eta", "e1 eta", 50, -2.5, 2.5) + + self.book(f,"e2Pt", "e2 p_{T}", 200, 0, 200) + self.book(f,"e2Phi", "e2 phi", 100, -3.2, 3.2) + self.book(f,"e2Eta", "e2 eta", 50, -2.5, 2.5) + + self.book(f,"e3Pt", "e3 p_{T}", 200, 0, 200) + self.book(f,"e3Phi", "e3 phi", 100, -3.2, 3.2) + self.book(f,"e3Eta", "e3 eta", 50, -2.5, 2.5) + self.book(f,"e3AbsEta", "e3 abs eta", 25, 0, 2.5) + + self.book(f, "e1e2Mass", "e1e2 Inv Mass", 32, 0, 320) + + self.book(f, "e3MtToPFMET", "e3 Met MT", 100, 0, 100) + + + self.book(f,"ee3DR", "e e3 DR", 50, 0, 10) + self.book(f,"ee3DPhi", "e e3 DPhi", 32, 0, 3.2) + + self.book(f,"ze3DR", "Z e3 DR", 50, 0, 10) + self.book(f,"ze3DPhi", "Z e3 DPhi", 32, 0, 3.2) + self.book(f,"Zpt", "Z p_{T}", 200, 0, 200) + + + + self.book(f, "type1_pfMetEt", "type1_pfMetEt",200, 0, 200) + self.book(f, "jetN_30", "Number of jets, p_{T}>30", 10, -0.5, 9.5) + self.book(f, "bjetCSVVeto30", "number of bjets", 10, -0.5, 9.5) + + for s in sign: + self.book(s+'/tNoCuts', "CUT_FLOW", "Cut Flow", len(cut_flow_step), 0, len(cut_flow_step)) + + xaxis = self.histograms[s+'/tNoCuts/CUT_FLOW'].GetXaxis() + self.cut_flow_histo = self.histograms[s+'/tNoCuts/CUT_FLOW'] + self.cut_flow_map = {} + for i, name in enumerate(cut_flow_step): + xaxis.SetBinLabel(i+1, name) + self.cut_flow_map[name] = i+0.5 + + def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): + weight = self.event_weight(row) + histos = self.histograms + + histos[folder+'/e1Pt'].Fill(row.e1Pt, weight) + histos[folder+'/e1Eta'].Fill(row.e1Eta, weight) + histos[folder+'/e1Phi'].Fill(row.e1Phi, weight) + + histos[folder+'/e2Pt'].Fill(row.e2Pt, weight) + histos[folder+'/e2Eta'].Fill(row.e2Eta, weight) + histos[folder+'/e2Phi'].Fill(row.e2Phi, weight) + + histos[folder+'/e3Pt'].Fill(row.e3Pt, weight) + histos[folder+'/e3Eta'].Fill(row.e3Eta, weight) + histos[folder+'/e3AbsEta'].Fill(abs(row.e3Eta), weight) + histos[folder+'/e3Phi'].Fill(row.e3Phi, weight) + + histos[folder+'/e1e2Mass'].Fill(row.e1_e2_Mass, weight) + histos[folder+'/tMtToPFMET'].Fill(row.tMtToPFMET,weight) + + + histos[folder+'/type1_pfMetEt'].Fill(row.type1_pfMetEt) + histos[folder+'/ee3DR'].Fill(ee3DR(row)) + histos[folder+'/ee3DPhi'].Fill(ee3DPhi(row)) + histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight) + histos[folder+'/bjetCSVVeto30'].Fill(row.bjetCSVVeto30, weight) + + histos[folder+'/ze3DR'].Fill(deltaR(Z(row).Phi(), row.tPhi, Z(row).Eta(), row.e3Eta)) + histos[folder+'/ze3DPhi'].Fill(deltaPhi(Z(row).Phi(), row.e3Phi)) + histos[folder+'/Zpt'].Fill(Z(row).Pt()) + + + def process(self): + + cut_flow_histo = self.cut_flow_histo + cut_flow_trk = cut_flow_tracker(cut_flow_histo) + myevent =() + #print self.tree.inputfilename + for row in self.tree: + jn = row.jetVeto30 + if jn > 3 : jn = 3 + + #if row.run > 2: + if not bool(row.singleE27WP80Pass) : continue + # if hasattr(self.tree, 'row.e1MatchesEle27WP80') and hasattr(self.tree, 'row.e2MatchesEle27WP80') : + #if not bool(row.e1MatchesEle27WP80) and not bool(row.e2MatchesEle27WP80) : continue + + #else : + if not bool(row.e3MatchesSingleE27WP80) : continue + #if not bool(row.singleEPass) : continue + #if not bool(row.e1MatchesSingleE) and not bool(row.e2MatchesSingleE) : continue + + if row.bjetCSVVeto30!=0 : continue + if row.e1Pt < 30 : continue + if row.e2Pt < 30 : continue + +# for i, row in enumerate(self.tree): +# if i >= 100: +# return + # print bool(cut_flow_trk.disabled) + cut_flow_trk.new_row(row.run,row.lumi,row.evt) + #print row.run,row.lumi,row.evt + cut_flow_trk.Fill('allEvents') + if not selections.eSelection(row, 'e1'): continue + cut_flow_trk.Fill('e1sel') + if not selections.lepton_id_iso(row, 'e1', 'eid13Tight_etauiso01'): continue + if abs(row.e1Eta) > 1.4442 and abs(row.e1Eta < 1.566) : continue + + + cut_flow_trk.Fill('e1IDiso') + if not selections.eSelection(row, 'e2'): continue + cut_flow_trk.Fill('e2sel') + if not selections.lepton_id_iso(row, 'e2', 'eid13Tight_etauiso01'): continue + if abs(row.e2Eta) > 1.4442 and abs(row.e2Eta) < 1.566 : continue + + cut_flow_trk.Fill('e2IDiso') + if not abs(row.e1_e2_Mass-91.2) < 20: continue + cut_flow_trk.Fill('ZMass') + + if not selections.lepton_id_iso(row, 'e3', 'eid13Tight_idiso02'): continue + + cut_flow_trk.Fill('tsel') + + + if row.tauVetoPt20EleTight3MuLoose : continue + #if row.tauHpsVetoPt20 : continue + if row.muVetoPt5IsoIdVtx : continue + if row.eVetoCicLooseIso : continue # change it with Loose + + #if not row.e3MtToMET < 50: continue + cut_flow_trk.Fill('MtToMet') + + # if etDR(row) < 1. : continue + if (row.run, row.lumi, row.evt, row.e1Pt, row.e2Pt)==myevent: continue + myevent=(row.run, row.lumi, row.evt, row.e1Pt, row.e2Pt) + + eleiso = 'eLoose' + sign = 'ss' if row.e1_e2_SS else 'os' + folder = sign+'/'+eleiso + + self.fill_histos(row, folder) + folder=folder+'/'+str(int(jn)) + self.fill_histos(row, folder) + + if selections.lepton_id_iso(row, 'e3', 'eid13Tight_etauiso01'): + eleiso = 'eTigh' + folder = sign+'/'+eleiso + self.fill_histos(row, folder) + cut_flow_trk.Fill('tTightIso') + folder=folder+'/'+str(int(jn)) + self.fill_histos(row, folder) + + + + + cut_flow_trk.flush() + + + + def finish(self): + self.write_histos() + + diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index 2963dd77..63764fec 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -250,10 +250,15 @@ task :fakeeet => get_analyzer_results("TauFakeRateAnalyzer.py", samples['signalM samples['wzjets'] + samples['zjets'] + samples['Zembedded']+samples['dataSingleE']) -task :fakeeetMVA => get_analyzer_results("TauFakeRateAnalyzerMVA.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + - samples['wwjets'] + samples['zzjets'] + - samples['wzjets'] + - samples['zjets'] + samples['Zembedded']+samples['dataSingleE']) +task :fakeeetMVA => get_analyzer_results("TauFakeRateAnalyzerMVA.py",# samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['Zembedded']+ samples['zjets'] + + samples['wwjets'] + samples['zzjets'] + + samples['wzjets'] + + samples['dataSingleE']) + +task :fakeeeeMVA => get_analyzer_results("EleFakeRateAnalyzerMVA.py", #samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['zjets'] + samples['Zembedded']+ + samples['wwjets'] + samples['zzjets'] + + samples['wzjets'] + + samples['dataSingleE']) $etdir = "plots/#{$jobid}/LFVHETauAnalyzer/et/" diff --git a/lfvetau/TauFakeRateAnalyzerMVA.py b/lfvetau/TauFakeRateAnalyzerMVA.py index d02c2ca6..7156d29b 100644 --- a/lfvetau/TauFakeRateAnalyzerMVA.py +++ b/lfvetau/TauFakeRateAnalyzerMVA.py @@ -242,7 +242,7 @@ def process(self): if row.muVetoPt5IsoIdVtx : continue if row.eVetoCicLooseIso : continue # change it with Loose - if not row.tMtToMET < 50: continue + # if not row.tMtToMET < 50: continue cut_flow_trk.Fill('MtToMet') # if etDR(row) < 1. : continue diff --git a/lfvetau/make_proxies.sh b/lfvetau/make_proxies.sh index f7700080..289e1493 100755 --- a/lfvetau/make_proxies.sh +++ b/lfvetau/make_proxies.sh @@ -18,6 +18,7 @@ fi echo "Building cython wrappers from file: $afile" +rake "make_wrapper[$afile, eee/final/Ntuple, EEETree]" rake "make_wrapper[$afile, ee/final/Ntuple, EETree]" rake "make_wrapper[$afile, eet/final/Ntuple, EETauTree]" rake "make_wrapper[$afile, et/final/Ntuple, ETauTree]" diff --git a/lfvetau/run.sh b/lfvetau/run.sh index 608bc3b8..361f2f37 100755 --- a/lfvetau/run.sh +++ b/lfvetau/run.sh @@ -12,12 +12,13 @@ export jobid=$jobid8 #export jobid='newNtuple_3JuneOldWXJetsXsec' #rake genkin #rake recoplots -rake recoplotsMVA +#rake recoplotsMVA #rake recoplotsMVAeMtcut #rake controlplots #rake controlplotsMVA #rake fakeeet #rake fakeeetMVA +rake fakeeeeMVA #rake fits #rake drawTauFakeRate #export jobid=$jobidmt From bba6afac8d3ab50dac495219820d967817f1eef8 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Thu, 16 Oct 2014 10:46:26 -0500 Subject: [PATCH 108/192] make code more linear --- lfvetau/BasePlotter.py | 490 ++++++++++++++++------------------------- 1 file changed, 190 insertions(+), 300 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index a55e8ca0..bafa64e2 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -11,6 +11,7 @@ import os import math import rootpy.plotting.views as views +from pdb import set_trace from rootpy.plotting.hist import HistStack import rootpy.plotting as plotting from FinalStateAnalysis.MetaData.data_views import data_views @@ -21,7 +22,9 @@ from FinalStateAnalysis.MetaData.data_styles import data_styles from FinalStateAnalysis.PlotTools.Plotter import Plotter from FinalStateAnalysis.PlotTools.SubtractionView import SubtractionView, PositiveView - +from FinalStateAnalysis.PlotTools.MedianView import MedianView +from FinalStateAnalysis.PlotTools.SystematicsView import SystematicsView +from FinalStateAnalysis.StatTools.quad import quad import ROOT import glob from pdb import set_trace @@ -35,72 +38,67 @@ def _f(path): return path return _f +def remove_name_entry(dictionary): + return dict( [ i for i in dictionary.iteritems() if i[0] != 'name'] ) + +def histo_diff_quad(mc_err, *systematics): + nbins = mc_err.GetNbinsX() + clone = mc_err.Clone() + sys_up = [i for i, _ in systematics] + sys_dw = [i for _, i in systematics] + + #bin loop + for ibin in range(nbins+2): #from uflow to oflow + content = clone.GetBinContent(ibin) + error = clone.GetBinError(ibin) + + shifts_up = [abs(i.GetBinContent(ibin) - content) for i in sys_up] + shifts_dw = [abs(i.GetBinContent(ibin) - content) for i in sys_dw] + max_shift = [max(i, j) for i, j in zip(shifts_up, shifts_dw)] + + new_err = quad(error, *max_shift) + clone.SetBinError(ibin, new_err) + + return clone class BasePlotter(Plotter): - def __init__ (self, channel, files, lumifiles, outputdir,forceLumi=-1): + def __init__ (self, blind_region=None, forceLumi=-1): cwd = os.getcwd() - self.channel = channel + self.period = '8TeV' + self.sqrts = 8 jobid = os.environ['jobid'] - period = '7TeV' if '7TeV' in jobid else '8TeV' - self.period = period - self.sqrts = 7 if '7TeV' in jobid else 8 + print "\nPlotting e tau for %s\n" % jobid + + files = glob.glob('results/%s/LFVHETauAnalyzerMVA/*.root' % jobid) + lumifiles = glob.glob('inputs/%s/*.lumicalc.sum' % jobid) + + outputdir = 'plots/%s/lfvet' % jobid + if not os.path.exists(outputdir): + os.makedirs(outputdir) + + samples = [os.path.basename(i).split('.')[0] for i in files] + + self.blind_region=blind_region + if self.blind_region: + # Don't look at the SS all pass region + blinder = lambda x: BlindView(x, "os/.*",blind_in_range(*self.blind_region)) + + super(BasePlotter, self).__init__(files, lumifiles, outputdir, blinder, forceLumi=forceLumi) + + self.views['fakes'] = {'view' : self.make_fakes()} self.mc_samples = [ - 'ggHiggsToETau', - 'vbfHiggsToETau', - 'GluGluToHToTauTau_M-125_8TeV-powheg-pythia6', - 'VBF_HToTauTau_M-125_8TeV-powheg-pythia6', - #'Zjets_M50', - 'Zjets_M50_skimmedLL', - 'Z1jets_M50_skimmedLL', - 'Z2jets_M50_skimmedLL', - 'Z3jets_M50_skimmedLL', - 'Z4jets_M50_skimmedLL', - 'Zjets_M50_skimmedTT', - 'Z1jets_M50_skimmedTT', - 'Z2jets_M50_skimmedTT', - 'Z3jets_M50_skimmedTT', - 'Z4jets_M50_skimmedTT', + 'GluGluToHToTauTau_M-125*', + 'VBF_HToTauTau_M-125*', 'TTJets*', - 'T_t*', - 'Tbar_t*', - 'WplusJets_madgraph_skimmed', - 'Wplus1Jets_madgraph', - # 'Wplus1Jets_madgraph_tapas', - 'Wplus2Jets_madgraph', - # 'Wplus2Jets_madgraph_tapas', - 'Wplus3Jets_madgraph', - 'Wplus4Jets_madgraph', - 'WWJets*', - 'WZJets*', - 'ZZJets*', - 'Fake*', - 'data*', - + 'T*_t*', + '[WZ][WZ]Jets', + #'Wplus*Jets_madgraph*', #superseded by fakes + 'Z*jets_M50_skimmedLL', + 'Z*jets_M50_skimmedTT', ] -## files = [] -## lumifiles = [] -## -## for x in mc_samples: -## files.extend(glob.glob('results/%s/LFVHETauAnalyzerMVA/%s.root' % (jobid, x))) -## lumifiles.extend(glob.glob('inputs/%s/%s.lumicalc.sum' % (jobid, x))) -## self.outputdir = 'plots/%s/LFVHETauAnalyzerMVA/%s' % (jobid, channel) -## self.base_out_dir = self.outputdir -## if not os.path.exists(self.outputdir): -## os.makedirs(self.outputdir) -## - self.blindstart=100 - self.blindend=150 - - blinder = None - blind = 'blind' not in os.environ or os.environ['blind'] == 'YES' - print '\n\nRunning Blind: %s\n\n' % blind - self.blind = blind - - if blind: - # Don't look at the SS all pass region - blinder = lambda x: BlindView(x, "os/.*",blind_in_range(100, 150)) - super(BasePlotter, self).__init__(files, lumifiles, outputdir, blinder) + + def simpleplot_mc(self, folder, signal, variable, rebin=1, xaxis='', leftside=True, xrange=None, preprocess=None, sort=True,forceLumi=-1): ''' Compare Monte Carlo signal to bkg ''' @@ -282,56 +280,6 @@ def add_ratio_bandplot(self, data_hist, mc_stack, err_hist, x_range=None, ratio return data_clone - - def get_isoid_unc (self, folder, variable, rebin, preprocess, obj=['e1', 'e2']): - # 'e1idp1s/','e1idm1s/', 'e1isop1s/','e1isom1s/','e2idp1s/','e2idm1s/', 'e2isop1s/','e2isom1s/' - unc_list = [] - for n, lep in enumerate(obj): - - bkg_lep_iso_p1s_stack_view = self.make_stack(rebin, preprocess, lep+'isop1s/'+folder) - bkg_lep_iso_p1s_stack= bkg_lep_iso_p1s_stack_view.Get(variable) - histo_lep_iso_p1s = bkg_lep_iso_p1s_stack.GetStack().Last().Clone() - - bkg_lep_iso_m1s_stack_view = self.make_stack(rebin, preprocess, lep+'isom1s/'+folder) - bkg_lep_iso_m1s_stack=bkg_lep_iso_m1s_stack_view.Get(variable) - histo_lep_iso_m1s = bkg_lep_iso_m1s_stack.GetStack().Last().Clone() - - bkg_lep_id_p1s_stack_view = self.make_stack(rebin, preprocess, lep+'idp1s/'+folder) - bkg_lep_id_p1s_stack= bkg_lep_id_p1s_stack_view.Get(variable) - histo_lep_id_p1s = bkg_lep_id_p1s_stack.GetStack().Last().Clone() - - bkg_lep_id_m1s_stack_view = self.make_stack(rebin, preprocess, lep+'idm1s/'+folder) - bkg_lep_id_m1s_stack=bkg_lep_id_m1s_stack_view.Get(variable) - histo_lep_id_m1s = bkg_lep_id_m1s_stack.GetStack().Last().Clone() - - #bkg_obj2_iso_p1s_stack_view = self.make_stack(rebin, preprocess, obj2+'isop1s/'+folder) - #bkg_obj2_iso_p1s_stack= bkg_obj2_iso_p1s_stack_view.Get(variable) - #histo_obj2_iso_p1s = bkg_obj2_iso_p1s_stack.GetStack().Last().Clone() - - #bkg_obj2_iso_m1s_stack_view = self.make_stack(rebin, preprocess, obj2+'isom1s/'+folder) - #bkg_obj2_iso_m1s_stack=bkg_obj2_iso_m1s_stack_view.Get(variable) - #histo_obj2_iso_m1s = bkg_obj2_iso_m1s_stack.GetStack().Last().Clone() - - #bkg_obj2_id_p1s_stack_view = self.make_stack(rebin, preprocess, obj2+'idp1s/'+folder) - #bkg_obj2_id_p1s_stack= bkg_obj2_id_p1s_stack_view.Get(variable) - #histo_obj2_id_p1s = bkg_obj2_id_p1s_stack.GetStack().Last().Clone() - - #bkg_obj2_id_m1s_stack_view = self.make_stack(rebin, preprocess, obj2+'idm1s/'+folder) - #bkg_obj2_id_m1s_stack=bkg_obj2_id_m1s_stack_view.Get(variable) - #histo_obj2_id_m1s = bkg_obj2_id_m1s_stack.GetStack().Last().Clone() - - self.keep.append(histo_lep_iso_p1s) - self.keep.append(histo_lep_iso_m1s) - self.keep.append(histo_lep_id_p1s) - self.keep.append(histo_lep_id_m1s) - #self.keep.append(histo_obj2_iso_p1s) - #self.keep.append(histo_obj2_iso_m1s) - #self.keep.append(histo_obj2_id_p1s) - #self.keep.append(histo_obj2_id_m1s) - - unc_list.extend([(histo_lep_iso_p1s, histo_lep_iso_m1s), (histo_lep_id_p1s, histo_lep_id_m1s)]) - return unc_list -#[(histo_obj1_iso_p1s, histo_obj1_iso_m1s), (histo_obj1_id_p1s, histo_obj1_id_m1s), (histo_obj2_iso_p1s, histo_obj2_iso_m1s), (histo_obj2_id_p1s, histo_obj2_id_m1s)] def add_ratio_diff(self, data_hist, mc_stack, err_hist, x_range=None, ratio_range=0.2): #resize the canvas and the pad to fit the second pad self.canvas.SetCanvasSize( self.canvas.GetWw(), int(self.canvas.GetWh()*1.3) ) @@ -369,11 +317,10 @@ def add_ratio_diff(self, data_hist, mc_stack, err_hist, x_range=None, ratio_ran #print err for ibin in err: band.SetBinError(ibin[0], ibin[1]) - blind=None - blind = 'blind' not in os.environ or os.environ['blind'] == 'YES' - if blind<>None: + + if self.blind_region: for ibin in err: - if ibin>=band.FindBin(self.blindstart) and ibin <= band.FindBin(self.blindend): + if ibin >= band.FindBin(self.blind_region[0]) and ibin <= band.FindBin(self.blind_region[1]): band.SetBinError(ibin, 10) if not x_range: @@ -395,7 +342,7 @@ def add_ratio_diff(self, data_hist, mc_stack, err_hist, x_range=None, ratio_ran ref_function.Draw('same') band.SetMarkerStyle(0) band.SetLineColor(1) - band.SetFillStyle(3001) + band.SetFillStyle('x') band.SetFillColor(1) band.Draw('samee2') @@ -406,220 +353,163 @@ def add_ratio_diff(self, data_hist, mc_stack, err_hist, x_range=None, ratio_ran self.pad.cd() return data_clone + def make_fakes(self): + data_view = self.get_view('data') + central_fakes = views.SubdirectoryView(data_view, 'tLoose') + up_fakes = views.SubdirectoryView(data_view, 'tLooseUp') + style = data_styles['Fakes*'] + return views.TitleView( + views.StyleView( + MedianView(highv=up_fakes, centv=central_fakes), + **remove_name_entry(style) + ), + style['name'] + ) + def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', - leftside=True, xrange=None, preprocess=None, + leftside=True, xrange=None, preprocess=None, show_ratio=False, ratio_range=0.2, sort=True, obj=['e1', 'e2']): + #xsection uncertainties + #names must match with what defined in self.mc_samples + xsec_unc_mapper = { + 'TTJets*' : 0.026, + 'T*_t*' : 0.041, + '[WZ][WZ]Jets' : 0.056, #diboson + 'Wplus*Jets_madgraph*' : 0.035, #WJets + 'Z*jets_M50_skimmedLL' : 0.032, + } + + path = os.path.join(folder,variable) + + #make MC views with xsec error + mc_views_nosys = self.mc_views(rebin, preprocess) + mc_views = [] + for view, name in zip(mc_views_nosys, self.mc_samples): + new = SystematicsView( + view, + xsec_unc_mapper.get(name, 0.) #default to 0 + ) + mc_views.append(new) + + #make MC stack + mc_stack_view = views.StackView(*mc_views, sorted=sort) + mc_stack = mc_stack_view.Get( path ) + + #make histo clone for err computation + mc_sum_view = views.SumView(*mc_views) + mc_err = mc_sum_view.Get( path ) + + #add lumi uncertainty + mc_err = SystematicsView.add_error( mc_err, 0.026 ) + #Add MC systematics + folder_systematics = [ + ('p1s', 'm1s'), #PU correction + ('trp1s', 'trm1s'), #trig scale factor + ] + + #Add as many eid sys as requested + for name in obj: + folder_systematics.extend([ + ('%sidp1s' % name, '%sidm1s' % name), #eID scale factor + ('%sisop1s' % name, '%sisop1s' % name), #e Iso scale factor + ]) + + met_systematics = [ + ('_jes', '_jes_minus'), + ('_mes', '_mes_minus'), + ('_ees', '_ees_minus'), + ('_tes', '_tes_minus'), + ('_ues', '_ues_minus'), + ] + + name_systematics = [] #which are not MET + #add MET sys if necessary + if 'collmass' in variable.lower() or \ + 'met' in variable.lower(): + c = 1 + #name_systematics.extend(met_systematics) + + systematics = [] + for sys_up, sys_dw in folder_systematics: + h_up = mc_sum_view.Get(os.path.join(sys_up, path)) + h_dw = mc_sum_view.Get(os.path.join(sys_dw, path)) + systematics.append( + (h_up, h_dw) + ) + + #check if we have to apply met uncertainties + for sys_up, sys_dw in name_systematics: + h_up = mc_sum_view.Get(path + sys_up) + h_dw = mc_sum_view.Get(path + sys_dw) + systematics.append( + (h_up, h_dw) + ) + #ADD systematics + mc_err = histo_diff_quad(mc_err, *systematics) + + #get fakes + fakes_view = RebinView(self.get_view('fakes'), rebin) + fakes = fakes_view.Get(path) - mc_stack_view = self.make_stack(rebin, preprocess, folder, sort) + #add them to backgrounds + mc_stack.Add(fakes) + mc_err += fakes + #set_trace() - mc_stack = mc_stack_view.Get(variable) + #draw stack mc_stack.Draw() + self.keep.append(mc_stack) + #set cosmetics self.canvas.SetLogy(True) mc_stack.GetHistogram().GetXaxis().SetTitle(xaxis) if xrange: mc_stack.GetXaxis().SetRangeUser(xrange[0], xrange[1]) mc_stack.Draw() - self.keep.append(mc_stack) - - - finalhisto= mc_stack.GetStack().Last().Clone() - finalhisto.Sumw2() - - histlist = mc_stack.GetHists(); - bkg_stack = mc_stack_view.Get(variable) - bkg_stack.GetStack().RemoveLast()## mettere il check se c'e` il fake altirmenti histo=mc_stack.GetStack().Last().Clone() - histo=bkg_stack.GetStack().Last().Clone() - histo.Sumw2() - - fake_p1s_histo=None - - if not folder.startswith('tLoose'): - ##if folder.startswith('os'): - ## newfolder=folder#.replace('os','ss') - ## print 'newfolder', newfolder - ## #tau fake error - ## - ##fake_stack_view = self.make_stack(rebin, preprocess, 'tLoose/'+newfolder, sort) - ## fake_p1s_stack_view = self.make_stack(rebin, preprocess, 'tLooseUp/'+newfolder, sort) - ## fake_m1s_stack_view = self.make_stack(rebin, preprocess, 'tLooseDown/'+newfolder, sort) - ## - ## #if (type(fake_stack_view)==ROOT.THStack): - ## #print 'adding tau fakerate uncertainty' - ## - ## try: - ##fake_stack = fake_stack_view.Get(variable) - ##fakehisto = fake_stack.GetStack().Last().Clone() - ## - ## fake_p1s_stack = fake_p1s_stack_view.Get(variable) - ## fake_p1s_histo = fake_p1s_stack.GetStack().Last().Clone() - ## fake_m1s_stack = fake_m1s_stack_view.Get(variable) - ## fake_m1s_histo = fake_m1s_stack.GetStack().Last().Clone() - ## - ## except: - ## print 'no fake taus' - ## fake_diffup = 0 - ## fake_diffdown = 0 - - - print folder - print self.mc_samples - isFakesIn= False - if 'Fakes' in self.mc_samples: - self.mc_samples.remove('Fakes') - self.mc_samples.remove('finalDYLL') - isFakesIn=True - - bkg_p1s_stack_view = self.make_stack(rebin, preprocess, 'p1s/'+folder, sort) - bkg_p1s_stack=bkg_p1s_stack_view.Get(variable) - histo_p1s = bkg_p1s_stack.GetStack().Last().Clone() - - bkg_m1s_stack_view = self.make_stack(rebin, preprocess, 'm1s/'+folder, sort) - bkg_m1s_stack=bkg_m1s_stack_view.Get(variable) - histo_m1s = bkg_m1s_stack.GetStack().Last().Clone() - - tr_p1s_stack_view = self.make_stack(rebin, preprocess, 'trp1s/'+folder, sort) - tr_p1s_stack=tr_p1s_stack_view.Get(variable) - histotr_p1s = tr_p1s_stack.GetStack().Last().Clone() - - tr_m1s_stack_view = self.make_stack(rebin, preprocess, 'trm1s/'+folder, sort) - tr_m1s_stack=tr_m1s_stack_view.Get(variable) - histotr_m1s = tr_m1s_stack.GetStack().Last().Clone() - #if os.path.exists(folder+'tLoose/') : - # fr_tau_stack_view = self.make_stack(rebin, preprocess, 'tLoose/'+folder, sort) - # fr_tau_stack=fr_tau_stack_view.Get(variable) - # histofr_tau = fr_tau_stack.GetStack().Last().Clone() - # histofr_tau.SetTitle('Fakes') - - xsec_unc_mapper = { - 'EWK Dibosons': 0.056, - 'SM Higgs': 0.0, #still to add - 't#bar{t}' : 0.026, - 'Single Top' : 0.041, - 'DY (#rightarrow #tau#tau) + jets' : 0., - 'DY (#rightarrow ll) + jets' : 0.032, - 'W + jets': 0.035, - 'QCD' : 0.0, - 'Fakes' :0.0, - } - - ibin =1 - - iso_id_unc = self.get_isoid_unc( folder, variable, rebin, preprocess, obj) - if isFakesIn: - self.mc_samples.append('Fakes') - self.mc_samples.append('finalDYLL') - - met_histos=[] - if 'Met' in variable or 'MET' in variable: - if not 'mva' in variable or not 'MVA' in variable: - if 'type1_' in variable or '_Ty1' in variable: - ##print variable - newMetName=variable.replace('type1_', '') if 'type1_' in variable else variable.replace('_Ty', '') - met_histos.extend([mc_stack_view.Get(newMetName+'_jes'),mc_stack_view.Get(newMetName+'_mes'),mc_stack_view.Get(newMetName+'_tes'),mc_stack_view.Get(newMetName+'_ues'), mc_stack_view.Get(newMetName+'_ees') ]) ##add the ees - else: - met_histos.extend([mc_stack_view.Get(variable+'_jes'),mc_stack_view.Get(variable+'_mes'),mc_stack_view.Get(variable+'_tes'),mc_stack_view.Get(variable+'_ues'),mc_stack_view.Get(variable+'_ees')]) ##add the ees - - while ibin < histo.GetXaxis().GetNbins()+1: - ##print ibin,histo.GetXaxis().GetNbins() - err2=0 - - #if isFakesIn: - #diff_fake_up= abs(fakehisto.GetBinContent(ibin)-fake_p1s_histo.GetBinContent(ibin)) - #diff_fake_down= abs(fakehisto.GetBinContent(ibin)-fake_m1s_histo.GetBinContent(ibin)) - #print ibin, fakehisto.GetBinContent(ibin), fake_p1s_histo.GetBinContent(ibin), fake_m1s_histo.GetBinContent(ibin) - #diff_fake = diff_fake_up if diff_fake_up > diff_fake_down else diff_fake_down - - #err2+= pow(diff_fake,2) - ##err2+=pow(fakehisto.GetBinContent(ibin) * 0.3) - #print 'TAU SYSTEMATICS:', fakehisto.GetBinContent(ibin), diff_fake - - for h in histlist: - err2 += h.GetBinError(ibin)**2 - - err2 += h.GetBinContent(ibin)*xsec_unc_mapper[h.GetTitle()] - - - #tau fake rake, I approximate with 5%. Redo it in the correct way - #diff_fake = abs(histo.GetBinContent(ibin) - finalhisto.GetBinContent(ibin)) - #err2 += pow(diff_fake*0.05,2) - - #why is not working? - #diff_fake = abs(fake_diffup.GetBinContent(ibin)) if abs(fake_diffup.GetBinContent(ibin)) > abs(fake_diffdown.GetBinContent(ibin)) else abs(fake_diffdown.GetBinContent(ibin)) - - if not folder.startswith('tLoose'): - diff_p = abs(histo.GetBinContent(ibin) - histo_p1s.GetBinContent(ibin)) - diff_m = abs(histo.GetBinContent(ibin) - histo_m1s.GetBinContent(ibin)) - err2 += diff_p**2 if diff_p > diff_m else diff_m**2 - diff_tr_p = abs(histo.GetBinContent(ibin) - histotr_p1s.GetBinContent(ibin)) - diff_tr_m = abs(histo.GetBinContent(ibin) - histotr_m1s.GetBinContent(ibin)) - err2 += diff_tr_p**2 if diff_tr_p > diff_tr_m else diff_tr_m**2 - err2 += (0.026*h.GetBinContent(ibin))**2 #lumi error - - - for h in iso_id_unc : - diff_isoid_p = abs(histo.GetBinContent(ibin) - h[0].GetBinContent(ibin)) - diff_isoid_m = abs(histo.GetBinContent(ibin) - h[1].GetBinContent(ibin)) - err2 += diff_isoid_p**2 if diff_isoid_p > diff_isoid_m else diff_isoid_m**2 - - #add met unc https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuidePATTools#MET_Systematics_Tools only to met plots (no cut on the met) - if 'Met' in variable or 'MET' in variable: - if not 'mva' in variable or not 'MVA' in variable: - if not '_jes' in variable and not '_mes' in variable and not '_tes' in variable \ - and not '_ees' in variable and not '_ues' in variable: - if not 'type1_' in variable and not '_Ty1' in variable: - for h in met_histos: - diff = abs(histo.GetBinContent(ibin) - h.GetStack().Last().GetBinContent(ibin)) - ##print variable, diff, histo.GetBinContent(ibin), h.GetStack().Last().GetBinContent(ibin), h.GetName() - err2+=diff**2 - else: - myh = mc_stack_view.Get(variable.replace('type1_', '')) if 'type1_' in variable else variable.replace('_Ty', '') - for h in met_histos: - diff = abs(h.GetStack().Last().GetBinContent(ibin) - myh.GetStack().Last().GetBinContent(ibin)) - err2+=diff**2 - - #histo.SetBinError(ibin, math.sqrt(err2)) - #finalhisto.SetBinError(ibin, math.sqrt(err2)) + #set cosmetics and draw error + mc_err.SetMarkerStyle(0) + mc_err.SetLineColor(1) + mc_err.SetFillStyle('x') + mc_err.SetFillColor(1) + mc_err.Draw('pe2 same') + self.keep.append(mc_err) + + #Get signal + signals = [ + 'ggHiggsToETau', + 'vbfHiggsToETau', + ] + for name in signals: + sig_view = self.get_view(name) + if preprocess: + sig_view = preprocess(sig_view) + sig_view = RebinView(sig_view, rebin) + histogram = sig_view.Get(path) + histogram.Draw('same') + self.keep.append(histogram) - - ibin+=1 - - - finalhisto.Draw('samee2') - finalhisto.SetMarkerStyle(0) - finalhisto.SetLineColor(1) - finalhisto.SetFillStyle(3001) - finalhisto.SetFillColor(1) - - - self.keep.append(finalhisto) # Draw data data_view = self.get_view('data') if preprocess: data_view = preprocess( data_view ) - data_view = self.get_wild_dir( - self.rebin_view(data_view, rebin), - folder - ) - data = data_view.Get(variable) + data_view = self.rebin_view(data_view, rebin) + data = data_view.Get(path) + data.Draw('same') print 'data', data.Integral() self.keep.append(data) + ## Make sure we can see everything if data.GetMaximum() > mc_stack.GetMaximum(): mc_stack.SetMaximum(1.2*data.GetMaximum()) - #mc_stack.SetMinimum(0.00001*data.GetMaximum()) - - # # Ad legend - #allentries = [data] - #allentries.append( x for x in mc_stack.GetHists() ) + self.add_legend([data, mc_stack], leftside, entries=len(mc_stack.GetHists())+1) if show_ratio: - self.add_ratio_diff(data, mc_stack, finalhisto, xrange, ratio_range) + self.add_ratio_plot(data, mc_err, xrange, ratio_range, True) # add_ratio_diff(data, mc_stack, mc_err, xrange, ratio_range) ##----- From 1b69544c857a6a75381a7fea804c86e4b57455d0 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Thu, 16 Oct 2014 10:46:57 -0500 Subject: [PATCH 109/192] make code more linear --- lfvetau/TauFakeRateAnalyzerMVA.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/lfvetau/TauFakeRateAnalyzerMVA.py b/lfvetau/TauFakeRateAnalyzerMVA.py index 5d6a4f54..d02c2ca6 100644 --- a/lfvetau/TauFakeRateAnalyzerMVA.py +++ b/lfvetau/TauFakeRateAnalyzerMVA.py @@ -185,7 +185,6 @@ def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): def process(self): - print 'LINE', get_linenumber() cut_flow_histo = self.cut_flow_histo cut_flow_trk = cut_flow_tracker(cut_flow_histo) myevent =() @@ -194,24 +193,20 @@ def process(self): jn = row.jetVeto30 if jn > 3 : jn = 3 - print 'LINE', get_linenumber() - #if row.run > 2: + #if row.run > 2: if not bool(row.singleE27WP80Pass) : continue - print 'LINE', get_linenumber() # if hasattr(self.tree, 'row.e1MatchesEle27WP80') and hasattr(self.tree, 'row.e2MatchesEle27WP80') : #if not bool(row.e1MatchesEle27WP80) and not bool(row.e2MatchesEle27WP80) : continue - print 'LINE', get_linenumber() - + #else : if not bool(row.e1MatchesSingleE27WP80) and not bool(row.e2MatchesSingleE27WP80) : continue #if not bool(row.singleEPass) : continue #if not bool(row.e1MatchesSingleE) and not bool(row.e2MatchesSingleE) : continue - print 'LINE', get_linenumber() + if row.bjetCSVVeto30!=0 : continue if row.e1Pt < 30 : continue if row.e2Pt < 30 : continue - print 'LINE', get_linenumber() - + # for i, row in enumerate(self.tree): # if i >= 100: # return @@ -224,8 +219,7 @@ def process(self): if not selections.lepton_id_iso(row, 'e1', 'eid13Tight_etauiso01'): continue if abs(row.e1Eta) > 1.4442 and abs(row.e1Eta < 1.566) : continue - print 'LINE', get_linenumber() - + cut_flow_trk.Fill('e1IDiso') if not selections.eSelection(row, 'e2'): continue cut_flow_trk.Fill('e2sel') @@ -247,8 +241,7 @@ def process(self): #if row.tauHpsVetoPt20 : continue if row.muVetoPt5IsoIdVtx : continue if row.eVetoCicLooseIso : continue # change it with Loose - print 'LINE', get_linenumber() - + if not row.tMtToMET < 50: continue cut_flow_trk.Fill('MtToMet') @@ -260,13 +253,11 @@ def process(self): sign = 'ss' if row.e1_e2_SS else 'os' folder = sign+'/'+tauiso - print 'LINE', get_linenumber() self.fill_histos(row, folder) folder=folder+'/'+str(int(jn)) self.fill_histos(row, folder) - print 'LINE', get_linenumber() - + if row.tPt < 90 and row.tPt>65 : folder = folder+'/tptregion' self.fill_histos(row, folder) @@ -299,9 +290,7 @@ def process(self): folder = sign+'/'+tauiso+'/tptregion' self.fill_histos(row, folder) - print 'LINE', get_linenumber() - - + if row.tLooseIso3Hits : tauiso = 'tLoose' folder = sign+'/'+tauiso From c07ebcbd335c46818c9c15680bc31ccc8f131771 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Thu, 16 Oct 2014 10:47:57 -0500 Subject: [PATCH 110/192] analysis env --- lfvetau/environment.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 lfvetau/environment.sh diff --git a/lfvetau/environment.sh b/lfvetau/environment.sh new file mode 100644 index 00000000..078465f7 --- /dev/null +++ b/lfvetau/environment.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +source ../environment.sh +source jobid.sh +export jobid=$jobid8 +export blind='YES' From 68df264a2fec35ed5f07a737cda2b7cae1da187c Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Fri, 17 Oct 2014 04:09:40 -0500 Subject: [PATCH 111/192] bug fix --- lfvetau/EleFakeRateAnalyzerMVA.py | 12 +++---- lfvetau/Rakefile | 52 +++++++++++++++---------------- lfvetau/run.sh | 4 +-- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/lfvetau/EleFakeRateAnalyzerMVA.py b/lfvetau/EleFakeRateAnalyzerMVA.py index 8c157d0c..c06dac4b 100644 --- a/lfvetau/EleFakeRateAnalyzerMVA.py +++ b/lfvetau/EleFakeRateAnalyzerMVA.py @@ -35,13 +35,13 @@ def deltaR(phi1, phi2, eta1, eta2): if (dphi>pi) : dphi = 2*pi-dphi return sqrt(deta*deta + dphi*dphi); -def etDR(row): +def ee3DR(row): return row.e1_e3_DR if row.e1_e3_DR < row.e2_e3_DR else row.e2_e3_DR -def etDPhi(row): - e1tDPhi=deltaPhi(row.e1Phi, row.e3Phi) - e2tDPhi=deltaPhi(row.e2Phi, row.e3Phi) - return e1tDPhi if e1tDPhi < e2tDPhi else e2tDPhi +def ee3DPhi(row): + e1e3DPhi=deltaPhi(row.e1Phi, row.e3Phi) + e2e3DPhi=deltaPhi(row.e2Phi, row.e3Phi) + return e1e3DPhi if e1e3DPhi < e2e3DPhi else e2e3DPhi def Z(row): e1p=ROOT.TVector3(row.e1Pt*cos(row.e1Phi),row.e1Pt*sin(row.e1Phi),row.e1Pt*sinh(row.e1Eta)) @@ -169,7 +169,7 @@ def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): histos[folder+'/e3Phi'].Fill(row.e3Phi, weight) histos[folder+'/e1e2Mass'].Fill(row.e1_e2_Mass, weight) - histos[folder+'/tMtToPFMET'].Fill(row.tMtToPFMET,weight) + #histos[folder+'/tMtToPFMET'].Fill(row.tMtToPFMET,weight) histos[folder+'/type1_pfMetEt'].Fill(row.type1_pfMetEt) diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index 63764fec..1f55fc21 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -74,7 +74,7 @@ def get_plotter_results(analyzer) end -$frfit_dir = "results/#{$jobid}/fakerate_fits" +$frfit_dir = "results/#{$jobid}/fakerate_fits_MtCut" directory $frfit_dir exponential = "scale*TMath::Exp(x*decay)+offset" exponential_vars = "scale[4., 0, 10],decay[-1e-2, -1, -1e-4],offset[1e-2, 0, 0.5]" @@ -108,18 +108,18 @@ fr_fits = Hash.new #mysamples = [ "zjets_skimmedLL", "zjets_skimmedTT"] #for s in mysamples -fr_fits["t_os_tNoCuts_tTigh_tPt"] = Hash[ - "samples" => Array["diboson", "dataSingleE"], - "analyzer" => $fr_analyzer, - "function" => pol0, - "variables" => pol0_vars, - #"rebin" => 1, - "rebin" => $fr_binning, - "range" => "30 200", - "title" => "#tau p_{T} (GeV)", - "min"=>"0", - "max"=>"0.1" - ] +#fr_fits["t_os_tNoCuts_tTigh_tPt"] = Hash[ +# "samples" => Array["diboson", "dataSingleE"], +# "analyzer" => $fr_analyzer, +# "function" => pol0, +# "variables" => pol0_vars, +# #"rebin" => 1, +# "rebin" => $fr_binning, +# "range" => "30 200", +# "title" => "#tau p_{T} (GeV)", +# "min"=>"0", +# "max"=>"0.1" +# ] fr_fits["t_os_tLoose_tTigh_tPt"] = Hash[ "samples" => Array["diboson", "dataSingleE"], "analyzer" => $fr_analyzer, @@ -135,18 +135,18 @@ fr_fits["t_os_tLoose_tTigh_tPt"] = Hash[ "max"=>"1" ] -fr_fits["t_os_tNoCuts_tTigh_tAbsEta"] = Hash[ - "samples" => Array["diboson", "dataSingleE"], - "analyzer" => $fr_analyzer, - "function" => pol2, - "variables" => pol2_vars, - "rebin" => 1, - #"range" => "-2.3 2.3", - "range" => "0 2.3", - "title" => "#tau #eta", - "min"=>"0", - "max"=>"0.1" - ] +#fr_fits["t_os_tNoCuts_tTigh_tAbsEta"] = Hash[ +# "samples" => Array["diboson", "dataSingleE"], +# "analyzer" => $fr_analyzer, +# "function" => pol2, +# "variables" => pol2_vars, +# "rebin" => 1, +# #"range" => "-2.3 2.3", +# "range" => "0 2.3", +# "title" => "#tau #eta", +# "min"=>"0", +# "max"=>"0.1" +# ] fr_fits["t_os_tLoose_tTigh_tAbsEta"] = Hash[ "samples" => Array["diboson", "dataSingleE"], "analyzer" => $fr_analyzer, @@ -179,7 +179,7 @@ fr_fits.each do |fit, fit_info| fit_output = $frfit_dir + "/#{fit}.root" - subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/#{fit_info['analyzer']}/#{x}.root"} + subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/#{fit_info['analyzer']}_tMtCut/#{x}.root"} # subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/TauFakeRateAnalyzerMVA_eTight/#{x}.root"} subsample_input_list = subsamples_inputs_result_list.join(" ") diff --git a/lfvetau/run.sh b/lfvetau/run.sh index 361f2f37..e1caa128 100755 --- a/lfvetau/run.sh +++ b/lfvetau/run.sh @@ -17,8 +17,8 @@ export jobid=$jobid8 #rake controlplots #rake controlplotsMVA #rake fakeeet -#rake fakeeetMVA -rake fakeeeeMVA +rake fakeeetMVA +#rake fakeeeeMVA #rake fits #rake drawTauFakeRate #export jobid=$jobidmt From fcfca198db262a5c5bdab7c4bf1b737396d8fa16 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 17 Oct 2014 04:10:59 -0500 Subject: [PATCH 112/192] added support for embeded samples --- lfvetau/BasePlotter.py | 155 ++++++++++++++++++-------- lfvetau/plotRecoQuantitiesMVA.py | 184 ++++++------------------------- 2 files changed, 143 insertions(+), 196 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index bafa64e2..446b349d 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -62,11 +62,12 @@ def histo_diff_quad(mc_err, *systematics): return clone class BasePlotter(Plotter): - def __init__ (self, blind_region=None, forceLumi=-1): + def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): cwd = os.getcwd() self.period = '8TeV' self.sqrts = 8 jobid = os.environ['jobid'] + self.use_embedded = use_embedded print "\nPlotting e tau for %s\n" % jobid files = glob.glob('results/%s/LFVHETauAnalyzerMVA/*.root' % jobid) @@ -96,8 +97,39 @@ def __init__ (self, blind_region=None, forceLumi=-1): 'Z*jets_M50_skimmedLL', 'Z*jets_M50_skimmedTT', ] + + if use_embedded: + self.mc_samples.pop() + self.views['Ztt_embedded'] = {'view' : self.make_embedded('os/gg/ept30/h_collmass_pfmet')} + + def make_fakes(self): + '''Sets up the fakes view''' + data_view = self.get_view('data') + central_fakes = views.SubdirectoryView(data_view, 'tLoose') + up_fakes = views.SubdirectoryView(data_view, 'tLooseUp') + style = data_styles['Fakes*'] + return views.TitleView( + views.StyleView( + MedianView(highv=up_fakes, centv=central_fakes), + **remove_name_entry(style) + ), + style['name'] + ) + def make_embedded(self, normalization_path): + '''Configures the embedded view''' + embedded_view = self.get_view('ZetauEmbedded_Run2012*', 'unweighted_view') + zjets_view = self.get_view('Z*jets_M50_skimmedTT') + embedded_histo = embedded_view.Get(normalization_path) + zjets_histo = zjets_view.Get(normalization_path) + + embed_int = embedded_histo.Integral() + zjets_int = zjets_histo.Integral() + + scale_factor = zjets_int / embed_int + scaled_view = views.ScaleView(embedded_view, scale_factor) + return scaled_view def simpleplot_mc(self, folder, signal, variable, rebin=1, xaxis='', leftside=True, xrange=None, preprocess=None, sort=True,forceLumi=-1): @@ -353,19 +385,35 @@ def add_ratio_diff(self, data_hist, mc_stack, err_hist, x_range=None, ratio_ran self.pad.cd() return data_clone - def make_fakes(self): - data_view = self.get_view('data') - central_fakes = views.SubdirectoryView(data_view, 'tLoose') - up_fakes = views.SubdirectoryView(data_view, 'tLooseUp') - style = data_styles['Fakes*'] - return views.TitleView( - views.StyleView( - MedianView(highv=up_fakes, centv=central_fakes), - **remove_name_entry(style) - ), - style['name'] - ) + def add_shape_systematics(self, histo, path, view, folder_systematics = [], name_systematics = []): + '''Adds shape systematics + add_shape_systematics(self, histo, path, view, folder_systematics = [], name_systematics = []) --> histo + histo is the central value + path is the path if the central value histo + view contains all the systematics. + folder_systematics is a list of tuples with the folders containing shifts (up, down) + name_systematics is a list of tuples containing the postfix to obtain the shifts (up, down) + ''' + systematics = [] + for sys_up, sys_dw in folder_systematics: + h_up = view.Get(os.path.join(sys_up, path)) + h_dw = view.Get(os.path.join(sys_dw, path)) + systematics.append( + (h_up, h_dw) + ) + + #check if we have to apply met uncertainties + for sys_up, sys_dw in name_systematics: + h_up = view.Get(path + sys_up) + h_dw = view.Get(path + sys_dw) + systematics.append( + (h_up, h_dw) + ) + + #ADD systematics + return histo_diff_quad(histo, *systematics) + def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', leftside=True, xrange=None, preprocess=None, show_ratio=False, ratio_range=0.2, sort=True, obj=['e1', 'e2']): @@ -377,6 +425,7 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', '[WZ][WZ]Jets' : 0.056, #diboson 'Wplus*Jets_madgraph*' : 0.035, #WJets 'Z*jets_M50_skimmedLL' : 0.032, + 'Z*jets_M50_skimmedTT' : 0.032, } path = os.path.join(folder,variable) @@ -398,23 +447,12 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', #make histo clone for err computation mc_sum_view = views.SumView(*mc_views) mc_err = mc_sum_view.Get( path ) - - #add lumi uncertainty - mc_err = SystematicsView.add_error( mc_err, 0.026 ) - #Add MC systematics + #Add MC-only systematics folder_systematics = [ ('p1s', 'm1s'), #PU correction - ('trp1s', 'trm1s'), #trig scale factor ] - #Add as many eid sys as requested - for name in obj: - folder_systematics.extend([ - ('%sidp1s' % name, '%sidm1s' % name), #eID scale factor - ('%sisop1s' % name, '%sisop1s' % name), #e Iso scale factor - ]) - met_systematics = [ ('_jes', '_jes_minus'), ('_mes', '_mes_minus'), @@ -430,27 +468,58 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', c = 1 #name_systematics.extend(met_systematics) - systematics = [] - for sys_up, sys_dw in folder_systematics: - h_up = mc_sum_view.Get(os.path.join(sys_up, path)) - h_dw = mc_sum_view.Get(os.path.join(sys_dw, path)) - systematics.append( - (h_up, h_dw) - ) + #add them + mc_err = self.add_shape_systematics( + mc_err, + path, + mc_sum_view, + folder_systematics, + name_systematics) + + #check if we are using the embedded sample + if self.use_embedded: + embed_view = self.get_view('Ztt_embedded') + if preprocess: + embed_view = preprocess(embed_view) + embed_view = RebinView( embed_view, rebin) - #check if we have to apply met uncertainties - for sys_up, sys_dw in name_systematics: - h_up = mc_sum_view.Get(path + sys_up) - h_dw = mc_sum_view.Get(path + sys_dw) - systematics.append( - (h_up, h_dw) - ) - - #ADD systematics - mc_err = histo_diff_quad(mc_err, *systematics) + embed = embed_view.Get(path) + + #add xsec error + embed = SystematicsView.add_error( embed, xsec_unc_mapper['Z*jets_M50_skimmedTT']) + + #add them to backgrounds + mc_stack.Add(embed) + mc_err += embed + mc_sum_view = views.SumView(mc_sum_view, embed_view) + + #Add MC and embed systematics + folder_systematics = [ + ('trp1s', 'trm1s'), #trig scale factor + ] + + #Add as many eid sys as requested + for name in obj: + folder_systematics.extend([ + ('%sidp1s' % name, '%sidm1s' % name), #eID scale factor + ('%sisop1s' % name, '%sisop1s' % name), #e Iso scale factor + ]) + + mc_err = self.add_shape_systematics( + mc_err, + path, + mc_sum_view, + folder_systematics) + + #add lumi uncertainty + mc_err = SystematicsView.add_error( mc_err, 0.026 ) #get fakes - fakes_view = RebinView(self.get_view('fakes'), rebin) + fakes_view = self.get_view('fakes') + if preprocess: + fakes_view = preprocess(fakes_view) + fakes_view = RebinView(fakes_view, rebin) + fakes = fakes_view.Get(path) #add them to backgrounds diff --git a/lfvetau/plotRecoQuantitiesMVA.py b/lfvetau/plotRecoQuantitiesMVA.py index f7078209..396f7360 100644 --- a/lfvetau/plotRecoQuantitiesMVA.py +++ b/lfvetau/plotRecoQuantitiesMVA.py @@ -1,15 +1,19 @@ #from mauro plotters + +#Set logging before anything to override rootpy very verbose defaults +import sys +import logging +logging.basicConfig(stream=sys.stderr, level=logging.INFO) + import os -from sys import argv, stdout, stderr import ROOT -import sys +from pdb import set_trace from FinalStateAnalysis.PlotTools.MegaBase import make_dirs from FinalStateAnalysis.MetaData.data_styles import data_styles from FinalStateAnalysis.PlotTools.BlindView import BlindView, blind_in_range from FinalStateAnalysis.PlotTools.SubtractionView import SubtractionView, PositiveView - +import itertools import glob -import logging import sys from BasePlotter import BasePlotter @@ -24,163 +28,37 @@ print "\nPlotting %s for %s\n" % (channel, jobid) -mc_samples = [ - 'ggHiggsToETau', - 'vbfHiggsToETau', - 'GluGluToHToTauTau_M-125_8TeV-powheg-pythia6', - 'VBF_HToTauTau_M-125_8TeV-powheg-pythia6', - #'Zjets_M50', - 'Zjets_M50_skimmedLL', - 'Z1jets_M50_skimmedLL', - 'Z2jets_M50_skimmedLL', - 'Z3jets_M50_skimmedLL', - 'Z4jets_M50_skimmedLL', - 'Zjets_M50_skimmedTT', - 'Z1jets_M50_skimmedTT', - 'Z2jets_M50_skimmedTT', - 'Z3jets_M50_skimmedTT', - 'Z4jets_M50_skimmedTT', - 'TTJets*', - 'T_t*', - 'Tbar_t*', - #'WplusJets_madgraph_skimmed', - 'Wplus1Jets_madgraph*', - #'Wplus1Jets_madgraph_tapas', - 'Wplus2Jets_madgraph*', - #'Wplus2Jets_madgraph_tapas', - 'Wplus3Jets_madgraph', - 'Wplus4Jets_madgraph', - 'WWJets*', - 'WZJets*', - 'ZZJets*', - 'Fake*', - 'data*' -] - - -files = [] -lumifiles = [] - -for x in mc_samples: - files.extend(glob.glob('results/%s/LFVHETauAnalyzerMVA_noOverlap/%s.root' % (jobid, x))) - lumifiles.extend(glob.glob('inputs/%s/%s.lumicalc.sum' % (jobid, x))) - -sign = ['os', 'ss'] -jets = [0, 1, 2] -processtype=['gg'] -threshold=['ept30'] - -outputdir = 'plots/%s/LFVHETauAnalyzerMVA/%s/' % (jobid, channel) -if not os.path.exists(outputdir): - os.makedirs(outputdir) - - - -def remove_name_entry(dictionary): - return dict( [ i for i in dictionary.iteritems() if i[0] != 'name'] ) - - - - -plotter = BasePlotter(channel,files, lumifiles, outputdir, forceLumi=19800) - -ggMCSignal =views.ScaleView( views.TitleView(views.StyleView(plotter.get_view('ggHiggsToETau'), **remove_name_entry(data_styles['ggHiggsToETau*'])), 'LFV gg Higgs, BR = 1.'),1.) -vbfMCSignal = views.ScaleView(views.TitleView(views.StyleView(plotter.get_view('vbfHiggsToETau'), **remove_name_entry(data_styles['vbfHiggsToETau*'])), 'LFV vbf Higgs, BR = 1.'),1.) +#check if blind +blind = 'blind' not in os.environ or os.environ['blind'] == 'YES' +blind_region=[100, 150] if blind else None -plotter.views['ggMCSignal']= {'view': ggMCSignal} -plotter.views['vbfMCSignal']= {'view': vbfMCSignal} +plotter = BasePlotter(blind_region) -EWKDiboson = views.TitleView(views.StyleView( - views.SumView( - *[ plotter.get_view(regex) for regex in \ - filter(lambda x : x.startswith('WW') or x.startswith('WZ') or x.startswith('ZZ') or x.startswith('WG'), mc_samples )] - ), **remove_name_entry(data_styles['WW*'#,'WZ*', 'WG*', 'ZZ*' -]) -), 'EWK Dibosons') -Wplus = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('Wplus'), mc_samples )]), **remove_name_entry(data_styles['Wplus*Jets*'])), 'W + jets') -DYLL = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('skimmedLL'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*LL'])), 'DY (#rightarrow ll) + jets') -DYLLfake = views.SubdirectoryView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedLL'), mc_samples )]), 'tLoose') +signs = ['os', 'ss'] +jets = ['0', '1', '2'] +processtype = ['gg'] +threshold = ['ept30'] -DYTT = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedTT'), mc_samples )]), **remove_name_entry(data_styles['Z*jets*TT'])), -'DY (#rightarrow #tau#tau) + jets') -TT = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('TT') , mc_samples)]), **remove_name_entry(data_styles['TTJets*'])), 't#bar{t}') -singleT = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('T_') or x.startswith('Tbar_'), mc_samples)]), **remove_name_entry(data_styles['T*_t*'])), 'Single Top') -SMH = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : 'HToTauTau' in x , mc_samples)]), **remove_name_entry(data_styles['GluGluToHToTauTau*'])), 'SM Higgs') - - -plotter.views['EWKDiboson']={'view' : EWKDiboson } -plotter.views['Wplus']={'view' : Wplus } -#plotter.views['DYLL']={'view' : DYLL } -plotter.views['DYTT']={'view' : DYTT } -plotter.views['singleT']={'view' : singleT } -plotter.views['SMH']={'view' : SMH } -plotter.views['TT']={'view' : TT } -#plotter.views['DY']={'view' : DY } -new_mc_samples =[] - -#DYLL = views.TitleView(views.StyleView(views.SubtractionView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedTT'), mc_samples )]), views.SubdirectoryView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.endswith('jets_M50_skimmedLL'), mc_samples )]), 'tLoose')), **remove_name_entry(data_styles['Z*jets*LL'])), 'DY (#rightarrow ll) + jets') -finalDYLL = SubtractionView(DYLL,DYLLfake) -plotter.views['finalDYLL']={'view' : finalDYLL } - -new_mc_samples.extend(['EWKDiboson', - 'SMH', 'singleT',#'Wplus', - 'TT', - 'finalDYLL', 'DYTT'#, 'ggMCSignal', 'vbfMCSignal' -]) -def get_fakeTaus(x): - y=x - if x.startswith('os') or x.startswith('ss'): - y = x.replace('.*s/', 'tLoose/*s/') - - return y - -#myFake = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('Fake'), mc_samples)]),**data_styles['Fakes*']), 'Fakes') - -Fakes = views.SubdirectoryView(views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : 'Fake*' in x, mc_samples)]), **remove_name_entry(data_styles['Fakes*'])),'Fakes'), 'tLoose/') - -#SumView(views.PathModifierView( views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('Fake'), mc_samples)]), get_fakeTaus)),**remove_name_entry(data_styles['Fakes*'])), 'Fakes') -plotter.views['Fakes']= {'view': Fakes} -new_mc_samples.extend(['Fakes']) - -print new_mc_samples - -histoname = [('tPt', 'p_{T}(#tau) (GeV)', 5), ('tEta', '#eta(#tau)', 2), ('tPhi', '#phi(#tau)', 5), +histo_info = [('tPt', 'p_{T}(#tau) (GeV)', 5), ('tEta', '#eta(#tau)', 2), ('tPhi', '#phi(#tau)', 5), ('ePt', 'p_{T}(e) (GeV)', 5), ('eEta', '#eta(e)', 2), ('ePhi', '#phi(e)', 5), - ('et_DeltaPhi', 'e#tau #Delta#phi', 1.), ('et_DeltaR', 'e#tau #Delta R', 1.), - ('h_collmass_pfmet', 'M_{coll}(e#tau) (GeV)', 1.), ('h_vismass', 'M_{vis} (GeV)', 1.), - ('jetN_30', 'number of jets (p_{T} > 30 GeV)', 1.) , ('ePFMET_Mt', 'M_{T} e-PFMET', 5), + ('et_DeltaPhi', 'e#tau #Delta#phi', 1), ('et_DeltaR', 'e#tau #Delta R', 1), + ('h_collmass_pfmet', 'M_{coll}(e#tau) (GeV)', 1), ('h_vismass', 'M_{vis} (GeV)', 1), + ('jetN_30', 'number of jets (p_{T} > 30 GeV)', 1) , ('ePFMET_Mt', 'M_{T} e-PFMET', 5), ('tPFMET_Mt', 'M_{T} #tau-PFMET', 5) ] - -plotter.mc_samples = new_mc_samples -foldernames = [] -for i in sign: - for j in processtype: - for k in threshold: - for jn in jets: - - foldernames.append(i+'/'+j+'/'+k +'/'+str(jn)) - foldernames.append(i+'/'+j+'/'+k +'/'+str(jn)+'/selected') - - - -for foldername in foldernames: - for n,h in enumerate(histoname) : - +logging.debug("Starting plotting") +for sign, proc, thr, njet in itertools.product(signs, processtype, threshold, jets): + path = os.path.join(sign, proc, thr, njet) + plotter.set_subdir(path) + for var, xlabel, rebin in histo_info: + logging.debug("Plotting %s/%s" % (path, var) ) plotter.pad.SetLogy(False) - #print foldername + #plotter.plot_without_uncert(foldername,h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.5, sort=True, obj=['e']) + plotter.plot_with_bkg_uncert(path, var, rebin, xlabel, + leftside=False, show_ratio=True, ratio_range=0.5, + sort=True, obj=['e']) - #plotter.simpleplot_mc(foldername,['ggMCSignal','vbfMCSignal'], h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, forceLumi=19800) - #plotter.plot_with_bkg_uncert(foldername,h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.5, sort=True, obj=['e']) - plotter.plot_without_uncert(foldername,h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.5, sort=True, obj=['e']) - #plotter.plot_mc_vs_data(foldername, h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=False, ratio_range=0.2) - - - - if not os.path.exists(outputdir+foldername): - os.makedirs(outputdir+foldername) - - plotter.save(foldername+'/'+h[0]) + plotter.save(var) From 382ff679d251df7fb4641298d29e61d4685e949b Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 17 Oct 2014 04:11:44 -0500 Subject: [PATCH 113/192] added more files to ignore --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index a5e0c25b..901bd4c6 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,9 @@ docs/build/* callgrind.out.* *.orig *.rej +*.*~ +*.out +*_setup.py +*Tree.pyx +*Tree.cpp +#*.*# From 0e306a25f063df8389d3236c2c39c63fd65f388c Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Fri, 17 Oct 2014 11:43:15 -0500 Subject: [PATCH 114/192] bug fix --- lfvetau/EleFakeRateAnalyzerMVA.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lfvetau/EleFakeRateAnalyzerMVA.py b/lfvetau/EleFakeRateAnalyzerMVA.py index c06dac4b..d1e41731 100644 --- a/lfvetau/EleFakeRateAnalyzerMVA.py +++ b/lfvetau/EleFakeRateAnalyzerMVA.py @@ -178,7 +178,7 @@ def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight) histos[folder+'/bjetCSVVeto30'].Fill(row.bjetCSVVeto30, weight) - histos[folder+'/ze3DR'].Fill(deltaR(Z(row).Phi(), row.tPhi, Z(row).Eta(), row.e3Eta)) + histos[folder+'/ze3DR'].Fill(deltaR(Z(row).Phi(), row.e3Phi, Z(row).Eta(), row.e3Eta)) histos[folder+'/ze3DPhi'].Fill(deltaPhi(Z(row).Phi(), row.e3Phi)) histos[folder+'/Zpt'].Fill(Z(row).Pt()) @@ -216,14 +216,14 @@ def process(self): cut_flow_trk.Fill('allEvents') if not selections.eSelection(row, 'e1'): continue cut_flow_trk.Fill('e1sel') - if not selections.lepton_id_iso(row, 'e1', 'eid13Tight_etauiso01'): continue + if not selections.lepton_id_iso(row, 'e1', 'eid13Loose_etauiso01'): continue if abs(row.e1Eta) > 1.4442 and abs(row.e1Eta < 1.566) : continue cut_flow_trk.Fill('e1IDiso') if not selections.eSelection(row, 'e2'): continue cut_flow_trk.Fill('e2sel') - if not selections.lepton_id_iso(row, 'e2', 'eid13Tight_etauiso01'): continue + if not selections.lepton_id_iso(row, 'e2', 'eid13Loose_etauiso01'): continue if abs(row.e2Eta) > 1.4442 and abs(row.e2Eta) < 1.566 : continue cut_flow_trk.Fill('e2IDiso') From 2e43765fb5d7c405f6e7739c16856d6314e16310 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Fri, 17 Oct 2014 11:43:48 -0500 Subject: [PATCH 115/192] update code to embedded sample --- lfvetau/LFVHETauAnalyzerMVA.py | 118 +++++++++++++++++++++------------ lfvetau/mcCorrections.py | 23 +++++++ 2 files changed, 98 insertions(+), 43 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index c08e9c22..68b7159d 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -44,7 +44,10 @@ def __init__(self, tree, outfile, **kwargs): self.pucorrector = mcCorrections.make_puCorrector('singlee') self.pucorrectorUp = mcCorrections.make_puCorrectorUp('singlee') self.pucorrectorDown = mcCorrections.make_puCorrectorDown('singlee') - + target = os.path.basename(os.environ['megatarget']) + self.is_data = target.startswith('data_') + self.is_embedded = ('Embedded' in target) + self.is_mc = not (self.is_data or self.is_embedded) @staticmethod def tau_veto(row): @@ -60,51 +63,77 @@ def obj3_matches_gen(row): def event_weight(self, row): - if row.run > 2: #FIXME! add tight ID correction + if self.is_data: #FIXME! add tight ID correction return [1.] - allmcCorrections= mcCorrections.get_electronId_corrections13_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e') * mcCorrections.get_trigger_corrections_MVA(row,'e') - - - trUp_mcCorrections = mcCorrections.get_electronId_corrections13_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e') * mcCorrections.get_trigger_corrections_p1s_MVA(row,'e') - trDown_mcCorrections = mcCorrections.get_electronId_corrections13_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e') * mcCorrections.get_trigger_corrections_m1s_MVA(row,'e') + allmcCorrections= mcCorrections.get_electronId_corrections13_MVA(row, 'e') * \ + mcCorrections.get_electronIso_corrections13_MVA(row, 'e') + trUp_mcCorrections = 1. + trDown_mcCorrections = 1. eidUp_mcCorrections= mcCorrections.get_electronId_corrections13_p1s_MVA(row, 'e') *\ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e') * mcCorrections.get_trigger_corrections_MVA(row,'e') + mcCorrections.get_electronIso_corrections13_MVA(row, 'e') eidDown_mcCorrections= mcCorrections.get_electronId_corrections13_m1s_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e') * mcCorrections.get_trigger_corrections_MVA(row,'e') + mcCorrections.get_electronIso_corrections13_MVA(row, 'e') eisoUp_mcCorrections= mcCorrections.get_electronId_corrections13_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_p1s_MVA(row, 'e') * mcCorrections.get_trigger_corrections_MVA(row,'e') + mcCorrections.get_electronIso_corrections13_p1s_MVA(row, 'e') eisoDown_mcCorrections= mcCorrections.get_electronId_corrections13_m1s_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_p1s_MVA(row, 'e') * mcCorrections.get_trigger_corrections_MVA(row,'e') - - #pucorrlist = self.pucorrector(row.nTruePU) - - weight = self.pucorrector(row.nTruePU) *\ - allmcCorrections - weight_up = self.pucorrectorUp(row.nTruePU) *\ - allmcCorrections - weight_down = self.pucorrectorDown(row.nTruePU) *\ + mcCorrections.get_electronIso_corrections13_p1s_MVA(row, 'e') + + + if self.is_embedded: + allmcCorrections= allmcCorrections*mcCorrections.get_trigger_efficiency_MVA(row,'e') + trUp_mcCorrections = allmcCorrections*mcCorrections.get_trigger_efficiency_p1s_MVA(row,'e') + trDown_mcCorrections = allmcCorrections*mcCorrections.get_trigger_efficiency_m1s_MVA(row,'e') + eidUp_mcCorrections= eidUp_mcCorrections* mcCorrections.get_trigger_efficiency_MVA(row,'e') + eidDown_mcCorrections= eidDown_mcCorrections* mcCorrections.get_trigger_efficiency_MVA(row,'e') + eisoUp_mcCorrections= eisoUp_mcCorrections * mcCorrections.get_trigger_efficiency_MVA(row,'e') + eisoDown_mcCorrections= eisoDown_mcCorrections* mcCorrections.get_trigger_efficiency_MVA(row,'e') + + return [allmcCorrections, allmcCorrections, allmcCorrections, trUp_mcCorrections, trDown_mcCorrections ,eidUp_mcCorrections, eidDown_mcCorrections, eisoUp_mcCorrections,eisoDown_mcCorrections] + + + + + + else: + allmcCorrections= allmcCorrections * mcCorrections.get_trigger_corrections_MVA(row,'e') + + + trUp_mcCorrections = allmcCorrections* mcCorrections.get_trigger_corrections_p1s_MVA(row,'e') + trDown_mcCorrections = allmcCorrections* mcCorrections.get_trigger_corrections_m1s_MVA(row,'e') + + eidUp_mcCorrections= eidUp_mcCorrections* mcCorrections.get_trigger_corrections_MVA(row,'e') + eidDown_mcCorrections= eidDown_mcCorrections* mcCorrections.get_trigger_corrections_MVA(row,'e') + eisoUp_mcCorrections= eisoUp_mcCorrections * mcCorrections.get_trigger_corrections_MVA(row,'e') + eisoDown_mcCorrections= eisoDown_mcCorrections* mcCorrections.get_trigger_corrections_MVA(row,'e') + + #pucorrlist = self.pucorrector(row.nTruePU) + + weight = self.pucorrector(row.nTruePU) *\ allmcCorrections + weight_up = self.pucorrectorUp(row.nTruePU) *\ + allmcCorrections + weight_down = self.pucorrectorDown(row.nTruePU) *\ + allmcCorrections + + weight_tr_up = self.pucorrector(row.nTruePU) *\ + trUp_mcCorrections + weight_tr_down = self.pucorrector(row.nTruePU) *\ + trDown_mcCorrections + + + weight_eid_up = self.pucorrector(row.nTruePU) *\ + eidUp_mcCorrections + weight_eid_down = self.pucorrector(row.nTruePU) *\ + eidDown_mcCorrections + weight_eiso_up = self.pucorrector(row.nTruePU) *\ + eisoUp_mcCorrections + weight_eiso_down = self.pucorrector(row.nTruePU) *\ + eisoDown_mcCorrections - weight_tr_up = self.pucorrector(row.nTruePU) *\ - trUp_mcCorrections - weight_tr_down = self.pucorrector(row.nTruePU) *\ - trDown_mcCorrections + + return [weight, weight_up, weight_down, weight_tr_up, weight_tr_down, weight_eid_up, weight_eid_down, weight_eiso_up, weight_eiso_down] - - weight_eid_up = self.pucorrector(row.nTruePU) *\ - eidUp_mcCorrections - weight_eid_down = self.pucorrector(row.nTruePU) *\ - eidDown_mcCorrections - weight_eiso_up = self.pucorrector(row.nTruePU) *\ - eisoUp_mcCorrections - weight_eiso_down = self.pucorrector(row.nTruePU) *\ - eisoDown_mcCorrections - - return [weight, weight_up, weight_down, weight_tr_up, weight_tr_down, weight_eid_up, weight_eid_down, weight_eiso_up, weight_eiso_down,] ## def begin(self): @@ -467,6 +496,7 @@ def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): def process(self): + central_weights = fakerate_central_histogram(25,0, 2.5) p1s_weights = fakerate_p1s_histogram(25,0, 2.5)#fakerate_p1s_histogram(25,0, 2.5) @@ -493,9 +523,13 @@ def process(self): if jn_jes_minus >3 : jn_jes_minus=3 #if row.run > 2 : #apply the trigger to data only (MC triggers enter in the scale factors) - if not bool(row.singleE27WP80Pass) : continue + + if self.is_embedded : - if not bool(row.eMatchesSingleE27WP80): continue + if not bool(row.doubleMuPass) : continue + else: + if not bool(row.singleE27WP80Pass) : continue + if not bool(row.eMatchesSingleE27WP80): continue if not selections.eSelection(row, 'e'): continue @@ -504,7 +538,6 @@ def process(self): if abs(row.eEta) > 1.4442 and abs(row.eEta) < 1.566 : continue if not selections.tauSelection(row, 't'): continue - if row.bjetCSVVeto30!=0 : continue if row.ePt < 30 : continue #if row.eMtToPFMET <40 : continue @@ -514,9 +547,6 @@ def process(self): #isTauTight = False frw=self.fakerate_weights(row.tEta, central_weights, p1s_weights, m1s_weights ) - - #print bool(row.tTightIso3Hits) - #if row.tauVetoPt20EleTight3MuLoose : continue #if row.muVetoPt5IsoIdVtx : continue @@ -559,6 +589,8 @@ def process(self): if dirpaths[0][0] == True and sign=='os': self.fill_histos(row, folder,isTauTight, frw) + if row.bjetCSVVeto30!=0 : continue # it is better vetoing on b-jets after the histo for the DY embedded + for n,dirpath in enumerate(dirpaths): jetlist = [(int(jn), str(int(jn)))] if dirpath[0]==False : continue diff --git a/lfvetau/mcCorrections.py b/lfvetau/mcCorrections.py index 9a6c64a5..408f0ed5 100755 --- a/lfvetau/mcCorrections.py +++ b/lfvetau/mcCorrections.py @@ -54,6 +54,7 @@ def make_puCorrectorDown(dataset, kind=None): correct_eReco_mva = HetauCorrection.scale_elereco_hww correct_eIso_mva = HetauCorrection.scale_eleIso_hww correct_trigger_mva = HetauCorrection.single_ele_mva +efficiency_trigger_mva = HetauCorrection.single_ele_eff_mva def get_electron_corrections(row,*args): 'makes corrections to iso and id of electrons' @@ -108,6 +109,28 @@ def get_trigger_corrections_m1s_MVA(row, *args): ret *= correct_trigger_mva(pt,eta)[0]-correct_trigger_mva(pt,eta)[1] return ret +def get_trigger_efficiency_MVA(row, *args): + ret = 1. + for arg in args: + eta = getattr(row, '%sEta' % arg) + pt = getattr(row, '%sPt' % arg) + ret *= efficiency_trigger_mva(pt,eta)[0] + return ret +def get_trigger_efficiency_p1s_MVA(row, *args): + ret = 1. + for arg in args: + eta = getattr(row, '%sEta' % arg) + pt = getattr(row, '%sPt' % arg) + ret *= efficiency_trigger_mva(pt,eta)[0]+efficiency_trigger_mva(pt,eta)[1] + return ret +def get_trigger_efficiency_m1s_MVA(row, *args): + ret = 1. + for arg in args: + eta = getattr(row, '%sEta' % arg) + pt = getattr(row, '%sPt' % arg) + ret *= efficiency_trigger_mva(pt,eta)[0]-efficiency_trigger_mva(pt,eta)[1] + + return ret def get_electronId_corrections13_MVA(row, *args): ret = 1. From 1cb62bf02bcb7099ca5efea930df525212b2f671 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Mon, 20 Oct 2014 08:35:17 -0500 Subject: [PATCH 116/192] update --- lfvetau/EleFakeRateAnalyzerMVA.py | 12 +- lfvetau/LFVHETauAnalyzerMVA.py | 384 +++++++++++++++--------------- 2 files changed, 201 insertions(+), 195 deletions(-) diff --git a/lfvetau/EleFakeRateAnalyzerMVA.py b/lfvetau/EleFakeRateAnalyzerMVA.py index d1e41731..bc8955d0 100644 --- a/lfvetau/EleFakeRateAnalyzerMVA.py +++ b/lfvetau/EleFakeRateAnalyzerMVA.py @@ -112,16 +112,16 @@ def begin(self): self.book(f,"e1Pt", "e1 p_{T}", 200, 0, 200) self.book(f,"e1Phi", "e1 phi", 100, -3.2, 3.2) - self.book(f,"e1Eta", "e1 eta", 50, -2.5, 2.5) + self.book(f,"e1Eta", "e1 eta", 46, -2.3, 2.3) self.book(f,"e2Pt", "e2 p_{T}", 200, 0, 200) self.book(f,"e2Phi", "e2 phi", 100, -3.2, 3.2) - self.book(f,"e2Eta", "e2 eta", 50, -2.5, 2.5) + self.book(f,"e2Eta", "e2 eta", 46, -2.3, 2.3) self.book(f,"e3Pt", "e3 p_{T}", 200, 0, 200) self.book(f,"e3Phi", "e3 phi", 100, -3.2, 3.2) - self.book(f,"e3Eta", "e3 eta", 50, -2.5, 2.5) - self.book(f,"e3AbsEta", "e3 abs eta", 25, 0, 2.5) + self.book(f,"e3Eta", "e3 eta", 46, -2.3, 2.3) + self.book(f,"e3AbsEta", "e3 abs eta", 23, 0, 2.3) self.book(f, "e1e2Mass", "e1e2 Inv Mass", 32, 0, 320) @@ -216,14 +216,14 @@ def process(self): cut_flow_trk.Fill('allEvents') if not selections.eSelection(row, 'e1'): continue cut_flow_trk.Fill('e1sel') - if not selections.lepton_id_iso(row, 'e1', 'eid13Loose_etauiso01'): continue + if not selections.lepton_id_iso(row, 'e1', 'eid13Loose_idiso02'): continue if abs(row.e1Eta) > 1.4442 and abs(row.e1Eta < 1.566) : continue cut_flow_trk.Fill('e1IDiso') if not selections.eSelection(row, 'e2'): continue cut_flow_trk.Fill('e2sel') - if not selections.lepton_id_iso(row, 'e2', 'eid13Loose_etauiso01'): continue + if not selections.lepton_id_iso(row, 'e2', 'eid13Loose_idiso02'): continue if abs(row.e2Eta) > 1.4442 and abs(row.e2Eta) < 1.566 : continue cut_flow_trk.Fill('e2IDiso') diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 68b7159d..d5f4c8f7 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -155,8 +155,8 @@ def begin(self): folder.append(d+i+'/'+j+'/'+k +'/'+jn) folder.append(d+i+'/'+j+'/'+k +'/'+jn+'/selected') - self.book('os/gg/ept30/', "h_collmass_pfmet" , "h_collmass_pfmet", 32, 0, 320) - self.book('os/gg/ept30/', "h_vismass", "h_vismass", 32, 0, 320) + self.book(d+'os/gg/ept30/', "h_collmass_pfmet" , "h_collmass_pfmet", 32, 0, 320) + self.book(d+'os/gg/ept30/', "h_vismass", "h_vismass", 32, 0, 320) @@ -281,211 +281,217 @@ def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): if row.run < 2: pudir.extend( ['p1s/', 'm1s/', 'trp1s/', 'trm1s/', 'eidp1s/','eidm1s/', 'eisop1s/','eisom1s/']) looseList = ['tLoose/', 'tLooseUp/', 'tLooseDown/', 'tLooseUnweight/'] - if f=='os/gg/ept30' : - if bool(isTauTight)==True: - histos[f+'/h_collmass_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[0]) - histos[f+'/h_vismass'].Fill(row.e_t_Mass, weight[0]) - else: + + if bool(isTauTight) == False: + if f.startswith('os') or f.startswith('ss') : + frweight_bv = frw[0]/(1.-frw[0]) + err = 0.3/pow(1-frw[0], 2) #tau pog told to mu-tau group to use 30% uncertainty on tau fake rate. + frweight_p1s = frweight_bv*(1+err) + frweight_m1s = frweight_bv*(1-err) + fr_weights = [frweight_bv, frweight_p1s, frweight_m1s] + + for n, l in enumerate(looseList) : + frweight = weight[0]*fr_weights[n] if n < len(looseList)-1 else weight[0] + folder = l+f + + if f=='os/gg/ept30' : + histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*frweight) + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, row.EmbPtWeight*frweight) + continue - if bool(isTauTight) == False: - if f.startswith('os') or f.startswith('ss') : - frweight_bv = frw[0]/(1.-frw[0]) - err = 0.3/pow(1-frw[0], 2) #tau pog told to mu-tau group to use 30% uncertainty on tau fake rate. - frweight_p1s = frweight_bv*(1+err) - frweight_m1s = frweight_bv*(1-err) - fr_weights = [frweight_bv, frweight_p1s, frweight_m1s] - - for n, l in enumerate(looseList) : - frweight = weight[0]*fr_weights[n] if n < len(looseList)-1 else weight[0] - folder = l+f - histos[folder+'/tPt'].Fill(row.tPt, frweight) - histos[folder+'/tEta'].Fill(row.tEta, frweight) - histos[folder+'/tPhi'].Fill(row.tPhi, frweight) - histos[folder+'/ePt'].Fill(row.ePt, frweight) - histos[folder+'/eEta'].Fill(row.eEta, frweight) - histos[folder+'/ePhi'].Fill(row.ePhi, frweight) - histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), frweight) - histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, frweight) - histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - - histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), frweight) - histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - - #histos[folder+'/h_collmass_pfmet_jes'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_mes'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_tes'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_ees'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_ues'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), frweight) - - - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, frweight) - histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, frweight) - histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, frweight) + + histos[folder+'/tPt'].Fill(row.tPt, frweight) + histos[folder+'/tEta'].Fill(row.tEta, frweight) + histos[folder+'/tPhi'].Fill(row.tPhi, frweight) + histos[folder+'/ePt'].Fill(row.ePt, frweight) + histos[folder+'/eEta'].Fill(row.eEta, frweight) + histos[folder+'/ePhi'].Fill(row.ePhi, frweight) + histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), frweight) + histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, frweight) + histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : + histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : + histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : + histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : + histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + + histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), frweight) + histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + + #histos[folder+'/h_collmass_pfmet_jes'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_Phi), frweight) + #histos[folder+'/h_collmass_pfmet_mes'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), frweight) + #histos[folder+'/h_collmass_pfmet_tes'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), frweight) + #histos[folder+'/h_collmass_pfmet_ees'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), frweight) + #histos[folder+'/h_collmass_pfmet_ues'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), frweight) + + + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, frweight) + histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, frweight) + histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, frweight) - histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.pfMetPhi), frweight) - histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), frweight) - histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), frweight) - histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, frweight) - histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, frweight) - histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, frweight) - ##histos[folder+'/ePFMET_Mt_Ty1_ues_minus'].Fill(row.eMtToPfMet_Ty1_ues_minus, frweight) - ##histos[folder+'/ePFMET_Mt_Ty1_ues_plus'].Fill(row.eMtToPfMet_Ty1_ues_plus, frweight) - #histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, frweight) - #histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, frweight) - #histos[folder+'/ePFMET_Mt_jes'].Fill(row.eMtToPfMet_jes, frweight) - #histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus, frweight) - #histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, frweight) - #histos[folder+'/ePFMET_Mt_mes'].Fill(row.eMtToPfMet_mes, frweight) - #histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus, frweight) - #histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, frweight) - #histos[folder+'/ePFMET_Mt_ees'].Fill(row.eMtToPfMet_ees, frweight) - #histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus, frweight) - #histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, frweight) - #histos[folder+'/ePFMET_Mt_tes'].Fill(row.eMtToPfMet_tes, frweight) - #histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus, frweight) - #histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, frweight) - #histos[folder+'/ePFMET_Mt_ues'].Fill(row.eMtToPfMet_ues, frweight) - + histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.pfMetPhi), frweight) + histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), frweight) + histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), frweight) + histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, frweight) + histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, frweight) + histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, frweight) + ##histos[folder+'/ePFMET_Mt_Ty1_ues_minus'].Fill(row.eMtToPfMet_Ty1_ues_minus, frweight) + ##histos[folder+'/ePFMET_Mt_Ty1_ues_plus'].Fill(row.eMtToPfMet_Ty1_ues_plus, frweight) + #histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, frweight) + #histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, frweight) + #histos[folder+'/ePFMET_Mt_jes'].Fill(row.eMtToPfMet_jes, frweight) + #histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus, frweight) + #histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, frweight) + #histos[folder+'/ePFMET_Mt_mes'].Fill(row.eMtToPfMet_mes, frweight) + #histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus, frweight) + #histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, frweight) + #histos[folder+'/ePFMET_Mt_ees'].Fill(row.eMtToPfMet_ees, frweight) + #histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus, frweight) + #histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, frweight) + #histos[folder+'/ePFMET_Mt_tes'].Fill(row.eMtToPfMet_tes, frweight) + #histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus, frweight) + #histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, frweight) + #histos[folder+'/ePFMET_Mt_ues'].Fill(row.eMtToPfMet_ues, frweight) + - histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), frweight) - histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), frweight) - histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), frweight) - histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, frweight) - histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, frweight) - #histos[folder+'/tPFMET_Mt_jes'].Fill(row.tMtToPfMet_jes, frweight) - #histos[folder+'/tPFMET_Mt_mes'].Fill(row.tMtToPfMet_mes, frweight) - #histos[folder+'/tPFMET_Mt_ees'].Fill(row.tMtToPfMet_ees, frweight) - #histos[folder+'/tPFMET_Mt_tes'].Fill(row.tMtToPfMet_tes, frweight) - #histos[folder+'/tPFMET_Mt_ues'].Fill(row.tMtToPfMet_ues, frweight) + histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), frweight) + histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), frweight) + histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), frweight) + histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, frweight) + histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, frweight) + #histos[folder+'/tPFMET_Mt_jes'].Fill(row.tMtToPfMet_jes, frweight) + #histos[folder+'/tPFMET_Mt_mes'].Fill(row.tMtToPfMet_mes, frweight) + #histos[folder+'/tPFMET_Mt_ees'].Fill(row.tMtToPfMet_ees, frweight) + #histos[folder+'/tPFMET_Mt_tes'].Fill(row.tMtToPfMet_tes, frweight) + #histos[folder+'/tPFMET_Mt_ues'].Fill(row.tMtToPfMet_ues, frweight) - histos[folder+'/jetN_20'].Fill(row.jetVeto20, frweight) - histos[folder+'/jetN_30'].Fill(row.jetVeto30, frweight) + histos[folder+'/jetN_20'].Fill(row.jetVeto20, frweight) + histos[folder+'/jetN_30'].Fill(row.jetVeto30, frweight) - else: # if it is TauTight - if not f.startswith('os') and not f.startswith('ss') : # if the dir name start with mVeto, eVeto or tVeto I don't want the different weight of MC corrections - pudir = [''] + else: # if it is TauTight + if not f.startswith('os') and not f.startswith('ss') : # if the dir name start with mVeto, eVeto or tVeto I don't want the different weight of MC corrections + pudir = [''] - for n,d in enumerate(pudir) : - if 'minus' in f or 'plus' in f : - if n >0 : break - - folder = d+f - print folder - - histos[folder+'/tPt'].Fill(row.tPt, weight[n]) - histos[folder+'/tEta'].Fill(row.tEta, weight[n]) - histos[folder+'/tPhi'].Fill(row.tPhi, weight[n]) - histos[folder+'/ePt'].Fill(row.ePt, weight[n]) - histos[folder+'/eEta'].Fill(row.eEta, weight[n]) - histos[folder+'/ePhi'].Fill(row.ePhi, weight[n]) - histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), weight[n]) - histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, weight[n]) + for n,d in enumerate(pudir) : + if 'minus' in f or 'plus' in f : + if n >0 : break - histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - - - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), weight[n]) - histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + folder = d+f + #print folder + if f=='os/gg/ept30' : + histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, row.EmbPtWeight*weight[n]) + continue + + histos[folder+'/tPt'].Fill(row.tPt, weight[n]) + histos[folder+'/tEta'].Fill(row.tEta, weight[n]) + histos[folder+'/tPhi'].Fill(row.tPhi, weight[n]) + histos[folder+'/ePt'].Fill(row.ePt, weight[n]) + histos[folder+'/eEta'].Fill(row.eEta, weight[n]) + histos[folder+'/ePhi'].Fill(row.ePhi, weight[n]) + histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), weight[n]) + histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, weight[n]) + + histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : + histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : + histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : + histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : + histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + + + histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), weight[n]) + histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, weight[n]) + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, weight[n]) + + histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, weight[n]) + histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, weight[n]) + + histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) + histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) + histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), weight[n]) + + histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, weight[n]) + histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, weight[n]) + histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, weight[n]) + + histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), weight[n]) + histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), weight[n]) + histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), weight[n]) + + histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, weight[n]) + histos[folder+'/tPFMET_Mt_Ty1'].Fill(row.tMtToPfMet_Ty1, weight[n]) + histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, weight[n]) - histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, weight[n]) - histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, weight[n]) + histos[folder+'/jetN_20'].Fill(row.jetVeto20, weight[n]) + histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight[n]) - histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) - histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) - histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), weight[n]) + + if n == 0: # if I'm in the dir starting with os or ss I want also the energy scale uncertainties + histos[folder+'/h_collmass_pfmet_jes_plus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_plus_Phi), weight[n]) + histos[folder+'/h_collmass_pfmet_jes_minus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_minus_Phi), weight[n]) + ### add the minus in the ntuple. + #histos[folder+'/h_collmass_pfmet_mes_plus'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), weight[n]) + #histos[folder+'/h_collmass_pfmet_tes_plus'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), weight[n]) + #histos[folder+'/h_collmass_pfmet_ees_plus'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), weight[n]) + #histos[folder+'/h_collmass_pfmet_ues_plus'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), weight[n]) - histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, weight[n]) - histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, weight[n]) - histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, weight[n]) - histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), weight[n]) - histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), weight[n]) - histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), weight[n]) - - histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, weight[n]) - histos[folder+'/tPFMET_Mt_Ty1'].Fill(row.tMtToPfMet_Ty1, weight[n]) - histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, weight[n]) + histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, weight[n]) + histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, weight[n]) - histos[folder+'/jetN_20'].Fill(row.jetVeto20, weight[n]) - histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight[n]) - - - if n == 0: # if I'm in the dir starting with os or ss I want also the energy scale uncertainties - histos[folder+'/h_collmass_pfmet_jes_plus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_plus_Phi), weight[n]) - histos[folder+'/h_collmass_pfmet_jes_minus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_minus_Phi), weight[n]) - ### add the minus in the ntuple. - #histos[folder+'/h_collmass_pfmet_mes_plus'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), weight[n]) - #histos[folder+'/h_collmass_pfmet_tes_plus'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), weight[n]) - #histos[folder+'/h_collmass_pfmet_ees_plus'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), weight[n]) - #histos[folder+'/h_collmass_pfmet_ues_plus'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), weight[n]) - - - histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, weight[n]) - histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, weight[n]) - - histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus,weight[n]) - histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, weight[n]) - - histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus,weight[n]) - histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, weight[n]) - - histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus,weight[n]) - histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, weight[n]) + histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus,weight[n]) + histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, weight[n]) - histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus,weight[n]) - histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, weight[n]) + histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus,weight[n]) + histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, weight[n]) - histos[folder+'/tPFMET_Mt_jes_plus'].Fill(row.tMtToPfMet_jes_plus,weight[n]) - histos[folder+'/tPFMET_Mt_mes_plus'].Fill(row.tMtToPfMet_mes_plus,weight[n]) - histos[folder+'/tPFMET_Mt_ees_plus'].Fill(row.tMtToPfMet_ees_plus,weight[n]) - histos[folder+'/tPFMET_Mt_tes_plus'].Fill(row.tMtToPfMet_tes_plus,weight[n]) - histos[folder+'/tPFMET_Mt_ues_plus'].Fill(row.tMtToPfMet_ues_plus,weight[n]) - histos[folder+'/tPFMET_Mt_jes_minus'].Fill(row.tMtToPfMet_jes_minus,weight[n]) - histos[folder+'/tPFMET_Mt_mes_minus'].Fill(row.tMtToPfMet_mes_minus,weight[n]) - histos[folder+'/tPFMET_Mt_ees_minus'].Fill(row.tMtToPfMet_ees_minus,weight[n]) - histos[folder+'/tPFMET_Mt_tes_minus'].Fill(row.tMtToPfMet_tes_minus,weight[n]) - histos[folder+'/tPFMET_Mt_ues_minus'].Fill(row.tMtToPfMet_ues_minus,weight[n]) + histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus,weight[n]) + histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, weight[n]) + + histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus,weight[n]) + histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, weight[n]) + + histos[folder+'/tPFMET_Mt_jes_plus'].Fill(row.tMtToPfMet_jes_plus,weight[n]) + histos[folder+'/tPFMET_Mt_mes_plus'].Fill(row.tMtToPfMet_mes_plus,weight[n]) + histos[folder+'/tPFMET_Mt_ees_plus'].Fill(row.tMtToPfMet_ees_plus,weight[n]) + histos[folder+'/tPFMET_Mt_tes_plus'].Fill(row.tMtToPfMet_tes_plus,weight[n]) + histos[folder+'/tPFMET_Mt_ues_plus'].Fill(row.tMtToPfMet_ues_plus,weight[n]) + histos[folder+'/tPFMET_Mt_jes_minus'].Fill(row.tMtToPfMet_jes_minus,weight[n]) + histos[folder+'/tPFMET_Mt_mes_minus'].Fill(row.tMtToPfMet_mes_minus,weight[n]) + histos[folder+'/tPFMET_Mt_ees_minus'].Fill(row.tMtToPfMet_ees_minus,weight[n]) + histos[folder+'/tPFMET_Mt_tes_minus'].Fill(row.tMtToPfMet_tes_minus,weight[n]) + histos[folder+'/tPFMET_Mt_ues_minus'].Fill(row.tMtToPfMet_ues_minus,weight[n]) From b17b9e5756860bcd0375a416cfdfebfc87f2b8db Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Mon, 20 Oct 2014 08:36:31 -0500 Subject: [PATCH 117/192] adding fakeratefit --- lfvetau/Rakefile | 78 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index 1f55fc21..6d81bb58 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -74,8 +74,10 @@ def get_plotter_results(analyzer) end -$frfit_dir = "results/#{$jobid}/fakerate_fits_MtCut" +$frfit_dir = "results/#{$jobid}/fakerate_fits" directory $frfit_dir +$efrfit_dir = "results/#{$jobid}/efakerate_fits" +directory $efrfit_dir exponential = "scale*TMath::Exp(x*decay)+offset" exponential_vars = "scale[4., 0, 10],decay[-1e-2, -1, -1e-4],offset[1e-2, 0, 0.5]" exponentialpol1 = "scale*TMath::Exp(x*decay)+offset+slope*x" @@ -102,7 +104,9 @@ erf_vars = "scale[0.1, 0, 10],shift[1., 0.8, 1.2],steep[100.], offset[1e-2, 0, $fr_binning = "30,40,50,60,70,80,100,120,150,200" #$fr_binning = "30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200" $fr_analyzer = "TauFakeRateAnalyzerMVA" #was TauFakeRateAnalyzer +$efr_analyzer = "EleFakeRateAnalyzerMVA" fr_fits = Hash.new +efr_fits = Hash.new # Fake rate fit configurations #mysamples = [ "zjets_skimmedLL", "zjets_skimmedTT"] @@ -134,6 +138,20 @@ fr_fits["t_os_tLoose_tTigh_tPt"] = Hash[ "min"=>"0", "max"=>"1" ] +efr_fits["e_os_eLoose_eTigh_e3Pt"] = Hash[ + "samples" => Array["diboson", "dataSingleE"], + "analyzer" => $efr_analyzer, + #"function" => exponential, + #"variables" => exponential_vars, + "function" => pol0, + "variables"=>pol0_vars, + #"rebin" => 1, + "rebin" => $fr_binning, + "range" => "30 200", + "title" => "e p_{T} (GeV)", + "min"=>"0", + "max"=>"1.2" + ] #fr_fits["t_os_tNoCuts_tTigh_tAbsEta"] = Hash[ # "samples" => Array["diboson", "dataSingleE"], @@ -161,9 +179,24 @@ fr_fits["t_os_tLoose_tTigh_tAbsEta"] = Hash[ ] +efr_fits["e_os_eLoose_eTigh_e3AbsEta"] = Hash[ + "samples" => Array["diboson", "dataSingleE"], + "analyzer" => $efr_analyzer, + "function" => pol2, + "variables" => pol2_vars, + "rebin" => 1, + "range" => "0 2.3", + #"range" => "-2.3 2.3", + "title" => "e #eta", + "min"=>"0", + "max"=>"1.2" + ] + + task :fits => [] +task :efits => [] fr_fits.each do |fit, fit_info| fit_configuration = fit.split("_") @@ -178,8 +211,8 @@ fr_fits.each do |fit, fit_info| end - fit_output = $frfit_dir + "/#{fit}.root" - subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/#{fit_info['analyzer']}_tMtCut/#{x}.root"} + fit_output = $efrfit_dir + "/#{fit}.root" + subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/#{fit_info['analyzer']}/#{x}.root"} # subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/TauFakeRateAnalyzerMVA_eTight/#{x}.root"} subsample_input_list = subsamples_inputs_result_list.join(" ") @@ -210,6 +243,42 @@ fr_fits.each do |fit, fit_info| end #end +efr_fits.each do |fit, fit_info| + fit_configuration = fit.split("_") + sign = fit_configuration[1] + denom = fit_configuration[2] + num = fit_configuration[3] + var = fit_configuration[4] + + subsample_inputs = [] + fit_info['samples'].each do |sample| + subsample_inputs += samples[sample] + end + fit_output = $efrfit_dir + "/#{fit}.root" + subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/#{fit_info['analyzer']}/#{x}.root"} + subsample_input_list = subsamples_inputs_result_list.join(" ") + + # Path to histograms in root files + denom_path = Array[sign, denom,var].join("/") + num_path = Array[sign, num, var].join("/") + + corrected_file = fit_output.sub('.root', '.corrected_inputs.root') + file corrected_file => subsamples_inputs_result_list + [fit_info['analyzer'] + '.py', "CorrectFakeRateData.py"] do |t| + sh "mkdir -p #{$efrfit_dir}" + sh "python CorrectFakeRateData.py --files #{subsample_input_list} --lumifiles inputs/#{$jobid}/*sum --outputfile #{t.name} --numerator '#{num_path}' --denom '#{denom_path}' --rebin #{fit_info['rebin']}" + puts "" + end + + file fit_output => corrected_file do |t| + sh "fit_efficiency_chi2.py #{fit_output} numerator denominator \'#{fit_info['function']}\' \'#{fit_info['variables']}\' #{corrected_file} --plot --xrange #{fit_info['range']} --xtitle \'#{fit_info['title']}\' --min \'#{fit_info['min']}\' --max \'#{fit_info['max']}\' --show-error " + puts "" + end + + + task :efits => fit_output + +end + ################################################################################ @@ -230,7 +299,8 @@ task :genkinEMu => get_analyzer_results("LFVHAnalyzeGENEMu.py", samples['signalM task :recoplots => get_analyzer_results("LFVHETauAnalyzer.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'])# + samples['dataSingleE'] ) -task :recoplotsMVA => get_analyzer_results("LFVHETauAnalyzerMVA.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + samples['Zembedded']+ +task :recoplotsMVA => get_analyzer_results("LFVHETauAnalyzerMVA.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + + samples['Zembedded']+ samples['dataSingleE'] ) task :recoplotsMVAeMtcut => get_analyzer_results("LFVHETauAnalyzerMVA_eMTCut.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + From 2970b7815533ba2a403ce82d7966a25a906e564c Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Tue, 21 Oct 2014 02:56:24 -0500 Subject: [PATCH 118/192] update --- lfvetau/EleFakeRateAnalyzerMVA.py | 2 +- lfvetau/baseSelections.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lfvetau/EleFakeRateAnalyzerMVA.py b/lfvetau/EleFakeRateAnalyzerMVA.py index bc8955d0..f10ec340 100644 --- a/lfvetau/EleFakeRateAnalyzerMVA.py +++ b/lfvetau/EleFakeRateAnalyzerMVA.py @@ -230,7 +230,7 @@ def process(self): if not abs(row.e1_e2_Mass-91.2) < 20: continue cut_flow_trk.Fill('ZMass') - if not selections.lepton_id_iso(row, 'e3', 'eid13Tight_idiso02'): continue + if not selections.lepton_id_iso(row, 'e3', 'eid13Tight_mvaLoose'): continue cut_flow_trk.Fill('tsel') diff --git a/lfvetau/baseSelections.py b/lfvetau/baseSelections.py index 2aa603b4..bb167dab 100755 --- a/lfvetau/baseSelections.py +++ b/lfvetau/baseSelections.py @@ -22,7 +22,7 @@ def muSelection(row, name): def eSelection(row, name): if getattr( row, getVar(name,'Pt')) < 20: return False #was 20 - if getattr( row, getVar(name,'AbsEta')) > 2.1: return False#as in H->tau_etau_h # was 2.3 + if getattr( row, getVar(name,'AbsEta')) > 2.3: return False#as in H->tau_etau_h # was 2.3 if getattr( row, getVar(name,'MissingHits')): return False if getattr( row, getVar(name,'HasConversion')): return False # if not getattr( row, getVar(name,'ChargeIdTight')): return False From 49509f7171d19d3ab6b96aea08a104f0aae535e0 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Thu, 23 Oct 2014 10:53:23 -0500 Subject: [PATCH 119/192] Reshuffle code to make it more compact, add histogram self-filling, make code faster --- lfvetau/LFVHETauAnalyzerMVA.py | 836 +++++++++++++----------------- lfvetau/TauFakeRateAnalyzerMVA.py | 13 +- lfvetau/baseSelections.py | 4 +- lfvetau/fakerate_functions.py | 105 ++-- lfvetau/mcCorrections.py | 207 ++++---- 5 files changed, 484 insertions(+), 681 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index c08e9c22..02473291 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -1,5 +1,9 @@ from ETauTree import ETauTree +import sys +import logging +logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) import os +from pdb import set_trace import ROOT import math import glob @@ -10,10 +14,40 @@ from FinalStateAnalysis.PlotTools.decorators import memo_last from FinalStateAnalysis.PlotTools.MegaBase import MegaBase from math import sqrt, pi, cos -from fakerate_functions import fakerate_central_histogram, fakerate_p1s_histogram, fakerate_m1s_histogram - - - +from fakerate_functions import tau_fake_rate, tau_fake_rate_up, tau_fake_rate_dw +import itertools +import traceback +from FinalStateAnalysis.PlotTools.decorators import memo + +@memo +def getVar(name, var): + return name+var + +met_et = 'pfMet%sEt' +met_phi = 'pfMet%sPhi' + +@memo +def met(shift=''): + return met_et % shift + +@memo +def metphi(shift=''): + return met_phi % shift + +def attr_getter(attribute): + '''return a function that gets an attribute''' + def f(row, weight): + return (getattr(row,attribute), weight) + return f + +def merge_functions(fcn_1, fcn_2): + '''merges two functions to become a TH2''' + def f(row, weight): + r1, w1 = fcn_1(row, weight) + r2, w2 = fcn_2(row, weight) + w = w1 if w1 and w2 else None + return ((r1, r2), w) + return f def collmass(row, met, metPhi): ptnu =abs(met*cos(deltaPhi(metPhi, row.tPhi))) @@ -27,24 +61,81 @@ def deltaPhi(phi1, phi2): return PHI else: return 2*pi-PHI + def deltaR(phi1, ph2, eta1, eta2): deta = eta1 - eta2 dphi = abs(phi1-phi2) if (dphi>pi) : dphi = 2*pi-dphi return sqrt(deta*deta + dphi*dphi); +def make_collmass_systematics(shift): + met_name = met(shift) + phi_name = metphi(shift) + def collmass_shifted(row, weight): + met = getattr(row, met_name) + phi = getattr(row, phi_name) + return collmass(row, met, phi), weight + return collmass_shifted + class LFVHETauAnalyzerMVA(MegaBase): tree = 'et/final/Ntuple' def __init__(self, tree, outfile, **kwargs): + logging.debug('LFVHETauAnalyzerMVA constructor') self.channel='ET' super(LFVHETauAnalyzerMVA, self).__init__(tree, outfile, **kwargs) self.tree = ETauTree(tree) self.out=outfile self.histograms = {} - self.pucorrector = mcCorrections.make_puCorrector('singlee') - self.pucorrectorUp = mcCorrections.make_puCorrectorUp('singlee') - self.pucorrectorDown = mcCorrections.make_puCorrectorDown('singlee') - + + #undertand what we are running + target = os.path.basename(os.environ['megatarget']) + self.is_data = target.startswith('data_') + self.is_embedded = ('Embedded' in target) + self.is_mc = not (self.is_data or self.is_embedded) + + #systematics used + self.systematics = { + 'trig' : (['', 'trp1s', 'trm1s'] if not self.is_data else []), + 'pu' : (['', 'p1s', 'm1s'] if self.is_mc else []), + 'eid' : (['', 'eidp1s','eidm1s'] if not self.is_data else []), + 'eiso' : (['', 'eisop1s','eisom1s'] if not self.is_data else []), + 'jes' : (['', '_jes_plus','_jes_minus'] if self.is_mc else ['']), + 'mvetos': (['', 'mVetoUp', 'mVetoDown'] if self.is_mc else ['']), + 'tvetos': (['', 'tVetoUp', 'tVetoDown'] if self.is_mc else ['']), + 'evetos': (['', 'eVetoUp', 'eVetoDown'] if self.is_mc else ['']), + 'met' : ([ "_jes_plus_", "_mes_plus_", "_tes_plus_", "_ees_plus_", "_ues_plus_", "_jes_minus_", "_mes_minus_", "_tes_minus_", "_ees_minus_", "_ues_minus_"] if self.is_mc else []), + } + + #self filling histograms + coll_mass = make_collmass_systematics('') #no sys shift + self.histo_locations = {} #just a mapping of the histograms we have to avoid changing self.histograms indexing an screw other files + self.hfunc = { #maps the name of non-trivial histograms to a function to get the proper value, the function MUST have two args (evt and weight). Used in fill_histos later + 'nTruePU' : lambda row, weight: (row.nTruePU,None), + 'weight' : lambda row, weight: (weight,None) if weight is not None else (1.,None), + 'Event_ID': lambda row, weight: (array.array("f", [row.run,row.lumi,int(row.evt)/10**5,int(row.evt)%10**5] ), None), + 'h_collmass_pfmet' : coll_mass, + 'h_collmass_vs_dPhi_pfmet' : merge_functions( + attr_getter('tToMETDPhi'), + coll_mass + ), + 'MetEt_vs_dPhi' : merge_functions( + lambda row, weight: (deltaPhi(row.tPhi, getattr(row, metphi())), weight), + attr_getter('type1_pfMetEt') + ), + 'ePFMET_DeltaPhi' : lambda row, weight: (deltaPhi(row.ePhi, getattr(row, metphi())), weight), + 'tPFMET_DeltaPhi' : lambda row, weight: (deltaPhi(row.tPhi, getattr(row, metphi())), weight), + } + for shift in self.systematics['met']: + #patch name + postfix = shift[:-1] + self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + + #PU correctors + self.pucorrector = mcCorrections.make_shifted_weights( + mcCorrections.make_puCorrector('singlee'), + ['p1s', 'm1s'], + [mcCorrections.make_puCorrectorUp('singlee'), mcCorrections.make_puCorrectorDown('singlee')] + ) @staticmethod def tau_veto(row): @@ -59,77 +150,55 @@ def obj3_matches_gen(row): return t.genDecayMode != -2 - def event_weight(self, row): + def event_weight(self, row, sys_shifts): if row.run > 2: #FIXME! add tight ID correction - return [1.] - allmcCorrections= mcCorrections.get_electronId_corrections13_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e') * mcCorrections.get_trigger_corrections_MVA(row,'e') + return {'' : 1.} + + weights = {} + for shift in sys_shifts: + weights[shift] = mcCorrections.eid_correction( row, 'e', shift=shift) * \ + mcCorrections.eiso_correction(row, 'e', shift=shift) * \ + mcCorrections.trig_correction(row, 'e', shift=shift) * \ + self.pucorrector(row.nTruePU, shift=shift) - - trUp_mcCorrections = mcCorrections.get_electronId_corrections13_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e') * mcCorrections.get_trigger_corrections_p1s_MVA(row,'e') - trDown_mcCorrections = mcCorrections.get_electronId_corrections13_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e') * mcCorrections.get_trigger_corrections_m1s_MVA(row,'e') - - eidUp_mcCorrections= mcCorrections.get_electronId_corrections13_p1s_MVA(row, 'e') *\ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e') * mcCorrections.get_trigger_corrections_MVA(row,'e') - eidDown_mcCorrections= mcCorrections.get_electronId_corrections13_m1s_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e') * mcCorrections.get_trigger_corrections_MVA(row,'e') - eisoUp_mcCorrections= mcCorrections.get_electronId_corrections13_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_p1s_MVA(row, 'e') * mcCorrections.get_trigger_corrections_MVA(row,'e') - eisoDown_mcCorrections= mcCorrections.get_electronId_corrections13_m1s_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_p1s_MVA(row, 'e') * mcCorrections.get_trigger_corrections_MVA(row,'e') - - #pucorrlist = self.pucorrector(row.nTruePU) - - weight = self.pucorrector(row.nTruePU) *\ - allmcCorrections - weight_up = self.pucorrectorUp(row.nTruePU) *\ - allmcCorrections - weight_down = self.pucorrectorDown(row.nTruePU) *\ - allmcCorrections - - weight_tr_up = self.pucorrector(row.nTruePU) *\ - trUp_mcCorrections - weight_tr_down = self.pucorrector(row.nTruePU) *\ - trDown_mcCorrections - - - weight_eid_up = self.pucorrector(row.nTruePU) *\ - eidUp_mcCorrections - weight_eid_down = self.pucorrector(row.nTruePU) *\ - eidDown_mcCorrections - weight_eiso_up = self.pucorrector(row.nTruePU) *\ - eisoUp_mcCorrections - weight_eiso_down = self.pucorrector(row.nTruePU) *\ - eisoDown_mcCorrections - - return [weight, weight_up, weight_down, weight_tr_up, weight_tr_down, weight_eid_up, weight_eid_down, weight_eiso_up, weight_eiso_down,] + return weights ## def begin(self): - + logging.debug('Booking histograms directory tree') + sys_shifts = self.systematics['trig'] + \ + self.systematics['pu'] + \ + self.systematics['eid'] + \ + self.systematics['eiso'] + \ + self.systematics['mvetos'] + \ + self.systematics['tvetos'] + \ + self.systematics['evetos'] + \ + ['tLoose', 'tLooseUp', 'tLooseDown', 'tLooseUnweight'] + sys_shifts = list( set( sys_shifts ) ) #remove double dirs processtype=['gg'] threshold=['ept30'] - sign=['os', 'ss'] - jetN = ['0','0_jes_plus','0_jes_minus', '1','1_jes_plus','1_jes_minus', '2','2_jes_plus','2_jes_minus', '3','3_jes_plus','3_jes_minus'] - folder=[] - pudir = ['','p1s/', 'm1s/','trp1s/', 'trm1s/', 'eidp1s/','eidm1s/', 'eisop1s/','eisom1s/', 'mVetoUp/', 'mVetoDown/', 'eVetoUp/', 'eVetoDown/', 'tVetoUp/', 'tVetoDown/', 'tLoose/','tLooseUp/','tLooseDown/', 'tLooseUnweight/'] - - for d in pudir : - for i in sign: - for j in processtype: - for k in threshold: - #folder.append(d+i+'/'+j+'/'+k) - for jn in jetN: + signs =['os', 'ss'] + jetN = [''.join(i) for i in itertools.product(['0', '1', '2', '3'], self.systematics['jes'])] - folder.append(d+i+'/'+j+'/'+k +'/'+jn) - folder.append(d+i+'/'+j+'/'+k +'/'+jn+'/selected') + folder=[] - self.book('os/gg/ept30/', "h_collmass_pfmet" , "h_collmass_pfmet", 32, 0, 320) - self.book('os/gg/ept30/', "h_vismass", "h_vismass", 32, 0, 320) + for tuple_path in itertools.product(sys_shifts, signs, processtype, threshold, jetN): + folder.append(os.path.join(*tuple_path)) + path = list(tuple_path) + path.append('selected') + folder.append(os.path.join(*path)) + def book_with_sys(location, name, *args, **kwargs): + postfixes = kwargs['postfixes'] + del kwargs['postfixes'] + self.book(location, name, *args, **kwargs) + for postfix in postfixes: + #patch name to be removed + fix = postfix[:-1] + self.book(location, name+fix, *args, **kwargs) + self.book('os/gg/ept30/', "h_collmass_pfmet" , "h_collmass_pfmet", 32, 0, 320) + self.book('os/gg/ept30/', "e_t_Mass", "h_vismass", 32, 0, 320) for f in folder: self.book(f,"tPt", "tau p_{T}", 200, 0, 200) @@ -140,458 +209,245 @@ def begin(self): self.book(f,"ePhi", "e phi", 100, -3.2, 3.2) self.book(f,"eEta", "e eta", 50, -2.5, 2.5) - self.book(f, "et_DeltaPhi", "e-tau DeltaPhi" , 50, 0, 3.2) - self.book(f, "et_DeltaR", "e-tau DeltaR" , 50, 0, 3.2) + self.book(f, "e_t_DPhi", "e-tau DeltaPhi" , 50, 0, 3.2) + self.book(f, "e_t_DR", "e-tau DeltaR" , 50, 0, 3.2) - self.book(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320) - self.book(f, "h_collmass_mvamet", "h_collmass_mvamet", 32, 0, 320) - self.book(f, "h_collmass_pfmet_Ty1", "h_collmass_pfmet_Ty1", 32, 0, 320) - - self.book(f, "h_collmass_pfmet_jes_plus", "h_collmass_pfmet_jes_plus", 50, 0, 100) - self.book(f, "h_collmass_pfmet_mes_plus", "h_collmass_pfmet_mes_plus", 50, 0, 100 ) - self.book(f, "h_collmass_pfmet_tes_plus", "h_collmass_pfmet_tes_plus", 50, 0, 100) - self.book(f, "h_collmass_pfmet_ees_plus", "h_collmass_pfmet_ees_plus", 50, 0, 100) - self.book(f, "h_collmass_pfmet_ues_plus", "h_collmass_pfmet_ues_plus", 50, 0, 100) - - self.book(f, "h_collmass_pfmet_jes_minus", "h_collmass_pfmet_jes_minus", 50, 0, 100) - self.book(f, "h_collmass_pfmet_mes_minus", "h_collmass_pfmet_mes_minus", 50, 0, 100 ) - self.book(f, "h_collmass_pfmet_tes_minus", "h_collmass_pfmet_tes_minus", 50, 0, 100) - self.book(f, "h_collmass_pfmet_ees_minus", "h_collmass_pfmet_ees_minus", 50, 0, 100) - self.book(f, "h_collmass_pfmet_ues_minus", "h_collmass_pfmet_ues_minus", 50, 0, 100) - - self.book(f, "h_collmassSpread_pfmet", "h_collmassSpread_pfmet", 40, -100, 100) - self.book(f, "h_collmassSpread_mvamet", "h_collmassSpread_mvamet", 40, -100, 100) - self.book(f, "h_collmassSpread_lowPhi_pfmet", "h_collmassSpread_lowPhi_pfmet", 40, -100, 100) - self.book(f, "h_collmassSpread_lowPhi_mvamet", "h_collmassSpread_lowPhi_mvamet", 40, -100, 100) - self.book(f, "h_collmassSpread_highPhi_pfmet", "h_collmassSpread_highPhi_pfmet", 40, -100, 100) - self.book(f, "h_collmassSpread_highPhi_mvamet", "h_collmassSpread_highPhi_mvamet", 40, -100, 100) - self.book(f, "h_collmass_lowPhi_pfmet", "h_collmass_lowPhi_pfmet", 32, 0, 320) - self.book(f, "h_collmass_lowPhi_mvamet", "h_collmass_lowPhi_mvamet", 32, 0, 320) - self.book(f, "h_collmass_highPhi_pfmet", "h_collmass_highPhi_pfmet", 32, 0, 320) - self.book(f, "h_collmass_highPhi_mvamet", "h_collmass_highPhi_mvamet", 32, 0, 320) + book_with_sys(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320, + postfixes=self.systematics['met']) + self.book(f, "h_collmass_vs_dPhi_pfmet", "h_collmass_vs_dPhi_pfmet", 50, 0, 3.2, 32, 0, 320, type=ROOT.TH2F) - self.book(f, "h_collmass_vs_dPhi_mvamet", "h_collmass_vs_dPhi_mvamet", 50, 0, 3.2, 32, 0, 320, type=ROOT.TH2F) - self.book(f, "h_collmassSpread_vs_dPhi_pfmet", "h_collmassSpread_vs_dPhi_pfmet", 50, 0, 3.2, 20, -100, 100, type=ROOT.TH2F) - self.book(f, "h_collmassSpread_vs_dPhi_mvamet", "h_collmassSpread_vs_dPhi_mvamet", 50, 0, 3.2, 20, -100, 100, type=ROOT.TH2F) - - self.book(f, "h_vismass", "h_vismass", 32, 0, 320) - self.book(f, "type1_pfMetEt_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 50, 0, 3.2, 64, 0, 320, type=ROOT.TH2F) - self.book(f, "mvaMetEt_vs_dPhi", "MVAMet vs #Delta#phi(#tau,MVAMet)", 50, 0, 3.2, 64, 0, 320, type=ROOT.TH2F) - - self.book(f, "tPFMET_DeltaPhi", "tau-PFMET DeltaPhi" , 50, 0, 3.2) - self.book(f, "tPFMET_Mt", "tau-PFMET M_{T}" , 200, 0, 200) - self.book(f, "tPFMET_DeltaPhi_Ty1", "tau-type1PFMET DeltaPhi" , 50, 0, 3.2) - self.book(f, "tPFMET_Mt_Ty1", "tau-type1PFMET M_{T}" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_jes_plus', "tau-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_mes_plus', "tau-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_ees_plus', "tau-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_tes_plus', "tau-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_ues_plus', "tau-MVAMET M_{T} JES_plus" , 200, 0, 200) - - self.book(f, 'tPFMET_Mt_jes_minus', "tau-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_mes_minus', "tau-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_ees_minus', "tau-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_tes_minus', "tau-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_ues_minus', "tau-MVAMET M_{T} JES_minus" , 200, 0, 200) + self.book(f, "e_t_Mass", "h_vismass", 32, 0, 320) - self.book(f, "tMVAMET_DeltaPhi", "tau-MVAMET DeltaPhi" , 50, 0, 3.2) - self.book(f, "tMVAMET_Mt", "tau-MVAMET M_{T}" , 200, 0, 200) - - self.book(f, "ePFMET_DeltaPhi_Ty1", "e-type1PFMET DeltaPhi" , 50, 0, 3.2) - self.book(f, "ePFMET_Mt_Ty1", "e-type1PFMET M_{T}" , 200, 0, 200) - self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 50, 0, 3.2) - self.book(f, "ePFMET_Mt", "e-PFMET M_{T}" , 200, 0, 200) - #self.book(f, 'ePFMET_Mt_jes', "e-MVAMET M_{T} JES" , 200, 0, 200) - #self.book(f, 'ePFMET_Mt_mes', "e-MVAMET M_{T} JES" , 200, 0, 200) - #self.book(f, 'ePFMET_Mt_ees', "e-MVAMET M_{T} JES" , 200, 0, 200) - #self.book(f, 'ePFMET_Mt_tes', "e-MVAMET M_{T} JES" , 200, 0, 200) - #self.book(f, 'ePFMET_Mt_ues', "e-MVAMET M_{T} JES" , 200, 0, 200) - #self.book(f, "ePFMET_Mt_Ty1_ues_minus", "e-type1PFMET M_{T} ues_minus" , 200, 0, 200) - #self.book(f, "ePFMET_Mt_Ty1_ues_plus", "e-type1PFMET M_{T} ues_plus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_jes_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_mes_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_ees_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_tes_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_ues_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_jes_plus', "e-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_mes_plus', "e-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_ees_plus', "e-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_tes_plus', "e-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_ues_plus', "e-MVAMET M_{T} JES_plus" , 200, 0, 200) - - self.book(f, "eMVAMET_DeltaPhi", "e-MVAMET DeltaPhi" , 50, 0, 3.2) - self.book(f, "eMVAMET_Mt", "e-MVAMET M_{T}" , 200, 0, 200) + self.book(f, "MetEt_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 50, 0, 3.2, 64, 0, 320, type=ROOT.TH2F) + + self.book(f, "tPFMET_DeltaPhi", "tau-type1PFMET DeltaPhi" , 50, 0, 3.2) - self.book(f, "jetN_20", "Number of jets, p_{T}>20", 10, -0.5, 9.5) - self.book(f, "jetN_30", "Number of jets, p_{T}>30", 10, -0.5, 9.5) - - def fakerate_weights(self, tEta, central_weights, p1s_weights, m1s_weights): - frweight=[1.,1.,1.] - - #central_weights = fakerate_central_histogram(25,0, 2.5) - #p1s_weights = fakerate_central_histogram(25,0, 2.5) - #m1s_weights = fakerate_central_histogram(25,0, 2.5) - - for n,w in enumerate( central_weights ): - if abs(tEta) < w[1]: - break - frweight[0] = w[0] - frweight[1] = p1s_weights[n][0] - frweight[2] = m1s_weights[n][0] - + #self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 50, 0, 3.2) + ## book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 200, 0, 200, + ## postfixes=self.systematics['met']) + ## book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 200, 0, 200, + ## postfixes=self.systematics['met']) + + self.book(f, "jetVeto20", "Number of jets, p_{T}>20", 10, -0.5, 9.5) + self.book(f, "jetVeto30", "Number of jets, p_{T}>30", 10, -0.5, 9.5) - return frweight; - - - - def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): - weight = self.event_weight(row) - histos = self.histograms - pudir =[''] - if row.run < 2: pudir.extend( ['p1s/', 'm1s/', 'trp1s/', 'trm1s/', 'eidp1s/','eidm1s/', 'eisop1s/','eisom1s/']) - looseList = ['tLoose/', 'tLooseUp/', 'tLooseDown/', 'tLooseUnweight/'] + #index dirs and histograms + for key in self.histograms: + location = os.path.dirname(key) + name = os.path.basename(key) + if location in self.histo_locations: + self.histo_locations[location].append(name) + else: + self.histo_locations[location] = [name] + + def fakerate_weights(self, tEta): + tLoose = tau_fake_rate(tEta) + tLooseUp = tau_fake_rate_up(tEta) + tLooseDown= tau_fake_rate_dw(tEta) - if f=='os/gg/ept30' : - if bool(isTauTight)==True: - histos[f+'/h_collmass_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[0]) - histos[f+'/h_vismass'].Fill(row.e_t_Mass, weight[0]) - else: - - if bool(isTauTight) == False: - if f.startswith('os') or f.startswith('ss') : - frweight_bv = frw[0]/(1.-frw[0]) - err = 0.3/pow(1-frw[0], 2) #tau pog told to mu-tau group to use 30% uncertainty on tau fake rate. - frweight_p1s = frweight_bv*(1+err) - frweight_m1s = frweight_bv*(1-err) - fr_weights = [frweight_bv, frweight_p1s, frweight_m1s] - - for n, l in enumerate(looseList) : - frweight = weight[0]*fr_weights[n] if n < len(looseList)-1 else weight[0] - folder = l+f - histos[folder+'/tPt'].Fill(row.tPt, frweight) - histos[folder+'/tEta'].Fill(row.tEta, frweight) - histos[folder+'/tPhi'].Fill(row.tPhi, frweight) - histos[folder+'/ePt'].Fill(row.ePt, frweight) - histos[folder+'/eEta'].Fill(row.eEta, frweight) - histos[folder+'/ePhi'].Fill(row.ePhi, frweight) - histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), frweight) - histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, frweight) - histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - - histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), frweight) - histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - - #histos[folder+'/h_collmass_pfmet_jes'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_mes'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_tes'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_ees'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_ues'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), frweight) - - - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, frweight) - histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, frweight) - histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, frweight) - - histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.pfMetPhi), frweight) - histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), frweight) - histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), frweight) - histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, frweight) - histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, frweight) - histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, frweight) - ##histos[folder+'/ePFMET_Mt_Ty1_ues_minus'].Fill(row.eMtToPfMet_Ty1_ues_minus, frweight) - ##histos[folder+'/ePFMET_Mt_Ty1_ues_plus'].Fill(row.eMtToPfMet_Ty1_ues_plus, frweight) - #histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, frweight) - #histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, frweight) - #histos[folder+'/ePFMET_Mt_jes'].Fill(row.eMtToPfMet_jes, frweight) - #histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus, frweight) - #histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, frweight) - #histos[folder+'/ePFMET_Mt_mes'].Fill(row.eMtToPfMet_mes, frweight) - #histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus, frweight) - #histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, frweight) - #histos[folder+'/ePFMET_Mt_ees'].Fill(row.eMtToPfMet_ees, frweight) - #histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus, frweight) - #histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, frweight) - #histos[folder+'/ePFMET_Mt_tes'].Fill(row.eMtToPfMet_tes, frweight) - #histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus, frweight) - #histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, frweight) - #histos[folder+'/ePFMET_Mt_ues'].Fill(row.eMtToPfMet_ues, frweight) + tLoose = tLoose / (1. - tLoose ) + tLooseUp = tLooseUp / (1. - tLooseUp ) + tLooseDown= tLooseDown / (1. - tLooseDown) + frweight = { + 'tLoose' : tLoose , + 'tLooseUp' : tLooseUp , + 'tLooseDown' : tLooseDown, + 'tLooseUnweight' : 1., + } - - histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), frweight) - histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), frweight) - histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), frweight) - histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, frweight) - histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, frweight) - #histos[folder+'/tPFMET_Mt_jes'].Fill(row.tMtToPfMet_jes, frweight) - #histos[folder+'/tPFMET_Mt_mes'].Fill(row.tMtToPfMet_mes, frweight) - #histos[folder+'/tPFMET_Mt_ees'].Fill(row.tMtToPfMet_ees, frweight) - #histos[folder+'/tPFMET_Mt_tes'].Fill(row.tMtToPfMet_tes, frweight) - #histos[folder+'/tPFMET_Mt_ues'].Fill(row.tMtToPfMet_ues, frweight) - - histos[folder+'/jetN_20'].Fill(row.jetVeto20, frweight) - histos[folder+'/jetN_30'].Fill(row.jetVeto30, frweight) - - else: # if it is TauTight - if not f.startswith('os') and not f.startswith('ss') : # if the dir name start with mVeto, eVeto or tVeto I don't want the different weight of MC corrections - pudir = [''] - - for n,d in enumerate(pudir) : - if 'minus' in f or 'plus' in f : - if n >0 : break - - folder = d+f - print folder - - histos[folder+'/tPt'].Fill(row.tPt, weight[n]) - histos[folder+'/tEta'].Fill(row.tEta, weight[n]) - histos[folder+'/tPhi'].Fill(row.tPhi, weight[n]) - histos[folder+'/ePt'].Fill(row.ePt, weight[n]) - histos[folder+'/eEta'].Fill(row.eEta, weight[n]) - histos[folder+'/ePhi'].Fill(row.ePhi, weight[n]) - histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), weight[n]) - histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, weight[n]) - - histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - - - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), weight[n]) - histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - - - - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, weight[n]) - - histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, weight[n]) - histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, weight[n]) - - histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) - histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) - histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), weight[n]) - - histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, weight[n]) - histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, weight[n]) - histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, weight[n]) - - histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), weight[n]) - histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), weight[n]) - histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), weight[n]) - - histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, weight[n]) - histos[folder+'/tPFMET_Mt_Ty1'].Fill(row.tMtToPfMet_Ty1, weight[n]) - histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, weight[n]) - - histos[folder+'/jetN_20'].Fill(row.jetVeto20, weight[n]) - histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight[n]) - - - if n == 0: # if I'm in the dir starting with os or ss I want also the energy scale uncertainties - histos[folder+'/h_collmass_pfmet_jes_plus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_plus_Phi), weight[n]) - histos[folder+'/h_collmass_pfmet_jes_minus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_minus_Phi), weight[n]) - ### add the minus in the ntuple. - #histos[folder+'/h_collmass_pfmet_mes_plus'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), weight[n]) - #histos[folder+'/h_collmass_pfmet_tes_plus'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), weight[n]) - #histos[folder+'/h_collmass_pfmet_ees_plus'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), weight[n]) - #histos[folder+'/h_collmass_pfmet_ues_plus'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), weight[n]) - - - histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, weight[n]) - histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, weight[n]) - - histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus,weight[n]) - histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, weight[n]) - - histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus,weight[n]) - histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, weight[n]) - - histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus,weight[n]) - histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, weight[n]) - - histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus,weight[n]) - histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, weight[n]) - - histos[folder+'/tPFMET_Mt_jes_plus'].Fill(row.tMtToPfMet_jes_plus,weight[n]) - histos[folder+'/tPFMET_Mt_mes_plus'].Fill(row.tMtToPfMet_mes_plus,weight[n]) - histos[folder+'/tPFMET_Mt_ees_plus'].Fill(row.tMtToPfMet_ees_plus,weight[n]) - histos[folder+'/tPFMET_Mt_tes_plus'].Fill(row.tMtToPfMet_tes_plus,weight[n]) - histos[folder+'/tPFMET_Mt_ues_plus'].Fill(row.tMtToPfMet_ues_plus,weight[n]) - histos[folder+'/tPFMET_Mt_jes_minus'].Fill(row.tMtToPfMet_jes_minus,weight[n]) - histos[folder+'/tPFMET_Mt_mes_minus'].Fill(row.tMtToPfMet_mes_minus,weight[n]) - histos[folder+'/tPFMET_Mt_ees_minus'].Fill(row.tMtToPfMet_ees_minus,weight[n]) - histos[folder+'/tPFMET_Mt_tes_minus'].Fill(row.tMtToPfMet_tes_minus,weight[n]) - histos[folder+'/tPFMET_Mt_ues_minus'].Fill(row.tMtToPfMet_ues_minus,weight[n]) - - - - - + return frweight; + def fill_histos(self, folder_str, row, weight, filter_label = ''): + '''fills histograms''' + #find all keys matching + for attr in self.histo_locations[folder_str]: + name = attr + #if attr=='DEBUG': + # set_trace() + if filter_label: + if not attr.startswith(filter_label+'$'): + continue + attr = attr.replace(filter_label+'$', '') + path = os.path.join(folder_str,name) + value = self.histograms[path] + if value.InheritsFrom('TH2'): + if attr in self.hfunc: + try: + result, out_weight = self.hfunc[attr](row, weight) + except Exception as e: + raise RuntimeError("Error running function %s. Error: \n\n %s" % (attr, str(e))) + r1, r2 = result + if out_weight is None: + value.Fill( r1, r2 ) #saves you when filling NTuples! + else: + value.Fill( r1, r2, out_weight ) + else: + attr1, attr2 = tuple(attr.split('#')) + v1 = getattr(row,attr1) + v2 = getattr(row,attr2) + value.Fill( v1, v2, weight ) if weight is not None else value.Fill( v1, v2 ) + else: + if attr in self.hfunc: + try: + result, out_weight = self.hfunc[attr](row, weight) + except Exception as e: + raise RuntimeError("Error running function %s. Error: \n\n %s" % (attr, str(e))) + if out_weight is None: + value.Fill( result ) #saves you when filling NTuples! + else: + value.Fill( result, out_weight ) + else: + value.Fill( getattr(row,attr), weight ) if weight is not None else value.Fill( getattr(row,attr) ) + return None + def process(self): - - - central_weights = fakerate_central_histogram(25,0, 2.5) - - p1s_weights = fakerate_p1s_histogram(25,0, 2.5)#fakerate_p1s_histogram(25,0, 2.5) - - m1s_weights = fakerate_m1s_histogram(25,0, 2.5)#fakerate_m1s_histogram(25,0, 2.5) - - + logging.debug('Starting processing') + systematics = self.systematics frw = [] - myevent =() + lock =() + ievt = 0 + logging.debug('Starting evt loop') for row in self.tree: - #for n, row in enumerate(self.tree): + if (ievt % 100) == 0: + logging.debug('New event') + ievt += 1 + #avoid double counting events! + evt_id = (row.run, row.lumi, row.evt) + if evt_id == lock: continue + if lock != () and evt_id == lock: + logging.info('Removing duplicate of event: %d %d %d' % evt_id) + + # + #preselection, common to everything and everyone + # - sign = 'ss' if row.e_t_SS else 'os' - processtype = '' ## use a line as for sign when the vbf when selections are defined - ptthreshold = [30] - processtype ='gg'##changed from 20 - jn = row.jetVeto30 - if jn > 3 : jn = 3 - jn_jes_plus = row.jetVeto30jes_plus - jn_jes_minus = row.jetVeto30jes_minus - - if jn_jes_plus >3 : jn_jes_plus=3 - if jn_jes_minus >3 : jn_jes_minus=3 - - #if row.run > 2 : #apply the trigger to data only (MC triggers enter in the scale factors) + #trigger if not bool(row.singleE27WP80Pass) : continue + if not bool(row.eMatchesSingleE27WP80): continue - if not bool(row.eMatchesSingleE27WP80): continue - + #objects if not selections.eSelection(row, 'e'): continue - - if not selections.lepton_id_iso(row, 'e', 'eid13Tight_etauiso01'): continue - - if abs(row.eEta) > 1.4442 and abs(row.eEta) < 1.566 : continue - if not selections.tauSelection(row, 't'): continue - - if row.bjetCSVVeto30!=0 : continue if row.ePt < 30 : continue - #if row.eMtToPFMET <40 : continue - + if not selections.tauSelection(row, 't'): continue if not row.tAntiElectronMVA5Tight : continue if not row.tAntiMuon2Loose : continue if not row.tLooseIso3Hits : continue - - #isTauTight = False - frw=self.fakerate_weights(row.tEta, central_weights, p1s_weights, m1s_weights ) - - #print bool(row.tTightIso3Hits) + #bjet veto + if row.bjetCSVVeto30!=0 : continue - #if row.tauVetoPt20EleTight3MuLoose : continue - #if row.muVetoPt5IsoIdVtx : continue - #if row.eVetoCicLooseIso : continue # change it with Loose + #e ID/ISO + if not selections.lepton_id_iso(row, 'e', 'eid13Tight_etauiso01'): continue + logging.debug('Passed preselection') - if row.tauVetoPt20EleTight3MuLoose and row.tauVetoPt20EleTight3MuLoose_tes_minus and row.tauVetoPt20EleTight3MuLoose_tes_plus: continue - if row.muVetoPt5IsoIdVtx and row.muVetoPt5IsoIdVtx_mes_minus and row.muVetoPt5IsoIdVtx_mes_plus : continue - if row.eVetoCicLooseIso and row.eVetoCicLooseIso_ees_minus and row.eVetoCicLooseIso_ees_plus : continue - - standardSelection=True - tesminus =True - tesplus =True - mesminus =True - mesplus =True - eesminus =True - eesplus =True - - if row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx or row.eVetoCicLooseIso : standardSelection = False - - if row.tauVetoPt20EleTight3MuLoose_tes_minus or row.muVetoPt5IsoIdVtx or row.eVetoCicLooseIso : tesminus = False - if row.tauVetoPt20EleTight3MuLoose_tes_plus or row.muVetoPt5IsoIdVtx or row.eVetoCicLooseIso : tesplus = False - if row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx_mes_minus or row.eVetoCicLooseIso : mesminus = False - if row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx_mes_plus or row.eVetoCicLooseIso : mesplus = False - if row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx or row.eVetoCicLooseIso_ees_minus : eesminus = False - if row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx or row.eVetoCicLooseIso_ees_plus : eesplus = False - - dirpaths = [(standardSelection, sign+'/'+processtype), (mesplus, 'mVetoUp/'+sign+'/'+processtype), (mesminus, 'mVetoDown/'+sign+'/'+processtype), \ - (eesplus, 'eVetoUp/'+sign+'/'+processtype), (eesminus, 'eVetoDown/'+sign+'/'+processtype), \ - (tesplus, 'tVetoUp/'+sign+'/'+processtype), (tesminus, 'tVetoDown/'+sign+'/'+processtype)] + #tau ID, id Tau is tight then go in full selection, otherwise use for fakes + tau_id_category = [''] if row.tTightIso3Hits else ['tLoose', 'tLooseUp', 'tLooseDown', 'tLooseUnweight'] + isTauTight = bool(row.tTightIso3Hits) - - - if (row.run, row.lumi, row.evt)==myevent: continue - if myevent!=() and (row.run, row.lumi, row.evt)==(myevent[0], myevent[1], myevent[2]): print row.ePt, row.tPt - - myevent=(row.run, row.lumi, row.evt) + #jet category + jn = min(row.jetVeto30, 3) + jn_jes_plus = min(row.jetVeto30jes_plus, 3) + jn_jes_minus = min(row.jetVeto30jes_minus, 3) + jet_category = ['%i' % jn, '%i_jes_plus' % jn_jes_plus, '%i_jes_minus' % jn_jes_minus] + jet_categories = [jn, jn_jes_plus, jn_jes_minus] + + # + # Full tight selection + # + full_selection = [[''] for _ in jet_categories] + for idx, njet in enumerate(jet_categories): + if njet == 0 : + if row.tPt < 35: continue + if row.ePt < 40 : continue + if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue + if row.tMtToPFMET > 50 : continue + full_selection[idx].append('selected') + elif njet == 1 : + if row.tPt < 40: continue + if row.ePt < 35 : continue + if row.tMtToPFMET > 35 : continue + full_selection[idx].append('selected') + elif njet == 2 : + if row.tPt < 40: continue + if row.ePt < 30 : continue # no cut as only electrons with pt>30 are in the ntuples + if row.tMtToPFMET > 35 : continue + if row.vbfMass < 550 : continue + if row.vbfDeta < 3.5 : continue + full_selection[idx].append('selected') + + logging.debug('Passed full selection') + + jet_directories = [] + for jet_dir, sel_dir in zip(jet_category, full_selection): + jet_directories.extend( + [os.path.join(jet_dir, i) for i in sel_dir] + ) + + # + #different selections + # + sign = 'ss' if row.e_t_SS else 'os' + processtype ='gg' + ptthreshold = ['ept30'] - isTauTight = bool(row.tTightIso3Hits) - folder = dirpaths[0][1]+'/ept30' - if dirpaths[0][0] == True and sign=='os': - self.fill_histos(row, folder,isTauTight, frw) + tvetoes = [row.tauVetoPt20EleTight3MuLoose, row.tauVetoPt20EleTight3MuLoose_tes_minus, row.tauVetoPt20EleTight3MuLoose_tes_plus] + mvetoes = [row.muVetoPt5IsoIdVtx, row.muVetoPt5IsoIdVtx_mes_minus, row.muVetoPt5IsoIdVtx_mes_plus] + evetoes = [row.eVetoCicLooseIso, row.eVetoCicLooseIso_ees_minus, row.eVetoCicLooseIso_ees_plus] - for n,dirpath in enumerate(dirpaths): - jetlist = [(int(jn), str(int(jn)))] - if dirpath[0]==False : continue - if n==0: - jetlist.extend([(int(jn_jes_plus), str(int(jn_jes_plus))+'_jes_plus'), (int(jn_jes_minus), str(int(jn_jes_plus))+'_jes_minus')]) - for jet in jetlist: - #for j in ptthreshold: - folder = dirpath[1]+'/ept30/'+jet[1] - - #print row.tLooseIso3Hits, row.tTightIso3Hits, isTauTight - - self.fill_histos(row, folder,isTauTight, frw) - - if jet[0] == 0 : - if row.tPt < 35: continue - if row.ePt < 40 : continue - if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue - if row.tMtToPFMET > 50 : continue - if jet[0] == 1 : - if row.tPt < 40: continue - if row.ePt < 35 : continue - if row.tMtToPFMET > 35 : continue - if jet[0] == 2 : - if row.tPt < 40: continue - if row.ePt < 30 : continue # no cut as only electrons with pt>30 are in the ntuples - if row.tMtToPFMET > 35 : continue - if row.vbfMass < 550 : continue - if row.vbfDeta < 3.5 : continue - folder = dirpath[1]+'/ept30/'+jet[1]+'/selected' - self.fill_histos(row, folder, isTauTight,frw) + tdirs = [ i for i, j in zip( systematics['tvetos'], tvetoes) if not j] + mdirs = [ i for i, j in zip( systematics['mvetos'], mvetoes) if not j] + edirs = [ i for i, j in zip( systematics['evetos'], evetoes) if not j] + + #if any of the lists is empty + if not tdirs or not mdirs or not edirs: + continue + logging.debug('Passed Vetoes') + + #make all possible veto combos... + all_dirs = [''.join(i) for i in itertools.product(tdirs, mdirs, edirs)] + #...and choose only the meaningful ones + veto_sys = set(systematics['tvetos']+systematics['mvetos']+systematics['evetos']) + all_dirs = [i for i in all_dirs if i in veto_sys] + + #event weight + sys_shifts = systematics['trig'] + \ + systematics['pu'] + \ + systematics['eid'] + \ + systematics['eiso'] + + #set_trace() + weight_map = self.event_weight(row, sys_shifts) + + sys_directories = all_dirs + sys_shifts + if not isTauTight: + #if is a loose tau just compute the fakes! + sys_directories = tau_id_category - - + #gather the one and only weight we do care about + mc_weight = weight_map[''] + + #weights are the fr ones... + weight_map = self.fakerate_weights(row.tEta) + for i in weight_map: + #...times the mc weight (if any) + weight_map[i] *= mc_weight + + #Fill histograms in appropriate direcotries + for sys, e_thr, jet_dir in itertools.product(sys_directories, ptthreshold, jet_directories): + #if we fill a histogram, lock the event + lock = evt_id + dir_name = os.path.join(sys, sign, processtype, + e_thr, jet_dir) + if dir_name[-1] == '/': + dir_name = dir_name[:-1] + logging.debug('Filling %s' % dir_name) + #fill them! + weight_to_use = weight_map[sys] if sys in weight_map else weight_map[''] + self.fill_histos(dir_name, row, weight_to_use) def finish(self): diff --git a/lfvetau/TauFakeRateAnalyzerMVA.py b/lfvetau/TauFakeRateAnalyzerMVA.py index db2d2503..7db90068 100644 --- a/lfvetau/TauFakeRateAnalyzerMVA.py +++ b/lfvetau/TauFakeRateAnalyzerMVA.py @@ -82,13 +82,14 @@ def event_weight(self, row): #if bool(row.e1MatchesEle27WP80) and not bool(row.e2MatchesEle27WP80) : etrig = 'e1' #if not bool(row.e1MatchesEle27WP80) and bool(row.e2MatchesEle27WP80) : etrig = 'e2' + + + return self.pucorrector(row.nTruePU) * \ - mcCorrections.get_electronId_corrections13_MVA(row, 'e1') * \ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e1') * \ - mcCorrections.get_electronId_corrections13_MVA(row, 'e2') * \ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e2')* mcCorrections.get_trigger_corrections_MVA(row, etrig) -##add the trigger correction - + mcCorrections.eid_correction( row, 'e1', 'e2') * \ + mcCorrections.eiso_correction(row, 'e1', 'e2') * \ + mcCorrections.trig_correction(row, etrig ) + def begin(self): tauiso = ['tNoCuts', 'tSuperSuperLoose', 'tSuperLoose', 'tLoose', 'tTigh'] diff --git a/lfvetau/baseSelections.py b/lfvetau/baseSelections.py index 2aa603b4..9fcf168c 100755 --- a/lfvetau/baseSelections.py +++ b/lfvetau/baseSelections.py @@ -21,10 +21,12 @@ def muSelection(row, name): return True def eSelection(row, name): + eAbsEta = getattr( row, getVar(name,'AbsEta')) if getattr( row, getVar(name,'Pt')) < 20: return False #was 20 - if getattr( row, getVar(name,'AbsEta')) > 2.1: return False#as in H->tau_etau_h # was 2.3 + if eAbsEta > 2.1: return False#as in H->tau_etau_h # was 2.3 if getattr( row, getVar(name,'MissingHits')): return False if getattr( row, getVar(name,'HasConversion')): return False + if eAbsEta > 1.4442 and eAbsEta < 1.566: return False # if not getattr( row, getVar(name,'ChargeIdTight')): return False if not getattr( row, getVar(name,'ChargeIdLoose')): return False if getattr( row, getVar(name,'JetCSVBtag')) > 0.8: return False diff --git a/lfvetau/fakerate_functions.py b/lfvetau/fakerate_functions.py index 4849d733..01486bd2 100644 --- a/lfvetau/fakerate_functions.py +++ b/lfvetau/fakerate_functions.py @@ -3,83 +3,36 @@ import glob import ROOT from math import sqrt +from FinalStateAnalysis.StatTools.RooFunctorFromWS import build_roofunctor, make_corrector_from_histo - -def fakerate_central_histogram(nbin, xmin, xmax ): - - - - frfit_dir = os.path.join('results', os.environ['jobid'], 'fakerate_fits')+'/' - - - myfile = ROOT.TFile (frfit_dir+'t_os_tLoose_tTigh_tAbsEta.root') - myWS = myfile.Get('fit_efficiency') - efficiency_x = myWS.var('x') - efficiency_func = myWS.function("efficiency") - frhisto = efficiency_func.createHistogram("efficiency_x", efficiency_x) - results = myWS.genobj("fitresult_chi2_efficiency_xy_data") - parameters=results.floatParsFinal() - weight = [] - - for n in range(1, nbin) : - - eta = (n -0.5)* (xmax - xmin)/nbin - etamin = (n-1)* (xmax - xmin)/nbin - - weight.append((parameters[0].getVal()+parameters[1].getVal()*eta+parameters[2].getVal()*eta*eta, etamin)) - - return weight - -def fakerate_p1s_histogram(nbin, xmin, xmax) : - - frfit_dir = os.path.join('results', os.environ['jobid'], 'fakerate_fits')+'/' - - myfile = ROOT.TFile (frfit_dir+'t_os_tLoose_tTigh_tAbsEta.root') - myWS = myfile.Get('fit_efficiency') - efficiency_x = myWS.var('x') - efficiency_func = myWS.function("efficiency") - frhisto = efficiency_func.createHistogram("efficiency_x", efficiency_x) - results = myWS.genobj("fitresult_chi2_efficiency_xy_data") - parameters=results.floatParsFinal() - covMatrix = results.covarianceMatrix() - weight = [] - - for n in range(1, nbin) : - - eta = (n -0.5)* (xmax - xmin)/nbin - etamin = (n-1)* (xmax - xmin)/nbin - - err2= covMatrix(0,0) + covMatrix(1,1) * eta*eta + covMatrix(2,2) *eta*eta*eta*eta + 2*eta*covMatrix(0,1) + 2*eta*eta*covMatrix(0,2) + 2*eta*eta*eta*covMatrix(1,2) - myweight = (parameters[0].getVal()+parameters[1].getVal()*eta+parameters[2].getVal()*eta*eta)+ sqrt(err2) - - weight.append((myweight, etamin)) - - return weight - -def fakerate_m1s_histogram(nbin, xmin, xmax) : - - frfit_dir = os.path.join('results', os.environ['jobid'], 'fakerate_fits')+'/' - - myfile = ROOT.TFile (frfit_dir+'t_os_tLoose_tTigh_tAbsEta.root') - myWS = myfile.Get('fit_efficiency') - efficiency_x = myWS.var('x') - efficiency_func = myWS.function("efficiency") - frhisto = efficiency_func.createHistogram("efficiency_x", efficiency_x) - results = myWS.genobj("fitresult_chi2_efficiency_xy_data") - parameters=results.floatParsFinal() - covMatrix = results.covarianceMatrix() - - weight = [] - - for n in range(1, nbin) : - - eta = (n -0.5)* (xmax - xmin)/nbin - etamin = (n-1)* (xmax - xmin)/nbin - - err2= covMatrix(0,0) + covMatrix(1,1) * eta*eta + covMatrix(2,2) *eta*eta*eta*eta + 2*eta*covMatrix(0,1) + 2*eta*eta*covMatrix(0,2) + 2*eta*eta*eta*covMatrix(1,2) - myweight = (parameters[0].getVal()+parameters[1].getVal()*eta+parameters[2].getVal()*eta*eta) - sqrt(err2) +frfit_dir = os.path.join('results', os.environ['jobid'], 'fakerate_fits')+'/' - weight.append((myweight, etamin)) +tau_fake_rate = build_roofunctor( + frfit_dir+'t_os_tLoose_tTigh_tAbsEta.root', + 'fit_efficiency', + 'efficiency' +) + +def inflate_systematics(functor, inflation): + '''Christian recipe: INFLATE ALL THE SYSTEMATICS!''' + def fcn(*args): + return functor(*args) * inflation + return fcn + +tau_fake_rate_up = inflate_systematics(tau_fake_rate, 1.3) +tau_fake_rate_dw = inflate_systematics(tau_fake_rate, 0.7) + +# Tau fakes as it should be +# tau_fake_rate_up = make_corrector_from_histo( +# frfit_dir+'t_os_tLoose_tTigh_tAbsEta_2.root', +# 'efficiency_up', +# '1D' +# ) +# +# tau_fake_rate_dw = make_corrector_from_histo( +# frfit_dir+'t_os_tLoose_tTigh_tAbsEta_2.root', +# 'efficiency_dw', +# '1D' +# ) - return weight diff --git a/lfvetau/mcCorrections.py b/lfvetau/mcCorrections.py index 9a6c64a5..d68bf815 100755 --- a/lfvetau/mcCorrections.py +++ b/lfvetau/mcCorrections.py @@ -2,6 +2,11 @@ import glob import FinalStateAnalysis.TagAndProbe.HetauCorrection as HetauCorrection import FinalStateAnalysis.TagAndProbe.PileupWeight as PileupWeight +from FinalStateAnalysis.PlotTools.decorators import memo, memo_last + +@memo +def getVar(name, var): + return name+var is7TeV = bool('7TeV' in os.environ['jobid']) pu_distributions = { @@ -24,6 +29,7 @@ def make_puCorrector(dataset, kind=None): # return weights else: raise KeyError('dataset not present. Please check the spelling or add it to mcCorrectors.py') + def make_puCorrectorUp(dataset, kind=None): 'makes PU reweighting according to the pu distribution of the reference data and the MC, MC distribution can be forced' if not kind: @@ -32,6 +38,7 @@ def make_puCorrectorUp(dataset, kind=None): return PileupWeight.PileupWeight( 'S6' if is7TeV else 'S10', *(pu_distributionsUp[dataset])) else: raise KeyError('dataset not present. Please check the spelling or add it to mcCorrectors.py') + def make_puCorrectorDown(dataset, kind=None): 'makes PU reweighting according to the pu distribution of the reference data and the MC, MC distribution can be forced' if not kind: @@ -41,113 +48,97 @@ def make_puCorrectorDown(dataset, kind=None): else: raise KeyError('dataset not present. Please check the spelling or add it to mcCorrectors.py') +def make_shifted_weights(default, shifts, functors): + '''make_shifted_weights(default, shifts, functors) --> functor + takes as imput the central value functor and two lists + the name of the shifts and the shifted functors + the returned functor takes one additional string to + select the shifted functor. If the shift kwarg is missing + or does not match any shift tag the central (default) + fuctor output is returned''' + #make default fetching faster + default = default + def functor(*args, **kwargs): + shift = '' + if 'shift' in kwargs: + shift = kwargs['shift'] + del kwargs['shift'] + + #check if to apply shifts + for tag, fcn in zip(shifts, functors): + if tag == shift: + return fcn(*args, **kwargs) + + return default(*args, **kwargs) + return functor + +def make_multiple(fcn, indexed=False, shift=0): + '''make_multiple(fcn, indexed=True, shift=0) --> functor + takes as imput a weight correction function of pt and eta + and returns a functor multiple(row,*args) --> weight + where *args are the base name of the objects upon which + compute the correction. + + If indexed is true means that fcn returns a tuple + (weight, error) shift +/-1 makes the functor return the + weight+/-error in this case''' + def multiple(row,*args): + ret = 1. + for arg in args: + abseta = abs( + getattr( + row, + getVar(arg,'Eta') + ) + ) + pt = getattr(row, getVar(arg,'Pt')) + fcn_ret = fcn(pt,abseta) + if indexed: + value, err = fcn_ret + if shift == 1: + ret *= (value + err) + elif shift == -1: + ret *= (value - err) + else: + ret *= value + else: + ret *= fcn_ret + return ret + return multiple + + ##put here the trigger correction as in https://github.com/mverzett/UWHiggs/blob/WH_At_Paper/wh/mcCorrectors.py -correct_e = HetauCorrection.correct_hamburg_e -correct_eid13_mva = HetauCorrection.correct_eid13_mva -correct_eiso13_mva = HetauCorrection.correct_eiso13_mva -correct_eid13_p1s_mva = HetauCorrection.correct_eid13_p1s_mva -correct_eiso13_p1s_mva = HetauCorrection.correct_eiso13_p1s_mva -correct_eid13_m1s_mva = HetauCorrection.correct_eid13_m1s_mva -correct_eiso13_m1s_mva = HetauCorrection.correct_eiso13_m1s_mva -correct_eid_mva = HetauCorrection.scale_eleId_hww -correct_eReco_mva = HetauCorrection.scale_elereco_hww -correct_eIso_mva = HetauCorrection.scale_eleIso_hww -correct_trigger_mva = HetauCorrection.single_ele_mva - -def get_electron_corrections(row,*args): - 'makes corrections to iso and id of electrons' - ret = 1. - for arg in args: - abseta = abs(getattr(row, '%sEta' % arg)) - pt = getattr(row, '%sPt' % arg) - ret *= correct_e(pt,abseta) - return ret - -def get_electronId_corrections_MVA(row, *args): - ret = 1. - for arg in args: - eta = getattr(row, '%sEta' % arg) - pt = getattr(row, '%sPt' % arg) - ret *= correct_eid_mva(pt,eta)[0] - return ret -def get_electronReco_corrections_MVA(row, *args): - ret = 1. - for arg in args: - eta = getattr(row, '%sEta' % arg) - pt = getattr(row, '%sPt' % arg) - ret *= correct_eReco_mva(pt,eta)[0] - return ret -def get_electronIso_corrections_MVA(row, *args): - ret = 1. - for arg in args: - eta = getattr(row, '%sEta' % arg) - pt = getattr(row, '%sPt' % arg) - ret *= correct_eIso_mva(pt,eta)[0] - return ret - -def get_trigger_corrections_MVA(row, *args): - ret = 1. - for arg in args: - eta = getattr(row, '%sEta' % arg) - pt = getattr(row, '%sPt' % arg) - ret *= correct_trigger_mva(pt,eta)[0] - return ret -def get_trigger_corrections_p1s_MVA(row, *args): - ret = 1. - for arg in args: - eta = getattr(row, '%sEta' % arg) - pt = getattr(row, '%sPt' % arg) - ret *= correct_trigger_mva(pt,eta)[0]+correct_trigger_mva(pt,eta)[1] - return ret -def get_trigger_corrections_m1s_MVA(row, *args): - ret = 1. - for arg in args: - eta = getattr(row, '%sEta' % arg) - pt = getattr(row, '%sPt' % arg) - ret *= correct_trigger_mva(pt,eta)[0]-correct_trigger_mva(pt,eta)[1] - - return ret - -def get_electronId_corrections13_MVA(row, *args): - ret = 1. - for arg in args: - eta = getattr(row, '%sEta' % arg) - pt = getattr(row, '%sPt' % arg) - ret *= correct_eid13_mva(pt,eta) - return ret -def get_electronIso_corrections13_MVA(row, *args): - ret = 1. - for arg in args: - eta = getattr(row, '%sEta' % arg) - pt = getattr(row, '%sPt' % arg) - ret *= correct_eiso13_mva(pt,eta) - return ret -def get_electronId_corrections13_p1s_MVA(row, *args): - ret = 1. - for arg in args: - eta = getattr(row, '%sEta' % arg) - pt = getattr(row, '%sPt' % arg) - ret *= correct_eid13_p1s_mva(pt,eta) - return ret -def get_electronIso_corrections13_p1s_MVA(row, *args): - ret = 1. - for arg in args: - eta = getattr(row, '%sEta' % arg) - pt = getattr(row, '%sPt' % arg) - ret *= correct_eiso13_p1s_mva(pt,eta) - return ret -def get_electronId_corrections13_m1s_MVA(row, *args): - ret = 1. - for arg in args: - eta = getattr(row, '%sEta' % arg) - pt = getattr(row, '%sPt' % arg) - ret *= correct_eid13_m1s_mva(pt,eta) - return ret -def get_electronIso_corrections13_m1s_MVA(row, *args): - ret = 1. - for arg in args: - eta = getattr(row, '%sEta' % arg) - pt = getattr(row, '%sPt' % arg) - ret *= correct_eiso13_m1s_mva(pt,eta) - return ret +correct_e = make_multiple(HetauCorrection.correct_hamburg_e) +correct_eid13_mva = make_multiple(HetauCorrection.correct_eid13_mva) +correct_eid13_p1s_mva = make_multiple(HetauCorrection.correct_eid13_p1s_mva) +correct_eid13_m1s_mva = make_multiple(HetauCorrection.correct_eid13_m1s_mva) + +correct_eiso13_mva = make_multiple(HetauCorrection.correct_eiso13_mva) +correct_eiso13_p1s_mva = make_multiple(HetauCorrection.correct_eiso13_p1s_mva) +correct_eiso13_m1s_mva = make_multiple(HetauCorrection.correct_eiso13_m1s_mva) + +#correct_eid_mva = make_multiple(HetauCorrection.scale_eleId_hww) +#correct_eReco_mva = make_multiple(HetauCorrection.scale_elereco_hww) +#correct_eIso_mva = make_multiple(HetauCorrection.scale_eleIso_hww) +correct_trigger_mva = make_multiple(HetauCorrection.single_ele_mva, indexed=True) +correct_trigger_mva_up = make_multiple(HetauCorrection.single_ele_mva, indexed=True, shift=1) +correct_trigger_mva_dw = make_multiple(HetauCorrection.single_ele_mva, indexed=True, shift=-1) + +eiso_correction = make_shifted_weights( + correct_eiso13_mva, + ['eisop1s','eisom1s'], + [correct_eiso13_p1s_mva, correct_eiso13_m1s_mva], +) + +eid_correction = make_shifted_weights( + correct_eid13_mva, + ['eidp1s','eidm1s'], + [correct_eid13_p1s_mva, correct_eid13_m1s_mva] +) + +trig_correction = make_shifted_weights( + correct_trigger_mva, + ['trp1s', 'trm1s'], + [correct_trigger_mva_up, correct_trigger_mva_dw] +) From 98b8222e1c3b6b8db902884a90e97e4167a2d0d6 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Thu, 23 Oct 2014 10:54:00 -0500 Subject: [PATCH 120/192] switch back to non MT-cut fake rates --- lfvetau/Rakefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index 1f55fc21..0d147ac8 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -74,7 +74,7 @@ def get_plotter_results(analyzer) end -$frfit_dir = "results/#{$jobid}/fakerate_fits_MtCut" +$frfit_dir = "results/#{$jobid}/fakerate_fits" directory $frfit_dir exponential = "scale*TMath::Exp(x*decay)+offset" exponential_vars = "scale[4., 0, 10],decay[-1e-2, -1, -1e-4],offset[1e-2, 0, 0.5]" @@ -179,8 +179,8 @@ fr_fits.each do |fit, fit_info| fit_output = $frfit_dir + "/#{fit}.root" - subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/#{fit_info['analyzer']}_tMtCut/#{x}.root"} - # subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/TauFakeRateAnalyzerMVA_eTight/#{x}.root"} + #subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/#{fit_info['analyzer']}_tMtCut/#{x}.root"} + subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/TauFakeRateAnalyzerMVA/#{x}.root"} subsample_input_list = subsamples_inputs_result_list.join(" ") # Path to histograms in root files From b32163a57ce3dc8a902b254f9392e52520ebbe79 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Thu, 23 Oct 2014 10:54:21 -0500 Subject: [PATCH 121/192] add MEGAPATH to environment --- lfvetau/environment.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/lfvetau/environment.sh b/lfvetau/environment.sh index 078465f7..dfb159e1 100644 --- a/lfvetau/environment.sh +++ b/lfvetau/environment.sh @@ -3,4 +3,5 @@ source ../environment.sh source jobid.sh export jobid=$jobid8 +export MEGAPATH=/hdfs/store/user/taroni/ export blind='YES' From f05efad91aa6e3569d3a9013415c1d3e93d352d2 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Thu, 23 Oct 2014 10:54:35 -0500 Subject: [PATCH 122/192] update jobid --- lfvetau/jobid.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lfvetau/jobid.sh b/lfvetau/jobid.sh index adca46df..6dae8217 100644 --- a/lfvetau/jobid.sh +++ b/lfvetau/jobid.sh @@ -6,5 +6,5 @@ #export jobid8='newNtuple_2Sept' #export jobid8='newNtuple_1Oct' export jobidmt='MCntuples_8April' -export jobid8='newNtuple_10Oct' +export jobid8='newNtuple_16Oct' export jobidSync='newNtuple_Sync' From 10c3f5fccc1053b8adc7eaf0e462d4fb74109d56 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Thu, 23 Oct 2014 11:28:34 -0500 Subject: [PATCH 123/192] bug fix for embedded sample --- lfvetau/LFVHETauAnalyzerMVA.py | 278 ++++++++++++++++----------------- 1 file changed, 139 insertions(+), 139 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index d5f4c8f7..8aa15b6f 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -300,87 +300,87 @@ def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): continue - histos[folder+'/tPt'].Fill(row.tPt, frweight) - histos[folder+'/tEta'].Fill(row.tEta, frweight) - histos[folder+'/tPhi'].Fill(row.tPhi, frweight) - histos[folder+'/ePt'].Fill(row.ePt, frweight) - histos[folder+'/eEta'].Fill(row.eEta, frweight) - histos[folder+'/ePhi'].Fill(row.ePhi, frweight) - histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), frweight) - histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, frweight) - histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + histos[folder+'/tPt'].Fill(row.tPt, row.EmbPtWeight*frweight) + histos[folder+'/tEta'].Fill(row.tEta, row.EmbPtWeight*frweight) + histos[folder+'/tPhi'].Fill(row.tPhi, row.EmbPtWeight*frweight) + histos[folder+'/ePt'].Fill(row.ePt, row.EmbPtWeight*frweight) + histos[folder+'/eEta'].Fill(row.eEta, row.EmbPtWeight*frweight) + histos[folder+'/ePhi'].Fill(row.ePhi, row.EmbPtWeight*frweight) + histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), row.EmbPtWeight*frweight) + histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, row.EmbPtWeight*frweight) + histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*frweight) + histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*frweight) + histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*frweight) + histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*frweight) if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*frweight) + histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*frweight) if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*frweight) + histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*frweight) if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*frweight) + histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*frweight) if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - - histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), frweight) - histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - - #histos[folder+'/h_collmass_pfmet_jes'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_mes'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_tes'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_ees'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_ues'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), frweight) + histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*frweight) + histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*frweight) + + histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*frweight) + histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*frweight) + histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), row.EmbPtWeight*frweight) + histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*frweight) + histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*frweight) + + #histos[folder+'/h_collmass_pfmet_jes'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_Phi), row.EmbPtWeight*frweight) + #histos[folder+'/h_collmass_pfmet_mes'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), row.EmbPtWeight*frweight) + #histos[folder+'/h_collmass_pfmet_tes'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), row.EmbPtWeight*frweight) + #histos[folder+'/h_collmass_pfmet_ees'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), row.EmbPtWeight*frweight) + #histos[folder+'/h_collmass_pfmet_ues'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), row.EmbPtWeight*frweight) - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, frweight) - histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, frweight) - histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, frweight) + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, row.EmbPtWeight*frweight) + histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, row.EmbPtWeight*frweight) + histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, row.EmbPtWeight*frweight) - histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.pfMetPhi), frweight) - histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), frweight) - histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), frweight) - histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, frweight) - histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, frweight) - histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, frweight) - ##histos[folder+'/ePFMET_Mt_Ty1_ues_minus'].Fill(row.eMtToPfMet_Ty1_ues_minus, frweight) - ##histos[folder+'/ePFMET_Mt_Ty1_ues_plus'].Fill(row.eMtToPfMet_Ty1_ues_plus, frweight) - #histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, frweight) - #histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, frweight) - #histos[folder+'/ePFMET_Mt_jes'].Fill(row.eMtToPfMet_jes, frweight) - #histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus, frweight) - #histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, frweight) - #histos[folder+'/ePFMET_Mt_mes'].Fill(row.eMtToPfMet_mes, frweight) - #histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus, frweight) - #histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, frweight) - #histos[folder+'/ePFMET_Mt_ees'].Fill(row.eMtToPfMet_ees, frweight) - #histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus, frweight) - #histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, frweight) - #histos[folder+'/ePFMET_Mt_tes'].Fill(row.eMtToPfMet_tes, frweight) - #histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus, frweight) - #histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, frweight) - #histos[folder+'/ePFMET_Mt_ues'].Fill(row.eMtToPfMet_ues, frweight) + histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.pfMetPhi), row.EmbPtWeight*frweight) + histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), row.EmbPtWeight*frweight) + histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), row.EmbPtWeight*frweight) + histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, row.EmbPtWeight*frweight) + histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, row.EmbPtWeight*frweight) + histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, row.EmbPtWeight*frweight) + ##histos[folder+'/ePFMET_Mt_Ty1_ues_minus'].Fill(row.eMtToPfMet_Ty1_ues_minus, row.EmbPtWeight*frweight) + ##histos[folder+'/ePFMET_Mt_Ty1_ues_plus'].Fill(row.eMtToPfMet_Ty1_ues_plus, row.EmbPtWeight*frweight) + #histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, row.EmbPtWeight*frweight) + #histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, row.EmbPtWeight*frweight) + #histos[folder+'/ePFMET_Mt_jes'].Fill(row.eMtToPfMet_jes, row.EmbPtWeight*frweight) + #histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus, row.EmbPtWeight*frweight) + #histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, row.EmbPtWeight*frweight) + #histos[folder+'/ePFMET_Mt_mes'].Fill(row.eMtToPfMet_mes, row.EmbPtWeight*frweight) + #histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus, row.EmbPtWeight*frweight) + #histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, row.EmbPtWeight*frweight) + #histos[folder+'/ePFMET_Mt_ees'].Fill(row.eMtToPfMet_ees, row.EmbPtWeight*frweight) + #histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus, row.EmbPtWeight*frweight) + #histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, row.EmbPtWeight*frweight) + #histos[folder+'/ePFMET_Mt_tes'].Fill(row.eMtToPfMet_tes, row.EmbPtWeight*frweight) + #histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus, row.EmbPtWeight*frweight) + #histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, row.EmbPtWeight*frweight) + #histos[folder+'/ePFMET_Mt_ues'].Fill(row.eMtToPfMet_ues, row.EmbPtWeight*frweight) - histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), frweight) - histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), frweight) - histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), frweight) - histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, frweight) - histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, frweight) - #histos[folder+'/tPFMET_Mt_jes'].Fill(row.tMtToPfMet_jes, frweight) - #histos[folder+'/tPFMET_Mt_mes'].Fill(row.tMtToPfMet_mes, frweight) - #histos[folder+'/tPFMET_Mt_ees'].Fill(row.tMtToPfMet_ees, frweight) - #histos[folder+'/tPFMET_Mt_tes'].Fill(row.tMtToPfMet_tes, frweight) - #histos[folder+'/tPFMET_Mt_ues'].Fill(row.tMtToPfMet_ues, frweight) + histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), row.EmbPtWeight*frweight) + histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.EmbPtWeight*frweight) + histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.EmbPtWeight*frweight) + histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, row.EmbPtWeight*frweight) + histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, row.EmbPtWeight*frweight) + #histos[folder+'/tPFMET_Mt_jes'].Fill(row.tMtToPfMet_jes, row.EmbPtWeight*frweight) + #histos[folder+'/tPFMET_Mt_mes'].Fill(row.tMtToPfMet_mes, row.EmbPtWeight*frweight) + #histos[folder+'/tPFMET_Mt_ees'].Fill(row.tMtToPfMet_ees, row.EmbPtWeight*frweight) + #histos[folder+'/tPFMET_Mt_tes'].Fill(row.tMtToPfMet_tes, row.EmbPtWeight*frweight) + #histos[folder+'/tPFMET_Mt_ues'].Fill(row.tMtToPfMet_ues, row.EmbPtWeight*frweight) - histos[folder+'/jetN_20'].Fill(row.jetVeto20, frweight) - histos[folder+'/jetN_30'].Fill(row.jetVeto30, frweight) + histos[folder+'/jetN_20'].Fill(row.jetVeto20, row.EmbPtWeight*frweight) + histos[folder+'/jetN_30'].Fill(row.jetVeto30, row.EmbPtWeight*frweight) else: # if it is TauTight if not f.startswith('os') and not f.startswith('ss') : # if the dir name start with mVeto, eVeto or tVeto I don't want the different weight of MC corrections @@ -391,107 +391,106 @@ def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): if n >0 : break folder = d+f - #print folder if f=='os/gg/ept30' : histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) histos[folder+'/h_vismass'].Fill(row.e_t_Mass, row.EmbPtWeight*weight[n]) continue - histos[folder+'/tPt'].Fill(row.tPt, weight[n]) - histos[folder+'/tEta'].Fill(row.tEta, weight[n]) - histos[folder+'/tPhi'].Fill(row.tPhi, weight[n]) - histos[folder+'/ePt'].Fill(row.ePt, weight[n]) - histos[folder+'/eEta'].Fill(row.eEta, weight[n]) - histos[folder+'/ePhi'].Fill(row.ePhi, weight[n]) - histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), weight[n]) - histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, weight[n]) + histos[folder+'/tPt'].Fill(row.tPt, row.EmbPtWeight*weight[n]) + histos[folder+'/tEta'].Fill(row.tEta, row.EmbPtWeight*weight[n]) + histos[folder+'/tPhi'].Fill(row.tPhi, row.EmbPtWeight*weight[n]) + histos[folder+'/ePt'].Fill(row.ePt, row.EmbPtWeight*weight[n]) + histos[folder+'/eEta'].Fill(row.eEta, row.EmbPtWeight*weight[n]) + histos[folder+'/ePhi'].Fill(row.ePhi, row.EmbPtWeight*weight[n]) + histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, row.EmbPtWeight*weight[n]) - histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*weight[n]) if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*weight[n]) if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*weight[n]) if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*weight[n]) if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*weight[n]) - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), weight[n]) - histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, weight[n]) + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, row.EmbPtWeight*weight[n]) - histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, weight[n]) - histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, weight[n]) + histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, row.EmbPtWeight*weight[n]) + histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, row.EmbPtWeight*weight[n]) - histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) - histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) - histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), weight[n]) + histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, weight[n]) - histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, weight[n]) - histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, weight[n]) + histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, row.EmbPtWeight*weight[n]) + histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, row.EmbPtWeight*weight[n]) + histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, row.EmbPtWeight*weight[n]) - histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), weight[n]) - histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), weight[n]) - histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), weight[n]) + histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, weight[n]) - histos[folder+'/tPFMET_Mt_Ty1'].Fill(row.tMtToPfMet_Ty1, weight[n]) - histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, weight[n]) + histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, row.EmbPtWeight*weight[n]) + histos[folder+'/tPFMET_Mt_Ty1'].Fill(row.tMtToPfMet_Ty1, row.EmbPtWeight*weight[n]) + histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, row.EmbPtWeight*weight[n]) - histos[folder+'/jetN_20'].Fill(row.jetVeto20, weight[n]) - histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight[n]) + histos[folder+'/jetN_20'].Fill(row.jetVeto20, row.EmbPtWeight*weight[n]) + histos[folder+'/jetN_30'].Fill(row.jetVeto30, row.EmbPtWeight*weight[n]) if n == 0: # if I'm in the dir starting with os or ss I want also the energy scale uncertainties - histos[folder+'/h_collmass_pfmet_jes_plus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_plus_Phi), weight[n]) - histos[folder+'/h_collmass_pfmet_jes_minus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_minus_Phi), weight[n]) + histos[folder+'/h_collmass_pfmet_jes_plus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_plus_Phi), row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmass_pfmet_jes_minus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_minus_Phi), row.EmbPtWeight*weight[n]) ### add the minus in the ntuple. - #histos[folder+'/h_collmass_pfmet_mes_plus'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), weight[n]) - #histos[folder+'/h_collmass_pfmet_tes_plus'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), weight[n]) - #histos[folder+'/h_collmass_pfmet_ees_plus'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), weight[n]) - #histos[folder+'/h_collmass_pfmet_ues_plus'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), weight[n]) + #histos[folder+'/h_collmass_pfmet_mes_plus'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), row.EmbPtWeight*weight[n]) + #histos[folder+'/h_collmass_pfmet_tes_plus'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), row.EmbPtWeight*weight[n]) + #histos[folder+'/h_collmass_pfmet_ees_plus'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), row.EmbPtWeight*weight[n]) + #histos[folder+'/h_collmass_pfmet_ues_plus'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), row.EmbPtWeight*weight[n]) - histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, weight[n]) - histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, weight[n]) + histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, row.EmbPtWeight*weight[n]) + histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, row.EmbPtWeight*weight[n]) - histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus,weight[n]) - histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, weight[n]) + histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus,row.EmbPtWeight*weight[n]) + histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, row.EmbPtWeight*weight[n]) - histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus,weight[n]) - histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, weight[n]) + histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus,row.EmbPtWeight*weight[n]) + histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, row.EmbPtWeight*weight[n]) - histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus,weight[n]) - histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, weight[n]) + histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus,row.EmbPtWeight*weight[n]) + histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, row.EmbPtWeight*weight[n]) - histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus,weight[n]) - histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, weight[n]) + histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus,row.EmbPtWeight*weight[n]) + histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, row.EmbPtWeight*weight[n]) - histos[folder+'/tPFMET_Mt_jes_plus'].Fill(row.tMtToPfMet_jes_plus,weight[n]) - histos[folder+'/tPFMET_Mt_mes_plus'].Fill(row.tMtToPfMet_mes_plus,weight[n]) - histos[folder+'/tPFMET_Mt_ees_plus'].Fill(row.tMtToPfMet_ees_plus,weight[n]) - histos[folder+'/tPFMET_Mt_tes_plus'].Fill(row.tMtToPfMet_tes_plus,weight[n]) - histos[folder+'/tPFMET_Mt_ues_plus'].Fill(row.tMtToPfMet_ues_plus,weight[n]) - histos[folder+'/tPFMET_Mt_jes_minus'].Fill(row.tMtToPfMet_jes_minus,weight[n]) - histos[folder+'/tPFMET_Mt_mes_minus'].Fill(row.tMtToPfMet_mes_minus,weight[n]) - histos[folder+'/tPFMET_Mt_ees_minus'].Fill(row.tMtToPfMet_ees_minus,weight[n]) - histos[folder+'/tPFMET_Mt_tes_minus'].Fill(row.tMtToPfMet_tes_minus,weight[n]) - histos[folder+'/tPFMET_Mt_ues_minus'].Fill(row.tMtToPfMet_ues_minus,weight[n]) + histos[folder+'/tPFMET_Mt_jes_plus'].Fill(row.tMtToPfMet_jes_plus,row.EmbPtWeight*weight[n]) + histos[folder+'/tPFMET_Mt_mes_plus'].Fill(row.tMtToPfMet_mes_plus,row.EmbPtWeight*weight[n]) + histos[folder+'/tPFMET_Mt_ees_plus'].Fill(row.tMtToPfMet_ees_plus,row.EmbPtWeight*weight[n]) + histos[folder+'/tPFMET_Mt_tes_plus'].Fill(row.tMtToPfMet_tes_plus,row.EmbPtWeight*weight[n]) + histos[folder+'/tPFMET_Mt_ues_plus'].Fill(row.tMtToPfMet_ues_plus,row.EmbPtWeight*weight[n]) + histos[folder+'/tPFMET_Mt_jes_minus'].Fill(row.tMtToPfMet_jes_minus,row.EmbPtWeight*weight[n]) + histos[folder+'/tPFMET_Mt_mes_minus'].Fill(row.tMtToPfMet_mes_minus,row.EmbPtWeight*weight[n]) + histos[folder+'/tPFMET_Mt_ees_minus'].Fill(row.tMtToPfMet_ees_minus,row.EmbPtWeight*weight[n]) + histos[folder+'/tPFMET_Mt_tes_minus'].Fill(row.tMtToPfMet_tes_minus,row.EmbPtWeight*weight[n]) + histos[folder+'/tPFMET_Mt_ues_minus'].Fill(row.tMtToPfMet_ues_minus,row.EmbPtWeight*weight[n]) @@ -605,6 +604,7 @@ def process(self): for jet in jetlist: #for j in ptthreshold: folder = dirpath[1]+'/ept30/'+jet[1] + #print folder #print row.tLooseIso3Hits, row.tTightIso3Hits, isTauTight From 65eebc04bcbb1e4e4dd95cf429bdac48c03c853b Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Thu, 23 Oct 2014 11:35:30 -0500 Subject: [PATCH 124/192] bug fix for embedded sample --- lfvetau/LFVHETauAnalyzerMVA.py | 287 +++++++++++++++++---------------- 1 file changed, 144 insertions(+), 143 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 8aa15b6f..377948ed 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -293,94 +293,94 @@ def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): for n, l in enumerate(looseList) : frweight = weight[0]*fr_weights[n] if n < len(looseList)-1 else weight[0] folder = l+f - + frweight = row.EmbPtWeight*frweight if f=='os/gg/ept30' : - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*frweight) - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, row.EmbPtWeight*frweight) + histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, frweight) continue - histos[folder+'/tPt'].Fill(row.tPt, row.EmbPtWeight*frweight) - histos[folder+'/tEta'].Fill(row.tEta, row.EmbPtWeight*frweight) - histos[folder+'/tPhi'].Fill(row.tPhi, row.EmbPtWeight*frweight) - histos[folder+'/ePt'].Fill(row.ePt, row.EmbPtWeight*frweight) - histos[folder+'/eEta'].Fill(row.eEta, row.EmbPtWeight*frweight) - histos[folder+'/ePhi'].Fill(row.ePhi, row.EmbPtWeight*frweight) - histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), row.EmbPtWeight*frweight) - histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, row.EmbPtWeight*frweight) - histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*frweight) - histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*frweight) - histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*frweight) - histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*frweight) + histos[folder+'/tPt'].Fill(row.tPt, frweight) + histos[folder+'/tEta'].Fill(row.tEta, frweight) + histos[folder+'/tPhi'].Fill(row.tPhi, frweight) + histos[folder+'/ePt'].Fill(row.ePt, frweight) + histos[folder+'/eEta'].Fill(row.eEta, frweight) + histos[folder+'/ePhi'].Fill(row.ePhi, frweight) + histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), frweight) + histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, frweight) + histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*frweight) - histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*frweight) + histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*frweight) - histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*frweight) + histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*frweight) - histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*frweight) + histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*frweight) - histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*frweight) - - histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*frweight) - histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*frweight) - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), row.EmbPtWeight*frweight) - histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*frweight) - histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*frweight) - - #histos[folder+'/h_collmass_pfmet_jes'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_Phi), row.EmbPtWeight*frweight) - #histos[folder+'/h_collmass_pfmet_mes'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), row.EmbPtWeight*frweight) - #histos[folder+'/h_collmass_pfmet_tes'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), row.EmbPtWeight*frweight) - #histos[folder+'/h_collmass_pfmet_ees'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), row.EmbPtWeight*frweight) - #histos[folder+'/h_collmass_pfmet_ues'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), row.EmbPtWeight*frweight) + histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + + histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) + histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) + histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), frweight) + histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) + histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) + + #histos[folder+'/h_collmass_pfmet_jes'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_Phi), frweight) + #histos[folder+'/h_collmass_pfmet_mes'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), frweight) + #histos[folder+'/h_collmass_pfmet_tes'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), frweight) + #histos[folder+'/h_collmass_pfmet_ees'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), frweight) + #histos[folder+'/h_collmass_pfmet_ues'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), frweight) - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, row.EmbPtWeight*frweight) - histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, row.EmbPtWeight*frweight) - histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, row.EmbPtWeight*frweight) + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, frweight) + histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, frweight) + histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, frweight) - histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.pfMetPhi), row.EmbPtWeight*frweight) - histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), row.EmbPtWeight*frweight) - histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), row.EmbPtWeight*frweight) - histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, row.EmbPtWeight*frweight) - histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, row.EmbPtWeight*frweight) - histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, row.EmbPtWeight*frweight) - ##histos[folder+'/ePFMET_Mt_Ty1_ues_minus'].Fill(row.eMtToPfMet_Ty1_ues_minus, row.EmbPtWeight*frweight) - ##histos[folder+'/ePFMET_Mt_Ty1_ues_plus'].Fill(row.eMtToPfMet_Ty1_ues_plus, row.EmbPtWeight*frweight) - #histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, row.EmbPtWeight*frweight) - #histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, row.EmbPtWeight*frweight) - #histos[folder+'/ePFMET_Mt_jes'].Fill(row.eMtToPfMet_jes, row.EmbPtWeight*frweight) - #histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus, row.EmbPtWeight*frweight) - #histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, row.EmbPtWeight*frweight) - #histos[folder+'/ePFMET_Mt_mes'].Fill(row.eMtToPfMet_mes, row.EmbPtWeight*frweight) - #histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus, row.EmbPtWeight*frweight) - #histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, row.EmbPtWeight*frweight) - #histos[folder+'/ePFMET_Mt_ees'].Fill(row.eMtToPfMet_ees, row.EmbPtWeight*frweight) - #histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus, row.EmbPtWeight*frweight) - #histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, row.EmbPtWeight*frweight) - #histos[folder+'/ePFMET_Mt_tes'].Fill(row.eMtToPfMet_tes, row.EmbPtWeight*frweight) - #histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus, row.EmbPtWeight*frweight) - #histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, row.EmbPtWeight*frweight) - #histos[folder+'/ePFMET_Mt_ues'].Fill(row.eMtToPfMet_ues, row.EmbPtWeight*frweight) + histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.pfMetPhi), frweight) + histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), frweight) + histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), frweight) + histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, frweight) + histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, frweight) + histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, frweight) + ##histos[folder+'/ePFMET_Mt_Ty1_ues_minus'].Fill(row.eMtToPfMet_Ty1_ues_minus, frweight) + ##histos[folder+'/ePFMET_Mt_Ty1_ues_plus'].Fill(row.eMtToPfMet_Ty1_ues_plus, frweight) + #histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, frweight) + #histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, frweight) + #histos[folder+'/ePFMET_Mt_jes'].Fill(row.eMtToPfMet_jes, frweight) + #histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus, frweight) + #histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, frweight) + #histos[folder+'/ePFMET_Mt_mes'].Fill(row.eMtToPfMet_mes, frweight) + #histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus, frweight) + #histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, frweight) + #histos[folder+'/ePFMET_Mt_ees'].Fill(row.eMtToPfMet_ees, frweight) + #histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus, frweight) + #histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, frweight) + #histos[folder+'/ePFMET_Mt_tes'].Fill(row.eMtToPfMet_tes, frweight) + #histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus, frweight) + #histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, frweight) + #histos[folder+'/ePFMET_Mt_ues'].Fill(row.eMtToPfMet_ues, frweight) - histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), row.EmbPtWeight*frweight) - histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.EmbPtWeight*frweight) - histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.EmbPtWeight*frweight) - histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, row.EmbPtWeight*frweight) - histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, row.EmbPtWeight*frweight) - #histos[folder+'/tPFMET_Mt_jes'].Fill(row.tMtToPfMet_jes, row.EmbPtWeight*frweight) - #histos[folder+'/tPFMET_Mt_mes'].Fill(row.tMtToPfMet_mes, row.EmbPtWeight*frweight) - #histos[folder+'/tPFMET_Mt_ees'].Fill(row.tMtToPfMet_ees, row.EmbPtWeight*frweight) - #histos[folder+'/tPFMET_Mt_tes'].Fill(row.tMtToPfMet_tes, row.EmbPtWeight*frweight) - #histos[folder+'/tPFMET_Mt_ues'].Fill(row.tMtToPfMet_ues, row.EmbPtWeight*frweight) + histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), frweight) + histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), frweight) + histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), frweight) + histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, frweight) + histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, frweight) + #histos[folder+'/tPFMET_Mt_jes'].Fill(row.tMtToPfMet_jes, frweight) + #histos[folder+'/tPFMET_Mt_mes'].Fill(row.tMtToPfMet_mes, frweight) + #histos[folder+'/tPFMET_Mt_ees'].Fill(row.tMtToPfMet_ees, frweight) + #histos[folder+'/tPFMET_Mt_tes'].Fill(row.tMtToPfMet_tes, frweight) + #histos[folder+'/tPFMET_Mt_ues'].Fill(row.tMtToPfMet_ues, frweight) - histos[folder+'/jetN_20'].Fill(row.jetVeto20, row.EmbPtWeight*frweight) - histos[folder+'/jetN_30'].Fill(row.jetVeto30, row.EmbPtWeight*frweight) + histos[folder+'/jetN_20'].Fill(row.jetVeto20, frweight) + histos[folder+'/jetN_30'].Fill(row.jetVeto30, frweight) else: # if it is TauTight if not f.startswith('os') and not f.startswith('ss') : # if the dir name start with mVeto, eVeto or tVeto I don't want the different weight of MC corrections @@ -391,106 +391,107 @@ def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): if n >0 : break folder = d+f + weight[n] = row.EmbPtWeight*weight[n] if f=='os/gg/ept30' : - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, weight[n]) continue - histos[folder+'/tPt'].Fill(row.tPt, row.EmbPtWeight*weight[n]) - histos[folder+'/tEta'].Fill(row.tEta, row.EmbPtWeight*weight[n]) - histos[folder+'/tPhi'].Fill(row.tPhi, row.EmbPtWeight*weight[n]) - histos[folder+'/ePt'].Fill(row.ePt, row.EmbPtWeight*weight[n]) - histos[folder+'/eEta'].Fill(row.eEta, row.EmbPtWeight*weight[n]) - histos[folder+'/ePhi'].Fill(row.ePhi, row.EmbPtWeight*weight[n]) - histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, row.EmbPtWeight*weight[n]) + histos[folder+'/tPt'].Fill(row.tPt, weight[n]) + histos[folder+'/tEta'].Fill(row.tEta, weight[n]) + histos[folder+'/tPhi'].Fill(row.tPhi, weight[n]) + histos[folder+'/ePt'].Fill(row.ePt, weight[n]) + histos[folder+'/eEta'].Fill(row.eEta, weight[n]) + histos[folder+'/ePhi'].Fill(row.ePhi, weight[n]) + histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), weight[n]) + histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, weight[n]) - histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*weight[n]) - histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) + histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*weight[n]) - histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, row.EmbPtWeight*weight[n]) - histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) + histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) + histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), weight[n]) + histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) + histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, row.EmbPtWeight*weight[n]) + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, weight[n]) - histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, row.EmbPtWeight*weight[n]) - histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, row.EmbPtWeight*weight[n]) + histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, weight[n]) + histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, weight[n]) - histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) + histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) + histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), weight[n]) - histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, row.EmbPtWeight*weight[n]) - histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, row.EmbPtWeight*weight[n]) - histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, row.EmbPtWeight*weight[n]) + histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, weight[n]) + histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, weight[n]) + histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, weight[n]) - histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.EmbPtWeight*weight[n]) - histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.EmbPtWeight*weight[n]) + histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), weight[n]) + histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), weight[n]) + histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), weight[n]) - histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, row.EmbPtWeight*weight[n]) - histos[folder+'/tPFMET_Mt_Ty1'].Fill(row.tMtToPfMet_Ty1, row.EmbPtWeight*weight[n]) - histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, row.EmbPtWeight*weight[n]) + histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, weight[n]) + histos[folder+'/tPFMET_Mt_Ty1'].Fill(row.tMtToPfMet_Ty1, weight[n]) + histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, weight[n]) - histos[folder+'/jetN_20'].Fill(row.jetVeto20, row.EmbPtWeight*weight[n]) - histos[folder+'/jetN_30'].Fill(row.jetVeto30, row.EmbPtWeight*weight[n]) + histos[folder+'/jetN_20'].Fill(row.jetVeto20, weight[n]) + histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight[n]) if n == 0: # if I'm in the dir starting with os or ss I want also the energy scale uncertainties - histos[folder+'/h_collmass_pfmet_jes_plus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_plus_Phi), row.EmbPtWeight*weight[n]) - histos[folder+'/h_collmass_pfmet_jes_minus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_minus_Phi), row.EmbPtWeight*weight[n]) + histos[folder+'/h_collmass_pfmet_jes_plus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_plus_Phi), weight[n]) + histos[folder+'/h_collmass_pfmet_jes_minus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_minus_Phi), weight[n]) ### add the minus in the ntuple. - #histos[folder+'/h_collmass_pfmet_mes_plus'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), row.EmbPtWeight*weight[n]) - #histos[folder+'/h_collmass_pfmet_tes_plus'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), row.EmbPtWeight*weight[n]) - #histos[folder+'/h_collmass_pfmet_ees_plus'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), row.EmbPtWeight*weight[n]) - #histos[folder+'/h_collmass_pfmet_ues_plus'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), row.EmbPtWeight*weight[n]) + #histos[folder+'/h_collmass_pfmet_mes_plus'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), weight[n]) + #histos[folder+'/h_collmass_pfmet_tes_plus'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), weight[n]) + #histos[folder+'/h_collmass_pfmet_ees_plus'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), weight[n]) + #histos[folder+'/h_collmass_pfmet_ues_plus'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), weight[n]) - histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, row.EmbPtWeight*weight[n]) - histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, row.EmbPtWeight*weight[n]) + histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, weight[n]) + histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, weight[n]) - histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus,row.EmbPtWeight*weight[n]) - histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, row.EmbPtWeight*weight[n]) + histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus,weight[n]) + histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, weight[n]) - histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus,row.EmbPtWeight*weight[n]) - histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, row.EmbPtWeight*weight[n]) + histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus,weight[n]) + histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, weight[n]) - histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus,row.EmbPtWeight*weight[n]) - histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, row.EmbPtWeight*weight[n]) + histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus,weight[n]) + histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, weight[n]) - histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus,row.EmbPtWeight*weight[n]) - histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, row.EmbPtWeight*weight[n]) + histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus,weight[n]) + histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, weight[n]) - histos[folder+'/tPFMET_Mt_jes_plus'].Fill(row.tMtToPfMet_jes_plus,row.EmbPtWeight*weight[n]) - histos[folder+'/tPFMET_Mt_mes_plus'].Fill(row.tMtToPfMet_mes_plus,row.EmbPtWeight*weight[n]) - histos[folder+'/tPFMET_Mt_ees_plus'].Fill(row.tMtToPfMet_ees_plus,row.EmbPtWeight*weight[n]) - histos[folder+'/tPFMET_Mt_tes_plus'].Fill(row.tMtToPfMet_tes_plus,row.EmbPtWeight*weight[n]) - histos[folder+'/tPFMET_Mt_ues_plus'].Fill(row.tMtToPfMet_ues_plus,row.EmbPtWeight*weight[n]) - histos[folder+'/tPFMET_Mt_jes_minus'].Fill(row.tMtToPfMet_jes_minus,row.EmbPtWeight*weight[n]) - histos[folder+'/tPFMET_Mt_mes_minus'].Fill(row.tMtToPfMet_mes_minus,row.EmbPtWeight*weight[n]) - histos[folder+'/tPFMET_Mt_ees_minus'].Fill(row.tMtToPfMet_ees_minus,row.EmbPtWeight*weight[n]) - histos[folder+'/tPFMET_Mt_tes_minus'].Fill(row.tMtToPfMet_tes_minus,row.EmbPtWeight*weight[n]) - histos[folder+'/tPFMET_Mt_ues_minus'].Fill(row.tMtToPfMet_ues_minus,row.EmbPtWeight*weight[n]) + histos[folder+'/tPFMET_Mt_jes_plus'].Fill(row.tMtToPfMet_jes_plus,weight[n]) + histos[folder+'/tPFMET_Mt_mes_plus'].Fill(row.tMtToPfMet_mes_plus,weight[n]) + histos[folder+'/tPFMET_Mt_ees_plus'].Fill(row.tMtToPfMet_ees_plus,weight[n]) + histos[folder+'/tPFMET_Mt_tes_plus'].Fill(row.tMtToPfMet_tes_plus,weight[n]) + histos[folder+'/tPFMET_Mt_ues_plus'].Fill(row.tMtToPfMet_ues_plus,weight[n]) + histos[folder+'/tPFMET_Mt_jes_minus'].Fill(row.tMtToPfMet_jes_minus,weight[n]) + histos[folder+'/tPFMET_Mt_mes_minus'].Fill(row.tMtToPfMet_mes_minus,weight[n]) + histos[folder+'/tPFMET_Mt_ees_minus'].Fill(row.tMtToPfMet_ees_minus,weight[n]) + histos[folder+'/tPFMET_Mt_tes_minus'].Fill(row.tMtToPfMet_tes_minus,weight[n]) + histos[folder+'/tPFMET_Mt_ues_minus'].Fill(row.tMtToPfMet_ues_minus,weight[n]) From a4caa7d0fe90cbf65202d880eafce98bb1c72c63 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Tue, 28 Oct 2014 11:41:03 -0500 Subject: [PATCH 125/192] update --- lfvetau/BasePlotter.py | 107 +++++++++++++++++++++++++------ lfvetau/LFVHETauAnalyzerMVA.py | 27 ++++---- lfvetau/plotRecoQuantitiesMVA.py | 22 ++++++- 3 files changed, 119 insertions(+), 37 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index 446b349d..8bdb46dd 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -28,6 +28,7 @@ import ROOT import glob from pdb import set_trace +from FinalStateAnalysis.PlotTools.THBin import zipBins def create_mapper(mapping): def _f(path): @@ -46,7 +47,6 @@ def histo_diff_quad(mc_err, *systematics): clone = mc_err.Clone() sys_up = [i for i, _ in systematics] sys_dw = [i for _, i in systematics] - #bin loop for ibin in range(nbins+2): #from uflow to oflow content = clone.GetBinContent(ibin) @@ -55,8 +55,10 @@ def histo_diff_quad(mc_err, *systematics): shifts_up = [abs(i.GetBinContent(ibin) - content) for i in sys_up] shifts_dw = [abs(i.GetBinContent(ibin) - content) for i in sys_dw] max_shift = [max(i, j) for i, j in zip(shifts_up, shifts_dw)] + #print shifts_up, shifts_dw, max_shift, error, content new_err = quad(error, *max_shift) + #print clone.GetTitle(), ibin, new_err, clone.GetBinContent(ibin) clone.SetBinError(ibin, new_err) return clone @@ -82,7 +84,7 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): self.blind_region=blind_region if self.blind_region: # Don't look at the SS all pass region - blinder = lambda x: BlindView(x, "os/.*",blind_in_range(*self.blind_region)) + blinder = lambda x: BlindView(x, "os/.*mass*",blind_in_range(*self.blind_region)) super(BasePlotter, self).__init__(files, lumifiles, outputdir, blinder, forceLumi=forceLumi) @@ -95,22 +97,25 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): '[WZ][WZ]Jets', #'Wplus*Jets_madgraph*', #superseded by fakes 'Z*jets_M50_skimmedLL', - 'Z*jets_M50_skimmedTT', + 'Z*jets_M50_skimmedTT' ] + if use_embedded: + self.mc_samples.pop() - self.views['Ztt_embedded'] = {'view' : self.make_embedded('os/gg/ept30/h_collmass_pfmet')} + self.views['ZetauEmbedded'] = {'view' : self.make_embedded('os/gg/ept30/h_collmass_pfmet')} def make_fakes(self): '''Sets up the fakes view''' data_view = self.get_view('data') central_fakes = views.SubdirectoryView(data_view, 'tLoose') up_fakes = views.SubdirectoryView(data_view, 'tLooseUp') + dw_fakes = views.SubdirectoryView(data_view, 'tLooseDown') style = data_styles['Fakes*'] return views.TitleView( views.StyleView( - MedianView(highv=up_fakes, centv=central_fakes), + MedianView(highv=up_fakes, lowv=dw_fakes, centv=central_fakes, maxdiff=True), **remove_name_entry(style) ), style['name'] @@ -126,9 +131,16 @@ def make_embedded(self, normalization_path): embed_int = embedded_histo.Integral() zjets_int = zjets_histo.Integral() + scale_factor = zjets_int / embed_int - scaled_view = views.ScaleView(embedded_view, scale_factor) + + scaled_view = views.TitleView( + views.StyleView(views.ScaleView(embedded_view, scale_factor), + **remove_name_entry(data_styles['ZetauEmbedded']) + ), + 'Z #rightarrow #tau#tau (embedded)' + ) return scaled_view def simpleplot_mc(self, folder, signal, variable, rebin=1, xaxis='', @@ -394,6 +406,8 @@ def add_shape_systematics(self, histo, path, view, folder_systematics = [], name folder_systematics is a list of tuples with the folders containing shifts (up, down) name_systematics is a list of tuples containing the postfix to obtain the shifts (up, down) ''' + + systematics = [] for sys_up, sys_dw in folder_systematics: h_up = view.Get(os.path.join(sys_up, path)) @@ -410,13 +424,27 @@ def add_shape_systematics(self, histo, path, view, folder_systematics = [], name (h_up, h_dw) ) + #ADD systematics return histo_diff_quad(histo, *systematics) + + + def add_histo_error(self, histo, histoerr): + clone = histo.GetStack().Last().Clone('errhist') + for bin in range(1,clone.GetXaxis().GetNbins()): + error = histoerr.GetBinError(bin)*clone.GetBinContent(bin)/histoerr.GetBinContent(bin) if histoerr.GetBinContent(bin) <>0 else histoerr.GetBinError(bin) + clone.SetBinError(bin, error ) + + return clone + + def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', leftside=True, xrange=None, preprocess=None, show_ratio=False, ratio_range=0.2, sort=True, obj=['e1', 'e2']): + + #xsection uncertainties #names must match with what defined in self.mc_samples xsec_unc_mapper = { @@ -428,10 +456,19 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', 'Z*jets_M50_skimmedTT' : 0.032, } + path = os.path.join(folder,variable) #make MC views with xsec error mc_views_nosys = self.mc_views(rebin, preprocess) + mc_views_noFake=[] + for view, name in zip(mc_views_nosys, self.mc_samples): + viewNoFake = views.SubdirectoryView(view, 'tLoose/') + mc_views_noFake.append(viewNoFake) + + mc_noFakeStack = views.SumView(*mc_views_noFake) + #mc_noFakes= mc_noFakeStack.Get(path) + mc_views = [] for view, name in zip(mc_views_nosys, self.mc_samples): new = SystematicsView( @@ -453,12 +490,12 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', ('p1s', 'm1s'), #PU correction ] - met_systematics = [ - ('_jes', '_jes_minus'), - ('_mes', '_mes_minus'), - ('_ees', '_ees_minus'), - ('_tes', '_tes_minus'), - ('_ues', '_ues_minus'), + met_systematics = [ #it was without plus + ('_jes_plus', '_jes_minus'), + ('_mes_plus', '_mes_minus'), + ('_ees_plus', '_ees_minus'), + ('_tes_plus', '_tes_minus'), + ('_ues_plus', '_ues_minus'), ] name_systematics = [] #which are not MET @@ -466,9 +503,10 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', if 'collmass' in variable.lower() or \ 'met' in variable.lower(): c = 1 - #name_systematics.extend(met_systematics) + #name_systematics.extend(met_systematics) # TO ADD WHEN RERUN WITH THE NEW BINNING #add them + mc_err = self.add_shape_systematics( mc_err, path, @@ -478,33 +516,44 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', #check if we are using the embedded sample if self.use_embedded: - embed_view = self.get_view('Ztt_embedded') + embed_view = self.get_view('ZetauEmbedded') if preprocess: embed_view = preprocess(embed_view) embed_view = RebinView( embed_view, rebin) + embed_view_noFake = views.SubdirectoryView(embed_view, 'tLoose/') + embed = embed_view.Get(path) + embed_NoFakes = embed_view_noFake.Get(path) + + #mc_noFakes+=embed_NoFakes + mc_views_noFake.append(embed_view_noFake) + + mc_noFakeStack = views.SumView( *mc_views_noFake) #add xsec error embed = SystematicsView.add_error( embed, xsec_unc_mapper['Z*jets_M50_skimmedTT']) - + #add them to backgrounds mc_stack.Add(embed) mc_err += embed + mc_sum_view = views.SumView(mc_sum_view, embed_view) #Add MC and embed systematics folder_systematics = [ ('trp1s', 'trm1s'), #trig scale factor ] - + + #print folder_systematics #Add as many eid sys as requested for name in obj: folder_systematics.extend([ ('%sidp1s' % name, '%sidm1s' % name), #eID scale factor ('%sisop1s' % name, '%sisop1s' % name), #e Iso scale factor ]) - + + mc_err = self.add_shape_systematics( mc_err, path, @@ -520,25 +569,37 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', fakes_view = preprocess(fakes_view) fakes_view = RebinView(fakes_view, rebin) + fakes_view = SubtractionView(fakes_view, mc_noFakeStack) fakes = fakes_view.Get(path) - + #add them to backgrounds mc_stack.Add(fakes) - mc_err += fakes + + mc_err.Sumw2() + mc_err.Add(fakes) #set_trace() + #add jet category uncertainty + mc_err = SystematicsView.add_error( mc_err, 0.05 ) + + #draw stack mc_stack.Draw() self.keep.append(mc_stack) #set cosmetics self.canvas.SetLogy(True) + #self.canvas.SetGridx(True) + #self.canvas.SetGridy(True) + #self.pad.SetGridx(True) + #self.pad.SetGridy(True) + mc_stack.GetHistogram().GetXaxis().SetTitle(xaxis) if xrange: mc_stack.GetXaxis().SetRangeUser(xrange[0], xrange[1]) mc_stack.Draw() - #set cosmetics and draw error + #set cosmetics mc_err.SetMarkerStyle(0) mc_err.SetLineColor(1) mc_err.SetFillStyle('x') @@ -546,6 +607,8 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', mc_err.Draw('pe2 same') self.keep.append(mc_err) + + #Get signal signals = [ 'ggHiggsToETau', @@ -578,7 +641,9 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', self.add_legend([data, mc_stack], leftside, entries=len(mc_stack.GetHists())+1) if show_ratio: - self.add_ratio_plot(data, mc_err, xrange, ratio_range, True) # add_ratio_diff(data, mc_stack, mc_err, xrange, ratio_range) + self.add_ratio_plot(data, mc_err, xrange, ratio_range, True) # add_ratio_diff(data, mc_stack, mc_err, xrange, ratio_range) + #self.add_ratio_plot(data, mc_stack, xrange, ratio_range, True) # add_ratio_diff(data, mc_stack, mc_err, xrange, ratio_range) + ##----- diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 377948ed..b8bf610d 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -176,17 +176,17 @@ def begin(self): self.book(f, "h_collmass_mvamet", "h_collmass_mvamet", 32, 0, 320) self.book(f, "h_collmass_pfmet_Ty1", "h_collmass_pfmet_Ty1", 32, 0, 320) - self.book(f, "h_collmass_pfmet_jes_plus", "h_collmass_pfmet_jes_plus", 50, 0, 100) - self.book(f, "h_collmass_pfmet_mes_plus", "h_collmass_pfmet_mes_plus", 50, 0, 100 ) - self.book(f, "h_collmass_pfmet_tes_plus", "h_collmass_pfmet_tes_plus", 50, 0, 100) - self.book(f, "h_collmass_pfmet_ees_plus", "h_collmass_pfmet_ees_plus", 50, 0, 100) - self.book(f, "h_collmass_pfmet_ues_plus", "h_collmass_pfmet_ues_plus", 50, 0, 100) - - self.book(f, "h_collmass_pfmet_jes_minus", "h_collmass_pfmet_jes_minus", 50, 0, 100) - self.book(f, "h_collmass_pfmet_mes_minus", "h_collmass_pfmet_mes_minus", 50, 0, 100 ) - self.book(f, "h_collmass_pfmet_tes_minus", "h_collmass_pfmet_tes_minus", 50, 0, 100) - self.book(f, "h_collmass_pfmet_ees_minus", "h_collmass_pfmet_ees_minus", 50, 0, 100) - self.book(f, "h_collmass_pfmet_ues_minus", "h_collmass_pfmet_ues_minus", 50, 0, 100) + self.book(f, "h_collmass_pfmet_jes_plus", "h_collmass_pfmet_jes_plus", 32, 0, 320) + self.book(f, "h_collmass_pfmet_mes_plus", "h_collmass_pfmet_mes_plus", 32, 0, 320) + self.book(f, "h_collmass_pfmet_tes_plus", "h_collmass_pfmet_tes_plus", 32, 0, 320) + self.book(f, "h_collmass_pfmet_ees_plus", "h_collmass_pfmet_ees_plus", 32, 0, 320) + self.book(f, "h_collmass_pfmet_ues_plus", "h_collmass_pfmet_ues_plus", 32, 0, 320) + + self.book(f, "h_collmass_pfmet_jes_minus", "h_collmass_pfmet_jes_minus", 32, 0, 320) + self.book(f, "h_collmass_pfmet_mes_minus", "h_collmass_pfmet_mes_minus", 32, 0, 320) + self.book(f, "h_collmass_pfmet_tes_minus", "h_collmass_pfmet_tes_minus", 32, 0, 320) + self.book(f, "h_collmass_pfmet_ees_minus", "h_collmass_pfmet_ees_minus", 32, 0, 320) + self.book(f, "h_collmass_pfmet_ues_minus", "h_collmass_pfmet_ues_minus", 32, 0, 320) self.book(f, "h_collmassSpread_pfmet", "h_collmassSpread_pfmet", 40, -100, 100) self.book(f, "h_collmassSpread_mvamet", "h_collmassSpread_mvamet", 40, -100, 100) @@ -278,14 +278,15 @@ def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): weight = self.event_weight(row) histos = self.histograms pudir =[''] - if row.run < 2: pudir.extend( ['p1s/', 'm1s/', 'trp1s/', 'trm1s/', 'eidp1s/','eidm1s/', 'eisop1s/','eisom1s/']) + if self.is_data == False : pudir.extend( ['p1s/', 'm1s/', 'trp1s/', 'trm1s/', 'eidp1s/','eidm1s/', 'eisop1s/','eisom1s/']) looseList = ['tLoose/', 'tLooseUp/', 'tLooseDown/', 'tLooseUnweight/'] if bool(isTauTight) == False: if f.startswith('os') or f.startswith('ss') : frweight_bv = frw[0]/(1.-frw[0]) - err = 0.3/pow(1-frw[0], 2) #tau pog told to mu-tau group to use 30% uncertainty on tau fake rate. + #err = 0.3*abs(2-frw[0]/pow(1-frw[0], 2)) #tau pog told to mu-tau group to use 30% uncertainty on tau fake rate. + err=0.3 frweight_p1s = frweight_bv*(1+err) frweight_m1s = frweight_bv*(1-err) fr_weights = [frweight_bv, frweight_p1s, frweight_m1s] diff --git a/lfvetau/plotRecoQuantitiesMVA.py b/lfvetau/plotRecoQuantitiesMVA.py index 396f7360..5f05582e 100644 --- a/lfvetau/plotRecoQuantitiesMVA.py +++ b/lfvetau/plotRecoQuantitiesMVA.py @@ -32,7 +32,9 @@ blind = 'blind' not in os.environ or os.environ['blind'] == 'YES' blind_region=[100, 150] if blind else None -plotter = BasePlotter(blind_region) +embedded = True + +plotter = BasePlotter(blind_region,use_embedded=embedded) signs = ['os', 'ss'] jets = ['0', '1', '2'] @@ -49,16 +51,30 @@ logging.debug("Starting plotting") for sign, proc, thr, njet in itertools.product(signs, processtype, threshold, jets): path = os.path.join(sign, proc, thr, njet) - plotter.set_subdir(path) + plotter.set_subdir(os.path.join('embedded',path)) if embedded else plotter.set_subdir(path) + for var, xlabel, rebin in histo_info: logging.debug("Plotting %s/%s" % (path, var) ) plotter.pad.SetLogy(False) #plotter.plot_without_uncert(foldername,h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.5, sort=True, obj=['e']) plotter.plot_with_bkg_uncert(path, var, rebin, xlabel, - leftside=False, show_ratio=True, ratio_range=0.5, + leftside=False, show_ratio=True, ratio_range=1., sort=True, obj=['e']) + plotter.save(var) + + plotter.set_subdir(os.path.join('embedded', path+'/selected'))if embedded else plotter.set_subdir(path+'/selected') + for var, xlabel, rebin in histo_info: + logging.debug("Plotting %s/%s" % (path, var) ) + plotter.pad.SetLogy(False) + plotter.plot_with_bkg_uncert(path+'/selected', var, rebin, xlabel, + leftside=False, show_ratio=True, ratio_range=1., + sort=True, obj=['e']) + + + plotter.save(var,dotroot=False) + From f8fd4480bb4f32b2dc425065801eadd204071b44 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 3 Nov 2014 04:13:37 -0600 Subject: [PATCH 126/192] bugfix --- lfvetau/LFVHETauAnalyzerMVA.py | 41 ++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 2cd578e0..1b8bf83c 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -1,7 +1,7 @@ from ETauTree import ETauTree import sys import logging -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.WARNING) import os from pdb import set_trace import ROOT @@ -18,6 +18,8 @@ import itertools import traceback from FinalStateAnalysis.PlotTools.decorators import memo +import FinalStateAnalysis.PlotTools.pytree as pytree +from FinalStateAnalysis.Utilities.struct import struct @memo def getVar(name, var): @@ -124,6 +126,7 @@ def __init__(self, tree, outfile, **kwargs): ), 'ePFMET_DeltaPhi' : lambda row, weight: (deltaPhi(row.ePhi, getattr(row, metphi())), weight), 'tPFMET_DeltaPhi' : lambda row, weight: (deltaPhi(row.tPhi, getattr(row, metphi())), weight), + 'evtInfo' : lambda row, weight: (struct(run=row.run,lumi=row.lumi,evt=row.evt,weight=weight), None) } for shift in self.systematics['met']: #patch name @@ -203,6 +206,13 @@ def book_with_sys(location, name, *args, **kwargs): self.book('os/gg/ept30/', "e_t_Mass", "h_vismass", 32, 0, 320) for f in folder: + self.book( + f, + 'evtInfo', 'evtInfo', + 'run/l:lumi/l:evt/l:weight/D', + type=pytree.PyTree + ) + self.book(f,"tPt", "tau p_{T}", 200, 0, 200) self.book(f,"tPhi", "tau phi", 100, -3.2, 3.2) self.book(f,"tEta", "tau eta", 50, -2.5, 2.5) @@ -359,7 +369,7 @@ def process(self): #Fill embedded sample normalization BEFORE the vetoes if not row.e_t_SS: - self.fill_histos('os/gg/ept30/', row, weight_map['']) + self.fill_histos('os/gg/ept30', row, weight_map['']) # it is better vetoing on b-jets after the histo for the DY embedded #bjet veto @@ -373,8 +383,9 @@ def process(self): jn = min(row.jetVeto30, 3) jn_jes_plus = min(row.jetVeto30jes_plus, 3) jn_jes_minus = min(row.jetVeto30jes_minus, 3) - jet_category = ['%i' % jn, '%i_jes_plus' % jn_jes_plus, '%i_jes_minus' % jn_jes_minus] + jet_category_names = ['%i' % jn, '%i_jes_plus' % jn_jes_plus, '%i_jes_minus' % jn_jes_minus] jet_categories = [jn, jn_jes_plus, jn_jes_minus] + passes_full_selection = False # # Full tight selection @@ -387,11 +398,13 @@ def process(self): if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue if row.tMtToPFMET > 50 : continue full_selection[idx].append('selected') + passes_full_selection = True elif njet == 1 : if row.tPt < 40: continue if row.ePt < 35 : continue if row.tMtToPFMET > 35 : continue full_selection[idx].append('selected') + passes_full_selection = True elif njet == 2 : if row.tPt < 40: continue if row.ePt < 30 : continue # no cut as only electrons with pt>30 are in the ntuples @@ -399,11 +412,13 @@ def process(self): if row.vbfMass < 550 : continue if row.vbfDeta < 3.5 : continue full_selection[idx].append('selected') + passes_full_selection = True - logging.debug('Passed full selection') + if passes_full_selection: + logging.debug('Passed full selection') jet_directories = [] - for jet_dir, sel_dir in zip(jet_category, full_selection): + for jet_dir, sel_dir in zip(jet_category_names, full_selection): jet_directories.extend( [os.path.join(jet_dir, i) for i in sel_dir] ) @@ -418,15 +433,16 @@ def process(self): # # Lepton vetoes # - tvetoes = [row.tauVetoPt20EleTight3MuLoose, row.tauVetoPt20EleTight3MuLoose_tes_minus, row.tauVetoPt20EleTight3MuLoose_tes_plus] - mvetoes = [row.muVetoPt5IsoIdVtx, row.muVetoPt5IsoIdVtx_mes_minus, row.muVetoPt5IsoIdVtx_mes_plus] - evetoes = [row.eVetoCicLooseIso, row.eVetoCicLooseIso_ees_minus, row.eVetoCicLooseIso_ees_plus] + tvetoes = [row.tauVetoPt20EleTight3MuLoose, row.tauVetoPt20EleTight3MuLoose_tes_plus, row.tauVetoPt20EleTight3MuLoose_tes_minus] + mvetoes = [row.muVetoPt5IsoIdVtx , row.muVetoPt5IsoIdVtx_mes_plus , row.muVetoPt5IsoIdVtx_mes_minus ] + evetoes = [row.eVetoCicLooseIso , row.eVetoCicLooseIso_ees_plus , row.eVetoCicLooseIso_ees_minus ] tdirs = [ i for i, j in zip( systematics['tvetos'], tvetoes) if not j] mdirs = [ i for i, j in zip( systematics['mvetos'], mvetoes) if not j] edirs = [ i for i, j in zip( systematics['evetos'], evetoes) if not j] #if any of the lists is empty + #set_trace() if not tdirs or not mdirs or not edirs: continue logging.debug('Passed Vetoes') @@ -438,6 +454,8 @@ def process(self): all_dirs = [i for i in all_dirs if i in veto_sys] sys_directories = all_dirs + sys_shifts + #remove duplicates + sys_directories = list(set(sys_directories)) if not isTauTight: #if is a loose tau just compute the fakes! sys_directories = tau_id_category @@ -452,6 +470,10 @@ def process(self): weight_map[i] *= mc_weight #Fill histograms in appropriate direcotries + #if passes_full_selection: + #dirs = [os.path.join(sys, sign, processtype, e_thr, jet_dir) for sys, e_thr, jet_dir in itertools.product(sys_directories, ptthreshold, jet_directories)] + #if len(dirs) <> len(set(dirs)): + # set_trace() for sys, e_thr, jet_dir in itertools.product(sys_directories, ptthreshold, jet_directories): #if we fill a histogram, lock the event lock = evt_id @@ -459,7 +481,8 @@ def process(self): e_thr, jet_dir) if dir_name[-1] == '/': dir_name = dir_name[:-1] - logging.debug('Filling %s' % dir_name) + if passes_full_selection: + logging.debug('Filling %s' % dir_name) #fill them! weight_to_use = weight_map[sys] if sys in weight_map else weight_map[''] self.fill_histos(dir_name, row, weight_to_use) From bc06cf3dbd16d41a65072ad67cbf6f394c1f9f40 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Tue, 4 Nov 2014 08:01:05 -0600 Subject: [PATCH 127/192] bugfix --- lfvetau/LFVHETauAnalyzerMVA.py | 3 ++- lfvetau/mcCorrections.py | 12 +++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 1b8bf83c..8d7a53a2 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -383,8 +383,9 @@ def process(self): jn = min(row.jetVeto30, 3) jn_jes_plus = min(row.jetVeto30jes_plus, 3) jn_jes_minus = min(row.jetVeto30jes_minus, 3) - jet_category_names = ['%i' % jn, '%i_jes_plus' % jn_jes_plus, '%i_jes_minus' % jn_jes_minus] jet_categories = [jn, jn_jes_plus, jn_jes_minus] + jet_category_names = ['%i%s' % i for i in zip(jet_categories, systematics['jes'])] + passes_full_selection = False # diff --git a/lfvetau/mcCorrections.py b/lfvetau/mcCorrections.py index 91f3bd50..a1d5de32 100755 --- a/lfvetau/mcCorrections.py +++ b/lfvetau/mcCorrections.py @@ -85,12 +85,10 @@ def make_multiple(fcn, indexed=False, shift=0): def multiple(row,*args): ret = 1. for arg in args: - abseta = abs( - getattr( + abseta = getattr( row, getVar(arg,'Eta') ) - ) pt = getattr(row, getVar(arg,'Pt')) fcn_ret = fcn(pt,abseta) if indexed: @@ -109,19 +107,19 @@ def multiple(row,*args): ##put here the trigger correction as in https://github.com/mverzett/UWHiggs/blob/WH_At_Paper/wh/mcCorrectors.py -correct_e = make_multiple(HetauCorrection.correct_hamburg_e) -correct_eid13_mva = make_multiple(HetauCorrection.correct_eid13_mva) +correct_e = make_multiple(HetauCorrection.correct_hamburg_e ) +correct_eid13_mva = make_multiple(HetauCorrection.correct_eid13_mva ) correct_eid13_p1s_mva = make_multiple(HetauCorrection.correct_eid13_p1s_mva) correct_eid13_m1s_mva = make_multiple(HetauCorrection.correct_eid13_m1s_mva) -correct_eiso13_mva = make_multiple(HetauCorrection.correct_eiso13_mva) +correct_eiso13_mva = make_multiple(HetauCorrection.correct_eiso13_mva ) correct_eiso13_p1s_mva = make_multiple(HetauCorrection.correct_eiso13_p1s_mva) correct_eiso13_m1s_mva = make_multiple(HetauCorrection.correct_eiso13_m1s_mva) #correct_eid_mva = make_multiple(HetauCorrection.scale_eleId_hww) #correct_eReco_mva = make_multiple(HetauCorrection.scale_elereco_hww) #correct_eIso_mva = make_multiple(HetauCorrection.scale_eleIso_hww) -correct_trigger_mva = make_multiple(HetauCorrection.single_ele_mva, indexed=True) +correct_trigger_mva = make_multiple(HetauCorrection.single_ele_mva, indexed=True) correct_trigger_mva_up = make_multiple(HetauCorrection.single_ele_mva, indexed=True, shift=1) correct_trigger_mva_dw = make_multiple(HetauCorrection.single_ele_mva, indexed=True, shift=-1) From 5f4f7329b39a585d00623b1c8e09619331d0fd4a Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Wed, 5 Nov 2014 03:02:26 -0600 Subject: [PATCH 128/192] code update --- lfvetau/BasePlotter.py | 16 +- lfvetau/LFVHETauAnalyzerMVA.py | 286 +++++++++++++++++++++++-------- lfvetau/Rakefile | 75 ++++---- lfvetau/jobid.sh | 1 + lfvetau/plotRecoQuantitiesMVA.py | 4 +- lfvetau/setup.sh | 2 +- 6 files changed, 274 insertions(+), 110 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index 8bdb46dd..b2fac705 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -406,8 +406,7 @@ def add_shape_systematics(self, histo, path, view, folder_systematics = [], name folder_systematics is a list of tuples with the folders containing shifts (up, down) name_systematics is a list of tuples containing the postfix to obtain the shifts (up, down) ''' - - + systematics = [] for sys_up, sys_dw in folder_systematics: h_up = view.Get(os.path.join(sys_up, path)) @@ -502,8 +501,9 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', #add MET sys if necessary if 'collmass' in variable.lower() or \ 'met' in variable.lower(): - c = 1 - #name_systematics.extend(met_systematics) # TO ADD WHEN RERUN WITH THE NEW BINNING + if not variable.lower().startswith('type1'): + c = 1 + name_systematics.extend(met_systematics) # TO ADD WHEN RERUN WITH THE NEW BINNING #add them @@ -580,7 +580,13 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', #set_trace() #add jet category uncertainty - mc_err = SystematicsView.add_error( mc_err, 0.05 ) + jetcat_unc_mapper = { + 0 : 0.017, + 1 : 0.035, + 2 : 0.05 + } + jetn = folder[len(folder)-1:] if not '/selected' in folder else folder[len(folder)-10:len(folder)-9] + mc_err = SystematicsView.add_error( mc_err, jetcat_unc_mapper.get(jetn, 0. )) #draw stack diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index b8bf610d..ae527b24 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -11,7 +11,7 @@ from FinalStateAnalysis.PlotTools.MegaBase import MegaBase from math import sqrt, pi, cos from fakerate_functions import fakerate_central_histogram, fakerate_p1s_histogram, fakerate_m1s_histogram - +from FinalStateAnalysis.Utilities.struct import struct @@ -89,6 +89,7 @@ def event_weight(self, row): eisoUp_mcCorrections= eisoUp_mcCorrections * mcCorrections.get_trigger_efficiency_MVA(row,'e') eisoDown_mcCorrections= eisoDown_mcCorrections* mcCorrections.get_trigger_efficiency_MVA(row,'e') + return [allmcCorrections, allmcCorrections, allmcCorrections, trUp_mcCorrections, trDown_mcCorrections ,eidUp_mcCorrections, eidDown_mcCorrections, eisoUp_mcCorrections,eisoDown_mcCorrections] @@ -131,6 +132,8 @@ def event_weight(self, row): weight_eiso_down = self.pucorrector(row.nTruePU) *\ eisoDown_mcCorrections + #if row.evt == 76 : + # print row.evt, weight, self.pucorrector(row.nTruePU) , allmcCorrections, mcCorrections.get_trigger_corrections_MVA(row,'e') , mcCorrections.get_electronId_corrections13_MVA(row, 'e'), mcCorrections.get_electronIso_corrections13_MVA(row, 'e') return [weight, weight_up, weight_down, weight_tr_up, weight_tr_down, weight_eid_up, weight_eid_down, weight_eiso_up, weight_eiso_down] @@ -161,6 +164,13 @@ def begin(self): for f in folder: + self.book( + f, + 'evtInfo', 'evtInfo', + 'run/l:lumi/l:evt/l:weight/D', + type=pytree.PyTree + ) + self.book(f,"tPt", "tau p_{T}", 200, 0, 200) self.book(f,"tPhi", "tau phi", 100, -3.2, 3.2) self.book(f,"tEta", "tau eta", 50, -2.5, 2.5) @@ -202,11 +212,48 @@ def begin(self): self.book(f, "h_collmass_vs_dPhi_mvamet", "h_collmass_vs_dPhi_mvamet", 50, 0, 3.2, 32, 0, 320, type=ROOT.TH2F) self.book(f, "h_collmassSpread_vs_dPhi_pfmet", "h_collmassSpread_vs_dPhi_pfmet", 50, 0, 3.2, 20, -100, 100, type=ROOT.TH2F) self.book(f, "h_collmassSpread_vs_dPhi_mvamet", "h_collmassSpread_vs_dPhi_mvamet", 50, 0, 3.2, 20, -100, 100, type=ROOT.TH2F) + + self.book(f, "h_vismass", "h_vismass", 32, 0, 320) - self.book(f, "type1_pfMetEt_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 50, 0, 3.2, 64, 0, 320, type=ROOT.TH2F) - self.book(f, "mvaMetEt_vs_dPhi", "MVAMet vs #Delta#phi(#tau,MVAMet)", 50, 0, 3.2, 64, 0, 320, type=ROOT.TH2F) + self.book(f, "type1_pfMet_Et", "PFMet", 200, 0, 200) + self.book(f, "pfMet_Et", "PFMet", 200, 0, 200) + self.book(f, "type1_pfMet_Phi", "PFMet #phi", 100, -3.2, 3.2) + self.book(f, "pfMet_Phi", "PFMet #phi", 100, -3.2, 3.2) + + self.book(f, "pfMet_Et_ees_minus", "pfMet_Et_ees_minus", 200, 0, 200) + self.book(f, "pfMet_Et_jes_minus", "pfMet_Et_jes_minus", 200, 0, 200) + self.book(f, "pfMet_Et_mes_minus", "pfMet_Et_mes_minus", 200, 0, 200) + self.book(f, "pfMet_Et_tes_minus", "pfMet_Et_tes_minus", 200, 0, 200) + self.book(f, "pfMet_Et_ues_minus", "pfMet_Et_ues_minus", 200, 0, 200) + + + self.book(f, "pfMet_Et_jes_plus", "pfMet_Et_jes_plus", 200, 0, 200) + self.book(f, "pfMet_Et_ees_plus", "pfMet_Et_ees_plus", 200, 0, 200) + self.book(f, "pfMet_Et_mes_plus", "pfMet_Et_mes_plus", 200, 0, 200) + self.book(f, "pfMet_Et_tes_plus", "pfMet_Et_tes_plus", 200, 0, 200) + self.book(f, "pfMet_Et_ues_plus", "pfMet_Et_ues_plus", 200, 0, 200) + + self.book(f, "pfMet_Phi_ees_plus", "pfMet_Phi_ees_plus", 100, -3.2, 3.2) + self.book(f, "pfMet_Phi_jes_plus", "pfMet_Phi_jes_plus", 100, -3.2, 3.2) + self.book(f, "pfMet_Phi_mes_plus", "pfMet_Phi_mes_plus", 100, -3.2, 3.2) + self.book(f, "pfMet_Phi_tes_plus", "pfMet_Phi_tes_plus", 100, -3.2, 3.2) + self.book(f, "pfMet_Phi_ues_plus", "pfMet_Phi_ues_plus", 100, -3.2, 3.2) + + self.book(f, "pfMet_Phi_ees_minus", "pfMet_Phi_ees_minus", 100, -3.2, 3.2) + self.book(f, "pfMet_Phi_jes_minus", "pfMet_Phi_jes_minus", 100, -3.2, 3.2) + self.book(f, "pfMet_Phi_mes_minus", "pfMet_Phi_mes_minus", 100, -3.2, 3.2) + self.book(f, "pfMet_Phi_tes_minus", "pfMet_Phi_tes_minus", 100, -3.2, 3.2) + self.book(f, "pfMet_Phi_ues_minus", "pfMet_Phi_ues_minus", 100, -3.2, 3.2) + + #self.book(f, "pfMet_jes_Et", "pfMet_jes_Et", 200, 0, 200) + #self.book(f, "pfMet_jes_Phi", "pfMet_jes_Phi", 100, -3.2, 3.2) + #self.book(f, "pfMet_ues_AtanToPhi", "pfMet_ues_AtanToPhi", 100, -3.2, 3.2) + + + self.book(f, "type1_pfMet_Et_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 50, 0, 3.2, 64, 0, 320, type=ROOT.TH2F) + self.book(f, "mvaMet_Et_vs_dPhi", "MVAMet vs #Delta#phi(#tau,MVAMet)", 50, 0, 3.2, 64, 0, 320, type=ROOT.TH2F) self.book(f, "tPFMET_DeltaPhi", "tau-PFMET DeltaPhi" , 50, 0, 3.2) self.book(f, "tPFMET_Mt", "tau-PFMET M_{T}" , 200, 0, 200) @@ -337,11 +384,57 @@ def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): #histos[folder+'/h_collmass_pfmet_tes'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), frweight) #histos[folder+'/h_collmass_pfmet_ees'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), frweight) #histos[folder+'/h_collmass_pfmet_ues'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), frweight) - + histos[folder+'/h_collmass_pfmet_ees_minus'].Fill(collmass(row, row.pfMet_ees_minus_Et, row.pfMet_ees_minus_Phi), frweight) + histos[folder+'/h_collmass_pfmet_ees_plus' ].Fill(collmass(row, row.pfMet_ees_plus_Et , row.pfMet_ees_plus_Phi ), frweight) + histos[folder+'/h_collmass_pfmet_jes_minus'].Fill(collmass(row, row.pfMet_jes_minus_Et, row.pfMet_jes_minus_Phi), frweight) + histos[folder+'/h_collmass_pfmet_jes_plus' ].Fill(collmass(row, row.pfMet_jes_plus_Et , row.pfMet_jes_plus_Phi ), frweight) + histos[folder+'/h_collmass_pfmet_mes_minus'].Fill(collmass(row, row.pfMet_mes_minus_Et, row.pfMet_mes_minus_Phi), frweight) + histos[folder+'/h_collmass_pfmet_mes_plus' ].Fill(collmass(row, row.pfMet_mes_plus_Et , row.pfMet_mes_plus_Phi ), frweight) + histos[folder+'/h_collmass_pfmet_tes_minus'].Fill(collmass(row, row.pfMet_tes_minus_Et, row.pfMet_tes_minus_Phi), frweight) + histos[folder+'/h_collmass_pfmet_tes_plus' ].Fill(collmass(row, row.pfMet_tes_plus_Et , row.pfMet_tes_plus_Phi ), frweight) + histos[folder+'/h_collmass_pfmet_ues_minus'].Fill(collmass(row, row.pfMet_ues_minus_Et, row.pfMet_ues_minus_Phi), frweight) + histos[folder+'/h_collmass_pfmet_ues_plus' ].Fill(collmass(row, row.pfMet_ues_plus_Et , row.pfMet_ues_plus_Phi ), frweight) + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, frweight) - histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, frweight) - histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, frweight) + + histos[folder+'/type1_pfMet_Et'].Fill(row.type1_pfMetEt, frweight) + histos[folder+'/pfMet_Et'].Fill(row.pfMetEt, frweight) + histos[folder+'/type1_pfMet_Phi'].Fill(row.type1_pfMetPhi, frweight) + histos[folder+'/pfMet_Phi'].Fill(row.pfMetPhi, frweight) + + histos[folder+'/pfMet_Et_ees_minus'].Fill( row.pfMet_ees_minus_Et , frweight) + histos[folder+'/pfMet_Et_jes_minus'].Fill( row.pfMet_jes_minus_Et , frweight) + histos[folder+'/pfMet_Et_mes_minus'].Fill( row.pfMet_mes_minus_Et , frweight) + histos[folder+'/pfMet_Et_tes_minus'].Fill( row.pfMet_tes_minus_Et , frweight) + histos[folder+'/pfMet_Et_ues_minus'].Fill( row.pfMet_ues_minus_Et , frweight) + + histos[folder+'/pfMet_Et_ees_plus'].Fill( row.pfMet_ees_plus_Et , frweight) + histos[folder+'/pfMet_Et_jes_plus'].Fill( row.pfMet_jes_plus_Et , frweight) + histos[folder+'/pfMet_Et_mes_plus'].Fill( row.pfMet_mes_plus_Et , frweight) + histos[folder+'/pfMet_Et_tes_plus'].Fill( row.pfMet_tes_plus_Et , frweight) + histos[folder+'/pfMet_Et_ues_plus'].Fill( row.pfMet_ues_plus_Et , frweight) + + + histos[folder+'/pfMet_Phi_ees_minus'].Fill(row.pfMet_ees_minus_Phi, frweight) + histos[folder+'/pfMet_Phi_jes_minus'].Fill(row.pfMet_jes_minus_Phi, frweight) + histos[folder+'/pfMet_Phi_mes_minus'].Fill(row.pfMet_mes_minus_Phi, frweight) + histos[folder+'/pfMet_Phi_tes_minus'].Fill(row.pfMet_tes_minus_Phi, frweight) + histos[folder+'/pfMet_Phi_ues_minus'].Fill(row.pfMet_ues_minus_Phi, frweight) + + histos[folder+'/pfMet_Phi_ees_plus'].Fill( row.pfMet_ees_plus_Phi , frweight) + histos[folder+'/pfMet_Phi_jes_plus'].Fill( row.pfMet_jes_plus_Phi , frweight) + histos[folder+'/pfMet_Phi_mes_plus'].Fill( row.pfMet_mes_plus_Phi , frweight) + histos[folder+'/pfMet_Phi_tes_plus'].Fill( row.pfMet_tes_plus_Phi , frweight) + histos[folder+'/pfMet_Phi_ues_plus'].Fill( row.pfMet_ues_plus_Phi , frweight) + + #histos[folder+'/pfMet_jes_Et'].Fill( row.pfMet_jes_Et , frweight) + #histos[folder+'/pfMet_jes_Phi'].Fill( row.pfMet_jes_Phi , frweight) + + #histos[folder+'/pfMet_ues_AtanToPhi'].Fill(rowpfMet_ues_AtanToPhi, frweight) + + histos[folder+'/type1_pfMet_Et_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, frweight) + histos[folder+'/mvaMet_Et_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, frweight) histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.pfMetPhi), frweight) histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), frweight) @@ -349,24 +442,6 @@ def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, frweight) histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, frweight) histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, frweight) - ##histos[folder+'/ePFMET_Mt_Ty1_ues_minus'].Fill(row.eMtToPfMet_Ty1_ues_minus, frweight) - ##histos[folder+'/ePFMET_Mt_Ty1_ues_plus'].Fill(row.eMtToPfMet_Ty1_ues_plus, frweight) - #histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, frweight) - #histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, frweight) - #histos[folder+'/ePFMET_Mt_jes'].Fill(row.eMtToPfMet_jes, frweight) - #histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus, frweight) - #histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, frweight) - #histos[folder+'/ePFMET_Mt_mes'].Fill(row.eMtToPfMet_mes, frweight) - #histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus, frweight) - #histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, frweight) - #histos[folder+'/ePFMET_Mt_ees'].Fill(row.eMtToPfMet_ees, frweight) - #histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus, frweight) - #histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, frweight) - #histos[folder+'/ePFMET_Mt_tes'].Fill(row.eMtToPfMet_tes, frweight) - #histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus, frweight) - #histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, frweight) - #histos[folder+'/ePFMET_Mt_ues'].Fill(row.eMtToPfMet_ues, frweight) - histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), frweight) @@ -374,12 +449,47 @@ def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), frweight) histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, frweight) histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, frweight) - #histos[folder+'/tPFMET_Mt_jes'].Fill(row.tMtToPfMet_jes, frweight) - #histos[folder+'/tPFMET_Mt_mes'].Fill(row.tMtToPfMet_mes, frweight) - #histos[folder+'/tPFMET_Mt_ees'].Fill(row.tMtToPfMet_ees, frweight) - #histos[folder+'/tPFMET_Mt_tes'].Fill(row.tMtToPfMet_tes, frweight) - #histos[folder+'/tPFMET_Mt_ues'].Fill(row.tMtToPfMet_ues, frweight) + histos[folder+'/h_collmass_pfmet_ees_minus'].Fill(collmass(row, row.pfMet_ees_minus_Et, row.pfMet_ees_minus_Phi), frweight) + histos[folder+'/h_collmass_pfmet_ees_plus' ].Fill(collmass(row, row.pfMet_ees_plus_Et , row.pfMet_ees_plus_Phi ), frweight) + histos[folder+'/h_collmass_pfmet_jes_minus'].Fill(collmass(row, row.pfMet_jes_minus_Et, row.pfMet_jes_minus_Phi), frweight) + histos[folder+'/h_collmass_pfmet_jes_plus' ].Fill(collmass(row, row.pfMet_jes_plus_Et , row.pfMet_jes_plus_Phi ), frweight) + histos[folder+'/h_collmass_pfmet_mes_minus'].Fill(collmass(row, row.pfMet_mes_minus_Et, row.pfMet_mes_minus_Phi), frweight) + histos[folder+'/h_collmass_pfmet_mes_plus' ].Fill(collmass(row, row.pfMet_mes_plus_Et , row.pfMet_mes_plus_Phi ), frweight) + histos[folder+'/h_collmass_pfmet_tes_minus'].Fill(collmass(row, row.pfMet_tes_minus_Et, row.pfMet_tes_minus_Phi), frweight) + histos[folder+'/h_collmass_pfmet_tes_plus' ].Fill(collmass(row, row.pfMet_tes_plus_Et , row.pfMet_tes_plus_Phi ), frweight) + histos[folder+'/h_collmass_pfmet_ues_minus'].Fill(collmass(row, row.pfMet_ues_minus_Et, row.pfMet_ues_minus_Phi), frweight) + histos[folder+'/h_collmass_pfmet_ues_plus' ].Fill(collmass(row, row.pfMet_ues_plus_Et , row.pfMet_ues_plus_Phi ), frweight) + + + histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus,frweight) + histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, frweight) + + histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus,frweight) + histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, frweight) + + histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus,frweight) + histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, frweight) + + histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus,frweight) + histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, frweight) + + histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus,frweight) + histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, frweight) + + histos[folder+'/tPFMET_Mt_jes_plus'].Fill(row.tMtToPfMet_jes_plus, frweight) + histos[folder+'/tPFMET_Mt_mes_plus'].Fill(row.tMtToPfMet_mes_plus, frweight) + histos[folder+'/tPFMET_Mt_ees_plus'].Fill(row.tMtToPfMet_ees_plus, frweight) + histos[folder+'/tPFMET_Mt_tes_plus'].Fill(row.tMtToPfMet_tes_plus, frweight) + histos[folder+'/tPFMET_Mt_ues_plus'].Fill(row.tMtToPfMet_ues_plus, frweight) + histos[folder+'/tPFMET_Mt_jes_minus'].Fill(row.tMtToPfMet_jes_minus,frweight) + histos[folder+'/tPFMET_Mt_mes_minus'].Fill(row.tMtToPfMet_mes_minus,frweight) + histos[folder+'/tPFMET_Mt_ees_minus'].Fill(row.tMtToPfMet_ees_minus,frweight) + histos[folder+'/tPFMET_Mt_tes_minus'].Fill(row.tMtToPfMet_tes_minus,frweight) + histos[folder+'/tPFMET_Mt_ues_minus'].Fill(row.tMtToPfMet_ues_minus,frweight) + + + histos[folder+'/jetN_20'].Fill(row.jetVeto20, frweight) histos[folder+'/jetN_30'].Fill(row.jetVeto30, frweight) @@ -398,6 +508,8 @@ def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): histos[folder+'/h_vismass'].Fill(row.e_t_Mass, weight[n]) continue + histos[folder+'/evtInfo'].Fill( struct(run=row.run,lumi=row.lumi,evt=row.evt,weight=weight[n])) + histos[folder+'/tPt'].Fill(row.tPt, weight[n]) histos[folder+'/tEta'].Fill(row.tEta, weight[n]) histos[folder+'/tPhi'].Fill(row.tPhi, weight[n]) @@ -431,12 +543,47 @@ def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - - + histos[folder+'/h_vismass'].Fill(row.e_t_Mass, weight[n]) + + histos[folder+'/type1_pfMet_Et'].Fill(row.type1_pfMetEt, weight[n]) + histos[folder+'/pfMet_Et'].Fill(row.pfMetEt, weight[n]) + histos[folder+'/type1_pfMet_Phi'].Fill(row.type1_pfMetPhi, weight[n]) + histos[folder+'/pfMet_Phi'].Fill(row.pfMetPhi,weight[n]) + + histos[folder+'/pfMet_Et_ees_minus'].Fill( row.pfMet_ees_minus_Et , weight[n]) + histos[folder+'/pfMet_Et_jes_minus'].Fill( row.pfMet_jes_minus_Et , weight[n]) + histos[folder+'/pfMet_Et_mes_minus'].Fill( row.pfMet_mes_minus_Et , weight[n]) + histos[folder+'/pfMet_Et_tes_minus'].Fill( row.pfMet_tes_minus_Et , weight[n]) + histos[folder+'/pfMet_Et_ues_minus'].Fill( row.pfMet_ues_minus_Et , weight[n]) - histos[folder+'/type1_pfMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, weight[n]) - histos[folder+'/mvaMetEt_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, weight[n]) + histos[folder+'/pfMet_Et_ees_plus'].Fill( row.pfMet_ees_plus_Et , weight[n]) + histos[folder+'/pfMet_Et_jes_plus'].Fill( row.pfMet_jes_plus_Et , weight[n]) + histos[folder+'/pfMet_Et_mes_plus'].Fill( row.pfMet_mes_plus_Et , weight[n]) + histos[folder+'/pfMet_Et_tes_plus'].Fill( row.pfMet_tes_plus_Et , weight[n]) + histos[folder+'/pfMet_Et_ues_plus'].Fill( row.pfMet_ues_plus_Et , weight[n]) + + + histos[folder+'/pfMet_Phi_ees_minus'].Fill(row.pfMet_ees_minus_Phi, weight[n]) + histos[folder+'/pfMet_Phi_jes_minus'].Fill(row.pfMet_jes_minus_Phi, weight[n]) + histos[folder+'/pfMet_Phi_mes_minus'].Fill(row.pfMet_mes_minus_Phi, weight[n]) + histos[folder+'/pfMet_Phi_tes_minus'].Fill(row.pfMet_tes_minus_Phi, weight[n]) + histos[folder+'/pfMet_Phi_ues_minus'].Fill(row.pfMet_ues_minus_Phi, weight[n]) + + histos[folder+'/pfMet_Phi_ees_plus'].Fill( row.pfMet_ees_plus_Phi , weight[n]) + histos[folder+'/pfMet_Phi_jes_plus'].Fill( row.pfMet_jes_plus_Phi , weight[n]) + histos[folder+'/pfMet_Phi_mes_plus'].Fill( row.pfMet_mes_plus_Phi , weight[n]) + histos[folder+'/pfMet_Phi_tes_plus'].Fill( row.pfMet_tes_plus_Phi , weight[n]) + histos[folder+'/pfMet_Phi_ues_plus'].Fill( row.pfMet_ues_plus_Phi , weight[n]) + + #histos[folder+'/pfMet_jes_Et'].Fill( row.pfMet_jes_Et , weight[n]) + #histos[folder+'/pfMet_jes_Phi'].Fill( row.pfMet_jes_Phi , weight[n]) + + #histos[folder+'/pfMet_ues_AtanToPhi'].Fill(row.pfMet_ues_AtanToPhi, weight[n]) + + + histos[folder+'/type1_pfMet_Et_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, weight[n]) + histos[folder+'/mvaMet_Et_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, weight[n]) histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) @@ -458,42 +605,45 @@ def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight[n]) - if n == 0: # if I'm in the dir starting with os or ss I want also the energy scale uncertainties - histos[folder+'/h_collmass_pfmet_jes_plus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_plus_Phi), weight[n]) - histos[folder+'/h_collmass_pfmet_jes_minus'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_minus_Phi), weight[n]) - ### add the minus in the ntuple. - #histos[folder+'/h_collmass_pfmet_mes_plus'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), weight[n]) - #histos[folder+'/h_collmass_pfmet_tes_plus'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), weight[n]) - #histos[folder+'/h_collmass_pfmet_ees_plus'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), weight[n]) - #histos[folder+'/h_collmass_pfmet_ues_plus'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), weight[n]) - - - histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, weight[n]) - histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, weight[n]) - - histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus,weight[n]) - histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, weight[n]) - - histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus,weight[n]) - histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, weight[n]) - - histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus,weight[n]) - histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, weight[n]) - - histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus,weight[n]) - histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, weight[n]) - - histos[folder+'/tPFMET_Mt_jes_plus'].Fill(row.tMtToPfMet_jes_plus,weight[n]) - histos[folder+'/tPFMET_Mt_mes_plus'].Fill(row.tMtToPfMet_mes_plus,weight[n]) - histos[folder+'/tPFMET_Mt_ees_plus'].Fill(row.tMtToPfMet_ees_plus,weight[n]) - histos[folder+'/tPFMET_Mt_tes_plus'].Fill(row.tMtToPfMet_tes_plus,weight[n]) - histos[folder+'/tPFMET_Mt_ues_plus'].Fill(row.tMtToPfMet_ues_plus,weight[n]) - histos[folder+'/tPFMET_Mt_jes_minus'].Fill(row.tMtToPfMet_jes_minus,weight[n]) - histos[folder+'/tPFMET_Mt_mes_minus'].Fill(row.tMtToPfMet_mes_minus,weight[n]) - histos[folder+'/tPFMET_Mt_ees_minus'].Fill(row.tMtToPfMet_ees_minus,weight[n]) - histos[folder+'/tPFMET_Mt_tes_minus'].Fill(row.tMtToPfMet_tes_minus,weight[n]) - histos[folder+'/tPFMET_Mt_ues_minus'].Fill(row.tMtToPfMet_ues_minus,weight[n]) + # if n == 0: # if I'm in the dir starting with os or ss I want also the energy scale uncertainties + histos[folder+'/h_collmass_pfmet_ees_minus'].Fill(collmass(row, row.pfMet_ees_minus_Et, row.pfMet_ees_minus_Phi), weight[n]) + histos[folder+'/h_collmass_pfmet_ees_plus' ].Fill(collmass(row, row.pfMet_ees_plus_Et , row.pfMet_ees_plus_Phi ), weight[n]) + histos[folder+'/h_collmass_pfmet_jes_minus'].Fill(collmass(row, row.pfMet_jes_minus_Et, row.pfMet_jes_minus_Phi), weight[n]) + histos[folder+'/h_collmass_pfmet_jes_plus' ].Fill(collmass(row, row.pfMet_jes_plus_Et , row.pfMet_jes_plus_Phi ), weight[n]) + histos[folder+'/h_collmass_pfmet_mes_minus'].Fill(collmass(row, row.pfMet_mes_minus_Et, row.pfMet_mes_minus_Phi), weight[n]) + histos[folder+'/h_collmass_pfmet_mes_plus' ].Fill(collmass(row, row.pfMet_mes_plus_Et , row.pfMet_mes_plus_Phi ), weight[n]) + histos[folder+'/h_collmass_pfmet_tes_minus'].Fill(collmass(row, row.pfMet_tes_minus_Et, row.pfMet_tes_minus_Phi), weight[n]) + histos[folder+'/h_collmass_pfmet_tes_plus' ].Fill(collmass(row, row.pfMet_tes_plus_Et , row.pfMet_tes_plus_Phi ), weight[n]) + histos[folder+'/h_collmass_pfmet_ues_minus'].Fill(collmass(row, row.pfMet_ues_minus_Et, row.pfMet_ues_minus_Phi), weight[n]) + histos[folder+'/h_collmass_pfmet_ues_plus' ].Fill(collmass(row, row.pfMet_ues_plus_Et , row.pfMet_ues_plus_Phi ), weight[n]) + + histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, weight[n]) + histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, weight[n]) + + histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus,weight[n]) + histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, weight[n]) + + histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus,weight[n]) + histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, weight[n]) + + histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus,weight[n]) + histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, weight[n]) + + histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus,weight[n]) + histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, weight[n]) + + histos[folder+'/tPFMET_Mt_jes_plus'].Fill(row.tMtToPfMet_jes_plus,weight[n]) + histos[folder+'/tPFMET_Mt_mes_plus'].Fill(row.tMtToPfMet_mes_plus,weight[n]) + histos[folder+'/tPFMET_Mt_ees_plus'].Fill(row.tMtToPfMet_ees_plus,weight[n]) + histos[folder+'/tPFMET_Mt_tes_plus'].Fill(row.tMtToPfMet_tes_plus,weight[n]) + histos[folder+'/tPFMET_Mt_ues_plus'].Fill(row.tMtToPfMet_ues_plus,weight[n]) + histos[folder+'/tPFMET_Mt_jes_minus'].Fill(row.tMtToPfMet_jes_minus,weight[n]) + histos[folder+'/tPFMET_Mt_mes_minus'].Fill(row.tMtToPfMet_mes_minus,weight[n]) + histos[folder+'/tPFMET_Mt_ees_minus'].Fill(row.tMtToPfMet_ees_minus,weight[n]) + histos[folder+'/tPFMET_Mt_tes_minus'].Fill(row.tMtToPfMet_tes_minus,weight[n]) + histos[folder+'/tPFMET_Mt_ues_minus'].Fill(row.tMtToPfMet_ues_minus,weight[n]) + diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index 6d81bb58..bbe25820 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -76,6 +76,8 @@ end $frfit_dir = "results/#{$jobid}/fakerate_fits" directory $frfit_dir +$frfit_dirMC = "results/#{$jobid}/fakerate_fits_MC" +directory $frfit_dirMC $efrfit_dir = "results/#{$jobid}/efakerate_fits" directory $efrfit_dir exponential = "scale*TMath::Exp(x*decay)+offset" @@ -112,20 +114,8 @@ efr_fits = Hash.new #mysamples = [ "zjets_skimmedLL", "zjets_skimmedTT"] #for s in mysamples -#fr_fits["t_os_tNoCuts_tTigh_tPt"] = Hash[ -# "samples" => Array["diboson", "dataSingleE"], -# "analyzer" => $fr_analyzer, -# "function" => pol0, -# "variables" => pol0_vars, -# #"rebin" => 1, -# "rebin" => $fr_binning, -# "range" => "30 200", -# "title" => "#tau p_{T} (GeV)", -# "min"=>"0", -# "max"=>"0.1" -# ] fr_fits["t_os_tLoose_tTigh_tPt"] = Hash[ - "samples" => Array["diboson", "dataSingleE"], + "samples" => Array["diboson", "dataSingleE", "zjets_skimmedLL"], "analyzer" => $fr_analyzer, #"function" => exponential, #"variables" => exponential_vars, @@ -139,7 +129,7 @@ fr_fits["t_os_tLoose_tTigh_tPt"] = Hash[ "max"=>"1" ] efr_fits["e_os_eLoose_eTigh_e3Pt"] = Hash[ - "samples" => Array["diboson", "dataSingleE"], + "samples" => Array["diboson", "dataSingleE", "zjets_skimmedLL"], "analyzer" => $efr_analyzer, #"function" => exponential, #"variables" => exponential_vars, @@ -153,20 +143,8 @@ efr_fits["e_os_eLoose_eTigh_e3Pt"] = Hash[ "max"=>"1.2" ] -#fr_fits["t_os_tNoCuts_tTigh_tAbsEta"] = Hash[ -# "samples" => Array["diboson", "dataSingleE"], -# "analyzer" => $fr_analyzer, -# "function" => pol2, -# "variables" => pol2_vars, -# "rebin" => 1, -# #"range" => "-2.3 2.3", -# "range" => "0 2.3", -# "title" => "#tau #eta", -# "min"=>"0", -# "max"=>"0.1" -# ] fr_fits["t_os_tLoose_tTigh_tAbsEta"] = Hash[ - "samples" => Array["diboson", "dataSingleE"], + "samples" => Array["diboson", "dataSingleE", "zjets_skimmedLL"], "analyzer" => $fr_analyzer, "function" => pol2, "variables" => pol2_vars, @@ -180,7 +158,7 @@ fr_fits["t_os_tLoose_tTigh_tAbsEta"] = Hash[ efr_fits["e_os_eLoose_eTigh_e3AbsEta"] = Hash[ - "samples" => Array["diboson", "dataSingleE"], + "samples" => Array["diboson", "dataSingleE", "zjets_skimmedLL"], "analyzer" => $efr_analyzer, "function" => pol2, "variables" => pol2_vars, @@ -196,7 +174,33 @@ efr_fits["e_os_eLoose_eTigh_e3AbsEta"] = Hash[ task :fits => [] +task :fitsMC => [] + task :efits => [] + +fr_fits.each do |fit, fit_info| + fit_configuration = fit.split("_") + sign = fit_configuration[1] + denom = fit_configuration[2] + num = fit_configuration[3] + var = fit_configuration[4] + + subsample_inputs = samples['zjets_skimmedLL'] + fit_output = $frfit_dirMC + "/#{fit}.root" + subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/#{fit_info['analyzer']}/#{x}.root"} + subsample_input_list = subsamples_inputs_result_list.join(" ") + denom_path = Array[sign, denom,var].join("/") + num_path = Array[sign, num, var].join("/") + + file fit_output => subsamples_inputs_result_list + [fit_info['analyzer'] + '.py'] do |t| + sh "mkdir -p #{$frfit_dirMC}" + sh "fit_efficiency_chi2.py #{fit_output} '#{num_path}' '#{denom_path}' \'#{pol0}\' \'#{pol0_vars}\' #{subsample_input_list} --plot --xrange #{fit_info['range']} --xtitle \'#{fit_info['title']}\' --min \'#{fit_info['min']}\' --max \'#{fit_info['max']}\' --show-error --rebin #{fit_info['rebin']} " + puts "" + end + + task :fits_MC => fit_output + +end fr_fits.each do |fit, fit_info| fit_configuration = fit.split("_") @@ -211,7 +215,7 @@ fr_fits.each do |fit, fit_info| end - fit_output = $efrfit_dir + "/#{fit}.root" + fit_output = $frfit_dir + "/#{fit}.root" subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/#{fit_info['analyzer']}/#{x}.root"} # subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/TauFakeRateAnalyzerMVA_eTight/#{x}.root"} subsample_input_list = subsamples_inputs_result_list.join(" ") @@ -299,9 +303,10 @@ task :genkinEMu => get_analyzer_results("LFVHAnalyzeGENEMu.py", samples['signalM task :recoplots => get_analyzer_results("LFVHETauAnalyzer.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'])# + samples['dataSingleE'] ) -task :recoplotsMVA => get_analyzer_results("LFVHETauAnalyzerMVA.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + - samples['Zembedded']+ - samples['dataSingleE'] ) +task :recoplotsMVA => get_analyzer_results("LFVHETauAnalyzerMVA.py", samples['signalMCgg']# + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + + #samples['Zembedded']+ + #samples['dataSingleE'] + ) task :recoplotsMVAeMtcut => get_analyzer_results("LFVHETauAnalyzerMVA_eMTCut.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + samples['dataSingleE'] ) @@ -320,12 +325,14 @@ task :fakeeet => get_analyzer_results("TauFakeRateAnalyzer.py", samples['signalM samples['wzjets'] + samples['zjets'] + samples['Zembedded']+samples['dataSingleE']) -task :fakeeetMVA => get_analyzer_results("TauFakeRateAnalyzerMVA.py",# samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['Zembedded']+ samples['zjets'] + +task :fakeeetMVA => get_analyzer_results("TauFakeRateAnalyzerMVA.py",# samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['Zembedded'] + + samples['zjets'] + samples['wwjets'] + samples['zzjets'] + samples['wzjets'] + samples['dataSingleE']) -task :fakeeeeMVA => get_analyzer_results("EleFakeRateAnalyzerMVA.py", #samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['zjets'] + samples['Zembedded']+ +task :fakeeeeMVA => get_analyzer_results("EleFakeRateAnalyzerMVA.py", #samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['Zembedded']+ + samples['zjets'] + samples['wwjets'] + samples['zzjets'] + samples['wzjets'] + samples['dataSingleE']) diff --git a/lfvetau/jobid.sh b/lfvetau/jobid.sh index adca46df..68cc2809 100644 --- a/lfvetau/jobid.sh +++ b/lfvetau/jobid.sh @@ -7,4 +7,5 @@ #export jobid8='newNtuple_1Oct' export jobidmt='MCntuples_8April' export jobid8='newNtuple_10Oct' +#export jobid8='newNtuple_16Oct' export jobidSync='newNtuple_Sync' diff --git a/lfvetau/plotRecoQuantitiesMVA.py b/lfvetau/plotRecoQuantitiesMVA.py index 5f05582e..cc15cb1f 100644 --- a/lfvetau/plotRecoQuantitiesMVA.py +++ b/lfvetau/plotRecoQuantitiesMVA.py @@ -36,7 +36,7 @@ plotter = BasePlotter(blind_region,use_embedded=embedded) -signs = ['os', 'ss'] +signs = ['os','ss'] jets = ['0', '1', '2'] processtype = ['gg'] threshold = ['ept30'] @@ -46,7 +46,7 @@ ('et_DeltaPhi', 'e#tau #Delta#phi', 1), ('et_DeltaR', 'e#tau #Delta R', 1), ('h_collmass_pfmet', 'M_{coll}(e#tau) (GeV)', 1), ('h_vismass', 'M_{vis} (GeV)', 1), ('jetN_30', 'number of jets (p_{T} > 30 GeV)', 1) , ('ePFMET_Mt', 'M_{T} e-PFMET', 5), - ('tPFMET_Mt', 'M_{T} #tau-PFMET', 5) ] + ('tPFMET_Mt', 'M_{T} #tau-PFMET', 5) , ('pfMet_Et', 'pfMet', 5)] logging.debug("Starting plotting") for sign, proc, thr, njet in itertools.product(signs, processtype, threshold, jets): diff --git a/lfvetau/setup.sh b/lfvetau/setup.sh index 8ac918c1..419b693c 100755 --- a/lfvetau/setup.sh +++ b/lfvetau/setup.sh @@ -16,7 +16,7 @@ rake "meta:getmeta[inputs/$jobid, eg/metaInfo, 8]" #export jobid='newNtuple_10Oct' echo $jobid -$jobid '{print $1}') +$jobid '{print $1}' #export datasrc=/nfs_scratch/taroni/data #export MEGAPATH=/nfs_scratch/taroni/data From 159512c4d54b5dffa040fe807b311219c30c805c Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Thu, 6 Nov 2014 05:05:21 -0600 Subject: [PATCH 129/192] code update --- lfvetau/LFVHETauAnalyzerMVA.py | 41 ++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 8d7a53a2..0f54295f 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -178,7 +178,7 @@ def begin(self): self.systematics['mvetos'] + \ self.systematics['tvetos'] + \ self.systematics['evetos'] + \ - ['tLoose', 'tLooseUp', 'tLooseDown', 'tLooseUnweight'] + ['tLoose/', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] sys_shifts = list( set( sys_shifts ) ) #remove double dirs processtype=['gg'] threshold=['ept30'] @@ -214,32 +214,55 @@ def book_with_sys(location, name, *args, **kwargs): ) self.book(f,"tPt", "tau p_{T}", 200, 0, 200) + self.book(f,"tPt_tes_plus", "tau p_{T} (tes+)", 200, 0, 200) + self.book(f,"tPt_tes_minus", "tau p_{T} (tes-)", 200, 0, 200) + self.book(f,"tPhi", "tau phi", 100, -3.2, 3.2) self.book(f,"tEta", "tau eta", 50, -2.5, 2.5) self.book(f,"ePt", "e p_{T}", 200, 0, 200) + self.book(f,"ePt_ees_plus", "e p_{T} (ees+)", 200, 0, 200) + self.book(f,"ePt_ees_minus", "e p_{T} (ees-)", 200, 0, 200) + self.book(f,"ePhi", "e phi", 100, -3.2, 3.2) self.book(f,"eEta", "e eta", 50, -2.5, 2.5) self.book(f, "e_t_DPhi", "e-tau DeltaPhi" , 50, 0, 3.2) self.book(f, "e_t_DR", "e-tau DeltaR" , 50, 0, 3.2) + + #self.book(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320) book_with_sys(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320, postfixes=self.systematics['met']) self.book(f, "h_collmass_vs_dPhi_pfmet", "h_collmass_vs_dPhi_pfmet", 50, 0, 3.2, 32, 0, 320, type=ROOT.TH2F) self.book(f, "e_t_Mass", "h_vismass", 32, 0, 320) + self.book(f, "e_t_Mass_tes_plus" , "h_vismass_tes_plus", 32, 0, 320) + self.book(f, "e_t_Mass_tes_minus", "h_vismass_tes_minus", 32, 0, 320) + self.book(f, "e_t_Mass_ees_plus" , "h_vismass_ees_plus", 32, 0, 320) + self.book(f, "e_t_Mass_ees_minus", "h_vismass_ees_minus", 32, 0, 320) self.book(f, "MetEt_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 50, 0, 3.2, 64, 0, 320, type=ROOT.TH2F) self.book(f, "tPFMET_DeltaPhi", "tau-type1PFMET DeltaPhi" , 50, 0, 3.2) + + self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 50, 0, 3.2) - #self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 50, 0, 3.2) - ## book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 200, 0, 200, - ## postfixes=self.systematics['met']) - ## book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 200, 0, 200, - ## postfixes=self.systematics['met']) + self.book(f,"tMtToPFMET", "tau-PFMET M_{T}" , 200, 0, 200) + #book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 200, 0, 200, + # postfixes=self.systematics['met']) + self.book(f,"eMtToPFMET", "e-PFMET M_{T}" , 200, 0, 200) + #book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 200, 0, 200, + # postfixes=self.systematics['met']) + + + self.book(f, "pfMetEt", "pfMetEt", 200, 0, 200) + #book_with_sys(f, "pfMet_Et", "pfMet_Et", 200, 0, 200, postfixes=self.systematics['met']) + + self.book(f, "pfMetPhi", "pfMetPhi", 100, -3.2, 3.2) + #book_with_sys(f, "pfMet_Phi", "pfMet_Phi", 100, -3.2, 3.2, postfixes=self.systematics['met']) + self.book(f, "jetVeto20", "Number of jets, p_{T}>20", 10, -0.5, 9.5) self.book(f, "jetVeto30", "Number of jets, p_{T}>30", 10, -0.5, 9.5) @@ -264,8 +287,8 @@ def fakerate_weights(self, tEta): frweight = { 'tLoose' : tLoose , - 'tLooseUp' : tLooseUp , - 'tLooseDown' : tLooseDown, + 'tLoose/Up' : tLooseUp , + 'tLoose/Down' : tLooseDown, 'tLooseUnweight' : 1., } @@ -376,7 +399,7 @@ def process(self): if row.bjetCSVVeto30!=0 : continue #tau ID, id Tau is tight then go in full selection, otherwise use for fakes - tau_id_category = [''] if row.tTightIso3Hits else ['tLoose', 'tLooseUp', 'tLooseDown', 'tLooseUnweight'] + tau_id_category = [''] if row.tTightIso3Hits else ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] isTauTight = bool(row.tTightIso3Hits) #jet category From 390b6852fd57b01f62bed9acc44ab35102e36da4 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Thu, 6 Nov 2014 05:13:13 -0600 Subject: [PATCH 130/192] LFVHETauAnalyzerMVA.py --- lfvetau/LFVHETauAnalyzerMVA.py | 1070 ++++++++++++-------------------- 1 file changed, 399 insertions(+), 671 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index ae527b24..0f54295f 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -1,5 +1,9 @@ from ETauTree import ETauTree +import sys +import logging +logging.basicConfig(stream=sys.stderr, level=logging.WARNING) import os +from pdb import set_trace import ROOT import math import glob @@ -10,10 +14,42 @@ from FinalStateAnalysis.PlotTools.decorators import memo_last from FinalStateAnalysis.PlotTools.MegaBase import MegaBase from math import sqrt, pi, cos -from fakerate_functions import fakerate_central_histogram, fakerate_p1s_histogram, fakerate_m1s_histogram +from fakerate_functions import tau_fake_rate, tau_fake_rate_up, tau_fake_rate_dw +import itertools +import traceback +from FinalStateAnalysis.PlotTools.decorators import memo +import FinalStateAnalysis.PlotTools.pytree as pytree from FinalStateAnalysis.Utilities.struct import struct +@memo +def getVar(name, var): + return name+var + +met_et = 'pfMet%sEt' +met_phi = 'pfMet%sPhi' + +@memo +def met(shift=''): + return met_et % shift + +@memo +def metphi(shift=''): + return met_phi % shift +def attr_getter(attribute): + '''return a function that gets an attribute''' + def f(row, weight): + return (getattr(row,attribute), weight) + return f + +def merge_functions(fcn_1, fcn_2): + '''merges two functions to become a TH2''' + def f(row, weight): + r1, w1 = fcn_1(row, weight) + r2, w2 = fcn_2(row, weight) + w = w1 if w1 and w2 else None + return ((r1, r2), w) + return f def collmass(row, met, metPhi): ptnu =abs(met*cos(deltaPhi(metPhi, row.tPhi))) @@ -27,28 +63,84 @@ def deltaPhi(phi1, phi2): return PHI else: return 2*pi-PHI + def deltaR(phi1, ph2, eta1, eta2): deta = eta1 - eta2 dphi = abs(phi1-phi2) if (dphi>pi) : dphi = 2*pi-dphi return sqrt(deta*deta + dphi*dphi); +def make_collmass_systematics(shift): + met_name = met(shift) + phi_name = metphi(shift) + def collmass_shifted(row, weight): + met = getattr(row, met_name) + phi = getattr(row, phi_name) + return collmass(row, met, phi), weight + return collmass_shifted + class LFVHETauAnalyzerMVA(MegaBase): tree = 'et/final/Ntuple' def __init__(self, tree, outfile, **kwargs): + logging.debug('LFVHETauAnalyzerMVA constructor') self.channel='ET' super(LFVHETauAnalyzerMVA, self).__init__(tree, outfile, **kwargs) self.tree = ETauTree(tree) self.out=outfile self.histograms = {} - self.pucorrector = mcCorrections.make_puCorrector('singlee') - self.pucorrectorUp = mcCorrections.make_puCorrectorUp('singlee') - self.pucorrectorDown = mcCorrections.make_puCorrectorDown('singlee') + + #understand what we are running target = os.path.basename(os.environ['megatarget']) self.is_data = target.startswith('data_') self.is_embedded = ('Embedded' in target) self.is_mc = not (self.is_data or self.is_embedded) + #systematics used + self.systematics = { + 'trig' : (['', 'trp1s', 'trm1s'] if not self.is_data else []), + 'pu' : (['', 'p1s', 'm1s'] if self.is_mc else []), + 'eid' : (['', 'eidp1s','eidm1s'] if not self.is_data else []), + 'eiso' : (['', 'eisop1s','eisom1s'] if not self.is_data else []), + 'jes' : (['', '_jes_plus','_jes_minus'] if self.is_mc else ['']), + 'mvetos': (['', 'mVetoUp', 'mVetoDown'] if self.is_mc else ['']), + 'tvetos': (['', 'tVetoUp', 'tVetoDown'] if self.is_mc else ['']), + 'evetos': (['', 'eVetoUp', 'eVetoDown'] if self.is_mc else ['']), + 'met' : ([ "_jes_plus_", "_mes_plus_", "_tes_plus_", "_ees_plus_", "_ues_plus_", "_jes_minus_", "_mes_minus_", "_tes_minus_", "_ees_minus_", "_ues_minus_"] if self.is_mc else []), + } + + #self filling histograms + coll_mass = make_collmass_systematics('') #no sys shift + self.histo_locations = {} #just a mapping of the histograms we have to avoid changing self.histograms indexing an screw other files + self.hfunc = { #maps the name of non-trivial histograms to a function to get the proper value, the function MUST have two args (evt and weight). Used in fill_histos later + 'nTruePU' : lambda row, weight: (row.nTruePU,None), + 'weight' : lambda row, weight: (weight,None) if weight is not None else (1.,None), + 'Event_ID': lambda row, weight: (array.array("f", [row.run,row.lumi,int(row.evt)/10**5,int(row.evt)%10**5] ), None), + 'h_collmass_pfmet' : coll_mass, + 'h_collmass_vs_dPhi_pfmet' : merge_functions( + attr_getter('tToMETDPhi'), + coll_mass + ), + 'MetEt_vs_dPhi' : merge_functions( + lambda row, weight: (deltaPhi(row.tPhi, getattr(row, metphi())), weight), + attr_getter('type1_pfMetEt') + ), + 'ePFMET_DeltaPhi' : lambda row, weight: (deltaPhi(row.ePhi, getattr(row, metphi())), weight), + 'tPFMET_DeltaPhi' : lambda row, weight: (deltaPhi(row.tPhi, getattr(row, metphi())), weight), + 'evtInfo' : lambda row, weight: (struct(run=row.run,lumi=row.lumi,evt=row.evt,weight=weight), None) + } + for shift in self.systematics['met']: + #patch name + postfix = shift[:-1] + self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + + #PU correctors + self.pucorrector = mcCorrections.make_shifted_weights( + mcCorrections.make_puCorrector('singlee'), + ['p1s', 'm1s'], + [mcCorrections.make_puCorrectorUp('singlee'), mcCorrections.make_puCorrectorDown('singlee')] + ) + self.trig_weight = mcCorrections.trig_efficiency if self.is_embedded else mcCorrections.trig_correction + @staticmethod def tau_veto(row): if not row.tAntiMuonLoose2 or not row.tAntiElectronMVA5Tight or not row.tDecayFinding : @@ -57,111 +149,61 @@ def tau_veto(row): @staticmethod def obj1_matches_gen(row): return row.eGenPdgId == -1*row.eCharge*11 + @staticmethod def obj3_matches_gen(row): return t.genDecayMode != -2 - - def event_weight(self, row): - if self.is_data: #FIXME! add tight ID correction - return [1.] - - allmcCorrections= mcCorrections.get_electronId_corrections13_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e') - trUp_mcCorrections = 1. - trDown_mcCorrections = 1. - eidUp_mcCorrections= mcCorrections.get_electronId_corrections13_p1s_MVA(row, 'e') *\ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e') - eidDown_mcCorrections= mcCorrections.get_electronId_corrections13_m1s_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e') - eisoUp_mcCorrections= mcCorrections.get_electronId_corrections13_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_p1s_MVA(row, 'e') - eisoDown_mcCorrections= mcCorrections.get_electronId_corrections13_m1s_MVA(row, 'e') * \ - mcCorrections.get_electronIso_corrections13_p1s_MVA(row, 'e') - - - if self.is_embedded: - allmcCorrections= allmcCorrections*mcCorrections.get_trigger_efficiency_MVA(row,'e') - trUp_mcCorrections = allmcCorrections*mcCorrections.get_trigger_efficiency_p1s_MVA(row,'e') - trDown_mcCorrections = allmcCorrections*mcCorrections.get_trigger_efficiency_m1s_MVA(row,'e') - eidUp_mcCorrections= eidUp_mcCorrections* mcCorrections.get_trigger_efficiency_MVA(row,'e') - eidDown_mcCorrections= eidDown_mcCorrections* mcCorrections.get_trigger_efficiency_MVA(row,'e') - eisoUp_mcCorrections= eisoUp_mcCorrections * mcCorrections.get_trigger_efficiency_MVA(row,'e') - eisoDown_mcCorrections= eisoDown_mcCorrections* mcCorrections.get_trigger_efficiency_MVA(row,'e') - - - return [allmcCorrections, allmcCorrections, allmcCorrections, trUp_mcCorrections, trDown_mcCorrections ,eidUp_mcCorrections, eidDown_mcCorrections, eisoUp_mcCorrections,eisoDown_mcCorrections] - - - - + def event_weight(self, row, sys_shifts): + if self.is_data: + return {'' : 1.} + + weights = {} + embedded_weight = row.EmbPtWeight if self.is_embedded else 1. + for shift in sys_shifts: + weights[shift] = embedded_weight *\ + mcCorrections.eid_correction( row, 'e', shift=shift) * \ + mcCorrections.eiso_correction(row, 'e', shift=shift) * \ + self.trig_weight(row, 'e', shift=shift) * \ + self.pucorrector(row.nTruePU, shift=shift) - else: - allmcCorrections= allmcCorrections * mcCorrections.get_trigger_corrections_MVA(row,'e') - - - trUp_mcCorrections = allmcCorrections* mcCorrections.get_trigger_corrections_p1s_MVA(row,'e') - trDown_mcCorrections = allmcCorrections* mcCorrections.get_trigger_corrections_m1s_MVA(row,'e') - - eidUp_mcCorrections= eidUp_mcCorrections* mcCorrections.get_trigger_corrections_MVA(row,'e') - eidDown_mcCorrections= eidDown_mcCorrections* mcCorrections.get_trigger_corrections_MVA(row,'e') - eisoUp_mcCorrections= eisoUp_mcCorrections * mcCorrections.get_trigger_corrections_MVA(row,'e') - eisoDown_mcCorrections= eisoDown_mcCorrections* mcCorrections.get_trigger_corrections_MVA(row,'e') - - #pucorrlist = self.pucorrector(row.nTruePU) - - weight = self.pucorrector(row.nTruePU) *\ - allmcCorrections - weight_up = self.pucorrectorUp(row.nTruePU) *\ - allmcCorrections - weight_down = self.pucorrectorDown(row.nTruePU) *\ - allmcCorrections - - weight_tr_up = self.pucorrector(row.nTruePU) *\ - trUp_mcCorrections - weight_tr_down = self.pucorrector(row.nTruePU) *\ - trDown_mcCorrections - - - weight_eid_up = self.pucorrector(row.nTruePU) *\ - eidUp_mcCorrections - weight_eid_down = self.pucorrector(row.nTruePU) *\ - eidDown_mcCorrections - weight_eiso_up = self.pucorrector(row.nTruePU) *\ - eisoUp_mcCorrections - weight_eiso_down = self.pucorrector(row.nTruePU) *\ - eisoDown_mcCorrections - - #if row.evt == 76 : - # print row.evt, weight, self.pucorrector(row.nTruePU) , allmcCorrections, mcCorrections.get_trigger_corrections_MVA(row,'e') , mcCorrections.get_electronId_corrections13_MVA(row, 'e'), mcCorrections.get_electronIso_corrections13_MVA(row, 'e') - - return [weight, weight_up, weight_down, weight_tr_up, weight_tr_down, weight_eid_up, weight_eid_down, weight_eiso_up, weight_eiso_down] - - + return weights ## def begin(self): - + logging.debug('Booking histograms directory tree') + sys_shifts = self.systematics['trig'] + \ + self.systematics['pu'] + \ + self.systematics['eid'] + \ + self.systematics['eiso'] + \ + self.systematics['mvetos'] + \ + self.systematics['tvetos'] + \ + self.systematics['evetos'] + \ + ['tLoose/', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + sys_shifts = list( set( sys_shifts ) ) #remove double dirs processtype=['gg'] threshold=['ept30'] - sign=['os', 'ss'] - jetN = ['0','0_jes_plus','0_jes_minus', '1','1_jes_plus','1_jes_minus', '2','2_jes_plus','2_jes_minus', '3','3_jes_plus','3_jes_minus'] - folder=[] - pudir = ['','p1s/', 'm1s/','trp1s/', 'trm1s/', 'eidp1s/','eidm1s/', 'eisop1s/','eisom1s/', 'mVetoUp/', 'mVetoDown/', 'eVetoUp/', 'eVetoDown/', 'tVetoUp/', 'tVetoDown/', 'tLoose/','tLooseUp/','tLooseDown/', 'tLooseUnweight/'] + signs =['os', 'ss'] + jetN = [''.join(i) for i in itertools.product(['0', '1', '2', '3'], self.systematics['jes'])] - for d in pudir : - for i in sign: - for j in processtype: - for k in threshold: - #folder.append(d+i+'/'+j+'/'+k) - for jn in jetN: - - folder.append(d+i+'/'+j+'/'+k +'/'+jn) - folder.append(d+i+'/'+j+'/'+k +'/'+jn+'/selected') - - self.book(d+'os/gg/ept30/', "h_collmass_pfmet" , "h_collmass_pfmet", 32, 0, 320) - self.book(d+'os/gg/ept30/', "h_vismass", "h_vismass", 32, 0, 320) - + folder=[] + for tuple_path in itertools.product(sys_shifts, signs, processtype, threshold, jetN): + folder.append(os.path.join(*tuple_path)) + path = list(tuple_path) + path.append('selected') + folder.append(os.path.join(*path)) + + def book_with_sys(location, name, *args, **kwargs): + postfixes = kwargs['postfixes'] + del kwargs['postfixes'] + self.book(location, name, *args, **kwargs) + for postfix in postfixes: + #patch name to be removed + fix = postfix[:-1] + self.book(location, name+fix, *args, **kwargs) + + self.book('os/gg/ept30/', "h_collmass_pfmet" , "h_collmass_pfmet", 32, 0, 320) + self.book('os/gg/ept30/', "e_t_Mass", "h_vismass", 32, 0, 320) for f in folder: self.book( @@ -170,618 +212,304 @@ def begin(self): 'run/l:lumi/l:evt/l:weight/D', type=pytree.PyTree ) - + self.book(f,"tPt", "tau p_{T}", 200, 0, 200) + self.book(f,"tPt_tes_plus", "tau p_{T} (tes+)", 200, 0, 200) + self.book(f,"tPt_tes_minus", "tau p_{T} (tes-)", 200, 0, 200) + self.book(f,"tPhi", "tau phi", 100, -3.2, 3.2) self.book(f,"tEta", "tau eta", 50, -2.5, 2.5) self.book(f,"ePt", "e p_{T}", 200, 0, 200) + self.book(f,"ePt_ees_plus", "e p_{T} (ees+)", 200, 0, 200) + self.book(f,"ePt_ees_minus", "e p_{T} (ees-)", 200, 0, 200) + self.book(f,"ePhi", "e phi", 100, -3.2, 3.2) self.book(f,"eEta", "e eta", 50, -2.5, 2.5) - self.book(f, "et_DeltaPhi", "e-tau DeltaPhi" , 50, 0, 3.2) - self.book(f, "et_DeltaR", "e-tau DeltaR" , 50, 0, 3.2) + self.book(f, "e_t_DPhi", "e-tau DeltaPhi" , 50, 0, 3.2) + self.book(f, "e_t_DR", "e-tau DeltaR" , 50, 0, 3.2) - self.book(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320) - self.book(f, "h_collmass_mvamet", "h_collmass_mvamet", 32, 0, 320) - self.book(f, "h_collmass_pfmet_Ty1", "h_collmass_pfmet_Ty1", 32, 0, 320) - - self.book(f, "h_collmass_pfmet_jes_plus", "h_collmass_pfmet_jes_plus", 32, 0, 320) - self.book(f, "h_collmass_pfmet_mes_plus", "h_collmass_pfmet_mes_plus", 32, 0, 320) - self.book(f, "h_collmass_pfmet_tes_plus", "h_collmass_pfmet_tes_plus", 32, 0, 320) - self.book(f, "h_collmass_pfmet_ees_plus", "h_collmass_pfmet_ees_plus", 32, 0, 320) - self.book(f, "h_collmass_pfmet_ues_plus", "h_collmass_pfmet_ues_plus", 32, 0, 320) - - self.book(f, "h_collmass_pfmet_jes_minus", "h_collmass_pfmet_jes_minus", 32, 0, 320) - self.book(f, "h_collmass_pfmet_mes_minus", "h_collmass_pfmet_mes_minus", 32, 0, 320) - self.book(f, "h_collmass_pfmet_tes_minus", "h_collmass_pfmet_tes_minus", 32, 0, 320) - self.book(f, "h_collmass_pfmet_ees_minus", "h_collmass_pfmet_ees_minus", 32, 0, 320) - self.book(f, "h_collmass_pfmet_ues_minus", "h_collmass_pfmet_ues_minus", 32, 0, 320) - - self.book(f, "h_collmassSpread_pfmet", "h_collmassSpread_pfmet", 40, -100, 100) - self.book(f, "h_collmassSpread_mvamet", "h_collmassSpread_mvamet", 40, -100, 100) - self.book(f, "h_collmassSpread_lowPhi_pfmet", "h_collmassSpread_lowPhi_pfmet", 40, -100, 100) - self.book(f, "h_collmassSpread_lowPhi_mvamet", "h_collmassSpread_lowPhi_mvamet", 40, -100, 100) - self.book(f, "h_collmassSpread_highPhi_pfmet", "h_collmassSpread_highPhi_pfmet", 40, -100, 100) - self.book(f, "h_collmassSpread_highPhi_mvamet", "h_collmassSpread_highPhi_mvamet", 40, -100, 100) - self.book(f, "h_collmass_lowPhi_pfmet", "h_collmass_lowPhi_pfmet", 32, 0, 320) - self.book(f, "h_collmass_lowPhi_mvamet", "h_collmass_lowPhi_mvamet", 32, 0, 320) - self.book(f, "h_collmass_highPhi_pfmet", "h_collmass_highPhi_pfmet", 32, 0, 320) - self.book(f, "h_collmass_highPhi_mvamet", "h_collmass_highPhi_mvamet", 32, 0, 320) - self.book(f, "h_collmass_vs_dPhi_pfmet", "h_collmass_vs_dPhi_pfmet", 50, 0, 3.2, 32, 0, 320, type=ROOT.TH2F) - self.book(f, "h_collmass_vs_dPhi_mvamet", "h_collmass_vs_dPhi_mvamet", 50, 0, 3.2, 32, 0, 320, type=ROOT.TH2F) - self.book(f, "h_collmassSpread_vs_dPhi_pfmet", "h_collmassSpread_vs_dPhi_pfmet", 50, 0, 3.2, 20, -100, 100, type=ROOT.TH2F) - self.book(f, "h_collmassSpread_vs_dPhi_mvamet", "h_collmassSpread_vs_dPhi_mvamet", 50, 0, 3.2, 20, -100, 100, type=ROOT.TH2F) - - - self.book(f, "h_vismass", "h_vismass", 32, 0, 320) - - self.book(f, "type1_pfMet_Et", "PFMet", 200, 0, 200) - self.book(f, "pfMet_Et", "PFMet", 200, 0, 200) - self.book(f, "type1_pfMet_Phi", "PFMet #phi", 100, -3.2, 3.2) - self.book(f, "pfMet_Phi", "PFMet #phi", 100, -3.2, 3.2) - - self.book(f, "pfMet_Et_ees_minus", "pfMet_Et_ees_minus", 200, 0, 200) - self.book(f, "pfMet_Et_jes_minus", "pfMet_Et_jes_minus", 200, 0, 200) - self.book(f, "pfMet_Et_mes_minus", "pfMet_Et_mes_minus", 200, 0, 200) - self.book(f, "pfMet_Et_tes_minus", "pfMet_Et_tes_minus", 200, 0, 200) - self.book(f, "pfMet_Et_ues_minus", "pfMet_Et_ues_minus", 200, 0, 200) - - - self.book(f, "pfMet_Et_jes_plus", "pfMet_Et_jes_plus", 200, 0, 200) - self.book(f, "pfMet_Et_ees_plus", "pfMet_Et_ees_plus", 200, 0, 200) - self.book(f, "pfMet_Et_mes_plus", "pfMet_Et_mes_plus", 200, 0, 200) - self.book(f, "pfMet_Et_tes_plus", "pfMet_Et_tes_plus", 200, 0, 200) - self.book(f, "pfMet_Et_ues_plus", "pfMet_Et_ues_plus", 200, 0, 200) - - self.book(f, "pfMet_Phi_ees_plus", "pfMet_Phi_ees_plus", 100, -3.2, 3.2) - self.book(f, "pfMet_Phi_jes_plus", "pfMet_Phi_jes_plus", 100, -3.2, 3.2) - self.book(f, "pfMet_Phi_mes_plus", "pfMet_Phi_mes_plus", 100, -3.2, 3.2) - self.book(f, "pfMet_Phi_tes_plus", "pfMet_Phi_tes_plus", 100, -3.2, 3.2) - self.book(f, "pfMet_Phi_ues_plus", "pfMet_Phi_ues_plus", 100, -3.2, 3.2) - - self.book(f, "pfMet_Phi_ees_minus", "pfMet_Phi_ees_minus", 100, -3.2, 3.2) - self.book(f, "pfMet_Phi_jes_minus", "pfMet_Phi_jes_minus", 100, -3.2, 3.2) - self.book(f, "pfMet_Phi_mes_minus", "pfMet_Phi_mes_minus", 100, -3.2, 3.2) - self.book(f, "pfMet_Phi_tes_minus", "pfMet_Phi_tes_minus", 100, -3.2, 3.2) - self.book(f, "pfMet_Phi_ues_minus", "pfMet_Phi_ues_minus", 100, -3.2, 3.2) - - #self.book(f, "pfMet_jes_Et", "pfMet_jes_Et", 200, 0, 200) - #self.book(f, "pfMet_jes_Phi", "pfMet_jes_Phi", 100, -3.2, 3.2) - #self.book(f, "pfMet_ues_AtanToPhi", "pfMet_ues_AtanToPhi", 100, -3.2, 3.2) - - - self.book(f, "type1_pfMet_Et_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 50, 0, 3.2, 64, 0, 320, type=ROOT.TH2F) - self.book(f, "mvaMet_Et_vs_dPhi", "MVAMet vs #Delta#phi(#tau,MVAMet)", 50, 0, 3.2, 64, 0, 320, type=ROOT.TH2F) - - self.book(f, "tPFMET_DeltaPhi", "tau-PFMET DeltaPhi" , 50, 0, 3.2) - self.book(f, "tPFMET_Mt", "tau-PFMET M_{T}" , 200, 0, 200) - self.book(f, "tPFMET_DeltaPhi_Ty1", "tau-type1PFMET DeltaPhi" , 50, 0, 3.2) - self.book(f, "tPFMET_Mt_Ty1", "tau-type1PFMET M_{T}" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_jes_plus', "tau-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_mes_plus', "tau-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_ees_plus', "tau-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_tes_plus', "tau-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_ues_plus', "tau-MVAMET M_{T} JES_plus" , 200, 0, 200) - - self.book(f, 'tPFMET_Mt_jes_minus', "tau-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_mes_minus', "tau-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_ees_minus', "tau-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_tes_minus', "tau-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'tPFMET_Mt_ues_minus', "tau-MVAMET M_{T} JES_minus" , 200, 0, 200) + #self.book(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320) + book_with_sys(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320, + postfixes=self.systematics['met']) + + self.book(f, "h_collmass_vs_dPhi_pfmet", "h_collmass_vs_dPhi_pfmet", 50, 0, 3.2, 32, 0, 320, type=ROOT.TH2F) - self.book(f, "tMVAMET_DeltaPhi", "tau-MVAMET DeltaPhi" , 50, 0, 3.2) - self.book(f, "tMVAMET_Mt", "tau-MVAMET M_{T}" , 200, 0, 200) - - self.book(f, "ePFMET_DeltaPhi_Ty1", "e-type1PFMET DeltaPhi" , 50, 0, 3.2) - self.book(f, "ePFMET_Mt_Ty1", "e-type1PFMET M_{T}" , 200, 0, 200) - self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 50, 0, 3.2) - self.book(f, "ePFMET_Mt", "e-PFMET M_{T}" , 200, 0, 200) - #self.book(f, 'ePFMET_Mt_jes', "e-MVAMET M_{T} JES" , 200, 0, 200) - #self.book(f, 'ePFMET_Mt_mes', "e-MVAMET M_{T} JES" , 200, 0, 200) - #self.book(f, 'ePFMET_Mt_ees', "e-MVAMET M_{T} JES" , 200, 0, 200) - #self.book(f, 'ePFMET_Mt_tes', "e-MVAMET M_{T} JES" , 200, 0, 200) - #self.book(f, 'ePFMET_Mt_ues', "e-MVAMET M_{T} JES" , 200, 0, 200) - #self.book(f, "ePFMET_Mt_Ty1_ues_minus", "e-type1PFMET M_{T} ues_minus" , 200, 0, 200) - #self.book(f, "ePFMET_Mt_Ty1_ues_plus", "e-type1PFMET M_{T} ues_plus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_jes_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_mes_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_ees_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_tes_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_ues_minus', "e-MVAMET M_{T} JES_minus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_jes_plus', "e-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_mes_plus', "e-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_ees_plus', "e-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_tes_plus', "e-MVAMET M_{T} JES_plus" , 200, 0, 200) - self.book(f, 'ePFMET_Mt_ues_plus', "e-MVAMET M_{T} JES_plus" , 200, 0, 200) - - self.book(f, "eMVAMET_DeltaPhi", "e-MVAMET DeltaPhi" , 50, 0, 3.2) - self.book(f, "eMVAMET_Mt", "e-MVAMET M_{T}" , 200, 0, 200) + self.book(f, "e_t_Mass", "h_vismass", 32, 0, 320) + self.book(f, "e_t_Mass_tes_plus" , "h_vismass_tes_plus", 32, 0, 320) + self.book(f, "e_t_Mass_tes_minus", "h_vismass_tes_minus", 32, 0, 320) + self.book(f, "e_t_Mass_ees_plus" , "h_vismass_ees_plus", 32, 0, 320) + self.book(f, "e_t_Mass_ees_minus", "h_vismass_ees_minus", 32, 0, 320) - self.book(f, "jetN_20", "Number of jets, p_{T}>20", 10, -0.5, 9.5) - self.book(f, "jetN_30", "Number of jets, p_{T}>30", 10, -0.5, 9.5) - - def fakerate_weights(self, tEta, central_weights, p1s_weights, m1s_weights): - frweight=[1.,1.,1.] - - #central_weights = fakerate_central_histogram(25,0, 2.5) - #p1s_weights = fakerate_central_histogram(25,0, 2.5) - #m1s_weights = fakerate_central_histogram(25,0, 2.5) - - for n,w in enumerate( central_weights ): - if abs(tEta) < w[1]: - break - frweight[0] = w[0] - frweight[1] = p1s_weights[n][0] - frweight[2] = m1s_weights[n][0] - - - return frweight; + self.book(f, "MetEt_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 50, 0, 3.2, 64, 0, 320, type=ROOT.TH2F) + self.book(f, "tPFMET_DeltaPhi", "tau-type1PFMET DeltaPhi" , 50, 0, 3.2) - - def fill_histos(self, row, f='os/gg/ept0/0', isTauTight=False, frw=[1.,1.,1.]): - weight = self.event_weight(row) - histos = self.histograms - pudir =[''] - if self.is_data == False : pudir.extend( ['p1s/', 'm1s/', 'trp1s/', 'trm1s/', 'eidp1s/','eidm1s/', 'eisop1s/','eisom1s/']) - looseList = ['tLoose/', 'tLooseUp/', 'tLooseDown/', 'tLooseUnweight/'] - - - if bool(isTauTight) == False: - if f.startswith('os') or f.startswith('ss') : - frweight_bv = frw[0]/(1.-frw[0]) - #err = 0.3*abs(2-frw[0]/pow(1-frw[0], 2)) #tau pog told to mu-tau group to use 30% uncertainty on tau fake rate. - err=0.3 - frweight_p1s = frweight_bv*(1+err) - frweight_m1s = frweight_bv*(1-err) - fr_weights = [frweight_bv, frweight_p1s, frweight_m1s] + self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 50, 0, 3.2) - for n, l in enumerate(looseList) : - frweight = weight[0]*fr_weights[n] if n < len(looseList)-1 else weight[0] - folder = l+f - frweight = row.EmbPtWeight*frweight - if f=='os/gg/ept30' : - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, frweight) - continue - - - histos[folder+'/tPt'].Fill(row.tPt, frweight) - histos[folder+'/tEta'].Fill(row.tEta, frweight) - histos[folder+'/tPhi'].Fill(row.tPhi, frweight) - histos[folder+'/ePt'].Fill(row.ePt, frweight) - histos[folder+'/eEta'].Fill(row.eEta, frweight) - histos[folder+'/ePhi'].Fill(row.ePhi, frweight) - histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), frweight) - histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, frweight) - histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - - histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, frweight) - histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, frweight) - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), frweight) - histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), frweight) - histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), frweight) - - #histos[folder+'/h_collmass_pfmet_jes'].Fill(collmass(row, row.pfMet_jes_Et, row.pfMet_jes_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_mes'].Fill(collmass(row, row.pfMet_mes_Et, row.pfMet_mes_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_tes'].Fill(collmass(row, row.pfMet_tes_Et, row.pfMet_tes_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_ees'].Fill(collmass(row, row.pfMet_ees_Et, row.pfMet_ees_Phi), frweight) - #histos[folder+'/h_collmass_pfmet_ues'].Fill(collmass(row, row.pfMet_ues_Et, row.pfMet_ues_Phi), frweight) - histos[folder+'/h_collmass_pfmet_ees_minus'].Fill(collmass(row, row.pfMet_ees_minus_Et, row.pfMet_ees_minus_Phi), frweight) - histos[folder+'/h_collmass_pfmet_ees_plus' ].Fill(collmass(row, row.pfMet_ees_plus_Et , row.pfMet_ees_plus_Phi ), frweight) - histos[folder+'/h_collmass_pfmet_jes_minus'].Fill(collmass(row, row.pfMet_jes_minus_Et, row.pfMet_jes_minus_Phi), frweight) - histos[folder+'/h_collmass_pfmet_jes_plus' ].Fill(collmass(row, row.pfMet_jes_plus_Et , row.pfMet_jes_plus_Phi ), frweight) - histos[folder+'/h_collmass_pfmet_mes_minus'].Fill(collmass(row, row.pfMet_mes_minus_Et, row.pfMet_mes_minus_Phi), frweight) - histos[folder+'/h_collmass_pfmet_mes_plus' ].Fill(collmass(row, row.pfMet_mes_plus_Et , row.pfMet_mes_plus_Phi ), frweight) - histos[folder+'/h_collmass_pfmet_tes_minus'].Fill(collmass(row, row.pfMet_tes_minus_Et, row.pfMet_tes_minus_Phi), frweight) - histos[folder+'/h_collmass_pfmet_tes_plus' ].Fill(collmass(row, row.pfMet_tes_plus_Et , row.pfMet_tes_plus_Phi ), frweight) - histos[folder+'/h_collmass_pfmet_ues_minus'].Fill(collmass(row, row.pfMet_ues_minus_Et, row.pfMet_ues_minus_Phi), frweight) - histos[folder+'/h_collmass_pfmet_ues_plus' ].Fill(collmass(row, row.pfMet_ues_plus_Et , row.pfMet_ues_plus_Phi ), frweight) - - - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, frweight) - - histos[folder+'/type1_pfMet_Et'].Fill(row.type1_pfMetEt, frweight) - histos[folder+'/pfMet_Et'].Fill(row.pfMetEt, frweight) - histos[folder+'/type1_pfMet_Phi'].Fill(row.type1_pfMetPhi, frweight) - histos[folder+'/pfMet_Phi'].Fill(row.pfMetPhi, frweight) - - histos[folder+'/pfMet_Et_ees_minus'].Fill( row.pfMet_ees_minus_Et , frweight) - histos[folder+'/pfMet_Et_jes_minus'].Fill( row.pfMet_jes_minus_Et , frweight) - histos[folder+'/pfMet_Et_mes_minus'].Fill( row.pfMet_mes_minus_Et , frweight) - histos[folder+'/pfMet_Et_tes_minus'].Fill( row.pfMet_tes_minus_Et , frweight) - histos[folder+'/pfMet_Et_ues_minus'].Fill( row.pfMet_ues_minus_Et , frweight) - - histos[folder+'/pfMet_Et_ees_plus'].Fill( row.pfMet_ees_plus_Et , frweight) - histos[folder+'/pfMet_Et_jes_plus'].Fill( row.pfMet_jes_plus_Et , frweight) - histos[folder+'/pfMet_Et_mes_plus'].Fill( row.pfMet_mes_plus_Et , frweight) - histos[folder+'/pfMet_Et_tes_plus'].Fill( row.pfMet_tes_plus_Et , frweight) - histos[folder+'/pfMet_Et_ues_plus'].Fill( row.pfMet_ues_plus_Et , frweight) - - - histos[folder+'/pfMet_Phi_ees_minus'].Fill(row.pfMet_ees_minus_Phi, frweight) - histos[folder+'/pfMet_Phi_jes_minus'].Fill(row.pfMet_jes_minus_Phi, frweight) - histos[folder+'/pfMet_Phi_mes_minus'].Fill(row.pfMet_mes_minus_Phi, frweight) - histos[folder+'/pfMet_Phi_tes_minus'].Fill(row.pfMet_tes_minus_Phi, frweight) - histos[folder+'/pfMet_Phi_ues_minus'].Fill(row.pfMet_ues_minus_Phi, frweight) - - histos[folder+'/pfMet_Phi_ees_plus'].Fill( row.pfMet_ees_plus_Phi , frweight) - histos[folder+'/pfMet_Phi_jes_plus'].Fill( row.pfMet_jes_plus_Phi , frweight) - histos[folder+'/pfMet_Phi_mes_plus'].Fill( row.pfMet_mes_plus_Phi , frweight) - histos[folder+'/pfMet_Phi_tes_plus'].Fill( row.pfMet_tes_plus_Phi , frweight) - histos[folder+'/pfMet_Phi_ues_plus'].Fill( row.pfMet_ues_plus_Phi , frweight) - - #histos[folder+'/pfMet_jes_Et'].Fill( row.pfMet_jes_Et , frweight) - #histos[folder+'/pfMet_jes_Phi'].Fill( row.pfMet_jes_Phi , frweight) - - #histos[folder+'/pfMet_ues_AtanToPhi'].Fill(rowpfMet_ues_AtanToPhi, frweight) - - histos[folder+'/type1_pfMet_Et_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, frweight) - histos[folder+'/mvaMet_Et_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, frweight) - - histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.pfMetPhi), frweight) - histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), frweight) - histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), frweight) - histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, frweight) - histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, frweight) - histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, frweight) - - - histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), frweight) - histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), frweight) - histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), frweight) - histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, frweight) - histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, frweight) - - histos[folder+'/h_collmass_pfmet_ees_minus'].Fill(collmass(row, row.pfMet_ees_minus_Et, row.pfMet_ees_minus_Phi), frweight) - histos[folder+'/h_collmass_pfmet_ees_plus' ].Fill(collmass(row, row.pfMet_ees_plus_Et , row.pfMet_ees_plus_Phi ), frweight) - histos[folder+'/h_collmass_pfmet_jes_minus'].Fill(collmass(row, row.pfMet_jes_minus_Et, row.pfMet_jes_minus_Phi), frweight) - histos[folder+'/h_collmass_pfmet_jes_plus' ].Fill(collmass(row, row.pfMet_jes_plus_Et , row.pfMet_jes_plus_Phi ), frweight) - histos[folder+'/h_collmass_pfmet_mes_minus'].Fill(collmass(row, row.pfMet_mes_minus_Et, row.pfMet_mes_minus_Phi), frweight) - histos[folder+'/h_collmass_pfmet_mes_plus' ].Fill(collmass(row, row.pfMet_mes_plus_Et , row.pfMet_mes_plus_Phi ), frweight) - histos[folder+'/h_collmass_pfmet_tes_minus'].Fill(collmass(row, row.pfMet_tes_minus_Et, row.pfMet_tes_minus_Phi), frweight) - histos[folder+'/h_collmass_pfmet_tes_plus' ].Fill(collmass(row, row.pfMet_tes_plus_Et , row.pfMet_tes_plus_Phi ), frweight) - histos[folder+'/h_collmass_pfmet_ues_minus'].Fill(collmass(row, row.pfMet_ues_minus_Et, row.pfMet_ues_minus_Phi), frweight) - histos[folder+'/h_collmass_pfmet_ues_plus' ].Fill(collmass(row, row.pfMet_ues_plus_Et , row.pfMet_ues_plus_Phi ), frweight) - - - histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus,frweight) - histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, frweight) - - histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus,frweight) - histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, frweight) - - histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus,frweight) - histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, frweight) - - histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus,frweight) - histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, frweight) - - histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus,frweight) - histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, frweight) - - histos[folder+'/tPFMET_Mt_jes_plus'].Fill(row.tMtToPfMet_jes_plus, frweight) - histos[folder+'/tPFMET_Mt_mes_plus'].Fill(row.tMtToPfMet_mes_plus, frweight) - histos[folder+'/tPFMET_Mt_ees_plus'].Fill(row.tMtToPfMet_ees_plus, frweight) - histos[folder+'/tPFMET_Mt_tes_plus'].Fill(row.tMtToPfMet_tes_plus, frweight) - histos[folder+'/tPFMET_Mt_ues_plus'].Fill(row.tMtToPfMet_ues_plus, frweight) - histos[folder+'/tPFMET_Mt_jes_minus'].Fill(row.tMtToPfMet_jes_minus,frweight) - histos[folder+'/tPFMET_Mt_mes_minus'].Fill(row.tMtToPfMet_mes_minus,frweight) - histos[folder+'/tPFMET_Mt_ees_minus'].Fill(row.tMtToPfMet_ees_minus,frweight) - histos[folder+'/tPFMET_Mt_tes_minus'].Fill(row.tMtToPfMet_tes_minus,frweight) - histos[folder+'/tPFMET_Mt_ues_minus'].Fill(row.tMtToPfMet_ues_minus,frweight) - - - - histos[folder+'/jetN_20'].Fill(row.jetVeto20, frweight) - histos[folder+'/jetN_30'].Fill(row.jetVeto30, frweight) - - else: # if it is TauTight - if not f.startswith('os') and not f.startswith('ss') : # if the dir name start with mVeto, eVeto or tVeto I don't want the different weight of MC corrections - pudir = [''] - - for n,d in enumerate(pudir) : - if 'minus' in f or 'plus' in f : - if n >0 : break - - folder = d+f - weight[n] = row.EmbPtWeight*weight[n] - if f=='os/gg/ept30' : - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, weight[n]) - continue - - histos[folder+'/evtInfo'].Fill( struct(run=row.run,lumi=row.lumi,evt=row.evt,weight=weight[n])) - - histos[folder+'/tPt'].Fill(row.tPt, weight[n]) - histos[folder+'/tEta'].Fill(row.tEta, weight[n]) - histos[folder+'/tPhi'].Fill(row.tPhi, weight[n]) - histos[folder+'/ePt'].Fill(row.ePt, weight[n]) - histos[folder+'/eEta'].Fill(row.eEta, weight[n]) - histos[folder+'/ePhi'].Fill(row.ePhi, weight[n]) - histos[folder+'/et_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.tPhi), weight[n]) - histos[folder+'/et_DeltaR'].Fill(row.e_t_DR, weight[n]) - - histos[folder+'/h_collmass_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmass_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmassSpread_vs_dPhi_pfmet'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - histos[folder+'/h_collmassSpread_vs_dPhi_mvamet'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.pfMetPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmassSpread_highPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.pfMetPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - histos[folder+'/h_collmassSpread_lowPhi_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.mva_metPhi) > 1.57 : - histos[folder+'/h_collmass_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmassSpread_highPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - if deltaPhi(row.tPhi, row.mva_metPhi) < 1.57 : - histos[folder+'/h_collmass_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmassSpread_lowPhi_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - histos[folder+'/h_collmassSpread_pfmet'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi)-125.0, weight[n]) - histos[folder+'/h_collmassSpread_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi)-125.0, weight[n]) - - - histos[folder+'/h_collmass_pfmet'].Fill(collmass(row, row.pfMetEt, row.pfMetPhi), weight[n]) - histos[folder+'/h_collmass_mvamet'].Fill(collmass(row, row.mva_metEt, row.mva_metPhi), weight[n]) - histos[folder+'/h_collmass_pfmet_Ty1'].Fill(collmass(row, row.type1_pfMetEt, row.type1_pfMetPhi), weight[n]) - - - histos[folder+'/h_vismass'].Fill(row.e_t_Mass, weight[n]) - - histos[folder+'/type1_pfMet_Et'].Fill(row.type1_pfMetEt, weight[n]) - histos[folder+'/pfMet_Et'].Fill(row.pfMetEt, weight[n]) - histos[folder+'/type1_pfMet_Phi'].Fill(row.type1_pfMetPhi, weight[n]) - histos[folder+'/pfMet_Phi'].Fill(row.pfMetPhi,weight[n]) - - histos[folder+'/pfMet_Et_ees_minus'].Fill( row.pfMet_ees_minus_Et , weight[n]) - histos[folder+'/pfMet_Et_jes_minus'].Fill( row.pfMet_jes_minus_Et , weight[n]) - histos[folder+'/pfMet_Et_mes_minus'].Fill( row.pfMet_mes_minus_Et , weight[n]) - histos[folder+'/pfMet_Et_tes_minus'].Fill( row.pfMet_tes_minus_Et , weight[n]) - histos[folder+'/pfMet_Et_ues_minus'].Fill( row.pfMet_ues_minus_Et , weight[n]) - - histos[folder+'/pfMet_Et_ees_plus'].Fill( row.pfMet_ees_plus_Et , weight[n]) - histos[folder+'/pfMet_Et_jes_plus'].Fill( row.pfMet_jes_plus_Et , weight[n]) - histos[folder+'/pfMet_Et_mes_plus'].Fill( row.pfMet_mes_plus_Et , weight[n]) - histos[folder+'/pfMet_Et_tes_plus'].Fill( row.pfMet_tes_plus_Et , weight[n]) - histos[folder+'/pfMet_Et_ues_plus'].Fill( row.pfMet_ues_plus_Et , weight[n]) - - - histos[folder+'/pfMet_Phi_ees_minus'].Fill(row.pfMet_ees_minus_Phi, weight[n]) - histos[folder+'/pfMet_Phi_jes_minus'].Fill(row.pfMet_jes_minus_Phi, weight[n]) - histos[folder+'/pfMet_Phi_mes_minus'].Fill(row.pfMet_mes_minus_Phi, weight[n]) - histos[folder+'/pfMet_Phi_tes_minus'].Fill(row.pfMet_tes_minus_Phi, weight[n]) - histos[folder+'/pfMet_Phi_ues_minus'].Fill(row.pfMet_ues_minus_Phi, weight[n]) - - histos[folder+'/pfMet_Phi_ees_plus'].Fill( row.pfMet_ees_plus_Phi , weight[n]) - histos[folder+'/pfMet_Phi_jes_plus'].Fill( row.pfMet_jes_plus_Phi , weight[n]) - histos[folder+'/pfMet_Phi_mes_plus'].Fill( row.pfMet_mes_plus_Phi , weight[n]) - histos[folder+'/pfMet_Phi_tes_plus'].Fill( row.pfMet_tes_plus_Phi , weight[n]) - histos[folder+'/pfMet_Phi_ues_plus'].Fill( row.pfMet_ues_plus_Phi , weight[n]) - - #histos[folder+'/pfMet_jes_Et'].Fill( row.pfMet_jes_Et , weight[n]) - #histos[folder+'/pfMet_jes_Phi'].Fill( row.pfMet_jes_Phi , weight[n]) - - #histos[folder+'/pfMet_ues_AtanToPhi'].Fill(row.pfMet_ues_AtanToPhi, weight[n]) + self.book(f,"tMtToPFMET", "tau-PFMET M_{T}" , 200, 0, 200) + #book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 200, 0, 200, + # postfixes=self.systematics['met']) + self.book(f,"eMtToPFMET", "e-PFMET M_{T}" , 200, 0, 200) + #book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 200, 0, 200, + # postfixes=self.systematics['met']) + + self.book(f, "pfMetEt", "pfMetEt", 200, 0, 200) + #book_with_sys(f, "pfMet_Et", "pfMet_Et", 200, 0, 200, postfixes=self.systematics['met']) - histos[folder+'/type1_pfMet_Et_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), row.type1_pfMetEt, weight[n]) - histos[folder+'/mvaMet_Et_vs_dPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), row.mva_metEt, weight[n]) - - histos[folder+'/ePFMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) - histos[folder+'/ePFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.ePhi, row.type1_pfMetPhi), weight[n]) - histos[folder+'/eMVAMET_DeltaPhi'].Fill(deltaPhi(row.ePhi, row.mva_metPhi), weight[n]) - - histos[folder+'/ePFMET_Mt'].Fill(row.eMtToPFMET, weight[n]) - histos[folder+'/ePFMET_Mt_Ty1'].Fill(row.eMtToPfMet_Ty1, weight[n]) - histos[folder+'/eMVAMET_Mt'].Fill(row.eMtToMVAMET, weight[n]) - - histos[folder+'/tPFMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.pfMetPhi), weight[n]) - histos[folder+'/tPFMET_DeltaPhi_Ty1'].Fill(deltaPhi(row.tPhi, row.type1_pfMetPhi), weight[n]) - histos[folder+'/tMVAMET_DeltaPhi'].Fill(deltaPhi(row.tPhi, row.mva_metPhi), weight[n]) - - histos[folder+'/tPFMET_Mt'].Fill(row.tMtToPFMET, weight[n]) - histos[folder+'/tPFMET_Mt_Ty1'].Fill(row.tMtToPfMet_Ty1, weight[n]) - histos[folder+'/tMVAMET_Mt'].Fill(row.tMtToMVAMET, weight[n]) - - histos[folder+'/jetN_20'].Fill(row.jetVeto20, weight[n]) - histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight[n]) - + self.book(f, "pfMetPhi", "pfMetPhi", 100, -3.2, 3.2) + #book_with_sys(f, "pfMet_Phi", "pfMet_Phi", 100, -3.2, 3.2, postfixes=self.systematics['met']) + - # if n == 0: # if I'm in the dir starting with os or ss I want also the energy scale uncertainties - histos[folder+'/h_collmass_pfmet_ees_minus'].Fill(collmass(row, row.pfMet_ees_minus_Et, row.pfMet_ees_minus_Phi), weight[n]) - histos[folder+'/h_collmass_pfmet_ees_plus' ].Fill(collmass(row, row.pfMet_ees_plus_Et , row.pfMet_ees_plus_Phi ), weight[n]) - histos[folder+'/h_collmass_pfmet_jes_minus'].Fill(collmass(row, row.pfMet_jes_minus_Et, row.pfMet_jes_minus_Phi), weight[n]) - histos[folder+'/h_collmass_pfmet_jes_plus' ].Fill(collmass(row, row.pfMet_jes_plus_Et , row.pfMet_jes_plus_Phi ), weight[n]) - histos[folder+'/h_collmass_pfmet_mes_minus'].Fill(collmass(row, row.pfMet_mes_minus_Et, row.pfMet_mes_minus_Phi), weight[n]) - histos[folder+'/h_collmass_pfmet_mes_plus' ].Fill(collmass(row, row.pfMet_mes_plus_Et , row.pfMet_mes_plus_Phi ), weight[n]) - histos[folder+'/h_collmass_pfmet_tes_minus'].Fill(collmass(row, row.pfMet_tes_minus_Et, row.pfMet_tes_minus_Phi), weight[n]) - histos[folder+'/h_collmass_pfmet_tes_plus' ].Fill(collmass(row, row.pfMet_tes_plus_Et , row.pfMet_tes_plus_Phi ), weight[n]) - histos[folder+'/h_collmass_pfmet_ues_minus'].Fill(collmass(row, row.pfMet_ues_minus_Et, row.pfMet_ues_minus_Phi), weight[n]) - histos[folder+'/h_collmass_pfmet_ues_plus' ].Fill(collmass(row, row.pfMet_ues_plus_Et , row.pfMet_ues_plus_Phi ), weight[n]) - - - histos[folder+'/ePFMET_Mt_jes_minus'].Fill(row.eMtToPfMet_jes_minus, weight[n]) - histos[folder+'/ePFMET_Mt_jes_plus'].Fill(row.eMtToPfMet_jes_plus, weight[n]) - - histos[folder+'/ePFMET_Mt_mes_minus'].Fill(row.eMtToPfMet_mes_minus,weight[n]) - histos[folder+'/ePFMET_Mt_mes_plus'].Fill(row.eMtToPfMet_mes_plus, weight[n]) - - histos[folder+'/ePFMET_Mt_ees_minus'].Fill(row.eMtToPfMet_ees_minus,weight[n]) - histos[folder+'/ePFMET_Mt_ees_plus'].Fill(row.eMtToPfMet_ees_plus, weight[n]) - - histos[folder+'/ePFMET_Mt_tes_minus'].Fill(row.eMtToPfMet_tes_minus,weight[n]) - histos[folder+'/ePFMET_Mt_tes_plus'].Fill(row.eMtToPfMet_tes_plus, weight[n]) - - histos[folder+'/ePFMET_Mt_ues_minus'].Fill(row.eMtToPfMet_ues_minus,weight[n]) - histos[folder+'/ePFMET_Mt_ues_plus'].Fill(row.eMtToPfMet_ues_plus, weight[n]) - - histos[folder+'/tPFMET_Mt_jes_plus'].Fill(row.tMtToPfMet_jes_plus,weight[n]) - histos[folder+'/tPFMET_Mt_mes_plus'].Fill(row.tMtToPfMet_mes_plus,weight[n]) - histos[folder+'/tPFMET_Mt_ees_plus'].Fill(row.tMtToPfMet_ees_plus,weight[n]) - histos[folder+'/tPFMET_Mt_tes_plus'].Fill(row.tMtToPfMet_tes_plus,weight[n]) - histos[folder+'/tPFMET_Mt_ues_plus'].Fill(row.tMtToPfMet_ues_plus,weight[n]) - histos[folder+'/tPFMET_Mt_jes_minus'].Fill(row.tMtToPfMet_jes_minus,weight[n]) - histos[folder+'/tPFMET_Mt_mes_minus'].Fill(row.tMtToPfMet_mes_minus,weight[n]) - histos[folder+'/tPFMET_Mt_ees_minus'].Fill(row.tMtToPfMet_ees_minus,weight[n]) - histos[folder+'/tPFMET_Mt_tes_minus'].Fill(row.tMtToPfMet_tes_minus,weight[n]) - histos[folder+'/tPFMET_Mt_ues_minus'].Fill(row.tMtToPfMet_ues_minus,weight[n]) - + self.book(f, "jetVeto20", "Number of jets, p_{T}>20", 10, -0.5, 9.5) + self.book(f, "jetVeto30", "Number of jets, p_{T}>30", 10, -0.5, 9.5) + + #index dirs and histograms + for key in self.histograms: + location = os.path.dirname(key) + name = os.path.basename(key) + if location in self.histo_locations: + self.histo_locations[location].append(name) + else: + self.histo_locations[location] = [name] + + def fakerate_weights(self, tEta): + tLoose = tau_fake_rate(tEta) + tLooseUp = tau_fake_rate_up(tEta) + tLooseDown= tau_fake_rate_dw(tEta) + + tLoose = tLoose / (1. - tLoose ) + tLooseUp = tLooseUp / (1. - tLooseUp ) + tLooseDown= tLooseDown / (1. - tLooseDown) + frweight = { + 'tLoose' : tLoose , + 'tLoose/Up' : tLooseUp , + 'tLoose/Down' : tLooseDown, + 'tLooseUnweight' : 1., + } - - + return frweight; + def fill_histos(self, folder_str, row, weight, filter_label = ''): + '''fills histograms''' + #find all keys matching + for attr in self.histo_locations[folder_str]: + name = attr + #if attr=='DEBUG': + # set_trace() + if filter_label: + if not attr.startswith(filter_label+'$'): + continue + attr = attr.replace(filter_label+'$', '') + path = os.path.join(folder_str,name) + value = self.histograms[path] + if value.InheritsFrom('TH2'): + if attr in self.hfunc: + try: + result, out_weight = self.hfunc[attr](row, weight) + except Exception as e: + raise RuntimeError("Error running function %s. Error: \n\n %s" % (attr, str(e))) + r1, r2 = result + if out_weight is None: + value.Fill( r1, r2 ) #saves you when filling NTuples! + else: + value.Fill( r1, r2, out_weight ) + else: + attr1, attr2 = tuple(attr.split('#')) + v1 = getattr(row,attr1) + v2 = getattr(row,attr2) + value.Fill( v1, v2, weight ) if weight is not None else value.Fill( v1, v2 ) + else: + if attr in self.hfunc: + try: + result, out_weight = self.hfunc[attr](row, weight) + except Exception as e: + raise RuntimeError("Error running function %s. Error: \n\n %s" % (attr, str(e))) + if out_weight is None: + value.Fill( result ) #saves you when filling NTuples! + else: + value.Fill( result, out_weight ) + else: + value.Fill( getattr(row,attr), weight ) if weight is not None else value.Fill( getattr(row,attr) ) + return None + def process(self): - - - - central_weights = fakerate_central_histogram(25,0, 2.5) - - p1s_weights = fakerate_p1s_histogram(25,0, 2.5)#fakerate_p1s_histogram(25,0, 2.5) - - m1s_weights = fakerate_m1s_histogram(25,0, 2.5)#fakerate_m1s_histogram(25,0, 2.5) - - + logging.debug('Starting processing') + systematics = self.systematics frw = [] - myevent =() + lock =() + ievt = 0 + logging.debug('Starting evt loop') for row in self.tree: - #for n, row in enumerate(self.tree): - - sign = 'ss' if row.e_t_SS else 'os' - processtype = '' ## use a line as for sign when the vbf when selections are defined - ptthreshold = [30] - processtype ='gg'##changed from 20 - jn = row.jetVeto30 - if jn > 3 : jn = 3 - jn_jes_plus = row.jetVeto30jes_plus - jn_jes_minus = row.jetVeto30jes_minus - - if jn_jes_plus >3 : jn_jes_plus=3 - if jn_jes_minus >3 : jn_jes_minus=3 - - #if row.run > 2 : #apply the trigger to data only (MC triggers enter in the scale factors) - + if (ievt % 100) == 0: + logging.debug('New event') + ievt += 1 + #avoid double counting events! + evt_id = (row.run, row.lumi, row.evt) + if evt_id == lock: continue + if lock != () and evt_id == lock: + logging.info('Removing duplicate of event: %d %d %d' % evt_id) + + # + #preselection, common to everything and everyone + # + #trigger if self.is_embedded : - if not bool(row.doubleMuPass) : continue else: if not bool(row.singleE27WP80Pass) : continue if not bool(row.eMatchesSingleE27WP80): continue - + + #objects if not selections.eSelection(row, 'e'): continue - - if not selections.lepton_id_iso(row, 'e', 'eid13Tight_etauiso01'): continue - - if abs(row.eEta) > 1.4442 and abs(row.eEta) < 1.566 : continue - if not selections.tauSelection(row, 't'): continue - if row.ePt < 30 : continue - #if row.eMtToPFMET <40 : continue - + if not selections.tauSelection(row, 't'): continue if not row.tAntiElectronMVA5Tight : continue if not row.tAntiMuon2Loose : continue if not row.tLooseIso3Hits : continue - - #isTauTight = False - frw=self.fakerate_weights(row.tEta, central_weights, p1s_weights, m1s_weights ) - - #if row.tauVetoPt20EleTight3MuLoose : continue - #if row.muVetoPt5IsoIdVtx : continue - #if row.eVetoCicLooseIso : continue # change it with Loose - - if row.tauVetoPt20EleTight3MuLoose and row.tauVetoPt20EleTight3MuLoose_tes_minus and row.tauVetoPt20EleTight3MuLoose_tes_plus: continue - if row.muVetoPt5IsoIdVtx and row.muVetoPt5IsoIdVtx_mes_minus and row.muVetoPt5IsoIdVtx_mes_plus : continue - if row.eVetoCicLooseIso and row.eVetoCicLooseIso_ees_minus and row.eVetoCicLooseIso_ees_plus : continue - - standardSelection=True - tesminus =True - tesplus =True - mesminus =True - mesplus =True - eesminus =True - eesplus =True - - if row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx or row.eVetoCicLooseIso : standardSelection = False - - if row.tauVetoPt20EleTight3MuLoose_tes_minus or row.muVetoPt5IsoIdVtx or row.eVetoCicLooseIso : tesminus = False - if row.tauVetoPt20EleTight3MuLoose_tes_plus or row.muVetoPt5IsoIdVtx or row.eVetoCicLooseIso : tesplus = False - if row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx_mes_minus or row.eVetoCicLooseIso : mesminus = False - if row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx_mes_plus or row.eVetoCicLooseIso : mesplus = False - if row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx or row.eVetoCicLooseIso_ees_minus : eesminus = False - if row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx or row.eVetoCicLooseIso_ees_plus : eesplus = False - - dirpaths = [(standardSelection, sign+'/'+processtype), (mesplus, 'mVetoUp/'+sign+'/'+processtype), (mesminus, 'mVetoDown/'+sign+'/'+processtype), \ - (eesplus, 'eVetoUp/'+sign+'/'+processtype), (eesminus, 'eVetoDown/'+sign+'/'+processtype), \ - (tesplus, 'tVetoUp/'+sign+'/'+processtype), (tesminus, 'tVetoDown/'+sign+'/'+processtype)] - - - - if (row.run, row.lumi, row.evt)==myevent: continue - if myevent!=() and (row.run, row.lumi, row.evt)==(myevent[0], myevent[1], myevent[2]): print row.ePt, row.tPt - - myevent=(row.run, row.lumi, row.evt) + #e ID/ISO + if not selections.lepton_id_iso(row, 'e', 'eid13Tight_etauiso01'): continue + logging.debug('Passed preselection') + + # + # Compute event weight + # + #event weight + sys_shifts = systematics['trig'] + \ + systematics['pu'] + \ + systematics['eid'] + \ + systematics['eiso'] + + #set_trace() + weight_map = self.event_weight(row, sys_shifts) + + #Fill embedded sample normalization BEFORE the vetoes + if not row.e_t_SS: + self.fill_histos('os/gg/ept30', row, weight_map['']) + + # it is better vetoing on b-jets after the histo for the DY embedded + #bjet veto + if row.bjetCSVVeto30!=0 : continue + + #tau ID, id Tau is tight then go in full selection, otherwise use for fakes + tau_id_category = [''] if row.tTightIso3Hits else ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] isTauTight = bool(row.tTightIso3Hits) - folder = dirpaths[0][1]+'/ept30' - if dirpaths[0][0] == True and sign=='os': - self.fill_histos(row, folder,isTauTight, frw) - - if row.bjetCSVVeto30!=0 : continue # it is better vetoing on b-jets after the histo for the DY embedded - - for n,dirpath in enumerate(dirpaths): - jetlist = [(int(jn), str(int(jn)))] - if dirpath[0]==False : continue - if n==0: - jetlist.extend([(int(jn_jes_plus), str(int(jn_jes_plus))+'_jes_plus'), (int(jn_jes_minus), str(int(jn_jes_plus))+'_jes_minus')]) - for jet in jetlist: - #for j in ptthreshold: - folder = dirpath[1]+'/ept30/'+jet[1] - #print folder - - #print row.tLooseIso3Hits, row.tTightIso3Hits, isTauTight - - self.fill_histos(row, folder,isTauTight, frw) - - if jet[0] == 0 : - if row.tPt < 35: continue - if row.ePt < 40 : continue - if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue - if row.tMtToPFMET > 50 : continue - if jet[0] == 1 : - if row.tPt < 40: continue - if row.ePt < 35 : continue - if row.tMtToPFMET > 35 : continue - if jet[0] == 2 : - if row.tPt < 40: continue - if row.ePt < 30 : continue # no cut as only electrons with pt>30 are in the ntuples - if row.tMtToPFMET > 35 : continue - if row.vbfMass < 550 : continue - if row.vbfDeta < 3.5 : continue - folder = dirpath[1]+'/ept30/'+jet[1]+'/selected' - self.fill_histos(row, folder, isTauTight,frw) + + #jet category + jn = min(row.jetVeto30, 3) + jn_jes_plus = min(row.jetVeto30jes_plus, 3) + jn_jes_minus = min(row.jetVeto30jes_minus, 3) + jet_categories = [jn, jn_jes_plus, jn_jes_minus] + jet_category_names = ['%i%s' % i for i in zip(jet_categories, systematics['jes'])] + + passes_full_selection = False + + # + # Full tight selection + # + full_selection = [[''] for _ in jet_categories] + for idx, njet in enumerate(jet_categories): + if njet == 0 : + if row.tPt < 35: continue + if row.ePt < 40 : continue + if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue + if row.tMtToPFMET > 50 : continue + full_selection[idx].append('selected') + passes_full_selection = True + elif njet == 1 : + if row.tPt < 40: continue + if row.ePt < 35 : continue + if row.tMtToPFMET > 35 : continue + full_selection[idx].append('selected') + passes_full_selection = True + elif njet == 2 : + if row.tPt < 40: continue + if row.ePt < 30 : continue # no cut as only electrons with pt>30 are in the ntuples + if row.tMtToPFMET > 35 : continue + if row.vbfMass < 550 : continue + if row.vbfDeta < 3.5 : continue + full_selection[idx].append('selected') + passes_full_selection = True + + if passes_full_selection: + logging.debug('Passed full selection') + + jet_directories = [] + for jet_dir, sel_dir in zip(jet_category_names, full_selection): + jet_directories.extend( + [os.path.join(jet_dir, i) for i in sel_dir] + ) + + # + #different selections + # + sign = 'ss' if row.e_t_SS else 'os' + processtype ='gg' + ptthreshold = ['ept30'] + + # + # Lepton vetoes + # + tvetoes = [row.tauVetoPt20EleTight3MuLoose, row.tauVetoPt20EleTight3MuLoose_tes_plus, row.tauVetoPt20EleTight3MuLoose_tes_minus] + mvetoes = [row.muVetoPt5IsoIdVtx , row.muVetoPt5IsoIdVtx_mes_plus , row.muVetoPt5IsoIdVtx_mes_minus ] + evetoes = [row.eVetoCicLooseIso , row.eVetoCicLooseIso_ees_plus , row.eVetoCicLooseIso_ees_minus ] + + tdirs = [ i for i, j in zip( systematics['tvetos'], tvetoes) if not j] + mdirs = [ i for i, j in zip( systematics['mvetos'], mvetoes) if not j] + edirs = [ i for i, j in zip( systematics['evetos'], evetoes) if not j] + + #if any of the lists is empty + #set_trace() + if not tdirs or not mdirs or not edirs: + continue + logging.debug('Passed Vetoes') + + #make all possible veto combos... + all_dirs = [''.join(i) for i in itertools.product(tdirs, mdirs, edirs)] + #...and choose only the meaningful ones + veto_sys = set(systematics['tvetos']+systematics['mvetos']+systematics['evetos']) + all_dirs = [i for i in all_dirs if i in veto_sys] + + sys_directories = all_dirs + sys_shifts + #remove duplicates + sys_directories = list(set(sys_directories)) + if not isTauTight: + #if is a loose tau just compute the fakes! + sys_directories = tau_id_category - - + #gather the one and only weight we do care about + mc_weight = weight_map[''] + + #weights are the fr ones... + weight_map = self.fakerate_weights(row.tEta) + for i in weight_map: + #...times the mc weight (if any) + weight_map[i] *= mc_weight + + #Fill histograms in appropriate direcotries + #if passes_full_selection: + #dirs = [os.path.join(sys, sign, processtype, e_thr, jet_dir) for sys, e_thr, jet_dir in itertools.product(sys_directories, ptthreshold, jet_directories)] + #if len(dirs) <> len(set(dirs)): + # set_trace() + for sys, e_thr, jet_dir in itertools.product(sys_directories, ptthreshold, jet_directories): + #if we fill a histogram, lock the event + lock = evt_id + dir_name = os.path.join(sys, sign, processtype, + e_thr, jet_dir) + if dir_name[-1] == '/': + dir_name = dir_name[:-1] + if passes_full_selection: + logging.debug('Filling %s' % dir_name) + #fill them! + weight_to_use = weight_map[sys] if sys in weight_map else weight_map[''] + self.fill_histos(dir_name, row, weight_to_use) def finish(self): From a8515300b4eeac3581a21fb31d2293d456ba74ea Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Thu, 6 Nov 2014 11:25:20 -0600 Subject: [PATCH 131/192] Fix minor bug in JES uncertainty plotting, reshuffle fake subtraction and make compliant with new directory structure. Added method to produce shapes to be used for limit setting --- lfvetau/BasePlotter.py | 248 ++++++++++++++++++++++++++++++++++------- 1 file changed, 210 insertions(+), 38 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index b2fac705..1a5a46f4 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -63,6 +63,28 @@ def histo_diff_quad(mc_err, *systematics): return clone +def name_systematic(name): + '''makes functor that makes a name systematic (with postfix)''' + return lambda x: x+name + +def dir_systematic(name): + '''makes functor that makes a directory systematic''' + return lambda x: os.path.join(name,x) + +def parse_cgs_groups(file_path): + if not os.path.isfile(file_path): + raise NameError('%s is not a file!' % file_path) + + groups = {} + regex = re.compile('$ GROUP (?P\w+) (?P[a-zA-Z\_\, ]+)') + with open(file_path) as infile: + for line in infile: + match = regex.match(line) + if match: + groups[match.group('groupname')] = [ i.strip() for i in match.group('includes').split(',') ] + return groups + + class BasePlotter(Plotter): def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): cwd = os.getcwd() @@ -88,7 +110,6 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): super(BasePlotter, self).__init__(files, lumifiles, outputdir, blinder, forceLumi=forceLumi) - self.views['fakes'] = {'view' : self.make_fakes()} self.mc_samples = [ 'GluGluToHToTauTau_M-125*', 'VBF_HToTauTau_M-125*', @@ -99,27 +120,107 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): 'Z*jets_M50_skimmedLL', 'Z*jets_M50_skimmedTT' ] - - if use_embedded: - + if use_embedded: self.mc_samples.pop() self.views['ZetauEmbedded'] = {'view' : self.make_embedded('os/gg/ept30/h_collmass_pfmet')} + self.views['fakes'] = {'view' : self.make_fakes()} + + #names must match with what defined in self.mc_samples + self.datacard_names = { + 'GluGluToHToTauTau_M-125*' : 'SMGG126' , + 'VBF_HToTauTau_M-125*' : 'SMVBF126' , + 'TTJets*' : 'ttbar' , + 'T*_t*' : 'singlet' , + '[WZ][WZ]Jets' : 'diboson' , + 'Z*jets_M50_skimmedTT' : 'ztautau' , + 'ZetauEmbedded' : 'ztautau' , + 'Z*jets_M50_skimmedLL' : 'zjetsother', + 'missing1' : 'WWVBF126', + 'missing2' : 'WWGG126', + 'ggHiggsToETau' : 'LFVGG', + 'vbfHiggsToETau' : 'LFVVBF', + 'fakes' : 'fakes', + } + + self.sample_groups = {#parse_cgs_groups('card_config/cgs.0.conf') + 'fullsimbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', + 'diboson', 'zjetsother', 'WWVBF126', 'WWGG126',], + 'simbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', 'ztautau' + 'diboson', 'zjetsother', 'WWVBF126', 'WWGG126',] + } + + self.systematics = { + 'PU_Uncertainty' : { + 'type' : 'yield', + '+' : dir_systematic('p1s'), + '-' : dir_systematic('m1s'), + 'apply_to' : ['simbkg'], + }, + 'E_Trig' : { + 'type' : 'yield', + '+' : dir_systematic('trp1s'), + '-' : dir_systematic('trm1s'), + 'apply_to' : ['simbkg'], + }, + 'E_ID' : { + 'type' : 'yield', + '+' : dir_systematic('eidp1s'), + '-' : dir_systematic('eidm1s'), + 'apply_to' : ['simbkg'], + }, + 'E_Iso' : { + 'type' : 'yield', + '+' : dir_systematic('eisop1s'), + '-' : dir_systematic('eisom1s'), + 'apply_to' : ['simbkg'], + }, + 'JES' : { + 'type' : 'shape', + '+' : lambda x: x.replace('/0/','/0_jes_plus/').replace('/1/','/1_jes_plus/').replace('/2/','/2_jes_plus/')+'_jes_plus' , + '-' : lambda x: x.replace('/0/','/0_jes_minus/').replace('/1/','/1_jes_minus/').replace('/2/','/2_jes_minus/')+'_jes_minus' , + 'apply_to' : ['fullsimbkg'], + }, + 'UES' : { + 'type' : 'shape', + '+' : lambda x: name_systematic('_ues_plus'), + '-' : lambda x: name_systematic('_ues_minus'), + 'apply_to' : ['fullsimbkg'], + }, + 'shape_FAKES' : { + 'type' : 'shape', + '+' : lambda x: dir_systematic('Up'), + '-' : lambda x: dir_systematic('Down'), + 'apply_to' : ['fakes'], + } + ## 'TES' : { TODO! MISSING + ## 'type' : 'shape', + ## '+' : , + ## '-' : , + ## }, + } + def make_fakes(self): '''Sets up the fakes view''' data_view = self.get_view('data') central_fakes = views.SubdirectoryView(data_view, 'tLoose') - up_fakes = views.SubdirectoryView(data_view, 'tLooseUp') - dw_fakes = views.SubdirectoryView(data_view, 'tLooseDown') + mc_views = self.mc_views() + if use_embedded: + mc_views.append(self.get_view('ZetauEmbedded')) + mc_sum = views.SumView(*mc_views) + mc_sum = views.SubdirectoryView(mc_sum, 'tLoose') + + fakes_view = SubtractionView(central_fakes, mc_sum, restrict_positive=True) style = data_styles['Fakes*'] return views.TitleView( views.StyleView( - MedianView(highv=up_fakes, lowv=dw_fakes, centv=central_fakes, maxdiff=True), + fakes_view, **remove_name_entry(style) ), style['name'] ) + #MedianView(highv=up_fakes, lowv=dw_fakes, centv=central_fakes, maxdiff=True), def make_embedded(self, normalization_path): '''Configures the embedded view''' @@ -460,14 +561,6 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', #make MC views with xsec error mc_views_nosys = self.mc_views(rebin, preprocess) - mc_views_noFake=[] - for view, name in zip(mc_views_nosys, self.mc_samples): - viewNoFake = views.SubdirectoryView(view, 'tLoose/') - mc_views_noFake.append(viewNoFake) - - mc_noFakeStack = views.SumView(*mc_views_noFake) - #mc_noFakes= mc_noFakeStack.Get(path) - mc_views = [] for view, name in zip(mc_views_nosys, self.mc_samples): new = SystematicsView( @@ -502,7 +595,6 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', if 'collmass' in variable.lower() or \ 'met' in variable.lower(): if not variable.lower().startswith('type1'): - c = 1 name_systematics.extend(met_systematics) # TO ADD WHEN RERUN WITH THE NEW BINNING #add them @@ -514,22 +606,28 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', folder_systematics, name_systematics) + #add jet category uncertainty + jetcat_unc_mapper = { + 0 : 0.017, + 1 : 0.035, + 2 : 0.05 + } + #find inn which jet category we are + regex = re.compile('\/\d\/') + found = regex.findall(path) + jet_unc = 0. + if found: + njet = int(found[0].strip('/')) + jet_unc = jetcat_unc_mapper.get(njet, 0. ) + mc_err = SystematicsView.add_error(mc_err, jet_unc) + #check if we are using the embedded sample if self.use_embedded: embed_view = self.get_view('ZetauEmbedded') if preprocess: embed_view = preprocess(embed_view) embed_view = RebinView( embed_view, rebin) - - embed_view_noFake = views.SubdirectoryView(embed_view, 'tLoose/') - embed = embed_view.Get(path) - embed_NoFakes = embed_view_noFake.Get(path) - - #mc_noFakes+=embed_NoFakes - mc_views_noFake.append(embed_view_noFake) - - mc_noFakeStack = views.SumView( *mc_views_noFake) #add xsec error embed = SystematicsView.add_error( embed, xsec_unc_mapper['Z*jets_M50_skimmedTT']) @@ -550,7 +648,7 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', for name in obj: folder_systematics.extend([ ('%sidp1s' % name, '%sidm1s' % name), #eID scale factor - ('%sisop1s' % name, '%sisop1s' % name), #e Iso scale factor + ('%sisop1s' % name, '%sisom1s' % name), #e Iso scale factor ]) @@ -568,10 +666,15 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', if preprocess: fakes_view = preprocess(fakes_view) fakes_view = RebinView(fakes_view, rebin) - - fakes_view = SubtractionView(fakes_view, mc_noFakeStack) fakes = fakes_view.Get(path) + fakes = self.add_shape_systematics( + fakes, + path, + fakes_view, + [('Up','Down')] + ) + #add them to backgrounds mc_stack.Add(fakes) @@ -579,16 +682,6 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', mc_err.Add(fakes) #set_trace() - #add jet category uncertainty - jetcat_unc_mapper = { - 0 : 0.017, - 1 : 0.035, - 2 : 0.05 - } - jetn = folder[len(folder)-1:] if not '/selected' in folder else folder[len(folder)-10:len(folder)-9] - mc_err = SystematicsView.add_error( mc_err, jetcat_unc_mapper.get(jetn, 0. )) - - #draw stack mc_stack.Draw() self.keep.append(mc_stack) @@ -728,6 +821,85 @@ def plot_without_uncert (self, folder, variable, rebin=1, xaxis='', if show_ratio: self.add_ratio_diff(data, mc_stack, finalhisto, xrange, ratio_range) + def write_shapes(self, folder, variable, output_dir, + rebin=1, preprocess=None): #, systematics): + '''Makes shapes for computing the limit and returns a list of systematic effects to be added to unc.vals/conf + make_shapes(folder, variable, output_dir, [rebin=1, preprocess=None) --> unc_conf_lines (list), unc_vals_lines (list) + ''' + output_dir.cd() + path = os.path.join(folder,variable) + + #make MC views with xsec error + bkg_views = dict( + [(self.datacard_names[i], j) for i, j in zip(self.mc_samples, self.mc_views(rebin, preprocess))] + ) + #cache histograms, since getting them is time consuming + bkg_histos = {} + for name, view in bkg_views.iteritems(): + mc_histo = view.Get(path) + bkg_histos[name] = mc_histo.Clone() + mc_histo.SetName(name) + mc_histo.Write() + + if use_embedded: + view = self.get_view('ZetauEmbedded') + name = self.datacard_names['ZetauEmbedded'] + bkg_views[name] = view + mc_histo = view.Get(path) + bkg_histos[name] = mc_histo.Clone() + mc_histo.SetName(name) + mc_histo.Write() + + bkg_views['fakes'] = self.get_view('fakes') + fake_shape = bkg_views['fakes'].Get(path) + bkg_histos['fakes'] = fake_shape.Clone() + fake_shape.Write() + + unc_conf_lines = [] + unc_vals_lines = [] + category_name = output_dir.GetName() + for unc_name, info in self.systematics: + targets = [] + for target in info['apply_to']: + if target in self.sample_groups: + targets.extend(self.sample_groups[target]) + else: + targets.append(target) + + yield_unc = (info['type'] == 'yield') + unc_conf = 'lnN' if yield_unc else 'shape' + unc_conf_lines.append('%s %s' % (unc_name, unc_conf)) + shift = 0. + for target in targets: + up = bkg_views[target].Get( + info['+'](path) + ) + down = bkg_views[target].Get( + info['-'](path) + ) + if yield_unc: + central = bkg_histos[target] + integral = central.Integral() + integral_up = up.Integral() + integral_down = down.Integral() + shift = max( + shift, + (integral_up - integral) / integral, + (integral - integral_down) / integral + ) + else: + up.SetName('%s_%sUp' % (target, unc_name)) + down.SetName('%s_%sDown' % (target, unc_name)) + up.Write() + down.Write() + shift += 1 + unc_vals_lines.append( + '%s %s %.2f' % (category_name, ','.join(targets), shift) + ) + + return unc_conf_lines, unc_vals_lines + +##----- From da60e3aa8534e054a3111ae82b397cdc7d46c01c Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Thu, 6 Nov 2014 11:27:33 -0600 Subject: [PATCH 132/192] First version. Prepares the datacards for limit setting, significance computation etc. --- lfvetau/prepare_limit.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lfvetau/prepare_limit.sh diff --git a/lfvetau/prepare_limit.sh b/lfvetau/prepare_limit.sh new file mode 100644 index 00000000..73358b56 --- /dev/null +++ b/lfvetau/prepare_limit.sh @@ -0,0 +1,37 @@ +#! /bin/env bash + +#$1 --> gategoy (0, 1, 2) --> 0 jets, 1 jet, vbf +category=$1 +input_dir=plots/$jobid/lfvet/ +output_dir=limits/$jobid/$category/ +mkdir -p output_dir + +#copy basic config +cp card_config/cgs.$category.conf $output_dir/cgs.config +cp card_config/unc.$category.conf $output_dir/unc.config +cp card_config/unc.$category.vals $output_dir/unc.vals + +#copy shape file +cp $input_dir/shapes.$category.root $output_dir/shapes.root + +#add dynamically assigned variables +cat $input_dir/unc.$category.conf >> $output_dir/unc.config +cat $input_dir/unc.$category.vals >> $output_dir/unc.vals + +#add bbb errors +if [ $category == '0' ]; then + command='gg0etau:fakes' +elif [ $category == '1' ]; then + command='boostetau:fakes' +else + command='vbfetau:fakes,ttbar,singlet,ztautau,SMVBF126,WWVBF126' +fi + +#TODO: normalize or not? +#will it work with input and output in the same place? +add_bbb_errors.py --normalize -i $output_dir -o $output_dir $command + +#build datacard +pushd $output_dir +create-datacard.py -i shapes.root +popd From a0119a5f6e545e791d84947f33dc78e002aea1bc Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Fri, 7 Nov 2014 10:01:34 -0600 Subject: [PATCH 133/192] code updates --- lfvetau/LFVHETauAnalyzerMVA.py | 133 +++++++++++++++++++++++---------- 1 file changed, 92 insertions(+), 41 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 0f54295f..eb28446d 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -25,9 +25,10 @@ def getVar(name, var): return name+var -met_et = 'pfMet%sEt' -met_phi = 'pfMet%sPhi' - +met_et = 'pfMet_Et%s' +met_phi = 'pfMet_Phi%s' +t_pt = 'tPt%s' +etMass = 'e_t_Mass%s' @memo def met(shift=''): return met_et % shift @@ -35,6 +36,14 @@ def met(shift=''): @memo def metphi(shift=''): return met_phi % shift +@memo +def tpt(shift=''): + return t_pt % shift + +@memo +def vismass(shift=''): + return etMass % shift + def attr_getter(attribute): '''return a function that gets an attribute''' @@ -71,13 +80,19 @@ def deltaR(phi1, ph2, eta1, eta2): return sqrt(deta*deta + dphi*dphi); def make_collmass_systematics(shift): - met_name = met(shift) - phi_name = metphi(shift) - def collmass_shifted(row, weight): - met = getattr(row, met_name) - phi = getattr(row, phi_name) - return collmass(row, met, phi), weight - return collmass_shifted + if shift.startswith('tes'): + ptnu =abs(met*cos(deltaPhi(metPhi, row.tPhi))) + visfrac = tpt/(tpt+ptnu) + vis_mass = vismass(shift) + return (vis_mass / sqrt(visfrac)) + else: + met_name = met(shift) + phi_name = metphi(shift) + def collmass_shifted(row, weight): + met = getattr(row, met_name) + phi = getattr(row, phi_name) + return collmass(row, met, phi), weight + return collmass_shifted class LFVHETauAnalyzerMVA(MegaBase): tree = 'et/final/Ntuple' @@ -105,7 +120,8 @@ def __init__(self, tree, outfile, **kwargs): 'mvetos': (['', 'mVetoUp', 'mVetoDown'] if self.is_mc else ['']), 'tvetos': (['', 'tVetoUp', 'tVetoDown'] if self.is_mc else ['']), 'evetos': (['', 'eVetoUp', 'eVetoDown'] if self.is_mc else ['']), - 'met' : ([ "_jes_plus_", "_mes_plus_", "_tes_plus_", "_ees_plus_", "_ues_plus_", "_jes_minus_", "_mes_minus_", "_tes_minus_", "_ees_minus_", "_ues_minus_"] if self.is_mc else []), + 'met' : ([ "_jes_plus", "_mes_plus", "_tes_plus", "_ees_plus", "_ues_plus", "_jes_minus", "_mes_minus", "_tes_minus", "_ees_minus", "_ues_minus"] if self.is_mc else []), + 'tes' : (["_tes_plus","_tes_minus"]), } #self filling histograms @@ -122,7 +138,7 @@ def __init__(self, tree, outfile, **kwargs): ), 'MetEt_vs_dPhi' : merge_functions( lambda row, weight: (deltaPhi(row.tPhi, getattr(row, metphi())), weight), - attr_getter('type1_pfMetEt') + attr_getter('type1_pfMet_Et') ), 'ePFMET_DeltaPhi' : lambda row, weight: (deltaPhi(row.ePhi, getattr(row, metphi())), weight), 'tPFMET_DeltaPhi' : lambda row, weight: (deltaPhi(row.tPhi, getattr(row, metphi())), weight), @@ -130,8 +146,12 @@ def __init__(self, tree, outfile, **kwargs): } for shift in self.systematics['met']: #patch name - postfix = shift[:-1] + postfix = shift self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + for shift in self.systematics['tes']: + #patch name + postfix = shift + self.hfunc['h_collmass%s_pfmet' % postfix] = make_collmass_systematics(shift) #PU correctors self.pucorrector = mcCorrections.make_shifted_weights( @@ -178,7 +198,8 @@ def begin(self): self.systematics['mvetos'] + \ self.systematics['tvetos'] + \ self.systematics['evetos'] + \ - ['tLoose/', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + \ + ['tesUp', 'tesDown'] sys_shifts = list( set( sys_shifts ) ) #remove double dirs processtype=['gg'] threshold=['ept30'] @@ -188,23 +209,23 @@ def begin(self): folder=[] for tuple_path in itertools.product(sys_shifts, signs, processtype, threshold, jetN): - folder.append(os.path.join(*tuple_path)) - path = list(tuple_path) - path.append('selected') - folder.append(os.path.join(*path)) - + folder.append(os.path.join(*tuple_path)) + path = list(tuple_path) + path.append('selected') + folder.append(os.path.join(*path)) + def book_with_sys(location, name, *args, **kwargs): postfixes = kwargs['postfixes'] del kwargs['postfixes'] self.book(location, name, *args, **kwargs) for postfix in postfixes: #patch name to be removed - fix = postfix[:-1] + fix = postfix self.book(location, name+fix, *args, **kwargs) self.book('os/gg/ept30/', "h_collmass_pfmet" , "h_collmass_pfmet", 32, 0, 320) self.book('os/gg/ept30/', "e_t_Mass", "h_vismass", 32, 0, 320) - + for f in folder: self.book( f, @@ -212,7 +233,7 @@ def book_with_sys(location, name, *args, **kwargs): 'run/l:lumi/l:evt/l:weight/D', type=pytree.PyTree ) - + self.book(f,"tPt", "tau p_{T}", 200, 0, 200) self.book(f,"tPt_tes_plus", "tau p_{T} (tes+)", 200, 0, 200) self.book(f,"tPt_tes_minus", "tau p_{T} (tes-)", 200, 0, 200) @@ -249,19 +270,19 @@ def book_with_sys(location, name, *args, **kwargs): self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 50, 0, 3.2) - self.book(f,"tMtToPFMET", "tau-PFMET M_{T}" , 200, 0, 200) - #book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 200, 0, 200, - # postfixes=self.systematics['met']) - self.book(f,"eMtToPFMET", "e-PFMET M_{T}" , 200, 0, 200) - #book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 200, 0, 200, - # postfixes=self.systematics['met']) + #self.book(f,"tMtToPFMET", "tau-PFMET M_{T}" , 200, 0, 200) + book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 200, 0, 200, + postfixes=self.systematics['met']) + #self.book(f,"eMtToPFMET", "e-PFMET M_{T}" , 200, 0, 200) + book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 200, 0, 200, + postfixes=self.systematics['met']) - self.book(f, "pfMetEt", "pfMetEt", 200, 0, 200) - #book_with_sys(f, "pfMet_Et", "pfMet_Et", 200, 0, 200, postfixes=self.systematics['met']) + #self.book(f, "pfMetEt", "pfMetEt", 200, 0, 200) + book_with_sys(f, "pfMet_Et", "pfMet_Et", 200, 0, 200, postfixes=self.systematics['met']) - self.book(f, "pfMetPhi", "pfMetPhi", 100, -3.2, 3.2) - #book_with_sys(f, "pfMet_Phi", "pfMet_Phi", 100, -3.2, 3.2, postfixes=self.systematics['met']) + #self.book(f, "pfMetPhi", "pfMetPhi", 100, -3.2, 3.2) + book_with_sys(f, "pfMet_Phi", "pfMet_Phi", 100, -3.2, 3.2, postfixes=self.systematics['met']) self.book(f, "jetVeto20", "Number of jets, p_{T}>20", 10, -0.5, 9.5) @@ -385,7 +406,9 @@ def process(self): sys_shifts = systematics['trig'] + \ systematics['pu'] + \ systematics['eid'] + \ - systematics['eiso'] + systematics['eiso'] #+ \ + #systematics['tesPlus'] + \ #vanno aggiunte piu` avanti come le jet categories. Non hanno un peso, cambia la soglia + #systematics['tesMinus'] #set_trace() weight_map = self.event_weight(row, sys_shifts) @@ -415,24 +438,40 @@ def process(self): # Full tight selection # full_selection = [[''] for _ in jet_categories] + tes_categories = [ ('', False),( 'tesUp', False), ('tesDown', False)] for idx, njet in enumerate(jet_categories): if njet == 0 : - if row.tPt < 35: continue + tThr = 35 + if min(row.tPt, row.tPt_tes_plus, row.tPt_tes_minus) < tThr: continue + tes_categories=[ ('', bool(row.tPt > tThr)),( 'tesUp', bool(row.tPt_tes_plus > tThr)), ('tesDown', bool(row.tPt_tes_minus > tThr))] + #if row.tPt > 35: tes_categories.append('') + #if row.tPt_tes_plus > 35: tes_categories.append('tesPlus/') + #if row.tPt_tes_minus > 35: tes_categories.append('tesDown/') if row.ePt < 40 : continue if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue - if row.tMtToPFMET > 50 : continue + if row.tMtToPfMet > 50 : continue full_selection[idx].append('selected') passes_full_selection = True elif njet == 1 : - if row.tPt < 40: continue + tThr = 40 + if min(row.tPt, row.tPt_tes_plus, row.tPt_tes_minus) < tThr: continue + tes_categories=[ ('', bool(row.tPt > tThr)),( 'tesUp', bool(row.tPt_tes_plus > tThr)), ('tesDown', bool(row.tPt_tes_minus > tThr))] + #if row.tPt > 40: tes_category.append('') + #if row.tPt_tes_plus > 40: tes_categories.append('tesPlus/') + #if row.tPt_tes_minus > 40: tes_categories.append('tesDown/') if row.ePt < 35 : continue - if row.tMtToPFMET > 35 : continue + if row.tMtToPfMet > 35 : continue full_selection[idx].append('selected') passes_full_selection = True elif njet == 2 : - if row.tPt < 40: continue + tThr = 40 + if min(row.tPt, row.tPt_tes_plus, row.tPt_tes_minus) < tThr: continue + tes_categories=[ ('', bool(row.tPt > tThr)),( 'tesUp', bool(row.tPt_tes_plus > tThr)), ('tesDown', bool(row.tPt_tes_minus > tThr))] + #if row.tPt > 40: tes_category.append('') + #if row.tPt_tes_plus > 40: tes_categories.append('tesPlus/') + #if row.tPt_tes_Minus > 40: tes_categories.append('tesDown/') if row.ePt < 30 : continue # no cut as only electrons with pt>30 are in the ntuples - if row.tMtToPFMET > 35 : continue + if row.tMtToPfMet > 35 : continue if row.vbfMass < 550 : continue if row.vbfDeta < 3.5 : continue full_selection[idx].append('selected') @@ -440,12 +479,15 @@ def process(self): if passes_full_selection: logging.debug('Passed full selection') - + + jet_directories = [] for jet_dir, sel_dir in zip(jet_category_names, full_selection): jet_directories.extend( [os.path.join(jet_dir, i) for i in sel_dir] ) + + # #different selections @@ -477,9 +519,17 @@ def process(self): veto_sys = set(systematics['tvetos']+systematics['mvetos']+systematics['evetos']) all_dirs = [i for i in all_dirs if i in veto_sys] - sys_directories = all_dirs + sys_shifts + tes_directories =[] + for tdir,tbool in tes_categories: + if tbool==True: tes_directories.append(tdir) + if tdir == '' and tbool==False : + all_dirs=[] + syst_shifts=[] + + sys_directories = all_dirs + sys_shifts +tes_directories #remove duplicates sys_directories = list(set(sys_directories)) + if not isTauTight: #if is a loose tau just compute the fakes! sys_directories = tau_id_category @@ -509,6 +559,7 @@ def process(self): logging.debug('Filling %s' % dir_name) #fill them! weight_to_use = weight_map[sys] if sys in weight_map else weight_map[''] + self.fill_histos(dir_name, row, weight_to_use) From a354d038829c32af26b6a639668289aef3b55c65 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Fri, 7 Nov 2014 10:05:38 -0600 Subject: [PATCH 134/192] code updates --- lfvetau/LFVHETauAnalyzerMVA.py | 133 +++++++++++++++++++++++---------- 1 file changed, 92 insertions(+), 41 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 0f54295f..eb28446d 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -25,9 +25,10 @@ def getVar(name, var): return name+var -met_et = 'pfMet%sEt' -met_phi = 'pfMet%sPhi' - +met_et = 'pfMet_Et%s' +met_phi = 'pfMet_Phi%s' +t_pt = 'tPt%s' +etMass = 'e_t_Mass%s' @memo def met(shift=''): return met_et % shift @@ -35,6 +36,14 @@ def met(shift=''): @memo def metphi(shift=''): return met_phi % shift +@memo +def tpt(shift=''): + return t_pt % shift + +@memo +def vismass(shift=''): + return etMass % shift + def attr_getter(attribute): '''return a function that gets an attribute''' @@ -71,13 +80,19 @@ def deltaR(phi1, ph2, eta1, eta2): return sqrt(deta*deta + dphi*dphi); def make_collmass_systematics(shift): - met_name = met(shift) - phi_name = metphi(shift) - def collmass_shifted(row, weight): - met = getattr(row, met_name) - phi = getattr(row, phi_name) - return collmass(row, met, phi), weight - return collmass_shifted + if shift.startswith('tes'): + ptnu =abs(met*cos(deltaPhi(metPhi, row.tPhi))) + visfrac = tpt/(tpt+ptnu) + vis_mass = vismass(shift) + return (vis_mass / sqrt(visfrac)) + else: + met_name = met(shift) + phi_name = metphi(shift) + def collmass_shifted(row, weight): + met = getattr(row, met_name) + phi = getattr(row, phi_name) + return collmass(row, met, phi), weight + return collmass_shifted class LFVHETauAnalyzerMVA(MegaBase): tree = 'et/final/Ntuple' @@ -105,7 +120,8 @@ def __init__(self, tree, outfile, **kwargs): 'mvetos': (['', 'mVetoUp', 'mVetoDown'] if self.is_mc else ['']), 'tvetos': (['', 'tVetoUp', 'tVetoDown'] if self.is_mc else ['']), 'evetos': (['', 'eVetoUp', 'eVetoDown'] if self.is_mc else ['']), - 'met' : ([ "_jes_plus_", "_mes_plus_", "_tes_plus_", "_ees_plus_", "_ues_plus_", "_jes_minus_", "_mes_minus_", "_tes_minus_", "_ees_minus_", "_ues_minus_"] if self.is_mc else []), + 'met' : ([ "_jes_plus", "_mes_plus", "_tes_plus", "_ees_plus", "_ues_plus", "_jes_minus", "_mes_minus", "_tes_minus", "_ees_minus", "_ues_minus"] if self.is_mc else []), + 'tes' : (["_tes_plus","_tes_minus"]), } #self filling histograms @@ -122,7 +138,7 @@ def __init__(self, tree, outfile, **kwargs): ), 'MetEt_vs_dPhi' : merge_functions( lambda row, weight: (deltaPhi(row.tPhi, getattr(row, metphi())), weight), - attr_getter('type1_pfMetEt') + attr_getter('type1_pfMet_Et') ), 'ePFMET_DeltaPhi' : lambda row, weight: (deltaPhi(row.ePhi, getattr(row, metphi())), weight), 'tPFMET_DeltaPhi' : lambda row, weight: (deltaPhi(row.tPhi, getattr(row, metphi())), weight), @@ -130,8 +146,12 @@ def __init__(self, tree, outfile, **kwargs): } for shift in self.systematics['met']: #patch name - postfix = shift[:-1] + postfix = shift self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + for shift in self.systematics['tes']: + #patch name + postfix = shift + self.hfunc['h_collmass%s_pfmet' % postfix] = make_collmass_systematics(shift) #PU correctors self.pucorrector = mcCorrections.make_shifted_weights( @@ -178,7 +198,8 @@ def begin(self): self.systematics['mvetos'] + \ self.systematics['tvetos'] + \ self.systematics['evetos'] + \ - ['tLoose/', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + \ + ['tesUp', 'tesDown'] sys_shifts = list( set( sys_shifts ) ) #remove double dirs processtype=['gg'] threshold=['ept30'] @@ -188,23 +209,23 @@ def begin(self): folder=[] for tuple_path in itertools.product(sys_shifts, signs, processtype, threshold, jetN): - folder.append(os.path.join(*tuple_path)) - path = list(tuple_path) - path.append('selected') - folder.append(os.path.join(*path)) - + folder.append(os.path.join(*tuple_path)) + path = list(tuple_path) + path.append('selected') + folder.append(os.path.join(*path)) + def book_with_sys(location, name, *args, **kwargs): postfixes = kwargs['postfixes'] del kwargs['postfixes'] self.book(location, name, *args, **kwargs) for postfix in postfixes: #patch name to be removed - fix = postfix[:-1] + fix = postfix self.book(location, name+fix, *args, **kwargs) self.book('os/gg/ept30/', "h_collmass_pfmet" , "h_collmass_pfmet", 32, 0, 320) self.book('os/gg/ept30/', "e_t_Mass", "h_vismass", 32, 0, 320) - + for f in folder: self.book( f, @@ -212,7 +233,7 @@ def book_with_sys(location, name, *args, **kwargs): 'run/l:lumi/l:evt/l:weight/D', type=pytree.PyTree ) - + self.book(f,"tPt", "tau p_{T}", 200, 0, 200) self.book(f,"tPt_tes_plus", "tau p_{T} (tes+)", 200, 0, 200) self.book(f,"tPt_tes_minus", "tau p_{T} (tes-)", 200, 0, 200) @@ -249,19 +270,19 @@ def book_with_sys(location, name, *args, **kwargs): self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 50, 0, 3.2) - self.book(f,"tMtToPFMET", "tau-PFMET M_{T}" , 200, 0, 200) - #book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 200, 0, 200, - # postfixes=self.systematics['met']) - self.book(f,"eMtToPFMET", "e-PFMET M_{T}" , 200, 0, 200) - #book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 200, 0, 200, - # postfixes=self.systematics['met']) + #self.book(f,"tMtToPFMET", "tau-PFMET M_{T}" , 200, 0, 200) + book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 200, 0, 200, + postfixes=self.systematics['met']) + #self.book(f,"eMtToPFMET", "e-PFMET M_{T}" , 200, 0, 200) + book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 200, 0, 200, + postfixes=self.systematics['met']) - self.book(f, "pfMetEt", "pfMetEt", 200, 0, 200) - #book_with_sys(f, "pfMet_Et", "pfMet_Et", 200, 0, 200, postfixes=self.systematics['met']) + #self.book(f, "pfMetEt", "pfMetEt", 200, 0, 200) + book_with_sys(f, "pfMet_Et", "pfMet_Et", 200, 0, 200, postfixes=self.systematics['met']) - self.book(f, "pfMetPhi", "pfMetPhi", 100, -3.2, 3.2) - #book_with_sys(f, "pfMet_Phi", "pfMet_Phi", 100, -3.2, 3.2, postfixes=self.systematics['met']) + #self.book(f, "pfMetPhi", "pfMetPhi", 100, -3.2, 3.2) + book_with_sys(f, "pfMet_Phi", "pfMet_Phi", 100, -3.2, 3.2, postfixes=self.systematics['met']) self.book(f, "jetVeto20", "Number of jets, p_{T}>20", 10, -0.5, 9.5) @@ -385,7 +406,9 @@ def process(self): sys_shifts = systematics['trig'] + \ systematics['pu'] + \ systematics['eid'] + \ - systematics['eiso'] + systematics['eiso'] #+ \ + #systematics['tesPlus'] + \ #vanno aggiunte piu` avanti come le jet categories. Non hanno un peso, cambia la soglia + #systematics['tesMinus'] #set_trace() weight_map = self.event_weight(row, sys_shifts) @@ -415,24 +438,40 @@ def process(self): # Full tight selection # full_selection = [[''] for _ in jet_categories] + tes_categories = [ ('', False),( 'tesUp', False), ('tesDown', False)] for idx, njet in enumerate(jet_categories): if njet == 0 : - if row.tPt < 35: continue + tThr = 35 + if min(row.tPt, row.tPt_tes_plus, row.tPt_tes_minus) < tThr: continue + tes_categories=[ ('', bool(row.tPt > tThr)),( 'tesUp', bool(row.tPt_tes_plus > tThr)), ('tesDown', bool(row.tPt_tes_minus > tThr))] + #if row.tPt > 35: tes_categories.append('') + #if row.tPt_tes_plus > 35: tes_categories.append('tesPlus/') + #if row.tPt_tes_minus > 35: tes_categories.append('tesDown/') if row.ePt < 40 : continue if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue - if row.tMtToPFMET > 50 : continue + if row.tMtToPfMet > 50 : continue full_selection[idx].append('selected') passes_full_selection = True elif njet == 1 : - if row.tPt < 40: continue + tThr = 40 + if min(row.tPt, row.tPt_tes_plus, row.tPt_tes_minus) < tThr: continue + tes_categories=[ ('', bool(row.tPt > tThr)),( 'tesUp', bool(row.tPt_tes_plus > tThr)), ('tesDown', bool(row.tPt_tes_minus > tThr))] + #if row.tPt > 40: tes_category.append('') + #if row.tPt_tes_plus > 40: tes_categories.append('tesPlus/') + #if row.tPt_tes_minus > 40: tes_categories.append('tesDown/') if row.ePt < 35 : continue - if row.tMtToPFMET > 35 : continue + if row.tMtToPfMet > 35 : continue full_selection[idx].append('selected') passes_full_selection = True elif njet == 2 : - if row.tPt < 40: continue + tThr = 40 + if min(row.tPt, row.tPt_tes_plus, row.tPt_tes_minus) < tThr: continue + tes_categories=[ ('', bool(row.tPt > tThr)),( 'tesUp', bool(row.tPt_tes_plus > tThr)), ('tesDown', bool(row.tPt_tes_minus > tThr))] + #if row.tPt > 40: tes_category.append('') + #if row.tPt_tes_plus > 40: tes_categories.append('tesPlus/') + #if row.tPt_tes_Minus > 40: tes_categories.append('tesDown/') if row.ePt < 30 : continue # no cut as only electrons with pt>30 are in the ntuples - if row.tMtToPFMET > 35 : continue + if row.tMtToPfMet > 35 : continue if row.vbfMass < 550 : continue if row.vbfDeta < 3.5 : continue full_selection[idx].append('selected') @@ -440,12 +479,15 @@ def process(self): if passes_full_selection: logging.debug('Passed full selection') - + + jet_directories = [] for jet_dir, sel_dir in zip(jet_category_names, full_selection): jet_directories.extend( [os.path.join(jet_dir, i) for i in sel_dir] ) + + # #different selections @@ -477,9 +519,17 @@ def process(self): veto_sys = set(systematics['tvetos']+systematics['mvetos']+systematics['evetos']) all_dirs = [i for i in all_dirs if i in veto_sys] - sys_directories = all_dirs + sys_shifts + tes_directories =[] + for tdir,tbool in tes_categories: + if tbool==True: tes_directories.append(tdir) + if tdir == '' and tbool==False : + all_dirs=[] + syst_shifts=[] + + sys_directories = all_dirs + sys_shifts +tes_directories #remove duplicates sys_directories = list(set(sys_directories)) + if not isTauTight: #if is a loose tau just compute the fakes! sys_directories = tau_id_category @@ -509,6 +559,7 @@ def process(self): logging.debug('Filling %s' % dir_name) #fill them! weight_to_use = weight_map[sys] if sys in weight_map else weight_map[''] + self.fill_histos(dir_name, row, weight_to_use) From 3b5f8a9bc97e326b3e5820ac0e54fce600f6d053 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 7 Nov 2014 11:13:11 -0600 Subject: [PATCH 135/192] version -1 (not tested) of limit setting for et --- lfvetau/BasePlotter.py | 64 ++++++++-- lfvetau/Rakefile | 115 +++++++++++++++++- .../._Datacards_FixedMetPAS_Oct31.zip | Bin 0 -> 4096 bytes lfvetau/card_config/cgs.0.conf | 20 +++ lfvetau/card_config/cgs.1.conf | 20 +++ lfvetau/card_config/cgs.2.conf | 20 +++ lfvetau/card_config/cgs.conf | 20 +++ lfvetau/card_config/unc.0.conf | 32 +++++ lfvetau/card_config/unc.0.vals | 31 +++++ lfvetau/card_config/unc.1.conf | 29 +++++ lfvetau/card_config/unc.1.vals | 27 ++++ lfvetau/card_config/unc.2.conf | 29 +++++ lfvetau/card_config/unc.2.vals | 30 +++++ lfvetau/plotRecoQuantitiesMVA.py | 25 +++- lfvetau/prepare_limit.sh | 20 ++- 15 files changed, 465 insertions(+), 17 deletions(-) create mode 100644 lfvetau/card_config/._Datacards_FixedMetPAS_Oct31.zip create mode 100644 lfvetau/card_config/cgs.0.conf create mode 100644 lfvetau/card_config/cgs.1.conf create mode 100644 lfvetau/card_config/cgs.2.conf create mode 100644 lfvetau/card_config/cgs.conf create mode 100755 lfvetau/card_config/unc.0.conf create mode 100755 lfvetau/card_config/unc.0.vals create mode 100755 lfvetau/card_config/unc.1.conf create mode 100755 lfvetau/card_config/unc.1.vals create mode 100755 lfvetau/card_config/unc.2.conf create mode 100755 lfvetau/card_config/unc.2.vals diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index 1a5a46f4..cff5122b 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -193,6 +193,12 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): '-' : lambda x: dir_systematic('Down'), 'apply_to' : ['fakes'], } + 'stat' : { + 'type' : 'stat', + '+' : lambda x: x, + '-' : lambda x: x, + 'apply_to' : ['fakes','simbkg'], + } ## 'TES' : { TODO! MISSING ## 'type' : 'shape', ## '+' : , @@ -866,9 +872,10 @@ def write_shapes(self, folder, variable, output_dir, else: targets.append(target) - yield_unc = (info['type'] == 'yield') - unc_conf = 'lnN' if yield_unc else 'shape' - unc_conf_lines.append('%s %s' % (unc_name, unc_conf)) + unc_conf = 'lnN' if info['type'] == 'yield' or info['type'] == 'stat' else 'shape' + #stat shapes are uncorrelated between samples + if info['type'] <> 'stat': + unc_conf_lines.append('%s %s' % (unc_name, unc_conf)) shift = 0. for target in targets: up = bkg_views[target].Get( @@ -877,7 +884,7 @@ def write_shapes(self, folder, variable, output_dir, down = bkg_views[target].Get( info['-'](path) ) - if yield_unc: + if info['type'] == 'yield': central = bkg_histos[target] integral = central.Integral() integral_up = up.Integral() @@ -887,15 +894,54 @@ def write_shapes(self, folder, variable, output_dir, (integral_up - integral) / integral, (integral - integral_down) / integral ) - else: + elif info['type'] == 'shape': up.SetName('%s_%sUp' % (target, unc_name)) down.SetName('%s_%sDown' % (target, unc_name)) up.Write() down.Write() - shift += 1 - unc_vals_lines.append( - '%s %s %.2f' % (category_name, ','.join(targets), shift) - ) + elif info['type'] == 'stat': + nbins = up.GetNbinsX() + up.Rebin(nbins) + yield_val = up.GetBinContent(1) + yield_err = up.GetBinError(1) + unc_value = 1. + (yield_err / yield_val) + stat_unc_name = '%s_%s' % (target, unc_name) + unc_conf_lines.append('%s %s' % (stat_unc_name, unc_conf)) + unc_vals_lines.append( + '%s %s %.2f' % (category_name, target, unc_value) + ) + else: + raise ValueError('systematic uncertainty type:"%s" not recognised!' % info['type']) + + if info['type'] <> 'stat': + shift += 1 + unc_vals_lines.append( + '%s %s %.2f' % (category_name, ','.join(targets), shift) + ) + + #Get signal + signals = [ + 'ggHiggsToETau', + 'vbfHiggsToETau', + ] + for name in signals: + sig_view = self.get_view(name) + if preprocess: + sig_view = preprocess(sig_view) + sig_view = RebinView(sig_view, rebin) + + histogram = sig_view.Get(path) + histogram.SetName(self.datacard_names[name]) + histogram.Write() + + # Draw data + data_view = self.get_view('data') + if preprocess: + data_view = preprocess( data_view ) + data_view = self.rebin_view(data_view, rebin) + data = data_view.Get(path) + data.SetName('data_obs') + data.Write() return unc_conf_lines, unc_vals_lines diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index 920014e0..62cf46e7 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -6,8 +6,8 @@ require ENV['CMSSW_BASE'] + '/src/FinalStateAnalysis/PlotTools/rake/tools.rb' require 'pathname' $jobid = ENV['jobid'] - $blind = ENV['blind'] + # Figure out what run period we are in $period = '8TeV' PU = ENV['PU'] @@ -348,5 +348,116 @@ end task :drawTauFakeRate => get_plotter_results("plotTauFakeRate.py") -task :drawplots => "#{$emtdir}/plot#{$period}.root" +## +## Make shapes +## +$shapedir = "plots/#{$jobid}/lfvet/" + +#All shape files are made at the same time +file "#{$shapedir}/.shapes_timestamp" => get_analyzer_results("LFVHETauAnalyzer.py", + samples['signalMCgg'] + \ + samples['signalMCvbf'] + \ + samples['ggHiggsTo2Taus'] + \ + samples['vbfHiggsTo2Taus'] + \ + samples['ttbar'] + \ + samples['singlet'] + \ + samples['singletbar'] + \ + samples['wjets'] + \ + samples['wwjets'] + \ + samples['wzjets'] + \ + samples['zzjets'] + \ + samples['zjets']) do |t| + sh "python plotRecoQuantitiesMVA.py" + sh "touch #{t.name}" +end + +## +## Prepare datacards +## +$limitdir = "limits/#{$jobid}/" +def prepare_limit(category) + #input file does not matter since shape files are made all at once + datacard = "#{$limitdir}/#{category}/126/datacard.txt" + file datacard => "#{$shapedir}/.shapes_timestamp" do |t| + sh "./prepare_limit.sh #{category}" + end + return datacard +end + +0_jet_card = prepare_limit('0') +1_jet_card = prepare_limit('1') +2_jet_card = prepare_limit('2') + +#combine cards +cmb_card = "#{$limitdir}/et_cmb/126/datacard.txt" +file cmb_card => [0_jet_card, 1_jet_card, 2_jet_card] do |t| + sh "mkdir -p #{$limitdir}/et_cmb/126" + sh "hadd -f #{$limitdir}/et_cmb/shapes.root #{$limitdir}/[0-9]/shapes.root" + chdir("#{$limitdir}/et_cmb/126") do + sh "rm -f shapes.root" + sh "ln -s ../shapes.root" + end + sh "combine_cards_with_names.sh #{ t.prerequisites.join(' ')} > #{cmb_card}" + end +end + +#TODO combination! +task :shapes => [ + 0_jet_card, + 1_jet_card, + 2_jet_card, + cmb_card +] + +## +## Compute Limit +## +def compute_limit(category) + #input file does not matter since shape files are made all at once + datacard = "#{$limitdir}/#{category}/126/datacard.txt" + timestamp = "#{$limitdir}/#{category}/.limit_timestamp" + file timestamp => datacard do |t| + sh "compute_limits.sh #{$limitdir}/#{category} 1 #{$blind}" + sh "touch #{t.name}" + end + return timestamp +end + +0_jet_limit = compute_limit('0') +1_jet_limit = compute_limit('1') +2_jet_limit = compute_limit('2') +c_jet_limit = compute_limit('et_cmb') +#TODO combination! +task :limits => [ + 0_jet_limit, + 1_jet_limit, + 2_jet_limit, + c_jet_limit +] + +## +## Compute Significance +## +def compute_significance(category) + #input file does not matter since shape files are made all at once + datacard = "#{$limitdir}/#{category}/126/datacard.txt" + timestamp = "#{$limitdir}/#{category}/.limit_timestamp" + file timestamp => datacard do |t| + sh "compute_significance.sh #{$limitdir}/#{category}/126 #{$blind}" + sh "touch #{t.name}" + end + return timestamp +end + +0_jet_significance = compute_significance('0') +1_jet_significance = compute_significance('1') +2_jet_significance = compute_significance('2') +c_jet_significance = compute_significance('et_cmb') +#TODO combination! +task :limits => [ + 0_jet_significance, + 1_jet_significance, + 2_jet_significance, + c_jet_significance +] diff --git a/lfvetau/card_config/._Datacards_FixedMetPAS_Oct31.zip b/lfvetau/card_config/._Datacards_FixedMetPAS_Oct31.zip new file mode 100644 index 0000000000000000000000000000000000000000..648df4f6aca1963fc3c4496cbe105ff2d5e16087 GIT binary patch literal 4096 zcmeH~Pj1sd6voFz2oO@$1t1m>dBZZc<2Xs%2qDLgX;PI!KID;=IU3|OSjfp<|JvpE@^6_Y_RG-i8)s%u%6Roiv1JXBi=Ty&c7 zGR4ahMY?L5CK;awZZf=xsf{h)%bX*3If5?&{9LC#K9c8z#&WbC;Ubbkj4x%3=1lf5 XOk+L^-_R#tyY}_>|0z8IwX3V&i(8oJ literal 0 HcmV?d00001 diff --git a/lfvetau/card_config/cgs.0.conf b/lfvetau/card_config/cgs.0.conf new file mode 100644 index 00000000..d7f519ec --- /dev/null +++ b/lfvetau/card_config/cgs.0.conf @@ -0,0 +1,20 @@ +# cgs.config: Specification of groups, categories, and samples + +#$ GROUP signal Higgs_vtth_sm_120,Higgs_gf_sm_120,Higgs_vbf_sm_120 +#$ GROUP background Ztt,ttbar,EWK,Fakes +#categories: emu_vbf +#signals: signal +#backgrounds: background +#data: data_obs + +$ GROUP signal LFVGG,LFVVBF +$ GROUP gghiggs LFVGG,SMGG126,WWGG126 +$ GROUP vbfhiggs LFVVBF,SMVBF126,WWVBF126 +$ GROUP zjets ztautau,zjetsother +$ GROUP background ww,ttbar,singlet,ztautau,zjetsother,fakes +$ GROUP simulated ww,ttbar,singlet,ztautau,zjetsother,LFVVBF,SMVBF126,WWVBF126,LFVGG,SMGG126,WWGG126 + +categories: gg0etau +signals: signal +backgrounds: background +data: data_obs diff --git a/lfvetau/card_config/cgs.1.conf b/lfvetau/card_config/cgs.1.conf new file mode 100644 index 00000000..d400591f --- /dev/null +++ b/lfvetau/card_config/cgs.1.conf @@ -0,0 +1,20 @@ +# cgs.config: Specification of groups, categories, and samples + +#$ GROUP signal Higgs_vtth_sm_120,Higgs_gf_sm_120,Higgs_vbf_sm_120 +#$ GROUP background Ztt,ttbar,EWK,Fakes +#categories: emu_vbf +#signals: signal +#backgrounds: background +#data: data_obs + +$ GROUP signal LFVGG,LFVVBF +$ GROUP gghiggs LFVGG,SMGG126,WWGG126 +$ GROUP vbfhiggs LFVVBF,SMVBF126,WWVBF126 +$ GROUP zjets ztautau,zjetsother +$ GROUP background ww,ttbar,singlet,ztautau,zjetsother,fakes +$ GROUP simulated ww,ttbar,singlet,ztautau,zjetsother,LFVVBF,SMVBF126,WWVBF126,LFVGG,SMGG126,WWGG126 + +categories: boostetau +signals: signal +backgrounds: background +data: data_obs diff --git a/lfvetau/card_config/cgs.2.conf b/lfvetau/card_config/cgs.2.conf new file mode 100644 index 00000000..ae9e9ec1 --- /dev/null +++ b/lfvetau/card_config/cgs.2.conf @@ -0,0 +1,20 @@ +# cgs.config: Specification of groups, categories, and samples + +#$ GROUP signal Higgs_vtth_sm_120,Higgs_gf_sm_120,Higgs_vbf_sm_120 +#$ GROUP background Ztt,ttbar,EWK,Fakes +#categories: emu_vbf +#signals: signal +#backgrounds: background +#data: data_obs + +$ GROUP signal LFVGG,LFVVBF +$ GROUP gghiggs LFVGG,SMGG126,WWGG126 +$ GROUP vbfhiggs LFVVBF,SMVBF126,WWVBF126 +$ GROUP zjets ztautau,zjetsother +$ GROUP background ww,ttbar,singlet,ztautau,zjetsother,fakes +$ GROUP simulated ww,ttbar,singlet,ztautau,zjetsother,LFVVBF,SMVBF126,WWVBF126,LFVGG,SMGG126,WWGG126 + +categories: vbfetau +signals: signal +backgrounds: background +data: data_obs diff --git a/lfvetau/card_config/cgs.conf b/lfvetau/card_config/cgs.conf new file mode 100644 index 00000000..a3bba4a2 --- /dev/null +++ b/lfvetau/card_config/cgs.conf @@ -0,0 +1,20 @@ +# cgs.config: Specification of groups, categories, and samples + +#$ GROUP signal Higgs_vtth_sm_120,Higgs_gf_sm_120,Higgs_vbf_sm_120 +#$ GROUP background Ztt,ttbar,EWK,Fakes +#categories: emu_vbf +#signals: signal +#backgrounds: background +#data: data_obs + +$ GROUP signal LFVGG,LFVVBF +$ GROUP gghiggs LFVGG,SMGG126,WWGG126 +$ GROUP vbfhiggs LFVVBF,SMVBF126,WWVBF126 +$ GROUP zjets ztautau,zjetsother +$ GROUP background ww,ttbar,singlet,ztautau,zjetsother,fakes +$ GROUP simulated ww,ttbar,singlet,ztautau,zjetsother,LFVVBF,SMVBF126,WWVBF126,LFVGG,SMGG126,WWGG126 + +categories: gg0etau,boostetau,vbfetau +signals: signal +backgrounds: background +data: data_obs diff --git a/lfvetau/card_config/unc.0.conf b/lfvetau/card_config/unc.0.conf new file mode 100755 index 00000000..f988cb4d --- /dev/null +++ b/lfvetau/card_config/unc.0.conf @@ -0,0 +1,32 @@ +lumi lnN +Effi_E lnN +Effi_et_Tau lnN +Effi_et_Tau_highPt lnN + +Theo_Scale_gg lnN +Theo_PDF_gg lnN + +Theo_UE lnN +Theo_Scale_vbf lnN +Theo_PDF_vbf lnN + +Norm_ZTauTau lnN +Norm_ZTauTau_et_0Jet_extra lnN +Norm_ZJetsOther lnN + +Norm_WW lnN +Norm_TT lnN +Norm_FAKES lnN +Norm_FAKES_mt_0Jet lnN +Norm_SMGG lnN +Norm_SMVBF lnN +Norm_WWGG lnN +Norm_WWVBF lnN +Norm_TOP lnN + +norm_JES_muhad lnN +norm_MET_muhad lnN +shape_MuTau_TES shape +shape_FAKES shape + +#Stat_muhad_0Jet_WWVBF126_bin20 shape diff --git a/lfvetau/card_config/unc.0.vals b/lfvetau/card_config/unc.0.vals new file mode 100755 index 00000000..0302ee8b --- /dev/null +++ b/lfvetau/card_config/unc.0.vals @@ -0,0 +1,31 @@ +gg0mutau gghiggs Theo_PDF_gg 1.097 +gg0mutau vbfhiggs Theo_PDF_vbf 1.036 + +gg0mutau gghiggs Theo_UE 1.04 +gg0mutau vbfhiggs Theo_UE 1.1 + +gg0mutau gghiggs Theo_Scale_gg 1.08 +gg0mutau vbfhiggs Theo_Scale_vbf 1.04 + +gg0mutau zjets Norm_ZTauTau 1.03 +gg0mutau ztautau Norm_ZTauTau_mt_0Jet_extra 1.05 +gg0mutau zjetsother Norm_ZJetsOther 1.3 + +#TODO: check eff electron +gg0mutau simulated lumi 1.026 +gg0mutau simulated Effi_E 1.02 +gg0mutau simulated Effi_et_Tau 1.06 +gg0mutau simulated Effi_et_Tau_highPt 1.03 + +gg0mutau ww Norm_WW 1.15 +gg0mutau singlet Norm_TOP 1.10 +gg0mutau ttbar Norm_TT 1.10 +gg0mutau fakes Norm_FAKES 1.30 + +gg0mutau fakes Norm_FAKES_et_0Jet 1.1 + +gg0mutau signal,ztautau,SMVBF126,SMGG126 shape_MuTau_TES 1 +gg0mutau fakes shape_FAKES 1 + +#gg0mutau SMGG126 Stat_muhad_0Jet_SMGG126_bin46 1 +#gg0mutau zjetsother norm_JES_muhad 1.098364 diff --git a/lfvetau/card_config/unc.1.conf b/lfvetau/card_config/unc.1.conf new file mode 100755 index 00000000..83bdb404 --- /dev/null +++ b/lfvetau/card_config/unc.1.conf @@ -0,0 +1,29 @@ +lumi lnN +Effi_E lnN +Effi_et_Tau lnN +Effi_et_Tau_highPt lnN + +Theo_UE lnN + +Theo_Scale_gg lnN +Theo_PDF_gg lnN + +Theo_Scale_vbf lnN +Theo_PDF_vbf lnN + +Norm_ZTauTau lnN +Norm_ZTauTau_et_1Jet_extra lnN +Norm_ZJetsOther lnN +Norm_WW lnN +Norm_TT lnN +Norm_FAKES lnN +Norm_SMGG lnN +Norm_SMVBF lnN +Norm_WWGG lnN +Norm_WWVBF lnN +Norm_TOP lnN + +norm_JES_muhad lnN +norm_MET_muhad lnN +shape_MuTau_TES shape +shape_FAKES shape diff --git a/lfvetau/card_config/unc.1.vals b/lfvetau/card_config/unc.1.vals new file mode 100755 index 00000000..c1247723 --- /dev/null +++ b/lfvetau/card_config/unc.1.vals @@ -0,0 +1,27 @@ +boostetau gghiggs Theo_PDF_gg 1.097 +boostetau vbfhiggs Theo_PDF_vbf 1.036 + +boostetau gghiggs Theo_UE 0.95 +boostetau vbfhiggs Theo_UE 1.0 + +boostetau gghiggs Theo_Scale_gg 1.1 +boostetau vbfhiggs Theo_Scale_vbf 1.015 + +boostetau zjets Norm_ZTauTau 1.03 +boostetau ztautau Norm_ZTauTau_et_1Jet_extra 1.05 +boostetau zjetsother Norm_ZJetsOther 1.3 + +boostetau simulated lumi 1.026 +boostetau simulated Effi_E 1.02 +boostetau simulated Effi_et_Tau 1.06 +boostetau simulated Effi_et_Tau_highPt 1.03 + +boostetau ww Norm_WW 1.15 +boostetau singlet Norm_TOP 1.10 +boostetau ttbar Norm_TT 1.10 +boostetau fakes Norm_FAKES 1.30 + +boostetau signal,ztautau,SMVBF126,SMGG126 shape_ETau_TES 1 +boostetau fakes shape_FAKES 1 + +#boostetau zjetsother norm_JES_muhad 1.060191 diff --git a/lfvetau/card_config/unc.2.conf b/lfvetau/card_config/unc.2.conf new file mode 100755 index 00000000..5bc3188a --- /dev/null +++ b/lfvetau/card_config/unc.2.conf @@ -0,0 +1,29 @@ +lumi lnN +Effi_E lnN +Effi_et_Tau lnN +Effi_et_Tau_highPt lnN + +Theo_UE lnN + +Theo_Scale_gg lnN +Theo_PDF_gg lnN + +Theo_Scale_vbf lnN +Theo_PDF_vbf lnN + +Norm_ZTauTau lnN +Norm_ZTauTau_et_vbf_extra lnN +Norm_WW_et_vbf_extra lnN +Norm_TT_et_vbf_extra lnN +Norm_ZJetsOther lnN +Norm_WW lnN +Norm_TT lnN +Norm_FAKES lnN +Norm_SMGG lnN +Norm_SMVBF lnN +Norm_WWGG lnN +Norm_WWVBF lnN +Norm_TOP lnN + +shape_ETau_TES shape +shape_FAKES shape diff --git a/lfvetau/card_config/unc.2.vals b/lfvetau/card_config/unc.2.vals new file mode 100755 index 00000000..d6d9a642 --- /dev/null +++ b/lfvetau/card_config/unc.2.vals @@ -0,0 +1,30 @@ +vbfetau gghiggs Theo_PDF_gg 1.097 +vbfetau vbfhiggs Theo_PDF_vbf 1.036 + +vbfetau gghiggs Theo_UE 0.90 +vbfetau vbfhiggs Theo_UE 0.99 + +vbfetau gghiggs Theo_Scale_gg 0.7 +vbfetau vbfhiggs Theo_Scale_vbf 1.02 + +vbfetau zjets Norm_ZTauTau 1.03 +vbfetau ztautau Norm_ZTauTau_et_vbf_extra 1.10 +vbfetau zjetsother Norm_ZJetsOther 1.3 + +vbfetau ww Norm_WW_et_vbf_extra 1.5 +vbfetau ttbar Norm_TT_et_vbf_extra 1.33 + +vbfetau simulated lumi 1.026 +vbfetau simulated Effi_E 1.02 +vbfetau simulated Effi_et_Tau 1.06 +vbfetau simulated Effi_et_Tau_highPt 1.03 + +vbfetau ww Norm_WW 1.15 +vbfetau singlet Norm_TOP 1.10 +vbfetau ttbar Norm_TT 1.10 +vbfetau fakes Norm_FAKES 1.30 + +vbfetau signal, ztautau, SMVBF126,SMGG126 shape_ETau_TES 1 +vbfetau fakes shape_FAKES 1 + +#vbfetau ttbar norm_JES_muhad 1.053767 diff --git a/lfvetau/plotRecoQuantitiesMVA.py b/lfvetau/plotRecoQuantitiesMVA.py index cc15cb1f..90db06fb 100644 --- a/lfvetau/plotRecoQuantitiesMVA.py +++ b/lfvetau/plotRecoQuantitiesMVA.py @@ -76,5 +76,28 @@ plotter.save(var,dotroot=False) - + +#make shapes for limit setting +signal_region = 'os/gg/ept30/%s/selected' +jets_names = [ + ('0', 'gg0etau' ), + ('1', 'boostetau'), + ('2', 'vbfetau' ), +] +pjoin = os.path.join +for njets, cat_name in jets_names: + output_dir = plotter.base_out_dir + tfile = ROOT.TFile(pjoin(output_dir, 'shapes.%s.root' % njets), 'recreate') + output_dir = tfile.mkdir(cat_name) + unc_conf_lines, unc_vals_lines = plotter.write_shapes( signal_region, 'h_collmass_pfmet', output_dir) + logging.warning('shape file %s created' % tfile.GetName()) + tfile.Close() + with open(pjoin(output_dir, 'unc.%s.conf' % njets), 'w') as conf: + conf.write('\n'.join(unc_conf_lines)) + with open(pjoin(output_dir, 'unc.%s.vals' % njets), 'w') as vals: + vals.write('\n'.join(unc_vals_lines)) + + + + diff --git a/lfvetau/prepare_limit.sh b/lfvetau/prepare_limit.sh index 73358b56..f736472c 100644 --- a/lfvetau/prepare_limit.sh +++ b/lfvetau/prepare_limit.sh @@ -1,7 +1,14 @@ #! /bin/env bash -#$1 --> gategoy (0, 1, 2) --> 0 jets, 1 jet, vbf +#$1 --> category (0, 1, 2) --> 0 jets, 1 jet, vbf +#$2 --> files extensions produced by plotting (used inoptimization) category=$1 +if [[ -z "$2" ]]; +then + file_extension=$2 +else + file_extension=$1 +fi input_dir=plots/$jobid/lfvet/ output_dir=limits/$jobid/$category/ mkdir -p output_dir @@ -12,11 +19,11 @@ cp card_config/unc.$category.conf $output_dir/unc.config cp card_config/unc.$category.vals $output_dir/unc.vals #copy shape file -cp $input_dir/shapes.$category.root $output_dir/shapes.root +cp $input_dir/shapes.$file_extension.root $output_dir/shapes.root #add dynamically assigned variables -cat $input_dir/unc.$category.conf >> $output_dir/unc.config -cat $input_dir/unc.$category.vals >> $output_dir/unc.vals +cat $input_dir/unc.$file_extension.conf >> $output_dir/unc.config +cat $input_dir/unc.$file_extension.vals >> $output_dir/unc.vals #add bbb errors if [ $category == '0' ]; then @@ -33,5 +40,8 @@ add_bbb_errors.py --normalize -i $output_dir -o $output_dir $command #build datacard pushd $output_dir -create-datacard.py -i shapes.root +mkdir 126 +create-datacard.py -i shapes.root -o 126/datacard.txt popd + +exit 0 From 7927e6d0c35db61d81e3a9dac5813b2d3a1f8d0c Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 7 Nov 2014 11:13:52 -0600 Subject: [PATCH 136/192] remove spurious file --- .../._Datacards_FixedMetPAS_Oct31.zip | Bin 4096 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 lfvetau/card_config/._Datacards_FixedMetPAS_Oct31.zip diff --git a/lfvetau/card_config/._Datacards_FixedMetPAS_Oct31.zip b/lfvetau/card_config/._Datacards_FixedMetPAS_Oct31.zip deleted file mode 100644 index 648df4f6aca1963fc3c4496cbe105ff2d5e16087..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4096 zcmeH~Pj1sd6voFz2oO@$1t1m>dBZZc<2Xs%2qDLgX;PI!KID;=IU3|OSjfp<|JvpE@^6_Y_RG-i8)s%u%6Roiv1JXBi=Ty&c7 zGR4ahMY?L5CK;awZZf=xsf{h)%bX*3If5?&{9LC#K9c8z#&WbC;Ubbkj4x%3=1lf5 XOk+L^-_R#tyY}_>|0z8IwX3V&i(8oJ From 757214cb6d67b19ba75b3931e8251929309e4f33 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Mon, 10 Nov 2014 03:38:35 -0600 Subject: [PATCH 137/192] fakerate uncertainties --- lfvetau/TauFakeRateAnalyzerMVA.py | 6 +++--- lfvetau/fakerate_functions.py | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lfvetau/TauFakeRateAnalyzerMVA.py b/lfvetau/TauFakeRateAnalyzerMVA.py index 7db90068..38f4cdfc 100644 --- a/lfvetau/TauFakeRateAnalyzerMVA.py +++ b/lfvetau/TauFakeRateAnalyzerMVA.py @@ -117,7 +117,7 @@ def begin(self): self.book(f, "e1e2Mass", "e1e2 Inv Mass", 32, 0, 320) - self.book(f, "tMtToPFMET", "#tau Met MT", 100, 0, 100) + self.book(f, "tMtToPfMet", "#tau Met MT", 100, 0, 100) self.book(f,"tRawIso3Hits", "tRawIso3Hits", 500, 0, 100) self.book(f,"tPt", "t p_{T}", 200, 0, 200) @@ -163,7 +163,7 @@ def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): histos[folder+'/e2Phi'].Fill(row.e2Phi, weight) histos[folder+'/e1e2Mass'].Fill(row.e1_e2_Mass, weight) - histos[folder+'/tMtToPFMET'].Fill(row.tMtToPFMET,weight) + histos[folder+'/tMtToPfMet'].Fill(row.tMtToPfMet,weight) #histos[folder+'/tRawIso3Hits'].Fill(row.tRawIso3Hits, weight) histos[folder+'/tPt'].Fill(row.tPt, weight) @@ -173,7 +173,7 @@ def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): histos[folder+'/tAbsEta'].Fill(abs(row.tEta), weight) histos[folder+'/tPhi'].Fill(row.tPhi, weight) - histos[folder+'/type1_pfMetEt'].Fill(row.type1_pfMetEt) + histos[folder+'/type1_pfMetEt'].Fill(row.type1_pfMet_Et) histos[folder+'/etDR'].Fill(etDR(row)) histos[folder+'/etDPhi'].Fill(etDPhi(row)) histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight) diff --git a/lfvetau/fakerate_functions.py b/lfvetau/fakerate_functions.py index 01486bd2..04815f4c 100644 --- a/lfvetau/fakerate_functions.py +++ b/lfvetau/fakerate_functions.py @@ -19,20 +19,20 @@ def fcn(*args): return functor(*args) * inflation return fcn -tau_fake_rate_up = inflate_systematics(tau_fake_rate, 1.3) -tau_fake_rate_dw = inflate_systematics(tau_fake_rate, 0.7) + #tau_fake_rate_up = inflate_systematics(tau_fake_rate, 1.3) + #tau_fake_rate_dw = inflate_systematics(tau_fake_rate, 0.7) -# Tau fakes as it should be -# tau_fake_rate_up = make_corrector_from_histo( -# frfit_dir+'t_os_tLoose_tTigh_tAbsEta_2.root', -# 'efficiency_up', -# '1D' -# ) -# -# tau_fake_rate_dw = make_corrector_from_histo( -# frfit_dir+'t_os_tLoose_tTigh_tAbsEta_2.root', -# 'efficiency_dw', -# '1D' -# ) +###Tau fakes as it should be +tau_fake_rate_up = make_corrector_from_histo( + frfit_dir+'t_os_tLoose_tTigh_tAbsEta_2.root', + 'efficiency_up', + '1D' +) + +tau_fake_rate_dw = make_corrector_from_histo( + frfit_dir+'t_os_tLoose_tTigh_tAbsEta_2.root', + 'efficiency_dw', + '1D' +) From 7b84ec955ab33d4f1aa667da06cf8355c6bcefb8 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 10 Nov 2014 08:47:44 -0600 Subject: [PATCH 138/192] fix minor bugs --- lfvetau/BasePlotter.py | 30 +++++----- lfvetau/Rakefile | 49 +++++++++-------- lfvetau/plotRecoQuantitiesMVA.py | 94 ++++++++++++++++++-------------- 3 files changed, 93 insertions(+), 80 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index cff5122b..fee9b7cf 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -145,9 +145,9 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): self.sample_groups = {#parse_cgs_groups('card_config/cgs.0.conf') 'fullsimbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', - 'diboson', 'zjetsother', 'WWVBF126', 'WWGG126',], - 'simbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', 'ztautau' - 'diboson', 'zjetsother', 'WWVBF126', 'WWGG126',] + 'diboson', 'zjetsother'], #, 'WWVBF126', 'WWGG126',], + 'simbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', 'ztautau', + 'diboson', 'zjetsother']#, 'WWVBF126', 'WWGG126',] } self.systematics = { @@ -155,7 +155,7 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): 'type' : 'yield', '+' : dir_systematic('p1s'), '-' : dir_systematic('m1s'), - 'apply_to' : ['simbkg'], + 'apply_to' : ['fullsimbkg'], }, 'E_Trig' : { 'type' : 'yield', @@ -183,16 +183,16 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): }, 'UES' : { 'type' : 'shape', - '+' : lambda x: name_systematic('_ues_plus'), - '-' : lambda x: name_systematic('_ues_minus'), + '+' : name_systematic('_ues_plus'), + '-' : name_systematic('_ues_minus'), 'apply_to' : ['fullsimbkg'], }, 'shape_FAKES' : { 'type' : 'shape', - '+' : lambda x: dir_systematic('Up'), - '-' : lambda x: dir_systematic('Down'), + '+' : dir_systematic('Up'), + '-' : dir_systematic('Down'), 'apply_to' : ['fakes'], - } + }, 'stat' : { 'type' : 'stat', '+' : lambda x: x, @@ -212,7 +212,7 @@ def make_fakes(self): data_view = self.get_view('data') central_fakes = views.SubdirectoryView(data_view, 'tLoose') mc_views = self.mc_views() - if use_embedded: + if self.use_embedded: mc_views.append(self.get_view('ZetauEmbedded')) mc_sum = views.SumView(*mc_views) mc_sum = views.SubdirectoryView(mc_sum, 'tLoose') @@ -847,7 +847,7 @@ def write_shapes(self, folder, variable, output_dir, mc_histo.SetName(name) mc_histo.Write() - if use_embedded: + if self.use_embedded: view = self.get_view('ZetauEmbedded') name = self.datacard_names['ZetauEmbedded'] bkg_views[name] = view @@ -864,7 +864,7 @@ def write_shapes(self, folder, variable, output_dir, unc_conf_lines = [] unc_vals_lines = [] category_name = output_dir.GetName() - for unc_name, info in self.systematics: + for unc_name, info in self.systematics.iteritems(): targets = [] for target in info['apply_to']: if target in self.sample_groups: @@ -877,12 +877,14 @@ def write_shapes(self, folder, variable, output_dir, if info['type'] <> 'stat': unc_conf_lines.append('%s %s' % (unc_name, unc_conf)) shift = 0. + path_up = info['+'](path) + path_dw = info['-'](path) for target in targets: up = bkg_views[target].Get( - info['+'](path) + path_up ) down = bkg_views[target].Get( - info['-'](path) + path_dw ) if info['type'] == 'yield': central = bkg_histos[target] diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index 62cf46e7..c249eeff 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -384,13 +384,15 @@ def prepare_limit(category) return datacard end -0_jet_card = prepare_limit('0') -1_jet_card = prepare_limit('1') -2_jet_card = prepare_limit('2') +card_0_jet = prepare_limit('0') +card_1_jet = prepare_limit('1') +card_2_jet = prepare_limit('2') #combine cards cmb_card = "#{$limitdir}/et_cmb/126/datacard.txt" -file cmb_card => [0_jet_card, 1_jet_card, 2_jet_card] do |t| +file cmb_card => [card_0_jet, + card_1_jet, + card_2_jet] do |t| sh "mkdir -p #{$limitdir}/et_cmb/126" sh "hadd -f #{$limitdir}/et_cmb/shapes.root #{$limitdir}/[0-9]/shapes.root" chdir("#{$limitdir}/et_cmb/126") do @@ -398,14 +400,13 @@ file cmb_card => [0_jet_card, 1_jet_card, 2_jet_card] do |t| sh "ln -s ../shapes.root" end sh "combine_cards_with_names.sh #{ t.prerequisites.join(' ')} > #{cmb_card}" - end end #TODO combination! task :shapes => [ - 0_jet_card, - 1_jet_card, - 2_jet_card, + card_0_jet, + card_1_jet, + card_2_jet, cmb_card ] @@ -423,16 +424,16 @@ def compute_limit(category) return timestamp end -0_jet_limit = compute_limit('0') -1_jet_limit = compute_limit('1') -2_jet_limit = compute_limit('2') -c_jet_limit = compute_limit('et_cmb') +limit_0_jet = compute_limit('0') +limit_1_jet = compute_limit('1') +limit_2_jet = compute_limit('2') +limit_c_jet = compute_limit('et_cmb') #TODO combination! task :limits => [ - 0_jet_limit, - 1_jet_limit, - 2_jet_limit, - c_jet_limit + limit_0_jet, + limit_1_jet, + limit_2_jet, + limit_c_jet, ] ## @@ -449,15 +450,15 @@ def compute_significance(category) return timestamp end -0_jet_significance = compute_significance('0') -1_jet_significance = compute_significance('1') -2_jet_significance = compute_significance('2') -c_jet_significance = compute_significance('et_cmb') +significance_0_jet = compute_significance('0') +significance_1_jet = compute_significance('1') +significance_2_jet = compute_significance('2') +significance_c_jet = compute_significance('et_cmb') #TODO combination! task :limits => [ - 0_jet_significance, - 1_jet_significance, - 2_jet_significance, - c_jet_significance + significance_0_jet, + significance_1_jet, + significance_2_jet, + significance_c_jet ] diff --git a/lfvetau/plotRecoQuantitiesMVA.py b/lfvetau/plotRecoQuantitiesMVA.py index 90db06fb..49ebf2cd 100644 --- a/lfvetau/plotRecoQuantitiesMVA.py +++ b/lfvetau/plotRecoQuantitiesMVA.py @@ -41,41 +41,51 @@ processtype = ['gg'] threshold = ['ept30'] -histo_info = [('tPt', 'p_{T}(#tau) (GeV)', 5), ('tEta', '#eta(#tau)', 2), ('tPhi', '#phi(#tau)', 5), - ('ePt', 'p_{T}(e) (GeV)', 5), ('eEta', '#eta(e)', 2), ('ePhi', '#phi(e)', 5), - ('et_DeltaPhi', 'e#tau #Delta#phi', 1), ('et_DeltaR', 'e#tau #Delta R', 1), - ('h_collmass_pfmet', 'M_{coll}(e#tau) (GeV)', 1), ('h_vismass', 'M_{vis} (GeV)', 1), - ('jetN_30', 'number of jets (p_{T} > 30 GeV)', 1) , ('ePFMET_Mt', 'M_{T} e-PFMET', 5), - ('tPFMET_Mt', 'M_{T} #tau-PFMET', 5) , ('pfMet_Et', 'pfMet', 5)] +histo_info = [ + ('tPt', 'p_{T}(#tau) (GeV)', 5), + ('tEta', '#eta(#tau)', 2), + ('tPhi', '#phi(#tau)', 5), + ('ePt', 'p_{T}(e) (GeV)', 5), + ('eEta', '#eta(e)', 2), + ('ePhi', '#phi(e)', 5), + ('e_t_DPhi', 'e#tau #Delta#phi', 1), + ('e_t_DR', 'e#tau #Delta R', 1), + ('h_collmass_pfmet', 'M_{coll}(e#tau) (GeV)', 1), + ('e_t_Mass', 'M_{vis} (GeV)', 1), + ('jetVeto30', 'number of jets (p_{T} > 30 GeV)', 1) , + ('eMtToPfMet', 'M_{T} e-PFMET', 5), + ('tMtToPfMet', 'M_{T} #tau-PFMET', 5) , + ('pfMet_Et', 'pfMet', 5) +] logging.debug("Starting plotting") for sign, proc, thr, njet in itertools.product(signs, processtype, threshold, jets): - path = os.path.join(sign, proc, thr, njet) - - plotter.set_subdir(os.path.join('embedded',path)) if embedded else plotter.set_subdir(path) - - for var, xlabel, rebin in histo_info: - logging.debug("Plotting %s/%s" % (path, var) ) - plotter.pad.SetLogy(False) - #plotter.plot_without_uncert(foldername,h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.5, sort=True, obj=['e']) - plotter.plot_with_bkg_uncert(path, var, rebin, xlabel, - leftside=False, show_ratio=True, ratio_range=1., - sort=True, obj=['e']) - - - plotter.save(var) - - plotter.set_subdir(os.path.join('embedded', path+'/selected'))if embedded else plotter.set_subdir(path+'/selected') - - for var, xlabel, rebin in histo_info: - logging.debug("Plotting %s/%s" % (path, var) ) - plotter.pad.SetLogy(False) - plotter.plot_with_bkg_uncert(path+'/selected', var, rebin, xlabel, - leftside=False, show_ratio=True, ratio_range=1., - sort=True, obj=['e']) - - - plotter.save(var,dotroot=False) + path = os.path.join(sign, proc, thr, njet) + + plotter.set_subdir(os.path.join('embedded',path)) if embedded else plotter.set_subdir(path) + + for var, xlabel, rebin in histo_info: + logging.debug("Plotting %s/%s" % (path, var) ) + plotter.pad.SetLogy(False) + #plotter.plot_without_uncert(foldername,h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.5, sort=True, obj=['e']) + plotter.plot_with_bkg_uncert(path, var, rebin, xlabel, + leftside=False, show_ratio=True, ratio_range=1., + sort=True, obj=['e']) + + + plotter.save(var) + + plotter.set_subdir(os.path.join('embedded', path+'/selected'))if embedded else plotter.set_subdir(path+'/selected') + + for var, xlabel, rebin in histo_info: + logging.debug("Plotting %s/%s" % (path, var) ) + plotter.pad.SetLogy(False) + plotter.plot_with_bkg_uncert(path+'/selected', var, rebin, xlabel, + leftside=False, show_ratio=True, ratio_range=1., + sort=True, obj=['e']) + + + plotter.save(var,dotroot=False) #make shapes for limit setting signal_region = 'os/gg/ept30/%s/selected' @@ -86,16 +96,16 @@ ] pjoin = os.path.join for njets, cat_name in jets_names: - output_dir = plotter.base_out_dir - tfile = ROOT.TFile(pjoin(output_dir, 'shapes.%s.root' % njets), 'recreate') - output_dir = tfile.mkdir(cat_name) - unc_conf_lines, unc_vals_lines = plotter.write_shapes( signal_region, 'h_collmass_pfmet', output_dir) - logging.warning('shape file %s created' % tfile.GetName()) - tfile.Close() - with open(pjoin(output_dir, 'unc.%s.conf' % njets), 'w') as conf: - conf.write('\n'.join(unc_conf_lines)) - with open(pjoin(output_dir, 'unc.%s.vals' % njets), 'w') as vals: - vals.write('\n'.join(unc_vals_lines)) + output_path = plotter.base_out_dir + tfile = ROOT.TFile(pjoin(output_path, 'shapes.%s.root' % njets), 'recreate') + output_dir = tfile.mkdir(cat_name) + unc_conf_lines, unc_vals_lines = plotter.write_shapes( signal_region % njets, 'h_collmass_pfmet', output_dir) + logging.warning('shape file %s created' % tfile.GetName()) + tfile.Close() + with open(pjoin(output_path, 'unc.%s.conf' % njets), 'w') as conf: + conf.write('\n'.join(unc_conf_lines)) + with open(pjoin(output_path, 'unc.%s.vals' % njets), 'w') as vals: + vals.write('\n'.join(unc_vals_lines)) From bca8112634743bc87733df2b1d1afd864e4f3017 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Tue, 11 Nov 2014 23:56:44 -0600 Subject: [PATCH 139/192] bugfix in automatic datacard creation --- lfvetau/BasePlotter.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index fee9b7cf..cf826a09 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -859,6 +859,7 @@ def write_shapes(self, folder, variable, output_dir, bkg_views['fakes'] = self.get_view('fakes') fake_shape = bkg_views['fakes'].Get(path) bkg_histos['fakes'] = fake_shape.Clone() + fake_shape.SetName('fakes') fake_shape.Write() unc_conf_lines = [] @@ -910,7 +911,7 @@ def write_shapes(self, folder, variable, output_dir, stat_unc_name = '%s_%s' % (target, unc_name) unc_conf_lines.append('%s %s' % (stat_unc_name, unc_conf)) unc_vals_lines.append( - '%s %s %.2f' % (category_name, target, unc_value) + '%s %s %s %.2f' % (category_name, target, stat_unc_name, unc_value) ) else: raise ValueError('systematic uncertainty type:"%s" not recognised!' % info['type']) @@ -918,7 +919,7 @@ def write_shapes(self, folder, variable, output_dir, if info['type'] <> 'stat': shift += 1 unc_vals_lines.append( - '%s %s %.2f' % (category_name, ','.join(targets), shift) + '%s %s %s %.2f' % (category_name, ','.join(targets), unc_name, shift) ) #Get signal From 2a286ebd0293fc3ef86417147ffd080e42321187 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Tue, 11 Nov 2014 23:57:50 -0600 Subject: [PATCH 140/192] fix names and uncertainties --- lfvetau/card_config/cgs.0.conf | 8 ++++---- lfvetau/card_config/cgs.1.conf | 8 ++++---- lfvetau/card_config/cgs.2.conf | 8 ++++---- lfvetau/card_config/unc.0.conf | 12 +++--------- lfvetau/card_config/unc.0.vals | 13 ++++--------- lfvetau/card_config/unc.1.conf | 9 ++------- lfvetau/card_config/unc.1.vals | 9 +++------ lfvetau/card_config/unc.2.conf | 5 +---- lfvetau/card_config/unc.2.vals | 6 +----- 9 files changed, 26 insertions(+), 52 deletions(-) diff --git a/lfvetau/card_config/cgs.0.conf b/lfvetau/card_config/cgs.0.conf index d7f519ec..2411ac9e 100644 --- a/lfvetau/card_config/cgs.0.conf +++ b/lfvetau/card_config/cgs.0.conf @@ -8,11 +8,11 @@ #data: data_obs $ GROUP signal LFVGG,LFVVBF -$ GROUP gghiggs LFVGG,SMGG126,WWGG126 -$ GROUP vbfhiggs LFVVBF,SMVBF126,WWVBF126 +$ GROUP gghiggs LFVGG,SMGG126 +$ GROUP vbfhiggs LFVVBF,SMVBF126 $ GROUP zjets ztautau,zjetsother -$ GROUP background ww,ttbar,singlet,ztautau,zjetsother,fakes -$ GROUP simulated ww,ttbar,singlet,ztautau,zjetsother,LFVVBF,SMVBF126,WWVBF126,LFVGG,SMGG126,WWGG126 +$ GROUP background diboson,ttbar,singlet,ztautau,zjetsother,fakes +$ GROUP simulated diboson,ttbar,singlet,ztautau,zjetsother,LFVVBF,SMVBF126,WWVBF126,LFVGG,SMGG126,WWGG126 categories: gg0etau signals: signal diff --git a/lfvetau/card_config/cgs.1.conf b/lfvetau/card_config/cgs.1.conf index d400591f..840186e1 100644 --- a/lfvetau/card_config/cgs.1.conf +++ b/lfvetau/card_config/cgs.1.conf @@ -8,11 +8,11 @@ #data: data_obs $ GROUP signal LFVGG,LFVVBF -$ GROUP gghiggs LFVGG,SMGG126,WWGG126 -$ GROUP vbfhiggs LFVVBF,SMVBF126,WWVBF126 +$ GROUP gghiggs LFVGG,SMGG126 +$ GROUP vbfhiggs LFVVBF,SMVBF126 $ GROUP zjets ztautau,zjetsother -$ GROUP background ww,ttbar,singlet,ztautau,zjetsother,fakes -$ GROUP simulated ww,ttbar,singlet,ztautau,zjetsother,LFVVBF,SMVBF126,WWVBF126,LFVGG,SMGG126,WWGG126 +$ GROUP background diboson,ttbar,singlet,ztautau,zjetsother,fakes +$ GROUP simulated diboson,ttbar,singlet,ztautau,zjetsother,LFVVBF,SMVBF126,LFVGG,SMGG126 categories: boostetau signals: signal diff --git a/lfvetau/card_config/cgs.2.conf b/lfvetau/card_config/cgs.2.conf index ae9e9ec1..fd444137 100644 --- a/lfvetau/card_config/cgs.2.conf +++ b/lfvetau/card_config/cgs.2.conf @@ -8,11 +8,11 @@ #data: data_obs $ GROUP signal LFVGG,LFVVBF -$ GROUP gghiggs LFVGG,SMGG126,WWGG126 -$ GROUP vbfhiggs LFVVBF,SMVBF126,WWVBF126 +$ GROUP gghiggs LFVGG,SMGG126 +$ GROUP vbfhiggs LFVVBF,SMVBF126 $ GROUP zjets ztautau,zjetsother -$ GROUP background ww,ttbar,singlet,ztautau,zjetsother,fakes -$ GROUP simulated ww,ttbar,singlet,ztautau,zjetsother,LFVVBF,SMVBF126,WWVBF126,LFVGG,SMGG126,WWGG126 +$ GROUP background diboson,ttbar,singlet,ztautau,zjetsother,fakes +$ GROUP simulated diboson,ttbar,singlet,ztautau,zjetsother,LFVVBF,SMVBF126,LFVGG,SMGG126 categories: vbfetau signals: signal diff --git a/lfvetau/card_config/unc.0.conf b/lfvetau/card_config/unc.0.conf index f988cb4d..690f525e 100755 --- a/lfvetau/card_config/unc.0.conf +++ b/lfvetau/card_config/unc.0.conf @@ -1,5 +1,5 @@ lumi lnN -Effi_E lnN +#Effi_E lnN Effi_et_Tau lnN Effi_et_Tau_highPt lnN @@ -14,19 +14,13 @@ Norm_ZTauTau lnN Norm_ZTauTau_et_0Jet_extra lnN Norm_ZJetsOther lnN -Norm_WW lnN +Norm_DIBOSON lnN Norm_TT lnN Norm_FAKES lnN Norm_FAKES_mt_0Jet lnN Norm_SMGG lnN Norm_SMVBF lnN -Norm_WWGG lnN -Norm_WWVBF lnN Norm_TOP lnN -norm_JES_muhad lnN -norm_MET_muhad lnN -shape_MuTau_TES shape -shape_FAKES shape +#shape_MuTau_TES shape -#Stat_muhad_0Jet_WWVBF126_bin20 shape diff --git a/lfvetau/card_config/unc.0.vals b/lfvetau/card_config/unc.0.vals index 0302ee8b..0db59ca5 100755 --- a/lfvetau/card_config/unc.0.vals +++ b/lfvetau/card_config/unc.0.vals @@ -8,24 +8,19 @@ gg0mutau gghiggs Theo_Scale_gg 1.08 gg0mutau vbfhiggs Theo_Scale_vbf 1.04 gg0mutau zjets Norm_ZTauTau 1.03 -gg0mutau ztautau Norm_ZTauTau_mt_0Jet_extra 1.05 +gg0mutau ztautau Norm_ZTauTau_et_0Jet_extra 1.05 gg0mutau zjetsother Norm_ZJetsOther 1.3 #TODO: check eff electron gg0mutau simulated lumi 1.026 -gg0mutau simulated Effi_E 1.02 +#gg0mutau simulated Effi_E 1.02 gg0mutau simulated Effi_et_Tau 1.06 gg0mutau simulated Effi_et_Tau_highPt 1.03 -gg0mutau ww Norm_WW 1.15 +gg0mutau diboson Norm_DIBOSON 1.15 gg0mutau singlet Norm_TOP 1.10 gg0mutau ttbar Norm_TT 1.10 gg0mutau fakes Norm_FAKES 1.30 -gg0mutau fakes Norm_FAKES_et_0Jet 1.1 +#gg0mutau signal,ztautau,SMVBF126,SMGG126 shape_MuTau_TES 1 -gg0mutau signal,ztautau,SMVBF126,SMGG126 shape_MuTau_TES 1 -gg0mutau fakes shape_FAKES 1 - -#gg0mutau SMGG126 Stat_muhad_0Jet_SMGG126_bin46 1 -#gg0mutau zjetsother norm_JES_muhad 1.098364 diff --git a/lfvetau/card_config/unc.1.conf b/lfvetau/card_config/unc.1.conf index 83bdb404..e647f7b0 100755 --- a/lfvetau/card_config/unc.1.conf +++ b/lfvetau/card_config/unc.1.conf @@ -1,5 +1,5 @@ lumi lnN -Effi_E lnN +#Effi_E lnN Effi_et_Tau lnN Effi_et_Tau_highPt lnN @@ -14,16 +14,11 @@ Theo_PDF_vbf lnN Norm_ZTauTau lnN Norm_ZTauTau_et_1Jet_extra lnN Norm_ZJetsOther lnN -Norm_WW lnN +Norm_DIBOSON lnN Norm_TT lnN Norm_FAKES lnN Norm_SMGG lnN Norm_SMVBF lnN -Norm_WWGG lnN -Norm_WWVBF lnN Norm_TOP lnN -norm_JES_muhad lnN -norm_MET_muhad lnN shape_MuTau_TES shape -shape_FAKES shape diff --git a/lfvetau/card_config/unc.1.vals b/lfvetau/card_config/unc.1.vals index c1247723..9e3cf26e 100755 --- a/lfvetau/card_config/unc.1.vals +++ b/lfvetau/card_config/unc.1.vals @@ -12,16 +12,13 @@ boostetau ztautau Norm_ZTauTau_et_1Jet_extra 1.05 boostetau zjetsother Norm_ZJetsOther 1.3 boostetau simulated lumi 1.026 -boostetau simulated Effi_E 1.02 +#boostetau simulated Effi_E 1.02 boostetau simulated Effi_et_Tau 1.06 boostetau simulated Effi_et_Tau_highPt 1.03 -boostetau ww Norm_WW 1.15 +boostetau diboson Norm_DIBOSON 1.15 boostetau singlet Norm_TOP 1.10 boostetau ttbar Norm_TT 1.10 boostetau fakes Norm_FAKES 1.30 -boostetau signal,ztautau,SMVBF126,SMGG126 shape_ETau_TES 1 -boostetau fakes shape_FAKES 1 - -#boostetau zjetsother norm_JES_muhad 1.060191 +#boostetau signal,ztautau,SMVBF126,SMGG126 shape_ETau_TES 1 diff --git a/lfvetau/card_config/unc.2.conf b/lfvetau/card_config/unc.2.conf index 5bc3188a..9373743b 100755 --- a/lfvetau/card_config/unc.2.conf +++ b/lfvetau/card_config/unc.2.conf @@ -1,5 +1,5 @@ lumi lnN -Effi_E lnN +#Effi_E lnN Effi_et_Tau lnN Effi_et_Tau_highPt lnN @@ -24,6 +24,3 @@ Norm_SMVBF lnN Norm_WWGG lnN Norm_WWVBF lnN Norm_TOP lnN - -shape_ETau_TES shape -shape_FAKES shape diff --git a/lfvetau/card_config/unc.2.vals b/lfvetau/card_config/unc.2.vals index d6d9a642..cc3c95bf 100755 --- a/lfvetau/card_config/unc.2.vals +++ b/lfvetau/card_config/unc.2.vals @@ -15,7 +15,7 @@ vbfetau ww Norm_WW_et_vbf_extra 1.5 vbfetau ttbar Norm_TT_et_vbf_extra 1.33 vbfetau simulated lumi 1.026 -vbfetau simulated Effi_E 1.02 +#vbfetau simulated Effi_E 1.02 vbfetau simulated Effi_et_Tau 1.06 vbfetau simulated Effi_et_Tau_highPt 1.03 @@ -24,7 +24,3 @@ vbfetau singlet Norm_TOP 1.10 vbfetau ttbar Norm_TT 1.10 vbfetau fakes Norm_FAKES 1.30 -vbfetau signal, ztautau, SMVBF126,SMGG126 shape_ETau_TES 1 -vbfetau fakes shape_FAKES 1 - -#vbfetau ttbar norm_JES_muhad 1.053767 From fd9877e08ddac960d40a09ff2a026dc4c7791fad Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 12 Nov 2014 00:02:53 -0600 Subject: [PATCH 141/192] update jobid --- lfvetau/jobid.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lfvetau/jobid.sh b/lfvetau/jobid.sh index 6dae8217..f71c987c 100644 --- a/lfvetau/jobid.sh +++ b/lfvetau/jobid.sh @@ -6,5 +6,5 @@ #export jobid8='newNtuple_2Sept' #export jobid8='newNtuple_1Oct' export jobidmt='MCntuples_8April' -export jobid8='newNtuple_16Oct' +export jobid8='newNtuple_5Nov' export jobidSync='newNtuple_Sync' From c49b814625d23235ee309d3e87edb78810a4b9b3 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 12 Nov 2014 00:04:24 -0600 Subject: [PATCH 142/192] major bugfixes, added additional optional positional agrument to run optimization --- lfvetau/prepare_limit.sh | 50 +++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 11 deletions(-) mode change 100644 => 100755 lfvetau/prepare_limit.sh diff --git a/lfvetau/prepare_limit.sh b/lfvetau/prepare_limit.sh old mode 100644 new mode 100755 index f736472c..ffff2c4a --- a/lfvetau/prepare_limit.sh +++ b/lfvetau/prepare_limit.sh @@ -1,46 +1,74 @@ #! /bin/env bash +#set -o nounset +set -o errexit + #$1 --> category (0, 1, 2) --> 0 jets, 1 jet, vbf #$2 --> files extensions produced by plotting (used inoptimization) category=$1 -if [[ -z "$2" ]]; +file_extension=$2 +if [ -z "$file_extension" ]; then - file_extension=$2 -else - file_extension=$1 + file_extension=$category fi input_dir=plots/$jobid/lfvet/ output_dir=limits/$jobid/$category/ -mkdir -p output_dir +mkdir -p $output_dir #copy basic config -cp card_config/cgs.$category.conf $output_dir/cgs.config -cp card_config/unc.$category.conf $output_dir/unc.config +cp card_config/cgs.$category.conf $output_dir/cgs.conf +cp card_config/unc.$category.conf $output_dir/unc.conf cp card_config/unc.$category.vals $output_dir/unc.vals #copy shape file cp $input_dir/shapes.$file_extension.root $output_dir/shapes.root #add dynamically assigned variables -cat $input_dir/unc.$file_extension.conf >> $output_dir/unc.config +cat $input_dir/unc.$file_extension.conf >> $output_dir/unc.conf cat $input_dir/unc.$file_extension.vals >> $output_dir/unc.vals #add bbb errors if [ $category == '0' ]; then - command='gg0etau:fakes' + command='gg0etau:fakes' + category_name='gg0etau' + samples='fakes' elif [ $category == '1' ]; then command='boostetau:fakes' + category_name='boostetau' + samples='fakes' else command='vbfetau:fakes,ttbar,singlet,ztautau,SMVBF126,WWVBF126' + category_name='vbfetau' + samples='fakes ttbar singlet ztautau SMVBF126' fi #TODO: normalize or not? #will it work with input and output in the same place? -add_bbb_errors.py --normalize -i $output_dir -o $output_dir $command +echo >> $output_dir/unc.conf +echo >> $output_dir/unc.vals +echo >> $output_dir/unc.conf +echo >> $output_dir/unc.vals +echo "#bbb uncertainties" >> $output_dir/unc.conf +echo "#bbb uncertainties" >> $output_dir/unc.vals +for sample in $samples; do + echo "adding bbb errors for $sample" + echo add_stat_shapes.py $output_dir/shapes.root $output_dir/shapes.root --normalize --filter $category_name/$sample --prefix $category_name + bbb_added=$(add_stat_shapes.py $output_dir/shapes.root $output_dir/shapes.root --normalize --filter $category_name/$sample --prefix $category_name | grep _bin_) + echo >> $output_dir/unc.conf + echo >> $output_dir/unc.vals + for unc in $bbb_added; do + echo $unc shape >> $output_dir/unc.conf + echo $category_name $sample $unc 1.0 >> $output_dir/unc.vals + done +done #build datacard pushd $output_dir -mkdir 126 +mkdir -p 126 +pushd 126 +rm -rf shapes.root +ln -s ../shapes.root +popd create-datacard.py -i shapes.root -o 126/datacard.txt popd From 93514fb466c1a5a69814a09336c2a7518a0e2d96 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Wed, 12 Nov 2014 03:25:42 -0600 Subject: [PATCH 143/192] adding electron fake rate --- lfvetau/EleFakeRateAnalyzerMVA.py | 15 +++---- lfvetau/LFVHETauAnalyzerMVA.py | 72 ++++++++++++++++++++++++++++--- lfvetau/fakerate_functions.py | 18 ++++++++ lfvetau/mcCorrections.py | 21 +++++++-- 4 files changed, 107 insertions(+), 19 deletions(-) diff --git a/lfvetau/EleFakeRateAnalyzerMVA.py b/lfvetau/EleFakeRateAnalyzerMVA.py index f10ec340..9af2da35 100644 --- a/lfvetau/EleFakeRateAnalyzerMVA.py +++ b/lfvetau/EleFakeRateAnalyzerMVA.py @@ -86,13 +86,10 @@ def event_weight(self, row): #if bool(row.e1MatchesEle27WP80) and not bool(row.e2MatchesEle27WP80) : etrig = 'e1' #if not bool(row.e1MatchesEle27WP80) and bool(row.e2MatchesEle27WP80) : etrig = 'e2' return self.pucorrector(row.nTruePU) * \ - mcCorrections.get_electronId_corrections13_MVA(row, 'e1') * \ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e1') * \ - mcCorrections.get_electronId_corrections13_MVA(row, 'e2') * \ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e2')* \ - mcCorrections.get_electronId_corrections13_MVA(row, 'e3') * \ - mcCorrections.get_electronIso_corrections13_MVA(row, 'e3') * \ - mcCorrections.get_trigger_corrections_MVA(row, etrig) + mcCorrections.eid_correction( row, 'e1', 'e2', 'e3') * \ + mcCorrections.eiso_correction(row, 'e1', 'e2', 'e3') * \ + mcCorrections.trig_correction(row, etrig ) + ##add the trigger correction def begin(self): @@ -172,7 +169,7 @@ def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): #histos[folder+'/tMtToPFMET'].Fill(row.tMtToPFMET,weight) - histos[folder+'/type1_pfMetEt'].Fill(row.type1_pfMetEt) + histos[folder+'/type1_pfMetEt'].Fill(row.type1_pfMet_Et) histos[folder+'/ee3DR'].Fill(ee3DR(row)) histos[folder+'/ee3DPhi'].Fill(ee3DPhi(row)) histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight) @@ -230,7 +227,7 @@ def process(self): if not abs(row.e1_e2_Mass-91.2) < 20: continue cut_flow_trk.Fill('ZMass') - if not selections.lepton_id_iso(row, 'e3', 'eid13Tight_mvaLoose'): continue + if not selections.lepton_id_iso(row, 'e3', 'eid13Loose_idiso02'): continue #very loose loose eid13Tight_mvaLoose cut_flow_trk.Fill('tsel') diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index eb28446d..850c30d4 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -14,7 +14,7 @@ from FinalStateAnalysis.PlotTools.decorators import memo_last from FinalStateAnalysis.PlotTools.MegaBase import MegaBase from math import sqrt, pi, cos -from fakerate_functions import tau_fake_rate, tau_fake_rate_up, tau_fake_rate_dw +from fakerate_functions import tau_fake_rate, tau_fake_rate_up, tau_fake_rate_dw, e_fake_rate, e_fake_rate_up, e_fake_rate_dw import itertools import traceback from FinalStateAnalysis.PlotTools.decorators import memo @@ -109,6 +109,9 @@ def __init__(self, tree, outfile, **kwargs): self.is_data = target.startswith('data_') self.is_embedded = ('Embedded' in target) self.is_mc = not (self.is_data or self.is_embedded) + self.efake = e_fake_rate(0.2) + self.efakeup = e_fake_rate_up(0.2) + self.efakedw = e_fake_rate_dw(0.2) #systematics used self.systematics = { @@ -179,8 +182,9 @@ def event_weight(self, row, sys_shifts): return {'' : 1.} weights = {} - embedded_weight = row.EmbPtWeight if self.is_embedded else 1. for shift in sys_shifts: + embedded_weight = row.EmbPtWeight*mcCorrections.eEmb_correction( row, 'e', shift=shift) if self.is_embedded else 1. + weights[shift] = embedded_weight *\ mcCorrections.eid_correction( row, 'e', shift=shift) * \ mcCorrections.eiso_correction(row, 'e', shift=shift) * \ @@ -199,7 +203,9 @@ def begin(self): self.systematics['tvetos'] + \ self.systematics['evetos'] + \ ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + \ - ['tesUp', 'tesDown'] + ['tesUp', 'tesDown'] +\ + ['eLoose', 'eLoose/Up', 'eLoose/Down'] +\ + ['etLoose', 'etLoose/Up', 'etLoose/Down'] sys_shifts = list( set( sys_shifts ) ) #remove double dirs processtype=['gg'] threshold=['ept30'] @@ -305,11 +311,31 @@ def fakerate_weights(self, tEta): tLoose = tLoose / (1. - tLoose ) tLooseUp = tLooseUp / (1. - tLooseUp ) tLooseDown= tLooseDown / (1. - tLooseDown) + + + eLoose = self.efake + eLooseUp = self.efakeup + eLooseDown= self.efakedw + + eLoose = eLoose / (1. - eLoose ) + eLooseUp = eLooseUp / (1. - eLooseUp ) + eLooseDown= eLooseDown / (1. - eLooseDown) + + + etLoose = tLoose * eLoose + etLooseUp = tLooseUp * eLooseUp + etLooseDown= tLooseDown *eLooseDown frweight = { 'tLoose' : tLoose , 'tLoose/Up' : tLooseUp , 'tLoose/Down' : tLooseDown, + 'eLoose' : eLoose , + 'eLoose/Up' : eLooseUp , + 'eLoose/Down' : eLooseDown, + 'etLoose' : etLoose , + 'etLoose/Up' : etLooseUp , + 'etLoose/Down' : etLooseDown, 'tLooseUnweight' : 1., } @@ -394,10 +420,13 @@ def process(self): if not row.tAntiElectronMVA5Tight : continue if not row.tAntiMuon2Loose : continue if not row.tLooseIso3Hits : continue - + logging.debug('object selection passed') #e ID/ISO - if not selections.lepton_id_iso(row, 'e', 'eid13Tight_etauiso01'): continue + if not selections.lepton_id_iso(row, 'e', 'eid13Tight_idiso02'): continue logging.debug('Passed preselection') + isETight = False + if selections.lepton_id_iso(row, 'e', 'eid13Tight_etauiso01'): isETight = True + logging.debug('tigh electron: %s' %isETight) # # Compute event weight @@ -423,6 +452,8 @@ def process(self): #tau ID, id Tau is tight then go in full selection, otherwise use for fakes tau_id_category = [''] if row.tTightIso3Hits else ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + e_id_category = [''] if isETight else ['eLoose', 'eLoose/Up', 'eLoose/Down'] + et_id_category = [''] if isETight and row.tTightIso3Hits else ['etLoose', 'etLoose/Up', 'etLoose/Down'] isTauTight = bool(row.tTightIso3Hits) #jet category @@ -530,7 +561,7 @@ def process(self): #remove duplicates sys_directories = list(set(sys_directories)) - if not isTauTight: + if not isTauTight and isETight: #if is a loose tau just compute the fakes! sys_directories = tau_id_category @@ -543,6 +574,35 @@ def process(self): #...times the mc weight (if any) weight_map[i] *= mc_weight + if not isETight and isTauTight: + #if is a loose tau just compute the fakes! + sys_directories = e_id_category + logging.debug('fake electron') + #gather the one and only weight we do care about + mc_weight = weight_map[''] + + #weights are the fr ones... + weight_map = self.fakerate_weights(row.eEta) + for i in weight_map: + #...times the mc weight (if any) + weight_map[i] *= mc_weight + + if not isETight and not isTauTight: + #if is a loose tau just compute the fakes! + sys_directories = et_id_category + + #gather the one and only weight we do care about + mc_weight = weight_map[''] + + #weights are the fr ones... + weight_map = self.fakerate_weights(row.tEta) + for i in weight_map: + #...times the mc weight (if any) + weight_map[i] *= mc_weight + + + + #Fill histograms in appropriate direcotries #if passes_full_selection: #dirs = [os.path.join(sys, sign, processtype, e_thr, jet_dir) for sys, e_thr, jet_dir in itertools.product(sys_directories, ptthreshold, jet_directories)] diff --git a/lfvetau/fakerate_functions.py b/lfvetau/fakerate_functions.py index 04815f4c..afe34a9b 100644 --- a/lfvetau/fakerate_functions.py +++ b/lfvetau/fakerate_functions.py @@ -35,4 +35,22 @@ def fcn(*args): '1D' ) +efrfit_dir = os.path.join('results', os.environ['jobid'], 'efakerate_fits')+'/' + +e_fake_rate = build_roofunctor( + efrfit_dir+'e_os_eLoose_eTigh_e3AbsEta.root', + 'fit_efficiency', + 'efficiency' +) +e_fake_rate_up = make_corrector_from_histo( + efrfit_dir+'e_os_eLoose_eTigh_e3AbsEta_2.root', + 'efficiency_up', + '1D' +) + +e_fake_rate_dw = make_corrector_from_histo( + efrfit_dir+'e_os_eLoose_eTigh_e3AbsEta_2.root', + 'efficiency_dw', + '1D' +) diff --git a/lfvetau/mcCorrections.py b/lfvetau/mcCorrections.py index a1d5de32..07548d93 100755 --- a/lfvetau/mcCorrections.py +++ b/lfvetau/mcCorrections.py @@ -85,10 +85,10 @@ def make_multiple(fcn, indexed=False, shift=0): def multiple(row,*args): ret = 1. for arg in args: - abseta = getattr( - row, - getVar(arg,'Eta') - ) + abseta = getattr( + row, + getVar(arg,'Eta') + ) pt = getattr(row, getVar(arg,'Pt')) fcn_ret = fcn(pt,abseta) if indexed: @@ -127,6 +127,11 @@ def multiple(row,*args): efficiency_trigger_mva_up = make_multiple(HetauCorrection.single_ele_eff_mva, indexed=True, shift=1) efficiency_trigger_mva_dw = make_multiple(HetauCorrection.single_ele_eff_mva, indexed=True, shift=-1) +correct_eEmb = make_multiple(HetauCorrection.correct_eEmb,indexed=True) +correct_eEmb_p1s = make_multiple(HetauCorrection.correct_eEmb,indexed=True, shift=1) +correct_eEmb_m1s = make_multiple(HetauCorrection.correct_eEmb,indexed=True, shift=-1) + + eiso_correction = make_shifted_weights( correct_eiso13_mva, ['eisop1s','eisom1s'], @@ -139,6 +144,13 @@ def multiple(row,*args): [correct_eid13_p1s_mva, correct_eid13_m1s_mva] ) +eEmb_correction = make_shifted_weights( + correct_eEmb, + ['eEmbp1s','eEmbm1s'], + [correct_eEmb_p1s, correct_eEmb_m1s] +) + + trig_correction = make_shifted_weights( correct_trigger_mva, ['trp1s', 'trm1s'], @@ -150,3 +162,4 @@ def multiple(row,*args): ['trp1s', 'trm1s'], [efficiency_trigger_mva_up, efficiency_trigger_mva_dw] ) + From 73ac677ffb38dc27a73926fbd964db43741391c7 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 12 Nov 2014 04:11:35 -0600 Subject: [PATCH 144/192] fix bugs in limit setting --- lfvetau/Rakefile | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index c249eeff..bbfed274 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -354,23 +354,27 @@ task :drawTauFakeRate => get_plotter_results("plotTauFakeRate.py") $shapedir = "plots/#{$jobid}/lfvet/" #All shape files are made at the same time -file "#{$shapedir}/.shapes_timestamp" => get_analyzer_results("LFVHETauAnalyzer.py", - samples['signalMCgg'] + \ - samples['signalMCvbf'] + \ - samples['ggHiggsTo2Taus'] + \ - samples['vbfHiggsTo2Taus'] + \ - samples['ttbar'] + \ - samples['singlet'] + \ - samples['singletbar'] + \ - samples['wjets'] + \ - samples['wwjets'] + \ - samples['wzjets'] + \ - samples['zzjets'] + \ - samples['zjets']) do |t| - sh "python plotRecoQuantitiesMVA.py" +## file "#{$shapedir}/.shapes_timestamp" => get_analyzer_results("LFVHETauAnalyzer.py", +## samples['signalMCgg'] + \ +## samples['signalMCvbf'] + \ +## samples['ggHiggsTo2Taus'] + \ +## samples['vbfHiggsTo2Taus'] + \ +## samples['ttbar'] + \ +## samples['singlet'] + \ +## samples['singletbar'] + \ +## samples['wjets'] + \ +## samples['wwjets'] + \ +## samples['wzjets'] + \ +## samples['zzjets'] + \ +## samples['zjets']) do |t| +## sh "python plotRecoQuantitiesMVA.py" +## sh "touch #{t.name}" +## end +file "#{$shapedir}/.shapes_timestamp" => [] do |t| sh "touch #{t.name}" end + ## ## Prepare datacards ## @@ -398,8 +402,9 @@ file cmb_card => [card_0_jet, chdir("#{$limitdir}/et_cmb/126") do sh "rm -f shapes.root" sh "ln -s ../shapes.root" + local_paths = t.prerequisites.map{|x| x.sub($limitdir,'../../')} + sh "combine_cards_with_names.sh #{ local_paths.join(' ')} > datacard.txt" end - sh "combine_cards_with_names.sh #{ t.prerequisites.join(' ')} > #{cmb_card}" end #TODO combination! @@ -442,9 +447,11 @@ task :limits => [ def compute_significance(category) #input file does not matter since shape files are made all at once datacard = "#{$limitdir}/#{category}/126/datacard.txt" - timestamp = "#{$limitdir}/#{category}/.limit_timestamp" + timestamp = "#{$limitdir}/#{category}/.significance_timestamp" file timestamp => datacard do |t| - sh "compute_significance.sh #{$limitdir}/#{category}/126 #{$blind}" + chdir("#{$limitdir}/#{category}") do + sh "compute_significance.sh 126 #{$blind} datacard.txt" + end sh "touch #{t.name}" end return timestamp @@ -455,10 +462,10 @@ significance_1_jet = compute_significance('1') significance_2_jet = compute_significance('2') significance_c_jet = compute_significance('et_cmb') #TODO combination! -task :limits => [ +task :significance => [ significance_0_jet, significance_1_jet, significance_2_jet, - significance_c_jet +# significance_c_jet ] From 001cf85bfc4782159e95b7f586544471c2b8f1c0 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 12 Nov 2014 04:12:10 -0600 Subject: [PATCH 145/192] first real optimizer commit --- lfvetau/optimizer.py | 139 +++++++++++++++---------------------------- 1 file changed, 49 insertions(+), 90 deletions(-) diff --git a/lfvetau/optimizer.py b/lfvetau/optimizer.py index 1becd2eb..21364858 100644 --- a/lfvetau/optimizer.py +++ b/lfvetau/optimizer.py @@ -4,104 +4,63 @@ import os import itertools -RUN_OPTIMIZATION = ('RUN_OPTIMIZATION' in os.environ) and eval(os.environ['RUN_OPTIMIZATION']) - -lep_id = [ - 'eid12Tight_h2taucuts', - 'eid12Tight_h2taucuts020', - #'eid12Loose_h2taucuts', - #'eid12Loose_h2taucuts020', - 'eid12Medium_h2taucuts', - 'eid12Medium_h2taucuts020' - ] \ - if RUN_OPTIMIZATION else \ - [ - #'eid12Loose_h2taucuts', - #'eid12Loose_h2taucuts020', - 'eid12Tight_h2taucuts', - 'eid12Medium_h2taucuts020', - 'eid12Medium_h2taucuts' - ] +def make_0j_selector(tthr, ethr, e_t_DPhi, tMT): + def selector(row): + return row.tPt > tthr and \ + row.ePt > ethr and \ + row.e_t_DPhi > e_t_DPhi and \ + row.tMtToPfMet < tMT + return selector -LT_cut = [ - 0, - 80, - 110, - 140, - 170, - 200, - 3000 - ] +def make_1j_selector(tthr, ethr, tMT): + def selector(row): + return row.tPt > tthr and \ + row.ePt > ethr and \ + row.tMtToPfMet < tMT + return selector -tauIDs = [ - 'tMediumIso3Hits', - None - ] +def make_2j_selector(tthr, ethr, tMT, vbfmass, vbfdeta): + def selector(row): + return row.tPt > tthr and \ + row.ePt > ethr and \ + row.tMtToPfMet < tMT and \ + row.vbfMass > vbfmass and \ + row.vbfDeta > vbfdeta + return selector -tauPTs = [ - 0, - 30, - 40, - 60 - ] +RUN_OPTIMIZATION = ('RUN_OPTIMIZATION' in os.environ) and eval(os.environ['RUN_OPTIMIZATION']) -charge_fakes = [ - 80, - ] +grid_search = { + 0 : {}, + 1 : {}, + 2 : {}, +} -grid_search = {} -counter_1, counter_2, counter_3, counter_4 = 0, 0, 0, 0 if RUN_OPTIMIZATION: - for lead_id, sublead_id, lt_thr, tauID, tauPT, charge_fakes in \ - itertools.product(lep_id, lep_id, LT_cut, tauIDs, tauPTs, charge_fakes): - cut_name = '%s:%s:%s:%s:%s:%s' % (lead_id, sublead_id, lt_thr, tauID, tauPT, charge_fakes) - counter_1 += 1 - if (lead_id.startswith('eid13Loose') or sublead_id.startswith('eid13Loose')) and \ - not (lead_id.startswith('eid13Loose') and sublead_id.startswith('eid13Loose')): - continue - counter_2 += 1 - if tauPT > 0 and lt_thr > 0: - continue - counter_3 += 1 - ## if lt_thr and not tauID: - ## continue - ## counter_4 += 1 - grid_search[cut_name] = { - 'leading_iso' : lead_id, - 'subleading_iso' : sublead_id, - 'LT' : lt_thr, - 'tauID': tauID, - 'tauPT': tauPT, - 'charge_fakes' : charge_fakes, - } -else: - grid_search['MMT'] = { - 'leading_iso' : 'eid12Medium_h2taucuts', - 'subleading_iso' : 'eid12Medium_h2taucuts020', - 'LT' : 50, - 'tauID' : None, - 'tauPT' : 0, - 'charge_fakes' : 80, - } - grid_search['EMT'] = { - 'leading_iso' : 'eid12Medium_h2taucuts', - 'subleading_iso' : 'eid12Medium_h2taucuts', - 'LT' : 50, - 'tauID' : None, - 'tauPT' : 0, - 'charge_fakes' : 80, - } - grid_search['EET'] = { - 'leading_iso' : 'eid12Tight_h2taucuts', - 'subleading_iso' : 'eid12Medium_h2taucuts020', - 'LT' : 50, - 'tauID' : None, - 'tauPT' : 0, - 'charge_fakes' : 100, - } + t_thrs = range(20,70,10)+[35,45] + e_thr = range(20,70,10)+[35,45] + + mt_thr = range(0,50,10)+[35] + dphi = [3.14, 3.00, 2.7, 2.4, 2.2] + vbf_mass = range(400, 700, 100) + [550] + vbf_deta = [3.0, 3.5, 4.0] + + gg_template = 't%i_e%i_dp%.1f_mt%i' + for thresholds in itertools.product(t_thrs, e_thr, dphi, mt_thr): + grid_search[0][gg_template % thresholds] = make_0j_selector(*thresholds) + + boost_template = 't%i_e%i_mt%i' + for thresholds in itertools.product(t_thrs, e_thr, mt_thr): + grid_search[1][boost_template % thresholds] = make_1j_selector(*thresholds) + + vbf_template = 't%i_e%i_mt%i_vbfm%i_vbfeta%i' + for thresholds in itertools.product(t_thrs, e_thr, mt_thr, vbf_mass, vbf_deta): + grid_search[2][vbf_template % thresholds] = make_2j_selector(*thresholds) if __name__ == "__main__": - print '\n'.join(grid_search.keys()) + from pdb import set_trace + set_trace() + #print '\n'.join(grid_search.keys()) else: print "Running optimization: %s" % RUN_OPTIMIZATION From e1666f0f30eeb937d1a5844a41084a1e79d36266 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Wed, 12 Nov 2014 10:56:39 -0600 Subject: [PATCH 146/192] eLoose bug fix --- lfvetau/BasePlotter.py | 2 +- lfvetau/LFVHETauAnalyzerMVA.py | 2 +- lfvetau/Rakefile | 40 +++++++++++++++++++++++++++++----- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index cf826a09..301fc948 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -106,7 +106,7 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): self.blind_region=blind_region if self.blind_region: # Don't look at the SS all pass region - blinder = lambda x: BlindView(x, "os/.*mass*",blind_in_range(*self.blind_region)) + blinder = lambda x: BlindView(x, "os/.*ass*",blind_in_range(*self.blind_region)) super(BasePlotter, self).__init__(files, lumifiles, outputdir, blinder, forceLumi=forceLumi) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index d458fa0a..9cc25a64 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -205,7 +205,7 @@ def begin(self): ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + \ ['tesUp', 'tesDown'] +\ ['eLoose', 'eLoose/Up', 'eLoose/Down'] +\ - ['etLoose', 'etLoose/Up', 'etLoose/Down'] + ['etLoose', 'etLoose/Up', 'etLoose/Down'] +\ ['tesUp', 'tesDown'] sys_shifts = list( set( sys_shifts ) ) #remove double dirs processtype=['gg'] diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index c249eeff..439781fa 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -80,6 +80,8 @@ $frfit_dirMC = "results/#{$jobid}/fakerate_fits_MC" directory $frfit_dirMC $efrfit_dir = "results/#{$jobid}/efakerate_fits" directory $efrfit_dir +$efrfit_dirMC = "results/#{$jobid}/efakerate_fits_MC" +directory $efrfit_dirMC exponential = "scale*TMath::Exp(x*decay)+offset" exponential_vars = "scale[4., 0, 10],decay[-1e-2, -1, -1e-4],offset[1e-2, 0, 0.5]" exponentialpol1 = "scale*TMath::Exp(x*decay)+offset+slope*x" @@ -88,9 +90,9 @@ landau = "scale*TMath::Landau(x,mu,sigma,0)+offset" landau_vars = "scale[0.5, 0, 15],mu[5, 0, 30],sigma[1.9, 0.1, 20],offset[1e-2, 0, 0.5]" pol0 = "const" -pol0_vars = "const[ 0.01, 0, 1]" +pol0_vars = "const[ 0.5, 0, 1]" pol1 = "p0+p1*x" -pol1_vars = "p0[ 0.5, 0, 1], p1[ -0.001, -1, 1]" +pol1_vars = "p0[ 0.5, 0, 1], p1[ -0.1, -1, 1]" pol2 = "p0+p1*x+p2*x*x" pol2_vars = "p0[ 0.05, 0, 1], p1[ -0.005, -1, 1], p2[ 0.005, 0, 1]" @@ -160,8 +162,8 @@ fr_fits["t_os_tLoose_tTigh_tAbsEta"] = Hash[ efr_fits["e_os_eLoose_eTigh_e3AbsEta"] = Hash[ "samples" => Array["diboson", "dataSingleE", "zjets_skimmedLL"], "analyzer" => $efr_analyzer, - "function" => pol2, - "variables" => pol2_vars, + "function" => pol1, + "variables" => pol1_vars, "rebin" => 1, "range" => "0 2.3", #"range" => "-2.3 2.3", @@ -176,6 +178,8 @@ efr_fits["e_os_eLoose_eTigh_e3AbsEta"] = Hash[ task :fits => [] task :fitsMC => [] +task :efitsMC => [] + task :efits => [] fr_fits.each do |fit, fit_info| @@ -198,8 +202,31 @@ fr_fits.each do |fit, fit_info| puts "" end - task :fits_MC => fit_output + task :fits_MC => fit_output + +end + +efr_fits.each do |fit, fit_info| + fit_configuration = fit.split("_") + sign = fit_configuration[1] + denom = fit_configuration[2] + num = fit_configuration[3] + var = fit_configuration[4] + subsample_inputs = samples['zjets_skimmedLL'] + fit_output = $efrfit_dirMC + "/#{fit}.root" + subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/#{fit_info['analyzer']}/#{x}.root"} + subsample_input_list = subsamples_inputs_result_list.join(" ") + denom_path = Array[sign, denom,var].join("/") + num_path = Array[sign, num, var].join("/") + + file fit_output => subsamples_inputs_result_list + [fit_info['analyzer'] + '.py'] do |t| + sh "mkdir -p #{$efrfit_dirMC}" + sh "fit_efficiency_chi2.py #{fit_output} '#{num_path}' '#{denom_path}' \'#{pol0}\' \'#{pol0_vars}\' #{subsample_input_list} --plot --xrange #{fit_info['range']} --xtitle \'#{fit_info['title']}\' --min \'#{fit_info['min']}\' --max \'#{fit_info['max']}\' --show-error --rebin #{fit_info['rebin']} " + puts "" + end + + task :efits_MC => fit_output end fr_fits.each do |fit, fit_info| @@ -334,7 +361,8 @@ task :fakeeeeMVA => get_analyzer_results("EleFakeRateAnalyzerMVA.py", #samples[' samples['zjets'] + samples['wwjets'] + samples['zzjets'] + samples['wzjets'] + - samples['dataSingleE']) + samples['dataSingleE'] + ) $etdir = "plots/#{$jobid}/LFVHETauAnalyzer/et/" From bf2554c105421d2b3d3f133ac64201694559f875 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Thu, 13 Nov 2014 10:29:46 -0600 Subject: [PATCH 147/192] eFake bug fix --- lfvetau/EleFakeRateAnalyzerMVA.py | 9 +-------- lfvetau/LFVHETauAnalyzerMVA.py | 11 +++++------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/lfvetau/EleFakeRateAnalyzerMVA.py b/lfvetau/EleFakeRateAnalyzerMVA.py index 9af2da35..bba86070 100644 --- a/lfvetau/EleFakeRateAnalyzerMVA.py +++ b/lfvetau/EleFakeRateAnalyzerMVA.py @@ -75,20 +75,13 @@ def event_weight(self, row): if row.run > 2: #FIXME! add tight ID correction return 1. - etrig = 'e1' - if row.e2Pt > row.e1Pt : etrig = 'e2' - if bool(row.e1MatchesSingleE27WP80) and not bool(row.e2MatchesSingleE27WP80) : etrig = 'e1' - if not bool(row.e1MatchesSingleE27WP80) and bool(row.e2MatchesSingleE27WP80) : etrig = 'e2' - - if bool(row.e3MatchesSingleE27WP80) and not bool(row.e1MatchesSingleE27WP80) and not bool(row.e2MatchesSingleE27WP80) : etrig ='e3' - #if bool(row.e1MatchesEle27WP80) and not bool(row.e2MatchesEle27WP80) : etrig = 'e1' #if not bool(row.e1MatchesEle27WP80) and bool(row.e2MatchesEle27WP80) : etrig = 'e2' return self.pucorrector(row.nTruePU) * \ mcCorrections.eid_correction( row, 'e1', 'e2', 'e3') * \ mcCorrections.eiso_correction(row, 'e1', 'e2', 'e3') * \ - mcCorrections.trig_correction(row, etrig ) + mcCorrections.trig_correction(row, 'e3' ) ##add the trigger correction diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 9cc25a64..1388ee71 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -124,7 +124,7 @@ def __init__(self, tree, outfile, **kwargs): 'tvetos': (['', 'tVetoUp', 'tVetoDown'] if self.is_mc else ['']), 'evetos': (['', 'eVetoUp', 'eVetoDown'] if self.is_mc else ['']), 'met' : ([ "_jes_plus", "_mes_plus", "_tes_plus", "_ees_plus", "_ues_plus", "_jes_minus", "_mes_minus", "_tes_minus", "_ees_minus", "_ues_minus"] if self.is_mc else []), - 'tes' : (["_tes_plus","_tes_minus"]), + 'tes' : (["_tes_plus","_tes_minus"]if self.is_mc else ['']), } #self filling histograms @@ -205,8 +205,7 @@ def begin(self): ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + \ ['tesUp', 'tesDown'] +\ ['eLoose', 'eLoose/Up', 'eLoose/Down'] +\ - ['etLoose', 'etLoose/Up', 'etLoose/Down'] +\ - ['tesUp', 'tesDown'] + ['etLoose', 'etLoose/Up', 'etLoose/Down'] sys_shifts = list( set( sys_shifts ) ) #remove double dirs processtype=['gg'] threshold=['ept30'] @@ -551,9 +550,9 @@ def process(self): tes_directories =[] for tdir,tbool in tes_categories: if tbool==True: tes_directories.append(tdir) - if tdir == '' and tbool==False : - all_dirs=[] - syst_shifts=[] + #if tdir == '' and tbool==False : + # all_dirs=[] + # syst_shifts=[] sys_directories = all_dirs + sys_shifts +tes_directories #remove duplicates From 6fc37f842872e564fa4062ce71ed9448ef0a5aca Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Fri, 14 Nov 2014 04:00:44 -0600 Subject: [PATCH 148/192] baseSelections.py --- lfvetau/baseSelections.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lfvetau/baseSelections.py b/lfvetau/baseSelections.py index 3f0a4d99..4740caea 100755 --- a/lfvetau/baseSelections.py +++ b/lfvetau/baseSelections.py @@ -22,7 +22,7 @@ def muSelection(row, name): def eSelection(row, name): eAbsEta = getattr( row, getVar(name,'AbsEta')) - if getattr( row, getVar(name,'Pt')) < 20: return False #was 20 + if getattr( row, getVar(name,'Pt')) < 30: return False #was 20 if eAbsEta > 2.3: return False if getattr( row, getVar(name,'MissingHits')): return False if getattr( row, getVar(name,'HasConversion')): return False From 59790e0a753085e052ac8b25f920c0a01bc94098 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Fri, 14 Nov 2014 08:49:00 -0600 Subject: [PATCH 149/192] elefake bug fix --- lfvetau/BasePlotter.py | 15 ++++++++------- lfvetau/EleFakeRateAnalyzerMVA.py | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index 301fc948..07b82b2d 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -198,12 +198,13 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): '+' : lambda x: x, '-' : lambda x: x, 'apply_to' : ['fakes','simbkg'], - } - ## 'TES' : { TODO! MISSING - ## 'type' : 'shape', - ## '+' : , - ## '-' : , - ## }, + }, + 'TES' : { + 'type' : 'shape', + '+' : dir_systematic('tesUp'), + '-' : dir_systematic('tesDown'), + 'apply_to' : ['simbkg'], + }, } @@ -680,7 +681,7 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', fakes_view, [('Up','Down')] ) - + fakes = SystematicsView.add_error(fakes, 0.30) #add them to backgrounds mc_stack.Add(fakes) diff --git a/lfvetau/EleFakeRateAnalyzerMVA.py b/lfvetau/EleFakeRateAnalyzerMVA.py index bba86070..a3e8c1ec 100644 --- a/lfvetau/EleFakeRateAnalyzerMVA.py +++ b/lfvetau/EleFakeRateAnalyzerMVA.py @@ -219,7 +219,7 @@ def process(self): cut_flow_trk.Fill('e2IDiso') if not abs(row.e1_e2_Mass-91.2) < 20: continue cut_flow_trk.Fill('ZMass') - + if not selections.eSelection(row, 'e3'): continue if not selections.lepton_id_iso(row, 'e3', 'eid13Loose_idiso02'): continue #very loose loose eid13Tight_mvaLoose cut_flow_trk.Fill('tsel') From 951f093e08fea819c32a6278c1287b8bceac70fd Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Wed, 19 Nov 2014 05:38:14 -0600 Subject: [PATCH 150/192] adding tau overlap check --- lfvetau/EleFakeRateAnalyzerMVA.py | 90 ++++++++++++++++++------------- lfvetau/LFVHETauAnalyzerMVA.py | 2 +- lfvetau/TauFakeRateAnalyzerMVA.py | 1 + lfvetau/baseSelections.py | 4 ++ 4 files changed, 60 insertions(+), 37 deletions(-) diff --git a/lfvetau/EleFakeRateAnalyzerMVA.py b/lfvetau/EleFakeRateAnalyzerMVA.py index a3e8c1ec..3004ecd8 100644 --- a/lfvetau/EleFakeRateAnalyzerMVA.py +++ b/lfvetau/EleFakeRateAnalyzerMVA.py @@ -35,22 +35,6 @@ def deltaR(phi1, phi2, eta1, eta2): if (dphi>pi) : dphi = 2*pi-dphi return sqrt(deta*deta + dphi*dphi); -def ee3DR(row): - return row.e1_e3_DR if row.e1_e3_DR < row.e2_e3_DR else row.e2_e3_DR - -def ee3DPhi(row): - e1e3DPhi=deltaPhi(row.e1Phi, row.e3Phi) - e2e3DPhi=deltaPhi(row.e2Phi, row.e3Phi) - return e1e3DPhi if e1e3DPhi < e2e3DPhi else e2e3DPhi - -def Z(row): - e1p=ROOT.TVector3(row.e1Pt*cos(row.e1Phi),row.e1Pt*sin(row.e1Phi),row.e1Pt*sinh(row.e1Eta)) - e2p=ROOT.TVector3(row.e2Pt*cos(row.e2Phi),row.e2Pt*sin(row.e2Phi),row.e2Pt*sinh(row.e2Eta)) - e1FourVector= ROOT.TLorentzVector(e1p, sqrt(e1p.Mag2()+row.e1Mass*row.e1Mass)) - e2FourVector= ROOT.TLorentzVector(e2p, sqrt(e2p.Mag2()+row.e2Mass*row.e2Mass)) - zFourVector = e1FourVector+e2FourVector - return zFourVector - class EleFakeRateAnalyzerMVA(MegaBase): tree = 'eee/final/Ntuple' @@ -61,7 +45,9 @@ def __init__(self, tree, outfile, **kwargs): self.out=outfile self.histograms = {} self.pucorrector = mcCorrections.make_puCorrector('singlee') - + self.mye1 = 'e1' + self.mye2 = 'e2' + self.mye3 = 'e3' optimizer_keys = [ i for i in optimizer.grid_search.keys() if i.startswith(self.channel) ] self.grid_search = {} if len(optimizer_keys) > 1: @@ -79,9 +65,28 @@ def event_weight(self, row): #if bool(row.e1MatchesEle27WP80) and not bool(row.e2MatchesEle27WP80) : etrig = 'e1' #if not bool(row.e1MatchesEle27WP80) and bool(row.e2MatchesEle27WP80) : etrig = 'e2' return self.pucorrector(row.nTruePU) * \ - mcCorrections.eid_correction( row, 'e1', 'e2', 'e3') * \ - mcCorrections.eiso_correction(row, 'e1', 'e2', 'e3') * \ - mcCorrections.trig_correction(row, 'e3' ) + mcCorrections.eid_correction( row, self.mye1, self.mye2, self.mye3) * \ + mcCorrections.eiso_correction(row, self.mye1, self.mye2, self.mye3) * \ + mcCorrections.trig_correction(row, self.mye3 ) + + def ee3DR(row): + return getattr(row, self.mye1+'_'+self.mye3+'_DR') if getattr(row, self.mye1+'_'+self.mye3+'_DR') < getattr(row, self.mye2+'_'+self.mye3+'_DR') else getattr(row, self.mye2+'_'+self.mye3+'_DR') + + def ee3DPhi(row): + e1e3DPhi=deltaPhi(getattr(row, self.mye1+'Phi'), getattr(row, self.mye3+'Phi')) + e2e3DPhi=deltaPhi(getattr(row, self.mye2+'Phi'), getattr(row, self.mye3+'Phi')) + return e1e3DPhi if e1e3DPhi < e2e3DPhi else e2e3DPhi + + def Z(row): + e1p=ROOT.TVector3(getattr(row, self.mye1+'Pt')*cos(getattr(row, self.mye1+'Phi')),getattr(row, self.mye1+'Pt')*sin(getattr(row, self.mye1+'Phi')),getattr(row, self.mye1+'Pt')*sin(getattr(row, self.mye1+'Eta'))) + e2p=ROOT.TVector3(getattr(row, self.mye2+'Pt')*cos(getattr(row, self.mye2+'Phi')),getattr(row, self.mye2+'Pt')*sin(getattr(row, self.mye2+'Phi')),getattr(row, self.mye2+'Pt')*sin(getattr(row, self.mye2+'Eta'))) + e1FourVector= ROOT.TLorentzVector(e1p, sqrt(e1p.Mag2()+pow(getattr(row, self.mye1+'Mass'),2))) + e2FourVector= ROOT.TLorentzVector(e2p, sqrt(e2p.Mag2()+pow(getattr(row, self.mye2+'Mass'),2))) + zFourVector = e1FourVector+e2FourVector + return zFourVector + + + ##add the trigger correction @@ -145,20 +150,23 @@ def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): weight = self.event_weight(row) histos = self.histograms - histos[folder+'/e1Pt'].Fill(row.e1Pt, weight) - histos[folder+'/e1Eta'].Fill(row.e1Eta, weight) - histos[folder+'/e1Phi'].Fill(row.e1Phi, weight) - histos[folder+'/e2Pt'].Fill(row.e2Pt, weight) - histos[folder+'/e2Eta'].Fill(row.e2Eta, weight) - histos[folder+'/e2Phi'].Fill(row.e2Phi, weight) + + + histos[folder+'/e1Pt'].Fill( getattr(row, self.mye1+'Pt'), weight) + histos[folder+'/e1Eta'].Fill(getattr(row, self.mye1+'Eta'), weight) + histos[folder+'/e1Phi'].Fill(getattr(row, self.mye1+'Phi'), weight) - histos[folder+'/e3Pt'].Fill(row.e3Pt, weight) - histos[folder+'/e3Eta'].Fill(row.e3Eta, weight) - histos[folder+'/e3AbsEta'].Fill(abs(row.e3Eta), weight) - histos[folder+'/e3Phi'].Fill(row.e3Phi, weight) + histos[folder+'/e2Pt'].Fill( getattr(row, self.mye2+'Pt' ), weight) + histos[folder+'/e2Eta'].Fill(getattr(row, self.mye2+'Eta'), weight) + histos[folder+'/e2Phi'].Fill(getattr(row, self.mye2+'Phi'), weight) - histos[folder+'/e1e2Mass'].Fill(row.e1_e2_Mass, weight) + histos[folder+'/e3Pt'].Fill( getattr(row, self.mye3+'Pt' ), weight) + histos[folder+'/e3Eta'].Fill(getattr(row, self.mye3+'Eta'), weight) + histos[folder+'/e3Phi'].Fill(getattr(row, self.mye3+'Phi'), weight) + histos[folder+'/e3AbsEta'].Fill(abs(getattr(row, self.mye3+'Eta')), weight) + + histos[folder+'/e1e2Mass'].Fill(getattr(row, self.mye1+'_'+self.mye2+'_Mass'), weight) #histos[folder+'/tMtToPFMET'].Fill(row.tMtToPFMET,weight) @@ -168,8 +176,8 @@ def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight) histos[folder+'/bjetCSVVeto30'].Fill(row.bjetCSVVeto30, weight) - histos[folder+'/ze3DR'].Fill(deltaR(Z(row).Phi(), row.e3Phi, Z(row).Eta(), row.e3Eta)) - histos[folder+'/ze3DPhi'].Fill(deltaPhi(Z(row).Phi(), row.e3Phi)) + histos[folder+'/ze3DR'].Fill(deltaR(Z(row).Phi(), getattr(row, self.mye3+'Phi'), Z(row).Eta(), getattr(row, self.mye3+'Eta'))) + histos[folder+'/ze3DPhi'].Fill(deltaPhi(Z(row).Phi(), getattr(row, self.mye3+'Phi'))) histos[folder+'/Zpt'].Fill(Z(row).Pt()) @@ -216,11 +224,21 @@ def process(self): if not selections.lepton_id_iso(row, 'e2', 'eid13Loose_idiso02'): continue if abs(row.e2Eta) > 1.4442 and abs(row.e2Eta) < 1.566 : continue - cut_flow_trk.Fill('e2IDiso') - if not abs(row.e1_e2_Mass-91.2) < 20: continue - cut_flow_trk.Fill('ZMass') +## cut_flow_trk.Fill('e2IDiso') +## if not abs(row.e1_e2_Mass-91.2) < 20: continue +## cut_flow_trk.Fill('ZMass') if not selections.eSelection(row, 'e3'): continue if not selections.lepton_id_iso(row, 'e3', 'eid13Loose_idiso02'): continue #very loose loose eid13Tight_mvaLoose + if abs(row.e3Eta) > 1.4442 and abs(row.e3Eta) < 1.566 : continue + + Zs= [(abs(row.e1_e2_Mass-91.2), ['e1', 'e2', 'e3']) , (abs(row.e2_e3_Mass-91.2), ['e2', 'e3', 'e1']), (abs(row.e1_e3_Mass-91.2), ['e1', 'e3', 'e2'])] + + for ele in range(0, 2) : + + if Zs[ele][0] == min(Zs[z][0] for z in range (0,2)) : + self.mye1 = Zs[ele][1][0] + self.mye2 = Zs[ele][1][1] + self.mye3 = Zs[ele][1][2] cut_flow_trk.Fill('tsel') diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 1388ee71..90aec14b 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -423,7 +423,7 @@ def process(self): logging.debug('Passed preselection') isETight = False if selections.lepton_id_iso(row, 'e', 'eid13Tight_etauiso01'): isETight = True - logging.debug('tigh electron: %s' %isETight) + logging.debug('tight electron: %s' %isETight) # # Compute event weight diff --git a/lfvetau/TauFakeRateAnalyzerMVA.py b/lfvetau/TauFakeRateAnalyzerMVA.py index 38f4cdfc..5ed0cac1 100644 --- a/lfvetau/TauFakeRateAnalyzerMVA.py +++ b/lfvetau/TauFakeRateAnalyzerMVA.py @@ -242,6 +242,7 @@ def process(self): #if row.tauHpsVetoPt20 : continue if row.muVetoPt5IsoIdVtx : continue if row.eVetoCicLooseIso : continue # change it with Loose + # if not row.tMtToMET < 50: continue cut_flow_trk.Fill('MtToMet') diff --git a/lfvetau/baseSelections.py b/lfvetau/baseSelections.py index 4740caea..f4ba726c 100755 --- a/lfvetau/baseSelections.py +++ b/lfvetau/baseSelections.py @@ -32,12 +32,16 @@ def eSelection(row, name): if getattr( row, getVar(name,'JetCSVBtag')) > 0.8: return False ###if getattr( row, getVar(name,'JetBtag')) > 3.3: return False if abs(getattr( row, getVar(name,'DZ'))) > 0.2: return False + #if getattr(row, getVar(name, 'MuonIdIsoVtxOverlap')): return False return True def tauSelection(row, name): if getattr( row, getVar(name,'Pt')) < 30: return False if getattr( row, getVar(name,'AbsEta')) > 2.3: return False if abs(getattr( row, getVar(name,'DZ'))) > 0.2: return False + if getattr( row, getVar(name, 'MuonIdIsoVtxOverlap')): return False + if getattr( row, getVar(name, 'ElectronPt10IdIsoVtxOverlap')): return False # change to tCiCLooseElecOverlap + return True From ea34373c374ce226a7a983fccfed8ce71b1fa07d Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Wed, 19 Nov 2014 05:38:44 -0600 Subject: [PATCH 151/192] electron fake, first attempt --- lfvetau/BasePlotter.py | 112 ++++++++++++++++++++++++++++++++++------- 1 file changed, 95 insertions(+), 17 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index 07b82b2d..7878fd88 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -124,7 +124,9 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): if use_embedded: self.mc_samples.pop() self.views['ZetauEmbedded'] = {'view' : self.make_embedded('os/gg/ept30/h_collmass_pfmet')} - self.views['fakes'] = {'view' : self.make_fakes()} + self.views['fakes'] = {'view' : self.make_fakes('t')} + #self.views['efakes'] = {'view' : self.make_fakes('e')} + #self.views['etfakes'] = {'view' : self.make_fakes('et')} #names must match with what defined in self.mc_samples self.datacard_names = { @@ -141,6 +143,8 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): 'ggHiggsToETau' : 'LFVGG', 'vbfHiggsToETau' : 'LFVVBF', 'fakes' : 'fakes', + ##'efakes' : 'efakes', + ##'etfakes' : 'etfakes' } self.sample_groups = {#parse_cgs_groups('card_config/cgs.0.conf') @@ -191,13 +195,13 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): 'type' : 'shape', '+' : dir_systematic('Up'), '-' : dir_systematic('Down'), - 'apply_to' : ['fakes'], + 'apply_to' : ['fakes']#,'efakes','etfakes'], }, 'stat' : { 'type' : 'stat', '+' : lambda x: x, '-' : lambda x: x, - 'apply_to' : ['fakes','simbkg'], + 'apply_to' : ['fakes']#,'simbkg','efakes','etfakes'], }, 'TES' : { 'type' : 'shape', @@ -208,17 +212,25 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): } - def make_fakes(self): + def make_fakes(self, obj='t'): '''Sets up the fakes view''' + print 'making fakes for %s' %obj data_view = self.get_view('data') - central_fakes = views.SubdirectoryView(data_view, 'tLoose') + tfakes = views.SubdirectoryView(data_view, 'tLoose') + efakes = views.SubdirectoryView(data_view, 'eLoose') + etfakes= views.SubdirectoryView(data_view, 'etLoose') + central_fakes=SubtractionView(views.SumView(tfakes,efakes),etfakes, restrict_positive=True) mc_views = self.mc_views() if self.use_embedded: mc_views.append(self.get_view('ZetauEmbedded')) mc_sum = views.SumView(*mc_views) - mc_sum = views.SubdirectoryView(mc_sum, 'tLoose') + mc_sum_t = views.SubdirectoryView(mc_sum, 'tLoose') + mc_sum_e = views.SubdirectoryView(mc_sum, 'eLoose') + mc_sum_et = views.SubdirectoryView(mc_sum, 'etLoose') + allmc=SubtractionView(views.SumView(mc_sum_t,mc_sum_e),mc_sum_et, restrict_positive=True) - fakes_view = SubtractionView(central_fakes, mc_sum, restrict_positive=True) + fakes_view = SubtractionView(central_fakes, allmc, restrict_positive=True) + #fakes_view =central_fakes style = data_styles['Fakes*'] return views.TitleView( views.StyleView( @@ -684,10 +696,48 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', fakes = SystematicsView.add_error(fakes, 0.30) #add them to backgrounds mc_stack.Add(fakes) - + mc_err.Sumw2() mc_err.Add(fakes) #set_trace() + + #####get efakes + ##efakes_view = self.get_view('efakes') + ##if preprocess: + ## efakes_view = preprocess(efakes_view) + ##efakes_view = RebinView(efakes_view, rebin) + ##efakes = efakes_view.Get(path) + ## + ##efakes = self.add_shape_systematics( + ## efakes, + ## path, + ## efakes_view, + ## [('Up','Down')] + ##) + #####add them to backgrounds + ##mc_stack.Add(efakes) + ## + ##mc_err.Sumw2() + ##mc_err.Add(efakes) + ###set_trace() + ##etfakes_view = self.get_view('etfakes') + ##if preprocess: + ## etfakes_view = preprocess(etfakes_view) + ##etfakes_view = RebinView(etfakes_view, rebin) + ##etfakes = etfakes_view.Get(path) + ## + ##etfakes = self.add_shape_systematics( + ## etfakes, + ## path, + ## etfakes_view, + ## [('Up','Down')] + ##) + #####add them to backgrounds + ##mc_stack.Add(etfakes) + ## + ##mc_err.Sumw2() + ##mc_err.Add(etfakes) + ###set_trace() #draw stack mc_stack.Draw() @@ -695,10 +745,10 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', #set cosmetics self.canvas.SetLogy(True) - #self.canvas.SetGridx(True) - #self.canvas.SetGridy(True) - #self.pad.SetGridx(True) - #self.pad.SetGridy(True) + ##self.canvas.SetGridx(True) + ##self.canvas.SetGridy(True) + ##self.pad.SetGridx(True) + ##self.pad.SetGridy(True) mc_stack.GetHistogram().GetXaxis().SetTitle(xaxis) if xrange: @@ -783,20 +833,36 @@ def plot_without_uncert (self, folder, variable, rebin=1, xaxis='', fake_p1s_histo=None - if not folder.startswith('tLoose'): + if not folder.startswith('tLoose') and not folder.startswith('eLoose') and not folder.startswith('etLoose') : isFakesIn= False + ##isEFakesIn=False + isETFakesIn=False if 'Fakes' in self.mc_samples: self.mc_samples.remove('Fakes') - self.mc_samples.remove('finalDYLL') + if 'finalDYLL' in self.mc_samples: self.mc_samples.remove('finalDYLL') isFakesIn=True - - + ##if 'eFakes' in self.mc_samples: + ## self.mc_samples.remove('eFakes') + ## if 'finalDYLL' in self.mc_samples: self.mc_samples.remove('finalDYLL') + ## isEFakesIn=True + ##if 'etFakes' in self.mc_samples: + ## self.mc_samples.remove('etFakes') + ## if 'finalDYLL' in self.mc_samples: self.mc_samples.remove('finalDYLL') + ## isETFakesIn=True + + ibin =1 if isFakesIn: self.mc_samples.append('Fakes') + # self.mc_samples.append('etFakes') self.mc_samples.append('finalDYLL') - + ## if isEFakesIn: + ## self.mc_samples.append('eFakes') + ## if not 'finalDYLL' in self.mc_samples: self.mc_samples.append('finalDYLL') + ## if isETFakesIn: + ## self.mc_samples.append('etFakes') + ## if not 'finalDYLL' in self.mc_samples: self.mc_samples.append('finalDYLL') finalhisto.Draw('samee2') @@ -862,6 +928,18 @@ def write_shapes(self, folder, variable, output_dir, bkg_histos['fakes'] = fake_shape.Clone() fake_shape.SetName('fakes') fake_shape.Write() + + ##bkg_views['efakes'] = self.get_view('efakes') + ##efake_shape = bkg_views['efakes'].Get(path) + ##bkg_histos['efakes'] = fake_shape.Clone() + ##efake_shape.SetName('efakes') + ##efake_shape.Write() + + #bkg_views['etfakes'] = self.get_view('etfakes') + #etfake_shape = bkg_views['etfakes'].Get(path) + #bkg_histos['etfakes'] = fake_shape.Clone() + #etfake_shape.SetName('etfakes') + #etfake_shape.Write() unc_conf_lines = [] unc_vals_lines = [] From c14f3ae03e46deac922382d708fd3544ff6be4ba Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Fri, 21 Nov 2014 03:11:00 -0600 Subject: [PATCH 152/192] ees in the analyzer --- lfvetau/EleFakeRateAnalyzerMVA.py | 17 ++-- lfvetau/LFVHETauAnalyzerMVA.py | 150 ++++++++++++++++++++++-------- lfvetau/TauFakeRateAnalyzerMVA.py | 1 + lfvetau/baseSelections.py | 11 ++- 4 files changed, 131 insertions(+), 48 deletions(-) diff --git a/lfvetau/EleFakeRateAnalyzerMVA.py b/lfvetau/EleFakeRateAnalyzerMVA.py index 3004ecd8..bb538039 100644 --- a/lfvetau/EleFakeRateAnalyzerMVA.py +++ b/lfvetau/EleFakeRateAnalyzerMVA.py @@ -69,15 +69,15 @@ def event_weight(self, row): mcCorrections.eiso_correction(row, self.mye1, self.mye2, self.mye3) * \ mcCorrections.trig_correction(row, self.mye3 ) - def ee3DR(row): + def ee3DR(self, row): return getattr(row, self.mye1+'_'+self.mye3+'_DR') if getattr(row, self.mye1+'_'+self.mye3+'_DR') < getattr(row, self.mye2+'_'+self.mye3+'_DR') else getattr(row, self.mye2+'_'+self.mye3+'_DR') - def ee3DPhi(row): + def ee3DPhi(self, row): e1e3DPhi=deltaPhi(getattr(row, self.mye1+'Phi'), getattr(row, self.mye3+'Phi')) e2e3DPhi=deltaPhi(getattr(row, self.mye2+'Phi'), getattr(row, self.mye3+'Phi')) return e1e3DPhi if e1e3DPhi < e2e3DPhi else e2e3DPhi - def Z(row): + def Z(self, row): e1p=ROOT.TVector3(getattr(row, self.mye1+'Pt')*cos(getattr(row, self.mye1+'Phi')),getattr(row, self.mye1+'Pt')*sin(getattr(row, self.mye1+'Phi')),getattr(row, self.mye1+'Pt')*sin(getattr(row, self.mye1+'Eta'))) e2p=ROOT.TVector3(getattr(row, self.mye2+'Pt')*cos(getattr(row, self.mye2+'Phi')),getattr(row, self.mye2+'Pt')*sin(getattr(row, self.mye2+'Phi')),getattr(row, self.mye2+'Pt')*sin(getattr(row, self.mye2+'Eta'))) e1FourVector= ROOT.TLorentzVector(e1p, sqrt(e1p.Mag2()+pow(getattr(row, self.mye1+'Mass'),2))) @@ -171,14 +171,14 @@ def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): histos[folder+'/type1_pfMetEt'].Fill(row.type1_pfMet_Et) - histos[folder+'/ee3DR'].Fill(ee3DR(row)) - histos[folder+'/ee3DPhi'].Fill(ee3DPhi(row)) + histos[folder+'/ee3DR'].Fill(self.ee3DR(row)) + histos[folder+'/ee3DPhi'].Fill(self.ee3DPhi(row)) histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight) histos[folder+'/bjetCSVVeto30'].Fill(row.bjetCSVVeto30, weight) - histos[folder+'/ze3DR'].Fill(deltaR(Z(row).Phi(), getattr(row, self.mye3+'Phi'), Z(row).Eta(), getattr(row, self.mye3+'Eta'))) - histos[folder+'/ze3DPhi'].Fill(deltaPhi(Z(row).Phi(), getattr(row, self.mye3+'Phi'))) - histos[folder+'/Zpt'].Fill(Z(row).Pt()) + histos[folder+'/ze3DR'].Fill(deltaR(self.Z(row).Phi(), getattr(row, self.mye3+'Phi'), self.Z(row).Eta(), getattr(row, self.mye3+'Eta'))) + histos[folder+'/ze3DPhi'].Fill(deltaPhi(self.Z(row).Phi(), getattr(row, self.mye3+'Phi'))) + histos[folder+'/Zpt'].Fill(self.Z(row).Pt()) def process(self): @@ -204,6 +204,7 @@ def process(self): if row.bjetCSVVeto30!=0 : continue if row.e1Pt < 30 : continue if row.e2Pt < 30 : continue + if row.e3Pt < 30 : continue # for i, row in enumerate(self.tree): # if i >= 100: diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 90aec14b..933e8e12 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -44,6 +44,14 @@ def tpt(shift=''): def vismass(shift=''): return etMass % shift +def create_mapper(mapping): + def _f(path): + for key, out in mapping.iteritems(): + if key == path: + path = path.replace(key,out) + print 'path', path + return path + return _f def attr_getter(attribute): '''return a function that gets an attribute''' @@ -204,6 +212,7 @@ def begin(self): self.systematics['evetos'] + \ ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + \ ['tesUp', 'tesDown'] +\ + ['eesUp', 'eesDown'] +\ ['eLoose', 'eLoose/Up', 'eLoose/Down'] +\ ['etLoose', 'etLoose/Up', 'etLoose/Down'] sys_shifts = list( set( sys_shifts ) ) #remove double dirs @@ -240,56 +249,56 @@ def book_with_sys(location, name, *args, **kwargs): type=pytree.PyTree ) - self.book(f,"tPt", "tau p_{T}", 200, 0, 200) - self.book(f,"tPt_tes_plus", "tau p_{T} (tes+)", 200, 0, 200) - self.book(f,"tPt_tes_minus", "tau p_{T} (tes-)", 200, 0, 200) + self.book(f,"tPt", "tau p_{T}", 40, 0, 200) + self.book(f,"tPt_tes_plus", "tau p_{T} (tes+)", 40, 0, 200) + self.book(f,"tPt_tes_minus", "tau p_{T} (tes-)",40, 0, 200) - self.book(f,"tPhi", "tau phi", 100, -3.2, 3.2) - self.book(f,"tEta", "tau eta", 50, -2.5, 2.5) + self.book(f,"tPhi", "tau phi", 26, -3.25, 3.25) + self.book(f,"tEta", "tau eta", 10, -2.5, 2.5) - self.book(f,"ePt", "e p_{T}", 200, 0, 200) - self.book(f,"ePt_ees_plus", "e p_{T} (ees+)", 200, 0, 200) - self.book(f,"ePt_ees_minus", "e p_{T} (ees-)", 200, 0, 200) + self.book(f,"ePt", "e p_{T}", 40, 0, 200) + self.book(f,"ePt_ees_plus", "e p_{T} (ees+)", 40, 0, 200) + self.book(f,"ePt_ees_minus", "e p_{T} (ees-)",40, 0, 200) - self.book(f,"ePhi", "e phi", 100, -3.2, 3.2) - self.book(f,"eEta", "e eta", 50, -2.5, 2.5) + self.book(f,"ePhi", "e phi", 26, -3.2, 3.2) + self.book(f,"eEta", "e eta", 10, -2.5, 2.5) - self.book(f, "e_t_DPhi", "e-tau DeltaPhi" , 50, 0, 3.2) - self.book(f, "e_t_DR", "e-tau DeltaR" , 50, 0, 3.2) + self.book(f, "e_t_DPhi", "e-tau DeltaPhi" , 20, 0, 3.2) + self.book(f, "e_t_DR", "e-tau DeltaR" , 20, 0, 3.2) #self.book(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320) - book_with_sys(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320, + book_with_sys(f, "h_collmass_pfmet", "h_collmass_pfmet", 40, 0, 400, postfixes=self.systematics['met']) - self.book(f, "h_collmass_vs_dPhi_pfmet", "h_collmass_vs_dPhi_pfmet", 50, 0, 3.2, 32, 0, 320, type=ROOT.TH2F) + self.book(f, "h_collmass_vs_dPhi_pfmet", "h_collmass_vs_dPhi_pfmet", 20, 0, 3.2, 40, 0, 400, type=ROOT.TH2F) - self.book(f, "e_t_Mass", "h_vismass", 32, 0, 320) - self.book(f, "e_t_Mass_tes_plus" , "h_vismass_tes_plus", 32, 0, 320) - self.book(f, "e_t_Mass_tes_minus", "h_vismass_tes_minus", 32, 0, 320) - self.book(f, "e_t_Mass_ees_plus" , "h_vismass_ees_plus", 32, 0, 320) - self.book(f, "e_t_Mass_ees_minus", "h_vismass_ees_minus", 32, 0, 320) + self.book(f, "e_t_Mass", "h_vismass", 40, 0, 400) + self.book(f, "e_t_Mass_tes_plus" , "h_vismass_tes_plus", 40 , 0, 400) + self.book(f, "e_t_Mass_tes_minus", "h_vismass_tes_minus",40 , 0, 400) + self.book(f, "e_t_Mass_ees_plus" , "h_vismass_ees_plus", 40 , 0, 400) + self.book(f, "e_t_Mass_ees_minus", "h_vismass_ees_minus",40 , 0, 400) - self.book(f, "MetEt_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 50, 0, 3.2, 64, 0, 320, type=ROOT.TH2F) + self.book(f, "MetEt_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 20, 0, 3.2, 40, 0, 400, type=ROOT.TH2F) - self.book(f, "tPFMET_DeltaPhi", "tau-type1PFMET DeltaPhi" , 50, 0, 3.2) + self.book(f, "tPFMET_DeltaPhi", "tau-type1PFMET DeltaPhi" , 20, 0, 3.2) - self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 50, 0, 3.2) + self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 20, 0, 3.2) #self.book(f,"tMtToPFMET", "tau-PFMET M_{T}" , 200, 0, 200) - book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 200, 0, 200, + book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 40, 0, 200, postfixes=self.systematics['met']) #self.book(f,"eMtToPFMET", "e-PFMET M_{T}" , 200, 0, 200) - book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 200, 0, 200, + book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 40, 0, 200, postfixes=self.systematics['met']) #self.book(f, "pfMetEt", "pfMetEt", 200, 0, 200) - book_with_sys(f, "pfMet_Et", "pfMet_Et", 200, 0, 200, postfixes=self.systematics['met']) + book_with_sys(f, "pfMet_Et", "pfMet_Et", 40, 0, 200, postfixes=self.systematics['met']) #self.book(f, "pfMetPhi", "pfMetPhi", 100, -3.2, 3.2) - book_with_sys(f, "pfMet_Phi", "pfMet_Phi", 100, -3.2, 3.2, postfixes=self.systematics['met']) + book_with_sys(f, "pfMet_Phi", "pfMet_Phi", 26, -3.2, 3.2, postfixes=self.systematics['met']) - self.book(f, "jetVeto20", "Number of jets, p_{T}>20", 10, -0.5, 9.5) - self.book(f, "jetVeto30", "Number of jets, p_{T}>30", 10, -0.5, 9.5) + self.book(f, "jetVeto20", "Number of jets, p_{T}>20", 5, -0.5, 4.5) + self.book(f, "jetVeto30", "Number of jets, p_{T}>30", 5, -0.5, 4.5) #index dirs and histograms for key in self.histograms: @@ -412,7 +421,7 @@ def process(self): #objects if not selections.eSelection(row, 'e'): continue - if row.ePt < 30 : continue + #if row.ePt < 30 : continue if not selections.tauSelection(row, 't'): continue if not row.tAntiElectronMVA5Tight : continue if not row.tAntiMuon2Loose : continue @@ -461,29 +470,60 @@ def process(self): jet_category_names = ['%i%s' % i for i in zip(jet_categories, systematics['jes'])] passes_full_selection = False + tThr = 30 + eThr = 30 + tes_categories_presel=[ ('', bool(row.tPt > tThr)),( 'tesUp', bool(row.tPt_tes_plus > tThr)), ('tesDown', bool(row.tPt_tes_minus > tThr))] + ees_categories_presel=[ ('', bool(row.ePt > eThr)),( 'eesUp', bool(row.ePt_ees_plus > eThr)), ('eesDown', bool(row.ePt_ees_minus > eThr))] # # Full tight selection # full_selection = [[''] for _ in jet_categories] - tes_categories = [ ('', False),( 'tesUp', False), ('tesDown', False)] +# tes_categories = [ ('', False),( 'tesUp', False), ('tesDown', False)] +# ees_categories = [ ('', False),( 'eesUp', False), ('eesDown', False)] for idx, njet in enumerate(jet_categories): if njet == 0 : tThr = 35 + eThr = 30 if min(row.tPt, row.tPt_tes_plus, row.tPt_tes_minus) < tThr: continue - tes_categories=[ ('', bool(row.tPt > tThr)),( 'tesUp', bool(row.tPt_tes_plus > tThr)), ('tesDown', bool(row.tPt_tes_minus > tThr))] + if min(row.ePt, row.ePt_ees_plus, row.ePt_ees_minus) < eThr: continue + tes_categories_mapper={ + '' : bool(row.tPt > tThr), + 'tesUp' : bool(row.tPt_tes_plus > tThr), + 'tesDown': bool(row.tPt_tes_minus > tThr)} + + ees_categories_mapper={ + '' : bool(row.ePt > eThr), + 'eesUp' : bool(row.ePt_ees_plus > eThr), + 'eesDown': bool(row.ePt_ees_minus > eThr)} + + + #if row.tPt > 35: tes_categories.append('') #if row.tPt_tes_plus > 35: tes_categories.append('tesPlus/') #if row.tPt_tes_minus > 35: tes_categories.append('tesDown/') - if row.ePt < 40 : continue + #if row.ePt < 40 : continue if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue if row.tMtToPfMet > 50 : continue full_selection[idx].append('selected') passes_full_selection = True elif njet == 1 : tThr = 40 + eThr = 35 + if min(row.tPt, row.tPt_tes_plus, row.tPt_tes_minus) < tThr: continue - tes_categories=[ ('', bool(row.tPt > tThr)),( 'tesUp', bool(row.tPt_tes_plus > tThr)), ('tesDown', bool(row.tPt_tes_minus > tThr))] + if min(row.ePt, row.ePt_ees_plus, row.ePt_ees_minus) < eThr: continue + + tes_categories_mapper={ + '' : bool(row.tPt > tThr), + 'tesUp' : bool(row.tPt_tes_plus > tThr), + 'tesDown': bool(row.tPt_tes_minus > tThr)} + + ees_categories_mapper={ + '' : bool(row.ePt > eThr), + 'eesUp' : bool(row.ePt_ees_plus > eThr), + 'eesDown': bool(row.ePt_ees_minus > eThr)} + #if row.tPt > 40: tes_category.append('') #if row.tPt_tes_plus > 40: tes_categories.append('tesPlus/') #if row.tPt_tes_minus > 40: tes_categories.append('tesDown/') @@ -493,8 +533,20 @@ def process(self): passes_full_selection = True elif njet == 2 : tThr = 40 + eThr = 30 + if min(row.tPt, row.tPt_tes_plus, row.tPt_tes_minus) < tThr: continue - tes_categories=[ ('', bool(row.tPt > tThr)),( 'tesUp', bool(row.tPt_tes_plus > tThr)), ('tesDown', bool(row.tPt_tes_minus > tThr))] + if min(row.ePt, row.ePt_ees_plus, row.ePt_ees_minus) < eThr: continue + tes_categories_mapper={ + '' : bool(row.tPt > tThr), + 'tesUp' : bool(row.tPt_tes_plus > tThr), + 'tesDown': bool(row.tPt_tes_minus > tThr)} + + ees_categories_mapper={ + '' : bool(row.ePt > eThr), + 'eesUp' : bool(row.ePt_ees_plus > eThr), + 'eesDown': bool(row.ePt_ees_minus > eThr)} + #if row.tPt > 40: tes_category.append('') #if row.tPt_tes_plus > 40: tes_categories.append('tesPlus/') #if row.tPt_tes_Minus > 40: tes_categories.append('tesDown/') @@ -548,16 +600,20 @@ def process(self): all_dirs = [i for i in all_dirs if i in veto_sys] tes_directories =[] - for tdir,tbool in tes_categories: + for tdir,tbool in tes_categories_presel: if tbool==True: tes_directories.append(tdir) + ees_directories =[] + for edir,ebool in ees_categories_presel: + if ebool==True: ees_directories.append(edir) #if tdir == '' and tbool==False : # all_dirs=[] # syst_shifts=[] - sys_directories = all_dirs + sys_shifts +tes_directories + sys_directories = all_dirs + sys_shifts +tes_directories+ees_directories #remove duplicates sys_directories = list(set(sys_directories)) + if not isTauTight and isETight: #if is a loose tau just compute the fakes! sys_directories = tau_id_category @@ -597,7 +653,16 @@ def process(self): #...times the mc weight (if any) weight_map[i] *= mc_weight - + + if tes_categories_presel[0]==False or ees_categories_presel[0]==False : + sys_directories = [] + if ees_categories_presel[0]==True : + sys_directories.extend([i for i,j in tes_categories_presel if j==True ]) + elif tes_categories_presel[0]==True : + sys_directories.extend([i for i,j in ees_categories_presel if j==True ]) + else: + continue + #Fill histograms in appropriate direcotries @@ -616,7 +681,16 @@ def process(self): logging.debug('Filling %s' % dir_name) #fill them! weight_to_use = weight_map[sys] if sys in weight_map else weight_map[''] - + if dir_name.endswith('selected'): + if not dir_name.startswith('tes') and not dir_name.startswith('ees') : + if tes_categories_mapper.get('', False) == False or ees_categories_mapper.get('', False) == False : continue + else : + #print dir_name[:dir_name.index('/')] + name = dir_name[:dir_name.index('/')] + if tes_categories_mapper.get(name, False) == False or ees_categories_mapper.get(name, False) == False : continue + + + self.fill_histos(dir_name, row, weight_to_use) diff --git a/lfvetau/TauFakeRateAnalyzerMVA.py b/lfvetau/TauFakeRateAnalyzerMVA.py index 5ed0cac1..ac7cc75b 100644 --- a/lfvetau/TauFakeRateAnalyzerMVA.py +++ b/lfvetau/TauFakeRateAnalyzerMVA.py @@ -231,6 +231,7 @@ def process(self): if not abs(row.e1_e2_Mass-91.2) < 20: continue cut_flow_trk.Fill('ZMass') if not selections.tauSelection(row, 't'): continue + if row.tPt < 30 : continue cut_flow_trk.Fill('tsel') if not row.tAntiMuon2Loose: continue diff --git a/lfvetau/baseSelections.py b/lfvetau/baseSelections.py index f4ba726c..abb3f6d2 100755 --- a/lfvetau/baseSelections.py +++ b/lfvetau/baseSelections.py @@ -22,7 +22,11 @@ def muSelection(row, name): def eSelection(row, name): eAbsEta = getattr( row, getVar(name,'AbsEta')) - if getattr( row, getVar(name,'Pt')) < 30: return False #was 20 + if getattr( row, getVar(name,'Pt_ees_minus')) !=0 and getattr( row, getVar(name,'Pt_ees_plus')) !=0: + if min(getattr( row, getVar(name,'Pt')),getattr( row, getVar(name,'Pt_ees_minus')), getattr( row, getVar(name,'Pt_ees_plus'))) < 30: return False + else: + if getattr( row, getVar(name,'Pt')) < 30: return False #was 20 + if eAbsEta > 2.3: return False if getattr( row, getVar(name,'MissingHits')): return False if getattr( row, getVar(name,'HasConversion')): return False @@ -36,7 +40,10 @@ def eSelection(row, name): return True def tauSelection(row, name): - if getattr( row, getVar(name,'Pt')) < 30: return False + if getattr( row, getVar(name,'Pt_tes_minus')) !=0 and getattr( row, getVar(name,'Pt_tes_plus')) !=0: + if min(getattr( row, getVar(name,'Pt')),getattr( row, getVar(name,'Pt_tes_minus')), getattr( row, getVar(name,'Pt_tes_plus'))) < 30: return False + else: + if getattr( row, getVar(name,'Pt')) < 30: return False if getattr( row, getVar(name,'AbsEta')) > 2.3: return False if abs(getattr( row, getVar(name,'DZ'))) > 0.2: return False if getattr( row, getVar(name, 'MuonIdIsoVtxOverlap')): return False From 09fe2eef083e82929dd2a47166320607f127d5d6 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 21 Nov 2014 03:19:32 -0600 Subject: [PATCH 153/192] add TES uncertainty and 1% BR --- lfvetau/BasePlotter.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index cf826a09..91643ea9 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -199,11 +199,11 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): '-' : lambda x: x, 'apply_to' : ['fakes','simbkg'], } - ## 'TES' : { TODO! MISSING - ## 'type' : 'shape', - ## '+' : , - ## '-' : , - ## }, + 'TES' : { + 'type' : 'shape', + '+' : dir_systematic('tesUp'), + '-' : dir_systematic('tesDown'), + }, } @@ -827,7 +827,7 @@ def plot_without_uncert (self, folder, variable, rebin=1, xaxis='', if show_ratio: self.add_ratio_diff(data, mc_stack, finalhisto, xrange, ratio_range) - def write_shapes(self, folder, variable, output_dir, + def write_shapes(self, folder, variable, output_dir, br_strenght=0.01, rebin=1, preprocess=None): #, systematics): '''Makes shapes for computing the limit and returns a list of systematic effects to be added to unc.vals/conf make_shapes(folder, variable, output_dir, [rebin=1, preprocess=None) --> unc_conf_lines (list), unc_vals_lines (list) @@ -931,7 +931,10 @@ def write_shapes(self, folder, variable, output_dir, sig_view = self.get_view(name) if preprocess: sig_view = preprocess(sig_view) - sig_view = RebinView(sig_view, rebin) + sig_view = views.ScaleView( + RebinView(sig_view, rebin), + br_strenght + ) histogram = sig_view.Get(path) histogram.SetName(self.datacard_names[name]) From 709edb84b1326bf494bf1c1a5e5c9084fadb49fa Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 21 Nov 2014 03:20:31 -0600 Subject: [PATCH 154/192] fix limit setting --- lfvetau/Rakefile | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index bbfed274..3420263e 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -371,7 +371,7 @@ $shapedir = "plots/#{$jobid}/lfvet/" ## sh "touch #{t.name}" ## end file "#{$shapedir}/.shapes_timestamp" => [] do |t| - sh "touch #{t.name}" + sh "python plotRecoQuantitiesMVA.py" end @@ -381,7 +381,7 @@ end $limitdir = "limits/#{$jobid}/" def prepare_limit(category) #input file does not matter since shape files are made all at once - datacard = "#{$limitdir}/#{category}/126/datacard.txt" + datacard = "#{$limitdir}/#{category}/126/datacard_et_#{category}.txt" file datacard => "#{$shapedir}/.shapes_timestamp" do |t| sh "./prepare_limit.sh #{category}" end @@ -393,17 +393,18 @@ card_1_jet = prepare_limit('1') card_2_jet = prepare_limit('2') #combine cards -cmb_card = "#{$limitdir}/et_cmb/126/datacard.txt" +cmb_card = "#{$limitdir}/et_cmb/126/datacard_et_cmb.txt" file cmb_card => [card_0_jet, card_1_jet, card_2_jet] do |t| - sh "mkdir -p #{$limitdir}/et_cmb/126" - sh "hadd -f #{$limitdir}/et_cmb/shapes.root #{$limitdir}/[0-9]/shapes.root" - chdir("#{$limitdir}/et_cmb/126") do + sh "mkdir -p #{$limitdir}/cmb/126" + sh "hadd -f #{$limitdir}/cmb/shapes.root #{$limitdir}/[0-9]/shapes.root" + chdir("#{$limitdir}/cmb/126") do sh "rm -f shapes.root" sh "ln -s ../shapes.root" local_paths = t.prerequisites.map{|x| x.sub($limitdir,'../../')} - sh "combine_cards_with_names.sh #{ local_paths.join(' ')} > datacard.txt" + local_name = File.basename(t.name) + sh "combine_cards_with_names.sh #{ local_paths.join(' ')} > #{local_name}" end end @@ -420,7 +421,7 @@ task :shapes => [ ## def compute_limit(category) #input file does not matter since shape files are made all at once - datacard = "#{$limitdir}/#{category}/126/datacard.txt" + datacard = "#{$limitdir}/#{category}/126/datacard_et_#{category}.txt" timestamp = "#{$limitdir}/#{category}/.limit_timestamp" file timestamp => datacard do |t| sh "compute_limits.sh #{$limitdir}/#{category} 1 #{$blind}" @@ -432,7 +433,7 @@ end limit_0_jet = compute_limit('0') limit_1_jet = compute_limit('1') limit_2_jet = compute_limit('2') -limit_c_jet = compute_limit('et_cmb') +limit_c_jet = compute_limit('cmb') #TODO combination! task :limits => [ limit_0_jet, @@ -446,11 +447,12 @@ task :limits => [ ## def compute_significance(category) #input file does not matter since shape files are made all at once - datacard = "#{$limitdir}/#{category}/126/datacard.txt" + datacard = "#{$limitdir}/#{category}/126/datacard_et_#{category}.txt" timestamp = "#{$limitdir}/#{category}/.significance_timestamp" file timestamp => datacard do |t| chdir("#{$limitdir}/#{category}") do - sh "compute_significance.sh 126 #{$blind} datacard.txt" + dcard_name = File.basename(datacard) + sh "compute_significance.sh 126 #{$blind} #{dcard_name}" end sh "touch #{t.name}" end @@ -460,7 +462,7 @@ end significance_0_jet = compute_significance('0') significance_1_jet = compute_significance('1') significance_2_jet = compute_significance('2') -significance_c_jet = compute_significance('et_cmb') +significance_c_jet = compute_significance('cmb') #TODO combination! task :significance => [ significance_0_jet, From afcaf0d95cfa16c4f8511ae96344ed9d8ee0ab57 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 21 Nov 2014 03:21:40 -0600 Subject: [PATCH 155/192] fix datacard name --- lfvetau/prepare_limit.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lfvetau/prepare_limit.sh b/lfvetau/prepare_limit.sh index ffff2c4a..9de13573 100755 --- a/lfvetau/prepare_limit.sh +++ b/lfvetau/prepare_limit.sh @@ -69,7 +69,7 @@ pushd 126 rm -rf shapes.root ln -s ../shapes.root popd -create-datacard.py -i shapes.root -o 126/datacard.txt +create-datacard.py -i shapes.root -o 126/datacard_et_$category.txt popd exit 0 From 2beffd7f908afdd4b222b7d93dc9eacbfc230f9a Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 21 Nov 2014 03:24:09 -0600 Subject: [PATCH 156/192] add timestamp --- lfvetau/plotRecoQuantitiesMVA.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lfvetau/plotRecoQuantitiesMVA.py b/lfvetau/plotRecoQuantitiesMVA.py index 49ebf2cd..b7b48cb8 100644 --- a/lfvetau/plotRecoQuantitiesMVA.py +++ b/lfvetau/plotRecoQuantitiesMVA.py @@ -107,7 +107,8 @@ with open(pjoin(output_path, 'unc.%s.vals' % njets), 'w') as vals: vals.write('\n'.join(unc_vals_lines)) - +with open(pjoin(output_path,'.shapes_timestamp'),'w') as stamp: + stamp.write('no use') From aefafcbe35b3a2a572350ba32430c10e6513b23e Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 21 Nov 2014 07:21:50 -0600 Subject: [PATCH 157/192] should be a little faster --- lfvetau/LFVHETauAnalyzerMVA.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 933e8e12..f41ce260 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -44,6 +44,10 @@ def tpt(shift=''): def vismass(shift=''): return etMass % shift +@memo +def split(string, separator='#'): + return tuple(attr.split(separator)) + def create_mapper(mapping): def _f(path): for key, out in mapping.iteritems(): @@ -131,7 +135,7 @@ def __init__(self, tree, outfile, **kwargs): 'mvetos': (['', 'mVetoUp', 'mVetoDown'] if self.is_mc else ['']), 'tvetos': (['', 'tVetoUp', 'tVetoDown'] if self.is_mc else ['']), 'evetos': (['', 'eVetoUp', 'eVetoDown'] if self.is_mc else ['']), - 'met' : ([ "_jes_plus", "_mes_plus", "_tes_plus", "_ees_plus", "_ues_plus", "_jes_minus", "_mes_minus", "_tes_minus", "_ees_minus", "_ues_minus"] if self.is_mc else []), + 'met' : (["_jes_plus", "_mes_plus", "_tes_plus", "_ees_plus", "_ues_plus", "_jes_minus", "_mes_minus", "_tes_minus", "_ees_minus", "_ues_minus"] if self.is_mc else []), 'tes' : (["_tes_plus","_tes_minus"]if self.is_mc else ['']), } @@ -301,13 +305,13 @@ def book_with_sys(location, name, *args, **kwargs): self.book(f, "jetVeto30", "Number of jets, p_{T}>30", 5, -0.5, 4.5) #index dirs and histograms - for key in self.histograms: + for key, value in self.histograms.iteritems(): location = os.path.dirname(key) name = os.path.basename(key) - if location in self.histo_locations: - self.histo_locations[location].append(name) + if location not in self.histo_locations: + self.histo_locations[location] = {name : value} else: - self.histo_locations[location] = [name] + self.histo_locations[location][name] = value def fakerate_weights(self, tEta): tLoose = tau_fake_rate(tEta) @@ -350,7 +354,7 @@ def fakerate_weights(self, tEta): def fill_histos(self, folder_str, row, weight, filter_label = ''): '''fills histograms''' #find all keys matching - for attr in self.histo_locations[folder_str]: + for attr, value in self.histo_locations[folder_str].iteritems(): name = attr #if attr=='DEBUG': # set_trace() @@ -358,8 +362,6 @@ def fill_histos(self, folder_str, row, weight, filter_label = ''): if not attr.startswith(filter_label+'$'): continue attr = attr.replace(filter_label+'$', '') - path = os.path.join(folder_str,name) - value = self.histograms[path] if value.InheritsFrom('TH2'): if attr in self.hfunc: try: @@ -372,7 +374,7 @@ def fill_histos(self, folder_str, row, weight, filter_label = ''): else: value.Fill( r1, r2, out_weight ) else: - attr1, attr2 = tuple(attr.split('#')) + attr1, attr2 = split(attr) v1 = getattr(row,attr1) v2 = getattr(row,attr2) value.Fill( v1, v2, weight ) if weight is not None else value.Fill( v1, v2 ) @@ -390,7 +392,6 @@ def fill_histos(self, folder_str, row, weight, filter_label = ''): value.Fill( getattr(row,attr), weight ) if weight is not None else value.Fill( getattr(row,attr) ) return None - def process(self): logging.debug('Starting processing') systematics = self.systematics @@ -417,7 +418,7 @@ def process(self): if not bool(row.doubleMuPass) : continue else: if not bool(row.singleE27WP80Pass) : continue - if not bool(row.eMatchesSingleE27WP80): continue + if not bool(row.eMatchesSingleE27WP80): continue #objects if not selections.eSelection(row, 'e'): continue From f1286c08d061fcbc79a345b0aaa7625d2a8d8aaf Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Fri, 21 Nov 2014 09:05:06 -0600 Subject: [PATCH 158/192] electron Thr adjustement --- lfvetau/LFVHETauAnalyzerMVA.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 933e8e12..71046096 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -484,7 +484,7 @@ def process(self): for idx, njet in enumerate(jet_categories): if njet == 0 : tThr = 35 - eThr = 30 + eThr = 40 if min(row.tPt, row.tPt_tes_plus, row.tPt_tes_minus) < tThr: continue if min(row.ePt, row.ePt_ees_plus, row.ePt_ees_minus) < eThr: continue tes_categories_mapper={ From 6c6098c44a8ff4b7587f07e5578435a7d8c51900 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 21 Nov 2014 10:52:54 -0600 Subject: [PATCH 159/192] snapshot with tes systematics and faster analysis --- lfvetau/LFVHETauAnalyzerMVA.py | 262 +++++++++++---------------------- lfvetau/baseSelections.py | 12 +- 2 files changed, 93 insertions(+), 181 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index f41ce260..8bf0694b 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -135,8 +135,9 @@ def __init__(self, tree, outfile, **kwargs): 'mvetos': (['', 'mVetoUp', 'mVetoDown'] if self.is_mc else ['']), 'tvetos': (['', 'tVetoUp', 'tVetoDown'] if self.is_mc else ['']), 'evetos': (['', 'eVetoUp', 'eVetoDown'] if self.is_mc else ['']), - 'met' : (["_jes_plus", "_mes_plus", "_tes_plus", "_ees_plus", "_ues_plus", "_jes_minus", "_mes_minus", "_tes_minus", "_ees_minus", "_ues_minus"] if self.is_mc else []), - 'tes' : (["_tes_plus","_tes_minus"]if self.is_mc else ['']), + 'met' : (["_mes_plus", "_ues_plus", "_mes_minus", "_ues_minus"] if self.is_mc else []), + 'tes' : (["", "_tes_plus", "_tes_minus"] if self.is_mc else ['']), + 'ees' : (["", "_ees_plus", '_ees_minus'] if self.is_mc else ['']) } #self filling histograms @@ -214,17 +215,21 @@ def begin(self): self.systematics['mvetos'] + \ self.systematics['tvetos'] + \ self.systematics['evetos'] + \ + [i.strip('_') for i in self.systematics['jes']] + \ + [i.strip('_') for i in self.systematics['tes']] + \ + [i.strip('_') for i in self.systematics['ees']] + \ ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + \ - ['tesUp', 'tesDown'] +\ - ['eesUp', 'eesDown'] +\ ['eLoose', 'eLoose/Up', 'eLoose/Down'] +\ ['etLoose', 'etLoose/Up', 'etLoose/Down'] sys_shifts = list( set( sys_shifts ) ) #remove double dirs processtype=['gg'] threshold=['ept30'] signs =['os', 'ss'] - jetN = [''.join(i) for i in itertools.product(['0', '1', '2', '3'], self.systematics['jes'])] - + jetN = ['0', '1', '2', '3'] #[''.join(i) for i in itertools.product(['0', '1', '2', '3'], self.systematics['jes'])] + full_met_systematics = self.systematics['met']+self.systematics['jes']+ \ + self.systematics['tes']+self.systematics['ees'] + #remove empty string + full_met_systematics = [i for i in full_met_systematics if i] folder=[] for tuple_path in itertools.product(sys_shifts, signs, processtype, threshold, jetN): @@ -272,7 +277,7 @@ def book_with_sys(location, name, *args, **kwargs): #self.book(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320) book_with_sys(f, "h_collmass_pfmet", "h_collmass_pfmet", 40, 0, 400, - postfixes=self.systematics['met']) + postfixes=full_met_systematics) self.book(f, "h_collmass_vs_dPhi_pfmet", "h_collmass_vs_dPhi_pfmet", 20, 0, 3.2, 40, 0, 400, type=ROOT.TH2F) @@ -290,16 +295,16 @@ def book_with_sys(location, name, *args, **kwargs): #self.book(f,"tMtToPFMET", "tau-PFMET M_{T}" , 200, 0, 200) book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 40, 0, 200, - postfixes=self.systematics['met']) + postfixes=full_met_systematics) #self.book(f,"eMtToPFMET", "e-PFMET M_{T}" , 200, 0, 200) book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 40, 0, 200, - postfixes=self.systematics['met']) + postfixes=full_met_systematics) #self.book(f, "pfMetEt", "pfMetEt", 200, 0, 200) - book_with_sys(f, "pfMet_Et", "pfMet_Et", 40, 0, 200, postfixes=self.systematics['met']) + book_with_sys(f, "pfMet_Et", "pfMet_Et", 40, 0, 200, postfixes=full_met_systematics) #self.book(f, "pfMetPhi", "pfMetPhi", 100, -3.2, 3.2) - book_with_sys(f, "pfMet_Phi", "pfMet_Phi", 26, -3.2, 3.2, postfixes=self.systematics['met']) + book_with_sys(f, "pfMet_Phi", "pfMet_Phi", 26, -3.2, 3.2, postfixes=full_met_systematics) self.book(f, "jetVeto20", "Number of jets, p_{T}>20", 5, -0.5, 4.5) self.book(f, "jetVeto30", "Number of jets, p_{T}>30", 5, -0.5, 4.5) @@ -400,6 +405,18 @@ def process(self): lock =() ievt = 0 logging.debug('Starting evt loop') + + #pre-compute static things + sys_shifts = systematics['trig'] + \ + systematics['pu'] + \ + systematics['eid'] + \ + systematics['eiso'] #+ \ + + jes_dirs = [i.strip('_') for i in systematics['jes']] + #anyway the first is always "" + tes_dirs = [i.strip('_') for i in systematics['tes']][1:] + ees_dirs = [i.strip('_') for i in systematics['ees']][1:] + for row in self.tree: if (ievt % 100) == 0: logging.debug('New event') @@ -431,20 +448,12 @@ def process(self): #e ID/ISO if not selections.lepton_id_iso(row, 'e', 'eid13Tight_idiso02'): continue logging.debug('Passed preselection') - isETight = False - if selections.lepton_id_iso(row, 'e', 'eid13Tight_etauiso01'): isETight = True - logging.debug('tight electron: %s' %isETight) # # Compute event weight # #event weight - sys_shifts = systematics['trig'] + \ - systematics['pu'] + \ - systematics['eid'] + \ - systematics['eiso'] #+ \ - #systematics['tesPlus'] + \ #vanno aggiunte piu` avanti come le jet categories. Non hanno un peso, cambia la soglia - #systematics['tesMinus'] + #sys_shifts is precomputed #set_trace() weight_map = self.event_weight(row, sys_shifts) @@ -458,118 +467,70 @@ def process(self): if row.bjetCSVVeto30!=0 : continue #tau ID, id Tau is tight then go in full selection, otherwise use for fakes - tau_id_category = [''] if row.tTightIso3Hits else ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] - e_id_category = [''] if isETight else ['eLoose', 'eLoose/Up', 'eLoose/Down'] - et_id_category = [''] if isETight and row.tTightIso3Hits else ['etLoose', 'etLoose/Up', 'etLoose/Down'] isTauTight = bool(row.tTightIso3Hits) + isETight = bool(selections.lepton_id_iso(row, 'e', 'eid13Tight_etauiso01')) + etau_category = [''] + if (not isETight) and (not isTauTight): + etau_category = ['etLoose', 'etLoose/Up', 'etLoose/Down'] + elif (not isTauTight): + etau_category = ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + elif (not isETight): + etau_category = ['eLoose', 'eLoose/Up', 'eLoose/Down'] #jet category - jn = min(row.jetVeto30, 3) - jn_jes_plus = min(row.jetVeto30jes_plus, 3) - jn_jes_minus = min(row.jetVeto30jes_minus, 3) - jet_categories = [jn, jn_jes_plus, jn_jes_minus] - jet_category_names = ['%i%s' % i for i in zip(jet_categories, systematics['jes'])] - - passes_full_selection = False - tThr = 30 - eThr = 30 - tes_categories_presel=[ ('', bool(row.tPt > tThr)),( 'tesUp', bool(row.tPt_tes_plus > tThr)), ('tesDown', bool(row.tPt_tes_minus > tThr))] - ees_categories_presel=[ ('', bool(row.ePt > eThr)),( 'eesUp', bool(row.ePt_ees_plus > eThr)), ('eesDown', bool(row.ePt_ees_minus > eThr))] + central = struct( + njets = min(row.jetVeto30, 3), + tPt = row.tPt, + ePt = row.ePt + ) + jets = [min(row.jetVeto30, 3), min(row.jetVeto30jes_plus, 3), min(row.jetVeto30jes_minus, 3)] + tpts = [row.tPt_tes_plus, row.tPt_tes_minus] + epts = [row.ePt_ees_plus, row.ePt_ees_minus] + sys_effects = [(name, central.clone(njets = jnum)) for name, jnum in zip(jes_dirs, jets)] + sys_effects.extend( + [(name, central.clone(tPt = pt)) for name, pt in zip(tes_dirs, tpts)] + ) + sys_effects.extend( + [(name, central.clone(ePt = pt)) for name, pt in zip(ees_dirs, epts)] + ) # # Full tight selection # - full_selection = [[''] for _ in jet_categories] -# tes_categories = [ ('', False),( 'tesUp', False), ('tesDown', False)] -# ees_categories = [ ('', False),( 'eesUp', False), ('eesDown', False)] - for idx, njet in enumerate(jet_categories): - if njet == 0 : - tThr = 35 - eThr = 30 - if min(row.tPt, row.tPt_tes_plus, row.tPt_tes_minus) < tThr: continue - if min(row.ePt, row.ePt_ees_plus, row.ePt_ees_minus) < eThr: continue - tes_categories_mapper={ - '' : bool(row.tPt > tThr), - 'tesUp' : bool(row.tPt_tes_plus > tThr), - 'tesDown': bool(row.tPt_tes_minus > tThr)} - - ees_categories_mapper={ - '' : bool(row.ePt > eThr), - 'eesUp' : bool(row.ePt_ees_plus > eThr), - 'eesDown': bool(row.ePt_ees_minus > eThr)} - - - - #if row.tPt > 35: tes_categories.append('') - #if row.tPt_tes_plus > 35: tes_categories.append('tesPlus/') - #if row.tPt_tes_minus > 35: tes_categories.append('tesDown/') - #if row.ePt < 40 : continue + passes_full_selection = False + selection_categories = [] + for name, shifted in sys_effects: + #preselection. flat pt values + if shifted.ePt > 30 and shifted.tPt > 30: + selection_categories.append((name, '%i' % shifted.njets, '')) + else: + continue + + if shifted.njets == 0 : + if shifted.tPt < 35: continue + if shifted.ePt < 40: continue if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue if row.tMtToPfMet > 50 : continue - full_selection[idx].append('selected') + selection_categories.append((name, '0', 'selected')) passes_full_selection = True - elif njet == 1 : - tThr = 40 - eThr = 35 - - if min(row.tPt, row.tPt_tes_plus, row.tPt_tes_minus) < tThr: continue - if min(row.ePt, row.ePt_ees_plus, row.ePt_ees_minus) < eThr: continue - - tes_categories_mapper={ - '' : bool(row.tPt > tThr), - 'tesUp' : bool(row.tPt_tes_plus > tThr), - 'tesDown': bool(row.tPt_tes_minus > tThr)} - - ees_categories_mapper={ - '' : bool(row.ePt > eThr), - 'eesUp' : bool(row.ePt_ees_plus > eThr), - 'eesDown': bool(row.ePt_ees_minus > eThr)} - - #if row.tPt > 40: tes_category.append('') - #if row.tPt_tes_plus > 40: tes_categories.append('tesPlus/') - #if row.tPt_tes_minus > 40: tes_categories.append('tesDown/') - if row.ePt < 35 : continue + elif shifted.njets == 1 : + if shifted.tPt < 40: continue + if shifted.ePt < 35: continue if row.tMtToPfMet > 35 : continue - full_selection[idx].append('selected') + selection_categories.append((name, '1', 'selected')) passes_full_selection = True - elif njet == 2 : - tThr = 40 - eThr = 30 - - if min(row.tPt, row.tPt_tes_plus, row.tPt_tes_minus) < tThr: continue - if min(row.ePt, row.ePt_ees_plus, row.ePt_ees_minus) < eThr: continue - tes_categories_mapper={ - '' : bool(row.tPt > tThr), - 'tesUp' : bool(row.tPt_tes_plus > tThr), - 'tesDown': bool(row.tPt_tes_minus > tThr)} - - ees_categories_mapper={ - '' : bool(row.ePt > eThr), - 'eesUp' : bool(row.ePt_ees_plus > eThr), - 'eesDown': bool(row.ePt_ees_minus > eThr)} - - #if row.tPt > 40: tes_category.append('') - #if row.tPt_tes_plus > 40: tes_categories.append('tesPlus/') - #if row.tPt_tes_Minus > 40: tes_categories.append('tesDown/') - if row.ePt < 30 : continue # no cut as only electrons with pt>30 are in the ntuples + elif shifted.njets == 2 : + if shifted.tPt < 40: continue + if shifted.ePt < 30: continue if row.tMtToPfMet > 35 : continue if row.vbfMass < 550 : continue if row.vbfDeta < 3.5 : continue - full_selection[idx].append('selected') + selection_categories.append((name, '2', 'selected')) passes_full_selection = True if passes_full_selection: logging.debug('Passed full selection') - - jet_directories = [] - for jet_dir, sel_dir in zip(jet_category_names, full_selection): - jet_directories.extend( - [os.path.join(jet_dir, i) for i in sel_dir] - ) - - - # #different selections # @@ -599,25 +560,15 @@ def process(self): #...and choose only the meaningful ones veto_sys = set(systematics['tvetos']+systematics['mvetos']+systematics['evetos']) all_dirs = [i for i in all_dirs if i in veto_sys] - - tes_directories =[] - for tdir,tbool in tes_categories_presel: - if tbool==True: tes_directories.append(tdir) - ees_directories =[] - for edir,ebool in ees_categories_presel: - if ebool==True: ees_directories.append(edir) - #if tdir == '' and tbool==False : - # all_dirs=[] - # syst_shifts=[] - sys_directories = all_dirs + sys_shifts +tes_directories+ees_directories + sys_directories = all_dirs + sys_shifts #remove duplicates sys_directories = list(set(sys_directories)) - - if not isTauTight and isETight: + #at least one loose object + if (not isETight) or (not isTauTight): #if is a loose tau just compute the fakes! - sys_directories = tau_id_category + sys_directories = etau_category #gather the one and only weight we do care about mc_weight = weight_map[''] @@ -628,70 +579,29 @@ def process(self): #...times the mc weight (if any) weight_map[i] *= mc_weight - if not isETight and isTauTight: - #if is a loose tau just compute the fakes! - sys_directories = e_id_category - logging.debug('fake electron') - #gather the one and only weight we do care about - mc_weight = weight_map[''] - #weights are the fr ones... - weight_map = self.fakerate_weights(row.eEta) - for i in weight_map: - #...times the mc weight (if any) - weight_map[i] *= mc_weight - - if not isETight and not isTauTight: - #if is a loose tau just compute the fakes! - sys_directories = et_id_category - - #gather the one and only weight we do care about - mc_weight = weight_map[''] - - #weights are the fr ones... - weight_map = self.fakerate_weights(row.tEta) - for i in weight_map: - #...times the mc weight (if any) - weight_map[i] *= mc_weight - - - if tes_categories_presel[0]==False or ees_categories_presel[0]==False : - sys_directories = [] - if ees_categories_presel[0]==True : - sys_directories.extend([i for i,j in tes_categories_presel if j==True ]) - elif tes_categories_presel[0]==True : - sys_directories.extend([i for i,j in ees_categories_presel if j==True ]) - else: - continue - - - #Fill histograms in appropriate direcotries #if passes_full_selection: #dirs = [os.path.join(sys, sign, processtype, e_thr, jet_dir) for sys, e_thr, jet_dir in itertools.product(sys_directories, ptthreshold, jet_directories)] #if len(dirs) <> len(set(dirs)): # set_trace() - for sys, e_thr, jet_dir in itertools.product(sys_directories, ptthreshold, jet_directories): + for sys, e_thr, selection in itertools.product(sys_directories, ptthreshold, selection_categories): + selection_sys, jet_dir, selection_step = selection + #if we have multiple systematic shifts applied + #reject the combination + if selection_sys and sys: + continue + #if we fill a histogram, lock the event lock = evt_id - dir_name = os.path.join(sys, sign, processtype, - e_thr, jet_dir) + dir_name = os.path.join(sys, selection_sys, sign, processtype, + e_thr, jet_dir, selection_step) if dir_name[-1] == '/': dir_name = dir_name[:-1] if passes_full_selection: logging.debug('Filling %s' % dir_name) #fill them! weight_to_use = weight_map[sys] if sys in weight_map else weight_map[''] - if dir_name.endswith('selected'): - if not dir_name.startswith('tes') and not dir_name.startswith('ees') : - if tes_categories_mapper.get('', False) == False or ees_categories_mapper.get('', False) == False : continue - else : - #print dir_name[:dir_name.index('/')] - name = dir_name[:dir_name.index('/')] - if tes_categories_mapper.get(name, False) == False or ees_categories_mapper.get(name, False) == False : continue - - - self.fill_histos(dir_name, row, weight_to_use) diff --git a/lfvetau/baseSelections.py b/lfvetau/baseSelections.py index abb3f6d2..bda855ff 100755 --- a/lfvetau/baseSelections.py +++ b/lfvetau/baseSelections.py @@ -22,10 +22,11 @@ def muSelection(row, name): def eSelection(row, name): eAbsEta = getattr( row, getVar(name,'AbsEta')) - if getattr( row, getVar(name,'Pt_ees_minus')) !=0 and getattr( row, getVar(name,'Pt_ees_plus')) !=0: - if min(getattr( row, getVar(name,'Pt')),getattr( row, getVar(name,'Pt_ees_minus')), getattr( row, getVar(name,'Pt_ees_plus'))) < 30: return False + ept = getattr( row, getVar(name,'Pt_ees_minus')) + if ept: + if ept < 30: return False else: - if getattr( row, getVar(name,'Pt')) < 30: return False #was 20 + if getattr( row, getVar(name,'Pt')) < 30: return False #was 20 if eAbsEta > 2.3: return False if getattr( row, getVar(name,'MissingHits')): return False @@ -40,8 +41,9 @@ def eSelection(row, name): return True def tauSelection(row, name): - if getattr( row, getVar(name,'Pt_tes_minus')) !=0 and getattr( row, getVar(name,'Pt_tes_plus')) !=0: - if min(getattr( row, getVar(name,'Pt')),getattr( row, getVar(name,'Pt_tes_minus')), getattr( row, getVar(name,'Pt_tes_plus'))) < 30: return False + tpt = getattr( row, getVar(name,'Pt_tes_minus')) + if tpt: + if tpt < 30: return False else: if getattr( row, getVar(name,'Pt')) < 30: return False if getattr( row, getVar(name,'AbsEta')) > 2.3: return False From b9925e67a864a6a147cb4d3cdc307d2ac483f410 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Mon, 24 Nov 2014 09:30:51 -0600 Subject: [PATCH 160/192] appropriate rebin --- lfvetau/plotRecoQuantitiesMVA.py | 41 ++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/lfvetau/plotRecoQuantitiesMVA.py b/lfvetau/plotRecoQuantitiesMVA.py index 49ebf2cd..9ec03ba7 100644 --- a/lfvetau/plotRecoQuantitiesMVA.py +++ b/lfvetau/plotRecoQuantitiesMVA.py @@ -37,25 +37,25 @@ plotter = BasePlotter(blind_region,use_embedded=embedded) signs = ['os','ss'] -jets = ['0', '1', '2'] +jets = ['0','1','2'] processtype = ['gg'] threshold = ['ept30'] histo_info = [ - ('tPt', 'p_{T}(#tau) (GeV)', 5), - ('tEta', '#eta(#tau)', 2), - ('tPhi', '#phi(#tau)', 5), - ('ePt', 'p_{T}(e) (GeV)', 5), - ('eEta', '#eta(e)', 2), - ('ePhi', '#phi(e)', 5), + ('tPt', 'p_{T}(#tau) (GeV)', 1), + ('tEta', '#eta(#tau)', 1), + ('tPhi', '#phi(#tau)', 1), + ('ePt', 'p_{T}(e) (GeV)', 1), + ('eEta', '#eta(e)', 1), + ('ePhi', '#phi(e)', 1), ('e_t_DPhi', 'e#tau #Delta#phi', 1), ('e_t_DR', 'e#tau #Delta R', 1), ('h_collmass_pfmet', 'M_{coll}(e#tau) (GeV)', 1), ('e_t_Mass', 'M_{vis} (GeV)', 1), ('jetVeto30', 'number of jets (p_{T} > 30 GeV)', 1) , - ('eMtToPfMet', 'M_{T} e-PFMET', 5), - ('tMtToPfMet', 'M_{T} #tau-PFMET', 5) , - ('pfMet_Et', 'pfMet', 5) + ('eMtToPfMet', 'M_{T} e-PFMET', 1), + ('tMtToPfMet', 'M_{T} #tau-PFMET', 1) , + ('pfMet_Et', 'pfMet', 1) ] logging.debug("Starting plotting") @@ -68,16 +68,27 @@ logging.debug("Plotting %s/%s" % (path, var) ) plotter.pad.SetLogy(False) #plotter.plot_without_uncert(foldername,h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.5, sort=True, obj=['e']) + if int(njet)==2: + if 'collmass' in var or 'Mass' in var: + rebin=rebin*5 + elif not 'Eta' in var and not 'jet' in var: + rebin = rebin*2 + plotter.plot_with_bkg_uncert(path, var, rebin, xlabel, - leftside=False, show_ratio=True, ratio_range=1., - sort=True, obj=['e']) - - + leftside=False, show_ratio=True, ratio_range=1., + sort=True, obj=['e']) + + plotter.save(var) - + plotter.set_subdir(os.path.join('embedded', path+'/selected'))if embedded else plotter.set_subdir(path+'/selected') for var, xlabel, rebin in histo_info: + if int(njet)==1: + if not 'Eta' in var and not 'jet' in var: rebin = rebin*2 + if int(njet) ==2: + if 'collmass' in var or 'Mass' in var: rebin=rebin*5 + if 'Pt' in var or 'Mt' in var or 'pfMet' in var : rebin=rebin*4 logging.debug("Plotting %s/%s" % (path, var) ) plotter.pad.SetLogy(False) plotter.plot_with_bkg_uncert(path+'/selected', var, rebin, xlabel, From cefccc9d7f0dc89927e8a12a1be27e47bf6742dd Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Wed, 26 Nov 2014 05:33:10 -0600 Subject: [PATCH 161/192] bug fix for elefakerate --- lfvetau/EleFakeRateAnalyzerMVA.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lfvetau/EleFakeRateAnalyzerMVA.py b/lfvetau/EleFakeRateAnalyzerMVA.py index bb538039..ad1d7adf 100644 --- a/lfvetau/EleFakeRateAnalyzerMVA.py +++ b/lfvetau/EleFakeRateAnalyzerMVA.py @@ -48,13 +48,13 @@ def __init__(self, tree, outfile, **kwargs): self.mye1 = 'e1' self.mye2 = 'e2' self.mye3 = 'e3' - optimizer_keys = [ i for i in optimizer.grid_search.keys() if i.startswith(self.channel) ] + #optimizer_keys = [ i for i in optimizer.grid_search.keys() if i.startswith(self.channel) ] self.grid_search = {} - if len(optimizer_keys) > 1: - for key in optimizer_keys: - self.grid_search[key] = optimizer.grid_search[key] - else: - self.grid_search[''] = optimizer.grid_search[optimizer_keys[0]] + #if len(optimizer_keys) > 1: + # for key in optimizer_keys: + # self.grid_search[key] = optimizer.grid_search[key] + #else: + # self.grid_search[''] = optimizer.grid_search[optimizer_keys[0]] def event_weight(self, row): @@ -70,7 +70,18 @@ def event_weight(self, row): mcCorrections.trig_correction(row, self.mye3 ) def ee3DR(self, row): - return getattr(row, self.mye1+'_'+self.mye3+'_DR') if getattr(row, self.mye1+'_'+self.mye3+'_DR') < getattr(row, self.mye2+'_'+self.mye3+'_DR') else getattr(row, self.mye2+'_'+self.mye3+'_DR') + mye1_mye3_dr = 100. + mye2_mye3_dr = 100. + try: + mye1_mye3_dr = getattr(row, self.mye1+'_'+self.mye3+'_DR') + except AttributeError: + mye1_mye3_dr =getattr(row, self.mye3+'_'+self.mye1+'_DR') + try : + mye2_mye3_dr = getattr(row, self.mye2+'_'+self.mye3+'_DR') + except AttributeError: + mye2_mye3_dr =getattr(row, self.mye3+'_'+self.mye2+'_DR') + + return mye1_mye3_dr if mye1_mye3_dr < mye2_mye3_dr else mye1_mye3_dr def ee3DPhi(self, row): e1e3DPhi=deltaPhi(getattr(row, self.mye1+'Phi'), getattr(row, self.mye3+'Phi')) From ca80b0d615f2dec1ba42eac3a9405f58cd68be4a Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Wed, 26 Nov 2014 08:50:41 -0600 Subject: [PATCH 162/192] bug fix for collmass syst --- lfvetau/LFVHETauAnalyzerMVA.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 8bf0694b..c591e030 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -167,7 +167,15 @@ def __init__(self, tree, outfile, **kwargs): for shift in self.systematics['tes']: #patch name postfix = shift - self.hfunc['h_collmass%s_pfmet' % postfix] = make_collmass_systematics(shift) + self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + for shift in self.systematics['jes']: + #patch name + postfix = shift + self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + for shift in self.systematics['ees']: + #patch name + postfix = shift + self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) #PU correctors self.pucorrector = mcCorrections.make_shifted_weights( From 28a6d0ec90c1876273294587442742716f648b64 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Thu, 27 Nov 2014 04:14:43 -0600 Subject: [PATCH 163/192] minor datacard fixes --- lfvetau/card_config/unc.0.vals | 2 +- lfvetau/card_config/unc.1.vals | 2 +- lfvetau/card_config/unc.2.vals | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lfvetau/card_config/unc.0.vals b/lfvetau/card_config/unc.0.vals index 0db59ca5..996ee635 100755 --- a/lfvetau/card_config/unc.0.vals +++ b/lfvetau/card_config/unc.0.vals @@ -7,7 +7,7 @@ gg0mutau vbfhiggs Theo_UE 1.1 gg0mutau gghiggs Theo_Scale_gg 1.08 gg0mutau vbfhiggs Theo_Scale_vbf 1.04 -gg0mutau zjets Norm_ZTauTau 1.03 +gg0mutau ztautau Norm_ZTauTau 1.03 gg0mutau ztautau Norm_ZTauTau_et_0Jet_extra 1.05 gg0mutau zjetsother Norm_ZJetsOther 1.3 diff --git a/lfvetau/card_config/unc.1.vals b/lfvetau/card_config/unc.1.vals index 9e3cf26e..919bef15 100755 --- a/lfvetau/card_config/unc.1.vals +++ b/lfvetau/card_config/unc.1.vals @@ -7,7 +7,7 @@ boostetau vbfhiggs Theo_UE 1.0 boostetau gghiggs Theo_Scale_gg 1.1 boostetau vbfhiggs Theo_Scale_vbf 1.015 -boostetau zjets Norm_ZTauTau 1.03 +boostetau ztautau Norm_ZTauTau 1.03 boostetau ztautau Norm_ZTauTau_et_1Jet_extra 1.05 boostetau zjetsother Norm_ZJetsOther 1.3 diff --git a/lfvetau/card_config/unc.2.vals b/lfvetau/card_config/unc.2.vals index cc3c95bf..f6d5102a 100755 --- a/lfvetau/card_config/unc.2.vals +++ b/lfvetau/card_config/unc.2.vals @@ -7,7 +7,7 @@ vbfetau vbfhiggs Theo_UE 0.99 vbfetau gghiggs Theo_Scale_gg 0.7 vbfetau vbfhiggs Theo_Scale_vbf 1.02 -vbfetau zjets Norm_ZTauTau 1.03 +vbfetau ztautau Norm_ZTauTau 1.03 vbfetau ztautau Norm_ZTauTau_et_vbf_extra 1.10 vbfetau zjetsother Norm_ZJetsOther 1.3 @@ -19,7 +19,7 @@ vbfetau simulated lumi 1.026 vbfetau simulated Effi_et_Tau 1.06 vbfetau simulated Effi_et_Tau_highPt 1.03 -vbfetau ww Norm_WW 1.15 +vbfetau diboson Norm_DIBOSON 1.15 vbfetau singlet Norm_TOP 1.10 vbfetau ttbar Norm_TT 1.10 vbfetau fakes Norm_FAKES 1.30 From 58066aba961c6c890f6584bd84ad012572a18f71 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Thu, 27 Nov 2014 04:15:03 -0600 Subject: [PATCH 164/192] add last remaining systematics --- lfvetau/BasePlotter.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index d69aa2d5..60786f8f 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -181,8 +181,20 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): }, 'JES' : { 'type' : 'shape', - '+' : lambda x: x.replace('/0/','/0_jes_plus/').replace('/1/','/1_jes_plus/').replace('/2/','/2_jes_plus/')+'_jes_plus' , - '-' : lambda x: x.replace('/0/','/0_jes_minus/').replace('/1/','/1_jes_minus/').replace('/2/','/2_jes_minus/')+'_jes_minus' , + '+' : lambda x: os.path.join('jes_plus', x)+'_jes_plus' , + '-' : lambda x: os.path.join('jes_minus', x)+'_jes_minus' , + 'apply_to' : ['fullsimbkg'], + }, + 'TES' : { + 'type' : 'shape', + '+' : lambda x: os.path.join('tes_plus', x)+'_tes_plus' , + '-' : lambda x: os.path.join('tes_minus', x)+'_tes_minus' , + 'apply_to' : ['fullsimbkg'], + }, + 'EES' : { + 'type' : 'shape', + '+' : lambda x: os.path.join('ees_plus', x) +'_ees_plus' , + '-' : lambda x: os.path.join('ees_minus', x)+'_ees_minus' , 'apply_to' : ['fullsimbkg'], }, 'UES' : { @@ -203,12 +215,6 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): '-' : lambda x: x, 'apply_to' : ['fakes','simbkg'], } - 'TES' : { - 'type' : 'shape', - '+' : dir_systematic('tesUp'), - '-' : dir_systematic('tesDown'), - 'apply_to' : ['simbkg'], - }, } @@ -916,14 +922,21 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=0.01, if self.use_embedded: view = self.get_view('ZetauEmbedded') + if preprocess: + view = preprocess(view) + view = self.rebin_view(view, rebin) name = self.datacard_names['ZetauEmbedded'] bkg_views[name] = view mc_histo = view.Get(path) bkg_histos[name] = mc_histo.Clone() mc_histo.SetName(name) mc_histo.Write() - - bkg_views['fakes'] = self.get_view('fakes') + + fakes_view = self.get_view('fakes') + if preprocess: + fakes_view = preprocess(fakes_view) + fakes_view = self.rebin_view(fakes_view, rebin) + bkg_views['fakes'] = fakes_view fake_shape = bkg_views['fakes'].Get(path) bkg_histos['fakes'] = fake_shape.Clone() fake_shape.SetName('fakes') From dc28c11f348c10ac4e4693bcbbe5f18709378275 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Thu, 27 Nov 2014 04:15:30 -0600 Subject: [PATCH 165/192] add argparser to make plotting/shape writing faster --- lfvetau/plotRecoQuantitiesMVA.py | 151 +++++++++++++++++-------------- 1 file changed, 81 insertions(+), 70 deletions(-) diff --git a/lfvetau/plotRecoQuantitiesMVA.py b/lfvetau/plotRecoQuantitiesMVA.py index b7b48cb8..3c656f89 100644 --- a/lfvetau/plotRecoQuantitiesMVA.py +++ b/lfvetau/plotRecoQuantitiesMVA.py @@ -16,6 +16,14 @@ import glob import sys from BasePlotter import BasePlotter +from argparse import ArgumentParser + +parser = ArgumentParser(description=__doc__) +parser.add_argument('--no-plots', dest='no_plots', action='store_true', + default=False, help='Does not print plots') +parser.add_argument('--no-shapes', dest='no_shapes', action='store_true', + default=False, help='Does not create shapes for limit computation') +args = parser.parse_args() jobid = os.environ['jobid'] #jobid = 'MCntuples_3March' @@ -36,79 +44,82 @@ plotter = BasePlotter(blind_region,use_embedded=embedded) -signs = ['os','ss'] -jets = ['0', '1', '2'] -processtype = ['gg'] -threshold = ['ept30'] - -histo_info = [ - ('tPt', 'p_{T}(#tau) (GeV)', 5), - ('tEta', '#eta(#tau)', 2), - ('tPhi', '#phi(#tau)', 5), - ('ePt', 'p_{T}(e) (GeV)', 5), - ('eEta', '#eta(e)', 2), - ('ePhi', '#phi(e)', 5), - ('e_t_DPhi', 'e#tau #Delta#phi', 1), - ('e_t_DR', 'e#tau #Delta R', 1), - ('h_collmass_pfmet', 'M_{coll}(e#tau) (GeV)', 1), - ('e_t_Mass', 'M_{vis} (GeV)', 1), - ('jetVeto30', 'number of jets (p_{T} > 30 GeV)', 1) , - ('eMtToPfMet', 'M_{T} e-PFMET', 5), - ('tMtToPfMet', 'M_{T} #tau-PFMET', 5) , - ('pfMet_Et', 'pfMet', 5) -] - -logging.debug("Starting plotting") -for sign, proc, thr, njet in itertools.product(signs, processtype, threshold, jets): - path = os.path.join(sign, proc, thr, njet) - - plotter.set_subdir(os.path.join('embedded',path)) if embedded else plotter.set_subdir(path) - - for var, xlabel, rebin in histo_info: - logging.debug("Plotting %s/%s" % (path, var) ) - plotter.pad.SetLogy(False) - #plotter.plot_without_uncert(foldername,h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.5, sort=True, obj=['e']) - plotter.plot_with_bkg_uncert(path, var, rebin, xlabel, - leftside=False, show_ratio=True, ratio_range=1., - sort=True, obj=['e']) - - - plotter.save(var) - - plotter.set_subdir(os.path.join('embedded', path+'/selected'))if embedded else plotter.set_subdir(path+'/selected') - - for var, xlabel, rebin in histo_info: - logging.debug("Plotting %s/%s" % (path, var) ) - plotter.pad.SetLogy(False) - plotter.plot_with_bkg_uncert(path+'/selected', var, rebin, xlabel, - leftside=False, show_ratio=True, ratio_range=1., - sort=True, obj=['e']) - +if not args.no_plots: + signs = ['os','ss'] + jets = ['0', '1', '2'] + processtype = ['gg'] + threshold = ['ept30'] + + histo_info = [ + ('tPt', 'p_{T}(#tau) (GeV)', 5), + ('tEta', '#eta(#tau)', 2), + ('tPhi', '#phi(#tau)', 5), + ('ePt', 'p_{T}(e) (GeV)', 5), + ('eEta', '#eta(e)', 2), + ('ePhi', '#phi(e)', 5), + ('e_t_DPhi', 'e#tau #Delta#phi', 1), + ('e_t_DR', 'e#tau #Delta R', 1), + ('h_collmass_pfmet', 'M_{coll}(e#tau) (GeV)', 1), + ('e_t_Mass', 'M_{vis} (GeV)', 1), + ('jetVeto30', 'number of jets (p_{T} > 30 GeV)', 1) , + ('eMtToPfMet', 'M_{T} e-PFMET', 5), + ('tMtToPfMet', 'M_{T} #tau-PFMET', 5) , + ('pfMet_Et', 'pfMet', 5) + ] + + logging.debug("Starting plotting") + for sign, proc, thr, njet in itertools.product(signs, processtype, threshold, jets): + path = os.path.join(sign, proc, thr, njet) - plotter.save(var,dotroot=False) + plotter.set_subdir(os.path.join('embedded',path)) if embedded else plotter.set_subdir(path) + + for var, xlabel, rebin in histo_info: + logging.debug("Plotting %s/%s" % (path, var) ) + plotter.pad.SetLogy(False) + #plotter.plot_without_uncert(foldername,h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.5, sort=True, obj=['e']) + plotter.plot_with_bkg_uncert(path, var, rebin, xlabel, + leftside=False, show_ratio=True, ratio_range=1., + sort=True, obj=['e']) + + + plotter.save(var) + + plotter.set_subdir(os.path.join('embedded', path+'/selected'))if embedded else plotter.set_subdir(path+'/selected') + + for var, xlabel, rebin in histo_info: + logging.debug("Plotting %s/%s" % (path, var) ) + plotter.pad.SetLogy(False) + plotter.plot_with_bkg_uncert(path+'/selected', var, rebin, xlabel, + leftside=False, show_ratio=True, ratio_range=1., + sort=True, obj=['e']) + + + plotter.save(var,dotroot=False) #make shapes for limit setting -signal_region = 'os/gg/ept30/%s/selected' -jets_names = [ - ('0', 'gg0etau' ), - ('1', 'boostetau'), - ('2', 'vbfetau' ), -] -pjoin = os.path.join -for njets, cat_name in jets_names: - output_path = plotter.base_out_dir - tfile = ROOT.TFile(pjoin(output_path, 'shapes.%s.root' % njets), 'recreate') - output_dir = tfile.mkdir(cat_name) - unc_conf_lines, unc_vals_lines = plotter.write_shapes( signal_region % njets, 'h_collmass_pfmet', output_dir) - logging.warning('shape file %s created' % tfile.GetName()) - tfile.Close() - with open(pjoin(output_path, 'unc.%s.conf' % njets), 'w') as conf: - conf.write('\n'.join(unc_conf_lines)) - with open(pjoin(output_path, 'unc.%s.vals' % njets), 'w') as vals: - vals.write('\n'.join(unc_vals_lines)) - -with open(pjoin(output_path,'.shapes_timestamp'),'w') as stamp: - stamp.write('no use') +if not args.no_shapes: + signal_region = 'os/gg/ept30/%s/selected' + jets_names = [ + ('0', 'gg0etau' , 1), + ('1', 'boostetau', 1), + ('2', 'vbfetau' , 5), + ] + pjoin = os.path.join + for njets, cat_name, rebin in jets_names: + output_path = plotter.base_out_dir + tfile = ROOT.TFile(pjoin(output_path, 'shapes.%s.root' % njets), 'recreate') + output_dir = tfile.mkdir(cat_name) + unc_conf_lines, unc_vals_lines = plotter.write_shapes( + signal_region % njets, 'h_collmass_pfmet', output_dir, rebin=rebin) + logging.warning('shape file %s created' % tfile.GetName()) + tfile.Close() + with open(pjoin(output_path, 'unc.%s.conf' % njets), 'w') as conf: + conf.write('\n'.join(unc_conf_lines)) + with open(pjoin(output_path, 'unc.%s.vals' % njets), 'w') as vals: + vals.write('\n'.join(unc_vals_lines)) + + with open(pjoin(output_path,'.shapes_timestamp'),'w') as stamp: + stamp.write('no use') From 747c1120720b2413bf70d30a810d69f250d1dadc Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 28 Nov 2014 03:53:08 -0600 Subject: [PATCH 166/192] added empty bin protection and tes and ees systematics --- lfvetau/BasePlotter.py | 55 +++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index 60786f8f..d81e818c 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -83,7 +83,14 @@ def parse_cgs_groups(file_path): if match: groups[match.group('groupname')] = [ i.strip() for i in match.group('includes').split(',') ] return groups - + +def remove_empty_bins(histogram, weight): + ret = histogram.Clone() + for i in range(ret.GetNbinsX() + 2): + if ret.GetBinContent(i) <= 0: + ret.SetBinContent(i, 0.9200*weight) #MEAN WEIGHT + ret.SetBinError(i, 1.8*weight) + return ret class BasePlotter(Plotter): def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): @@ -123,7 +130,11 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): if use_embedded: self.mc_samples.pop() - self.views['ZetauEmbedded'] = {'view' : self.make_embedded('os/gg/ept30/h_collmass_pfmet')} + embedded_view, weight = self.make_embedded('os/gg/ept30/h_collmass_pfmet') + self.views['ZetauEmbedded'] = { + 'view' : embedded_view, + 'weight' : weight + } self.views['fakes'] = {'view' : self.make_fakes('t')} #self.views['efakes'] = {'view' : self.make_fakes('e')} #self.views['etfakes'] = {'view' : self.make_fakes('et')} @@ -151,7 +162,8 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): 'fullsimbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', 'diboson', 'zjetsother'], #, 'WWVBF126', 'WWGG126',], 'simbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', 'ztautau', - 'diboson', 'zjetsother']#, 'WWVBF126', 'WWGG126',] + 'diboson', 'zjetsother'], #'WWVBF126', 'WWGG126',] + 'realtau' : ['ztautau', 'SMGG126', 'SMVBF126'], } self.systematics = { @@ -189,13 +201,13 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): 'type' : 'shape', '+' : lambda x: os.path.join('tes_plus', x)+'_tes_plus' , '-' : lambda x: os.path.join('tes_minus', x)+'_tes_minus' , - 'apply_to' : ['fullsimbkg'], + 'apply_to' : ['realtau'], }, 'EES' : { 'type' : 'shape', '+' : lambda x: os.path.join('ees_plus', x) +'_ees_plus' , '-' : lambda x: os.path.join('ees_minus', x)+'_ees_minus' , - 'apply_to' : ['fullsimbkg'], + 'apply_to' : ['simbkg'], }, 'UES' : { 'type' : 'shape', @@ -267,7 +279,7 @@ def make_embedded(self, normalization_path): ), 'Z #rightarrow #tau#tau (embedded)' ) - return scaled_view + return scaled_view, scale_factor def simpleplot_mc(self, folder, signal, variable, rebin=1, xaxis='', leftside=True, xrange=None, preprocess=None, sort=True,forceLumi=-1): @@ -912,47 +924,48 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=0.01, bkg_views = dict( [(self.datacard_names[i], j) for i, j in zip(self.mc_samples, self.mc_views(rebin, preprocess))] ) + bkg_weights = dict( + [(self.datacard_names[i], self.get_view(i, 'weight')) for i in self.mc_samples] + ) #cache histograms, since getting them is time consuming bkg_histos = {} for name, view in bkg_views.iteritems(): mc_histo = view.Get(path) bkg_histos[name] = mc_histo.Clone() + mc_histo = remove_empty_bins( + mc_histo, bkg_weights[name]) mc_histo.SetName(name) mc_histo.Write() if self.use_embedded: view = self.get_view('ZetauEmbedded') + weight = self.get_view('ZetauEmbedded', 'weight') if preprocess: view = preprocess(view) view = self.rebin_view(view, rebin) name = self.datacard_names['ZetauEmbedded'] + bkg_weights[name] = weight bkg_views[name] = view mc_histo = view.Get(path) bkg_histos[name] = mc_histo.Clone() + mc_histo = remove_empty_bins( + mc_histo, weight) mc_histo.SetName(name) mc_histo.Write() fakes_view = self.get_view('fakes') if preprocess: fakes_view = preprocess(fakes_view) + weights = fakes_view.Get(os.path.join(folder,'weight')) fakes_view = self.rebin_view(fakes_view, rebin) bkg_views['fakes'] = fakes_view + bkg_weights['fakes'] = abs(weights.GetMean()) fake_shape = bkg_views['fakes'].Get(path) bkg_histos['fakes'] = fake_shape.Clone() + fake_shape = remove_empty_bins( + fake_shape, bkg_weights['fakes']) fake_shape.SetName('fakes') fake_shape.Write() - - ##bkg_views['efakes'] = self.get_view('efakes') - ##efake_shape = bkg_views['efakes'].Get(path) - ##bkg_histos['efakes'] = fake_shape.Clone() - ##efake_shape.SetName('efakes') - ##efake_shape.Write() - - #bkg_views['etfakes'] = self.get_view('etfakes') - #etfake_shape = bkg_views['etfakes'].Get(path) - #bkg_histos['etfakes'] = fake_shape.Clone() - #etfake_shape.SetName('etfakes') - #etfake_shape.Write() unc_conf_lines = [] unc_vals_lines = [] @@ -990,6 +1003,10 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=0.01, (integral - integral_down) / integral ) elif info['type'] == 'shape': + #remove empty bins also for shapes + #(but not in general to not spoil the stat uncertainties) + up = remove_empty_bins(up, bkg_weights[target]) + down = remove_empty_bins(down, bkg_weights[target]) up.SetName('%s_%sUp' % (target, unc_name)) down.SetName('%s_%sDown' % (target, unc_name)) up.Write() @@ -1000,7 +1017,7 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=0.01, yield_val = up.GetBinContent(1) yield_err = up.GetBinError(1) unc_value = 1. + (yield_err / yield_val) - stat_unc_name = '%s_%s' % (target, unc_name) + stat_unc_name = '%s_%s_%s' % (target, category_name, unc_name) unc_conf_lines.append('%s %s' % (stat_unc_name, unc_conf)) unc_vals_lines.append( '%s %s %s %.2f' % (category_name, target, stat_unc_name, unc_value) From 00fa62d107aee2768f9e9e939f940c58c5474271 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 28 Nov 2014 08:25:01 -0600 Subject: [PATCH 167/192] add SM Higgs as background and empty bin protection for fakes v0.1 --- lfvetau/BasePlotter.py | 21 ++++++++++++++++++--- lfvetau/card_config/cgs.0.conf | 2 +- lfvetau/card_config/cgs.1.conf | 2 +- lfvetau/card_config/cgs.2.conf | 2 +- lfvetau/card_config/unc.2.conf | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index d81e818c..b086934f 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -63,6 +63,13 @@ def histo_diff_quad(mc_err, *systematics): return clone +def mean(histo): + '''compute histogram mean because root is not able to''' + nbins = histo.GetNbinsX() + wsum = sum( histo.GetBinCenter(i)*histo.GetBinContent(i) for i in xrange(1, nbins+1)) + entries = sum(histo.GetBinContent(i) for i in xrange(1, nbins+1)) + return float(wsum)/entries + def name_systematic(name): '''makes functor that makes a name systematic (with postfix)''' return lambda x: x+name @@ -954,19 +961,27 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=0.01, mc_histo.Write() fakes_view = self.get_view('fakes') + d_view = self.get_view('data') + weights_view = views.SumView( + views.SubdirectoryView(d_view, 'tLoose'), + views.SubdirectoryView(d_view, 'eLoose'), + views.SubdirectoryView(d_view, 'etLoose') + ) if preprocess: fakes_view = preprocess(fakes_view) - weights = fakes_view.Get(os.path.join(folder,'weight')) + weights_view = preprocess(weights_view) + weights = weights_view.Get(os.path.join(folder,'weight')) fakes_view = self.rebin_view(fakes_view, rebin) bkg_views['fakes'] = fakes_view - bkg_weights['fakes'] = abs(weights.GetMean()) + bkg_weights['fakes'] = mean(weights) + print bkg_weights['fakes'] fake_shape = bkg_views['fakes'].Get(path) bkg_histos['fakes'] = fake_shape.Clone() fake_shape = remove_empty_bins( fake_shape, bkg_weights['fakes']) fake_shape.SetName('fakes') fake_shape.Write() - + unc_conf_lines = [] unc_vals_lines = [] category_name = output_dir.GetName() diff --git a/lfvetau/card_config/cgs.0.conf b/lfvetau/card_config/cgs.0.conf index 2411ac9e..299f6d87 100644 --- a/lfvetau/card_config/cgs.0.conf +++ b/lfvetau/card_config/cgs.0.conf @@ -11,7 +11,7 @@ $ GROUP signal LFVGG,LFVVBF $ GROUP gghiggs LFVGG,SMGG126 $ GROUP vbfhiggs LFVVBF,SMVBF126 $ GROUP zjets ztautau,zjetsother -$ GROUP background diboson,ttbar,singlet,ztautau,zjetsother,fakes +$ GROUP background diboson,ttbar,singlet,ztautau,zjetsother,fakes,SMVBF126,SMGG126 $ GROUP simulated diboson,ttbar,singlet,ztautau,zjetsother,LFVVBF,SMVBF126,WWVBF126,LFVGG,SMGG126,WWGG126 categories: gg0etau diff --git a/lfvetau/card_config/cgs.1.conf b/lfvetau/card_config/cgs.1.conf index 840186e1..e9a51211 100644 --- a/lfvetau/card_config/cgs.1.conf +++ b/lfvetau/card_config/cgs.1.conf @@ -11,7 +11,7 @@ $ GROUP signal LFVGG,LFVVBF $ GROUP gghiggs LFVGG,SMGG126 $ GROUP vbfhiggs LFVVBF,SMVBF126 $ GROUP zjets ztautau,zjetsother -$ GROUP background diboson,ttbar,singlet,ztautau,zjetsother,fakes +$ GROUP background diboson,ttbar,singlet,ztautau,zjetsother,fakes,SMVBF126,SMGG126 $ GROUP simulated diboson,ttbar,singlet,ztautau,zjetsother,LFVVBF,SMVBF126,LFVGG,SMGG126 categories: boostetau diff --git a/lfvetau/card_config/cgs.2.conf b/lfvetau/card_config/cgs.2.conf index fd444137..2bd819a3 100644 --- a/lfvetau/card_config/cgs.2.conf +++ b/lfvetau/card_config/cgs.2.conf @@ -11,7 +11,7 @@ $ GROUP signal LFVGG,LFVVBF $ GROUP gghiggs LFVGG,SMGG126 $ GROUP vbfhiggs LFVVBF,SMVBF126 $ GROUP zjets ztautau,zjetsother -$ GROUP background diboson,ttbar,singlet,ztautau,zjetsother,fakes +$ GROUP background diboson,ttbar,singlet,ztautau,zjetsother,fakes,SMVBF126,SMGG126 $ GROUP simulated diboson,ttbar,singlet,ztautau,zjetsother,LFVVBF,SMVBF126,LFVGG,SMGG126 categories: vbfetau diff --git a/lfvetau/card_config/unc.2.conf b/lfvetau/card_config/unc.2.conf index 9373743b..de8fc7a3 100755 --- a/lfvetau/card_config/unc.2.conf +++ b/lfvetau/card_config/unc.2.conf @@ -16,7 +16,7 @@ Norm_ZTauTau_et_vbf_extra lnN Norm_WW_et_vbf_extra lnN Norm_TT_et_vbf_extra lnN Norm_ZJetsOther lnN -Norm_WW lnN +Norm_DIBOSON lnN Norm_TT lnN Norm_FAKES lnN Norm_SMGG lnN From 91583be8fd9362de3c3355eca7c8eeddde022d41 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 28 Nov 2014 09:37:40 -0600 Subject: [PATCH 168/192] bugfixes --- lfvetau/BasePlotter.py | 3 +-- lfvetau/Rakefile | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index b086934f..af694d2d 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -919,7 +919,7 @@ def plot_without_uncert (self, folder, variable, rebin=1, xaxis='', if show_ratio: self.add_ratio_diff(data, mc_stack, finalhisto, xrange, ratio_range) - def write_shapes(self, folder, variable, output_dir, br_strenght=0.01, + def write_shapes(self, folder, variable, output_dir, br_strenght=1, rebin=1, preprocess=None): #, systematics): '''Makes shapes for computing the limit and returns a list of systematic effects to be added to unc.vals/conf make_shapes(folder, variable, output_dir, [rebin=1, preprocess=None) --> unc_conf_lines (list), unc_vals_lines (list) @@ -974,7 +974,6 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=0.01, fakes_view = self.rebin_view(fakes_view, rebin) bkg_views['fakes'] = fakes_view bkg_weights['fakes'] = mean(weights) - print bkg_weights['fakes'] fake_shape = bkg_views['fakes'].Get(path) bkg_histos['fakes'] = fake_shape.Clone() fake_shape = remove_empty_bins( diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index 19193181..fab8c777 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -421,7 +421,7 @@ card_1_jet = prepare_limit('1') card_2_jet = prepare_limit('2') #combine cards -cmb_card = "#{$limitdir}/et_cmb/126/datacard_et_cmb.txt" +cmb_card = "#{$limitdir}/cmb/126/datacard_et_cmb.txt" file cmb_card => [card_0_jet, card_1_jet, card_2_jet] do |t| From e6dc7fc1be2aca1a22d848ed91fb158d7e6004c3 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Fri, 28 Nov 2014 11:40:15 -0600 Subject: [PATCH 169/192] few update --- lfvetau/BasePlotter.py | 6 +- lfvetau/LFVHETauAnalyzerMVA.py | 19 +-- lfvetau/Rakefile | 6 +- lfvetau/computeEmbeddedPeakScaleFactor.py | 153 ++++++++++++++++++++++ lfvetau/computeyields.py | 150 +++++++++++++++++++++ 5 files changed, 319 insertions(+), 15 deletions(-) create mode 100644 lfvetau/computeEmbeddedPeakScaleFactor.py create mode 100644 lfvetau/computeyields.py diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index 60786f8f..48e93509 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -189,13 +189,13 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): 'type' : 'shape', '+' : lambda x: os.path.join('tes_plus', x)+'_tes_plus' , '-' : lambda x: os.path.join('tes_minus', x)+'_tes_minus' , - 'apply_to' : ['fullsimbkg'], + 'apply_to' : ['simbkg'], }, 'EES' : { 'type' : 'shape', '+' : lambda x: os.path.join('ees_plus', x) +'_ees_plus' , '-' : lambda x: os.path.join('ees_minus', x)+'_ees_minus' , - 'apply_to' : ['fullsimbkg'], + 'apply_to' : ['simbkg'], }, 'UES' : { 'type' : 'shape', @@ -900,7 +900,7 @@ def plot_without_uncert (self, folder, variable, rebin=1, xaxis='', if show_ratio: self.add_ratio_diff(data, mc_stack, finalhisto, xrange, ratio_range) - def write_shapes(self, folder, variable, output_dir, br_strenght=0.01, + def write_shapes(self, folder, variable, output_dir, br_strenght=1, rebin=1, preprocess=None): #, systematics): '''Makes shapes for computing the limit and returns a list of systematic effects to be added to unc.vals/conf make_shapes(folder, variable, output_dir, [rebin=1, preprocess=None) --> unc_conf_lines (list), unc_vals_lines (list) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index c591e030..6003b477 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -136,8 +136,8 @@ def __init__(self, tree, outfile, **kwargs): 'tvetos': (['', 'tVetoUp', 'tVetoDown'] if self.is_mc else ['']), 'evetos': (['', 'eVetoUp', 'eVetoDown'] if self.is_mc else ['']), 'met' : (["_mes_plus", "_ues_plus", "_mes_minus", "_ues_minus"] if self.is_mc else []), - 'tes' : (["", "_tes_plus", "_tes_minus"] if self.is_mc else ['']), - 'ees' : (["", "_ees_plus", '_ees_minus'] if self.is_mc else ['']) + 'tes' : (["", "_tes_plus", "_tes_minus"] if not self.is_data else ['']), + 'ees' : (["", "_ees_plus", '_ees_minus'] if not self.is_data else ['']) } #self filling histograms @@ -176,6 +176,7 @@ def __init__(self, tree, outfile, **kwargs): #patch name postfix = shift self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + #PU correctors self.pucorrector = mcCorrections.make_shifted_weights( @@ -259,13 +260,13 @@ def book_with_sys(location, name, *args, **kwargs): self.book('os/gg/ept30/', "e_t_Mass", "h_vismass", 32, 0, 320) for f in folder: - self.book( - f, - 'evtInfo', 'evtInfo', - 'run/l:lumi/l:evt/l:weight/D', - type=pytree.PyTree - ) - + #self.book( + # f, + # 'evtInfo', 'evtInfo', + # 'run/l:lumi/l:evt/l:weight/D', + # type=pytree.PyTree + #) + self.book(f,"weight", "weight", 100, 0, 10) self.book(f,"tPt", "tau p_{T}", 40, 0, 200) self.book(f,"tPt_tes_plus", "tau p_{T} (tes+)", 40, 0, 200) self.book(f,"tPt_tes_minus", "tau p_{T} (tes-)",40, 0, 200) diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index 19193181..50f25239 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -329,9 +329,9 @@ task :genkinEMu => get_analyzer_results("LFVHAnalyzeGENEMu.py", samples['signalM task :recoplots => get_analyzer_results("LFVHETauAnalyzer.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'])# + samples['dataSingleE'] ) -task :recoplotsMVA => get_analyzer_results("LFVHETauAnalyzerMVA.py", samples['signalMCgg']# + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + - #samples['Zembedded']+ - #samples['dataSingleE'] +task :recoplotsMVA => get_analyzer_results("LFVHETauAnalyzerMVA.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + + samples['Zembedded']+ + samples['dataSingleE'] ) task :recoplotsMVAeMtcut => get_analyzer_results("LFVHETauAnalyzerMVA_eMTCut.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + diff --git a/lfvetau/computeEmbeddedPeakScaleFactor.py b/lfvetau/computeEmbeddedPeakScaleFactor.py new file mode 100644 index 00000000..a5df2ef7 --- /dev/null +++ b/lfvetau/computeEmbeddedPeakScaleFactor.py @@ -0,0 +1,153 @@ +from FinalStateAnalysis.Utilities.rootbindings import ROOT +import math +import logging +import sys + +ROOT.gStyle.SetOptStat(0) +ROOT.gStyle.SetOptTitle(0) +ROOT.gROOT.SetBatch() + +file_dataA = ROOT.TFile('results/newNtuple_5Nov/LFVHETauAnalyzerMVA/ZetauEmbedded_Run2012A.root') +file_dataB = ROOT.TFile('results/newNtuple_5Nov/LFVHETauAnalyzerMVA/ZetauEmbedded_Run2012B.root') +file_dataC = ROOT.TFile('results/newNtuple_5Nov/LFVHETauAnalyzerMVA/ZetauEmbedded_Run2012C.root') +file_dataD = ROOT.TFile('results/newNtuple_5Nov/LFVHETauAnalyzerMVA/ZetauEmbedded_Run2012D.root') + +dataA=file_dataA.Get('os/gg/ept30/h_collmass_pfmet') +dataB=file_dataB.Get('os/gg/ept30/h_collmass_pfmet') +dataC=file_dataC.Get('os/gg/ept30/h_collmass_pfmet') +dataD=file_dataD.Get('os/gg/ept30/h_collmass_pfmet') + +data=dataC.Clone() +data.Add(dataB) +data.Add(dataA) +data.Add(dataD) + +c= ROOT.TCanvas("c","c", 800, 1000) +c.Draw() +c.SetGridx(1) +c.SetGridy(1) + + +njets=[0,1,2,3,4] + +file_MC0 = ROOT.TFile('results/newNtuple_5Nov/LFVHETauAnalyzerMVA/Z0jets_M50_skimmedTT.root') +file_MC1 = ROOT.TFile('results/newNtuple_5Nov/LFVHETauAnalyzerMVA/Z1jets_M50_skimmedTT.root') +file_MC2 = ROOT.TFile('results/newNtuple_5Nov/LFVHETauAnalyzerMVA/Z2jets_M50_skimmedTT.root') +file_MC3 = ROOT.TFile('results/newNtuple_5Nov/LFVHETauAnalyzerMVA/Z3jets_M50_skimmedTT.root') +file_MC4 = ROOT.TFile('results/newNtuple_5Nov/LFVHETauAnalyzerMVA/Z4jets_M50_skimmedTT.root') + +mc0 = file_MC0.Get('os/gg/ept30/h_collmass_pfmet') +mc1 = file_MC1.Get('os/gg/ept30/h_collmass_pfmet') +mc2 = file_MC2.Get('os/gg/ept30/h_collmass_pfmet') +mc3 = file_MC3.Get('os/gg/ept30/h_collmass_pfmet') +mc4 = file_MC4.Get('os/gg/ept30/h_collmass_pfmet') + +datalumi = 0 +#for i in ['A', 'B', 'C', 'D'] : +for i in ['C', 'D'] : + lumifile = 'inputs/newNtuple_5Nov/data_SingleElectron_Run2012%s_22Jan2013_v1.lumicalc.sum' %(i) + f = open(lumifile, 'r') + lumistring = f.readline() + datalumi += float(lumistring) + + +mc_lumi=[] + +for i in range(0,5): + + lumifile = 'inputs/newNtuple_5Nov/Z%sjets_M50_skimmedTT.lumicalc.sum' %(str(int(i))) + f = open(lumifile, 'r') + lumistring = f.readline() + mc_lumi.append(float(lumistring)) + +mc=mc0.Clone() +mc.Scale(datalumi/mc_lumi[0]) +mc.Add(mc1, datalumi/mc_lumi[1]) +mc.Add(mc2, datalumi/mc_lumi[2]) +mc.Add(mc3, datalumi/mc_lumi[3]) +mc.Add(mc4, datalumi/mc_lumi[4]) +mc.SetMarkerStyle(20) +mc.SetMarkerColor(4) +mc.SetLineColor(4) + +data.Scale(mc.Integral()/data.Integral() ) + +max_data = data.GetBinContent(data.GetMaximumBin()) +max_mc = mc.GetBinContent(mc.GetMaximumBin()) +mc.Draw() +data.SetMarkerStyle(20) +data.SetMarkerColor(2) +data.SetLineColor(2) +data.Draw() + +m = ROOT.RooRealVar('m', 'Collinear Mass', 90,40,250) +os_data = ROOT.RooDataHist('z_data','z_data',ROOT.RooArgList(m),data) +os_mc = ROOT.RooDataHist('z_mc','z_mc',ROOT.RooArgList(m),mc) +mean = ROOT.RooRealVar('mean', 'mean', 90,70,110) +sigmaL = ROOT.RooRealVar('sigmaL' ,'sigmaL' ,10 ,0 ,100) +sigmaR = ROOT.RooRealVar('sigmaR' ,'sigmaR' ,10 ,0 ,100) +alphaL = ROOT.RooRealVar('alphaL' ,'alphaL' ,1 ,0 ,30 ) +alphaR = ROOT.RooRealVar('alphaR' ,'alphaR' ,1 ,0 ,30 ) +command = ROOT.RooCruijff("os_func", "os_func",m, mean, sigmaL, sigmaR, alphaL, alphaR) + + +frame = m.frame(ROOT.RooFit.Title("Z mass peak")) + +fit_result_mc = command.fitTo( + os_mc, + ROOT.RooFit.Save(True)) + +os_mc.plotOn( + frame,ROOT.RooFit.LineColor(ROOT.EColor.kBlue),ROOT.RooFit.MarkerColor(ROOT.EColor.kBlue) +) +mcpeak = mean.getVal() +mcpeakerr = mean.getError() + +command.plotOn(frame,#ROOT.RooFit.VisualizeError(fit_result_mc,1), + ROOT.RooFit.LineColor(ROOT.EColor.kBlue)) + +leg = ROOT.TLegend(0.5,0.8,0.85,0.7) + + +print '____________________' + +fit_result = command.fitTo( + os_data, + ROOT.RooFit.Save(True)) +os_data.plotOn(frame,ROOT.RooFit.LineColor(ROOT.EColor.kRed),ROOT.RooFit.MarkerColor(ROOT.EColor.kRed) ) +command.plotOn(frame,ROOT.RooFit.LineColor(ROOT.EColor.kRed)) +datapeak = mean.getVal() +datapeakerr= mean.getError() +print 'datapeak : %f +/- %f, mcpeak: %f +/- %f' %(datapeak,datapeakerr, mcpeak, mcpeakerr ) + +leg.AddEntry(mc, "DY->#tau#tau (MC)", "lp") +leg.AddEntry(data, "DY->#tau#tau (embedded)", "lp") + +pt = ROOT.TPaveText(0.5, 0.5, 0.85, 0.65) +pt.AddText("MC peak: %.2f #pm %.2f GeV" %(mcpeak, mcpeakerr)) +pt.AddText("Emb peak: %.2f #pm %.2f GeV" %(datapeak, datapeakerr)) + +frame.addObject(pt) + +#text = ROOT.TText(124.5,1400, 'MC peak: %.2f #pm %.2f GeV' %(mcpeak, mcpeakerr)) +#text2 = ROOT.TText(120, 1300, 'Emb peak: %.2f #pm %.2f GeV'%(datapeak, datapeakerr)) +#text.SetTextSize(0.03) +#text.SetTextColor(4) +#text2.SetTextSize(0.03) +#frame.addObject(text) +#text2.SetTextColor(2) +#frame.addObject(text2) +leg.SetFillColor(0) +frame.addObject(leg) +frame.Draw() +#pt.AddText(text) +#pt.AddText(text2) +#Leg.Draw() +#leg.SetFillColor(0) +pt.SetFillColor(0) +pt.SetShadowColor(0) +pt.Paint() + +c.Update() +c.SaveAs('Zfit.pdf') +c.SaveAs('Zfit.png') diff --git a/lfvetau/computeyields.py b/lfvetau/computeyields.py new file mode 100644 index 00000000..e8c4c1d9 --- /dev/null +++ b/lfvetau/computeyields.py @@ -0,0 +1,150 @@ +import ROOT +import sys +import os +import math + +try: + massrange = sys.argv[1].split(',') + print massrange +except: + + print 'please give me the mass range in the format 50,300 ' + +ROOT.gROOT.SetBatch() # don't pop up canvases + +ROOT.gROOT.SetStyle('Plain') # white background +ROOT.gStyle.SetOptStat(0) + +samples = [ + "zjetsother", + "diboson", + "SMVBF126", + "singlet", + "SMGG126", + "ttbar", + "ztautau", + "fakes", + "LFVGG", + "LFVVBF" +] + +names = { + "zjetsother" : "zjetsother", + "diboson" : "diboson" , + "SMVBF126" : "SMH" , + "SMGG126" : "SMH" , + "singlet" : "singlet" , + "ttbar" : "ttbar" , + "ztautau" : "ztautau" , + "fakes" : "fakes" , + "LFVGG" : "LFVH" , + "LFVVBF" : "LFVH" +} + + +mymapper ={ + "fakes" : ["Fakes "], + "ztautau" : ["$ Z \\rightarrow \\tau\\tau$ "], + "diboson" : ["EWK Diboson "], + "zjetsother" : ["$Z \\rightarrow ee, \\mu\\mu$"], + "ttbar" : ["$t\\bar{t}$ "], + "singlet" : ["$t$, $\\bar{t}$ "], + "SMH" : ["SM Higgs Background "], + "tot" : ["Sum of Backgrounds "], + "LFVH" : ["LFV Higgs Signal "], +} + + + + +for jet in range (0, 3) : + + #norm_file = 'plots/newNtuple_5Nov/lfvet/unc.%s.vals' %(str(jet)) + #f = open(norm_file, 'r') + #lines= f.readlines() + #for line in lines : + # norm= line.split() + # print jet, norm, norm[1].split(',') + + + #print jet + file1 = ROOT.TFile.Open('plots/newNtuple_5Nov/lfvet/shapes.%s.root' %(str(jet))) + #print 'plots/newNtuple_5Nov/lfvet/shapes.%s.root' %(str(jet)) + #print file1.GetListOfKeys()[0].GetName() + mydir = file1.Get(file1.GetListOfKeys()[0].GetName()) + mylist=mydir.GetListOfKeys() + totbackground =0. + totbackgrounderr2=0. + for sample in samples: + #print sample + histo = mydir.Get(sample) + sublist = filter(lambda x : sample in x.GetName() and sample != x.GetName(), mylist) + + integral = 0 + err2=0 + + for i in range(histo.GetXaxis().FindBin(float(massrange[0])), histo.GetXaxis().FindBin(float(massrange[1]))+1): + integral += histo.GetBinContent(i) + err2 += histo.GetBinError(i)*histo.GetBinError(i) + if integral != 0: + print sample, integral, math.sqrt(err2), math.sqrt(err2)/integral + else: + print sample, integral, math.sqrt(err2) + + for histname in sublist: + #print 'histo name', histname.GetName() + systHistInt=0. + h = mydir.Get(histname.GetName()).Clone() + #print histo.Integral(), h.Integral() + for i in range(histo.GetXaxis().FindBin(float(massrange[0])), histo.GetXaxis().FindBin(float(massrange[1]))+1): + systHistInt+=pow(h.GetBinContent(i) - histo.GetBinContent(i), 2) + #print sample, h.GetBinContent(i) , histo.GetBinContent(i), h.GetBinContent(i) - histo.GetBinContent(i) + #print histname.GetName(), systHistInt + #print systHistInt, integral + err2+= systHistInt + + + + #print histo.FindBin(float(massrange[0])), histo.FindBin(float(massrange[1])), histo.GetXaxis().GetNbins() + + if integral != 0: + print sample, integral, math.sqrt(err2), math.sqrt(err2)/integral + else: + print sample, integral, math.sqrt(err2), + + if not 'LFV' in sample: + totbackground += integral + totbackgrounderr2 += err2 + #print totbackground, totbackgrounderr2 + + try: + print mymapper[names[sample]][1+3*jet],mymapper[names[sample]][3+3*jet] + mymapper[names[sample]][1+3*jet]=float(mymapper[names[sample]][1+3*jet]) + integral + mymapper[names[sample]][3+3*jet]=math.sqrt(pow(float(mymapper[names[sample]][3+3*jet]),2) + err2) + + except: + mymapper[names[sample]].extend([ integral, "$\pm$" , math.sqrt(err2)]) + + print 'tot', totbackground, math.sqrt(totbackgrounderr2) + mylist = ["%.2f" % totbackground, "$\pm$" , "%.2f" % math.sqrt(totbackgrounderr2)] + mymapper["tot"].extend(mylist) + + #error=ROOT.Double() + #print histo.IntegralAndError(histo.FindBin(float(massrange[0])), histo.FindBin(float(massrange[1])), error), error + +for k,v in mymapper.iteritems(): + for n,obj in enumerate(v) : + if isinstance(obj, float): mymapper[k][n]=str('%.2f' %obj) + +outfile = open('yields_MassRange_%s_%s.tex' %(str(massrange[0]),str(massrange[1])) ,'w') +outfile.write('\\begin{table}[h] \n') +outfile.write('\\begin{tabular}{|c|rcl|rcl|rcl|}\n') + +for k,v in mymapper.iteritems(): + print ' & '.join(v)+'\\\\\\hline\n' + outfile.write(' & '.join(v)+'\\\\\n') + +outfile.write('\\end{tabular}\n') +outfile.write('\\end{table}\n') + +outfile.close() From 2a94998da9ac118dede17e16430dd405de7e4710 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Sun, 30 Nov 2014 04:19:24 -0600 Subject: [PATCH 170/192] add the option to plot the data or not --- lfvetau/BasePlotter.py | 42 ++++++++++++++++++++------------ lfvetau/plotRecoQuantitiesMVA.py | 36 +++++++++++++-------------- 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index af694d2d..f59685a2 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -586,7 +586,7 @@ def add_histo_error(self, histo, histoerr): def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', leftside=True, xrange=None, preprocess=None, - show_ratio=False, ratio_range=0.2, sort=True, obj=['e1', 'e2']): + show_ratio=False, ratio_range=0.2, sort=True, obj=['e1', 'e2'], plot_data=False): #xsection uncertainties @@ -795,33 +795,43 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', 'ggHiggsToETau', 'vbfHiggsToETau', ] + sig = [] for name in signals: sig_view = self.get_view(name) if preprocess: sig_view = preprocess(sig_view) sig_view = RebinView(sig_view, rebin) + sig_view = views.ScaleView(sig_view, 100) histogram = sig_view.Get(path) histogram.Draw('same') self.keep.append(histogram) + sig.append(histogram) + for lfvh in sig: + if lfvh.GetMaximum() > mc_stack.GetMaximum(): + mc_stack.SetMaximum(1.2*lfvh.GetMaximum()) + + if plot_data==True: + # Draw data + data_view = self.get_view('data') + if preprocess: + data_view = preprocess( data_view ) + data_view = self.rebin_view(data_view, rebin) + data = data_view.Get(path) - # Draw data - data_view = self.get_view('data') - if preprocess: - data_view = preprocess( data_view ) - data_view = self.rebin_view(data_view, rebin) - data = data_view.Get(path) - - data.Draw('same') - print 'data', data.Integral() - self.keep.append(data) + data.Draw('same') + print 'data', data.Integral() + self.keep.append(data) - ## Make sure we can see everything - if data.GetMaximum() > mc_stack.GetMaximum(): - mc_stack.SetMaximum(1.2*data.GetMaximum()) + ## Make sure we can see everything + if data.GetMaximum() > mc_stack.GetMaximum(): + mc_stack.SetMaximum(1.2*data.GetMaximum()) - self.add_legend([data, mc_stack], leftside, entries=len(mc_stack.GetHists())+1) - if show_ratio: + if plot_data: + self.add_legend([data, mc_stack], leftside, entries=len(mc_stack.GetHists())+1) + else: + self.add_legend([sig[0], sig[1], mc_stack], leftside, entries=len(mc_stack.GetHists())+1) + if show_ratio and plot_data: self.add_ratio_plot(data, mc_err, xrange, ratio_range, True) # add_ratio_diff(data, mc_stack, mc_err, xrange, ratio_range) #self.add_ratio_plot(data, mc_stack, xrange, ratio_range, True) # add_ratio_diff(data, mc_stack, mc_err, xrange, ratio_range) diff --git a/lfvetau/plotRecoQuantitiesMVA.py b/lfvetau/plotRecoQuantitiesMVA.py index e0e3c093..6823733c 100644 --- a/lfvetau/plotRecoQuantitiesMVA.py +++ b/lfvetau/plotRecoQuantitiesMVA.py @@ -83,29 +83,29 @@ elif not 'Eta' in var and not 'jet' in var: rebin = rebin*2 - plotter.plot_with_bkg_uncert(path, var, rebin, xlabel, - leftside=False, show_ratio=True, ratio_range=1., - sort=True, obj=['e']) + plotter.plot_with_bkg_uncert(path, var, rebin, xlabel, + leftside=False, show_ratio=True, ratio_range=1., + sort=True, obj=['e'], data=True) - plotter.save(var) + plotter.save(var) - plotter.set_subdir(os.path.join('embedded', path+'/selected'))if embedded else plotter.set_subdir(path+'/selected') - - for var, xlabel, rebin in histo_info: - if int(njet)==1: - if not 'Eta' in var and not 'jet' in var: rebin = rebin*2 - if int(njet) ==2: - if 'collmass' in var or 'Mass' in var: rebin=rebin*5 - if 'Pt' in var or 'Mt' in var or 'pfMet' in var : rebin=rebin*4 - logging.debug("Plotting %s/%s" % (path, var) ) - plotter.pad.SetLogy(False) - plotter.plot_with_bkg_uncert(path+'/selected', var, rebin, xlabel, - leftside=False, show_ratio=True, ratio_range=1., - sort=True, obj=['e']) + plotter.set_subdir(os.path.join('embedded', path+'/selected'))if embedded else plotter.set_subdir(path+'/selected') + + for var, xlabel, rebin in histo_info: + if int(njet)==1: + if not 'Eta' in var and not 'jet' in var: rebin = rebin*2 + if int(njet) ==2: + if 'collmass' in var or 'Mass' in var: rebin=rebin*5 + if 'Pt' in var or 'Mt' in var or 'pfMet' in var : rebin=rebin*4 + logging.debug("Plotting %s/%s" % (path, var) ) + plotter.pad.SetLogy(False) + plotter.plot_with_bkg_uncert(path+'/selected', var, rebin, xlabel, + leftside=False, show_ratio=True, ratio_range=1., + sort=True, obj=['e'], plot_data=True) - plotter.save(var,dotroot=False) + plotter.save(var,dotroot=False) #make shapes for limit setting if not args.no_shapes: From 21fd3c7e3454951a8766e4190e5f5da6c53b5570 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Mon, 1 Dec 2014 02:30:09 -0600 Subject: [PATCH 171/192] bugfix --- lfvetau/card_config/unc.0.vals | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/lfvetau/card_config/unc.0.vals b/lfvetau/card_config/unc.0.vals index 996ee635..a27143d8 100755 --- a/lfvetau/card_config/unc.0.vals +++ b/lfvetau/card_config/unc.0.vals @@ -1,26 +1,24 @@ -gg0mutau gghiggs Theo_PDF_gg 1.097 -gg0mutau vbfhiggs Theo_PDF_vbf 1.036 +gg0etau gghiggs Theo_PDF_gg 1.097 +gg0etau vbfhiggs Theo_PDF_vbf 1.036 -gg0mutau gghiggs Theo_UE 1.04 -gg0mutau vbfhiggs Theo_UE 1.1 +gg0etau gghiggs Theo_UE 1.04 +gg0etau vbfhiggs Theo_UE 1.1 -gg0mutau gghiggs Theo_Scale_gg 1.08 -gg0mutau vbfhiggs Theo_Scale_vbf 1.04 +gg0etau gghiggs Theo_Scale_gg 1.08 +gg0etau vbfhiggs Theo_Scale_vbf 1.04 -gg0mutau ztautau Norm_ZTauTau 1.03 -gg0mutau ztautau Norm_ZTauTau_et_0Jet_extra 1.05 -gg0mutau zjetsother Norm_ZJetsOther 1.3 +gg0etau ztautau Norm_ZTauTau 1.03 +gg0etau ztautau Norm_ZTauTau_et_0Jet_extra 1.05 +gg0etau zjetsother Norm_ZJetsOther 1.3 #TODO: check eff electron -gg0mutau simulated lumi 1.026 -#gg0mutau simulated Effi_E 1.02 -gg0mutau simulated Effi_et_Tau 1.06 -gg0mutau simulated Effi_et_Tau_highPt 1.03 +gg0etau simulated lumi 1.026 +gg0etau simulated Effi_et_Tau 1.06 +gg0etau simulated Effi_et_Tau_highPt 1.03 -gg0mutau diboson Norm_DIBOSON 1.15 -gg0mutau singlet Norm_TOP 1.10 -gg0mutau ttbar Norm_TT 1.10 -gg0mutau fakes Norm_FAKES 1.30 +gg0etau diboson Norm_DIBOSON 1.15 +gg0etau singlet Norm_TOP 1.10 +gg0etau ttbar Norm_TT 1.10 +gg0etau fakes Norm_FAKES 1.30 -#gg0mutau signal,ztautau,SMVBF126,SMGG126 shape_MuTau_TES 1 From 5df04adb5e63fe0743ae2ddd544091047e58e856 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Wed, 10 Dec 2014 07:33:48 -0600 Subject: [PATCH 172/192] new set of cuts --- lfvetau/BasePlotter.py | 205 +++++++++- lfvetau/EmbeddedCheck.py | 623 +++++++++++++++++++++++++++++++ lfvetau/FakeTauControlRegion.py | 172 +++++++++ lfvetau/LFVHETauAnalyzerMVA.py | 24 +- lfvetau/TTbarControlRegion.py | 623 +++++++++++++++++++++++++++++++ lfvetau/baseSelections.py | 21 ++ lfvetau/mcCorrections.py | 1 + lfvetau/produceShapeForYields.py | 71 ++++ 8 files changed, 1718 insertions(+), 22 deletions(-) create mode 100644 lfvetau/EmbeddedCheck.py create mode 100644 lfvetau/FakeTauControlRegion.py create mode 100644 lfvetau/TTbarControlRegion.py create mode 100644 lfvetau/produceShapeForYields.py diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index f59685a2..1035b216 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -109,9 +109,13 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): print "\nPlotting e tau for %s\n" % jobid files = glob.glob('results/%s/LFVHETauAnalyzerMVA/*.root' % jobid) + #files = glob.glob('results/%s/EmbeddedCheck/*.root' % jobid) + #files = glob.glob('results/%s/TTbarControlRegion/*.root' % jobid) lumifiles = glob.glob('inputs/%s/*.lumicalc.sum' % jobid) outputdir = 'plots/%s/lfvet' % jobid + #outputdir = 'plots/%s/EmbeddedCheck' % jobid + #outputdir = 'plots/%s/TTBar' % jobid if not os.path.exists(outputdir): os.makedirs(outputdir) @@ -132,7 +136,12 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): '[WZ][WZ]Jets', #'Wplus*Jets_madgraph*', #superseded by fakes 'Z*jets_M50_skimmedLL', + #'WH*HToTauTau', + #'WH*HToWW', + #'vbfHWW', + #'ggHWW', 'Z*jets_M50_skimmedTT' + ] if use_embedded: @@ -158,19 +167,23 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): 'Z*jets_M50_skimmedLL' : 'zjetsother', 'missing1' : 'WWVBF126', 'missing2' : 'WWGG126', +# 'vbfHWW' : 'WWVBF126', +# 'ggHWW' : 'WWGG126', 'ggHiggsToETau' : 'LFVGG', 'vbfHiggsToETau' : 'LFVVBF', 'fakes' : 'fakes', +# 'WH*HToTauTau' : 'VHtautau' , #"VHtautau", +# 'WH*HToWW' : 'VHWW' , #"VHWW", ##'efakes' : 'efakes', ##'etfakes' : 'etfakes' } self.sample_groups = {#parse_cgs_groups('card_config/cgs.0.conf') 'fullsimbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', - 'diboson', 'zjetsother'], #, 'WWVBF126', 'WWGG126',], + 'diboson', 'zjetsother'],# 'WWVBF126', 'WWGG126','VHWW','VHtautau'], 'simbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', 'ztautau', - 'diboson', 'zjetsother'], #'WWVBF126', 'WWGG126',] - 'realtau' : ['ztautau', 'SMGG126', 'SMVBF126'], + 'diboson', 'zjetsother'],#'WWVBF126', 'WWGG126','VHWW','VHtautau'], + 'realtau' : ['ztautau', 'SMGG126', 'SMVBF126'],# 'VHtautau'], } self.systematics = { @@ -801,7 +814,8 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', if preprocess: sig_view = preprocess(sig_view) sig_view = RebinView(sig_view, rebin) - sig_view = views.ScaleView(sig_view, 100) + if not plot_data: + sig_view = views.ScaleView(sig_view, 100) histogram = sig_view.Get(path) histogram.Draw('same') @@ -1021,11 +1035,14 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, integral = central.Integral() integral_up = up.Integral() integral_down = down.Integral() - shift = max( - shift, - (integral_up - integral) / integral, - (integral - integral_down) / integral - ) + if integral == 0 and integral_up == 0 and integral_down ==0 : + shift=shift + else: + shift = max( + shift, + (integral_up - integral) / integral, + (integral - integral_down) / integral + ) elif info['type'] == 'shape': #remove empty bins also for shapes #(but not in general to not spoil the stat uncertainties) @@ -1040,7 +1057,175 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, up.Rebin(nbins) yield_val = up.GetBinContent(1) yield_err = up.GetBinError(1) - unc_value = 1. + (yield_err / yield_val) + print target, yield_val, yield_err, + if yield_val==0: + unc_value = 0. + else: + unc_value = 1. + (yield_err / yield_val) + stat_unc_name = '%s_%s_%s' % (target, category_name, unc_name) + unc_conf_lines.append('%s %s' % (stat_unc_name, unc_conf)) + unc_vals_lines.append( + '%s %s %s %.2f' % (category_name, target, stat_unc_name, unc_value) + ) + else: + raise ValueError('systematic uncertainty type:"%s" not recognised!' % info['type']) + + if info['type'] <> 'stat': + shift += 1 + unc_vals_lines.append( + '%s %s %s %.2f' % (category_name, ','.join(targets), unc_name, shift) + ) + + #Get signal + signals = [ + 'ggHiggsToETau', + 'vbfHiggsToETau', + ] + for name in signals: + sig_view = self.get_view(name) + if preprocess: + sig_view = preprocess(sig_view) + sig_view = views.ScaleView( + RebinView(sig_view, rebin), + br_strenght + ) + + histogram = sig_view.Get(path) + histogram.SetName(self.datacard_names[name]) + histogram.Write() + + # Draw data + data_view = self.get_view('data') + if preprocess: + data_view = preprocess( data_view ) + data_view = self.rebin_view(data_view, rebin) + data = data_view.Get(path) + data.SetName('data_obs') + data.Write() + + return unc_conf_lines, unc_vals_lines + +##----- + + def write_shapes_for_yields(self, folder, variable, output_dir, br_strenght=1, + rebin=1, preprocess=None): #, systematics): + '''Makes shapes for computing the limit and returns a list of systematic effects to be added to unc.vals/conf + make_shapes(folder, variable, output_dir, [rebin=1, preprocess=None) --> unc_conf_lines (list), unc_vals_lines (list) + ''' + output_dir.cd() + path = os.path.join(folder,variable) + + #make MC views with xsec error + bkg_views = dict( + [(self.datacard_names[i], j) for i, j in zip(self.mc_samples, self.mc_views(rebin, preprocess))] + ) + bkg_weights = dict( + [(self.datacard_names[i], self.get_view(i, 'weight')) for i in self.mc_samples] + ) + #cache histograms, since getting them is time consuming + bkg_histos = {} + for name, view in bkg_views.iteritems(): + mc_histo = view.Get(path) + bkg_histos[name] = mc_histo.Clone() + #mc_histo = remove_empty_bins( + # mc_histo, bkg_weights[name]) + mc_histo.SetName(name) + mc_histo.Write() + + if self.use_embedded: + view = self.get_view('ZetauEmbedded') + weight = self.get_view('ZetauEmbedded', 'weight') + if preprocess: + view = preprocess(view) + view = self.rebin_view(view, rebin) + name = self.datacard_names['ZetauEmbedded'] + bkg_weights[name] = weight + bkg_views[name] = view + mc_histo = view.Get(path) + bkg_histos[name] = mc_histo.Clone() + #mc_histo = remove_empty_bins( + # mc_histo, weight) + mc_histo.SetName(name) + mc_histo.Write() + + fakes_view = self.get_view('fakes') + d_view = self.get_view('data') + weights_view = views.SumView( + views.SubdirectoryView(d_view, 'tLoose'), + views.SubdirectoryView(d_view, 'eLoose'), + views.SubdirectoryView(d_view, 'etLoose') + ) + if preprocess: + fakes_view = preprocess(fakes_view) + weights_view = preprocess(weights_view) + weights = weights_view.Get(os.path.join(folder,'weight')) + fakes_view = self.rebin_view(fakes_view, rebin) + bkg_views['fakes'] = fakes_view + bkg_weights['fakes'] = mean(weights) + fake_shape = bkg_views['fakes'].Get(path) + bkg_histos['fakes'] = fake_shape.Clone() + #fake_shape = remove_empty_bins( + # fake_shape, bkg_weights['fakes']) + fake_shape.SetName('fakes') + fake_shape.Write() + + unc_conf_lines = [] + unc_vals_lines = [] + category_name = output_dir.GetName() + for unc_name, info in self.systematics.iteritems(): + targets = [] + for target in info['apply_to']: + if target in self.sample_groups: + targets.extend(self.sample_groups[target]) + else: + targets.append(target) + + unc_conf = 'lnN' if info['type'] == 'yield' or info['type'] == 'stat' else 'shape' + #stat shapes are uncorrelated between samples + if info['type'] <> 'stat': + unc_conf_lines.append('%s %s' % (unc_name, unc_conf)) + shift = 0. + path_up = info['+'](path) + path_dw = info['-'](path) + for target in targets: + up = bkg_views[target].Get( + path_up + ) + down = bkg_views[target].Get( + path_dw + ) + if info['type'] == 'yield': + central = bkg_histos[target] + integral = central.Integral() + integral_up = up.Integral() + integral_down = down.Integral() + if integral == 0 and integral_up == 0 and integral_down ==0 : + shift=shift + else: + shift = max( + shift, + (integral_up - integral) / integral, + (integral - integral_down) / integral + ) + elif info['type'] == 'shape': + #remove empty bins also for shapes + #(but not in general to not spoil the stat uncertainties) + #up = remove_empty_bins(up, bkg_weights[target]) + #down = remove_empty_bins(down, bkg_weights[target]) + up.SetName('%s_%sUp' % (target, unc_name)) + down.SetName('%s_%sDown' % (target, unc_name)) + up.Write() + down.Write() + elif info['type'] == 'stat': + nbins = up.GetNbinsX() + up.Rebin(nbins) + yield_val = up.GetBinContent(1) + yield_err = up.GetBinError(1) + print target, yield_val, yield_err, + if yield_val==0: + unc_value = 0. + else: + unc_value = 1. + (yield_err / yield_val) stat_unc_name = '%s_%s_%s' % (target, category_name, unc_name) unc_conf_lines.append('%s %s' % (stat_unc_name, unc_conf)) unc_vals_lines.append( diff --git a/lfvetau/EmbeddedCheck.py b/lfvetau/EmbeddedCheck.py new file mode 100644 index 00000000..96bec627 --- /dev/null +++ b/lfvetau/EmbeddedCheck.py @@ -0,0 +1,623 @@ +from ETauTree import ETauTree +import sys +import logging +logging.basicConfig(stream=sys.stderr, level=logging.WARNING) +import os +from pdb import set_trace +import ROOT +import math +import glob +import array +import mcCorrections +import baseSelections as selections +import FinalStateAnalysis.PlotTools.pytree as pytree +from FinalStateAnalysis.PlotTools.decorators import memo_last +from FinalStateAnalysis.PlotTools.MegaBase import MegaBase +from math import sqrt, pi, cos +from fakerate_functions import tau_fake_rate, tau_fake_rate_up, tau_fake_rate_dw, e_fake_rate, e_fake_rate_up, e_fake_rate_dw +import itertools +import traceback +from FinalStateAnalysis.PlotTools.decorators import memo +import FinalStateAnalysis.PlotTools.pytree as pytree +from FinalStateAnalysis.Utilities.struct import struct + +@memo +def getVar(name, var): + return name+var + +met_et = 'pfMet_Et%s' +met_phi = 'pfMet_Phi%s' +t_pt = 'tPt%s' +etMass = 'e_t_Mass%s' +@memo +def met(shift=''): + return met_et % shift + +@memo +def metphi(shift=''): + return met_phi % shift +@memo +def tpt(shift=''): + return t_pt % shift + +@memo +def vismass(shift=''): + return etMass % shift + +@memo +def split(string, separator='#'): + return tuple(attr.split(separator)) + +def create_mapper(mapping): + def _f(path): + for key, out in mapping.iteritems(): + if key == path: + path = path.replace(key,out) + print 'path', path + return path + return _f + +def attr_getter(attribute): + '''return a function that gets an attribute''' + def f(row, weight): + return (getattr(row,attribute), weight) + return f + +def merge_functions(fcn_1, fcn_2): + '''merges two functions to become a TH2''' + def f(row, weight): + r1, w1 = fcn_1(row, weight) + r2, w2 = fcn_2(row, weight) + w = w1 if w1 and w2 else None + return ((r1, r2), w) + return f + +def collmass(row, met, metPhi): + ptnu =abs(met*cos(deltaPhi(metPhi, row.tPhi))) + visfrac = row.tPt/(row.tPt+ptnu) + #print met, cos(deltaPhi(metPhi, row.tPhi)), ptnu, visfrac + return (row.e_t_Mass / sqrt(visfrac)) + +def deltaPhi(phi1, phi2): + PHI = abs(phi1-phi2) + if PHI<=pi: + return PHI + else: + return 2*pi-PHI + +def deltaR(phi1, ph2, eta1, eta2): + deta = eta1 - eta2 + dphi = abs(phi1-phi2) + if (dphi>pi) : dphi = 2*pi-dphi + return sqrt(deta*deta + dphi*dphi); + +def make_collmass_systematics(shift): + if shift.startswith('tes'): + ptnu =abs(met*cos(deltaPhi(metPhi, row.tPhi))) + visfrac = tpt/(tpt+ptnu) + vis_mass = vismass(shift) + return (vis_mass / sqrt(visfrac)) + else: + met_name = met(shift) + phi_name = metphi(shift) + def collmass_shifted(row, weight): + met = getattr(row, met_name) + phi = getattr(row, phi_name) + return collmass(row, met, phi), weight + return collmass_shifted + +class EmbeddedCheck(MegaBase): + tree = 'et/final/Ntuple' + def __init__(self, tree, outfile, **kwargs): + logging.debug('EmbeddedCheck constructor') + self.channel='ET' + super(EmbeddedCheck, self).__init__(tree, outfile, **kwargs) + self.tree = ETauTree(tree) + self.out=outfile + self.histograms = {} + + #understand what we are running + target = os.path.basename(os.environ['megatarget']) + self.is_data = target.startswith('data_') + self.is_embedded = ('Embedded' in target) + self.is_mc = not (self.is_data or self.is_embedded) + self.efake = e_fake_rate(0.2) + self.efakeup = e_fake_rate_up(0.2) + self.efakedw = e_fake_rate_dw(0.2) + + #systematics used + self.systematics = { + 'trig' : (['', 'trp1s', 'trm1s'] if not self.is_data else []), + 'pu' : (['', 'p1s', 'm1s'] if self.is_mc else []), + 'eid' : (['', 'eidp1s','eidm1s'] if not self.is_data else []), + 'eiso' : (['', 'eisop1s','eisom1s'] if not self.is_data else []), + 'jes' : (['', '_jes_plus','_jes_minus'] if self.is_mc else ['']), + 'mvetos': (['', 'mVetoUp', 'mVetoDown'] if self.is_mc else ['']), + 'tvetos': (['', 'tVetoUp', 'tVetoDown'] if self.is_mc else ['']), + 'evetos': (['', 'eVetoUp', 'eVetoDown'] if self.is_mc else ['']), + 'met' : (["_mes_plus", "_ues_plus", "_mes_minus", "_ues_minus"] if self.is_mc else []), + 'tes' : (["", "_tes_plus", "_tes_minus"] if not self.is_data else ['']), + 'ees' : (["", "_ees_plus", '_ees_minus'] if not self.is_data else ['']) + } + + #self filling histograms + coll_mass = make_collmass_systematics('') #no sys shift + self.histo_locations = {} #just a mapping of the histograms we have to avoid changing self.histograms indexing an screw other files + self.hfunc = { #maps the name of non-trivial histograms to a function to get the proper value, the function MUST have two args (evt and weight). Used in fill_histos later + 'nTruePU' : lambda row, weight: (row.nTruePU,None), + 'weight' : lambda row, weight: (weight,None) if weight is not None else (1.,None), + 'Event_ID': lambda row, weight: (array.array("f", [row.run,row.lumi,int(row.evt)/10**5,int(row.evt)%10**5] ), None), + 'h_collmass_pfmet' : coll_mass, + 'h_collmass_vs_dPhi_pfmet' : merge_functions( + attr_getter('tToMETDPhi'), + coll_mass + ), + 'MetEt_vs_dPhi' : merge_functions( + lambda row, weight: (deltaPhi(row.tPhi, getattr(row, metphi())), weight), + attr_getter('type1_pfMet_Et') + ), + 'ePFMET_DeltaPhi' : lambda row, weight: (deltaPhi(row.ePhi, getattr(row, metphi())), weight), + 'tPFMET_DeltaPhi' : lambda row, weight: (deltaPhi(row.tPhi, getattr(row, metphi())), weight), + 'evtInfo' : lambda row, weight: (struct(run=row.run,lumi=row.lumi,evt=row.evt,weight=weight), None) + } + for shift in self.systematics['met']: + #patch name + postfix = shift + self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + for shift in self.systematics['tes']: + #patch name + postfix = shift + self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + for shift in self.systematics['jes']: + #patch name + postfix = shift + self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + for shift in self.systematics['ees']: + #patch name + postfix = shift + self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + + + #PU correctors + self.pucorrector = mcCorrections.make_shifted_weights( + mcCorrections.make_puCorrector('singlee'), + ['p1s', 'm1s'], + [mcCorrections.make_puCorrectorUp('singlee'), mcCorrections.make_puCorrectorDown('singlee')] + ) + self.trig_weight = mcCorrections.trig_efficiency if self.is_embedded else mcCorrections.trig_correction + + @staticmethod + def tau_veto(row): + if not row.tAntiMuonLoose2 or not row.tAntiElectronMVA5Tight or not row.tDecayFinding : + return False + + @staticmethod + def obj1_matches_gen(row): + return row.eGenPdgId == -1*row.eCharge*11 + + @staticmethod + def obj3_matches_gen(row): + return t.genDecayMode != -2 + + def event_weight(self, row, sys_shifts): + if self.is_data: + return {'' : 1.} + + weights = {} + for shift in sys_shifts: + embedded_weight = row.EmbPtWeight*mcCorrections.eEmb_correction( row, 'e', shift=shift) if self.is_embedded else 1. + + weights[shift] = embedded_weight *\ + mcCorrections.eid_correction( row, 'e', shift=shift) * \ + mcCorrections.eiso_correction(row, 'e', shift=shift) * \ + self.trig_weight(row, 'e', shift=shift) * \ + self.pucorrector(row.nTruePU, shift=shift) + + return weights +## + def begin(self): + logging.debug('Booking histograms directory tree') + sys_shifts = self.systematics['trig'] + \ + self.systematics['pu'] + \ + self.systematics['eid'] + \ + self.systematics['eiso'] + \ + self.systematics['mvetos'] + \ + self.systematics['tvetos'] + \ + self.systematics['evetos'] + \ + [i.strip('_') for i in self.systematics['jes']] + \ + [i.strip('_') for i in self.systematics['tes']] + \ + [i.strip('_') for i in self.systematics['ees']] + \ + ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + \ + ['eLoose', 'eLoose/Up', 'eLoose/Down'] +\ + ['etLoose', 'etLoose/Up', 'etLoose/Down'] + sys_shifts = list( set( sys_shifts ) ) #remove double dirs + processtype=['gg'] + threshold=['ept30'] + signs =['os', 'ss'] + jetN = ['0', '1', '2', '3'] #[''.join(i) for i in itertools.product(['0', '1', '2', '3'], self.systematics['jes'])] + full_met_systematics = self.systematics['met']+self.systematics['jes']+ \ + self.systematics['tes']+self.systematics['ees'] + #remove empty string + full_met_systematics = [i for i in full_met_systematics if i] + folder=[] + + for tuple_path in itertools.product(sys_shifts, signs, processtype, threshold, jetN): + folder.append(os.path.join(*tuple_path)) + path = list(tuple_path) + path.append('selected') + folder.append(os.path.join(*path)) + + def book_with_sys(location, name, *args, **kwargs): + postfixes = kwargs['postfixes'] + del kwargs['postfixes'] + self.book(location, name, *args, **kwargs) + for postfix in postfixes: + #patch name to be removed + fix = postfix + self.book(location, name+fix, *args, **kwargs) + + self.book('os/gg/ept30/', "h_collmass_pfmet" , "h_collmass_pfmet", 32, 0, 320) + + for f in folder: + #self.book( + # f, + # 'evtInfo', 'evtInfo', + # 'run/l:lumi/l:evt/l:weight/D', + # type=pytree.PyTree + #) + self.book(f,"weight", "weight", 100, 0, 10) + self.book(f,"tPt", "tau p_{T}", 40, 0, 200) + self.book(f,"tPt_tes_plus", "tau p_{T} (tes+)", 40, 0, 200) + self.book(f,"tPt_tes_minus", "tau p_{T} (tes-)",40, 0, 200) + + self.book(f,"tPhi", "tau phi", 26, -3.25, 3.25) + self.book(f,"tEta", "tau eta", 10, -2.5, 2.5) + + self.book(f,"ePt", "e p_{T}", 40, 0, 200) + self.book(f,"ePt_ees_plus", "e p_{T} (ees+)", 40, 0, 200) + self.book(f,"ePt_ees_minus", "e p_{T} (ees-)",40, 0, 200) + + self.book(f,"ePhi", "e phi", 26, -3.2, 3.2) + self.book(f,"eEta", "e eta", 10, -2.5, 2.5) + + self.book(f, "e_t_DPhi", "e-tau DeltaPhi" , 20, 0, 3.2) + self.book(f, "e_t_DR", "e-tau DeltaR" , 20, 0, 3.2) + + #self.book(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320) + book_with_sys(f, "h_collmass_pfmet", "h_collmass_pfmet", 40, 0, 400, + postfixes=full_met_systematics) + + self.book(f, "h_collmass_vs_dPhi_pfmet", "h_collmass_vs_dPhi_pfmet", 20, 0, 3.2, 40, 0, 400, type=ROOT.TH2F) + + self.book(f, "e_t_Mass", "h_vismass", 40, 0, 400) + self.book(f, "e_t_Mass_tes_plus" , "h_vismass_tes_plus", 40 , 0, 400) + self.book(f, "e_t_Mass_tes_minus", "h_vismass_tes_minus",40 , 0, 400) + self.book(f, "e_t_Mass_ees_plus" , "h_vismass_ees_plus", 40 , 0, 400) + self.book(f, "e_t_Mass_ees_minus", "h_vismass_ees_minus",40 , 0, 400) + + self.book(f, "MetEt_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 20, 0, 3.2, 40, 0, 400, type=ROOT.TH2F) + + self.book(f, "tPFMET_DeltaPhi", "tau-type1PFMET DeltaPhi" , 20, 0, 3.2) + + self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 20, 0, 3.2) + + #self.book(f,"tMtToPFMET", "tau-PFMET M_{T}" , 200, 0, 200) + book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 40, 0, 200, + postfixes=full_met_systematics) + #self.book(f,"eMtToPFMET", "e-PFMET M_{T}" , 200, 0, 200) + book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 40, 0, 200, + postfixes=full_met_systematics) + + #self.book(f, "pfMetEt", "pfMetEt", 200, 0, 200) + book_with_sys(f, "pfMet_Et", "pfMet_Et", 40, 0, 200, postfixes=full_met_systematics) + + #self.book(f, "pfMetPhi", "pfMetPhi", 100, -3.2, 3.2) + book_with_sys(f, "pfMet_Phi", "pfMet_Phi", 26, -3.2, 3.2, postfixes=full_met_systematics) + + self.book(f, "jetVeto20", "Number of jets, p_{T}>20", 5, -0.5, 4.5) + self.book(f, "jetVeto30", "Number of jets, p_{T}>30", 5, -0.5, 4.5) + + #index dirs and histograms + for key, value in self.histograms.iteritems(): + location = os.path.dirname(key) + name = os.path.basename(key) + if location not in self.histo_locations: + self.histo_locations[location] = {name : value} + else: + self.histo_locations[location][name] = value + + def fakerate_weights(self, tEta): + tLoose = tau_fake_rate(tEta) + tLooseUp = tau_fake_rate_up(tEta) + tLooseDown= tau_fake_rate_dw(tEta) + + tLoose = tLoose / (1. - tLoose ) + tLooseUp = tLooseUp / (1. - tLooseUp ) + tLooseDown= tLooseDown / (1. - tLooseDown) + + + eLoose = self.efake + eLooseUp = self.efakeup + eLooseDown= self.efakedw + + eLoose = eLoose / (1. - eLoose ) + eLooseUp = eLooseUp / (1. - eLooseUp ) + eLooseDown= eLooseDown / (1. - eLooseDown) + + + etLoose = tLoose * eLoose + etLooseUp = tLooseUp * eLooseUp + etLooseDown= tLooseDown *eLooseDown + + frweight = { + 'tLoose' : tLoose , + 'tLoose/Up' : tLooseUp , + 'tLoose/Down' : tLooseDown, + 'eLoose' : eLoose , + 'eLoose/Up' : eLooseUp , + 'eLoose/Down' : eLooseDown, + 'etLoose' : etLoose , + 'etLoose/Up' : etLooseUp , + 'etLoose/Down' : etLooseDown, + 'tLooseUnweight' : 1., + } + + return frweight; + + def fill_histos(self, folder_str, row, weight, filter_label = ''): + '''fills histograms''' + #find all keys matching + for attr, value in self.histo_locations[folder_str].iteritems(): + name = attr + #if attr=='DEBUG': + # set_trace() + if filter_label: + if not attr.startswith(filter_label+'$'): + continue + attr = attr.replace(filter_label+'$', '') + if value.InheritsFrom('TH2'): + if attr in self.hfunc: + try: + result, out_weight = self.hfunc[attr](row, weight) + except Exception as e: + raise RuntimeError("Error running function %s. Error: \n\n %s" % (attr, str(e))) + r1, r2 = result + if out_weight is None: + value.Fill( r1, r2 ) #saves you when filling NTuples! + else: + value.Fill( r1, r2, out_weight ) + else: + attr1, attr2 = split(attr) + v1 = getattr(row,attr1) + v2 = getattr(row,attr2) + value.Fill( v1, v2, weight ) if weight is not None else value.Fill( v1, v2 ) + else: + if attr in self.hfunc: + try: + result, out_weight = self.hfunc[attr](row, weight) + except Exception as e: + raise RuntimeError("Error running function %s. Error: \n\n %s" % (attr, str(e))) + if out_weight is None: + value.Fill( result ) #saves you when filling NTuples! + else: + value.Fill( result, out_weight ) + else: + value.Fill( getattr(row,attr), weight ) if weight is not None else value.Fill( getattr(row,attr) ) + return None + + def process(self): + logging.debug('Starting processing') + systematics = self.systematics + + frw = [] + lock =() + ievt = 0 + logging.debug('Starting evt loop') + + #pre-compute static things + sys_shifts = systematics['trig'] + \ + systematics['pu'] + \ + systematics['eid'] + \ + systematics['eiso'] #+ \ + + jes_dirs = [i.strip('_') for i in systematics['jes']] + #anyway the first is always "" + tes_dirs = [i.strip('_') for i in systematics['tes']][1:] + ees_dirs = [i.strip('_') for i in systematics['ees']][1:] + + for row in self.tree: + if (ievt % 100) == 0: + logging.debug('New event') + ievt += 1 + #avoid double counting events! + evt_id = (row.run, row.lumi, row.evt) + if evt_id == lock: continue + if lock != () and evt_id == lock: + logging.info('Removing duplicate of event: %d %d %d' % evt_id) + + # + #preselection, common to everything and everyone + # + #trigger + if self.is_embedded : + if not bool(row.doubleMuPass) : continue + else: + if not bool(row.singleE27WP80Pass) : continue + if not bool(row.eMatchesSingleE27WP80): continue + + #objects + if not selections.eSelection(row, 'e'): continue + #if row.ePt < 30 : continue + if not selections.tauSelection(row, 't'): continue + if not row.tAntiElectronMVA5Tight : continue + if not row.tAntiMuon2Loose : continue + if not row.tLooseIso3Hits : continue + logging.debug('object selection passed') + #e ID/ISO + if not selections.lepton_id_iso(row, 'e', 'eid13Tight_idiso02'): continue + logging.debug('Passed preselection') + + + #TO ENHANCE Z->tautau + if row.e_t_DR > 2.0: continue + + # + # Compute event weight + # + #event weight + #sys_shifts is precomputed + + #set_trace() + weight_map = self.event_weight(row, sys_shifts) + + #Fill embedded sample normalization BEFORE the vetoes + if not row.e_t_SS: + self.fill_histos('os/gg/ept30', row, weight_map['']) + + # it is better vetoing on b-jets after the histo for the DY embedded + #bjet veto + if row.bjetCSVVeto30!=0 : continue + + #tau ID, id Tau is tight then go in full selection, otherwise use for fakes + isTauTight = bool(row.tTightIso3Hits) + isETight = bool(selections.lepton_id_iso(row, 'e', 'eid13Tight_etauiso01')) + etau_category = [''] + if (not isETight) and (not isTauTight): + etau_category = ['etLoose', 'etLoose/Up', 'etLoose/Down'] + elif (not isTauTight): + etau_category = ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + elif (not isETight): + etau_category = ['eLoose', 'eLoose/Up', 'eLoose/Down'] + + #jet category + central = struct( + njets = min(row.jetVeto30, 3), + tPt = row.tPt, + ePt = row.ePt + ) + jets = [min(row.jetVeto30, 3), min(row.jetVeto30jes_plus, 3), min(row.jetVeto30jes_minus, 3)] + tpts = [row.tPt_tes_plus, row.tPt_tes_minus] + epts = [row.ePt_ees_plus, row.ePt_ees_minus] + sys_effects = [(name, central.clone(njets = jnum)) for name, jnum in zip(jes_dirs, jets)] + sys_effects.extend( + [(name, central.clone(tPt = pt)) for name, pt in zip(tes_dirs, tpts)] + ) + sys_effects.extend( + [(name, central.clone(ePt = pt)) for name, pt in zip(ees_dirs, epts)] + ) + + # + # Full tight selection + # + passes_full_selection = False + selection_categories = [] + for name, shifted in sys_effects: + #preselection. flat pt values + if shifted.ePt > 30 and shifted.tPt > 30: + selection_categories.append((name, '%i' % shifted.njets, '')) + else: + continue + + if shifted.njets == 0 : + if shifted.tPt < 35: continue + if shifted.ePt < 40: continue + if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue + if row.tMtToPfMet > 50 : continue + selection_categories.append((name, '0', 'selected')) + passes_full_selection = True + elif shifted.njets == 1 : + if shifted.tPt < 40: continue + if shifted.ePt < 35: continue + if row.tMtToPfMet > 35 : continue + selection_categories.append((name, '1', 'selected')) + passes_full_selection = True + elif shifted.njets == 2 : + if shifted.tPt < 40: continue + if shifted.ePt < 30: continue + if row.tMtToPfMet > 35 : continue + if row.vbfMass < 550 : continue + if row.vbfDeta < 3.5 : continue + selection_categories.append((name, '2', 'selected')) + passes_full_selection = True + + if passes_full_selection: + logging.debug('Passed full selection') + + # + #different selections + # + sign = 'ss' if row.e_t_SS else 'os' + processtype ='gg' + ptthreshold = ['ept30'] + + # + # Lepton vetoes + # + tvetoes = [row.tauVetoPt20EleTight3MuLoose, row.tauVetoPt20EleTight3MuLoose_tes_plus, row.tauVetoPt20EleTight3MuLoose_tes_minus] + mvetoes = [row.muVetoPt5IsoIdVtx , row.muVetoPt5IsoIdVtx_mes_plus , row.muVetoPt5IsoIdVtx_mes_minus ] + evetoes = [row.eVetoCicLooseIso , row.eVetoCicLooseIso_ees_plus , row.eVetoCicLooseIso_ees_minus ] + + tdirs = [ i for i, j in zip( systematics['tvetos'], tvetoes) if not j] + mdirs = [ i for i, j in zip( systematics['mvetos'], mvetoes) if not j] + edirs = [ i for i, j in zip( systematics['evetos'], evetoes) if not j] + + #if any of the lists is empty + #set_trace() + if not tdirs or not mdirs or not edirs: + continue + logging.debug('Passed Vetoes') + + #make all possible veto combos... + all_dirs = [''.join(i) for i in itertools.product(tdirs, mdirs, edirs)] + #...and choose only the meaningful ones + veto_sys = set(systematics['tvetos']+systematics['mvetos']+systematics['evetos']) + all_dirs = [i for i in all_dirs if i in veto_sys] + + sys_directories = all_dirs + sys_shifts + #remove duplicates + sys_directories = list(set(sys_directories)) + + #at least one loose object + if (not isETight) or (not isTauTight): + #if is a loose tau just compute the fakes! + sys_directories = etau_category + + #gather the one and only weight we do care about + mc_weight = weight_map[''] + + #weights are the fr ones... + weight_map = self.fakerate_weights(row.tEta) + for i in weight_map: + #...times the mc weight (if any) + weight_map[i] *= mc_weight + + + #Fill histograms in appropriate direcotries + #if passes_full_selection: + #dirs = [os.path.join(sys, sign, processtype, e_thr, jet_dir) for sys, e_thr, jet_dir in itertools.product(sys_directories, ptthreshold, jet_directories)] + #if len(dirs) <> len(set(dirs)): + # set_trace() + for sys, e_thr, selection in itertools.product(sys_directories, ptthreshold, selection_categories): + selection_sys, jet_dir, selection_step = selection + #if we have multiple systematic shifts applied + #reject the combination + if selection_sys and sys: + continue + + #if we fill a histogram, lock the event + lock = evt_id + dir_name = os.path.join(sys, selection_sys, sign, processtype, + e_thr, jet_dir, selection_step) + if dir_name[-1] == '/': + dir_name = dir_name[:-1] + if passes_full_selection: + logging.debug('Filling %s' % dir_name) + #fill them! + weight_to_use = weight_map[sys] if sys in weight_map else weight_map[''] + self.fill_histos(dir_name, row, weight_to_use) + + + def finish(self): + self.write_histos() + + diff --git a/lfvetau/FakeTauControlRegion.py b/lfvetau/FakeTauControlRegion.py new file mode 100644 index 00000000..de3fcc96 --- /dev/null +++ b/lfvetau/FakeTauControlRegion.py @@ -0,0 +1,172 @@ +##Correction Factor still to add +from ETauTree import ETauTree +import os +import ROOT +import math +import optimizer +import glob +import array +import mcCorrections +import baseSelections as selections +import FinalStateAnalysis.PlotTools.pytree as pytree +from FinalStateAnalysis.PlotTools.decorators import memo_last +from FinalStateAnalysis.PlotTools.MegaBase import MegaBase +from math import sqrt, pi, sin, cos, acos, sinh +from cutflowtracker import cut_flow_tracker +#Makes the cut flow histogram +cut_flow_step = ['allEvents', 'e1sel', 'e1IDiso', 'e2sel', 'e2IDiso', 'ZMass', 'tsel', 'tAntiMuon', 'tAntiEle', 'MtToMet', 'tRawIso10','tRawIso5', 'tLooseIso', 'tTightIso' +] + +from inspect import currentframe + +def get_linenumber(): + cf = currentframe() + return cf.f_back.f_lineno + +def deltaPhi(phi1, phi2): + PHI = abs(phi1-phi2) + if PHI<=pi: + return PHI + else: + return 2*pi-PHI +def deltaR(phi1, phi2, eta1, eta2): + deta = eta1 - eta2 + dphi = abs(phi1-phi2) + if (dphi>pi) : dphi = 2*pi-dphi + return sqrt(deta*deta + dphi*dphi); + +def etDR(row): + return row.e1_t_DR if row.e1_t_DR < row.e2_t_DR else row.e2_t_DR + +def etDPhi(row): + e1tDPhi=deltaPhi(row.e1Phi, row.tPhi) + e2tDPhi=deltaPhi(row.e2Phi, row.tPhi) + return e1tDPhi if e1tDPhi < e2tDPhi else e2tDPhi + +def Z(row): + e1p=ROOT.TVector3(row.e1Pt*cos(row.e1Phi),row.e1Pt*sin(row.e1Phi),row.e1Pt*sinh(row.e1Eta)) + e2p=ROOT.TVector3(row.e2Pt*cos(row.e2Phi),row.e2Pt*sin(row.e2Phi),row.e2Pt*sinh(row.e2Eta)) + e1FourVector= ROOT.TLorentzVector(e1p, sqrt(e1p.Mag2()+row.e1Mass*row.e1Mass)) + e2FourVector= ROOT.TLorentzVector(e2p, sqrt(e2p.Mag2()+row.e2Mass*row.e2Mass)) + zFourVector = e1FourVector+e2FourVector + return zFourVector + + +class FakeTauControlRegion(MegaBase): + tree = 'et/final/Ntuple' + def __init__(self, tree, outfile, **kwargs): + self.channel='ET' + super(FakeTauControlRegion, self).__init__(tree, outfile, **kwargs) + self.tree = ETauTree(tree) + self.out=outfile + self.histograms = {} + self.pucorrector = mcCorrections.make_puCorrector('singlee') + + #optimizer_keys = [ i for i in optimizer.grid_search.keys() if i.startswith(self.channel) ] + #self.grid_search = {} + #if len(optimizer_keys) > 1: + # for key in optimizer_keys: + # self.grid_search[key] = optimizer.grid_search[key] + #else: + # self.grid_search[''] = optimizer.grid_search[optimizer_keys[0]] + + + def event_weight(self, row): + if row.run > 2: #FIXME! add tight ID correction + return 1. + + + + + return self.pucorrector(row.nTruePU) * \ + mcCorrections.eid_correction( row, 'e') * \ + mcCorrections.eiso_correction(row, 'e') * \ + mcCorrections.trig_correction(row, 'e') + + def begin(self): + + tauiso = [ 'tLoose', 'tTigh'] + folder = [] + sign = ['ss','os'] + for iso in tauiso: + for s in sign: + folder.append(s+'/'+iso) + folder.append(s+'/'+iso+'/tptregion') + j=0 + while j < 4 : + folder.append(s+'/'+iso+'/'+str(j)) + folder.append(s+'/'+iso+'/'+str(j)+'/tptregion') + j+=1 + + for f in folder: + + self.book(f,"ePt", "e p_{T}", 200, 0, 200) + self.book(f,"ePhi", "e phi", 100, -3.2, 3.2) + self.book(f,"eEta", "e eta", 50, -2.5, 2.5) + self.book(f,"tPt", "t p_{T}", 200, 0, 200) + self.book(f,"tPhi", "t phi", 100, -3.2, 3.2) + self.book(f,"tEta", "t eta", 50, -2.5, 2.5) + self.book(f,"tAbsEta", "t abs eta", 50, -2.5, 2.5) + + + def fill_histos(self, row, folder='os/Loose', fakeRate = False): + weight = self.event_weight(row) + histos = self.histograms + + histos[folder+'/ePt'].Fill(row.ePt, weight) + histos[folder+'/eEta'].Fill(row.eEta, weight) + histos[folder+'/ePhi'].Fill(row.ePhi, weight) + + histos[folder+'/tPt'].Fill(row.tPt, weight) + histos[folder+'/tEta'].Fill(row.tEta, weight) + histos[folder+'/tAbsEta'].Fill(abs(row.tEta), weight) + histos[folder+'/tPhi'].Fill(row.tPhi, weight) + + def process(self): + + #print self.tree.inputfilename + for row in self.tree: + jn = row.jetVeto30 + if jn > 3 : jn = 3 + + if not bool(row.singleE27WP80Pass) : continue + + if not bool(row.eMatchesSingleE27WP80) : continue + + if row.bjetCSVVeto30!=0 : continue + if not selections.eLowPtSelection(row, 'e'): continue + if not selections.lepton_id_iso(row, 'e', 'eid13Loose_idantiso'): continue + if abs(row.eEta) > 1.4442 and abs(row.eEta < 1.566) : continue + + + if not selections.tauSelection(row, 't'): continue + if row.tPt < 30 : continue + + if not row.tAntiMuon2Loose: continue + if not row.tAntiElectronMVA5Tight: continue #was 3 + if row.tauVetoPt20EleTight3MuLoose : continue + #if row.tauHpsVetoPt20 : continue + if row.muVetoPt5IsoIdVtx : continue + if row.eVetoCicLooseIso : continue # change it with Loose + + sign = 'ss' if row.e_t_SS else 'os' + if row.tLooseIso3Hits : + tauiso = 'tLoose' + folder = sign+'/'+tauiso + self.fill_histos(row, folder) + folder=folder+'/'+str(int(jn)) + self.fill_histos(row, folder) + + if row.tTightIso3Hits : + tauiso = 'tTigh' + folder = sign+'/'+tauiso + self.fill_histos(row, folder) + folder=folder+'/'+str(int(jn)) + self.fill_histos(row, folder) + + + + def finish(self): + self.write_histos() + + diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 6003b477..d2ee1d0b 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -516,24 +516,24 @@ def process(self): continue if shifted.njets == 0 : - if shifted.tPt < 35: continue - if shifted.ePt < 40: continue - if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue - if row.tMtToPfMet > 50 : continue + if shifted.tPt < 30: continue #was 35 + if shifted.ePt < 50: continue #was 40 + if deltaPhi(row.ePhi, row.tPhi) < 2.5 : continue #was 2.7 + if row.tMtToPfMet > 70 : continue #was 50 selection_categories.append((name, '0', 'selected')) passes_full_selection = True elif shifted.njets == 1 : - if shifted.tPt < 40: continue - if shifted.ePt < 35: continue - if row.tMtToPfMet > 35 : continue + if shifted.tPt < 30: continue #was 40 + if shifted.ePt < 40: continue #was 35 + if row.tMtToPfMet > 45 : continue #was 35 selection_categories.append((name, '1', 'selected')) passes_full_selection = True elif shifted.njets == 2 : - if shifted.tPt < 40: continue - if shifted.ePt < 30: continue - if row.tMtToPfMet > 35 : continue - if row.vbfMass < 550 : continue - if row.vbfDeta < 3.5 : continue + if shifted.tPt < 30: continue #was 40 + if shifted.ePt < 40: continue #was 30 + if row.tMtToPfMet > 55 : continue #was 35 + if row.vbfMass < 500 : continue #was 550 + if row.vbfDeta < 2.5 : continue #was 3.5 selection_categories.append((name, '2', 'selected')) passes_full_selection = True diff --git a/lfvetau/TTbarControlRegion.py b/lfvetau/TTbarControlRegion.py new file mode 100644 index 00000000..f6f7cfb2 --- /dev/null +++ b/lfvetau/TTbarControlRegion.py @@ -0,0 +1,623 @@ +from ETauTree import ETauTree +import sys +import logging +logging.basicConfig(stream=sys.stderr, level=logging.WARNING) +import os +from pdb import set_trace +import ROOT +import math +import glob +import array +import mcCorrections +import baseSelections as selections +import FinalStateAnalysis.PlotTools.pytree as pytree +from FinalStateAnalysis.PlotTools.decorators import memo_last +from FinalStateAnalysis.PlotTools.MegaBase import MegaBase +from math import sqrt, pi, cos +from fakerate_functions import tau_fake_rate, tau_fake_rate_up, tau_fake_rate_dw, e_fake_rate, e_fake_rate_up, e_fake_rate_dw +import itertools +import traceback +from FinalStateAnalysis.PlotTools.decorators import memo +import FinalStateAnalysis.PlotTools.pytree as pytree +from FinalStateAnalysis.Utilities.struct import struct + +@memo +def getVar(name, var): + return name+var + +met_et = 'pfMet_Et%s' +met_phi = 'pfMet_Phi%s' +t_pt = 'tPt%s' +etMass = 'e_t_Mass%s' +@memo +def met(shift=''): + return met_et % shift + +@memo +def metphi(shift=''): + return met_phi % shift +@memo +def tpt(shift=''): + return t_pt % shift + +@memo +def vismass(shift=''): + return etMass % shift + +@memo +def split(string, separator='#'): + return tuple(attr.split(separator)) + +def create_mapper(mapping): + def _f(path): + for key, out in mapping.iteritems(): + if key == path: + path = path.replace(key,out) + print 'path', path + return path + return _f + +def attr_getter(attribute): + '''return a function that gets an attribute''' + def f(row, weight): + return (getattr(row,attribute), weight) + return f + +def merge_functions(fcn_1, fcn_2): + '''merges two functions to become a TH2''' + def f(row, weight): + r1, w1 = fcn_1(row, weight) + r2, w2 = fcn_2(row, weight) + w = w1 if w1 and w2 else None + return ((r1, r2), w) + return f + +def collmass(row, met, metPhi): + ptnu =abs(met*cos(deltaPhi(metPhi, row.tPhi))) + visfrac = row.tPt/(row.tPt+ptnu) + #print met, cos(deltaPhi(metPhi, row.tPhi)), ptnu, visfrac + return (row.e_t_Mass / sqrt(visfrac)) + +def deltaPhi(phi1, phi2): + PHI = abs(phi1-phi2) + if PHI<=pi: + return PHI + else: + return 2*pi-PHI + +def deltaR(phi1, ph2, eta1, eta2): + deta = eta1 - eta2 + dphi = abs(phi1-phi2) + if (dphi>pi) : dphi = 2*pi-dphi + return sqrt(deta*deta + dphi*dphi); + +def make_collmass_systematics(shift): + if shift.startswith('tes'): + ptnu =abs(met*cos(deltaPhi(metPhi, row.tPhi))) + visfrac = tpt/(tpt+ptnu) + vis_mass = vismass(shift) + return (vis_mass / sqrt(visfrac)) + else: + met_name = met(shift) + phi_name = metphi(shift) + def collmass_shifted(row, weight): + met = getattr(row, met_name) + phi = getattr(row, phi_name) + return collmass(row, met, phi), weight + return collmass_shifted + +class TTbarControlRegion(MegaBase): + tree = 'et/final/Ntuple' + def __init__(self, tree, outfile, **kwargs): + logging.debug('TTbar constructor') + self.channel='ET' + super(TTbarControlRegion, self).__init__(tree, outfile, **kwargs) + self.tree = ETauTree(tree) + self.out=outfile + self.histograms = {} + + #understand what we are running + target = os.path.basename(os.environ['megatarget']) + self.is_data = target.startswith('data_') + self.is_embedded = ('Embedded' in target) + self.is_mc = not (self.is_data or self.is_embedded) + self.efake = e_fake_rate(0.2) + self.efakeup = e_fake_rate_up(0.2) + self.efakedw = e_fake_rate_dw(0.2) + + #systematics used + self.systematics = { + 'trig' : (['', 'trp1s', 'trm1s'] if not self.is_data else []), + 'pu' : (['', 'p1s', 'm1s'] if self.is_mc else []), + 'eid' : (['', 'eidp1s','eidm1s'] if not self.is_data else []), + 'eiso' : (['', 'eisop1s','eisom1s'] if not self.is_data else []), + 'jes' : (['', '_jes_plus','_jes_minus'] if self.is_mc else ['']), + 'mvetos': (['', 'mVetoUp', 'mVetoDown'] if self.is_mc else ['']), + 'tvetos': (['', 'tVetoUp', 'tVetoDown'] if self.is_mc else ['']), + 'evetos': (['', 'eVetoUp', 'eVetoDown'] if self.is_mc else ['']), + 'met' : (["_mes_plus", "_ues_plus", "_mes_minus", "_ues_minus"] if self.is_mc else []), + 'tes' : (["", "_tes_plus", "_tes_minus"] if not self.is_data else ['']), + 'ees' : (["", "_ees_plus", '_ees_minus'] if not self.is_data else ['']) + } + + #self filling histograms + coll_mass = make_collmass_systematics('') #no sys shift + self.histo_locations = {} #just a mapping of the histograms we have to avoid changing self.histograms indexing an screw other files + self.hfunc = { #maps the name of non-trivial histograms to a function to get the proper value, the function MUST have two args (evt and weight). Used in fill_histos later + 'nTruePU' : lambda row, weight: (row.nTruePU,None), + 'weight' : lambda row, weight: (weight,None) if weight is not None else (1.,None), + 'Event_ID': lambda row, weight: (array.array("f", [row.run,row.lumi,int(row.evt)/10**5,int(row.evt)%10**5] ), None), + 'h_collmass_pfmet' : coll_mass, + 'h_collmass_vs_dPhi_pfmet' : merge_functions( + attr_getter('tToMETDPhi'), + coll_mass + ), + 'MetEt_vs_dPhi' : merge_functions( + lambda row, weight: (deltaPhi(row.tPhi, getattr(row, metphi())), weight), + attr_getter('type1_pfMet_Et') + ), + 'ePFMET_DeltaPhi' : lambda row, weight: (deltaPhi(row.ePhi, getattr(row, metphi())), weight), + 'tPFMET_DeltaPhi' : lambda row, weight: (deltaPhi(row.tPhi, getattr(row, metphi())), weight), + 'evtInfo' : lambda row, weight: (struct(run=row.run,lumi=row.lumi,evt=row.evt,weight=weight), None) + } + for shift in self.systematics['met']: + #patch name + postfix = shift + self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + for shift in self.systematics['tes']: + #patch name + postfix = shift + self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + for shift in self.systematics['jes']: + #patch name + postfix = shift + self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + for shift in self.systematics['ees']: + #patch name + postfix = shift + self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + + + #PU correctors + self.pucorrector = mcCorrections.make_shifted_weights( + mcCorrections.make_puCorrector('singlee'), + ['p1s', 'm1s'], + [mcCorrections.make_puCorrectorUp('singlee'), mcCorrections.make_puCorrectorDown('singlee')] + ) + self.trig_weight = mcCorrections.trig_efficiency if self.is_embedded else mcCorrections.trig_correction + + @staticmethod + def tau_veto(row): + if not row.tAntiMuonLoose2 or not row.tAntiElectronMVA5Tight or not row.tDecayFinding : + return False + + @staticmethod + def obj1_matches_gen(row): + return row.eGenPdgId == -1*row.eCharge*11 + + @staticmethod + def obj3_matches_gen(row): + return t.genDecayMode != -2 + + def event_weight(self, row, sys_shifts): + if self.is_data: + return {'' : 1.} + + weights = {} + for shift in sys_shifts: + embedded_weight = row.EmbPtWeight*mcCorrections.eEmb_correction( row, 'e', shift=shift) if self.is_embedded else 1. + + weights[shift] = embedded_weight *\ + mcCorrections.eid_correction( row, 'e', shift=shift) * \ + mcCorrections.eiso_correction(row, 'e', shift=shift) * \ + self.trig_weight(row, 'e', shift=shift) * \ + self.pucorrector(row.nTruePU, shift=shift) + + return weights +## + def begin(self): + logging.debug('Booking histograms directory tree') + sys_shifts = self.systematics['trig'] + \ + self.systematics['pu'] + \ + self.systematics['eid'] + \ + self.systematics['eiso'] + \ + self.systematics['mvetos'] + \ + self.systematics['tvetos'] + \ + self.systematics['evetos'] + \ + [i.strip('_') for i in self.systematics['jes']] + \ + [i.strip('_') for i in self.systematics['tes']] + \ + [i.strip('_') for i in self.systematics['ees']] + \ + ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + \ + ['eLoose', 'eLoose/Up', 'eLoose/Down'] +\ + ['etLoose', 'etLoose/Up', 'etLoose/Down'] + sys_shifts = list( set( sys_shifts ) ) #remove double dirs + processtype=['gg'] + threshold=['ept30'] + signs =['os', 'ss'] + jetN = ['0', '1', '2', '3'] #[''.join(i) for i in itertools.product(['0', '1', '2', '3'], self.systematics['jes'])] + full_met_systematics = self.systematics['met']+self.systematics['jes']+ \ + self.systematics['tes']+self.systematics['ees'] + #remove empty string + full_met_systematics = [i for i in full_met_systematics if i] + folder=[] + + for tuple_path in itertools.product(sys_shifts, signs, processtype, threshold, jetN): + folder.append(os.path.join(*tuple_path)) + path = list(tuple_path) + path.append('selected') + folder.append(os.path.join(*path)) + + def book_with_sys(location, name, *args, **kwargs): + postfixes = kwargs['postfixes'] + del kwargs['postfixes'] + self.book(location, name, *args, **kwargs) + for postfix in postfixes: + #patch name to be removed + fix = postfix + self.book(location, name+fix, *args, **kwargs) + + self.book('os/gg/ept30/', "h_collmass_pfmet" , "h_collmass_pfmet", 32, 0, 320) + self.book('os/gg/ept30/', "e_t_Mass", "h_vismass", 32, 0, 320) + + for f in folder: + #self.book( + # f, + # 'evtInfo', 'evtInfo', + # 'run/l:lumi/l:evt/l:weight/D', + # type=pytree.PyTree + #) + self.book(f,"weight", "weight", 100, 0, 10) + self.book(f,"tPt", "tau p_{T}", 40, 0, 200) + self.book(f,"tPt_tes_plus", "tau p_{T} (tes+)", 40, 0, 200) + self.book(f,"tPt_tes_minus", "tau p_{T} (tes-)",40, 0, 200) + + self.book(f,"tPhi", "tau phi", 26, -3.25, 3.25) + self.book(f,"tEta", "tau eta", 10, -2.5, 2.5) + + self.book(f,"ePt", "e p_{T}", 40, 0, 200) + self.book(f,"ePt_ees_plus", "e p_{T} (ees+)", 40, 0, 200) + self.book(f,"ePt_ees_minus", "e p_{T} (ees-)",40, 0, 200) + + self.book(f,"ePhi", "e phi", 26, -3.2, 3.2) + self.book(f,"eEta", "e eta", 10, -2.5, 2.5) + + self.book(f, "e_t_DPhi", "e-tau DeltaPhi" , 20, 0, 3.2) + self.book(f, "e_t_DR", "e-tau DeltaR" , 20, 0, 3.2) + + #self.book(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320) + book_with_sys(f, "h_collmass_pfmet", "h_collmass_pfmet", 40, 0, 400, + postfixes=full_met_systematics) + + self.book(f, "h_collmass_vs_dPhi_pfmet", "h_collmass_vs_dPhi_pfmet", 20, 0, 3.2, 40, 0, 400, type=ROOT.TH2F) + + self.book(f, "e_t_Mass", "h_vismass", 40, 0, 400) + self.book(f, "e_t_Mass_tes_plus" , "h_vismass_tes_plus", 40 , 0, 400) + self.book(f, "e_t_Mass_tes_minus", "h_vismass_tes_minus",40 , 0, 400) + self.book(f, "e_t_Mass_ees_plus" , "h_vismass_ees_plus", 40 , 0, 400) + self.book(f, "e_t_Mass_ees_minus", "h_vismass_ees_minus",40 , 0, 400) + + self.book(f, "MetEt_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 20, 0, 3.2, 40, 0, 400, type=ROOT.TH2F) + + self.book(f, "tPFMET_DeltaPhi", "tau-type1PFMET DeltaPhi" , 20, 0, 3.2) + + self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 20, 0, 3.2) + + #self.book(f,"tMtToPFMET", "tau-PFMET M_{T}" , 200, 0, 200) + book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 40, 0, 200, + postfixes=full_met_systematics) + #self.book(f,"eMtToPFMET", "e-PFMET M_{T}" , 200, 0, 200) + book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 40, 0, 200, + postfixes=full_met_systematics) + + #self.book(f, "pfMetEt", "pfMetEt", 200, 0, 200) + book_with_sys(f, "pfMet_Et", "pfMet_Et", 40, 0, 200, postfixes=full_met_systematics) + + #self.book(f, "pfMetPhi", "pfMetPhi", 100, -3.2, 3.2) + book_with_sys(f, "pfMet_Phi", "pfMet_Phi", 26, -3.2, 3.2, postfixes=full_met_systematics) + + self.book(f, "jetVeto20", "Number of jets, p_{T}>20", 5, -0.5, 4.5) + self.book(f, "jetVeto30", "Number of jets, p_{T}>30", 5, -0.5, 4.5) + + #index dirs and histograms + for key, value in self.histograms.iteritems(): + location = os.path.dirname(key) + name = os.path.basename(key) + if location not in self.histo_locations: + self.histo_locations[location] = {name : value} + else: + self.histo_locations[location][name] = value + + def fakerate_weights(self, tEta): + tLoose = tau_fake_rate(tEta) + tLooseUp = tau_fake_rate_up(tEta) + tLooseDown= tau_fake_rate_dw(tEta) + + tLoose = tLoose / (1. - tLoose ) + tLooseUp = tLooseUp / (1. - tLooseUp ) + tLooseDown= tLooseDown / (1. - tLooseDown) + + + eLoose = self.efake + eLooseUp = self.efakeup + eLooseDown= self.efakedw + + eLoose = eLoose / (1. - eLoose ) + eLooseUp = eLooseUp / (1. - eLooseUp ) + eLooseDown= eLooseDown / (1. - eLooseDown) + + + etLoose = tLoose * eLoose + etLooseUp = tLooseUp * eLooseUp + etLooseDown= tLooseDown *eLooseDown + + frweight = { + 'tLoose' : tLoose , + 'tLoose/Up' : tLooseUp , + 'tLoose/Down' : tLooseDown, + 'eLoose' : eLoose , + 'eLoose/Up' : eLooseUp , + 'eLoose/Down' : eLooseDown, + 'etLoose' : etLoose , + 'etLoose/Up' : etLooseUp , + 'etLoose/Down' : etLooseDown, + 'tLooseUnweight' : 1., + } + + return frweight; + + def fill_histos(self, folder_str, row, weight, filter_label = ''): + '''fills histograms''' + #find all keys matching + for attr, value in self.histo_locations[folder_str].iteritems(): + name = attr + #if attr=='DEBUG': + # set_trace() + if filter_label: + if not attr.startswith(filter_label+'$'): + continue + attr = attr.replace(filter_label+'$', '') + if value.InheritsFrom('TH2'): + if attr in self.hfunc: + try: + result, out_weight = self.hfunc[attr](row, weight) + except Exception as e: + raise RuntimeError("Error running function %s. Error: \n\n %s" % (attr, str(e))) + r1, r2 = result + if out_weight is None: + value.Fill( r1, r2 ) #saves you when filling NTuples! + else: + value.Fill( r1, r2, out_weight ) + else: + attr1, attr2 = split(attr) + v1 = getattr(row,attr1) + v2 = getattr(row,attr2) + value.Fill( v1, v2, weight ) if weight is not None else value.Fill( v1, v2 ) + else: + if attr in self.hfunc: + try: + result, out_weight = self.hfunc[attr](row, weight) + except Exception as e: + raise RuntimeError("Error running function %s. Error: \n\n %s" % (attr, str(e))) + if out_weight is None: + value.Fill( result ) #saves you when filling NTuples! + else: + value.Fill( result, out_weight ) + else: + value.Fill( getattr(row,attr), weight ) if weight is not None else value.Fill( getattr(row,attr) ) + return None + + def process(self): + logging.debug('Starting processing') + systematics = self.systematics + + frw = [] + lock =() + ievt = 0 + logging.debug('Starting evt loop') + + #pre-compute static things + sys_shifts = systematics['trig'] + \ + systematics['pu'] + \ + systematics['eid'] + \ + systematics['eiso'] #+ \ + + jes_dirs = [i.strip('_') for i in systematics['jes']] + #anyway the first is always "" + tes_dirs = [i.strip('_') for i in systematics['tes']][1:] + ees_dirs = [i.strip('_') for i in systematics['ees']][1:] + + for row in self.tree: + if (ievt % 100) == 0: + logging.debug('New event') + ievt += 1 + #avoid double counting events! + evt_id = (row.run, row.lumi, row.evt) + if evt_id == lock: continue + if lock != () and evt_id == lock: + logging.info('Removing duplicate of event: %d %d %d' % evt_id) + + # + #preselection, common to everything and everyone + # + #trigger + if self.is_embedded : + if not bool(row.doubleMuPass) : continue + else: + if not bool(row.singleE27WP80Pass) : continue + if not bool(row.eMatchesSingleE27WP80): continue + + #objects + if not selections.eSelection(row, 'e'): continue + #if row.ePt < 30 : continue + if not selections.tauSelection(row, 't'): continue + if not row.tAntiElectronMVA5Tight : continue + if not row.tAntiMuon2Loose : continue + if not row.tLooseIso3Hits : continue + logging.debug('object selection passed') + #e ID/ISO + if not selections.lepton_id_iso(row, 'e', 'eid13Tight_idiso02'): continue + logging.debug('Passed preselection') + + # + # Compute event weight + # + #event weight + #sys_shifts is precomputed + + #set_trace() + weight_map = self.event_weight(row, sys_shifts) + + #Fill embedded sample normalization BEFORE the vetoes + if not row.e_t_SS: + self.fill_histos('os/gg/ept30', row, weight_map['']) + + # it is better vetoing on b-jets after the histo for the DY embedded + #bjet veto + if row.bjetCSVVeto30==0 : continue + + #tau ID, id Tau is tight then go in full selection, otherwise use for fakes + isTauTight = bool(row.tTightIso3Hits) + isETight = bool(selections.lepton_id_iso(row, 'e', 'eid13Tight_etauiso01')) + etau_category = [''] + if (not isETight) and (not isTauTight): + etau_category = ['etLoose', 'etLoose/Up', 'etLoose/Down'] + elif (not isTauTight): + etau_category = ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'] + elif (not isETight): + etau_category = ['eLoose', 'eLoose/Up', 'eLoose/Down'] + + #jet category + central = struct( + njets = 2, + #njets = min(row.jetVeto30, 3), + tPt = row.tPt, + ePt = row.ePt + ) + #jets = [min(row.jetVeto30, 3), min(row.jetVeto30jes_plus, 3), min(row.jetVeto30jes_minus, 3)] + jets = [2,2,2] + tpts = [row.tPt_tes_plus, row.tPt_tes_minus] + epts = [row.ePt_ees_plus, row.ePt_ees_minus] + sys_effects = [(name, central.clone(njets = jnum)) for name, jnum in zip(jes_dirs, jets)] + sys_effects.extend( + [(name, central.clone(tPt = pt)) for name, pt in zip(tes_dirs, tpts)] + ) + sys_effects.extend( + [(name, central.clone(ePt = pt)) for name, pt in zip(ees_dirs, epts)] + ) + + # + # Full tight selection + # + passes_full_selection = False + selection_categories = [] + for name, shifted in sys_effects: + #preselection. flat pt values + if shifted.ePt > 30 and shifted.tPt > 30: + selection_categories.append((name, '%i' % shifted.njets, '')) + else: + continue + + ##if shifted.njets == 0 : + ## if shifted.tPt < 35: continue + ## if shifted.ePt < 40: continue + ## if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue + ## if row.tMtToPfMet > 50 : continue + ## selection_categories.append((name, '0', 'selected')) + ## passes_full_selection = True + ##elif shifted.njets == 1 : + ## if shifted.tPt < 40: continue + ## if shifted.ePt < 35: continue + ## if row.tMtToPfMet > 35 : continue + ## selection_categories.append((name, '1', 'selected')) + ## passes_full_selection = True + ##el + if shifted.njets == 2 : + if shifted.tPt < 40: continue + if shifted.ePt < 30: continue + if row.tMtToPfMet > 35 : continue + if row.vbfMass < 550 : continue + if row.vbfDeta < 3.5 : continue + selection_categories.append((name, '2', 'selected')) + passes_full_selection = True + + if passes_full_selection: + logging.debug('Passed full selection') + + # + #different selections + # + sign = 'ss' if row.e_t_SS else 'os' + processtype ='gg' + ptthreshold = ['ept30'] + + # + # Lepton vetoes + # + tvetoes = [row.tauVetoPt20EleTight3MuLoose, row.tauVetoPt20EleTight3MuLoose_tes_plus, row.tauVetoPt20EleTight3MuLoose_tes_minus] + mvetoes = [row.muVetoPt5IsoIdVtx , row.muVetoPt5IsoIdVtx_mes_plus , row.muVetoPt5IsoIdVtx_mes_minus ] + evetoes = [row.eVetoCicLooseIso , row.eVetoCicLooseIso_ees_plus , row.eVetoCicLooseIso_ees_minus ] + + tdirs = [ i for i, j in zip( systematics['tvetos'], tvetoes) if not j] + mdirs = [ i for i, j in zip( systematics['mvetos'], mvetoes) if not j] + edirs = [ i for i, j in zip( systematics['evetos'], evetoes) if not j] + + #if any of the lists is empty + #set_trace() + if not tdirs or not mdirs or not edirs: + continue + logging.debug('Passed Vetoes') + + #make all possible veto combos... + all_dirs = [''.join(i) for i in itertools.product(tdirs, mdirs, edirs)] + #...and choose only the meaningful ones + veto_sys = set(systematics['tvetos']+systematics['mvetos']+systematics['evetos']) + all_dirs = [i for i in all_dirs if i in veto_sys] + + sys_directories = all_dirs + sys_shifts + #remove duplicates + sys_directories = list(set(sys_directories)) + + #at least one loose object + if (not isETight) or (not isTauTight): + #if is a loose tau just compute the fakes! + sys_directories = etau_category + + #gather the one and only weight we do care about + mc_weight = weight_map[''] + + #weights are the fr ones... + weight_map = self.fakerate_weights(row.tEta) + for i in weight_map: + #...times the mc weight (if any) + weight_map[i] *= mc_weight + + + #Fill histograms in appropriate direcotries + #if passes_full_selection: + #dirs = [os.path.join(sys, sign, processtype, e_thr, jet_dir) for sys, e_thr, jet_dir in itertools.product(sys_directories, ptthreshold, jet_directories)] + #if len(dirs) <> len(set(dirs)): + # set_trace() + for sys, e_thr, selection in itertools.product(sys_directories, ptthreshold, selection_categories): + selection_sys, jet_dir, selection_step = selection + #if we have multiple systematic shifts applied + #reject the combination + if selection_sys and sys: + continue + + #if we fill a histogram, lock the event + lock = evt_id + dir_name = os.path.join(sys, selection_sys, sign, processtype, + e_thr, jet_dir, selection_step) + if dir_name[-1] == '/': + dir_name = dir_name[:-1] + if passes_full_selection: + logging.debug('Filling %s' % dir_name) + #fill them! + weight_to_use = weight_map[sys] if sys in weight_map else weight_map[''] + self.fill_histos(dir_name, row, weight_to_use) + + + def finish(self): + self.write_histos() + + diff --git a/lfvetau/baseSelections.py b/lfvetau/baseSelections.py index bda855ff..423a53c6 100755 --- a/lfvetau/baseSelections.py +++ b/lfvetau/baseSelections.py @@ -39,6 +39,25 @@ def eSelection(row, name): if abs(getattr( row, getVar(name,'DZ'))) > 0.2: return False #if getattr(row, getVar(name, 'MuonIdIsoVtxOverlap')): return False return True +def eLowPtSelection(row, name): + eAbsEta = getattr( row, getVar(name,'AbsEta')) + ept = getattr( row, getVar(name,'Pt_ees_minus')) + if ept: + if ept < 15: return False + else: + if getattr( row, getVar(name,'Pt')) < 15: return False #was 20 + + if eAbsEta > 2.3: return False + if getattr( row, getVar(name,'MissingHits')): return False + if getattr( row, getVar(name,'HasConversion')): return False + if eAbsEta > 1.4442 and eAbsEta < 1.566: return False +# if not getattr( row, getVar(name,'ChargeIdTight')): return False + if not getattr( row, getVar(name,'ChargeIdLoose')): return False + if getattr( row, getVar(name,'JetCSVBtag')) > 0.8: return False + ###if getattr( row, getVar(name,'JetBtag')) > 3.3: return False + if abs(getattr( row, getVar(name,'DZ'))) > 0.2: return False + #if getattr(row, getVar(name, 'MuonIdIsoVtxOverlap')): return False + return True def tauSelection(row, name): tpt = getattr( row, getVar(name,'Pt_tes_minus')) @@ -81,6 +100,8 @@ def lepton_id_iso(row, name, label): #label in the format eidtype_isotype return bool( RelPFIsoDB < 0.15 or (RelPFIsoDB < 0.20 and AbsEta < 1.479)) if isolabel == 'idiso02': return bool( RelPFIsoDB < 0.20 ) + if isolabel == 'idantiso': + return bool( RelPFIsoDB > 0.20 ) if isolabel == 'etauiso012' or isolabel == 'mutauiso012': return bool( RelPFIsoDB < 0.12 ) if isolabel == 'etauiso01' or isolabel == 'mutauiso01': diff --git a/lfvetau/mcCorrections.py b/lfvetau/mcCorrections.py index 07548d93..dddc6b81 100755 --- a/lfvetau/mcCorrections.py +++ b/lfvetau/mcCorrections.py @@ -90,6 +90,7 @@ def multiple(row,*args): getVar(arg,'Eta') ) pt = getattr(row, getVar(arg,'Pt')) + if pt<30: pt =30 #only fakerate checks allow pt < 30. This is an approximation to not re-run the Tag and Probe fcn_ret = fcn(pt,abseta) if indexed: value, err = fcn_ret diff --git a/lfvetau/produceShapeForYields.py b/lfvetau/produceShapeForYields.py new file mode 100644 index 00000000..4127d8d4 --- /dev/null +++ b/lfvetau/produceShapeForYields.py @@ -0,0 +1,71 @@ +#from mauro plotters + +#Set logging before anything to override rootpy very verbose defaults +import sys +import logging +logging.basicConfig(stream=sys.stderr, level=logging.INFO) + +import os +import ROOT +from pdb import set_trace +from FinalStateAnalysis.PlotTools.MegaBase import make_dirs +from FinalStateAnalysis.MetaData.data_styles import data_styles +from FinalStateAnalysis.PlotTools.BlindView import BlindView, blind_in_range +from FinalStateAnalysis.PlotTools.SubtractionView import SubtractionView, PositiveView +import itertools +import glob +import sys +from BasePlotter import BasePlotter +from argparse import ArgumentParser + +parser = ArgumentParser(description=__doc__) +parser.add_argument('--no-plots', dest='no_plots', action='store_true', + default=False, help='Does not print plots') +parser.add_argument('--no-shapes', dest='no_shapes', action='store_true', + default=False, help='Does not create shapes for limit computation') +args = parser.parse_args() + +jobid = os.environ['jobid'] +#jobid = 'MCntuples_3March' +channel = 'et' +import rootpy.plotting.views as views + +ROOT.gROOT.SetStyle("Plain") +ROOT.gROOT.SetBatch(True) +ROOT.gStyle.SetOptStat(0) + +print "\nPlotting %s for %s\n" % (channel, jobid) + +#check if blind +blind = 'blind' not in os.environ or os.environ['blind'] == 'YES' +blind_region=[100, 150] if blind else None + +embedded = True + +plotter = BasePlotter(blind_region,use_embedded=embedded) + +signal_region = 'os/gg/ept30/%s/selected' +jets_names = [ + ('0', 'gg0etau' , 1), + ('1', 'boostetau', 1), + ('2', 'vbfetau' , 5), +] +pjoin = os.path.join +for njets, cat_name, rebin in jets_names: + output_path = plotter.base_out_dir + tfile = ROOT.TFile(pjoin(output_path, 'shapes.%s.root' % njets), 'recreate') + output_dir = tfile.mkdir(cat_name) + unc_conf_lines, unc_vals_lines = plotter.write_shapes_for_yields( + signal_region % njets, 'h_collmass_pfmet', output_dir, rebin=rebin) + logging.warning('shape file %s created' % tfile.GetName()) + tfile.Close() + with open(pjoin(output_path, 'unc.%s.conf' % njets), 'w') as conf: + conf.write('\n'.join(unc_conf_lines)) + with open(pjoin(output_path, 'unc.%s.vals' % njets), 'w') as vals: + vals.write('\n'.join(unc_vals_lines)) + +with open(pjoin(output_path,'.shapes_timestamp'),'w') as stamp: + stamp.write('no use') + + + From bc8bdfc118674dd11fc279f58e839da8293d1f0b Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 10 Dec 2014 07:36:40 -0600 Subject: [PATCH 173/192] compliant with Maria's naming --- lfvetau/prepare_limit.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lfvetau/prepare_limit.sh b/lfvetau/prepare_limit.sh index 9de13573..a7980142 100755 --- a/lfvetau/prepare_limit.sh +++ b/lfvetau/prepare_limit.sh @@ -21,7 +21,8 @@ cp card_config/unc.$category.conf $output_dir/unc.conf cp card_config/unc.$category.vals $output_dir/unc.vals #copy shape file -cp $input_dir/shapes.$file_extension.root $output_dir/shapes.root +shapes=shapesETau$category'Jet.root' +cp $input_dir/shapes.$file_extension.root $output_dir/$shapes #add dynamically assigned variables cat $input_dir/unc.$file_extension.conf >> $output_dir/unc.conf @@ -52,8 +53,8 @@ echo "#bbb uncertainties" >> $output_dir/unc.conf echo "#bbb uncertainties" >> $output_dir/unc.vals for sample in $samples; do echo "adding bbb errors for $sample" - echo add_stat_shapes.py $output_dir/shapes.root $output_dir/shapes.root --normalize --filter $category_name/$sample --prefix $category_name - bbb_added=$(add_stat_shapes.py $output_dir/shapes.root $output_dir/shapes.root --normalize --filter $category_name/$sample --prefix $category_name | grep _bin_) + echo add_stat_shapes.py $output_dir/$shapes $output_dir/$shapes --normalize --filter $category_name/$sample --prefix $category_name + bbb_added=$(add_stat_shapes.py $output_dir/$shapes $output_dir/$shapes --normalize --filter $category_name/$sample --prefix $category_name | grep _bin_) echo >> $output_dir/unc.conf echo >> $output_dir/unc.vals for unc in $bbb_added; do @@ -66,10 +67,10 @@ done pushd $output_dir mkdir -p 126 pushd 126 -rm -rf shapes.root -ln -s ../shapes.root +rm -rf $shapes +ln -s ../$shapes popd -create-datacard.py -i shapes.root -o 126/datacard_et_$category.txt +create-datacard.py -i $shapes -o 126/datacard_et_$category.txt popd exit 0 From 33b8f89e49bed26eeb226aeecae5d8e9ba77af33 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 10 Dec 2014 07:36:59 -0600 Subject: [PATCH 174/192] compliant with Maria's naming --- lfvetau/Rakefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index fab8c777..b251c046 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -426,10 +426,10 @@ file cmb_card => [card_0_jet, card_1_jet, card_2_jet] do |t| sh "mkdir -p #{$limitdir}/cmb/126" - sh "hadd -f #{$limitdir}/cmb/shapes.root #{$limitdir}/[0-9]/shapes.root" + sh "hadd -f #{$limitdir}/cmb/shapesETauHad.root #{$limitdir}/[0-9]/shapesETau$category?Jet.root" chdir("#{$limitdir}/cmb/126") do - sh "rm -f shapes.root" - sh "ln -s ../shapes.root" + sh "rm -f shapesETauHad.root" + sh "ln -s ../shapesETauHad.root" local_paths = t.prerequisites.map{|x| x.sub($limitdir,'../../')} local_name = File.basename(t.name) sh "combine_cards_with_names.sh #{ local_paths.join(' ')} > #{local_name}" From 34fe2dea8c1c63471506028c6c4294b7a4da725b Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Wed, 10 Dec 2014 07:37:32 -0600 Subject: [PATCH 175/192] change in br values --- lfvetau/plotRecoQuantitiesMVA.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lfvetau/plotRecoQuantitiesMVA.py b/lfvetau/plotRecoQuantitiesMVA.py index 3c656f89..ac39082f 100644 --- a/lfvetau/plotRecoQuantitiesMVA.py +++ b/lfvetau/plotRecoQuantitiesMVA.py @@ -110,7 +110,8 @@ tfile = ROOT.TFile(pjoin(output_path, 'shapes.%s.root' % njets), 'recreate') output_dir = tfile.mkdir(cat_name) unc_conf_lines, unc_vals_lines = plotter.write_shapes( - signal_region % njets, 'h_collmass_pfmet', output_dir, rebin=rebin) + signal_region % njets, 'h_collmass_pfmet', output_dir, rebin=rebin, + br_strenght=1) logging.warning('shape file %s created' % tfile.GetName()) tfile.Close() with open(pjoin(output_path, 'unc.%s.conf' % njets), 'w') as conf: From b59b2d24be926253548a34a2b5ea19c5507b6672 Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 12 Dec 2014 02:57:13 -0600 Subject: [PATCH 176/192] optimizer --- lfvetau/optimizer.py | 96 +++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/lfvetau/optimizer.py b/lfvetau/optimizer.py index 21364858..c0fe2af8 100644 --- a/lfvetau/optimizer.py +++ b/lfvetau/optimizer.py @@ -4,59 +4,65 @@ import os import itertools -def make_0j_selector(tthr, ethr, e_t_DPhi, tMT): - def selector(row): - return row.tPt > tthr and \ - row.ePt > ethr and \ - row.e_t_DPhi > e_t_DPhi and \ - row.tMtToPfMet < tMT - return selector - -def make_1j_selector(tthr, ethr, tMT): - def selector(row): - return row.tPt > tthr and \ - row.ePt > ethr and \ - row.tMtToPfMet < tMT - return selector - -def make_2j_selector(tthr, ethr, tMT, vbfmass, vbfdeta): - def selector(row): - return row.tPt > tthr and \ - row.ePt > ethr and \ - row.tMtToPfMet < tMT and \ - row.vbfMass > vbfmass and \ - row.vbfDeta > vbfdeta - return selector - RUN_OPTIMIZATION = ('RUN_OPTIMIZATION' in os.environ) and eval(os.environ['RUN_OPTIMIZATION']) -grid_search = { - 0 : {}, - 1 : {}, - 2 : {}, +_0jets = { + 'tPt' : range(20,70,10)+[35,45], + 'ePt' : range(20,70,10)+[35,45], + 'dphi' : [3.14, 3.00, 2.7, 2.4, 2.2], + 'tMtToPfMet' : range(0,50,10)+[35], } +_0jet_region_template = 'tPt%i_ePt%i_dphi%.2f_tMtToPfMet%i' +def _get_0jet_regions(tPt, ePt, dphi, tMtToPfMet): + pass_tPt = [i for i in _0jets['tPt' ] if tPt > i] + pass_ePt = [i for i in _0jets['ePt' ] if ePt > i] + pass_dphi = [i for i in _0jets['dphi' ] if dphi > i] + pass_tMtToPfMet = [i for i in _0jets['tMtToPfMet'] if tMtToPfMet < i] + return [_0jet_region_template % i for i in itertools(pass_tPt, pass_ePt, pass_dphi, pass_tMtToPfMet)] -if RUN_OPTIMIZATION: - t_thrs = range(20,70,10)+[35,45] - e_thr = range(20,70,10)+[35,45] - mt_thr = range(0,50,10)+[35] - dphi = [3.14, 3.00, 2.7, 2.4, 2.2] - vbf_mass = range(400, 700, 100) + [550] - vbf_deta = [3.0, 3.5, 4.0] - - gg_template = 't%i_e%i_dp%.1f_mt%i' - for thresholds in itertools.product(t_thrs, e_thr, dphi, mt_thr): - grid_search[0][gg_template % thresholds] = make_0j_selector(*thresholds) +_1jets = { + 'tPt' : range(20,70,10)+[35,45], + 'ePt' : range(20,70,10)+[35,45], + 'tMtToPfMet' : range(0,50,10)+[35], +} +_1jet_region_template = 'tPt%i_ePt%i_tMtToPfMet%i' +def _get_1jet_regions(tPt, ePt, tMtToPfMet): + pass_tPt = [i for i in _1jets['tPt' ] if tPt > i] + pass_ePt = [i for i in _1jets['ePt' ] if ePt > i] + pass_tMtToPfMet = [i for i in _1jets['tMtToPfMet'] if tMtToPfMet < i] + return [_1jet_region_template % i for i in itertools(pass_tPt, pass_ePt, pass_tMtToPfMet)] + +_2jets = { + 'tPt' : range(20,70,10)+[35,45], + 'ePt' : range(20,70,10)+[35,45], + 'tMtToPfMet' : range(0,50,10)+[35], + 'vbf_mass' : range(400, 700, 100) + [550], + 'vbf_deta' : [3.0, 3.5, 4.0], +} +_2jet_region_template = 'tPt%i_ePt%i_tMtToPfMet%i_vbf_mass%i_vbf_deta%.1f' +def _get_2jet_regions(tPt, ePt, dphi, tMtToPfMet, vbf_mass, vbf_deta): + pass_tPt = [i for i in _2jets['tPt' ] if tPt > i] + pass_ePt = [i for i in _2jets['ePt' ] if ePt > i] + pass_tMtToPfMet = [i for i in _2jets['tMtToPfMet'] if tMtToPfMet < i] + pass_vbf_mass = [i for i in _2jets['vbf_mass'] if vbf_mass < i] + pass_vbf_deta = [i for i in _2jets['vbf_deta'] if vbf_deta < i] + return [_2jet_region_template % i for i in itertools(pass_tPt, pass_ePt, pass_tMtToPfMet, pass_vbf_mass, pass_vbf_deta)] - boost_template = 't%i_e%i_mt%i' - for thresholds in itertools.product(t_thrs, e_thr, mt_thr): - grid_search[1][boost_template % thresholds] = make_1j_selector(*thresholds) +def empty(*args): + return [] - vbf_template = 't%i_e%i_mt%i_vbfm%i_vbfeta%i' - for thresholds in itertools.product(t_thrs, e_thr, mt_thr, vbf_mass, vbf_deta): - grid_search[2][vbf_template % thresholds] = make_2j_selector(*thresholds) +compute_regions_0jet = _get_0jet_regions if RUN_OPTIMIZATION else empty +compute_regions_1jet = _get_1jet_regions if RUN_OPTIMIZATION else empty +compute_regions_2jet = _get_2jet_regions if RUN_OPTIMIZATION else empty +regions = {0 : [], 1 : [], 2 : []} +if RUN_OPTIMIZATION: + regions = { + 0 : [_0jet_region_template % i for i in itertools(_0jets['tPt'], _0jets['ePt'], _0jets['dphi'], _0jets['tMtToPfMet'])], + 1 : [_1jet_region_template % i for i in itertools(_1jets['tPt'], _1jets['ePt'], _1jets['tMtToPfMet'])], + 2 : [_2jet_region_template % i for i in itertools(_2jets['tPt'], _2jets['ePt'], _2jets['tMtToPfMet'], _2jets['vbf_mass'], _2jets['vbf_deta'])], + } if __name__ == "__main__": from pdb import set_trace From b5b965ea9f8f5c812d016563de4ccab7f156786e Mon Sep 17 00:00:00 2001 From: Mauro Verzetti Date: Fri, 12 Dec 2014 03:01:48 -0600 Subject: [PATCH 177/192] bugfix --- lfvetau/optimizer.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lfvetau/optimizer.py b/lfvetau/optimizer.py index c0fe2af8..94a121bf 100644 --- a/lfvetau/optimizer.py +++ b/lfvetau/optimizer.py @@ -18,7 +18,7 @@ def _get_0jet_regions(tPt, ePt, dphi, tMtToPfMet): pass_ePt = [i for i in _0jets['ePt' ] if ePt > i] pass_dphi = [i for i in _0jets['dphi' ] if dphi > i] pass_tMtToPfMet = [i for i in _0jets['tMtToPfMet'] if tMtToPfMet < i] - return [_0jet_region_template % i for i in itertools(pass_tPt, pass_ePt, pass_dphi, pass_tMtToPfMet)] + return [_0jet_region_template % i for i in itertools.product(pass_tPt, pass_ePt, pass_dphi, pass_tMtToPfMet)] _1jets = { @@ -31,7 +31,7 @@ def _get_1jet_regions(tPt, ePt, tMtToPfMet): pass_tPt = [i for i in _1jets['tPt' ] if tPt > i] pass_ePt = [i for i in _1jets['ePt' ] if ePt > i] pass_tMtToPfMet = [i for i in _1jets['tMtToPfMet'] if tMtToPfMet < i] - return [_1jet_region_template % i for i in itertools(pass_tPt, pass_ePt, pass_tMtToPfMet)] + return [_1jet_region_template % i for i in itertools.product(pass_tPt, pass_ePt, pass_tMtToPfMet)] _2jets = { 'tPt' : range(20,70,10)+[35,45], @@ -47,7 +47,7 @@ def _get_2jet_regions(tPt, ePt, dphi, tMtToPfMet, vbf_mass, vbf_deta): pass_tMtToPfMet = [i for i in _2jets['tMtToPfMet'] if tMtToPfMet < i] pass_vbf_mass = [i for i in _2jets['vbf_mass'] if vbf_mass < i] pass_vbf_deta = [i for i in _2jets['vbf_deta'] if vbf_deta < i] - return [_2jet_region_template % i for i in itertools(pass_tPt, pass_ePt, pass_tMtToPfMet, pass_vbf_mass, pass_vbf_deta)] + return [_2jet_region_template % i for i in itertools.product(pass_tPt, pass_ePt, pass_tMtToPfMet, pass_vbf_mass, pass_vbf_deta)] def empty(*args): return [] @@ -59,9 +59,9 @@ def empty(*args): regions = {0 : [], 1 : [], 2 : []} if RUN_OPTIMIZATION: regions = { - 0 : [_0jet_region_template % i for i in itertools(_0jets['tPt'], _0jets['ePt'], _0jets['dphi'], _0jets['tMtToPfMet'])], - 1 : [_1jet_region_template % i for i in itertools(_1jets['tPt'], _1jets['ePt'], _1jets['tMtToPfMet'])], - 2 : [_2jet_region_template % i for i in itertools(_2jets['tPt'], _2jets['ePt'], _2jets['tMtToPfMet'], _2jets['vbf_mass'], _2jets['vbf_deta'])], + 0 : [_0jet_region_template % i for i in itertools.product(_0jets['tPt'], _0jets['ePt'], _0jets['dphi'], _0jets['tMtToPfMet'])], + 1 : [_1jet_region_template % i for i in itertools.product(_1jets['tPt'], _1jets['ePt'], _1jets['tMtToPfMet'])], + 2 : [_2jet_region_template % i for i in itertools.product(_2jets['tPt'], _2jets['ePt'], _2jets['tMtToPfMet'], _2jets['vbf_mass'], _2jets['vbf_deta'])], } if __name__ == "__main__": From 846ef98366dbddc20639e06bb2827203524417b8 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Fri, 12 Dec 2014 03:26:06 -0600 Subject: [PATCH 178/192] optimizer --- lfvetau/optimizer.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lfvetau/optimizer.py b/lfvetau/optimizer.py index 94a121bf..a6fb18a5 100644 --- a/lfvetau/optimizer.py +++ b/lfvetau/optimizer.py @@ -7,10 +7,10 @@ RUN_OPTIMIZATION = ('RUN_OPTIMIZATION' in os.environ) and eval(os.environ['RUN_OPTIMIZATION']) _0jets = { - 'tPt' : range(20,70,10)+[35,45], - 'ePt' : range(20,70,10)+[35,45], + 'tPt' : range(30,50,10)+[35,45], + 'ePt' : range(30,70,10)+[35,45], 'dphi' : [3.14, 3.00, 2.7, 2.4, 2.2], - 'tMtToPfMet' : range(0,50,10)+[35], + 'tMtToPfMet' : range(20,50,10)+[35], } _0jet_region_template = 'tPt%i_ePt%i_dphi%.2f_tMtToPfMet%i' def _get_0jet_regions(tPt, ePt, dphi, tMtToPfMet): @@ -22,9 +22,9 @@ def _get_0jet_regions(tPt, ePt, dphi, tMtToPfMet): _1jets = { - 'tPt' : range(20,70,10)+[35,45], - 'ePt' : range(20,70,10)+[35,45], - 'tMtToPfMet' : range(0,50,10)+[35], + 'tPt' : range(30,60,10)+[35,45], + 'ePt' : range(30,70,10)+[35,45], + 'tMtToPfMet' : range(20,50,10)+[35], } _1jet_region_template = 'tPt%i_ePt%i_tMtToPfMet%i' def _get_1jet_regions(tPt, ePt, tMtToPfMet): @@ -34,11 +34,11 @@ def _get_1jet_regions(tPt, ePt, tMtToPfMet): return [_1jet_region_template % i for i in itertools.product(pass_tPt, pass_ePt, pass_tMtToPfMet)] _2jets = { - 'tPt' : range(20,70,10)+[35,45], - 'ePt' : range(20,70,10)+[35,45], + 'tPt' : range(30,50,10)+[35,45], + 'ePt' : range(30,70,10)+[35,45], 'tMtToPfMet' : range(0,50,10)+[35], - 'vbf_mass' : range(400, 700, 100) + [550], - 'vbf_deta' : [3.0, 3.5, 4.0], + 'vbf_mass' : range(400, 600, 100) + [550], + 'vbf_deta' : [2.5, 3.0, 3.5, 4.0], } _2jet_region_template = 'tPt%i_ePt%i_tMtToPfMet%i_vbf_mass%i_vbf_deta%.1f' def _get_2jet_regions(tPt, ePt, dphi, tMtToPfMet, vbf_mass, vbf_deta): From 1fb00cec30a75d4ae9b15197275ede4ba12f74e2 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Fri, 12 Dec 2014 05:12:02 -0600 Subject: [PATCH 179/192] cut optimizer --- lfvetau/LFVHETauAnalyzerMVA.py | 125 +++++++++++++++++++-------------- lfvetau/optimizer.py | 18 ++--- 2 files changed, 83 insertions(+), 60 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index d2ee1d0b..f9c6a8c1 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -20,6 +20,7 @@ from FinalStateAnalysis.PlotTools.decorators import memo import FinalStateAnalysis.PlotTools.pytree as pytree from FinalStateAnalysis.Utilities.struct import struct +import optimizer @memo def getVar(name, var): @@ -129,12 +130,12 @@ def __init__(self, tree, outfile, **kwargs): self.systematics = { 'trig' : (['', 'trp1s', 'trm1s'] if not self.is_data else []), 'pu' : (['', 'p1s', 'm1s'] if self.is_mc else []), - 'eid' : (['', 'eidp1s','eidm1s'] if not self.is_data else []), - 'eiso' : (['', 'eisop1s','eisom1s'] if not self.is_data else []), + 'eid' : (['', 'eidp1s','eidm1s'] if False else []), + 'eiso' : (['', 'eisop1s','eisom1s'] if False else []), 'jes' : (['', '_jes_plus','_jes_minus'] if self.is_mc else ['']), - 'mvetos': (['', 'mVetoUp', 'mVetoDown'] if self.is_mc else ['']), - 'tvetos': (['', 'tVetoUp', 'tVetoDown'] if self.is_mc else ['']), - 'evetos': (['', 'eVetoUp', 'eVetoDown'] if self.is_mc else ['']), + 'mvetos': (['', 'mVetoUp', 'mVetoDown'] if False else ['']), + 'tvetos': (['', 'tVetoUp', 'tVetoDown'] if False else ['']), + 'evetos': (['', 'eVetoUp', 'eVetoDown'] if False else ['']), 'met' : (["_mes_plus", "_ues_plus", "_mes_minus", "_ues_minus"] if self.is_mc else []), 'tes' : (["", "_tes_plus", "_tes_minus"] if not self.is_data else ['']), 'ees' : (["", "_ees_plus", '_ees_minus'] if not self.is_data else ['']) @@ -246,6 +247,11 @@ def begin(self): path = list(tuple_path) path.append('selected') folder.append(os.path.join(*path)) + prefix_path = os.path.join(*tuple_path) + for region in optimizer.regions[tuple_path[-1]]: + folder.append( + os.path.join(prefix_path, region) + ) def book_with_sys(location, name, *args, **kwargs): postfixes = kwargs['postfixes'] @@ -266,57 +272,57 @@ def book_with_sys(location, name, *args, **kwargs): # 'run/l:lumi/l:evt/l:weight/D', # type=pytree.PyTree #) - self.book(f,"weight", "weight", 100, 0, 10) - self.book(f,"tPt", "tau p_{T}", 40, 0, 200) - self.book(f,"tPt_tes_plus", "tau p_{T} (tes+)", 40, 0, 200) - self.book(f,"tPt_tes_minus", "tau p_{T} (tes-)",40, 0, 200) - - self.book(f,"tPhi", "tau phi", 26, -3.25, 3.25) - self.book(f,"tEta", "tau eta", 10, -2.5, 2.5) - - self.book(f,"ePt", "e p_{T}", 40, 0, 200) - self.book(f,"ePt_ees_plus", "e p_{T} (ees+)", 40, 0, 200) - self.book(f,"ePt_ees_minus", "e p_{T} (ees-)",40, 0, 200) - - self.book(f,"ePhi", "e phi", 26, -3.2, 3.2) - self.book(f,"eEta", "e eta", 10, -2.5, 2.5) - - self.book(f, "e_t_DPhi", "e-tau DeltaPhi" , 20, 0, 3.2) - self.book(f, "e_t_DR", "e-tau DeltaR" , 20, 0, 3.2) + #@# self.book(f,"weight", "weight", 100, 0, 10) + #@# self.book(f,"tPt", "tau p_{T}", 40, 0, 200) + #@# self.book(f,"tPt_tes_plus", "tau p_{T} (tes+)", 40, 0, 200) + #@# self.book(f,"tPt_tes_minus", "tau p_{T} (tes-)",40, 0, 200) + #@# + #@# self.book(f,"tPhi", "tau phi", 26, -3.25, 3.25) + #@# self.book(f,"tEta", "tau eta", 10, -2.5, 2.5) + #@# + #@# self.book(f,"ePt", "e p_{T}", 40, 0, 200) + #@# self.book(f,"ePt_ees_plus", "e p_{T} (ees+)", 40, 0, 200) + #@# self.book(f,"ePt_ees_minus", "e p_{T} (ees-)",40, 0, 200) + #@# + #@# self.book(f,"ePhi", "e phi", 26, -3.2, 3.2) + #@# self.book(f,"eEta", "e eta", 10, -2.5, 2.5) + #@# + #@# self.book(f, "e_t_DPhi", "e-tau DeltaPhi" , 20, 0, 3.2) + #@# self.book(f, "e_t_DR", "e-tau DeltaR" , 20, 0, 3.2) #self.book(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320) book_with_sys(f, "h_collmass_pfmet", "h_collmass_pfmet", 40, 0, 400, postfixes=full_met_systematics) - self.book(f, "h_collmass_vs_dPhi_pfmet", "h_collmass_vs_dPhi_pfmet", 20, 0, 3.2, 40, 0, 400, type=ROOT.TH2F) - - self.book(f, "e_t_Mass", "h_vismass", 40, 0, 400) - self.book(f, "e_t_Mass_tes_plus" , "h_vismass_tes_plus", 40 , 0, 400) - self.book(f, "e_t_Mass_tes_minus", "h_vismass_tes_minus",40 , 0, 400) - self.book(f, "e_t_Mass_ees_plus" , "h_vismass_ees_plus", 40 , 0, 400) - self.book(f, "e_t_Mass_ees_minus", "h_vismass_ees_minus",40 , 0, 400) - - self.book(f, "MetEt_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 20, 0, 3.2, 40, 0, 400, type=ROOT.TH2F) - - self.book(f, "tPFMET_DeltaPhi", "tau-type1PFMET DeltaPhi" , 20, 0, 3.2) - - self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 20, 0, 3.2) - - #self.book(f,"tMtToPFMET", "tau-PFMET M_{T}" , 200, 0, 200) - book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 40, 0, 200, - postfixes=full_met_systematics) - #self.book(f,"eMtToPFMET", "e-PFMET M_{T}" , 200, 0, 200) - book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 40, 0, 200, - postfixes=full_met_systematics) - - #self.book(f, "pfMetEt", "pfMetEt", 200, 0, 200) - book_with_sys(f, "pfMet_Et", "pfMet_Et", 40, 0, 200, postfixes=full_met_systematics) - - #self.book(f, "pfMetPhi", "pfMetPhi", 100, -3.2, 3.2) - book_with_sys(f, "pfMet_Phi", "pfMet_Phi", 26, -3.2, 3.2, postfixes=full_met_systematics) - - self.book(f, "jetVeto20", "Number of jets, p_{T}>20", 5, -0.5, 4.5) - self.book(f, "jetVeto30", "Number of jets, p_{T}>30", 5, -0.5, 4.5) + #@# self.book(f, "h_collmass_vs_dPhi_pfmet", "h_collmass_vs_dPhi_pfmet", 20, 0, 3.2, 40, 0, 400, type=ROOT.TH2F) + #@# + #@# self.book(f, "e_t_Mass", "h_vismass", 40, 0, 400) + #@# self.book(f, "e_t_Mass_tes_plus" , "h_vismass_tes_plus", 40 , 0, 400) + #@# self.book(f, "e_t_Mass_tes_minus", "h_vismass_tes_minus",40 , 0, 400) + #@# self.book(f, "e_t_Mass_ees_plus" , "h_vismass_ees_plus", 40 , 0, 400) + #@# self.book(f, "e_t_Mass_ees_minus", "h_vismass_ees_minus",40 , 0, 400) + #@# + #@# self.book(f, "MetEt_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 20, 0, 3.2, 40, 0, 400, type=ROOT.TH2F) + #@# + #@# self.book(f, "tPFMET_DeltaPhi", "tau-type1PFMET DeltaPhi" , 20, 0, 3.2) + #@# + #@# self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 20, 0, 3.2) + #@# + #@# #self.book(f,"tMtToPFMET", "tau-PFMET M_{T}" , 200, 0, 200) + #@# book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 40, 0, 200, + #@# postfixes=full_met_systematics) + #@# #self.book(f,"eMtToPFMET", "e-PFMET M_{T}" , 200, 0, 200) + #@# book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 40, 0, 200, + #@# postfixes=full_met_systematics) + #@# + #@# #self.book(f, "pfMetEt", "pfMetEt", 200, 0, 200) + #@# book_with_sys(f, "pfMet_Et", "pfMet_Et", 40, 0, 200, postfixes=full_met_systematics) + #@# + #@# #self.book(f, "pfMetPhi", "pfMetPhi", 100, -3.2, 3.2) + #@# book_with_sys(f, "pfMet_Phi", "pfMet_Phi", 26, -3.2, 3.2, postfixes=full_met_systematics) + #@# + #@# self.book(f, "jetVeto20", "Number of jets, p_{T}>20", 5, -0.5, 4.5) + #@# self.book(f, "jetVeto30", "Number of jets, p_{T}>30", 5, -0.5, 4.5) #index dirs and histograms for key, value in self.histograms.iteritems(): @@ -516,6 +522,12 @@ def process(self): continue if shifted.njets == 0 : + selection_categories.extend([ + (name, '0', i) for i in optimizer.compute_regions_0jet( + shifted.tPt, shifted.ePt, deltaPhi(row.ePhi, row.tPhi), + row.tMtToPfMet) + ]) + if shifted.tPt < 30: continue #was 35 if shifted.ePt < 50: continue #was 40 if deltaPhi(row.ePhi, row.tPhi) < 2.5 : continue #was 2.7 @@ -523,12 +535,23 @@ def process(self): selection_categories.append((name, '0', 'selected')) passes_full_selection = True elif shifted.njets == 1 : + selection_categories.extend([ + (name, '1', i) for i in optimizer.compute_regions_1jet( + shifted.tPt, shifted.ePt, row.tMtToPfMet) + ]) + if shifted.tPt < 30: continue #was 40 if shifted.ePt < 40: continue #was 35 if row.tMtToPfMet > 45 : continue #was 35 selection_categories.append((name, '1', 'selected')) passes_full_selection = True elif shifted.njets == 2 : + selection_categories.extend([ + (name, '2', i) for i in optimizer.compute_regions_2jet( + shifted.tPt, shifted.ePt, row.tMtToPfMet, row.vbfMass, + row.vbfDeta) + ]) + if shifted.tPt < 30: continue #was 40 if shifted.ePt < 40: continue #was 30 if row.tMtToPfMet > 55 : continue #was 35 diff --git a/lfvetau/optimizer.py b/lfvetau/optimizer.py index a6fb18a5..c2fdd070 100644 --- a/lfvetau/optimizer.py +++ b/lfvetau/optimizer.py @@ -1,4 +1,4 @@ -#author Mauro Verzetti + #author Mauro Verzetti 'small interface module to deal with optimizization' import os @@ -41,12 +41,12 @@ def _get_1jet_regions(tPt, ePt, tMtToPfMet): 'vbf_deta' : [2.5, 3.0, 3.5, 4.0], } _2jet_region_template = 'tPt%i_ePt%i_tMtToPfMet%i_vbf_mass%i_vbf_deta%.1f' -def _get_2jet_regions(tPt, ePt, dphi, tMtToPfMet, vbf_mass, vbf_deta): +def _get_2jet_regions(tPt, ePt, tMtToPfMet, vbf_mass, vbf_deta): pass_tPt = [i for i in _2jets['tPt' ] if tPt > i] pass_ePt = [i for i in _2jets['ePt' ] if ePt > i] pass_tMtToPfMet = [i for i in _2jets['tMtToPfMet'] if tMtToPfMet < i] - pass_vbf_mass = [i for i in _2jets['vbf_mass'] if vbf_mass < i] - pass_vbf_deta = [i for i in _2jets['vbf_deta'] if vbf_deta < i] + pass_vbf_mass = [i for i in _2jets['vbf_mass'] if vbf_mass > i] + pass_vbf_deta = [i for i in _2jets['vbf_deta'] if vbf_deta > i] return [_2jet_region_template % i for i in itertools.product(pass_tPt, pass_ePt, pass_tMtToPfMet, pass_vbf_mass, pass_vbf_deta)] def empty(*args): @@ -56,13 +56,13 @@ def empty(*args): compute_regions_1jet = _get_1jet_regions if RUN_OPTIMIZATION else empty compute_regions_2jet = _get_2jet_regions if RUN_OPTIMIZATION else empty -regions = {0 : [], 1 : [], 2 : []} +regions = {'0' : [], '1' : [], '2' : [], '3' : []} if RUN_OPTIMIZATION: regions = { - 0 : [_0jet_region_template % i for i in itertools.product(_0jets['tPt'], _0jets['ePt'], _0jets['dphi'], _0jets['tMtToPfMet'])], - 1 : [_1jet_region_template % i for i in itertools.product(_1jets['tPt'], _1jets['ePt'], _1jets['tMtToPfMet'])], - 2 : [_2jet_region_template % i for i in itertools.product(_2jets['tPt'], _2jets['ePt'], _2jets['tMtToPfMet'], _2jets['vbf_mass'], _2jets['vbf_deta'])], - } + '0' : [_0jet_region_template % i for i in itertools.product(_0jets['tPt'], _0jets['ePt'], _0jets['dphi'], _0jets['tMtToPfMet'])], + '1' : [_1jet_region_template % i for i in itertools.product(_1jets['tPt'], _1jets['ePt'], _1jets['tMtToPfMet'])], + '2' : [_2jet_region_template % i for i in itertools.product(_2jets['tPt'], _2jets['ePt'], _2jets['tMtToPfMet'], _2jets['vbf_mass'], _2jets['vbf_deta'])], + '3' : []} if __name__ == "__main__": from pdb import set_trace From 96a698a95f7b13207e361df6a6bd91e616ec152f Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Sun, 14 Dec 2014 08:51:09 -0600 Subject: [PATCH 180/192] try to reduce the combination --- lfvetau/optimizer.py | 49 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/lfvetau/optimizer.py b/lfvetau/optimizer.py index c2fdd070..2dd2cba9 100644 --- a/lfvetau/optimizer.py +++ b/lfvetau/optimizer.py @@ -4,14 +4,20 @@ import os import itertools -RUN_OPTIMIZATION = ('RUN_OPTIMIZATION' in os.environ) and eval(os.environ['RUN_OPTIMIZATION']) - +#RUN_OPTIMIZATION = ('RUN_OPTIMIZATION' in os.environ) and eval(os.environ['RUN_OPTIMIZATION']) +RUN_OPTIMIZATION = True _0jets = { - 'tPt' : range(30,50,10)+[35,45], - 'ePt' : range(30,70,10)+[35,45], - 'dphi' : [3.14, 3.00, 2.7, 2.4, 2.2], + 'tPt' : [30],#range(30,50,10)+[35,45], + 'ePt' : [40],#range(30,70,10)+[35,45], + 'dphi' : [3.00, 2.7, 2.4, 2.2], 'tMtToPfMet' : range(20,50,10)+[35], } +_0jets_default = { + 'tPt' : 30, + 'ePt' : 50, + 'dphi': 2.5, + 'tMtToPfMet' :50, +} _0jet_region_template = 'tPt%i_ePt%i_dphi%.2f_tMtToPfMet%i' def _get_0jet_regions(tPt, ePt, dphi, tMtToPfMet): pass_tPt = [i for i in _0jets['tPt' ] if tPt > i] @@ -19,27 +25,44 @@ def _get_0jet_regions(tPt, ePt, dphi, tMtToPfMet): pass_dphi = [i for i in _0jets['dphi' ] if dphi > i] pass_tMtToPfMet = [i for i in _0jets['tMtToPfMet'] if tMtToPfMet < i] return [_0jet_region_template % i for i in itertools.product(pass_tPt, pass_ePt, pass_dphi, pass_tMtToPfMet)] + #return [_0jet_region_template % i for i in itertools.product(pass_tPt, [_0jets_default['ePt']], [_0jets_default['dphi']], [_0jets_default['tMtToPfMet']])]+[_0jet_region_template % i for i in itertools.product([_0jets_default['tPt']] , pass_ePt, [_0jets_default['dphi']], [_0jets_default['tMtToPfMet']])] _1jets = { - 'tPt' : range(30,60,10)+[35,45], - 'ePt' : range(30,70,10)+[35,45], + 'tPt' : [30],#range(30,60,10)+[35,45], + 'ePt' : [40],#range(30,70,10)+[35,45], 'tMtToPfMet' : range(20,50,10)+[35], } +_1jets_default = { + 'tPt' : 30, + 'ePt' : 40, + 'tMtToPfMet' :35, +} + _1jet_region_template = 'tPt%i_ePt%i_tMtToPfMet%i' def _get_1jet_regions(tPt, ePt, tMtToPfMet): pass_tPt = [i for i in _1jets['tPt' ] if tPt > i] pass_ePt = [i for i in _1jets['ePt' ] if ePt > i] pass_tMtToPfMet = [i for i in _1jets['tMtToPfMet'] if tMtToPfMet < i] return [_1jet_region_template % i for i in itertools.product(pass_tPt, pass_ePt, pass_tMtToPfMet)] - + #return [_1jet_region_template % i for i in itertools.product(pass_tPt, [_1jets_default['ePt']],[_1jets_default['tMtToPfMet']])] + + _2jets = { - 'tPt' : range(30,50,10)+[35,45], - 'ePt' : range(30,70,10)+[35,45], + 'tPt' : [30],#range(30,50,10)+[35,45], + 'ePt' : [40], #range(30,70,10)+[35,45], 'tMtToPfMet' : range(0,50,10)+[35], 'vbf_mass' : range(400, 600, 100) + [550], 'vbf_deta' : [2.5, 3.0, 3.5, 4.0], } +_2jets_default = { + 'tPt' : 30, + 'ePt' : 40, + 'tMtToPfMet' : 35, + 'vbf_mass' : 400, + 'vbf_deta' : 2.5, +} + _2jet_region_template = 'tPt%i_ePt%i_tMtToPfMet%i_vbf_mass%i_vbf_deta%.1f' def _get_2jet_regions(tPt, ePt, tMtToPfMet, vbf_mass, vbf_deta): pass_tPt = [i for i in _2jets['tPt' ] if tPt > i] @@ -48,6 +71,9 @@ def _get_2jet_regions(tPt, ePt, tMtToPfMet, vbf_mass, vbf_deta): pass_vbf_mass = [i for i in _2jets['vbf_mass'] if vbf_mass > i] pass_vbf_deta = [i for i in _2jets['vbf_deta'] if vbf_deta > i] return [_2jet_region_template % i for i in itertools.product(pass_tPt, pass_ePt, pass_tMtToPfMet, pass_vbf_mass, pass_vbf_deta)] + #return [_2jet_region_template % i for i in itertools.product(pass_tPt, [_2jets_default['ePt']],[_2jets_default['tMtToPfMet']], [_2jets_default['vbf_mass']], [_2jets_default['vbf_deta']])] + + def empty(*args): return [] @@ -62,6 +88,9 @@ def empty(*args): '0' : [_0jet_region_template % i for i in itertools.product(_0jets['tPt'], _0jets['ePt'], _0jets['dphi'], _0jets['tMtToPfMet'])], '1' : [_1jet_region_template % i for i in itertools.product(_1jets['tPt'], _1jets['ePt'], _1jets['tMtToPfMet'])], '2' : [_2jet_region_template % i for i in itertools.product(_2jets['tPt'], _2jets['ePt'], _2jets['tMtToPfMet'], _2jets['vbf_mass'], _2jets['vbf_deta'])], + #'0':[_0jet_region_template % i for i in itertools.product(_0jets['tPt'], [_0jets_default['ePt']], [_0jets_default['dphi']], [_0jets_default['tMtToPfMet']])] + [_0jet_region_template % i for i in itertools.product([_0jets_default['tPt']] , _0jets['ePt'], [_0jets_default['dphi']], [_0jets_default['tMtToPfMet']])], + #'1':[_1jet_region_template % i for i in itertools.product(_1jets['tPt'], [_1jets_default['ePt']],[_1jets_default['tMtToPfMet']])], + #'2':[_2jet_region_template % i for i in itertools.product(_2jets['tPt'], [_2jets_default['ePt']],[_2jets_default['tMtToPfMet']], [_2jets_default['vbf_mass']], [_2jets_default['vbf_deta']])], '3' : []} if __name__ == "__main__": From 649645769660d15f7e49b1057d31384009110c6b Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Mon, 22 Dec 2014 04:48:12 -0600 Subject: [PATCH 181/192] optimization --- lfvetau/LFVHETauAnalyzerMVA.py | 4 ++ lfvetau/Rakefile | 6 ++ lfvetau/optimizer.py | 125 +++++++++++++++++++++++---------- 3 files changed, 97 insertions(+), 38 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index f9c6a8c1..a02e8386 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -252,6 +252,7 @@ def begin(self): folder.append( os.path.join(prefix_path, region) ) + def book_with_sys(location, name, *args, **kwargs): postfixes = kwargs['postfixes'] @@ -266,6 +267,7 @@ def book_with_sys(location, name, *args, **kwargs): self.book('os/gg/ept30/', "e_t_Mass", "h_vismass", 32, 0, 320) for f in folder: + #print f #self.book( # f, # 'evtInfo', 'evtInfo', @@ -522,6 +524,7 @@ def process(self): continue if shifted.njets == 0 : + selection_categories.extend([ (name, '0', i) for i in optimizer.compute_regions_0jet( shifted.tPt, shifted.ePt, deltaPhi(row.ePhi, row.tPhi), @@ -628,6 +631,7 @@ def process(self): lock = evt_id dir_name = os.path.join(sys, selection_sys, sign, processtype, e_thr, jet_dir, selection_step) + if dir_name[-1] == '/': dir_name = dir_name[:-1] if passes_full_selection: diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index 64fd3b29..3103bc88 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -333,6 +333,12 @@ task :recoplotsMVA => get_analyzer_results("LFVHETauAnalyzerMVA.py", samples['si samples['Zembedded']+ samples['dataSingleE'] ) +task :testMVA => get_analyzer_results("LFVHETauAnalyzerMVA.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + + samples['Zembedded']+ + samples['dataSingleE'] + ) + task :recoplotsMVAeMtcut => get_analyzer_results("LFVHETauAnalyzerMVA_eMTCut.py", samples['signalMCgg'] + samples['signalMCvbf'] + samples['ggHiggsTo2Taus'] + samples['vbfHiggsTo2Taus'] + samples['ttbar'] + samples['singlet'] + samples['singletbar'] + samples['wjets'] + samples['wwjets'] + samples['wzjets'] + samples['zzjets'] + samples['zjets'] + samples['dataSingleE'] ) diff --git a/lfvetau/optimizer.py b/lfvetau/optimizer.py index 2dd2cba9..489a805c 100644 --- a/lfvetau/optimizer.py +++ b/lfvetau/optimizer.py @@ -6,31 +6,42 @@ #RUN_OPTIMIZATION = ('RUN_OPTIMIZATION' in os.environ) and eval(os.environ['RUN_OPTIMIZATION']) RUN_OPTIMIZATION = True + _0jets = { - 'tPt' : [30],#range(30,50,10)+[35,45], - 'ePt' : [40],#range(30,70,10)+[35,45], - 'dphi' : [3.00, 2.7, 2.4, 2.2], - 'tMtToPfMet' : range(20,50,10)+[35], + 'tPt' : range(30,50,10)+[35,45], + 'ePt' : range(30,50,10)+[35,45], + 'dphi' : [3.00, 2.7, 2.4, 2.2], + 'tMtToPfMet' : range(20,50,10)+[35], } _0jets_default = { - 'tPt' : 30, - 'ePt' : 50, - 'dphi': 2.5, - 'tMtToPfMet' :50, + 'tPt' : 30, + 'ePt' : 50, + 'dphi': 2.5, + 'tMtToPfMet' :50, } -_0jet_region_template = 'tPt%i_ePt%i_dphi%.2f_tMtToPfMet%i' +_0jet_region_templates = ['tPt%i', 'ePt%i', 'dphi%.2f', 'tMtToPfMet%i'] #'tPt%i_ePt%i_dphi%.2f_tMtToPfMet%i' def _get_0jet_regions(tPt, ePt, dphi, tMtToPfMet): - pass_tPt = [i for i in _0jets['tPt' ] if tPt > i] - pass_ePt = [i for i in _0jets['ePt' ] if ePt > i] - pass_dphi = [i for i in _0jets['dphi' ] if dphi > i] - pass_tMtToPfMet = [i for i in _0jets['tMtToPfMet'] if tMtToPfMet < i] - return [_0jet_region_template % i for i in itertools.product(pass_tPt, pass_ePt, pass_dphi, pass_tMtToPfMet)] - #return [_0jet_region_template % i for i in itertools.product(pass_tPt, [_0jets_default['ePt']], [_0jets_default['dphi']], [_0jets_default['tMtToPfMet']])]+[_0jet_region_template % i for i in itertools.product([_0jets_default['tPt']] , pass_ePt, [_0jets_default['dphi']], [_0jets_default['tMtToPfMet']])] + pass_tPt = [i for i in _0jets['tPt' ] if tPt > i] + pass_ePt = [i for i in _0jets['ePt' ] if ePt > i] + pass_dphi = [i for i in _0jets['dphi' ] if dphi > i] + pass_tMtToPfMet = [i for i in _0jets['tMtToPfMet'] if tMtToPfMet < i] + cuts = [pass_tPt, pass_ePt, pass_dphi, pass_tMtToPfMet] + pass_default_tPt = tPt > _0jets_default['tPt' ] + pass_default_ePt = ePt > _0jets_default['ePt' ] + pass_default_dphi = dphi > _0jets_default['dphi' ] + pass_default_tMtToPfMet = tMtToPfMet < _0jets_default['tMtToPfMet'] + defaults = [pass_default_tPt, pass_default_ePt, pass_default_dphi, pass_default_tMtToPfMet] + ret = [] + for cut_idx, opts in enumerate(cuts): + if all(j for i,j in enumerate(defaults) if i != cut_idx): + ret.extend([_0jet_region_templates[cut_idx] % i for i in opts]) + + return ret _1jets = { - 'tPt' : [30],#range(30,60,10)+[35,45], - 'ePt' : [40],#range(30,70,10)+[35,45], + 'tPt' : range(30,50,10)+[35,45], + 'ePt' : range(30,50,10)+[35,45], 'tMtToPfMet' : range(20,50,10)+[35], } _1jets_default = { @@ -39,19 +50,31 @@ def _get_0jet_regions(tPt, ePt, dphi, tMtToPfMet): 'tMtToPfMet' :35, } -_1jet_region_template = 'tPt%i_ePt%i_tMtToPfMet%i' +_1jet_region_templates = ['tPt%i', 'ePt%i', 'tMtToPfMet%i']#'tPt%i_ePt%i_tMtToPfMet%i' def _get_1jet_regions(tPt, ePt, tMtToPfMet): - pass_tPt = [i for i in _1jets['tPt' ] if tPt > i] - pass_ePt = [i for i in _1jets['ePt' ] if ePt > i] - pass_tMtToPfMet = [i for i in _1jets['tMtToPfMet'] if tMtToPfMet < i] - return [_1jet_region_template % i for i in itertools.product(pass_tPt, pass_ePt, pass_tMtToPfMet)] - #return [_1jet_region_template % i for i in itertools.product(pass_tPt, [_1jets_default['ePt']],[_1jets_default['tMtToPfMet']])] + pass_tPt = [i for i in _1jets['tPt' ] if tPt > i] + pass_ePt = [i for i in _1jets['ePt' ] if ePt > i] + pass_tMtToPfMet = [i for i in _1jets['tMtToPfMet'] if tMtToPfMet < i] + + cuts = [pass_tPt, pass_ePt, pass_tMtToPfMet] + pass_default_tPt = tPt > _1jets_default['tPt' ] + pass_default_ePt = ePt > _1jets_default['ePt' ] + pass_default_tMtToPfMet = tMtToPfMet < _1jets_default['tMtToPfMet'] + + defaults = [pass_default_tPt, pass_default_ePt, pass_default_tMtToPfMet] + ret = [] + for cut_idx, opts in enumerate(cuts): + if all(j for i,j in enumerate(defaults) if i != cut_idx): + ret.extend([_1jet_region_templates[cut_idx] % i for i in opts]) + + return ret + _2jets = { - 'tPt' : [30],#range(30,50,10)+[35,45], - 'ePt' : [40], #range(30,70,10)+[35,45], - 'tMtToPfMet' : range(0,50,10)+[35], + 'tPt' : range(30,50,10)+[35,45], + 'ePt' : range(30,50,10)+[35,45], + 'tMtToPfMet' : range(20,50,10)+[35], 'vbf_mass' : range(400, 600, 100) + [550], 'vbf_deta' : [2.5, 3.0, 3.5, 4.0], } @@ -63,36 +86,62 @@ def _get_1jet_regions(tPt, ePt, tMtToPfMet): 'vbf_deta' : 2.5, } -_2jet_region_template = 'tPt%i_ePt%i_tMtToPfMet%i_vbf_mass%i_vbf_deta%.1f' +_2jet_region_templates = ['tPt%i', 'ePt%i', 'tMtToPfMet%i', 'vbf_mass%i', 'vbf_deta%.1f' ]#'tPt%i_ePt%i_tMtToPfMet%i_vbf_mass%i_vbf_deta%.1f' def _get_2jet_regions(tPt, ePt, tMtToPfMet, vbf_mass, vbf_deta): - pass_tPt = [i for i in _2jets['tPt' ] if tPt > i] - pass_ePt = [i for i in _2jets['ePt' ] if ePt > i] + pass_tPt = [i for i in _2jets['tPt' ] if tPt > i] + pass_ePt = [i for i in _2jets['ePt' ] if ePt > i] pass_tMtToPfMet = [i for i in _2jets['tMtToPfMet'] if tMtToPfMet < i] pass_vbf_mass = [i for i in _2jets['vbf_mass'] if vbf_mass > i] pass_vbf_deta = [i for i in _2jets['vbf_deta'] if vbf_deta > i] - return [_2jet_region_template % i for i in itertools.product(pass_tPt, pass_ePt, pass_tMtToPfMet, pass_vbf_mass, pass_vbf_deta)] - #return [_2jet_region_template % i for i in itertools.product(pass_tPt, [_2jets_default['ePt']],[_2jets_default['tMtToPfMet']], [_2jets_default['vbf_mass']], [_2jets_default['vbf_deta']])] + + cuts = [pass_tPt, pass_ePt, pass_tMtToPfMet, pass_vbf_mass, pass_vbf_deta] + pass_default_tPt = tPt > _2jets_default['tPt' ] + pass_default_ePt = ePt > _2jets_default['ePt' ] + pass_default_tMtToPfMet = tMtToPfMet < _2jets_default['tMtToPfMet'] + pass_default_vbf_mass = vbf_mass > _2jets_default['vbf_mass'] + pass_default_vbf_deta = vbf_deta > _2jets_default['vbf_deta'] + + defaults = [pass_default_tPt, pass_default_ePt, pass_default_tMtToPfMet, pass_default_vbf_mass, pass_default_vbf_deta] + ret = [] + for cut_idx, opts in enumerate(cuts): + if all(j for i,j in enumerate(defaults) if i != cut_idx): + ret.extend([_2jet_region_templates[cut_idx] % i for i in opts]) + + return ret - + def empty(*args): return [] - +## compute_regions_0jet = _get_0jet_regions if RUN_OPTIMIZATION else empty compute_regions_1jet = _get_1jet_regions if RUN_OPTIMIZATION else empty compute_regions_2jet = _get_2jet_regions if RUN_OPTIMIZATION else empty - +## +ret0 = [] +defaults = [_0jets_default['tPt'], _0jets_default['ePt'], _0jets_default['dphi'], _0jets_default['tMtToPfMet']] +cuts0 = [_0jets['tPt'], _0jets['ePt'], _0jets['dphi'], _0jets['tMtToPfMet']] +cuts1 = [_1jets['tPt'], _1jets['ePt'], _1jets['tMtToPfMet']] +cuts2 = [_2jets['tPt'], _2jets['ePt'], _2jets['tMtToPfMet'], _2jets['vbf_mass'], _2jets['vbf_deta']] +for cut_idx, opts in enumerate(cuts0): + if all(j for i,j in enumerate(defaults) if i != cut_idx): + ret0.extend([_0jet_region_templates[cut_idx] % i for i in opts]) + regions = {'0' : [], '1' : [], '2' : [], '3' : []} + if RUN_OPTIMIZATION: + regions = { - '0' : [_0jet_region_template % i for i in itertools.product(_0jets['tPt'], _0jets['ePt'], _0jets['dphi'], _0jets['tMtToPfMet'])], - '1' : [_1jet_region_template % i for i in itertools.product(_1jets['tPt'], _1jets['ePt'], _1jets['tMtToPfMet'])], - '2' : [_2jet_region_template % i for i in itertools.product(_2jets['tPt'], _2jets['ePt'], _2jets['tMtToPfMet'], _2jets['vbf_mass'], _2jets['vbf_deta'])], + '0' : [_0jet_region_templates[cut_idx] % i for cut_idx, opts in enumerate(cuts0) for i in opts],#itertools.product(_0jets['tPt'], _0jets['ePt'], _0jets['dphi'], _0jets['tMtToPfMet'])], + '1' : [_1jet_region_templates[cut_idx] % i for cut_idx, opts in enumerate(cuts1) for i in opts],#[_1jet_region_template % i for i in itertools.product(_1jets['tPt'], _1jets['ePt'], _1jets['tMtToPfMet'])], + '2' : [_2jet_region_templates[cut_idx] % i for cut_idx, opts in enumerate(cuts2) for i in opts],#[_2jet_region_template % i for i in itertools.product(_2jets['tPt'], _2jets['ePt'], _2jets['tMtToPfMet'], _2jets['vbf_mass'], _2jets['vbf_deta'])], #'0':[_0jet_region_template % i for i in itertools.product(_0jets['tPt'], [_0jets_default['ePt']], [_0jets_default['dphi']], [_0jets_default['tMtToPfMet']])] + [_0jet_region_template % i for i in itertools.product([_0jets_default['tPt']] , _0jets['ePt'], [_0jets_default['dphi']], [_0jets_default['tMtToPfMet']])], #'1':[_1jet_region_template % i for i in itertools.product(_1jets['tPt'], [_1jets_default['ePt']],[_1jets_default['tMtToPfMet']])], #'2':[_2jet_region_template % i for i in itertools.product(_2jets['tPt'], [_2jets_default['ePt']],[_2jets_default['tMtToPfMet']], [_2jets_default['vbf_mass']], [_2jets_default['vbf_deta']])], '3' : []} - + + print regions['0'] + if __name__ == "__main__": from pdb import set_trace set_trace() From 1dd3f32499eee7091fdfe5269495303b17e0ce04 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Wed, 14 Jan 2015 10:10:56 -0600 Subject: [PATCH 182/192] shape for optimization studies --- lfvetau/BasePlotter.py | 243 ++++++++++++++++++++++++++++----- lfvetau/LFVHETauAnalyzerMVA.py | 2 +- lfvetau/baseSelections.py | 4 +- 3 files changed, 210 insertions(+), 39 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index 1035b216..59832393 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -134,7 +134,7 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): 'TTJets*', 'T*_t*', '[WZ][WZ]Jets', - #'Wplus*Jets_madgraph*', #superseded by fakes + 'Wplus*Jets_madgraph*', #superseded by fakes #add in case of optimization study 'Z*jets_M50_skimmedLL', #'WH*HToTauTau', #'WH*HToWW', @@ -151,7 +151,7 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): 'view' : embedded_view, 'weight' : weight } - self.views['fakes'] = {'view' : self.make_fakes('t')} + #self.views['fakes'] = {'view' : self.make_fakes('t')} #self.views['efakes'] = {'view' : self.make_fakes('e')} #self.views['etfakes'] = {'view' : self.make_fakes('et')} @@ -171,7 +171,8 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): # 'ggHWW' : 'WWGG126', 'ggHiggsToETau' : 'LFVGG', 'vbfHiggsToETau' : 'LFVVBF', - 'fakes' : 'fakes', + 'Wplus*Jets_madgraph*' : 'wplusjets'#add in case of optimization study +# 'fakes' : 'fakes', # 'WH*HToTauTau' : 'VHtautau' , #"VHtautau", # 'WH*HToWW' : 'VHWW' , #"VHWW", ##'efakes' : 'efakes', @@ -180,9 +181,9 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): self.sample_groups = {#parse_cgs_groups('card_config/cgs.0.conf') 'fullsimbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', - 'diboson', 'zjetsother'],# 'WWVBF126', 'WWGG126','VHWW','VHtautau'], + 'diboson', 'zjetsother', 'wplusjets'],# 'WWVBF126', 'WWGG126','VHWW','VHtautau'], #wplusjets added in case of optimization study 'simbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', 'ztautau', - 'diboson', 'zjetsother'],#'WWVBF126', 'WWGG126','VHWW','VHtautau'], + 'diboson', 'zjetsother', 'wplusjets'],#'WWVBF126', 'WWGG126','VHWW','VHtautau'], 'realtau' : ['ztautau', 'SMGG126', 'SMVBF126'],# 'VHtautau'], } @@ -199,18 +200,18 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): '-' : dir_systematic('trm1s'), 'apply_to' : ['simbkg'], }, - 'E_ID' : { - 'type' : 'yield', - '+' : dir_systematic('eidp1s'), - '-' : dir_systematic('eidm1s'), - 'apply_to' : ['simbkg'], - }, - 'E_Iso' : { - 'type' : 'yield', - '+' : dir_systematic('eisop1s'), - '-' : dir_systematic('eisom1s'), - 'apply_to' : ['simbkg'], - }, +## 'E_ID' : { ## to comment in case of optimization study +## 'type' : 'yield', +## '+' : dir_systematic('eidp1s'), +## '-' : dir_systematic('eidm1s'), +## 'apply_to' : ['simbkg'], +## }, +## 'E_Iso' : { ## to comment in case of optimization study +## 'type' : 'yield', +## '+' : dir_systematic('eisop1s'), +## '-' : dir_systematic('eisom1s'), +## 'apply_to' : ['simbkg'], +## }, 'JES' : { 'type' : 'shape', '+' : lambda x: os.path.join('jes_plus', x)+'_jes_plus' , @@ -229,23 +230,23 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): '-' : lambda x: os.path.join('ees_minus', x)+'_ees_minus' , 'apply_to' : ['simbkg'], }, - 'UES' : { - 'type' : 'shape', - '+' : name_systematic('_ues_plus'), - '-' : name_systematic('_ues_minus'), - 'apply_to' : ['fullsimbkg'], - }, - 'shape_FAKES' : { - 'type' : 'shape', - '+' : dir_systematic('Up'), - '-' : dir_systematic('Down'), - 'apply_to' : ['fakes']#,'efakes','etfakes'], - }, +## 'UES' : { ## to comment in case of optimization study +## 'type' : 'shape', +## '+' : name_systematic('_ues_plus'), +## '-' : name_systematic('_ues_minus'), +## 'apply_to' : ['fullsimbkg'], +## }, +## 'shape_FAKES' : { ## to comment in case of optimization study +## 'type' : 'shape', +## '+' : dir_systematic('Up'), +## '-' : dir_systematic('Down'), +## 'apply_to' : ['fakes']#,'efakes','etfakes'], +## }, 'stat' : { 'type' : 'stat', '+' : lambda x: x, '-' : lambda x: x, - 'apply_to' : ['fakes','simbkg'], + 'apply_to' : [ 'simbkg'],#['fakes','simbkg'], ## no fakes in case of optimization study } } @@ -984,7 +985,7 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, mc_histo.SetName(name) mc_histo.Write() - fakes_view = self.get_view('fakes') + fakes_view = self.get_view('fakes') d_view = self.get_view('data') weights_view = views.SumView( views.SubdirectoryView(d_view, 'tLoose'), @@ -992,7 +993,7 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, views.SubdirectoryView(d_view, 'etLoose') ) if preprocess: - fakes_view = preprocess(fakes_view) + fakes_view = preprocess(fakes_view) weights_view = preprocess(weights_view) weights = weights_view.Get(os.path.join(folder,'weight')) fakes_view = self.rebin_view(fakes_view, rebin) @@ -1105,10 +1106,10 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, return unc_conf_lines, unc_vals_lines -##----- + ##----- - def write_shapes_for_yields(self, folder, variable, output_dir, br_strenght=1, - rebin=1, preprocess=None): #, systematics): + def write_shapes_for_yields(self, folder, variable, output_dir, br_strenght=1, + rebin=1, preprocess=None): #, systematics): '''Makes shapes for computing the limit and returns a list of systematic effects to be added to unc.vals/conf make_shapes(folder, variable, output_dir, [rebin=1, preprocess=None) --> unc_conf_lines (list), unc_vals_lines (list) ''' @@ -1148,7 +1149,7 @@ def write_shapes_for_yields(self, folder, variable, output_dir, br_strenght=1, mc_histo.SetName(name) mc_histo.Write() - fakes_view = self.get_view('fakes') + fakes_view = self.get_view('fakes')#to comment for optimization study d_view = self.get_view('data') weights_view = views.SumView( views.SubdirectoryView(d_view, 'tLoose'), @@ -1158,7 +1159,7 @@ def write_shapes_for_yields(self, folder, variable, output_dir, br_strenght=1, if preprocess: fakes_view = preprocess(fakes_view) weights_view = preprocess(weights_view) - weights = weights_view.Get(os.path.join(folder,'weight')) + weights = weights_view.Get(os.path.join(folder,'weight')) #to comment for optimization study fakes_view = self.rebin_view(fakes_view, rebin) bkg_views['fakes'] = fakes_view bkg_weights['fakes'] = mean(weights) @@ -1275,3 +1276,171 @@ def write_shapes_for_yields(self, folder, variable, output_dir, br_strenght=1, + def write_shapes_for_optimization(self, folder, variable, output_dir, br_strenght=1, + rebin=1, preprocess=None): #, systematics): + '''Makes shapes for computing the limit and returns a list of systematic effects to be added to unc.vals/conf + make_shapes(folder, variable, output_dir, [rebin=1, preprocess=None) --> unc_conf_lines (list), unc_vals_lines (list) + ''' + output_dir.cd() + path = os.path.join(folder,variable) + + #make MC views with xsec error + bkg_views = dict( + [(self.datacard_names[i], j) for i, j in zip(self.mc_samples, self.mc_views(rebin, preprocess))] + ) + bkg_weights = dict( + [(self.datacard_names[i], self.get_view(i, 'weight')) for i in self.mc_samples] + ) + #cache histograms, since getting them is time consuming + bkg_histos = {} + for name, view in bkg_views.iteritems(): + mc_histo = view.Get(path) + bkg_histos[name] = mc_histo.Clone() + #mc_histo = remove_empty_bins( + # mc_histo, bkg_weights[name]) + mc_histo.SetName(name) + mc_histo.Write() + + if self.use_embedded: + view = self.get_view('ZetauEmbedded') + weight = self.get_view('ZetauEmbedded', 'weight') + if preprocess: + view = preprocess(view) + view = self.rebin_view(view, rebin) + name = self.datacard_names['ZetauEmbedded'] + bkg_weights[name] = weight + bkg_views[name] = view + mc_histo = view.Get(path) + bkg_histos[name] = mc_histo.Clone() + #mc_histo = remove_empty_bins( + # mc_histo, weight) + mc_histo.SetName(name) + mc_histo.Write() + + ## fakes_view = self.get_view('fakes')#to comment for optimization study + d_view = self.get_view('data') + weights_view = views.SumView( + views.SubdirectoryView(d_view, 'tLoose'), + views.SubdirectoryView(d_view, 'eLoose'), + views.SubdirectoryView(d_view, 'etLoose') + ) + if preprocess: + fakes_view = preprocess(fakes_view) + weights_view = preprocess(weights_view) +## weights = weights_view.Get(os.path.join(folder,'weight')) #to comment for optimization study +## fakes_view = self.rebin_view(fakes_view, rebin) +## bkg_views['fakes'] = fakes_view +## bkg_weights['fakes'] = mean(weights) +## fake_shape = bkg_views['fakes'].Get(path) +## bkg_histos['fakes'] = fake_shape.Clone() +## #fake_shape = remove_empty_bins( +## # fake_shape, bkg_weights['fakes']) +## fake_shape.SetName('fakes') +## fake_shape.Write() + + unc_conf_lines = [] + unc_vals_lines = [] + category_name = output_dir.GetName() + for unc_name, info in self.systematics.iteritems(): + targets = [] + for target in info['apply_to']: + if target in self.sample_groups: + targets.extend(self.sample_groups[target]) + else: + targets.append(target) + + unc_conf = 'lnN' if info['type'] == 'yield' or info['type'] == 'stat' else 'shape' + #stat shapes are uncorrelated between samples + if info['type'] <> 'stat': + unc_conf_lines.append('%s %s' % (unc_name, unc_conf)) + shift = 0. + path_up = info['+'](path) + path_dw = info['-'](path) + for target in targets: + up = bkg_views[target].Get( + path_up + ) + down = bkg_views[target].Get( + path_dw + ) + if info['type'] == 'yield': + central = bkg_histos[target] + integral = central.Integral() + integral_up = up.Integral() + integral_down = down.Integral() + if integral == 0 and integral_up == 0 and integral_down ==0 : + shift=shift + else: + shift = max( + shift, + (integral_up - integral) / integral, + (integral - integral_down) / integral + ) + elif info['type'] == 'shape': + #remove empty bins also for shapes + #(but not in general to not spoil the stat uncertainties) + #up = remove_empty_bins(up, bkg_weights[target]) + #down = remove_empty_bins(down, bkg_weights[target]) + up.SetName('%s_%sUp' % (target, unc_name)) + down.SetName('%s_%sDown' % (target, unc_name)) + up.Write() + down.Write() + elif info['type'] == 'stat': + nbins = up.GetNbinsX() + up.Rebin(nbins) + yield_val = up.GetBinContent(1) + yield_err = up.GetBinError(1) + print target, yield_val, yield_err, + if yield_val==0: + unc_value = 0. + else: + unc_value = 1. + (yield_err / yield_val) + stat_unc_name = '%s_%s_%s' % (target, category_name, unc_name) + unc_conf_lines.append('%s %s' % (stat_unc_name, unc_conf)) + unc_vals_lines.append( + '%s %s %s %.2f' % (category_name, target, stat_unc_name, unc_value) + ) + else: + raise ValueError('systematic uncertainty type:"%s" not recognised!' % info['type']) + + if info['type'] <> 'stat': + shift += 1 + unc_vals_lines.append( + '%s %s %s %.2f' % (category_name, ','.join(targets), unc_name, shift) + ) + + #Get signal + signals = [ + 'ggHiggsToETau', + 'vbfHiggsToETau', + ] + for name in signals: + sig_view = self.get_view(name) + if preprocess: + sig_view = preprocess(sig_view) + sig_view = views.ScaleView( + RebinView(sig_view, rebin), + br_strenght + ) + + histogram = sig_view.Get(path) + histogram.SetName(self.datacard_names[name]) + histogram.Write() + + # Draw data + data_view = self.get_view('data') + if preprocess: + data_view = preprocess( data_view ) + data_view = self.rebin_view(data_view, rebin) + data = data_view.Get(path) + data.SetName('data_obs') + data.Write() + + return unc_conf_lines, unc_vals_lines + +##----- + + + + + diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index a02e8386..92a3451d 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -274,7 +274,7 @@ def book_with_sys(location, name, *args, **kwargs): # 'run/l:lumi/l:evt/l:weight/D', # type=pytree.PyTree #) - #@# self.book(f,"weight", "weight", 100, 0, 10) + self.book(f,"weight", "weight", 100, 0, 10) #@# self.book(f,"tPt", "tau p_{T}", 40, 0, 200) #@# self.book(f,"tPt_tes_plus", "tau p_{T} (tes+)", 40, 0, 200) #@# self.book(f,"tPt_tes_minus", "tau p_{T} (tes-)",40, 0, 200) diff --git a/lfvetau/baseSelections.py b/lfvetau/baseSelections.py index 423a53c6..dc77d8e4 100755 --- a/lfvetau/baseSelections.py +++ b/lfvetau/baseSelections.py @@ -22,7 +22,7 @@ def muSelection(row, name): def eSelection(row, name): eAbsEta = getattr( row, getVar(name,'AbsEta')) - ept = getattr( row, getVar(name,'Pt_ees_minus')) + ept = getattr( row, getVar(name,'Pt_ees_minus')) if ept: if ept < 30: return False else: @@ -100,6 +100,8 @@ def lepton_id_iso(row, name, label): #label in the format eidtype_isotype return bool( RelPFIsoDB < 0.15 or (RelPFIsoDB < 0.20 and AbsEta < 1.479)) if isolabel == 'idiso02': return bool( RelPFIsoDB < 0.20 ) + if isolabel == 'idiso05': + return bool( RelPFIsoDB < 0.5 ) if isolabel == 'idantiso': return bool( RelPFIsoDB > 0.20 ) if isolabel == 'etauiso012' or isolabel == 'mutauiso012': From 363939495cd1c66270dbca8976c8e2209862c87f Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Thu, 15 Jan 2015 11:15:44 -0600 Subject: [PATCH 183/192] EleFakeRate bug fix --- lfvetau/EleFakeRateAnalyzerMVA.py | 387 ++++++++++++++++++++++++++---- 1 file changed, 337 insertions(+), 50 deletions(-) diff --git a/lfvetau/EleFakeRateAnalyzerMVA.py b/lfvetau/EleFakeRateAnalyzerMVA.py index ad1d7adf..1ee112db 100644 --- a/lfvetau/EleFakeRateAnalyzerMVA.py +++ b/lfvetau/EleFakeRateAnalyzerMVA.py @@ -116,36 +116,36 @@ def begin(self): for f in folder: - self.book(f,"e1Pt", "e1 p_{T}", 200, 0, 200) - self.book(f,"e1Phi", "e1 phi", 100, -3.2, 3.2) - self.book(f,"e1Eta", "e1 eta", 46, -2.3, 2.3) - - self.book(f,"e2Pt", "e2 p_{T}", 200, 0, 200) - self.book(f,"e2Phi", "e2 phi", 100, -3.2, 3.2) - self.book(f,"e2Eta", "e2 eta", 46, -2.3, 2.3) + ##self.book(f,"e1Pt", "e1 p_{T}", 200, 0, 200) + ##self.book(f,"e1Phi", "e1 phi", 100, -3.2, 3.2) + ##self.book(f,"e1Eta", "e1 eta", 46, -2.3, 2.3) + ## + ##self.book(f,"e2Pt", "e2 p_{T}", 200, 0, 200) + ##self.book(f,"e2Phi", "e2 phi", 100, -3.2, 3.2) + ##self.book(f,"e2Eta", "e2 eta", 46, -2.3, 2.3) self.book(f,"e3Pt", "e3 p_{T}", 200, 0, 200) - self.book(f,"e3Phi", "e3 phi", 100, -3.2, 3.2) + ##self.book(f,"e3Phi", "e3 phi", 100, -3.2, 3.2) self.book(f,"e3Eta", "e3 eta", 46, -2.3, 2.3) self.book(f,"e3AbsEta", "e3 abs eta", 23, 0, 2.3) - self.book(f, "e1e2Mass", "e1e2 Inv Mass", 32, 0, 320) - - self.book(f, "e3MtToPFMET", "e3 Met MT", 100, 0, 100) - - - self.book(f,"ee3DR", "e e3 DR", 50, 0, 10) - self.book(f,"ee3DPhi", "e e3 DPhi", 32, 0, 3.2) - - self.book(f,"ze3DR", "Z e3 DR", 50, 0, 10) - self.book(f,"ze3DPhi", "Z e3 DPhi", 32, 0, 3.2) - self.book(f,"Zpt", "Z p_{T}", 200, 0, 200) - - - - self.book(f, "type1_pfMetEt", "type1_pfMetEt",200, 0, 200) - self.book(f, "jetN_30", "Number of jets, p_{T}>30", 10, -0.5, 9.5) - self.book(f, "bjetCSVVeto30", "number of bjets", 10, -0.5, 9.5) + ##self.book(f, "e1e2Mass", "e1e2 Inv Mass", 32, 0, 320) + ## + ##self.book(f, "e3MtToPFMET", "e3 Met MT", 100, 0, 100) + ## + ## + ##self.book(f,"ee3DR", "e e3 DR", 50, 0, 10) + ##self.book(f,"ee3DPhi", "e e3 DPhi", 32, 0, 3.2) + ## + ##self.book(f,"ze3DR", "Z e3 DR", 50, 0, 10) + ##self.book(f,"ze3DPhi", "Z e3 DPhi", 32, 0, 3.2) + ##self.book(f,"Zpt", "Z p_{T}", 200, 0, 200) + ## + ## + ## + ##self.book(f, "type1_pfMetEt", "type1_pfMetEt",200, 0, 200) + ##self.book(f, "jetN_30", "Number of jets, p_{T}>30", 10, -0.5, 9.5) + ##self.book(f, "bjetCSVVeto30", "number of bjets", 10, -0.5, 9.5) for s in sign: self.book(s+'/tNoCuts', "CUT_FLOW", "Cut Flow", len(cut_flow_step), 0, len(cut_flow_step)) @@ -164,32 +164,32 @@ def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): - histos[folder+'/e1Pt'].Fill( getattr(row, self.mye1+'Pt'), weight) - histos[folder+'/e1Eta'].Fill(getattr(row, self.mye1+'Eta'), weight) - histos[folder+'/e1Phi'].Fill(getattr(row, self.mye1+'Phi'), weight) - - histos[folder+'/e2Pt'].Fill( getattr(row, self.mye2+'Pt' ), weight) - histos[folder+'/e2Eta'].Fill(getattr(row, self.mye2+'Eta'), weight) - histos[folder+'/e2Phi'].Fill(getattr(row, self.mye2+'Phi'), weight) + ##histos[folder+'/e1Pt'].Fill( getattr(row, self.mye1+'Pt'), weight) + ##histos[folder+'/e1Eta'].Fill(getattr(row, self.mye1+'Eta'), weight) + ##histos[folder+'/e1Phi'].Fill(getattr(row, self.mye1+'Phi'), weight) + ## + ##histos[folder+'/e2Pt'].Fill( getattr(row, self.mye2+'Pt' ), weight) + ##histos[folder+'/e2Eta'].Fill(getattr(row, self.mye2+'Eta'), weight) + ##histos[folder+'/e2Phi'].Fill(getattr(row, self.mye2+'Phi'), weight) histos[folder+'/e3Pt'].Fill( getattr(row, self.mye3+'Pt' ), weight) histos[folder+'/e3Eta'].Fill(getattr(row, self.mye3+'Eta'), weight) - histos[folder+'/e3Phi'].Fill(getattr(row, self.mye3+'Phi'), weight) + ##histos[folder+'/e3Phi'].Fill(getattr(row, self.mye3+'Phi'), weight) histos[folder+'/e3AbsEta'].Fill(abs(getattr(row, self.mye3+'Eta')), weight) - histos[folder+'/e1e2Mass'].Fill(getattr(row, self.mye1+'_'+self.mye2+'_Mass'), weight) - #histos[folder+'/tMtToPFMET'].Fill(row.tMtToPFMET,weight) - - - histos[folder+'/type1_pfMetEt'].Fill(row.type1_pfMet_Et) - histos[folder+'/ee3DR'].Fill(self.ee3DR(row)) - histos[folder+'/ee3DPhi'].Fill(self.ee3DPhi(row)) - histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight) - histos[folder+'/bjetCSVVeto30'].Fill(row.bjetCSVVeto30, weight) - - histos[folder+'/ze3DR'].Fill(deltaR(self.Z(row).Phi(), getattr(row, self.mye3+'Phi'), self.Z(row).Eta(), getattr(row, self.mye3+'Eta'))) - histos[folder+'/ze3DPhi'].Fill(deltaPhi(self.Z(row).Phi(), getattr(row, self.mye3+'Phi'))) - histos[folder+'/Zpt'].Fill(self.Z(row).Pt()) + ##histos[folder+'/e1e2Mass'].Fill(getattr(row, self.mye1+'_'+self.mye2+'_Mass'), weight) + ###histos[folder+'/tMtToPFMET'].Fill(row.tMtToPFMET,weight) + ## + ## + ##histos[folder+'/type1_pfMetEt'].Fill(row.type1_pfMet_Et) + ##histos[folder+'/ee3DR'].Fill(self.ee3DR(row)) + ##histos[folder+'/ee3DPhi'].Fill(self.ee3DPhi(row)) + ##histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight) + ##histos[folder+'/bjetCSVVeto30'].Fill(row.bjetCSVVeto30, weight) + ## + ##histos[folder+'/ze3DR'].Fill(deltaR(self.Z(row).Phi(), getattr(row, self.mye3+'Phi'), self.Z(row).Eta(), getattr(row, self.mye3+'Eta'))) + ##histos[folder+'/ze3DPhi'].Fill(deltaPhi(self.Z(row).Phi(), getattr(row, self.mye3+'Phi'))) + ##histos[folder+'/Zpt'].Fill(self.Z(row).Pt()) def process(self): @@ -226,21 +226,21 @@ def process(self): cut_flow_trk.Fill('allEvents') if not selections.eSelection(row, 'e1'): continue cut_flow_trk.Fill('e1sel') - if not selections.lepton_id_iso(row, 'e1', 'eid13Loose_idiso02'): continue + if not selections.lepton_id_iso(row, 'e1', 'eid13Tight_idiso02'): continue if abs(row.e1Eta) > 1.4442 and abs(row.e1Eta < 1.566) : continue cut_flow_trk.Fill('e1IDiso') if not selections.eSelection(row, 'e2'): continue cut_flow_trk.Fill('e2sel') - if not selections.lepton_id_iso(row, 'e2', 'eid13Loose_idiso02'): continue + if not selections.lepton_id_iso(row, 'e2', 'eid13Tight_idiso02'): continue if abs(row.e2Eta) > 1.4442 and abs(row.e2Eta) < 1.566 : continue ## cut_flow_trk.Fill('e2IDiso') ## if not abs(row.e1_e2_Mass-91.2) < 20: continue ## cut_flow_trk.Fill('ZMass') if not selections.eSelection(row, 'e3'): continue - if not selections.lepton_id_iso(row, 'e3', 'eid13Loose_idiso02'): continue #very loose loose eid13Tight_mvaLoose + if not selections.lepton_id_iso(row, 'e3', 'eid13Tight_idiso02'): continue #very loose loose eid13Tight_mvaLoose if abs(row.e3Eta) > 1.4442 and abs(row.e3Eta) < 1.566 : continue Zs= [(abs(row.e1_e2_Mass-91.2), ['e1', 'e2', 'e3']) , (abs(row.e2_e3_Mass-91.2), ['e2', 'e3', 'e1']), (abs(row.e1_e3_Mass-91.2), ['e1', 'e3', 'e2'])] @@ -293,4 +293,291 @@ def process(self): def finish(self): self.write_histos() - +####Correction Factor still to add +##from EEETree import EEETree +##import os +##import ROOT +##import math +##import optimizer +##import glob +##import array +##import mcCorrections +##import baseSelections as selections +##import FinalStateAnalysis.PlotTools.pytree as pytree +##from FinalStateAnalysis.PlotTools.decorators import memo_last +##from FinalStateAnalysis.PlotTools.MegaBase import MegaBase +##from math import sqrt, pi, sin, cos, acos, sinh +##from cutflowtracker import cut_flow_tracker +###Makes the cut flow histogram +##cut_flow_step = ['allEvents', 'e1sel', 'e1IDiso', 'e2sel', 'e2IDiso', 'ZMass', 'e3Pt','e3Eta','e3missinHits','e3conversion','e3ChargeId','e3Btag','e3DZ','tsel', 'MtToMet', 'tTightIso' +##] +## +##from inspect import currentframe +## +##def get_linenumber(): +## cf = currentframe() +## return cf.f_back.f_lineno +## +##def deltaPhi(phi1, phi2): +## PHI = abs(phi1-phi2) +## if PHI<=pi: +## return PHI +## else: +## return 2*pi-PHI +##def deltaR(phi1, phi2, eta1, eta2): +## deta = eta1 - eta2 +## dphi = abs(phi1-phi2) +## if (dphi>pi) : dphi = 2*pi-dphi +## return sqrt(deta*deta + dphi*dphi); +## +##def ee3DR(row): +## return row.e1_e3_DR if row.e1_e3_DR < row.e2_e3_DR else row.e2_e3_DR +## +##def ee3DPhi(row): +## e1e3DPhi=deltaPhi(row.e1Phi, row.e3Phi) +## e2e3DPhi=deltaPhi(row.e2Phi, row.e3Phi) +## return e1e3DPhi if e1e3DPhi < e2e3DPhi else e2e3DPhi +## +##def Z(row): +## e1p=ROOT.TVector3(row.e1Pt*cos(row.e1Phi),row.e1Pt*sin(row.e1Phi),row.e1Pt*sinh(row.e1Eta)) +## e2p=ROOT.TVector3(row.e2Pt*cos(row.e2Phi),row.e2Pt*sin(row.e2Phi),row.e2Pt*sinh(row.e2Eta)) +## e1FourVector= ROOT.TLorentzVector(e1p, sqrt(e1p.Mag2()+row.e1Mass*row.e1Mass)) +## e2FourVector= ROOT.TLorentzVector(e2p, sqrt(e2p.Mag2()+row.e2Mass*row.e2Mass)) +## zFourVector = e1FourVector+e2FourVector +## return zFourVector +## +## +##class EleFakeRateAnalyzerMVA(MegaBase): +## tree = 'eee/final/Ntuple' +## def __init__(self, tree, outfile, **kwargs): +## self.channel='EET' +## super(EleFakeRateAnalyzerMVA, self).__init__(tree, outfile, **kwargs) +## self.tree = EEETree(tree) +## self.out=outfile +## self.histograms = {} +## self.pucorrector = mcCorrections.make_puCorrector('singlee') +## +## #optimizer_keys = [ i for i in optimizer.grid_search.keys() if i.startswith(self.channel) ] +## ##self.grid_search = {} +## ##if len(optimizer_keys) > 1: +## ## for key in optimizer_keys: +## ## self.grid_search[key] = optimizer.grid_search[key] +## ##else: +## ## self.grid_search[''] = optimizer.grid_search[optimizer_keys[0]] +## +## +## def event_weight(self, row): +## if row.run > 2: #FIXME! add tight ID correction +## return 1. +## +## etrig = 'e1' +## if row.e2Pt > row.e1Pt : etrig = 'e2' +## if bool(row.e1MatchesSingleE27WP80) and not bool(row.e2MatchesSingleE27WP80) : etrig = 'e1' +## if not bool(row.e1MatchesSingleE27WP80) and bool(row.e2MatchesSingleE27WP80) : etrig = 'e2' +## +## if bool(row.e3MatchesSingleE27WP80) and not bool(row.e1MatchesSingleE27WP80) and not bool(row.e2MatchesSingleE27WP80) : etrig ='e3' +## +## return self.pucorrector(row.nTruePU) * \ +## mcCorrections.eid_correction( row, 'e1', 'e2', 'e3') * \ +## mcCorrections.eiso_correction(row, 'e1', 'e2', 'e3') * \ +## mcCorrections.trig_correction(row, etrig ) +## # mcCorrections.trig_correction(row, 'e3' ) +## +####add the trigger correction +## +## def begin(self): +## +## eiso = ['eLoose', 'eTigh'] +## folder = [] +## sign = ['ss','os'] +## for iso in eiso: +## for s in sign: +## folder.append(s+'/'+iso) +## j=0 +## while j < 4 : +## folder.append(s+'/'+iso+'/'+str(j)) +## j+=1 +## +## for f in folder: +## +## ##self.book(f,"e1Pt", "e1 p_{T}", 200, 0, 200) +## ##self.book(f,"e1Phi", "e1 phi", 100, -3.2, 3.2) +## ##self.book(f,"e1Eta", "e1 eta", 46, -2.3, 2.3) +## ## +## ##self.book(f,"e2Pt", "e2 p_{T}", 200, 0, 200) +## ##self.book(f,"e2Phi", "e2 phi", 100, -3.2, 3.2) +## ##self.book(f,"e2Eta", "e2 eta", 46, -2.3, 2.3) +## +## self.book(f,"e3Pt", "e3 p_{T}", 200, 0, 200) +## ##self.book(f,"e3Phi", "e3 phi", 100, -3.2, 3.2) +## self.book(f,"e3Eta", "e3 eta", 46, -2.3, 2.3) +## self.book(f,"e3AbsEta", "e3 abs eta", 23, 0, 2.3) +## +## ##self.book(f, "e1e2Mass", "e1e2 Inv Mass", 32, 0, 320) +## ## +## ##self.book(f, "e3MtToPFMET", "e3 Met MT", 100, 0, 100) +## ## +## ## +## ##self.book(f,"ee3DR", "e e3 DR", 50, 0, 10) +## ##self.book(f,"ee3DPhi", "e e3 DPhi", 32, 0, 3.2) +## ## +## ##self.book(f,"ze3DR", "Z e3 DR", 50, 0, 10) +## ##self.book(f,"ze3DPhi", "Z e3 DPhi", 32, 0, 3.2) +## ##self.book(f,"Zpt", "Z p_{T}", 200, 0, 200) +## ## +## ## +## ## +## ##self.book(f, "type1_pfMetEt", "type1_pfMetEt",200, 0, 200) +## ##self.book(f, "jetN_30", "Number of jets, p_{T}>30", 10, -0.5, 9.5) +## ##self.book(f, "bjetCSVVeto30", "number of bjets", 10, -0.5, 9.5) +## +## for s in sign: +## self.book(s+'/tNoCuts', "CUT_FLOW", "Cut Flow", len(cut_flow_step), 0, len(cut_flow_step)) +## +## xaxis = self.histograms[s+'/tNoCuts/CUT_FLOW'].GetXaxis() +## self.cut_flow_histo = self.histograms[s+'/tNoCuts/CUT_FLOW'] +## self.cut_flow_map = {} +## for i, name in enumerate(cut_flow_step): +## xaxis.SetBinLabel(i+1, name) +## self.cut_flow_map[name] = i+0.5 +## +## def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): +## weight = self.event_weight(row) +## histos = self.histograms +## +## ##histos[folder+'/e1Pt'].Fill(row.e1Pt, weight) +## ##histos[folder+'/e1Eta'].Fill(row.e1Eta, weight) +## ##histos[folder+'/e1Phi'].Fill(row.e1Phi, weight) +## ## +## ##histos[folder+'/e2Pt'].Fill(row.e2Pt, weight) +## ##histos[folder+'/e2Eta'].Fill(row.e2Eta, weight) +## ##histos[folder+'/e2Phi'].Fill(row.e2Phi, weight) +## +## histos[folder+'/e3Pt'].Fill(row.e3Pt, weight) +## histos[folder+'/e3Eta'].Fill(row.e3Eta, weight) +## histos[folder+'/e3AbsEta'].Fill(abs(row.e3Eta), weight) +## ##histos[folder+'/e3Phi'].Fill(row.e3Phi, weight) +## +## ##histos[folder+'/e1e2Mass'].Fill(row.e1_e2_Mass, weight) +## ###histos[folder+'/tMtToPFMET'].Fill(row.tMtToPFMET,weight) +## ## +## ## +## ##histos[folder+'/type1_pfMetEt'].Fill(row.type1_pfMet_Et) +## ##histos[folder+'/ee3DR'].Fill(ee3DR(row)) +## ##histos[folder+'/ee3DPhi'].Fill(ee3DPhi(row)) +## ##histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight) +## ##histos[folder+'/bjetCSVVeto30'].Fill(row.bjetCSVVeto30, weight) +## ## +## ##histos[folder+'/ze3DR'].Fill(deltaR(Z(row).Phi(), row.e3Phi, Z(row).Eta(), row.e3Eta)) +## ##histos[folder+'/ze3DPhi'].Fill(deltaPhi(Z(row).Phi(), row.e3Phi)) +## ##histos[folder+'/Zpt'].Fill(Z(row).Pt()) +## +## +## def process(self): +## +## cut_flow_histo = self.cut_flow_histo +## cut_flow_trk = cut_flow_tracker(cut_flow_histo) +## myevent =() +## #print self.tree.inputfilename +## for row in self.tree: +## jn = row.jetVeto30 +## if jn > 3 : jn = 3 +## +## #if row.run > 2: +## if not bool(row.singleE27WP80Pass) : continue +## # if hasattr(self.tree, 'row.e1MatchesEle27WP80') and hasattr(self.tree, 'row.e2MatchesEle27WP80') : +## #if not bool(row.e1MatchesEle27WP80) and not bool(row.e2MatchesEle27WP80) : continue +## +## #else : +## if not bool(row.e3MatchesSingleE27WP80) : continue +## #if not bool(row.singleEPass) : continue +## #if not bool(row.e1MatchesSingleE) and not bool(row.e2MatchesSingleE) : continue +## +## if row.bjetCSVVeto30!=0 : continue +## if row.e1Pt < 30 : continue +## if row.e2Pt < 30 : continue +## +### for i, row in enumerate(self.tree): +### if i >= 100: +### return +## # print bool(cut_flow_trk.disabled) +## cut_flow_trk.new_row(row.run,row.lumi,row.evt) +## #print row.run,row.lumi,row.evt +## cut_flow_trk.Fill('allEvents') +## if not selections.eSelection(row, 'e1'): continue +## cut_flow_trk.Fill('e1sel') +## if not selections.lepton_id_iso(row, 'e1', 'eid13Loose_idiso02'): continue +## if abs(row.e1Eta) > 1.4442 and abs(row.e1Eta < 1.566) : continue +## +## +## cut_flow_trk.Fill('e1IDiso') +## if not selections.eSelection(row, 'e2'): continue +## cut_flow_trk.Fill('e2sel') +## if not selections.lepton_id_iso(row, 'e2', 'eid13Loose_idiso02'): continue +## if abs(row.e2Eta) > 1.4442 and abs(row.e2Eta) < 1.566 : continue +## +## cut_flow_trk.Fill('e2IDiso') +## if not abs(row.e1_e2_Mass-91.2) < 20: continue +## cut_flow_trk.Fill('ZMass') +## #if not selections.eSelection(row, 'e3'): continue +## +## if row.e3Pt < 30: continue +## cut_flow_trk.Fill('e3Pt') +## if abs(row.e3Eta) >2.3: continue +## if abs(row.e3Eta) > 1.4442 and abs(row.e3Eta) < 1.566 : continue +#### cut_flow_trk.Fill('e3Eta') +#### if row.e3MissingHits: continue +#### cut_flow_trk.Fill('e3missinHits') +#### if row.e3HasConversion: continue +#### cut_flow_trk.Fill('e3conversion') +#### if not row.e3ChargeIdLoose: continue +#### cut_flow_trk.Fill('e3ChargeId') +#### if row.e3JetCSVBtag >0.8: continue +#### cut_flow_trk.Fill('e3Btag') +#### if row.e3DZ >0.2: continue +#### cut_flow_trk.Fill('e3DZ') +## +## ##if not selections.lepton_id_iso(row, 'e3', 'eid13Loose_idiso02'): continue #very loose loose eid13Tight_mvaLoose +## if not selections.lepton_id_iso(row, 'e3', 'eid13Tight_idiso02'): continue #very loose loose eid13Tight_mvaLoose +## +## cut_flow_trk.Fill('tsel') +## +## +## if row.tauVetoPt20EleTight3MuLoose : continue +## #if row.tauHpsVetoPt20 : continue +## if row.muVetoPt5IsoIdVtx : continue +## if row.eVetoCicLooseIso : continue # change it with Loose +## +## #if not row.e3MtToMET < 50: continue +## cut_flow_trk.Fill('MtToMet') +## +## # if etDR(row) < 1. : continue +## ##if (row.run, row.lumi, row.evt, row.e1Pt, row.e2Pt)==myevent: continue +## ##myevent=(row.run, row.lumi, row.evt, row.e1Pt, row.e2Pt) +## +## eleiso = 'eLoose' +## sign = 'ss' if row.e1_e2_SS else 'os' +## folder = sign+'/'+eleiso +## +## self.fill_histos(row, folder) +## folder=folder+'/'+str(int(jn)) +## self.fill_histos(row, folder) +## +## if selections.lepton_id_iso(row, 'e3', 'eid13Tight_etauiso01'): +## eleiso = 'eTigh' +## folder = sign+'/'+eleiso +## self.fill_histos(row, folder) +## cut_flow_trk.Fill('tTightIso') +## folder=folder+'/'+str(int(jn)) +## self.fill_histos(row, folder) +## +## +## +## +## cut_flow_trk.flush() +## +## +## +## def finish(self): +## self.write_histos() +## From fe4ef65d406d6bbd5c400913bcb08a6744329a6a Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Thu, 15 Jan 2015 11:16:45 -0600 Subject: [PATCH 184/192] adding tools for S/(S+B) studies --- lfvetau/Rakefile | 67 +++-- lfvetau/plotEleFakeRate.py | 214 +++++++++++++ lfvetau/plotSoverSN.py | 398 +++++++++++++++++++++++++ lfvetau/produceShapeForOptimization.py | 88 ++++++ lfvetau/readNtuple.py | 2 +- 5 files changed, 735 insertions(+), 34 deletions(-) create mode 100644 lfvetau/plotEleFakeRate.py create mode 100644 lfvetau/plotSoverSN.py create mode 100644 lfvetau/produceShapeForOptimization.py diff --git a/lfvetau/Rakefile b/lfvetau/Rakefile index 3103bc88..b209b765 100644 --- a/lfvetau/Rakefile +++ b/lfvetau/Rakefile @@ -105,7 +105,7 @@ erf_vars = "scale[0.1, 0, 10],shift[1., 0.8, 1.2],steep[100.], offset[1e-2, 0, #$fr_binning = "30,35,40,45,50,55,60,70,80,90,100,120,140,160,180,200" #$fr_binning = "30,40,50,60,70,80,100,120,140,160,200" -$fr_binning = "30,40,50,60,70,80,100,120,150,200" +$fr_binning = "0,30,40,50,60,70,80,100,120,150,200" #$fr_binning = "30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200" $fr_analyzer = "TauFakeRateAnalyzerMVA" #was TauFakeRateAnalyzer $efr_analyzer = "EleFakeRateAnalyzerMVA" @@ -117,7 +117,7 @@ efr_fits = Hash.new #for s in mysamples fr_fits["t_os_tLoose_tTigh_tPt"] = Hash[ - "samples" => Array["diboson", "dataSingleE", "zjets_skimmedLL"], + "samples" => Array["diboson", "dataSingleE"],#, "zjets_skimmedLL"], "analyzer" => $fr_analyzer, #"function" => exponential, #"variables" => exponential_vars, @@ -131,14 +131,14 @@ fr_fits["t_os_tLoose_tTigh_tPt"] = Hash[ "max"=>"1" ] efr_fits["e_os_eLoose_eTigh_e3Pt"] = Hash[ - "samples" => Array["diboson", "dataSingleE", "zjets_skimmedLL"], + "samples" => Array["diboson", "dataSingleE"], "analyzer" => $efr_analyzer, #"function" => exponential, #"variables" => exponential_vars, "function" => pol0, "variables"=>pol0_vars, #"rebin" => 1, - "rebin" => $fr_binning, + "rebin" => "30,50,70,100,150,200",#$fr_binning, "range" => "30 200", "title" => "e p_{T} (GeV)", "min"=>"0", @@ -160,11 +160,11 @@ fr_fits["t_os_tLoose_tTigh_tAbsEta"] = Hash[ efr_fits["e_os_eLoose_eTigh_e3AbsEta"] = Hash[ - "samples" => Array["diboson", "dataSingleE", "zjets_skimmedLL"], + "samples" => Array["diboson", "dataSingleE"],#, "zjets_skimmedLL"], "analyzer" => $efr_analyzer, - "function" => pol1, - "variables" => pol1_vars, - "rebin" => 1, + "function" => pol0, + "variables" => pol0_vars, + "rebin" => "0.,0.4,0.8,1.2,1.6,2.0,2.3",#4, "range" => "0 2.3", #"range" => "-2.3 2.3", "title" => "e #eta", @@ -182,30 +182,30 @@ task :efitsMC => [] task :efits => [] -fr_fits.each do |fit, fit_info| - fit_configuration = fit.split("_") - sign = fit_configuration[1] - denom = fit_configuration[2] - num = fit_configuration[3] - var = fit_configuration[4] - - subsample_inputs = samples['zjets_skimmedLL'] - fit_output = $frfit_dirMC + "/#{fit}.root" - subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/#{fit_info['analyzer']}/#{x}.root"} - subsample_input_list = subsamples_inputs_result_list.join(" ") - denom_path = Array[sign, denom,var].join("/") - num_path = Array[sign, num, var].join("/") - - file fit_output => subsamples_inputs_result_list + [fit_info['analyzer'] + '.py'] do |t| - sh "mkdir -p #{$frfit_dirMC}" - sh "fit_efficiency_chi2.py #{fit_output} '#{num_path}' '#{denom_path}' \'#{pol0}\' \'#{pol0_vars}\' #{subsample_input_list} --plot --xrange #{fit_info['range']} --xtitle \'#{fit_info['title']}\' --min \'#{fit_info['min']}\' --max \'#{fit_info['max']}\' --show-error --rebin #{fit_info['rebin']} " - puts "" - end - - task :fits_MC => fit_output - -end - +##fr_fits.each do |fit, fit_info| +## fit_configuration = fit.split("_") +## sign = fit_configuration[1] +## denom = fit_configuration[2] +## num = fit_configuration[3] +## var = fit_configuration[4] +## +## subsample_inputs = samples['zjets_skimmedLL'] +## fit_output = $frfit_dirMC + "/#{fit}.root" +## subsamples_inputs_result_list = subsample_inputs.map{|x| "results/#{$jobid}/#{fit_info['analyzer']}/#{x}.root"} +## subsample_input_list = subsamples_inputs_result_list.join(" ") +## denom_path = Array[sign, denom,var].join("/") +## num_path = Array[sign, num, var].join("/") +## +## file fit_output => subsamples_inputs_result_list + [fit_info['analyzer'] + '.py'] do |t| +## sh "mkdir -p #{$frfit_dirMC}" +## sh "fit_efficiency_chi2.py #{fit_output} '#{num_path}' '#{denom_path}' \'#{pol0}\' \'#{pol0_vars}\' #{subsample_input_list} --plot --xrange #{fit_info['range']} --xtitle \'#{fit_info['title']}\' --min \'#{fit_info['min']}\' --max \'#{fit_info['max']}\' --show-error --rebin #{fit_info['rebin']} " +## puts "" +## end +## +## task :fits_MC => fit_output +## +##end +## efr_fits.each do |fit, fit_info| fit_configuration = fit.split("_") sign = fit_configuration[1] @@ -293,7 +293,8 @@ efr_fits.each do |fit, fit_info| num_path = Array[sign, num, var].join("/") corrected_file = fit_output.sub('.root', '.corrected_inputs.root') - file corrected_file => subsamples_inputs_result_list + [fit_info['analyzer'] + '.py', "CorrectFakeRateData.py"] do |t| + #file corrected_file => subsamples_inputs_result_list + [fit_info['analyzer'] + '.py', "CorrectFakeRateData.py"] do |t| + file corrected_file do |t| sh "mkdir -p #{$efrfit_dir}" sh "python CorrectFakeRateData.py --files #{subsample_input_list} --lumifiles inputs/#{$jobid}/*sum --outputfile #{t.name} --numerator '#{num_path}' --denom '#{denom_path}' --rebin #{fit_info['rebin']}" puts "" diff --git a/lfvetau/plotEleFakeRate.py b/lfvetau/plotEleFakeRate.py new file mode 100644 index 00000000..8f8b1b1c --- /dev/null +++ b/lfvetau/plotEleFakeRate.py @@ -0,0 +1,214 @@ +import ROOT +import math + +ROOT.gStyle.SetOptStat(0) +ROOT.gStyle.SetOptTitle(0) +ROOT.gROOT.SetBatch() + +file_data = ROOT.TFile('results/newNtuple_3Dec/efakerate_fits/e_os_eLoose_eTigh_e3AbsEta.corrected_inputs.root') + +data_uncorrected = file_data.Get('numerator_uncorr') +den_data_uncorrected = file_data.Get('denominator_uncorr') +data_corrected = file_data.Get('numerator') +den_data_corrected = file_data.Get('denominator') + +data_uncorrected.Sumw2() +data_corrected.Sumw2() + +data_uncorrected.Divide(den_data_uncorrected) +data_corrected.Divide(den_data_corrected) + +c= ROOT.TCanvas("c","c", 800, 1000) +c.Draw() +c.SetGridx(1) +c.SetGridy(1) + +pad1 = ROOT.TPad("pad1", "pad1", 0, 0.2, 1, 1) +pad1.Draw() +pad1.cd() +pad1.SetGridx(1) +pad1.SetGridy(1) +data_uncorrected.Draw('PE') +data_uncorrected.SetMarkerStyle(23) +data_uncorrected.GetXaxis().SetRangeUser(0, 2.2) +data_uncorrected.GetYaxis().SetRangeUser(0, 1.2) +data_uncorrected.SetMarkerColor(4) +data_uncorrected.SetLineColor(4) +data_uncorrected.GetYaxis().SetTitle("fakerate") +data_uncorrected.GetYaxis().SetTitleOffset(1.3) +data_uncorrected.GetXaxis().SetTitle("e |#eta|") +data_corrected.Draw('SAMEPE') +data_corrected.SetMarkerStyle(22) + +file_MC = ROOT.TFile('results/newNtuple_3Dec/efakerate_fits_MC/e_os_eLoose_eTigh_e3AbsEta_plot.root') + +cMC = file_MC.Get('asdf') +dataMC = cMC.GetPrimitive('hxy_xy_data') + +pad1.cd() +dataMC.Draw('SAMEP') +#dataMC.GetYaxis().SetRangeUser(0,1) + + +dataMC.SetMarkerStyle(20) +dataMC.SetMarkerColor(2) +dataMC.SetLineColor(2) + +leg=ROOT.TLegend(0.3,0.85,0.7,0.7) +leg.SetFillColor(0) +leg.AddEntry(data_corrected, 'data, bkg corrected', 'lp') +leg.AddEntry(data_uncorrected, 'data', 'lp') +leg.AddEntry(dataMC, 'Z+jets MC', 'lp') +leg.Draw() + +c.cd() + +pad2 = ROOT.TPad("pad2", "pad2", 0, 0.05, 1,0.2) +pad2.Draw() +pad2.cd() +pad2.SetGridx(1) +pad2.SetGridy(1) + +denom=ROOT.TH1F("denom", "denom", data_corrected.GetXaxis().GetNbins(), data_corrected.GetXaxis().GetXmin(), data_corrected.GetXaxis().GetXmax()) +for bin in range(1, dataMC.GetN()+1): + denom.Fill( dataMC.GetX()[bin-1],dataMC.GetY()[bin-1]) + x = dataMC.GetX()[bin-1] + err = math.sqrt(math.pow(data_corrected.GetBinError(bin)/dataMC.GetY()[bin-1],2)+math.pow(dataMC.GetErrorY(bin-1)/dataMC.GetY()[bin-1],2)*math.pow(data_corrected.GetBinContent(bin)/dataMC.GetY()[bin-1],2)) + + print x, data_corrected.GetBinContent(bin)/dataMC.GetY()[bin-1] , err, data_corrected.GetBinError(bin), dataMC.GetErrorY(bin-1) + denom.SetBinError(denom.FindBin(x), err) + +ratio= data_corrected.Clone() +ratio.Divide(denom) +ratio.SetMarkerStyle(22) +ratio.Draw('PE1') +ratio.GetXaxis().SetRangeUser(0,2.2) +ratio.GetYaxis().SetTitle('data/mc') +ratio.GetYaxis().SetRangeUser(0,5) +ratio.GetYaxis().SetTitleSize(0.1) +ratio.GetYaxis().SetLabelSize(.1) +ratio.GetXaxis().SetTitleSize(.1) +ratio.GetXaxis().SetLabelSize(.1) +ratio.GetYaxis().SetNdivisions(504, False) +ratio.GetYaxis().SetTitleOffset(0.3) + +myline = ROOT.TLine(0.05, 1, 2.29, 1) +myline.SetLineColor(2) +myline.SetLineWidth(2) +myline.SetLineStyle(2) +myline.Draw() + + +c.Update() +c.SaveAs('eFakerateComparison_Eta.pdf') + + +file_data.Close() +file_MC.Close() + +file_data = ROOT.TFile('results/newNtuple_3Dec/efakerate_fits/e_os_eLoose_eTigh_e3Pt.corrected_inputs.root') + +data_uncorrected = file_data.Get('numerator_uncorr') +den_data_uncorrected = file_data.Get('denominator_uncorr') +data_corrected = file_data.Get('numerator') +den_data_corrected = file_data.Get('denominator') + +data_uncorrected.Sumw2() +data_corrected.Sumw2() + +data_uncorrected.Divide(den_data_uncorrected) +data_corrected.Divide(den_data_corrected) + +c= ROOT.TCanvas("c","c", 800, 1000) +c.Draw() +c.SetGridx(1) +c.SetGridy(1) +pad1 = ROOT.TPad("pad1", "pad1", 0, 0.2, 1, 1) +pad1.Draw() +pad1.cd() +pad1.SetGridx(1) +pad1.SetGridy(1) +pad1.cd() +data_uncorrected.Draw('SAMEPE') +data_uncorrected.GetXaxis().SetRangeUser(0, 2.3) +data_uncorrected.GetYaxis().SetRangeUser(0, 1.2) +data_uncorrected.GetYaxis().SetTitle("fakerate") +data_uncorrected.GetYaxis().SetTitleOffset(1.3) +data_uncorrected.GetXaxis().SetTitle("e p_{T} (GeV)") +data_uncorrected.SetMarkerStyle(23) +data_uncorrected.SetMarkerColor(4) +data_uncorrected.SetLineColor(4) +data_corrected.Draw('PE') +data_corrected.SetMarkerStyle(22) + +file_MC = ROOT.TFile('results/newNtuple_3Dec/efakerate_fits_MC/e_os_eLoose_eTigh_e3Pt_plot.root') + +cMC = file_MC.Get('asdf') +dataMC = cMC.GetPrimitive('hxy_xy_data') + +pad1.cd() +dataMC.Draw('SAMEP') +#dataMC.GetYaxis().SetRangeUser(0,1) + + +dataMC.SetMarkerStyle(20) +dataMC.SetMarkerColor(2) +dataMC.SetLineColor(2) + +leg=ROOT.TLegend(0.3,0.85,0.7,0.7) +leg.SetFillColor(0) +leg.AddEntry(data_corrected, 'data, bkg corrected', 'lp') +leg.AddEntry(data_uncorrected, 'data', 'lp') +leg.AddEntry(dataMC, 'Z+jets MC', 'lp') +leg.Draw() +c.cd() + +pad2 = ROOT.TPad("pad2", "pad2", 0, 0.05, 1,0.2) +pad2.Draw() +pad2.cd() +pad2.SetGridx(1) +pad2.SetGridy(1) + +halfbinwidths=[5,5,5,5,5,10,10,15,24.7] + +denom=ROOT.TGraphErrors(dataMC.GetN()) + +for ibin in range(1, dataMC.GetN()+1): + + denom.SetPoint(ibin-1, dataMC.GetX()[ibin-1],data_corrected.GetBinContent(ibin)/dataMC.GetY()[ibin-1]) + x = dataMC.GetX()[ibin-1] + err = math.sqrt(math.pow(data_corrected.GetBinError(ibin)/dataMC.GetY()[ibin-1],2)+math.pow(dataMC.GetErrorY(ibin-1)/dataMC.GetY()[ibin-1],2)*math.pow(data_corrected.GetBinContent(ibin)/dataMC.GetY()[ibin-1],2)) + print x, data_corrected.GetBinContent(ibin)/dataMC.GetY()[ibin-1] , err, data_corrected.GetBinError(ibin), dataMC.GetErrorY(ibin-1) + denom.SetPointError(ibin-1, halfbinwidths[ibin-1], err) + + + +ratio= denom +#ratio.Divide(denom) +ratio.SetMarkerStyle(22) +ratio.Draw('APE') +ratio.GetXaxis().SetRangeUser(30,200) +ratio.GetYaxis().SetTitle('data/mc') +ratio.GetYaxis().SetRangeUser(0,4) +ratio.GetYaxis().SetTitleSize(0.15) +ratio.GetYaxis().SetLabelSize(.15) +ratio.GetXaxis().SetTitleSize(.1) +ratio.GetXaxis().SetLabelSize(.1) +ratio.GetYaxis().SetNdivisions(504, False) + +line = ROOT.TLine(35, 1, 190, 1) +line.SetLineColor(2) +line.SetLineWidth(2) +line.SetLineStyle(2) +line.Draw() + +ratio.GetYaxis().SetTitleOffset(0.3) +pad2.Update() + +c.Update() +c.SaveAs('eFakerateComparison_Pt.pdf') + + +file_data.Close() +file_MC.Close() + diff --git a/lfvetau/plotSoverSN.py b/lfvetau/plotSoverSN.py new file mode 100644 index 00000000..eb6da1e4 --- /dev/null +++ b/lfvetau/plotSoverSN.py @@ -0,0 +1,398 @@ +import ROOT +import sys +import os +import math + +try: + massrange = sys.argv[1].split(',') + print massrange +except: + + print 'please give me the mass range in the format 50,300 ' + +ROOT.gROOT.SetBatch() # don't pop up canvases + +ROOT.gROOT.SetStyle('Plain') # white background +ROOT.gStyle.SetOptStat(0) +ROOT.gStyle.SetOptTitle(0) +ROOT.gStyle.SetPadGridX(1) +ROOT.gStyle.SetPadGridY(1) + + + +samples = [ + "zjetsother", + "diboson", + "SMVBF126", + "singlet", + "SMGG126", + "ttbar", + "ztautau", + "wplusjets", + "LFVGG", + "LFVVBF" +] + +names = { + "zjetsother" : "zjetsother", + "diboson" : "diboson" , + "SMVBF126" : "SMH" , + "SMGG126" : "SMH" , + "singlet" : "singlet" , + "ttbar" : "ttbar" , + "ztautau" : "ztautau" , + "wplusjets" : "wplusjets" , + "LFVGG" : "LFVH" , + "LFVVBF" : "LFVH" +} + + +mymapper ={ + "wplusjets" : ["W $+$ jets "], + "ztautau" : ["$ Z \\rightarrow \\tau\\tau$ "], + "diboson" : ["EWK Diboson "], + "zjetsother" : ["$Z \\rightarrow ee, \\mu\\mu$"], + "ttbar" : ["$t\\bar{t}$ "], + "singlet" : ["$t$, $\\bar{t}$ "], + "SMH" : ["SM Higgs Background "], + "tot" : ["Sum of Backgrounds "], + "LFVH" : ["LFV Higgs Signal "], +} + +dirname = ['gg0etau', 'boostetau', 'vbfetau'] + +tPt = [30, 35, 40, 45, 50, 60, 70, 80, 90] +ePt = [30, 35, 40, 45, 50, 60, 70, 80, 90] +tMtToPfMet = [5, 10, 20, 30, 35, 40, 50, 60, 70, 80, 90] + +dphi = [0.50, 1.0, 1.50, 2.20, 2.40, 2.70, 3.00] + +vbf_mass = [200, 300, 400, 450, 500, 550, 600, 700, 800, 900] +vbf_deta = [2.0, 2.5, 3.0, 3.5, 4.0] + + + + +for jet in range (0, 3) : + file1 = ROOT.TFile.Open('plots/newNtuple_5Nov/lfvet/shapes.%s.root' %(str(jet))) + cuts= [ + ['selected', 'tPt30', 'tPt35', 'tPt40', 'tPt45','tPt50','tPt60','tPt70','tPt80','tPt90', + 'ePt30', 'ePt35', 'ePt40', 'ePt45','ePt50','ePt60','ePt70','ePt80','ePt90', + 'dphi0.50','dphi1.00','dphi1.50','dphi2.20','dphi2.40','dphi2.70', 'dphi3.00', + 'tMtToPfMet5','tMtToPfMet10','tMtToPfMet20','tMtToPfMet30','tMtToPfMet35','tMtToPfMet40', 'tMtToPfMet50', 'tMtToPfMet60', 'tMtToPfMet70' , 'tMtToPfMet80', 'tMtToPfMet90' ], + ['selected', 'tPt30', 'tPt35', 'tPt40', 'tPt45','tPt50','tPt60','tPt70','tPt80','tPt90', + 'ePt30', 'ePt35', 'ePt40', 'ePt45', 'ePt50','ePt60','ePt70','ePt80','ePt90', + 'tMtToPfMet5','tMtToPfMet10','tMtToPfMet20','tMtToPfMet30','tMtToPfMet35','tMtToPfMet40' , 'tMtToPfMet50', 'tMtToPfMet60', 'tMtToPfMet70' , 'tMtToPfMet80', 'tMtToPfMet90'], + ['selected', 'tPt30', 'tPt35', 'tPt40', 'tPt45','tPt50','tPt60','tPt70','tPt80','tPt90', + 'ePt30', 'ePt35', 'ePt40', 'ePt45', 'ePt50','ePt60','ePt70','ePt80','ePt90', + 'tMtToPfMet5','tMtToPfMet10','tMtToPfMet20','tMtToPfMet30','tMtToPfMet35','tMtToPfMet40', 'tMtToPfMet50', 'tMtToPfMet60', 'tMtToPfMet70', 'tMtToPfMet80', 'tMtToPfMet90', + 'vbf_mass200', 'vbf_mass300', 'vbf_mass400', 'vbf_mass450', 'vbf_mass500', 'vbf_mass550', 'vbf_mass600', 'vbf_mass700', 'vbf_mass800', 'vbf_mass900', + 'vbf_deta2.0','vbf_deta2.5','vbf_deta3.0','vbf_deta3.5', 'vbf_deta4.0' ] + ] + + + tPtcount =0 + ePtcount =0 + dphicount=0 + tMtcount =0 + vbfmasscount =0 + vbfdetacount =0 + + tPt_g = ROOT.TGraphErrors(len(tPt)) + ePt_g = ROOT.TGraphErrors(len(tPt)) + dphi_g = ROOT.TGraphErrors(len(dphi)) + tMt_g = ROOT.TGraphErrors(len(tMtToPfMet)) + vbfMass_g = ROOT.TGraphErrors(len(vbf_mass)) + vbfdeta_g = ROOT.TGraphErrors(len(vbf_deta)) + + tPt_ratio = ROOT.TGraphErrors(len(tPt)) + ePt_ratio = ROOT.TGraphErrors(len(tPt)) + dphi_ratio = ROOT.TGraphErrors(len(dphi)) + tMt_ratio = ROOT.TGraphErrors(len(tMtToPfMet)) + vbfMass_ratio = ROOT.TGraphErrors(len(vbf_mass)) + vbfdeta_ratio = ROOT.TGraphErrors(len(vbf_deta)) + + + for cut in cuts[jet]: + mydir = file1.Get("%s_%s" %(dirname[jet], cut)) + #mylist=mydir.GetListOfKeys() + totbackground =0. + totbackgrounderr2=0. + sig_int =0. + sig_err2 =0. + + + + + for sample in samples: + print dirname[jet], cut, mydir.GetName(), sample + histo = mydir.Get(sample) + integral = 0 + err2=0 + + for i in range(histo.GetXaxis().FindBin(float(massrange[0])), histo.GetXaxis().FindBin(float(massrange[1]))+1): + integral += histo.GetBinContent(i) + err2 += histo.GetBinError(i)*histo.GetBinError(i) + + if not 'LFV' in sample: + totbackground += integral + totbackgrounderr2 += err2 + + else: + sig_int =integral + sig_err2 =err2 + + + den = (sig_int+totbackground) + #print "_".join([dirname[jet], cut]), sig_int/(sig_int+totbackground) , math.sqrt((sig_err2+totbackgrounderr2)* pow(sig_int,2) / pow(den,4)) + if den==0 : + if 'tPt' in cut : tPtcount+=1 + if 'ePt' in cut : ePtcount+=1 + if 'dphi' in cut : dphicount+=1 + if 'tMtToPfMet' in cut : tMtcount+=1 + if 'vbf_mass' in cut :vbfmasscount+=1 + if 'vbf_deta' in cut : vbfdetacount+=1 + continue + + error = math.sqrt((totbackgrounderr2 * pow(sig_int,2) +sig_err2*(4*pow(den,2) - pow(sig_int,2) ))/4*pow(den,3)) + if 'tPt' in cut : + tPt_g.SetPoint(tPtcount, tPt[tPtcount], sig_int/math.sqrt(sig_int+totbackground)) + tPt_g.SetPointError(tPtcount, 0, math.sqrt((sig_err2+totbackgrounderr2)* pow(sig_int,2) / pow(den,4))) + tPt_ratio.SetPoint(tPtcount, tPt[tPtcount], sig_int/error) + tPt_ratio.SetPointError(tPtcount, 0, math.sqrt(sig_err2)/error) + tPtcount+=1 + if 'ePt' in cut : + print ePtcount, len(ePt), ePt[ePtcount] + ePt_g.SetPoint(ePtcount, ePt[ePtcount], sig_int/math.sqrt(sig_int+totbackground)) + ePt_g.SetPointError(ePtcount, 0, math.sqrt((sig_err2+totbackgrounderr2)* pow(sig_int,2) / pow(den,4))) + ePt_ratio.SetPoint(ePtcount, ePt[ePtcount], sig_int/error) + ePt_ratio.SetPointError(ePtcount, 0, math.sqrt(sig_err2)/error) + ePtcount+=1 + if 'dphi' in cut : + dphi_g.SetPoint(dphicount, dphi[dphicount], sig_int/math.sqrt(sig_int+totbackground)) + dphi_g.SetPointError(dphicount, 0, math.sqrt((sig_err2+totbackgrounderr2)* pow(sig_int,2) / pow(den,4))) + dphi_ratio.SetPoint(dphicount, dphi[dphicount], sig_int/error) + dphi_ratio.SetPointError(dphicount, 0, math.sqrt(sig_err2)/error) + dphicount+=1 + if 'tMtToPfMet' in cut : + tMt_g.SetPoint(tMtcount, tMtToPfMet[tMtcount], sig_int/math.sqrt(sig_int+totbackground)) + tMt_g.SetPointError(tMtcount, 0, math.sqrt((sig_err2+totbackgrounderr2)* pow(sig_int,2) / pow(den,4))) + tMt_ratio.SetPoint(tMtcount, tMtToPfMet[tMtcount], sig_int/error) + tMt_ratio.SetPointError(tMtcount, 0, math.sqrt(sig_err2)/error) + tMtcount+=1 + if 'vbf_mass' in cut : + vbfMass_g.SetPoint(vbfmasscount, vbf_mass[vbfmasscount], sig_int/math.sqrt(sig_int+totbackground)) + vbfMass_g.SetPointError(vbfmasscount, 0, math.sqrt((sig_err2+totbackgrounderr2)* pow(sig_int,2) / pow(den,4))) + vbfMass_ratio.SetPoint(vbfmasscount, vbf_mass[vbfmasscount], sig_int/error) + vbfMass_ratio.SetPointError(vbfmasscount, 0, math.sqrt(sig_err2)/error) + vbfmasscount+=1 + if 'vbf_deta' in cut : + vbfdeta_g.SetPoint(vbfdetacount, vbf_deta[vbfdetacount], sig_int/math.sqrt(sig_int+totbackground)) + vbfdeta_g.SetPointError(vbfdetacount, 0, math.sqrt((sig_err2+totbackgrounderr2)* pow(sig_int,2) / pow(den,4))) + vbfdeta_ratio.SetPoint(vbfdetacount, vbf_deta[vbfdetacount], sig_int/error) + vbfdeta_ratio.SetPointError(vbfdetacount, 0, math.sqrt(sig_err2)/error) + vbfdetacount+=1 + + c=ROOT.TCanvas("c", "c", 800, 800) + massInterval = massrange[0]+'_'+massrange[1] + c.Draw() + c.Divide(1,2) + + c.SetGridx(1) + c.SetGridy(1) + if jet==0: + c.cd(1) + tPt_g.SetTitle("0 jet, #tau p_{T} threshold") + tPt_g.Draw("AP") + tPt_g.GetXaxis().SetTitle("#tau p_{T} (GeV)") + tPt_g.GetYaxis().SetTitle("S/#sqrt(S+B)") + tPt_g.SetMarkerStyle(20) + ##tPt_g.SetMarkerSize(0.3) + c.cd(2) + tPt_ratio.Draw("AP") + tPt_ratio.GetXaxis().SetTitle("#tau p_{T} (GeV)") + tPt_ratio.GetYaxis().SetTitle("S/#sigma(S/#sqrt(S+B))") + tPt_ratio.SetMarkerStyle(20) + + c.Update() + c.SaveAs("0jet_tPt_%s.pdf" %massInterval) + c.Clear() + c.Divide(1,2) + c.cd(1) + ePt_g.SetTitle("0 jet, e p_{T} threshold") + ePt_g.Draw("AP") + ePt_g.GetXaxis().SetTitle("e p_{T} (GeV)") + ePt_g.GetYaxis().SetTitle("S/#sqrt(S+B)") + ePt_g.SetMarkerStyle(20) + c.cd(2) + ePt_ratio.Draw("AP") + ePt_ratio.GetXaxis().SetTitle("e p_{T} (GeV)") + ePt_ratio.GetYaxis().SetTitle("S/#sigma(S/#sqrt(S+B))") + ePt_ratio.SetMarkerStyle(20) + c.Update() + c.SaveAs("0jet_ePt_%s.pdf" %massInterval) + c.Clear() + c.Divide(1,2) + c.cd(1) + dphi_g.SetTitle("0 jet, #Delta#Phi") + dphi_g.Draw("AP") + dphi_g.GetXaxis().SetTitle("e - #tau #Delta#Phi") + dphi_g.GetYaxis().SetTitle("S/#sqrt(S+B)") + dphi_g.SetMarkerStyle(20) + c.cd(2) + dphi_ratio.Draw("AP") + dphi_ratio.GetXaxis().SetTitle("e - #tau #Delta#Phi") + dphi_ratio.GetYaxis().SetTitle("S/#sigma(S/#sqrt(S+B))") + dphi_ratio.SetMarkerStyle(20) + c.Update() + c.SaveAs("0jet_dphi_%s.pdf" %massInterval) + c.Clear() + c.Divide(1,2) + c.cd(1) + tMt_g.SetTitle("0 jet, #tau Met M_{T}") + tMt_g.Draw("AP") + tMt_g.GetXaxis().SetTitle("#tau Met M_{T}") + tMt_g.GetYaxis().SetTitle("S/#sqrt(S+B)") + tMt_g.SetMarkerStyle(20) + c.cd(2) + tMt_ratio.Draw("AP") + tMt_ratio.GetXaxis().SetTitle("#tau Met M_{T}") + tMt_ratio.GetYaxis().SetTitle("S/#sigma(S/#sqrt(S+B))") + tMt_ratio.SetMarkerStyle(20) + c.Update() + c.SaveAs("0jet_tMt_%s.pdf" %massInterval) + c.Clear() + c.Divide(1,2) + c.cd(1) + if jet==1: + c.Clear() + c.Divide(1,2) + c.cd(1) + tPt_g.SetTitle("1 jet, #tau p_{T} threshold") + tPt_g.Draw("AP") + tPt_g.GetXaxis().SetTitle("#tau p_{T} (GeV)") + tPt_g.GetYaxis().SetTitle("S/#sqrt(S+B)") + tPt_g.SetMarkerStyle(20) + c.cd(2) + tPt_ratio.Draw("AP") + tPt_ratio.GetXaxis().SetTitle("#tau p_{T} (GeV)") + tPt_ratio.GetYaxis().SetTitle("S/#sigma(S/#sqrt(S+B))") + tPt_ratio.SetMarkerStyle(20) + c.Update() + c.SaveAs("1jet_tPt_%s.pdf" %massInterval) + c.Clear() + c.Divide(1,2) + c.cd(1) + ePt_g.SetTitle("1 jet, e p_{T} threshold") + ePt_g.Draw("AP") + ePt_g.GetXaxis().SetTitle("e p_{T} (GeV)") + ePt_g.GetYaxis().SetTitle("S/#sqrt(S+B)") + ePt_g.SetMarkerStyle(20) + c.cd(2) + ePt_ratio.Draw("AP") + ePt_ratio.GetXaxis().SetTitle("e p_{T} (GeV)") + ePt_ratio.GetYaxis().SetTitle("S/#sigma(S/#sqrt(S+B))") + ePt_ratio.SetMarkerStyle(20) + c.Update() + c.SaveAs("1jet_ePt_%s.pdf" %massInterval) + c.Clear() + c.Divide(1,2) + c.cd(1) + tMt_g.SetTitle("1 jet, #tau Met M_{T}") + tMt_g.Draw("AP") + tMt_g.GetXaxis().SetTitle("#tau Met M_{T}") + tMt_g.GetYaxis().SetTitle("S/#sqrt(S+B)") + tMt_g.SetMarkerStyle(20) + c.cd(2) + tMt_ratio.Draw("AP") + tMt_ratio.GetXaxis().SetTitle("#tau Met M_{T}") + tMt_ratio.GetYaxis().SetTitle("S/#sigma(S/#sqrt(S+B))") + tMt_ratio.SetMarkerStyle(20) + c.Update() + c.SaveAs("1jet_tMt_%s.pdf" %massInterval) + c.Clear() + c.Divide(1,2) + c.cd(1) + if jet==2: + c.Clear() + c.Divide(1,2) + c.cd(1) + tPt_g.SetTitle("2 jet, #tau p_{T} threshold") + tPt_g.Draw("AP") + tPt_g.GetXaxis().SetTitle("#tau p_{T} (GeV)") + tPt_g.GetYaxis().SetTitle("S/#sqrt(S+B)") + tPt_g.SetMarkerStyle(20) + c.cd(2) + tPt_ratio.Draw("AP") + tPt_ratio.GetXaxis().SetTitle("#tau p_{T} (GeV)") + tPt_ratio.GetYaxis().SetTitle("S/#sigma(S/#sqrt(S+B))") + tPt_ratio.SetMarkerStyle(20) + c.Update() + c.SaveAs("2jet_tPt_%s.pdf" %massInterval) + c.Clear() + c.Divide(1,2) + c.cd(1) + ePt_g.SetTitle("2 jet, e p_{T} threshold") + ePt_g.Draw("AP") + ePt_g.GetXaxis().SetTitle("e p_{T} (GeV)") + ePt_g.GetYaxis().SetTitle("S/#sqrt(S+B)") + ePt_g.SetMarkerStyle(20) + c.cd(2) + ePt_ratio.Draw("AP") + ePt_ratio.GetXaxis().SetTitle("e p_{T} (GeV)") + ePt_ratio.GetYaxis().SetTitle("S/#sigma(S/#sqrt(S+B))") + ePt_ratio.SetMarkerStyle(20) + c.Update() + c.SaveAs("2jet_ePt_%s.pdf" %massInterval) + c.Clear() + c.Divide(1,2) + c.cd(1) + tMt_g.SetTitle("2 jet, #tau Met M_{T}") + tMt_g.Draw("AP") + tMt_g.GetXaxis().SetTitle("#tau Met M_{T}") + tMt_g.GetYaxis().SetTitle("S/#sqrt(S+B)") + tMt_g.SetMarkerStyle(20) + c.cd(2) + tMt_ratio.Draw("AP") + tMt_ratio.GetXaxis().SetTitle("#tau Met M_{T}") + tMt_ratio.GetYaxis().SetTitle("S/#sigma(S/#sqrt(S+B))") + tMt_ratio.SetMarkerStyle(20) + c.Update() + c.SaveAs("2jet_tMt_%s.pdf" %massInterval) + c.Clear() + c.Divide(1,2) + c.cd(1) + vbfMass_g.SetTitle("2 jet, vbf Mass") + vbfMass_g.Draw("AP") + vbfMass_g.GetXaxis().SetTitle("M_{jj}") + vbfMass_g.GetYaxis().SetTitle("S/#sqrt(S+B)") + vbfMass_g.SetMarkerStyle(20) + c.cd(2) + vbfMass_ratio.Draw("AP") + vbfMass_ratio.GetXaxis().SetTitle("M_{jj}") + vbfMass_ratio.GetYaxis().SetTitle("S/#sigma(S/#sqrt(S+B))") + vbfMass_ratio.SetMarkerStyle(20) + + c.Update() + c.SaveAs("2jet_vbfMass_%s.pdf" %massInterval) + c.Clear() + c.Divide(1,2) + c.cd(1) + vbfdeta_g.SetTitle("2 jet, #Delta#eta_{jj}") + vbfdeta_g.Draw("AP") + vbfdeta_g.GetXaxis().SetTitle("#Delta#eta_{jj}") + vbfdeta_g.GetYaxis().SetTitle("S/#sqrt(S+B)") + vbfdeta_g.SetMarkerStyle(20) + c.cd(2) + vbfdeta_ratio.Draw("AP") + vbfdeta_ratio.GetXaxis().SetTitle("2 jet, #Delta#eta_{jj}") + vbfdeta_ratio.GetYaxis().SetTitle("S/#sigma(S/#sqrt(S+B))") + vbfdeta_ratio.SetMarkerStyle(20) + + c.Update() + c.SaveAs("2jet_vbfDeta_%s.pdf" %massInterval) + c.Clear() + + + file1.Close() + diff --git a/lfvetau/produceShapeForOptimization.py b/lfvetau/produceShapeForOptimization.py new file mode 100644 index 00000000..3a43e2c8 --- /dev/null +++ b/lfvetau/produceShapeForOptimization.py @@ -0,0 +1,88 @@ +#from mauro plotters + +#Set logging before anything to override rootpy very verbose defaults +import sys +import logging +logging.basicConfig(stream=sys.stderr, level=logging.INFO) + +import os +import ROOT +from pdb import set_trace +from FinalStateAnalysis.PlotTools.MegaBase import make_dirs +from FinalStateAnalysis.MetaData.data_styles import data_styles +from FinalStateAnalysis.PlotTools.BlindView import BlindView, blind_in_range +from FinalStateAnalysis.PlotTools.SubtractionView import SubtractionView, PositiveView +import itertools +import glob +import sys +from BasePlotter import BasePlotter +from argparse import ArgumentParser + +parser = ArgumentParser(description=__doc__) +parser.add_argument('--no-plots', dest='no_plots', action='store_true', + default=False, help='Does not print plots') +parser.add_argument('--no-shapes', dest='no_shapes', action='store_true', + default=False, help='Does not create shapes for limit computation') +args = parser.parse_args() + +jobid = os.environ['jobid'] +#jobid = 'MCntuples_3March' +channel = 'et' +import rootpy.plotting.views as views + +ROOT.gROOT.SetStyle("Plain") +ROOT.gROOT.SetBatch(True) +ROOT.gStyle.SetOptStat(0) + +print "\nPlotting %s for %s\n" % (channel, jobid) + +#check if blind +blind = 'blind' not in os.environ or os.environ['blind'] == 'YES' +blind_region=[100, 150] if blind else None + +embedded = False + +plotter = BasePlotter(blind_region,use_embedded=embedded) + + +cuts= [ + ['selected', 'tPt30', 'tPt35', 'tPt40', 'tPt45','tPt50','tPt60','tPt70','tPt80','tPt90', + 'ePt30', 'ePt35', 'ePt40', 'ePt45','ePt50','ePt60','ePt70','ePt80','ePt90', + 'dphi0.50','dphi1.00','dphi1.50','dphi2.20','dphi2.40','dphi2.70', 'dphi3.00', + 'tMtToPfMet5','tMtToPfMet10','tMtToPfMet20','tMtToPfMet30','tMtToPfMet35','tMtToPfMet40', 'tMtToPfMet50', 'tMtToPfMet60', 'tMtToPfMet70' , 'tMtToPfMet80', 'tMtToPfMet90' ], + ['selected', 'tPt30', 'tPt35', 'tPt40', 'tPt45','tPt50','tPt60','tPt70','tPt80','tPt90', + 'ePt30', 'ePt35', 'ePt40', 'ePt45', 'ePt50','ePt60','ePt70','ePt80','ePt90', + 'tMtToPfMet5','tMtToPfMet10','tMtToPfMet20','tMtToPfMet30','tMtToPfMet35','tMtToPfMet40' , 'tMtToPfMet50', 'tMtToPfMet60', 'tMtToPfMet70' , 'tMtToPfMet80', 'tMtToPfMet90'], + ['selected', 'tPt30', 'tPt35', 'tPt40', 'tPt45','tPt50','tPt60','tPt70','tPt80','tPt90', + 'ePt30', 'ePt35', 'ePt40', 'ePt45', 'ePt50','ePt60','ePt70','ePt80','ePt90', + 'tMtToPfMet5','tMtToPfMet10','tMtToPfMet20','tMtToPfMet30','tMtToPfMet35','tMtToPfMet40', 'tMtToPfMet50', 'tMtToPfMet60', 'tMtToPfMet70', 'tMtToPfMet80', 'tMtToPfMet90', + 'vbf_mass200', 'vbf_mass300', 'vbf_mass400', 'vbf_mass450', 'vbf_mass500', 'vbf_mass550', 'vbf_mass600', 'vbf_mass700', 'vbf_mass800', 'vbf_mass900', + 'vbf_deta2.0','vbf_deta2.5','vbf_deta3.0','vbf_deta3.5', 'vbf_deta4.0' ] +] + +jets_names = [ + ('0', 'gg0etau_%s' , 1), + ('1', 'boostetau_%s', 1), + ('2', 'vbfetau_%s' , 5), +] +pjoin = os.path.join +for njets, cat_name, rebin in jets_names: + output_path = plotter.base_out_dir + tfile = ROOT.TFile(pjoin(output_path, 'shapes.%s.root' % njets), 'recreate') + for cut in cuts[int(njets)]: + signal_region = 'os/gg/ept30/%s/%s' %(njets, cut) + output_dir = tfile.mkdir(cat_name %cut) + unc_conf_lines, unc_vals_lines = plotter.write_shapes_for_optimization( + signal_region, 'h_collmass_pfmet', output_dir, rebin=rebin) + logging.warning('shape file %s created' % tfile.GetName()) + tfile.Close() + with open(pjoin(output_path, 'unc.%s.conf' % njets), 'w') as conf: + conf.write('\n'.join(unc_conf_lines)) + with open(pjoin(output_path, 'unc.%s.vals' % njets), 'w') as vals: + vals.write('\n'.join(unc_vals_lines)) + +with open(pjoin(output_path,'.shapes_timestamp'),'w') as stamp: + stamp.write('no use') + + + diff --git a/lfvetau/readNtuple.py b/lfvetau/readNtuple.py index 6db52736..43777afb 100644 --- a/lfvetau/readNtuple.py +++ b/lfvetau/readNtuple.py @@ -27,7 +27,7 @@ #f= ROOT.TFile("/hdfs/store/user/taroni/testneNtupleMoreTrees/Zjets_M50/make_ntuples_cfg-patTuple_cfg-00037C53-AAD1-E111-B1BE-003048D45F38.root") #one tree only #f= ROOT.TFile("/hdfs/store/user/taroni/testneNtuple/Zjets_M50/make_ntuples_cfg-patTuple_cfg-00037C53-AAD1-E111-B1BE-003048D45F38.root") - +f= ROOT.TFile("/hdfs/store/user/taroni/newNtuple_3Dec/data_SingleElectron_Run2012A_22Jan2013_v1/make_ntuples_cfg-patTuple_cfg-08172766-C973-E211-B14C-0030487D8541.root") f.ls() mytree = f.Get("et/final/Ntuple") From 8f4eed2ff6d20b7339fafeb9a9912fa2085b0bbe Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Tue, 20 Jan 2015 04:01:26 -0600 Subject: [PATCH 185/192] no veto on additional lepton --- lfvetau/EleFakeRateAnalyzerMVA.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lfvetau/EleFakeRateAnalyzerMVA.py b/lfvetau/EleFakeRateAnalyzerMVA.py index 1ee112db..da585db2 100644 --- a/lfvetau/EleFakeRateAnalyzerMVA.py +++ b/lfvetau/EleFakeRateAnalyzerMVA.py @@ -128,6 +128,7 @@ def begin(self): ##self.book(f,"e3Phi", "e3 phi", 100, -3.2, 3.2) self.book(f,"e3Eta", "e3 eta", 46, -2.3, 2.3) self.book(f,"e3AbsEta", "e3 abs eta", 23, 0, 2.3) + self.book(f,"e3Pt_vs_e3AbsEta", "e3 pt vs e3 abs eta", 23, 0, 2.3, 20, 0, 200., type=ROOT.TH2F) ##self.book(f, "e1e2Mass", "e1e2 Inv Mass", 32, 0, 320) ## @@ -176,6 +177,7 @@ def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): histos[folder+'/e3Eta'].Fill(getattr(row, self.mye3+'Eta'), weight) ##histos[folder+'/e3Phi'].Fill(getattr(row, self.mye3+'Phi'), weight) histos[folder+'/e3AbsEta'].Fill(abs(getattr(row, self.mye3+'Eta')), weight) + histos[folder+'/e3Pt_vs_e3AbsEta'].Fill(abs(getattr(row, self.mye3+'Eta')), getattr(row, self.mye3+'Pt'), weight) ##histos[folder+'/e1e2Mass'].Fill(getattr(row, self.mye1+'_'+self.mye2+'_Mass'), weight) ###histos[folder+'/tMtToPFMET'].Fill(row.tMtToPFMET,weight) @@ -226,21 +228,21 @@ def process(self): cut_flow_trk.Fill('allEvents') if not selections.eSelection(row, 'e1'): continue cut_flow_trk.Fill('e1sel') - if not selections.lepton_id_iso(row, 'e1', 'eid13Tight_idiso02'): continue + if not selections.lepton_id_iso(row, 'e1', 'eid13Loose_idiso05'): continue if abs(row.e1Eta) > 1.4442 and abs(row.e1Eta < 1.566) : continue cut_flow_trk.Fill('e1IDiso') if not selections.eSelection(row, 'e2'): continue cut_flow_trk.Fill('e2sel') - if not selections.lepton_id_iso(row, 'e2', 'eid13Tight_idiso02'): continue + if not selections.lepton_id_iso(row, 'e2', 'eid13Loose_idiso05'): continue if abs(row.e2Eta) > 1.4442 and abs(row.e2Eta) < 1.566 : continue ## cut_flow_trk.Fill('e2IDiso') ## if not abs(row.e1_e2_Mass-91.2) < 20: continue ## cut_flow_trk.Fill('ZMass') if not selections.eSelection(row, 'e3'): continue - if not selections.lepton_id_iso(row, 'e3', 'eid13Tight_idiso02'): continue #very loose loose eid13Tight_mvaLoose + if not selections.lepton_id_iso(row, 'e3', 'eid13Loose_idiso05'): continue #very loose loose eid13Tight_mvaLoose if abs(row.e3Eta) > 1.4442 and abs(row.e3Eta) < 1.566 : continue Zs= [(abs(row.e1_e2_Mass-91.2), ['e1', 'e2', 'e3']) , (abs(row.e2_e3_Mass-91.2), ['e2', 'e3', 'e1']), (abs(row.e1_e3_Mass-91.2), ['e1', 'e3', 'e2'])] @@ -255,17 +257,16 @@ def process(self): cut_flow_trk.Fill('tsel') - if row.tauVetoPt20EleTight3MuLoose : continue - #if row.tauHpsVetoPt20 : continue - if row.muVetoPt5IsoIdVtx : continue - if row.eVetoCicLooseIso : continue # change it with Loose + #if row.tauVetoPt20EleTight3MuLoose : continue + #if row.muVetoPt5IsoIdVtx : continue + #if row.eVetoCicLooseIso : continue # change it with Loose #if not row.e3MtToMET < 50: continue - cut_flow_trk.Fill('MtToMet') + cut_flow_trk.Fill('MtToMet') - # if etDR(row) < 1. : continue - if (row.run, row.lumi, row.evt, row.e1Pt, row.e2Pt)==myevent: continue - myevent=(row.run, row.lumi, row.evt, row.e1Pt, row.e2Pt) + + #if (row.run, row.lumi, row.evt, row.e1Pt, row.e2Pt)==myevent: continue + #myevent=(row.run, row.lumi, row.evt, row.e1Pt, row.e2Pt) eleiso = 'eLoose' sign = 'ss' if row.e1_e2_SS else 'os' From b016e973a803c1e5aa53b2de1568a2e2dc8b3268 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Fri, 23 Jan 2015 07:44:56 -0600 Subject: [PATCH 186/192] Electron fake update --- lfvetau/EleFakeRateAnalyzerMVA.py | 10 +- lfvetau/NewEleFakeRateFromW.py | 244 ++++++++++++++++++++++++++++++ 2 files changed, 249 insertions(+), 5 deletions(-) create mode 100644 lfvetau/NewEleFakeRateFromW.py diff --git a/lfvetau/EleFakeRateAnalyzerMVA.py b/lfvetau/EleFakeRateAnalyzerMVA.py index da585db2..461c2664 100644 --- a/lfvetau/EleFakeRateAnalyzerMVA.py +++ b/lfvetau/EleFakeRateAnalyzerMVA.py @@ -257,12 +257,12 @@ def process(self): cut_flow_trk.Fill('tsel') - #if row.tauVetoPt20EleTight3MuLoose : continue - #if row.muVetoPt5IsoIdVtx : continue - #if row.eVetoCicLooseIso : continue # change it with Loose + if row.tauVetoPt20EleTight3MuLoose : continue + if row.muVetoPt5IsoIdVtx : continue + if row.eVetoCicLooseIso : continue # change it with Loose #if not row.e3MtToMET < 50: continue - cut_flow_trk.Fill('MtToMet') + cut_flow_trk.Fill('MtToMet') #if (row.run, row.lumi, row.evt, row.e1Pt, row.e2Pt)==myevent: continue @@ -276,7 +276,7 @@ def process(self): folder=folder+'/'+str(int(jn)) self.fill_histos(row, folder) - if selections.lepton_id_iso(row, 'e3', 'eid13Tight_etauiso01'): + if selections.lepton_id_iso(row, 'e3', 'eid13Loose_etauiso01'): eleiso = 'eTigh' folder = sign+'/'+eleiso self.fill_histos(row, folder) diff --git a/lfvetau/NewEleFakeRateFromW.py b/lfvetau/NewEleFakeRateFromW.py new file mode 100644 index 00000000..750d5609 --- /dev/null +++ b/lfvetau/NewEleFakeRateFromW.py @@ -0,0 +1,244 @@ +##Correction Factor still to add +from EETree import EETree +import os +import ROOT +import math +import optimizer +import glob +import array +import mcCorrections +import baseSelections as selections +import FinalStateAnalysis.PlotTools.pytree as pytree +from FinalStateAnalysis.PlotTools.decorators import memo_last +from FinalStateAnalysis.PlotTools.MegaBase import MegaBase +from math import sqrt, pi, sin, cos, acos, sinh +from cutflowtracker import cut_flow_tracker +#Makes the cut flow histogram +cut_flow_step = ['allEvents', 'e1sel', 'e1IDiso', 'e2sel', 'e2IDiso', 'ZMass', 'tsel', 'tAntiMuon', 'tAntiEle', 'MtToMet', 'tRawIso10','tRawIso5', 'tLooseIso', 'tTightIso' +] + +from inspect import currentframe + +def get_linenumber(): + cf = currentframe() + return cf.f_back.f_lineno + +def deltaPhi(phi1, phi2): + PHI = abs(phi1-phi2) + if PHI<=pi: + return PHI + else: + return 2*pi-PHI +def deltaR(phi1, phi2, eta1, eta2): + deta = eta1 - eta2 + dphi = abs(phi1-phi2) + if (dphi>pi) : dphi = 2*pi-dphi + return sqrt(deta*deta + dphi*dphi); + + +class NewEleFakeRateFromW(MegaBase): + tree = 'ee/final/Ntuple' + def __init__(self, tree, outfile, **kwargs): + self.channel='EE' + super(NewEleFakeRateFromW, self).__init__(tree, outfile, **kwargs) + self.tree = EETree(tree) + self.out=outfile + self.histograms = {} + self.pucorrector = mcCorrections.make_puCorrector('singlee') + self.mye1 = 'e1' + self.mye2 = 'e2' + #optimizer_keys = [ i for i in optimizer.grid_search.keys() if i.startswith(self.channel) ] + self.grid_search = {} + #if len(optimizer_keys) > 1: + # for key in optimizer_keys: + # self.grid_search[key] = optimizer.grid_search[key] + #else: + # self.grid_search[''] = optimizer.grid_search[optimizer_keys[0]] + + + def event_weight(self, row): + if row.run > 2: #FIXME! add tight ID correction + return 1. + + + return self.pucorrector(row.nTruePU) * \ + mcCorrections.eid_correction( row, 'e1', 'e2') * \ + mcCorrections.eiso_correction(row, 'e1', 'e2') * \ + mcCorrections.trig_correction(row, 'e2' ) + + + +##add the trigger correction + + def begin(self): + + eiso = ['eLoose', 'eTigh'] + folder = [] + sign = ['ss','os'] + for iso in eiso: + for s in sign: + folder.append(s+'/'+iso) + j=0 + while j < 4 : + folder.append(s+'/'+iso+'/'+str(j)) + j+=1 + + for f in folder: + + self.book(f,"e1Pt", "e1 p_{T}", 200, 0, 200) + ##self.book(f,"e1Phi", "e1 phi", 100, -3.2, 3.2) + ##self.book(f,"e1Eta", "e1 eta", 46, -2.3, 2.3) + ## + self.book(f,"e2Pt", "e2 p_{T}", 200, 0, 200) + self.book(f,"e2Phi", "e2 phi", 100, -3.2, 3.2) + self.book(f,"e2Eta", "e2 eta", 46, -2.3, 2.3) + self.book(f,"e2AbsEta", "e2 abs eta", 23, 0, 2.3) + self.book(f,"e2Pt_vs_e2AbsEta", "e2 pt vs e2 abs eta", 23, 0, 2.3, 20, 0, 200., type=ROOT.TH2F) + + + self.book(f, "e1e2Mass", "e1e2 Inv Mass", 32, 0, 320) + self.book(f, "e1MtToPFMET", "e1MtToPFMET", 20, 0, 200 ) + self.book(f, "e2MtToPFMET", "e2MtToPFMET", 20, 0, 200 ) + self.book(f, "e1e2_DeltaPhi", "e1-e2 DeltaPhi" , 32, 0, 3.2) + self.book(f, "e1e2_DeltaR", "e1-e2 DeltaR" , 32, 0, 3.2) + + + for s in sign: + self.book(s+'/tNoCuts', "CUT_FLOW", "Cut Flow", len(cut_flow_step), 0, len(cut_flow_step)) + + xaxis = self.histograms[s+'/tNoCuts/CUT_FLOW'].GetXaxis() + self.cut_flow_histo = self.histograms[s+'/tNoCuts/CUT_FLOW'] + self.cut_flow_map = {} + for i, name in enumerate(cut_flow_step): + xaxis.SetBinLabel(i+1, name) + self.cut_flow_map[name] = i+0.5 + + def fill_histos(self, row, folder='os/tSuperLoose', fakeRate = False): + weight = self.event_weight(row) + histos = self.histograms + + + + + ##histos[folder+'/e1Pt'].Fill( getattr(row, self.mye1+'Pt'), weight) + ##histos[folder+'/e1Eta'].Fill(getattr(row, self.mye1+'Eta'), weight) + ##histos[folder+'/e1Phi'].Fill(getattr(row, self.mye1+'Phi'), weight) + ## + histos[folder+'/e2Pt'].Fill( row.e2Pt , weight) + histos[folder+'/e2Eta'].Fill(row.e2Eta, weight) + histos[folder+'/e2Phi'].Fill(row.e2Phi, weight) + histos[folder+'/e2AbsEta'].Fill(abs(row.e2Eta), weight) + histos[folder+'/e2Pt_vs_e2AbsEta'].Fill(abs(row.e2Eta), row.e2Pt, weight) + + histos[folder+'/e1e2Mass'].Fill(getattr(row, 'e1_e2_Mass'), weight) + histos[folder+'/e1MtToPFMET'].Fill(row.e1MtToPfMet,weight) + histos[folder+'/e2MtToPFMET'].Fill(row.e2MtToPfMet,weight) + + histos[folder+'/e1e2_DeltaPhi'].Fill(deltaPhi(row.e1Phi, row.e2Phi), weight) + histos[folder+'/e1e2_DeltaR'].Fill(row.e1_e2_DR, weight) + + + ###histos[folder+'/type1_pfMetEt'].Fill(row.type1_pfMet_Et) + ##histos[folder+'/ee3DR'].Fill(self.ee3DR(row)) + ##histos[folder+'/ee3DPhi'].Fill(self.ee3DPhi(row)) + ##histos[folder+'/jetN_30'].Fill(row.jetVeto30, weight) + ##histos[folder+'/bjetCSVVeto30'].Fill(row.bjetCSVVeto30, weight) + ## + ##histos[folder+'/ze3DR'].Fill(deltaR(self.Z(row).Phi(), getattr(row, self.mye3+'Phi'), self.Z(row).Eta(), getattr(row, self.mye3+'Eta'))) + ##histos[folder+'/ze3DPhi'].Fill(deltaPhi(self.Z(row).Phi(), getattr(row, self.mye3+'Phi'))) + ##histos[folder+'/Zpt'].Fill(self.Z(row).Pt()) + + + def process(self): + + cut_flow_histo = self.cut_flow_histo + cut_flow_trk = cut_flow_tracker(cut_flow_histo) + myevent =() + #print self.tree.inputfilename + for row in self.tree: + jn = row.jetVeto30 + if jn > 3 : jn = 3 + + #if row.run > 2: + if not bool(row.singleE27WP80Pass) : continue + # if hasattr(self.tree, 'row.e1MatchesEle27WP80') and hasattr(self.tree, 'row.e2MatchesEle27WP80') : + #if not bool(row.e1MatchesEle27WP80) and not bool(row.e2MatchesEle27WP80) : continue + + #else : + if not bool(row.e2MatchesSingleE27WP80) : continue + if not bool(row.e1MatchesSingleE27WP80) : continue + #if not bool(row.singleEPass) : continue + #if not bool(row.e1MatchesSingleE) and not bool(row.e2MatchesSingleE) : continue + + if row.bjetCSVVeto30!=0 : continue + #if jn !=0: continue + if row.e1Pt < 30 : continue + if row.e2Pt < 30 : continue + +# for i, row in enumerate(self.tree): +# if i >= 100: +# return + # print bool(cut_flow_trk.disabled) + cut_flow_trk.new_row(row.run,row.lumi,row.evt) + #print row.run,row.lumi,row.evt + cut_flow_trk.Fill('allEvents') + if not selections.eSelection(row, 'e1'): continue + cut_flow_trk.Fill('e1sel') + if not selections.lepton_id_iso(row, 'e1', 'eid13Tight_etauiso01'): continue ##good iso point 0.5 + if abs(row.e1Eta) > 1.4442 and abs(row.e1Eta < 1.566) : continue + + + cut_flow_trk.Fill('e1IDiso') + if not selections.eSelection(row, 'e2'): continue + cut_flow_trk.Fill('e2sel') + if not selections.lepton_id_iso(row, 'e2', 'eid13Loose_idiso05'): continue # goodisopoint 0.5 + if abs(row.e2Eta) > 1.4442 and abs(row.e2Eta) < 1.566 : continue + + + ##if not row.e1_e2_SS: continue + ## cut_flow_trk.Fill('e2IDiso') + if abs(row.e1_e2_Mass-91.2) < 20: continue + ## cut_flow_trk.Fill('ZMass')' + + if row.e1MtToPfMet < 20 : continue + + + cut_flow_trk.Fill('tsel') + + + if row.tauVetoPt20EleTight3MuLoose : continue + if row.muVetoPt5IsoIdVtx : continue + if row.eVetoCicLooseIso : continue # change it with Loose + + #if not row.e3MtToMET < 50: continue + cut_flow_trk.Fill('MtToMet') + + + #if (row.run, row.lumi, row.evt, row.e1Pt, row.e2Pt)==myevent: continue + #myevent=(row.run, row.lumi, row.evt, row.e1Pt, row.e2Pt) + + eleiso = 'eLoose' + sign = 'ss' if row.e1_e2_SS else 'os' + folder = sign+'/'+eleiso + + self.fill_histos(row, folder) + folder=folder+'/'+str(int(jn)) + self.fill_histos(row, folder) + + if selections.lepton_id_iso(row, 'e2', 'eid13Tight_etauiso01'): + eleiso = 'eTigh' + folder = sign+'/'+eleiso + self.fill_histos(row, folder) + cut_flow_trk.Fill('tTightIso') + folder=folder+'/'+str(int(jn)) + self.fill_histos(row, folder) + + + + + cut_flow_trk.flush() + + + + def finish(self): + self.write_histos() From 66925654caf7e00b8767528b8424e5d40e543474 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Tue, 3 Feb 2015 07:10:30 -0600 Subject: [PATCH 187/192] Neglecting ees --- lfvetau/BasePlotter.py | 147 +++++++++++++++++++++++++---------------- 1 file changed, 91 insertions(+), 56 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index 59832393..4a3f4f45 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -91,14 +91,25 @@ def parse_cgs_groups(file_path): groups[match.group('groupname')] = [ i.strip() for i in match.group('includes').split(',') ] return groups -def remove_empty_bins(histogram, weight): +def remove_empty_bins(histogram, weight, first = 0, last = 0): ret = histogram.Clone() - for i in range(ret.GetNbinsX() + 2): + last = last if last else ret.GetNbinsX() + 1 + for i in range(first, last+1): if ret.GetBinContent(i) <= 0: ret.SetBinContent(i, 0.9200*weight) #MEAN WEIGHT ret.SetBinError(i, 1.8*weight) return ret +def find_fill_range(histo): + first, last = (0, 0) + for i in range(histo.GetNbinsX() + 2): + if histo.GetBinContent(i) > 0: + if first: + last = i + else: + first = i + return first, last + class BasePlotter(Plotter): def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): cwd = os.getcwd() @@ -129,17 +140,19 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): super(BasePlotter, self).__init__(files, lumifiles, outputdir, blinder, forceLumi=forceLumi) self.mc_samples = [ - 'GluGluToHToTauTau_M-125*', - 'VBF_HToTauTau_M-125*', + 'ggH[tWB][tWB]', + 'vbfH[tWB][tWB]', + ##'GluGluToHToTauTau_M-125*', + ##'VBF_HToTauTau_M-125*', 'TTJets*', 'T*_t*', '[WZ][WZ]Jets', - 'Wplus*Jets_madgraph*', #superseded by fakes #add in case of optimization study + #'Wplus*Jets_madgraph*', #superseded by fakes #add in case of optimization study 'Z*jets_M50_skimmedLL', - #'WH*HToTauTau', - #'WH*HToWW', - #'vbfHWW', - #'ggHWW', + ##'WH*HToTauTau', + ##'WH*HToWW', + ##'vbfHWW', + ##'ggHWW'#, 'Z*jets_M50_skimmedTT' ] @@ -151,14 +164,16 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): 'view' : embedded_view, 'weight' : weight } - #self.views['fakes'] = {'view' : self.make_fakes('t')} + self.views['fakes'] = {'view' : self.make_fakes('t')} # comment in case of optimization study #self.views['efakes'] = {'view' : self.make_fakes('e')} #self.views['etfakes'] = {'view' : self.make_fakes('et')} #names must match with what defined in self.mc_samples self.datacard_names = { - 'GluGluToHToTauTau_M-125*' : 'SMGG126' , - 'VBF_HToTauTau_M-125*' : 'SMVBF126' , + ##'GluGluToHToTauTau_M-125*' : 'SMGG126' , + ##'VBF_HToTauTau_M-125*' : 'SMVBF126' , + 'ggH[tWB][tWB]' : 'SMGG126' , + 'vbfH[tWB][tWB]' : 'SMVBF126' , 'TTJets*' : 'ttbar' , 'T*_t*' : 'singlet' , '[WZ][WZ]Jets' : 'diboson' , @@ -167,23 +182,23 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): 'Z*jets_M50_skimmedLL' : 'zjetsother', 'missing1' : 'WWVBF126', 'missing2' : 'WWGG126', -# 'vbfHWW' : 'WWVBF126', -# 'ggHWW' : 'WWGG126', + ##'vbfHWW' : 'WWVBF126', + ##'ggHWW' : 'WWGG126', 'ggHiggsToETau' : 'LFVGG', 'vbfHiggsToETau' : 'LFVVBF', - 'Wplus*Jets_madgraph*' : 'wplusjets'#add in case of optimization study -# 'fakes' : 'fakes', -# 'WH*HToTauTau' : 'VHtautau' , #"VHtautau", -# 'WH*HToWW' : 'VHWW' , #"VHWW", +# 'Wplus*Jets_madgraph*' : 'wplusjets'#add in case of optimization study + 'fakes' : 'fakes', + ##'WH*HToTauTau' : 'VHtautau' , #"VHtautau", + ##'WH*HToWW' : 'VHWW' , #"VHWW", ##'efakes' : 'efakes', ##'etfakes' : 'etfakes' } self.sample_groups = {#parse_cgs_groups('card_config/cgs.0.conf') 'fullsimbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', - 'diboson', 'zjetsother', 'wplusjets'],# 'WWVBF126', 'WWGG126','VHWW','VHtautau'], #wplusjets added in case of optimization study + 'diboson', 'zjetsother'],# 'WWVBF126', 'WWGG126','VHWW','VHtautau'], #wplusjets added in case of optimization study# 'wplusjets'], 'simbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', 'ztautau', - 'diboson', 'zjetsother', 'wplusjets'],#'WWVBF126', 'WWGG126','VHWW','VHtautau'], + 'diboson', 'zjetsother'],# 'WWVBF126', 'WWGG126','VHWW','VHtautau'],# 'wplusjets'], 'realtau' : ['ztautau', 'SMGG126', 'SMVBF126'],# 'VHtautau'], } @@ -200,18 +215,18 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): '-' : dir_systematic('trm1s'), 'apply_to' : ['simbkg'], }, -## 'E_ID' : { ## to comment in case of optimization study -## 'type' : 'yield', -## '+' : dir_systematic('eidp1s'), -## '-' : dir_systematic('eidm1s'), -## 'apply_to' : ['simbkg'], -## }, -## 'E_Iso' : { ## to comment in case of optimization study -## 'type' : 'yield', -## '+' : dir_systematic('eisop1s'), -## '-' : dir_systematic('eisom1s'), -## 'apply_to' : ['simbkg'], -## }, + 'E_ID' : { ## to comment in case of optimization study + 'type' : 'yield', + '+' : dir_systematic('eidp1s'), + '-' : dir_systematic('eidm1s'), + 'apply_to' : ['simbkg'], + }, + 'E_Iso' : { ## to comment in case of optimization study + 'type' : 'yield', + '+' : dir_systematic('eisop1s'), + '-' : dir_systematic('eisom1s'), + 'apply_to' : ['simbkg'], + }, 'JES' : { 'type' : 'shape', '+' : lambda x: os.path.join('jes_plus', x)+'_jes_plus' , @@ -224,24 +239,24 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): '-' : lambda x: os.path.join('tes_minus', x)+'_tes_minus' , 'apply_to' : ['realtau'], }, - 'EES' : { + ##'EES' : { + ## 'type' : 'shape', + ## '+' : lambda x: os.path.join('ees_plus', x) +'_ees_plus' , + ## '-' : lambda x: os.path.join('ees_minus', x)+'_ees_minus' , + ## 'apply_to' : ['simbkg'], + ##}, + 'UES' : { ## to comment in case of optimization study 'type' : 'shape', - '+' : lambda x: os.path.join('ees_plus', x) +'_ees_plus' , - '-' : lambda x: os.path.join('ees_minus', x)+'_ees_minus' , - 'apply_to' : ['simbkg'], + '+' : name_systematic('_ues_plus'), + '-' : name_systematic('_ues_minus'), + 'apply_to' : ['fullsimbkg'], + }, + 'shape_FAKES' : { ## to comment in case of optimization study + 'type' : 'shape', + '+' : dir_systematic('Up'), + '-' : dir_systematic('Down'), + 'apply_to' : ['fakes']#,'efakes','etfakes'], }, -## 'UES' : { ## to comment in case of optimization study -## 'type' : 'shape', -## '+' : name_systematic('_ues_plus'), -## '-' : name_systematic('_ues_minus'), -## 'apply_to' : ['fullsimbkg'], -## }, -## 'shape_FAKES' : { ## to comment in case of optimization study -## 'type' : 'shape', -## '+' : dir_systematic('Up'), -## '-' : dir_systematic('Down'), -## 'apply_to' : ['fakes']#,'efakes','etfakes'], -## }, 'stat' : { 'type' : 'stat', '+' : lambda x: x, @@ -643,7 +658,7 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', met_systematics = [ #it was without plus ('_jes_plus', '_jes_minus'), ('_mes_plus', '_mes_minus'), - ('_ees_plus', '_ees_minus'), + ##('_ees_plus', '_ees_minus'), ('_tes_plus', '_tes_minus'), ('_ues_plus', '_ues_minus'), ] @@ -841,9 +856,12 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', ## Make sure we can see everything if data.GetMaximum() > mc_stack.GetMaximum(): mc_stack.SetMaximum(1.2*data.GetMaximum()) - + if lfvh.GetMaximum() > mc_stack.GetMaximum(): + mc_stack.SetMaximum(1.2*lfvh.GetMaximum()) + if plot_data: self.add_legend([data, mc_stack], leftside, entries=len(mc_stack.GetHists())+1) + #self.add_legend([data, sig[0], sig[1], mc_stack], leftside, entries=len(mc_stack.GetHists())+3) else: self.add_legend([sig[0], sig[1], mc_stack], leftside, entries=len(mc_stack.GetHists())+1) if show_ratio and plot_data: @@ -952,6 +970,16 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, output_dir.cd() path = os.path.join(folder,variable) + # Draw data + data_view = self.get_view('data') + if preprocess: + data_view = preprocess( data_view ) + data_view = self.rebin_view(data_view, rebin) + data = data_view.Get(path) + first_filled, last_filled = find_fill_range(data) + data.SetName('data_obs') + data.Write() + #make MC views with xsec error bkg_views = dict( [(self.datacard_names[i], j) for i, j in zip(self.mc_samples, self.mc_views(rebin, preprocess))] @@ -965,7 +993,8 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, mc_histo = view.Get(path) bkg_histos[name] = mc_histo.Clone() mc_histo = remove_empty_bins( - mc_histo, bkg_weights[name]) + mc_histo, bkg_weights[name], + first_filled, last_filled) mc_histo.SetName(name) mc_histo.Write() @@ -981,7 +1010,8 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, mc_histo = view.Get(path) bkg_histos[name] = mc_histo.Clone() mc_histo = remove_empty_bins( - mc_histo, weight) + mc_histo, weight, + first_filled, last_filled) mc_histo.SetName(name) mc_histo.Write() @@ -1002,7 +1032,8 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, fake_shape = bkg_views['fakes'].Get(path) bkg_histos['fakes'] = fake_shape.Clone() fake_shape = remove_empty_bins( - fake_shape, bkg_weights['fakes']) + fake_shape, bkg_weights['fakes'], + first_filled, last_filled) fake_shape.SetName('fakes') fake_shape.Write() @@ -1047,8 +1078,12 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, elif info['type'] == 'shape': #remove empty bins also for shapes #(but not in general to not spoil the stat uncertainties) - up = remove_empty_bins(up, bkg_weights[target]) - down = remove_empty_bins(down, bkg_weights[target]) + up = remove_empty_bins( + up, bkg_weights[target], + first_filled, last_filled) + down = remove_empty_bins( + down, bkg_weights[target], + first_filled, last_filled) up.SetName('%s_%sUp' % (target, unc_name)) down.SetName('%s_%sDown' % (target, unc_name)) up.Write() @@ -1390,7 +1425,7 @@ def write_shapes_for_optimization(self, folder, variable, output_dir, br_strengh up.Rebin(nbins) yield_val = up.GetBinContent(1) yield_err = up.GetBinError(1) - print target, yield_val, yield_err, + #print target, yield_val, yield_err, if yield_val==0: unc_value = 0. else: From 247973faf44c5f1b9d5370ebd336af2d8788ee3c Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Thu, 12 Feb 2015 08:01:14 -0600 Subject: [PATCH 188/192] plotter for Feb 11th datacard --- lfvetau/BasePlotter.py | 58 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index 4a3f4f45..c8937cf8 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -142,17 +142,17 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): self.mc_samples = [ 'ggH[tWB][tWB]', 'vbfH[tWB][tWB]', - ##'GluGluToHToTauTau_M-125*', - ##'VBF_HToTauTau_M-125*', + #'GluGluToHToTauTau_M-125*', + #'VBF_HToTauTau_M-125*', 'TTJets*', 'T*_t*', '[WZ][WZ]Jets', #'Wplus*Jets_madgraph*', #superseded by fakes #add in case of optimization study 'Z*jets_M50_skimmedLL', - ##'WH*HToTauTau', - ##'WH*HToWW', - ##'vbfHWW', - ##'ggHWW'#, + #'WH*HToTauTau', + #'WH*HToWW', + #'vbfHWW', + #'ggHWW', 'Z*jets_M50_skimmedTT' ] @@ -170,8 +170,8 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): #names must match with what defined in self.mc_samples self.datacard_names = { - ##'GluGluToHToTauTau_M-125*' : 'SMGG126' , - ##'VBF_HToTauTau_M-125*' : 'SMVBF126' , + #'GluGluToHToTauTau_M-125*' : 'SMGG126' , + #'VBF_HToTauTau_M-125*' : 'SMVBF126' , 'ggH[tWB][tWB]' : 'SMGG126' , 'vbfH[tWB][tWB]' : 'SMVBF126' , 'TTJets*' : 'ttbar' , @@ -180,26 +180,26 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): 'Z*jets_M50_skimmedTT' : 'ztautau' , 'ZetauEmbedded' : 'ztautau' , 'Z*jets_M50_skimmedLL' : 'zjetsother', - 'missing1' : 'WWVBF126', - 'missing2' : 'WWGG126', - ##'vbfHWW' : 'WWVBF126', - ##'ggHWW' : 'WWGG126', + #'missing1' : 'WWVBF126', + #'missing2' : 'WWGG126', + #'vbfHWW' : 'WWVBF126', + #'ggHWW' : 'WWGG126', 'ggHiggsToETau' : 'LFVGG', 'vbfHiggsToETau' : 'LFVVBF', # 'Wplus*Jets_madgraph*' : 'wplusjets'#add in case of optimization study 'fakes' : 'fakes', - ##'WH*HToTauTau' : 'VHtautau' , #"VHtautau", - ##'WH*HToWW' : 'VHWW' , #"VHWW", + #'WH*HToTauTau' : 'VH',#'VHtautau' , #"VHtautau", + #'WH*HToWW' : 'VH'#,'VHWW' , #"VHWW", ##'efakes' : 'efakes', ##'etfakes' : 'etfakes' } self.sample_groups = {#parse_cgs_groups('card_config/cgs.0.conf') 'fullsimbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', - 'diboson', 'zjetsother'],# 'WWVBF126', 'WWGG126','VHWW','VHtautau'], #wplusjets added in case of optimization study# 'wplusjets'], + 'diboson', 'zjetsother'],#, 'WWVBF126', 'WWGG126','VHWW','VHtautau'], #wplusjets added in case of optimization study# 'wplusjets'], 'simbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', 'ztautau', - 'diboson', 'zjetsother'],# 'WWVBF126', 'WWGG126','VHWW','VHtautau'],# 'wplusjets'], - 'realtau' : ['ztautau', 'SMGG126', 'SMVBF126'],# 'VHtautau'], + 'diboson', 'zjetsother'],#, 'WWVBF126', 'WWGG126','VHWW','VHtautau'],# 'wplusjets'], + 'realtau' : ['ztautau', 'SMGG126', 'SMVBF126'],#, 'VHtautau'], } self.systematics = { @@ -215,18 +215,18 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): '-' : dir_systematic('trm1s'), 'apply_to' : ['simbkg'], }, - 'E_ID' : { ## to comment in case of optimization study - 'type' : 'yield', - '+' : dir_systematic('eidp1s'), - '-' : dir_systematic('eidm1s'), - 'apply_to' : ['simbkg'], - }, - 'E_Iso' : { ## to comment in case of optimization study - 'type' : 'yield', - '+' : dir_systematic('eisop1s'), - '-' : dir_systematic('eisom1s'), - 'apply_to' : ['simbkg'], - }, + ##'E_ID' : { ## to comment in case of optimization study + ## 'type' : 'yield', + ## '+' : dir_systematic('eidp1s'), + ## '-' : dir_systematic('eidm1s'), + ## 'apply_to' : ['simbkg'], + ##}, + ##'E_Iso' : { ## to comment in case of optimization study + ## 'type' : 'yield', + ## '+' : dir_systematic('eisop1s'), + ## '-' : dir_systematic('eisom1s'), + ## 'apply_to' : ['simbkg'], + ##}, 'JES' : { 'type' : 'shape', '+' : lambda x: os.path.join('jes_plus', x)+'_jes_plus' , From 5bdfffbd93582af78198e9b2199eac98c41297ea Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Tue, 10 Mar 2015 12:59:19 -0500 Subject: [PATCH 189/192] adding Zee syst --- lfvetau/LFVHETauAnalyzerMVA.py | 191 +++++++++++++++++++++------------ 1 file changed, 121 insertions(+), 70 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 92a3451d..92a13682 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -28,14 +28,20 @@ def getVar(name, var): met_et = 'pfMet_Et%s' met_phi = 'pfMet_Phi%s' +ty1met_et = 'type1_pfMet_Et%s' +ty1met_phi = 'type1_pfMet_Phi%s' t_pt = 'tPt%s' etMass = 'e_t_Mass%s' @memo def met(shift=''): + if not 'es' in shift : + return ty1met_et %shift return met_et % shift @memo def metphi(shift=''): + if not 'es' in shift : + return ty1met_phi %shift return met_phi % shift @memo def tpt(shift=''): @@ -92,12 +98,33 @@ def deltaR(phi1, ph2, eta1, eta2): if (dphi>pi) : dphi = 2*pi-dphi return sqrt(deta*deta + dphi*dphi); +def collmassZeeShift(row,weight): + ptnu =abs(row.type1_pfMet_Et*cos(deltaPhi(type1_pfMet_Phi, row.tPhi))) + visfrac = row.tPt/(row.tPt+ptnu) + #print met, cos(deltaPhi(metPhi, row.tPhi)), ptnu, visfrac + return (row.e_t_Mass / sqrt(visfrac))*weight + + def make_collmass_systematics(shift): + if shift.startswith('tes'): - ptnu =abs(met*cos(deltaPhi(metPhi, row.tPhi))) + ptnu =abs(met*cos(deltaPhi(metphi, row.tPhi))) visfrac = tpt/(tpt+ptnu) vis_mass = vismass(shift) return (vis_mass / sqrt(visfrac)) + elif shift.startswith('ees'): + ptnu =abs(met*cos(deltaPhi(metphi, row.tPhi))) + visfrac = tpt/(tpt+ptnu) + vis_mass = vismass(shift) + return (vis_mass / sqrt(visfrac)) + + elif shift.startswith('etaufake'): + + if shift== 'etaufakep1s': + return collmassZeeShift(row, 1.025) + else: + return collmassZeeShift(row,0.975) + else: met_name = met(shift) phi_name = metphi(shift) @@ -122,23 +149,37 @@ def __init__(self, tree, outfile, **kwargs): self.is_data = target.startswith('data_') self.is_embedded = ('Embedded' in target) self.is_mc = not (self.is_data or self.is_embedded) - self.efake = e_fake_rate(0.2) - self.efakeup = e_fake_rate_up(0.2) - self.efakedw = e_fake_rate_dw(0.2) + self.is_Zee = (target.endswith('skimmedLL') or target.endswith('skimmedLL.root') ) + #self.efake = e_fake_rate(0.2) # new fakerate shows a pt dependence + #self.efakeup = e_fake_rate_up(0.2) + #self.efakedw = e_fake_rate_dw(0.2) #systematics used self.systematics = { + 'trig' : (['', 'trp1s', 'trm1s'] if not self.is_data else []), 'pu' : (['', 'p1s', 'm1s'] if self.is_mc else []), - 'eid' : (['', 'eidp1s','eidm1s'] if False else []), - 'eiso' : (['', 'eisop1s','eisom1s'] if False else []), + 'eid' : (['', 'eidp1s','eidm1s'] if not self.is_data else []), + 'etaufake' : (['', 'etaufakep1s','etaufakem1s'] if self.is_Zee else []), + 'eiso' : (['', 'eisop1s','eisom1s'] if not self.is_data else []), 'jes' : (['', '_jes_plus','_jes_minus'] if self.is_mc else ['']), - 'mvetos': (['', 'mVetoUp', 'mVetoDown'] if False else ['']), - 'tvetos': (['', 'tVetoUp', 'tVetoDown'] if False else ['']), - 'evetos': (['', 'eVetoUp', 'eVetoDown'] if False else ['']), + 'mvetos': (['', 'mVetoUp', 'mVetoDown'] if self.is_mc else ['']), + 'tvetos': (['', 'tVetoUp', 'tVetoDown'] if self.is_mc else ['']), + 'evetos': (['', 'eVetoUp', 'eVetoDown'] if self.is_mc else ['']), 'met' : (["_mes_plus", "_ues_plus", "_mes_minus", "_ues_minus"] if self.is_mc else []), 'tes' : (["", "_tes_plus", "_tes_minus"] if not self.is_data else ['']), 'ees' : (["", "_ees_plus", '_ees_minus'] if not self.is_data else ['']) + #### 'trig' : (['', 'trp1s', 'trm1s'] if not self.is_data else []), + #### 'pu' : (['', 'p1s', 'm1s'] if self.is_mc else []), + #### 'eid' : (['', 'eidp1s','eidm1s'] if False else []), + #### 'eiso' : (['', 'eisop1s','eisom1s'] if False else []), + #### 'jes' : (['', '_jes_plus','_jes_minus'] if self.is_mc else ['']), + #### 'mvetos': (['', 'mVetoUp', 'mVetoDown'] if False else ['']), + #### 'tvetos': (['', 'tVetoUp', 'tVetoDown'] if False else ['']), + #### 'evetos': (['', 'eVetoUp', 'eVetoDown'] if False else ['']), + #### 'met' : (["_mes_plus", "_ues_plus", "_mes_minus", "_ues_minus"] if self.is_mc else []), + #### 'tes' : (["", "_tes_plus", "_tes_minus"] if not self.is_data else ['']), + #### 'ees' : (["", "_ees_plus", '_ees_minus'] if not self.is_data else ['']) } #self filling histograms @@ -177,6 +218,10 @@ def __init__(self, tree, outfile, **kwargs): #patch name postfix = shift self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) + for shift in self.systematics['etaufake']: + #patch name + postfix = shift + self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) #PU correctors @@ -213,6 +258,7 @@ def event_weight(self, row, sys_shifts): mcCorrections.eiso_correction(row, 'e', shift=shift) * \ self.trig_weight(row, 'e', shift=shift) * \ self.pucorrector(row.nTruePU, shift=shift) + if self.is_Zee: weights[shift] =weights[shift]*mcCorrections.etaufake_correction( row, 't', shift=shift) return weights ## @@ -221,6 +267,7 @@ def begin(self): sys_shifts = self.systematics['trig'] + \ self.systematics['pu'] + \ self.systematics['eid'] + \ + self.systematics['etaufake'] + \ self.systematics['eiso'] + \ self.systematics['mvetos'] + \ self.systematics['tvetos'] + \ @@ -261,6 +308,8 @@ def book_with_sys(location, name, *args, **kwargs): for postfix in postfixes: #patch name to be removed fix = postfix + if 'type1_' in name : name=name[6:] ## remove this line when the ntuples have the correct systematics + #print name self.book(location, name+fix, *args, **kwargs) self.book('os/gg/ept30/', "h_collmass_pfmet" , "h_collmass_pfmet", 32, 0, 320) @@ -275,57 +324,57 @@ def book_with_sys(location, name, *args, **kwargs): # type=pytree.PyTree #) self.book(f,"weight", "weight", 100, 0, 10) - #@# self.book(f,"tPt", "tau p_{T}", 40, 0, 200) - #@# self.book(f,"tPt_tes_plus", "tau p_{T} (tes+)", 40, 0, 200) - #@# self.book(f,"tPt_tes_minus", "tau p_{T} (tes-)",40, 0, 200) - #@# - #@# self.book(f,"tPhi", "tau phi", 26, -3.25, 3.25) - #@# self.book(f,"tEta", "tau eta", 10, -2.5, 2.5) - #@# - #@# self.book(f,"ePt", "e p_{T}", 40, 0, 200) - #@# self.book(f,"ePt_ees_plus", "e p_{T} (ees+)", 40, 0, 200) - #@# self.book(f,"ePt_ees_minus", "e p_{T} (ees-)",40, 0, 200) - #@# - #@# self.book(f,"ePhi", "e phi", 26, -3.2, 3.2) - #@# self.book(f,"eEta", "e eta", 10, -2.5, 2.5) - #@# - #@# self.book(f, "e_t_DPhi", "e-tau DeltaPhi" , 20, 0, 3.2) - #@# self.book(f, "e_t_DR", "e-tau DeltaR" , 20, 0, 3.2) + self.book(f,"tPt", "tau p_{T}", 40, 0, 200) + self.book(f,"tPt_tes_plus", "tau p_{T} (tes+)", 40, 0, 200) + self.book(f,"tPt_tes_minus", "tau p_{T} (tes-)",40, 0, 200) + + self.book(f,"tPhi", "tau phi", 26, -3.25, 3.25) + self.book(f,"tEta", "tau eta", 10, -2.5, 2.5) + + self.book(f,"ePt", "e p_{T}", 40, 0, 200) + self.book(f,"ePt_ees_plus", "e p_{T} (ees+)", 40, 0, 200) + self.book(f,"ePt_ees_minus", "e p_{T} (ees-)",40, 0, 200) + + self.book(f,"ePhi", "e phi", 26, -3.2, 3.2) + self.book(f,"eEta", "e eta", 10, -2.5, 2.5) + + self.book(f, "e_t_DPhi", "e-tau DeltaPhi" , 20, 0, 3.2) + self.book(f, "e_t_DR", "e-tau DeltaR" , 20, 0, 3.2) #self.book(f, "h_collmass_pfmet", "h_collmass_pfmet", 32, 0, 320) book_with_sys(f, "h_collmass_pfmet", "h_collmass_pfmet", 40, 0, 400, postfixes=full_met_systematics) - - #@# self.book(f, "h_collmass_vs_dPhi_pfmet", "h_collmass_vs_dPhi_pfmet", 20, 0, 3.2, 40, 0, 400, type=ROOT.TH2F) - #@# - #@# self.book(f, "e_t_Mass", "h_vismass", 40, 0, 400) - #@# self.book(f, "e_t_Mass_tes_plus" , "h_vismass_tes_plus", 40 , 0, 400) - #@# self.book(f, "e_t_Mass_tes_minus", "h_vismass_tes_minus",40 , 0, 400) - #@# self.book(f, "e_t_Mass_ees_plus" , "h_vismass_ees_plus", 40 , 0, 400) - #@# self.book(f, "e_t_Mass_ees_minus", "h_vismass_ees_minus",40 , 0, 400) - #@# - #@# self.book(f, "MetEt_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 20, 0, 3.2, 40, 0, 400, type=ROOT.TH2F) - #@# - #@# self.book(f, "tPFMET_DeltaPhi", "tau-type1PFMET DeltaPhi" , 20, 0, 3.2) - #@# - #@# self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 20, 0, 3.2) - #@# - #@# #self.book(f,"tMtToPFMET", "tau-PFMET M_{T}" , 200, 0, 200) - #@# book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 40, 0, 200, - #@# postfixes=full_met_systematics) - #@# #self.book(f,"eMtToPFMET", "e-PFMET M_{T}" , 200, 0, 200) - #@# book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 40, 0, 200, - #@# postfixes=full_met_systematics) - #@# - #@# #self.book(f, "pfMetEt", "pfMetEt", 200, 0, 200) - #@# book_with_sys(f, "pfMet_Et", "pfMet_Et", 40, 0, 200, postfixes=full_met_systematics) - #@# - #@# #self.book(f, "pfMetPhi", "pfMetPhi", 100, -3.2, 3.2) - #@# book_with_sys(f, "pfMet_Phi", "pfMet_Phi", 26, -3.2, 3.2, postfixes=full_met_systematics) - #@# - #@# self.book(f, "jetVeto20", "Number of jets, p_{T}>20", 5, -0.5, 4.5) - #@# self.book(f, "jetVeto30", "Number of jets, p_{T}>30", 5, -0.5, 4.5) + + self.book(f, "h_collmass_vs_dPhi_pfmet", "h_collmass_vs_dPhi_pfmet", 20, 0, 3.2, 40, 0, 400, type=ROOT.TH2F) + + self.book(f, "e_t_Mass", "h_vismass", 40, 0, 400) + self.book(f, "e_t_Mass_tes_plus" , "h_vismass_tes_plus", 40 , 0, 400) + self.book(f, "e_t_Mass_tes_minus", "h_vismass_tes_minus",40 , 0, 400) + self.book(f, "e_t_Mass_ees_plus" , "h_vismass_ees_plus", 40 , 0, 400) + self.book(f, "e_t_Mass_ees_minus", "h_vismass_ees_minus",40 , 0, 400) + + self.book(f, "MetEt_vs_dPhi", "PFMet vs #Delta#phi(#tau,PFMet)", 20, 0, 3.2, 40, 0, 400, type=ROOT.TH2F) + self.book(f, "tPFMET_DeltaPhi", "tau-type1PFMET DeltaPhi" , 20, 0, 3.2) + + self.book(f, "ePFMET_DeltaPhi", "e-PFMET DeltaPhi" , 20, 0, 3.2) + + #self.book(f,"tMtToPFMET", "tau-PFMET M_{T}" , 200, 0, 200) + book_with_sys(f, "tMtToPfMet", "tau-PFMET M_{T}" , 40, 0, 200, + postfixes=full_met_systematics) + #self.book(f,"eMtToPFMET", "e-PFMET M_{T}" , 200, 0, 200) + book_with_sys(f, "eMtToPfMet", "e-PFMET M_{T}" , 40, 0, 200, + postfixes=full_met_systematics) + + #self.book(f, "pfMetEt", "pfMetEt", 200, 0, 200) + book_with_sys(f, "type1_pfMet_Et", "type1_pfMet_Et", 40, 0, 200, postfixes=full_met_systematics) + + #self.book(f, "pfMetPhi", "pfMetPhi", 100, -3.2, 3.2) + book_with_sys(f, "type1_pfMet_Phi", "type1_pfMet_Phi", 26, -3.2, 3.2, postfixes=full_met_systematics) + + self.book(f, "jetVeto20", "Number of jets, p_{T}>20", 5, -0.5, 4.5) + self.book(f, "jetVeto30", "Number of jets, p_{T}>30", 5, -0.5, 4.5) + #index dirs and histograms for key, value in self.histograms.iteritems(): location = os.path.dirname(key) @@ -335,7 +384,7 @@ def book_with_sys(location, name, *args, **kwargs): else: self.histo_locations[location][name] = value - def fakerate_weights(self, tEta): + def fakerate_weights(self, tEta, ePt): tLoose = tau_fake_rate(tEta) tLooseUp = tau_fake_rate_up(tEta) tLooseDown= tau_fake_rate_dw(tEta) @@ -345,9 +394,9 @@ def fakerate_weights(self, tEta): tLooseDown= tLooseDown / (1. - tLooseDown) - eLoose = self.efake - eLooseUp = self.efakeup - eLooseDown= self.efakedw + eLoose = e_fake_rate(ePt)#self.efake + eLooseUp = e_fake_rate_up(ePt)#self.efakeup + eLooseDown= e_fake_rate_dw(ePt)#self.efakedw eLoose = eLoose / (1. - eLoose ) eLooseUp = eLooseUp / (1. - eLooseUp ) @@ -427,6 +476,7 @@ def process(self): sys_shifts = systematics['trig'] + \ systematics['pu'] + \ systematics['eid'] + \ + systematics['etaufake'] + \ systematics['eiso'] #+ \ jes_dirs = [i.strip('_') for i in systematics['jes']] @@ -463,7 +513,7 @@ def process(self): if not row.tLooseIso3Hits : continue logging.debug('object selection passed') #e ID/ISO - if not selections.lepton_id_iso(row, 'e', 'eid13Tight_idiso02'): continue + if not selections.lepton_id_iso(row, 'e', 'eid13Loose_idiso05'): continue logging.debug('Passed preselection') # @@ -503,6 +553,7 @@ def process(self): jets = [min(row.jetVeto30, 3), min(row.jetVeto30jes_plus, 3), min(row.jetVeto30jes_minus, 3)] tpts = [row.tPt_tes_plus, row.tPt_tes_minus] epts = [row.ePt_ees_plus, row.ePt_ees_minus] + #print 'electron pt' , row.ePt, row.ePt_ees_plus, row.ePt_ees_minus sys_effects = [(name, central.clone(njets = jnum)) for name, jnum in zip(jes_dirs, jets)] sys_effects.extend( [(name, central.clone(tPt = pt)) for name, pt in zip(tes_dirs, tpts)] @@ -532,8 +583,8 @@ def process(self): ]) if shifted.tPt < 30: continue #was 35 - if shifted.ePt < 50: continue #was 40 - if deltaPhi(row.ePhi, row.tPhi) < 2.5 : continue #was 2.7 + if shifted.ePt < 45: continue #was 40 + if deltaPhi(row.ePhi, row.tPhi) < 2.3 : continue #was 2.7 if row.tMtToPfMet > 70 : continue #was 50 selection_categories.append((name, '0', 'selected')) passes_full_selection = True @@ -543,9 +594,9 @@ def process(self): shifted.tPt, shifted.ePt, row.tMtToPfMet) ]) - if shifted.tPt < 30: continue #was 40 - if shifted.ePt < 40: continue #was 35 - if row.tMtToPfMet > 45 : continue #was 35 + if shifted.tPt < 40: continue #was 40 + if shifted.ePt < 35: continue #was 35 + if row.tMtToPfMet > 40 : continue #was 35 selection_categories.append((name, '1', 'selected')) passes_full_selection = True elif shifted.njets == 2 : @@ -556,10 +607,10 @@ def process(self): ]) if shifted.tPt < 30: continue #was 40 - if shifted.ePt < 40: continue #was 30 - if row.tMtToPfMet > 55 : continue #was 35 - if row.vbfMass < 500 : continue #was 550 - if row.vbfDeta < 2.5 : continue #was 3.5 + if shifted.ePt < 35: continue #was 30 + if row.tMtToPfMet > 50 : continue #was 35 + if row.vbfMass < 400 : continue #was 550 + if row.vbfDeta < 2.3 : continue #was 3.5 selection_categories.append((name, '2', 'selected')) passes_full_selection = True @@ -609,7 +660,7 @@ def process(self): mc_weight = weight_map[''] #weights are the fr ones... - weight_map = self.fakerate_weights(row.tEta) + weight_map = self.fakerate_weights(row.tEta, row.ePt) for i in weight_map: #...times the mc weight (if any) weight_map[i] *= mc_weight From 38dd263b55de5e07fb3958df987ac4b65a1062c8 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Tue, 10 Mar 2015 13:01:08 -0500 Subject: [PATCH 190/192] adding Zee syst --- lfvetau/LFVHETauAnalyzerMVA.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index 92a13682..c0922b30 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -108,12 +108,12 @@ def collmassZeeShift(row,weight): def make_collmass_systematics(shift): if shift.startswith('tes'): - ptnu =abs(met*cos(deltaPhi(metphi, row.tPhi))) + ptnu =abs(met*cos(deltaPhi(metPhi, row.tPhi))) visfrac = tpt/(tpt+ptnu) vis_mass = vismass(shift) return (vis_mass / sqrt(visfrac)) elif shift.startswith('ees'): - ptnu =abs(met*cos(deltaPhi(metphi, row.tPhi))) + ptnu =abs(met*cos(deltaPhi(metPhi, row.tPhi))) visfrac = tpt/(tpt+ptnu) vis_mass = vismass(shift) return (vis_mass / sqrt(visfrac)) From 72975bcb343cf41a327ab40ffea58772deca2906 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Tue, 10 Mar 2015 13:11:43 -0500 Subject: [PATCH 191/192] adding Zee syst --- lfvetau/LFVHETauAnalyzerMVA.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lfvetau/LFVHETauAnalyzerMVA.py b/lfvetau/LFVHETauAnalyzerMVA.py index c0922b30..5278c94c 100644 --- a/lfvetau/LFVHETauAnalyzerMVA.py +++ b/lfvetau/LFVHETauAnalyzerMVA.py @@ -98,11 +98,6 @@ def deltaR(phi1, ph2, eta1, eta2): if (dphi>pi) : dphi = 2*pi-dphi return sqrt(deta*deta + dphi*dphi); -def collmassZeeShift(row,weight): - ptnu =abs(row.type1_pfMet_Et*cos(deltaPhi(type1_pfMet_Phi, row.tPhi))) - visfrac = row.tPt/(row.tPt+ptnu) - #print met, cos(deltaPhi(metPhi, row.tPhi)), ptnu, visfrac - return (row.e_t_Mass / sqrt(visfrac))*weight def make_collmass_systematics(shift): @@ -118,12 +113,13 @@ def make_collmass_systematics(shift): vis_mass = vismass(shift) return (vis_mass / sqrt(visfrac)) - elif shift.startswith('etaufake'): - - if shift== 'etaufakep1s': - return collmassZeeShift(row, 1.025) + elif shift.startswith('_Zee'): + ptnu =abs(row.type1_pfMet_Et*cos(deltaPhi(row.type1_pfMet_Phi, row.tPhi))) + visfrac = row.tPt/(row.tPt+ptnu) + if shift== '_Zee_p1s': + return 1.025*(row.e_t_Mass / sqrt(visfrac)) else: - return collmassZeeShift(row,0.975) + return 0.975*(row.e_t_Mass / sqrt(visfrac)) else: met_name = met(shift) @@ -168,7 +164,9 @@ def __init__(self, tree, outfile, **kwargs): 'evetos': (['', 'eVetoUp', 'eVetoDown'] if self.is_mc else ['']), 'met' : (["_mes_plus", "_ues_plus", "_mes_minus", "_ues_minus"] if self.is_mc else []), 'tes' : (["", "_tes_plus", "_tes_minus"] if not self.is_data else ['']), - 'ees' : (["", "_ees_plus", '_ees_minus'] if not self.is_data else ['']) + 'ees' : (["", "_ees_plus", '_ees_minus'] if not self.is_data else ['']), + 'Zee' : (['', '_Zee_p1s','Zee_m1s'] if self.is_Zee else ['']), + #### 'trig' : (['', 'trp1s', 'trm1s'] if not self.is_data else []), #### 'pu' : (['', 'p1s', 'm1s'] if self.is_mc else []), #### 'eid' : (['', 'eidp1s','eidm1s'] if False else []), @@ -218,7 +216,7 @@ def __init__(self, tree, outfile, **kwargs): #patch name postfix = shift self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) - for shift in self.systematics['etaufake']: + for shift in self.systematics['Zee']: #patch name postfix = shift self.hfunc['h_collmass_pfmet%s' % postfix] = make_collmass_systematics(shift) From 2fcd4d93b74351811ef0eaeb8c6681cbe9887018 Mon Sep 17 00:00:00 2001 From: Silvia Taroni Date: Fri, 26 Jun 2015 09:59:22 -0500 Subject: [PATCH 192/192] adding the possibility to reduce histo range --- lfvetau/BasePlotter.py | 419 ++++++++++++++++++++++++------- lfvetau/plotRecoQuantitiesMVA.py | 84 ++++--- 2 files changed, 371 insertions(+), 132 deletions(-) diff --git a/lfvetau/BasePlotter.py b/lfvetau/BasePlotter.py index c8937cf8..11e6ad03 100644 --- a/lfvetau/BasePlotter.py +++ b/lfvetau/BasePlotter.py @@ -68,6 +68,7 @@ def mean(histo): nbins = histo.GetNbinsX() wsum = sum( histo.GetBinCenter(i)*histo.GetBinContent(i) for i in xrange(1, nbins+1)) entries = sum(histo.GetBinContent(i) for i in xrange(1, nbins+1)) + #print histo.GetTitle(), wsum, entries, nbins, histo.GetEntries(), histo.Integral() return float(wsum)/entries def name_systematic(name): @@ -98,11 +99,26 @@ def remove_empty_bins(histogram, weight, first = 0, last = 0): if ret.GetBinContent(i) <= 0: ret.SetBinContent(i, 0.9200*weight) #MEAN WEIGHT ret.SetBinError(i, 1.8*weight) - return ret + return ret + +def change_histo_nbins(histogram, first = 0, last = 0): + nbins = int((last - first)/histogram.GetBinWidth(2)) + if nbins == histogram.GetNbinsX(): + return histogram + else: + name = "" + title ="" + name = histogram.GetName() + title = histogram.GetTitle() + newH = ROOT.TH1F(name, title, nbins , first, last) + for i in range (1, nbins+1): + newH.SetBinContent(i, histogram.GetBinContent(i)) + newH.SetBinError(i, histogram.GetBinError(i)) + return newH def find_fill_range(histo): first, last = (0, 0) - for i in range(histo.GetNbinsX() + 2): + for i in range(histo.GetNbinsX() + 1): if histo.GetBinContent(i) > 0: if first: last = i @@ -120,10 +136,12 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): print "\nPlotting e tau for %s\n" % jobid files = glob.glob('results/%s/LFVHETauAnalyzerMVA/*.root' % jobid) + #files = glob.glob('results/%s/ControlRegionZee_invertedAntiE/*.root' % jobid) #files = glob.glob('results/%s/EmbeddedCheck/*.root' % jobid) #files = glob.glob('results/%s/TTbarControlRegion/*.root' % jobid) lumifiles = glob.glob('inputs/%s/*.lumicalc.sum' % jobid) + #outputdir = 'plots/%s/ControlRegionZee_invertedAntiE' % jobid outputdir = 'plots/%s/lfvet' % jobid #outputdir = 'plots/%s/EmbeddedCheck' % jobid #outputdir = 'plots/%s/TTBar' % jobid @@ -133,10 +151,11 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): samples = [os.path.basename(i).split('.')[0] for i in files] self.blind_region=blind_region + blinder=None if self.blind_region: # Don't look at the SS all pass region blinder = lambda x: BlindView(x, "os/.*ass*",blind_in_range(*self.blind_region)) - + super(BasePlotter, self).__init__(files, lumifiles, outputdir, blinder, forceLumi=forceLumi) self.mc_samples = [ @@ -151,8 +170,8 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): 'Z*jets_M50_skimmedLL', #'WH*HToTauTau', #'WH*HToWW', - #'vbfHWW', - #'ggHWW', + ##'vbfHWW', + ##'ggHWW', 'Z*jets_M50_skimmedTT' ] @@ -170,8 +189,8 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): #names must match with what defined in self.mc_samples self.datacard_names = { - #'GluGluToHToTauTau_M-125*' : 'SMGG126' , - #'VBF_HToTauTau_M-125*' : 'SMVBF126' , + ##'GluGluToHToTauTau_M-125*' : 'SMGG126' , + ##'VBF_HToTauTau_M-125*' : 'SMVBF126' , 'ggH[tWB][tWB]' : 'SMGG126' , 'vbfH[tWB][tWB]' : 'SMVBF126' , 'TTJets*' : 'ttbar' , @@ -182,24 +201,27 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): 'Z*jets_M50_skimmedLL' : 'zjetsother', #'missing1' : 'WWVBF126', #'missing2' : 'WWGG126', - #'vbfHWW' : 'WWVBF126', - #'ggHWW' : 'WWGG126', + ##'vbfHWW' : 'WWVBF126', + ##'ggHWW' : 'WWGG126', + ##'vbfHBB' : 'BBVBF126', + ##'ggHBB' : 'BBGG126', 'ggHiggsToETau' : 'LFVGG', 'vbfHiggsToETau' : 'LFVVBF', # 'Wplus*Jets_madgraph*' : 'wplusjets'#add in case of optimization study 'fakes' : 'fakes', - #'WH*HToTauTau' : 'VH',#'VHtautau' , #"VHtautau", - #'WH*HToWW' : 'VH'#,'VHWW' , #"VHWW", + #'WH*HToTauTau' : 'VHtautau' , #"VHtautau", + #'WH*HToWW' : 'VHWW' , #"VHWW", ##'efakes' : 'efakes', ##'etfakes' : 'etfakes' } self.sample_groups = {#parse_cgs_groups('card_config/cgs.0.conf') - 'fullsimbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', - 'diboson', 'zjetsother'],#, 'WWVBF126', 'WWGG126','VHWW','VHtautau'], #wplusjets added in case of optimization study# 'wplusjets'], - 'simbkg' : ['SMGG126', 'SMVBF126', 'ttbar', 'singlet', 'ztautau', + 'fullsimbkg' : ['SMGG126', 'SMVBF126','LFVGG', 'LFVVBF','ttbar', 'singlet', + 'diboson', 'zjetsother'],# 'WWVBF126', 'WWGG126','VHWW','VHtautau'], #wplusjets added in case of optimization study# 'wplusjets'], + 'simbkg' : ['SMGG126', 'SMVBF126', 'LFVGG', 'LFVVBF', 'ttbar', 'singlet', 'ztautau', 'diboson', 'zjetsother'],#, 'WWVBF126', 'WWGG126','VHWW','VHtautau'],# 'wplusjets'], - 'realtau' : ['ztautau', 'SMGG126', 'SMVBF126'],#, 'VHtautau'], + 'realtau' : ['diboson', 'ttbar', 'singlet', 'ztautau', 'SMGG126', 'SMVBF126','LFVGG', 'LFVVBF'],#, 'VHtautau'], + 'Zee' : ['zjetsother'] } self.systematics = { @@ -228,7 +250,7 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): ## 'apply_to' : ['simbkg'], ##}, 'JES' : { - 'type' : 'shape', + 'type' : 'yield', '+' : lambda x: os.path.join('jes_plus', x)+'_jes_plus' , '-' : lambda x: os.path.join('jes_minus', x)+'_jes_minus' , 'apply_to' : ['fullsimbkg'], @@ -246,7 +268,7 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): ## 'apply_to' : ['simbkg'], ##}, 'UES' : { ## to comment in case of optimization study - 'type' : 'shape', + 'type' : 'yield', '+' : name_systematic('_ues_plus'), '-' : name_systematic('_ues_minus'), 'apply_to' : ['fullsimbkg'], @@ -257,12 +279,25 @@ def __init__ (self, blind_region=None, forceLumi=-1, use_embedded=False): '-' : dir_systematic('Down'), 'apply_to' : ['fakes']#,'efakes','etfakes'], }, - 'stat' : { - 'type' : 'stat', - '+' : lambda x: x, - '-' : lambda x: x, - 'apply_to' : [ 'simbkg'],#['fakes','simbkg'], ## no fakes in case of optimization study - } + 'norm_etaufake' : { ## was shape etaufake + 'type' : 'yield', + '+' : dir_systematic('etaufakep1s'), + '-' : dir_systematic('etaufakem1s'), + 'apply_to' : ['Zee']#,'efakes','etfakes'], + }, + 'shape_ZeeMassShift' : { ## to comment in case of optimization study + 'type' : 'shape', + '+' : name_systematic('_Zee_p1s'), + '-' : name_systematic('_Zee_m1s'), + 'apply_to' : ['Zee']#,'efakes','etfakes'], + }, + ##'stat' : { + ## 'type' : 'stat', + ## '+' : lambda x: x, + ## '-' : lambda x: x, + ## 'apply_to' : ['fakes','simbkg'], + ## #'apply_to' : [ 'simbkg'],#['fakes','simbkg'], ## no fakes in case of optimization study + ##} } @@ -625,7 +660,7 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', 'T*_t*' : 0.041, '[WZ][WZ]Jets' : 0.056, #diboson 'Wplus*Jets_madgraph*' : 0.035, #WJets - 'Z*jets_M50_skimmedLL' : 0.032, + 'Z*jets_M50_skimmedLL' : 0.300, # theoretical 0.032 'Z*jets_M50_skimmedTT' : 0.032, } @@ -658,7 +693,7 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', met_systematics = [ #it was without plus ('_jes_plus', '_jes_minus'), ('_mes_plus', '_mes_minus'), - ##('_ees_plus', '_ees_minus'), + #('_ees_plus', '_ees_minus'), ('_tes_plus', '_tes_minus'), ('_ues_plus', '_ues_minus'), ] @@ -722,9 +757,10 @@ def plot_with_bkg_uncert (self, folder, variable, rebin=1, xaxis='', folder_systematics.extend([ ('%sidp1s' % name, '%sidm1s' % name), #eID scale factor ('%sisop1s' % name, '%sisom1s' % name), #e Iso scale factor + ]) - + mc_err = self.add_shape_systematics( mc_err, path, @@ -963,7 +999,7 @@ def plot_without_uncert (self, folder, variable, rebin=1, xaxis='', self.add_ratio_diff(data, mc_stack, finalhisto, xrange, ratio_range) def write_shapes(self, folder, variable, output_dir, br_strenght=1, - rebin=1, preprocess=None): #, systematics): + rebin=1, last = 400, preprocess=None): #, systematics): '''Makes shapes for computing the limit and returns a list of systematic effects to be added to unc.vals/conf make_shapes(folder, variable, output_dir, [rebin=1, preprocess=None) --> unc_conf_lines (list), unc_vals_lines (list) ''' @@ -976,6 +1012,8 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, data_view = preprocess( data_view ) data_view = self.rebin_view(data_view, rebin) data = data_view.Get(path) + + data=change_histo_nbins(data, 0, last) first_filled, last_filled = find_fill_range(data) data.SetName('data_obs') data.Write() @@ -991,10 +1029,13 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, bkg_histos = {} for name, view in bkg_views.iteritems(): mc_histo = view.Get(path) + mc_histo = change_histo_nbins(mc_histo, 0, last) + first_filled_bkg, last_filled_bkg= find_fill_range(mc_histo) + print name, first_filled_bkg, last_filled_bkg, mc_histo.GetXaxis().GetNbins() bkg_histos[name] = mc_histo.Clone() mc_histo = remove_empty_bins( mc_histo, bkg_weights[name], - first_filled, last_filled) + first_filled_bkg, last_filled_bkg) mc_histo.SetName(name) mc_histo.Write() @@ -1008,10 +1049,12 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, bkg_weights[name] = weight bkg_views[name] = view mc_histo = view.Get(path) + mc_histo = change_histo_nbins(mc_histo, 0, last) + first_filled_bkg, last_filled_bkg= find_fill_range(mc_histo) bkg_histos[name] = mc_histo.Clone() mc_histo = remove_empty_bins( mc_histo, weight, - first_filled, last_filled) + first_filled_bkg, last_filled_bkg) mc_histo.SetName(name) mc_histo.Write() @@ -1026,17 +1069,49 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, fakes_view = preprocess(fakes_view) weights_view = preprocess(weights_view) weights = weights_view.Get(os.path.join(folder,'weight')) + #print folder fakes_view = self.rebin_view(fakes_view, rebin) bkg_views['fakes'] = fakes_view bkg_weights['fakes'] = mean(weights) fake_shape = bkg_views['fakes'].Get(path) + fake_shape = change_histo_nbins(fake_shape, 0, last) bkg_histos['fakes'] = fake_shape.Clone() + bkg_histos['fakes'] =change_histo_nbins(bkg_histos['fakes'] , 0, last) + first_filled_bkg, last_filled_bkg = find_fill_range(bkg_histos['fakes']) fake_shape = remove_empty_bins( fake_shape, bkg_weights['fakes'], - first_filled, last_filled) + first_filled_bkg, last_filled_bkg) fake_shape.SetName('fakes') fake_shape.Write() + #Get signal + signals = [ + 'ggHiggsToETau', + 'vbfHiggsToETau', + ] + for name in signals: + sig_view = self.get_view(name) + card_name = self.datacard_names[name] + if preprocess: + sig_view = preprocess(sig_view) + sig_view = views.ScaleView( + RebinView(sig_view, rebin), + br_strenght + ) + weights = self.get_view(name, 'weight') + bkg_views[card_name] = sig_view + bkg_weights[card_name] = weights + histogram = sig_view.Get(path) + histogram = change_histo_nbins(histogram, 0, last) + bkg_histos[card_name] = histogram.Clone() + first_filled_bkg, last_filled_bkg = find_fill_range(bkg_histos[card_name]) + histogram = remove_empty_bins( + histogram, bkg_weights[card_name], + first_filled_bkg, last_filled_bkg) + histogram.SetName(card_name) + histogram.Write() + + unc_conf_lines = [] unc_vals_lines = [] category_name = output_dir.GetName() @@ -1078,12 +1153,14 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, elif info['type'] == 'shape': #remove empty bins also for shapes #(but not in general to not spoil the stat uncertainties) + first_filled_bkg,last_filled_bkg= find_fill_range( bkg_histos[target]) up = remove_empty_bins( up, bkg_weights[target], - first_filled, last_filled) + first_filled_bkg, last_filled_bkg) + first_filled_bkg, last_filled_bkg= find_fill_range( bkg_histos[target]) down = remove_empty_bins( down, bkg_weights[target], - first_filled, last_filled) + first_filled_bkg, last_filled_bkg) up.SetName('%s_%sUp' % (target, unc_name)) down.SetName('%s_%sDown' % (target, unc_name)) up.Write() @@ -1112,33 +1189,6 @@ def write_shapes(self, folder, variable, output_dir, br_strenght=1, '%s %s %s %.2f' % (category_name, ','.join(targets), unc_name, shift) ) - #Get signal - signals = [ - 'ggHiggsToETau', - 'vbfHiggsToETau', - ] - for name in signals: - sig_view = self.get_view(name) - if preprocess: - sig_view = preprocess(sig_view) - sig_view = views.ScaleView( - RebinView(sig_view, rebin), - br_strenght - ) - - histogram = sig_view.Get(path) - histogram.SetName(self.datacard_names[name]) - histogram.Write() - - # Draw data - data_view = self.get_view('data') - if preprocess: - data_view = preprocess( data_view ) - data_view = self.rebin_view(data_view, rebin) - data = data_view.Get(path) - data.SetName('data_obs') - data.Write() - return unc_conf_lines, unc_vals_lines ##----- @@ -1151,6 +1201,16 @@ def write_shapes_for_yields(self, folder, variable, output_dir, br_strenght=1, output_dir.cd() path = os.path.join(folder,variable) + # Draw data + data_view = self.get_view('data') + if preprocess: + data_view = preprocess( data_view ) + data_view = self.rebin_view(data_view, rebin) + data = data_view.Get(path) + first_filled, last_filled = find_fill_range(data) + data.SetName('data_obs') + data.Write() + #make MC views with xsec error bkg_views = dict( [(self.datacard_names[i], j) for i, j in zip(self.mc_samples, self.mc_views(rebin, preprocess))] @@ -1162,9 +1222,12 @@ def write_shapes_for_yields(self, folder, variable, output_dir, br_strenght=1, bkg_histos = {} for name, view in bkg_views.iteritems(): mc_histo = view.Get(path) + first_filled_bkg, last_filled_bkg= find_fill_range(mc_histo) + print name, first_filled_bkg, last_filled_bkg, mc_histo.GetXaxis().GetNbins() bkg_histos[name] = mc_histo.Clone() #mc_histo = remove_empty_bins( - # mc_histo, bkg_weights[name]) + # mc_histo, bkg_weights[name], + # first_filled_bkg, last_filled_bkg) mc_histo.SetName(name) mc_histo.Write() @@ -1178,13 +1241,15 @@ def write_shapes_for_yields(self, folder, variable, output_dir, br_strenght=1, bkg_weights[name] = weight bkg_views[name] = view mc_histo = view.Get(path) + first_filled_bkg, last_filled_bkg= find_fill_range(mc_histo) bkg_histos[name] = mc_histo.Clone() #mc_histo = remove_empty_bins( - # mc_histo, weight) + # mc_histo, weight, + # first_filled_bkg, last_filled_bkg) mc_histo.SetName(name) mc_histo.Write() - fakes_view = self.get_view('fakes')#to comment for optimization study + fakes_view = self.get_view('fakes') d_view = self.get_view('data') weights_view = views.SumView( views.SubdirectoryView(d_view, 'tLoose'), @@ -1192,19 +1257,49 @@ def write_shapes_for_yields(self, folder, variable, output_dir, br_strenght=1, views.SubdirectoryView(d_view, 'etLoose') ) if preprocess: - fakes_view = preprocess(fakes_view) + fakes_view = preprocess(fakes_view) weights_view = preprocess(weights_view) - weights = weights_view.Get(os.path.join(folder,'weight')) #to comment for optimization study + weights = weights_view.Get(os.path.join(folder,'weight')) + #print folder fakes_view = self.rebin_view(fakes_view, rebin) bkg_views['fakes'] = fakes_view bkg_weights['fakes'] = mean(weights) fake_shape = bkg_views['fakes'].Get(path) bkg_histos['fakes'] = fake_shape.Clone() + first_filled_bkg, last_filled_bkg = find_fill_range(bkg_histos['fakes']) #fake_shape = remove_empty_bins( - # fake_shape, bkg_weights['fakes']) + # fake_shape, bkg_weights['fakes'], + # first_filled_bkg, last_filled_bkg) fake_shape.SetName('fakes') fake_shape.Write() + #Get signal + signals = [ + 'ggHiggsToETau', + 'vbfHiggsToETau', + ] + for name in signals: + sig_view = self.get_view(name) + card_name = self.datacard_names[name] + if preprocess: + sig_view = preprocess(sig_view) + sig_view = views.ScaleView( + RebinView(sig_view, rebin), + br_strenght + ) + weights = self.get_view(name, 'weight') + bkg_views[card_name] = sig_view + bkg_weights[card_name] = weights + histogram = sig_view.Get(path) + bkg_histos[card_name] = histogram.Clone() + first_filled_bkg, last_filled_bkg = find_fill_range(bkg_histos[card_name]) + #histogram = remove_empty_bins( + # histogram, bkg_weights[card_name], + # first_filled_bkg, last_filled_bkg) + histogram.SetName(card_name) + histogram.Write() + + unc_conf_lines = [] unc_vals_lines = [] category_name = output_dir.GetName() @@ -1246,8 +1341,14 @@ def write_shapes_for_yields(self, folder, variable, output_dir, br_strenght=1, elif info['type'] == 'shape': #remove empty bins also for shapes #(but not in general to not spoil the stat uncertainties) - #up = remove_empty_bins(up, bkg_weights[target]) - #down = remove_empty_bins(down, bkg_weights[target]) + first_filled_bkg,last_filled_bkg= find_fill_range( bkg_histos[target]) + ##up = remove_empty_bins( + ## up, bkg_weights[target], + ## first_filled_bkg, last_filled_bkg) + first_filled_bkg, last_filled_bkg= find_fill_range( bkg_histos[target]) + ##down = remove_empty_bins( + ## down, bkg_weights[target], + ## first_filled_bkg, last_filled_bkg) up.SetName('%s_%sUp' % (target, unc_name)) down.SetName('%s_%sDown' % (target, unc_name)) up.Write() @@ -1276,34 +1377,164 @@ def write_shapes_for_yields(self, folder, variable, output_dir, br_strenght=1, '%s %s %s %.2f' % (category_name, ','.join(targets), unc_name, shift) ) - #Get signal - signals = [ - 'ggHiggsToETau', - 'vbfHiggsToETau', - ] - for name in signals: - sig_view = self.get_view(name) - if preprocess: - sig_view = preprocess(sig_view) - sig_view = views.ScaleView( - RebinView(sig_view, rebin), - br_strenght - ) - - histogram = sig_view.Get(path) - histogram.SetName(self.datacard_names[name]) - histogram.Write() - - # Draw data - data_view = self.get_view('data') - if preprocess: - data_view = preprocess( data_view ) - data_view = self.rebin_view(data_view, rebin) - data = data_view.Get(path) - data.SetName('data_obs') - data.Write() - return unc_conf_lines, unc_vals_lines +## output_dir.cd() +## path = os.path.join(folder,variable) +## +## #make MC views with xsec error +## bkg_views = dict( +## [(self.datacard_names[i], j) for i, j in zip(self.mc_samples, self.mc_views(rebin, preprocess))] +## ) +## bkg_weights = dict( +## [(self.datacard_names[i], self.get_view(i, 'weight')) for i in self.mc_samples] +## ) +## #cache histograms, since getting them is time consuming +## bkg_histos = {} +## for name, view in bkg_views.iteritems(): +## mc_histo = view.Get(path) +## bkg_histos[name] = mc_histo.Clone() +## #mc_histo = remove_empty_bins( +## # mc_histo, bkg_weights[name]) +## mc_histo.SetName(name) +## mc_histo.Write() +## +## if self.use_embedded: +## view = self.get_view('ZetauEmbedded') +## weight = self.get_view('ZetauEmbedded', 'weight') +## if preprocess: +## view = preprocess(view) +## view = self.rebin_view(view, rebin) +## name = self.datacard_names['ZetauEmbedded'] +## bkg_weights[name] = weight +## bkg_views[name] = view +## mc_histo = view.Get(path) +## bkg_histos[name] = mc_histo.Clone() +## #mc_histo = remove_empty_bins( +## # mc_histo, weight) +## mc_histo.SetName(name) +## mc_histo.Write() +## +## fakes_view = self.get_view('fakes')#to comment for optimization study +## d_view = self.get_view('data') +## weights_view = views.SumView( +## views.SubdirectoryView(d_view, 'tLoose'), +## views.SubdirectoryView(d_view, 'eLoose'), +## views.SubdirectoryView(d_view, 'etLoose') +## ) +## if preprocess: +## fakes_view = preprocess(fakes_view) +## weights_view = preprocess(weights_view) +## weights = weights_view.Get(os.path.join(folder,'weight')) #to comment for optimization study +## fakes_view = self.rebin_view(fakes_view, rebin) +## bkg_views['fakes'] = fakes_view +## bkg_weights['fakes'] = mean(weights) +## fake_shape = bkg_views['fakes'].Get(path) +## bkg_histos['fakes'] = fake_shape.Clone() +## #fake_shape = remove_empty_bins( +## # fake_shape, bkg_weights['fakes']) +## fake_shape.SetName('fakes') +## fake_shape.Write() +## +## unc_conf_lines = [] +## unc_vals_lines = [] +## category_name = output_dir.GetName() +## for unc_name, info in self.systematics.iteritems(): +## print unc_name +## targets = [] +## for target in info['apply_to']: +## if target in self.sample_groups: +## targets.extend(self.sample_groups[target]) +## else: +## targets.append(target) +## +## unc_conf = 'lnN' if info['type'] == 'yield' or info['type'] == 'stat' else 'shape' +## #stat shapes are uncorrelated between samples +## if info['type'] <> 'stat': +## unc_conf_lines.append('%s %s' % (unc_name, unc_conf)) +## shift = 0. +## path_up = info['+'](path) +## path_dw = info['-'](path) +## for target in targets: +## up = bkg_views[target].Get( +## path_up +## ) +## down = bkg_views[target].Get( +## path_dw +## ) +## if info['type'] == 'yield': +## central = bkg_histos[target] +## integral = central.Integral() +## integral_up = up.Integral() +## integral_down = down.Integral() +## if integral == 0 and integral_up == 0 and integral_down ==0 : +## shift=shift +## else: +## shift = max( +## shift, +## (integral_up - integral) / integral, +## (integral - integral_down) / integral +## ) +## elif info['type'] == 'shape': +## #remove empty bins also for shapes +## #(but not in general to not spoil the stat uncertainties) +## #up = remove_empty_bins(up, bkg_weights[target]) +## #down = remove_empty_bins(down, bkg_weights[target]) +## up.SetName('%s_%sUp' % (target, unc_name)) +## down.SetName('%s_%sDown' % (target, unc_name)) +## up.Write() +## down.Write() +## elif info['type'] == 'stat': +## nbins = up.GetNbinsX() +## up.Rebin(nbins) +## yield_val = up.GetBinContent(1) +## yield_err = up.GetBinError(1) +## print target, yield_val, yield_err, +## if yield_val==0: +## unc_value = 0. +## else: +## unc_value = 1. + (yield_err / yield_val) +## stat_unc_name = '%s_%s_%s' % (target, category_name, unc_name) +## unc_conf_lines.append('%s %s' % (stat_unc_name, unc_conf)) +## unc_vals_lines.append( +## '%s %s %s %.2f' % (category_name, target, stat_unc_name, unc_value) +## ) +## else: +## raise ValueError('systematic uncertainty type:"%s" not recognised!' % info['type']) +## +## if info['type'] <> 'stat': +## shift += 1 +## unc_vals_lines.append( +## '%s %s %s %.2f' % (category_name, ','.join(targets), unc_name, shift) +## ) +## +## #Get signal +## signals = [ +## 'ggHiggsToETau', +## 'vbfHiggsToETau', +## ] +## for name in signals: +## sig_view = self.get_view(name) +## if preprocess: +## sig_view = preprocess(sig_view) +## sig_view = views.ScaleView( +## RebinView(sig_view, rebin), +## br_strenght +## ) +## +## histogram = sig_view.Get(path) +## histogram.SetName(self.datacard_names[name]) +## histogram.Write() +## +## # Draw data +## data_view = self.get_view('data') +## if preprocess: +## data_view = preprocess( data_view ) +## data_view = self.rebin_view(data_view, rebin) +## data = data_view.Get(path) +## data.SetName('data_obs') +## data.Write() +## +## return unc_conf_lines, unc_vals_lines ##----- diff --git a/lfvetau/plotRecoQuantitiesMVA.py b/lfvetau/plotRecoQuantitiesMVA.py index 1ff3a7cc..3b649c53 100644 --- a/lfvetau/plotRecoQuantitiesMVA.py +++ b/lfvetau/plotRecoQuantitiesMVA.py @@ -1,3 +1,4 @@ + #from mauro plotters #Set logging before anything to override rootpy very verbose defaults @@ -38,33 +39,40 @@ #check if blind blind = 'blind' not in os.environ or os.environ['blind'] == 'YES' +print 'blind?', blind blind_region=[100, 150] if blind else None +#blind_region=[100, 200] if blind else None embedded = True plotter = BasePlotter(blind_region,use_embedded=embedded) - if not args.no_plots: - signs = ['os','ss'] - jets = ['0','1','2'] + signs = ['os'] + jets = ['0', + '1', + '2' + ] processtype = ['gg'] threshold = ['ept30'] histo_info = [ - ('tPt', 'p_{T}(#tau) (GeV)', 1), - ('tEta', '#eta(#tau)', 1), - ('tPhi', '#phi(#tau)', 1), - ('ePt', 'p_{T}(e) (GeV)', 1), - ('eEta', '#eta(e)', 1), - ('ePhi', '#phi(e)', 1), - ('e_t_DPhi', 'e#tau #Delta#phi', 1), - ('e_t_DR', 'e#tau #Delta R', 1), - ('h_collmass_pfmet', 'M_{coll}(e#tau) (GeV)', 1), - ('e_t_Mass', 'M_{vis} (GeV)', 1), - ('jetVeto30', 'number of jets (p_{T} > 30 GeV)', 1) , - ('eMtToPfMet', 'M_{T} e-PFMET', 1), - ('tMtToPfMet', 'M_{T} #tau-PFMET', 1) , - ('pfMet_Et', 'pfMet', 1) + ('h_collmass_pfmet', 'M_{coll}(e#tau) (GeV)', 1)##, + ##('tPt', 'p_{T}(#tau) (GeV)', 1), + ##('tEta', '#eta(#tau)', 1), + ##('tPhi', '#phi(#tau)', 1), + ##('ePt', 'p_{T}(e) (GeV)', 1), + ##('eEta', '#eta(e)', 1), + ##('ePhi', '#phi(e)', 1), + ##('e_t_DPhi', 'e#tau #Delta#phi', 1), + ##('e_t_DR', 'e#tau #Delta R', 1), + ##('e_t_Mass', 'M_{vis} (GeV)', 1), + ##('jetVeto30', 'number of jets (p_{T} > 30 GeV)', 1) , + ##('eMtToPfMet', 'M_{T} e-PFMET', 1), + ##('tMtToPfMet', 'M_{T} #tau-PFMET', 1) , + ##('type1_pfMet_Et', 'pfMet', 1), + ##('vbfMass', 'M(j_{1},j_{2}) (GeV)', 1), + ##('vbfDeta', '#Delta#eta (j_{1}, j_{2})', 1) + ] logging.debug("Starting plotting") @@ -76,44 +84,44 @@ for var, xlabel, rebin in histo_info: logging.debug("Plotting %s/%s" % (path, var) ) plotter.pad.SetLogy(False) - #plotter.plot_without_uncert(foldername,h[0], rebin=int(h[2]), xaxis=h[1], leftside=False, show_ratio=True, ratio_range=0.5, sort=True, obj=['e']) - if int(njet)==2: - if 'collmass' in var or 'Mass' in var: - rebin=rebin*5 - elif not 'Eta' in var and not 'jet' in var: - rebin = rebin*2 - + ## if int(njet)==2: + ## if 'collmass' in var or 'Mass' in var: + ## rebin=rebin + ## elif not 'Eta' in var and not 'jet' in var: + ## rebin = rebin*2 plotter.plot_with_bkg_uncert(path, var, rebin, xlabel, leftside=False, show_ratio=True, ratio_range=1., - sort=True, obj=['e'], data=True) - - - plotter.save(var) + sort=True, obj=['e'], plot_data=True) + + plotter.save(var,dotroot=True) + plotter.set_subdir(os.path.join('embedded', path+'/selected'))if embedded else plotter.set_subdir(path+'/selected') for var, xlabel, rebin in histo_info: - if int(njet)==1: - if not 'Eta' in var and not 'jet' in var: rebin = rebin*2 - if int(njet) ==2: - if 'collmass' in var or 'Mass' in var: rebin=rebin*5 - if 'Pt' in var or 'Mt' in var or 'pfMet' in var : rebin=rebin*4 + ##if int(njet)==1: + ## if not 'Eta' in var and not 'jet' in var: rebin = rebin + ##if int(njet) ==2: + ## if 'collmass' in var or 'Mass' in var: rebin=rebin + ## if 'Pt' in var or 'Mt' in var or 'pfMet' in var : rebin=rebin*4 + logging.debug("Plotting %s/%s" % (path, var) ) plotter.pad.SetLogy(False) plotter.plot_with_bkg_uncert(path+'/selected', var, rebin, xlabel, leftside=False, show_ratio=True, ratio_range=1., sort=True, obj=['e'], plot_data=True) - - plotter.save(var,dotroot=False) + + plotter.save(var,dotroot=True) #make shapes for limit setting if not args.no_shapes: signal_region = 'os/gg/ept30/%s/selected' + ##signal_region = 'os/gg/ept30/%s' jets_names = [ ('0', 'gg0etau' , 1), - ('1', 'boostetau', 1), - ('2', 'vbfetau' , 5), + ('1', 'boostetau', 1),#was 2 + ('2', 'vbfetau' , 1),#was 5 ] pjoin = os.path.join for njets, cat_name, rebin in jets_names: @@ -122,7 +130,7 @@ output_dir = tfile.mkdir(cat_name) unc_conf_lines, unc_vals_lines = plotter.write_shapes( signal_region % njets, 'h_collmass_pfmet', output_dir, rebin=rebin, - br_strenght=1) + br_strenght=1, last=300) logging.warning('shape file %s created' % tfile.GetName()) tfile.Close() with open(pjoin(output_path, 'unc.%s.conf' % njets), 'w') as conf: